aboutsummaryrefslogtreecommitdiff
path: root/source/tile.cpp
diff options
context:
space:
mode:
authorNebuleon Fumika2013-01-10 18:01:32 -0500
committerNebuleon Fumika2013-01-10 18:01:32 -0500
commit736484548ea021452415a1711aab10e04b521451 (patch)
tree63cedb0dd10dbbf9c84a0ab19fbc7facbd978d37 /source/tile.cpp
parente1ec72de1078f0e371e212852a9273746b1aa42e (diff)
downloadsnes9x2005-736484548ea021452415a1711aab10e04b521451.tar.gz
snes9x2005-736484548ea021452415a1711aab10e04b521451.tar.bz2
snes9x2005-736484548ea021452415a1711aab10e04b521451.zip
Attempt to optimise the ADD background drawing mode so it's playable on automatic frameskip in games like Super Metroid. It doesn't work well.
See the video for this bug at <http://www.youtube.com/watch?v=sUWjVxAD9Q8>.
Diffstat (limited to 'source/tile.cpp')
-rw-r--r--source/tile.cpp250
1 files changed, 191 insertions, 59 deletions
diff --git a/source/tile.cpp b/source/tile.cpp
index e18182d..653a6d7 100644
--- a/source/tile.cpp
+++ b/source/tile.cpp
@@ -764,15 +764,18 @@ static void WRITE_4PIXELS16_ADD (uint32 Offset, uint8 *Pixels, uint16 *ScreenCol
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N]))
{
- if (SubDepth [N])
+ switch (SubDepth [N])
{
- if (SubDepth [N] != 1)
- Screen [N] = COLOR_ADD (ScreenColors [Pixel], Screen [GFX.Delta + N]);
- else
- Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
- }
- else
+ case 0:
Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ break;
+ }
Depth [N] = GFX.Z2;
}
}
@@ -789,15 +792,18 @@ static void WRITE_4PIXELS16_FLIPPED_ADD (uint32 Offset, uint8 *Pixels, uint16 *S
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N]))
{
- if (SubDepth [N])
+ switch (SubDepth [N])
{
- if (SubDepth [N] != 1)
- Screen [N] = COLOR_ADD (ScreenColors [Pixel], Screen [GFX.Delta + N]);
- else
- Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
- }
- else
+ case 0:
Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ break;
+ }
Depth [N] = GFX.Z2;
}
}
@@ -814,15 +820,18 @@ static void WRITE_4PIXELS16_ADD1_2 (uint32 Offset, uint8 *Pixels, uint16 *Screen
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N]))
{
- if (SubDepth [N])
+ switch (SubDepth [N])
{
- if (SubDepth [N] != 1)
- Screen [N] = (uint16) (COLOR_ADD1_2 (ScreenColors [Pixel], Screen [GFX.Delta + N]));
- else
- Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
- }
- else
+ case 0:
Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = (uint16) (COLOR_ADD1_2 (ScreenColors [Pixel], Screen [GFX.Delta + N]));
+ break;
+ }
Depth [N] = GFX.Z2;
}
}
@@ -839,15 +848,18 @@ static void WRITE_4PIXELS16_FLIPPED_ADD1_2 (uint32 Offset, uint8 *Pixels, uint16
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N]))
{
- if (SubDepth [N])
+ switch (SubDepth [N])
{
- if (SubDepth [N] != 1)
- Screen [N] = (uint16) (COLOR_ADD1_2 (ScreenColors [Pixel], Screen [GFX.Delta + N]));
- else
- Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
- }
- else
+ case 0:
Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = (uint16) (COLOR_ADD1_2 (ScreenColors [Pixel], Screen [GFX.Delta + N]));
+ break;
+ }
Depth [N] = GFX.Z2;
}
}
@@ -864,15 +876,18 @@ static void WRITE_4PIXELS16_SUB (uint32 Offset, uint8 *Pixels, uint16 *ScreenCol
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N]))
{
- if (SubDepth [N])
+ switch (SubDepth [N])
{
- if (SubDepth [N] != 1)
- Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], Screen [GFX.Delta + N]);
- else
- Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
- }
- else
+ case 0:
Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ break;
+ }
Depth [N] = GFX.Z2;
}
}
@@ -889,15 +904,18 @@ static void WRITE_4PIXELS16_FLIPPED_SUB (uint32 Offset, uint8 *Pixels, uint16 *S
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N]))
{
- if (SubDepth [N])
+ switch (SubDepth [N])
{
- if (SubDepth [N] != 1)
- Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], Screen [GFX.Delta + N]);
- else
- Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
- }
- else
+ case 0:
Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ break;
+ }
Depth [N] = GFX.Z2;
}
}
@@ -914,15 +932,18 @@ static void WRITE_4PIXELS16_SUB1_2 (uint32 Offset, uint8 *Pixels, uint16 *Screen
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[N]))
{
- if (SubDepth [N])
+ switch (SubDepth [N])
{
- if (SubDepth [N] != 1)
- Screen [N] = (uint16) COLOR_SUB1_2 (ScreenColors [Pixel], Screen [GFX.Delta + N]);
- else
- Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
- }
- else
+ case 0:
Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = (uint16) COLOR_SUB1_2 (ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ break;
+ }
Depth [N] = GFX.Z2;
}
}
@@ -939,15 +960,18 @@ static void WRITE_4PIXELS16_FLIPPED_SUB1_2 (uint32 Offset, uint8 *Pixels, uint16
{
if (GFX.Z1 > Depth [N] && (Pixel = Pixels[3 - N]))
{
- if (SubDepth [N])
+ switch (SubDepth [N])
{
- if (SubDepth [N] != 1)
- Screen [N] = (uint16) COLOR_SUB1_2 (ScreenColors [Pixel], Screen [GFX.Delta + N]);
- else
- Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
- }
- else
+ case 0:
Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = (uint16) COLOR_SUB (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = (uint16) COLOR_SUB1_2 (ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ break;
+ }
Depth [N] = GFX.Z2;
}
}
@@ -957,10 +981,118 @@ static void WRITE_4PIXELS16_FLIPPED_SUB1_2 (uint32 Offset, uint8 *Pixels, uint16
void DrawTile16Add (uint32 Tile, uint32 Offset, uint32 StartLine,
uint32 LineCount)
{
- TILE_PREAMBLE
- register uint8 *bp;
+ TILE_PREAMBLE
+ register uint8 *bp;
+ uint8 Pixel;
+ uint16 *Screen = (uint16 *) GFX.S + Offset;
+ uint8 *Depth = GFX.ZBuffer + Offset;
+ uint8 *SubDepth = GFX.SubZBuffer + Offset;
- RENDER_TILE(WRITE_4PIXELS16_ADD, WRITE_4PIXELS16_FLIPPED_ADD, 4)
+ switch (Tile & (V_FLIP | H_FLIP))
+ {
+ case 0:
+ bp = pCache + StartLine;
+ for (l = LineCount; l != 0; l--, bp += 8, Screen += GFX.PPL, Depth += GFX.PPL, SubDepth += GFX.PPL)
+ {
+ for (uint8 N = 0; N < 8; N++)
+ {
+ if (GFX.Z1 > Depth [N] && (Pixel = bp[N]))
+ {
+ switch (SubDepth [N])
+ {
+ case 0:
+ Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ break;
+ }
+ Depth [N] = GFX.Z2;
+ }
+ }
+ }
+ break;
+ case H_FLIP:
+ bp = pCache + StartLine;
+ for (l = LineCount; l != 0; l--, bp += 8, Screen += GFX.PPL, Depth += GFX.PPL, SubDepth += GFX.PPL)
+ {
+ for (uint8 N = 0; N < 8; N++)
+ {
+ if (GFX.Z1 > Depth [N] && (Pixel = bp[7 - N]))
+ {
+ switch (SubDepth [N])
+ {
+ case 0:
+ Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ break;
+ }
+ Depth [N] = GFX.Z2;
+ }
+ }
+ }
+ break;
+ case H_FLIP | V_FLIP:
+ bp = pCache + 56 - StartLine;
+ for (l = LineCount; l != 0; l--, bp -= 8, Screen += GFX.PPL, Depth += GFX.PPL, SubDepth += GFX.PPL)
+ {
+ for (uint8 N = 0; N < 8; N++)
+ {
+ if (GFX.Z1 > Depth [N] && (Pixel = bp[7 - N]))
+ {
+ switch (SubDepth [N])
+ {
+ case 0:
+ Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ break;
+ }
+ Depth [N] = GFX.Z2;
+ }
+ }
+ }
+ break;
+ case V_FLIP:
+ bp = pCache + 56 - StartLine;
+ for (l = LineCount; l != 0; l--, bp -= 8, Screen += GFX.PPL, Depth += GFX.PPL, SubDepth += GFX.PPL)
+ {
+ for (uint8 N = 0; N < 8; N++)
+ {
+ if (GFX.Z1 > Depth [N] && (Pixel = bp[N]))
+ {
+ switch (SubDepth [N])
+ {
+ case 0:
+ Screen [N] = ScreenColors [Pixel];
+ break;
+ case 1:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], GFX.FixedColour);
+ break;
+ default:
+ Screen [N] = COLOR_ADD (ScreenColors [Pixel], Screen [GFX.Delta + N]);
+ break;
+ }
+ Depth [N] = GFX.Z2;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
}
void DrawClippedTile16Add (uint32 Tile, uint32 Offset,