summaryrefslogtreecommitdiff
path: root/genesis.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2020-05-08 11:40:30 -0700
committerMichael Pavone <pavone@retrodev.com>2020-05-08 11:40:30 -0700
commitb31a9b47266bf4ea531cd43f96dc2e666948f175 (patch)
treefdf3ac4e2cafaed2158d1295d30e589e9e416d5f /genesis.c
parentfd634d54cddc7419df08949f39fc50e4275ee8f7 (diff)
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Diffstat (limited to 'genesis.c')
-rw-r--r--genesis.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/genesis.c b/genesis.c
index 95fae21..4ed0261 100644
--- a/genesis.c
+++ b/genesis.c
@@ -348,9 +348,6 @@ static 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);
}
-//TODO: move this inside the system context
-static uint32_t last_frame_num;
-
//My refresh emulation isn't currently good enough and causes more problems than it solves
#define REFRESH_EMULATION
#ifdef REFRESH_EMULATION
@@ -387,9 +384,11 @@ m68k_context * sync_components(m68k_context * context, uint32_t address)
context->should_return = 1;
gen->reset_cycle = CYCLE_NEVER;
}
- if (v_context->frame != last_frame_num) {
- //printf("reached frame end %d | MCLK Cycles: %d, Target: %d, VDP cycles: %d, vcounter: %d, hslot: %d\n", last_frame_num, mclks, gen->frame_end, v_context->cycles, v_context->vcounter, v_context->hslot);
- last_frame_num = v_context->frame;
+ if (v_context->frame != gen->last_frame) {
+ //printf("reached frame end %d | MCLK Cycles: %d, Target: %d, VDP cycles: %d, vcounter: %d, hslot: %d\n", gen->last_frame, mclks, gen->frame_end, v_context->cycles, v_context->vcounter, v_context->hslot);
+ gen->last_frame = v_context->frame;
+ event_flush(mclks);
+ gen->last_flush_cycle = mclks;
if(exit_after){
--exit_after;
@@ -417,7 +416,11 @@ m68k_context * sync_components(m68k_context * context, uint32_t address)
gen->reset_cycle -= deduction;
}
event_cycle_adjust(mclks, deduction);
+ gen->last_flush_cycle -= deduction;
}
+ } else if (mclks - gen->last_flush_cycle > gen->soft_flush_cycles) {
+ event_soft_flush(mclks);
+ gen->last_flush_cycle = mclks;
}
gen->frame_end = vdp_cycles_to_frame_end(v_context);
context->sync_cycle = gen->frame_end;
@@ -1188,8 +1191,10 @@ void set_region(genesis_context *gen, rom_info *info, uint8_t region)
if (region & HZ50) {
gen->normal_clock = MCLKS_PAL;
+ gen->soft_flush_cycles = MCLKS_LINE * 262 / 3 + 2;
} else {
gen->normal_clock = MCLKS_NTSC;
+ gen->soft_flush_cycles = MCLKS_LINE * 313 / 3 + 2;
}
gen->master_clock = gen->normal_clock;
}