summaryrefslogtreecommitdiff
path: root/gflib
diff options
context:
space:
mode:
Diffstat (limited to 'gflib')
-rw-r--r--gflib/bg.c53
-rw-r--r--gflib/bg.h9
-rw-r--r--gflib/string_util.c6
-rw-r--r--gflib/string_util.h2
-rw-r--r--gflib/text.h4
-rw-r--r--gflib/window.c32
6 files changed, 57 insertions, 49 deletions
diff --git a/gflib/bg.c b/gflib/bg.c
index ec7c2113b..283a87ce0 100644
--- a/gflib/bg.c
+++ b/gflib/bg.c
@@ -42,10 +42,12 @@ static struct BgControl sGpuBgConfigs;
static struct BgConfig2 sGpuBgConfigs2[NUM_BACKGROUNDS];
static u32 sDmaBusyBitfield[NUM_BACKGROUNDS];
-u32 gUnneededFireRedVariable;
+u32 gWindowTileAutoAllocEnabled;
static const struct BgConfig sZeroedBgControlStruct = { 0 };
+static u32 GetBgType(u8 bg);
+
void ResetBgs(void)
{
ResetBgControlStructs();
@@ -288,7 +290,8 @@ bool8 IsInvalidBg(u8 bg)
return FALSE;
}
-int DummiedOutFireRedLeafGreenTileAllocFunc(int a1, int a2, int a3, int a4)
+// From FRLG. Dummied out.
+int BgTileAllocOp(int bg, int offset, int count, int mode)
{
return 0;
}
@@ -303,7 +306,7 @@ void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable)
sDmaBusyBitfield[i] = 0;
}
- gUnneededFireRedVariable = leftoverFireRedLeafGreenVariable;
+ gWindowTileAutoAllocEnabled = leftoverFireRedLeafGreenVariable;
}
void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numTemplates)
@@ -392,10 +395,8 @@ u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset)
sDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
- if (gUnneededFireRedVariable == 1)
- {
- DummiedOutFireRedLeafGreenTileAllocFunc(bg, tileOffset / 0x20, size / 0x20, 1);
- }
+ if (gWindowTileAutoAllocEnabled == TRUE)
+ BgTileAllocOp(bg, tileOffset / 0x20, size / 0x20, 1);
return cursor;
}
@@ -523,9 +524,9 @@ u16 GetBgAttribute(u8 bg, u8 attributeId)
case BG_ATTR_METRIC:
switch (GetBgType(bg))
{
- case 0:
+ case BG_TYPE_NORMAL:
return GetBgMetricTextMode(bg, 0) * 0x800;
- case 1:
+ case BG_TYPE_AFFINE:
return GetBgMetricAffineMode(bg, 0) * 0x100;
default:
return 0;
@@ -891,10 +892,10 @@ void CopyBgTilemapBufferToVram(u8 bg)
{
switch (GetBgType(bg))
{
- case 0:
+ case BG_TYPE_NORMAL:
sizeToLoad = GetBgMetricTextMode(bg, 0) * 0x800;
break;
- case 1:
+ case BG_TYPE_AFFINE:
sizeToLoad = GetBgMetricAffineMode(bg, 0) * 0x100;
break;
default:
@@ -915,7 +916,7 @@ void CopyToBgTilemapBufferRect(u8 bg, const void* src, u8 destX, u8 destY, u8 wi
{
switch (GetBgType(bg))
{
- case 0:
+ case BG_TYPE_NORMAL:
{
const u16 * srcCopy = src;
for (destY16 = destY; destY16 < (destY + height); destY16++)
@@ -927,7 +928,7 @@ void CopyToBgTilemapBufferRect(u8 bg, const void* src, u8 destX, u8 destY, u8 wi
}
break;
}
- case 1:
+ case BG_TYPE_AFFINE:
{
const u8 * srcCopy = src;
mode = GetBgMetricAffineMode(bg, 0x1);
@@ -963,7 +964,7 @@ void CopyRectToBgTilemapBufferRect(u8 bg, const void *src, u8 srcX, u8 srcY, u8
screenHeight = GetBgMetricTextMode(bg, 0x2) * 0x20;
switch (GetBgType(bg))
{
- case 0:
+ case BG_TYPE_NORMAL:
srcPtr = src + ((srcY * srcWidth) + srcX) * 2;
for (i = destX; i < (destX + rectWidth); i++)
{
@@ -976,7 +977,7 @@ void CopyRectToBgTilemapBufferRect(u8 bg, const void *src, u8 srcX, u8 srcY, u8
srcPtr += (srcWidth - destY) * 2;
}
break;
- case 1:
+ case BG_TYPE_AFFINE:
srcPtr = src + ((srcY * srcWidth) + srcX);
var = GetBgMetricAffineMode(bg, 0x1);
for (i = destX; i < (destX + rectWidth); i++)
@@ -1003,7 +1004,7 @@ void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width,
{
switch (GetBgType(bg))
{
- case 0:
+ case BG_TYPE_NORMAL:
for (y16 = y; y16 < (y + height); y16++)
{
for (x16 = x; x16 < (x + width); x16++)
@@ -1012,7 +1013,7 @@ void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width,
}
}
break;
- case 1:
+ case BG_TYPE_AFFINE:
mode = GetBgMetricAffineMode(bg, 0x1);
for (y16 = y; y16 < (y + height); y16++)
{
@@ -1046,7 +1047,7 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt
mode2 = GetBgMetricTextMode(bg, 0x2) * 0x20;
switch (GetBgType(bg))
{
- case 0:
+ case BG_TYPE_NORMAL:
for (y16 = y; y16 < (y + height); y16++)
{
for (x16 = x; x16 < (x + width); x16++)
@@ -1056,7 +1057,7 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt
}
}
break;
- case 1:
+ case BG_TYPE_AFFINE:
mode3 = GetBgMetricAffineMode(bg, 0x1);
for (y16 = y; y16 < (y + height); y16++)
{
@@ -1190,7 +1191,7 @@ void CopyTileMapEntry(const u16 *src, u16 *dest, s32 palette1, s32 tileOffset, s
*dest = var;
}
-u32 GetBgType(u8 bg)
+static u32 GetBgType(u8 bg)
{
u8 mode = GetBgMode();
@@ -1202,31 +1203,31 @@ u32 GetBgType(u8 bg)
{
case 0:
case 1:
- return 0;
+ return BG_TYPE_NORMAL;
}
break;
case 2:
switch (mode)
{
case 0:
- return 0;
+ return BG_TYPE_NORMAL;
case 1:
case 2:
- return 1;
+ return BG_TYPE_AFFINE;
}
break;
case 3:
switch (mode)
{
case 0:
- return 0;
+ return BG_TYPE_NORMAL;
case 2:
- return 1;
+ return BG_TYPE_AFFINE;
}
break;
}
- return 0xFFFF;
+ return BG_TYPE_NONE;
}
bool32 IsInvalidBg32(u8 bg)
diff --git a/gflib/bg.h b/gflib/bg.h
index 58fd1282c..60327eab3 100644
--- a/gflib/bg.h
+++ b/gflib/bg.h
@@ -25,6 +25,12 @@ enum
BG_ATTR_BASETILE,
};
+enum {
+ BG_TYPE_NORMAL,
+ BG_TYPE_AFFINE,
+ BG_TYPE_NONE = 0xFFFF
+};
+
struct BgTemplate
{
u16 bg:2; // 0x1, 0x2 -> 0x3
@@ -43,7 +49,7 @@ void Unused_ResetBgControlStruct(u8 bg);
u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode);
void SetTextModeAndHideBgs(void);
bool8 IsInvalidBg(u8 bg);
-int DummiedOutFireRedLeafGreenTileAllocFunc(int a1, int a2, int a3, int a4);
+int BgTileAllocOp(int bg, int offset, int count, int mode);
void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable);
void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numTemplates);
void InitBgFromTemplate(const struct BgTemplate *template);
@@ -78,7 +84,6 @@ u16 GetBgMetricTextMode(u8 bg, u8 whichMetric);
u32 GetBgMetricAffineMode(u8 bg, u8 whichMetric);
u32 GetTileMapIndexFromCoords(s32 x, s32 y, s32 screenSize, u32 screenWidth, u32 screenHeight);
void CopyTileMapEntry(const u16 *src, u16 *dest, s32 palette1, s32 tileOffset, s32 palette2);
-u32 GetBgType(u8 bg);
bool32 IsInvalidBg32(u8 bg);
bool32 IsTileMapOutsideWram(u8 bg);
diff --git a/gflib/string_util.c b/gflib/string_util.c
index addc7e4f2..b7485184a 100644
--- a/gflib/string_util.c
+++ b/gflib/string_util.c
@@ -630,7 +630,7 @@ bool32 IsStringJapanese(u8 *str)
{
while (*str != EOS)
{
- if (*str < CHAR_0)
+ if (*str <= JAPANESE_CHAR_END)
if (*str != CHAR_SPACE)
return TRUE;
str++;
@@ -639,13 +639,13 @@ bool32 IsStringJapanese(u8 *str)
return FALSE;
}
-bool32 sub_800924C(u8 *str, s32 n)
+bool32 IsStringNJapanese(u8 *str, s32 n)
{
s32 i;
for (i = 0; *str != EOS && i < n; i++)
{
- if (*str < CHAR_0)
+ if (*str <= JAPANESE_CHAR_END)
if (*str != CHAR_SPACE)
return TRUE;
str++;
diff --git a/gflib/string_util.h b/gflib/string_util.h
index 229193d52..7f3b64add 100644
--- a/gflib/string_util.h
+++ b/gflib/string_util.h
@@ -37,7 +37,7 @@ u8 *StringCopyN_Multibyte(u8 *dest, u8 *src, u32 n);
u32 StringLength_Multibyte(const u8 *str);
u8 *WriteColorChangeControlCode(u8 *dest, u32 colorType, u8 color);
bool32 IsStringJapanese(u8 *str);
-bool32 sub_800924C(u8 *str, s32 n);
+bool32 IsStringNJapanese(u8 *str, s32 n);
u8 GetExtCtrlCodeLength(u8 code);
s32 StringCompareWithoutExtCtrlCodes(const u8 *str1, const u8 *str2);
void ConvertInternationalString(u8 *s, u8 language);
diff --git a/gflib/text.h b/gflib/text.h
index f660eb8d1..a08d0a0ff 100644
--- a/gflib/text.h
+++ b/gflib/text.h
@@ -263,6 +263,10 @@
#define PLACEHOLDER_ID_KYOGRE 0xC
#define PLACEHOLDER_ID_GROUDON 0xD
+// Hiragana from 0x1-0x50, Katakana from 0x51-0xA0.
+// This excludes Japanese punctuation, which end at 0xB0
+#define JAPANESE_CHAR_END 0xA0
+
// battle placeholders are located in battle_message.h
#define NUM_TEXT_PRINTERS 32
diff --git a/gflib/window.c b/gflib/window.c
index b03b513da..c7b8c8917 100644
--- a/gflib/window.c
+++ b/gflib/window.c
@@ -10,7 +10,7 @@ u32 gUnusedWindowVar2;
u8 gTransparentTileNumber;
u32 gUnusedWindowVar3;
void *gWindowBgTilemapBuffers[NUM_BACKGROUNDS];
-extern u32 gUnneededFireRedVariable;
+extern u32 gWindowTileAutoAllocEnabled;
#define WINDOWS_MAX 32
@@ -55,9 +55,9 @@ bool16 InitWindows(const struct WindowTemplate *templates)
for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].bg; bgLayer != 0xFF && i < WINDOWS_MAX; ++i, bgLayer = templates[i].bg)
{
- 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, 0);
if (allocatedBaseBlock == -1)
return FALSE;
}
@@ -100,10 +100,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, 1);
}
}
@@ -132,9 +132,9 @@ u16 AddWindow(const struct WindowTemplate *template)
bgLayer = template->bg;
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, 0);
if (allocatedBaseBlock == -1)
return WINDOW_NONE;
@@ -174,10 +174,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, 1);
}
return win;
@@ -201,9 +201,9 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template)
bgLayer = template->bg;
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, 0);
if (allocatedBaseBlock == -1)
return WINDOW_NONE;
@@ -211,10 +211,10 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template)
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, 1);
}
return win;
@@ -224,10 +224,8 @@ void RemoveWindow(u8 windowId)
{
u8 bgLayer = gWindows[windowId].window.bg;
- if (gUnneededFireRedVariable == 1)
- {
- DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, gWindows[windowId].window.baseBlock, gWindows[windowId].window.width * gWindows[windowId].window.height, 2);
- }
+ if (gWindowTileAutoAllocEnabled == TRUE)
+ BgTileAllocOp(bgLayer, gWindows[windowId].window.baseBlock, gWindows[windowId].window.width * gWindows[windowId].window.height, 2);
gWindows[windowId].window = sDummyWindowTemplate;