summaryrefslogtreecommitdiff
path: root/arm9/src
diff options
context:
space:
mode:
Diffstat (limited to 'arm9/src')
-rw-r--r--arm9/src/game_init.c5
-rw-r--r--arm9/src/heap.c380
-rw-r--r--arm9/src/scrcmd.c556
-rw-r--r--arm9/src/scrcmd_18_c.c14
-rw-r--r--arm9/src/script.c2
-rw-r--r--arm9/src/script_buffers.c2
-rw-r--r--arm9/src/trainer_data.c2
-rw-r--r--arm9/src/unk_02015E30.c38
-rw-r--r--arm9/src/unk_02024E64.c38
9 files changed, 1005 insertions, 32 deletions
diff --git a/arm9/src/game_init.c b/arm9/src/game_init.c
index 327c66c6..a7508fab 100644
--- a/arm9/src/game_init.c
+++ b/arm9/src/game_init.c
@@ -4,16 +4,15 @@
#include "main.h"
#include "FS_rom.h"
#include "PAD_pad.h"
-#include "heap.h"
#include "MWC_string.h"
#include "tp.h"
#include "unk_0201B4E8.h"
#include "game_init.h"
#include "registers.h"
+#include "heap.h"
#pragma thumb on
-extern void FUN_020166C8(const u32 (*)[2], int, int, int);
extern void FUN_02022450(void);
typedef volatile struct
@@ -142,7 +141,7 @@ void FUN_02015FC8(void)
{
csum++;
}
- FUN_020166C8(UNK_020EDB10, 4, 92, (int)csum);
+ FUN_020166C8((u32 *)UNK_020EDB10, 4, 92, (int)csum);
}
void InitSystemForTheGame(void)
diff --git a/arm9/src/heap.c b/arm9/src/heap.c
new file mode 100644
index 00000000..c27a40c0
--- /dev/null
+++ b/arm9/src/heap.c
@@ -0,0 +1,380 @@
+#include "heap.h"
+
+extern void *tempName_NNS_FndCreateExpHeapEx(void *param0, u32 param1, u32 param2);
+extern void *tempName_NNS_FndAllocFromExpHeapEx(void *param0, u32 param1, s32 param2);
+extern void thunk_FUN_020adc8c();
+extern void FUN_020ADDF0(void *ptr1, void *ptr2);
+extern u32 FUN_02031810(void);
+extern void PrintErrorMessageAndReset(void);
+extern u32 FUN_020ADDC8(void *param0);
+extern void FUN_020AE82C(u32 param0, void *param1, u32 param2);
+extern u32 FUN_020ADDC0(void *param0);
+extern void FUN_020ADE2C(void *ptr1, void *ptr2, u32 param2);
+
+
+struct UnkStruct_020166C8 UNK_021C4D28;
+
+
+THUMB_FUNC void FUN_020166C8(u32 *param0, u32 param1, u32 param2, u32 pre_size)
+{
+ u32 unk_size = param1 + 24;
+
+ if (param2 < unk_size)
+ {
+ param2 = unk_size;
+ }
+ if (pre_size != 0)
+ {
+ while (pre_size % 4 != 0)
+ {
+ pre_size++;
+ }
+
+ OS_AllocFromArenaLo(OS_ARENA_MAIN, pre_size, 4);
+ }
+
+ u32 r7 = param2 * 2;
+
+ void *ptr = OS_AllocFromArenaLo(OS_ARENA_MAIN, (unk_size * 3 + 1) * sizeof(u32) + r7 + param2, 4);
+ UNK_021C4D28.unk00 = ptr;
+ ptr += (unk_size + 1) * 4;
+ UNK_021C4D28.unk04 = ptr;
+ ptr += unk_size * 4;
+ UNK_021C4D28.unk08 = ptr;
+ ptr += unk_size * 4;
+ UNK_021C4D28.unk0c = ptr;
+ ptr += r7;
+ UNK_021C4D28.unk10 = ptr;
+ UNK_021C4D28.unk14 = (u16)param2;
+ UNK_021C4D28.unk16 = (u16)param1;
+
+ r7 = 0;
+ UNK_021C4D28.unk1a = (u16)unk_size;
+ UNK_021C4D28.unk18 = (u16)unk_size;
+
+ while (r7 < param1)
+ {
+ void *ptr;
+ if (param0[1] == 0 || param0[1] != 2)
+ {
+ ptr = OS_AllocFromArenaLo(OS_ARENA_MAIN, param0[0], 4);
+ }
+ else
+ {
+ ptr = OS_AllocFromArenaHi(OS_ARENA_MAINEX, param0[0], 4);
+ }
+
+ if (ptr != 0)
+ {
+
+ UNK_021C4D28.unk00[r7] = tempName_NNS_FndCreateExpHeapEx(ptr, param0[0], 0);
+ UNK_021C4D28.unk10[r7] = (u8)r7;
+ }
+ else
+ {
+ ErrorHandling();
+ }
+
+ param0 += 2;
+ r7++;
+ }
+
+ while (param1 < unk_size + 1)
+ {
+ UNK_021C4D28.unk00[param1] = 0;
+ UNK_021C4D28.unk10[param1] = (u8)UNK_021C4D28.unk1a;
+
+ param1++;
+ }
+
+ while (param1 < param2)
+ {
+ UNK_021C4D28.unk10[param1] = (u8)UNK_021C4D28.unk1a;
+
+ param1++;
+ }
+
+ for (param1 = 0; param1 < param2; param1++)
+ {
+ UNK_021C4D28.unk0c[param1] = 0;
+ }
+}
+
+THUMB_FUNC s32 FUN_020167F4()
+{
+ s32 i = UNK_021C4D28.unk16;
+ s32 j = UNK_021C4D28.unk18;
+
+ if (i < j)
+ {
+ void **ptr = UNK_021C4D28.unk00 + i;
+ do
+ {
+ if (*ptr == 0)
+ {
+ return i;
+ }
+ i++;
+ ptr++;
+ } while (i < j);
+ }
+
+ return -1;
+}
+
+THUMB_FUNC u32 FUN_0201681C(u32 param0, u32 param1, u32 param2)
+{
+ return FUN_02016834(param0, param1, param2, 4);
+}
+
+THUMB_FUNC u32 FUN_02016828(u32 param0, u32 param1, u32 param2)
+{
+ return FUN_02016834(param0, param1, param2, -4);
+}
+
+THUMB_FUNC u32 FUN_02016834(u32 param0, u32 param1, u32 param2, s32 param3)
+{
+ GF_ASSERT(OS_GetProcMode() != OS_PROCMODE_IRQ);
+
+ u8 *ptr = UNK_021C4D28.unk10;
+ if (UNK_021C4D28.unk1a == ptr[param1])
+ {
+ void *ptr2 = UNK_021C4D28.unk00[ptr[param0]];
+ if (ptr2 != 0)
+ {
+ void *ptr3 = tempName_NNS_FndAllocFromExpHeapEx(ptr2, param2, param3);
+ if (ptr3 != 0)
+ {
+ param3 = FUN_020167F4();
+ if (param3 >= 0)
+ {
+ UNK_021C4D28.unk00[param3] = tempName_NNS_FndCreateExpHeapEx(ptr3, param2, 0);
+
+
+ if (UNK_021C4D28.unk00[param3] != 0)
+ {
+ UNK_021C4D28.unk04[param3] = ptr2;
+ UNK_021C4D28.unk08[param3] = ptr3;
+ UNK_021C4D28.unk10[param1] = (u8)param3;
+
+ return 1;
+ }
+ else
+ {
+ ErrorHandling();
+ }
+ }
+ else
+ {
+ ErrorHandling();
+ }
+ }
+ else
+ {
+ ErrorHandling();
+ }
+ }
+ else
+ {
+ ErrorHandling();
+ }
+ }
+ else
+ {
+ ErrorHandling();
+ }
+ return 0;
+}
+
+THUMB_FUNC void FUN_020168D0(u32 heap_id)
+{
+ GF_ASSERT (OS_GetProcMode() != OS_PROCMODE_IRQ);
+
+ if (UNK_021C4D28.unk00[UNK_021C4D28.unk10[heap_id]] != 0)
+ {
+ thunk_FUN_020adc8c();
+
+ u8 index = UNK_021C4D28.unk10[heap_id];
+ void *ptr1 = UNK_021C4D28.unk04[index];
+ void *ptr2 = UNK_021C4D28.unk08[index];
+ if (ptr1 != 0 && ptr2 != 0)
+ {
+ FUN_020ADDF0(ptr1, ptr2);
+ }
+ else
+ {
+ ErrorHandling();
+ }
+
+ UNK_021C4D28.unk00[UNK_021C4D28.unk10[heap_id]] = 0;
+ UNK_021C4D28.unk04[UNK_021C4D28.unk10[heap_id]] = 0;
+ UNK_021C4D28.unk08[UNK_021C4D28.unk10[heap_id]] = 0;
+
+ UNK_021C4D28.unk10[heap_id] = (u8)UNK_021C4D28.unk1a;
+ }
+}
+
+THUMB_FUNC u32 *FUN_02016944(void *param0, u32 param1, s32 param2, u32 param3)
+{
+ GF_ASSERT(param0);
+
+ OSIntrMode intr_mode = OS_DisableInterrupts();
+ param1 += 16;
+ u32 *ptr = (u32 *)tempName_NNS_FndAllocFromExpHeapEx(param0, param1, param2);
+
+ OS_RestoreInterrupts(intr_mode);
+ if (ptr != 0)
+ {
+ ptr[3] = (ptr[3] & ~0xff) | (param3 & 0xff);
+
+ ptr += 4;
+ }
+
+ return ptr;
+}
+
+THUMB_FUNC void FUN_02016988()
+{
+ if (FUN_02031810() != 0)
+ {
+ PrintErrorMessageAndReset();
+ }
+}
+
+void *AllocFromHeap(u32 heap_id, u32 size)
+{
+ void *ptr = 0;
+ if (heap_id < UNK_021C4D28.unk14)
+ {
+ u8 index = UNK_021C4D28.unk10[heap_id];
+ ptr = FUN_02016944(UNK_021C4D28.unk00[index], size, 4, heap_id);
+ }
+ if (ptr != 0)
+ {
+ UNK_021C4D28.unk0c[heap_id]++;
+ }
+ else
+ {
+ FUN_02016988();
+ }
+
+ return ptr;
+}
+
+void *AllocFromHeapAtEnd(u32 heap_id, u32 size)
+{
+ void *ptr = 0;
+ if (heap_id < UNK_021C4D28.unk14)
+ {
+ u8 index = UNK_021C4D28.unk10[heap_id];
+ ptr = FUN_02016944(UNK_021C4D28.unk00[index], size, -4, heap_id);
+ }
+
+ if (ptr != 0)
+ {
+ UNK_021C4D28.unk0c[heap_id]++;
+ }
+ else
+ {
+ FUN_02016988();
+ }
+
+ return ptr;
+}
+
+void FreeToHeap(void *ptr)
+{
+ u8 heap_id = (u8)((u32 *)ptr)[-1];
+
+ if ((u16)heap_id < UNK_021C4D28.unk14)
+ {
+ u8 index = UNK_021C4D28.unk10[heap_id];
+ void *ptr2 = UNK_021C4D28.unk00[index];
+ GF_ASSERT(ptr2);
+
+ if (UNK_021C4D28.unk0c[heap_id] == 0)
+ {
+ FUN_02016B90(heap_id);
+ }
+ GF_ASSERT(UNK_021C4D28.unk0c[heap_id]);
+
+ UNK_021C4D28.unk0c[heap_id]--;
+ OSIntrMode intr_mode = OS_DisableInterrupts();
+ FUN_020ADDF0(ptr2, ptr - 16);
+ OS_RestoreInterrupts(intr_mode);
+ return;
+ }
+
+ ErrorHandling();
+}
+
+void FUN_02016A8C(u32 param0, void *param1)
+{
+ GF_ASSERT (OS_GetProcMode() != OS_PROCMODE_IRQ);
+
+ if (param0 < UNK_021C4D28.unk14)
+ {
+ u8 index = UNK_021C4D28.unk10[param0];
+ void *ptr = UNK_021C4D28.unk00[index];
+ GF_ASSERT (ptr );
+
+ u8 heap_id = (u8)((u32 *)param1)[-1];
+ GF_ASSERT (heap_id == param0);
+
+ FUN_020ADDF0(ptr, param1 - 16);
+ GF_ASSERT (UNK_021C4D28.unk0c[param0]);
+
+ UNK_021C4D28.unk0c[param0]--;
+ return;
+ }
+
+ ErrorHandling();
+}
+
+THUMB_FUNC u32 FUN_02016AF8(u32 param0)
+{
+ if (param0 < UNK_021C4D28.unk14)
+ {
+ u8 index = UNK_021C4D28.unk10[param0];
+ return FUN_020ADDC8(UNK_021C4D28.unk00[index]);
+ }
+
+ ErrorHandling();
+ return 0;
+}
+
+THUMB_FUNC void FUN_02016B20(u32 param0, u32 param1, u32 param2)
+{
+ if (param1 < UNK_021C4D28.unk14)
+ {
+
+ u8 index = UNK_021C4D28.unk10[param1];
+ FUN_020AE82C(param0, UNK_021C4D28.unk00[index], param2);
+ return;
+ }
+
+ ErrorHandling();
+}
+
+THUMB_FUNC void FUN_02016B44(void *ptr, u32 param1)
+{
+ GF_ASSERT (OS_GetProcMode() != OS_PROCMODE_IRQ);
+
+ param1 += 16;
+ if (FUN_020ADDC0(ptr - 16) >= param1)
+ {
+ u8 heap_id = (u8)((u32 *)ptr)[-1];
+
+ u8 index = UNK_021C4D28.unk10[heap_id];
+
+ FUN_020ADE2C(UNK_021C4D28.unk00[index], ptr - 16, param1);
+ return;
+ }
+ ErrorHandling();
+}
+
+THUMB_FUNC u32 FUN_02016B90(u32 param0)
+{
+#pragma unused(param0)
+ return 1;
+}
diff --git a/arm9/src/scrcmd.c b/arm9/src/scrcmd.c
new file mode 100644
index 00000000..9e6a337a
--- /dev/null
+++ b/arm9/src/scrcmd.c
@@ -0,0 +1,556 @@
+#include "scrcmd.h"
+#include "unk_0204639C.h"
+
+extern u16 *GetVarPointer(struct UnkSavStruct80* arg, u16);
+extern u16 VarGet(struct UnkSavStruct80* arg, u16 wk);
+extern void *FUN_02039438(struct UnkSavStruct80* arg, u32 id);
+extern void *CreateScriptContext(struct UnkSavStruct80* arg, u16 id);
+extern u8 FUN_02058448(u32 param0);
+extern void FlagSet(struct UnkSavStruct80 *arg, u16 flag);
+extern void FlagClear(struct UnkSavStruct80 *arg, u16 flag);
+extern u8 FlagCheck(struct UnkSavStruct80 *arg, u16 flag);
+extern void TrainerFlagSet(struct UnkSavStruct80 *arg, u16 flag);
+extern void TrainerFlagClear(struct UnkSavStruct80 *arg, u16 flag);
+extern u8 TrainerFlagCheck(struct UnkSavStruct80 *arg, u16 flag);
+extern void MOD05_ShowMessageInField(struct ScriptContext *ctx, struct MsgData *msgData, u16 id);
+extern void MOD05_021E2BD0(struct ScriptContext *ctx, struct MsgData *msgData, u16 msgId, u32 param4, void *param5);
+extern void MOD05_021E2C58(struct ScriptContext *ctx, u16 typ, u16 id, u16 word1, s16 word2, u8 param5);
+extern struct ScrStrBufs *MOD06_02244210(struct SaveBlock2 *sav, u16 poke, u16 sex, u8 flag, u8 *unk);
+extern void MOD05_021E2CBC(struct ScriptContext *ctx, struct ScrStrBufs *str, u8 param2, u32 param3);
+extern void MOD05_021E2BB8(void *param0, struct ScriptContext *ctx);
+extern BOOL FUN_020546C8(u8 param0);
+
+static BOOL RunPauseTimer(struct ScriptContext* ctx);
+static u32 Compare(u16 a, u16 b);
+static BOOL FUN_02039CC8(struct ScriptContext* ctx);
+/*static*/ BOOL FUN_0203A2F0(struct ScriptContext* ctx);
+
+extern u8 sScriptConditionTable[6][3];
+
+THUMB_FUNC BOOL ScrCmd_Nop(struct ScriptContext* ctx)
+{
+#pragma unused(ctx)
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Dummy(struct ScriptContext* ctx)
+{
+#pragma unused(ctx)
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_End(struct ScriptContext* ctx)
+{
+ StopScript(ctx);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Wait(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80* arg = ctx->unk80;
+ u16 num = ScriptReadHalfword(ctx);
+ u16 wk = ScriptReadHalfword(ctx);
+ u16* VarPointer = GetVarPointer(arg, wk);
+ *VarPointer = num;
+ ctx->data[0] = wk;
+ SetupNativeScript(ctx, RunPauseTimer);
+ return TRUE;
+}
+
+THUMB_FUNC static BOOL RunPauseTimer(struct ScriptContext* ctx)
+{
+ u16* VarPointer = GetVarPointer(ctx->unk80, (u16)ctx->data[0]);
+ *VarPointer = (u16)(*VarPointer - 1);
+ return !(*VarPointer);
+}
+
+THUMB_FUNC BOOL ScrCmd_DebugWatch(struct ScriptContext* ctx)
+{
+ u16 wk = ScriptReadHalfword(ctx);
+ VarGet(ctx->unk80, wk);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_LoadByte(struct ScriptContext* ctx)
+{
+ u8 index = ScriptReadByte(ctx);
+ ctx->data[index] = ScriptReadByte(ctx);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_LoadWord(struct ScriptContext* ctx)
+{
+ u8 index = ScriptReadByte(ctx);
+ ctx->data[index] = ScriptReadWord(ctx);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_LoadByteFromAddr(struct ScriptContext* ctx)
+{
+ u8 index = ScriptReadByte(ctx);
+ ctx->data[index] = *(u8 *)ScriptReadWord(ctx);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_WriteByteToAddr(struct ScriptContext* ctx)
+{
+ u8* ptr = (u8*)ScriptReadWord(ctx);
+ *ptr = ScriptReadByte(ctx);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_SetPtrByte(struct ScriptContext* ctx)
+{
+ u8* ptr = (u8*)ScriptReadWord(ctx);
+ *ptr = (u8)ctx->data[ScriptReadByte(ctx)];
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CopyLocal(struct ScriptContext* ctx)
+{
+ u8 index_store = ScriptReadByte(ctx);
+ u8 index_load = ScriptReadByte(ctx);
+ ctx->data[index_store] = ctx->data[index_load];
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CopyByte(struct ScriptContext* ctx)
+{
+ u8 *target = (u8 *)ScriptReadWord(ctx);
+ u8 *source = (u8 *)ScriptReadWord(ctx);
+ *target = *source;
+ return FALSE;
+}
+
+THUMB_FUNC static u32 Compare(u16 a, u16 b)
+{
+ if (a < b)
+ {
+ return 0;
+ }
+ else if (a == b)
+ {
+ return 1;
+ }
+ else
+ {
+ return 2;
+ }
+}
+
+THUMB_FUNC BOOL ScrCmd_CompareLocalToLocal(struct ScriptContext* ctx)
+{
+ u8 a = (u8)ctx->data[ScriptReadByte(ctx)];
+ u8 b = (u8)ctx->data[ScriptReadByte(ctx)];
+ ctx->comparisonResult = (u8)Compare(a, b);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CompareLocalToValue(struct ScriptContext* ctx)
+{
+ u8 a = (u8)ctx->data[ScriptReadByte(ctx)];
+ u8 b = ScriptReadByte(ctx);
+ ctx->comparisonResult = (u8)Compare(a, b);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CompareLocalToAddr(struct ScriptContext* ctx)
+{
+ u8 a = (u8)ctx->data[ScriptReadByte(ctx)];
+ u8 b = *(u8*)ScriptReadWord(ctx);
+ ctx->comparisonResult = (u8)Compare(a, b);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CompareAddrToLocal(struct ScriptContext* ctx)
+{
+ u8 a = *(u8*)ScriptReadWord(ctx);
+ u8 b = (u8)ctx->data[ScriptReadByte(ctx)];
+ ctx->comparisonResult = (u8)Compare(a, b);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CompareAddrToValue(struct ScriptContext* ctx)
+{
+ u8 a = *(u8*)ScriptReadWord(ctx);
+ u8 b = (u8)ScriptReadByte(ctx);
+ ctx->comparisonResult = (u8)Compare(a, b);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CompareAddrToAddr(struct ScriptContext* ctx)
+{
+ u8 a = *(u8*)ScriptReadWord(ctx);
+ u8 b = *(u8*)ScriptReadWord(ctx);
+ ctx->comparisonResult = (u8)Compare(a, b);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CompareVarToValue(struct ScriptContext* ctx)
+{
+ u16 a = *GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 b = ScriptReadHalfword(ctx);
+ ctx->comparisonResult = (u8)Compare(a, b);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CompareVarToVar(struct ScriptContext* ctx)
+{
+ u16 *a = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 *b = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ ctx->comparisonResult = (u8)Compare(*a, *b);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_RunScript(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80* unk80 = ctx->unk80;
+ u8 *unk1 = (u8 *)FUN_02039438(unk80, 0x7);
+ u32 **unk2 = (u32 **)FUN_02039438(unk80, 0xe);
+ u16 id = ScriptReadHalfword(ctx);
+
+ *unk2 = CreateScriptContext(unk80, id);
+ *unk1 = (u8)(*unk1 + 1);
+ return TRUE;
+}
+
+THUMB_FUNC BOOL ScrCmd_RunScriptWait(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80* unk80 = ctx->unk80;
+ u8 *unk1 = (u8 *)FUN_02039438(unk80, 0x5);
+ u8 *unk2 = (u8 *)FUN_02039438(unk80, 0x7);
+ u32 **unk3 = (u32 **)FUN_02039438(unk80, 0xe);
+
+ u16 id = ScriptReadHalfword(ctx);
+ *unk1 = 1;
+ *unk3 = CreateScriptContext(unk80, id);
+ *unk2 = (u8)(*unk2 + 1);
+
+ SetupNativeScript(ctx, FUN_02039CC8);
+ return TRUE;
+}
+
+THUMB_FUNC static BOOL FUN_02039CC8(struct ScriptContext* ctx)
+{
+ u8* unk = FUN_02039438(ctx->unk80, 0x5);
+
+ if (*unk == 0)
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_RestartCurrentScript(struct ScriptContext* ctx)
+{
+ u8* unk = (u8 *)FUN_02039438(ctx->unk80, 0x5);
+
+ *unk = 0;
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_GoTo(struct ScriptContext* ctx)
+{
+ s32 offset = (s32)ScriptReadWord(ctx);
+ ScriptJump(ctx, ctx->scriptPtr + offset);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_ObjectGoTo(struct ScriptContext* ctx)
+{
+ u32* unk = FUN_02039438(ctx->unk80, 0xa);
+ u8 id = ScriptReadByte(ctx);
+ s32 offset = (s32)ScriptReadWord(ctx);
+ if (FUN_02058448(*unk) == id)
+ {
+ ScriptJump(ctx, ctx->scriptPtr + offset);
+ }
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_BgGoTo(struct ScriptContext* ctx)
+{
+ u32 bgId = FUN_02046534(ctx->unk74);
+ u8 id = ScriptReadByte(ctx);
+ s32 offset = (s32)ScriptReadWord(ctx);
+
+ if (bgId == id)
+ {
+ ScriptJump(ctx, ctx->scriptPtr + offset);
+ }
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_DirectionGoTo(struct ScriptContext* ctx)
+{
+ u32 *playerDirection = FUN_02039438(ctx->unk80, 0x9);
+ u8 dir = ScriptReadByte(ctx);
+ s32 offset = (s32)ScriptReadWord(ctx);
+
+ if (*playerDirection == dir)
+ {
+ ScriptJump(ctx, ctx->scriptPtr + offset);
+ }
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Call(struct ScriptContext* ctx)
+{
+ s32 offset = (s32)ScriptReadWord(ctx);
+ ScriptCall(ctx, ctx->scriptPtr + offset);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Return(struct ScriptContext* ctx)
+{
+ ScriptReturn(ctx);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_GoToIf(struct ScriptContext* ctx)
+{
+ u8 compareType = ScriptReadByte(ctx);
+ s32 offset = (s32)ScriptReadWord(ctx);
+
+ if (sScriptConditionTable[compareType][ctx->comparisonResult] == TRUE)
+ {
+ ScriptJump(ctx, ctx->scriptPtr + offset);
+ }
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CallIf(struct ScriptContext* ctx)
+{
+ u8 compareType = ScriptReadByte(ctx);
+ s32 offset = (s32)ScriptReadWord(ctx);
+
+ if (sScriptConditionTable[compareType][ctx->comparisonResult] == TRUE)
+ {
+ ScriptCall(ctx, ctx->scriptPtr + offset);
+ }
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_SetFlag(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80 *unk80 = ctx->unk80;
+ u16 flag = ScriptReadHalfword(ctx);
+ FlagSet(unk80, flag);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_ClearFlag(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80 *unk80 = ctx->unk80;
+ u16 flag = ScriptReadHalfword(ctx);
+ FlagClear(unk80, flag);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CheckFlag(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80 *unk80 = ctx->unk80;
+ u16 flag = ScriptReadHalfword(ctx);
+ ctx->comparisonResult = FlagCheck(unk80, flag);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CheckFlagVar(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80 *unk80 = ctx->unk80;
+ u16 *wk1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 *wk2 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ *wk2 = FlagCheck(unk80, *wk1);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_SetFlagVar(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80 *unk80 = ctx->unk80;
+ u16 *wk = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ FlagSet(unk80, *wk);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_SetTrainerFlag(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80 *unk80 = ctx->unk80;
+ u16 flag = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ TrainerFlagSet(unk80, flag);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_ClearTrainerFlag(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80 *unk80 = ctx->unk80;
+ u16 flag = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ TrainerFlagClear(unk80, flag);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CheckTrainerFlag(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80 *unk80 = ctx->unk80;
+ u16 flag = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ ctx->comparisonResult = TrainerFlagCheck(unk80, flag);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_AddVar(struct ScriptContext* ctx)
+{
+ u16 *wk1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 wk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ *wk1 = (u16)(*wk1 + wk2);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_SubVar(struct ScriptContext* ctx)
+{
+ u16 *wk1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 wk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ *wk1 = (u16)(*wk1 - wk2);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_SetVar(struct ScriptContext* ctx)
+{
+ u16 *wk = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ *wk = ScriptReadHalfword(ctx);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_CopyVar(struct ScriptContext* ctx)
+{
+ u16 *wk1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 *wk2 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ *wk1 = *wk2;
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_SetOrCopyVar(struct ScriptContext* ctx)
+{
+ u16 *wk1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 wk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ *wk1 = wk2;
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Message(struct ScriptContext* ctx)
+{
+ u8 id = ScriptReadByte(ctx);
+ MOD05_ShowMessageInField(ctx, ctx->msgData, id);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_MessageFrom(struct ScriptContext* ctx)
+{
+ u16 arc = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 msg = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ struct MsgData *msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, arc, 32);
+ MOD05_ShowMessageInField(ctx, msgData, msg);
+ DestroyMsgData(msgData);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_MessageFrom2(struct ScriptContext* ctx)
+{
+ u16 arc = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 msg = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ struct MsgData *msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, arc, 32);
+ MOD05_021E2BD0(ctx, msgData, msg, 1, NULL);
+ DestroyMsgData(msgData);
+ SetupNativeScript(ctx, FUN_0203A2F0);
+ return TRUE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Unk01FC(struct ScriptContext* ctx)
+{
+ u16 typ = ScriptReadHalfword(ctx);
+ u16 id = ScriptReadHalfword(ctx);
+ u16 word1 = ScriptReadHalfword(ctx);
+ s16 word2 = (s16)ScriptReadHalfword(ctx);
+
+ MOD05_021E2C58(ctx, typ, id, word1, word2, 0xff);
+ return FALSE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Unk01FD(struct ScriptContext* ctx)
+{
+ u16 typ = ScriptReadHalfword(ctx);
+ u16 id = ScriptReadHalfword(ctx);
+ u16 word1 = ScriptReadHalfword(ctx);
+ s16 word2 = (s16)ScriptReadHalfword(ctx);
+
+ MOD05_021E2C58(ctx, typ, id, word1, word2, 1);
+ SetupNativeScript(ctx, FUN_0203A2F0);
+ return TRUE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Unk01FE(struct ScriptContext* ctx)
+{
+ u8 id = ScriptReadByte(ctx);
+
+ if (ctx->unk80->unkA8 == NULL)
+ {
+ return FALSE;
+ }
+
+ u16 *unkArr = ctx->unk80->unkA8->unk90[id].unk0;
+ if (unkArr[0] == 0xFFFF)
+ {
+ struct MsgData *msgdata = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 0x22b, 32);
+ MOD05_021E2BD0(ctx, msgdata, unkArr[1], 1, NULL);
+ DestroyMsgData(msgdata);
+ }
+ else
+ {
+ MOD05_021E2C58(ctx, unkArr[0], unkArr[1], unkArr[2], (s16)unkArr[3], 1);
+ }
+ SetupNativeScript(ctx, FUN_0203A2F0);
+ return TRUE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Unk01FF(struct ScriptContext* ctx)
+{
+ struct UnkSavStruct80 *unk80 = ctx->unk80;
+ u8 msg = ScriptReadByte(ctx);
+ u16 poke = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
+ u16 sex = ScriptReadHalfword(ctx);
+ u8 flag = ScriptReadByte(ctx);
+ u8 unk = 0;
+
+ struct ScrStrBufs *str = MOD06_02244210(unk80->saveBlock2, poke, sex, flag, &unk);
+ MOD05_021E2CBC(ctx, str, (u8)(msg + unk), 1);
+ ScrStrBufs_delete(str);
+
+ SetupNativeScript(ctx, FUN_0203A2F0);
+ return TRUE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Unk026D(struct ScriptContext* ctx) //message unown font?
+{
+ struct UnkStruct_0203A288 myLocalStruct;
+ u16 msg = ScriptReadHalfword(ctx);
+
+ MOD05_021E2BB8(&myLocalStruct, ctx);
+ myLocalStruct.unk2 = 3;
+
+ MOD05_021E2BD0(ctx, ctx->msgData, msg, 0, &myLocalStruct);
+ SetupNativeScript(ctx, FUN_0203A2F0);
+
+ return TRUE;
+}
+
+THUMB_FUNC BOOL ScrCmd_Unk002C(struct ScriptContext* ctx)
+{
+ u8 msg = ScriptReadByte(ctx);
+ MOD05_021E2BD0(ctx, ctx->msgData, msg, 1, NULL);
+ SetupNativeScript(ctx, FUN_0203A2F0);
+ return TRUE;
+}
+
+THUMB_FUNC /*static*/ BOOL FUN_0203A2F0(struct ScriptContext* ctx)
+{
+ u8 *unk = (u8 *)FUN_02039438(ctx->unk80, 3);
+ return FUN_020546C8(*unk);
+}
diff --git a/arm9/src/scrcmd_18_c.c b/arm9/src/scrcmd_18_c.c
index b8bbbcdd..633ad71c 100644
--- a/arm9/src/scrcmd_18_c.c
+++ b/arm9/src/scrcmd_18_c.c
@@ -6,19 +6,19 @@
#include "map_header.h"
#include "scrcmd.h"
-extern u16 VarGet(struct UnkStruct_0204639C* arg, u16 wk);
-extern u16 *GetVarPointer(struct UnkStruct_0204639C* arg, u16);
+extern u16 VarGet(struct UnkSavStruct80* arg, u16 wk);
+extern u16 *GetVarPointer(struct UnkSavStruct80* arg, u16);
extern BOOL GiveMon(u32 heap_id, struct SaveBlock2 * sav2, u16 species, u8 level, u16 item, u32 mapSec, u8 encounterType);
-THUMB_FUNC BOOL ScrCmd_givemon(struct ScriptContext* ctx)
+THUMB_FUNC BOOL ScrCmd_GiveMon(struct ScriptContext* ctx)
{
- u32 mapSec = FUN_02034824(*(ctx->unk80->unk1C));
- struct UnkStruct_0204639C *savePtr = ctx->unk80;
+ u32 mapSec = FUN_02034824(*(ctx->unk80->mapId));
+ struct UnkSavStruct80 *savePtr = ctx->unk80;
u16 species = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
u16 level = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
u16 item = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
u16 * varPtr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
- struct PlayerParty * party = SavArray_PlayerParty_get((struct SaveBlock2 *) savePtr->unkC);
- *varPtr = (u16)GiveMon(11, (struct SaveBlock2 *) savePtr->unkC, species, (u8)level, item, mapSec, 12);
+ struct PlayerParty * party = SavArray_PlayerParty_get(savePtr->saveBlock2);
+ *varPtr = (u16)GiveMon(11, savePtr->saveBlock2, species, (u8)level, item, mapSec, 12);
return FALSE;
}
diff --git a/arm9/src/script.c b/arm9/src/script.c
index a5a5a6e4..d067ac79 100644
--- a/arm9/src/script.c
+++ b/arm9/src/script.c
@@ -27,7 +27,7 @@ THUMB_FUNC u8 SetupBytecodeScript(struct ScriptContext *ctx, const u8 *ptr)
return 1;
}
-THUMB_FUNC void SetupNativeScript(struct ScriptContext *ctx, u8 (*ptr)(struct ScriptContext *))
+THUMB_FUNC void SetupNativeScript(struct ScriptContext *ctx, BOOL (*ptr)(struct ScriptContext *))
{
ctx->mode = 2;
ctx->nativePtr = ptr;
diff --git a/arm9/src/script_buffers.c b/arm9/src/script_buffers.c
index 293c0bac..e9a55051 100644
--- a/arm9/src/script_buffers.c
+++ b/arm9/src/script_buffers.c
@@ -130,7 +130,7 @@ void BufferPlayersName(struct ScrStrBufs * mgr, u32 idx, struct PlayerData * dat
void BufferRivalsName(struct ScrStrBufs * mgr, u32 idx, struct SaveBlock2 * sav2)
{
- u16 * name = FUN_02024EE8(FUN_02024EC0(sav2));
+ u16 * name = GetRivalNamePtr(FUN_02024EC0(sav2));
CopyU16ArrayToString(mgr->tmpbuf, name);
SetStringAsPlaceholder(mgr, idx, mgr->tmpbuf, NULL);
}
diff --git a/arm9/src/trainer_data.c b/arm9/src/trainer_data.c
index a797956c..f161b302 100644
--- a/arm9/src/trainer_data.c
+++ b/arm9/src/trainer_data.c
@@ -22,7 +22,7 @@ void EnemyTrainerSet_Init(struct BattleSetupStruct * enemies, struct SaveBlock2
// FIXME: String formatting in files/msgdata/msg/narc_0559.txt is abnormal.
msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 559, heap_id);
- rivalName = FUN_02024EE8(FUN_02024EC0(sav2));
+ rivalName = GetRivalNamePtr(FUN_02024EC0(sav2));
for (i = 0; i < 4; i++)
{
if (enemies->trainer_idxs[i] != 0)
diff --git a/arm9/src/unk_02015E30.c b/arm9/src/unk_02015E30.c
new file mode 100644
index 00000000..d52fb236
--- /dev/null
+++ b/arm9/src/unk_02015E30.c
@@ -0,0 +1,38 @@
+
+#include "unk_02015E30.h"
+
+extern u64 FUN_02020BF4();
+extern u64 FUN_02020C14(u64 param0);
+
+struct UnkStruct_02015E30 UNK_021C4898;
+
+THUMB_FUNC void FUN_02015E30()
+{
+ UNK_021C4898.unk00 = 0;
+}
+
+THUMB_FUNC void FUN_02015E3C(struct IGT *igt)
+{
+ struct UnkStruct_02015E30 *unk1 = &UNK_021C4898;
+ UNK_021C4898.unk00 = 1;
+ UNK_021C4898.unk10 = 0;
+ UNK_021C4898.unk14 = 0;
+ UNK_021C4898.unk08 = 0;
+ UNK_021C4898.unk04 = igt;
+
+ UNK_021C4898.unk18 = FUN_02020BF4();
+}
+
+THUMB_FUNC void FUN_02015E60()
+{
+ if (UNK_021C4898.unk00 != 0)
+ {
+ u64 res = FUN_02020C14(FUN_02020BF4() - UNK_021C4898.unk18);
+
+ if (UNK_021C4898.unk08 < res)
+ {
+ AddIGTSeconds(UNK_021C4898.unk04, (u32)(res - UNK_021C4898.unk08));
+ UNK_021C4898.unk08 = res;
+ }
+ }
+}
diff --git a/arm9/src/unk_02024E64.c b/arm9/src/unk_02024E64.c
index fc596418..d8682531 100644
--- a/arm9/src/unk_02024E64.c
+++ b/arm9/src/unk_02024E64.c
@@ -5,22 +5,22 @@ extern void FUN_02025484(void *param0);
THUMB_FUNC u32 FUN_02024E64()
{
- return 0x74C;
+ return sizeof(struct UnkStruct_02024E64);
}
-THUMB_FUNC void FUN_02024E6C(void *param0)
+THUMB_FUNC void FUN_02024E6C(struct UnkStruct_02024E64 *param0)
{
- MIi_CpuClearFast(0, param0, 0x74C);
+ MIi_CpuClearFast(0, param0, sizeof(struct UnkStruct_02024E64));
- FUN_020250A4(param0);
+ FUN_020250A4(param0->unk0);
- FUN_02025484(param0 + (7 << 8));
+ FUN_02025484(param0->unk700);
- MIi_CpuClear16(0xFFFF, param0 + 0x724, 8);
- MIi_CpuClear16(0xFFFF, param0 + 0x734, 0xb);
+ MIi_CpuClear16(0xFFFF, param0->rival_name_buf, sizeof(param0->rival_name_buf) / sizeof(u16));
+ MIi_CpuClear16(0xFFFF, param0->unk734, sizeof(param0->unk734) / sizeof(u16));
}
-THUMB_FUNC void *FUN_02024EB4(struct SaveBlock2 *sav2)
+THUMB_FUNC struct UnkStruct_02024E64 *FUN_02024EB4(struct SaveBlock2 *sav2)
{
return SavArray_get(sav2, 0xa);
}
@@ -30,33 +30,33 @@ THUMB_FUNC void *FUN_02024EC0(struct SaveBlock2 *sav2)
return FUN_02022634(sav2, 0xa);
}
-THUMB_FUNC void *FUN_02024ECC(struct SaveBlock2 *sav2)
+THUMB_FUNC struct UnkStruct_02024E64 *FUN_02024ECC(struct SaveBlock2 *sav2)
{
return SavArray_get(sav2, 0xa);
}
THUMB_FUNC void *FUN_02024ED8(struct SaveBlock2 *sav2)
{
- void *res = SavArray_get(sav2, 0xa);
- return res + (7 << 8);
+ struct UnkStruct_02024E64 *res = SavArray_get(sav2, 0xa);
+ return res->unk700;
}
-THUMB_FUNC u16 *FUN_02024EE8(void *buf)
+THUMB_FUNC u16 *GetRivalNamePtr(struct UnkStruct_02024E64 *unk)
{
- return buf + 0x724;
+ return unk->rival_name_buf;
}
-THUMB_FUNC void FUN_02024EF4(u16 *buf, struct String *str)
+THUMB_FUNC void RivalsNameToU16Array(struct UnkStruct_02024E64 *unk, struct String *str)
{
- CopyStringToU16Array(str, buf + 0x392, 8);
+ CopyStringToU16Array(str, unk->rival_name_buf, sizeof(unk->rival_name_buf) / sizeof(u16));
}
-THUMB_FUNC u16 *FUN_02024F0C(void *buf)
+THUMB_FUNC u16 *FUN_02024F0C(struct UnkStruct_02024E64 *unk)
{
- return buf + 0x734;
+ return unk->unk734;
}
-THUMB_FUNC void FUN_02024F18(u16 *buf, struct String *str)
+THUMB_FUNC void FUN_02024F18(struct UnkStruct_02024E64 *unk, struct String *str)
{
- CopyStringToU16Array(str, buf + 0x39A, 0xb);
+ CopyStringToU16Array(str, unk->unk734, sizeof(unk->unk734) / sizeof(u16));
}