comparison genesis.c @ 1971:80920c21bb52

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
author Michael Pavone <pavone@retrodev.com>
date Fri, 08 May 2020 11:40:30 -0700
parents 2fd0a8cb1c80
children 81df9aa2de9b
comparison
equal deleted inserted replaced
1970:41b9509ede38 1971:80920c21bb52
346 ym_run(gen->ym, target); 346 ym_run(gen->ym, target);
347 347
348 //printf("Target: %d, YM bufferpos: %d, PSG bufferpos: %d\n", target, gen->ym->buffer_pos, gen->psg->buffer_pos * 2); 348 //printf("Target: %d, YM bufferpos: %d, PSG bufferpos: %d\n", target, gen->ym->buffer_pos, gen->psg->buffer_pos * 2);
349 } 349 }
350 350
351 //TODO: move this inside the system context
352 static uint32_t last_frame_num;
353
354 //My refresh emulation isn't currently good enough and causes more problems than it solves 351 //My refresh emulation isn't currently good enough and causes more problems than it solves
355 #define REFRESH_EMULATION 352 #define REFRESH_EMULATION
356 #ifdef REFRESH_EMULATION 353 #ifdef REFRESH_EMULATION
357 #define REFRESH_INTERVAL 128 354 #define REFRESH_INTERVAL 128
358 #define REFRESH_DELAY 2 355 #define REFRESH_DELAY 2
385 if (mclks >= gen->reset_cycle) { 382 if (mclks >= gen->reset_cycle) {
386 gen->reset_requested = 1; 383 gen->reset_requested = 1;
387 context->should_return = 1; 384 context->should_return = 1;
388 gen->reset_cycle = CYCLE_NEVER; 385 gen->reset_cycle = CYCLE_NEVER;
389 } 386 }
390 if (v_context->frame != last_frame_num) { 387 if (v_context->frame != gen->last_frame) {
391 //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); 388 //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);
392 last_frame_num = v_context->frame; 389 gen->last_frame = v_context->frame;
390 event_flush(mclks);
391 gen->last_flush_cycle = mclks;
393 392
394 if(exit_after){ 393 if(exit_after){
395 --exit_after; 394 --exit_after;
396 if (!exit_after) { 395 if (!exit_after) {
397 exit(0); 396 exit(0);
415 gen->psg->cycles -= deduction; 414 gen->psg->cycles -= deduction;
416 if (gen->reset_cycle != CYCLE_NEVER) { 415 if (gen->reset_cycle != CYCLE_NEVER) {
417 gen->reset_cycle -= deduction; 416 gen->reset_cycle -= deduction;
418 } 417 }
419 event_cycle_adjust(mclks, deduction); 418 event_cycle_adjust(mclks, deduction);
420 } 419 gen->last_flush_cycle -= deduction;
420 }
421 } else if (mclks - gen->last_flush_cycle > gen->soft_flush_cycles) {
422 event_soft_flush(mclks);
423 gen->last_flush_cycle = mclks;
421 } 424 }
422 gen->frame_end = vdp_cycles_to_frame_end(v_context); 425 gen->frame_end = vdp_cycles_to_frame_end(v_context);
423 context->sync_cycle = gen->frame_end; 426 context->sync_cycle = gen->frame_end;
424 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->current_cycle, v_context->vcounter, v_context->hslot); 427 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->current_cycle, v_context->vcounter, v_context->hslot);
425 if (context->int_ack) { 428 if (context->int_ack) {
1186 gen->version_reg = NO_DISK | USA; 1189 gen->version_reg = NO_DISK | USA;
1187 } 1190 }
1188 1191
1189 if (region & HZ50) { 1192 if (region & HZ50) {
1190 gen->normal_clock = MCLKS_PAL; 1193 gen->normal_clock = MCLKS_PAL;
1194 gen->soft_flush_cycles = MCLKS_LINE * 262 / 3 + 2;
1191 } else { 1195 } else {
1192 gen->normal_clock = MCLKS_NTSC; 1196 gen->normal_clock = MCLKS_NTSC;
1197 gen->soft_flush_cycles = MCLKS_LINE * 313 / 3 + 2;
1193 } 1198 }
1194 gen->master_clock = gen->normal_clock; 1199 gen->master_clock = gen->normal_clock;
1195 } 1200 }
1196 1201
1197 static uint8_t load_state(system_header *system, uint8_t slot) 1202 static uint8_t load_state(system_header *system, uint8_t slot)