# HG changeset patch # User Michael Pavone # Date 1447818959 28800 # Node ID 90d54ccf95574cf208de2b00a5423367108aede8 # Parent 12b1a8a323066b3fc3825c37853f1925cd6bff37 Fix a bad interaction between the implementation of STOP and the way interrupt cycles are calculated. Prevent addition of refresh delays while VDP has the bus. diff -r 12b1a8a32306 -r 90d54ccf9557 blastem.c --- a/blastem.c Mon Nov 16 22:00:32 2015 -0800 +++ b/blastem.c Tue Nov 17 19:55:59 2015 -0800 @@ -175,6 +175,10 @@ context->target_cycle = context->int_cycle < context->sync_cycle ? context->int_cycle : context->sync_cycle; if (context->should_return) { context->target_cycle = context->current_cycle; + } else if (context->target_cycle < context->current_cycle) { + //Changes to SR can result in an interrupt cycle that's in the past + //This can cause issues with the implementation of STOP though + context->target_cycle = context->current_cycle; } /*printf("Cyc: %d, Trgt: %d, Int Cyc: %d, Int: %d, Mask: %X, V: %d, H: %d, HICount: %d, HReg: %d, Line: %d\n", context->current_cycle, context->target_cycle, context->int_cycle, context->int_num, (context->status & 0x7), @@ -241,9 +245,11 @@ vdp_context * v_context = gen->vdp; z80_context * z_context = gen->z80; //lame estimation of refresh cycle delay - refresh_counter += context->current_cycle - 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); + if (!gen->bus_busy) { + refresh_counter += context->current_cycle - 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); + } uint32_t mclks = context->current_cycle; sync_z80(z_context, mclks);