more hdk stuffs

This commit is contained in:
minjaesong
2025-04-07 19:05:49 +09:00
parent a72279c86c
commit 44a234c416
4 changed files with 142 additions and 1 deletions

View 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)

View 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

View 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

View File

@@ -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