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