all repos — mgba @ c2040a1f63dcbedb9a16a17ae174858523a77151

mGBA Game Boy Advance Emulator

GBA Video: Fix mode 0 being able to read tiles above appropriate tile range
Jeffrey Pfau jeffrey@endrift.com
Thu, 15 Jan 2015 02:01:33 -0800
commit

c2040a1f63dcbedb9a16a17ae174858523a77151

parent

1a9b0eec6f1c9c270135370b5ffc00c7fd47f9c0

2 files changed, 38 insertions(+), 18 deletions(-)

jump to
M CHANGESCHANGES

@@ -59,6 +59,7 @@ - GBA BIOS: Fix BIOS prefetch after returning from an IRQ

- GBA BIOS: Fix BIOS prefetch after reset - GBA Memory: Fix alignment of open bus 8- and 16-bit loads - GBA BIOS: Fix HuffUnComp boundary conditions + - GBA Video: Fix mode 0 being able to read tiles above appropriate tile range Misc: - Qt: Disable sync to video by default - GBA: Exit cleanly on FATAL if the port supports it
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -1010,6 +1010,10 @@ BACKGROUND_TEXT_SELECT_CHARACTER; \

paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 4; \ palette = &mainPalette[paletteData]; \ charBase = (background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 5)) + (localY << 2); \ + if (UNLIKELY(charBase >= 0x10000)) { \ + pixel += 8; \ + continue; \ + } \ LOAD_32(tileData, charBase, vram); \ if (tileData) { \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \

@@ -1058,35 +1062,43 @@ charBase = (background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 6)) + (localY << 3); \

int end2 = end - 4; \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ int shift = inX & 0x3; \ - if (end2 > outX) { \ - LOAD_32(tileData, charBase, vram); \ - tileData >>= 8 * shift; \ - shift = 0; \ - for (; outX < end2; ++outX, ++pixel) { \ - BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \ + if (LIKELY(charBase < 0x10000)) { \ + if (end2 > outX) { \ + LOAD_32(tileData, charBase, vram); \ + tileData >>= 8 * shift; \ + shift = 0; \ + for (; outX < end2; ++outX, ++pixel) { \ + BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \ + } \ } \ } \ \ - LOAD_32(tileData, charBase + 4, vram); \ - tileData >>= 8 * shift; \ - for (; outX < end; ++outX, ++pixel) { \ - BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \ + if (LIKELY(charBase < 0x10000)) { \ + LOAD_32(tileData, charBase + 4, vram); \ + tileData >>= 8 * shift; \ + for (; outX < end; ++outX, ++pixel) { \ + BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \ + } \ } \ } else { \ int start = outX; \ outX = end - 1; \ pixel = &renderer->row[outX]; \ - if (end2 > start) { \ + if (LIKELY(charBase < 0x10000)) { \ + if (end2 > start) { \ + LOAD_32(tileData, charBase, vram); \ + for (; outX >= end2; --outX, --pixel) { \ + BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \ + } \ + charBase += 4; \ + } \ + } \ + \ + if (LIKELY(charBase < 0x10000)) { \ LOAD_32(tileData, charBase, vram); \ - for (; outX >= end2; --outX, --pixel) { \ + for (; outX >= renderer->start; --outX, --pixel) { \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \ } \ - charBase += 4; \ - } \ - \ - LOAD_32(tileData, charBase, vram); \ - for (; outX >= renderer->start; --outX, --pixel) { \ - BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \ } \ outX = end; \ pixel = &renderer->row[outX]; \

@@ -1094,6 +1106,9 @@ }

#define DRAW_BACKGROUND_MODE_0_TILE_PREFIX_256(BLEND, OBJWIN) \ charBase = (background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 6)) + (localY << 3); \ + if (UNLIKELY(charBase >= 0x10000)) { \ + return; \ + } \ int end = mod8 - 4; \ pixel = &renderer->row[outX]; \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \

@@ -1139,6 +1154,10 @@ #define DRAW_BACKGROUND_MODE_0_TILES_256(BLEND, OBJWIN) \

for (; tileX < tileEnd; ++tileX) { \ BACKGROUND_TEXT_SELECT_CHARACTER; \ charBase = (background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 6)) + (localY << 3); \ + if (UNLIKELY(charBase >= 0x10000)) { \ + pixel += 8; \ + continue; \ + } \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ LOAD_32(tileData, charBase, vram); \ if (tileData) { \