1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-12-11 18:49:16 +00:00

Preliminary support for stepping.

This commit is contained in:
Radosław Kujawa 2017-01-26 13:11:00 +01:00
parent 941e89173a
commit 80b6848108
2 changed files with 40 additions and 17 deletions

View File

@ -10,6 +10,8 @@
#include "instruction.h" #include "instruction.h"
#include "rk65c02.h" #include "rk65c02.h"
void rk65c02_exec(rk65c02emu_t *);
rk65c02emu_t rk65c02emu_t
rk65c02_init(bus_t *b) rk65c02_init(bus_t *b)
{ {
@ -23,30 +25,49 @@ rk65c02_init(bus_t *b)
} }
void void
rk65c02_start(rk65c02emu_t *e) { rk65c02_exec(rk65c02emu_t *e)
{
instruction_t i; instruction_t i;
instrdef_t id; instrdef_t id;
/* XXX: handle breakpoints and watch points */
/* if disassembly-when-running enabled */
disassemble(e->bus, e->regs.PC);
i = instruction_fetch(e->bus, e->regs.PC);
id = instruction_decode(i.opcode);
if (id.emul != NULL) {
id.emul(e, &id, &i);
/* if (!instruction_modify_pc) */
program_counter_increment(e, &id);
} else {
printf("unimplemented opcode %X @ %X\n", i.opcode,
e->regs.PC);
e->state = STOPPED;
e->stopreason = EMUERROR;
}
}
void
rk65c02_start(rk65c02emu_t *e) {
e->state = RUNNING; e->state = RUNNING;
while (e->state == RUNNING) { while (e->state == RUNNING) {
/* XXX: handle breakpoints and watch points */ rk65c02_exec(e);
}
}
/* if disassembly-when-running enabled */ void
disassemble(e->bus, e->regs.PC); rk65c02_step(rk65c02emu_t *e, uint16_t steps) {
i = instruction_fetch(e->bus, e->regs.PC); uint16_t i = 0;
id = instruction_decode(i.opcode);
if (id.emul != NULL) { e->state = STEPPING;
id.emul(e, &id, &i); while ((e->state == STEPPING) && (i < steps)) {
/* if (!instruction_modify_pc) */ rk65c02_exec(e);
program_counter_increment(e, &id); i++;
} else {
printf("unimplemented opcode %X @ %X\n", i.opcode,
e->regs.PC);
e->state = STOPPED;
e->stopreason = EMUERROR;
}
} }
} }
/* /*

View File

@ -9,10 +9,11 @@ typedef enum {
STEPPING /* XXX: how to implement? */ STEPPING /* XXX: how to implement? */
} emu_state_t; } emu_state_t;
typedef enum typedef enum {
STP, /* due to 65C02 STP instruction */ STP, /* due to 65C02 STP instruction */
BREAKPOINT, /* due to breakpoint set */ BREAKPOINT, /* due to breakpoint set */
WATCHPOINT, /* due to watchpoint set */ WATCHPOINT, /* due to watchpoint set */
STEPPED, /* stepped appropriate number of instructions */
HOST, /* due to host stop function called */ HOST, /* due to host stop function called */
EMUERROR /* due to emulator error */ EMUERROR /* due to emulator error */
} emu_stop_reason_t; } emu_stop_reason_t;
@ -56,6 +57,7 @@ typedef struct rk65c02emu rk65c02emu_t;
rk65c02emu_t rk65c02_init(bus_t *); rk65c02emu_t rk65c02_init(bus_t *);
void rk65c02_start(rk65c02emu_t *); void rk65c02_start(rk65c02emu_t *);
void rk65c02_step(rk65c02emu_t *, uint16_t);
#endif #endif