diff --git a/src/gba/renderers/software-mode0.c b/src/gba/renderers/software-mode0.c index 2dea1da1d..b41970b26 100644 --- a/src/gba/renderers/software-mode0.c +++ b/src/gba/renderers/software-mode0.c @@ -21,15 +21,17 @@ palette = &mainPalette[paletteData]; \ charBase = (background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 5)) + (localY << 2); \ vram = renderer->d.vramBG[charBase >> VRAM_BLOCK_OFFSET]; \ - LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ - if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ - tileData >>= 4 * mod8; \ - for (; outX < end; ++outX) { \ - BACKGROUND_DRAW_PIXEL_16(BLEND, OBJWIN, 0); \ - } \ - } else { \ - for (outX = end - 1; outX >= renderer->start; --outX) { \ - BACKGROUND_DRAW_PIXEL_16(BLEND, OBJWIN, 0); \ + if (LIKELY(vram)) { \ + LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ + tileData >>= 4 * mod8; \ + for (; outX < end; ++outX) { \ + BACKGROUND_DRAW_PIXEL_16(BLEND, OBJWIN, 0); \ + } \ + } else { \ + for (outX = end - 1; outX >= renderer->start; --outX) { \ + BACKGROUND_DRAW_PIXEL_16(BLEND, OBJWIN, 0); \ + } \ } \ } @@ -189,37 +191,39 @@ #define DRAW_BACKGROUND_MODE_0_TILE_SUFFIX_256(BLEND, OBJWIN) \ charBase = (background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 6)) + (localY << 3); \ vram = renderer->d.vramBG[charBase >> VRAM_BLOCK_OFFSET]; \ - int end2 = end - 4; \ - if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ - int shift = inX & 0x3; \ - if (end2 > outX) { \ - LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + if (LIKELY(vram)) { \ + int end2 = end - 4; \ + if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ + int shift = inX & 0x3; \ + if (end2 > outX) { \ + LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + tileData >>= 8 * shift; \ + shift = 0; \ + for (; outX < end2; ++outX) { \ + BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ + } \ + } \ + \ + LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ tileData >>= 8 * shift; \ - shift = 0; \ - for (; outX < end2; ++outX) { \ + for (; outX < end; ++outX) { \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ } \ - } \ - \ - LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ - tileData >>= 8 * shift; \ - for (; outX < end; ++outX) { \ - BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ - } \ - } else { \ - int start = outX; \ - outX = end - 1; \ - if (end2 > start) { \ + } else { \ + int start = outX; \ + outX = end - 1; \ + if (end2 > start) { \ + LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + for (; outX >= end2; --outX) { \ + BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ + } \ + charBase += 4; \ + } \ + \ LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ - for (; outX >= end2; --outX) { \ + for (; outX >= renderer->start; --outX) { \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ } \ - charBase += 4; \ - } \ - \ - LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ - for (; outX >= renderer->start; --outX) { \ - BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ } \ } @@ -412,39 +416,41 @@ #define DRAW_BACKGROUND_MODE_0_TILE_SUFFIX_256EXT(BLEND, OBJWIN) \ charBase = (background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 6)) + (localY << 3); \ vram = renderer->d.vramBG[charBase >> VRAM_BLOCK_OFFSET]; \ - int end2 = end - 4; \ - paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 8; \ - palette = &mainPalette[paletteData]; \ - if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ - int shift = inX & 0x3; \ - if (end2 > outX) { \ - LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + if (LIKELY(vram)) { \ + int end2 = end - 4; \ + paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 8; \ + palette = &mainPalette[paletteData]; \ + if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ + int shift = inX & 0x3; \ + if (end2 > outX) { \ + LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + tileData >>= 8 * shift; \ + shift = 0; \ + for (; outX < end2; ++outX) { \ + BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ + } \ + } \ + \ + LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ tileData >>= 8 * shift; \ - shift = 0; \ - for (; outX < end2; ++outX) { \ + for (; outX < end; ++outX) { \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ } \ - } \ - \ - LOAD_32(tileData, (charBase + 4) & VRAM_BLOCK_MASK, vram); \ - tileData >>= 8 * shift; \ - for (; outX < end; ++outX) { \ - BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ - } \ - } else { \ - int start = outX; \ - outX = end - 1; \ - if (end2 > start) { \ + } else { \ + int start = outX; \ + outX = end - 1; \ + if (end2 > start) { \ + LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ + for (; outX >= end2; --outX) { \ + BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ + } \ + charBase += 4; \ + } \ + \ LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ - for (; outX >= end2; --outX) { \ + for (; outX >= renderer->start; --outX) { \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ } \ - charBase += 4; \ - } \ - \ - LOAD_32(tileData, charBase & VRAM_BLOCK_MASK, vram); \ - for (; outX >= renderer->start; --outX) { \ - BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN, 0); \ } \ }