summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--65c02.ts12
-rw-r--r--instructions/BRK.ts37
-rw-r--r--instructions/CLC.ts2
-rw-r--r--instructions/DEC.ts6
-rw-r--r--instructions/INX.ts2
-rw-r--r--instructions/INY.ts2
-rw-r--r--instructions/ROL.ts1
-rw-r--r--instructions/ROR.ts1
-rw-r--r--opcode_matrix.json74
9 files changed, 73 insertions, 64 deletions
diff --git a/65c02.ts b/65c02.ts
index 157e66c..5720a75 100644
--- a/65c02.ts
+++ b/65c02.ts
@@ -147,12 +147,15 @@ export default class The65c02 {
             let resetVector = 0;
             this.io.address.set(0xFFFC);
             this.read()
+            console.log('reset vector LO', this.io.data.num().toString(16))
             resetVector |= this.io.data.num();
             this.io.address.set(0xFFFD);
             this.read()
+            console.log('reset vector HI', this.io.data.num().toString(16))
             resetVector |= this.io.data.num() << 8;
             // move PC to RV
-            this.programCounter.set(resetVector)
+            this.programCounter.set(resetVector);
+            return;
         }
         this.io.address.set(this.programCounter.num());
         this.read();
@@ -204,6 +207,7 @@ export default class The65c02 {
         const lo_abit = this.readPC().num()
         this.programCounter.increment()
         const hi_abit = this.readPC().num()
+        this.programCounter.increment()
         return (hi_abit << 8) | lo_abit
     }
     getAbsoluteXAddr(): number {
@@ -211,6 +215,7 @@ export default class The65c02 {
         const lo_abit = this.readPC().num()
         this.programCounter.increment()
         const hi_abit = this.readPC().num()
+        this.programCounter.increment()
         return this.regX.num() + ((hi_abit << 8) | lo_abit)
     }
     getAbsoluteYAddr(): number {
@@ -218,6 +223,7 @@ export default class The65c02 {
         const lo_abit = this.readPC().num()
         this.programCounter.increment()
         const hi_abit = this.readPC().num()
+        this.programCounter.increment()
         return this.regX.num() + ((hi_abit << 8) | lo_abit)
     }
     getIndirectXAddr(): number {
@@ -281,7 +287,9 @@ export default class The65c02 {
                 this.programCounter.increment()
                 const offset = this.readPC()
                 this.programCounter.increment()
-                return this.programCounter.num() + offset.num()
+                const neg = offset.bit(7);
+                offset.setBit(7, false)
+                return this.programCounter.num() + (offset.num() * (neg ? -1 : 1))
             case 'zero-page':
                 return this.getZPAddr()
             case 'zero-page, X-indexed':
diff --git a/instructions/BRK.ts b/instructions/BRK.ts
index 419eeef..6a2f4e1 100644
--- a/instructions/BRK.ts
+++ b/instructions/BRK.ts
@@ -1,25 +1,18 @@
 import type The65c02 from "../65c02.ts";
 
-export default function (this: The65c02, mode: string) {
-    switch (mode) {
-        case 'implied':
-            this.io.interruptRequest.HI()
-            //TODO: push shit onto stack
-            this.push(this.programCounter.num() & 0x00FF)
-            this.push(this.programCounter.num() & 0xFF00)
-            this.push(this.status.num())
-            this.io.data.set(this.programCounter.num() & 0x00FF)
-            this.io.address.set(0xFFFF)
-            this.write()
-            this.io.data.set(this.programCounter.num() & 0xFF00)
-            this.io.address.set(0xFFFE)
-            this.write()
-            this.BRK = true
-            this.programCounter.increment();
-            this.programCounter.increment();
-            break;
-    
-        default:
-            throw 'wha';
-    }
+export default function (this: The65c02) {
+    this.io.interruptRequest.HI()
+    //TODO: push shit onto stack
+    this.push(this.programCounter.num() & 0x00FF)
+    this.push(this.programCounter.num() & 0xFF00)
+    this.push(this.status.num())
+    this.io.data.set(this.programCounter.num() & 0x00FF)
+    this.io.address.set(0xFFFF)
+    this.write()
+    this.io.data.set(this.programCounter.num() & 0xFF00)
+    this.io.address.set(0xFFFE)
+    this.write()
+    this.BRK = true
+    this.programCounter.increment();
+    this.programCounter.increment();
 }
\ No newline at end of file
diff --git a/instructions/CLC.ts b/instructions/CLC.ts
index d14b2f4..f909d85 100644
--- a/instructions/CLC.ts
+++ b/instructions/CLC.ts
@@ -2,7 +2,7 @@ import type The65c02 from "../65c02.ts";
 
 export default function (this: The65c02, mode: string) {
     switch (mode) {
-        case 'implied':
+        case 'implicit':
             this.carry = false;
             this.programCounter.increment();
             break;
diff --git a/instructions/DEC.ts b/instructions/DEC.ts
index 2f9d7a9..19f40f9 100644
--- a/instructions/DEC.ts
+++ b/instructions/DEC.ts
@@ -1,6 +1,12 @@
 import type The65c02 from "../65c02.ts";
 
 export default function (this: The65c02, mode: string) {
+    if (mode == 'implicit') {
+        this.flagZN(this.regA.num() - 1)
+        this.regA.decrement();
+        this.programCounter.increment()
+        return;
+    }
     const addr = this.getAddr(mode);
     this.io.address.set(addr);
     this.read();
diff --git a/instructions/INX.ts b/instructions/INX.ts
index 9c1cc1b..9a947e1 100644
--- a/instructions/INX.ts
+++ b/instructions/INX.ts
@@ -2,7 +2,7 @@ import type The65c02 from "../65c02.ts";
 
 export default function (this: The65c02, mode: string) {
     switch (mode) {
-        case 'implied':
+        case 'implicit':
             this.regX.increment()
             this.negative = this.regX.bit(7);
             this.zero = this.regX.num() == 0;
diff --git a/instructions/INY.ts b/instructions/INY.ts
index 566c6d4..7e8784d 100644
--- a/instructions/INY.ts
+++ b/instructions/INY.ts
@@ -2,7 +2,7 @@ import type The65c02 from "../65c02.ts";
 
 export default function (this: The65c02, mode: string) {
     switch (mode) {
-        case 'implied':
+        case 'implicit':
             this.regY.increment()
             this.negative = this.regY.bit(7);
             this.zero = this.regY.num() == 0;
diff --git a/instructions/ROL.ts b/instructions/ROL.ts
index c76ef8b..bd1e810 100644
--- a/instructions/ROL.ts
+++ b/instructions/ROL.ts
@@ -7,6 +7,7 @@ export default function (this: The65c02, mode: string) {
         this.negative = (result & 256) != 0
         this.carry = (mem & 256) != 0
         this.regA.set(result & 0xFF);
+        this.programCounter.increment()
     } else {
         const addr = this.getAddr(mode)
         this.io.address.set(addr);
diff --git a/instructions/ROR.ts b/instructions/ROR.ts
index 7226604..60226c9 100644
--- a/instructions/ROR.ts
+++ b/instructions/ROR.ts
@@ -7,6 +7,7 @@ export default function (this: The65c02, mode: string) {
         this.negative = (result & 256) != 0
         this.carry = (mem & 256) != 0
         this.regA.set(result & 0xFF);
+        this.programCounter.increment()
     } else {
         const addr = this.getAddr(mode)
         this.io.address.set(addr);
diff --git a/opcode_matrix.json b/opcode_matrix.json
index 5cabf60..9ce0902 100644
--- a/opcode_matrix.json
+++ b/opcode_matrix.json
@@ -29,7 +29,7 @@
     },
     "18": {
         "mnemonic": "CLC",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "19": {
         "mnemonic": "ORA",
@@ -61,7 +61,7 @@
     },
     "28": {
         "mnemonic": "PLP",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "29": {
         "mnemonic": "AND",
@@ -97,7 +97,7 @@
     },
     "38": {
         "mnemonic": "SEC",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "39": {
         "mnemonic": "AND",
@@ -105,7 +105,7 @@
     },
     "40": {
         "mnemonic": "RTI",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "41": {
         "mnemonic": "EOR",
@@ -125,7 +125,7 @@
     },
     "48": {
         "mnemonic": "PHA",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "49": {
         "mnemonic": "EOR",
@@ -157,7 +157,7 @@
     },
     "58": {
         "mnemonic": "CLI",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "59": {
         "mnemonic": "EOR",
@@ -165,7 +165,7 @@
     },
     "60": {
         "mnemonic": "RTS",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "61": {
         "mnemonic": "ADC",
@@ -189,7 +189,7 @@
     },
     "68": {
         "mnemonic": "PLA",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "69": {
         "mnemonic": "ADC",
@@ -225,7 +225,7 @@
     },
     "78": {
         "mnemonic": "SEI",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "79": {
         "mnemonic": "ADC",
@@ -257,7 +257,7 @@
     },
     "88": {
         "mnemonic": "DEY",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "89": {
         "mnemonic": "BIT",
@@ -293,7 +293,7 @@
     },
     "98": {
         "mnemonic": "TYA",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "99": {
         "mnemonic": "STA",
@@ -301,7 +301,7 @@
     },
     "00": {
         "mnemonic": "BRK",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "01": {
         "mnemonic": "ORA",
@@ -317,7 +317,7 @@
     },
     "08": {
         "mnemonic": "PHP",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "09": {
         "mnemonic": "ORA",
@@ -325,7 +325,7 @@
     },
     "0a": {
         "mnemonic": "ASL",
-        "mode": "accumulator (implied)"
+        "mode": "implicit"
     },
     "0d": {
         "mnemonic": "ORA",
@@ -345,7 +345,7 @@
     },
     "2a": {
         "mnemonic": "ROL",
-        "mode": "accumulator (implied)"
+        "mode": "implicit"
     },
     "2c": {
         "mnemonic": "BIT",
@@ -369,7 +369,7 @@
     },
     "4a": {
         "mnemonic": "LSR",
-        "mode": "accumulator (implied)"
+        "mode": "implicit"
     },
     "4c": {
         "mnemonic": "JMP",
@@ -393,7 +393,7 @@
     },
     "6a": {
         "mnemonic": "ROR",
-        "mode": "accumulator (implied)"
+        "mode": "implicit"
     },
     "6c": {
         "mnemonic": "JMP",
@@ -417,7 +417,7 @@
     },
     "8a": {
         "mnemonic": "TXA",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "8c": {
         "mnemonic": "STY",
@@ -433,7 +433,7 @@
     },
     "9a": {
         "mnemonic": "TXS",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "9d": {
         "mnemonic": "STA",
@@ -465,7 +465,7 @@
     },
     "a8": {
         "mnemonic": "TAY",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "a9": {
         "mnemonic": "LDA",
@@ -473,7 +473,7 @@
     },
     "aa": {
         "mnemonic": "TAX",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "ac": {
         "mnemonic": "LDY",
@@ -509,7 +509,7 @@
     },
     "b8": {
         "mnemonic": "CLV",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "b9": {
         "mnemonic": "LDA",
@@ -517,7 +517,7 @@
     },
     "ba": {
         "mnemonic": "TSX",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "bc": {
         "mnemonic": "LDY",
@@ -553,7 +553,7 @@
     },
     "c8": {
         "mnemonic": "INY",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "c9": {
         "mnemonic": "CMP",
@@ -561,7 +561,7 @@
     },
     "ca": {
         "mnemonic": "DEX",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "cc": {
         "mnemonic": "CPY",
@@ -593,7 +593,7 @@
     },
     "d8": {
         "mnemonic": "CLD",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "d9": {
         "mnemonic": "CMP",
@@ -629,7 +629,7 @@
     },
     "e8": {
         "mnemonic": "INX",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "e9": {
         "mnemonic": "SBC",
@@ -637,7 +637,7 @@
     },
     "ea": {
         "mnemonic": "NOP",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "ec": {
         "mnemonic": "CPX",
@@ -669,7 +669,7 @@
     },
     "f8": {
         "mnemonic": "SED",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "f9": {
         "mnemonic": "SBC",
@@ -701,7 +701,7 @@
     },
     "1a": {
         "mnemonic": "INC",
-        "mode": "accumulator (implied)"
+        "mode": "implicit"
     },
     "1c": {
         "mnemonic": "TRB",
@@ -717,7 +717,7 @@
     },
     "3a": {
         "mnemonic": "DEC",
-        "mode": "accumulator (implied)"
+        "mode": "implicit"
     },
     "3c": {
         "mnemonic": "BIT",
@@ -733,7 +733,7 @@
     },
     "5a": {
         "mnemonic": "PHY",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "5f": {
         "mnemonic": "BBR5",
@@ -745,7 +745,7 @@
     },
     "7a": {
         "mnemonic": "PLY",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "7c": {
         "mnemonic": "JMP",
@@ -797,7 +797,7 @@
     },
     "cb": {
         "mnemonic": "WAI",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "cf": {
         "mnemonic": "BBS4",
@@ -813,11 +813,11 @@
     },
     "da": {
         "mnemonic": "PHX",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "db": {
         "mnemonic": "STP",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "df": {
         "mnemonic": "BBS5",
@@ -841,7 +841,7 @@
     },
     "fa": {
         "mnemonic": "PLX",
-        "mode": "implied"
+        "mode": "implicit"
     },
     "ff": {
         "mnemonic": "BBS7",