rev |
line source |
nuclear@0
|
1 #include "gbasys.h"
|
nuclear@1
|
2 #include "logger.h"
|
nuclear@0
|
3
|
nuclear@0
|
4 static void draw(void);
|
nuclear@1
|
5 static void keyb(int key, int pressed);
|
nuclear@1
|
6 static void keyb_intr(void);
|
nuclear@0
|
7
|
nuclear@1
|
8 static unsigned short keystate;
|
nuclear@1
|
9
|
nuclear@1
|
10 #define EVQ_SIZE 8
|
nuclear@1
|
11 volatile static unsigned short evhead, evtail;
|
nuclear@1
|
12 static unsigned short events[EVQ_SIZE];
|
nuclear@0
|
13
|
nuclear@0
|
14 int main(void)
|
nuclear@0
|
15 {
|
nuclear@0
|
16 gba_init();
|
nuclear@1
|
17 interrupt(INTR_KEY, keyb_intr);
|
nuclear@0
|
18
|
nuclear@0
|
19 set_video_mode(VMODE_LFB_160x128_16, 1);
|
nuclear@0
|
20
|
nuclear@0
|
21 clear_buffer(front_buffer, 0);
|
nuclear@1
|
22 set_text_writebg(1);
|
nuclear@1
|
23 logmsg(LOG_ALL, "please wait...\n");
|
nuclear@0
|
24
|
nuclear@0
|
25 for(;;) {
|
nuclear@1
|
26 /* process events */
|
nuclear@1
|
27 while(evhead != evtail) {
|
nuclear@1
|
28 unsigned short ev = events[evhead];
|
nuclear@1
|
29 evhead = (evhead + 1) % EVQ_SIZE;
|
nuclear@1
|
30 keyb(ev, 1);
|
nuclear@1
|
31 }
|
nuclear@0
|
32 draw();
|
nuclear@0
|
33 }
|
nuclear@0
|
34 return 0;
|
nuclear@0
|
35 }
|
nuclear@0
|
36
|
nuclear@0
|
37 static void draw(void)
|
nuclear@0
|
38 {
|
nuclear@0
|
39 }
|
nuclear@0
|
40
|
nuclear@1
|
41 static void keyb(int key, int pressed)
|
nuclear@0
|
42 {
|
nuclear@1
|
43 static const char *keyname[] = {
|
nuclear@1
|
44 "A", "B", "select", "start", "right", "left", "up", "down", "RT", "LT"
|
nuclear@1
|
45 };
|
nuclear@1
|
46 int i;
|
nuclear@1
|
47 for(i=0; i<32; i++) {
|
nuclear@1
|
48 if(key & 1) {
|
nuclear@1
|
49 break;
|
nuclear@1
|
50 }
|
nuclear@1
|
51 key >>= 1;
|
nuclear@1
|
52 }
|
nuclear@1
|
53 if(i < sizeof keyname / sizeof *keyname) {
|
nuclear@1
|
54 logmsg(LOG_ALL, "key %s %s\n", keyname[i], pressed ? "pressed" : "released");
|
nuclear@1
|
55 }
|
nuclear@0
|
56 }
|
nuclear@1
|
57
|
nuclear@1
|
58 static void keyb_intr(void)
|
nuclear@1
|
59 {
|
nuclear@1
|
60 int i;
|
nuclear@1
|
61 unsigned short prev_keystate = keystate;
|
nuclear@1
|
62 unsigned short diff;
|
nuclear@1
|
63 keystate = get_key_state(KEY_ALL);
|
nuclear@1
|
64 diff = keystate ^ prev_keystate;
|
nuclear@1
|
65
|
nuclear@1
|
66 for(i=0; i<32; i++) {
|
nuclear@1
|
67 int key = 1 << i;
|
nuclear@1
|
68
|
nuclear@1
|
69 if(diff & key) {
|
nuclear@1
|
70 events[evtail] = key;
|
nuclear@1
|
71 evtail = (evtail + 1) % EVQ_SIZE;
|
nuclear@1
|
72 }
|
nuclear@1
|
73 }
|
nuclear@1
|
74 }
|