comparison genesis.c @ 1876:96971b673f51

Only do full sync on VDP data port reads instead of all VDP port reads, provides a perf bump for games that busy wait on the status or HV registers
author Michael Pavone <pavone@retrodev.com>
date Mon, 19 Aug 2019 19:15:52 -0700
parents dc94354eab66
children 377f110e4cea
comparison
equal deleted inserted replaced
1875:3457d338ae25 1876:96971b673f51
630 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle; 630 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle;
631 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); 631 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
632 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); 632 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
633 last_sync_cycle = context->current_cycle; 633 last_sync_cycle = context->current_cycle;
634 #endif 634 #endif
635 sync_components(context, 0);
636 genesis_context *gen = context->system; 635 genesis_context *gen = context->system;
637 vdp_context * v_context = gen->vdp; 636 vdp_context * v_context = gen->vdp;
638 uint32_t before_cycle = v_context->cycles;
639 if (vdp_port < 0x10) { 637 if (vdp_port < 0x10) {
640 if (vdp_port < 4) { 638 if (vdp_port < 4) {
639 sync_components(context, 0);
640 uint32_t before_cycle = v_context->cycles;
641 value = vdp_data_port_read(v_context); 641 value = vdp_data_port_read(v_context);
642 if (v_context->cycles != before_cycle) {
643 //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);
644 context->current_cycle = v_context->cycles;
645 //Lock the Z80 out of the bus until the VDP access is complete
646 genesis_context *gen = context->system;
647 gen->bus_busy = 1;
648 sync_z80(gen->z80, v_context->cycles);
649 gen->bus_busy = 0;
650 }
642 } else if(vdp_port < 8) { 651 } else if(vdp_port < 8) {
652 vdp_run_context(v_context, context->current_cycle);
643 value = vdp_control_port_read(v_context); 653 value = vdp_control_port_read(v_context);
644 } else { 654 } else {
655 vdp_run_context(v_context, context->current_cycle);
645 value = vdp_hv_counter_read(v_context); 656 value = vdp_hv_counter_read(v_context);
646 //printf("HV Counter: %X at cycle %d\n", value, v_context->cycles); 657 //printf("HV Counter: %X at cycle %d\n", value, v_context->cycles);
647 } 658 }
648 } else if (vdp_port < 0x18){ 659 } else if (vdp_port < 0x18){
649 fatal_error("Illegal read from PSG port %X\n", vdp_port); 660 fatal_error("Illegal read from PSG port %X\n", vdp_port);
650 } else { 661 } else {
651 value = get_open_bus_value(&gen->header); 662 value = get_open_bus_value(&gen->header);
652 }
653 if (v_context->cycles != before_cycle) {
654 //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);
655 context->current_cycle = v_context->cycles;
656 //Lock the Z80 out of the bus until the VDP access is complete
657 genesis_context *gen = context->system;
658 gen->bus_busy = 1;
659 sync_z80(gen->z80, v_context->cycles);
660 gen->bus_busy = 0;
661 } 663 }
662 #ifdef REFRESH_EMULATION 664 #ifdef REFRESH_EMULATION
663 last_sync_cycle -= 4; 665 last_sync_cycle -= 4;
664 //refresh may have happened while we were waiting on the VDP, 666 //refresh may have happened while we were waiting on the VDP,
665 //so advance refresh_counter but don't add any delays 667 //so advance refresh_counter but don't add any delays