# HG changeset patch # User Mike Pavone # Date 1358737829 28800 # Node ID 209a37eed3e793d3807ee9b15dff7a2674a1ed8c # Parent 7c227a8ec53d51207821b43921c73c7e55a7e207 Add support for breaking into the debugger while game is running diff -r 7c227a8ec53d -r 209a37eed3e7 blastem.c --- a/blastem.c Thu Jan 17 20:00:07 2013 -0800 +++ b/blastem.c Sun Jan 20 19:10:29 2013 -0800 @@ -118,7 +118,9 @@ } } -m68k_context * sync_components(m68k_context * context) +int break_on_sync = 0; + +m68k_context * sync_components(m68k_context * context, uint32_t address) { //TODO: Handle sync targets smaller than a single frame vdp_context * v_context = context->next_context; @@ -126,7 +128,7 @@ if (mclks >= MCLKS_PER_FRAME) { //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, mclks); vdp_run_context(v_context, MCLKS_PER_FRAME); - wait_render_frame(v_context); + break_on_sync |= wait_render_frame(v_context); mclks -= MCLKS_PER_FRAME; vdp_adjust_cycles(v_context, MCLKS_PER_FRAME); io_adjust_cycles(&gamepad_1, context->current_cycle, MCLKS_PER_FRAME/MCLKS_PER_68K); @@ -140,13 +142,17 @@ vdp_run_context(v_context, mclks); } adjust_int_cycle(context, v_context); + if (break_on_sync && address) { + break_on_sync = 0; + debugger(context, address); + } return context; } m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_t value) { //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle); - sync_components(context); + sync_components(context, 0); vdp_context * v_context = context->next_context; if (vdp_port < 0x10) { int blocked; @@ -201,7 +207,7 @@ m68k_context * vdp_port_read(uint32_t vdp_port, m68k_context * context) { - sync_components(context); + sync_components(context, 0); vdp_context * v_context = context->next_context; if (vdp_port < 0x10) { if (vdp_port < 4) { diff -r 7c227a8ec53d -r 209a37eed3e7 blastem.h --- a/blastem.h Thu Jan 17 20:00:07 2013 -0800 +++ b/blastem.h Sun Jan 20 19:10:29 2013 -0800 @@ -2,6 +2,7 @@ #define BLASTEM_H_ #include +#include "m68k_to_x86.h" typedef struct { uint32_t th_counter; @@ -20,6 +21,7 @@ void io_adjust_cycles(io_port * pad, uint32_t current_cycle, uint32_t deduction); uint16_t read_dma_value(uint32_t address); +m68k_context * debugger(m68k_context * context, uint32_t address); #endif //BLASTEM_H_ diff -r 7c227a8ec53d -r 209a37eed3e7 m68k_to_x86.h --- a/m68k_to_x86.h Thu Jan 17 20:00:07 2013 -0800 +++ b/m68k_to_x86.h Sun Jan 20 19:10:29 2013 -0800 @@ -1,3 +1,5 @@ +#ifndef M68K_TO_X86_H_ +#define M68K_TO_X86_H_ #include #include #include "68kinst.h" @@ -63,3 +65,5 @@ void insert_breakpoint(m68k_context * context, uint32_t address, uint8_t * bp_handler); void remove_breakpoint(m68k_context * context, uint32_t address); +#endif //M68K_TO_X86_H_ + diff -r 7c227a8ec53d -r 209a37eed3e7 render.h --- a/render.h Thu Jan 17 20:00:07 2013 -0800 +++ b/render.h Sun Jan 20 19:10:29 2013 -0800 @@ -5,7 +5,7 @@ void render_init(int width, int height); void render_context(vdp_context * context); void render_wait_quit(vdp_context * context); -void wait_render_frame(vdp_context * context); +int wait_render_frame(vdp_context * context); #endif //RENDER_SDL_H_ diff -r 7c227a8ec53d -r 209a37eed3e7 render_sdl.c --- a/render_sdl.c Thu Jan 17 20:00:07 2013 -0800 +++ b/render_sdl.c Sun Jan 20 19:10:29 2013 -0800 @@ -190,10 +190,11 @@ #define MIN_DELAY 10 uint32_t frame_counter = 0; uint32_t start = 0; -void wait_render_frame(vdp_context * context) +int wait_render_frame(vdp_context * context) { FILE * outfile; SDL_Event event; + int ret = 0; while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: @@ -218,6 +219,9 @@ fclose(outfile); puts("state saved to state.gst"); break; + case SDLK_u: + ret = 1; + break; case SDLK_RETURN: gamepad_1.input[GAMEPAD_TH0] |= BUTTON_START; break; @@ -336,6 +340,7 @@ start = last_frame; frame_counter = 0; }*/ + return ret; } diff -r 7c227a8ec53d -r 209a37eed3e7 runtime.S --- a/runtime.S Thu Jan 17 20:00:07 2013 -0800 +++ b/runtime.S Sun Jan 20 19:10:29 2013 -0800 @@ -7,6 +7,7 @@ do_sync: call m68k_save_context mov %rsi, %rdi + xor %esi, %esi call sync_components mov %rax, %rsi call m68k_load_context @@ -51,7 +52,14 @@ ret skip_int: cmp 84(%rsi), %eax - jnb do_sync + jb skip_sync_int + call m68k_save_context + mov %rsi, %rdi + mov %ecx, %esi + call sync_components + mov %rax, %rsi + call m68k_load_context +skip_sync_int: ret .global m68k_trap @@ -554,6 +562,7 @@ call m68k_save_context push %rcx mov %rsi, %rdi + xor %esi, %esi call sync_components pop %rsi push %rax