nuclear@5: #include "config.h" nuclear@4: #include nuclear@2: #include nuclear@0: #include "gbasys.h" nuclear@1: #include "logger.h" nuclear@2: #include "sincos.h" nuclear@5: #include "game.h" nuclear@2: 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@2: 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@2: sincos_init(); nuclear@2: 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@5: game_keyb(ev, 1); nuclear@1: } nuclear@2: nuclear@2: /* this is needed because there's no key release interrupt (!) */ nuclear@2: keystate = get_key_state(KEY_ALL); nuclear@2: nuclear@5: game_draw(); nuclear@0: } nuclear@0: return 0; nuclear@0: } nuclear@0: 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: }