panic screen, debug font, asmutil.s
[gbajam21] / src / gamescr.c
index 330331e..bd73b1b 100644 (file)
@@ -1,14 +1,13 @@
+#include <stdlib.h>
 #include <string.h>
 #include "gbaregs.h"
 #include "dma.h"
 #include "data.h"
+#include "util.h"
+#include "intr.h"
 #include "debug.h"
 
-#define present(x) \
-       do { \
-               REG_DISPCNT = DISPCNT_BG2 | 4 | ((x) << 4); \
-       } while(0)
-
+static unsigned char tex[32 * 32] __attribute__((section(".iwram")));
 
 void gamescr(void)
 {
@@ -16,10 +15,12 @@ void gamescr(void)
        static uint16_t *vram[] = { (uint16_t*)VRAM_LFB_FB0_ADDR, (uint16_t*)VRAM_LFB_FB1_ADDR };
        uint16_t *cdst;
        unsigned char *csrc;
-       uint32_t tun, *tunptr;
+       uint32_t tun, *tunptr, *tuncache;
 
        REG_DISPCNT = 4 | DISPCNT_BG2 | DISPCNT_FB1;
 
+       vblperf_start(0xff);
+
        cdst = (uint16_t*)CRAM_BG_ADDR;
        csrc = tuncross_cmap;
        for(i=0; i<256; i++) {
@@ -27,6 +28,15 @@ void gamescr(void)
                csrc += 3;
        }
 
+       fillblock_16byte(vram[0], 0xffffffff, 240 * 160 / 16);
+       fillblock_16byte(vram[1], 0xffffffff, 240 * 160 / 16);
+
+       if(!(tuncache = malloc(240 * 160 * 2))) {
+               panic(get_pc(), "failed to allocate tuntab");
+       }
+       memcpy(tuncache, tunmap, 240 * 160 * 2);
+       memcpy(tex, tuncross_pixels, 32 * 32);
+
        nframes = 0;
        for(;;) {
                backbuf = ++nframes & 1;
@@ -34,32 +44,32 @@ void gamescr(void)
                zoffs = nframes << 1;
 
                cdst = vram[backbuf];
-               tunptr = tunmap;
-               for(i=0; i<160; i++) {
-                       for(j=0; j<240/2; j++) {
+               tunptr = tuncache;
+               for(i=0; i<160 * 240 / 2; i++) {
+                       //for(j=1; j<240/2; j++) {
                                uint16_t pp;
 
                                tun = *tunptr++;
-                               angle = tun & 0xffff;
-                               depth = tun >> 16;
-                               tx = (angle >> 6) & 0x7f;
-                               ty = ((depth >> 7) - zoffs) & 0x7f;
-                               pp = tuncross_pixels[(ty << 7) + tx];
 
-                               tun = *tunptr++;
-                               angle = tun & 0xffff;
-                               depth = tun >> 16;
-                               tx = (angle >> 6) & 0x7f;
-                               ty = ((depth >> 7) - zoffs) & 0x7f;
-                               pp |= (uint16_t)tuncross_pixels[(ty << 7) + tx] << 8;
+                               angle = tun & 0xff;
+                               depth = (tun >> 8) & 0xff;
+                               tx = (angle >> 1) & 0x1f;
+                               ty = ((depth >> 1) + zoffs) & 0x1f;
+                               pp = tex[(ty << 5) + tx];
+
+                               angle = (tun >> 16) & 0xff;
+                               depth = (tun >> 24) & 0xff;
+                               tx = (angle >> 1) & 0x1f;
+                               ty = ((depth >> 1) + zoffs) & 0x1f;
+                               pp |= (uint16_t)tex[(ty << 5) + tx] << 8;
 
                                *cdst++ = pp;
-                       }
+                       //}
                }
 
-               //while(!(REG_DISPSTAT & DISPSTAT_VBLANK));
-               while(REG_VCOUNT < 160);
-               //REG_DISPCNT ^= DISPCNT_FB1;
+               vblperf_end();
+               wait_vblank();
                present(backbuf);
+               vblperf_begin();
        }
 }