Skip to content

Commit c8b4b88

Browse files
committed
🍻 impl msdos player
1 parent 543d924 commit c8b4b88

File tree

9 files changed

+150
-15
lines changed

9 files changed

+150
-15
lines changed

package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"TD ${filename}.exe"
145145
]
146146
},
147-
"MASM": {
147+
"MASM-v6.11": {
148148
"baseBundle": "<built-in>/MASM-v6.11.jsdos",
149149
"before": [
150150
"set PATH=C:\\MASM"
@@ -159,6 +159,22 @@
159159
"link ${filename}.OBJ;",
160160
">debug ${filename}.exe"
161161
]
162+
},
163+
"MASM-v5.00": {
164+
"baseBundle": "<built-in>/MASM-v5.00.jsdos",
165+
"before": [
166+
"set PATH=C:\\MASM"
167+
],
168+
"run": [
169+
"masm ${file};",
170+
"link ${filename};",
171+
">${filename}"
172+
],
173+
"debug": [
174+
"masm ${file};",
175+
"link ${filename}.OBJ;",
176+
">debug ${filename}.exe"
177+
]
162178
}
163179
}
164180
},

src/ASM/main.ts

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export async function activate(context: vscode.ExtensionContext) {
6666
);
6767
const bundle = await fs.readFile(bundlePath);
6868

