summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blastem.c14
-rw-r--r--blastem.h2
-rw-r--r--m68k_to_x86.h4
-rw-r--r--render.h2
-rw-r--r--render_sdl.c7
-rw-r--r--runtime.S11
6 files changed, 33 insertions, 7 deletions
diff --git a/blastem.c b/blastem.c
index 33bf145..8946e13 100644
--- a/blastem.c
+++ b/blastem.c
@@ -118,7 +118,9 @@ void adjust_int_cycle(m68k_context * context, vdp_context * v_context)
}
}
-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 @@ m68k_context * sync_components(m68k_context * context)
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 @@ m68k_context * sync_components(m68k_context * context)
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_write(uint32_t vdp_port, m68k_context * context, uint16_
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 --git a/blastem.h b/blastem.h
index e9f62ad..6ba1335 100644
--- a/blastem.h
+++ b/blastem.h
@@ -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 @@ extern io_port gamepad_2;
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 --git a/m68k_to_x86.h b/m68k_to_x86.h
index fdfaa4b..ab0c979 100644
--- a/m68k_to_x86.h
+++ b/m68k_to_x86.h
@@ -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 m68k_reset(m68k_context * context);
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 --git a/render.h b/render.h
index 031a748..d92ba50 100644
--- a/render.h
+++ b/render.h
@@ -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 --git a/render_sdl.c b/render_sdl.c
index ab9fd50..23e3fa0 100644
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -190,10 +190,11 @@ void render_wait_quit(vdp_context * context)
#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 @@ void wait_render_frame(vdp_context * context)
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 @@ void wait_render_frame(vdp_context * context)
start = last_frame;
frame_counter = 0;
}*/
+ return ret;
}
diff --git a/runtime.S b/runtime.S
index 88ed7c8..8c126fa 100644
--- a/runtime.S
+++ b/runtime.S
@@ -7,6 +7,7 @@ handle_cycle_limit:
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 @@ already_supervisor:
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 @@ m68k_native_addr_and_sync:
call m68k_save_context
push %rcx
mov %rsi, %rdi
+ xor %esi, %esi
call sync_components
pop %rsi
push %rax