clean up bg tile alloc code
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
gUnneededFireRedVariable
|
gWindowTileAutoAllocEnabled
|
||||||
|
|||||||
+9
-2
@@ -23,6 +23,13 @@ enum
|
|||||||
BG_CTRL_ATTR_WRAPAROUND = 8,
|
BG_CTRL_ATTR_WRAPAROUND = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum BgTileAllocMode
|
||||||
|
{
|
||||||
|
BG_TILE_FIND_FREE_SPACE,
|
||||||
|
BG_TILE_ALLOC,
|
||||||
|
BG_TILE_FREE,
|
||||||
|
};
|
||||||
|
|
||||||
struct BgTemplate
|
struct BgTemplate
|
||||||
{
|
{
|
||||||
u32 bg:2; // 0x1, 0x2 -> 0x3
|
u32 bg:2; // 0x1, 0x2 -> 0x3
|
||||||
@@ -43,8 +50,8 @@ u16 GetBgControlAttribute(u8 bg, u8 attributeId);
|
|||||||
u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode);
|
u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode);
|
||||||
void SetTextModeAndHideBgs(void);
|
void SetTextModeAndHideBgs(void);
|
||||||
bool8 IsInvalidBg(u8 bg);
|
bool8 IsInvalidBg(u8 bg);
|
||||||
int DummiedOutFireRedLeafGreenTileAllocFunc(int bg, int offset, int count, int mode);
|
int BgTileAllocOp(int bg, int offset, int count, int mode);
|
||||||
void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable);
|
void ResetBgsAndClearDma3BusyFlags(bool32 enableWindowTileAutoAlloc);
|
||||||
void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numTemplates);
|
void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numTemplates);
|
||||||
void InitBgFromTemplate(const struct BgTemplate *template);
|
void InitBgFromTemplate(const struct BgTemplate *template);
|
||||||
void SetBgMode(u8 bgMode);
|
void SetBgMode(u8 bgMode);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ static struct BgConfig2 sGpuBgConfigs2[4];
|
|||||||
static u32 sDmaBusyBitfield[4];
|
static u32 sDmaBusyBitfield[4];
|
||||||
static u8 gpu_tile_allocation_map_bg[0x100];
|
static u8 gpu_tile_allocation_map_bg[0x100];
|
||||||
|
|
||||||
u32 gUnneededFireRedVariable;
|
u32 gWindowTileAutoAllocEnabled;
|
||||||
|
|
||||||
static const struct BgConfig sZeroedBgControlStruct = { 0 };
|
static const struct BgConfig sZeroedBgControlStruct = { 0 };
|
||||||
|
|
||||||
@@ -283,7 +283,7 @@ bool8 IsInvalidBg(u8 bg)
|
|||||||
return FALSE;
|
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 start, end;
|
||||||
int blockSize;
|
int blockSize;
|
||||||
@@ -292,7 +292,7 @@ int DummiedOutFireRedLeafGreenTileAllocFunc(int bg, int offset, int count, int m
|
|||||||
|
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case 0:
|
case BG_TILE_FIND_FREE_SPACE:
|
||||||
start = GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX) * (BG_CHAR_SIZE / TILE_SIZE_4BPP);
|
start = GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX) * (BG_CHAR_SIZE / TILE_SIZE_4BPP);
|
||||||
end = start + 0x400;
|
end = start + 0x400;
|
||||||
if (end > 0x800)
|
if (end > 0x800)
|
||||||
@@ -321,13 +321,13 @@ int DummiedOutFireRedLeafGreenTileAllocFunc(int bg, int offset, int count, int m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
case 1:
|
case BG_TILE_ALLOC:
|
||||||
start = GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX) * (BG_CHAR_SIZE / TILE_SIZE_4BPP) + offset;
|
start = GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX) * (BG_CHAR_SIZE / TILE_SIZE_4BPP) + offset;
|
||||||
end = start + count;
|
end = start + count;
|
||||||
for (i = start; i < end; i++)
|
for (i = start; i < end; i++)
|
||||||
gpu_tile_allocation_map_bg[i / 8] |= 1 << (i % 8);
|
gpu_tile_allocation_map_bg[i / 8] |= 1 << (i % 8);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case BG_TILE_FREE:
|
||||||
start = GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX) * (BG_CHAR_SIZE / TILE_SIZE_4BPP) + offset;
|
start = GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX) * (BG_CHAR_SIZE / TILE_SIZE_4BPP) + offset;
|
||||||
end = start + count;
|
end = start + count;
|
||||||
for (i = start; i < end; i++)
|
for (i = start; i < end; i++)
|
||||||
@@ -338,7 +338,7 @@ int DummiedOutFireRedLeafGreenTileAllocFunc(int bg, int offset, int count, int m
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable)
|
void ResetBgsAndClearDma3BusyFlags(bool32 enableWindowTileAutoAlloc)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
ResetBgs();
|
ResetBgs();
|
||||||
@@ -348,7 +348,7 @@ void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable)
|
|||||||
sDmaBusyBitfield[i] = 0;
|
sDmaBusyBitfield[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gUnneededFireRedVariable = leftoverFireRedLeafGreenVariable;
|
gWindowTileAutoAllocEnabled = enableWindowTileAutoAlloc;
|
||||||
|
|
||||||
for (i = 0; i < 0x100; i++)
|
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));
|
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;
|
return cursor;
|
||||||
|
|||||||
+12
-19
@@ -1,23 +1,16 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
|
#include "bg.h"
|
||||||
|
|
||||||
extern u8 gWindowClearTile;
|
extern u8 gWindowClearTile;
|
||||||
extern void* gWindowBgTilemapBuffers[];
|
extern void* gWindowBgTilemapBuffers[];
|
||||||
extern u32 gUnneededFireRedVariable;
|
extern u32 gWindowTileAutoAllocEnabled;
|
||||||
|
|
||||||
#define WINDOWS_MAX 32
|
#define WINDOWS_MAX 32
|
||||||
|
|
||||||
EWRAM_DATA struct Window gWindows[WINDOWS_MAX] = {0};
|
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 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 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);
|
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)
|
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)
|
if (allocatedBaseBlock == -1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -104,10 +97,10 @@ bool16 InitWindows(const struct WindowTemplate *templates)
|
|||||||
gWindows[i].tileData = allocatedTilemapBuffer;
|
gWindows[i].tileData = allocatedTilemapBuffer;
|
||||||
gWindows[i].window = templates[i];
|
gWindows[i].window = templates[i];
|
||||||
|
|
||||||
if (gUnneededFireRedVariable == 1)
|
if (gWindowTileAutoAllocEnabled == TRUE)
|
||||||
{
|
{
|
||||||
gWindows[i].window.baseBlock = allocatedBaseBlock;
|
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;
|
bgLayer = template->priority;
|
||||||
allocatedBaseBlock = 0;
|
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)
|
if (allocatedBaseBlock == -1)
|
||||||
return 0xFF;
|
return 0xFF;
|
||||||
@@ -178,10 +171,10 @@ u16 AddWindow(const struct WindowTemplate *template)
|
|||||||
gWindows[win].tileData = allocatedTilemapBuffer;
|
gWindows[win].tileData = allocatedTilemapBuffer;
|
||||||
gWindows[win].window = *template;
|
gWindows[win].window = *template;
|
||||||
|
|
||||||
if (gUnneededFireRedVariable == 1)
|
if (gWindowTileAutoAllocEnabled == TRUE)
|
||||||
{
|
{
|
||||||
gWindows[win].window.baseBlock = allocatedBaseBlock;
|
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;
|
return win;
|
||||||
@@ -191,9 +184,9 @@ void RemoveWindow(u8 windowId)
|
|||||||
{
|
{
|
||||||
u8 bgLayer = gWindows[windowId].window.priority;
|
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;
|
gWindows[windowId].window = sDummyWindowTemplate;
|
||||||
|
|||||||
Reference in New Issue
Block a user