diff --git a/assets/disk0/home/hdk/compile.js b/assets/disk0/home/hdk/compile.js index 840688e..aaf4b4f 100644 --- a/assets/disk0/home/hdk/compile.js +++ b/assets/disk0/home/hdk/compile.js @@ -1,9 +1,26 @@ if (exec_args[1] === undefined) { - println("Usage: compile myfile.js") - println("The compiled file will be myfile.bin") + println("Usage: compile -le/-lo myfile.js") + println(" The compiled and linked file will be myfile.out") return 1 } -const filenameWithoutExt = exec_args[1].substringBeforeLast(".") -_G.shell.execute(`gzip -c ${exec_args[1]} | writeto ${filenameWithoutExt}.gz`) -_G.shell.execute(`enc ${filenameWithoutExt}.gz ${filenameWithoutExt}.bin`) -_G.shell.execute(`rm ${filenameWithoutExt}.gz`) \ No newline at end of file + +// with linking +if (exec_args[2]) { + const filenameWithoutExt = exec_args[2].substringBeforeLast(".") + const tempFilename = generateRandomHashStr(32) + + _G.shell.execute(`gzip -c ${exec_args[2]} | writeto ${tempFilename}.gz`) + _G.shell.execute(`enc ${tempFilename}.gz ${tempFilename}.bin`) + _G.shell.execute(`rm ${tempFilename}.gz`) + + _G.shell.execute(`link -${exec_args[1][2]} ${tempFilename}.bin`) + _G.shell.execute(`mv ${tempFilename}.out ${filenameWithoutExt}.out`) + _G.shell.execute(`rm ${tempFilename}.bin`) +} +// with no linking +else { + const filenameWithoutExt = exec_args[1].substringBeforeLast(".") + _G.shell.execute(`gzip -c ${exec_args[1]} | writeto ${filenameWithoutExt}.gz`) + _G.shell.execute(`enc ${filenameWithoutExt}.gz ${filenameWithoutExt}.bin`) + _G.shell.execute(`rm ${filenameWithoutExt}.gz`) +} diff --git a/assets/disk0/home/hdk/free.js b/assets/disk0/home/hdk/free.js new file mode 100644 index 0000000..db79d4f --- /dev/null +++ b/assets/disk0/home/hdk/free.js @@ -0,0 +1,14 @@ +if (exec_args[1] === undefined) { + println("Usage: free ptr_in_hex") + println(" This will free the pointer loaded using 'load'") + return 1 +} + +// check for CUM header +const ptr = parseInt(exec_args[1], 16) +const magic = sys.peek(ptr) + +if (magic != 0xA5) return 1 + + +sys.free(ptr) \ No newline at end of file diff --git a/assets/disk0/home/hdk/run.js b/assets/disk0/home/hdk/run.js index 0de487a..b067117 100644 --- a/assets/disk0/home/hdk/run.js +++ b/assets/disk0/home/hdk/run.js @@ -12,7 +12,8 @@ if (magic != 0xA5) return 1 const source = sys.toObjectCode(ptr) -const wrapper = new Function("exec_args", `const g={exec_args};with(g){${source}}`); +//const wrapper = new Function("exec_args", `const g={exec_args};with(g){${source}}`); +const wrapper = new Function("_BIOS", "_G", "_TVDOS", "exec_args", source) const newArgs = ["@ptr:"+ptr].concat(exec_args.slice(2)) -wrapper(newArgs) \ No newline at end of file +wrapper(_BIOS, _G, _TVDOS, newArgs) \ No newline at end of file