Skip to content

Commit

Permalink
Making journal.h structs named, making small changes to function na…
Browse files Browse the repository at this point in the history
…mes, mirroring param names in include files, removing unnecessary comments, using heap ids, and returning `BOOL`s instead of `int`s
  • Loading branch information
Viperio19 committed Dec 9, 2024
1 parent 71441e5 commit 36f95a2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 54 deletions.
12 changes: 6 additions & 6 deletions asm/macros/scrcmd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2464,13 +2464,13 @@
.short 460
.endm

.macro ScrCmd_CreateJournalEvent arg0, arg1, arg2, arg3, arg4
.macro ScrCmd_CreateJournalEvent eventType, eventParam, unused1, unused2, unused3
.short 461
.short \arg0
.short \arg1
.short \arg2
.short \arg3
.short \arg4
.short \eventType
.short \eventParam
.short \unused1
.short \unused2
.short \unused3
.endm

.macro ScrCmd_1CE
Expand Down
16 changes: 8 additions & 8 deletions include/journal.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,37 +109,37 @@ enum JournalOnlineEventType {
ONLINE_EVENT_WIFI_CLUB,
};

typedef struct {
typedef struct JournalEntryTitle {
u32 year : 7;
u32 month : 4;
u32 week : 3;
u32 day : 5;
u32 mapID : 13;
} JournalEntryTitle;

typedef struct {
typedef struct JournalEntryLocationEvent {
u8 eventType;
u8 padding_01;
u16 locationID; // can be a mapID, a mapLabelTextID, or an index refering to a gym
u16 trainerID;
u16 item;
} JournalEntryLocationEvent;

typedef struct {
typedef struct JournalEntryMon {
u8 battleResult;
u8 stringVariant : 2;
u8 timeOfDay : 4;
u8 gender : 2;
u16 species;
} JournalEntryMon;

typedef struct {
typedef struct JournalEntryTrainer {
u16 standard : 1;
u16 trainerID : 15;
u16 mapID;
} JournalEntryTrainer;

typedef struct {
typedef struct JournalEntryOnlineEvent {
u8 eventType;
u8 result : 4; // can be a battle result, the placement in a contest, or an index refering to a plaza minigame
u8 unused1 : 1;
Expand All @@ -150,7 +150,7 @@ typedef struct {
u16 pokemonName[12];
} JournalEntryOnlineEvent;

typedef struct {
typedef struct JournalEntry {
JournalEntryTitle title;
u32 locationEvents[MAX_JOURNAL_LOCATION_EVENTS];
JournalEntryMon mon;
Expand Down Expand Up @@ -187,8 +187,8 @@ void *JournalEntry_CreateEventUsedMove(u8 moveIndex, u16 mapID, u32 heapID);
void *JournalEntry_CreateEventDugUnderground(u32 heapID);
void *JournalEntry_CreateEventBuiltSecretBase(u32 heapID);
void *JournalEntry_CreateEventBattleFacility(u32 heapID, u32 eventType);
void *JournalEntry_CreateMonCaught(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID);
void *JournalEntry_CreateMonDefeated(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID);
void *JournalEntry_CreateEventMonCaught(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID);
void *JournalEntry_CreateEventMonDefeated(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID);
void *JournalEntry_CreateEventStandardTrainer(u16 mapID, u16 trainerID, u32 heapID);
void *JournalEntry_CreateEventSingleBattle(u16 *opponentName, u8 opponentGender, u8 battleResult, u32 heapID);
void *JournalEntry_CreateEventDoubleBattle(u16 *opponentName, u8 opponentGender, u8 battleResult, u32 heapID);
Expand Down
4 changes: 2 additions & 2 deletions src/encounter.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,13 +954,13 @@ static void UpdateJournal(FieldSystem *fieldSystem, FieldBattleDTO *dto)

if (fieldSystem->unk_78.unk_02 >= 5) {
caughtMon = Party_GetPokemonBySlotIndex(dto->parties[1], 0);
journalEntryMon = JournalEntry_CreateMonDefeated(SaveData_GetPlayTime(fieldSystem->saveData), Pokemon_GetValue(caughtMon, MON_DATA_SPECIES, 0), Pokemon_GetValue(caughtMon, MON_DATA_GENDER, 0), dto->timeOfDay, HEAP_ID_FIELDMAP);
journalEntryMon = JournalEntry_CreateEventMonDefeated(SaveData_GetPlayTime(fieldSystem->saveData), Pokemon_GetValue(caughtMon, MON_DATA_SPECIES, 0), Pokemon_GetValue(caughtMon, MON_DATA_GENDER, 0), dto->timeOfDay, HEAP_ID_FIELDMAP);
JournalEntry_SaveData(fieldSystem->journalEntry, journalEntryMon, JOURNAL_MON);
}
} else if (resultMask == BATTLE_RESULT_CAPTURED_MON) {
int caughtBattlerIdx = dto->caughtBattlerIdx;
caughtMon = Party_GetPokemonBySlotIndex(dto->parties[caughtBattlerIdx], 0);
journalEntryMon = JournalEntry_CreateMonCaught(SaveData_GetPlayTime(fieldSystem->saveData), Pokemon_GetValue(caughtMon, MON_DATA_SPECIES, 0), Pokemon_GetValue(caughtMon, MON_DATA_GENDER, 0), dto->timeOfDay, HEAP_ID_FIELDMAP);
journalEntryMon = JournalEntry_CreateEventMonCaught(SaveData_GetPlayTime(fieldSystem->saveData), Pokemon_GetValue(caughtMon, MON_DATA_SPECIES, 0), Pokemon_GetValue(caughtMon, MON_DATA_GENDER, 0), dto->timeOfDay, HEAP_ID_FIELDMAP);

JournalEntry_SaveData(fieldSystem->journalEntry, journalEntryMon, JOURNAL_MON);
}
Expand Down
8 changes: 4 additions & 4 deletions src/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ static JournalEntryMon *JournalEntry_CreateMon(u32 heapID)
return journalEntryMon;
}

void *JournalEntry_CreateMonCaught(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID)
void *JournalEntry_CreateEventMonCaught(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID)
{
JournalEntryMon *journalEntryMon = JournalEntry_CreateMon(heapID);
u8 v1;
Expand All @@ -796,14 +796,14 @@ void *JournalEntry_CreateMonCaught(const PlayTime *playTime, u16 species, u8 gen
journalEntryMon->stringVariant = 0;
} else if (v1 == 1 || v1 == 3) {
journalEntryMon->stringVariant = 1;
} else { // v1 == 5
} else {
journalEntryMon->stringVariant = 2;
}

return journalEntryMon;
}

void *JournalEntry_CreateMonDefeated(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID)
void *JournalEntry_CreateEventMonDefeated(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID)
{
JournalEntryMon *journalEntryMon = JournalEntry_CreateMon(heapID);
u8 v1;
Expand All @@ -819,7 +819,7 @@ void *JournalEntry_CreateMonDefeated(const PlayTime *playTime, u16 species, u8 g
journalEntryMon->stringVariant = 0;
} else if (v1 == 2 || v1 == 4) {
journalEntryMon->stringVariant = 1;
} else { // v1 == 0
} else {
journalEntryMon->stringVariant = 2;
}

Expand Down
68 changes: 34 additions & 34 deletions src/journal_display/journal_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ int JournalController_Init(OverlayManager *ovyManager, int *state)
G2S_BlendNone();

SetAutorepeat(4, 8);
Heap_Create(3, 42, 0x20000);
Heap_Create(HEAP_ID_APPLICATION, HEAP_ID_JOURNAL, 0x20000);

v1 = OverlayManager_Args(ovyManager);
v0 = OverlayManager_NewData(ovyManager, sizeof(UnkStruct_ov81_021D1610), 42);
v0 = OverlayManager_NewData(ovyManager, sizeof(UnkStruct_ov81_021D1610), HEAP_ID_JOURNAL);
memset(v0, 0, sizeof(UnkStruct_ov81_021D1610));
v0->bgConfig = BgConfig_New(42);
v0->bgConfig = BgConfig_New(HEAP_ID_JOURNAL);

v0->saveData = v1;
v0->journalEntry = SaveData_GetJournal(v1);
v0->trainerInfo = SaveData_GetTrainerInfo(v1);

sub_0208C120(0, 42);
Font_UseImmediateGlyphAccess(FONT_SYSTEM, 42);
sub_0208C120(0, HEAP_ID_JOURNAL);
Font_UseImmediateGlyphAccess(FONT_SYSTEM, HEAP_ID_JOURNAL);

JournalController_SetVRAMBanks();
JournalController_SetupBgs(v0->bgConfig);
Expand All @@ -107,7 +107,7 @@ int JournalController_Init(OverlayManager *ovyManager, int *state)
GXLayers_EngineAToggleLayers(GX_PLANEMASK_OBJ, 1);
sub_02004550(67, 0, 0);

return 1;
return TRUE;
}

int JournalController_Main(OverlayManager *ovyManager, int *state)
Expand All @@ -129,11 +129,11 @@ int JournalController_Main(OverlayManager *ovyManager, int *state)
break;
case JOURNAL_STATE_CLOSE:
if (JournalController_IsClosingTransitionDone(v0) == 1) {
return 1;
return TRUE;
}
}

return 0;
return FALSE;
}

int JournalController_Exit(OverlayManager *ovyManager, int *state)
Expand All @@ -148,9 +148,9 @@ int JournalController_Exit(OverlayManager *ovyManager, int *state)

Font_UseLazyGlyphAccess(FONT_SYSTEM);
OverlayManager_FreeData(ovyManager);
Heap_Destroy(42);
Heap_Destroy(HEAP_ID_JOURNAL);

return 1;
return TRUE;
}

static void JournalController_MainCallback(void *data)
Expand Down Expand Up @@ -264,8 +264,8 @@ static void JournalController_SetupBgs(BgConfig *bgConfig)

Bg_InitFromTemplate(bgConfig, 3, &v4, 0);

Bg_ClearTilesRange(0, 32, 0, 42);
Bg_ClearTilesRange(1, 32, 0, 42);
Bg_ClearTilesRange(0, 32, 0, HEAP_ID_JOURNAL);
Bg_ClearTilesRange(1, 32, 0, HEAP_ID_JOURNAL);
}

static void JournalController_TeardownBgs(BgConfig *bgConfig)
Expand All @@ -281,16 +281,16 @@ static void JournalController_TeardownBgs(BgConfig *bgConfig)
static void ov81_021D1050(UnkStruct_ov81_021D1610 *param0)
{
u16 *v0;
NARC *v1 = NARC_ctor(NARC_INDEX_GRAPHIC__F_NOTE_GRA, 42);
NARC *v1 = NARC_ctor(NARC_INDEX_GRAPHIC__F_NOTE_GRA, HEAP_ID_JOURNAL);

if (TrainerInfo_Gender(param0->trainerInfo) == 0) {
Graphics_LoadTilesToBgLayerFromOpenNARC(v1, 2, param0->bgConfig, 2, 0, 0, 0, 42);
Graphics_LoadTilemapToBgLayerFromOpenNARC(v1, 0, param0->bgConfig, 2, 0, 0, 0, 42);
Graphics_LoadPaletteFromOpenNARC(v1, 4, 0, 0, 0, 42);
Graphics_LoadTilesToBgLayerFromOpenNARC(v1, 2, param0->bgConfig, 2, 0, 0, 0, HEAP_ID_JOURNAL);
Graphics_LoadTilemapToBgLayerFromOpenNARC(v1, 0, param0->bgConfig, 2, 0, 0, 0, HEAP_ID_JOURNAL);
Graphics_LoadPaletteFromOpenNARC(v1, 4, 0, 0, 0, HEAP_ID_JOURNAL);
} else {
Graphics_LoadTilesToBgLayerFromOpenNARC(v1, 3, param0->bgConfig, 2, 0, 0, 0, 42);
Graphics_LoadTilemapToBgLayerFromOpenNARC(v1, 1, param0->bgConfig, 2, 0, 0, 0, 42);
Graphics_LoadPaletteFromOpenNARC(v1, 5, 0, 0, 0, 42);
Graphics_LoadTilesToBgLayerFromOpenNARC(v1, 3, param0->bgConfig, 2, 0, 0, 0, HEAP_ID_JOURNAL);
Graphics_LoadTilemapToBgLayerFromOpenNARC(v1, 1, param0->bgConfig, 2, 0, 0, 0, HEAP_ID_JOURNAL);
Graphics_LoadPaletteFromOpenNARC(v1, 5, 0, 0, 0, HEAP_ID_JOURNAL);
}

NARC_dtor(v1);
Expand All @@ -299,15 +299,15 @@ static void ov81_021D1050(UnkStruct_ov81_021D1610 *param0)
MI_CpuCopy16(v0, param0->unk_5C, 0x800);
Bg_LoadTilemapBuffer(param0->bgConfig, 3, param0->unk_5C, 0x800);

Font_LoadTextPalette(0, 15 * 32, 42);
Font_LoadTextPalette(0, 15 * 32, HEAP_ID_JOURNAL);
Bg_MaskPalette(4, 0);
}

static void ov81_021D1130(UnkStruct_ov81_021D1610 *param0)
{
param0->loader = MessageLoader_Init(0, 26, 366, 42);
param0->template = StringTemplate_Default(42);
param0->strbuf = Strbuf_Init(128, 42);
param0->loader = MessageLoader_Init(0, 26, 366, HEAP_ID_JOURNAL);
param0->template = StringTemplate_Default(HEAP_ID_JOURNAL);
param0->strbuf = Strbuf_Init(128, HEAP_ID_JOURNAL);
}

static void ov81_021D115C(UnkStruct_ov81_021D1610 *param0)
Expand Down Expand Up @@ -350,13 +350,13 @@ static int JournalController_HandleInput(UnkStruct_ov81_021D1610 *param0)
return JOURNAL_STATE_TURN_LEFT;
}
} else {
sub_0208C120(1, 42);
sub_0208C120(1, HEAP_ID_JOURNAL);
return JOURNAL_STATE_CLOSE;
}
}

