Preliminary pass at straightening out VRAM loads
@@ -811,7 +811,7 @@ if (background->size & 1) { \
xBase += (localX & 0x100) << 5; \ } \ screenBase = yBase + (xBase >> 3); \ - mapData = vram[screenBase]; \ + LOAD_16(mapData, screenBase << 1, vram); \ localY = inY & 0x7; \ if (GBA_TEXT_MAP_VFLIP(mapData)) { \ localY = 7 - localY; \@@ -852,7 +852,7 @@ #define DRAW_BACKGROUND_MODE_0_TILE_SUFFIX_16(BLEND, OBJWIN) \
paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 4; \ palette = &mainPalette[paletteData]; \ charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 5)) >> 2) + localY; \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ tileData >>= 4 * mod8; \ for (; outX < end; ++outX) { \@@ -868,7 +868,7 @@ }
#define DRAW_BACKGROUND_MODE_0_TILE_PREFIX_16(BLEND, OBJWIN) \ charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 5)) >> 2) + localY; \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 4; \ palette = &mainPalette[paletteData]; \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \@@ -902,7 +902,7 @@ for (x = 0; x < 8; ++x) { \
if (!mosaicWait) { \ paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 4; \ palette = &mainPalette[paletteData]; \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ tileData >>= x * 4; \ } else { \@@ -931,7 +931,7 @@ BACKGROUND_TEXT_SELECT_CHARACTER; \
paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 4; \ palette = &mainPalette[paletteData]; \ charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 5)) >> 2) + localY; \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ if (tileData) { \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ BACKGROUND_DRAW_PIXEL_16(BLEND, OBJWIN); \@@ -980,7 +980,7 @@ int end2 = end - 4; \
if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ int shift = inX & 0x3; \ if (end2 > outX) { \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ tileData >>= 8 * shift; \ shift = 0; \ for (; outX < end2; ++outX) { \@@ -989,7 +989,7 @@ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \
} \ } \ \ - tileData = ((uint32_t*) vram)[charBase + 1]; \ + LOAD_32(tileData, (charBase + 1) << 2, vram); \ tileData >>= 8 * shift; \ for (; outX < end; ++outX) { \ pixel = &renderer->row[outX]; \@@ -999,7 +999,7 @@ } else { \
int start = outX; \ outX = end - 1; \ if (end2 > start) { \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ for (; outX >= end2; --outX) { \ pixel = &renderer->row[outX]; \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \@@ -1007,7 +1007,7 @@ } \
++charBase; \ } \ \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ for (; outX >= renderer->start; --outX) { \ pixel = &renderer->row[outX]; \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \@@ -1021,7 +1021,7 @@ outX = renderer->end - 8 + end; \
int end2 = 4 - end; \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ if (end2 > 0) { \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ for (; outX < renderer->end - end2; ++outX) { \ pixel = &renderer->row[outX]; \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \@@ -1029,7 +1029,7 @@ } \
++charBase; \ } \ \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ for (; outX < renderer->end; ++outX) { \ pixel = &renderer->row[outX]; \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \@@ -1039,7 +1039,7 @@ int shift = end & 0x3; \
int start = outX; \ outX = renderer->end - 1; \ if (end2 > 0) { \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ tileData >>= 8 * shift; \ for (; outX >= start + 4; --outX) { \ pixel = &renderer->row[outX]; \@@ -1048,7 +1048,7 @@ } \
shift = 0; \ } \ \ - tileData = ((uint32_t*) vram)[charBase + 1]; \ + LOAD_32(tileData, (charBase + 1) << 2, vram); \ tileData >>= 8 * shift; \ for (; outX >= start; --outX) { \ pixel = &renderer->row[outX]; \@@ -1061,7 +1061,7 @@ for (; tileX < tileEnd; ++tileX) { \
BACKGROUND_TEXT_SELECT_CHARACTER; \ charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 6)) >> 2) + (localY << 1); \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ if (tileData) { \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \ ++pixel; \@@ -1074,7 +1074,7 @@ ++pixel; \
} else { \ pixel += 4; \ } \ - tileData = ((uint32_t*) vram)[charBase + 1]; \ + LOAD_32(tileData, (charBase + 1) << 2, vram); \ if (tileData) { \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \ ++pixel; \@@ -1088,7 +1088,7 @@ } else { \
pixel += 4; \ } \ } else { \ - uint32_t tileData = ((uint32_t*) vram)[charBase + 1]; \ + LOAD_32(tileData, (charBase + 1) << 2, vram); \ if (tileData) { \ pixel += 3; \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \@@ -1100,7 +1100,7 @@ --pixel; \
BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \ } \ pixel += 4; \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ if (tileData) { \ pixel += 3; \ BACKGROUND_DRAW_PIXEL_256(BLEND, OBJWIN); \@@ -1124,18 +1124,18 @@ for (x = 0; x < 8; ++x) { \
if (!mosaicWait) { \ if (!GBA_TEXT_MAP_HFLIP(mapData)) { \ if (x >= 4) { \ - tileData = ((uint32_t*) vram)[charBase + 1]; \ + LOAD_32(tileData, (charBase + 1) << 2, vram); \ tileData >>= (x - 4) * 8; \ } else { \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ tileData >>= x * 8; \ } \ } else { \ if (x >= 4) { \ - tileData = ((uint32_t*) vram)[charBase]; \ + LOAD_32(tileData, charBase << 2, vram); \ tileData >>= (7 - x) * 8; \ } else { \ - tileData = ((uint32_t*) vram)[charBase + 1]; \ + LOAD_32(tileData, (charBase + 1) << 2, vram); \ tileData >>= (3 - x) * 8; \ } \ } \@@ -1348,7 +1348,7 @@ uint32_t* pixel;
for (outX = renderer->start, pixel = &renderer->row[outX]; outX < renderer->end; ++outX, ++pixel) { BACKGROUND_BITMAP_ITERATE(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS); - color = ((uint16_t*)renderer->d.vram)[(localX >> 8) + (localY >> 8) * VIDEO_HORIZONTAL_PIXELS]; + LOAD_16(color, (localX >> 8) + (localY >> 8) * VIDEO_HORIZONTAL_PIXELS << 1, renderer->d.vram); #ifndef COLOR_16_BIT unsigned color32; color32 = 0;@@ -1413,7 +1413,7 @@ uint32_t* pixel;
for (outX = renderer->start, pixel = &renderer->row[outX]; outX < renderer->end; ++outX, ++pixel) { BACKGROUND_BITMAP_ITERATE(160, 128); - color = ((uint16_t*)renderer->d.vram)[offset + (localX >> 8) + (localY >> 8) * 160]; + LOAD_16(color, offset + (localX >> 8) + (localY >> 8) * 320, renderer->d.vram); #ifndef COLOR_16_BIT unsigned color32 = 0; color32 |= (color << 9) & 0xF80000;