/* gc_n64_usb : Gamecube or N64 controller to USB firmware Copyright (C) 2007-2015 Raphael Assenat This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include "gcn64_protocol.h" #include "gcn64txrx.h" #undef FORCE_KEYBOARD #define GCN64_BUF_SIZE 320 // Supports up to 39 bytes static unsigned char gcn64_workbuf[GCN64_BUF_SIZE]; /******** IO port definitions and options **************/ #ifndef STK525 #define GCN64_DATA_PORT PORTD #define GCN64_DATA_DDR DDRD #define GCN64_DATA_PIN PIND #define GCN64_DATA_BIT (1<<0) #define GCN64_BIT_NUM_S "0" // for asm #else #define GCN64_DATA_PORT PORTA #define GCN64_DATA_DDR DDRA #define GCN64_DATA_PIN PINA #define GCN64_DATA_BIT (1<<0) #define GCN64_BIT_NUM_S "0" // for asm #endif #define DISABLE_INTS_DURING_COMM /* Read a byte from the buffer (where 1 byte is 1 bit). * MSb first. */ unsigned char gcn64_protocol_getByte(int offset) { unsigned char val, b; unsigned char volatile *addr = gcn64_workbuf + offset; for (b=0x80, val=0; b; b>>=1) { if (*addr) val |= b; addr++; } return val; } void gcn64_protocol_getBytes(int offset, int n_bytes, unsigned char *dstbuf) { int i; for (i=0; i> 8) { case 0x05: return CONTROLLER_IS_N64; case 0x09: // normal controllers case 0x0b: // Never saw this one, but it is mentionned above. return CONTROLLER_IS_GC; case 0x08: if (id == 0x0820) { // Ascii keyboard return CONTROLLER_IS_GC_KEYBOARD; } // wavebird, controller off. return CONTROLLER_IS_GC; default: return CONTROLLER_IS_UNKNOWN; } return 0; }