# HG changeset patch # User Mike Pavone # Date 1604262958 28800 # Node ID b05295c2ad04d79aacfdb177ccd5891be6f62a88 # Parent 579fe3f6fe7699560e11cb702a7e3a20dd9cc82d Small improvement to refresh cycle approximation diff -r 579fe3f6fe76 -r b05295c2ad04 genesis.c --- a/genesis.c Sun Nov 01 12:35:08 2020 -0800 +++ b/genesis.c Sun Nov 01 12:35:58 2020 -0800 @@ -583,7 +583,7 @@ vdp_test_port_write(gen->vdp, value); } #ifdef REFRESH_EMULATION - last_sync_cycle -= 4; + last_sync_cycle -= 4 * MCLKS_PER_68K; //refresh may have happened while we were waiting on the VDP, //so advance refresh_counter but don't add any delays if (vdp_port >= 4 && vdp_port < 8 && v_context->cycles != before_cycle) { @@ -674,7 +674,7 @@ value = get_open_bus_value(&gen->header); } #ifdef REFRESH_EMULATION - last_sync_cycle -= 4; + last_sync_cycle -= 4 * MCLKS_PER_68K; //refresh may have happened while we were waiting on the VDP, //so advance refresh_counter but don't add any delays refresh_counter += (context->current_cycle - last_sync_cycle); @@ -735,6 +735,13 @@ static m68k_context * io_write(uint32_t location, m68k_context * context, uint8_t value) { genesis_context * gen = context->system; +#ifdef REFRESH_EMULATION + //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access + refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle; + context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); + refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); + last_sync_cycle = context->current_cycle - 4*MCLKS_PER_68K; +#endif if (location < 0x10000) { //Access to Z80 memory incurs a one 68K cycle wait state context->current_cycle += MCLKS_PER_68K; @@ -859,6 +866,11 @@ } } } +#ifdef REFRESH_EMULATION + //no refresh delays during IO access + refresh_counter += context->current_cycle - last_sync_cycle; + refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); +#endif return context; } @@ -882,6 +894,13 @@ { uint8_t value; genesis_context *gen = context->system; +#ifdef REFRESH_EMULATION + //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access + refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle; + context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); + refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); + last_sync_cycle = context->current_cycle - 4*MCLKS_PER_68K; +#endif if (location < 0x10000) { //Access to Z80 memory incurs a one 68K cycle wait state context->current_cycle += MCLKS_PER_68K; @@ -977,6 +996,11 @@ } } } +#ifdef REFRESH_EMULATION + //no refresh delays during IO access + refresh_counter += context->current_cycle - last_sync_cycle; + refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); +#endif return value; }