Skip to content

Commit 5da6522

Browse files
committed
Rewrite some code
use async and make some changes due to the update of MASM to 6.11
1 parent 0eb5bdb commit 5da6522

File tree

14 files changed

+584
-187
lines changed

14 files changed

+584
-187
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ scripts/VSC-ExtUse.conf
1111
*.nls.*.json
1212
!/i18n/*/*.i18n.json
1313

14+
tools/boxasm.bat

.vscodeignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ LICENSE
2323
scripts/work/*
2424
!scripts/work/ignore.txt
2525
tools/dosbox/dosbox-0.74.conf
26+
tools/boxasm.bat
27+
tools/masm/ML.*
2628
scripts/VSC-ExtUse.conf
2729
# ignore i18n
2830
i18n

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
### [unreleased]
66

7-
- update masm tools to `6.11`
7+
- MASM插件更新到 `6.11`,最近在想如何支持`masm6.x`语法
8+
- 尝试用异步重写了一些代码,希望不要引入bug
89

910
### 0.4.0
1011

doc/Toolspath.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ VSCode文档中关于插件安装路径的说明[VSCode-doc](https://code.visual
2626
16位环境模拟工具和汇编工具来自[github仓库](https://github.com/xsro/VSC-ASMtasks/releases),使用的是msdos的是MS-DOS Player (i486) for Win32 console
2727

2828
| file | masm.exe(ml.exe) | link.exe | debug.exe | tasm.exe | tlink.exe | td.exe | dosbox | msdos |
29-
| ------- | -------- | -------- | --------- | -------- | --------- | ------ | ------ | --------- |
30-
| version | 6.11 | 5.31.009 | --- | 4.1 | 7.1.30.1 | -- | 0.74-3 | 4/10/2020 |
29+
| ------- | ---------------- | -------- | --------- | -------- | --------- | ------ | ------ | --------- |
30+
| version | 6.11 | 5.31.009 | --- | 4.1 | 7.1.30.1 | -- | 0.74-3 | 4/10/2020 |
3131

3232
## 自定义汇编工具路径
3333

@@ -51,6 +51,9 @@ VSCode文档中关于插件安装路径的说明[VSCode-doc](https://code.visual
5151
- SDL_net.dll
5252
4. player文件夹:MSDOS-player软件目录(for windows)
5353
- msdos.exe
54+
- **假如**这里有文件`playerasm.bat`插件会使用这个文件来进行汇编链接操作
55+
5. 假如这里有文件`boxasm.bat`插件会使用这个文件来进行操作
56+
5457

5558
#### 首选项中设置
5659

i18n/chs/package.i18n.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dosasm.config.masmortasm.description": "使用MASM还是TASM作为汇编工具",
88
"dosasm.config.masmortasm.enum1": "使用MASM汇编工具集,包括masm.exe,link.exe,debug.exe...",
99
"dosasm.config.masmortasm.enum2": "使用TASM汇编工具集,包括tasm.exe,tlink.exe,td.exe...",
10-
"dosasm.config.emulator.description": "windows下选择使用的16位环境模拟器,其他系统都视为使用DOSBox",
10+
"dosasm.config.emulator.description": "windows下选择使用的16位环境模拟器,其他系统都视为使用DOSBox,msdos player可能不够稳定",
1111
"dosasm.config.emulator.dosbox": "全部使用dosbox模拟16位系统环境,相对比较稳定",
1212
"dosasm.config.emulator.player": "尽量使用msdos player模拟,td时使用dosbox,不会弹出一个窗口,但是可能无法得到程序预期的运行结果",
1313
"dosasm.config.emulator.auto": "自动选择(推荐):使用MSDOS-player汇编链接,使用dosbox运行,TD调试时用dosbox,debug调试时用MSDOS player",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "MASM/TASM",
44
"publisher": "xsro",
55
"description": "DOS汇编语言开发环境和语法支持,win下安装即用,自带DOSBox.exe和TASM/MASM工具",
6-
"version": "0.4.1-alpha.1",
6+
"version": "0.5.0",
77
"keywords": [
88
"dosbox",
99
"16位",

scripts/boxasm.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
::this batch file will be used in dosbox by vscode extension
1+
::this batch file will be used in dosbox by xsro.masm-tasm
22
@echo off
33
if exist T.exe del T.exe
44
if exist T.OBJ del T.OBJ

scripts/playerasm.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
::a small batch to reduce ts code when using msdos
1+
::this batch file is used to assemble and link ASM code by xsro.masm-tasm
22
::%1 toolspath
33
::%2 masmortasm
44
::%3 file path
55
::%4 workpath
6-
:: exit 9 copy dailed
76
@echo off
87
set "cdo=%CD%">nul
98
::echo ASMfile:%~f3
@@ -17,7 +16,7 @@ if "%2" == "TASM" goto tasm
1716
goto end
1817
:masm
1918
echo (msdos-player)masm T.ASM;
20-
msdos masm T.ASM;
19+
masm T.ASM;
2120
echo (msdos-player)link T.OBJ;
2221
msdos link T.OBJ;
2322
goto end
@@ -28,5 +27,6 @@ goto end
2827
msdos tlink /v/3 T.OBJ
2928
:end
3029
cd "%cdo%"
30+
exit
3131

3232

src/DOSBox.ts

Lines changed: 114 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,129 @@
1-
import { Uri, workspace, window, TextDocument } from 'vscode';
2-
1+
import { Uri, workspace, window, TextDocument, FileType } from 'vscode';
32
import { Config } from './configration';
4-
import { exec } from 'child_process';
3+
import { exec, ExecOptions } from 'child_process';
54
import { AssemblerDiag } from './language/diagnose';
65
import * as nls from 'vscode-nls';
76
const localize = nls.loadMessageBundle();
8-
export class DOSBox {
9-
constructor() {
10-
}
11-
/**打开dosbox,操作文件
12-
* @param conf 配置信息
13-
* @param more 需要执行的额外命令
14-
* @param doc 需要处理的文件,假如有会清理工作文件夹,复制该文件到工作文件夹
15-
* @param diag 如果有则诊断输出信息
16-
*/
17-
public openDOSBox(conf: Config, more?: string, doc?: TextDocument, diag?: AssemblerDiag) {
18-
let boxcmd: string = '@echo off\n';
19-
//mount the necessary path
20-
boxcmd += `mount c \\\"${conf.path}\\\"\nmount d \\\"${conf.workpath}\\\"\n`;
21-
//switch to the working space and add path\
22-
boxcmd += "d:\nset PATH=%%PATH%%;c:\\tasm;c:\\masm\n";
23-
if (doc) { boxcmd += "echo Your file has been copied as D:\\T.ASM\n"; };
24-
boxcmd += "@echo on";
25-
//add extra commands
26-
if (more) { boxcmd += "\n" + more; }
27-
//change string to needed form as dosbox parameter
28-
boxcmd = boxcmd.replace(/\n/g, '" -c "');
29-
let boxcommand = '-c "' + boxcmd + '"';
30-
//command for open dosbox
31-
let command = conf.OpenDosbox + ' -conf "' + conf.dosboxconfuri.fsPath + '" ';
32-
//exec command by terminal
33-
let callback = (error: any, stdout: string, stderr: string) => {
34-
if (error) { console.error(error); }
35-
else {
36-
if (diag && doc) { this.BOXdiag(conf, diag, doc); }
37-
console.log(stderr, stdout);
38-
}
39-
};
40-
if (process.platform === 'win32') {
41-
if (more) { command = "copy/Y ..\\boxasm.bat boxasm.bat & " + command; }
42-
if (doc) { command = 'del/Q T*.* & copy "' + doc.fileName + '" "T.ASM" & ' + command; }
43-
exec(command + boxcommand, { cwd: conf.workpath, shell: 'cmd.exe' }, callback);
44-
}
45-
else {
46-
if (more) { command = "cp ../boxasm.bat ./; " + command; }
47-
if (doc) { command = 'rm -f [Tt]*.*;cp "' + doc.fileName + '" T.ASM;' + command; }
48-
exec(command + boxcommand, { cwd: conf.workpath }, callback);
7+
/**
8+
* A function used when using boxasm.bat
9+
* @param conf The config information
10+
* @param runOrDebug true for run ASM code,false for debug
11+
* @param doc the source ASM file
12+
* @param diag using its `diag.ErrMsgProcess` to process the assembler's output
13+
*/
14+
export function runDosbox2(conf: Config, runOrDebug: boolean, doc: TextDocument, diag: AssemblerDiag) {
15+
let fs = workspace.fs;
16+
let src: Uri = Uri.joinPath(conf.extScriptsUri, "./boxasm.bat");
17+
let target: Uri = Uri.joinPath(conf.toolsUri, "./boxasm.bat");
18+
fs.copy(src, target, { overwrite: conf.toolsBuiltin }).then(
19+
() => {
20+
runDosbox(conf, conf.boxasmCommand(runOrDebug), doc).then(
21+
(stdout) => { BOXdiag(conf, diag, doc); }
22+
);
23+
},
24+
(reason) => {
25+
console.log(reason);
26+
runDosbox(conf, conf.boxasmCommand(runOrDebug), doc).then(
27+
(stdout) => { BOXdiag(conf, diag, doc); }
28+
);
4929
}
50-
}
51-
public BoxOpenCurrentFolder(conf: Config, doc: TextDocument) {
52-
let folderpath: string = Uri.joinPath(doc.uri, '../').fsPath;
53-
let Ecmd: string = '-noautoexec -c "mount e \\\"' + folderpath + '\\\"" -c "mount c \\\"' + conf.path + '\\\"" -c "set PATH=%%PATH%%;c:\\masm;c:\\tasm" -c "e:"';
54-
let command = conf.OpenDosbox + ' -conf "' + conf.dosboxconfuri.fsPath + '" ';
30+
);
31+
}
32+
/**open dosbox and do things about it
33+
* @param conf The config information
34+
* @param more The commands needed to exec in dosbox
35+
* @param doc If defined, copy this file to workspace as T.xxx(xxx is the files extension)
36+
*/
37+
export function runDosbox(conf: Config, more?: string, doc?: TextDocument): Promise<string> {
38+
let filename = doc?.fileName;
39+
let fileext = filename?.substring(filename.lastIndexOf("."), filename.length);
40+
let preCommand: string = "";
41+
let boxcmd: string = '@echo off\n';
42+
boxcmd += `mount c \\\"${conf.path}\\\"\nmount d \\\"${conf.workpath}\\\"\n`;//mount the necessary path
43+
boxcmd += "d:\nset PATH=%%PATH%%;c:\\tasm;c:\\masm\n";//switch to the working space and add path\
44+
if (doc) {
45+
boxcmd += `echo Your file has been copied as D:\\T${fileext}\n`;
5546
if (process.platform === 'win32') {
56-
exec(command + Ecmd, { cwd: conf.workpath, shell: 'cmd.exe' });
47+
preCommand = `del/Q T*.* & copy "${filename}" "T${fileext}" & `;
5748
}
5849
else {
59-
exec(command + Ecmd, { cwd: conf.workpath });
50+
preCommand = `rm -f [Tt]*.*;cp "${filename}" T${fileext};'`;
6051
}
61-
52+
};
53+
boxcmd += "@echo on";
54+
if (more) { boxcmd += "\n" + more; }//add extra commands
55+
let opt: OPTS = {
56+
cwd: conf.workpath,
57+
preOpen: preCommand,
58+
core: conf.OpenDosbox,
59+
boxcmd: boxcmd,
60+
parameter: ' -conf "' + conf.dosboxconfuri.fsPath + '" '
61+
};
62+
return openDosbox(opt);
63+
}
64+
export function BoxOpenCurrentFolder(conf: Config, doc: TextDocument) {
65+
let folderpath: string = Uri.joinPath(doc.uri, '../').fsPath;
66+
let opt: OPTS = {
67+
cwd: conf.workpath,
68+
core: conf.OpenDosbox,
69+
boxcmd: `mount e \\\"${folderpath}\\\"\nmount c \\\"${conf.path}\\\"\nset PATH=%%PATH%%;c:\\masm;c:\\tasm\ne:`,
70+
parameter: ' -conf "' + conf.dosboxconfuri.fsPath + '" '
71+
};
72+
openDosbox(opt);
73+
}
74+
interface OPTS {
75+
cwd: string,
76+
core: string
77+
preOpen?: string,
78+
parameter?: string,
79+
boxcmd?: string
80+
}
81+
function openDosbox(opt: OPTS): Promise<string> {
82+
let str = opt.core + opt.parameter;
83+
if (opt.preOpen) {
84+
str = opt.preOpen + str;
6285
}
63-
private BOXdiag(conf: Config, diag: AssemblerDiag, doc: TextDocument): string {
64-
let info: string = ' ', content: string;
65-
let document = doc;
66-
if (document) {
67-
content = document.getText();
68-
workspace.fs.readFile(conf.workloguri).then(
69-
(text) => {
70-
info = text.toString();
71-
if (diag.ErrMsgProcess(content, info, doc.uri, conf.MASMorTASM) === 0) {
72-
let Errmsgwindow = localize("dosbox.errmsg", '{0} Failed to compile. See the output for more information', conf.MASMorTASM);
73-
window.showErrorMessage(Errmsgwindow);
74-
}
75-
},
76-
() => { console.error('read dosbox mode T.txt FAILED'); }
77-
);
86+
if (opt.boxcmd) {
87+
let cmd = opt.boxcmd.replace(/\n/g, '" -c "');
88+
cmd = '-c "' + cmd + '"';
89+
str += cmd;
90+
}
91+
let execOption: ExecOptions;
92+
if (process.platform === 'win32') {
93+
execOption = { cwd: opt.cwd, shell: 'cmd.exe' };
94+
}
95+
else {
96+
execOption = { cwd: opt.cwd };
97+
}
98+
return new Promise(
99+
(resolve, reject) => {
100+
exec(str, execOption, (error: any, stdout: string, stderr: string) => {
101+
if (error) {
102+
reject(error);
103+
}
104+
else {
105+
resolve(stdout);
106+
}
107+
});
78108
}
79-
return info;
109+
);
110+
}
111+
function BOXdiag(conf: Config, diag: AssemblerDiag, doc: TextDocument): string {
112+
let info: string = ' ', content: string;
113+
if (doc) {
114+
content = doc.getText();
115+
workspace.fs.readFile(conf.workloguri).then(
116+
(text) => {
117+
info = text.toString();
118+
if (diag.ErrMsgProcess(content, info, doc.uri, conf.MASMorTASM) === 0) {
119+
let Errmsgwindow = localize("dosbox.errmsg", '{0} Failed to compile. See the output for more information', conf.MASMorTASM);
120+
window.showErrorMessage(Errmsgwindow);
121+
}
122+
},
123+
() => { console.error('read dosbox mode T.txt FAILED'); }
124+
);
80125
}
126+
return info;
81127
}
82128

83129

0 commit comments

Comments
 (0)