diff --git a/src/instruction.c b/src/instruction.c index 2333349..3de98ff 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -325,8 +325,8 @@ instruction_data_write_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i, uint * PC which is handled within emulation of a given opcode. */ default: - rk65c02_log(LOG_ERROR, - "unhandled addressing mode for opcode %x\n", i->opcode); + rk65c02_panic(e, "unhandled addressing mode for opcode %x\n", + i->opcode); break; } } @@ -389,8 +389,8 @@ instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i) * PC which is handled within emulation of a given opcode. */ default: - rk65c02_log(LOG_ERROR, - "unhandled addressing mode for opcode %x\n", i->opcode); + rk65c02_panic(e, "unhandled addressing mode for opcode %x\n", + i->opcode); break; } diff --git a/src/rk65c02.c b/src/rk65c02.c index 49a2df5..ade5ae2 100644 --- a/src/rk65c02.c +++ b/src/rk65c02.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -129,11 +130,8 @@ rk65c02_exec(rk65c02emu_t *e) * maturity, let's catch them here to help iron out the * bugs. */ - rk65c02_log(LOG_WARN, "invalid opcode %X @ %X\n", + rk65c02_panic(e, "invalid opcode %X @ %X\n", i.opcode, e->regs.PC); - - e->state = STOPPED; - e->stopreason = EMUERROR; } if (e->trace) @@ -235,6 +233,22 @@ rk65c02_regs_string_get(reg_state_t regs) return str; } + +void +rk65c02_panic(rk65c02emu_t *e, const char* fmt, ...) +{ + va_list args; + + va_start(args, fmt); + rk65c02_log(LOG_CRIT, fmt, args); + va_end(args); + + e->state = STOPPED; + e->stopreason = EMUERROR; + + /* TODO: run some UI callback. */ +} + /* int main(void) diff --git a/src/rk65c02.h b/src/rk65c02.h index 259b11e..c678478 100644 --- a/src/rk65c02.h +++ b/src/rk65c02.h @@ -82,7 +82,8 @@ void rk65c02_step(rk65c02emu_t *, uint16_t); char *rk65c02_regs_string_get(reg_state_t); void rk65c02_dump_regs(reg_state_t); void rk65c02_dump_stack(rk65c02emu_t *, uint8_t); -void rk65c02_irq(rk65c02emu_t *e); +void rk65c02_irq(rk65c02emu_t *); +void rk65c02_panic(rk65c02emu_t *, const char*, ...); #endif