8417df18d933bba04acb954cd6eedd99413c1f64
[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
8 static void vblank(void);
9
10 int main(void)
11 {
12         int i;
13         volatile uint16_t *cptr;
14
15         intr_init();
16
17         REG_WAITCNT = WAITCNT_PREFETCH | WAITCNT_ROM_2_1;
18
19         cptr = (uint16_t*)CRAM_BG_ADDR;
20         for(i=0; i<256; i++) {
21                 int c = i >> 3;
22                 *cptr++ = c | ((c >> 1) << 10);
23         }
24
25 #ifndef NOSOUND
26         mmInitDefault(sound_data, 8);
27         mmStart(MOD_POPCORN, MM_PLAY_LOOP);
28 #endif
29
30         intr_disable();
31         interrupt(INTR_VBLANK, vblank);
32         REG_DISPSTAT |= DISPSTAT_IEN_VBLANK;
33         unmask(INTR_VBLANK);
34
35         intr_enable();
36
37         if(init_screens() == -1) {
38                 panic(get_pc(), "failed to initialize screens");
39         }
40
41         if(change_screen(find_screen("game")) == -1) {
42                 panic(get_pc(), "failed to find game screen");
43         }
44
45         for(;;) {
46                 curscr->frame();
47         }
48         return 0;
49 }
50
51 static void vblank(void)
52 {
53         vblperf_count++;
54
55         if(curscr && curscr->vblank) {
56                 curscr->vblank();
57         }
58
59 #ifndef NOSOUND
60         mmVBlank();
61         mmFrame();
62 #endif
63 }