nuclear@4: #include nuclear@2: #include nuclear@0: #include "gbasys.h" nuclear@1: #include "logger.h" nuclear@2: #include "sincos.h" nuclear@2: nuclear@2: #define GFX_MODE VMODE_LFB_160x128_16 nuclear@2: #define WIDTH 160 nuclear@2: #define HEIGHT 128 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@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@1: 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@0: draw(); nuclear@0: } nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@2: static int offset; nuclear@2: nuclear@4: #define X16INT(x) ((x) << 16) nuclear@4: nuclear@0: static void draw(void) nuclear@0: { nuclear@2: int i, j; nuclear@2: unsigned long msec = get_millisec(); nuclear@2: uint16_t *pixels = back_buffer->pixels; nuclear@2: nuclear@2: clear_buffer(back_buffer, 0); nuclear@2: nuclear@2: for(i=0; i>= 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@2: */ 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: }