summaryrefslogtreecommitdiff
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
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
-rw-r--r--event_log.c15
-rw-r--r--event_log.h1
-rw-r--r--genesis.c17
-rw-r--r--genesis.h3
-rw-r--r--vdp.c2
5 files changed, 30 insertions, 8 deletions
diff --git a/event_log.c b/event_log.c
index dd6eaa7..79f2bc2 100644
--- a/event_log.c
+++ b/event_log.c
@@ -276,6 +276,7 @@ static void flush_socket(void)
}
}
+uint8_t wrote_since_last_flush;
void event_log(uint8_t type, uint32_t cycle, uint8_t size, uint8_t *payload)
{
if (!fully_active) {
@@ -294,6 +295,7 @@ void event_log(uint8_t type, uint32_t cycle, uint8_t size, uint8_t *payload)
if (listen_sock) {
if ((output_stream.next_out - compressed) > 1280 || !output_stream.avail_out) {
flush_socket();
+ wrote_since_last_flush = 1;
}
} else if (!output_stream.avail_out) {
fwrite(compressed, 1, compressed_storage, event_file);
@@ -467,9 +469,22 @@ void event_flush(uint32_t cycle)
output_stream.avail_out = compressed_storage;
} else if (listen_sock) {
flush_socket();
+ wrote_since_last_flush = 0;
}
}
+void event_soft_flush(uint32_t cycle)
+{
+ if (!fully_active || wrote_since_last_flush || event_file) {
+ return;
+ }
+ event_header(EVENT_FLUSH, cycle);
+ last = cycle;
+
+ deflate_flush(0);
+ flush_socket();
+}
+
static void init_event_reader_common(event_reader *reader)
{
reader->last_cycle = 0;
diff --git a/event_log.h b/event_log.h
index 0e44288..cd9ac28 100644
--- a/event_log.h
+++ b/event_log.h
@@ -48,6 +48,7 @@ void event_vram_word(uint32_t cycle, uint32_t address, uint16_t value);
void event_vram_byte(uint32_t cycle, uint16_t address, uint8_t byte, uint8_t auto_inc);
void event_state(uint32_t cycle, serialize_buffer *state);
void event_flush(uint32_t cycle);
+void event_soft_flush(uint32_t cycle);
void init_event_reader(event_reader *reader, uint8_t *data, size_t size);
void init_event_reader_tcp(event_reader *reader, char *address, char *port);
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;
}
diff --git a/genesis.h b/genesis.h
index 9070cc6..8418113 100644
--- a/genesis.h
+++ b/genesis.h
@@ -51,6 +51,9 @@ struct genesis_context {
uint32_t int_latency_prev1;
uint32_t int_latency_prev2;
uint32_t reset_cycle;
+ uint32_t last_frame;
+ uint32_t last_flush_cycle;
+ uint32_t soft_flush_cycles;
uint8_t bank_regs[8];
uint16_t z80_bank_reg;
uint16_t tmss_lock[2];
diff --git a/vdp.c b/vdp.c
index 8138ec6..f1d1065 100644
--- a/vdp.c
+++ b/vdp.c
@@ -2118,8 +2118,6 @@ static void advance_output_line(vdp_context *context)
context->pushed_frame = 1;
context->fb = NULL;
}
- //TODO: Check whether this happens before or after the cycle increment
- event_flush(context->cycles);
vdp_update_per_frame_debug(context);
context->h40_lines = 0;
context->frame++;