diff --git a/src/instruction.c b/src/instruction.c index 6845f54..2333349 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -296,10 +296,9 @@ instruction_data_write_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i, uint case ABSOLUTE: bus_write_1(e->bus, i->op1 + (i->op2 << 8), val); break; - case IZPX: - /* XXX */ - iaddr = bus_read_1(e->bus, i->op1 + e->regs.X); - iaddr |= (bus_read_1(e->bus, i->op1 + e->regs.X + 1) << 8); + case IZPX: /* Zero Page Indexed Indirect with X */ + iaddr = bus_read_1(e->bus,(uint8_t) (i->op1 + e->regs.X)); + iaddr |= (bus_read_1(e->bus, (uint8_t) (i->op1 + e->regs.X + 1)) << 8); bus_write_1(e->bus, iaddr, val); break; case IZPY: /* Zero Page Indirect Indexed with Y */ @@ -362,10 +361,9 @@ instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i) iaddr |= (bus_read_1(e->bus, i->op1 + 1) << 8); rv = bus_read_1(e->bus, iaddr); break; - case IZPX: - /* XXX: what about page wraps / roll over */ - iaddr = bus_read_1(e->bus, i->op1 + e->regs.X); - iaddr |= (bus_read_1(e->bus, i->op1 + e->regs.X + 1) << 8); + case IZPX: /* Zero Page Indexed Indirect with X */ + iaddr = bus_read_1(e->bus, (uint8_t) (i->op1 + e->regs.X)); + iaddr |= (bus_read_1(e->bus, (uint8_t) (i->op1 + e->regs.X + 1)) << 8); rv = bus_read_1(e->bus, iaddr); break; case IZPY: /* Zero Page Indirect Indexed with Y */ diff --git a/test/test_emulation.c b/test/test_emulation.c index 65d97c8..b4b8438 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -8,6 +8,7 @@ #include "rk65c02.h" #include "instruction.h" #include "debug.h" +#include "log.h" #include "utils.h" ATF_TC_WITHOUT_HEAD(emul_bit); @@ -1404,6 +1405,33 @@ ATF_TC_BODY(emul_smb, tc) } } +ATF_TC_WITHOUT_HEAD(emul_wrap_izpx); +ATF_TC_BODY(emul_wrap_izpx, tc) +{ + rk65c02emu_t e; + bus_t b; + + b = bus_init_with_default_devs(); + e = rk65c02_init(&b); + + e.regs.A = 0xAA; + e.regs.X = 0xA0; + + bus_write_1(&b, 0xB0, 0x10); + bus_write_1(&b, 0xB1, 0x20); + bus_write_1(&b, 0x90, 0x11); + bus_write_1(&b, 0x91, 0x20); + + bus_write_1(&b, 0x2011, 0x55); + + rk65c02_dump_regs(e.regs); + ATF_REQUIRE(rom_start(&e, "test_emulation_wrap_izpx.rom", tc)); + rk65c02_dump_regs(e.regs); + + ATF_CHECK(bus_read_1(&b, 0x2010) == 0xAA); + ATF_CHECK(e.regs.A == 0x55); +} + ATF_TC_WITHOUT_HEAD(emul_wrap_zpx); ATF_TC_BODY(emul_wrap_zpx, tc) { @@ -1472,6 +1500,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, emul_sign_overflow_thorough); ATF_TP_ADD_TC(tp, emul_wrap_zpx); + ATF_TP_ADD_TC(tp, emul_wrap_izpx); return (atf_no_error()); } diff --git a/test/test_emulation_wrap_izpx.s b/test/test_emulation_wrap_izpx.s new file mode 100644 index 0000000..1742893 --- /dev/null +++ b/test/test_emulation_wrap_izpx.s @@ -0,0 +1,7 @@ +start: sta (0x10,X) +; lda (0xF0,X) +.byte 0xA1,0xF0 + + stp + +