fix status register to match nestest

This commit is contained in:
Vineet K 2024-06-28 14:44:16 -04:00
parent 3977ab2a5d
commit f16ab6cb6d

14
cpu.c
View File

@ -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(&regs.status, 0, sizeof(regs.status));
regs.status.interrupt_disable = 1;
regs.status.unused = 1;
cycles += 7;