Skip to content

Commit

Permalink
Merge pull request #278 from lhearachel/charcode-util
Browse files Browse the repository at this point in the history
Document charcode_util.c
  • Loading branch information
lhearachel authored Oct 26, 2024
2 parents b4d8ed0 + 7154f2d commit c0dce46
Show file tree
Hide file tree
Showing 46 changed files with 274 additions and 280 deletions.
16 changes: 16 additions & 0 deletions include/charcode_util.h
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
6 changes: 6 additions & 0 deletions include/constants/charcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ enum {
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,

CHAR_JP_QUESTION = 0x00E2,

Expand Down
6 changes: 0 additions & 6 deletions include/constdata/const_020E4C40.h

This file was deleted.

6 changes: 0 additions & 6 deletions include/constdata/const_020E4C44.h

This file was deleted.

4 changes: 2 additions & 2 deletions include/global/pm_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define SPANISH 7
#define KOREAN 8

extern const u8 Unk_020E4C40;
extern const u8 Unk_020E4C44;
extern const u8 gGameVersion;
extern const u8 gGameLanguage;

#endif // POKEPLATINUM_PM_VERSION_H
13 changes: 0 additions & 13 deletions include/unk_020021B0.h

This file was deleted.

2 changes: 1 addition & 1 deletion platinum.us/main.lsf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Static main
Object main.nef.p/src_unk_0200112C.c.o
Object main.nef.p/src_game_version.c.o
Object main.nef.p/src_unk_02001AF4.c.o
Object main.nef.p/src_unk_020021B0.c.o
Object main.nef.p/src_charcode_util.c.o
Object main.nef.p/src_render_text.c.o
Object main.nef.p/src_font.c.o
Object main.nef.p/src_palette.c.o
Expand Down
6 changes: 3 additions & 3 deletions src/battle/battle_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "battle/scripts/sub_seq.naix"
#include "battle/struct_ov16_0225BFFC_decl.h"

#include "charcode_util.h"
#include "flags.h"
#include "heap.h"
#include "item.h"
Expand All @@ -43,7 +44,6 @@
#include "strbuf.h"
#include "trainer_data.h"
#include "trainer_info.h"
#include "unk_020021B0.h"
#include "unk_020366A0.h"
#include "unk_0208C098.h"

Expand Down Expand Up @@ -6275,7 +6275,7 @@ BOOL BattleSystem_TrainerIsOT(BattleSystem *battleSys, BattleContext *battleCtx)

if (trID == ATTACKING_MON.OTId
&& trGender == ATTACKING_MON.OTGender
&& GF_strncmp(trName, ATTACKING_MON.OTName, TRAINER_NAME_LEN) == 0) {
&& CharCode_CompareNumChars(trName, ATTACKING_MON.OTName, TRAINER_NAME_LEN) == 0) {
return TRUE;
}

Expand All @@ -6294,7 +6294,7 @@ BOOL BattleSystem_PokemonIsOT(BattleSystem *battleSys, Pokemon *mon)

if (trID == Pokemon_GetValue(mon, MON_DATA_OT_ID, NULL)
&& trGender == Pokemon_GetValue(mon, MON_DATA_OT_GENDER, NULL)
&& GF_strncmp(trName, monOTName, TRAINER_NAME_LEN) == 0) {
&& CharCode_CompareNumChars(trName, monOTName, TRAINER_NAME_LEN) == 0) {
return TRUE;
}

Expand Down
2 changes: 1 addition & 1 deletion src/battle/battle_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -9989,7 +9989,7 @@ static void BattleScript_GetExpTask(SysTask *task, void *inData)
}

if (BattleSystem_PokemonIsOT(data->battleSys, mon) == FALSE) {
if (Pokemon_GetValue(mon, MON_DATA_LANGUAGE, NULL) != Unk_020E4C44) {
if (Pokemon_GetValue(mon, MON_DATA_LANGUAGE, NULL) != gGameLanguage) {
totalExp = totalExp * 170 / 100;
} else {
totalExp = totalExp * 150 / 100;
Expand Down
148 changes: 148 additions & 0 deletions src/charcode_util.c
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;
}
4 changes: 2 additions & 2 deletions src/game_version.c
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;
2 changes: 1 addition & 1 deletion src/map_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const u16 MapHeader_GetMapMatrixID(u32 headerID)
mapMatrixID = sMapHeaders[headerID].mapMatrixID;

if (mapMatrixID == 22) {
if (Unk_020E4C40 == 11) {
if (gGameVersion == 11) {
mapMatrixID = 23;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pokeplatinum_c = files(
'strbuf.c',
'unk_0200112C.c',
'unk_02001AF4.c',
'unk_020021B0.c',
'charcode_util.c',
'render_text.c',
'font.c',
'palette.c',
Expand Down
4 changes: 2 additions & 2 deletions src/overlay006/ov6_02246444.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include "overlay006/struct_ov6_022465F4_decl.h"
#include "savedata/save_table.h"

#include "charcode_util.h"
#include "heap.h"
#include "save_player.h"
#include "trainer_info.h"
#include "unk_020021B0.h"
#include "unk_0202E2CC.h"

struct UnkStruct_ov6_022465F4_t {
Expand Down Expand Up @@ -49,7 +49,7 @@ static void ov6_02246458(UnkStruct_ov6_022465F4 *param0, int param1)

static void ov6_0224645C(UnkStruct_ov6_022465F4 *param0, const u16 *param1)
{
sub_020021D0(param0->unk_04, param1, 7 + 1);
CharCode_CopyNumChars(param0->unk_04, param1, 7 + 1);
}

static void ov6_02246468(UnkStruct_ov6_022465F4 *param0, UnkStruct_0202E4D4 *param1)
Expand Down
4 changes: 2 additions & 2 deletions src/overlay059/ov59_021D2B44.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

#include "savedata/save_table.h"

#include "charcode_util.h"
#include "communication_information.h"
#include "heap.h"
#include "save_player.h"
#include "savedata.h"
#include "trainer_info.h"
#include "unk_020021B0.h"

__attribute__((aligned(4))) static const u8 Unk_ov59_021D33B0[] = {
0x2,
Expand Down Expand Up @@ -160,7 +160,7 @@ static void ov59_021D2B90(SaveData *param0, UnkStruct_0202E794 *param1, UnkStruc
param1->unk_05 = GAME_VERSION;
param1->unk_06 = GAME_LANGUAGE;

sub_020021D0(param1->unk_08, TrainerInfo_Name(v1), 7 + 1);
CharCode_CopyNumChars(param1->unk_08, TrainerInfo_Name(v1), 7 + 1);

param1->unk_18 = param2[v0].unk_00;
param1->unk_18.unk_01 = 0;
Expand Down
Loading

0 comments on commit c0dce46

Please sign in to comment.