From 80b6848108db41fe263ecd4c46b190f8c8d9faf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Thu, 26 Jan 2017 13:11:00 +0100 Subject: [PATCH] Preliminary support for stepping. --- src/rk65c02.c | 53 +++++++++++++++++++++++++++++++++++---------------- src/rk65c02.h | 4 +++- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/rk65c02.c b/src/rk65c02.c index b2b59d7..1abea0c 100644 --- a/src/rk65c02.c +++ b/src/rk65c02.c @@ -10,6 +10,8 @@ #include "instruction.h" #include "rk65c02.h" +void rk65c02_exec(rk65c02emu_t *); + rk65c02emu_t rk65c02_init(bus_t *b) { @@ -23,30 +25,49 @@ rk65c02_init(bus_t *b) } void -rk65c02_start(rk65c02emu_t *e) { +rk65c02_exec(rk65c02emu_t *e) +{ instruction_t i; 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; while (e->state == RUNNING) { - /* XXX: handle breakpoints and watch points */ + rk65c02_exec(e); + } +} - /* if disassembly-when-running enabled */ - disassemble(e->bus, e->regs.PC); +void +rk65c02_step(rk65c02emu_t *e, uint16_t steps) { - i = instruction_fetch(e->bus, e->regs.PC); - id = instruction_decode(i.opcode); + uint16_t i = 0; - 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; - } + e->state = STEPPING; + while ((e->state == STEPPING) && (i < steps)) { + rk65c02_exec(e); + i++; } } /* diff --git a/src/rk65c02.h b/src/rk65c02.h index a21128e..4349fc7 100644 --- a/src/rk65c02.h +++ b/src/rk65c02.h @@ -9,10 +9,11 @@ typedef enum { STEPPING /* XXX: how to implement? */ } emu_state_t; -typedef enum +typedef enum { STP, /* due to 65C02 STP instruction */ BREAKPOINT, /* due to breakpoint set */ WATCHPOINT, /* due to watchpoint set */ + STEPPED, /* stepped appropriate number of instructions */ HOST, /* due to host stop function called */ EMUERROR /* due to emulator error */ } emu_stop_reason_t; @@ -56,6 +57,7 @@ typedef struct rk65c02emu rk65c02emu_t; rk65c02emu_t rk65c02_init(bus_t *); void rk65c02_start(rk65c02emu_t *); +void rk65c02_step(rk65c02emu_t *, uint16_t); #endif