if (gCoreSys.pressedKeys & PAD_BUTTON_START) {
sub_0208C120(1, 42);
sub_0208C120(1, HEAP_ID_JOURNAL);
return JOURNAL_STATE_CLOSE;
}

Expand Down Expand Up @@ -442,23 +442,23 @@ static u8 JournalController_PageExists(UnkStruct_ov81_021D1610 *param0, u8 param
JournalEntry_GetData(param0->journalEntry, &journalEntryTitle, JOURNAL_TITLE, param1);

if (journalEntryTitle.year == 0 && journalEntryTitle.month == 0 && journalEntryTitle.day == 0) {
return 0;
return FALSE;
}

return 1;
return TRUE;
}

static u8 JournalController_NewDirectionPageExists(UnkStruct_ov81_021D1610 *param0, s8 pageChange)
{
if (pageChange == 1) {
if (param0->page != 9 && JournalController_PageExists(param0, param0->page + 1) == 1) {
return 1;
return TRUE;
}
} else if (param0->page != 0 && JournalController_PageExists(param0, param0->page - 1) == 1) {
return 1;
return TRUE;
}

return 0;
return FALSE;
}

static void ov81_021D140C(UnkStruct_ov81_021D1610 *param0, u8 bgLayer, u8 palette)
Expand Down Expand Up @@ -505,10 +505,10 @@ static u8 ov81_021D14E0(UnkStruct_ov81_021D1610 *param0)
Bg_SetPriority(param0->bgLayer3, 1);
Bg_SetPriority(param0->bgLayer2, 2);
Bg_SetPriority(param0->bgLayer1, 3);
return 1;
return TRUE;
}

return 0;
return FALSE;
}

static u8 ov81_021D156C(UnkStruct_ov81_021D1610 *param0)
Expand All @@ -527,8 +527,8 @@ static u8 ov81_021D156C(UnkStruct_ov81_021D1610 *param0)
param0->unk_105F++;

if (param0->unk_105F == 9) {
return 1;
return TRUE;
}

return 0;
return FALSE;
}

0 comments on commit 36f95a2

Please sign in to comment.