From f4091374320a4decaf2756f3a90374e843c9f6c7 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 28 Dec 2018 01:35:37 +0100 Subject: More work on making code C89-compliant --- Makefile | 10 +- src/gfx.c | 485 ++++++++++++++++++++++++++++++++++--------------------------- src/ppu_.c | 24 +-- src/tile.c | 143 +++++++++--------- src/tile.h | 14 +- 5 files changed, 368 insertions(+), 308 deletions(-) diff --git a/Makefile b/Makefile index 16c3b74..5b26a78 100644 --- a/Makefile +++ b/Makefile @@ -284,8 +284,8 @@ else TARGET := $(TARGET_NAME)_libretro.dll CC = gcc fpic := - LD_FLAGS := - SHARED := -shared -static-libgcc -static-libstdc++ -Wl,--version-script=libretro/link.T + SHARED := -shared -Wl,--no-undefined -Wl,--version-script=libretro/link.T + LD_FLAGS += -static-libgcc -static-libstdc++ -lwinmm CFLAGS += -D__WIN32__ -D__WIN32_LIBRETRO__ endif @@ -306,6 +306,10 @@ OBJECTS := $(SOURCES:.c=.o) $(SOURCES_ASM:.S=.o) CFLAGS += $(DEFINES) $(COMMON_DEFINES) $(INCLUDES) +LDFLAGS += $(fpic) + +FLAGS += $(fpic) + ifneq (,$(findstring msvc,$(platform))) LIBM = OBJOUT = -Fo @@ -331,7 +335,7 @@ $(TARGET): $(OBJECTS) ifeq ($(STATIC_LINKING), 1) $(AR) rcs $@ $(OBJECTS) else - $(LD) $(LINKOUT)$@ $(SHARED) $(fpic) $(LDFLAGS) $(LIBS) + $(LD) $(LINKOUT)$@ $(SHARED) $(OBJECTS) $(LDFLAGS) $(LIBS) endif %.o: %.c diff --git a/src/gfx.c b/src/gfx.c index 72f13e1..3c39f87 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -245,6 +245,8 @@ void DrawHiResTile16(uint32 Tile, int32 Offset, bool8_32 S9xGraphicsInit(void) { + uint8 bitshift; + uint32 r, g, b; uint32 PixelOdd = 1; uint32 PixelEven = 2; @@ -253,7 +255,6 @@ bool8_32 S9xGraphicsInit(void) S9xSetRenderPixelFormat(RGB565); #endif - uint8 bitshift; for (bitshift = 0; bitshift < 4; bitshift++) { int i; @@ -379,7 +380,6 @@ bool8_32 S9xGraphicsInit(void) } return (FALSE); } - uint32 r, g, b; // Build a lookup table that multiplies a packed RGB value by 2 with // saturation. @@ -741,53 +741,57 @@ static INLINE void SelectTileRenderer(bool8_32 normal, bool NoZ) } } -void S9xSetupOBJ() +void S9xSetupOBJ(void) { + int C = 0; int SmallSize; int LargeSize; + int S; + int FirstSprite; switch (PPU.OBJSizeSelect) { - case 0: - SmallSize = 8; - LargeSize = 16; - break; - case 1: - SmallSize = 8; - LargeSize = 32; - break; - case 2: - SmallSize = 8; - LargeSize = 64; - break; - case 3: - SmallSize = 16; - LargeSize = 32; - break; - case 4: - SmallSize = 16; - LargeSize = 64; - break; - case 5: - default: - SmallSize = 32; - LargeSize = 64; - break; + case 0: + SmallSize = 8; + LargeSize = 16; + break; + case 1: + SmallSize = 8; + LargeSize = 32; + break; + case 2: + SmallSize = 8; + LargeSize = 64; + break; + case 3: + SmallSize = 16; + LargeSize = 32; + break; + case 4: + SmallSize = 16; + LargeSize = 64; + break; + case 5: + default: + SmallSize = 32; + LargeSize = 64; + break; } - int C = 0; + FirstSprite = PPU.FirstSprite & 0x7f; + S = FirstSprite; - int FirstSprite = PPU.FirstSprite & 0x7f; - int S = FirstSprite; do { int Size; + long VPos; + if (PPU.OBJ [S].Size) Size = LargeSize; else Size = SmallSize; - long VPos = PPU.OBJ [S].VPos; + VPos = PPU.OBJ [S].VPos; if (VPos >= PPU.ScreenHeight) VPos -= 256; @@ -811,6 +815,8 @@ void DrawOBJS(bool8_32 OnMain, uint8 D) { uint32 O; uint32 BaseTile, Tile; + int I = 0; + int S; BG.BitShift = 4; BG.TileShift = 5; @@ -827,10 +833,9 @@ void DrawOBJS(bool8_32 OnMain, uint8 D) GFX.Z1 = D + 2; - int I = 0; - int S; for (S = GFX.OBJList [I++]; S >= 0; S = GFX.OBJList [I++]) { + int clipcount; int clip, Offset; int VPos = GFX.VPositions [S]; int Size = GFX.Sizes[S]; @@ -852,7 +857,7 @@ void DrawOBJS(bool8_32 OnMain, uint8 D) if (PPU.OBJ[S].VFlip) BaseTile |= V_FLIP; - int clipcount = GFX.pCurrentClip->Count [4]; + clipcount = GFX.pCurrentClip->Count [4]; if (!clipcount) clipcount = 1; @@ -880,6 +885,8 @@ void DrawOBJS(bool8_32 OnMain, uint8 D) { if (VPos + Y + 7 >= (int) GFX.StartY && VPos + Y <= (int) GFX.EndY) { + int X; + int Middle; int StartLine; int TileLine; int LineCount; @@ -906,7 +913,7 @@ void DrawOBJS(bool8_32 OnMain, uint8 D) else Tile = BaseTile + ((Size - Y - 8) << 1); - int Middle = Size >> 3; + Middle = Size >> 3; if (PPU.OBJ[S].HPos < Left) { Tile += ((Left - PPU.OBJ[S].HPos) >> 3) * TileInc; @@ -914,9 +921,11 @@ void DrawOBJS(bool8_32 OnMain, uint8 D) O += Left * GFX_PIXSIZE; if ((Offset = (Left - PPU.OBJ[S].HPos) & 7)) { - O -= Offset * GFX_PIXSIZE; - int W = 8 - Offset; - int Width = Right - Left; + int W, Width; + + O -= Offset * GFX_PIXSIZE; + W = 8 - Offset; + Width = Right - Left; if (W > Width) W = Width; (*DrawClippedTilePtr)(Tile, O, Offset, W, @@ -941,15 +950,12 @@ void DrawOBJS(bool8_32 OnMain, uint8 D) else Offset = 0; - int X; for (X = 0; X < Middle; X++, O += 8 * GFX_PIXSIZE, Tile += TileInc) (*DrawTilePtr)(Tile, O, TileLine, LineCount); if (Offset) - { (*DrawClippedTilePtr)(Tile, O, 0, Offset, TileLine, LineCount); - } } } } @@ -958,6 +964,10 @@ void DrawOBJS(bool8_32 OnMain, uint8 D) void DrawBackgroundMosaic(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { + uint32 Y; + uint32 Lines; + uint32 OffsetMask; + uint32 OffsetShift; uint32 Tile; uint16* SC0; uint16* SC1; @@ -1000,9 +1010,6 @@ void DrawBackgroundMosaic(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) if (((uint8*)SC3 - Memory.VRAM) >= 0x10000) SC3 -= 0x08000; - uint32 Lines; - uint32 OffsetMask; - uint32 OffsetShift; if (BG.TileSize == 16) { @@ -1015,10 +1022,21 @@ void DrawBackgroundMosaic(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) OffsetShift = 3; } - uint32 Y; for (Y = GFX.StartY; Y <= GFX.EndY; Y += Lines) { + uint16* t; + uint32 Left = 0; + uint32 Right = 256; + uint16* b1; + uint16* b2; + uint32 VirtAlign; + uint32 ScreenLine; + uint32 Rem16; + uint32 MosaicLine; uint32 clip, x; + uint32 ClipCount; + uint32 HPos; + uint32 PixWidth; uint32 VOffset = LineData [Y].BG[bg].VOffset; uint32 HOffset = LineData [Y].BG[bg].HOffset; uint32 MosaicOffset = Y % PPU.Mosaic; @@ -1028,17 +1046,13 @@ void DrawBackgroundMosaic(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) (HOffset != LineData [Y + Lines].BG[bg].HOffset)) break; - uint32 MosaicLine = VOffset + Y - MosaicOffset; + MosaicLine = VOffset + Y - MosaicOffset; if (Y + Lines > GFX.EndY) - Lines = GFX.EndY + 1 - Y; - uint32 VirtAlign = (MosaicLine & 7) << 3; - - uint16* b1; - uint16* b2; - - uint32 ScreenLine = MosaicLine >> OffsetShift; - uint32 Rem16 = MosaicLine & 15; + Lines = GFX.EndY + 1 - Y; + VirtAlign = (MosaicLine & 7) << 3; + ScreenLine = MosaicLine >> OffsetShift; + Rem16 = MosaicLine & 15; if (ScreenLine & 0x20) b1 = SC2, b2 = SC3; @@ -1047,28 +1061,28 @@ void DrawBackgroundMosaic(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) b1 += (ScreenLine & 0x1f) << 5; b2 += (ScreenLine & 0x1f) << 5; - uint16* t; - uint32 Left = 0; - uint32 Right = 256; - uint32 ClipCount = GFX.pCurrentClip->Count [bg]; - uint32 HPos = HOffset; - uint32 PixWidth = PPU.Mosaic; + ClipCount = GFX.pCurrentClip->Count [bg]; + HPos = HOffset; + PixWidth = PPU.Mosaic; if (!ClipCount) ClipCount = 1; for (clip = 0; clip < ClipCount; clip++) { + uint32 s; if (GFX.pCurrentClip->Count [bg]) { - Left = GFX.pCurrentClip->Left [clip][bg]; - Right = GFX.pCurrentClip->Right [clip][bg]; - uint32 r = Left % PPU.Mosaic; - HPos = HOffset + Left; + uint32 r; + + Left = GFX.pCurrentClip->Left [clip][bg]; + Right = GFX.pCurrentClip->Right [clip][bg]; + r = Left % PPU.Mosaic; + HPos = HOffset + Left; PixWidth = PPU.Mosaic - r; } - uint32 s = Y * GFX_PPL + Left * GFX_PIXSIZE; + s = Y * GFX_PPL + Left * GFX_PIXSIZE; for (x = Left; x < Right; x += PixWidth, s += PixWidth * GFX_PIXSIZE, HPos += PixWidth, PixWidth = PPU.Mosaic) @@ -1182,6 +1196,10 @@ void DrawBackgroundMosaic(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) void DrawBackgroundOffset(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { + static const int Lines = 1; + uint32 Y; + int OffsetMask; + int OffsetShift; uint32 Tile; uint16* SC0; uint16* SC1; @@ -1192,6 +1210,7 @@ void DrawBackgroundOffset(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) uint16* BPS2; uint16* BPS3; uint32 Width; + int OffsetEnableMask; int VOffsetOffset = BGMode == 4 ? 0 : 32; uint8 depths [2] = {Z1, Z2}; @@ -1243,10 +1262,7 @@ void DrawBackgroundOffset(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) if (((uint8*)SC3 - Memory.VRAM) >= 0x10000) SC3 -= 0x08000; - static const int Lines = 1; - int OffsetMask; - int OffsetShift; - int OffsetEnableMask = 1 << (bg + 13); + OffsetEnableMask = 1 << (bg + 13); if (BG.TileSize == 16) { @@ -1260,7 +1276,6 @@ void DrawBackgroundOffset(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) } TileBlank = 0xFFFFFFFF; - uint32 Y; for (Y = GFX.StartY; Y <= GFX.EndY; Y++) { @@ -1268,6 +1283,7 @@ void DrawBackgroundOffset(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) uint32 VOff = LineData [Y].BG[2].VOffset - 1; uint32 HOff = LineData [Y].BG[2].HOffset; int VirtAlign; + int clipcount; int ScreenLine = VOff >> 3; uint16* s0; uint16* s1; @@ -1293,7 +1309,7 @@ void DrawBackgroundOffset(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) else VOffsetOffset = 32; } - int clipcount = GFX.pCurrentClip->Count [bg]; + clipcount = GFX.pCurrentClip->Count [bg]; if (!clipcount) clipcount = 1; @@ -1301,24 +1317,8 @@ void DrawBackgroundOffset(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { uint32 Left; uint32 Right; - - if (!GFX.pCurrentClip->Count [bg]) - { - Left = 0; - Right = 256; - } - else - { - Left = GFX.pCurrentClip->Left [clip][bg]; - Right = GFX.pCurrentClip->Right [clip][bg]; - - if (Right <= Left) - continue; - } - uint32 VOffset; uint32 HOffset; - uint32 LineHOffset = LineData [Y].BG[bg].HOffset; int32 Offset; uint32 HPos; uint32 Quot; @@ -1331,16 +1331,35 @@ void DrawBackgroundOffset(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) uint16* b2; uint32 TotalCount = 0; uint32 MaxCount = 8; + uint32 LineHOffset; + uint32 s; + bool8_32 left_hand_edge; - uint32 s = Left * GFX_PIXSIZE + Y * GFX_PPL; - bool8_32 left_hand_edge = (Left == 0); - Width = Right - Left; + if (!GFX.pCurrentClip->Count [bg]) + { + Left = 0; + Right = 256; + } + else + { + Left = GFX.pCurrentClip->Left [clip][bg]; + Right = GFX.pCurrentClip->Right [clip][bg]; + + if (Right <= Left) + continue; + } + + LineHOffset = LineData [Y].BG[bg].HOffset; + s = Left * GFX_PIXSIZE + Y * GFX_PPL; + left_hand_edge = (Left == 0); + Width = Right - Left; if (Left & 7) MaxCount = 8 - (Left & 7); while (Left < Right) { + int tx_index; if (left_hand_edge) { // The SNES offset-per-tile background mode has a @@ -1392,7 +1411,6 @@ void DrawBackgroundOffset(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) VirtAlign = ((Y + VOffset) & 7) << 3; ScreenLine = (VOffset + Y) >> OffsetShift; - int tx_index; tx_index = (((VOffset + Y) & 15) <= 7) << 3; if (ScreenLine & 0x20) @@ -1456,8 +1474,11 @@ void DrawBackgroundOffset(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) void DrawBackgroundMode5(uint32 BGMODE, uint32 bg, uint8 Z1, uint8 Z2) { + int Y; + int endy; + int Lines; + int VOffsetShift = 3; uint8 depths [2] = {Z1, Z2}; - uint32 Tile; uint16* SC0; uint16* SC1; @@ -1492,17 +1513,21 @@ void DrawBackgroundMode5(uint32 BGMODE, uint32 bg, uint8 Z1, uint8 Z2) if (((uint8*)SC3 - Memory.VRAM) >= 0x10000) SC3 -= 0x08000; - int Lines; - int VOffsetShift = 3; if (BG.TileSize == 16) VOffsetShift = 4; - int endy = GFX.EndY; - int Y; + endy = GFX.EndY; for (Y = GFX.StartY; Y <= endy; Y += Lines) { + uint16* b1; + uint16* b2; + int ScreenLine; + int t1; + int t2; int y = Y; + int clip; + int clipcount; uint32 VOffset = LineData [y].BG[bg].VOffset; uint32 HOffset = LineData [y].BG[bg].HOffset; int VirtAlign = (Y + VOffset) & 7; @@ -1516,9 +1541,7 @@ void DrawBackgroundMode5(uint32 BGMODE, uint32 bg, uint8 Z1, uint8 Z2) if (Y + Lines > endy) Lines = endy + 1 - Y; - int ScreenLine = (VOffset + Y) >> VOffsetShift; - int t1; - int t2; + ScreenLine = (VOffset + Y) >> VOffsetShift; if (((VOffset + Y) & 15) > 7) { t1 = 16; @@ -1529,8 +1552,6 @@ void DrawBackgroundMode5(uint32 BGMODE, uint32 bg, uint8 Z1, uint8 Z2) t1 = 0; t2 = 16; } - uint16* b1; - uint16* b2; if (ScreenLine & 0x20) b1 = SC2, b2 = SC3; @@ -1540,14 +1561,20 @@ void DrawBackgroundMode5(uint32 BGMODE, uint32 bg, uint8 Z1, uint8 Z2) b1 += (ScreenLine & 0x1f) << 5; b2 += (ScreenLine & 0x1f) << 5; - int clip; - int clipcount = GFX.pCurrentClip->Count [bg]; + clipcount = GFX.pCurrentClip->Count [bg]; if (!clipcount) clipcount = 1; for (clip = 0; clip < clipcount; clip++) { + int C; + int Middle; int Left; int Right; + uint16* t; + uint32 s; + uint32 HPos; + uint32 Quot; + uint32 Count = 0; if (!GFX.pCurrentClip->Count [bg]) { @@ -1563,13 +1590,10 @@ void DrawBackgroundMode5(uint32 BGMODE, uint32 bg, uint8 Z1, uint8 Z2) continue; } - uint32 s = (Left >> 1) * GFX_PIXSIZE + Y * GFX_PPL; - uint32 HPos = (HOffset + Left * GFX_PIXSIZE) & 0x3ff; - - uint32 Quot = HPos >> 3; - uint32 Count = 0; + s = (Left >> 1) * GFX_PIXSIZE + Y * GFX_PPL; + HPos = (HOffset + Left * GFX_PIXSIZE) & 0x3ff; + Quot = HPos >> 3; - uint16* t; if (Quot > 63) t = b2 + ((Quot >> 1) & 0x1f); else @@ -1644,8 +1668,8 @@ void DrawBackgroundMode5(uint32 BGMODE, uint32 bg, uint8 Z1, uint8 Z2) // Middle, unclipped tiles Count = Width - Count; - int C; - int Middle = Count >> 3; + + Middle = Count >> 3; Count &= 7; for (C = Middle; C > 0; s += 4, Quot++, C--) { @@ -1761,6 +1785,8 @@ void DrawBackgroundMode5(uint32 BGMODE, uint32 bg, uint8 Z1, uint8 Z2) void DrawBackground_8(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { + int Lines; + uint32 Y; uint32 Tile; uint16* SC0; uint16* SC1; @@ -1795,12 +1821,15 @@ void DrawBackground_8(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) if (((uint8*)SC3 - Memory.VRAM) >= 0x10000) SC3 -= 0x08000; - int Lines; TileBlank = 0xFFFFFFFF; - uint32 Y; for (Y = GFX.StartY; Y <= GFX.EndY; Y += Lines) { + int clip; + int clipcount; + uint16* b1; + uint16* b2; + uint32 ScreenLine; uint32 VOffset = LineData [Y].BG[bg].VOffset; uint32 HOffset = LineData [Y].BG[bg].HOffset; int VirtAlign = (Y + VOffset) & 7; @@ -1814,10 +1843,7 @@ void DrawBackground_8(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) Lines = GFX.EndY + 1 - Y; VirtAlign <<= 3; - - uint32 ScreenLine = (VOffset + Y) >> 3; - uint16* b1; - uint16* b2; + ScreenLine = (VOffset + Y) >> 3; if (ScreenLine & 0x20) b1 = SC2, b2 = SC3; @@ -1827,14 +1853,18 @@ void DrawBackground_8(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) b1 += (ScreenLine & 0x1f) << 5; b2 += (ScreenLine & 0x1f) << 5; - int clip; - int clipcount = GFX.pCurrentClip->Count [bg]; + clipcount = GFX.pCurrentClip->Count [bg]; if (!clipcount) clipcount = 1; for (clip = 0; clip < clipcount; clip++) { + int C; uint32 Left; uint32 Right; + uint32 s; + uint16* t; + uint32 Count = 0; + uint32 HPos, Quot; if (!GFX.pCurrentClip->Count [bg]) { @@ -1850,14 +1880,14 @@ void DrawBackground_8(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) continue; } - uint32 s = Left + Y * GFX_PPL; - uint32 HPos = (HOffset + Left) & 0x1ff; - uint32 Quot = HPos >> 3; - uint32 Count = 0; - uint16* t; + s = Left + Y * GFX_PPL; + HPos = (HOffset + Left) & 0x1ff; + Quot = HPos >> 3; - if (Quot > 31) t = b2 + (Quot & 0x1f); - else t = b1 + Quot; + if (Quot > 31) + t = b2 + (Quot & 0x1f); + else + t = b1 + Quot; Width = Right - Left; @@ -1866,7 +1896,8 @@ void DrawBackground_8(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { int32 Offset = (HPos & 7); Count = 8 - Offset; - if (Count > Width) Count = Width; + if (Count > Width) + Count = Width; s -= Offset; Tile = READ_2BYTES(t); if (Tile != TileBlank) @@ -1883,7 +1914,6 @@ void DrawBackground_8(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) // Middle, unclipped tiles Count = Width - Count; - int C; for (C = Count >> 3; C > 0; s += 8, Quot++, C--) { Tile = READ_2BYTES(t); @@ -1915,6 +1945,8 @@ void DrawBackground_8(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) void DrawBackground_16(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { + int Lines; + uint32 Y; uint32 Tile; uint16* SC0; uint16* SC1; @@ -1949,12 +1981,16 @@ void DrawBackground_16(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) if (((uint8*)SC3 - Memory.VRAM) >= 0x10000) SC3 -= 0x08000; - int Lines; TileBlank = 0xFFFFFFFF; - uint32 Y; for (Y = GFX.StartY; Y <= GFX.EndY; Y += Lines) { + int clip; + int clipcount; + int tx_index; + uint32 ScreenLine; + uint16* b1; + uint16* b2; uint32 VOffset = LineData [Y].BG[bg].VOffset; uint32 HOffset = LineData [Y].BG[bg].HOffset; int VirtAlign = (Y + VOffset) & 7; @@ -1969,10 +2005,9 @@ void DrawBackground_16(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) VirtAlign <<= 3; - uint32 ScreenLine = (VOffset + Y) >> 4; - int tx_index = (((VOffset + Y) & 15) <= 7) << 3; - uint16* b1; - uint16* b2; + + ScreenLine = (VOffset + Y) >> 4; + tx_index = (((VOffset + Y) & 15) <= 7) << 3; if (ScreenLine & 0x20) b1 = SC2, b2 = SC3; @@ -1982,14 +2017,19 @@ void DrawBackground_16(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) b1 += (ScreenLine & 0x1f) << 5; b2 += (ScreenLine & 0x1f) << 5; - int clip; - int clipcount = GFX.pCurrentClip->Count [bg]; + clipcount = GFX.pCurrentClip->Count [bg]; if (!clipcount) clipcount = 1; for (clip = 0; clip < clipcount; clip++) { + int C; uint32 Left; uint32 Right; + uint32 s; + uint32 HPos; + uint32 Quot; + uint32 Count = 0; + uint16* t; if (!GFX.pCurrentClip->Count [bg]) { @@ -2005,11 +2045,9 @@ void DrawBackground_16(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) continue; } - uint32 s = Left + Y * GFX_PPL; - uint32 HPos = (HOffset + Left) & 0x3ff; - uint32 Quot = HPos >> 3; - uint32 Count = 0; - uint16* t; + s = Left + Y * GFX_PPL; + HPos = (HOffset + Left) & 0x3ff; + Quot = HPos >> 3; if (Quot > 63) t = b2 + ((Quot >> 1) & 0x1f); else t = b1 + (Quot >> 1); @@ -2040,7 +2078,6 @@ void DrawBackground_16(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) // Middle, unclipped tiles Count = Width - Count; - int C; for (C = Count >> 3; C > 0; s += 8, Quot++, C--) { Tile = READ_2BYTES(t); @@ -2120,7 +2157,14 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) } #define RENDER_BACKGROUND_MODE7(FUNC) \ + int aa, cc; \ + int dir; \ + int startx, endx; \ + uint32 Left = 0; \ + uint32 Right = 256; \ uint32 clip, Line; \ + uint32 ClipCount; \ + SLineMatrixData *l; \ uint8 *VRAM1 = Memory.VRAM + 1; \ if (GFX.r2130 & 1) \ { \ @@ -2131,22 +2175,16 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) else \ GFX.ScreenColors = IPPU.ScreenColors; \ \ - int aa, cc; \ - int dir; \ - int startx, endx; \ - uint32 Left = 0; \ - uint32 Right = 256; \ - uint32 ClipCount = GFX.pCurrentClip->Count [bg]; \ -\ + ClipCount = GFX.pCurrentClip->Count [bg]; \ if (!ClipCount) \ - ClipCount = 1; \ + ClipCount = 1; \ \ Screen += GFX.StartY * GFX_PITCH; \ - SLineMatrixData *l = &LineMatrixData [GFX.StartY]; \ + l = &LineMatrixData [GFX.StartY]; \ \ for (Line = GFX.StartY; Line <= GFX.EndY; Line++, Screen += GFX_PITCH, l++) \ { \ - int yy; \ + int yy, BB, DD; \ \ int32 HOffset = ((int32) LineData [Line].BG[0].HOffset << M7) >> M7; \ int32 VOffset = ((int32) LineData [Line].BG[0].VOffset << M7) >> M7; \ @@ -2163,11 +2201,14 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) yy += (VOffset - CentreY) % 1023; \ else \ yy += VOffset - CentreY; \ - int BB = l->MatrixB * yy + (CentreX << 8); \ - int DD = l->MatrixD * yy + (CentreY << 8); \ + BB = l->MatrixB * yy + (CentreX << 8); \ + DD = l->MatrixD * yy + (CentreY << 8); \ \ for (clip = 0; clip < ClipCount; clip++) \ { \ + int xx; \ + int AA, CC; \ + uint16 *p; \ if (GFX.pCurrentClip->Count [bg]) \ { \ Left = GFX.pCurrentClip->Left [clip][bg]; \ @@ -2175,7 +2216,7 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) if (Right <= Left) \ continue; \ } \ - uint16 *p = (uint16 *) Screen + Left; \ + p = (uint16 *) Screen + Left; \ \ if (PPU.Mode7HFlip) \ { \ @@ -2193,13 +2234,12 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) aa = l->MatrixA; \ cc = l->MatrixC; \ } \ - int xx; \ if (PPU.Mode7Repeat == 0) \ xx = startx + (HOffset - CentreX) % 1023; \ else \ xx = startx + HOffset - CentreX; \ - int AA = l->MatrixA * xx; \ - int CC = l->MatrixC * xx; \ + AA = l->MatrixA * xx; \ + CC = l->MatrixC * xx; \ \ if (!PPU.Mode7Repeat) \ { \ @@ -2234,22 +2274,19 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { \ uint8 *TileData = VRAM1 + (Memory.VRAM[((Y & ~7) << 5) + ((X >> 2) & ~1)] << 7); \ uint32 b = *(TileData + ((Y & 7) << 4) + ((X & 7) << 1)); \ - if (b) \ - { \ + if (b) \ *p = (FUNC); \ - } \ } \ else \ { \ if (PPU.Mode7Repeat == 3) \ { \ + uint32 b; \ X = (x + HOffset) & 7; \ Y = (yy + CentreY) & 7; \ - uint32 b = *(VRAM1 + ((Y & 7) << 4) + ((X & 7) << 1)); \ + b = *(VRAM1 + ((Y & 7) << 4) + ((X & 7) << 1)); \ if (b ) \ - { \ *p = (FUNC); \ - } \ } \ } \ } \ @@ -2258,8 +2295,16 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) } #define RENDER_BACKGROUND_MODE7ADDSUB(DEPTH, FUNC) \ + int aa, cc; \ + int dir; \ + int startx, endx; \ + uint32 Left = 0; \ + uint32 Right = 256; \ uint32 clip, Line; \ uint8 *VRAM1 = Memory.VRAM + 1; \ + uint32 ClipCount; \ + uint8 *Depth; \ + SLineMatrixData *l; \ if (GFX.r2130 & 1) \ { \ if (IPPU.DirectColourMapsNeedRebuild) \ @@ -2269,22 +2314,18 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) else \ GFX.ScreenColors = IPPU.ScreenColors; \ \ - int aa, cc; \ - int dir; \ - int startx, endx; \ - uint32 Left = 0; \ - uint32 Right = 256; \ - uint32 ClipCount = GFX.pCurrentClip->Count [bg]; \ + ClipCount = GFX.pCurrentClip->Count [bg]; \ \ if (!ClipCount) \ ClipCount = 1; \ \ Screen += GFX.StartY * GFX_PITCH; \ - uint8 *Depth = GFX.DB + GFX.StartY * GFX_PPL; \ - SLineMatrixData *l = &LineMatrixData [GFX.StartY]; \ + Depth = GFX.DB + GFX.StartY * GFX_PPL; \ + l = &LineMatrixData [GFX.StartY]; \ \ for (Line = GFX.StartY; Line <= GFX.EndY; Line++, Screen += GFX_PITCH, Depth += GFX_PPL, l++) \ { \ + int BB, DD; \ int yy; \ \ int32 HOffset = ((int32) LineData [Line].BG[0].HOffset << M7) >> M7; \ @@ -2302,11 +2343,15 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) yy += (VOffset - CentreY) % 1023; \ else \ yy += VOffset - CentreY; \ - int BB = l->MatrixB * yy + (CentreX << 8); \ - int DD = l->MatrixD * yy + (CentreY << 8); \ + BB = l->MatrixB * yy + (CentreX << 8); \ + DD = l->MatrixD * yy + (CentreY << 8); \ \ for (clip = 0; clip < ClipCount; clip++) \ { \ + int AA, CC; \ + int xx; \ + uint16 *p; \ + uint8 *d; \ if (GFX.pCurrentClip->Count [bg]) \ { \ Left = GFX.pCurrentClip->Left [clip][bg]; \ @@ -2314,8 +2359,8 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) if (Right <= Left) \ continue; \ } \ - uint16 *p = (uint16 *) Screen + Left; \ - uint8 *d = Depth + Left; \ + p = (uint16 *) Screen + Left; \ + d = Depth + Left; \ \ if (PPU.Mode7HFlip) \ { \ @@ -2333,13 +2378,12 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) aa = l->MatrixA; \ cc = l->MatrixC; \ } \ - int xx; \ if (PPU.Mode7Repeat == 0) \ xx = startx + (HOffset - CentreX) % 1023; \ else \ xx = startx + HOffset - CentreX; \ - int AA = l->MatrixA * xx; \ - int CC = l->MatrixC * xx; \ + AA = l->MatrixA * xx; \ + CC = l->MatrixC * xx; \ \ if (!PPU.Mode7Repeat) \ { \ @@ -2385,9 +2429,10 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { \ if (PPU.Mode7Repeat == 3) \ { \ + uint32 b; \ X = (x + HOffset) & 7; \ Y = (yy + CentreY) & 7; \ - uint32 b = *(VRAM1 + ((Y & 7) << 4) + ((X & 7) << 1)); \ + b = *(VRAM1 + ((Y & 7) << 4) + ((X & 7) << 1)); \ if (DEPTH > *d && (b) ) \ { \ *p = (FUNC); \ @@ -2401,7 +2446,15 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) } #define RENDER_BACKGROUND_MODE7PRIO(FUNC) \ + SLineMatrixData *l; \ + int aa, cc; \ + int dir; \ + int startx, endx; \ + uint32 Left = 0; \ + uint32 Right = 256; \ uint32 clip, Line; \ + uint32 ClipCount; \ + uint8 *Depth; \ uint8 *VRAM1 = Memory.VRAM + 1; \ if (GFX.r2130 & 1) \ { \ @@ -2412,23 +2465,19 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) else \ GFX.ScreenColors = IPPU.ScreenColors; \ \ - int aa, cc; \ - int dir; \ - int startx, endx; \ - uint32 Left = 0; \ - uint32 Right = 256; \ - uint32 ClipCount = GFX.pCurrentClip->Count [bg]; \ + ClipCount = GFX.pCurrentClip->Count [bg]; \ \ if (!ClipCount) \ ClipCount = 1; \ \ Screen += GFX.StartY * GFX_PITCH; \ - uint8 *Depth = GFX.DB + GFX.StartY * GFX_PPL; \ - SLineMatrixData *l = &LineMatrixData [GFX.StartY]; \ + Depth = GFX.DB + GFX.StartY * GFX_PPL; \ + l = &LineMatrixData [GFX.StartY]; \ \ for (Line = GFX.StartY; Line <= GFX.EndY; Line++, Screen += GFX_PITCH, Depth += GFX_PPL, l++) \ { \ - int yy; \ + int BB, DD; \ + int yy; \ \ int32 HOffset = ((int32) LineData [Line].BG[0].HOffset << M7) >> M7; \ int32 VOffset = ((int32) LineData [Line].BG[0].VOffset << M7) >> M7; \ @@ -2445,11 +2494,15 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) yy += (VOffset - CentreY) % 1023; \ else \ yy += VOffset - CentreY; \ - int BB = l->MatrixB * yy + (CentreX << 8); \ - int DD = l->MatrixD * yy + (CentreY << 8); \ + BB = l->MatrixB * yy + (CentreX << 8); \ + DD = l->MatrixD * yy + (CentreY << 8); \ \ for (clip = 0; clip < ClipCount; clip++) \ { \ + int AA, CC; \ + int xx; \ + uint16 *p; \ + uint8 *d; \ if (GFX.pCurrentClip->Count [bg]) \ { \ Left = GFX.pCurrentClip->Left [clip][bg]; \ @@ -2457,8 +2510,8 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) if (Right <= Left) \ continue; \ } \ - uint16 *p = (uint16 *) Screen + Left; \ - uint8 *d = Depth + Left; \ + p = (uint16 *) Screen + Left; \ + d = Depth + Left; \ \ if (PPU.Mode7HFlip) \ { \ @@ -2476,13 +2529,12 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) aa = l->MatrixA; \ cc = l->MatrixC; \ } \ - int xx; \ if (PPU.Mode7Repeat == 0) \ xx = startx + (HOffset - CentreX) % 1023; \ else \ xx = startx + HOffset - CentreX; \ - int AA = l->MatrixA * xx; \ - int CC = l->MatrixC * xx; \ + AA = l->MatrixA * xx; \ + CC = l->MatrixC * xx; \ \ if (!PPU.Mode7Repeat) \ { \ @@ -2530,9 +2582,10 @@ static INLINE void DrawBackground(uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { \ if (PPU.Mode7Repeat == 3) \ { \ - X = (x + HOffset) & 7; \ - Y = (yy + CentreY) & 7; \ - uint32 b = *(VRAM1 + ((Y & 7) << 4) + ((X & 7) << 1)); \ + uint32 b; \ + X = (x + HOffset) & 7; \ + Y = (yy + CentreY) & 7; \ + b = *(VRAM1 + ((Y & 7) << 4) + ((X & 7) << 1)); \ GFX.Z1 = Mode7Depths [(b & 0x80) >> 7]; \ if (GFX.Z1 > *d && (b & 0x7f) ) \ { \ @@ -2859,13 +2912,15 @@ void DisplayChar(uint8* Screen, uint8 c) } } -void S9xUpdateScreen() // ~30-50ms! (called from FLUSH_REDRAW()) +void S9xUpdateScreen(void) // ~30-50ms! (called from FLUSH_REDRAW()) { + uint32 black; + uint32 starty, endy; + uint8_t *memoryfillram; int32 x2 = 1; GFX.S = GFX.Screen; - - unsigned char* memoryfillram = Memory.FillRAM; + memoryfillram = Memory.FillRAM; // get local copies of vid registers to be used later GFX.r2131 = memoryfillram [0x2131]; // ADDITION/SUBTRACTION & SUBTRACTION DESIGNATION FOR EACH SCREEN @@ -2897,8 +2952,8 @@ void S9xUpdateScreen() // ~30-50ms! (called from FLUSH_REDRAW()) if ((GFX.EndY = IPPU.CurrentLine - 1) >= PPU.ScreenHeight) GFX.EndY = PPU.ScreenHeight - 1; - uint32 starty = GFX.StartY; - uint32 endy = GFX.EndY; + starty = GFX.StartY; + endy = GFX.EndY; if (Settings.SupportHiRes && (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.LatchedInterlace)) @@ -2930,7 +2985,7 @@ void S9xUpdateScreen() // ~30-50ms! (called from FLUSH_REDRAW()) } } - uint32 black = BLACK | (BLACK << 16); + black = BLACK | (BLACK << 16); // Are we worrying about transparencies? if (Settings.Transparency) @@ -3548,6 +3603,8 @@ void S9xUpdateScreen() // ~30-50ms! (called from FLUSH_REDRAW()) if (!PPU.ForcedBlanking) { uint32 y; + uint8 subadd; + bool8_32 BG0, BG1, BG2, BG3, OB; // Loop through all lines being updated and clear the // zbuffer for each of the lines @@ -3570,14 +3627,14 @@ else \ // Define an inline function to handle which BGs are being displayed #define DISPLAY(n) ((GFX.r212c & n) || ((GFX.r212d & n) && subadd)) - uint8 subadd = GFX.r2131 & 0x3f; + subadd = GFX.r2131 & 0x3f; // go through all BGS are check if they need to be displayed - bool8_32 BG0 = DISPLAY(1) && !(Settings.os9x_hack & GFX_IGNORE_BG0); - bool8_32 BG1 = DISPLAY(2) && !(Settings.os9x_hack & GFX_IGNORE_BG1); - bool8_32 BG2 = DISPLAY(4) && !(Settings.os9x_hack & GFX_IGNORE_BG2); - bool8_32 BG3 = DISPLAY(8) && !(Settings.os9x_hack & GFX_IGNORE_BG3); - bool8_32 OB = DISPLAY(16) && !(Settings.os9x_hack & GFX_IGNORE_OBJ); + BG0 = DISPLAY(1) && !(Settings.os9x_hack & GFX_IGNORE_BG0); + BG1 = DISPLAY(2) && !(Settings.os9x_hack & GFX_IGNORE_BG1); + BG2 = DISPLAY(4) && !(Settings.os9x_hack & GFX_IGNORE_BG2); + BG3 = DISPLAY(8) && !(Settings.os9x_hack & GFX_IGNORE_BG3); + OB = DISPLAY(16) && !(Settings.os9x_hack & GFX_IGNORE_OBJ); if (PPU.BGMode <= 1) { @@ -3630,10 +3687,12 @@ else \ } else { + int bg = 0; + // screen mode 7 GFX.Mode7Mask = 0xff; GFX.Mode7PriorityMask = 0; - int bg = 0; + bg = 0; DrawBGMode7Background16New(GFX.Screen, bg); if (OB) { diff --git a/src/ppu_.c b/src/ppu_.c index b24bbb1..27891d5 100644 --- a/src/ppu_.c +++ b/src/ppu_.c @@ -60,7 +60,7 @@ extern FxInit_s SuperFX; extern FxRegs_s GSU; -void S9xUpdateHTimer() +void S9xUpdateHTimer(void) { if (PPU.HTimerEnabled) { @@ -117,7 +117,7 @@ void S9xUpdateHTimer() } } -void S9xFixColourBrightness() +void S9xFixColourBrightness(void) { IPPU.XB = mul_brightness [PPU.Brightness]; if (Settings.SixteenBit) @@ -375,14 +375,16 @@ void S9xSetPPU(uint8 Byte, uint16 Address) { static uint16 IncCount [4] = { 0, 32, 64, 128 }; static uint16 Shift [4] = { 0, 5, 6, 7 }; + uint8 i; + #ifdef DEBUGGER missing.vram_full_graphic_inc = (Byte & 0x0c) >> 2; #endif - PPU.VMA.Increment = 1; - uint8 i = (Byte & 0x0c) >> 2; + PPU.VMA.Increment = 1; + i = (Byte & 0x0c) >> 2; PPU.VMA.FullGraphicCount = IncCount [i]; - PPU.VMA.Mask1 = IncCount [i] * 8 - 1; - PPU.VMA.Shift = Shift [i]; + PPU.VMA.Mask1 = IncCount [i] * 8 - 1; + PPU.VMA.Shift = Shift [i]; } else PPU.VMA.FullGraphicCount = 0; @@ -2131,10 +2133,11 @@ uint8 S9xGetCPU(uint16 Address) return (Memory.FillRAM[Address]); } -void S9xResetPPU() +void S9xResetPPU(void) { uint8 B; int Sprite; + int c; PPU.BGMode = 0; PPU.BG3Priority = 0; @@ -2171,7 +2174,6 @@ void S9xResetPPU() PPU.ClipWindow2Inside[4] = PPU.ClipWindow2Inside[5] = TRUE; PPU.CGFLIP = 0; - int c; for (c = 0; c < 256; c++) { IPPU.Red [c] = (c & 7) << 2; @@ -2368,7 +2370,7 @@ void S9xProcessMouse(int which1) } } -void ProcessSuperScope() +void ProcessSuperScope(void) { int x, y; uint32 buttons; @@ -2507,11 +2509,13 @@ void S9xSuperFXExec(void) if ((Memory.FillRAM [0x3000 + GSU_SFR] & FLG_G) && (Memory.FillRAM [0x3000 + GSU_SCMR] & 0x18) == 0x18) { + int GSUStatus; + if (!Settings.WinterGold) FxEmulate(~0); else FxEmulate((Memory.FillRAM [0x3000 + GSU_CLSR] & 1) ? 700 : 350); - int GSUStatus = Memory.FillRAM [0x3000 + GSU_SFR] | + GSUStatus = Memory.FillRAM [0x3000 + GSU_SFR] | (Memory.FillRAM [0x3000 + GSU_SFR + 1] << 8); if ((GSUStatus & (FLG_G | FLG_IRQ)) == FLG_IRQ) { diff --git a/src/tile.c b/src/tile.c index edb9333..72b34c7 100644 --- a/src/tile.c +++ b/src/tile.c @@ -357,9 +357,8 @@ static INLINE void WRITE_4PIXELS_FLIPPEDx2x2(int32 Offset, uint8* Pixels) void DrawTile(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE - uint8* bp; + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELS, WRITE_4PIXELS_FLIPPED, 4) } @@ -368,9 +367,9 @@ void DrawClippedTile(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE + uint32 dd, d1, d2; uint8* bp; - + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELS, WRITE_4PIXELS_FLIPPED, 4) } @@ -378,10 +377,8 @@ void DrawClippedTile(uint32 Tile, int32 Offset, void DrawTilex2(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE - uint8* bp; - + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELSx2, WRITE_4PIXELS_FLIPPEDx2, 8) } @@ -389,9 +386,9 @@ void DrawClippedTilex2(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE + uint32 dd, d1, d2; uint8* bp; - + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELSx2, WRITE_4PIXELS_FLIPPEDx2, 8) } @@ -399,10 +396,8 @@ void DrawClippedTilex2(uint32 Tile, int32 Offset, void DrawTilex2x2(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE - uint8* bp; - + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELSx2x2, WRITE_4PIXELS_FLIPPEDx2x2, 8) } @@ -410,9 +405,9 @@ void DrawClippedTilex2x2(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELSx2x2, WRITE_4PIXELS_FLIPPEDx2x2, 8) } @@ -421,11 +416,11 @@ void DrawLargePixel(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Pixels, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE - - uint8* sp = GFX.S + Offset; - uint8* Depth = GFX.DB + Offset; + uint8 *sp, *Depth; uint8 pixel; + TILE_PREAMBLE + sp = GFX.S + Offset; + Depth = GFX.DB + Offset; #define PLOT_PIXEL(screen, pixel) (pixel) RENDER_TILE_LARGE(((uint8) GFX.ScreenColors [pixel]), PLOT_PIXEL) @@ -557,6 +552,7 @@ static INLINE void WRITE_4PIXELS16_FLIPPEDx2x2(int32 Offset, uint8* Pixels) void DrawTile16(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { + uint8* bp; #if 1 TILE_PREAMBLE #else @@ -591,7 +587,6 @@ void DrawTile16(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) uint32 l; #endif - uint8* bp; RENDER_TILE(WRITE_4PIXELS16, WRITE_4PIXELS16_FLIPPED, 4) } @@ -599,9 +594,9 @@ void DrawClippedTile16(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELS16, WRITE_4PIXELS16_FLIPPED, 4) } @@ -609,9 +604,8 @@ void DrawClippedTile16(uint32 Tile, int32 Offset, void DrawTile16x2(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELS16x2, WRITE_4PIXELS16_FLIPPEDx2, 8) } @@ -619,9 +613,9 @@ void DrawClippedTile16x2(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELS16x2, WRITE_4PIXELS16_FLIPPEDx2, 8) } @@ -629,9 +623,8 @@ void DrawClippedTile16x2(uint32 Tile, int32 Offset, void DrawTile16x2x2(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELS16x2x2, WRITE_4PIXELS16_FLIPPEDx2x2, 8) } @@ -639,9 +632,9 @@ void DrawClippedTile16x2x2(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELS16x2x2, WRITE_4PIXELS16_FLIPPEDx2x2, 8) } @@ -650,12 +643,12 @@ void DrawLargePixel16(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Pixels, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE - - uint16* sp = (uint16*) GFX.S + Offset; - uint8* Depth = GFX.DB + Offset; uint16 pixel; - + uint16 *sp; + uint8 *Depth; + TILE_PREAMBLE + sp = (uint16*) GFX.S + Offset; + Depth = GFX.DB + Offset; RENDER_TILE_LARGE(GFX.ScreenColors [pixel], PLOT_PIXEL) } @@ -919,9 +912,8 @@ static INLINE void WRITE_4PIXELS16_FLIPPED_SUB1_2(int32 Offset, uint8* Pixels) void DrawTile16Add(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELS16_ADD, WRITE_4PIXELS16_FLIPPED_ADD, 4) } @@ -929,9 +921,9 @@ void DrawClippedTile16Add(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELS16_ADD, WRITE_4PIXELS16_FLIPPED_ADD, 4) } @@ -939,9 +931,8 @@ void DrawClippedTile16Add(uint32 Tile, int32 Offset, void DrawTile16Add1_2(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELS16_ADD1_2, WRITE_4PIXELS16_FLIPPED_ADD1_2, 4) } @@ -949,9 +940,9 @@ void DrawClippedTile16Add1_2(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELS16_ADD1_2, WRITE_4PIXELS16_FLIPPED_ADD1_2, 4) } @@ -959,9 +950,8 @@ void DrawClippedTile16Add1_2(uint32 Tile, int32 Offset, void DrawTile16Sub(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELS16_SUB, WRITE_4PIXELS16_FLIPPED_SUB, 4) } @@ -969,9 +959,9 @@ void DrawClippedTile16Sub(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELS16_SUB, WRITE_4PIXELS16_FLIPPED_SUB, 4) } @@ -979,9 +969,8 @@ void DrawClippedTile16Sub(uint32 Tile, int32 Offset, void DrawTile16Sub1_2(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELS16_SUB1_2, WRITE_4PIXELS16_FLIPPED_SUB1_2, 4) } @@ -989,9 +978,9 @@ void DrawClippedTile16Sub1_2(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELS16_SUB1_2, WRITE_4PIXELS16_FLIPPED_SUB1_2, 4) } @@ -1103,9 +1092,8 @@ static INLINE void WRITE_4PIXELS16_FLIPPED_SUBF1_2(int32 Offset, uint8* Pixels) void DrawTile16FixedAdd1_2(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELS16_ADDF1_2, WRITE_4PIXELS16_FLIPPED_ADDF1_2, 4) } @@ -1113,9 +1101,9 @@ void DrawClippedTile16FixedAdd1_2(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELS16_ADDF1_2, WRITE_4PIXELS16_FLIPPED_ADDF1_2, 4) @@ -1124,9 +1112,8 @@ void DrawClippedTile16FixedAdd1_2(uint32 Tile, int32 Offset, void DrawTile16FixedSub1_2(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + TILE_PREAMBLE RENDER_TILE(WRITE_4PIXELS16_SUBF1_2, WRITE_4PIXELS16_FLIPPED_SUBF1_2, 4) } @@ -1134,9 +1121,9 @@ void DrawClippedTile16FixedSub1_2(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILE(WRITE_4PIXELS16_SUBF1_2, WRITE_4PIXELS16_FLIPPED_SUBF1_2, 4) @@ -1146,12 +1133,13 @@ void DrawLargePixel16Add(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Pixels, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE - - uint16* sp = (uint16*) GFX.S + Offset; - uint8* Depth = GFX.ZBuffer + Offset; + uint16 *sp; + uint8 *Depth; uint16 pixel; + TILE_PREAMBLE + sp = (uint16*) GFX.S + Offset; + Depth = GFX.ZBuffer + Offset; #define LARGE_ADD_PIXEL(s, p) \ (Depth [z + GFX.DepthDelta] ? (Depth [z + GFX.DepthDelta] != 1 ? \ COLOR_ADD (p, *(s + GFX.Delta)) : \ @@ -1165,11 +1153,13 @@ void DrawLargePixel16Add1_2(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Pixels, uint32 StartLine, uint32 LineCount) { + uint16 *sp; + uint8 *Depth; + uint16 pixel; TILE_PREAMBLE - uint16* sp = (uint16*) GFX.S + Offset; - uint8* Depth = GFX.ZBuffer + Offset; - uint16 pixel; + sp = (uint16*) GFX.S + Offset; + Depth = GFX.ZBuffer + Offset; #define LARGE_ADD_PIXEL1_2(s, p) \ ((uint16) (Depth [z + GFX.DepthDelta] ? (Depth [z + GFX.DepthDelta] != 1 ? \ @@ -1184,11 +1174,13 @@ void DrawLargePixel16Sub(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Pixels, uint32 StartLine, uint32 LineCount) { + uint16 *sp; + uint8 *Depth; + uint16 pixel; TILE_PREAMBLE - uint16* sp = (uint16*) GFX.S + Offset; - uint8* Depth = GFX.ZBuffer + Offset; - uint16 pixel; + sp = (uint16*) GFX.S + Offset; + Depth = GFX.ZBuffer + Offset; #define LARGE_SUB_PIXEL(s, p) \ (Depth [z + GFX.DepthDelta] ? (Depth [z + GFX.DepthDelta] != 1 ? \ @@ -1203,11 +1195,13 @@ void DrawLargePixel16Sub1_2(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Pixels, uint32 StartLine, uint32 LineCount) { + uint16 *sp; + uint8 *Depth; + uint16 pixel; TILE_PREAMBLE - uint16* sp = (uint16*) GFX.S + Offset; - uint8* Depth = GFX.ZBuffer + Offset; - uint16 pixel; + sp = (uint16*) GFX.S + Offset; + Depth = GFX.ZBuffer + Offset; #define LARGE_SUB_PIXEL1_2(s, p) \ (Depth [z + GFX.DepthDelta] ? (Depth [z + GFX.DepthDelta] != 1 ? \ @@ -1221,9 +1215,8 @@ void DrawLargePixel16Sub1_2(uint32 Tile, int32 Offset, void DrawHiResTile16(uint32 Tile, int32 Offset, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + TILE_PREAMBLE RENDER_TILEHI(WRITE_4PIXELSHI16, WRITE_4PIXELSHI16_FLIPPED, 4) } @@ -1231,9 +1224,9 @@ void DrawHiResClippedTile16(uint32 Tile, int32 Offset, uint32 StartPixel, uint32 Width, uint32 StartLine, uint32 LineCount) { - TILE_PREAMBLE uint8* bp; - + uint32 dd, d1, d2; + TILE_PREAMBLE TILE_CLIP_PREAMBLE RENDER_CLIPPED_TILEHI(WRITE_4PIXELSHI16, WRITE_4PIXELSHI16_FLIPPED, 4) } diff --git a/src/tile.h b/src/tile.h index f0d09fc..5e3e0fd 100644 --- a/src/tile.h +++ b/src/tile.h @@ -46,6 +46,7 @@ void SelectPalette(); extern uint32 TileBlank; #define TILE_PREAMBLE \ + uint32 l; \ uint8 *pCache; \ \ uint32 TileAddr = (BG.TileAddress + ((Tile & 0x3ff) << BG.TileShift)) & 0xffff; \ @@ -61,7 +62,6 @@ extern uint32 TileBlank; return; \ } \ \ - uint32 l; \ GFX.ScreenColors = &GFX.ScreenColorsPre[(Tile & GFX.PaletteMask) >> GFX.PaletteShift]; @@ -70,6 +70,7 @@ extern uint32 TileBlank; else GFX.ScreenColors = &IPPU.ScreenColors [(((Tile >> 10) & BG.PaletteMask) << BG.PaletteShift) + BG.StartPalette]; */ #define RENDER_TILE(NORMAL, FLIPPED, N) \ +{ \ int inc; \ if (!(Tile & V_FLIP)){ \ bp = pCache + StartLine; \ @@ -96,13 +97,10 @@ extern uint32 TileBlank; FLIPPED (Offset + N, bp); \ bp += inc, Offset += GFX_PPL; \ } \ - } + } \ +} #define TILE_CLIP_PREAMBLE \ - uint32 dd; \ - uint32 d1; \ - uint32 d2; \ -\ if (StartPixel < 4) \ { \ d1 = HeadMask [StartPixel]; \ @@ -126,6 +124,7 @@ extern uint32 TileBlank; #define RENDER_CLIPPED_TILE(NORMAL, FLIPPED, N) \ +{ \ int inc; \ if (Tile & V_FLIP){ \ bp = pCache + 56 - StartLine; \ @@ -154,7 +153,8 @@ extern uint32 TileBlank; FLIPPED (Offset + N, (uint8 *) &dd); \ bp += inc, Offset += GFX_PPL; \ } \ - } + } \ +} #define RENDER_TILE_LARGE(PIXEL, FUNCTION) \ if (!(Tile & (V_FLIP | H_FLIP))) \ -- cgit v1.2.3