diff --git a/src/instruction.c b/src/instruction.c index 4ee12da..350a730 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -353,8 +353,7 @@ instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i) rv = bus_read_1(e->bus, i->op1); break; case ZPX: - /* XXX: wraps around zero page? */ - rv = bus_read_1(e->bus, i->op1 + e->regs.X); + rv = bus_read_1(e->bus, (uint8_t) (i->op1 + e->regs.X)); break; case ZPY: rv = bus_read_1(e->bus, i->op1 + e->regs.Y); diff --git a/test/test_emulation.c b/test/test_emulation.c index bc9d381..34d1fa5 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -1409,6 +1409,7 @@ ATF_TC_BODY(emul_wrap_zpx, tc) { rk65c02emu_t e; bus_t b; + uint16_t i; b = bus_init_with_default_devs(); e = rk65c02_init(&b); @@ -1422,6 +1423,13 @@ ATF_TC_BODY(emul_wrap_zpx, tc) ATF_CHECK(bus_read_1(&b, 0x00) == 0xAA); ATF_CHECK(bus_read_1(&b, 0x01) == 0xAA); ATF_CHECK(bus_read_1(&b, 0x7E) == 0xAA); + + i = 0x200; + + while (i < 0x205) { + ATF_CHECK(bus_read_1(&b, i) == 0xAA); + i++; + } } ATF_TP_ADD_TCS(tp) diff --git a/test/test_emulation_wrap_zpx.s b/test/test_emulation_wrap_zpx.s index 17f5db2..8c0bf9d 100644 --- a/test/test_emulation_wrap_zpx.s +++ b/test/test_emulation_wrap_zpx.s @@ -3,5 +3,16 @@ start: sta 0x10,X sta 0x81,X sta 0x82,X sta 0xFF,X + + ldy 0x10,X + sty 0x200 + ldy 0x80,X + sty 0x201 + ldy 0x81,X + sty 0x202 + ldy 0x82,X + sty 0x203 + ldy 0xFF,X + sty 0x204 stp