improved Sega Mouse emulation (fixes Cannon Fodder mouse support)

This commit is contained in:
ekeeke31 2011-05-01 11:43:33 +00:00
parent 57c5d89380
commit 4a39669a8d

View File

@ -97,7 +97,7 @@ unsigned char mouse_read()
/* TL = busy status */ /* TL = busy status */
if (mouse.Wait) if (mouse.Wait)
{ {
/* wait before ACK, fix some buggy mouse routine (Shangai 2, Wack World,...) */ /* wait before ACK, fix some buggy mouse routine (Cannon Fodder, Shangai 2, Wack World,...) */
mouse.Wait = 0; mouse.Wait = 0;
/* TL = !TR */ /* TL = !TR */
@ -117,36 +117,26 @@ void mouse_write(unsigned char data, unsigned char mask)
/* update bits set as output only */ /* update bits set as output only */
data = (mouse.State & ~mask) | (data & mask); data = (mouse.State & ~mask) | (data & mask);
if (mouse.Counter == 0) /* TH transition */
if ((mouse.State ^ data) & 0x40)
{ {
/* wait for TH 1->0 transition */ /* start (TH=0) or stop (TH=1) acquisition */
if ((mouse.State & 0x40) && !(data & 0x40)) mouse.Counter = 1 - ((data & 0x40) >> 6);
{
/* start acquisition */
mouse.Counter = 1;
} }
}
else /* TR transition */
{
/* TR handshake */
if ((mouse.State ^ data) & 0x20) if ((mouse.State ^ data) & 0x20)
{ {
/* increment phase */ /* acquisition in progress */
if (mouse.Counter < 10) if ((mouse.Counter > 0) && (mouse.Counter < 10))
{ {
/* increment phase */
mouse.Counter++; mouse.Counter++;
} }
/* input latency */ /* TL handshake latency */
mouse.Wait = 1; mouse.Wait = 1;
} }
}
/* end of acquisition (TH=1) */
if (data & 0x40)
{
mouse.Counter = 0;
}
/* update internal state */ /* update internal state */
mouse.State = data; mouse.State = data;