summaryrefslogtreecommitdiff
path: root/arm9/src
diff options
context:
space:
mode:
authorMartmists <mail@martmists.com>2020-04-26 17:49:13 +0200
committerGitHub <noreply@github.com>2020-04-26 17:49:13 +0200
commitdaf2b831efe688dd9ee55f549d00a33c16e840ba (patch)
treebdb1765edc0c10ec83f02ded9e9c478d01e241a4 /arm9/src
parentf11bca0db09b9e7f7514f5033fe6c31b6efd05e2 (diff)
parenteb0b544c0678a0e601686fc32b6019b4e893d5f9 (diff)
Merge pull request #27 from PikalaxALT/pikalax_work
Separate build structures for ARM9 and ARM7
Diffstat (limited to 'arm9/src')
-rw-r--r--arm9/src/FUN_02000DF4.c12
-rw-r--r--arm9/src/main.c110
-rw-r--r--arm9/src/script.c163
-rw-r--r--arm9/src/string_util.c153
4 files changed, 438 insertions, 0 deletions
diff --git a/arm9/src/FUN_02000DF4.c b/arm9/src/FUN_02000DF4.c
new file mode 100644
index 00000000..0099480c
--- /dev/null
+++ b/arm9/src/FUN_02000DF4.c
@@ -0,0 +1,12 @@
+#include "global.h"
+#include "main.h"
+
+extern struct Unk2106FA0 gBacklightTop;
+
+void FUN_02000DF4(void)
+{
+ gBacklightTop.unk8 = -1;
+ gBacklightTop.unkC = 0;
+ gBacklightTop.unk10 = -1;
+ gBacklightTop.unk14 = 0;
+}
diff --git a/arm9/src/main.c b/arm9/src/main.c
new file mode 100644
index 00000000..bfd6c82e
--- /dev/null
+++ b/arm9/src/main.c
@@ -0,0 +1,110 @@
+#include "global.h"
+#include "main.h"
+
+extern struct Unk2106FA0 gBacklightTop;
+extern struct Unk2106FA0 gBacklightTop_2; // same as the first one, it's referenced twice in the constant pool...
+extern struct Unk2106FA0 gUnknown2106FB8;
+extern struct Unk21C48B8 gUnknown21C48B8;
+
+extern s32 gUnk027FFC20;
+extern struct {
+ s32 unk0;
+ s32 unk4;
+ u8 unk8;
+} gUnk021C4918;
+
+extern void PM_GetBackLight();
+extern void OS_WaitIrq();
+extern void FUN_02016438(s32);
+
+extern const s32 CONST_3F; // 0x0000003F
+extern const s32 CONST_34; // 0x00000034
+
+extern struct Unk21DBE18 gUnk021DBE18;
+extern struct Unk21DBE18 gUnk021D76C8;
+
+
+void NitroMain(void)
+{
+ InitSystemForTheGame();
+ InitGraphicMemory();
+ FUN_020163BC();
+ FUN_02016438(0);
+
+ PM_GetBackLight(&gBacklightTop_2, 0);
+
+ FUN_02022294();
+ FUN_0201259C();
+ FUN_02000DF4();
+ FUN_02002C14();
+ FUN_02002C50(0, 3);
+ FUN_02002C50(1, 3);
+ FUN_02002C50(3, 3);
+ gBacklightTop.unk18 = -1;
+ gBacklightTop.unk20 = FUN_0202254C();
+ FUN_02003B98(FUN_02029EF8(gBacklightTop.unk20), LoadPlayerDataAddress(gBacklightTop.unk20));
+ FUN_02020AFC();
+ if (FUN_020337E8(3) == 3)
+ FUN_02034188(3, 0);
+ if (FUN_020227FC(gBacklightTop.unk20) == 0)
+ {
+ FUN_02089D90(0);
+ }
+ else
+ {
+ switch (gUnk027FFC20)
+ {
+ case 0:
+ gBacklightTop.unk1C = 0;
+ FUN_02000E7C(&CONST_3F, &gUnk021DBE18);
+ break;
+ case 1:
+ gBacklightTop.unk1C = 1;
+ FUN_02000E7C(&CONST_34, &gUnk021D76C8);
+ break;
+ default:
+ ErrorHandling();
+ break;
+ }
+ }
+ gUnknown21C48B8.unk6C = 1;
+ gUnknown21C48B8.unk30 = 0;
+ FUN_02000FA4();
+ FUN_0200A2AC();
+ FUN_02015E30();
+ gBacklightTop.unk4 = 0;
+ for (;;)
+ {
+ FUN_02000EE8();
+ FUN_02000FE8();
+ FUN_02016464();
+ if ((gUnknown21C48B8.unk38 & 0x30C) == 0x30C && !gUnk021C4918.unk8) // soft reset?
+ {
+ FUN_02000F18(0); // soft reset?
+ }
+ if (FUN_0202FB80())
+ {
+ FUN_02000E0C();
+ FUN_0201B5CC(gUnknown21C48B8.unk18);
+ FUN_0201B5CC(gUnknown21C48B8.unk24);
+ if (!gUnknown21C48B8.unk30)
+ {
+ OS_WaitIrq(1, 1);
+ gUnknown21C48B8.unk2C++;
+ }
+ }
+ FUN_020125D4();
+ FUN_02015E60();
+ FUN_020222C4();
+ FUN_0201B5CC(gUnknown21C48B8.unk24);
+ OS_WaitIrq(1, 1);
+ gUnknown21C48B8.unk2C++;
+ gUnknown21C48B8.unk30 = 0;
+ FUN_0200A318();
+ FUN_0200E2D8();
+ if (gUnknown21C48B8.unk0)
+ gUnknown21C48B8.unk0(gUnknown21C48B8.unk4);
+ FUN_02003C10();
+ FUN_0201B5CC(gUnknown21C48B8.unk20);
+ }
+} \ No newline at end of file
diff --git a/arm9/src/script.c b/arm9/src/script.c
new file mode 100644
index 00000000..7a7ae894
--- /dev/null
+++ b/arm9/src/script.c
@@ -0,0 +1,163 @@
+#include "global.h"
+#include "script.h"
+
+u16 ScriptReadHalfword(struct ScriptContext *ctx);
+
+void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, void *cmdTableEnd)
+{
+ u32 i;
+
+ ctx->mode = 0;
+ ctx->scriptPtr = 0;
+ ctx->stackDepth = 0;
+ ctx->nativePtr = 0;
+ ctx->cmdTable = cmdTable;
+ ctx->cmdTableEnd = cmdTableEnd;
+
+ for (i = 0; i < 4; i++)
+ ctx->data[i] = 0;
+
+ for (i = 0; i < 20; i++)
+ ctx->stack[i] = 0;
+
+ ctx->unk74 = 0;
+}
+
+u8 SetupBytecodeScript(struct ScriptContext *ctx, const u8 *ptr)
+{
+ ctx->scriptPtr = ptr;
+ ctx->mode = 1;
+ return 1;
+}
+
+void SetupNativeScript(struct ScriptContext *ctx, u8 (*ptr)(struct ScriptContext *))
+{
+ ctx->mode = 2;
+ ctx->nativePtr = ptr;
+}
+
+void StopScript(struct ScriptContext *ctx)
+{
+ ctx->mode = 0;
+ ctx->scriptPtr = 0;
+}
+
+void FUN_02038B6C(struct ScriptContext *ctx, int r1)
+{
+ ctx->unk74 = r1;
+}
+
+extern void ErrorHandling(void);
+
+u8 RunScriptCommand(struct ScriptContext *ctx)
+{
+ if (ctx->mode == 0)
+ return FALSE;
+
+ switch (ctx->mode)
+ {
+ case 0:
+ return FALSE;
+ case 2:
+ if (ctx->nativePtr)
+ {
+ if (ctx->nativePtr(ctx) == TRUE)
+ ctx->mode = 1;
+ return TRUE;
+ }
+ ctx->mode = 1;
+ case 1:
+ while (1)
+ {
+ u16 cmdCode;
+ ScrCmdFunc *func;
+
+ if (!ctx->scriptPtr)
+ {
+ ctx->mode = 0;
+ return FALSE;
+ }
+
+ cmdCode = ScriptReadHalfword(ctx);
+ u32 cmdTableEnd = (u32)ctx->cmdTableEnd;
+ if (cmdCode >= cmdTableEnd)
+ {
+ ErrorHandling();
+ ctx->mode = 0;
+ return FALSE;
+ }
+
+ func = &ctx->cmdTable[cmdCode];
+
+ if ((*func)(ctx) == 1)
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+u8 ScriptPush(struct ScriptContext *ctx, const u8 *ptr)
+{
+ if (ctx->stackDepth + 1 >= 20)
+ {
+ return 1;
+ }
+ else
+ {
+ ctx->stack[ctx->stackDepth] = ptr;
+ ctx->stackDepth++;
+ return 0;
+ }
+}
+
+const u8 *ScriptPop(struct ScriptContext *ctx)
+{
+ if (ctx->stackDepth == 0)
+ return NULL;
+
+ ctx->stackDepth--;
+ return ctx->stack[ctx->stackDepth];
+}
+
+void ScriptJump(struct ScriptContext *ctx, const u8 *ptr)
+{
+ ctx->scriptPtr = ptr;
+}
+
+u8 ScriptCall(struct ScriptContext *ctx, const u8 *ptr)
+{
+ u8 ret = ScriptPush(ctx, ctx->scriptPtr);
+ ctx->scriptPtr = ptr;
+ return ret;
+}
+
+void ScriptReturn(struct ScriptContext *ctx)
+{
+ ctx->scriptPtr = ScriptPop(ctx);
+}
+
+u16 ScriptReadHalfword(struct ScriptContext *ctx)
+{
+ u16 value = *(ctx->scriptPtr++);
+ value += *(ctx->scriptPtr++) << 8;
+ return value;
+}
+
+u32 ScriptReadWord(struct ScriptContext *ctx)
+{
+ u32 value0 = *(ctx->scriptPtr++);
+ u32 value1 = *(ctx->scriptPtr++);
+ u32 value2 = *(ctx->scriptPtr++);
+ u32 value3 = *(ctx->scriptPtr++);
+ u32 retVal = 0;
+
+ retVal += value3;
+ retVal <<= 8;
+ retVal += value2;
+ retVal <<= 8;
+ retVal += value1;
+ retVal <<= 8;
+ retVal += value0;
+ return retVal;
+}
diff --git a/arm9/src/string_util.c b/arm9/src/string_util.c
new file mode 100644
index 00000000..8f9c96ff
--- /dev/null
+++ b/arm9/src/string_util.c
@@ -0,0 +1,153 @@
+#include "global.h"
+
+u16 gDigitTable[] = {
+ 0xA2,
+ 0xA3,
+ 0xA4,
+ 0xA5,
+ 0xA6,
+ 0xA7,
+ 0xA8,
+ 0xA9,
+ 0xAA,
+ 0xAB,
+ 0xAC,
+ 0xAD,
+ 0xAE,
+ 0xAF,
+ 0xB0,
+ 0xB1
+};
+
+s32 gPowersOfTen[] = {
+ 1,
+ 10,
+ 100,
+ 1000,
+ 10000,
+ 100000,
+ 1000000,
+ 10000000,
+ 100000000,
+ 1000000000,
+};
+
+static const u16 EOS = 0xFFFF;
+
+void StringCopy(u16 *dest, const u16 *src)
+{
+ u16 c = *src;
+ while (c != EOS) {
+ src++;
+ *dest = c;
+ c = *src;
+ dest++;
+ }
+ *dest = EOS;
+}
+
+u16 *StringCopyN(u16 *dest, const u16 *src, u32 num)
+{
+ u32 copied = 0;
+ if (num > copied) {
+ u16 *p = dest;
+ do {
+ u16 c = *src;
+ copied++;
+ src++;
+ *p = c;
+ p++;
+ } while (num > copied);
+ }
+ return dest + num;
+}
+
+u32 StringLength(const u16 *s)
+{
+ u16 c = *s;
+ u32 len = 0;
+ while (c != EOS) {
+ s++;
+ c = *s;
+ len++;
+ }
+ return len;
+}
+
+BOOL StringNotEqual(const u16 *s1, const u16 *s2)
+{
+ for (; *s1 == *s2; s1++, s2++) {
+ if (*s1 == EOS)
+ return FALSE;
+ }
+ return TRUE;
+}
+
+BOOL StringNotEqualN(const u16 *s1, const u16 *s2, u32 num)
+{
+ u16 c1, c2;
+ c2 = *s2;
+ c1 = *s1;
+ while (c1 == c2) {
+ if (num == 0) {
+ return FALSE;
+ }
+ if (*s1 == EOS && *s2 == EOS) {
+ return FALSE;
+ }
+ s1++;
+ s2++;
+ c2 = *s2;
+ c1 = *s1;
+ num--;
+ }
+ return TRUE;
+}
+
+u16 *StringFill(u16 *dest, u16 value, u32 num)
+{
+ u32 copied = 0;
+ if (num > copied) {
+ u16 *p = dest;
+ do {
+ copied++;
+ *p = value;
+ p++;
+ } while (copied < num);
+ }
+ return dest + copied;
+}
+
+u16 *StringFillEOS(u16 *dest, u32 num)
+{
+ return StringFill(dest, EOS, num);
+}
+
+enum PrintingMode {
+ NORMAL,
+ PAD_SPACE,
+ PAD_ZEROES
+};
+
+const u16 NON_DIGIT = 0xE2;
+
+u16 *ConvertUIntToDecimalString(u16 *dest, u32 value, enum PrintingMode mode, u32 n)
+{
+ for (u32 x = gPowersOfTen[n - 1]; x != 0; x = x / 10) {
+ u16 res = value / x;
+ value = value - x * res;
+ if (mode == PAD_ZEROES) {
+ *dest = res >= 10 ? NON_DIGIT : gDigitTable[res];
+ dest++;
+ } else if (res != 0 || x == 1) {
+ mode = PAD_ZEROES;
+ *dest = res >= 10 ? NON_DIGIT : gDigitTable[res];
+ dest++;
+ } else if (mode == PAD_SPACE) {
+ *dest = 1;
+ dest++;
+ }
+ }
+ *dest = EOS;
+ return dest;
+}