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