all repos — mgba @ 8257c85c95e79b3a1a5a32ebb8e5ce1ede1f66b8

mGBA Game Boy Advance Emulator

GB Software: Special case a fast draw path for backgrounds
Jeffrey Pfau jeffrey@endrift.com
Sun, 14 Feb 2016 20:08:41 -0800
commit

8257c85c95e79b3a1a5a32ebb8e5ce1ede1f66b8

parent

cd0a352a33d1613196ad5c3fa7e2af055e0fbecc

1 files changed, 28 insertions(+), 5 deletions(-)

jump to
M src/gb/renderers/software.csrc/gb/renderers/software.c

@@ -179,9 +179,27 @@ if (startX < 0) {

startX = 0; } int x; - for (x = startX; x < endX; ++x) { + if ((startX + sx) & 7) { + int startX2 = startX + 8 - ((startX + sx) & 7); + for (x = startX; x < startX2; ++x) { + int topX = ((x + sx) >> 3) & 0x1F; + int bottomX = 7 - ((x + sx) & 7); + int bgTile; + if (GBRegisterLCDCIsTileData(renderer->lcdc)) { + bgTile = maps[topX + topY]; + } else { + bgTile = ((int8_t*) maps)[topX + topY]; + } + uint8_t tileDataLower = data[(bgTile * 8 + bottomY) * 2]; + uint8_t tileDataUpper = data[(bgTile * 8 + bottomY) * 2 + 1]; + tileDataUpper >>= bottomX; + tileDataLower >>= bottomX; + renderer->row[x] = ((tileDataUpper & 1) << 1) | (tileDataLower & 1); + } + startX = startX2; + } + for (x = startX; x < endX; x += 8) { int topX = ((x + sx) >> 3) & 0x1F; - int bottomX = 7 - ((x + sx) & 7); int bgTile; if (GBRegisterLCDCIsTileData(renderer->lcdc)) { bgTile = maps[topX + topY];

@@ -190,9 +208,14 @@ bgTile = ((int8_t*) maps)[topX + topY];

} uint8_t tileDataLower = data[(bgTile * 8 + bottomY) * 2]; uint8_t tileDataUpper = data[(bgTile * 8 + bottomY) * 2 + 1]; - tileDataUpper >>= bottomX; - tileDataLower >>= bottomX; - renderer->row[x] = ((tileDataUpper & 1) << 1) | (tileDataLower & 1); + renderer->row[x + 7] = ((tileDataUpper & 1) << 1) | (tileDataLower & 1); + renderer->row[x + 6] = (tileDataUpper & 2) | ((tileDataLower & 2) >> 1); + renderer->row[x + 5] = ((tileDataUpper & 4) >> 1) | ((tileDataLower & 4) >> 2); + renderer->row[x + 4] = ((tileDataUpper & 8) >> 2) | ((tileDataLower & 8) >> 3); + renderer->row[x + 3] = ((tileDataUpper & 16) >> 3) | ((tileDataLower & 16) >> 4); + renderer->row[x + 2] = ((tileDataUpper & 32) >> 4) | ((tileDataLower & 32) >> 5); + renderer->row[x + 1] = ((tileDataUpper & 64) >> 5) | ((tileDataLower & 64) >> 6); + renderer->row[x + 0] = ((tileDataUpper & 128) >> 6) | ((tileDataLower & 128) >> 7); } }