gba-x3dtest

view src/main.c @ 8:fb0a0d6a8b52

sortof works
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 19 Jun 2014 05:53:46 +0300
parents 850be43b3135
children b0ed38f13261
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 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 }