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