Skip to content

Commit f0677bd

Browse files
committed
add programmatic language support
outline,hover,jump2definition Merge branch 'next' into master
2 parents afe4ce3 + 7b8a61b commit f0677bd

File tree

13 files changed

+416
-197
lines changed

13 files changed

+416
-197
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ All notable changes to the "masm-tasm" extension will be documented in this file
88
- [ ] 问题匹配功能完善
99
- [ ] hover的简单实现:如中断的简单信息
1010
- [ ] LSP和DAP支持(目前对我来说太难了)
11+
- [ ] 根据具体的AH值显示跳转到不同的信息
12+
13+
### 0.1.5
14+
15+
- [x] DOS 汇编基本的语法支持
16+
- [x] vscode 界面的大纲视图的简单实现
17+
18+
汇编语言支持的symbol大概有以下几种,但是vscode的[SymbolKind](https://code.visualstudio.com/api/references/vscode-api#SymbolKind)却与它们不对应,我决定做以下对应
19+
20+
|assembly symbol|vscode symbol|
21+
|---|---|
22+
|macro|Module|
23+
|segment|Class|
24+
|procedure|Function|
25+
|struct|Struct|
26+
|label|Key|
27+
|variable|Variable|
1128

1229
### 0.1.4
1330

README.md

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
# run and debug TASM and MASM via dosbox(and msdos-player)
1+
# DOS assembly (MASM/TASM) via DOSBox(and msdos-player)
22

33
[中文](https://github.com/xsro/masm-tasm/blob/master/doc/README_zh.md)
44

5-
This extension is modified from "[masm-code](https://github.com/Woodykaixa/masm-code)", focusing on the interaction with DOS emulator (DOSBox and msdos-player). It is helpful for you to study MASM, TASM and also the course <*principles& peripheral technology of microprocessor*>.
5+
Language support for DOS assembly,suitable for studying MASM/TASM and the course <*principles& peripheral technology of microprocessor*>.
66

7-
- Support both **TASM and MASM**: you can choose MASM or TASM in the preference
8-
- **Editor Menu**: run and debug with right click on the VSCode editor panel
9-
- **Convenient**: related tools packaged in the extension. Just install and right click (recommand to use this ext in windows otherwise you should install dosbox first)
7+
- Offer *grammar*,basic *outline* view and *hover* support for DOS assembly language
8+
- Support both **TASM and MASM** assembler tools: choose MASM or TASM in the preference
9+
- In **Editor Menu**: run and debug assembly with right click on the VSCode editor panel
10+
- **Convenient**: related tools packaged in the extension. Just install and right click
1011
- **Diagnose**: process the output of ASM tools and ouput them in VSCode
11-
- Welcome [issue](https://github.com/xsro/masm-tasm/issues) and PR to build a better extension with your help.
12-
- Some interesting code your may need:[masm-tasm wiki](https://github.com/xsro/masm-tasm/wiki/dosbox)
12+
- **Note**: Currently not support multi files assembly
1313

14-
Thanks to [Roncho](https://marketplace.visualstudio.com/publishers/Roncho)'s extension [Assembly (TASM)](https://marketplace.visualstudio.com/items?itemName=Roncho.assembly-8086). This extension now support assembly language using codes from it.
15-
Also, this extension may also work with extensions like: [MASM](https://marketplace.visualstudio.com/items?itemName=bltg-team.masm)[masm-code](https://marketplace.visualstudio.com/items?itemName=kaixa.masm-code)[x86 and x86_64 Assembly](https://marketplace.visualstudio.com/items?itemName=13xforever.language-x86-64-assembly)
14+
Thanks to [Roncho](https://marketplace.visualstudio.com/publishers/Roncho) 's extension [Assembly (TASM)](https://marketplace.visualstudio.com/items?itemName=Roncho.assembly-8086) and [Woodykaixa](https://github.com/Woodykaixa)'s [masm-code](https://github.com/Woodykaixa/masm-code). Welcome [issue](https://github.com/xsro/masm-tasm/issues) and PR to build a better extension with your help.Here are some interesting code I use:[masm-tasm wiki](https://github.com/xsro/masm-tasm/wiki/dosbox)
1615

1716
## Features
1817

19-
when your are editing `.asm(.ASM)` files ,you can right click at the editor panel,then you will see several choices listed below:
18+
when you are editing `assembly` files ,you can right click at the editor panel,then you will see several choices listed below:
2019

21-
1. "Open dosbox": Open the dosbox. Copy current file to workspace as `D:\T.asm` in DOSBox. You can use command like `tasm T.asm` .[more info](https://github.com/xsro/masm-tasm/blob/master/doc/ASM_commands.md)
20+
1. "Open dosbox": Open the dosbox, prepare the environment(copy file to dosbox's D:\ and add tools to path),[more info](https://github.com/xsro/masm-tasm/blob/master/doc/ASM_commands.md)
2221
2. "Run ASM code": Compile and Run the program
2322
3. "Debug ASM code": Compile and Debug the program
2423

@@ -40,12 +39,41 @@ your file will be copied as `D:\T.ASM` in DOSBox. (The extension will copy your
4039

4140
![diagnose](https://github.com/xsro/masm-tasm/raw/master/pics/demo_diagnose_tasm.gif)
4241

42+
## Extension Settings
43+
44+
for more,please see the `preference->settings`
45+
46+
- `masmtasm.ASM.MASMorTASM` use `MASM` or `TASM` assembler in DOS emulator to run and debug assembly
47+
- `masmtasm.ASM.emulator` use dosbox or msdos-player as DOS emulator,defalut is DOSBox
48+
- `DOSBox` more stable
49+
- `msdos-player`quiet, it runs in command prompt(CMD). So it cannot support GUI like `TD.exe`
50+
- `auto` auto select
51+
1. use msdos-player to compile and link
52+
2. use DOSBox to run
53+
3. use msdos-player for MASM(debug)
54+
4. use DOSBox for TASM(TD)
55+
- `masmtasm.ASM.savefirst` save file first before using
56+
- `masmtasm.ASM.toolspath` custom path of your ASM tools. [more info](#about-tools)
57+
- `masmtasm.dosbox.CustomResolution`: size(resolution) of the dosbox window,for example `1024x960`
58+
59+
### About Tools
60+
61+
The assembler MASM and TASM can only run in 16-bit environment. So the extension use DOSBox and MSDOS-player to emulate the 16-bit environment.
62+
the extension has built in tools for windows. But if you need to use assembler or emulator of different version. You can oragnize your tools follow the structure bellow and add the you folder's path to `masmtasm.ASM.toolspath`
63+
64+
- tools:your tools folder name, you can add the path of it to settings `masmtasm.ASM.toolspath`
65+
1. `TASM`: TASM tools including `tasm.exe`,`tlink.exe`,`td.exe`
66+
2. `MASM`: MASM tools including `masm.exe`,`link.exe`,`debug.exe`
67+
3. `dosbox`: dosbox.exe and related files
68+
4. `player`: msdos.exe
69+
70+
Linux and other OS user do not need folder dosbox and player. Instead, we should make sure DOSBox can be opened by shell command `dosbox` (node: child_process.exec("dosbox"))
71+
4372
## Docs & Thanks & Licenses
4473

4574
- this extension is [MIT license](https://github.com/xsro/masm-tasm/blob/master/LICENSE).
46-
- thanks for [masm-code](https://github.com/Woodykaixa/masm-code),[msdos player](http://takeda-toshiya.my.coocan.jp/msdos),[dosbox](https://www.dosbox.com)
47-
- their [info and licences](https://github.com/xsro/masm-tasm/blob/master/doc/license_and_info.md)
48-
- [about the tools](https://github.com/xsro/masm-tasm/blob/master/doc/Toolspath.md)
75+
- thanks for [Roncho](https://marketplace.visualstudio.com/publishers/Roncho)'s [Assembly (TASM)](https://marketplace.visualstudio.com/items?itemName=Roncho.assembly-8086),[Woodykaixa](https://github.com/Woodykaixa)'s [masm-code](https://github.com/Woodykaixa/masm-code),[msdos player](http://takeda-toshiya.my.coocan.jp/msdos),[dosbox](https://www.dosbox.com)
76+
- [about the assembly and emulator tools](https://github.com/xsro/masm-tasm/blob/master/doc/Toolspath.md)
4977
- [some infomation :wiki](https://github.com/xsro/masm-tasm/wiki)
5078

5179
Enjoy!:smile:

doc/README_zh.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
1. 同时支持调用**TASM****MASM**: 可以在设置(首选项)中修改使用MASM还是TASM工具集
66
2. 提供编辑器**右键菜单**:在汇编语言的编辑器添加了“打开dosbox,运行,调试”的三个选项
77
3. 提供diagnose**问题输出**功能:假如汇编未通过,会标明错误信息与位置,可以在命令面板输入`清除MASM/TASM的所有问题信息`清除本插件输出的diagnose问题信息
8-
4. 调用[dosbox](https://www.dosbox.com)[msdos player](http://takeda-toshiya.my.coocan.jp/msdos)模拟16位系统环境,运行相关组件
9-
5. 通过 [Roncho](https://marketplace.visualstudio.com/publishers/Roncho)'s extension [Assembly (TASM)](https://marketplace.visualstudio.com/items?itemName=Roncho.assembly-8086)的代码来实现语法支持
8+
4. 提供悬浮提示,跳转定义
9+
5. 调用[dosbox](https://www.dosbox.com)[msdos player](http://takeda-toshiya.my.coocan.jp/msdos)模拟16位系统环境,运行相关组件
1010

11-
非常感谢以上软件!插件难免会有一些bug,欢迎到github发[issue](https://github.com/xsro/masm-tasm/issues)以及PR,大家一起交流和完善。
11+
非常感谢[Roncho](https://marketplace.visualstudio.com/publishers/Roncho)[Assembly (TASM)](https://marketplace.visualstudio.com/items?itemName=Roncho.assembly-8086)[Woodykaixa](https://github.com/Woodykaixa)[masm-code](https://github.com/Woodykaixa/masm-code)!插件难免会有一些bug,欢迎到github发[issue](https://github.com/xsro/masm-tasm/issues)以及PR,大家一起交流和完善。
1212

1313
## 安装使用
1414

1515
- windows 无需其他操作,相关软件已打包在插件之中
16-
- linux 请先安装dosbox [详情](https://github.com/xsro/masm-tasm/blob/master/doc/Get_start.md#linux)
16+
- linux 请先安装dosbox [详情](doc/Get_start.md#linux)
1717

1818
## Features主要功能
1919

2020
当编辑器为汇编文件时,在编辑器界面右键菜单中会提供以下三个选项:
2121

22-
1. 打开dosbox并配置环境(挂载):打开DOSBox,然后就可以手动在打开的DOSBox窗口进行[汇编相关操作](https://github.com/xsro/masm-tasm/blob/master/doc/ASM_commands.md)
22+
1. 打开dosbox并配置环境(挂载):打开DOSBox,然后就可以手动在打开的DOSBox窗口进行[汇编相关操作](doc/ASM_commands.md)
2323
2. 运行当前程序(汇编+链接+运行):生成exe程序并运行
2424
3. 调试当前程序(汇编+链接+调试):生成exe程序并调试,使用MASM则会调用debug调试,使用TASM会调用td调试
2525

@@ -43,7 +43,6 @@
4343

4444
## Some Tips 一些相关信息
4545

46-
- 这个插件专注于汇编的编译运行调试环节,推荐结合汇编语法支持(高亮、代码片段等)的插件一起使用,如:[MASM](https://marketplace.visualstudio.com/items?itemName=bltg-team.masm)[TASM](https://marketplace.visualstudio.com/items?itemName=Roncho.assembly-8086)[masm-code](https://marketplace.visualstudio.com/items?itemName=kaixa.masm-code)[x86 and x86_64 Assembly](https://marketplace.visualstudio.com/items?itemName=13xforever.language-x86-64-assembly)等。
4746
- 一些有趣的汇编代码: [dosbox codes](https://github.com/xsro/masm-tasm/wiki/dosbox#写代码)
4847
- 使用终端任务调用dosbox:[VSC-ASMtasks](https://github.com/xsro/VSC-ASMtasks)
4948

@@ -63,13 +62,13 @@
6362
- 调整dosbox窗口大小
6463
- 规定dosbox运行程序之后进行什么操作(是否直接退出程序,还是等待)
6564
- 启动相关功能之前是否先保存文件(不保存的话,只能操作之前保存的版本,建议保存)
66-
- 设置自定义汇编工具路径,详见:[自定义汇编工具路径](https://github.com/xsro/masm-tasm/blob/master/doc/Toolspath.md#自定义汇编工具路径)
65+
- 设置自定义汇编工具路径,详见:[自定义汇编工具路径](doc/Toolspath.md#自定义汇编工具路径)
6766

6867
### 文档 & 感谢 & 许可
6968

70-
- 这个插件是[MIT license](https://github.com/xsro/masm-tasm/blob/master/LICENSE).
69+
- 这个插件是[MIT license](LICENSE).
7170
- 感谢[masm-code](https://github.com/Woodykaixa/masm-code),[msdos player](http://takeda-toshiya.my.coocan.jp/msdos),[dosbox](https://www.dosbox.com)
72-
- 他们的[相关信息](https://github.com/xsro/masm-tasm/blob/master/doc/license_and_info.md)
71+
- 他们的[相关信息](doc/license_and_info.md)
7372
- [一些相关资料:wiki](https://github.com/xsro/VSC-ASMtasks/wiki)
7473

7574
Enjoy!:smile:

package.json

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "masm-tasm",
3-
"displayName": "MASM/TASM via DOSBox",
3+
"displayName": "MASM/TASM",
44
"publisher": "xsro",
5-
"description": "Run and Debug MASM/TASM code in DOSBox with right click in the editor of assembly codes",
6-
"version": "0.1.4",
5+
"description": "DOS汇编语言开发环境和语法支持,安装即用,自带DOSBox.exe和TASM/MASM工具",
6+
"version": "0.2.0",
77
"keywords":["dosbox","16位","汇编","微机原理","tasm","masm"],
88
"icon":"dosboxasm.png",
99
"engines": {
@@ -32,16 +32,20 @@
3232
{
3333
"id": "assembly",
3434
"aliases": [
35-
"Assembly (TASM)",
36-
"assembly",
37-
"TASM"
35+
"assembly(DOS)"
3836
],
3937
"extensions": [
4038
".asm"
4139
],
4240
"configuration": "./language-configuration.json"
4341
}
4442
],
43+
"snippets": [
44+
{
45+
"language": "assembly",
46+
"path": "./snippets.json"
47+
}
48+
],
4549
"grammars": [
4650
{
4751
"language": "assembly",
@@ -52,17 +56,17 @@
5256
"menus": {
5357
"editor/context": [
5458
{
55-
"when": "resourceExtname == .ASM || resourceExtname == .asm && editorFocus",
59+
"when": "resourceLangId == assembly && editorFocus",
5660
"command": "masm-tasm.opendosbox",
5761
"group": "0_MASM-TASM@1"
5862
},
5963
{
60-
"when": "resourceExtname == .ASM || resourceExtname == .asm && editorFocus",
64+
"when": "resourceLangId == assembly && editorFocus",
6165
"command": "masm-tasm.runASM",
6266
"group": "0_MASM-TASM@2"
6367
},
6468
{
65-
"when": "resourceExtname == .ASM || resourceExtname == .asm && editorFocus",
69+
"when": "resourceLangId == assembly && editorFocus",
6670
"command": "masm-tasm.debugASM",
6771
"group": "0_MASM-TASM@3"
6872
}
@@ -120,15 +124,10 @@
120124
"default": true,
121125
"description": "%dosasm.config.savefirst%"
122126
},
123-
"masmtasm.language.hover":{
127+
"masmtasm.language.programmaticFeatures":{
124128
"type":"boolean",
125129
"default":true,
126-
"description": "hover for test,need restart to apply changes"
127-
},
128-
"masmtasm.language.CompletionItem":{
129-
"type":"boolean",
130-
"default":false,
131-
"description": "autocomplet for test,need restart to apply changes"
130+
"description": "experimental programmatic features like hover,outline,jump to definition. You can close them by choosing false"
132131
},
133132
"masmtasm.dosbox.run": {
134133
"type": "string",

snippets.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"Macro":{
3+
"prefix":"macro",
4+
"body":[
5+
"${1:name} MACRO ${2:params}",
6+
"\t$0",
7+
"ENDM"
8+
]
9+
},
10+
"Procedure":{
11+
"prefix":"proc",
12+
"body":[
13+
";${2:description}",
14+
"${1:name} PROC",
15+
"\t$0",
16+
"${1:name} ENDP"
17+
]
18+
},
19+
"Segment":{
20+
"prefix":"segment",
21+
"body":[
22+
";${2:description}",
23+
"${1:name} SEGMENT USE16",
24+
"\t$0",
25+
"${1:name} ENDS"
26+
]
27+
},
28+
"DOS print Char":{
29+
"prefix":"cprint",
30+
"body":[
31+
"MOV DL, '${1:char}'",
32+
"MOV AH, 2H",
33+
"INT 21H"
34+
],
35+
"description":"Prints a charcters"
36+
},
37+
"helloworld":{
38+
"prefix":"helloword",
39+
"body":[
40+
".386",
41+
"DATA SEGMENT USE16",
42+
"${1:MESG DB 'Hello word','$'}",
43+
"DATA ENDS",
44+
"CODE SEGMENT USE16",
45+
"\tASSUME CS:CODE,DS:DATA",
46+
"BEG:",
47+
"\tMOV AX,DATA",
48+
"\tMOV DS,AX",
49+
"${2:\tMOV AH,9\n\tMOV DX, OFFSET MESG\n\tINT 21H}",
50+
"\tMOV AH,4CH",
51+
"\tINT 21H;back to dos",
52+
"CODE ENDS",
53+
"END BEG"
54+
],
55+
"description":"HELLO WORD assembly sample"
56+
}
57+
}

src/DOSBox.ts

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Uri,workspace, window} from 'vscode'
1+
import { Uri,workspace, window, TextDocument} from 'vscode'
22

33
import { Config } from './configration'
44
import { execSync} from 'child_process'
5-
import { landiagnose } from './diagnose'
5+
import { landiagnose } from './language/diagnose'
66
export class DOSBox{
77
constructor(){
88
}
@@ -12,52 +12,41 @@ export class DOSBox{
1212
* @param fileuri 清理工作文件夹,复制该文件到工作文件夹,假如没有那么就不处理
1313
* @param diag 如果有则诊断输出信息
1414
*/
15-
public openDOSBox(conf:Config,more?:string,fileuri?:Uri,diag?:landiagnose) {
15+
public openDOSBox(conf:Config,more?:string,doc?:TextDocument,diag?:landiagnose) {
1616
let boxcommand=' '
1717
if(more){
1818
let boxparam=more.replace(/\n/g,'"-c "')
1919
boxcommand='-c "'+boxparam+'"'
2020
}
2121
if(process.platform=='win32'){
2222
let wincommand='start/min/wait "" "'+conf.path+'/dosbox/dosbox.exe" -conf "'+conf.dosboxconfuri.fsPath+'" '
23-
if(fileuri) wincommand='del/Q T*.* & copy "'+fileuri.fsPath+'" "T.ASM" & '+wincommand
23+
if(doc) wincommand='del/Q T*.* & copy "'+doc.fileName+'" "T.ASM" & '+wincommand
2424
execSync(wincommand+boxcommand,{cwd:conf.workpath,shell:'cmd.exe'})
25-
console.log(wincommand+boxcommand)
2625
}
2726
else{
2827
let linuxcommand='dosbox -conf "'+conf.dosboxconfuri.fsPath+'" '
29-
if(fileuri) linuxcommand='rm -f [Tt]*.*;cp "'+fileuri.fsPath+'" T.ASM;'+linuxcommand
30-
console.log(linuxcommand+boxcommand)
28+
if(doc) linuxcommand='rm -f [Tt]*.*;cp "'+doc.fileName+'" T.ASM;'+linuxcommand
3129
execSync(linuxcommand+boxcommand,{cwd:conf.workpath})
3230

3331
}
34-
if(diag) this.BOXdiag(conf,diag)
32+
if(diag && doc) this.BOXdiag(conf,diag,doc)
3533
}
36-
private BOXdiag(conf:Config,diag:landiagnose):string{
37-
let info:string=' ',content
38-
let turi=window.activeTextEditor?.document.uri
39-
let texturi:Uri
40-
if (turi) {
41-
texturi=turi
34+
private BOXdiag(conf:Config,diag:landiagnose,doc:TextDocument):string{
35+
let info:string=' ',content:string
36+
let document=doc
37+
if (document) {
38+
content=document.getText()
4239
workspace.fs.readFile(conf.workloguri).then(
4340
(text)=>{
4441
info=text.toString()
45-
workspace.fs.readFile(texturi).then(
46-
(text)=>{
47-
content=text.toString()
48-
if(diag.ErrMsgProcess(content,info,texturi,conf.MASMorTASM)==0){
49-
let Errmsgwindow=conf.MASMorTASM+'汇编出错,无法运行/调试'
50-
window.showErrorMessage(Errmsgwindow);
51-
}
52-
}
53-
)
54-
},
42+
if(diag.ErrMsgProcess(content,info,doc.uri,conf.MASMorTASM)==0){
43+
let Errmsgwindow=conf.MASMorTASM+'汇编出错,无法运行/调试'
44+
window.showErrorMessage(Errmsgwindow);
45+
}},
5546
()=>{console.error('read dosbox mode T.txt FAILED')}
5647
)}
5748
return info
5849
}
59-
60-
6150
}
6251

6352

0 commit comments

Comments
 (0)