Skip to content

Commit

Permalink
Merge pull request #145 from iequalshane/master
Browse files Browse the repository at this point in the history
Fixed an issue where an EA 4-way multitap could be incorrectly detected.
  • Loading branch information
Stephane-D committed Jul 31, 2019
2 parents b728267 + 461148f commit 6822a34
Showing 1 changed file with 49 additions and 41 deletions.
90 changes: 49 additions & 41 deletions src/joy.c
Expand Up @@ -46,36 +46,44 @@ void JOY_reset()
vu8 *pb;
u8 a, id;
u16 i;
#if (HALT_Z80_ON_IO == 1)
u16 z80state;
#endif
#if (HALT_Z80_ON_IO == 1)
u16 z80state;
#endif

gport = 0xFFFF;

/* disable ints */
SYS_disableInts();

#if (HALT_Z80_ON_IO == 1)
z80state = Z80_isBusTaken();
if (!z80state) Z80_requestBus(FALSE);
#if (HALT_Z80_ON_IO == 1)
z80state = Z80_isBusTaken();
if (!z80state) Z80_requestBus(FALSE);
#endif

/* check for EA 4-Way Play */
pb = (vu8 *)0xa10009;
*pb = 0x40;
pb = (vu8 *)0xa1000b;
*pb = 0x43;
pb = (vu8 *)0xa10005;
*pb = 0x7C;
pb = (vu8 *)0xa1000b;
*pb = 0x7F;
pb = (vu8 *)0xa10003;
*pb = 0x40;

pb = (vu8 *)0xa10005;
*pb = 0x7C;
*pb = 0x0C;
asm volatile ("nop");
asm volatile ("nop");
pb = (vu8 *)0xa10003;
a = *pb & 3;

pb = (vu8 *)0xa10005;
*pb = 0x7C;
asm volatile ("nop");
asm volatile ("nop");
pb = (vu8 *)0xa10003;
b = *pb & 3;

/* EA 4-Way Play detected */
if (a == 0)
if (a != 0 && b == 0)
{
/* EA 4-Way Play is the only thing that can be plugged in as it takes both ports */
portType[PORT_1] = PORT_TYPE_EA4WAYPLAY;
Expand Down Expand Up @@ -113,17 +121,17 @@ void JOY_reset()
pb += 2;
*pb = 0x40;

#if (HALT_Z80_ON_IO == 1)
if (!z80state) Z80_releaseBus();
#if (HALT_Z80_ON_IO == 1)
if (!z80state) Z80_releaseBus();
#endif

/* need to wait */
VDP_waitVSync();
VDP_waitVSync();

#if (HALT_Z80_ON_IO == 1)
z80state = Z80_isBusTaken();
if (!z80state) Z80_requestBus(FALSE);
#if (HALT_Z80_ON_IO == 1)
z80state = Z80_isBusTaken();
if (!z80state) Z80_requestBus(FALSE);
#endif

/* get ID port 1 */
Expand Down Expand Up @@ -223,8 +231,8 @@ void JOY_reset()
}
}

#if (HALT_Z80_ON_IO == 1)
if (!z80state) Z80_releaseBus();
#if (HALT_Z80_ON_IO == 1)
if (!z80state) Z80_releaseBus();
#endif

/* now update pads to reflect true type (3 or 6 button) */
Expand Down Expand Up @@ -255,25 +263,25 @@ static void externalIntCB()
{
vu8 *pb;
u16 hv;
#if (HALT_Z80_ON_IO == 1)
u16 z80state;
#endif
#if (HALT_Z80_ON_IO == 1)
u16 z80state;
#endif

hv = GET_HVCOUNTER; /* read HV counter */

if (extSet || (gport == 0xFFFF)) return;

#if (HALT_Z80_ON_IO == 1)
z80state = Z80_isBusTaken();
if (!z80state) Z80_requestBus(FALSE);
#if (HALT_Z80_ON_IO == 1)
z80state = Z80_isBusTaken();
if (!z80state) Z80_requestBus(FALSE);
#endif

pb = (vu8 *)0xa10003 + gport*2;
if (portType[gport] == PORT_TYPE_JUSTIFIER)
*pb = gun | 0x10; /* deselect gun */

#if (HALT_Z80_ON_IO == 1)
if (!z80state) Z80_releaseBus();
#if (HALT_Z80_ON_IO == 1)
if (!z80state) Z80_releaseBus();
#endif

if (!gun)
Expand All @@ -294,15 +302,15 @@ static void externalIntCB()

void JOY_setSupport(u16 port, u16 support)
{
#if (HALT_Z80_ON_IO == 1)
u16 z80state;
#if (HALT_Z80_ON_IO == 1)
u16 z80state;
#endif

if (port > PORT_2) return;

#if (HALT_Z80_ON_IO == 1)
z80state = Z80_isBusTaken();
if (!z80state) Z80_requestBus(FALSE);
#if (HALT_Z80_ON_IO == 1)
z80state = Z80_isBusTaken();
if (!z80state) Z80_requestBus(FALSE);
#endif

if ((portType[port] == PORT_TYPE_MENACER) || (portType[port] == PORT_TYPE_JUSTIFIER))
Expand Down Expand Up @@ -466,8 +474,8 @@ void JOY_setSupport(u16 port, u16 support)
else
portSupport[port] = support;

#if (HALT_Z80_ON_IO == 1)
if (!z80state) Z80_releaseBus();
#if (HALT_Z80_ON_IO == 1)
if (!z80state) Z80_releaseBus();
#endif
}

Expand Down Expand Up @@ -1125,16 +1133,16 @@ void JOY_update()
u16 val;
u16 newstate;
u16 change;
#if (HALT_Z80_ON_IO == 1)
u16 z80state;
#if (HALT_Z80_ON_IO == 1)
u16 z80state;
#endif

/* disable ints */
SYS_disableInts();

#if (HALT_Z80_ON_IO == 1)
z80state = Z80_isBusTaken();
if (!z80state) Z80_requestBus(FALSE);
#if (HALT_Z80_ON_IO == 1)
z80state = Z80_isBusTaken();
if (!z80state) Z80_requestBus(FALSE);
#endif

switch (portSupport[PORT_1])
Expand Down Expand Up @@ -1253,8 +1261,8 @@ void JOY_update()
break;
}

#if (HALT_Z80_ON_IO == 1)
if (!z80state) Z80_releaseBus();
#if (HALT_Z80_ON_IO == 1)
if (!z80state) Z80_releaseBus();
#endif

/* restore ints */
Expand Down

0 comments on commit 6822a34

Please sign in to comment.