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/sprite.c26
-rw-r--r--gflib/sprite.h2
-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
8 files changed, 71 insertions, 63 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/sprite.c b/gflib/sprite.c
index 43432cf3a..9629fc31b 100644
--- a/gflib/sprite.c
+++ b/gflib/sprite.c
@@ -210,7 +210,7 @@ const union AffineAnimCmd * const gDummySpriteAffineAnimTable[] = { &sDummyAffin
const struct SpriteTemplate gDummySpriteTemplate =
{
.tileTag = 0,
- .paletteTag = 0xFFFF,
+ .paletteTag = TAG_NONE,
.oam = &gDummyOamData,
.anims = gDummySpriteAnimTable,
.images = NULL,
@@ -588,7 +588,7 @@ u8 CreateSpriteAt(u8 index, const struct SpriteTemplate *template, s16 x, s16 y,
CalcCenterToCornerVec(sprite, sprite->oam.shape, sprite->oam.size, sprite->oam.affineMode);
- if (template->tileTag == 0xFFFF)
+ if (template->tileTag == TAG_NONE)
{
s16 tileNum;
sprite->images = template->images;
@@ -611,7 +611,7 @@ u8 CreateSpriteAt(u8 index, const struct SpriteTemplate *template, s16 x, s16 y,
if (sprite->oam.affineMode & ST_OAM_AFFINE_ON_MASK)
InitSpriteAffineAnim(sprite);
- if (template->paletteTag != 0xFFFF)
+ if (template->paletteTag != TAG_NONE)
sprite->oam.paletteNum = IndexOfSpritePaletteTag(template->paletteTag);
return index;
@@ -893,7 +893,7 @@ void ResetAllSprites(void)
// UB: template pointer may point to freed temporary storage
void FreeSpriteTiles(struct Sprite *sprite)
{
- if (sprite->template->tileTag != 0xFFFF)
+ if (sprite->template->tileTag != TAG_NONE)
FreeSpriteTilesByTag(sprite->template->tileTag);
}
@@ -1540,7 +1540,7 @@ void FreeSpriteTilesByTag(u16 tag)
for (i = start; i < start + count; i++)
FREE_SPRITE_TILE(i);
- sSpriteTileRangeTags[index] = 0xFFFF;
+ sSpriteTileRangeTags[index] = TAG_NONE;
}
}
@@ -1550,7 +1550,7 @@ void FreeSpriteTileRanges(void)
for (i = 0; i < MAX_SPRITES; i++)
{
- sSpriteTileRangeTags[i] = 0xFFFF;
+ sSpriteTileRangeTags[i] = TAG_NONE;
SET_SPRITE_TILE_RANGE(i, 0, 0);
}
}
@@ -1580,16 +1580,16 @@ u16 GetSpriteTileTagByTileStart(u16 start)
for (i = 0; i < MAX_SPRITES; i++)
{
- if (sSpriteTileRangeTags[i] != 0xFFFF && sSpriteTileRanges[i * 2] == start)
+ if (sSpriteTileRangeTags[i] != TAG_NONE && sSpriteTileRanges[i * 2] == start)
return sSpriteTileRangeTags[i];
}
- return 0xFFFF;
+ return TAG_NONE;
}
void AllocSpriteTileRange(u16 tag, u16 start, u16 count)
{
- u8 freeIndex = IndexOfSpriteTileTag(0xFFFF);
+ u8 freeIndex = IndexOfSpriteTileTag(TAG_NONE);
sSpriteTileRangeTags[freeIndex] = tag;
SET_SPRITE_TILE_RANGE(freeIndex, start, count);
}
@@ -1599,7 +1599,7 @@ void FreeAllSpritePalettes(void)
u8 i;
gReservedSpritePaletteCount = 0;
for (i = 0; i < 16; i++)
- sSpritePaletteTags[i] = 0xFFFF;
+ sSpritePaletteTags[i] = TAG_NONE;
}
u8 LoadSpritePalette(const struct SpritePalette *palette)
@@ -1609,7 +1609,7 @@ u8 LoadSpritePalette(const struct SpritePalette *palette)
if (index != 0xFF)
return index;
- index = IndexOfSpritePaletteTag(0xFFFF);
+ index = IndexOfSpritePaletteTag(TAG_NONE);
if (index == 0xFF)
{
@@ -1638,7 +1638,7 @@ void DoLoadSpritePalette(const u16 *src, u16 paletteOffset)
u8 AllocSpritePalette(u16 tag)
{
- u8 index = IndexOfSpritePaletteTag(0xFFFF);
+ u8 index = IndexOfSpritePaletteTag(TAG_NONE);
if (index == 0xFF)
{
return 0xFF;
@@ -1669,7 +1669,7 @@ void FreeSpritePaletteByTag(u16 tag)
{
u8 index = IndexOfSpritePaletteTag(tag);
if (index != 0xFF)
- sSpritePaletteTags[index] = 0xFFFF;
+ sSpritePaletteTags[index] = TAG_NONE;
}
void SetSubspriteTables(struct Sprite *sprite, const struct SubspriteTable *subspriteTables)
diff --git a/gflib/sprite.h b/gflib/sprite.h
index 02bc0748b..89299d43e 100644
--- a/gflib/sprite.h
+++ b/gflib/sprite.h
@@ -3,7 +3,7 @@
#define MAX_SPRITES 64
#define SPRITE_NONE 0xFF
-#define SPRITE_INVALID_TAG 0xFFFF
+#define TAG_NONE 0xFFFF
struct SpriteSheet
{
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..f71cd557f 100644
--- a/gflib/text.h
+++ b/gflib/text.h
@@ -265,6 +265,10 @@
// battle placeholders are located in battle_message.h
+// Hiragana from 0x1-0x50, Katakana from 0x51-0xA0.
+// This excludes Japanese punctuation, which end at 0xB0
+#define JAPANESE_CHAR_END 0xA0
+
#define NUM_TEXT_PRINTERS 32
#define TEXT_SPEED_FF 0xFF
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;