# HG changeset patch # User John Tsiombikas # Date 1498265257 -10800 # Node ID 302bcd73edc45084b9fd74fa08910106e2d52edb # Parent ca7108a828675845ed1eb46158c84f66fe9556b4 added 6button support diff -r ca7108a82867 -r 302bcd73edc4 src/io.h --- a/src/io.h Sat Jun 24 02:33:52 2017 +0300 +++ b/src/io.h Sat Jun 24 03:47:37 2017 +0300 @@ -34,14 +34,18 @@ }; enum { - IO_PAD_UP = 1, - IO_PAD_DOWN = 2, - IO_PAD_LEFT = 4, - IO_PAD_RIGHT = 8, - IO_PAD_B = 16, - IO_PAD_C = 32, - IO_PAD_A = 64, - IO_PAD_START = 128 + IO_PAD_UP = 0x001, + IO_PAD_DOWN = 0x002, + IO_PAD_LEFT = 0x004, + IO_PAD_RIGHT = 0x008, + IO_PAD_B = 0x010, + IO_PAD_C = 0x020, + IO_PAD_A = 0x040, + IO_PAD_START = 0x080, + + IO_PAD_Z = 0x100, + IO_PAD_Y = 0x200, + IO_PAD_X = 0x400 }; #define IO_PAD_LOW_MASK 0x3f #define IO_PAD_HIGH_MASK (IO_PAD_A | IO_PAD_START) @@ -66,6 +70,36 @@ return bnstate; } +static inline uint16_t io_readpad6(int port) +{ + uint16_t bnstate; + + IO_REG_DATA(port) = 0x40; /* start with mode 1 */ + asm volatile("nop"); + asm volatile("nop"); + bnstate = ~IO_REG_DATA(port) & IO_PAD_LOW_MASK; + + IO_REG_DATA(port) = 0; /* select mode 0 */ + asm volatile("nop"); + asm volatile("nop"); + bnstate |= ~(IO_REG_DATA(port) << 2) & IO_PAD_HIGH_MASK; + + /* then introduce two more rising edges to trigger extended mode */ + IO_REG_DATA(port) = 0x40; + asm volatile("nop"); + asm volatile("nop"); + IO_REG_DATA(port) = 0; + asm volatile("nop"); + asm volatile("nop"); + IO_REG_DATA(port) = 0x40; + asm volatile("nop"); + asm volatile("nop"); + + bnstate |= (uint16_t)(~IO_REG_DATA(port) & 0x7) << 8; + IO_REG_DATA(port) = 0; /* return mode to 0 */ + return bnstate; +} + void io_init(void); /*uint16_t io_readpad(int port);*/ diff -r ca7108a82867 -r 302bcd73edc4 src/pad.h --- a/src/pad.h Sat Jun 24 02:33:52 2017 +0300 +++ b/src/pad.h Sat Jun 24 03:47:37 2017 +0300 @@ -3,12 +3,13 @@ #include "io.h" -static uint16_t pad_bnstate[2], pad_prev_bnstate[2], pad_bndiff[2]; +uint16_t pad_bnstate[2], pad_prev_bnstate[2], pad_bndiff[2]; +char pad_6bn; static inline void pad_update(int pad) { pad_prev_bnstate[pad] = pad_bnstate[pad]; - pad_bnstate[pad] = io_readpad(pad); + pad_bnstate[pad] = pad_6bn ? io_readpad6(pad) : io_readpad(pad); pad_bndiff[pad] = pad_bnstate[pad] ^ pad_prev_bnstate[pad]; }