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