-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #278 from lhearachel/charcode-util
Document charcode_util.c
- Loading branch information
Showing
46 changed files
with
274 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef POKEPLATINUM_CHARCODE_UTIL_H | ||
#define POKEPLATINUM_CHARCODE_UTIL_H | ||
|
||
#include "charcode.h" | ||
#include "strbuf.h" | ||
|
||
charcode_t *CharCode_Copy(charcode_t *dst, const charcode_t *src); | ||
charcode_t *CharCode_CopyNumChars(charcode_t *dst, const charcode_t *src, u32 num); | ||
u32 CharCode_Length(const charcode_t *str); | ||
BOOL CharCode_Compare(const charcode_t *str1, const charcode_t *str2); | ||
BOOL CharCode_CompareNumChars(const charcode_t *str1, const charcode_t *str2, u32 num); | ||
charcode_t *CharCode_FillWith(charcode_t *str, charcode_t fill, u32 num); | ||
charcode_t *CharCode_FillWithEOS(charcode_t *str, u32 num); | ||
charcode_t *CharCode_FromInt(charcode_t *str, s32 i, enum PaddingMode paddingMode, u32 digits); | ||
|
||
#endif // POKEPLATINUM_CHARCODE_UTIL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#include "charcode_util.h" | ||
|
||
#include <nitro.h> | ||
#include <string.h> | ||
|
||
#include "constants/charcode.h" | ||
|
||
#include "charcode.h" | ||
|
||
static const charcode_t sHexadecimalDigits[] = { | ||
CHAR_JP_0, | ||
CHAR_JP_1, | ||
CHAR_JP_2, | ||
CHAR_JP_3, | ||
CHAR_JP_4, | ||
CHAR_JP_5, | ||
CHAR_JP_6, | ||
CHAR_JP_7, | ||
CHAR_JP_8, | ||
CHAR_JP_9, | ||
CHAR_JP_A, | ||
CHAR_JP_B, | ||
CHAR_JP_C, | ||
CHAR_JP_D, | ||
CHAR_JP_E, | ||
CHAR_JP_F, | ||
}; | ||
|
||
static const int sPowersOfTen[] = { | ||
1, | ||
10, | ||
100, | ||
1000, | ||
10000, | ||
100000, | ||
1000000, | ||
10000000, | ||
100000000, | ||
1000000000, | ||
}; | ||
|
||
charcode_t *CharCode_Copy(charcode_t *dst, const charcode_t *src) | ||
{ | ||
while (*src != CHAR_EOS) { | ||
*dst = *src; | ||
dst++; | ||
src++; | ||
} | ||
|
||
*dst = 0xffff; | ||
return dst; | ||
} | ||
|
||
charcode_t *CharCode_CopyNumChars(charcode_t *dst, const charcode_t *src, u32 num) | ||
{ | ||
for (int i = 0; i < num; i++) { | ||
dst[i] = src[i]; | ||
} | ||
|
||
return &dst[num]; | ||
} | ||
|
||
u32 CharCode_Length(const charcode_t *str) | ||
{ | ||
u32 i = 0; | ||
while (str[i] != CHAR_EOS) { | ||
i++; | ||
} | ||
|
||
return i; | ||
} | ||
|
||
int CharCode_Compare(const charcode_t *str1, const charcode_t *str2) | ||
{ | ||
while (*str1 == *str2) { | ||
if (*str1 == CHAR_EOS) { | ||
return 0; | ||
} | ||
|
||
str1++; | ||
str2++; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
int CharCode_CompareNumChars(const charcode_t *str1, const charcode_t *str2, u32 num) | ||
{ | ||
while (*str1 == *str2) { | ||
if (num == 0) { | ||
return 0; | ||
} | ||
|
||
if (*str1 == CHAR_EOS && *str2 == CHAR_EOS) { | ||
return 0; | ||
} | ||
|
||
num--; | ||
str1++; | ||
str2++; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
charcode_t *CharCode_FillWith(charcode_t *str, charcode_t fill, u32 num) | ||
{ | ||
int i; | ||
for (i = 0; i < num; i++) { | ||
str[i] = fill; | ||
} | ||
|
||
return &str[i]; | ||
} | ||
|
||
charcode_t *CharCode_FillWithEOS(charcode_t *str, u32 num) | ||
{ | ||
return CharCode_FillWith(str, CHAR_EOS, num); | ||
} | ||
|
||
charcode_t *CharCode_FromInt(charcode_t *str, s32 i, enum PaddingMode paddingMode, u32 digits) | ||
{ | ||
u32 j; | ||
u32 diff; | ||
u16 digit; | ||
|
||
for (j = sPowersOfTen[digits - 1]; j > 0; j /= 10) { | ||
digit = i / j; | ||
diff = i - (j * digit); | ||
|
||
if (paddingMode == PADDING_MODE_ZEROES) { | ||
*str = digit >= 10 ? CHAR_JP_QUESTION : sHexadecimalDigits[digit]; | ||
str++; | ||
} else if (digit != 0 || j == 1) { | ||
paddingMode = PADDING_MODE_ZEROES; | ||
*str = digit >= 10 ? CHAR_JP_QUESTION : sHexadecimalDigits[digit]; | ||
str++; | ||
} else if (paddingMode == PADDING_MODE_SPACES) { | ||
*str = CHAR_JP_SPACE; | ||
str++; | ||
} | ||
|
||
i = diff; | ||
} | ||
|
||
*str = CHAR_EOS; | ||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
const u8 Unk_020E4C40 = GAME_VERSION; | ||
const u8 Unk_020E4C44 = GAME_LANGUAGE; | ||
const u8 gGameVersion = GAME_VERSION; | ||
const u8 gGameLanguage = GAME_LANGUAGE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.