Skip to content

Commit 13e261b

Browse files
committed
side project is not funny
1 parent 90a10a0 commit 13e261b

File tree

7 files changed

+177
-40
lines changed

7 files changed

+177
-40
lines changed

masm-tasm/.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"outFiles": [
1818
"${workspaceFolder}/dist/**/*.js"
1919
],
20-
"preLaunchTask": "${defaultBuildTask}"
20+
"preLaunchTask": "npm: compile-web"
2121
},
2222
{
2323
"name": "Run Web Extension ",

masm-tasm/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@
251251
"default": true,
252252
"description": "%config.savefirst%"
253253
},
254+
"masmtasm.jsdos.ignore": {
255+
"type": "array",
256+
"items": {
257+
"type": "string"
258+
},
259+
"default": [
260+
"\\.git",
261+
"\\.vscode",
262+
"node_modules"
263+
]
264+
},
254265
"masmtasm.language.programmaticFeatures": {
255266
"type": "boolean",
256267
"default": true,

masm-tasm/resources/t/.jsdos/dosbox.conf

Whitespace-only changes.

masm-tasm/src/emulators/bundle.ts

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//methods for manipute jsdos-bundles
2+
import * as JSZip from "jszip";
3+
import * as vscode from "vscode";
4+
5+
const fs = vscode.workspace.fs;
6+
7+
export interface MountFs{
8+
type:"fs";
9+
dir: vscode.Uri;
10+
disk: string
11+
watch?:boolean
12+
}
13+
14+
export interface MountZip{
15+
type:"zip";
16+
zip:JSZip|Uint8Array;
17+
root:string;
18+
disk:string;
19+
}
20+
21+
export type MountOption=MountFs|MountZip
22+
23+
export interface CreateBundleOptions {
24+
sample?: string;
25+
boxConf?: string;
26+
mount?: MountOption[];
27+
}
28+
29+
// Copy function
30+
async function copyDirectory(sourceZip: JSZip, sourceDir: string, targetZip: JSZip, targetDir: string) {
31+
// Iterate through all files in the source JSZip
32+
for (const [relativePath, file] of Object.entries(sourceZip.files)){
33+
if (relativePath.startsWith(sourceDir)) {
34+
// Calculate the relative path of the target file
35+
const newRelativePath = relativePath.replace(sourceDir, targetDir);
36+
// If it's a directory, create a corresponding directory in the target JSZip
37+
if (file.dir) {
38+
targetZip.folder(newRelativePath);
39+
} else {
40+
// If it's a file, read the file content and create the same file in the target JSZip
41+
const content=await file.async('uint8array')
42+
targetZip.file(newRelativePath, content);
43+
}
44+
}
45+
}
46+
return targetZip;
47+
}
48+
49+
/**create a jsdos bundle file by add new files to the sample.
50+
* powered by https://stuk.github.io/jszip/
51+
*/
52+
export async function createBundle({
53+
sample,
54+
boxConf,
55+
mount,
56+
}: CreateBundleOptions): Promise<JSZip> {
57+
const zip = new JSZip();
58+
if (sample) {
59+
const zipdata = await fs.readFile(vscode.Uri.file(sample));
60+
await zip.loadAsync(zipdata);
61+
}
62+
63+
zip.file(".jsdos/dosbox.conf", boxConf ? boxConf : "");
64+
65+
if (mount) {
66+
for (const m of mount) {
67+
if(m.type==="fs"){
68+
await allFiles(m.dir, async (uri: vscode.Uri) => {
69+
const arr = await fs.readFile(uri);
70+
const dst =
71+
m.disk + uri.path.replace(m.dir.path, "");///home/web_user
72+
zip.file(dst, arr);
73+
});
74+
}
75+
if (m.type==="zip"){
76+
if(m.zip instanceof Uint8Array){
77+
const source=await JSZip.loadAsync(m.zip)
78+
await copyDirectory(source,m.root,zip,m.disk)
79+
}else if(m.zip instanceof JSZip){
80+
await copyDirectory(m.zip,m.root,zip,m.disk)
81+
}
82+
}
83+
}
84+
}
85+
86+
return zip;
87+
}
88+
89+
async function allFiles(
90+
dir: vscode.Uri,
91+
callback: (file: vscode.Uri) => Promise<void>
92+
) {
93+
const dirs = await fs.readDirectory(dir);
94+
const r: string[] | undefined = vscode.workspace
95+
.getConfiguration("masmtasm")
96+
.get("jsdos.ignore");
97+
const regs = r ? r.map((val) => new RegExp(val)) : [/\.git/, /\.vscode/];
98+
for (const [term, type] of dirs) {
99+
const uri = vscode.Uri.joinPath(dir, term);
100+
if (regs.some((val) => term.match(val))) {
101+
continue;
102+
}
103+
if (type === vscode.FileType.File) {
104+
await callback(uri);
105+
} else if (type === vscode.FileType.Directory) {
106+
await allFiles(uri, callback);
107+
}
108+
}
109+
}

masm-tasm/src/emulators/jsdos-ci.ts

+28-18
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class JsdosTerminal implements vscode.Pseudoterminal {
3030
this.writeEmitter.fire('\x1b[31mJSDos\x1b[0m\r\nhello');
3131
}
3232
close(): void {
33-
this.ci.exit();
33+
// this.ci.exit();
3434
}
3535
input = "";
3636
handleInput?(data: string): void {
@@ -66,20 +66,24 @@ function getWebviewContent(webview: vscode.Webview, extensionUri: vscode.Uri) {
6666

6767

6868
class Manager {
69-
ci: CommandInterface | undefined = undefined;
69+
hasCi: {ci: CommandInterface|undefined}={ci:undefined};
7070
terminal:vscode.Terminal|undefined=undefined;
71-
updateci(ci: CommandInterface) {
72-
const bar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
73-
bar.command = 'masmtasm.emulatorStatus';
74-
bar.text = `jsdos`;
75-
bar.show();
71+
shell:utils.Shell|undefined=undefined;
72+
bar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
73+
updateci(hasCi:{ci: CommandInterface}) {
74+
this.bar.command = 'masmtasm.emulatorStatus';
75+
this.bar.text = `jsdos`;
76+
this.bar.show();
77+
this.bar.color=new vscode.ThemeColor("activityBar.activeBackground")
7678

77-
this.ci = ci;
78-
const pty = new JsdosTerminal(this.ci);
79+
this.hasCi = hasCi;
80+
const pty = new JsdosTerminal(hasCi.ci);
7981
this.terminal=vscode.window.createTerminal({ name: "jsdos", pty, });
82+
this.shell=pty.shell
8083
}
8184
webview(context:vscode.ExtensionContext) {
82-
if (this.ci) {
85+
let ci=this.hasCi.ci;
86+
if (ci) {
8387
const panel = vscode.window.createWebviewPanel(
8488
"jsdos",
8589
"jsdos panel",
@@ -95,10 +99,10 @@ class Manager {
9599

96100
panel.webview.postMessage({
97101
command: "ci",
98-
width: this.ci?.width(),
99-
height: this.ci?.height()
102+
width: ci?.width(),
103+
height: ci?.height()
100104
});
101-
this.ci?.events().onFrame((rgb, rgba) => {
105+
ci?.events().onFrame((rgb, rgba) => {
102106
panel.webview.postMessage({
103107
command: 'rgb',
104108
time: new Date().getTime(),
@@ -114,13 +118,13 @@ class Manager {
114118
return;
115119
case 'keyup':
116120
const up = utils.htmlKey2jsdos(message.code);
117-
if (up && this.ci)
118-
this.ci.sendKeyEvent(up, false);
121+
if (up && ci)
122+
ci.sendKeyEvent(up, false);
119123
return;
120124
case 'keydown':
121125
const down = utils.htmlKey2jsdos(message.code);
122-
if (down && this.ci)
123-
this.ci.sendKeyEvent(down, true);
126+
if (down && ci)
127+
ci.sendKeyEvent(down, true);
124128
return;
125129
}
126130
},
@@ -137,7 +141,7 @@ export const manager=new Manager();
137141

138142
export function activate(context: vscode.ExtensionContext): void {
139143
async function statusBarCommand() {
140-
const items = ["show jsdos view", "show terminal"];
144+
const items = ["show jsdos view", "show terminal","exit"];
141145

142146
const placeHolder = 'manipulate emulator';
143147
const seleted = await vscode.window.showQuickPick(items, { placeHolder });
@@ -147,6 +151,12 @@ export function activate(context: vscode.ExtensionContext): void {
147151
if(seleted===items[1]){
148152
manager.terminal?.show();
149153
}
154+
if(seleted===items[2]){
155+
manager.hasCi.ci?.exit()
156+
manager.hasCi.ci=undefined
157+
manager.bar.hide()
158+
manager.terminal?.hide()
159+
}
150160
}
151161
const disposable = vscode.commands.registerCommand('masmtasm.emulatorStatus', statusBarCommand);
152162
context.subscriptions.push(disposable);

masm-tasm/src/emulators/jsdos.ts

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
import { ExtensionContext, ExtensionMode, Uri } from "vscode";
2+
import * as vscode from "vscode"
23
import { ActionContext, AsmResult, ExecAction } from "../ASM/manager";
34
import { DosEmulatorType } from "../utils/configuration";
45
import { CommandInterface, getEmulators,platform } from "emulators";
56
import { manager } from "./jsdos-ci";
7+
import { createBundle } from "./bundle";
8+
import { XhrOptions } from "emulators/dist/out/impl/http";
9+
610
platform.current.node_require=function(url:string){
711
return __non_webpack_require__(url);
812
};
9-
10-
const TEST_STRING="XDRGS";
11-
const config={
12-
dosboxConf: `[autoexec]
13-
echo ${TEST_STRING}
14-
`,
15-
jsdosConf: {
16-
version: "",
17-
},
18-
};
19-
20-
13+
const request=platform.current.httpRequest
14+
platform.current.httpRequest=function(url:string,options:XhrOptions){
15+
return request(url,options)
16+
}
2117

2218
class JsdosRuntime{
2319
emulators;
2420
ci:CommandInterface|undefined;
2521
constructor(pathprefix:string){
2622
this.emulators=getEmulators(pathprefix);
27-
const a=__non_webpack_require__(pathprefix+"wdosbox.js");
28-
console.log(a);
2923
}
30-
async run(){
31-
this.ci=await this.emulators.dosboxDirect(config,);
24+
async run(FS:Uint8Array){
25+
this.ci=await this.emulators.dosboxDirect(FS,);
3226
}
3327
}
3428

@@ -44,10 +38,25 @@ export class JSDosHost implements ExecAction{
4438
}else{
4539
throw new Error("not implemented");
4640
}
47-
await runtime.run();
48-
if(runtime.ci){
49-
manager.updateci(runtime.ci);
41+
42+
const source=await vscode.workspace.fs.readFile(Uri.joinPath(context.extensionUri,"resources","MASM-v6.11.zip"))
43+
const boxConf=`
44+
[AUTOEXEC]
45+
mount C ./C/
46+
c:
47+
`// disk name is not case sensitive but file path is
48+
const bundle=await createBundle({boxConf,mount:[{type:"zip",disk:"C","root":"C","zip":source}]});
49+
console.log(bundle.files)
50+
const data=await bundle.generateAsync({ type: "uint8array" })
51+
await runtime.run(data);
52+
if(runtime && runtime.ci){
53+
manager.updateci(runtime as {ci:CommandInterface});
5054
}
55+
vscode.workspace.fs.writeFile(Uri.joinPath(context.extensionUri,"resources","test.zip"),data)
56+
}
57+
58+
if(manager.hasCi.ci&&manager.terminal){
59+
manager.shell?.exec("echo hello")
5160
}
5261

5362
return {

masm-tasm/src/web/ASM.ts

-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import * as vscode from "vscode";
22
import { emulist } from "../emulators/main";
33
import { ActionType } from "../utils/configuration";
44
import { activateManager } from "../ASM/manager";
5-
import * as statusBar from '../emulators/jsdos-ci'
65

76
export async function activate(context: vscode.ExtensionContext) {
8-
statusBar.activate(context);
97

108
const execAction = activateManager(context, emulist);
119

0 commit comments

Comments
 (0)