From 49d22ce6ed5a769e91f7090ad99756ccad028bbe Mon Sep 17 00:00:00 2001 From: EkeEke Date: Thu, 27 Jun 2013 23:32:27 +0200 Subject: [PATCH] [Core/VDP] improved HVC latch behavior when not locked in hardware but forced for gun emulation ("Gunfight - 3 in 1" randomization issues when Justifier is enabled) --- core/input_hw/lightgun.c | 4 ++-- core/input_hw/lightgun.h | 2 +- core/vdp_ctrl.c | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/input_hw/lightgun.c b/core/input_hw/lightgun.c index f9a6d5f..4ed0b76 100644 --- a/core/input_hw/lightgun.c +++ b/core/input_hw/lightgun.c @@ -2,7 +2,7 @@ * Genesis Plus * Sega Light Phaser, Menacer & Konami Justifiers support * - * Copyright (C) 2007-2011 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2013 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -135,7 +135,7 @@ void lightgun_refresh(int port) m68k_update_irq(2); } - /* force HV Counter Latch (some games does not lock HV Counter but instead use larger offset value) */ + /* HACK: force HV Counter latch (some games does not lock HV Counter but instead use larger offset value) */ hvc_latch = 0x10000 | (y << 8); if (reg[12] & 1) { diff --git a/core/input_hw/lightgun.h b/core/input_hw/lightgun.h index 4a67946..0021297 100644 --- a/core/input_hw/lightgun.h +++ b/core/input_hw/lightgun.h @@ -2,7 +2,7 @@ * Genesis Plus * Sega Light Phaser, Menacer & Konami Justifiers support * - * Copyright (C) 2007-2011 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2013 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: diff --git a/core/vdp_ctrl.c b/core/vdp_ctrl.c index 96c9f42..e2fe42e 100644 --- a/core/vdp_ctrl.c +++ b/core/vdp_ctrl.c @@ -1370,17 +1370,26 @@ unsigned int vdp_hvc_r(unsigned int cycles) } else { + /* Mode 5: HV counters are frozen (cf. lightgun games & Sunset Riders) */ if (reg[1] & 4) { - /* Mode 5: both counters are frozen (Lightgun games, Sunset Riders) */ + /* check if HVC is really locked or is read within INT2 callback (HVC latch is forced for lightgun emulation, cf. lightgun.c) */ + if ((reg[0] & 0x02) || (m68k.int_mask == 0x0200)) + { #ifdef LOGVDP - error("[%d(%d)][%d(%d)] HVC read -> 0x%x (%x)\n", v_counter, (cycles/MCYCLES_PER_LINE-1)%lines_per_frame, cycles, cycles%MCYCLES_PER_LINE, hvc_latch & 0xffff, m68k_get_reg(M68K_REG_PC)); + error("[%d(%d)][%d(%d)] HVC read -> 0x%x (%x)\n", v_counter, (cycles/MCYCLES_PER_LINE-1)%lines_per_frame, cycles, cycles%MCYCLES_PER_LINE, data & 0xffff, m68k_get_reg(M68K_REG_PC)); #endif - return (data & 0xffff); + /* return latched HVC value */ + return (data & 0xffff); + } + + /* HV counters should be free-running (fixes "Gunfight - 3 in 1" randomization when Justifiers are enabled) */ + hvc_latch = 0; + data = hctab[cycles % MCYCLES_PER_LINE]; } else { - /* Mode 4: VCounter runs normally, HCounter is frozen */ + /* Mode 4: V counter runs normally, H counter is frozen */ data &= 0xff; } }