double buffering
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 17 Mar 2024 19:02:05 +0000 (21:02 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 17 Mar 2024 19:02:05 +0000 (21:02 +0200)
src/gpu.c
src/gpu.h
src/main.c

index bc2f1a4..6a4823e 100644 (file)
--- a/src/gpu.c
+++ b/src/gpu.c
@@ -51,6 +51,11 @@ void gpu_display(int en)
        REG_GP1 = GPCMD(GP1_DISPEN) | (en ? 0 : 1);
 }
 
+void gpu_dispstart(int x, int y)
+{
+       REG_GP1 = GPCMD(GP1_START) | x | (y << 10);
+}
+
 void gpu_cliprect(int x, int y, int w, int h)
 {
        REG_GP0 = GPCMD(GP0_CLIP_TL) | x | (y << 10);
index 4bfe724..b8e2119 100644 (file)
--- a/src/gpu.h
+++ b/src/gpu.h
@@ -18,6 +18,7 @@ struct gpu_gvert {
 void gpu_reset(void);
 void gpu_setmode(int xsz, int ysz, int bpp, int rate);
 void gpu_display(int en);
+void gpu_dispstart(int x, int y);
 void gpu_cliprect(int x, int y, int w, int h);
 void gpu_origin(int x, int y);
 
index 073ea1c..3850c99 100644 (file)
@@ -18,6 +18,7 @@ int main(void)
        int16_t rotmat[9] = {0x1000, 0, 0, 0, 0x1000, 0, 0, 0, 0x1000};
        int trans[3] = {160, 120, 0};
        int resv[3];
+       int yoffs = 0;
 
        gte_init();
 
@@ -25,10 +26,7 @@ int main(void)
        gpu_setmode(320, 264, 15, 50);
        gpu_display(1);
 
-       REG_GP0 = GPCMD(GP0_TEXPG) | TEXPG_DRAWDISP | TEXPG_DITHER;
-
-       gpu_cliprect(0, 0, 320, 264);
-       gpu_origin(0, 0);
+       REG_GP0 = GPCMD(GP0_TEXPG) | TEXPG_DITHER;
 
        for(;;) {
                rotmat[0] = rotmat[4] = COS(frame);
@@ -42,19 +40,26 @@ int main(void)
                        gte_cmd_rot();
                        gte_getvec(resv);
 
-                       triangle[i].x = (resv[0] >> 6) + 160;
-                       triangle[i].y = (resv[1] >> 6) + 130;
+                       triangle[i].x = (resv[0] >> 6);
+                       triangle[i].y = (resv[1] >> 6);
                }
 
-               gpu_fillrect(0, 0, 320, 264, 0x202020);
+               /* use previous frame yoffs as display area */
+               gpu_dispstart(0, yoffs);
+
+               /* set yoffs to the new back buffer */
+               yoffs = (frame++ & 1) ? 0 : 264;
+
+               gpu_cliprect(0, yoffs, 320, 264 + yoffs);
+               gpu_origin(160, 130 + yoffs);
+
+               gpu_fillrect(0, yoffs, 320, 264, 0x202020);
 
                gpu_draw_gouraud(GP0_GTRI, triangle, 3);
 
-               for(i=0; i<100000; i++) {
+               for(i=0; i<8192; i++) {
                        asm volatile("nop; nop; nop; nop");
                }
-
-               frame++;
        }
        return 0;
 }