diff options
author | Oxore <oxore@protonmail.com> | 2022-11-20 01:32:10 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2022-11-20 01:32:10 +0300 |
commit | 695242c3d8a6659dd6af80a7aabba38290eedb9b (patch) | |
tree | 55b6d8b06bee940087a57509272ad5549ce80183 | |
parent | 10aeabf19dcad8385432c2936275b48addb8b653 (diff) |
Fix breakpoint triggering in video cycle
-rw-r--r-- | emulator.cpp | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/emulator.cpp b/emulator.cpp index 1446de5..7be1c8a 100644 --- a/emulator.cpp +++ b/emulator.cpp @@ -380,8 +380,7 @@ int m68k_instr_callback(const int pc) printf("Breakpoint @ 0x%08x\n", pc); g_pc_backtrace.Normalize(); printf("PC backtrace (size=%zu):\n", g_pc_backtrace.Size()); - for (size_t i = 0; i < g_pc_backtrace.Size(); i++) - { + for (size_t i = 0; i < g_pc_backtrace.Size(); i++) { PrintInstructionTrace(g_pc_backtrace.buffer[i]); } return 1; @@ -439,6 +438,18 @@ void ParseAndReact( } } +static void RunSingleVideoCycle(M68KDebuggingControl& m68k_debug, Graphics& graphics) +{ + do { + g_cycles_counter += m68k_execute(1000); + if (m68k_debug.HasBreakpoint()) { + return; + } + } while (!g_vdp.Scanline()); + graphics.Render(g_vdp); + g_cycles_counter += m68k_execute(8000); +} + int emulator(M68KDebuggingControl& m68k_debug, Graphics& graphics) { const int port = 3333; @@ -488,21 +499,18 @@ int emulator(M68KDebuggingControl& m68k_debug, Graphics& graphics) break; } if (m68k_debug.IsRunning()) { - do { - g_cycles_counter += m68k_execute(1000); - } while(!g_vdp.Scanline()); - graphics.Render(g_vdp); - g_cycles_counter += m68k_execute(8000); - } - if (m68k_debug.HasBreakpoint()) { - m68k_debug.SetRunning(false); - m68k_debug.ResetPendingBreakpoint(); - const auto response = - exchange_ctx.WrapDataToSend("S05"); - if (DEBUG_TRACE_GDB_REMOTE) - printf("-> \"%s\"\n", response.c_str()); - if (send(conn_fd, &response[0], response.length(), 0) == -1) - perror("Send failed (response)"); + RunSingleVideoCycle(m68k_debug, graphics); + if (m68k_debug.HasBreakpoint()) { + m68k_debug.SetRunning(false); + printf("ResetPendingBreakpoint"); + m68k_debug.ResetPendingBreakpoint(); + const auto response = + exchange_ctx.WrapDataToSend("S05"); + if (DEBUG_TRACE_GDB_REMOTE) + printf("-> \"%s\"\n", response.c_str()); + if (send(conn_fd, &response[0], response.length(), 0) == -1) + perror("Send failed (response)"); + } } // TODO turn off O_NONBLOCK and poll instead of sleep, only use // nonlock when freerunning |