69+
const timeStamp = new Date().getTime().toString();
70+
const logFilename = timeStamp.substr(timeStamp.length - 5, 8) + '.log'.toUpperCase();
71+
6972
let result = "<should-not-return>";
7073
const uri = vscode.Uri.joinPath(seperateSpaceFolder, ("test" + path.extname(_uri.fsPath)).toUpperCase());
7174
await fs.copy(_uri, uri);
@@ -79,8 +82,6 @@ export async function activate(context: vscode.ExtensionContext) {
7982
'd:',
8083
...action.before
8184
];
82-
const timeStamp = new Date().getTime().toString();
83-
const logFilename = timeStamp.substr(timeStamp.length - 5, 8) + '.log'.toUpperCase();
8485
const logUri = vscode.Uri.joinPath(assemblyToolsFolder, logFilename);
8586
if (nodefs.existsSync(logUri.fsPath)) {
8687
await fs.delete(logUri);
@@ -174,8 +175,53 @@ export async function activate(context: vscode.ExtensionContext) {
174175
}
175176

176177
if (conf.extConf.emulator === conf.DosEmulatorType.msdos) {
177-
const t = api.msdosPlayer();
178-
t.show();
178+
const terminal = api.msdosPlayer();
179+
180+
terminal.show();
181+
api.dosbox.fromBundle(bundle, assemblyToolsFolder);
182+
action.before.forEach(
183+
val => {
184+
(terminal as vscode.Terminal).sendText(val.replace('C:', assemblyToolsFolder.fsPath));
185+
}
186+
);
187+
if (type === actionType.open) {
188+
terminal.sendText(`cd "${vscode.Uri.joinPath(_uri, '..').fsPath}"`);
189+
}
190+
else {
191+
terminal.sendText(`cd "${folder.fsPath}"`);
192+
function cb(val: string) {
193+
const r = val
194+
.replace("${file}", fileInfo.base)
195+
.replace("${filename}", fileInfo.name);
196+
if (val.startsWith('>')) {
197+
return r.replace(">", "");
198+
} else {
199+
return r + `>> ${logFilename} \n type ${logFilename}`;
200+
}
201+
}
202+
if (type === actionType.run) {
203+
action.run.map(cb).forEach(val => (terminal as vscode.Terminal).sendText(val));
204+
}
205+
if (type === actionType.debug) {
206+
action.debug.map(cb).forEach(val => (terminal as vscode.Terminal).sendText(val));
207+
}
208+
const logUri = vscode.Uri.joinPath(folder, logFilename);
209+
const [hook, promise] = messageCollector();
210+
nodefs.watchFile(logUri.fsPath, () => {
211+
try {
212+
if (nodefs.existsSync(logUri.fsPath)) {
213+
const text = nodefs.readFileSync(logUri.fsPath, { encoding: 'utf-8' });
214+
hook(text);
215+
}
216+
}
217+
catch (e) {
218+
console.error(e);
219+
}
220+
});
221+
//terminal.sendText('exit', true);
222+
result = await promise;
223+
}
224+
179225
}
180226

181227
const diagnose = diag.process(result, doc, conf.extConf.asmType);

src/ASM/statusBar.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ const emu = [
1111
];
1212

1313
const asm = [
14-
conf.Assembler.MASM,
14+
conf.Assembler['MASM-v5.00'],
15+
conf.Assembler['MASM-v6.11'],
1516
conf.Assembler.TASM
1617
];
1718

1819
const iterms: string[] = [];
1920
for (const e of emu) {
2021
for (const a of asm) {
21-
if (a === conf.Assembler.TASM && e === conf.DosEmulatorType.msdos) {
22-
continue;
22+
if (e === conf.DosEmulatorType.msdos) {
23+
if (a === conf.Assembler.TASM || a === conf.Assembler['MASM-v6.11'])
24+
continue;
2325
}
2426
iterms.push(e + '\t' + a);
2527
}

src/ASM/vscode-dosbox.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,21 @@ export interface Dosbox {
3838
}
3939

4040
export interface Jsdos {
41-
jszip: Jszip,
4241
/**
4342
* set the jsdos bundle to use
43+
*
44+
* @deprecated use jszip
4445
* @param bundle the Uint8Array data of the jsdos bundle or its Uri
4546
* @param updateConf use the conf file in the bundle
4647
*/
4748
setBundle(bundle: vscode.Uri | Uint8Array, updateConf?: boolean): void,
49+
/**
50+
* the [jszip object](https://stuk.github.io/jszip/)
51+
*
52+
* change this to change the bundle's data,
53+
* the extension call it to generate bundle data
54+
*/
55+
jszip: Jszip;
4856
updateConf(section: string, key: string, value: string | number | boolean): boolean,
4957
updateAutoexec(context: string[]): void,
5058
/**
@@ -71,7 +79,6 @@ export interface API {
7179
* @see https://github.com/js-dos/emulators
7280
*/
7381
emulators: Emulators;
74-
7582
/**
7683
* run Jsdos in ExtensionHost or Webview
7784
*/
@@ -80,17 +87,21 @@ export interface API {
8087
/**
8188
* run DOSBox via child_process
8289
*/
83-
dosbox: Dosbox
84-
;
90+
dosbox: Dosbox;
8591
/**
8692
* run DOSBox-x via child_process
8793
*/
8894
dosboxX: Dosbox;
95+
8996
/**
9097
* run msdos player via cmd.exe
9198
*
9299
* @returns a terminal to control
93100
*/
94-
msdosPlayer: () => vscode.Terminal;
101+
msdosPlayer(msdosArgs?: string[], command?: string): vscode.Terminal;
102+
/**path of the packed msdos player */
103+
msdosPath: string,
104+
/**path of the packed command.com file */
105+
commandPath: string
95106

96107
}

src/diagnose/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export class AssemblerMessageDiagnose {
6868
case Assembler.TASM:
6969
diag = tasmDiagnose(AsmMsg, doc, this._tasmCollection);
7070
break;
71-
case Assembler.MASM:
71+
case Assembler['MASM-v5.00']:
72+
case Assembler['MASM-v6.11']:
7273
diag = masmDiagnose(AsmMsg, doc, this._masmCollection);
7374
break;
7475
default:

src/diagnose/messageCollector.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export function messageCollector(): [(msg: string) => void, Promise<string>] {
1616
resolve(re[1]);
1717
resolve = undefined;
1818
}
19+
re = allmsg.match(/Microsoft \(R\) Macro Assembler Version 5.00([\s\S]*)Microsoft \(R\) Overlay Linker Version 3.60/);
20+
if (re && re[1] && resolve) {
21+
resolve(re[1]);
22+
resolve = undefined;
23+
}
1924
}
2025
,
2126
new Promise<string>(

src/test/suite/ASM.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const samplesUri = vscode.Uri.joinPath(vscode.Uri.file(__dirname), '../../../sam
1515
suite('Extension Test Suite', function () {
1616
vscode.window.showInformationMessage('Start all tests.');
1717
const MASMorTASM = [
18-
Assembler.MASM,
18+
Assembler['MASM-v5.00'],
19+
Assembler['MASM-v6.11'],
1920
Assembler.TASM,
2021
];
2122
const emulator: DosEmulatorType[] = [

src/test/suite/msdos.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as assert from 'assert';
2+
3+
// You can import and use all API from the 'vscode' module
4+
// as well as import your extension to test it
5+
import * as vscode from 'vscode';
6+
import { AsmResult } from '../../ASM/main';
7+
import { DosEmulatorType, Assembler } from '../../utils/configuration';
8+
// import * as myExtension from '../../extension';
9+
10+
const samplesUri = vscode.Uri.joinPath(vscode.Uri.file(__dirname), '../../../samples/');
11+
12+
suite('Extension Test Suite', () => {
13+
const file = '3中文路径hasError.asm';
14+
const emu = DosEmulatorType.msdos;
15+
const asm = Assembler['MASM-v5.00'];
16+
const shouldErr = 1;
17+
18+
test(`test file ${file} in ${emu} use ${asm} want should ${shouldErr} error`,
19+
async function () {
20+
if (process.platform !== 'win32') {
21+
this.skip();
22+
}
23+
this.timeout('60s');
24+
this.slow('20s');
25+
26+
//open test file. NOTE: the extension will be activated when open .asm file
27+
const samplefile = vscode.Uri.joinPath(samplesUri, file);
28+
29+
//update settings
30+
await vscode.workspace.getConfiguration('masmtasm').update("dosbox.run", "exit");
31+
await vscode.workspace.getConfiguration('masmtasm').update("ASM.emulator", emu);
32+
await vscode.workspace.getConfiguration('masmtasm').update("ASM.assembler", asm);
33+
34+
//assert the extension activated and command contributed
35+
const vscodecmds = await vscode.commands.getCommands(true);
36+
const cmd = 'masm-tasm.runASM';
37+
if (!vscodecmds.includes(cmd)) {
38+
await vscode.extensions.getExtension('xsro.masm-tasm')?.activate();
39+
}
40+
const vscodecmds2 = await vscode.commands.getCommands(true);
41+
assert.ok(vscodecmds2.includes(cmd));
42+
43+
//assert message processed
44+
const _result = await vscode.commands.executeCommand(cmd, samplefile);
45+
const { message, error } = _result as AsmResult;
46+
assert.strictEqual(error, shouldErr, message);
47+
});
48+
});

src/utils/configuration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* - TASM: including tasm.exe,tlink.exe,TD.exe
44
*/
55
export enum Assembler {
6+
'MASM-v6.11' = 'MASM-v6.11',
7+
'MASM-v5.00' = 'MASM-v5.00',
68
MASM = 'MASM',
79
TASM = 'TASM'
810
}
@@ -25,6 +27,9 @@ import * as vscode from 'vscode';
2527
class ExtensionConfiguration {
2628
public get asmType(): Assembler {
2729
const asmType: Assembler | undefined = vscode.workspace.getConfiguration('masmtasm').get('ASM.assembler');
30+
if (asmType === 'MASM') {
31+
return Assembler['MASM-v6.11'];
32+
}
2833
return asmType ? asmType : Assembler.TASM;
2934
}
3035
public get emulator(): DosEmulatorType {

0 commit comments

Comments
 (0)