From 75ac3317ed9f6964ffdde441ff27ee666ff0df6f Mon Sep 17 00:00:00 2001 From: EkeEke Date: Sun, 30 Jun 2013 13:06:04 +0200 Subject: [PATCH] [Core/Input] cleaner fix for lightgun emulation when HVC latch is disabled (better not make VDP core hackish) --- core/input_hw/lightgun.c | 22 +++++++++++++++++++--- core/vdp_ctrl.c | 23 ++++++++--------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/core/input_hw/lightgun.c b/core/input_hw/lightgun.c index 4ed0b76..d6bf46e 100644 --- a/core/input_hw/lightgun.c +++ b/core/input_hw/lightgun.c @@ -129,14 +129,25 @@ void lightgun_refresh(int port) } } - /* External Interrupt ? */ + /* External Interrupt enabled ? */ if (reg[11] & 0x08) { m68k_update_irq(2); } - /* HACK: force HV Counter latch (some games does not lock HV Counter but instead use larger offset value) */ - hvc_latch = 0x10000 | (y << 8); + /* HVC latch enabled ? */ + if (reg[0] & 0x02) + { + /* line accurate V-Counter value */ + hvc_latch = 0x10000 | (y << 8); + } + else + { + /* HACK: force HVC latch even when disabled (a few games does not lock HV Counter but instead applies larger offset value) */ + hvc_latch = 0x20000 | (y << 8); + } + + /* pixel accurate H-Counter value */ if (reg[12] & 1) { hvc_latch |= hc_320[((x / 2) + input.x_offset) % 210]; @@ -147,6 +158,11 @@ void lightgun_refresh(int port) } } } + else if (hvc_latch & 0x20000) + { + /* HVC should be free-running on other lines when latch is disabled (fixes "Gunfight - 3 in 1" randomization) */ + hvc_latch = 0; + } } } diff --git a/core/vdp_ctrl.c b/core/vdp_ctrl.c index e2fe42e..b9df03e 100644 --- a/core/vdp_ctrl.c +++ b/core/vdp_ctrl.c @@ -1362,7 +1362,7 @@ unsigned int vdp_hvc_r(unsigned int cycles) int vc; unsigned int data = hvc_latch; - /* Check if HVC is frozen */ + /* Check if HVC latch is enabled */ if (!data) { /* Cycle-accurate HCounter (Striker, Mickey Mania, Skitchin, Road Rash I,II,III, Sonic 3D Blast...) */ @@ -1370,26 +1370,18 @@ 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: H & V counters are frozen (cf. lightgun games, Sunset Riders logo) */ + if (reg[1] & 0x04) { - /* 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, data & 0xffff, m68k_get_reg(M68K_REG_PC)); + error("[%d(%d)][%d(%d)] HVC latch 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 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]; + /* return latched HVC value */ + return (data & 0xffff); } else { - /* Mode 4: V counter runs normally, H counter is frozen */ + /* Mode 4: by default, V counter runs normally & H counter is frozen */ data &= 0xff; } } @@ -1413,6 +1405,7 @@ unsigned int vdp_hvc_r(unsigned int cycles) vc = (vc & ~1) | ((vc >> 8) & 1); } + /* return HCounter in LSB & VCounter in MSB */ data |= ((vc & 0xff) << 8); #ifdef LOGVDP