diff options
author | Michael Pavone <pavone@retrodev.com> | 2015-11-16 21:57:17 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2015-11-16 21:57:17 -0800 |
commit | 992f1402a2aceb8637886d159eaff6f39468dc37 (patch) | |
tree | a2c3b9acc986357bca1be4250c90efafa00101a2 | |
parent | a330577630ed3e9c54ca066039d5c53c270c3e3c (diff) |
Approximation of refresh wait states
-rw-r--r-- | blastem.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -230,12 +230,21 @@ void sync_sound(genesis_context * gen, uint32_t target) //printf("Target: %d, YM bufferpos: %d, PSG bufferpos: %d\n", target, gen->ym->buffer_pos, gen->psg->buffer_pos * 2); } +#define REFRESH_INTERVAL 130 +#define REFRESH_DELAY 2 uint32_t last_frame_num; +uint32_t last_sync_cycle; +uint32_t refresh_counter; m68k_context * sync_components(m68k_context * context, uint32_t address) { genesis_context * gen = context->system; vdp_context * v_context = gen->vdp; z80_context * z_context = gen->z80; + //lame estimation of refresh cycle delay + refresh_counter += context->current_cycle - last_sync_cycle; + context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); + refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); + uint32_t mclks = context->current_cycle; sync_z80(z_context, mclks); sync_sound(gen, mclks); @@ -295,6 +304,7 @@ m68k_context * sync_components(m68k_context * context, uint32_t address) context->sync_cycle = context->current_cycle + 1; } } + last_sync_cycle = context->current_cycle; return context; } @@ -354,7 +364,7 @@ m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_ } if (v_context->cycles != before_cycle) { //printf("68K paused for %d (%d) cycles at cycle %d (%d) for write\n", v_context->cycles - context->current_cycle, v_context->cycles - before_cycle, context->current_cycle, before_cycle); - context->current_cycle = v_context->cycles; + last_sync_cycle = context->current_cycle = v_context->cycles; //Lock the Z80 out of the bus until the VDP access is complete gen->bus_busy = 1; sync_z80(gen->z80, v_context->cycles); @@ -427,7 +437,7 @@ uint16_t vdp_port_read(uint32_t vdp_port, m68k_context * context) } if (v_context->cycles != before_cycle) { //printf("68K paused for %d (%d) cycles at cycle %d (%d) for read\n", v_context->cycles - context->current_cycle, v_context->cycles - before_cycle, context->current_cycle, before_cycle); - context->current_cycle = v_context->cycles; + last_sync_cycle = context->current_cycle = v_context->cycles; //Lock the Z80 out of the bus until the VDP access is complete genesis_context *gen = context->system; gen->bus_busy = 1; |