foo
[gbajam21] / src / gamescr.c
index 330331e..4c7d6ba 100644 (file)
@@ -2,14 +2,10 @@
 #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)
-
-
 void gamescr(void)
 {
        int i, j, tx, ty, angle, depth, nframes, backbuf, zoffs;
@@ -20,6 +16,8 @@ void gamescr(void)
 
        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 +25,9 @@ void gamescr(void)
                csrc += 3;
        }
 
+       dma_fill16(3, vram[0], 0xffff, 240 * 160 / 2);
+       dma_fill16(3, vram[1], 0xffff, 240 * 160 / 2);
+
        nframes = 0;
        for(;;) {
                backbuf = ++nframes & 1;
@@ -36,7 +37,9 @@ void gamescr(void)
                cdst = vram[backbuf];
                tunptr = tunmap;
                for(i=0; i<160; i++) {
-                       for(j=0; j<240/2; j++) {
+                       cdst++;
+                       tunptr += 2;
+                       for(j=1; j<240/2; j++) {
                                uint16_t pp;
 
                                tun = *tunptr++;
@@ -57,9 +60,9 @@ void gamescr(void)
                        }
                }
 
-               //while(!(REG_DISPSTAT & DISPSTAT_VBLANK));
-               while(REG_VCOUNT < 160);
-               //REG_DISPCNT ^= DISPCNT_FB1;
+               vblperf_end();
+               wait_vblank();
                present(backbuf);
+               vblperf_start();
        }
 }