comparison genesis.c @ 2012:b05295c2ad04

Small improvement to refresh cycle approximation
author Mike Pavone <pavone@retrodev.com>
date Sun, 01 Nov 2020 12:35:58 -0800
parents 0740d90812ee
children 270a4c875e0a
comparison
equal deleted inserted replaced
2011:579fe3f6fe76 2012:b05295c2ad04
581 psg_write(gen->psg, value); 581 psg_write(gen->psg, value);
582 } else { 582 } else {
583 vdp_test_port_write(gen->vdp, value); 583 vdp_test_port_write(gen->vdp, value);
584 } 584 }
585 #ifdef REFRESH_EMULATION 585 #ifdef REFRESH_EMULATION
586 last_sync_cycle -= 4; 586 last_sync_cycle -= 4 * MCLKS_PER_68K;
587 //refresh may have happened while we were waiting on the VDP, 587 //refresh may have happened while we were waiting on the VDP,
588 //so advance refresh_counter but don't add any delays 588 //so advance refresh_counter but don't add any delays
589 if (vdp_port >= 4 && vdp_port < 8 && v_context->cycles != before_cycle) { 589 if (vdp_port >= 4 && vdp_port < 8 && v_context->cycles != before_cycle) {
590 refresh_counter = 0; 590 refresh_counter = 0;
591 } else { 591 } else {
672 fatal_error("Illegal read from PSG port %X\n", vdp_port); 672 fatal_error("Illegal read from PSG port %X\n", vdp_port);
673 } else { 673 } else {
674 value = get_open_bus_value(&gen->header); 674 value = get_open_bus_value(&gen->header);
675 } 675 }
676 #ifdef REFRESH_EMULATION 676 #ifdef REFRESH_EMULATION
677 last_sync_cycle -= 4; 677 last_sync_cycle -= 4 * MCLKS_PER_68K;
678 //refresh may have happened while we were waiting on the VDP, 678 //refresh may have happened while we were waiting on the VDP,
679 //so advance refresh_counter but don't add any delays 679 //so advance refresh_counter but don't add any delays
680 refresh_counter += (context->current_cycle - last_sync_cycle); 680 refresh_counter += (context->current_cycle - last_sync_cycle);
681 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); 681 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
682 last_sync_cycle = context->current_cycle; 682 last_sync_cycle = context->current_cycle;
733 static uint32_t zram_counter = 0; 733 static uint32_t zram_counter = 0;
734 734
735 static m68k_context * io_write(uint32_t location, m68k_context * context, uint8_t value) 735 static m68k_context * io_write(uint32_t location, m68k_context * context, uint8_t value)
736 { 736 {
737 genesis_context * gen = context->system; 737 genesis_context * gen = context->system;
738 #ifdef REFRESH_EMULATION
739 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access
740 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle;
741 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
742 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
743 last_sync_cycle = context->current_cycle - 4*MCLKS_PER_68K;
744 #endif
738 if (location < 0x10000) { 745 if (location < 0x10000) {
739 //Access to Z80 memory incurs a one 68K cycle wait state 746 //Access to Z80 memory incurs a one 68K cycle wait state
740 context->current_cycle += MCLKS_PER_68K; 747 context->current_cycle += MCLKS_PER_68K;
741 if (!z80_enabled || z80_get_busack(gen->z80, context->current_cycle)) { 748 if (!z80_enabled || z80_get_busack(gen->z80, context->current_cycle)) {
742 location &= 0x7FFF; 749 location &= 0x7FFF;
857 } else if (masked != 0x11300 && masked != 0x11000) { 864 } else if (masked != 0x11300 && masked != 0x11000) {
858 fatal_error("Machine freeze due to unmapped write to address %X\n", location | 0xA00000); 865 fatal_error("Machine freeze due to unmapped write to address %X\n", location | 0xA00000);
859 } 866 }
860 } 867 }
861 } 868 }
869 #ifdef REFRESH_EMULATION
870 //no refresh delays during IO access
871 refresh_counter += context->current_cycle - last_sync_cycle;
872 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
873 #endif
862 return context; 874 return context;
863 } 875 }
864 876
865 static m68k_context * io_write_w(uint32_t location, m68k_context * context, uint16_t value) 877 static m68k_context * io_write_w(uint32_t location, m68k_context * context, uint16_t value)
866 { 878 {
880 892
881 static uint8_t io_read(uint32_t location, m68k_context * context) 893 static uint8_t io_read(uint32_t location, m68k_context * context)
882 { 894 {
883 uint8_t value; 895 uint8_t value;
884 genesis_context *gen = context->system; 896 genesis_context *gen = context->system;
897 #ifdef REFRESH_EMULATION
898 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access
899 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle;
900 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
901 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
902 last_sync_cycle = context->current_cycle - 4*MCLKS_PER_68K;
903 #endif
885 if (location < 0x10000) { 904 if (location < 0x10000) {
886 //Access to Z80 memory incurs a one 68K cycle wait state 905 //Access to Z80 memory incurs a one 68K cycle wait state
887 context->current_cycle += MCLKS_PER_68K; 906 context->current_cycle += MCLKS_PER_68K;
888 if (!z80_enabled || z80_get_busack(gen->z80, context->current_cycle)) { 907 if (!z80_enabled || z80_get_busack(gen->z80, context->current_cycle)) {
889 location &= 0x7FFF; 908 location &= 0x7FFF;
975 fatal_error("Machine freeze due to read of unmapped IO location %X\n", location); 994 fatal_error("Machine freeze due to read of unmapped IO location %X\n", location);
976 value = 0xFF; 995 value = 0xFF;
977 } 996 }
978 } 997 }
979 } 998 }
999 #ifdef REFRESH_EMULATION
1000 //no refresh delays during IO access
1001 refresh_counter += context->current_cycle - last_sync_cycle;
1002 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
1003 #endif
980 return value; 1004 return value;
981 } 1005 }
982 1006
983 static uint16_t io_read_w(uint32_t location, m68k_context * context) 1007 static uint16_t io_read_w(uint32_t location, m68k_context * context)
984 { 1008 {