From cc4d2f524cbac1610e6ff517d55d7de48ebcafc7 Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Sat, 6 Jul 2019 05:53:42 +0800 Subject: finished dynamic_placeholder_text_util --- src/dynamic_placeholder_text_util.c | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/dynamic_placeholder_text_util.c (limited to 'src/dynamic_placeholder_text_util.c') diff --git a/src/dynamic_placeholder_text_util.c b/src/dynamic_placeholder_text_util.c new file mode 100644 index 000000000..c92cd2dcd --- /dev/null +++ b/src/dynamic_placeholder_text_util.c @@ -0,0 +1,70 @@ +#include "global.h" +#include "text.h" +#include "dynamic_placeholder_text_util.h" +#include "string_util.h" + +static EWRAM_DATA const u8 *sStringPointers[8] = {0}; + +static const u8 sTextColorTable[] = +{ + 0, 0, 0, 16, 17, 17, 17, 16, 16, 0, 0, 17, 1, 0, 17, 16, + 0, 16, 16, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, + 17, 1, 0, 0, 0, 16, 17, 0, 16, 16, 16, 0, 1, 0, 51, 51, + 51, 51, 51, 51, 51, 51, 35, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 50, +}; + +void DynamicPlaceholderTextUtil_Reset(void) +{ + const u8 **ptr = sStringPointers; + u8 *fillval = NULL; + const u8 **ptr2 = ptr + (NELEMS(sStringPointers) - 1); + + do + { + *ptr2-- = fillval; + } + while ((int)ptr2 >= (int)ptr); +} + +void DynamicPlaceholderTextUtil_SetPlaceholderPtr(u8 idx, const u8 *ptr) +{ + if (idx < NELEMS(sStringPointers)) + sStringPointers[idx] = ptr; +} + +u8 *DynamicPlaceholderTextUtil_ExpandPlaceholders(u8 *dest, const u8 *src) +{ + while (*src != EOS) + { + if (*src != CHAR_SPECIAL_F7) + { + *dest++ = *src++; + } + else + { + src++; + if (sStringPointers[*src] != NULL) + dest = StringCopy(dest, sStringPointers[*src]); + src++; + } + } + *dest = EOS; + return dest; +} + +const u8 *DynamicPlaceholderTextUtil_GetPlaceholderPtr(u8 idx) +{ + return sStringPointers[idx]; +} + +u8 GetColorFromTextColorTable(u16 graphicId) +{ + u32 test = graphicId >> 1; + u32 shift = (graphicId & 1) << 2; + + if (test > 0x4B) + return 3; + else + return (sTextColorTable[graphicId >> 1] >> shift) & 0xF; +} -- cgit v1.2.3 From 122f1395823cfa3dfd96842c61411ad29700f8de Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Mon, 8 Jul 2019 06:18:58 +0800 Subject: fixed multiple issue --- src/dynamic_placeholder_text_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dynamic_placeholder_text_util.c') diff --git a/src/dynamic_placeholder_text_util.c b/src/dynamic_placeholder_text_util.c index c92cd2dcd..6909fea30 100644 --- a/src/dynamic_placeholder_text_util.c +++ b/src/dynamic_placeholder_text_util.c @@ -24,7 +24,7 @@ void DynamicPlaceholderTextUtil_Reset(void) { *ptr2-- = fillval; } - while ((int)ptr2 >= (int)ptr); + while ((intptr_t)ptr2 >= (intptr_t)ptr); } void DynamicPlaceholderTextUtil_SetPlaceholderPtr(u8 idx, const u8 *ptr) -- cgit v1.2.3