summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2021-09-05 08:52:18 -0400
committerPikalaxALT <pikalaxalt@gmail.com>2021-09-05 08:52:18 -0400
commit66f4bf3667e407edfac6754a81bf48faffc0802e (patch)
treec19894339e6ebb8438d4b02de6ab22df442bdce0
parent9aaac32d700191262926a9495a2e5927cdb9e1bd (diff)
Reorganize font and string related code
-rw-r--r--arm9/global.inc2
-rw-r--r--arm9/src/font.c2
-rw-r--r--arm9/src/script_buffers.c3
-rw-r--r--arm9/src/unk_02021590.c50
-rw-r--r--arm9/src/unk_02021934.c94
-rw-r--r--arm9/src/unk_02021FF8.c40
-rw-r--r--include/string16.h5
-rw-r--r--include/unk_02021590.h2
-rw-r--r--include/unk_02021FF8.h2
9 files changed, 98 insertions, 102 deletions
diff --git a/arm9/global.inc b/arm9/global.inc
index e049b61d..fce4beab 100644
--- a/arm9/global.inc
+++ b/arm9/global.inc
@@ -1386,7 +1386,7 @@
.extern FontData_ModeSwitch
.extern TryLoadGlyph
.extern GetStringWidth
-.extern StringGetWidth
+.extern GetStringWidthMultiline
.extern StringGetWidth_SingleLine_HandleClearToControlCode
.extern String_ctor
.extern String_dtor
diff --git a/arm9/src/font.c b/arm9/src/font.c
index 537a7337..a0d1057b 100644
--- a/arm9/src/font.c
+++ b/arm9/src/font.c
@@ -179,7 +179,7 @@ THUMB_FUNC s32 FUN_02002F08(u32 param0, struct String *str, u32 param2)
{
GF_ASSERT(UNK_02106FC8->unk94[param0] != NULL);
- return StringGetWidth(UNK_02106FC8->unk94[param0], String_c_str(str), param2);
+ return GetStringWidthMultiline(UNK_02106FC8->unk94[param0], String_c_str(str), param2);
}
THUMB_FUNC u32 FUN_02002F40(u32 param0, struct String *str, u32 param2, u32 param3)
diff --git a/arm9/src/script_buffers.c b/arm9/src/script_buffers.c
index 550dcab5..37df6a71 100644
--- a/arm9/src/script_buffers.c
+++ b/arm9/src/script_buffers.c
@@ -13,6 +13,7 @@
#include "script_buffers.h"
#include "unk_02024E64.h"
#include "text.h"
+#include "string16.h"
#include "msgdata/msg.naix"
#include "graphic/font.naix"
@@ -20,8 +21,6 @@
extern u32 GetCityNamesMsgdataIdByCountry(u32);
extern void GetECWordIntoStringByIndex(u32 a0, struct String * a1);
-extern void StringCat_HandleTrainerName(struct String * dest, const struct String * src);
-extern void StrAddChar(struct String * str, u16 val);
extern void * GfGfxLoader_GetCharData(NarcId, s32, s32, struct UnkStruct_0200B870_sub **, u32);
extern void * GfGfxLoader_LoadFromNarc(NarcId narcId, s32 memberNo, BOOL isCompressed, u32 heap_id, BOOL allocAtEnd);
diff --git a/arm9/src/unk_02021590.c b/arm9/src/unk_02021590.c
index e6a3d690..c37ce589 100644
--- a/arm9/src/unk_02021590.c
+++ b/arm9/src/unk_02021590.c
@@ -210,3 +210,53 @@ THUMB_FUNC int GetGlyphWidth_FixedWidth(struct FontData * ptr, int a1)
#pragma unused(a1)
return ptr->gfxHeader.fixedWidth;
}
+
+THUMB_FUNC s32 GetStringWidthMultiline(struct FontData * r7, const u16 * arr, u32 r6)
+{
+ s32 ret = 0;
+ u32 r4 = 0;
+ while (*arr != 0xFFFF)
+ {
+ if (*arr == 0xFFFE)
+ {
+ arr = MsgArray_SkipControlCode(arr);
+ }
+ else if (*arr == 0xE000) // newline
+ {
+ if (ret < r4 - r6)
+ ret = (int)(r4 - r6);
+ r4 = 0;
+ arr++;
+ }
+ else
+ {
+ r4 += (r6 + r7->glyphWidthFunc(r7, *arr - 1));
+ arr++;
+ }
+ }
+ if (ret < r4 - r6)
+ ret = (int)(r4 - r6);
+ return ret;
+}
+
+THUMB_FUNC s32 StringGetWidth_SingleLine_HandleClearToControlCode(struct FontData * r6, const u16 * arr)
+{
+ s32 ret = 0;
+ while (*arr != 0xFFFF)
+ {
+ if (*arr == 0xFFFE)
+ {
+ if (MsgArray_GetControlCode(arr) == 515)
+ {
+ ret = MsgArray_ControlCodeGetField(arr, 0) - 12;
+ }
+ arr = MsgArray_SkipControlCode(arr);
+ }
+ else
+ {
+ ret += r6->glyphWidthFunc(r6, *arr - 1);
+ arr++;
+ }
+ }
+ return ret;
+}
diff --git a/arm9/src/unk_02021934.c b/arm9/src/unk_02021934.c
index 07ddde87..e87016c4 100644
--- a/arm9/src/unk_02021934.c
+++ b/arm9/src/unk_02021934.c
@@ -2,65 +2,11 @@
#include "string16.h"
#include "heap.h"
#include "string_util.h"
-#include "unk_0201B8B8.h"
-#include "unk_02021590.h"
#pragma thumb on
#define ASSERT_STR16(_str) ({ GF_ASSERT(_str != NULL); GF_ASSERT(_str->magic == STR16_MAGIC); })
-void StrAddChar(struct String * str, u16 val);
-
-s32 StringGetWidth(struct FontData * r7, const u16 * arr, u32 r6)
-{
- s32 ret = 0;
- u32 r4 = 0;
- while (*arr != 0xFFFF)
- {
- if (*arr == 0xFFFE)
- {
- arr = MsgArray_SkipControlCode(arr);
- }
- else if (*arr == 0xE000) // newline
- {
- if (ret < r4 - r6)
- ret = (int)(r4 - r6);
- r4 = 0;
- arr++;
- }
- else
- {
- r4 += (r6 + r7->glyphWidthFunc(r7, *arr - 1));
- arr++;
- }
- }
- if (ret < r4 - r6)
- ret = (int)(r4 - r6);
- return ret;
-}
-
-s32 StringGetWidth_SingleLine_HandleClearToControlCode(struct FontData * r6, const u16 * arr)
-{
- s32 ret = 0;
- while (*arr != 0xFFFF)
- {
- if (*arr == 0xFFFE)
- {
- if (MsgArray_GetControlCode(arr) == 515)
- {
- ret = MsgArray_ControlCodeGetField(arr, 0) - 12;
- }
- arr = MsgArray_SkipControlCode(arr);
- }
- else
- {
- ret += r6->glyphWidthFunc(r6, *arr - 1);
- arr++;
- }
- }
- return ret;
-}
-
struct String * String_ctor(u32 length, u32 heap_id)
{
struct String * ret = AllocFromHeap(heap_id, length * 2 + 10);
@@ -366,3 +312,43 @@ void StrUpperFirstChar(struct String * str)
str->data[0] -= 26;
}
}
+
+BOOL String_IsTrainerName(struct String * string)
+{
+ return string->size != 0 && string->data[0] == 0xF100;
+}
+
+void StringCat_HandleTrainerName(struct String * dest, struct String * src)
+{
+ if (String_IsTrainerName(src))
+ {
+ u16 * dest_p = &dest->data[dest->size];
+ u16 * src_p = &src->data[1];
+ s32 bit = 0;
+ u32 outsize = 0;
+ u16 cur_char = 0;
+
+ while (1)
+ {
+ cur_char = (u16)((*src_p >> bit) & 0x1FF);
+ bit += 9;
+ if (bit >= 15)
+ {
+ src_p++;
+ bit -= 15;
+ if (bit != 0)
+ {
+ cur_char |= (*src_p << (9 - bit)) & 0x1FF;
+ }
+ }
+ if (cur_char == 0x1FF)
+ break;
+ *dest_p++ = cur_char;
+ outsize++;
+ }
+ *dest_p = EOS;
+ dest->size += outsize;
+ }
+ else
+ StringCat(dest, src);
+}
diff --git a/arm9/src/unk_02021FF8.c b/arm9/src/unk_02021FF8.c
index 2fe37556..d578bba5 100644
--- a/arm9/src/unk_02021FF8.c
+++ b/arm9/src/unk_02021FF8.c
@@ -5,46 +5,6 @@
#pragma thumb on
-BOOL String_IsTrainerName(struct String * string)
-{
- return string->size != 0 && string->data[0] == 0xF100;
-}
-
-void StringCat_HandleTrainerName(struct String * dest, struct String * src)
-{
- if (String_IsTrainerName(src))
- {
- u16 * dest_p = &dest->data[dest->size];
- u16 * src_p = &src->data[1];
- s32 bit = 0;
- u32 outsize = 0;
- u16 cur_char = 0;
-
- while (1)
- {
- cur_char = (u16)((*src_p >> bit) & 0x1FF);
- bit += 9;
- if (bit >= 15)
- {
- src_p++;
- bit -= 15;
- if (bit != 0)
- {
- cur_char |= (*src_p << (9 - bit)) & 0x1FF;
- }
- }
- if (cur_char == 0x1FF)
- break;
- *dest_p++ = cur_char;
- outsize++;
- }
- *dest_p = EOS;
- dest->size += outsize;
- }
- else
- StringCat(dest, src);
-}
-
struct UnkStruct_020220C4 * FUN_020220C4(u8 * a0, u32 a1, void (*a2)(s32, s32, u32), u32 a3, u32 a4)
{
struct UnkStruct_020220C4 * ret;
diff --git a/include/string16.h b/include/string16.h
index f42ff918..d1e8b250 100644
--- a/include/string16.h
+++ b/include/string16.h
@@ -20,8 +20,6 @@ BOOL StringCompare(struct String *, struct String *);
void CopyU16ArrayToStringN(struct String *, u16 *, u32); // copy
void StringSetEmpty(struct String *); // set empty
struct String * StringDup(struct String *, u32 heap_id);
-s32 StringGetWidth(struct FontData * r7, const u16 * arr, u32 r6);
-s32 StringGetWidth_SingleLine_HandleClearToControlCode(struct FontData * r6, const u16 * arr);
void String_dtor(struct String * str);
void StringCopy(struct String * dest, struct String * src);
void String16_FormatInteger(struct String * str, int num, u32 ndigits, int strConvMode, BOOL whichCharset);
@@ -32,7 +30,10 @@ void StringGetLineN(struct String * dest, volatile struct String * src, u32 n);
void CopyU16ArrayToString(struct String * str, u16 * buf);
void CopyStringToU16Array(struct String * str, u16 * buf, u32 length);
u16 * String_c_str(struct String * str);
+void StrAddChar(struct String * str, u16 val);
void StringCat(struct String * dest, struct String * src);
void StrUpperFirstChar(struct String * str);
+BOOL String_IsTrainerName(struct String * string);
+void StringCat_HandleTrainerName(struct String * dest, struct String * src);
#endif //POKEDIAMOND_STRING16_H
diff --git a/include/unk_02021590.h b/include/unk_02021590.h
index 6ed73bb8..8c815992 100644
--- a/include/unk_02021590.h
+++ b/include/unk_02021590.h
@@ -48,5 +48,7 @@ void DecompressGlyphTiles_LazyFromNarc(struct FontData * ptr, u16 param1, struct
u32 GetStringWidth(struct FontData * ptr, const u16 * str, u32 letterSpacing);
int GetGlyphWidth_VariableWidth(struct FontData * ptr, int a1);
int GetGlyphWidth_FixedWidth(struct FontData * ptr, int a1);
+s32 GetStringWidthMultiline(struct FontData * r7, const u16 * arr, u32 r6);
+s32 StringGetWidth_SingleLine_HandleClearToControlCode(struct FontData * r6, const u16 * arr);
#endif //POKEDIAMOND_UNK_02021590_H
diff --git a/include/unk_02021FF8.h b/include/unk_02021FF8.h
index 59120668..48ef4322 100644
--- a/include/unk_02021FF8.h
+++ b/include/unk_02021FF8.h
@@ -17,8 +17,6 @@ struct UnkStruct_020220C4
struct UnkStruct_020220C4_sub * field_10;
};
-BOOL String_IsTrainerName(struct String * string);
-void StringCat_HandleTrainerName(struct String * dest, struct String * src);
struct UnkStruct_020220C4 * FUN_020220C4(u8 * a0, u32 a1, void (*a2)(s32, s32, u32), u32 a3, u32 a4);
void FUN_02022120(struct UnkStruct_020220C4_sub * sub);
void FUN_0202212C(struct UnkStruct_020220C4 * unk);