gba-x3dtest
annotate 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 |
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@9 | 23 set_video_mode(GFX_MODE, 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@8 | 29 if(game_init() == -1) { |
nuclear@8 | 30 return 1; |
nuclear@8 | 31 } |
nuclear@2 | 32 |
nuclear@0 | 33 for(;;) { |
nuclear@1 | 34 /* process events */ |
nuclear@1 | 35 while(evhead != evtail) { |
nuclear@1 | 36 unsigned short ev = events[evhead]; |
nuclear@1 | 37 evhead = (evhead + 1) % EVQ_SIZE; |
nuclear@5 | 38 game_keyb(ev, 1); |
nuclear@1 | 39 } |
nuclear@2 | 40 |
nuclear@2 | 41 /* this is needed because there's no key release interrupt (!) */ |
nuclear@2 | 42 keystate = get_key_state(KEY_ALL); |
nuclear@2 | 43 |
nuclear@5 | 44 game_draw(); |
nuclear@0 | 45 } |
nuclear@0 | 46 return 0; |
nuclear@0 | 47 } |
nuclear@0 | 48 |
nuclear@1 | 49 static void keyb_intr(void) |
nuclear@1 | 50 { |
nuclear@1 | 51 int i; |
nuclear@1 | 52 unsigned short prev_keystate = keystate; |
nuclear@1 | 53 unsigned short diff; |
nuclear@1 | 54 keystate = get_key_state(KEY_ALL); |
nuclear@1 | 55 diff = keystate ^ prev_keystate; |
nuclear@1 | 56 |
nuclear@1 | 57 for(i=0; i<32; i++) { |
nuclear@1 | 58 int key = 1 << i; |
nuclear@1 | 59 |
nuclear@1 | 60 if(diff & key) { |
nuclear@1 | 61 events[evtail] = key; |
nuclear@1 | 62 evtail = (evtail + 1) % EVQ_SIZE; |
nuclear@1 | 63 } |
nuclear@1 | 64 } |
nuclear@1 | 65 } |