changeset 2228:0db9dc6a9020

Some minor refresh emulation improvements
author Michael Pavone <pavone@retrodev.com>
date Mon, 05 Sep 2022 23:37:49 -0700
parents eaaf28af3c94
children f699f9d500b4
files genesis.c
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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;