diff --git a/src/emulation.c b/src/emulation.c index c1bb55f..fc090e6 100644 --- a/src/emulation.c +++ b/src/emulation.c @@ -8,7 +8,11 @@ emul_lda(rk65c02emu_t *e, instruction_t *i) instrdef_t id; id = instruction_decode(i->opcode); - e->regs.A = i->op1; + e->regs.A = instruction_data_read_1(e, &id, i); + + + /* adjust status flags */ + } diff --git a/src/instruction.c b/src/instruction.c index b3f4849..d583de1 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -137,3 +137,62 @@ instruction_decode(uint8_t opcode) return id; } +uint8_t +instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i) +{ + uint8_t rv; /* data read from the bus */ +// uint8_t ziaddr; /* indirect zero page address */ + uint16_t iaddr; /* indirect address */ + + rv = 0; + + switch (id->mode) { + case ACCUMULATOR: + rv = e->regs.A; + break; + case IMMEDIATE: + rv = i->op1; + break; + case ZP: + 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); + break; + case ZPY: + rv = bus_read_1(e->bus, i->op1 + e->regs.Y); + break; + case IZP: + 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); + break; + case IZPX: +/* ziaddr = bus_read_1(e->bus, i->op1 + e->regs.X); + ziaddr |= (bus_read_1(e->bus, i->op1 + e->regs.X + 1) << 8); + rv = bus_read_1(e->bus, ziaddr); + break; +*/ + case IZPY: +/* + iaddr = bus_read_1(e->bus, i->op1 + e->regs.Y); + iaddr |= (bus_read_1(e->bus, i->op1 + e->regs.Y + 1) << 8); + rv = bus_read_1(e->bus, ziaddr); +*/ + case RELATIVE: + case ABSOLUTE: + case ABSOLUTEX: + case ABSOLUTEY: + case IABSOLUTE: + case IABSOLUTEX: + + default: + printf("unhandled addressing mode for opcode %x\n", + i->opcode); + break; + } + + return rv; +} + diff --git a/src/instruction.h b/src/instruction.h index 3038820..4075cae 100644 --- a/src/instruction.h +++ b/src/instruction.h @@ -43,6 +43,7 @@ instruction_t instruction_fetch(bus_t *, uint16_t); instrdef_t instruction_decode(uint8_t); void instruction_print(instruction_t *); void disassemble(bus_t *, uint16_t); +uint8_t instruction_data_read_1(rk65c02emu_t *, instrdef_t *, instruction_t *); //void instruction_execute(rk65c02emu_t *, instruction_t *); #endif /* _INSTRUCTION_H_ */