mirror of
https://github.com/rkujawa/rk65c02.git
synced 2024-12-13 01:29:57 +00:00
Make instruction data read more flexible and split from emulation of particular instruction.
This commit is contained in:
parent
87cafb607f
commit
49b70f0e1f
@ -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 */
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user