summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYamaArashi <shadow962@live.com>2016-06-11 13:23:39 -0700
committerYamaArashi <shadow962@live.com>2016-06-11 13:23:39 -0700
commitabf89edae8dc5cd52428144288faef077999a910 (patch)
tree765d7f718367a6d98b5c988f483e01b93c758c57
parent5dde2ecaafbb17a78ccd6ae4807da0ad184bb2ff (diff)
fix rsfont
-rw-r--r--build_tools.sh2
-rw-r--r--include/text.h100
-rw-r--r--src/text.c73
-rw-r--r--tools/rsfont/font.c26
4 files changed, 123 insertions, 78 deletions
diff --git a/build_tools.sh b/build_tools.sh
index b5e28697f..7d99d5d90 100644
--- a/build_tools.sh
+++ b/build_tools.sh
@@ -2,3 +2,5 @@
make -C tools/gbagfx
make -C tools/scaninc
make -C tools/preproc
+make -C tools/bin2c
+make -C tools/rsfont
diff --git a/include/text.h b/include/text.h
index 030d51188..192190490 100644
--- a/include/text.h
+++ b/include/text.h
@@ -11,6 +11,61 @@
#define PLACEHOLDER_BEGIN 0xFD // string placeholder
#define EOS 0xFF // end of string
+struct WindowConfig
+{
+ u8 bgNum;
+ u8 charBaseBlock;
+ u8 screenBaseBlock;
+ u8 priority;
+ u8 paletteNum;
+ u8 foregroundColor;
+ u8 backgroundColor;
+ u8 shadowColor;
+ u8 fontNum;
+ u8 textMode;
+ u8 spacing;
+ u8 tilemapLeft;
+ u8 tilemapTop;
+ u8 width;
+ u8 height;
+ u8 *tileData;
+ u16 *tilemap;
+ u32 maybeUnused;
+};
+
+struct Window
+{
+ u8 textMode;
+ u8 fontNum;
+ u8 charset;
+ u8 foregroundColor;
+ u8 backgroundColor;
+ u8 shadowColor;
+ u8 paletteNum;
+ u8 tilemapLeft;
+ u8 tilemapTop;
+ u8 width;
+ u8 height;
+ u8 win_field_B;
+ u8 win_field_C;
+ u8 delayCounter;
+ u8 spacing;
+ u8 win_field_F;
+ u8 cursorX;
+ u8 cursorY;
+ u8 left;
+ u16 top;
+ u16 state;
+ u16 downArrowCounter;
+ u16 tileDataStartOffset;
+ u16 tileDataOffset;
+ u16 textIndex;
+ u8 *text;
+ u8 *tileData;
+ u16 *tilemap;
+ struct WindowConfig *config;
+};
+
extern vu16 *const gBGControlRegs[];
extern vu16 *const gBGHOffsetRegs[];
extern vu16 *const gBGVOffsetRegs[];
@@ -75,7 +130,52 @@ extern const struct WindowConfig gWindowConfig_81E725C;
extern const struct WindowConfig gWindowConfig_81E7278;
extern const struct WindowConfig gWindowConfig_81E7294;
+void LoadFontDefaultPalette(const struct WindowConfig *winConfig);
+void SetUpWindowConfig(const struct WindowConfig *winConfig);
+u16 InitWindowTileData(struct Window *win, u16 startOffset);
+u32 MultistepInitWindowTileData(struct Window *win, u16 startOffset);
+bool32 MultistepLoadFont(void);
+void InitWindowFromConfig(struct Window *win, struct WindowConfig *winConfig);
+void InitWindow(struct Window *win, u8 *text, u16 tileDataStartOffset, u8 left, u8 top);
+void sub_8002E4C(struct Window *win, u8 *text, u16 tileDataStartOffset, u8 left, u16 top, u32 a6);
+void sub_8002E90(struct Window *win, u8 *text);
+void sub_8002EB0(struct Window *win, u8 *text, u16 tileDataStartOffset, u8 left, u8 top);
+u8 sub_8002F44(struct Window *win);
+u8 sub_8003418(struct Window *win);
+u8 sub_8003460(struct Window *win, u8 *text, u16 tileDataStartOffset, u8 left, u8 top);
+u8 sub_8003490(struct Window *win, u8 c, u16 tileDataStartOffset, u8 left, u8 top);
+void sub_80034D4(u8 *tileData, u8 *text);
+u8 sub_80034EC(u8 *str);
+u8 *sub_8003504(u8 *dest, s32 value, u8 alignAmount, u8 alignType);
+u8 *sub_8003558(u8 *dest, u8 *src, u8 alignAmount, u8 alignType);
+u8 sub_80035AC(struct Window *win);
+u8 sub_800374C(struct Window *win);
+u8 sub_8003778(struct Window *win);
+u8 sub_80037A0(struct Window *win);
+u8 sub_80037C8(struct Window *win, u8 lineLength);
+void ClearWindowTextLines(struct Window *win);
+u16 GetWindowTilemapEntry(struct Window *win, u8 x, u8 y);
+void DrawWindowRect(struct Window *win, u16 tilemapEntry, u8 left, u8 top, u8 right, u8 bottom);
+void DrawWindowRect_DefaultPalette(struct Window *win, u16 tileNum, u8 left, u8 top, u8 right, u8 bottom);
+void FillWindowRect(struct Window *win, u16 tilemapEntry, u8 left, u8 top, u8 right, u8 bottom);
+void FillWindowRect_DefaultPalette(struct Window *win, u16 tileNum, u8 left, u8 top, u8 right, u8 bottom);
+void ZeroFillWindowRect(struct Window *win, u8 left, u8 top, u8 right, u8 bottom);
+void FillWindowRectWithBlankTile(struct Window *win, u8 left, u8 top, u8 right, u8 bottom);
u8 GetExtCtrlCodeLength(u8 code);
+u8 *AlignInt1(struct Window *win, u8 *dest, s32 value, u8 alignAmount, u8 alignType);
+u8 *AlignInt2(struct Window *win, u8 *dest, s32 value, u8 alignAmount, u8 alignType);
+u8 *AlignString(struct Window *win, u8 *dest, u8 *src, u8 alignAmount, u8 alignType);
+u8 GetStringWidth(struct Window *win, u8 *s);
+u8 sub_8004D04(struct Window *win, u8 *text, u16 tileDataStartOffset, u8 left, u16 top, u32 a6);
+u8 sub_8004D38(struct Window *win, u8 *text, u16 tileDataStartOffset, u8 left, u8 top);
+u8 sub_8004DB0(struct Window *win, u8 *text, u16 tileDataStartOffset, u8 left, u8 top, u16 a6);
+u8 sub_8004E24(struct Window *win);
+void sub_8004E28(struct Window *win, u8 *foreground, u8 *background, u8 *shadow);
+void sub_8004E3C(struct WindowConfig *winConfig, u8 *tileData, u8 *text);
+u8 GetStringWidthGivenWindowConfig(struct WindowConfig *winConfig, u8 *s);
void ConvertInternationalString(u8 *s, u8 language);
+void SkipExtCtrlCodes(u8 *str);
+s32 StringCompareWithoutExtCtrlCodes(u8 *str1, u8 *str2);
+u8 sub_8004FD0(struct Window *win, u8 *dest, u8 *src, u16 tileDataStartOffset, u8 left, u16 top, u8 a7, u32 a8);
#endif // GUARD_TEXT_H
diff --git a/src/text.c b/src/text.c
index 173a544ef..624f2fd8e 100644
--- a/src/text.c
+++ b/src/text.c
@@ -26,28 +26,6 @@ enum
WIN_STATE_WAIT_SOUND,
};
-struct WindowConfig
-{
- u8 bgNum;
- u8 charBaseBlock;
- u8 screenBaseBlock;
- u8 priority;
- u8 paletteNum;
- u8 foregroundColor;
- u8 backgroundColor;
- u8 shadowColor;
- u8 fontNum;
- u8 textMode;
- u8 spacing;
- u8 tilemapLeft;
- u8 tilemapTop;
- u8 width;
- u8 height;
- u8 *tileData;
- u16 *tilemap;
- u32 maybeUnused;
-};
-
struct Font
{
u32 type;
@@ -56,39 +34,6 @@ struct Font
u16 lowerTileOffset;
};
-struct Window
-{
- u8 textMode;
- u8 fontNum;
- u8 charset;
- u8 foregroundColor;
- u8 backgroundColor;
- u8 shadowColor;
- u8 paletteNum;
- u8 tilemapLeft;
- u8 tilemapTop;
- u8 width;
- u8 height;
- u8 win_field_B;
- u8 win_field_C;
- u8 delayCounter;
- u8 spacing;
- u8 win_field_F;
- u8 cursorX;
- u8 cursorY;
- u8 left;
- u16 top;
- u16 state;
- u16 downArrowCounter;
- u16 tileDataStartOffset;
- u16 tileDataOffset;
- u16 textIndex;
- u8 *text;
- u8 *tileData;
- u16 *tilemap;
- struct WindowConfig *config;
-};
-
struct GlyphBuffer
{
// 0-7 left tile
@@ -1782,7 +1727,7 @@ const struct WindowConfig gWindowConfig_81E7294 =
NULL, // tilemap
};
-static void UpdateBGRegs(struct WindowConfig *winConfig)
+static void UpdateBGRegs(const struct WindowConfig *winConfig)
{
u8 bgNum = winConfig->bgNum;
*gBGHOffsetRegs[bgNum] = 0;
@@ -1790,7 +1735,7 @@ static void UpdateBGRegs(struct WindowConfig *winConfig)
*gBGControlRegs[bgNum] = winConfig->priority | (winConfig->screenBaseBlock << 8) | (winConfig->charBaseBlock << 2);
}
-static void ClearBGMem(struct WindowConfig *winConfig)
+static void ClearBGMem(const struct WindowConfig *winConfig)
{
CpuFastFill(0, winConfig->tileData, 32);
@@ -1798,12 +1743,12 @@ static void ClearBGMem(struct WindowConfig *winConfig)
CpuFastFill(0, winConfig->tilemap, 0x800);
}
-void LoadFontDefaultPalette(struct WindowConfig *winConfig)
+void LoadFontDefaultPalette(const struct WindowConfig *winConfig)
{
LoadPalette(gFontDefaultPalette, 16 * winConfig->paletteNum, 32);
}
-void SetUpWindowConfig(struct WindowConfig *winConfig)
+void SetUpWindowConfig(const struct WindowConfig *winConfig)
{
UpdateBGRegs(winConfig);
ClearBGMem(winConfig);
@@ -1907,9 +1852,9 @@ static u16 LoadFixedWidthFont_Braille(struct Window *win, u16 startOffset)
return i;
}
-u16 MultistepInitWindowTileData(struct Window *win, u16 startOffset)
+u32 MultistepInitWindowTileData(struct Window *win, u16 startOffset)
{
- u16 retVal;
+ u32 retVal;
sMultistepLoadFont_Window = win;
sMultistepLoadFont_Index = 0;
sMultistepLoadFont_StartOffset = startOffset;
@@ -1932,9 +1877,9 @@ u16 MultistepInitWindowTileData(struct Window *win, u16 startOffset)
return retVal;
}
-u16 MultistepLoadFont()
+bool32 MultistepLoadFont(void)
{
- u16 retVal = 1;
+ bool32 retVal = TRUE;
if (sMultistepLoadFont_Window->config->textMode == 1)
{
@@ -1946,7 +1891,7 @@ u16 MultistepLoadFont()
sMultistepLoadFont_Index += 16;
if (sMultistepLoadFont_Index < 256)
- retVal = 0;
+ retVal = FALSE;
}
return retVal;
diff --git a/tools/rsfont/font.c b/tools/rsfont/font.c
index ba0e69cd2..ed48b31e6 100644
--- a/tools/rsfont/font.c
+++ b/tools/rsfont/font.c
@@ -42,7 +42,7 @@ void ConvertFromTiles1Bpp(unsigned char *src, unsigned char *dest, int numGlyphs
{
for (int i = 0; i < 8; i++)
{
- unsigned char srcRow = src[(glyph * 8) + i];
+ uint8_t srcRow = src[(glyph * 8) + i];
for (int j = 0; j < 8; j++)
{
@@ -61,7 +61,7 @@ void ConvertFromTiles1Bpp(unsigned char *src, unsigned char *dest, int numGlyphs
for (int i = 0; i < 8; i++)
{
- unsigned char srcRow = src[tile1Offset + i];
+ uint8_t srcRow = src[tile1Offset + i];
for (int j = 0; j < 8; j++)
{
@@ -73,7 +73,7 @@ void ConvertFromTiles1Bpp(unsigned char *src, unsigned char *dest, int numGlyphs
for (int i = 0; i < 8; i++)
{
- unsigned char srcRow = src[tile2Offset + i];
+ uint8_t srcRow = src[tile2Offset + i];
for (int j = 0; j < 8; j++)
{
@@ -94,7 +94,7 @@ void ConvertToTiles1Bpp(unsigned char *src, unsigned char *dest, int numGlyphs,
{
for (int i = 0; i < 8; i++)
{
- unsigned char destRow = 0;
+ uint8_t destRow = 0;
for (int j = 0; j < 8; j++)
{
@@ -121,7 +121,7 @@ void ConvertToTiles1Bpp(unsigned char *src, unsigned char *dest, int numGlyphs,
for (int i = 0; i < 8; i++)
{
- unsigned char destRow = 0;
+ uint8_t destRow = 0;
for (int j = 0; j < 8; j++)
{
@@ -141,7 +141,7 @@ void ConvertToTiles1Bpp(unsigned char *src, unsigned char *dest, int numGlyphs,
for (int i = 0; i < 8; i++)
{
- unsigned char destRow = 0;
+ uint8_t destRow = 0;
for (int j = 0; j < 8; j++)
{
@@ -177,7 +177,7 @@ void ConvertFromTiles4Bpp(unsigned char *src, unsigned char *dest, int numGlyphs
for (int i = 0; i < 8; i++)
{
- unsigned long srcRow = (src[offset + 3] << 24)
+ uint32_t srcRow = (src[offset + 3] << 24)
| (src[offset + 2] << 16)
| (src[offset + 1] << 8)
| src[offset];
@@ -211,7 +211,7 @@ void ConvertFromTiles4Bpp(unsigned char *src, unsigned char *dest, int numGlyphs
for (int i = 0; i < 8; i++)
{
- unsigned long srcRow = (src[tile1Offset + 3] << 24)
+ uint32_t srcRow = (src[tile1Offset + 3] << 24)
| (src[tile1Offset + 2] << 16)
| (src[tile1Offset + 1] << 8)
| src[tile1Offset];
@@ -229,7 +229,7 @@ void ConvertFromTiles4Bpp(unsigned char *src, unsigned char *dest, int numGlyphs
for (int i = 0; i < 8; i++)
{
- unsigned long srcRow = (src[tile2Offset + 3] << 24)
+ uint32_t srcRow = (src[tile2Offset + 3] << 24)
| (src[tile2Offset + 2] << 16)
| (src[tile2Offset + 1] << 8)
| src[tile2Offset];
@@ -263,7 +263,7 @@ void ConvertToTiles4Bpp(unsigned char *src, unsigned char *dest, int numGlyphs,
for (int i = 0; i < 8; i++)
{
- unsigned long destRow = 0;
+ uint32_t destRow = 0;
for (int j = 0; j < 8; j++)
{
@@ -304,7 +304,7 @@ void ConvertToTiles4Bpp(unsigned char *src, unsigned char *dest, int numGlyphs,
for (int i = 0; i < 8; i++)
{
- unsigned long destRow = 0;
+ uint32_t destRow = 0;
for (int j = 0; j < 8; j++)
{
@@ -329,7 +329,7 @@ void ConvertToTiles4Bpp(unsigned char *src, unsigned char *dest, int numGlyphs,
for (int i = 0; i < 8; i++)
{
- unsigned long destRow = 0;
+ uint32_t destRow = 0;
for (int j = 0; j < 8; j++)
{
@@ -399,8 +399,6 @@ void ReadFont(char *path, struct Image *image, int numGlyphs, int bpp, int layou
int fileSize;
unsigned char *buffer = ReadWholeFile(path, &fileSize);
- int tilesPerGlyph = layout > 0 ? 2 : 1;
-
int expectedFileSize = CalcFileSize(numGlyphs, bpp, layout);
if (fileSize != expectedFileSize)