all repos — mgba @ d9ecac8cca1339c5eea202c0c4612bc9057b0b49

mGBA Game Boy Advance Emulator

GBA Video: I can't believe I broke so this so much
Vicki Pfau vi@endrift.com
Fri, 17 Jul 2020 13:21:31 -0700
commit

d9ecac8cca1339c5eea202c0c4612bc9057b0b49

parent

dd67bf979767f11557852fb4e3522adbb915a623

1 files changed, 41 insertions(+), 30 deletions(-)

jump to
M src/gba/renderers/software-mode0.csrc/gba/renderers/software-mode0.c

@@ -42,6 +42,9 @@

#define DRAW_BACKGROUND_MODE_0_TILE_PREFIX_16(BLEND, OBJWIN) \ charBase = (background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 5)) + (localY << 2); \ vram = renderer->d.vramBG[charBase >> VRAM_BLOCK_OFFSET]; \ + if (UNLIKELY(!vram)) { \ + return; \ + } \ LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 4; \ palette = &mainPalette[paletteData]; \

@@ -389,25 +392,29 @@ vram = renderer->d.vramBG[charBase >> VRAM_BLOCK_OFFSET]; \

tileData = carryData; \ for (x = 0; x < 8; ++x) { \ if (!mosaicWait) { \ - if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ - if (x >= 4) { \ - LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ - tileData >>= (x - 4) * 8; \ - } else { \ - LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ - tileData >>= x * 8; \ - } \ + if (UNLIKELY(!vram)) { \ + carryData = 0; \ } else { \ - if (x >= 4) { \ - LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ - tileData >>= (7 - x) * 8; \ + if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ + if (x >= 4) { \ + LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ + tileData >>= (x - 4) * 8; \ + } else { \ + LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + tileData >>= x * 8; \ + } \ } else { \ - LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ - tileData >>= (3 - x) * 8; \ + if (x >= 4) { \ + LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + tileData >>= (7 - x) * 8; \ + } else { \ + LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ + tileData >>= (3 - x) * 8; \ + } \ } \ + tileData &= 0xFF; \ + carryData = tileData; \ } \ - tileData &= 0xFF; \ - carryData = tileData; \ mosaicWait = mosaicH; \ } \ tileData |= tileData << 8; \

@@ -622,25 +629,29 @@ for (x = 0; x < 8 && length; ++x, --length) { \

if (!mosaicWait) { \ paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 8; \ palette = &mainPalette[paletteData]; \ - if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ - if (x >= 4) { \ - LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ - tileData >>= (x - 4) * 8; \ - } else { \ - LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ - tileData >>= x * 8; \ - } \ + if (UNLIKELY(!vram)) { \ + carryData = 0; \ } else { \ - if (x >= 4) { \ - LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ - tileData >>= (7 - x) * 8; \ + if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ + if (x >= 4) { \ + LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ + tileData >>= (x - 4) * 8; \ + } else { \ + LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + tileData >>= x * 8; \ + } \ } else { \ - LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ - tileData >>= (3 - x) * 8; \ + if (x >= 4) { \ + LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + tileData >>= (7 - x) * 8; \ + } else { \ + LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ + tileData >>= (3 - x) * 8; \ + } \ } \ + tileData &= 0xFF; \ + carryData = tileData; \ } \ - tileData &= 0xFF; \ - carryData = tileData; \ mosaicWait = mosaicH; \ } \ tileData |= tileData << 8; \