pc port works
[gbajam22] / src / game.c
diff --git a/src/game.c b/src/game.c
new file mode 100644 (file)
index 0000000..38136aa
--- /dev/null
@@ -0,0 +1,52 @@
+#include <string.h>
+#include "gba.h"
+#include "game.h"
+
+struct screen *init_menu_screen(void);
+struct screen *init_game_screen(void);
+
+struct screen *curscr;
+
+#define MAX_SCR        4
+static struct screen *scrlist[MAX_SCR];
+static int num_scr;
+
+int init_screens(void)
+{
+       if(!(scrlist[num_scr++] = init_menu_screen())) {
+               return -1;
+       }
+       if(!(scrlist[num_scr++] = init_game_screen())) {
+               return -1;
+       }
+       return 0;
+}
+
+int change_screen(struct screen *scr)
+{
+       if(!scr) return -1;
+
+       mask(INTR_VBLANK);
+
+       if(scr->start && scr->start() == -1) {
+               return -1;
+       }
+       if(curscr && curscr->stop) {
+               curscr->stop();
+       }
+       curscr = scr;
+
+       unmask(INTR_VBLANK);
+       return 0;
+}
+
+struct screen *find_screen(const char *name)
+{
+       int i;
+       for(i=0; i<num_scr; i++) {
+               if(strcmp(scrlist[i]->name, name) == 0) {
+                       return scrlist[i];
+               }
+       }
+       return 0;
+}