summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsceptillion <33798691+sceptillion@users.noreply.github.com>2017-12-18 15:23:55 -0800
committersceptillion <33798691+sceptillion@users.noreply.github.com>2017-12-18 15:23:55 -0800
commitcbeb32fae45e58cabd8c97104033b6d672602ffb (patch)
tree13a197524567927e2f32200e7bde34e69b9b759c /src
parent3b992d3ad3376d3a37d9afbf60de91aecac5d32b (diff)
clean up bg tile alloc code
Diffstat (limited to 'src')
-rw-r--r--src/bg.c18
-rw-r--r--src/window.c31
2 files changed, 21 insertions, 28 deletions
diff --git a/src/bg.c b/src/bg.c
index b7da03dc6..ce9174fec 100644
--- a/src/bg.c
+++ b/src/bg.c
@@ -42,7 +42,7 @@ static struct BgConfig2 sGpuBgConfigs2[4];
static u32 sDmaBusyBitfield[4];
static u8 gpu_tile_allocation_map_bg[0x100];
-u32 gUnneededFireRedVariable;
+u32 gWindowTileAutoAllocEnabled;
static const struct BgConfig sZeroedBgControlStruct = { 0 };
@@ -283,7 +283,7 @@ bool8 IsInvalidBg(u8 bg)
return FALSE;
}
-int DummiedOutFireRedLeafGreenTileAllocFunc(int bg, int offset, int count, int mode)
+int BgTileAllocOp(int bg, int offset, int count, int mode)
{
int start, end;
int blockSize;
@@ -292,7 +292,7 @@ int DummiedOutFireRedLeafGreenTileAllocFunc(int bg, int offset, int count, int m
switch (mode)
{
- case 0:
+ case BG_TILE_FIND_FREE_SPACE:
start = GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX) * (BG_CHAR_SIZE / TILE_SIZE_4BPP);
end = start + 0x400;
if (end > 0x800)
@@ -321,13 +321,13 @@ int DummiedOutFireRedLeafGreenTileAllocFunc(int bg, int offset, int count, int m
}
}
return -1;
- case 1:
+ case BG_TILE_ALLOC:
start = GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX) * (BG_CHAR_SIZE / TILE_SIZE_4BPP) + offset;
end = start + count;
for (i = start; i < end; i++)
gpu_tile_allocation_map_bg[i / 8] |= 1 << (i % 8);
break;
- case 2:
+ case BG_TILE_FREE:
start = GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX) * (BG_CHAR_SIZE / TILE_SIZE_4BPP) + offset;
end = start + count;
for (i = start; i < end; i++)
@@ -338,7 +338,7 @@ int DummiedOutFireRedLeafGreenTileAllocFunc(int bg, int offset, int count, int m
return 0;
}
-void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable)
+void ResetBgsAndClearDma3BusyFlags(bool32 enableWindowTileAutoAlloc)
{
int i;
ResetBgs();
@@ -348,7 +348,7 @@ void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable)
sDmaBusyBitfield[i] = 0;
}
- gUnneededFireRedVariable = leftoverFireRedLeafGreenVariable;
+ gWindowTileAutoAllocEnabled = enableWindowTileAutoAlloc;
for (i = 0; i < 0x100; i++)
{
@@ -556,9 +556,9 @@ u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset)
sDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
- if (gUnneededFireRedVariable == 1)
+ if (gWindowTileAutoAllocEnabled == TRUE)
{
- DummiedOutFireRedLeafGreenTileAllocFunc(bg, tileOffset / 0x20, size / 0x20, 1);
+ BgTileAllocOp(bg, tileOffset / 0x20, size / 0x20, BG_TILE_ALLOC);
}
return cursor;
diff --git a/src/window.c b/src/window.c
index 7666fc91f..62879bd6c 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1,23 +1,16 @@
#include "global.h"
#include "window.h"
#include "malloc.h"
+#include "bg.h"
extern u8 gWindowClearTile;
extern void* gWindowBgTilemapBuffers[];
-extern u32 gUnneededFireRedVariable;
+extern u32 gWindowTileAutoAllocEnabled;
#define WINDOWS_MAX 32
EWRAM_DATA struct Window gWindows[WINDOWS_MAX] = {0};
-extern void* GetBgTilemapBuffer(u8 bg);
-extern int DummiedOutFireRedLeafGreenTileAllocFunc(int, int, int, int);
-extern u16 GetBgAttribute(u8 bg, u8 attributeId);
-extern void SetBgTilemapBuffer(u8 bg, void *tilemap);
-extern void CopyBgTilemapBufferToVram(u8 bg);
-extern u8 LoadBgTiles(u8 bg, void *src, u16 size, u16 destOffset);
-extern void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 width, u8 height, u8 paletteSlot, u16 tileNumDelta);
-extern void FillBgTilemapBufferRect(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height, u8 palette);
extern void BlitBitmapRect4Bit(struct Bitmap *src, struct Bitmap *dest, u16 srcX, u16 srcY, u16 destX, u16 destY, u16 width, u16 height, u8 colorKey);
extern void BlitBitmapRect4BitTo8Bit(struct Bitmap *src, struct Bitmap *dest, u16 srcX, u16 srcY, u16 destX, u16 destY, u16 width, u16 height, u8 colorKey, u8 paletteNum);
extern void FillBitmapRect4Bit(struct Bitmap *surface, u16 x, u16 y, u16 width, u16 height, u8 fillValue);
@@ -59,9 +52,9 @@ bool16 InitWindows(const struct WindowTemplate *templates)
for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].priority; bgLayer != 0xFF && i < 0x20; ++i, bgLayer = templates[i].priority)
{
- if (gUnneededFireRedVariable == 1)
+ if (gWindowTileAutoAllocEnabled == TRUE)
{
- allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, templates[i].width * templates[i].height, 0);
+ allocatedBaseBlock = BgTileAllocOp(bgLayer, 0, templates[i].width * templates[i].height, BG_TILE_FIND_FREE_SPACE);
if (allocatedBaseBlock == -1)
return FALSE;
}
@@ -104,10 +97,10 @@ bool16 InitWindows(const struct WindowTemplate *templates)
gWindows[i].tileData = allocatedTilemapBuffer;
gWindows[i].window = templates[i];
- if (gUnneededFireRedVariable == 1)
+ if (gWindowTileAutoAllocEnabled == TRUE)
{
gWindows[i].window.baseBlock = allocatedBaseBlock;
- DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, allocatedBaseBlock, templates[i].width * templates[i].height, 1);
+ BgTileAllocOp(bgLayer, allocatedBaseBlock, templates[i].width * templates[i].height, BG_TILE_ALLOC);
}
}
@@ -136,9 +129,9 @@ u16 AddWindow(const struct WindowTemplate *template)
bgLayer = template->priority;
allocatedBaseBlock = 0;
- if (gUnneededFireRedVariable == 1)
+ if (gWindowTileAutoAllocEnabled == TRUE)
{
- allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0);
+ allocatedBaseBlock = BgTileAllocOp(bgLayer, 0, template->width * template->height, BG_TILE_FIND_FREE_SPACE);
if (allocatedBaseBlock == -1)
return 0xFF;
@@ -178,10 +171,10 @@ u16 AddWindow(const struct WindowTemplate *template)
gWindows[win].tileData = allocatedTilemapBuffer;
gWindows[win].window = *template;
- if (gUnneededFireRedVariable == 1)
+ if (gWindowTileAutoAllocEnabled == TRUE)
{
gWindows[win].window.baseBlock = allocatedBaseBlock;
- DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, allocatedBaseBlock, gWindows[win].window.width * gWindows[win].window.height, 1);
+ BgTileAllocOp(bgLayer, allocatedBaseBlock, gWindows[win].window.width * gWindows[win].window.height, BG_TILE_ALLOC);
}
return win;
@@ -191,9 +184,9 @@ void RemoveWindow(u8 windowId)
{
u8 bgLayer = gWindows[windowId].window.priority;
- if (gUnneededFireRedVariable == 1)
+ if (gWindowTileAutoAllocEnabled == TRUE)
{
- DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, gWindows[windowId].window.baseBlock, gWindows[windowId].window.width * gWindows[windowId].window.height, 2);
+ BgTileAllocOp(bgLayer, gWindows[windowId].window.baseBlock, gWindows[windowId].window.width * gWindows[windowId].window.height, BG_TILE_FREE);
}
gWindows[windowId].window = sDummyWindowTemplate;