From f16ab6cb6dce3a64ead1d0f0bc99f3d034a005b2 Mon Sep 17 00:00:00 2001 From: vin Date: Fri, 28 Jun 2024 14:44:16 -0400 Subject: [PATCH] fix status register to match nestest --- cpu.c | 14 ++++++++------ 1 file 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 @@ #define STATUS_UPDATE_NEGATIVE(r) \ (regs.status.negative = ((r & (1 << 7)) != 0)) #define STATUS_TO_INT() \ - ((regs.status.carry << 7) | (regs.status.zero << 6) \ - | (regs.status.interrupt_disable << 5) | (regs.status.decimal_mode << 4) \ - | (regs.status.brk << 3) | (regs.status.unused << 2) \ - | (regs.status.overflow << 1) | regs.status.negative) + (regs.status.carry | (regs.status.zero << 1) \ + | (regs.status.interrupt_disable << 2) | (regs.status.decimal_mode << 3) \ + | (regs.status.brk << 4) | (regs.status.unused << 5) \ + | (regs.status.overflow << 6) | (regs.status.negative << 7)) #define MEMORY_MIRROR(addr) \ if (addr < 0x2000) \ @@ -766,7 +766,7 @@ tya(void) static void interpret(void) { - uint8_t opcode, did_memwrite, ret; + uint8_t opcode, did_memwrite, ret, status; uint16_t arg, mem, deref; uint32_t cycles_; enum addressing_mode mode; @@ -775,6 +775,7 @@ interpret(void) opcode = peek(regs.pc++); cycles_ = cycles; did_memwrite = 0; + status = STATUS_TO_INT(); printf("%04X %02X", regs.pc - 1, opcode); @@ -1908,7 +1909,7 @@ interpret(void) } printf("A:%02X X:%02X Y:%02X P:%02X SP:%02X CYC:%d\n", - regs.a, regs.x, regs.y, STATUS_TO_INT(), regs.sp, cycles_); + regs.a, regs.x, regs.y, status, regs.sp, cycles_); } loop_exit: } @@ -1922,6 +1923,7 @@ cpu_init(void) regs.sp = 0xFD; //memset(®s.status, 0, sizeof(regs.status)); + regs.status.interrupt_disable = 1; regs.status.unused = 1; cycles += 7;