This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextension.js
127 lines (97 loc) · 3.37 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
let vscode = require('vscode');
let cp = require('child_process');
function activate(context) {
console.log('Congratulations, your extension "kickassembler" is now active!');
// Define the build and run command
let commandBuildRun = vscode.commands.registerCommand('kickassembler.build_run', function() {
if (buildProgram() == 0) {
runProgram();
}
});
// Define the build and debug command
let commandBuildDebug = vscode.commands.registerCommand('kickassembler.build_debug', function() {
if (buildProgram() == 0) {
runDebugProgram();
}
});
// Define the build command
let commandBuild = vscode.commands.registerCommand('kickassembler.build', function () {
buildProgram();
});
context.subscriptions.push(commandBuild);
context.subscriptions.push(commandBuildRun);
context.subscriptions.push(commandBuildDebug);
}
function deactivate() {
}
exports.activate = activate;
exports.deactivate = deactivate;
/**
* Build the program with the compiler
*/
function buildProgram() {
let errorCode = 0;
// Check path settings
let configuration = vscode.workspace.getConfiguration('kickassembler');
let kickAssPath = configuration.get('kickAssPath');
let javaPath = configuration.get("javaPath");
if (kickAssPath == "") {
vscode.window.showErrorMessage('Kick Assembler JAR path not defined! Set kickassembler.kickAssPath in User Settings.');
return;
}
let editor = vscode.window.activeTextEditor;
let outputChannel = vscode.window.createOutputChannel('Kick Assembler Build');
outputChannel.clear();
outputChannel.show();
let java = cp.spawn(javaPath, [
"-jar",
kickAssPath,
editor.document.fileName
]);
java.on('close', function(e) {
outputChannel.appendLine('Child process exit code: ' + e);
errorCode = e;
if (e != 0) {
vscode.window.showErrorMessage('Compilation failed with errors.');
}
});
java.stdout.on('data', function(data) {
outputChannel.append('' + data);
});
java.stderr.on('data', function(data) {
outputChannel.append('' + data);
});
return errorCode;
}
/**
* Run the VICE emulator with the compiled program
*/
function runProgram() {
let configuration = vscode.workspace.getConfiguration('kickassembler');
let vicePath = configuration.get("vicePath");
let editor = vscode.window.activeTextEditor;
let prg = editor.document.fileName;
// very crude but will suffice for now
prg = prg.replace(".asm", ".prg");
let vice = cp.spawn(vicePath, [prg], {
detached : true,
stdio : 'ignore'
});
vice.unref();
}
/**
* Run C64 debugger with the compiled program
*/
function runDebugProgram() {
let configuration = vscode.workspace.getConfiguration('kickassembler');
let debuggerPath = configuration.get("debuggerPath");
let editor = vscode.window.activeTextEditor;
let prg = editor.document.fileName;
// very crude but will suffice for now
prg = prg.replace(".asm", ".prg");
let db = cp.spawn(debuggerPath, [prg], {
detached : true,
stdio : 'ignore'
});
db.unref();
}