[Core/IO] improved XE-1AP controller emulation

This commit is contained in:
EkeEke 2015-08-26 23:32:25 +02:00
parent 00b0cc6d71
commit 9476daf1e9
5 changed files with 77 additions and 82 deletions

View File

@ -76,7 +76,8 @@ Genesis Plus GX 1.7.5 (xx/xx/xxxx) (Eke-Eke)
* added Sega Graphic Board support (thanks to SMS Power) * added Sega Graphic Board support (thanks to SMS Power)
* added Master Tap emulation (multi-player support in Boom homebrew) * added Master Tap emulation (multi-player support in Boom homebrew)
* added gamepad type auto-detection * added gamepad type auto-detection
* added support for XE-1AP analog controller on both ports * added support for XE-1AP controller on both ports
* improved XE-1AP controller emulation
* improved HVC latch behavior for gun emulation (fixes "Gunfight - 3 in 1" randomization when using Justifier) * improved HVC latch behavior for gun emulation (fixes "Gunfight - 3 in 1" randomization when using Justifier)
* fixed TeamPlayer emulation (fixes multitap detection in Gauntlet 4) * fixed TeamPlayer emulation (fixes multitap detection in Gauntlet 4)

View File

@ -2,8 +2,8 @@
* Genesis Plus * Genesis Plus
* Input peripherals support * Input peripherals support
* *
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Copyright (C) 1998-2003 Charles Mac Donald (original code)
* Copyright (C) 2007-2014 Eke-Eke (Genesis Plus GX) * Copyright (C) 2007-2015 Eke-Eke (Genesis Plus GX)
* *
* Redistribution and use of this code or any derivative works are permitted * Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met: * provided that the following conditions are met:

View File

@ -2,8 +2,8 @@
* Genesis Plus * Genesis Plus
* Input peripherals support * Input peripherals support
* *
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Copyright (C) 1998-2003 Charles Mac Donald (original code)
* Copyright (C) 2007-2014 Eke-Eke (Genesis Plus GX) * Copyright (C) 2007-2015 Eke-Eke (Genesis Plus GX)
* *
* Redistribution and use of this code or any derivative works are permitted * Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met: * provided that the following conditions are met:
@ -102,12 +102,14 @@
#define INPUT_PICO_RED (0x0010) #define INPUT_PICO_RED (0x0010)
/* XE-1AP specific bitmask */ /* XE-1AP specific bitmask */
#define INPUT_XE_E1 (0x0800) #define INPUT_XE_E1 (0x2000)
#define INPUT_XE_E2 (0x0400) #define INPUT_XE_E2 (0x1000)
#define INPUT_XE_START (0x0200) #define INPUT_XE_START (0x0800)
#define INPUT_XE_SELECT (0x0100) #define INPUT_XE_SELECT (0x0400)
#define INPUT_XE_A (0x0080) #define INPUT_XE_A (0x0200)
#define INPUT_XE_B (0x0040) #define INPUT_XE_B (0x0100)
#define INPUT_XE_A2 (0x0080)
#define INPUT_XE_B2 (0x0040)
#define INPUT_XE_C (0x0020) #define INPUT_XE_C (0x0020)
#define INPUT_XE_D (0x0010) #define INPUT_XE_D (0x0010)

View File

