gba-trycatch

view src/main.c @ 9:b0ed38f13261

working on the rasterizer
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 22 Jun 2014 05:16:10 +0300
parents fb0a0d6a8b52
children 23f716fa7f10
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(GFX_MODE, 1);
25 clear_buffer(front_buffer, 0);
26 set_text_writebg(1);
27 logmsg(LOG_ALL, "please wait...\n");
29 if(game_init() == -1) {
30 return 1;
31 }
33 for(;;) {
34 /* process events */
35 while(evhead != evtail) {
36 unsigned short ev = events[evhead];
37 evhead = (evhead + 1) % EVQ_SIZE;
38 game_keyb(ev, 1);
39 }
41 /* this is needed because there's no key release interrupt (!) */
42 keystate = get_key_state(KEY_ALL);
44 game_draw();
45 }
46 return 0;
47 }
49 static void keyb_intr(void)
50 {
51 int i;
52 unsigned short prev_keystate = keystate;
53 unsigned short diff;
54 keystate = get_key_state(KEY_ALL);
55 diff = keystate ^ prev_keystate;
57 for(i=0; i<32; i++) {
58 int key = 1 << i;
60 if(diff & key) {
61 events[evtail] = key;
62 evtail = (evtail + 1) % EVQ_SIZE;
63 }
64 }
65 }