static void emu_main_loop_inner(void) { if (!emulationPaused) { if (cpuEvents & EVENT_RESET) { gui_console_printf("[CEmu] Calculator reset triggered...\n"); cpu_reset(); cpuEvents &= ~EVENT_RESET; } #ifdef DEBUG_SUPPORT if (!cpu.halted && (cpuEvents & EVENT_DEBUG_STEP)) { cpuEvents &= ~EVENT_DEBUG_STEP; open_debugger(DBG_STEP, 0); } #endif if (!asic.shipModeEnabled) { sched_process_pending_events(); cpu_execute(); } else { gui_emu_sleep(50); } } else { gui_emu_sleep(50); } }
void open_debugger(int reason, uint32_t data) { if (inDebugger) { /* Prevent recurse */ return; } if ((reason == DBG_STEP) && debugger.stepOverFirstStep) { if (((cpuEvents & EVENT_DEBUG_STEP_NEXT) && !(debugger.data.block[cpu.registers.PC] & DBG_TEMP_EXEC_BREAKPOINT)) || (cpuEvents & EVENT_DEBUG_STEP_OUT)) { debugger.stepOverFirstStep = false; gui_debugger_raise_or_disable(inDebugger = false); return; } debug_clear_temp_break(); } debugger.cpu_cycles = cpu.cycles; debugger.cpu_next = cpu.next; debugger.total_cycles = cpu.cycles + cpu.cycles_offset; if (debugger.currentBuffPos) { debugger.buffer[debugger.currentBuffPos] = '\0'; gui_console_printf("%s", debugger.buffer); debugger.currentBuffPos = 0; } if (debugger.currentErrBuffPos) { debugger.errBuffer[debugger.currentErrBuffPos] = '\0'; gui_console_err_printf("%s", debugger.errBuffer); debugger.currentErrBuffPos = 0; } inDebugger = true; gui_debugger_send_command(reason, data); while (inDebugger) { gui_emu_sleep(50); } cpu.next = debugger.cpu_next; cpu.cycles = debugger.cpu_cycles; cpu.cycles_offset = debugger.total_cycles - cpu.cycles; if (cpuEvents & EVENT_DEBUG_STEP) { cpu.next = cpu.cycles + 1; } }
/* Write to the 0xFXXX range of ports */ static void fxxx_write(const uint16_t pio, const uint8_t value) { /* 0xFFE appears to dump the contents of flash. Probably not a good thing to print to a console :) */ if (pio != 0xFFF) { return; } #ifdef DEBUG_SUPPORT debugger.buffer[debugger.currentBuffPos] = (char)value; debugger.currentBuffPos = (debugger.currentBuffPos + 1) % (SIZEOF_DBG_BUFFER); if (value == 0) { unsigned x; debugger.currentBuffPos = 0; gui_console_printf("%s",debugger.buffer); for(x=0; x<6; x++) { gui_emu_sleep(); } } #endif }
/* since it is called outside of cpu_execute(). Which means no read/write errors. */ void open_debugger(int reason, uint32_t address) { if (inDebugger) { return; // don't recurse } debugger.cpu_cycles = cpu.cycles; gui_debugger_entered_or_left(inDebugger = true); if (debugger.stepOverAddress < 0x1000000) { debugger.data.block[debugger.stepOverAddress] &= ~DBG_STEP_OVER_BREAKPOINT; debugger.stepOverAddress = UINT32_C(0xFFFFFFFF); } gui_debugger_send_command(reason, address); do { gui_emu_sleep(); } while(inDebugger); gui_debugger_entered_or_left(inDebugger = false); cpu.cycles = debugger.cpu_cycles; if (cpu_events & EVENT_DEBUG_STEP) { cpu.next = cpu.cycles + 1; } }
void enterVariableLink(void) { /* Wait for the GUI to finish whatever it needs to do */ do { gui_emu_sleep(); } while(emu_is_sending || emu_is_recieving); }