laser shots
[gbajam22] / src / gba / main.c
1 #include <math.h>
2 #include "gbaregs.h"
3 #include "intr.h"
4 #include "debug.h"
5 #include "game.h"
6 #include "maxmod.h"
7 #include "input.h"
8 #include "timer.h"
9 #include "xgl.h"
10
11 static void vblank(void);
12
13 int main(void)
14 {
15         int i;
16         volatile uint16_t *cptr;
17
18         intr_init();
19
20         REG_WAITCNT = WAITCNT_PREFETCH | WAITCNT_ROM_2_1;
21
22         cptr = (uint16_t*)CRAM_BG_ADDR;
23         for(i=0; i<256; i++) {
24                 int c = i >> 3;
25                 *cptr++ = c | ((c >> 1) << 10);
26         }
27
28 #ifndef NOSOUND
29         mmInitDefault(sound_data, 8);
30         mmStart(MOD_POPCORN, MM_PLAY_LOOP);
31 #endif
32
33         intr_disable();
34         interrupt(INTR_VBLANK, vblank);
35         REG_DISPSTAT |= DISPSTAT_IEN_VBLANK;
36         unmask(INTR_VBLANK);
37
38         xgl_init();
39
40         if(init_screens() == -1) {
41                 panic(get_pc(), "failed to initialize screens");
42         }
43
44         if(change_screen(find_screen("game")) == -1) {
45                 panic(get_pc(), "failed to find starting screen");
46         }
47
48         reset_msec_timer();
49         intr_enable();
50
51         for(;;) {
52                 curscr->frame();
53         }
54         return 0;
55 }
56
57 ARM_IWRAM
58 static void vblank(void)
59 {
60         vblperf_count++;
61
62         keyb_vblank();
63         curscr->vblank();
64
65 #ifndef NOSOUND
66         mmVBlank();
67         mmFrame();
68 #endif
69 }