From c5cc7d93afb9a5cc042d173c40c111ad2667d391 Mon Sep 17 00:00:00 2001 From: EkeEke Date: Thu, 27 Jun 2013 01:49:10 +0200 Subject: [PATCH] [Core/Input] added support for XE-A1P analog controller on both ports --- core/input_hw/activator.c | 8 ++--- core/input_hw/input.c | 13 +++++-- core/input_hw/paddle.c | 4 +-- core/input_hw/sportspad.c | 8 ++--- core/input_hw/xe_a1p.c | 74 +++++++++++++++++++++++++-------------- core/input_hw/xe_a1p.h | 8 +++-- core/io_ctrl.c | 11 ++++-- gx/gui/menu.c | 6 ---- 8 files changed, 82 insertions(+), 50 deletions(-) diff --git a/core/input_hw/activator.c b/core/input_hw/activator.c index f6fbdc9..2af22db 100644 --- a/core/input_hw/activator.c +++ b/core/input_hw/activator.c @@ -51,15 +51,15 @@ void activator_reset(int index) activator[index].Counter = 0; } -INLINE unsigned char activator_read(int port) +INLINE unsigned char activator_read(int index) { /* IR sensors 1-16 data (active low) */ - uint16 data = ~input.pad[port << 2]; + uint16 data = ~input.pad[index << 2]; /* D1 = D0 (data is ready) */ - uint8 temp = (activator[port].State & 0x01) << 1; + uint8 temp = (activator[index].State & 0x01) << 1; - switch (activator[port].Counter) + switch (activator[index].Counter) { case 0: /* x x x x 0 1 0 0 */ temp |= 0x04; diff --git a/core/input_hw/input.c b/core/input_hw/input.c index 3ddced7..4506c1a 100644 --- a/core/input_hw/input.c +++ b/core/input_hw/input.c @@ -198,6 +198,13 @@ void input_init(void) break; } + case SYSTEM_XE_A1P: + { + input.dev[4] = DEVICE_XE_A1P; + player++; + break; + } + case SYSTEM_MENACER: { input.dev[4] = DEVICE_LIGHTGUN; @@ -305,19 +312,19 @@ void input_reset(void) case DEVICE_XE_A1P: { - xe_a1p_reset(); + xe_a1p_reset(i); break; } case DEVICE_PADDLE: { - paddle_reset(i >> 2); + paddle_reset(i); break; } case DEVICE_SPORTSPAD: { - sportspad_reset(i >> 2); + sportspad_reset(i); break; } diff --git a/core/input_hw/paddle.c b/core/input_hw/paddle.c index 93f500f..2fa7093 100644 --- a/core/input_hw/paddle.c +++ b/core/input_hw/paddle.c @@ -45,8 +45,8 @@ static struct void paddle_reset(int index) { - input.analog[index << 2][0] = 128; - paddle[index].State = 0x40; + input.analog[index][0] = 128; + paddle[index>>2].State = 0x40; } INLINE unsigned char paddle_read(int port) diff --git a/core/input_hw/sportspad.c b/core/input_hw/sportspad.c index 03e176e..48154e1 100644 --- a/core/input_hw/sportspad.c +++ b/core/input_hw/sportspad.c @@ -46,10 +46,10 @@ static struct void sportspad_reset(int index) { - input.analog[index << 2][0] = 128; - input.analog[index << 2][1] = 128; - sportspad[index].State = 0x40; - sportspad[index].Counter = 0; + input.analog[index][0] = 128; + input.analog[index][1] = 128; + sportspad[index>>2].State = 0x40; + sportspad[index>>2].Counter = 0; } INLINE unsigned char sportspad_read(int port) diff --git a/core/input_hw/xe_a1p.c b/core/input_hw/xe_a1p.c index 0cb702f..8821ff9 100644 --- a/core/input_hw/xe_a1p.c +++ b/core/input_hw/xe_a1p.c @@ -43,39 +43,41 @@ static struct uint8 State; uint8 Counter; uint8 Latency; -} xe_a1p; +} xe_a1p[2]; -void xe_a1p_reset(void) +void xe_a1p_reset(int index) { - input.analog[0][0] = 128; - input.analog[0][1] = 128; - input.analog[1][0] = 128; - xe_a1p.State = 0x40; - xe_a1p.Counter = 0; - xe_a1p.Latency = 0; + input.analog[index][0] = 128; + input.analog[index][1] = 128; + input.analog[index+1][0] = 128; + index >>= 2; + xe_a1p[index].State = 0x40; + xe_a1p[index].Counter = 0; + xe_a1p[index].Latency = 0; } -unsigned char xe_a1p_read() +INLINE unsigned char xe_a1p_read(int index) { unsigned int temp = 0x40; + unsigned int port = index << 2; /* Left Stick X & Y analog values (bidirectional) */ - int x = input.analog[0][0]; - int y = input.analog[0][1]; + int x = input.analog[port][0]; + int y = input.analog[port][1]; /* Right Stick X or Y value (unidirectional) */ - int z = input.analog[1][0]; + int z = input.analog[port+1][0]; /* Buttons status (active low) */ - uint16 pad = ~input.pad[0]; + uint16 pad = ~input.pad[port]; /* Current internal cycle (0-7) */ - unsigned int cycle = xe_a1p.Counter & 7; + unsigned int cycle = xe_a1p[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_a1p.Counter >> 2) + switch (xe_a1p[index].Counter >> 2) { case 0: temp |= ((pad >> 8) & 0x0F); /* E1 E2 Start Select */ @@ -119,42 +121,62 @@ unsigned char xe_a1p_read() cycle = (cycle + 1) & 7; /* Update internal cycle counter */ - xe_a1p.Counter = (xe_a1p.Counter & ~7) | cycle; + xe_a1p[index].Counter = (xe_a1p[index].Counter & ~7) | cycle; /* Update internal latency on each read */ - xe_a1p.Latency++; + xe_a1p[index].Latency++; return temp; } -void xe_a1p_write(unsigned char data, unsigned char mask) +INLINE void xe_a1p_write(int index, unsigned char data, unsigned char mask) { /* update bits set as output only */ - data = (xe_a1p.State & ~mask) | (data & mask); + data = (xe_a1p[index].State & ~mask) | (data & mask); /* look for TH 1->0 transitions */ - if (!(data & 0x40) && (xe_a1p.State & 0x40)) + if (!(data & 0x40) && (xe_a1p[index].State & 0x40)) { /* reset acquisition cycle */ - xe_a1p.Latency = xe_a1p.Counter = 0; + xe_a1p[index].Latency = xe_a1p[index].Counter = 0; } else { /* some games immediately write new data to TH */ /* so we make sure first sequence has actually been handled */ - if (xe_a1p.Latency > 2) + if (xe_a1p[index].Latency > 2) { /* next acquisition sequence */ - xe_a1p.Counter = (xe_a1p.Counter & ~7) + 8; + xe_a1p[index].Counter = (xe_a1p[index].Counter & ~7) + 8; /* 5 sequence max with 8 cycles each */ - if (xe_a1p.Counter > 32) + if (xe_a1p[index].Counter > 32) { - xe_a1p.Counter = 32; + xe_a1p[index].Counter = 32; } } } /* update internal state */ - xe_a1p.State = data; + xe_a1p[index].State = data; +} + +unsigned char xe_a1p_1_read(void) +{ + return xe_a1p_read(0); +} + +unsigned char xe_a1p_2_read(void) +{ + return xe_a1p_read(1); +} + +void xe_a1p_1_write(unsigned char data, unsigned char mask) +{ + xe_a1p_write(0, data, mask); +} + +void xe_a1p_2_write(unsigned char data, unsigned char mask) +{ + xe_a1p_write(1, data, mask); } diff --git a/core/input_hw/xe_a1p.h b/core/input_hw/xe_a1p.h index 66b0360..7c474ed 100644 --- a/core/input_hw/xe_a1p.h +++ b/core/input_hw/xe_a1p.h @@ -40,8 +40,10 @@ #define _XE_A1PH_ /* Function prototypes */ -extern void xe_a1p_reset(void); -extern unsigned char xe_a1p_read(void); -extern void xe_a1p_write(unsigned char data, unsigned char mask); +extern void xe_a1p_reset(int index); +extern unsigned char xe_a1p_1_read(void); +extern unsigned char xe_a1p_2_read(void); +extern void xe_a1p_1_write(unsigned char data, unsigned char mask); +extern void xe_a1p_2_write(unsigned char data, unsigned char mask); #endif diff --git a/core/io_ctrl.c b/core/io_ctrl.c index 2b4f924..8d476ab 100644 --- a/core/io_ctrl.c +++ b/core/io_ctrl.c @@ -110,8 +110,8 @@ void io_init(void) case SYSTEM_XE_A1P: { - port[0].data_w = xe_a1p_write; - port[0].data_r = xe_a1p_read; + port[0].data_w = xe_a1p_1_write; + port[0].data_r = xe_a1p_1_read; break; } @@ -181,6 +181,13 @@ void io_init(void) break; } + case SYSTEM_XE_A1P: + { + port[1].data_w = xe_a1p_2_write; + port[1].data_r = xe_a1p_2_read; + break; + } + case SYSTEM_ACTIVATOR: { port[1].data_w = activator_2_write; diff --git a/gx/gui/menu.c b/gx/gui/menu.c index 5788cde..b3beba6 100644 --- a/gx/gui/menu.c +++ b/gx/gui/menu.c @@ -2183,12 +2183,6 @@ static void ctrlmenu(void) input.system[1] += 2; } - /* XE-1AP on port A only */ - if (input.system[1] == SYSTEM_XE_A1P) - { - input.system[1]++; - } - /* 4-wayplay uses both ports */ if (input.system[1] == SYSTEM_WAYPLAY) {