diff --git a/core/input_hw/teamplayer.c b/core/input_hw/teamplayer.c index bca12a1..b1bd006 100644 --- a/core/input_hw/teamplayer.c +++ b/core/input_hw/teamplayer.c @@ -2,7 +2,7 @@ * Genesis Plus * Team Player support * - * Copyright (C) 2007-2011 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2014 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -87,18 +87,20 @@ INLINE unsigned int teamplayer_read(int port) /* acquisition sequence */ switch (counter) { - case 0: /* initial state: TH = 1, TR = 1 -> RLDU = 0011 */ + case 0: /* initial state: xxx0011 */ { - return 0x73; + /* TL should match TR */ + return ((teamplayer[port].State & 0x20) >> 1) | 0x03; } - case 1: /* start request: TH = 0, TR = 1 -> RLDU = 1111 */ + case 1: /* start request: xxx1111 */ { - return 0x3F; + /* TL should match TR */ + return ((teamplayer[port].State & 0x20) >> 1) | 0x0F; } case 2: - case 3: /* ack request: TH=0, TR=0/1 -> RLDU = 0000 */ + case 3: /* ack request: xxx0000 */ { /* TL should match TR */ return ((teamplayer[port].State & 0x20) >> 1); @@ -107,7 +109,7 @@ INLINE unsigned int teamplayer_read(int port) case 4: case 5: case 6: - case 7: /* PAD type */ + case 7: /* PAD type: xxx0000 (3B), xxx0001 (6B) or xxx1111 (NC)*/ { unsigned int retval = input.dev[(port << 2) + (counter - 4)]; @@ -115,7 +117,7 @@ INLINE unsigned int teamplayer_read(int port) return (((teamplayer[port].State & 0x20) >> 1) | retval); } - default: /* PAD status */ + default: /* PAD status: xxxRLDU -> xxxSACB -> xxxMXYZ */ { unsigned int retval = 0x0F; @@ -136,23 +138,22 @@ INLINE void teamplayer_write(int port, unsigned char data, unsigned char mask) /* update bits set as output only */ unsigned int state = (teamplayer[port].State & ~mask) | (data & mask); - /* TH & TR handshaking */ - if ((teamplayer[port].State ^ state) & 0x60) + /* check if TH is HIGH */ + if (state & 0x40) { - if (state & 0x40) - { - /* TH high -> reset counter */ - teamplayer[port].Counter = 0; - } - else - { - /* increment counter */ - teamplayer[port].Counter++; - } - - /* update internal state */ - teamplayer[port].State = state; + /* reset counter */ + teamplayer[port].Counter = 0; } + + /* TH & TR handshaking */ + else if ((teamplayer[port].State ^ state) & 0x60) + { + /* increment counter */ + teamplayer[port].Counter++; + } + + /* update internal state */ + teamplayer[port].State = state; } unsigned char teamplayer_1_read(void) diff --git a/core/input_hw/teamplayer.h b/core/input_hw/teamplayer.h index 6e53c31..ea0e848 100644 --- a/core/input_hw/teamplayer.h +++ b/core/input_hw/teamplayer.h @@ -2,7 +2,7 @@ * Genesis Plus * Team Player support * - * Copyright (C) 2007-2011 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2014 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: diff --git a/core/io_ctrl.c b/core/io_ctrl.c index f221bf5..398b8f8 100644 --- a/core/io_ctrl.c +++ b/core/io_ctrl.c @@ -5,7 +5,7 @@ * Support for Master System (315-5216, 315-5237 & 315-5297), Game Gear & Mega Drive I/O chips * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) - * Copyright (C) 2007-2013 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2014 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -80,16 +80,9 @@ void io_init(void) /* Initialize IO Ports handlers & connected peripherals */ switch (input.system[0]) { - case SYSTEM_MS_GAMEPAD: + case SYSTEM_GAMEPAD: { - port[0].data_w = dummy_write; - port[0].data_r = gamepad_1_read; - break; - } - - case SYSTEM_MD_GAMEPAD: - { - port[0].data_w = gamepad_1_write; + port[0].data_w = (input.dev[0] == DEVICE_PAD2B) ? dummy_write : gamepad_1_write; port[0].data_r = gamepad_1_read; break; } @@ -160,16 +153,9 @@ void io_init(void) switch (input.system[1]) { - case SYSTEM_MS_GAMEPAD: + case SYSTEM_GAMEPAD: { - port[1].data_w = dummy_write; - port[1].data_r = gamepad_2_read; - break; - } - - case SYSTEM_MD_GAMEPAD: - { - port[1].data_w = gamepad_2_write; + port[1].data_w = (input.dev[4] == DEVICE_PAD2B) ? dummy_write : gamepad_2_write; port[1].data_r = gamepad_2_read; break; } diff --git a/core/io_ctrl.h b/core/io_ctrl.h index addc259..ca3d6be 100644 --- a/core/io_ctrl.h +++ b/core/io_ctrl.h @@ -5,7 +5,7 @@ * Support for Master System (315-5216, 315-5237 & 315-5297), Game Gear & Mega Drive I/O chips * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) - * Copyright (C) 2007-2013 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2007-2014 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: