# HG changeset patch # User Mike Pavone # Date 1358122288 28800 # Node ID 02e25abe2dcd5785921f0b3d144844b7e8eae90b # Parent b204fbed4efef81bbdcd4eb28c370dccc9876179 Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write diff -r b204fbed4efe -r 02e25abe2dcd blastem.c --- a/blastem.c Sun Jan 13 15:55:43 2013 -0800 +++ b/blastem.c Sun Jan 13 16:11:28 2013 -0800 @@ -104,6 +104,20 @@ #define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_68K) +void adjust_int_cycle(m68k_context * context, vdp_context * v_context) +{ + if (!(v_context->regs[REG_MODE_2] & 0x20 && ((context->status & 0x7) < 6)) || context->current_cycle >= VINT_CYCLE) { + context->int_cycle = CYCLE_NEVER; + context->target_cycle = context->sync_cycle; + } else if (context->int_cycle > VINT_CYCLE) { + context->int_cycle = VINT_CYCLE; + context->int_num = 6; + if (context->int_cycle < context->sync_cycle) { + context->target_cycle = context->int_cycle; + } + } +} + m68k_context * sync_components(m68k_context * context) { //TODO: Handle sync targets smaller than a single frame @@ -121,38 +135,11 @@ if (mclks) { vdp_run_context(v_context, mclks); } - if (v_context->regs[REG_MODE_2] & 0x20 && ((context->status & 0x7) < 6)) { - if (context->int_cycle > VINT_CYCLE) { - context->int_cycle = VINT_CYCLE; - context->int_num = 6; - if (context->int_cycle < context->sync_cycle) { - context->target_cycle = context->int_cycle; - } - } - } else { - context->int_cycle = 0xFFFFFFFF; - context->target_cycle = context->sync_cycle; - } } else { //printf("running VDP for %d cycles\n", mclks - v_context->cycles); vdp_run_context(v_context, mclks); - if (v_context->regs[REG_MODE_2] & 0x20 && ((context->status & 0x7) < 6)) { - if (context->int_cycle > VINT_CYCLE) { - context->int_cycle = VINT_CYCLE; - context->int_num = 6; - if (context->int_cycle < context->sync_cycle && context->int_cycle < context->current_cycle) { - context->target_cycle = context->int_cycle; - } - } - if (context->int_cycle <= context->current_cycle) { - context->int_cycle = CYCLE_NEVER; - context->target_cycle = context->sync_cycle; - } - } else { - context->int_cycle = CYCLE_NEVER; - context->target_cycle = context->sync_cycle; - } } + adjust_int_cycle(context, v_context); return context; } @@ -197,18 +184,7 @@ } context->current_cycle = v_context->cycles / MCLKS_PER_68K; } else { - if (v_context->regs[REG_MODE_2] & 0x20 && ((context->status & 0x7) < 6)) { - if (context->int_cycle > VINT_CYCLE) { - context->int_cycle = VINT_CYCLE; - context->int_num = 6; - if (context->int_cycle < context->sync_cycle) { - context->target_cycle = context->int_cycle; - } - } - } else { - context->int_cycle = 0xFFFFFFFF; - context->target_cycle = context->sync_cycle; - } + adjust_int_cycle(context, v_context); } } else { printf("Illegal write to HV Counter port %X\n", vdp_port);