@ -2,7 +2,7 @@
* Genesis Plus * Genesis Plus
* XE-1AP analog controller support * XE-1AP analog controller support
* *
* Copyright (C) 2011-2014 Eke-Eke (Genesis Plus GX) * Copyright (C) 2011-2015 Eke-Eke (Genesis Plus GX)
* *
* Redistribution and use of this code or any derivative works are permitted * Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met: * provided that the following conditions are met:
@ -38,6 +38,8 @@
#include "shared.h" #include "shared.h"
#define XE_1AP_LATENCY 3
static struct static struct
{ {
uint8 State; uint8 State;
@ -52,109 +54,99 @@ void xe_1ap_reset(int index)
input.analog[index+1][0] = 128; input.analog[index+1][0] = 128;
index >>= 2; index >>= 2;
xe_1ap[index].State = 0x40; xe_1ap[index].State = 0x40;
xe_1ap[index].Counter = 0; xe_1ap[index].Counter = 11;
xe_1ap[index].Latency = 0; xe_1ap[index].Latency = 0;
} }
INLINE unsigned char xe_1ap_read(int index) INLINE unsigned char xe_1ap_read(int index)
{ {
unsigned int temp = 0x40; unsigned char data;
unsigned int port = index << 2; unsigned int port = index << 2;
/* Left Stick X & Y analog values (bidirectional) */ /* Current data transfer cycle */
int x = input.analog[port][0]; switch (xe_1ap[index].Counter)
int y = input.analog[port][1];
/* Right Stick X or Y value (unidirectional) */
int z = input.analog[port+1][0];
/* Buttons status (active low) */
uint16 pad = ~input.pad[port];
/* Current internal cycle (0-7) */
unsigned int cycle = xe_1ap[index].Counter & 7;
/* Current 4-bit data cycle */
/* There are eight internal data cycle for each 5 acquisition sequence */
/* First 4 return the same 4-bit data, next 4 return next 4-bit data */
switch (xe_1ap[index].Counter >> 2)
{ {
case 0: case 0: /* E1 E2 Start Select buttons status (active low) */
temp |= ((pad >> 8) & 0x0F); /* E1 E2 Start Select */ data = (~input.pad[port] >> 10) & 0x0F;
break; break;
case 1: case 1: /* A/A' B/B' C D buttons status (active low) */
temp |= ((pad >> 4) & 0x0F); /* A B C D */ data = ((~input.pad[port] >> 4) & 0x0F) & ~((input.pad[port] >> 6) & 0x0C);
break; break;
case 2: case 2: /* CH0 high (Analog Stick Left/Right direction) */
temp |= ((x >> 4) & 0x0F); data = (input.analog[port][0] >> 4) & 0x0F;
break; break;
case 3: case 3: /* CH1 high (Analog Stick Up/Down direction) */
temp |= ((y >> 4) & 0x0F); data = (input.analog[port][1] >> 4) & 0x0F;
break; break;
case 4: case 4: /* CH2 high (N/A) */
data = 0x0;
break; break;
case 5: case 5: /* CH3 high (Throttle vertical or horizontal direction) */
temp |= ((z >> 4) & 0x0F); data = (input.analog[port+1][0] >> 4) & 0x0F;
break; break;
case 6: case 6: /* CH0 low (Analog Stick Left/Right direction) */
temp |= (x & 0x0F); data = input.analog[port][0] & 0x0F;
break; break;
case 7: case 7: /* CH1 low (Analog Stick Up/Down direction)*/
temp |= (y & 0x0F); data = input.analog[port][1] & 0x0F;
break; break;
case 8: case 8: /* CH2 low (N/A) */
data = 0x0;
break; break;
case 9: case 9: /* CH3 low (Throttle vertical or horizontal direction) */
temp |= (z & 0x0F); data = input.analog[port+1][0] & 0x0F;
break;
case 10: /* A B A' B' buttons status (active low) */
data = (~input.pad[port] >> 6) & 0x0F;
break;
default: /* N/A */
data = 0x0F;
break; break;
} }
/* TL indicates which part of data is returned (0=1st part, 1=2nd part) */ /* TL indicates current data cycle (0=1st cycle, 1=2nd cycle, etc) */
temp |= ((cycle & 4) << 2); data |= ((xe_1ap[index].Counter & 1) << 4);
/* TR indicates if data is ready (0=ready, 1=not ready) */ /* TR indicates if data is valid (0=valid, 1=not ready) */
/* Fastest One input routine actually expects this bit to switch between 0 & 1 */ /* Some games expect this bit to switch between 0 and 1 */
/* so we make the first read of a data cycle return 1 then 0 for remaining reads */ /* so we actually keep it high for some reads after the */
temp |= (!(cycle & 3) << 5); /* data cycle has been initialized or incremented */
if (xe_1ap[index].Latency)
{
if (xe_1ap[index].Latency > 1)
{
/* data is not ready */
data |= 0x20;
}
/* Automatically increment data cycle on each read (within current acquisition sequence) */ /* decrement internal latency */
cycle = (cycle + 1) & 7; xe_1ap[index].Latency--;
}
else if (xe_1ap[index].Counter <= 10)
{
/* next data cycle */
xe_1ap[index].Counter++;
/* Update internal cycle counter */ /* reinitialize internal latency */
xe_1ap[index].Counter = (xe_1ap[index].Counter & ~7) | cycle; xe_1ap[index].Latency = XE_1AP_LATENCY;
}
/* Update internal latency on each read */ return data;
xe_1ap[index].Latency++;
return temp;
} }
INLINE void xe_1ap_write(int index, unsigned char data, unsigned char mask) INLINE void xe_1ap_write(int index, unsigned char data, unsigned char mask)
{ {
/* update bits set as output only */ /* only update bits set as output */
data = (xe_1ap[index].State & ~mask) | (data & mask); data = (xe_1ap[index].State & ~mask) | (data & mask);
/* look for TH 1->0 transitions */ /* look for TH 1->0 transitions */
if (!(data & 0x40) && (xe_1ap[index].State & 0x40)) if (!(data & 0x40) && (xe_1ap[index].State & 0x40))
{ {
/* reset acquisition cycle */ /* reset data acquisition cycle */
xe_1ap[index].Latency = xe_1ap[index].Counter = 0; xe_1ap[index].Counter = 0;
}
else
{
/* some games immediately write new data to TH */
/* so we make sure first sequence has actually been handled */
if (xe_1ap[index].Latency > 2)
{
/* next acquisition sequence */
xe_1ap[index].Counter = (xe_1ap[index].Counter & ~7) + 8;
/* 5 sequence max with 8 cycles each */ /* initialize internal latency */
if (xe_1ap[index].Counter > 32) xe_1ap[index].Latency = XE_1AP_LATENCY;
{
xe_1ap[index].Counter = 32;
}
}
} }
/* update internal state */ /* update internal state */

View File

@ -2,7 +2,7 @@
* Genesis Plus * Genesis Plus
* XE-1AP analog controller support * XE-1AP analog controller support
* *
* Copyright (C) 2011-2014 Eke-Eke (Genesis Plus GX) * Copyright (C) 2011-2015 Eke-Eke (Genesis Plus GX)
* *
* Redistribution and use of this code or any derivative works are permitted * Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met: * provided that the following conditions are met: