From ee16c6431045802ad8a089aa57d27979f79bef01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Mon, 23 Jan 2017 10:48:37 +0100 Subject: [PATCH] Implement absolute X, absolute Y addressing. --- src/instruction.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/instruction.c b/src/instruction.c index 798944b..2b64a93 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -189,18 +189,29 @@ instruction_data_write_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i, uint case ACCUMULATOR: case IMMEDIATE: 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); bus_write_1(e->bus, iaddr, val); case IZPY: + /* XXX */ iaddr = bus_read_1(e->bus, i->op1 + e->regs.Y); iaddr |= (bus_read_1(e->bus, i->op1 + e->regs.Y + 1) << 8); bus_write_1(e->bus, iaddr, val); - case RELATIVE: case ABSOLUTEX: + bus_write_1(e->bus, (i->op1 + (i->op2 << 8)) + e->regs.X, val); + break; case ABSOLUTEY: + bus_write_1(e->bus, (i->op1 + (i->op2 << 8)) + e->regs.Y, val); + break; + case RELATIVE: case IABSOLUTE: case IABSOLUTEX: + /* + * IABSOLUTE, IABSOLUTEX, RELATIVE are only for branches + * and jumps. They do not read or write anything, only modify + * PC which is handled within emulation of a given opcode. + */ default: printf("unhandled addressing mode for opcode %x\n", i->opcode); @@ -255,10 +266,19 @@ instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i) rv = bus_read_1(e->bus, i->op1 + (i->op2 << 8)); break; case ABSOLUTEX: + rv = bus_read_1(e->bus, (i->op1 + (i->op2 << 8)) + e->regs.X); + break; case ABSOLUTEY: + rv = bus_read_1(e->bus, (i->op1 + (i->op2 << 8)) + e->regs.Y); + break; case IABSOLUTE: case IABSOLUTEX: case RELATIVE: + /* + * IABSOLUTE, IABSOLUTEX, RELATIVE are only for branches + * and jumps. They do not read or write anything, only modify + * PC which is handled within emulation of a given opcode. + */ default: printf("unhandled addressing mode for opcode %x\n", i->opcode);