Small change to Sega two controller adapter wiring.

Small change to Sega two controller adapter wiring. Wiring diagrams added for Sega two controller adapter and NES/SNES adapters.
This commit is contained in:
MickGyver
2020-03-02 11:24:26 +02:00
parent 32e910d3a6
commit 1015f20cd3
9 changed files with 50 additions and 17 deletions

View File

@@ -33,25 +33,28 @@
SegaControllers32U4::SegaControllers32U4(void)
{
// Setup select pin as output high (16, PB2)
DDRB |= B00000100; // output
PORTB |= B00000100; // high
// Setup select pin as output high (6, PD7)
DDRD |= B10000000; // output
PORTD |= B10000000; // high
// Setup select pin as output high (5, PC6)
DDRC |= B01000000; // output
PORTC |= B01000000; // high
// Setup input pins (A0,A1,A2,A3,14,15,16 or PF7,PF6,PF5,PF4,PB3,PB1,PB2)
// Setup input pins (A0,A1,A2,A3,14,15 or PF7,PF6,PF5,PF4,PB3,PB1)
DDRF &= ~B11110000; // input
PORTF |= B11110000; // high to enable internal pull-up
DDRB &= ~B00001010; // input
PORTB |= B00001010; // high to enable internal pull-up
// Setup input pins (TXO,RXI,2,3,4,6 or PD3,PD2,PD1,PD0,PD4,PD7)
DDRD &= ~B10011111; // input
PORTD |= B10011111; // high to enable internal pull-up
// Setup input pins (TXO,RXI,2,3,4,6 or PD3,PD2,PD1,PD0,PD4,PE6)
DDRD &= ~B00011111; // input
PORTD |= B00011111; // high to enable internal pull-up
DDRE &= ~B01000000; // input
PORTE |= B01000000; // high to enable internal pull-up
_inputReg1 = 0;
_inputReg2 = 0;
_inputReg3 = 0;
_inputReg4 = 0;
for(byte i=0; i<=1; i++)
{
_currentState[i] = 0;
@@ -77,7 +80,7 @@ word SegaControllers32U4::getStateMD1()
// Set the select pin low/high
_pinSelect[0] = !_pinSelect[0];
(!_pinSelect[0]) ? PORTB &= ~B00000100 : PORTB |= B00000100; // Set LOW on even cycle, HIGH on uneven cycle
(!_pinSelect[0]) ? PORTD &= ~B10000000 : PORTD |= B10000000; // Set LOW on even cycle, HIGH on uneven cycle
// Short delay to stabilise outputs in controller
delayMicroseconds(SC_CYCLE_DELAY);
@@ -166,6 +169,7 @@ word SegaControllers32U4::getStateMD2()
// Read input register(s)
_inputReg3 = PIND;
_inputReg4 = PINE;
if(_ignoreCycles[1] <= 0)
{
@@ -192,7 +196,7 @@ word SegaControllers32U4::getStateMD2()
(bitRead(_inputReg3, DB9_PIN3_BIT2) == LOW) ? _currentState[1] |= SC_BTN_LEFT : _currentState[1] &= ~SC_BTN_LEFT;
(bitRead(_inputReg3, DB9_PIN4_BIT2) == LOW) ? _currentState[1] |= SC_BTN_RIGHT : _currentState[1] &= ~SC_BTN_RIGHT;
(bitRead(_inputReg3, DB9_PIN6_BIT2) == LOW) ? _currentState[1] |= SC_BTN_B : _currentState[1] &= ~SC_BTN_B;
(bitRead(_inputReg3, DB9_PIN9_BIT2) == LOW) ? _currentState[1] |= SC_BTN_C : _currentState[1] &= ~SC_BTN_C;
(bitRead(_inputReg4, DB9_PIN9_BIT2) == LOW) ? _currentState[1] |= SC_BTN_C : _currentState[1] &= ~SC_BTN_C;
}
}
else // No Mega Drive controller is connected, use SMS/Atari mode
@@ -206,7 +210,7 @@ word SegaControllers32U4::getStateMD2()
if (bitRead(_inputReg3, DB9_PIN3_BIT2) == LOW) { _currentState[1] |= SC_BTN_LEFT; }
if (bitRead(_inputReg3, DB9_PIN4_BIT2) == LOW) { _currentState[1] |= SC_BTN_RIGHT; }
if (bitRead(_inputReg3, DB9_PIN6_BIT2) == LOW) { _currentState[1] |= SC_BTN_A; }
if (bitRead(_inputReg3, DB9_PIN9_BIT2) == LOW) { _currentState[1] |= SC_BTN_B; }
if (bitRead(_inputReg4, DB9_PIN9_BIT2) == LOW) { _currentState[1] |= SC_BTN_B; }
}
}
else // Select pin is LOW
@@ -223,7 +227,7 @@ word SegaControllers32U4::getStateMD2()
if(!_sixButtonMode[1])
{
(bitRead(_inputReg3, DB9_PIN6_BIT2) == LOW) ? _currentState[1] |= SC_BTN_A : _currentState[1] &= ~SC_BTN_A;
(bitRead(_inputReg3, DB9_PIN9_BIT2) == LOW) ? _currentState[1] |= SC_BTN_START : _currentState[1] &= ~SC_BTN_START;
(bitRead(_inputReg4, DB9_PIN9_BIT2) == LOW) ? _currentState[1] |= SC_BTN_START : _currentState[1] &= ~SC_BTN_START;
}
}
}