gba-x3dtest

annotate src/main.c @ 10:23f716fa7f10

changed to mode 5 again, this time with hardware scaling (looks kinda crap)
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 22 Jun 2014 06:31:14 +0300
parents b0ed38f13261
children
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@10 24 set_bg_scale(171, 206);
nuclear@0 25
nuclear@0 26 clear_buffer(front_buffer, 0);
nuclear@1 27 set_text_writebg(1);
nuclear@1 28 logmsg(LOG_ALL, "please wait...\n");
nuclear@0 29
nuclear@8 30 if(game_init() == -1) {
nuclear@8 31 return 1;
nuclear@8 32 }
nuclear@2 33
nuclear@0 34 for(;;) {
nuclear@1 35 /* process events */
nuclear@1 36 while(evhead != evtail) {
nuclear@1 37 unsigned short ev = events[evhead];
nuclear@1 38 evhead = (evhead + 1) % EVQ_SIZE;
nuclear@5 39 game_keyb(ev, 1);
nuclear@1 40 }
nuclear@2 41
nuclear@2 42 /* this is needed because there's no key release interrupt (!) */
nuclear@2 43 keystate = get_key_state(KEY_ALL);
nuclear@2 44
nuclear@5 45 game_draw();
nuclear@0 46 }
nuclear@0 47 return 0;
nuclear@0 48 }
nuclear@0 49
nuclear@1 50 static void keyb_intr(void)
nuclear@1 51 {
nuclear@1 52 int i;
nuclear@1 53 unsigned short prev_keystate = keystate;
nuclear@1 54 unsigned short diff;
nuclear@1 55 keystate = get_key_state(KEY_ALL);
nuclear@1 56 diff = keystate ^ prev_keystate;
nuclear@1 57
nuclear@1 58 for(i=0; i<32; i++) {
nuclear@1 59 int key = 1 << i;
nuclear@1 60
nuclear@1 61 if(diff & key) {
nuclear@1 62 events[evtail] = key;
nuclear@1 63 evtail = (evtail + 1) % EVQ_SIZE;
nuclear@1 64 }
nuclear@1 65 }
nuclear@1 66 }