nuclear@0: #include "gbasys.h" nuclear@1: #include "logger.h" nuclear@0: nuclear@0: static void draw(void); nuclear@1: static void keyb(int key, int pressed); nuclear@1: static void keyb_intr(void); nuclear@0: nuclear@1: static unsigned short keystate; nuclear@1: nuclear@1: #define EVQ_SIZE 8 nuclear@1: volatile static unsigned short evhead, evtail; nuclear@1: static unsigned short events[EVQ_SIZE]; nuclear@0: nuclear@0: int main(void) nuclear@0: { nuclear@0: gba_init(); nuclear@1: interrupt(INTR_KEY, keyb_intr); nuclear@0: nuclear@0: set_video_mode(VMODE_LFB_160x128_16, 1); nuclear@0: nuclear@0: clear_buffer(front_buffer, 0); nuclear@1: set_text_writebg(1); nuclear@1: logmsg(LOG_ALL, "please wait...\n"); nuclear@0: nuclear@0: for(;;) { nuclear@1: /* process events */ nuclear@1: while(evhead != evtail) { nuclear@1: unsigned short ev = events[evhead]; nuclear@1: evhead = (evhead + 1) % EVQ_SIZE; nuclear@1: keyb(ev, 1); nuclear@1: } nuclear@0: draw(); nuclear@0: } nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: static void draw(void) nuclear@0: { nuclear@0: } nuclear@0: nuclear@1: static void keyb(int key, int pressed) nuclear@0: { nuclear@1: static const char *keyname[] = { nuclear@1: "A", "B", "select", "start", "right", "left", "up", "down", "RT", "LT" nuclear@1: }; nuclear@1: int i; nuclear@1: for(i=0; i<32; i++) { nuclear@1: if(key & 1) { nuclear@1: break; nuclear@1: } nuclear@1: key >>= 1; nuclear@1: } nuclear@1: if(i < sizeof keyname / sizeof *keyname) { nuclear@1: logmsg(LOG_ALL, "key %s %s\n", keyname[i], pressed ? "pressed" : "released"); nuclear@1: } nuclear@0: } nuclear@1: nuclear@1: static void keyb_intr(void) nuclear@1: { nuclear@1: int i; nuclear@1: unsigned short prev_keystate = keystate; nuclear@1: unsigned short diff; nuclear@1: keystate = get_key_state(KEY_ALL); nuclear@1: diff = keystate ^ prev_keystate; nuclear@1: nuclear@1: for(i=0; i<32; i++) { nuclear@1: int key = 1 << i; nuclear@1: nuclear@1: if(diff & key) { nuclear@1: events[evtail] = key; nuclear@1: evtail = (evtail + 1) % EVQ_SIZE; nuclear@1: } nuclear@1: } nuclear@1: }