unsigned char wayplay_1_read(void) { if (pad_index < 4) { return gamepad_read(pad_index); } /* multitap detection */ return 0x70; }
unsigned char wayplay_1_read(void) { /* check if TH on port B is HIGH */ if (latch & 0x04) { /* 4-WayPlay detection : xxxxx00 */ return 0x7C; } /* TR & TL on port B select controller # (0-3) */ return gamepad_read(latch); }
unsigned char gamepad_2_read(void) { return gamepad_read(4); }
unsigned char gamepad_1_read(void) { return gamepad_read(0); }
int main() { // set for 16 MHz clock CPU_PRESCALE(0); // Configure all port B and port D pins as inputs with pullup resistors. DDRD = 0x00; DDRB = 0x00; PORTB = 0xFF; PORTD = 0xFF; // Turn the LED on during the configuration LED_CONFIG; LED_ON; // Initialize the USB, and then wait for the host to set configuration. usb_init(); while (!usb_configured()); // Initialize the gamepad interface gamepad_init(); // Wait an extra second for the PC's operating system to load drivers // and do whatever it does to actually be ready for input _delay_ms(1000); // Timer 0 configuration (~60Hz) TCCR0A = 0x00; // Normal mode TCCR0B = 0x05; // Clock/1024 TIMSK0 = (1<<TOIE0); LED_OFF; while (1) { while (!ready); // Block until the next cycle (~60Hz) cli(); ready = 0; sei(); // Read pressed buttons from gamepad interface gamepad_read(); // Reset key array reset_keys(); // Special functions // - Software reboot if (PRESSED_REBOOT) { reboot(); } // 6 keys can be sent at a time, with any number of modifiers. // // - Buttons A, B, X and Y have their own position in the key array. // - Up/down and left/right pairs share one position, as they are // mutually exclusive (you cannot pres up AND down). // - L and R use the left and right Shift modifiers. // - Select and Start use the left and right Ctrl modifiers. if (PRESSED_A) press_key(KEY_Z, 0); if (PRESSED_B) press_key(KEY_X, 1); if (PRESSED_X) press_key(KEY_A, 2); if (PRESSED_Y) press_key(KEY_S, 3); if (PRESSED_UP) { press_key(KEY_UP, 4); } else if (PRESSED_DOWN){ press_key(KEY_DOWN, 4); } if (PRESSED_LEFT) { press_key(KEY_LEFT, 5); } else if (PRESSED_RIGHT){ press_key(KEY_RIGHT, 5); } if (PRESSED_L) press_modifier(KEY_LEFT_SHIFT); if (PRESSED_R) press_modifier(KEY_RIGHT_SHIFT); if (PRESSED_SELECT) press_modifier(KEY_LEFT_CTRL); if (PRESSED_START) press_modifier(KEY_RIGHT_CTRL); usb_keyboard_send(); } }