# HG changeset patch # User Michael Pavone # Date 1662446269 25200 # Node ID 0db9dc6a9020c3d9aa4a0bdc15d25c2a2a87b9cc # Parent eaaf28af3c94473ff70f229451f8aaed2da1910d Some minor refresh emulation improvements diff -r eaaf28af3c94 -r 0db9dc6a9020 genesis.c --- a/genesis.c Mon Sep 05 22:18:25 2022 -0700 +++ b/genesis.c Mon Sep 05 23:37:49 2022 -0700 @@ -1107,6 +1107,7 @@ //no refresh delays during IO access refresh_counter += context->current_cycle - last_sync_cycle; refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); + last_sync_cycle = context->current_cycle; #endif return value; } @@ -1220,6 +1221,17 @@ { m68k_context *context = vcontext; genesis_context *gen = context->system; +#ifdef REFRESH_EMULATION + if (location >= 0x800000) { + //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 += 4*MCLKS_PER_68K; + refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); + last_sync_cycle = context->current_cycle; + } +#endif + if (location < 0x800000 || (location >= 0xA13000 && location < 0xA13100) || (location >= 0xA12000 && location < 0xA12100)) { //Only called if the cart/exp doesn't have a more specific handler for this region return get_open_bus_value(&gen->header); @@ -1274,6 +1286,16 @@ { m68k_context *context = vcontext; genesis_context *gen = context->system; +#ifdef REFRESH_EMULATION + if (location >= 0x800000) { + //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 += 4*MCLKS_PER_68K; + refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); + last_sync_cycle = context->current_cycle; + } +#endif uint8_t has_tmss = gen->version_reg & 0xF; if (has_tmss && (location == 0xA14000 || location == 0xA14002)) { gen->tmss_lock[location >> 1 & 1] = value;