From 7c4d6cea3f8e6be2b11cadba47a20b0a40c837a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Sat, 31 Mar 2018 12:38:45 +0200 Subject: [PATCH] Fix indirect indexed with Y addressing. Also fix test case for this. Problem wasn't detected, because test case was broken too. --- src/instruction.c | 10 ++++------ test/test_emulation.c | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/instruction.c b/src/instruction.c index 350a730..6845f54 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -302,11 +302,10 @@ instruction_data_write_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i, uint iaddr |= (bus_read_1(e->bus, i->op1 + e->regs.X + 1) << 8); bus_write_1(e->bus, iaddr, val); break; - case IZPY: - /* XXX */ + case IZPY: /* Zero Page Indirect Indexed with Y */ iaddr = bus_read_1(e->bus, i->op1); iaddr |= (bus_read_1(e->bus, i->op1 + 1) << 8); - bus_write_1(e->bus, iaddr, val + e->regs.Y); + bus_write_1(e->bus, iaddr + e->regs.Y, val); break; case ABSOLUTEX: bus_write_1(e->bus, (i->op1 + (i->op2 << 8)) + e->regs.X, val); @@ -369,11 +368,10 @@ instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i) iaddr |= (bus_read_1(e->bus, i->op1 + e->regs.X + 1) << 8); rv = bus_read_1(e->bus, iaddr); break; - case IZPY: - /* XXX: what about page wraps / roll over */ + case IZPY: /* Zero Page Indirect Indexed with Y */ iaddr = bus_read_1(e->bus, i->op1); iaddr |= (bus_read_1(e->bus, i->op1 + 1) << 8); - rv = bus_read_1(e->bus, iaddr) + e->regs.Y; + rv = bus_read_1(e->bus, iaddr + e->regs.Y); break; case ABSOLUTE: rv = bus_read_1(e->bus, i->op1 + (i->op2 << 8)); diff --git a/test/test_emulation.c b/test/test_emulation.c index 34d1fa5..65d97c8 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -122,7 +122,7 @@ ATF_TC_BODY(emul_cmp, tc) e.regs.Y = 0x01; bus_write_1(&b, 0x22, 0x0); bus_write_1(&b, 0x23, 0x20); - bus_write_1(&b, 0x2000, 0xF); + bus_write_1(&b, 0x2001, 0x10); rk65c02_dump_regs(e.regs); ATF_REQUIRE(rom_start(&e, "test_emulation_cmp_izpy.rom", tc)); rk65c02_dump_regs(e.regs); @@ -662,11 +662,11 @@ ATF_TC_BODY(emul_sta, tc) ATF_REQUIRE(rom_start(&e, "test_emulation_sta_izpx.rom", tc)); ATF_CHECK(bus_read_1(&b, 0x2010) == 0xAA); /* STA indirect zero page Y */ - e.regs.A = 0x54; + e.regs.A = 0x55; e.regs.X = 0; e.regs.Y = 0x1; ATF_REQUIRE(rom_start(&e, "test_emulation_sta_izpy.rom", tc)); - ATF_CHECK(bus_read_1(&b, 0x2010) == 0x55); + ATF_CHECK(bus_read_1(&b, 0x2011) == 0x55); bus_finish(&b); } @@ -729,7 +729,7 @@ ATF_TC_BODY(emul_ora, tc) e.regs.A = 0xAA; e.regs.X = 0; e.regs.Y = 0x1; - bus_write_1(&b, 0x2A04, 0x54); + bus_write_1(&b, 0x2A05, 0x55); bus_write_1(&b, 0x14, 0x04); bus_write_1(&b, 0x15, 0x2A); ATF_REQUIRE(rom_start(&e, "test_emulation_ora_izpy.rom", tc));