summaryrefslogtreecommitdiff
path: root/arm9/src/unk_02021934.c
diff options
context:
space:
mode:
authorThomas <doodrabbit@hotmail.com>2021-12-17 20:57:03 -0500
committerGitHub <noreply@github.com>2021-12-17 20:57:03 -0500
commitaf67eaffa7ab1a347a6f0e59ed7f1e107749d15a (patch)
treeb9f90f7b047b3dc5a411dbf65117bf07b237a37d /arm9/src/unk_02021934.c
parent3ab18655ca1311019212b3a2a9dbe32e5fbee55d (diff)
parent44cd7753b5dde323d1e8274b2dc8a5599729e83f (diff)
Merge pull request #463 from PikalaxALT/pikalax_workHEADmaster
Real-match math_util.c
Diffstat (limited to 'arm9/src/unk_02021934.c')
-rw-r--r--arm9/src/unk_02021934.c94
1 files changed, 40 insertions, 54 deletions
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);
+}