summaryrefslogtreecommitdiff
path: root/gflib
diff options
context:
space:
mode:
Diffstat (limited to 'gflib')
-rw-r--r--gflib/bg.c20
-rw-r--r--gflib/window.c104
-rw-r--r--gflib/window.h10
3 files changed, 68 insertions, 66 deletions
diff --git a/gflib/bg.c b/gflib/bg.c
index 66dd81a25..1ca8a44a1 100644
--- a/gflib/bg.c
+++ b/gflib/bg.c
@@ -22,7 +22,7 @@ struct BgControl
u8 unknown_2;
u8 unknown_3;
- } configs[4];
+ } configs[NUM_BACKGROUNDS];
u16 bgVisibilityAndMode;
};
@@ -39,8 +39,8 @@ struct BgConfig2
};
static struct BgControl sGpuBgConfigs;
-static struct BgConfig2 sGpuBgConfigs2[4];
-static u32 sDmaBusyBitfield[4];
+static struct BgConfig2 sGpuBgConfigs2[NUM_BACKGROUNDS];
+static u32 sDmaBusyBitfield[NUM_BACKGROUNDS];
u32 gUnneededFireRedVariable;
@@ -70,7 +70,7 @@ void ResetBgControlStructs(void)
struct BgConfig zeroedConfig = sZeroedBgControlStruct;
int i;
- for (i = 0; i < 4; i++)
+ for (i = 0; i < NUM_BACKGROUNDS; i++)
{
bgConfigs[i] = zeroedConfig;
}
@@ -259,7 +259,7 @@ static void SetBgAffineInternal(u8 bg, s32 srcCenterX, s32 srcCenterY, s16 dispC
return;
break;
case 2:
- if (bg < 2 || bg > 3)
+ if (bg < 2 || bg >= NUM_BACKGROUNDS)
return;
break;
case 0:
@@ -290,7 +290,7 @@ static void SetBgAffineInternal(u8 bg, s32 srcCenterX, s32 srcCenterY, s16 dispC
bool8 IsInvalidBg(u8 bg)
{
- if (bg > 3)
+ if (bg >= NUM_BACKGROUNDS)
return TRUE;
else
return FALSE;
@@ -306,7 +306,7 @@ void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable)
int i;
ResetBgs();
- for (i = 0; i < 4; i++)
+ for (i = 0; i < NUM_BACKGROUNDS; i++)
{
sDmaBusyBitfield[i] = 0;
}
@@ -325,7 +325,7 @@ void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numT
for (i = 0; i < numTemplates; i++)
{
bg = templates[i].bg;
- if (bg < 4)
+ if (bg < NUM_BACKGROUNDS)
{
SetBgControlAttributes(bg,
templates[i].charBaseIndex,
@@ -351,7 +351,7 @@ void InitBgFromTemplate(const struct BgTemplate *template)
{
u8 bg = template->bg;
- if (bg < 4)
+ if (bg < NUM_BACKGROUNDS)
{
SetBgControlAttributes(bg,
template->charBaseIndex,
@@ -1239,7 +1239,7 @@ u32 GetBgType(u8 bg)
bool32 IsInvalidBg32(u8 bg)
{
- if (bg > 3)
+ if (bg >= NUM_BACKGROUNDS)
return TRUE;
else
return FALSE;
diff --git a/gflib/window.c b/gflib/window.c
index 7c87ea86d..b03b513da 100644
--- a/gflib/window.c
+++ b/gflib/window.c
@@ -4,12 +4,12 @@
#include "bg.h"
#include "blit.h"
-u32 filler_03002F58;
-u32 filler_03002F5C;
+u32 gUnusedWindowVar1;
+u32 gUnusedWindowVar2;
// This global is set to 0 and never changed.
u8 gTransparentTileNumber;
-u32 filler_03002F64;
-void *gUnknown_03002F70[4];
+u32 gUnusedWindowVar3;
+void *gWindowBgTilemapBuffers[NUM_BACKGROUNDS];
extern u32 gUnneededFireRedVariable;
#define WINDOWS_MAX 32
@@ -23,7 +23,7 @@ static u8 GetNumActiveWindowsOnBg8Bit(u8 bgId);
static const struct WindowTemplate sDummyWindowTemplate = DUMMY_WIN_TEMPLATE;
-static void nullsub_8(void)
+static void DummyWindowBgTilemap(void)
{
}
@@ -38,22 +38,22 @@ bool16 InitWindows(const struct WindowTemplate *templates)
u8* allocatedTilemapBuffer;
int allocatedBaseBlock;
- for (i = 0; i < 0x4; ++i)
+ for (i = 0; i < NUM_BACKGROUNDS; ++i)
{
bgTilemapBuffer = GetBgTilemapBuffer(i);
if (bgTilemapBuffer != NULL)
- gUnknown_03002F70[i] = nullsub_8;
+ gWindowBgTilemapBuffers[i] = DummyWindowBgTilemap;
else
- gUnknown_03002F70[i] = bgTilemapBuffer;
+ gWindowBgTilemapBuffers[i] = bgTilemapBuffer;
}
- for (i = 0; i < 0x20; ++i)
+ for (i = 0; i < WINDOWS_MAX; ++i)
{
gWindows[i].window = sDummyWindowTemplate;
gWindows[i].tileData = NULL;
}
- for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].bg; bgLayer != 0xFF && i < 0x20; ++i, bgLayer = templates[i].bg)
+ for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].bg; bgLayer != 0xFF && i < WINDOWS_MAX; ++i, bgLayer = templates[i].bg)
{
if (gUnneededFireRedVariable == 1)
{
@@ -62,7 +62,7 @@ bool16 InitWindows(const struct WindowTemplate *templates)
return FALSE;
}
- if (gUnknown_03002F70[bgLayer] == NULL)
+ if (gWindowBgTilemapBuffers[bgLayer] == NULL)
{
attrib = GetBgAttribute(bgLayer, BG_ATTR_METRIC);
@@ -79,19 +79,19 @@ bool16 InitWindows(const struct WindowTemplate *templates)
for (j = 0; j < attrib; ++j)
allocatedTilemapBuffer[j] = 0;
- gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer;
+ gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer;
SetBgTilemapBuffer(bgLayer, allocatedTilemapBuffer);
}
}
- allocatedTilemapBuffer = AllocZeroed((u16)(0x20 * (templates[i].width * templates[i].height)));
+ allocatedTilemapBuffer = AllocZeroed((u16)(32 * (templates[i].width * templates[i].height)));
if (allocatedTilemapBuffer == NULL)
{
- if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gUnknown_03002F70[bgLayer] != nullsub_8))
+ if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap))
{
- Free(gUnknown_03002F70[bgLayer]);
- gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer;
+ Free(gWindowBgTilemapBuffers[bgLayer]);
+ gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer;
}
return FALSE;
@@ -127,7 +127,7 @@ u16 AddWindow(const struct WindowTemplate *template)
}
if (win == WINDOWS_MAX)
- return 0xFF;
+ return WINDOW_NONE;
bgLayer = template->bg;
allocatedBaseBlock = 0;
@@ -137,10 +137,10 @@ u16 AddWindow(const struct WindowTemplate *template)
allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0);
if (allocatedBaseBlock == -1)
- return 0xFF;
+ return WINDOW_NONE;
}
- if (gUnknown_03002F70[bgLayer] == NULL)
+ if (gWindowBgTilemapBuffers[bgLayer] == NULL)
{
attrib = GetBgAttribute(bgLayer, BG_ATTR_METRIC);
@@ -149,26 +149,26 @@ u16 AddWindow(const struct WindowTemplate *template)
allocatedTilemapBuffer = AllocZeroed(attrib);
if (allocatedTilemapBuffer == NULL)
- return 0xFF;
+ return WINDOW_NONE;
for (i = 0; i < attrib; ++i)
allocatedTilemapBuffer[i] = 0;
- gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer;
+ gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer;
SetBgTilemapBuffer(bgLayer, allocatedTilemapBuffer);
}
}
- allocatedTilemapBuffer = AllocZeroed((u16)(0x20 * (template->width * template->height)));
+ allocatedTilemapBuffer = AllocZeroed((u16)(32 * (template->width * template->height)));
if (allocatedTilemapBuffer == NULL)
{
- if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gUnknown_03002F70[bgLayer] != nullsub_8))
+ if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap))
{
- Free(gUnknown_03002F70[bgLayer]);
- gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer;
+ Free(gWindowBgTilemapBuffers[bgLayer]);
+ gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer;
}
- return 0xFF;
+ return WINDOW_NONE;
}
gWindows[win].tileData = allocatedTilemapBuffer;
@@ -196,7 +196,7 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template)
}
if (win == WINDOWS_MAX)
- return 0xFF;
+ return WINDOW_NONE;
bgLayer = template->bg;
allocatedBaseBlock = 0;
@@ -206,7 +206,7 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template)
allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0);
if (allocatedBaseBlock == -1)
- return 0xFF;
+ return WINDOW_NONE;
}
gWindows[win].window = *template;
@@ -233,10 +233,10 @@ void RemoveWindow(u8 windowId)
if (GetNumActiveWindowsOnBg(bgLayer) == 0)
{
- if (gUnknown_03002F70[bgLayer] != nullsub_8)
+ if (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap)
{
- Free(gUnknown_03002F70[bgLayer]);
- gUnknown_03002F70[bgLayer] = 0;
+ Free(gWindowBgTilemapBuffers[bgLayer]);
+ gWindowBgTilemapBuffers[bgLayer] = NULL;
}
}
@@ -251,16 +251,16 @@ void FreeAllWindowBuffers(void)
{
int i;
- for (i = 0; i < 4; ++i)
+ for (i = 0; i < NUM_BACKGROUNDS; ++i)
{
- if (gUnknown_03002F70[i] != NULL && gUnknown_03002F70[i] != nullsub_8)
+ if (gWindowBgTilemapBuffers[i] != NULL && gWindowBgTilemapBuffers[i] != DummyWindowBgTilemap)
{
- Free(gUnknown_03002F70[i]);
- gUnknown_03002F70[i] = NULL;
+ Free(gWindowBgTilemapBuffers[i]);
+ gWindowBgTilemapBuffers[i] = NULL;
}
}
- for (i = 0; i < 0x20; ++i)
+ for (i = 0; i < WINDOWS_MAX; ++i)
{
if (gWindows[i].tileData != NULL)
{
@@ -448,16 +448,16 @@ void FillWindowPixelRect(u8 windowId, u8 fillValue, u16 x, u16 y, u16 width, u16
void CopyToWindowPixelBuffer(u8 windowId, const void *src, u16 size, u16 tileOffset)
{
if (size != 0)
- CpuCopy16(src, gWindows[windowId].tileData + (0x20 * tileOffset), size);
+ CpuCopy16(src, gWindows[windowId].tileData + (32 * tileOffset), size);
else
- LZ77UnCompWram(src, gWindows[windowId].tileData + (0x20 * tileOffset));
+ LZ77UnCompWram(src, gWindows[windowId].tileData + (32 * tileOffset));
}
// Sets all pixels within the window to the fillValue color.
void FillWindowPixelBuffer(u8 windowId, u8 fillValue)
{
int fillSize = gWindows[windowId].window.width * gWindows[windowId].window.height;
- CpuFastFill8(fillValue, gWindows[windowId].tileData, 0x20 * fillSize);
+ CpuFastFill8(fillValue, gWindows[windowId].tileData, 32 * fillSize);
}
#define MOVE_TILES_DOWN(a) \
@@ -599,7 +599,7 @@ static u8 GetNumActiveWindowsOnBg(u8 bgId)
return windowsNum;
}
-static void nullsub_9(void)
+static void DummyWindowBgTilemap8Bit(void)
{
}
@@ -610,15 +610,15 @@ u16 AddWindow8Bit(const struct WindowTemplate *template)
u8* memAddress;
u8 bgLayer;
- for (windowId = 0; windowId < 32; windowId++)
+ for (windowId = 0; windowId < WINDOWS_MAX; windowId++)
{
if (gWindows[windowId].window.bg == 0xFF)
break;
}
if (windowId == WINDOWS_MAX)
- return 0xFF;
+ return WINDOW_NONE;
bgLayer = template->bg;
- if (gUnknown_03002F70[bgLayer] == 0)
+ if (gWindowBgTilemapBuffers[bgLayer] == NULL)
{
u16 attribute = GetBgAttribute(bgLayer, BG_ATTR_METRIC);
if (attribute != 0xFFFF)
@@ -626,22 +626,22 @@ u16 AddWindow8Bit(const struct WindowTemplate *template)
s32 i;
memAddress = Alloc(attribute);
if (memAddress == NULL)
- return 0xFF;
+ return WINDOW_NONE;
for (i = 0; i < attribute; i++) // if we're going to zero out the memory anyway, why not call AllocZeroed?
memAddress[i] = 0;
- gUnknown_03002F70[bgLayer] = memAddress;
+ gWindowBgTilemapBuffers[bgLayer] = memAddress;
SetBgTilemapBuffer(bgLayer, memAddress);
}
}
- memAddress = Alloc((u16)(0x40 * (template->width * template->height)));
+ memAddress = Alloc((u16)(64 * (template->width * template->height)));
if (memAddress == NULL)
{
- if (GetNumActiveWindowsOnBg8Bit(bgLayer) == 0 && gUnknown_03002F70[bgLayer] != nullsub_9)
+ if (GetNumActiveWindowsOnBg8Bit(bgLayer) == 0 && gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap8Bit)
{
- Free(gUnknown_03002F70[bgLayer]);
- gUnknown_03002F70[bgLayer] = NULL;
+ Free(gWindowBgTilemapBuffers[bgLayer]);
+ gWindowBgTilemapBuffers[bgLayer] = NULL;
}
- return 0xFF;
+ return WINDOW_NONE;
}
else
{
@@ -656,7 +656,7 @@ void FillWindowPixelBuffer8Bit(u8 windowId, u8 fillValue)
s32 i;
s32 size;
- size = (u16)(0x40 * (gWindows[windowId].window.width * gWindows[windowId].window.height));
+ size = (u16)(64 * (gWindows[windowId].window.width * gWindows[windowId].window.height));
for (i = 0; i < size; i++)
gWindows[windowId].tileData[i] = fillValue;
}
@@ -691,7 +691,7 @@ void BlitBitmapRectToWindow4BitTo8Bit(u8 windowId, const u8 *pixels, u16 srcX, u
void CopyWindowToVram8Bit(u8 windowId, u8 mode)
{
sWindowPtr = &gWindows[windowId];
- sWindowSize = 0x40 * (sWindowPtr->window.width * sWindowPtr->window.height);
+ sWindowSize = 64 * (sWindowPtr->window.width * sWindowPtr->window.height);
switch (mode)
{
diff --git a/gflib/window.h b/gflib/window.h
index 10e447789..3eac75a28 100644
--- a/gflib/window.h
+++ b/gflib/window.h
@@ -37,6 +37,8 @@ struct WindowTemplate
0, \
}
+#define WINDOW_NONE 0xFF
+
struct Window
{
struct WindowTemplate window;
@@ -70,9 +72,9 @@ void BlitBitmapRectToWindow4BitTo8Bit(u8 windowId, const u8 *pixels, u16 srcX, u
void CopyWindowToVram8Bit(u8 windowId, u8 mode);
extern struct Window gWindows[];
-extern void* gUnknown_03002F70[];
-extern u32 filler_03002F58;
-extern u32 filler_03002F5C;
-extern u32 filler_03002F64;
+extern void* gWindowBgTilemapBuffers[];
+extern u32 gUnusedWindowVar1;
+extern u32 gUnusedWindowVar2;
+extern u32 gUnusedWindowVar3;
#endif // GUARD_WINDOW_H