mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
more hdk stuffs
This commit is contained in:
61
assets/disk0/home/hdk/jmp.js
Normal file
61
assets/disk0/home/hdk/jmp.js
Normal file
@@ -0,0 +1,61 @@
|
||||
if (exec_args[1] === undefined) {
|
||||
println("Usage: jmp pointer_in_hexadecimal")
|
||||
println(" This will execute the binary image stored on the Core Memory at the given pointer.")
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
const ptr = parseInt(exec_args[1], 16)
|
||||
const magic = sys.peek(ptr)
|
||||
|
||||
if (magic != 0xA5) return 1
|
||||
|
||||
//////////////////////////////////
|
||||
|
||||
function seq(s) {
|
||||
let out = ""
|
||||
let cnt = 0
|
||||
let oldchar = s[0]
|
||||
for (let char of s) {
|
||||
if (char === oldchar) {
|
||||
cnt += 1
|
||||
}
|
||||
else {
|
||||
out += ('' + cnt) + oldchar
|
||||
cnt = 1
|
||||
}
|
||||
oldchar = char
|
||||
}
|
||||
return out + cnt + oldchar
|
||||
}
|
||||
|
||||
let key = "00"
|
||||
let keyBytes = [0x00]
|
||||
let keyCursor = 0
|
||||
|
||||
function getNewKeySeq() {
|
||||
key = seq(key)
|
||||
keyBytes = []
|
||||
keyCursor = 0
|
||||
for (let i = 0; i < key.length; i += 2) {
|
||||
keyBytes.push(parseInt(key.substring(i, i+2), 16))
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
|
||||
const payloadSize = (sys.peek(ptr+1) << 16) | (sys.peek(ptr+2) << 8) | sys.peek(ptr+3)
|
||||
|
||||
let encrypted = new Int8Array(payloadSize)
|
||||
|
||||
// read and decrypt
|
||||
for (let outcnt = 0; outcnt < payloadSize; outcnt++) {
|
||||
encrypted[outcnt] = sys.peek(ptr+4+outcnt) ^ keyBytes[keyCursor++]
|
||||
if (keyCursor >= keyBytes.length) {
|
||||
getNewKeySeq()
|
||||
}
|
||||
}
|
||||
|
||||
let image = gzip.decomp(encrypted)
|
||||
|
||||
eval(image)
|
||||
49
assets/disk0/home/hdk/link.js
Normal file
49
assets/disk0/home/hdk/link.js
Normal file
@@ -0,0 +1,49 @@
|
||||
if (exec_args[1] === undefined || exec_args[2] === undefined) {
|
||||
println("Usage: link -e/-o myfile.bin")
|
||||
println(" This will produce generic [E]xecutable/[O]bject code that will be loaded dynamically in the Core Memory")
|
||||
println("Usage: link -e/-o myfile.bin -a 1e00")
|
||||
println(" This will produce [E]xecutable/[O]bject code that will be loaded at memory address 1E00h")
|
||||
return 1
|
||||
}
|
||||
|
||||
let infilePath = _G.shell.resolvePathInput(exec_args[2]).full
|
||||
let infile = files.open(infilePath)
|
||||
let outfile = files.open(infilePath + ".out")
|
||||
let outMode = exec_args[1].toLowerCase()
|
||||
|
||||
let type = {
|
||||
"-r": "\x01",
|
||||
"-e": "\x02",
|
||||
"-o": "\x03",
|
||||
"-c": "\x04"
|
||||
}
|
||||
|
||||
function toI32(num) {
|
||||
const buffer = new ArrayBuffer(4)
|
||||
const view = new DataView(buffer)
|
||||
view.setInt32(0, num, false)
|
||||
return Array.from(new Uint8Array(buffer))
|
||||
}
|
||||
|
||||
function toI24(num) {
|
||||
return toI32(num).slice(-3)
|
||||
}
|
||||
|
||||
function i32ToI24(int) {
|
||||
return int.slice(-3)
|
||||
}
|
||||
|
||||
let addr = 0
|
||||
if (exec_args[3] !== undefined && exec_args[3].toLowerCase() == "-a" && exec_args[4] !== undefined)
|
||||
addr = parseInt(exec_args[4], 16)
|
||||
|
||||
outfile.sappend("\x20\xC0\xCC\x0A")
|
||||
outfile.sappend(type[outMode] || "\x00")
|
||||
outfile.bappend(toI24(addr))
|
||||
outfile.bappend(toI32(infile.size))
|
||||
outfile.sappend(infile.sread())
|
||||
|
||||
infile.close()
|
||||
outfile.close()
|
||||
|
||||
return 0
|
||||
29
assets/disk0/home/hdk/load.js
Normal file
29
assets/disk0/home/hdk/load.js
Normal file
@@ -0,0 +1,29 @@
|
||||
if (exec_args[1] === undefined) {
|
||||
println("Usage: load myfile.out")
|
||||
println(" This will load the binary image onto the Core Memory")
|
||||
return 1
|
||||
}
|
||||
|
||||
let infilePath = _G.shell.resolvePathInput(exec_args[1]).full
|
||||
let infile = files.open(infilePath)
|
||||
|
||||
const metaArea = sys.malloc(12)
|
||||
infile.pread(metaArea, 12, 0)
|
||||
let addrToLoad = (sys.peek(metaArea+5) << 16) | (sys.peek(metaArea+6) << 8) | (sys.peek(metaArea+7))
|
||||
const imageSize = (sys.peek(metaArea+9) << 16) | (sys.peek(metaArea+10) << 8) | (sys.peek(metaArea+11))
|
||||
sys.free(metaArea)
|
||||
|
||||
if (addrToLoad == 0)
|
||||
addrToLoad = sys.malloc(imageSize + 4)
|
||||
else
|
||||
forceAlloc(addrToLoad, imageSize + 4)
|
||||
|
||||
// writes IMAGE_SIZE and the BINARY_IMAGE directly to the memory
|
||||
infile.pread(addrToLoad, imageSize + 4, 8)
|
||||
infile.close()
|
||||
|
||||
// write magic 0xA5 to the beginning of the image area
|
||||
sys.poke(addrToLoad, 0xA5)
|
||||
|
||||
println(addrToLoad.toString(16).toUpperCase() + "h")
|
||||
return addrToLoad
|
||||
@@ -1022,6 +1022,8 @@ files.reservedNames = ["AUX", // unused
|
||||
|
||||
/** This function only creates a file descriptor; will not actually interact with the drives yet. */
|
||||
files.open = (fullPath) => {
|
||||
if (fullPath == undefined) throw Error("path is undefined")
|
||||
|
||||
if (files.reservedNames.includes(fullPath.toUpperCase())) {
|
||||
return new TVDOSFileDescriptor(fullPath.toUpperCase())
|
||||
}
|
||||
@@ -1263,7 +1265,7 @@ var require = (absdir) => {
|
||||
}
|
||||
|
||||
|
||||
var GL = require("A:/tvdos/include/gl.js")
|
||||
var GL = require("A:/tvdos/include/gl.mjs")
|
||||
|
||||
|
||||
// @param cmdsrc JS source code
|
||||
|
||||
Reference in New Issue
Block a user