1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-11-15 16:06:38 +00:00

Fix zero page wrap for indexed indirect mode.

This commit is contained in:
Radosław Kujawa 2018-03-31 15:03:22 +02:00
parent 7c4d6cea3f
commit 3c684fbf2c
3 changed files with 42 additions and 8 deletions

View File

@ -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 */

View File

@ -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());
}

View File

@ -0,0 +1,7 @@
start: sta (0x10,X)
; lda (0xF0,X)
.byte 0xA1,0xF0
stp