From: John Tsiombikas Date: Sun, 17 Mar 2024 19:02:05 +0000 (+0200) Subject: double buffering X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=4328f63283ecf1de957e5a8fb6da861894724934;p=psx_test1 double buffering --- diff --git a/src/gpu.c b/src/gpu.c index bc2f1a4..6a4823e 100644 --- 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); diff --git a/src/gpu.h b/src/gpu.h index 4bfe724..b8e2119 100644 --- 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); diff --git a/src/main.c b/src/main.c index 073ea1c..3850c99 100644 --- a/src/main.c +++ b/src/main.c @@ -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; }