non-gba port continues
[gbajam22] / src / gamescr.c
index 73566c3..e71c6e1 100644 (file)
@@ -7,6 +7,7 @@
 #include "intr.h"
 #include "input.h"
 #include "player.h"
+#include "gba.h"
 #include "sprite.h"
 #include "debug.h"
 #include "level.h"
 
 static void update(void);
 static void draw(void);
+#ifdef BUILD_GBA
 static void vblank(void);
+#endif
 
 static int nframes, num_vbl, backbuf;
-static uint16_t *vram[] = { (uint16_t*)VRAM_LFB_FB0_ADDR, (uint16_t*)VRAM_LFB_FB1_ADDR };
+static uint16_t *vram[] = { gba_vram_lfb0, gba_vram_lfb1 };
 
 static const char *testlvl =
-       "########\n"
-       "###   s#\n"
-       "### ####\n"
-       "###    #\n"
-       "##     #\n"
-       "##     #\n"
-       "##     #\n"
-       "## ### #\n"
-       "## ### #\n"
-       "##     #\n"
-       "#### ###\n"
-       "########\n";
+       "################\n"
+       "################\n"
+       "################\n"
+       "################\n"
+       "################\n"
+       "#######   s#####\n"
+       "####### ########\n"
+       "#######    #####\n"
+       "######     #####\n"
+       "######     #####\n"
+       "######     #####\n"
+       "###### ### #####\n"
+       "###### ### #####\n"
+       "######     #####\n"
+       "######## #######\n"
+       "################\n"
+       "################\n"
+       "################\n"
+       "################\n"
+       "################\n";
 
 static struct xvertex tm_floor[] __attribute__((section(".rodata"))) = {
        {0x10000, -0x10000, 0x10000,    0, 0x10000, 0,  210},
@@ -49,9 +60,11 @@ static struct player player;
 
 void gamescr(void)
 {
+       int i;
        unsigned char *fb;
+       uint16_t *cmap;
 
-       REG_DISPCNT = 4 | DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1;
+       gba_setmode(4, DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1);
 
        vblperf_setcolor(1);
 
@@ -59,14 +72,25 @@ void gamescr(void)
 
        xgl_init();
 
-       memset(&player, 0, sizeof player);
+       init_player(&player, lvl);
        player.phi = 0x100;
 
+       cmap = gba_bgpal;
+       *cmap++ = 0;
+       for(i=1; i<255; i++) {
+               *cmap++ = rand();
+       }
+       *cmap = 0xffff;
+
+
        select_input(BN_DPAD | BN_A | BN_B);
 
+       /* TODO emulate interrupts on non-GBA builds */
+#ifdef BUILD_GBA
        mask(INTR_VBLANK);
        screen_vblank = vblank;
        unmask(INTR_VBLANK);
+#endif
 
        nframes = 0;
        for(;;) {
@@ -103,6 +127,7 @@ static void draw(void)
        struct cell *cell;
 
        xgl_load_identity();
+       /*xgl_translate(0, 0, 0x100000);*/
        xgl_rotate_x(player.phi);
        xgl_rotate_y(player.theta);
        xgl_translate(player.x, 0, player.y);
@@ -115,13 +140,16 @@ static void draw(void)
 
                xgl_push_matrix();
                xgl_translate(x, 0, y);
+               xgl_index(i + 1);
                xgl_draw(XGL_QUADS, tm_floor, sizeof tm_floor / sizeof *tm_floor);
                xgl_pop_matrix();
        }
 }
 
+#ifdef BUILD_GBA
 __attribute__((noinline, target("arm"), section(".iwram")))
 static void vblank(void)
 {
        num_vbl++;
 }
+#endif