Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/nes2wii.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2014-01-29 07:52:31 +0400
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2014-01-29 07:52:31 +0400
commitc6e7d03e816434eeb74b0e66f409ac7385252d99 (patch)
tree28a05c520058363ffce50c113457ea824ae17455
parentb8c86f45da2b70f97c974a590103804a98ecd005 (diff)
Gamepad functions moved to gamepad.c
-rw-r--r--Makefile2
-rw-r--r--defines.h7
-rw-r--r--gamepad.c212
-rw-r--r--gamepad.h54
-rw-r--r--main.c118
-rw-r--r--nes2wii.h36
6 files changed, 281 insertions, 148 deletions
diff --git a/Makefile b/Makefile
index d1142d8..0529140 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
PRG = nes2wii
-OBJ = main.o wiimote.o
+OBJ = main.o wiimote.o gamepad.o
LFUSE = CF
HFUSE = C9
MCU_PROGRAMMER = m16
diff --git a/defines.h b/defines.h
index bbd2069..324d9b9 100644
--- a/defines.h
+++ b/defines.h
@@ -34,6 +34,13 @@
#define SMD_DATA4_PIN 6
#define SMD_DATA5_PIN 7
+#define DUALSHOCK_ENABLED
+#define DUALSHOCK_PORT D
+#define DUALSHOCK_DATA_PIN 2
+#define DUALSHOCK_COMMAND_PIN 3
+#define DUALSHOCK_ATTENTION_PIN 5
+#define DUALSHOCK_CLOCK_PIN 5
+
#define RED_LED_PORT B
#define RED_LED_PIN 4
#define GREEN_LED_PORT B
diff --git a/gamepad.c b/gamepad.c
new file mode 100644
index 0000000..dd6967a
--- /dev/null
+++ b/gamepad.c
@@ -0,0 +1,212 @@
+#include "defines.h"
+#include <avr/io.h>
+#include <util/delay.h>
+#include "gamepad.h"
+
+void init_nes_gamepad()
+{
+ NES_PORT_DDR |= 1<<NES_LATCH_PIN; // Latch, output
+ NES_PORT_DDR |= 1<<NES_CLOCK_PIN; // Clock, output
+ NES_PORT_DDR &= ~(1<<NES_DATA_PIN); // Data, input
+ NES_PORT_PORT |= 1<<NES_DATA_PIN; // Data, pull-up
+}
+
+uint8_t get_nes_gamepad()
+{
+ uint8_t gamepad_data = 0;
+ NES_PORT_PORT &= ~(1<<NES_LATCH_PIN); // Latch
+ int b;
+ for (b = 0; b < 8; b++)
+ {
+ NES_PORT_PORT &= ~(1<<NES_CLOCK_PIN); // Clock
+ _delay_us(10);
+ gamepad_data |= (((NES_PORT_PIN>>NES_DATA_PIN)&1)<<b);
+ NES_PORT_PORT |= 1<<NES_CLOCK_PIN; // Clock
+ _delay_us(10);
+ }
+ NES_PORT_PORT |= 1<<NES_LATCH_PIN; // Latch
+ return gamepad_data;
+}
+
+void init_snes_gamepad()
+{
+ SNES_PORT_DDR |= 1<<SNES_LATCH_PIN; // Latch, output
+ SNES_PORT_DDR |= 1<<SNES_CLOCK_PIN; // Clock, output
+ SNES_PORT_DDR &= ~(1<<SNES_DATA_PIN); // Data, input
+ SNES_PORT_PORT |= 1<<SNES_DATA_PIN; // Data, pull-up
+}
+
+uint16_t get_snes_gamepad()
+{
+ uint16_t gamepad_data = 0;
+ SNES_PORT_PORT &= ~(1<<SNES_LATCH_PIN); // Latch
+ int b;
+ for (b = 0; b < 16; b++)
+ {
+ SNES_PORT_PORT &= ~(1<<SNES_CLOCK_PIN); // Clock
+ _delay_us(10);
+ gamepad_data |= ((uint16_t)((SNES_PORT_PIN>>SNES_DATA_PIN)&1)<<b);
+ SNES_PORT_PORT |= 1<<SNES_CLOCK_PIN; // Clock
+ _delay_us(10);
+ }
+ SNES_PORT_PORT |= 1<<SNES_LATCH_PIN; // Latch
+ return gamepad_data;
+}
+
+void init_n64_gamepad()
+{
+ TCCR0 |= _BV(CS00); // Timer
+ N64_PORT_DDR &= ~(1<<N64_DATA_PIN); // Input
+ N64_PORT_PORT &= ~(1<<N64_DATA_PIN); // No pull-up (using external resistor)
+}
+
+int get_n64_gamepad(uint8_t* data)
+{
+ int b, bit;
+ N64SEND_0; N64SEND_0; N64SEND_0; N64SEND_0; N64SEND_0; N64SEND_0; N64SEND_0; N64SEND_1; N64SEND_STOP;
+ for (b = 0; b < 4; b++)
+ {
+ data[b] = 0;
+ for (bit = 0; bit < 8; bit++)
+ {
+ TCNT0 = 0;
+ while (!N64SIGNAL) if (TCNT0 >= 0xF0) return 0;
+ TCNT0 = 0;
+ while(N64SIGNAL) if (TCNT0 >= 0xF0) return 0;
+ data[b] = data[b]<<1;
+ if (TCNT0 < 0x24 * F_CPU / 20000000UL) data[b] |= 1;
+ }
+ }
+ return 1;
+}
+
+void init_smd_gamepad()
+{
+ SMD_SELECT_PORT_DDR |= 1<<SMD_SELECT_PIN; // Select, output
+ SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA0_PIN); // Data 0, input
+ SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA1_PIN); // Data 1, input
+ SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA2_PIN); // Data 2, input
+ SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA3_PIN); // Data 3, input
+ SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA4_PIN); // Data 4, input
+ SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA5_PIN); // Data 5, input
+ SMD_DATA_PORT_PORT |= 1<<SMD_DATA0_PIN; // Data 0, pull-up
+ SMD_DATA_PORT_PORT |= 1<<SMD_DATA1_PIN; // Data 1, pull-up
+ SMD_DATA_PORT_PORT |= 1<<SMD_DATA2_PIN; // Data 2, pull-up
+ SMD_DATA_PORT_PORT |= 1<<SMD_DATA3_PIN; // Data 3, pull-up
+ SMD_DATA_PORT_PORT |= 1<<SMD_DATA4_PIN; // Data 4, pull-up
+ SMD_DATA_PORT_PORT |= 1<<SMD_DATA5_PIN; // Data 5, pull-up
+}
+
+uint16_t get_smd_gamepad()
+{
+ uint8_t gamepad_data_low = 0;
+ uint8_t gamepad_data_high = 0;
+ SMD_SELECT_PORT_PORT &= ~(1<<SMD_SELECT_PIN); // Select - low
+ _delay_us(50);
+ gamepad_data_low = ((SMD_DATA_PORT_PIN>>SMD_DATA0_PIN)&1)
+ | (((SMD_DATA_PORT_PIN>>SMD_DATA1_PIN)&1)<<1)
+ | (((SMD_DATA_PORT_PIN>>SMD_DATA2_PIN)&1)<<2)
+ | (((SMD_DATA_PORT_PIN>>SMD_DATA3_PIN)&1)<<3)
+ | (((SMD_DATA_PORT_PIN>>SMD_DATA4_PIN)&1)<<4)
+ | (((SMD_DATA_PORT_PIN>>SMD_DATA5_PIN)&1)<<5);
+ SMD_SELECT_PORT_PORT |= 1<<SMD_SELECT_PIN; // Select - high
+ _delay_us(50);
+ gamepad_data_high = ((SMD_DATA_PORT_PIN>>SMD_DATA0_PIN)&1)
+ | (((SMD_DATA_PORT_PIN>>SMD_DATA1_PIN)&1)<<1)
+ | (((SMD_DATA_PORT_PIN>>SMD_DATA2_PIN)&1)<<2)
+ | (((SMD_DATA_PORT_PIN>>SMD_DATA3_PIN)&1)<<3)
+ | (((SMD_DATA_PORT_PIN>>SMD_DATA4_PIN)&1)<<4)
+ | (((SMD_DATA_PORT_PIN>>SMD_DATA5_PIN)&1)<<5);
+ return ((uint16_t)gamepad_data_high<<8) | gamepad_data_low;
+}
+
+void init_dualshock_gamepad()
+{
+ DUALSHOCK_PORT_DDR |= (1<<DUALSHOCK_COMMAND_PIN); // Command pin - output
+ DUALSHOCK_PORT_PORT |= (1<<DUALSHOCK_COMMAND_PIN); // Command pin - login high
+ DUALSHOCK_PORT_DDR &= ~(1<<DUALSHOCK_DATA_PIN); // Data pin - input
+ DUALSHOCK_PORT_PORT |= (1<<DUALSHOCK_DATA_PIN); // Data pin - pull-up
+ DUALSHOCK_PORT_DDR |= (1<<DUALSHOCK_ATTENTION_PIN); // Attention - output
+ DUALSHOCK_PORT_PORT |= (1<<DUALSHOCK_ATTENTION_PIN); // Attention - logic high
+ DUALSHOCK_PORT_DDR |= (1<<DUALSHOCK_CLOCK_PIN); // Clock - output
+ DUALSHOCK_PORT_PORT |= (1<<DUALSHOCK_CLOCK_PIN); // Clock - logic high
+ /*
+ DUALSHOCK_PORT_DDR &= ~(1<<DUALSHOCK_ACK_PIN); // Ack pin - input
+ DUALSHOCK_PORT_PORT |= (1<<DUALSHOCK_ACK_PIN); // Ack pin - pull-up
+ */
+}
+
+int dualshock_command(uint8_t* command, uint8_t* data, int length)
+{
+ DUALSHOCK_PORT_PORT &= ~(1<<DUALSHOCK_ATTENTION_PIN); // Attention!
+ _delay_us(20);
+ int b, bit;
+ for (b = 0; b < length; b++) // Each byte...
+ {
+ data[b] = 0;
+ for (bit = 0; bit < 8; bit++)
+ {
+ if ((command[b] >> bit) & 1) // 1?
+ DUALSHOCK_PORT_PORT |= (1<<DUALSHOCK_COMMAND_PIN); // 1!
+ else DUALSHOCK_PORT_PORT &= ~(1<<DUALSHOCK_COMMAND_PIN); // 0!
+ DUALSHOCK_PORT_PORT &= ~(1<<DUALSHOCK_CLOCK_PIN); // Clock - logic low
+ _delay_us(20);
+ if ((DUALSHOCK_PORT_PIN >> DUALSHOCK_DATA_PIN) & 1) // Reading data... 1?
+ data[b] |= (1<<bit); // 1!
+ DUALSHOCK_PORT_PORT |= (1<<DUALSHOCK_CLOCK_PIN); // Clock - logic high
+ _delay_us(20);
+ }
+ if (b == 1 && data[1] == 0xFF) // Alternative device detection
+ {
+ DUALSHOCK_PORT_PORT |= (1<<DUALSHOCK_ATTENTION_PIN); // No attention...
+ return 0;
+ }
+ /*
+ if (b<length-1) // Waiting for ACK
+ {
+ int t;
+ for (t = 0; t < 50; t++)
+ {
+ if (!((DUALSHOCK_PORT_PIN >> DUALSHOCK_ACK_PIN)&1)) // ACK reveived
+ {
+ ok = 1;
+ break;
+ }
+ _delay_us(1);
+ }
+ if ((b < 2) && !ok) return 0; // No ACK in first two bytes? Aboooort! Saving time
+ }
+ */
+ }
+ DUALSHOCK_PORT_PORT |= (1<<DUALSHOCK_ATTENTION_PIN); // No attention...
+ _delay_us(20);
+ return 1;
+}
+
+int get_dualshock_gamepad(uint8_t* data, int size, uint8_t motor_small, uint8_t motor_large) // pointer to uint8_t[21], number of bytes to request, vibration...
+{
+ static char dualshock_configered = 0;
+
+ uint8_t command_query[21] = {0x01, 0x42, 0, motor_small, motor_large, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ if (!dualshock_command(command_query, data, size))
+ {
+ dualshock_configered = 0;
+ return 0;
+ }
+ if (!dualshock_configered) // Need to reconfigure dualshock
+ {
+ uint8_t command_config_mode[5] = {0x01, 0x43, 0x00, 0x01, 0x00};
+ if (!dualshock_command(command_config_mode, data, sizeof(command_config_mode))) return 0;
+ uint8_t command_analog_mode[9] = {0x01, 0x44, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00};
+ if (!dualshock_command(command_analog_mode, data, sizeof(command_analog_mode))) return 0;
+ uint8_t command_config_motors[9] = {0x01, 0x4D, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF};
+ if (!dualshock_command(command_config_motors, data, sizeof(command_config_motors))) return 0;
+ uint8_t command_config_pressure[9] = {0x01, 0x4F, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00};
+ if (!dualshock_command(command_config_pressure, data, sizeof(command_config_pressure))) return 0;
+ uint8_t command_config_mode_exit[8] = {0x01, 0x43, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
+ if (!dualshock_command(command_config_mode_exit, data, sizeof(command_config_mode_exit))) return 0;
+ dualshock_configered = 1;
+ if (!dualshock_command(command_query, data, size)) return 0;
+ }
+ return 1;
+}
diff --git a/gamepad.h b/gamepad.h
new file mode 100644
index 0000000..bad8302
--- /dev/null
+++ b/gamepad.h
@@ -0,0 +1,54 @@
+#ifndef _GAMEPAD_H_
+#define _GAMEPAD_H_
+
+#include <inttypes.h>
+#include "defines.h"
+
+#define GLUE(a,b) a##b
+#define DDR(p) GLUE(DDR,p)
+#define PORT(p) GLUE(PORT,p)
+#define PIN(p) GLUE(PIN,p)
+
+#define N64_PORT_PORT PORT(N64_PORT)
+#define N64_PORT_DDR DDR(N64_PORT)
+#define N64_PORT_PIN PIN(N64_PORT)
+
+#define NES_PORT_PORT PORT(NES_PORT)
+#define NES_PORT_DDR DDR(NES_PORT)
+#define NES_PORT_PIN PIN(NES_PORT)
+
+#define SNES_PORT_PORT PORT(NES_PORT)
+#define SNES_PORT_DDR DDR(NES_PORT)
+#define SNES_PORT_PIN PIN(NES_PORT)
+
+#define SMD_SELECT_PORT_PORT PORT(SMD_SELECT_PORT)
+#define SMD_SELECT_PORT_DDR DDR(SMD_SELECT_PORT)
+#define SMD_DATA_PORT_PORT PORT(SMD_DATA_PORT)
+#define SMD_DATA_PORT_DDR DDR(SMD_DATA_PORT)
+#define SMD_DATA_PORT_PIN PIN(SMD_DATA_PORT)
+
+#define DUALSHOCK_PORT_PORT PORT(DUALSHOCK_PORT)
+#define DUALSHOCK_PORT_DDR DDR(DUALSHOCK_PORT)
+#define DUALSHOCK_PORT_PIN PIN(DUALSHOCK_PORT)
+
+#define WAIT(t) {TCNT0=0; while(TCNT0 < (F_CPU / 1000000UL) * t);}
+
+#define N64SEND(t) {N64_PORT_DDR |= (1<<N64_DATA_PIN); WAIT(t); N64_PORT_DDR &= ~(1<<N64_DATA_PIN);}
+#define N64SEND_1 {N64SEND(1); WAIT(3);}
+#define N64SEND_0 {N64SEND(3); WAIT(1);}
+#define N64SEND_STOP {N64SEND(1); WAIT(2);}
+#define N64SIGNAL (!((N64_PORT_PIN>>N64_DATA_PIN)&1))
+
+void init_nes_gamepad();
+uint8_t get_nes_gamepad();
+void init_snes_gamepad();
+uint16_t get_snes_gamepad();
+void init_n64_gamepad();
+int get_n64_gamepad(uint8_t* data);
+void init_smd_gamepad();
+uint16_t get_smd_gamepad();
+void init_dualshock_gamepad();
+int dualshock_command(uint8_t* command, uint8_t* data, int length);
+int get_dualshock_gamepad(uint8_t* data, int size, uint8_t motor_small, uint8_t motor_large);
+
+#endif \ No newline at end of file
diff --git a/main.c b/main.c
index cd446e8..2ce1a48 100644
--- a/main.c
+++ b/main.c
@@ -2,7 +2,9 @@
#include "defines.h"
#include <util/delay.h>
#include <avr/eeprom.h>
+#include <inttypes.h>
#include "wiimote.h"
+#include "gamepad.h"
// classic controller id
const unsigned char classic_controller_id[6] = {0x00, 0x00, 0xA4, 0x20, 0x01, 0x01};
@@ -21,121 +23,6 @@ const unsigned char cal_data[32] = {
volatile int red_led_timer = 0;
-void init_nes_gamepad()
-{
- NES_PORT_DDR |= 1<<NES_LATCH_PIN; // Latch, output
- NES_PORT_DDR |= 1<<NES_CLOCK_PIN; // Clock, output
- NES_PORT_DDR &= ~(1<<NES_DATA_PIN); // Data, input
- NES_PORT_PORT |= 1<<NES_DATA_PIN; // Data, pull-up
-}
-
-uint8_t get_nes_gamepad()
-{
- uint8_t gamepad_data = 0;
- NES_PORT_PORT &= ~(1<<NES_LATCH_PIN); // Latch
- int b;
- for (b = 0; b < 8; b++)
- {
- NES_PORT_PORT &= ~(1<<NES_CLOCK_PIN); // Clock
- _delay_us(10);
- gamepad_data |= (((NES_PORT_PIN>>NES_DATA_PIN)&1)<<b);
- NES_PORT_PORT |= 1<<NES_CLOCK_PIN; // Clock
- _delay_us(10);
- }
- NES_PORT_PORT |= 1<<NES_LATCH_PIN; // Latch
- return gamepad_data;
-}
-
-void init_snes_gamepad()
-{
- SNES_PORT_DDR |= 1<<SNES_LATCH_PIN; // Latch, output
- SNES_PORT_DDR |= 1<<SNES_CLOCK_PIN; // Clock, output
- SNES_PORT_DDR &= ~(1<<SNES_DATA_PIN); // Data, input
- SNES_PORT_PORT |= 1<<SNES_DATA_PIN; // Data, pull-up
-}
-
-uint16_t get_snes_gamepad()
-{
- uint16_t gamepad_data = 0;
- SNES_PORT_PORT &= ~(1<<SNES_LATCH_PIN); // Latch
- int b;
- for (b = 0; b < 16; b++)
- {
- SNES_PORT_PORT &= ~(1<<SNES_CLOCK_PIN); // Clock
- _delay_us(10);
- gamepad_data |= ((uint16_t)((SNES_PORT_PIN>>SNES_DATA_PIN)&1)<<b);
- SNES_PORT_PORT |= 1<<SNES_CLOCK_PIN; // Clock
- _delay_us(10);
- }
- SNES_PORT_PORT |= 1<<SNES_LATCH_PIN; // Latch
- return gamepad_data;
-}
-
-void init_n64_gamepad()
-{
- N64_PORT_DDR &= ~(1<<N64_DATA_PIN); // Input
- N64_PORT_PORT &= ~(1<<N64_DATA_PIN); // No pull-up (using external resistor)
-}
-
-int get_n64_gamepad(uint8_t* data)
-{
- int b, bit;
- N64SEND_0; N64SEND_0; N64SEND_0; N64SEND_0; N64SEND_0; N64SEND_0; N64SEND_0; N64SEND_1; N64SEND_STOP;
- for (b = 0; b < 4; b++)
- {
- data[b] = 0;
- for (bit = 0; bit < 8; bit++)
- {
- TCNT0 = 0;
- while (!N64SIGNAL) if (TCNT0 >= 0xF0) return 0;
- TCNT0 = 0;
- while(N64SIGNAL) if (TCNT0 >= 0xF0) return 0;
- data[b] = data[b]<<1;
- if (TCNT0 < 0x24 * F_CPU / 20000000UL) data[b] |= 1;
- }
- }
- return 1;
-}
-
-void init_smd_gamepad()
-{
- SMD_SELECT_PORT_DDR |= 1<<SMD_SELECT_PIN; // Select, output
- SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA0_PIN); // Data 0, input
- SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA1_PIN); // Data 1, input
- SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA2_PIN); // Data 2, input
- SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA3_PIN); // Data 3, input
- SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA4_PIN); // Data 4, input
- SMD_DATA_PORT_DDR &= ~(1<<SMD_DATA5_PIN); // Data 5, input
- SMD_DATA_PORT_PORT |= 1<<SMD_DATA0_PIN; // Data 0, pull-up
- SMD_DATA_PORT_PORT |= 1<<SMD_DATA1_PIN; // Data 1, pull-up
- SMD_DATA_PORT_PORT |= 1<<SMD_DATA2_PIN; // Data 2, pull-up
- SMD_DATA_PORT_PORT |= 1<<SMD_DATA3_PIN; // Data 3, pull-up
- SMD_DATA_PORT_PORT |= 1<<SMD_DATA4_PIN; // Data 4, pull-up
- SMD_DATA_PORT_PORT |= 1<<SMD_DATA5_PIN; // Data 5, pull-up
-}
-
-uint16_t get_smd_gamepad()
-{
- uint8_t gamepad_data_low = 0;
- uint8_t gamepad_data_high = 0;
- SMD_SELECT_PORT_PORT &= ~(1<<SMD_SELECT_PIN); // Select - low
- _delay_us(50);
- gamepad_data_low = ((SMD_DATA_PORT_PIN>>SMD_DATA0_PIN)&1)
- | (((SMD_DATA_PORT_PIN>>SMD_DATA1_PIN)&1)<<1)
- | (((SMD_DATA_PORT_PIN>>SMD_DATA2_PIN)&1)<<2)
- | (((SMD_DATA_PORT_PIN>>SMD_DATA3_PIN)&1)<<3)
- | (((SMD_DATA_PORT_PIN>>SMD_DATA4_PIN)&1)<<4)
- | (((SMD_DATA_PORT_PIN>>SMD_DATA5_PIN)&1)<<5);
- SMD_SELECT_PORT_PORT |= 1<<SMD_SELECT_PIN; // Select - high
- _delay_us(50);
- gamepad_data_high = ((SMD_DATA_PORT_PIN>>SMD_DATA0_PIN)&1)
- | (((SMD_DATA_PORT_PIN>>SMD_DATA1_PIN)&1)<<1)
- | (((SMD_DATA_PORT_PIN>>SMD_DATA2_PIN)&1)<<2)
- | (((SMD_DATA_PORT_PIN>>SMD_DATA3_PIN)&1)<<3)
- | (((SMD_DATA_PORT_PIN>>SMD_DATA4_PIN)&1)<<4)
- | (((SMD_DATA_PORT_PIN>>SMD_DATA5_PIN)&1)<<5);
- return ((uint16_t)gamepad_data_high<<8) | gamepad_data_low;
-}
void wiimote_query()
{
@@ -148,7 +35,6 @@ int main()
RED_LED_PORT_DDR |= (1<<RED_LED_PIN); // Red led, output
GREEN_LED_PORT_DDR |= (1<<GREEN_LED_PIN); // Red led, output
RED_ON;
- TCCR0 |= _BV(CS00); // Timer
#ifdef N64_ENABLED
init_n64_gamepad();
#endif
diff --git a/nes2wii.h b/nes2wii.h
index 238c377..5d64ec3 100644
--- a/nes2wii.h
+++ b/nes2wii.h
@@ -13,37 +13,6 @@
#define twi_scl_pin TWI_SCL_PIN
#define twi_sda_pin TWI_SDA_PIN
-#define N64_PORT_PORT PORT(N64_PORT)
-#define N64_PORT_DDR DDR(N64_PORT)
-#define N64_PORT_PIN PIN(N64_PORT)
-
-#define NES_PORT_PORT PORT(NES_PORT)
-#define NES_PORT_DDR DDR(NES_PORT)
-#define NES_PORT_PIN PIN(NES_PORT)
-
-#define SNES_PORT_PORT PORT(NES_PORT)
-#define SNES_PORT_DDR DDR(NES_PORT)
-#define SNES_PORT_PIN PIN(NES_PORT)
-
-#define SMD_SELECT_PORT_PORT PORT(SMD_SELECT_PORT)
-#define SMD_SELECT_PORT_DDR DDR(SMD_SELECT_PORT)
-#define SMD_DATA_PORT_PORT PORT(SMD_DATA_PORT)
-#define SMD_DATA_PORT_DDR DDR(SMD_DATA_PORT)
-#define SMD_DATA_PORT_PIN PIN(SMD_DATA_PORT)
-
-#define RED_LED_PORT_PORT PORT(RED_LED_PORT)
-#define RED_LED_PORT_DDR DDR(RED_LED_PORT)
-#define GREEN_LED_PORT_PORT PORT(GREEN_LED_PORT)
-#define GREEN_LED_PORT_DDR DDR(GREEN_LED_PORT)
-
-#define WAIT(t) {TCNT0=0; while(TCNT0 < (F_CPU / 1000000UL) * t);}
-
-#define N64SEND(t) {N64_PORT_DDR |= (1<<N64_DATA_PIN); WAIT(t); N64_PORT_DDR &= ~(1<<N64_DATA_PIN);}
-#define N64SEND_1 {N64SEND(1); WAIT(3);}
-#define N64SEND_0 {N64SEND(3); WAIT(1);}
-#define N64SEND_STOP {N64SEND(1); WAIT(2);}
-#define N64SIGNAL (!((N64_PORT_PIN>>N64_DATA_PIN)&1))
-
#define PRESS_A but_dat[5] &= 0b11101111; // BZL BB BY BA BX BZR BDL BDU
#define PRESS_B but_dat[5] &= 0b10111111; // BZL BB BY BA BX BZR BDL BDU
#define PRESS_X but_dat[5] &= 0b11110111; // BZL BB BY BA BX BZR BDL BDU
@@ -59,6 +28,11 @@
#define PRESS_LEFT but_dat[5] &= 0b11111101; // BZL BB BY BA BX BZR BDL BDU
#define PRESS_RIGHT but_dat[4] &= 0b01111111; // BDR BDD BLT B- BH B+ BRT 1
+#define RED_LED_PORT_PORT PORT(RED_LED_PORT)
+#define RED_LED_PORT_DDR DDR(RED_LED_PORT)
+#define GREEN_LED_PORT_PORT PORT(GREEN_LED_PORT)
+#define GREEN_LED_PORT_DDR DDR(GREEN_LED_PORT)
+
#define RED_ON RED_LED_PORT_PORT |= (1<<RED_LED_PIN);
#define RED_OFF RED_LED_PORT_PORT &= ~(1<<RED_LED_PIN);
#define GREEN_ON GREEN_LED_PORT_PORT |= (1<<GREEN_LED_PIN);