comparison genesis.c @ 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 0d1d5dccdd28
comparison
equal deleted inserted replaced
2227:eaaf28af3c94 2228:0db9dc6a9020
1105 } 1105 }
1106 #ifdef REFRESH_EMULATION 1106 #ifdef REFRESH_EMULATION
1107 //no refresh delays during IO access 1107 //no refresh delays during IO access
1108 refresh_counter += context->current_cycle - last_sync_cycle; 1108 refresh_counter += context->current_cycle - last_sync_cycle;
1109 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); 1109 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
1110 last_sync_cycle = context->current_cycle;
1110 #endif 1111 #endif
1111 return value; 1112 return value;
1112 } 1113 }
1113 1114
1114 static uint16_t io_read_w(uint32_t location, m68k_context * context) 1115 static uint16_t io_read_w(uint32_t location, m68k_context * context)
1218 1219
1219 static uint16_t unused_read(uint32_t location, void *vcontext) 1220 static uint16_t unused_read(uint32_t location, void *vcontext)
1220 { 1221 {
1221 m68k_context *context = vcontext; 1222 m68k_context *context = vcontext;
1222 genesis_context *gen = context->system; 1223 genesis_context *gen = context->system;
1224 #ifdef REFRESH_EMULATION
1225 if (location >= 0x800000) {
1226 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access
1227 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle;
1228 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
1229 refresh_counter += 4*MCLKS_PER_68K;
1230 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
1231 last_sync_cycle = context->current_cycle;
1232 }
1233 #endif
1234
1223 if (location < 0x800000 || (location >= 0xA13000 && location < 0xA13100) || (location >= 0xA12000 && location < 0xA12100)) { 1235 if (location < 0x800000 || (location >= 0xA13000 && location < 0xA13100) || (location >= 0xA12000 && location < 0xA12100)) {
1224 //Only called if the cart/exp doesn't have a more specific handler for this region 1236 //Only called if the cart/exp doesn't have a more specific handler for this region
1225 return get_open_bus_value(&gen->header); 1237 return get_open_bus_value(&gen->header);
1226 } else if (location == 0xA14000 || location == 0xA14002) { 1238 } else if (location == 0xA14000 || location == 0xA14002) {
1227 if (gen->version_reg & 0xF) { 1239 if (gen->version_reg & 0xF) {
1272 1284
1273 static void *unused_write(uint32_t location, void *vcontext, uint16_t value) 1285 static void *unused_write(uint32_t location, void *vcontext, uint16_t value)
1274 { 1286 {
1275 m68k_context *context = vcontext; 1287 m68k_context *context = vcontext;
1276 genesis_context *gen = context->system; 1288 genesis_context *gen = context->system;
1289 #ifdef REFRESH_EMULATION
1290 if (location >= 0x800000) {
1291 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access
1292 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle;
1293 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
1294 refresh_counter += 4*MCLKS_PER_68K;
1295 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
1296 last_sync_cycle = context->current_cycle;
1297 }
1298 #endif
1277 uint8_t has_tmss = gen->version_reg & 0xF; 1299 uint8_t has_tmss = gen->version_reg & 0xF;
1278 if (has_tmss && (location == 0xA14000 || location == 0xA14002)) { 1300 if (has_tmss && (location == 0xA14000 || location == 0xA14002)) {
1279 gen->tmss_lock[location >> 1 & 1] = value; 1301 gen->tmss_lock[location >> 1 & 1] = value;
1280 check_tmss_lock(gen); 1302 check_tmss_lock(gen);
1281 } else if (has_tmss && location == 0xA14100) { 1303 } else if (has_tmss && location == 0xA14100) {