mirror of https://github.com/mgba-emu/mgba.git
Replace bit-packed map data with flags
This commit is contained in:
parent
7cb183a8be
commit
6e40c7ec29
|
@ -111,15 +111,10 @@ union GBAOAM {
|
||||||
uint16_t raw[512];
|
uint16_t raw[512];
|
||||||
};
|
};
|
||||||
|
|
||||||
union GBATextMapData {
|
#define GBA_TEXT_MAP_TILE(MAP) ((MAP) & 0x03FF)
|
||||||
struct {
|
#define GBA_TEXT_MAP_HFLIP(MAP) ((MAP) & 0x0400)
|
||||||
unsigned tile : 10;
|
#define GBA_TEXT_MAP_VFLIP(MAP) ((MAP) & 0x0800)
|
||||||
unsigned hflip : 1;
|
#define GBA_TEXT_MAP_PALETTE(MAP) (((MAP) & 0xF000) >> 12)
|
||||||
unsigned vflip : 1;
|
|
||||||
unsigned palette : 4;
|
|
||||||
};
|
|
||||||
uint16_t packed;
|
|
||||||
};
|
|
||||||
|
|
||||||
union GBARegisterDISPCNT {
|
union GBARegisterDISPCNT {
|
||||||
struct {
|
struct {
|
||||||
|
|
|
@ -663,8 +663,8 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
|
||||||
xBase += (localX & 0x100) << 5; \
|
xBase += (localX & 0x100) << 5; \
|
||||||
} \
|
} \
|
||||||
screenBase = (background->screenBase >> 1) + (xBase >> 3) + (yBase << 2); \
|
screenBase = (background->screenBase >> 1) + (xBase >> 3) + (yBase << 2); \
|
||||||
mapData.packed = renderer->d.vram[screenBase]; \
|
mapData = renderer->d.vram[screenBase]; \
|
||||||
if (!mapData.vflip) { \
|
if (!GBA_TEXT_MAP_VFLIP(mapData)) { \
|
||||||
localY = inY & 0x7; \
|
localY = inY & 0x7; \
|
||||||
} else { \
|
} else { \
|
||||||
localY = 7 - (inY & 0x7); \
|
localY = 7 - (inY & 0x7); \
|
||||||
|
@ -708,7 +708,7 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
y -= y % mosaicV;
|
y -= y % mosaicV;
|
||||||
}
|
}
|
||||||
int inY = y + background->y;
|
int inY = y + background->y;
|
||||||
union GBATextMapData mapData;
|
uint16_t mapData;
|
||||||
|
|
||||||
unsigned yBase = inY & 0xF8;
|
unsigned yBase = inY & 0xF8;
|
||||||
if (background->size == 2) {
|
if (background->size == 2) {
|
||||||
|
@ -750,10 +750,10 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
|
|
||||||
int end = outX + 0x8 - mod8;
|
int end = outX + 0x8 - mod8;
|
||||||
if (!background->multipalette) {
|
if (!background->multipalette) {
|
||||||
paletteData = mapData.palette << 4;
|
paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 4;
|
||||||
charBase = ((background->charBase + (mapData.tile << 5)) >> 2) + localY;
|
charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 5)) >> 2) + localY;
|
||||||
tileData = ((uint32_t*)renderer->d.vram)[charBase];
|
tileData = ((uint32_t*)renderer->d.vram)[charBase];
|
||||||
if (!mapData.hflip) {
|
if (!GBA_TEXT_MAP_HFLIP(mapData)) {
|
||||||
tileData >>= 4 * mod8;
|
tileData >>= 4 * mod8;
|
||||||
for (; outX < end; ++outX) {
|
for (; outX < end; ++outX) {
|
||||||
BACKGROUND_DRAW_PIXEL_16;
|
BACKGROUND_DRAW_PIXEL_16;
|
||||||
|
@ -765,7 +765,7 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: hflip
|
// TODO: hflip
|
||||||
charBase = ((background->charBase + (mapData.tile << 6)) >> 2) + (localY << 1);
|
charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 6)) >> 2) + (localY << 1);
|
||||||
int end2 = end - 4;
|
int end2 = end - 4;
|
||||||
int shift = inX & 0x3;
|
int shift = inX & 0x3;
|
||||||
if (end2 > 0) {
|
if (end2 > 0) {
|
||||||
|
@ -792,10 +792,10 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
|
|
||||||
int end = 0x8 - mod8;
|
int end = 0x8 - mod8;
|
||||||
if (!background->multipalette) {
|
if (!background->multipalette) {
|
||||||
charBase = ((background->charBase + (mapData.tile << 5)) >> 2) + localY;
|
charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 5)) >> 2) + localY;
|
||||||
tileData = ((uint32_t*)renderer->d.vram)[charBase];
|
tileData = ((uint32_t*)renderer->d.vram)[charBase];
|
||||||
paletteData = mapData.palette << 4;
|
paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 4;
|
||||||
if (!mapData.hflip) {
|
if (!GBA_TEXT_MAP_HFLIP(mapData)) {
|
||||||
outX = renderer->end - mod8;
|
outX = renderer->end - mod8;
|
||||||
if (outX < 0) {
|
if (outX < 0) {
|
||||||
tileData >>= 4 * -outX;
|
tileData >>= 4 * -outX;
|
||||||
|
@ -816,7 +816,7 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: hflip
|
// TODO: hflip
|
||||||
charBase = ((background->charBase + (mapData.tile << 6)) >> 2) + (localY << 1);
|
charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 6)) >> 2) + (localY << 1);
|
||||||
outX = renderer->end - 8 + end;
|
outX = renderer->end - 8 + end;
|
||||||
int end2 = 4 - end;
|
int end2 = 4 - end;
|
||||||
if (end2 > 0) {
|
if (end2 > 0) {
|
||||||
|
@ -846,13 +846,13 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
if (!background->multipalette) {
|
if (!background->multipalette) {
|
||||||
for (; tileX < tileEnd; ++tileX) {
|
for (; tileX < tileEnd; ++tileX) {
|
||||||
BACKGROUND_TEXT_SELECT_CHARACTER;
|
BACKGROUND_TEXT_SELECT_CHARACTER;
|
||||||
charBase = ((background->charBase + (mapData.tile << 5)) >> 2) + localY;
|
charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 5)) >> 2) + localY;
|
||||||
tileData = carryData;
|
tileData = carryData;
|
||||||
for (x = 0; x < 8; ++x) {
|
for (x = 0; x < 8; ++x) {
|
||||||
if (!mosaicWait) {
|
if (!mosaicWait) {
|
||||||
paletteData = mapData.palette << 4;
|
paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 4;
|
||||||
tileData = ((uint32_t*)renderer->d.vram)[charBase];
|
tileData = ((uint32_t*)renderer->d.vram)[charBase];
|
||||||
if (!mapData.hflip) {
|
if (!GBA_TEXT_MAP_HFLIP(mapData)) {
|
||||||
tileData >>= x * 4;
|
tileData >>= x * 4;
|
||||||
} else {
|
} else {
|
||||||
tileData >>= (7 - x) * 4;
|
tileData >>= (7 - x) * 4;
|
||||||
|
@ -882,11 +882,11 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
if (!background->multipalette) {
|
if (!background->multipalette) {
|
||||||
for (; tileX < tileEnd; ++tileX) {
|
for (; tileX < tileEnd; ++tileX) {
|
||||||
BACKGROUND_TEXT_SELECT_CHARACTER;
|
BACKGROUND_TEXT_SELECT_CHARACTER;
|
||||||
paletteData = mapData.palette << 4;
|
paletteData = GBA_TEXT_MAP_PALETTE(mapData) << 4;
|
||||||
charBase = ((background->charBase + (mapData.tile << 5)) >> 2) + localY;
|
charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 5)) >> 2) + localY;
|
||||||
tileData = ((uint32_t*)renderer->d.vram)[charBase];
|
tileData = ((uint32_t*)renderer->d.vram)[charBase];
|
||||||
if (tileData) {
|
if (tileData) {
|
||||||
if (!mapData.hflip) {
|
if (!GBA_TEXT_MAP_HFLIP(mapData)) {
|
||||||
BACKGROUND_DRAW_PIXEL_16;
|
BACKGROUND_DRAW_PIXEL_16;
|
||||||
++outX;
|
++outX;
|
||||||
BACKGROUND_DRAW_PIXEL_16;
|
BACKGROUND_DRAW_PIXEL_16;
|
||||||
|
@ -929,8 +929,8 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
} else {
|
} else {
|
||||||
for (; tileX < tileEnd; ++tileX) {
|
for (; tileX < tileEnd; ++tileX) {
|
||||||
BACKGROUND_TEXT_SELECT_CHARACTER;
|
BACKGROUND_TEXT_SELECT_CHARACTER;
|
||||||
charBase = ((background->charBase + (mapData.tile << 6)) >> 2) + (localY << 1);
|
charBase = ((background->charBase + (GBA_TEXT_MAP_TILE(mapData) << 6)) >> 2) + (localY << 1);
|
||||||
if (!mapData.hflip) {
|
if (!GBA_TEXT_MAP_HFLIP(mapData)) {
|
||||||
tileData = ((uint32_t*)renderer->d.vram)[charBase];
|
tileData = ((uint32_t*)renderer->d.vram)[charBase];
|
||||||
if (tileData) {
|
if (tileData) {
|
||||||
BACKGROUND_DRAW_PIXEL_256;
|
BACKGROUND_DRAW_PIXEL_256;
|
||||||
|
|
Loading…
Reference in New Issue