diff --git a/include/xquack.h b/include/xquack.h new file mode 100644 index 0000000..836f92a --- /dev/null +++ b/include/xquack.h @@ -0,0 +1,11 @@ +#include "common.h" + +s32 func_001EE090(); +void func_001EE0B8(s32, s32, s32, s32, s32, s32, s32, s32); +void* func_001EE330(s32, s32, s32, s32, s32); +void* func_001EE428(s32, s32, s32, s32, s32); +void* func_001EE478(s32, s32, s32, s32, s32); +void* func_001EE570(); +void* func_001EE5D8(s32); +void* func_001EE660(void*); +void* func_001EE6B8(void*); diff --git a/kh.jp.yaml b/kh.jp.yaml index 2d055f2..9764a1d 100644 --- a/kh.jp.yaml +++ b/kh.jp.yaml @@ -40,7 +40,8 @@ segments: - [0x11120, c, xtrumpet] - [0x11FC0, c, xspinach] - [0x121E8, asm] - - [0x1EC48, c, xgoblin] + - [0x1C658, c, xturtle] + - [0x1EB78, c, xgoblin] - [0x1FBE8, c, xkingdom] - [0x20AB8, asm] - [0x3ABE8, c, xapple] diff --git a/src/xgoblin.c b/src/xgoblin.c index 1f1d67f..b29d728 100644 --- a/src/xgoblin.c +++ b/src/xgoblin.c @@ -36,6 +36,9 @@ extern UNK_TYPE D_004DD198[]; extern u_long128 D_004DDA00; extern s32 D_004DDC00; +// Loads several modules +INCLUDE_ASM(const s32, "xgoblin", func_0011EAF8); + s32 func_0011EBC8(void) { func_00122250(); return 0; diff --git a/src/xquack.c b/src/xquack.c index 52c11ab..293d36b 100644 --- a/src/xquack.c +++ b/src/xquack.c @@ -1,11 +1,26 @@ #include "common.h" +#include "xquack.h" #include "eekernel.h" #include "sifrpc.h" +typedef struct XDuck { + /* 0x00 */ u8 unk_00; + /* 0x00 */ s8 unk_01; + /* 0x02 */ s8 unk_02; + /* 0x03 */ s8 unk_03; + /* 0x04 */ s8 unk_04; + /* 0x05 */ char unk_05[11]; + /* 0x10 */ s32 unk_10; + /* 0x14 */ char unk_14[4]; + /* 0x18 */ s32 unk_18; + /* 0x1C */ char unk_1C[0x2C]; +} XDuck; // size = 0x48 + s32 D_003DE5B8; sceSifClientData D_003DE5C0; void* D_0062D980; +XDuck D_00639180[3]; s32 D_00639588; s32 D_00639880; @@ -41,9 +56,28 @@ INCLUDE_ASM(const s32, "xquack", func_001EDD20); INCLUDE_ASM(const s32, "xquack", func_001EDDC0); -INCLUDE_ASM(const s32, "xquack", func_001EDF28); +void* func_001EDF28(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + if (!(D_003DE5B8 & 8)) { + func_001EE0B8(41, arg0, arg1, arg2, arg3, 0, 0, 0); + return D_0062D980; + } + return D_0062D980; +} -INCLUDE_ASM(const s32, "xquack", func_001EDF88); +s32 func_001EDF88(s32 arg0) { + XDuck* p0; + s32 i; + + FlushCache(WRITEBACK_DCACHE); + p0 = D_00639180; + + for (i = 0; i <= ARRAY_COUNT(D_00639180); i++, p0++) { + if (p0->unk_04 != 0 && p0->unk_10 == arg0) { + return p0->unk_18; + } + } + return 0; +} INCLUDE_ASM(const s32, "xquack", func_001EDFF8); @@ -65,53 +99,87 @@ void* func_001EE188(void* arg0) { return D_0062D980; } -void* func_001EE1E0(void* arg0, void* arg1) { +void* func_001EE1E0(s32 arg0, s32 arg1) { func_001EE0B8(38, arg0, arg1, 0, 0, 0, 0, 0); return D_0062D980; } -INCLUDE_ASM(const s32, "xquack", func_001EE228); +void* func_001EE228(void* arg0) { + D_0062D980 = arg0; + sceSifCallRpc(&D_003DE5C0, 39, 0, &D_0062D980, 0x2000, &D_0062D980, 0x2000, NULL, NULL); -INCLUDE_ASM(const s32, "xquack", func_001EE280); + return D_0062D980; +} -void* func_001EE2D8(void* arg0, void* arg1, void* arg2) { +void* func_001EE280(void* arg0) { + D_0062D980 = arg0; + sceSifCallRpc(&D_003DE5C0, 15, 0, &D_0062D980, 0x2000, &D_0062D980, 0x2000, NULL, NULL); + + return D_0062D980; +} + +void* func_001EE2D8(s32 arg0, s32 arg1, s32 arg2) { D_00639880++; func_001EE0B8(4, arg0, arg1, arg2, 0, 0, 0, 0); return D_0062D980; } -INCLUDE_ASM(const s32, "xquack", func_001EE330); +void* func_001EE330(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + if (!(D_003DE5B8 & 2)) { + func_001EE0B8(5, arg0, arg1, arg2, arg3, arg4, 0, 0); + return D_0062D980; + } + return D_0062D980; +} -INCLUDE_ASM(const s32, "xquack", func_001EE390); +void* func_001EE390(s32 arg0, s32 arg1, s32 arg2) { + func_001EE0B8(6, arg0, arg1, arg2, 0, 0, 0, 0); + return D_0062D980; +} -INCLUDE_ASM(const s32, "xquack", func_001EE3D8); +void* func_001EE3D8(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + func_001EE0B8(2, arg0, arg1, arg2, arg3, 0, 0, 0); + return D_0062D980; +} -void* func_001EE428(void* arg0, void* arg1, void* arg2, s32 arg3, s32 arg4) { +void* func_001EE428(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { func_001EE0B8(7, arg0, arg1, arg2, arg3, arg4, 0, 0); return D_0062D980; } -void* func_001EE478(void* arg0, void* arg1, void* arg2, s32 arg3, s32 arg4) { +void* func_001EE478(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { func_001EE0B8(8, arg0, arg1, arg2, arg3, arg4, 0, 0); return D_0062D980; } -INCLUDE_ASM(const s32, "xquack", func_001EE4C8); +void* func_001EE4C8(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + func_001EE0B8(9, arg0, arg1, arg2, arg3, 0, 0, 0); + return D_0062D980; +} -void* func_001EE518(void* arg0, void* arg1, void* arg2) { +void* func_001EE518(s32 arg0, s32 arg1, s32 arg2) { D_00639880++; func_001EE0B8(11, arg0, arg1, arg2, 0, 0, 0, 0); return D_0062D980; } -INCLUDE_ASM(const s32, "xquack", func_001EE570); +void* func_001EE570(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5) { + if (!(D_003DE5B8 & 1)) { + func_001EE0B8(12, arg0, arg1, arg2, arg3, arg4, arg5, 0); + return D_0062D980; + } + return D_0062D980; +} -void* func_001EE5D8(void* arg0) { +void* func_001EE5D8(s32 arg0) { func_001EE0B8(13, arg0, 0, 0, 0, 0, 0, 0); return D_0062D980; } -INCLUDE_ASM(const s32, "xquack", func_001EE618); +void* func_001EE618(s32 arg0, s32 arg1, s32 arg2) { + func_001EE0B8(14, arg0, arg1, arg2, 0, 0, 0, 0); + return D_0062D980; +} void* func_001EE660(void* arg0) { D_0062D980 = arg0; @@ -125,30 +193,39 @@ void* func_001EE6B8(void* arg0) { return D_0062D980; } -void* func_001EE710(void* arg0, void* arg1, void* arg2) { +void* func_001EE710(s32 arg0, s32 arg1, s32 arg2) { D_00639880++; func_001EE0B8(3, arg0, arg1, arg2, 0, 0, 0, 0); return D_0062D980; } -void* func_001EE768(void* arg0) { +void* func_001EE768(s32 arg0) { func_001EE0B8(19, arg0, 0, 0, 0, 0, 0, 0); return D_0062D980; } -INCLUDE_ASM(const s32, "xquack", func_001EE7A8); +void* func_001EE7A8(s32 arg0, s32 arg1, s32 arg2) { + func_001EE0B8(20, arg0, arg1, arg2, 0, 0, 0, 0); + return D_0062D980; +} -INCLUDE_ASM(const s32, "xquack", func_001EE7F0); +void* func_001EE7F0(s32 arg0, s32 arg1, s32 arg2) { + func_001EE0B8(21, arg0, arg1, arg2, 0, 0, 0, 0); + return D_0062D980; +} -void* func_001EE838(void* arg0, void* arg1, void* arg2) { +void* func_001EE838(s32 arg0, s32 arg1, s32 arg2) { D_00639880++; func_001EE0B8(40, arg0, arg1, arg2, 0, 0, 0, 0); return D_0062D980; } -INCLUDE_ASM(const s32, "xquack", func_001EE890); +void* func_001EE890(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + func_001EE0B8(42, arg0, arg1, arg2, arg3, 0, 0, 0); + return D_0062D980; +} -void* func_001EE8E0(void* arg0, void* arg1) { +void* func_001EE8E0(s32 arg0, s32 arg1) { func_001EE0B8(43, arg0, arg1, 0, 0, 0, 0, 0); return D_0062D980; } diff --git a/src/xturtle.c b/src/xturtle.c new file mode 100644 index 0000000..6a192ce --- /dev/null +++ b/src/xturtle.c @@ -0,0 +1,364 @@ +#include "common.h" +#include "common_funcs.h" +#include "xquack.h" + +typedef struct XTurtle { + /* 0x00 */ char unk_00[0x14]; + /* 0x04 */ char unk_14; +} XTurtle; + +extern s32 D_002A0514; +extern s32 D_002BD8B4; +extern s32 D_002BD8B8[2]; +extern s32 D_002BD8C8; +extern s32 D_002BD8CC; +extern s32 D_002BD8E0; +extern s32 D_002BD8E4; + +extern char D_00486E70[]; +void (*D_004DCB70)(void); +extern s32 D_004DD180; + +XTurtle* func_0011CDD8(s32,s32,s32,s32,s32); + +void* func_0011C5D8() { + return func_001EE570(); +} + +s32 func_0011C5F0() { + return func_001EE618(); +} + +void* func_0011C608(s32 arg0) { + return func_001EE5D8(arg0); +} + +void* func_0011C620(void* arg0) { + return func_001EE660(arg0); +} + +void* func_0011C638(void* arg0) { + return func_001EE6B8(arg0); +} + +s32 func_0011C650() { + return func_001EE090(); +} + +void* func_0011C668(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + return func_001EE330(arg0, arg1, arg2, arg3, arg4); +} + +s32 func_0011C680(s32 arg0, s32 arg1, s32 arg2) { + return func_001EE390(arg0, arg1, arg2); +} + +void* func_0011C698(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + return func_001EE428(arg0, arg1, arg2, arg3, arg4); +} + +void* func_0011C6B0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + return func_001EE478(arg0, arg1, arg2, arg3, arg4); +} + +INCLUDE_ASM(const s32, "xturtle", func_0011C6C8); + +void func_0011C7D0() { + D_004DD180 = 0; +} + +void func_0011C7E0() { + D_004DD180 = 1; +} + +void func_0011C7F0() { + func_0011C7D0(); + func_0011C6C8(0); + func_001EE5D8(0); + func_001EE5D8(1); + func_001EE390(-100, -1, -1); + func_001EE1E0(0, 0); + func_001EE1E0(0, 1); + func_001EE1E0(1, 0); + func_001EE1E0(1, 1); + func_001EE1E0(0, -8); + func_001EE1E0(3, -8); + func_001EE228(10); + func_00113A10(0); + func_001EEC58(); + func_00101528(); +} + +INCLUDE_ASM(const s32, "xturtle", func_0011C898); + +INCLUDE_ASM(const s32, "xturtle", func_0011C938); + +s32 func_0011C9B0(void* arg0) { + return func_00120438(D_00486E70, arg0); // in xkingdom.c +} + +s32 func_0011C9D0() { + if (func_001EE090()) { + return 0; + } + + if (D_004DCB70 != NULL) { + D_004DCB70(); + } + + return 4; +} + +INCLUDE_ASM(const s32, "xturtle", func_0011CA10); + +INCLUDE_ASM(const s32, "xturtle", func_0011CB50); + +INCLUDE_ASM(const s32, "xturtle", func_0011CC20); + +INCLUDE_ASM(const s32, "xturtle", func_0011CDB8); + +INCLUDE_ASM(const s32, "xturtle", func_0011CDD8); + +INCLUDE_ASM(const s32, "xturtle", func_0011CE58); + +void func_0011CEB0(s32 arg0, s32 arg1) { + s32 val = arg0 < 1000 ? 2 : -8; + + func_0011C668(val, arg0, arg1, 0x3FFF, 0x3FFF); + func_0011CE58(arg0, arg1); +} + +s32 func_0011CF08(s32 arg0, s32 arg1) { + s32 val = arg0 < 1000 ? 2 : -8; + + return func_0011C680(val, arg0, arg1); +} + +void* func_0011CF38(s32 arg0, s32 arg1, s32 arg2) { + s32 val = arg0 < 1000 ? 2 : -8; + + return func_0011C698(val, arg0, arg1, -1, arg2); +} + +void* func_0011CF70(s32 arg0, s32 arg1) { + s32 val = arg0 < 1000 ? 2 : -1; + + return func_0011C668(val, arg0, arg1, 0x3FFF, 0x3FFF); +} + +s32 func_0011CFA8(s32 arg0, s32 arg1) { + s32 val = arg0 < 1000 ? 2 : -1; + + return func_0011C680(val, arg0, arg1); +} + +void* func_0011CFD8(s32 arg0, s32 arg1, s32 arg2) { + s32 val = arg0 < 1000 ? 2 : -1; + + return func_0011C698(val, arg0, arg1, -1, arg2); +} + +void func_0011D010(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + XTurtle* bleb = func_0011CDD8(arg0, arg1, arg2, arg3, 0); + + if (bleb != NULL) { + bleb->unk_14 = 1; + } +} + +void func_0011D040(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + XTurtle* bleb = func_0011CDD8(arg0, arg1, arg2, arg3, 1); + + if (bleb != NULL) { + bleb->unk_14 = 2; + } +} + +void func_0011D070(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + XTurtle* bleb = func_0011CDD8(arg0, arg1, arg2, arg3, 2); + + if (bleb != NULL) { + bleb->unk_14 = 1; + } +} + +void func_0011D0A0(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + XTurtle* bleb = func_0011CDD8(arg0, arg1, arg2, arg3, 3); + + if (bleb != NULL) { + bleb->unk_14 = 2; + } +} + +void func_0011D0D0(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + XTurtle* bleb = func_0011CDD8(arg0, arg1, arg2, arg3, 4); + + if (bleb != NULL) { + bleb->unk_14 = 2; + } +} + +INCLUDE_ASM(const s32, "xturtle", func_0011D100); + +INCLUDE_ASM(const s32, "xturtle", func_0011D180); + +INCLUDE_ASM(const s32, "xturtle", func_0011D1F8); + +INCLUDE_ASM(const s32, "xturtle", func_0011D278); + +INCLUDE_ASM(const s32, "xturtle", func_0011D310); + +INCLUDE_ASM(const s32, "xturtle", func_0011D3B8); + +INCLUDE_ASM(const s32, "xturtle", func_0011D420); + +INCLUDE_ASM(const s32, "xturtle", func_0011D4B8); + +INCLUDE_ASM(const s32, "xturtle", func_0011D520); + +void* func_0011D598(s32 arg0) { + return func_0011C668(2, arg0, 0, 0x3FFF, 0x3FFF); +} + +void* func_0011D5C0(s32 arg0, s32 arg1) { + s32 val = 0x3FFF; + if (arg1 != 0) { + val = 0x1FFF; + } + + return func_0011C6B0(2, arg0, 0, val, val); +} + +s32 func_0011D5F0(s32 arg0) { + return func_0011C680(2, arg0, 0); +} + +INCLUDE_ASM(const s32, "xturtle", func_0011D610); + +void func_0011D978(s32* arg0, s32* arg1) { + s32 val; + + if (*arg0 < 0) { + *arg0 = 0; + } + if (*arg1 < 0) { + *arg1 = 0; + } + if (*arg0 < 0x4000) { + val = *arg1; + } else { + *arg0 = 0x3FFF; + val = *arg1; + } + if (val > 0x3FFF) { + *arg1 = 0x3FFF; + } +} + +void func_0011D9C8(s32* arg0, s32* arg1, s32 arg2, s32 arg3) { + if ((arg3 == 2) && (D_002A0514 != 0)) { + *arg0 = 0; + *arg1 = 0; + } else if (arg2 == 0x3FFF) { + *arg0 = 0x3FFF; + *arg1 = 0x3FFF; + } else { + *arg0 = *arg0 + arg2; + *arg1 = *arg1 + arg2; + func_0011D978(arg0, arg1); + } +} + +INCLUDE_ASM(const s32, "xturtle", func_0011DA50); + +INCLUDE_ASM(const s32, "xturtle", func_0011DAC0); + +INCLUDE_ASM(const s32, "xturtle", func_0011DB18); + +INCLUDE_ASM(const s32, "xturtle", func_0011DBF8); + +INCLUDE_ASM(const s32, "xturtle", func_0011DCB8); + +INCLUDE_ASM(const s32, "xturtle", func_0011DFF0); + +void func_0011E048(s32 arg0) { + func_001EDD20(arg0); + func_0011DFF0(arg0); +} + +INCLUDE_ASM(const s32, "xturtle", func_0011E070); + +s32 func_0011E168(s32 arg0) { + D_002BD8E4 = func_0011E070(arg0); + return D_002BD8E4; +} + +INCLUDE_ASM(const s32, "xturtle", func_0011E190); + +void func_0011E2A8() { + func_0011C5F0(0, 0, 960); + func_0011C5D8(1, 0, 0x3000, 240, 0, 240); + D_002BD8B4 = 1; +} + +INCLUDE_ASM(const s32, "xturtle", func_0011E2F8); + +void func_0011E340() { + D_002BD8E0 = 1; +} + +void func_0011E350() { + D_002BD8E0 = 0; +} + +INCLUDE_ASM(const s32, "xturtle", func_0011E360); + +void func_0011E418() { + func_00101528(); +} + +INCLUDE_ASM(const s32, "xturtle", func_0011E430); + +INCLUDE_ASM(const s32, "xturtle", func_0011E520); +void func_0011E520(); + +INCLUDE_ASM(const s32, "xturtle", func_0011E578); + +s32 func_0011E5E8(UNK_TYPE arg0, UNK_TYPE arg1, s32 arg2) { + return func_0011CA10(0, arg2, D_002BD8C8, func_0011E520); +} + +INCLUDE_ASM(const s32, "xturtle", func_0011E618); +void func_0011E618(); + +s32 func_0011E6C0(UNK_TYPE arg0, UNK_TYPE arg1, s32 arg2) { + return func_0011CA10(1, arg2, D_002BD8CC, func_0011E618); +} + +INCLUDE_ASM(const s32, "xturtle", func_0011E6F0); + +void func_0011E7C8(s32 arg0, void* arg1) { + func_0011E6F0(0, 0x3000, 0, arg0, 0, arg1); +} + +void func_0011E7F8(s32 arg0, s32 arg1, s32 arg2, void* arg3) { + func_0011E6F0(1, arg0, arg1, arg2, 0, arg3); +} + +void func_0011E830(s32 arg0, void* arg1) { + func_0011E6F0(0, 0x3000, 0, arg0, 1, arg1); +} + +INCLUDE_ASM(const s32, "xturtle", func_0011E860); + +INCLUDE_ASM(const s32, "xturtle", func_0011E900); + +void* func_0011E9A8(s32 arg0, s32 arg1, s32 arg2, void* arg3) { + D_002BD8B8[arg0] = -1; + D_004DCB70 = arg3; + func_001EE1E0(1, arg0); + func_001EE518(arg0, arg1, arg2); + return func_0011ED30(10000, func_0011C9D0); +} + +INCLUDE_ASM(const s32, "xturtle", func_0011EA28);