Sunday, June 21, 2020

DIY NES to Atari Controller Adapter

I wanted to use my favorite NES controller with my controller-less Atari 65XE and 130XE. The NES controller uses a shift register, while the Atari expects 5 simple buttons. I wrote a simple Arduino program to convert one to the other. Using an Arduino mini, it fits in this little inline enclosure.






#define strobe 3 //PORTD
#define clk 4
#define data 2
void setup() {
DDRD = 1 | (1<<strobe) | (1<<clk); // NES outputs
}
void pulse_pin(byte pin, byte del) {
PORTD |= (1<<pin); //set
delayMicroseconds(del);
PORTD &= ~(1<<pin); //clear
delayMicroseconds(del);
}
void loop() {
byte btns = 0;
pulse_pin(strobe, 10); //latch the controller
for(int i = 0; i < 8; i++) { //read 8 bits
btns = btns << 1 | !(PIND & (1<<data));
pulse_pin(clk, 10); //clock next bit
}
// atari output d12-d8, open collector
DDRB = (btns & 0xf) | (!!(btns & 0xc0) << 4); // dpad + A||B
}

No comments:

Post a Comment