gba-trycatch

view src/main.c @ 5:850be43b3135

sdl version
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 16 Jun 2014 22:01:45 +0300
parents 78d1664c2443
children fb0a0d6a8b52
line source
1 #include "config.h"
2 #include <math.h>
3 #include <stdint.h>
4 #include "gbasys.h"
5 #include "logger.h"
6 #include "sincos.h"
7 #include "game.h"
9 static void keyb_intr(void);
11 static unsigned short keystate;
13 #define EVQ_SIZE 8
14 volatile static unsigned short evhead, evtail;
15 static unsigned short events[EVQ_SIZE];
17 int main(void)
18 {
19 gba_init();
21 interrupt(INTR_KEY, keyb_intr);
23 set_video_mode(VMODE_LFB_160x128_16, 1);
25 clear_buffer(front_buffer, 0);
26 set_text_writebg(1);
27 logmsg(LOG_ALL, "please wait...\n");
29 sincos_init();
31 for(;;) {
32 /* process events */
33 while(evhead != evtail) {
34 unsigned short ev = events[evhead];
35 evhead = (evhead + 1) % EVQ_SIZE;
36 game_keyb(ev, 1);
37 }
39 /* this is needed because there's no key release interrupt (!) */
40 keystate = get_key_state(KEY_ALL);
42 game_draw();
43 }
44 return 0;
45 }
47 static void keyb_intr(void)
48 {
49 int i;
50 unsigned short prev_keystate = keystate;
51 unsigned short diff;
52 keystate = get_key_state(KEY_ALL);
53 diff = keystate ^ prev_keystate;
55 for(i=0; i<32; i++) {
56 int key = 1 << i;
58 if(diff & key) {
59 events[evtail] = key;
60 evtail = (evtail + 1) % EVQ_SIZE;
61 }
62 }
63 }