Mercurial > repos > blastem
changeset 198:209a37eed3e7
Add support for breaking into the debugger while game is running
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 20 Jan 2013 19:10:29 -0800 |
parents | 7c227a8ec53d |
children | 69585e7d474f |
files | blastem.c blastem.h m68k_to_x86.h render.h render_sdl.c runtime.S |
diffstat | 6 files changed, 33 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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) {
--- 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 <stdint.h> +#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_
--- 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 <stdint.h> #include <stdio.h> #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_ +
--- 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_
--- 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; }
--- 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