diff --git a/cpu.c b/cpu.c index 968fcd8..594c462 100644 --- a/cpu.c +++ b/cpu.c @@ -81,10 +81,8 @@ peek(uint16_t addr) static uint16_t peek16(uint16_t addr) { - MEMORY_MIRROR(addr); - /* bytes are stored in little-endian (low then high) */ - return (uint16_t)memory[addr] | ((uint16_t)memory[addr + 1] << 8); + return peek(addr) | (peek(addr + 1) << 8); } static void @@ -108,7 +106,7 @@ memwrite16(uint16_t addr, uint16_t word) static uint8_t opcode_arg(enum addressing_mode mode) { - uint8_t arg, val; + uint16_t arg, val; if (mode != AM_ABS && mode != AM_ABS_X && mode != AM_ABS_Y) arg = peek(regs.pc++); @@ -149,14 +147,15 @@ opcode_arg(enum addressing_mode mode) abort(); } + printf("arg: $%04X $%04X\n", arg, val); + return val; } static uint16_t opcode_mem(enum addressing_mode mode) { - uint8_t arg; - uint16_t val; + uint16_t arg, val; if (mode != AM_ABS && mode != AM_ABS_X && mode != AM_ABS_Y) arg = peek(regs.pc++); @@ -173,6 +172,7 @@ opcode_mem(enum addressing_mode mode) case AM_ZP_Y: val = (arg + regs.y) % 256; break; + case AM_IMM: case AM_ABS: val = arg; break; @@ -1059,7 +1059,7 @@ interpret(void) cycles += 2; break; case 0x4c: - jmp(opcode_arg(AM_ABS)); + jmp(opcode_mem(AM_ABS)); cycles += 3; break; case 0x6c: @@ -1111,7 +1111,7 @@ interpret(void) cycles += 5; break; case 0xa2: - ldx(opcode_arg(AM_IMM)); + ldx(opcode_mem(AM_IMM)); cycles += 2; break; case 0xa6: @@ -1467,8 +1467,8 @@ main(int argc, char *argv[]) return 1; } - memwrite16(0xFFFC, 0x8000); - regs.pc = 0x8000; + memwrite16(0xFFFC, 0xC000); + regs.pc = 0xC000; printf("status: %i%i%i%i%i%i%i%i\n", regs.status.carry, regs.status.zero, regs.status.interrupt_disable,