summary refs log tree commit diff
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2025-04-05 08:59:56 +0300
committerWlodekM <[email protected]>2025-04-05 08:59:56 +0300
commit5b26ed42a61f8cfb057b050257d77920ea41e3f3 (patch)
treeea0b759a304ec62bd95c84406e0869c88f9b33d4
parent562e6237bb58919d800f431cb38de1784efbbe98 (diff)
fix some stack stuff, not sure if it should be 0xFF or 0x0 on startup but whatever
-rw-r--r--65c02.ts4
-rw-r--r--runtime.ts14
-rw-r--r--thing.s24
3 files changed, 31 insertions, 11 deletions
diff --git a/65c02.ts b/65c02.ts
index 9805d50..7fa0516 100644
--- a/65c02.ts
+++ b/65c02.ts
@@ -190,7 +190,7 @@ export default class The65c02 {
     //SECTION - utils
     /** push stuff onto stack */
     push(val: number) {
-        if (this.stackPointer.num() >= 0xFF)
+        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());
@@ -198,7 +198,7 @@ export default class The65c02 {
         this.write();
     }
     pop(): number {
-        if (this.stackPointer.num() <= 0)
+        if (this.stackPointer.num() == 0xFF)
             console.error('stack underflow');
         this.io.address.set(0x01FF - this.stackPointer.num());
         this.read()
diff --git a/runtime.ts b/runtime.ts
index 6bf9892..a7bf146 100644
--- a/runtime.ts
+++ b/runtime.ts
@@ -2,6 +2,8 @@ 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')
+
 // the thing used for ram
 const ram = new Uint8Array(2**16);
 
@@ -12,6 +14,8 @@ const cpu = new The65c02(function (this: The65c02) {
     this.io.data.set(ram[this.io.address.num()] ?? 0)
 }, function (this: The65c02) {
     if (this.io.address.num() == 0x5000) {
+        if (debug)
+            return console.log('CHROUT', `0x${this.io.data.num().toString(16)}`, String.fromCharCode(this.io.data.num()))
         return Deno.stdout.write(new Uint8Array([this.io.data.num()]))
     }
     // write
@@ -20,6 +24,9 @@ const cpu = new The65c02(function (this: The65c02) {
 
 await cpu.loadInstructions()
 
+// test
+cpu.stackPointer.set(0xFF)
+
 const args = parseArgs(Deno.args)
 
 const binStart = parseInt(args.b ?? args.binStart ?? '8000', 16)
@@ -68,8 +75,6 @@ function inspect() {
     console.log(` PC: ${cpu.programCounter.bits.reverse().map(k=>+k).join('')} (0x${cpu.programCounter.num().toString(16)})`)
 }
 
-const debug = Deno.args.includes('-d')
-
 let skip = 0;
 let breakpoints: number[] = []
 let instBreakpoints: string[] = []
@@ -160,7 +165,10 @@ c - continue
 k[NUM] - skip
 r[ADR] - breakpoint
 g[ADR] - goto, change PC
-I[INS] - breakpoint instruction`);
+I[INS] - breakpoint instruction
+:[ADDR]=[VAL] - set memory
+\\[ADDR] - get value
+m[ADDR] - set breakpoint on accessing that address`);
                 continue;
             } else if (i[0] == 'g'.charCodeAt(0)) {
                 const num = i[2] ? parseInt(new TextDecoder().decode(i.slice(1, 7)).replace('\n', '').replaceAll('\0', ''), 16) : cpu.programCounter.num();
diff --git a/thing.s b/thing.s
index 5e03ad8..983470b 100644
--- a/thing.s
+++ b/thing.s
@@ -4,11 +4,8 @@ ACIA_CMD	= $5002
 ACIA_CTRL	= $5003
 
 _start:
-  lda #$64
-  jsr CHROUT
-  lda #$20
-  pha
-  BRK
+  jmp printChar
+  brk
 
 CHROUT:
                 pha
@@ -17,4 +14,19 @@ CHROUT:
 ; .txdelay:       dec
 ;                 bne    .txdelay
                 pla
-                rts
\ No newline at end of file
+                rts
+
+fallback:
+  lda #$21
+  brk
+printChar:
+  jmp print
+fallback2:
+  lda #$22
+  brk
+print:
+  lda #$64
+  jsr CHROUT
+  lda #$20
+  pha
+  BRK
\ No newline at end of file