Skip to content

Commit

Permalink
0.3a-112e7bb
Browse files Browse the repository at this point in the history
  • Loading branch information
DirtBagXon committed Feb 27, 2025
1 parent e578ea8 commit fc806c9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 89 deletions.
18 changes: 0 additions & 18 deletions Config/Games.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1438,10 +1438,6 @@
</inputs>
</hardware>
<roms>
<patches>
<!-- Prevent "rolling start" scrolling glitch -->
<patch region="crom" bits="32" offset="0x14BDB8" value="0x20B201E0" />
</patches>
<region name="crom" stride="8" chunk_size="2" byte_swap="true">
<file offset="0" name="epr-19691.20" crc32="0x83523B89" />
<file offset="2" name="epr-19690.19" crc32="0x25F007FE" />
Expand Down Expand Up @@ -1530,8 +1526,6 @@
<patches>
<!-- Secret debug menu -->
<patch region="crom" bits="32" offset="0x199DE8" value="0x00050208" />
<!-- Prevent "rolling start" scrolling glitch -->
<patch region="crom" bits="32" offset="0x14BDF4" value="0x20B201E0" />
</patches>
<region name="crom" stride="8" chunk_size="2" byte_swap="true">
<file offset="0" name="epr-19734.20" crc32="0xBE897336" />
Expand Down Expand Up @@ -1564,10 +1558,6 @@
</inputs>
</hardware>
<roms>
<patches>
<!-- Prevent "rolling start" scrolling glitch -->
<patch region="crom" bits="32" offset="0x146350" value="0x20B201E0" />
</patches>
<region name="crom" stride="8" chunk_size="2" byte_swap="true">
<file offset="0" name="epr-19607a.20" crc32="0x24301A12" />
<file offset="2" name="epr-19608a.19" crc32="0x1426160E" />
Expand Down Expand Up @@ -1714,10 +1704,6 @@
</inputs>
</hardware>
<roms>
<patches>
<!-- Prevent "rolling start" scrolling glitch -->
<patch region="crom" bits="32" offset="0x14E424" value="0x20B201E0" />
</patches>
<region name="crom" stride="8" chunk_size="2" byte_swap="true">
<file offset="0" name="epr-20095a.20" crc32="0x58C7E393" />
<file offset="2" name="epr-20094a.19" crc32="0xDBF17A43" />
Expand Down Expand Up @@ -1766,10 +1752,6 @@
</inputs>
</hardware>
<roms>
<patches>
<!-- Prevent "rolling start" scrolling glitch -->
<patch region="crom" bits="32" offset="0x14E014" value="0x20B201E0" />
</patches>
<region name="crom" stride="8" chunk_size="2" byte_swap="true">
<file offset="0" name="epr-20095.20" crc32="0x44467BC1" />
<file offset="2" name="epr-20094.19" crc32="0x299B6257" />
Expand Down
109 changes: 58 additions & 51 deletions Src/Model3/TileGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,21 +422,18 @@ int CTileGen::GetLineScroll(int layerNumber, int yCoord) const
return (m_vramP[index] >> shift) & 0xFFFFu;
}

int CTileGen::GetTileNumber(int xCoord, int yCoord, int xScroll, int yScroll) const
int CTileGen::GetTilePairNumber(int xCoord, int yCoord, int xScroll, int yScroll) const
{
int xIndex = ((xCoord + xScroll) / 8) & 0x3F;
int xIndex = ((xCoord + xScroll) / 16) & 0x1F;
int yIndex = ((yCoord + yScroll) / 8) & 0x3F;

return (yIndex * 64) + xIndex;
return (yIndex * 32) + xIndex;
}

int CTileGen::GetTileData(int layerNum, int tileNumber) const
int CTileGen::GetTileData(int layerNum, int tilePairNumber) const
{
int addressBase = (0xF8000 + (layerNum * 0x2000)) / 4;
int offset = tileNumber / 2; // two tiles per 32bit word
int shift = (1 - (tileNumber % 2)) * 16; // triple check this

return (m_vramP[addressBase + offset] >> shift) & 0xFFFFu;
return m_vramP[addressBase + tilePairNumber];
}

