From e2568226af4af2d3b27e9e1a775e7244c5ef7191 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Thu, 3 Apr 2025 21:51:53 +0300 Subject: more progress on trying to get wozmon running --- eater.ts | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 eater.ts (limited to 'eater.ts') diff --git a/eater.ts b/eater.ts new file mode 100644 index 0000000..4440635 --- /dev/null +++ b/eater.ts @@ -0,0 +1,76 @@ +// deno-lint-ignore-file no-process-globals +import The65c02 from "./65c02.ts"; +// eater.ts +// a runtime meant to mimic ben eater's 65c02 computer + +if (!process.stdin.isRaw) + process.stdin.setRawMode(true) + +// the thing used for ram +const ram = new Uint8Array(2**16); + +// initiate the emulator +const cpu = new The65c02(function (this: The65c02) { + // since this is controlled by the user it's easy + // to map things into address space + this.io.data.set(ram[this.io.address.num()] ?? 0) + if (this.io.address.num() == 0x5000 + && ram[0x5001]) + ram[0x5001] = 0; +}, function (this: The65c02) { + if (this.io.address.num() == 0x5000) { + return Deno.stdout.write(new Uint8Array([this.io.data.num()])) + } + // write + ram[this.io.address.num()] = this.io.data.num() +}) + +const binStart = 0; + +await cpu.loadInstructions() + +const code = Deno.readFileSync('a.out') + +// mem address $0000 +ram[0xFFFC] = binStart & 0x00FF +ram[0xFFFD] = (binStart & 0xFF00) >> 8 + +// write code to ram before execution +for (let offset = 0; offset < code.length; offset++) { + const byte = code[offset]; + ram[binStart + offset] = byte; +} + +// pull RESB low to reset the 65c02 +cpu.io.reset.LO() +cpu.cycle() + +//the cpu reset, pull RESB high and start execution! +cpu.io.reset.HI() + + +let running = true; + +process.stdin.on('data', (data) => { + if (data[0] == 3) + return running = false; + // console.log(`uh`, data[0], data[0].toString(16)) + ram[0x5000] = data[0]; + ram[0x5001] = 0x08; + // cpu.io.interruptRequest.HI(); +}) + +// repeat until the cpu requests an interrupt +const clock = setInterval(() => { + if (!running) { + Deno.writeFileSync('ram.bin', ram) + clearInterval(clock) + + process.stdin.setRawMode(false); + Deno.exit(0) + } + if(cpu.io.interruptRequest.high && !cpu.IRQBDisable) + cpu.io.interruptRequest.LO(); + cpu.cycle(); +// 1MHz i think +}, 1) -- cgit 1.4.1-2-gfad0