diff options
-rw-r--r-- | 65c02.ts | 10 | ||||
-rw-r--r-- | eater.ts | 10 | ||||
-rw-r--r-- | runtime.ts | 6 |
3 files changed, 15 insertions, 11 deletions
diff --git a/65c02.ts b/65c02.ts index 7fa0516..4d4cc83 100644 --- a/65c02.ts +++ b/65c02.ts @@ -191,18 +191,18 @@ export default class The65c02 { /** push stuff onto stack */ push(val: number) { if (this.stackPointer.num() == 0) - console.error('stack overflow (no, not like the website)'); - this.stackPointer.increment(); - this.io.address.set(0x01FF - this.stackPointer.num()); + console.error(`stack overflow (no, not like the website)`); + this.stackPointer.decrement(); + this.io.address.set(0x0100 | this.stackPointer.num()); this.io.data.set(val); this.write(); } pop(): number { if (this.stackPointer.num() == 0xFF) console.error('stack underflow'); - this.io.address.set(0x01FF - this.stackPointer.num()); + this.io.address.set(0x0100 | this.stackPointer.num()); this.read() - this.stackPointer.decrement(); + this.stackPointer.increment(); return this.io.data.num() } getZPAddr(): number { diff --git a/eater.ts b/eater.ts index 20af12a..683b23a 100644 --- a/eater.ts +++ b/eater.ts @@ -1,6 +1,7 @@ // deno-lint-ignore-file no-process-globals import The65c02 from "./65c02.ts"; import matrix from "./opcode_matrix.json" with { type: "json" }; +import { type Buffer } from "node:buffer"; // eater.ts // a runtime meant to mimic ben eater's 65c02 computer @@ -30,6 +31,8 @@ const binStart = 0; await cpu.loadInstructions() +cpu.stackPointer.set(0xff) + const code = Deno.readFileSync('a.out') // mem address $0000 @@ -52,13 +55,11 @@ cpu.io.reset.HI() let running = true; -process.stdin.on('data', (data) => { +process.stdin.on('data', (data: Buffer) => { 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 @@ -81,6 +82,9 @@ const clock = setInterval(() => { throw 'oh no'; } const instr = goog; + console.log(`\ + PC AC XR YR SP NV-BDIZC +6502: ${cpu.programCounter.num().toString(16).padStart(4, '0')} ${cpu.regA.num().toString(16).padStart(2, '0')} ${cpu.regX.num().toString(16).padStart(2, '0')} ${cpu.regY.num().toString(16).padStart(2, '0')} ${cpu.stackPointer.num().toString(16).padStart(2, '0')} ${cpu.stackPointer.num().toString(2).padStart(8, '0')}`) console.debug(cpu.programCounter.num().toString(16).padStart(4, '0'),instr.mnemonic, instr.mode) cpu.cycle(); // 1MHz i think diff --git a/runtime.ts b/runtime.ts index a7bf146..5bfafef 100644 --- a/runtime.ts +++ b/runtime.ts @@ -2,7 +2,9 @@ import The65c02, { BitField, Pin } from "./65c02.ts"; import matrix from "./opcode_matrix.json" with { type: "json" }; import { parseArgs } from "jsr:@std/cli/parse-args"; -const debug = Deno.args.includes('-d') +const args = parseArgs(Deno.args) + +const debug = args.d // the thing used for ram const ram = new Uint8Array(2**16); @@ -27,8 +29,6 @@ await cpu.loadInstructions() // test cpu.stackPointer.set(0xFF) -const args = parseArgs(Deno.args) - const binStart = parseInt(args.b ?? args.binStart ?? '8000', 16) const resVec = parseInt(args.s ?? args.start ?? binStart.toString(16), 16) |