working on debug menu
This commit is contained in:
23
lib/cpu.c
23
lib/cpu.c
@ -7,7 +7,7 @@
|
||||
#include <timer.h>
|
||||
#include <memory.h>
|
||||
|
||||
cpu_context ctx = {0};
|
||||
static cpu_context ctx = {0};
|
||||
#define CPU_DEBUG 1
|
||||
#define FILE_LOG 0
|
||||
|
||||
@ -37,9 +37,9 @@ void cpu_init() {
|
||||
#endif
|
||||
}
|
||||
|
||||
static void fetch_instruction() {
|
||||
ctx.cur_opcode = bus_read(ctx.regs.pc++);
|
||||
ctx.cur_inst = instruction_by_opcode(ctx.cur_opcode);
|
||||
void fetch_instruction(cpu_context *ctx) {
|
||||
ctx->cur_opcode = bus_read(ctx->regs.pc++);
|
||||
ctx->cur_inst = instruction_by_opcode(ctx->cur_opcode);
|
||||
}
|
||||
|
||||
static void execute() {
|
||||
@ -57,15 +57,26 @@ bool cpu_step() {
|
||||
|
||||
if(!ctx.halted) {
|
||||
u16 pc = ctx.regs.pc;
|
||||
fetch_instruction();
|
||||
ctx.inst_pc = pc;
|
||||
fetch_instruction(&ctx);
|
||||
emu_cycles(1);
|
||||
|
||||
#if FILE_LOG == 1
|
||||
fprintf(log, "A:%02X F:%02X B:%02X C:%02X D:%02X E:%02X H:%02X L:%02X SP:%04X PC:%04X PCMEM:%02X,%02X,%02X,%02X\n",
|
||||
ctx.regs.a, ctx.regs.f, ctx.regs.b, ctx.regs.c, ctx.regs.d, ctx.regs.e, ctx.regs.h, ctx.regs.l, ctx.regs.sp, pc,
|
||||
bus_read(pc), bus_read(pc+1), bus_read(pc+2), bus_read(pc+3)
|
||||
);
|
||||
#endif
|
||||
fetch_data();
|
||||
fetch_data(&ctx);
|
||||
while(emu_get_context()->paused && !emu_get_context()->step)
|
||||
delay(10);
|
||||
if(emu_get_context()->paused) {
|
||||
emu_get_context()->step--;
|
||||
if(emu_get_context()->step == 0) {
|
||||
printf("debug!\n");
|
||||
emu_get_context()->debug = true;
|
||||
}
|
||||
}
|
||||
#if CPU_DEBUG == 1
|
||||
char flags[16];
|
||||
sprintf(flags, "%c%c%c%c",
|
||||
|
Reference in New Issue
Block a user