c203e5bacf03a5dad34fe17e2f4fce7f21fbe115
[gbajam22] / src / game.c
1 #include <string.h>
2 #include "gba.h"
3 #include "game.h"
4
5 struct screen *init_menu_screen(void);
6 struct screen *init_game_screen(void);
7
8 struct screen *curscr;
9
10 #define MAX_SCR 4
11 static struct screen *scrlist[MAX_SCR];
12 static int num_scr;
13
14 int init_screens(void)
15 {
16         if(!(scrlist[num_scr++] = init_menu_screen())) {
17                 return -1;
18         }
19         if(!(scrlist[num_scr++] = init_game_screen())) {
20                 return -1;
21         }
22         return 0;
23 }
24
25 int change_screen(struct screen *scr)
26 {
27         if(!scr) return -1;
28
29         mask(INTR_VBLANK);
30
31         if(curscr && curscr->stop) {
32                 curscr->stop();
33         }
34         if(scr->start && scr->start() == -1) {
35                 return -1;
36         }
37         curscr = scr;
38
39         unmask(INTR_VBLANK);
40         return 0;
41 }
42
43 struct screen *find_screen(const char *name)
44 {
45         int i;
46         for(i=0; i<num_scr; i++) {
47                 if(strcmp(scrlist[i]->name, name) == 0) {
48                         return scrlist[i];
49                 }
50         }
51         return 0;
52 }