a520cafa0b7b0ed4abf585606e63836a6959b728
[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         if(init_screens() == -1) {
36                 panic(get_pc(), "failed to initialize screens");
37         }
38
39         if(change_screen(find_screen("game")) == -1) {
40                 panic(get_pc(), "failed to find game screen");
41         }
42
43         intr_enable();
44
45         for(;;) {
46                 curscr->frame();
47         }
48         return 0;
49 }
50
51 ARM_IWRAM
52 static void vblank(void)
53 {
54         vblperf_count++;
55
56         curscr->vblank();
57
58 #ifndef NOSOUND
59         mmVBlank();
60         mmFrame();
61 #endif
62 }