finish egg hatch, clean up headers
This commit is contained in:
297
src/bg.c
297
src/bg.c
@@ -1,10 +1,12 @@
|
||||
#include "global.h"
|
||||
#include "bg.h"
|
||||
#include "dma3.h"
|
||||
#include "gpu_regs.h"
|
||||
|
||||
#define DISPCNT_ALL_BG_AND_MODE_BITS 0x0F07
|
||||
#define DISPCNT_ALL_BG_AND_MODE_BITS (DISPCNT_BG_ALL_ON | 0x7)
|
||||
|
||||
struct BgControl {
|
||||
struct BgControl
|
||||
{
|
||||
struct BgConfig {
|
||||
u16 visible:1;
|
||||
u16 unknown_1:1;
|
||||
@@ -24,7 +26,8 @@ struct BgControl {
|
||||
u16 bgVisibilityAndMode;
|
||||
};
|
||||
|
||||
struct BgConfig2 {
|
||||
struct BgConfig2
|
||||
{
|
||||
u32 baseTile:10;
|
||||
u32 basePalette:4;
|
||||
u32 unk_3:18;
|
||||
@@ -34,54 +37,36 @@ struct BgConfig2 {
|
||||
u32 bg_y;
|
||||
};
|
||||
|
||||
static struct BgControl gGpuBgConfigs;
|
||||
static struct BgConfig2 gGpuBgConfigs2[4];
|
||||
static u32 gDmaBusyBitfield[4];
|
||||
static IWRAM_DATA struct BgControl sGpuBgConfigs;
|
||||
static IWRAM_DATA struct BgConfig2 sGpuBgConfigs2[4];
|
||||
static IWRAM_DATA u32 sDmaBusyBitfield[4];
|
||||
|
||||
u32 gUnneededFireRedVariable;
|
||||
|
||||
static const struct BgConfig gZeroedBgControlStruct = { 0 };
|
||||
|
||||
extern void SetGpuReg(u8 regOffset, u16 value);
|
||||
extern void SetGpuReg_ForcedBlank(u8 regOffset, u16 value);
|
||||
extern u16 GetGpuReg(u8 regOffset);
|
||||
extern int CheckForSpaceForDma3Request(s16 index);
|
||||
|
||||
bool32 IsInvalidBg32(u8);
|
||||
void ResetBgControlStructs();
|
||||
u16 GetBgMetricTextMode(u8, u8);
|
||||
u32 GetBgMetricAffineMode(u8, u8);
|
||||
u32 GetBgType(u8);
|
||||
void SetTextModeAndHideBgs();
|
||||
bool8 IsInvalidBg(u8);
|
||||
bool32 IsTileMapOutsideWram(u8);
|
||||
void CopyRectToBgTilemapBufferRect(u8, void*, u8, u8, u8, u8, u8, u8, u8, u8, u8, u16, u16);
|
||||
void CopyTileMapEntry(u16*, u16*, s32, u32, u32);
|
||||
u32 GetTileMapIndexFromCoords(s32, s32, s32, u32, u32);
|
||||
void WriteSequenceToBgTilemapBuffer(u8, u16, u8, u8, u8, u8, u8, s16);
|
||||
static const struct BgConfig sZeroedBgControlStruct = { 0 };
|
||||
|
||||
void ResetBgs(void)
|
||||
{
|
||||
ResetBgControlStructs();
|
||||
gGpuBgConfigs.bgVisibilityAndMode = 0;
|
||||
sGpuBgConfigs.bgVisibilityAndMode = 0;
|
||||
SetTextModeAndHideBgs();
|
||||
}
|
||||
|
||||
void SetBgModeInternal(u8 bgMode)
|
||||
static void SetBgModeInternal(u8 bgMode)
|
||||
{
|
||||
gGpuBgConfigs.bgVisibilityAndMode &= 0xFFF8;
|
||||
gGpuBgConfigs.bgVisibilityAndMode |= bgMode;
|
||||
sGpuBgConfigs.bgVisibilityAndMode &= 0xFFF8;
|
||||
sGpuBgConfigs.bgVisibilityAndMode |= bgMode;
|
||||
}
|
||||
|
||||
u8 GetBgMode(void)
|
||||
{
|
||||
return gGpuBgConfigs.bgVisibilityAndMode & 0x7;
|
||||
return sGpuBgConfigs.bgVisibilityAndMode & 0x7;
|
||||
}
|
||||
|
||||
void ResetBgControlStructs(void)
|
||||
{
|
||||
struct BgConfig* bgConfigs = &gGpuBgConfigs.configs[0];
|
||||
struct BgConfig zeroedConfig = gZeroedBgControlStruct;
|
||||
struct BgConfig* bgConfigs = &sGpuBgConfigs.configs[0];
|
||||
struct BgConfig zeroedConfig = sZeroedBgControlStruct;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
@@ -94,7 +79,7 @@ void Unused_ResetBgControlStruct(u8 bg)
|
||||
{
|
||||
if (IsInvalidBg(bg) == FALSE)
|
||||
{
|
||||
gGpuBgConfigs.configs[bg] = gZeroedBgControlStruct;
|
||||
sGpuBgConfigs.configs[bg] = sZeroedBgControlStruct;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,68 +89,68 @@ void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenS
|
||||
{
|
||||
if (charBaseIndex != 0xFF)
|
||||
{
|
||||
gGpuBgConfigs.configs[bg].charBaseIndex = charBaseIndex & 0x3;
|
||||
sGpuBgConfigs.configs[bg].charBaseIndex = charBaseIndex & 0x3;
|
||||
}
|
||||
|
||||
if (mapBaseIndex != 0xFF)
|
||||
{
|
||||
gGpuBgConfigs.configs[bg].mapBaseIndex = mapBaseIndex & 0x1F;
|
||||
sGpuBgConfigs.configs[bg].mapBaseIndex = mapBaseIndex & 0x1F;
|
||||
}
|
||||
|
||||
if (screenSize != 0xFF)
|
||||
{
|
||||
gGpuBgConfigs.configs[bg].screenSize = screenSize & 0x3;
|
||||
sGpuBgConfigs.configs[bg].screenSize = screenSize & 0x3;
|
||||
}
|
||||
|
||||
if (paletteMode != 0xFF)
|
||||
{
|
||||
gGpuBgConfigs.configs[bg].paletteMode = paletteMode;
|
||||
sGpuBgConfigs.configs[bg].paletteMode = paletteMode;
|
||||
}
|
||||
|
||||
if (priority != 0xFF)
|
||||
{
|
||||
gGpuBgConfigs.configs[bg].priority = priority & 0x3;
|
||||
sGpuBgConfigs.configs[bg].priority = priority & 0x3;
|
||||
}
|
||||
|
||||
if (mosaic != 0xFF)
|
||||
{
|
||||
gGpuBgConfigs.configs[bg].mosaic = mosaic & 0x1;
|
||||
sGpuBgConfigs.configs[bg].mosaic = mosaic & 0x1;
|
||||
}
|
||||
|
||||
if (wraparound != 0xFF)
|
||||
{
|
||||
gGpuBgConfigs.configs[bg].wraparound = wraparound;
|
||||
sGpuBgConfigs.configs[bg].wraparound = wraparound;
|
||||
}
|
||||
|
||||
gGpuBgConfigs.configs[bg].unknown_2 = 0;
|
||||
gGpuBgConfigs.configs[bg].unknown_3 = 0;
|
||||
sGpuBgConfigs.configs[bg].unknown_2 = 0;
|
||||
sGpuBgConfigs.configs[bg].unknown_3 = 0;
|
||||
|
||||
gGpuBgConfigs.configs[bg].visible = 1;
|
||||
sGpuBgConfigs.configs[bg].visible = 1;
|
||||
}
|
||||
}
|
||||
|
||||
u16 GetBgControlAttribute(u8 bg, u8 attributeId)
|
||||
{
|
||||
if (IsInvalidBg(bg) == FALSE && gGpuBgConfigs.configs[bg].visible != FALSE)
|
||||
if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE)
|
||||
{
|
||||
switch (attributeId)
|
||||
{
|
||||
case BG_CTRL_ATTR_VISIBLE:
|
||||
return gGpuBgConfigs.configs[bg].visible;
|
||||
return sGpuBgConfigs.configs[bg].visible;
|
||||
case BG_CTRL_ATTR_CHARBASEINDEX:
|
||||
return gGpuBgConfigs.configs[bg].charBaseIndex;
|
||||
return sGpuBgConfigs.configs[bg].charBaseIndex;
|
||||
case BG_CTRL_ATTR_MAPBASEINDEX:
|
||||
return gGpuBgConfigs.configs[bg].mapBaseIndex;
|
||||
return sGpuBgConfigs.configs[bg].mapBaseIndex;
|
||||
case BG_CTRL_ATTR_SCREENSIZE:
|
||||
return gGpuBgConfigs.configs[bg].screenSize;
|
||||
return sGpuBgConfigs.configs[bg].screenSize;
|
||||
case BG_CTRL_ATTR_PALETTEMODE:
|
||||
return gGpuBgConfigs.configs[bg].paletteMode;
|
||||
return sGpuBgConfigs.configs[bg].paletteMode;
|
||||
case BG_CTRL_ATTR_PRIORITY:
|
||||
return gGpuBgConfigs.configs[bg].priority;
|
||||
return sGpuBgConfigs.configs[bg].priority;
|
||||
case BG_CTRL_ATTR_MOSAIC:
|
||||
return gGpuBgConfigs.configs[bg].mosaic;
|
||||
return sGpuBgConfigs.configs[bg].mosaic;
|
||||
case BG_CTRL_ATTR_WRAPAROUND:
|
||||
return gGpuBgConfigs.configs[bg].wraparound;
|
||||
return sGpuBgConfigs.configs[bg].wraparound;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,15 +162,15 @@ u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode)
|
||||
u16 offset;
|
||||
s8 cursor;
|
||||
|
||||
if (IsInvalidBg(bg) == FALSE && gGpuBgConfigs.configs[bg].visible != FALSE)
|
||||
if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case 0x1:
|
||||
offset = gGpuBgConfigs.configs[bg].charBaseIndex * BG_CHAR_SIZE;
|
||||
offset = sGpuBgConfigs.configs[bg].charBaseIndex * BG_CHAR_SIZE;
|
||||
break;
|
||||
case 0x2:
|
||||
offset = gGpuBgConfigs.configs[bg].mapBaseIndex * BG_SCREEN_SIZE;
|
||||
offset = sGpuBgConfigs.configs[bg].mapBaseIndex * BG_SCREEN_SIZE;
|
||||
break;
|
||||
default:
|
||||
cursor = -1;
|
||||
@@ -210,51 +195,51 @@ end:
|
||||
return cursor;
|
||||
}
|
||||
|
||||
void ShowBgInternal(u8 bg)
|
||||
static void ShowBgInternal(u8 bg)
|
||||
{
|
||||
u16 value;
|
||||
if (IsInvalidBg(bg) == FALSE && gGpuBgConfigs.configs[bg].visible != FALSE)
|
||||
if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE)
|
||||
{
|
||||
value = gGpuBgConfigs.configs[bg].priority |
|
||||
(gGpuBgConfigs.configs[bg].charBaseIndex << 2) |
|
||||
(gGpuBgConfigs.configs[bg].mosaic << 6) |
|
||||
(gGpuBgConfigs.configs[bg].paletteMode << 7) |
|
||||
(gGpuBgConfigs.configs[bg].mapBaseIndex << 8) |
|
||||
(gGpuBgConfigs.configs[bg].wraparound << 13) |
|
||||
(gGpuBgConfigs.configs[bg].screenSize << 14);
|
||||
value = sGpuBgConfigs.configs[bg].priority |
|
||||
(sGpuBgConfigs.configs[bg].charBaseIndex << 2) |
|
||||
(sGpuBgConfigs.configs[bg].mosaic << 6) |
|
||||
(sGpuBgConfigs.configs[bg].paletteMode << 7) |
|
||||
(sGpuBgConfigs.configs[bg].mapBaseIndex << 8) |
|
||||
(sGpuBgConfigs.configs[bg].wraparound << 13) |
|
||||
(sGpuBgConfigs.configs[bg].screenSize << 14);
|
||||
|
||||
SetGpuReg((bg << 1) + 0x8, value);
|
||||
|
||||
gGpuBgConfigs.bgVisibilityAndMode |= 1 << (bg + 8);
|
||||
gGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS;
|
||||
sGpuBgConfigs.bgVisibilityAndMode |= 1 << (bg + 8);
|
||||
sGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS;
|
||||
}
|
||||
}
|
||||
|
||||
void HideBgInternal(u8 bg)
|
||||
static void HideBgInternal(u8 bg)
|
||||
{
|
||||
if (IsInvalidBg(bg) == FALSE)
|
||||
{
|
||||
gGpuBgConfigs.bgVisibilityAndMode &= ~(1 << (bg + 8));
|
||||
gGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS;
|
||||
sGpuBgConfigs.bgVisibilityAndMode &= ~(1 << (bg + 8));
|
||||
sGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS;
|
||||
}
|
||||
}
|
||||
|
||||
void SyncBgVisibilityAndMode()
|
||||
static void SyncBgVisibilityAndMode(void)
|
||||
{
|
||||
SetGpuReg(0, (GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS) | gGpuBgConfigs.bgVisibilityAndMode);
|
||||
SetGpuReg(0, (GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS) | sGpuBgConfigs.bgVisibilityAndMode);
|
||||
}
|
||||
|
||||
void SetTextModeAndHideBgs()
|
||||
void SetTextModeAndHideBgs(void)
|
||||
{
|
||||
SetGpuReg(0, GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS);
|
||||
}
|
||||
|
||||
void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle)
|
||||
static void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle)
|
||||
{
|
||||
struct BgAffineSrcData src;
|
||||
struct BgAffineDstData dest;
|
||||
|
||||
switch (gGpuBgConfigs.bgVisibilityAndMode & 0x7)
|
||||
switch (sGpuBgConfigs.bgVisibilityAndMode & 0x7)
|
||||
{
|
||||
case 1:
|
||||
if (bg != 2)
|
||||
@@ -309,7 +294,7 @@ void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable)
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
gDmaBusyBitfield[i] = 0;
|
||||
sDmaBusyBitfield[i] = 0;
|
||||
}
|
||||
|
||||
gUnneededFireRedVariable = leftoverFireRedLeafGreenVariable;
|
||||
@@ -336,18 +321,18 @@ void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numT
|
||||
0,
|
||||
0);
|
||||
|
||||
gGpuBgConfigs2[bg].baseTile = templates[i].baseTile;
|
||||
gGpuBgConfigs2[bg].basePalette = 0;
|
||||
gGpuBgConfigs2[bg].unk_3 = 0;
|
||||
sGpuBgConfigs2[bg].baseTile = templates[i].baseTile;
|
||||
sGpuBgConfigs2[bg].basePalette = 0;
|
||||
sGpuBgConfigs2[bg].unk_3 = 0;
|
||||
|
||||
gGpuBgConfigs2[bg].tilemap = NULL;
|
||||
gGpuBgConfigs2[bg].bg_x = 0;
|
||||
gGpuBgConfigs2[bg].bg_y = 0;
|
||||
sGpuBgConfigs2[bg].tilemap = NULL;
|
||||
sGpuBgConfigs2[bg].bg_x = 0;
|
||||
sGpuBgConfigs2[bg].bg_y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InitBgFromTemplate(struct BgTemplate *template)
|
||||
void InitBgFromTemplate(const struct BgTemplate *template)
|
||||
{
|
||||
u8 bg = template->bg;
|
||||
|
||||
@@ -362,13 +347,13 @@ void InitBgFromTemplate(struct BgTemplate *template)
|
||||
0,
|
||||
0);
|
||||
|
||||
gGpuBgConfigs2[bg].baseTile = template->baseTile;
|
||||
gGpuBgConfigs2[bg].basePalette = 0;
|
||||
gGpuBgConfigs2[bg].unk_3 = 0;
|
||||
sGpuBgConfigs2[bg].baseTile = template->baseTile;
|
||||
sGpuBgConfigs2[bg].basePalette = 0;
|
||||
sGpuBgConfigs2[bg].unk_3 = 0;
|
||||
|
||||
gGpuBgConfigs2[bg].tilemap = NULL;
|
||||
gGpuBgConfigs2[bg].bg_x = 0;
|
||||
gGpuBgConfigs2[bg].bg_y = 0;
|
||||
sGpuBgConfigs2[bg].tilemap = NULL;
|
||||
sGpuBgConfigs2[bg].bg_x = 0;
|
||||
sGpuBgConfigs2[bg].bg_y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,11 +369,11 @@ u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset)
|
||||
|
||||
if (GetBgControlAttribute(bg, BG_CTRL_ATTR_PALETTEMODE) == 0)
|
||||
{
|
||||
tileOffset = (gGpuBgConfigs2[bg].baseTile + destOffset) * 0x20;
|
||||
tileOffset = (sGpuBgConfigs2[bg].baseTile + destOffset) * 0x20;
|
||||
}
|
||||
else
|
||||
{
|
||||
tileOffset = (gGpuBgConfigs2[bg].baseTile + destOffset) * 0x40;
|
||||
tileOffset = (sGpuBgConfigs2[bg].baseTile + destOffset) * 0x40;
|
||||
}
|
||||
|
||||
cursor = LoadBgVram(bg, src, size, tileOffset, DISPCNT_MODE_1);
|
||||
@@ -398,7 +383,7 @@ u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset)
|
||||
return -1;
|
||||
}
|
||||
|
||||
gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
|
||||
sDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
|
||||
|
||||
if (gUnneededFireRedVariable == 1)
|
||||
{
|
||||
@@ -408,7 +393,7 @@ u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset)
|
||||
return cursor;
|
||||
}
|
||||
|
||||
u16 LoadBgTilemap(u8 bg, void *src, u16 size, u16 destOffset)
|
||||
u16 LoadBgTilemap(u8 bg, const void *src, u16 size, u16 destOffset)
|
||||
{
|
||||
u8 cursor;
|
||||
|
||||
@@ -419,19 +404,19 @@ u16 LoadBgTilemap(u8 bg, void *src, u16 size, u16 destOffset)
|
||||
return -1;
|
||||
}
|
||||
|
||||
gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
|
||||
sDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
u16 Unused_LoadBgPalette(u8 bg, void *src, u16 size, u16 destOffset)
|
||||
u16 Unused_LoadBgPalette(u8 bg, const void *src, u16 size, u16 destOffset)
|
||||
{
|
||||
u16 paletteOffset;
|
||||
s8 cursor;
|
||||
|
||||
if (IsInvalidBg32(bg) == FALSE)
|
||||
{
|
||||
paletteOffset = (gGpuBgConfigs2[bg].basePalette * 0x20) + (destOffset * 2);
|
||||
paletteOffset = (sGpuBgConfigs2[bg].basePalette * 0x20) + (destOffset * 2);
|
||||
cursor = RequestDma3Copy(src, (void*)(paletteOffset + BG_PLTT), size, 0);
|
||||
|
||||
if (cursor == -1)
|
||||
@@ -444,7 +429,7 @@ u16 Unused_LoadBgPalette(u8 bg, void *src, u16 size, u16 destOffset)
|
||||
return -1;
|
||||
}
|
||||
|
||||
gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
|
||||
sDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
|
||||
|
||||
return (u8)cursor;
|
||||
}
|
||||
@@ -463,7 +448,7 @@ bool8 IsDma3ManagerBusyWithBgCopy(void)
|
||||
div = i / 0x20;
|
||||
mod = i % 0x20;
|
||||
|
||||
if ((gDmaBusyBitfield[div] & (1 << mod)) != FALSE)
|
||||
if ((sDmaBusyBitfield[div] & (1 << mod)) != FALSE)
|
||||
{
|
||||
reqSpace = CheckForSpaceForDma3Request(i);
|
||||
if (reqSpace == -1)
|
||||
@@ -471,7 +456,7 @@ bool8 IsDma3ManagerBusyWithBgCopy(void)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gDmaBusyBitfield[div] &= ~(1 << mod);
|
||||
sDmaBusyBitfield[div] &= ~(1 << mod);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +482,7 @@ _08001AE4:\n\
|
||||
sub r0, r5, r0\n\
|
||||
lsl r0, #24\n\
|
||||
lsr r0, #24\n\
|
||||
ldr r1, =gDmaBusyBitfield\n\
|
||||
ldr r1, =sDmaBusyBitfield\n\
|
||||
lsr r2, #22\n\
|
||||
add r4, r2, r1\n\
|
||||
mov r6, #0x1\n\
|
||||
@@ -603,7 +588,7 @@ u16 GetBgAttribute(u8 bg, u8 attributeId)
|
||||
case 9:
|
||||
return GetBgType(bg);
|
||||
case 10:
|
||||
return gGpuBgConfigs2[bg].baseTile;
|
||||
return sGpuBgConfigs2[bg].baseTile;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@@ -624,13 +609,13 @@ u32 ChangeBgX(u8 bg, u32 value, u8 op)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
gGpuBgConfigs2[bg].bg_x = value;
|
||||
sGpuBgConfigs2[bg].bg_x = value;
|
||||
break;
|
||||
case 1:
|
||||
gGpuBgConfigs2[bg].bg_x += value;
|
||||
sGpuBgConfigs2[bg].bg_x += value;
|
||||
break;
|
||||
case 2:
|
||||
gGpuBgConfigs2[bg].bg_x -= value;
|
||||
sGpuBgConfigs2[bg].bg_x -= value;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -639,23 +624,23 @@ u32 ChangeBgX(u8 bg, u32 value, u8 op)
|
||||
switch (bg)
|
||||
{
|
||||
case 0:
|
||||
temp1 = gGpuBgConfigs2[0].bg_x >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[0].bg_x >> 0x8;
|
||||
SetGpuReg(REG_OFFSET_BG0HOFS, temp1);
|
||||
break;
|
||||
case 1:
|
||||
temp1 = gGpuBgConfigs2[1].bg_x >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[1].bg_x >> 0x8;
|
||||
SetGpuReg(REG_OFFSET_BG1HOFS, temp1);
|
||||
break;
|
||||
case 2:
|
||||
if (mode == 0)
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[2].bg_x >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[2].bg_x >> 0x8;
|
||||
SetGpuReg(REG_OFFSET_BG2HOFS, temp1);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[2].bg_x >> 0x10;
|
||||
temp2 = gGpuBgConfigs2[2].bg_x & 0xFFFF;
|
||||
temp1 = sGpuBgConfigs2[2].bg_x >> 0x10;
|
||||
temp2 = sGpuBgConfigs2[2].bg_x & 0xFFFF;
|
||||
SetGpuReg(REG_OFFSET_BG2X_H, temp1);
|
||||
SetGpuReg(REG_OFFSET_BG2X_L, temp2);
|
||||
}
|
||||
@@ -663,20 +648,20 @@ u32 ChangeBgX(u8 bg, u32 value, u8 op)
|
||||
case 3:
|
||||
if (mode == 0)
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[3].bg_x >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[3].bg_x >> 0x8;
|
||||
SetGpuReg(REG_OFFSET_BG3HOFS, temp1);
|
||||
}
|
||||
else if (mode == 2)
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[3].bg_x >> 0x10;
|
||||
temp2 = gGpuBgConfigs2[3].bg_x & 0xFFFF;
|
||||
temp1 = sGpuBgConfigs2[3].bg_x >> 0x10;
|
||||
temp2 = sGpuBgConfigs2[3].bg_x & 0xFFFF;
|
||||
SetGpuReg(REG_OFFSET_BG3X_H, temp1);
|
||||
SetGpuReg(REG_OFFSET_BG3X_L, temp2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return gGpuBgConfigs2[bg].bg_x;
|
||||
return sGpuBgConfigs2[bg].bg_x;
|
||||
}
|
||||
|
||||
u32 GetBgX(u8 bg)
|
||||
@@ -685,7 +670,7 @@ u32 GetBgX(u8 bg)
|
||||
return -1;
|
||||
if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0)
|
||||
return -1;
|
||||
return gGpuBgConfigs2[bg].bg_x;
|
||||
return sGpuBgConfigs2[bg].bg_x;
|
||||
}
|
||||
|
||||
u32 ChangeBgY(u8 bg, u32 value, u8 op)
|
||||
@@ -703,13 +688,13 @@ u32 ChangeBgY(u8 bg, u32 value, u8 op)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
gGpuBgConfigs2[bg].bg_y = value;
|
||||
sGpuBgConfigs2[bg].bg_y = value;
|
||||
break;
|
||||
case 1:
|
||||
gGpuBgConfigs2[bg].bg_y += value;
|
||||
sGpuBgConfigs2[bg].bg_y += value;
|
||||
break;
|
||||
case 2:
|
||||
gGpuBgConfigs2[bg].bg_y -= value;
|
||||
sGpuBgConfigs2[bg].bg_y -= value;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -718,23 +703,23 @@ u32 ChangeBgY(u8 bg, u32 value, u8 op)
|
||||
switch (bg)
|
||||
{
|
||||
case 0:
|
||||
temp1 = gGpuBgConfigs2[0].bg_y >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[0].bg_y >> 0x8;
|
||||
SetGpuReg(REG_OFFSET_BG0VOFS, temp1);
|
||||
break;
|
||||
case 1:
|
||||
temp1 = gGpuBgConfigs2[1].bg_y >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[1].bg_y >> 0x8;
|
||||
SetGpuReg(REG_OFFSET_BG1VOFS, temp1);
|
||||
break;
|
||||
case 2:
|
||||
if (mode == 0)
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[2].bg_y >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[2].bg_y >> 0x8;
|
||||
SetGpuReg(REG_OFFSET_BG2VOFS, temp1);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[2].bg_y >> 0x10;
|
||||
temp2 = gGpuBgConfigs2[2].bg_y & 0xFFFF;
|
||||
temp1 = sGpuBgConfigs2[2].bg_y >> 0x10;
|
||||
temp2 = sGpuBgConfigs2[2].bg_y & 0xFFFF;
|
||||
SetGpuReg(REG_OFFSET_BG2Y_H, temp1);
|
||||
SetGpuReg(REG_OFFSET_BG2Y_L, temp2);
|
||||
}
|
||||
@@ -742,20 +727,20 @@ u32 ChangeBgY(u8 bg, u32 value, u8 op)
|
||||
case 3:
|
||||
if (mode == 0)
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[3].bg_y >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[3].bg_y >> 0x8;
|
||||
SetGpuReg(REG_OFFSET_BG3VOFS, temp1);
|
||||
}
|
||||
else if (mode == 2)
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[3].bg_y >> 0x10;
|
||||
temp2 = gGpuBgConfigs2[3].bg_y & 0xFFFF;
|
||||
temp1 = sGpuBgConfigs2[3].bg_y >> 0x10;
|
||||
temp2 = sGpuBgConfigs2[3].bg_y & 0xFFFF;
|
||||
SetGpuReg(REG_OFFSET_BG3Y_H, temp1);
|
||||
SetGpuReg(REG_OFFSET_BG3Y_L, temp2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return gGpuBgConfigs2[bg].bg_y;
|
||||
return sGpuBgConfigs2[bg].bg_y;
|
||||
}
|
||||
|
||||
u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
|
||||
@@ -773,13 +758,13 @@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
|
||||
{
|
||||
case 0:
|
||||
default:
|
||||
gGpuBgConfigs2[bg].bg_y = value;
|
||||
sGpuBgConfigs2[bg].bg_y = value;
|
||||
break;
|
||||
case 1:
|
||||
gGpuBgConfigs2[bg].bg_y += value;
|
||||
sGpuBgConfigs2[bg].bg_y += value;
|
||||
break;
|
||||
case 2:
|
||||
gGpuBgConfigs2[bg].bg_y -= value;
|
||||
sGpuBgConfigs2[bg].bg_y -= value;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -788,24 +773,24 @@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
|
||||
switch (bg)
|
||||
{
|
||||
case 0:
|
||||
temp1 = gGpuBgConfigs2[0].bg_y >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[0].bg_y >> 0x8;
|
||||
SetGpuReg_ForcedBlank(REG_OFFSET_BG0VOFS, temp1);
|
||||
break;
|
||||
case 1:
|
||||
temp1 = gGpuBgConfigs2[1].bg_y >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[1].bg_y >> 0x8;
|
||||
SetGpuReg_ForcedBlank(REG_OFFSET_BG1VOFS, temp1);
|
||||
break;
|
||||
case 2:
|
||||
if (mode == 0)
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[2].bg_y >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[2].bg_y >> 0x8;
|
||||
SetGpuReg_ForcedBlank(REG_OFFSET_BG2VOFS, temp1);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[2].bg_y >> 0x10;
|
||||
temp2 = gGpuBgConfigs2[2].bg_y & 0xFFFF;
|
||||
temp1 = sGpuBgConfigs2[2].bg_y >> 0x10;
|
||||
temp2 = sGpuBgConfigs2[2].bg_y & 0xFFFF;
|
||||
SetGpuReg_ForcedBlank(REG_OFFSET_BG2Y_H, temp1);
|
||||
SetGpuReg_ForcedBlank(REG_OFFSET_BG2Y_L, temp2);
|
||||
}
|
||||
@@ -813,20 +798,20 @@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
|
||||
case 3:
|
||||
if (mode == 0)
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[3].bg_y >> 0x8;
|
||||
temp1 = sGpuBgConfigs2[3].bg_y >> 0x8;
|
||||
SetGpuReg_ForcedBlank(REG_OFFSET_BG3VOFS, temp1);
|
||||
}
|
||||
else if (mode == 2)
|
||||
{
|
||||
temp1 = gGpuBgConfigs2[3].bg_y >> 0x10;
|
||||
temp2 = gGpuBgConfigs2[3].bg_y & 0xFFFF;
|
||||
temp1 = sGpuBgConfigs2[3].bg_y >> 0x10;
|
||||
temp2 = sGpuBgConfigs2[3].bg_y & 0xFFFF;
|
||||
SetGpuReg_ForcedBlank(REG_OFFSET_BG3Y_H, temp1);
|
||||
SetGpuReg_ForcedBlank(REG_OFFSET_BG3Y_L, temp2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return gGpuBgConfigs2[bg].bg_y;
|
||||
return sGpuBgConfigs2[bg].bg_y;
|
||||
}
|
||||
|
||||
u32 GetBgY(u8 bg)
|
||||
@@ -835,7 +820,7 @@ u32 GetBgY(u8 bg)
|
||||
return -1;
|
||||
if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0)
|
||||
return -1;
|
||||
return gGpuBgConfigs2[bg].bg_y;
|
||||
return sGpuBgConfigs2[bg].bg_y;
|
||||
}
|
||||
|
||||
void SetBgAffine(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle)
|
||||
@@ -922,7 +907,7 @@ void SetBgTilemapBuffer(u8 bg, void *tilemap)
|
||||
{
|
||||
if (IsInvalidBg32(bg) == FALSE && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) != 0x0)
|
||||
{
|
||||
gGpuBgConfigs2[bg].tilemap = tilemap;
|
||||
sGpuBgConfigs2[bg].tilemap = tilemap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -930,7 +915,7 @@ void UnsetBgTilemapBuffer(u8 bg)
|
||||
{
|
||||
if (IsInvalidBg32(bg) == FALSE && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) != 0x0)
|
||||
{
|
||||
gGpuBgConfigs2[bg].tilemap = NULL;
|
||||
sGpuBgConfigs2[bg].tilemap = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -940,7 +925,7 @@ void* GetBgTilemapBuffer(u8 bg)
|
||||
return NULL;
|
||||
if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0)
|
||||
return NULL;
|
||||
return gGpuBgConfigs2[bg].tilemap;
|
||||
return sGpuBgConfigs2[bg].tilemap;
|
||||
}
|
||||
|
||||
void CopyToBgTilemapBuffer(u8 bg, const void *src, u16 mode, u16 destOffset)
|
||||
@@ -949,11 +934,11 @@ void CopyToBgTilemapBuffer(u8 bg, const void *src, u16 mode, u16 destOffset)
|
||||
{
|
||||
if (mode != 0)
|
||||
{
|
||||
CpuCopy16(src, (void *)(gGpuBgConfigs2[bg].tilemap + (destOffset * 2)), mode);
|
||||
CpuCopy16(src, (void *)(sGpuBgConfigs2[bg].tilemap + (destOffset * 2)), mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
LZ77UnCompWram(src, (void *)(gGpuBgConfigs2[bg].tilemap + (destOffset * 2)));
|
||||
LZ77UnCompWram(src, (void *)(sGpuBgConfigs2[bg].tilemap + (destOffset * 2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -976,7 +961,7 @@ void CopyBgTilemapBufferToVram(u8 bg)
|
||||
sizeToLoad = 0;
|
||||
break;
|
||||
}
|
||||
LoadBgVram(bg, gGpuBgConfigs2[bg].tilemap, sizeToLoad, 0, 2);
|
||||
LoadBgVram(bg, sGpuBgConfigs2[bg].tilemap, sizeToLoad, 0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -997,7 +982,7 @@ void CopyToBgTilemapBufferRect(u8 bg, void* src, u8 destX, u8 destY, u8 width, u
|
||||
{
|
||||
for (destX16 = destX; destX16 < (destX + width); destX16++)
|
||||
{
|
||||
((u16*)gGpuBgConfigs2[bg].tilemap)[((destY16 * 0x20) + destX16)] = *((u16*)srcCopy)++;
|
||||
((u16*)sGpuBgConfigs2[bg].tilemap)[((destY16 * 0x20) + destX16)] = *((u16*)srcCopy)++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1008,7 +993,7 @@ void CopyToBgTilemapBufferRect(u8 bg, void* src, u8 destX, u8 destY, u8 width, u
|
||||
{
|
||||
for (destX16 = destX; destX16 < (destX + width); destX16++)
|
||||
{
|
||||
((u8*)gGpuBgConfigs2[bg].tilemap)[((destY16 * mode) + destX16)] = *((u8*)srcCopy)++;
|
||||
((u8*)sGpuBgConfigs2[bg].tilemap)[((destY16 * mode) + destX16)] = *((u8*)srcCopy)++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1045,7 +1030,7 @@ void CopyRectToBgTilemapBufferRect(u8 bg, void* src, u8 srcX, u8 srcY, u8 srcWid
|
||||
{
|
||||
for (destX16 = destX; destX16 < (destX + rectWidth); destX16++)
|
||||
{
|
||||
CopyTileMapEntry(&((u16*)srcCopy)[(srcY * rectWidth) + srcX], &((u16*)gGpuBgConfigs2[bg].tilemap)[GetTileMapIndexFromCoords(destX16, destY16, attribute, mode, mode2)], palette1, tileOffset, palette2);
|
||||
CopyTileMapEntry(&((u16*)srcCopy)[(srcY * rectWidth) + srcX], &((u16*)sGpuBgConfigs2[bg].tilemap)[GetTileMapIndexFromCoords(destX16, destY16, attribute, mode, mode2)], palette1, tileOffset, palette2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1056,7 +1041,7 @@ void CopyRectToBgTilemapBufferRect(u8 bg, void* src, u8 srcX, u8 srcY, u8 srcWid
|
||||
{
|
||||
for (destX16 = destX; destX16 < (destX + rectWidth); destX16++)
|
||||
{
|
||||
CopyTileMapEntry(&((u16*)srcCopy)[(srcY * rectWidth) + srcX], &((u16*)gGpuBgConfigs2[bg].tilemap)[GetTileMapIndexFromCoords(destX16, destY16, attribute, mode, mode2)], palette1, tileOffset, palette2);
|
||||
CopyTileMapEntry(&((u16*)srcCopy)[(srcY * rectWidth) + srcX], &((u16*)sGpuBgConfigs2[bg].tilemap)[GetTileMapIndexFromCoords(destX16, destY16, attribute, mode, mode2)], palette1, tileOffset, palette2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1184,7 +1169,7 @@ _080025F8:\n\
|
||||
bge _0800265A\n\
|
||||
ldr r2, [sp, #0x4]\n\
|
||||
lsl r0, r2, #4\n\
|
||||
ldr r1, =gGpuBgConfigs2+4\n\
|
||||
ldr r1, =sGpuBgConfigs2+4\n\
|
||||
add r0, r1\n\
|
||||
mov r10, r0\n\
|
||||
ldr r7, [sp, #0x20]\n\
|
||||
@@ -1256,7 +1241,7 @@ _08002674:\n\
|
||||
sub r2, r7, r2\n\
|
||||
str r2, [sp, #0x34]\n\
|
||||
str r0, [sp, #0x38]\n\
|
||||
ldr r7, =gGpuBgConfigs2+4\n\
|
||||
ldr r7, =sGpuBgConfigs2+4\n\
|
||||
mov r10, r7\n\
|
||||
ldr r0, [sp, #0x4]\n\
|
||||
lsl r0, #4\n\
|
||||
@@ -1326,7 +1311,7 @@ void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width,
|
||||
{
|
||||
for (x16 = x; x16 < (x + width); x16++)
|
||||
{
|
||||
((u16*)gGpuBgConfigs2[bg].tilemap)[((y16 * 0x20) + x16)] = tileNum;
|
||||
((u16*)sGpuBgConfigs2[bg].tilemap)[((y16 * 0x20) + x16)] = tileNum;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1336,7 +1321,7 @@ void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width,
|
||||
{
|
||||
for (x16 = x; x16 < (x + width); x16++)
|
||||
{
|
||||
((u8*)gGpuBgConfigs2[bg].tilemap)[((y16 * mode) + x16)] = tileNum;
|
||||
((u8*)sGpuBgConfigs2[bg].tilemap)[((y16 * mode) + x16)] = tileNum;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1371,7 +1356,7 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt
|
||||
{
|
||||
for (x16 = x; x16 < (x + width); x16++)
|
||||
{
|
||||
CopyTileMapEntry(&firstTileNum, &((u16*)gGpuBgConfigs2[bg].tilemap)[(u16)GetTileMapIndexFromCoords(x16, y16, attribute, mode, mode2)], paletteSlot, 0, 0);
|
||||
CopyTileMapEntry(&firstTileNum, &((u16*)sGpuBgConfigs2[bg].tilemap)[(u16)GetTileMapIndexFromCoords(x16, y16, attribute, mode, mode2)], paletteSlot, 0, 0);
|
||||
firstTileNum = (firstTileNum & 0xFC00) + ((firstTileNum + tileNumDelta) & 0x3FF);
|
||||
}
|
||||
}
|
||||
@@ -1382,7 +1367,7 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt
|
||||
{
|
||||
for (x16 = x; x16 < (x + width); x16++)
|
||||
{
|
||||
((u8*)gGpuBgConfigs2[bg].tilemap)[(y16 * mode3) + x16] = firstTileNum;
|
||||
((u8*)sGpuBgConfigs2[bg].tilemap)[(y16 * mode3) + x16] = firstTileNum;
|
||||
firstTileNum = (firstTileNum & 0xFC00) + ((firstTileNum + tileNumDelta) & 0x3FF);
|
||||
}
|
||||
}
|
||||
@@ -1614,9 +1599,9 @@ bool32 IsInvalidBg32(u8 bg)
|
||||
|
||||
bool32 IsTileMapOutsideWram(u8 bg)
|
||||
{
|
||||
if (gGpuBgConfigs2[bg].tilemap > (void*)IWRAM_END)
|
||||
if (sGpuBgConfigs2[bg].tilemap > (void*)IWRAM_END)
|
||||
return TRUE;
|
||||
if (gGpuBgConfigs2[bg].tilemap == 0x0)
|
||||
if (sGpuBgConfigs2[bg].tilemap == 0x0)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user