summaryrefslogtreecommitdiff
path: root/cpu.c
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2024-06-28 14:44:16 -0400
committervin <git@vineetk.net>2024-06-28 18:15:37 -0400
commitf16ab6cb6dce3a64ead1d0f0bc99f3d034a005b2 (patch)
tree65c24265665b33d6d49375e304a64e960ceb027f /cpu.c
parent3977ab2a5d41c939f480d91265328ca62ba7be1d (diff)
fix status register to match nestest
Diffstat (limited to 'cpu.c')
-rw-r--r--cpu.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/cpu.c b/cpu.c
index 6d8c599..66dbd4c 100644
--- a/cpu.c
+++ b/cpu.c
@@ -13,10 +13,10 @@
13#define STATUS_UPDATE_NEGATIVE(r) \ 13#define STATUS_UPDATE_NEGATIVE(r) \
14 (regs.status.negative = ((r & (1 << 7)) != 0)) 14 (regs.status.negative = ((r & (1 << 7)) != 0))
15#define STATUS_TO_INT() \ 15#define STATUS_TO_INT() \
16 ((regs.status.carry << 7) | (regs.status.zero << 6) \ 16 (regs.status.carry | (regs.status.zero << 1) \
17 | (regs.status.interrupt_disable << 5) | (regs.status.decimal_mode << 4) \ 17 | (regs.status.interrupt_disable << 2) | (regs.status.decimal_mode << 3) \
18 | (regs.status.brk << 3) | (regs.status.unused << 2) \ 18 | (regs.status.brk << 4) | (regs.status.unused << 5) \
19 | (regs.status.overflow << 1) | regs.status.negative) 19 | (regs.status.overflow << 6) | (regs.status.negative << 7))
20 20
21#define MEMORY_MIRROR(addr) \ 21#define MEMORY_MIRROR(addr) \
22 if (addr < 0x2000) \ 22 if (addr < 0x2000) \
@@ -766,7 +766,7 @@ tya(void)
766static void 766static void
767interpret(void) 767interpret(void)
768{ 768{
769 uint8_t opcode, did_memwrite, ret; 769 uint8_t opcode, did_memwrite, ret, status;
770 uint16_t arg, mem, deref; 770 uint16_t arg, mem, deref;
771 uint32_t cycles_; 771 uint32_t cycles_;
772 enum addressing_mode mode; 772 enum addressing_mode mode;
@@ -775,6 +775,7 @@ interpret(void)
775 opcode = peek(regs.pc++); 775 opcode = peek(regs.pc++);
776 cycles_ = cycles; 776 cycles_ = cycles;
777 did_memwrite = 0; 777 did_memwrite = 0;
778 status = STATUS_TO_INT();
778 779
779 printf("%04X %02X", regs.pc - 1, opcode); 780 printf("%04X %02X", regs.pc - 1, opcode);
780 781
@@ -1908,7 +1909,7 @@ interpret(void)
1908 } 1909 }
1909 1910
1910 printf("A:%02X X:%02X Y:%02X P:%02X SP:%02X CYC:%d\n", 1911 printf("A:%02X X:%02X Y:%02X P:%02X SP:%02X CYC:%d\n",
1911 regs.a, regs.x, regs.y, STATUS_TO_INT(), regs.sp, cycles_); 1912 regs.a, regs.x, regs.y, status, regs.sp, cycles_);
1912 } 1913 }
1913loop_exit: 1914loop_exit:
1914} 1915}
@@ -1922,6 +1923,7 @@ cpu_init(void)
1922 regs.sp = 0xFD; 1923 regs.sp = 0xFD;
1923 1924
1924 //memset(&regs.status, 0, sizeof(regs.status)); 1925 //memset(&regs.status, 0, sizeof(regs.status));
1926 regs.status.interrupt_disable = 1;
1925 regs.status.unused = 1; 1927 regs.status.unused = 1;
1926 1928
1927 cycles += 7; 1929 cycles += 7;