From c62e133afb34fc38445af7bbe61e88cf45e9a7e3 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Thu, 3 Apr 2025 12:28:21 +0300 Subject: it works, holy shit --- 65c02.ts | 2 +- runtime.ts | 26 +++++++++++++++++++------- thing.s | 24 +++++++++++++++++------- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/65c02.ts b/65c02.ts index 9d286d9..f1368a9 100644 --- a/65c02.ts +++ b/65c02.ts @@ -288,7 +288,7 @@ export default class The65c02 { this.programCounter.increment() const neg = offset.bit(7); offset.setBit(7, false) - return this.programCounter.num() + (offset.num() * (neg ? -1 : 1)) + return this.programCounter.num() + (offset.num() + (neg ? -128 : 0)) case 'zero-page': return this.getZPAddr() case 'zero-page, X-indexed': diff --git a/runtime.ts b/runtime.ts index ccb9dae..8ecfe1b 100644 --- a/runtime.ts +++ b/runtime.ts @@ -11,6 +11,9 @@ const cpu = new The65c02(function (this: The65c02) { // to map things into address space this.io.data.set(ram[this.io.address.num()] ?? 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() }) @@ -56,11 +59,11 @@ function inspect() { }).join('\n')); console.log('\nregisters:') - console.log(` A: ${cpu.regA.bits.map(k=>+k).join('')} (0x${cpu.regA.num().toString(16)})`) - console.log(` X: ${cpu.regX.bits.map(k=>+k).join('')} (0x${cpu.regX.num().toString(16)})`) - console.log(` Y: ${cpu.regY.bits.map(k=>+k).join('')} (0x${cpu.regY.num().toString(16)})`) - console.log(` SP: ${cpu.stackPointer.bits.map(k=>+k).join('')} (0x${cpu.stackPointer.num().toString(16)})`) - console.log(` PC: ${cpu.programCounter.bits.map(k=>+k).join('')} (0x${cpu.programCounter.num().toString(16)})`) + console.log(` A: ${cpu.regA.bits.reverse().map(k=>+k).join('')} (0x${cpu.regA.num().toString(16)})`) + console.log(` X: ${cpu.regX.bits.reverse().map(k=>+k).join('')} (0x${cpu.regX.num().toString(16)})`) + console.log(` Y: ${cpu.regY.bits.reverse().map(k=>+k).join('')} (0x${cpu.regY.num().toString(16)})`) + console.log(` SP: ${cpu.stackPointer.bits.reverse().map(k=>+k).join('')} (0x${cpu.stackPointer.num().toString(16)})`) + console.log(` PC: ${cpu.programCounter.bits.reverse().map(k=>+k).join('')} (0x${cpu.programCounter.num().toString(16)})`) } const debug = Deno.args.includes('-d') @@ -69,6 +72,10 @@ let skip = 0; let breakpoints: number[] = [] let instBreakpoints: string[] = [] +if (debug) { + console.info('NOTE; the instructions are executed after input') +} + // repeat until the cpu requests an interrupt while (!cpu.io.interruptRequest.high) { const instId = ram[cpu.programCounter.num()] @@ -80,8 +87,8 @@ while (!cpu.io.interruptRequest.high) { break; } const instr = goog; + if (debug) console.debug(cpu.programCounter.num().toString(16).padStart(4, '0'),instr.mnemonic, instr.mode) - cpu.cycle(); // debug step-by-step mode dbg: if (debug) { @@ -95,7 +102,7 @@ while (!cpu.io.interruptRequest.high) { skip = 0; console.log('hit breakpoint on', cpu.programCounter.num().toString(16)) } - if (skip > 0) { + if (skip != 0) { skip-- break dbg; } @@ -128,6 +135,7 @@ while (!cpu.io.interruptRequest.high) { console.log(`b - break, exit i - inspect s - inspect stack +c - continue k[NUM] - skip r[ADR] - breakpoint g[ADR] - goto, change PC @@ -140,8 +148,12 @@ I[INS] - breakpoint instruction`); const instr = new TextDecoder().decode(i.slice(1, 7)).replace('\n', '').replaceAll('\0', '') console.log(`instruction breakpoint set on`, instr) instBreakpoints.push(instr) + } else if (i[0] == 'c'.charCodeAt(0)) { + skip = -1 + console.log(`continuing execution`) } } + cpu.cycle(); } console.log('end of execution\n\n') diff --git a/thing.s b/thing.s index d492a15..e5df832 100644 --- a/thing.s +++ b/thing.s @@ -1,8 +1,18 @@ +ACIA_DATA = $5000 +ACIA_STATUS = $5001 +ACIA_CMD = $5002 +ACIA_CTRL = $5003 + _start: - lda #$78 - jsr goog - cmp #$78 - brk -goog: - lda #$50 - rts \ No newline at end of file + lda #$64 + jsr CHROUT + BRK + +CHROUT: + pha + sta ACIA_DATA + lda #$FF +.txdelay: dec + bne .txdelay + pla + rts \ No newline at end of file -- cgit 1.4.1-2-gfad0