aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-04-10 20:24:41 +0200
committerStapleButter <thetotalworm@gmail.com>2017-04-10 20:24:41 +0200
commit8bbcc83771fb466aabb751be86e0c593e45313ae (patch)
tree93a81a23a6cb7767fad4dc337ace6ab0763b1351
parentf2622c047b957c6562089c0e953334845e23fec6 (diff)
* always render normal BG/OBJ graphics (even if they're not getting displayed, they can still be fed to the capture unit)
* fix 3D viewport calculation * keep track of the clearbuffer attributes before VBlank
-rw-r--r--src/GPU2D.cpp40
-rw-r--r--src/GPU3D.cpp13
-rw-r--r--src/GPU3D.h2
-rw-r--r--src/GPU3D_Soft.cpp18
4 files changed, 41 insertions, 32 deletions
diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp
index 40f1c6e..e1419bf 100644
--- a/src/GPU2D.cpp
+++ b/src/GPU2D.cpp
@@ -368,6 +368,25 @@ void GPU2D::DrawScanline(u32 line)
u32 dispmode = DispCnt >> 16;
dispmode &= (Num ? 0x1 : 0x3);
+ // always render regular graphics
+ DrawScanline_Mode1(line, dst);
+
+ // capture
+ if ((Num == 0) && (CaptureCnt & (1<<31)))
+ {
+ u32 capwidth, capheight;
+ switch ((CaptureCnt >> 20) & 0x3)
+ {
+ case 0: capwidth = 128; capheight = 128; break;
+ case 1: capwidth = 256; capheight = 64; break;
+ case 2: capwidth = 256; capheight = 128; break;
+ case 3: capwidth = 256; capheight = 192; break;
+ }
+
+ if (line < capheight)
+ DoCapture(line, capwidth, dst);
+ }
+
switch (dispmode)
{
case 0: // screen off
@@ -377,10 +396,7 @@ void GPU2D::DrawScanline(u32 line)
}
break;
- case 1: // regular display
- {
- DrawScanline_Mode1(line, dst);
- }
+ case 1: // regular display, already taken care of
break;
case 2: // VRAM display
@@ -426,22 +442,6 @@ void GPU2D::DrawScanline(u32 line)
break;
}
- // capture
- if ((!Num) && (CaptureCnt & (1<<31)))
- {
- u32 capwidth, capheight;
- switch ((CaptureCnt >> 20) & 0x3)
- {
- case 0: capwidth = 128; capheight = 128; break;
- case 1: capwidth = 256; capheight = 64; break;
- case 2: capwidth = 256; capheight = 128; break;
- case 3: capwidth = 256; capheight = 192; break;
- }
-
- if (line < capheight)
- DoCapture(line, capwidth, dst);
- }
-
// master brightness
if (dispmode != 0)
{
diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp
index 41baf34..e06ff90 100644
--- a/src/GPU3D.cpp
+++ b/src/GPU3D.cpp
@@ -57,6 +57,10 @@
// (the idea is that each position matrix has an associated vector matrix)
//
// TODO: check if translate works on the vector matrix? seems pointless
+//
+// viewport Y coordinates are upside-down
+//
+// clear color/depth/bitmap/etc registers (04000350/04000354) are double-buffered
namespace GPU3D
@@ -237,6 +241,7 @@ Polygon* RenderPolygonRAM;
u32 RenderNumPolygons;
u32 ClearAttr1, ClearAttr2;
+u32 RenderClearAttr1, RenderClearAttr2;
u32 FlushRequest;
u32 FlushAttributes;
@@ -1634,10 +1639,11 @@ void ExecuteCommand()
break;
case 0x60: // viewport x1,y1,x2,y2
+ // note: viewport Y coordinates are upside-down
Viewport[0] = ExecParams[0] & 0xFF;
- Viewport[1] = (ExecParams[0] >> 8) & 0xFF;
+ Viewport[1] = 191 - (ExecParams[0] >> 24);
Viewport[2] = ((ExecParams[0] >> 16) & 0xFF) - Viewport[0] + 1;
- Viewport[3] = (ExecParams[0] >> 24) - Viewport[1] + 1;
+ Viewport[3] = (191 - ((ExecParams[0] >> 8) & 0xFF)) - Viewport[1] + 1;
break;
case 0x70: // box test
@@ -1725,6 +1731,9 @@ void VBlank()
RenderPolygonRAM = CurPolygonRAM;
RenderNumPolygons = NumPolygons;
+ RenderClearAttr1 = ClearAttr1;
+ RenderClearAttr2 = ClearAttr2;
+
CurRAMBank = CurRAMBank?0:1;
CurVertexRAM = &VertexRAM[CurRAMBank ? 6144 : 0];
CurPolygonRAM = &PolygonRAM[CurRAMBank ? 2048 : 0];
diff --git a/src/GPU3D.h b/src/GPU3D.h
index be121bf..5c29b76 100644
--- a/src/GPU3D.h
+++ b/src/GPU3D.h
@@ -59,7 +59,7 @@ typedef struct
extern u32 DispCnt;
extern u32 AlphaRef;
extern s32 Viewport[4];
-extern u32 ClearAttr1, ClearAttr2;
+extern u32 RenderClearAttr1, RenderClearAttr2;
bool Init();
void DeInit();
diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp
index f15761c..dc94130 100644
--- a/src/GPU3D_Soft.cpp
+++ b/src/GPU3D_Soft.cpp
@@ -781,12 +781,12 @@ void RenderPolygon(Polygon* polygon)
void RenderFrame(Vertex* vertices, Polygon* polygons, int npolys)
{
- u32 polyid = (ClearAttr1 >> 24) & 0x3F;
+ u32 polyid = (RenderClearAttr1 >> 24) & 0x3F;
if (DispCnt & (1<<14))
{
- u8 xoff = (ClearAttr2 >> 16) & 0xFF;
- u8 yoff = (ClearAttr2 >> 24) & 0xFF;
+ u8 xoff = (RenderClearAttr2 >> 16) & 0xFF;
+ u8 yoff = (RenderClearAttr2 >> 24) & 0xFF;
for (int y = 0; y < 256*192; y += 256)
{
@@ -818,16 +818,16 @@ void RenderFrame(Vertex* vertices, Polygon* polygons, int npolys)
else
{
// TODO: confirm color conversion
- u32 r = (ClearAttr1 << 1) & 0x3E; if (r) r++;
- u32 g = (ClearAttr1 >> 4) & 0x3E; if (g) g++;
- u32 b = (ClearAttr1 >> 9) & 0x3E; if (b) b++;
- u32 a = (ClearAttr1 >> 16) & 0x1F;
+ u32 r = (RenderClearAttr1 << 1) & 0x3E; if (r) r++;
+ u32 g = (RenderClearAttr1 >> 4) & 0x3E; if (g) g++;
+ u32 b = (RenderClearAttr1 >> 9) & 0x3E; if (b) b++;
+ u32 a = (RenderClearAttr1 >> 16) & 0x1F;
u32 color = r | (g << 8) | (b << 16) | (a << 24);
- u32 z = ((ClearAttr2 & 0x7FFF) * 0x200) + 0x1FF;
+ u32 z = ((RenderClearAttr2 & 0x7FFF) * 0x200) + 0x1FF;
if (z >= 0x10000 && z < 0xFFFFFF) z++;
- polyid |= ((ClearAttr1 & 0x8000) >> 7);
+ polyid |= ((RenderClearAttr1 & 0x8000) >> 7);
for (int i = 0; i < 256*192; i++)
{