[Core/Input] cleaner fix for lightgun emulation when HVC latch is disabled

(better not make VDP core hackish)
This commit is contained in:
EkeEke 2013-06-30 13:06:04 +02:00
parent 49d22ce6ed
commit 75ac3317ed
2 changed files with 27 additions and 18 deletions

View File

@ -129,14 +129,25 @@ void lightgun_refresh(int port)
} }
} }
/* External Interrupt ? */ /* External Interrupt enabled ? */
if (reg[11] & 0x08) if (reg[11] & 0x08)
{ {
m68k_update_irq(2); m68k_update_irq(2);
} }
/* HACK: force HV Counter latch (some games does not lock HV Counter but instead use larger offset value) */ /* HVC latch enabled ? */
hvc_latch = 0x10000 | (y << 8); 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) if (reg[12] & 1)
{ {
hvc_latch |= hc_320[((x / 2) + input.x_offset) % 210]; 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;
}
} }
} }

View File

@ -1362,7 +1362,7 @@ unsigned int vdp_hvc_r(unsigned int cycles)
int vc; int vc;
unsigned int data = hvc_latch; unsigned int data = hvc_latch;
/* Check if HVC is frozen */ /* Check if HVC latch is enabled */
if (!data) if (!data)
{ {
/* Cycle-accurate HCounter (Striker, Mickey Mania, Skitchin, Road Rash I,II,III, Sonic 3D Blast...) */ /* 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 else
{ {
/* Mode 5: HV counters are frozen (cf. lightgun games & Sunset Riders) */ /* Mode 5: H & V counters are frozen (cf. lightgun games, Sunset Riders logo) */
if (reg[1] & 4) 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 #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 #endif
/* return latched HVC value */ /* return latched HVC value */
return (data & 0xffff); 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 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; data &= 0xff;
} }
} }
@ -1413,6 +1405,7 @@ unsigned int vdp_hvc_r(unsigned int cycles)
vc = (vc & ~1) | ((vc >> 8) & 1); vc = (vc & ~1) | ((vc >> 8) & 1);
} }
/* return HCounter in LSB & VCounter in MSB */
data |= ((vc & 0xff) << 8); data |= ((vc & 0xff) << 8);
#ifdef LOGVDP #ifdef LOGVDP