int CTileGen::GetVFine(int yCoord, int yScroll) const
Expand All @@ -446,7 +443,7 @@ int CTileGen::GetVFine(int yCoord, int yScroll) const

int CTileGen::GetHFine(int xCoord, int xScroll) const
{
return (xCoord + xScroll) & 7;
return (xCoord + xScroll) & 15;
}

int CTileGen::GetLineMask(int layerNumber, int yCoord) const
Expand Down Expand Up @@ -489,25 +486,32 @@ UINT32 CTileGen::GetColour32(int layer, UINT32 data) const
return (a << 24) | (bb << 16) | (gg << 8) | rr;
}

void CTileGen::Draw4Bit(int tileData, int hFine, int vFine, UINT32* const lineBuffer, const UINT32* const pal, int& x) const
void CTileGen::Draw4BitTilePair(int tileData, int hStart, int hEnd, int vFine, UINT32* const lineBuffer, const UINT32* const pal, int& x) const
{
// Tile pattern offset: each tile occupies 32 bytes when using 4-bit pixels (offset of tile pattern within VRAM)
int patternOffset = ((tileData & 0x3FFF) << 1) | ((tileData >> 15) & 1);
patternOffset *= 32;
patternOffset /= 4;
int patternOffset[2];

patternOffset[0] = (((tileData >> 16) & 0x3FFF) << 1) | ((tileData >> 31) & 1);
patternOffset[0] *= 32;
patternOffset[0] /= 4;

patternOffset[1] = ((tileData & 0x3FFF) << 1) | ((tileData >> 15) & 1);
patternOffset[1] *= 32;
patternOffset[1] /= 4;

// Upper color bits; the lower 4 bits come from the tile pattern
int paletteIndex = tileData & 0x7FF0;
int paletteIndex[] = { (tileData >> 16) & 0x7FF0, tileData & 0x7FF0 };

uint32_t patterns[] = { m_vramP[patternOffset[0] + vFine], m_vramP[patternOffset[1] + vFine] };

auto pattern = m_vramP[patternOffset + vFine];
for (int i = hStart; i < hEnd; i++, x++) {
auto pattern = patterns[i / 8]; // first 8 pixels use pattern 1, next 8 pattern 2
auto p = (pattern >> ((7 - (i % 8)) * 4)) & 0xFu;
auto colour32 = pal[paletteIndex[i / 8] | p];

for (int i = 0; i < 8 - hFine; i++, x++) {
auto p = (pattern >> ((7 - (hFine + i)) * 4)) & 0xFu;
auto colour32 = pal[paletteIndex | p];
if (colour32 < 0x1000000) {
continue;
if (colour32 >= 0x1000000) { // if not transparent write pixel colour
lineBuffer[x] = colour32;
}
lineBuffer[x] = colour32;
}
}

Expand All @@ -526,36 +530,33 @@ void CTileGen::Draw4Bit(int tileData, int hFine, int vFine, UINT32* const lineBu
*colour16++ = pal[ paletteIndex | ((pattern >> 0) & 0xF) ];
*/

void CTileGen::Draw8Bit(int tileData, int hFine, int vFine, UINT32* const lineBuffer, const UINT32* const pal, int& x) const
void CTileGen::Draw8BitTilePair(int tileData, int hStart, int hEnd, int vFine, UINT32* const lineBuffer, const UINT32* const pal, int& x) const
{
// Tile pattern offset: each tile occupies 64 bytes when using 8-bit pixels
int patternOffset = tileData & 0x3FFF;
patternOffset *= 64;
patternOffset /= 4;
int patternOffset[2];

patternOffset[0] = (tileData >> 16) & 0x3FFF;
patternOffset[0] *= 64;
patternOffset[0] /= 4;

patternOffset[1] = tileData & 0x3FFF;
patternOffset[1] *= 64;
patternOffset[1] /= 4;

// Upper color bits
int paletteIndex = tileData & 0x7F00;
int paletteIndex[2] = { (tileData >> 16) & 0x7F00, tileData & 0x7F00 };

auto pattern1 = m_vramP[patternOffset + (vFine * 2)]; // first 4 pixels
auto pattern2 = m_vramP[patternOffset + (vFine * 2) + 1]; // next 4 pixels
uint32_t patterns[] = { m_vramP[patternOffset[0] + (vFine * 2)], m_vramP[patternOffset[0] + (vFine * 2) + 1],
m_vramP[patternOffset[1] + (vFine * 2)], m_vramP[patternOffset[1] + (vFine * 2) + 1]};

// might not hit this loop
for (int i = 0; i < 4 - hFine; i++, x++) {
auto p = (pattern1 >> ((3 - ((hFine + i) % 4)) * 8)) & 0xFFu;
auto colour32 = pal[paletteIndex | p];
if (colour32 < 0x1000000) {
continue;
}
lineBuffer[x] = colour32;
}
for (int i = hStart; i < hEnd; i++, x++) {
auto pattern = patterns[i / 4]; // each pattern contains 4 pixels
auto p = (pattern >> ((3 - (i % 4)) * 8)) & 0xFFu;
auto colour32 = pal[paletteIndex[i / 8] | p];

for (int i = 0; i < 4 - (hFine % 4); i++, x++) {
auto p = (pattern2 >> ((3 - ((hFine + i) % 4)) * 8)) & 0xFFu;
auto colour32 = pal[paletteIndex | p];
if (colour32 < 0x1000000) {
continue;
if (colour32 >= 0x1000000) { // if not transparent write pixel colour
lineBuffer[x] = colour32;
}
lineBuffer[x] = colour32;
}
}

Expand Down Expand Up @@ -583,30 +584,36 @@ void CTileGen::DrawLine(int line)
continue; // both disabled let's try next pair
}

UINT32* drawLayers[2] = { m_drawSurface[Above3D(primaryIndex)]->GetLine(line), m_drawSurface[Above3D(altIndex)]->GetLine(line) };
UINT32* drawLayers[2] = { m_drawSurface[Above3D(primaryIndex)]->GetLine(line),
m_drawSurface[Above3D(altIndex)]->GetLine(line) };

int lineMask = GetLineMask(primaryIndex, line);
int scrollX[2] = { LineScrollMode(primaryIndex) ? GetLineScroll(primaryIndex,line) : GetXScroll(primaryIndex), LineScrollMode(altIndex) ? GetLineScroll(altIndex,line) : GetXScroll(altIndex) };
int scrollX[2] = { LineScrollMode(primaryIndex) ? GetLineScroll(primaryIndex,line) : GetXScroll(primaryIndex),
LineScrollMode(altIndex) ? GetLineScroll(altIndex,line) : GetXScroll(altIndex) };
int scrollY[2] = { GetYScroll(primaryIndex),GetYScroll(altIndex) };

for (int x = 0; x < 496; ) {

int layer = (GetPixelMask(lineMask, x) + 1) & 1; // 1 means primary layer, so we flip so it's zero
bool maskSwitch = GetPixelMask(lineMask, x) != GetPixelMask(lineMask, x + 15);

if (hasLayer[layer]) {

const auto index = primaryIndex + layer;

int tileNumber = GetTileNumber(x, line, scrollX[layer], scrollY[layer]);
int hFine = GetHFine(x, scrollX[layer]);
int vFine = GetVFine(line, scrollY[layer]);
int tileData = GetTileData(index, tileNumber);
// tiles are loaded in pairs, since the RAM is 32-bit and each name table entry is 16-bit
// if the mask will change before we can draw all 16 pixels of the next tile pair, we reuse the previous tile pair
int tilePairNumber = GetTilePairNumber(maskSwitch ? (x - 16) : x, line, scrollX[layer], scrollY[layer]);
int hStart = GetHFine(x, scrollX[layer]);
int hEnd = maskSwitch ? 16 - (x & 15) : 16;
int vFine = GetVFine(line, scrollY[layer]);
int tileData = GetTileData(index, tilePairNumber);

if (Is4Bit(index)) {
Draw4Bit(tileData, hFine, vFine, drawLayers[layer], m_pal[index / 2], x);
Draw4BitTilePair(tileData, hStart, hEnd, vFine, drawLayers[layer], m_pal[index / 2], x);
}
else {
Draw8Bit(tileData, hFine, vFine, drawLayers[layer], m_pal[index / 2], x);
Draw8BitTilePair(tileData, hStart, hEnd, vFine, drawLayers[layer], m_pal[index / 2], x);
}
}
else {
Expand Down
38 changes: 19 additions & 19 deletions Src/Model3/TileGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,25 +290,25 @@ class CTileGen

ColourOffsetRegister m_colourOffsetRegs[2];

bool IsEnabled (int layerNumber) const;
bool Above3D (int layerNumber) const;
bool Is4Bit (int layerNumber) const;
int GetYScroll (int layerNumber) const;
int GetXScroll (int layerNumber) const;
bool LineScrollMode (int layerNumber) const;
int GetLineScroll (int layerNumber, int yCoord) const;
int GetTileNumber (int xCoord, int yCoord, int xScroll, int yScroll) const;
int GetTileData (int layerNum, int tileNumber) const;
int GetVFine (int yCoord, int yScroll) const;
int GetHFine (int xCoord, int xScroll) const;
int GetLineMask (int layerNumber, int yCoord) const;
int GetPixelMask (int lineMask, int xCoord) const;
UINT32 GetColour32 (int layer, UINT32 data) const;
void Draw4Bit (int tileData, int hFine, int vFine, UINT32* const lineBuffer, const UINT32* const pal, int& x) const;
void Draw8Bit (int tileData, int hFine, int vFine, UINT32* const lineBuffer, const UINT32* const pal, int& x) const;

void WritePalette (int layer, int address, UINT32 data);
void RecomputePalettes(int layer); // 0 = bottom, 1 = top
bool IsEnabled (int layerNumber) const;
bool Above3D (int layerNumber) const;
bool Is4Bit (int layerNumber) const;
int GetYScroll (int layerNumber) const;
int GetXScroll (int layerNumber) const;
bool LineScrollMode (int layerNumber) const;
int GetLineScroll (int layerNumber, int yCoord) const;
int GetTilePairNumber (int xCoord, int yCoord, int xScroll, int yScroll) const;
int GetTileData (int layerNum, int tilePairNumber) const;
int GetVFine (int yCoord, int yScroll) const;
int GetHFine (int xCoord, int xScroll) const;
int GetLineMask (int layerNumber, int yCoord) const;
int GetPixelMask (int lineMask, int xCoord) const;
UINT32 GetColour32 (int layer, UINT32 data) const;
void Draw4BitTilePair (int tileData, int hStart, int hEnd, int vFine, UINT32* const lineBuffer, const UINT32* const pal, int& x) const;
void Draw8BitTilePair (int tileData, int hStart, int hEnd, int vFine, UINT32* const lineBuffer, const UINT32* const pal, int& x) const;

void WritePalette (int layer, int address, UINT32 data);
void RecomputePalettes (int layer); // 0 = bottom, 1 = top

//const Util::Config::Node& m_config;
const bool m_gpuMultiThreaded;
Expand Down
2 changes: 1 addition & 1 deletion Src/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define INCLUDED_VERSION_H

#ifndef SUPERMODEL_VERSION
#define SUPERMODEL_VERSION "0.3a-e9f50fe-mm DirtBagXon (Sinden)"
#define SUPERMODEL_VERSION "0.3a-112e7bb-mm DirtBagXon (Sinden)"
#endif

#endif // INCLUDED_VERSION_H

0 comments on commit fc806c9

Please sign in to comment.