From d866013b4e5e57f185c45ede44b38cb4d654fed4 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Mon, 20 Apr 2020 10:23:05 -0400 Subject: update mwasmarm patcher and decompile string_util.c (thanks Demki) --- src/string_util.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/string_util.c (limited to 'src/string_util.c') diff --git a/src/string_util.c b/src/string_util.c new file mode 100644 index 00000000..891d945c --- /dev/null +++ b/src/string_util.c @@ -0,0 +1,143 @@ +#include "nitro.h" + +extern u32 gPowersOfTen[]; // at 0x20ECB24 +extern u16 gDigitTable[]; // at 0x20ECB08 + +static const u16 EOS = 0xFFFF; + +void StringCopy(u16 *dest, const u16 *src) +{ + u16 c = *src; + while (c != EOS) + { + src++; + *dest = c; + c = *src; + dest++; + } + *dest = EOS; +} + +u16 *StringCopyN(u16 *dest, const u16 *src, u32 num) +{ + u32 copied = 0; + if (num > copied) + { + u16 *p = dest; + do + { + u16 c = *src; + copied++; + src++; + *p = c; + p++; + } while (num > copied); + } + return dest + num; +} + +u32 StringLength(const u16 *s) +{ + u16 c = *s; + u32 len = 0; + while (c != EOS) + { + s++; + c = *s; + len++; + } + return len; +} + +BOOL StringNotEqual(const u16 *s1, const u16 *s2) +{ + for (; *s1 == *s2; s1++, s2++) + { + if (*s1 == EOS) + return FALSE; + } + return TRUE; +} + +BOOL StringNotEqualN(const u16 *s1, const u16 *s2, u32 num) +{ + u16 c1, c2; + c2 = *s2; + c1 = *s1; + while (c1 == c2) + { + if (num == 0) + { + return FALSE; + } + if (*s1 == EOS && *s2 == EOS) + { + return FALSE; + } + s1++; + s2++; + c2 = *s2; + c1 = *s1; + num--; + } + return TRUE; +} + +u16 *StringFill(u16 *dest, u16 value, u32 num) +{ + u32 copied = 0; + if (num > copied) + { + u16 *p = dest; + do + { + copied++; + *p = value; + p++; + } while (copied < num); + } + return dest + copied; +} + +u16 *StringFillEOS(u16 *dest, u32 num) +{ + return StringFill(dest, EOS, num); +} + +enum PrintingMode +{ + NORMAL, + PAD_SPACE, + PAD_ZEROES +}; + +const u16 NON_DIGIT = 0xE2; + +u16 *ConvertUIntToDecimalString(u16 *dest, u32 value, enum PrintingMode mode, u32 n) +{ + for (u32 x = gPowersOfTen[n]; + x != 0; + x = x / 10) + { + u16 res = value / x; + value = value - x * res; + if (mode == PAD_ZEROES) + { + *dest = res >= 10 ? NON_DIGIT : gDigitTable[res]; + dest++; + } + else if (res != 0 || x == 1) + { + mode = PAD_ZEROES; + *dest = res >= 10 ? NON_DIGIT : gDigitTable[res]; + dest++; + } + else if (mode == PAD_SPACE) + { + *dest = 1; + dest++; + } + } + *dest = EOS; + return dest; +} -- cgit v1.2.3 From 388dbcaef64532c14fb94b9e649f297ffe08e221 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Mon, 20 Apr 2020 10:53:18 -0400 Subject: update string_util.c --- src/string_util.c | 51 ++++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) (limited to 'src/string_util.c') diff --git a/src/string_util.c b/src/string_util.c index 891d945c..2159210d 100644 --- a/src/string_util.c +++ b/src/string_util.c @@ -1,15 +1,14 @@ #include "nitro.h" extern u32 gPowersOfTen[]; // at 0x20ECB24 -extern u16 gDigitTable[]; // at 0x20ECB08 +extern u16 gDigitTable[]; // at 0x20ECB08 static const u16 EOS = 0xFFFF; void StringCopy(u16 *dest, const u16 *src) { u16 c = *src; - while (c != EOS) - { + while (c != EOS) { src++; *dest = c; c = *src; @@ -21,11 +20,9 @@ void StringCopy(u16 *dest, const u16 *src) u16 *StringCopyN(u16 *dest, const u16 *src, u32 num) { u32 copied = 0; - if (num > copied) - { + if (num > copied) { u16 *p = dest; - do - { + do { u16 c = *src; copied++; src++; @@ -40,8 +37,7 @@ u32 StringLength(const u16 *s) { u16 c = *s; u32 len = 0; - while (c != EOS) - { + while (c != EOS) { s++; c = *s; len++; @@ -51,8 +47,7 @@ u32 StringLength(const u16 *s) BOOL StringNotEqual(const u16 *s1, const u16 *s2) { - for (; *s1 == *s2; s1++, s2++) - { + for (; *s1 == *s2; s1++, s2++) { if (*s1 == EOS) return FALSE; } @@ -64,14 +59,11 @@ BOOL StringNotEqualN(const u16 *s1, const u16 *s2, u32 num) u16 c1, c2; c2 = *s2; c1 = *s1; - while (c1 == c2) - { - if (num == 0) - { + while (c1 == c2) { + if (num == 0) { return FALSE; } - if (*s1 == EOS && *s2 == EOS) - { + if (*s1 == EOS && *s2 == EOS) { return FALSE; } s1++; @@ -86,11 +78,9 @@ BOOL StringNotEqualN(const u16 *s1, const u16 *s2, u32 num) u16 *StringFill(u16 *dest, u16 value, u32 num) { u32 copied = 0; - if (num > copied) - { + if (num > copied) { u16 *p = dest; - do - { + do { copied++; *p = value; p++; @@ -104,8 +94,7 @@ u16 *StringFillEOS(u16 *dest, u32 num) return StringFill(dest, EOS, num); } -enum PrintingMode -{ +enum PrintingMode { NORMAL, PAD_SPACE, PAD_ZEROES @@ -115,25 +104,17 @@ const u16 NON_DIGIT = 0xE2; u16 *ConvertUIntToDecimalString(u16 *dest, u32 value, enum PrintingMode mode, u32 n) { - for (u32 x = gPowersOfTen[n]; - x != 0; - x = x / 10) - { + for (u32 x = gPowersOfTen[n]; x != 0; x = x / 10) { u16 res = value / x; value = value - x * res; - if (mode == PAD_ZEROES) - { + if (mode == PAD_ZEROES) { *dest = res >= 10 ? NON_DIGIT : gDigitTable[res]; dest++; - } - else if (res != 0 || x == 1) - { + } else if (res != 0 || x == 1) { mode = PAD_ZEROES; *dest = res >= 10 ? NON_DIGIT : gDigitTable[res]; dest++; - } - else if (mode == PAD_SPACE) - { + } else if (mode == PAD_SPACE) { *dest = 1; dest++; } -- cgit v1.2.3 From 84e6fbb44f67343e587b8b5758bca0671f01bf8c Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Mon, 20 Apr 2020 13:11:51 -0400 Subject: migrate data symbols to string_util.c --- src/string_util.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/string_util.c') diff --git a/src/string_util.c b/src/string_util.c index 2159210d..7d755cb9 100644 --- a/src/string_util.c +++ b/src/string_util.c @@ -1,7 +1,36 @@ #include "nitro.h" -extern u32 gPowersOfTen[]; // at 0x20ECB24 -extern u16 gDigitTable[]; // at 0x20ECB08 +u16 gDigitTable[] = { + 0xA2, + 0xA3, + 0xA4, + 0xA5, + 0xA6, + 0xA7, + 0xA8, + 0xA9, + 0xAA, + 0xAB, + 0xAC, + 0xAD, + 0xAE, + 0xAF, + 0xB0, + 0xB1 +}; + +s32 gPowersOfTen[] = { + 1, + 10, + 100, + 1000, + 10000, + 100000, + 1000000, + 10000000, + 100000000, + 1000000000, +}; static const u16 EOS = 0xFFFF; @@ -104,7 +133,7 @@ const u16 NON_DIGIT = 0xE2; u16 *ConvertUIntToDecimalString(u16 *dest, u32 value, enum PrintingMode mode, u32 n) { - for (u32 x = gPowersOfTen[n]; x != 0; x = x / 10) { + for (u32 x = gPowersOfTen[n - 1]; x != 0; x = x / 10) { u16 res = value / x; value = value - x * res; if (mode == PAD_ZEROES) { -- cgit v1.2.3