diff --git a/nonmatching/README.md b/nonmatching/README.md index 6390c1e44..45f06b57c 100644 --- a/nonmatching/README.md +++ b/nonmatching/README.md @@ -19,12 +19,9 @@ Best attempts at functions that do not match yet. They are not built; see | [`func_L00_0068AC58`](shared/func_L00_0068AC58.c) | shared | 688 | BYTES 9/684 | | [`func_L41_0040F218`](shared/func_L41_0040F218.c) | shared | 376 | BYTES 5/376 | | [`func_0047D448`](game/func_0047D448.c) | game | 64 | BYTES 1/64 | -| [`func_004D58D0`](game/func_004D58D0.c) | game | 128 | BYTES 2/124 | -| [`func_004D73C8`](game/func_004D73C8.c) | game | 128 | BYTES 2/124 | | [`func_L02_003C56E8`](shared/func_L02_003C56E8.c) | shared | 224 | BYTES 4/224 | | [`func_01EA4940`](net/func_01EA4940.c) | net | 48 | BYTES 1/48 | | [`func_01EC9060`](net/func_01EC9060.c) | net | 92 | BYTES 2/92 | -| [`func_00500F00`](game/func_00500F00.c) | game | 112 | BYTES 3/112 | | [`func_L00_006C69F0`](shared/func_L00_006C69F0.c) | shared | 184 | BYTES 5/180 (4 words differ) | | [`func_L01_00568C08`](shared/func_L01_00568C08.c) | shared | 432 | BYTES 12/428 | | [`func_004B8888`](game/func_004B8888.c) | game | 128 | BYTES 4/124 | @@ -33,7 +30,6 @@ Best attempts at functions that do not match yet. They are not built; see | [`func_004E5550`](game/func_004E5550.c) | game | 64 | BYTES 2/60 | | [`func_L41_003E3060`](shared/func_L41_003E3060.c) | shared | 432 | BYTES 15/428 | | [`func_01ED32B8`](net/func_01ED32B8.c) | net | 84 | BYTES 3/84 | -| [`func_004BACD8`](game/func_004BACD8.c) | game | 120 | BYTES 4/120 | | [`func_0012E3F0`](core/func_0012E3F0.c) | core | 112 | BYTES 4/112 | | [`func_L01_0044A0F0`](shared/func_L01_0044A0F0.c) | shared | 144 | BYTES 5/140 | | [`func_L01_0047E690`](shared/func_L01_0047E690.c) | shared | 168 | BYTES 6/168 | @@ -50,7 +46,6 @@ Best attempts at functions that do not match yet. They are not built; see | [`func_004B9330`](game/func_004B9330.c) | game | 128 | BYTES 6/124 | | [`func_0012DD90`](core/func_0012DD90.c) | core | 144 | BYTES 7/144 | | [`func_004B1F38`](game/func_004B1F38.c) | game | 512 | BYTES 25/508 | -| [`func_004CB078`](game/func_004CB078.c) | game | 120 | BYTES 6/116 | | [`func_004D7998`](game/func_004D7998.c) | game | 464 | BYTES 24/464 (8 words differ) | | [`func_L01_0047F050`](shared/func_L01_0047F050.c) | shared | 128 | BYTES 7/128 | | [`func_L41_00446500`](shared/func_L41_00446500.c) | shared | 840 | BYTES 46/836 | @@ -85,14 +80,12 @@ Best attempts at functions that do not match yet. They are not built; see | [`func_01EEFE4C`](net/func_01EEFE4C.c) | net | 72 | BYTES 6/72 | | [`func_L01_003CF4F0`](shared/func_L01_003CF4F0.c) | shared | 144 | BYTES 12/144 | | [`func_L01_004330A8`](shared/func_L01_004330A8.c) | shared | 528 | BYTES 45/524 | -| [`func_00549CA0`](game/func_00549CA0.c) | game | 128 | BYTES 11/128 | | [`func_L05_004F24B0`](shared/func_L05_004F24B0.c) | shared | 104 | BYTES 9/104 | | [`func_0048A9A8`](game/func_0048A9A8.c) | game | 80 | BYTES 7/76 | | [`func_01EDBC10`](net/func_01EDBC10.c) | net | 84 | BYTES 8/84 | | [`func_004979A8`](game/func_004979A8.c) | game | 312 | BYTES 30/308 | | [`func_0015F018`](core/func_0015F018.c) | core | 80 | BYTES 8/80 | | [`func_0049A694`](game/func_0049A694.c) | game | 20 | BYTES 2/20 | -| [`func_004A0198`](game/func_004A0198.c) | game | 64 | BYTES 6/60 | | [`func_00515790`](game/func_00515790.c) | game | 80 | BYTES 8/80 | | [`func_01E9B240`](net/func_01E9B240.c) | net | 40 | BYTES 4/40 | | [`func_L00_005FED90`](shared/func_L00_005FED90.c) | shared | 88 | BYTES 9/88 | @@ -108,7 +101,6 @@ Best attempts at functions that do not match yet. They are not built; see | [`func_001412F8`](core/func_001412F8.c) | core | 140 | BYTES 15/140 | | [`func_00147D88`](core/func_00147D88.c) | core | 84 | BYTES 9/84 | | [`func_00497938`](game/func_00497938.c) | game | 32 | BYTES 3/28 | -| [`func_004A52C0`](game/func_004A52C0.c) | game | 32 | BYTES 3/28 | | [`func_004B69B0`](game/func_004B69B0.c) | game | 32 | BYTES 3/28 | | [`func_004B69D0`](game/func_004B69D0.c) | game | 32 | BYTES 3/28 | | [`func_01EC5280`](net/func_01EC5280.c) | net | 56 | BYTES 6/56 | @@ -136,13 +128,11 @@ Best attempts at functions that do not match yet. They are not built; see | [`func_00549C18`](game/func_00549C18.c) | game | 136 | BYTES 16/136 | | [`func_L00_006F5E28`](shared/func_L00_006F5E28.c) | shared | 472 | BYTES 56/472 | | [`func_L01_004D7008`](shared/func_L01_004D7008.c) | shared | 328 | BYTES 39/324 | -| [`func_004E55C0`](game/func_004E55C0.c) | game | 120 | BYTES 14/116 | | [`func_01EFD674`](net/func_01EFD674.c) | net | 124 | BYTES 15/124 | | [`func_L01_0045BE60`](shared/func_L01_0045BE60.c) | shared | 128 | BYTES 15/124 | | [`func_L00_0072A178`](l00_multiplayer_menu/func_L00_0072A178.c) | l00_multiplayer_menu | 1968 | BYTES 244/1964 | | [`func_0046DB78`](game/func_0046DB78.c) | game | 8 | BYTES 1/8 | | [`func_00489458`](game/func_00489458.c) | game | 32 | BYTES 4/32 | -| [`func_004A1D58`](game/func_004A1D58.c) | game | 48 | BYTES 6/48 | | [`func_01E9DDD0`](net/func_01E9DDD0.c) | net | 104 | BYTES 13/104 | | [`func_01EC0410`](net/func_01EC0410.c) | net | 128 | BYTES 16/128 | | [`func_01EE503C`](net/func_01EE503C.c) | net | 48 | BYTES 6/48 | @@ -191,7 +181,6 @@ Best attempts at functions that do not match yet. They are not built; see | [`func_L00_006AAE40`](shared/func_L00_006AAE40.c) | shared | 128 | BYTES 18/124 | | [`func_00122020`](core/func_00122020.c) | core | 108 | BYTES 16/108 | | [`func_01EE1550`](net/func_01EE1550.c) | net | 128 | BYTES 19/128 | -| [`func_004CAEC8`](game/func_004CAEC8.c) | game | 104 | BYTES 15/100 | | [`func_004FEDC8`](game/func_004FEDC8.c) | game | 104 | BYTES 15/100 | | [`func_01EED500`](net/func_01EED500.c) | net | 40 | BYTES 6/40 | | [`func_L00_00599710`](shared/func_L00_00599710.c) | shared | 520 | BYTES 78/516 | diff --git a/nonmatching/game/func_004A0198.c b/nonmatching/game/func_004A0198.c deleted file mode 100644 index 3ee3e6e8d..000000000 --- a/nonmatching/game/func_004A0198.c +++ /dev/null @@ -1,11 +0,0 @@ -/* Not matching yet: BYTES 6/60 (tools/try_func.py func_004A0198 --diff). Not part of the build. */ -extern void func_00505238(s32, s32); -extern char D_307254[]; - -// Stores arg1 at offset 0x4C in the 512-byte entry arg0 of D_307254, then calls func_00505238. -void func_004A0198(s32 arg0, s32 arg1) { - s32 *p; - p = (s32 *)(D_307254 + (arg0 << 9)); - p[0x13] = arg1; - func_00505238((arg0 << 6) + 0x14000C, arg1); -} diff --git a/nonmatching/game/func_004A1D58.c b/nonmatching/game/func_004A1D58.c deleted file mode 100644 index b49266500..000000000 --- a/nonmatching/game/func_004A1D58.c +++ /dev/null @@ -1,16 +0,0 @@ -/* Not matching yet: BYTES 6/48 (tools/try_func.py func_004A1D58 --diff). Not part of the build. */ -extern void func_0049EF30(s32 index); -s32 D_0021F658 = 0; - -// Stores 4, or 1 after calling func_0049EF30(0), into a global chosen by arg0. -void func_004A1D58(s32 arg0) { - s32 var_v0; - - if (arg0 != 0) { - var_v0 = 4; - } else { - func_0049EF30(0); - var_v0 = 1; - } - D_0021F658 = var_v0; -} diff --git a/nonmatching/game/func_004A52C0.c b/nonmatching/game/func_004A52C0.c deleted file mode 100644 index baeea116c..000000000 --- a/nonmatching/game/func_004A52C0.c +++ /dev/null @@ -1,8 +0,0 @@ -/* Not matching yet: BYTES 3/28 (tools/try_func.py func_004A52C0 --diff). Not part of the build. */ -extern u8 D_307B58[]; - -/* Stores a float into the 0xEC-byte entry arg0 at offset 0xD0 */ -void func_004A52C0(s32 arg0, f32 arg1) { - u8 *entry = D_307B58 + arg0 * 0xEC; - *(f32 *)(entry + 0xD0) = arg1; -} diff --git a/nonmatching/game/func_004BACD8.c b/nonmatching/game/func_004BACD8.c deleted file mode 100644 index 91c8ca87f..000000000 --- a/nonmatching/game/func_004BACD8.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Not matching yet: BYTES 4/120 (tools/try_func.py func_004BACD8 --diff). Not part of the build. */ -extern void func_00497980(s32 arg0); -extern s32 func_004A1A60(s32 *arg0, s32 arg1); -extern void func_004BAD50(s32 a0); -extern void func_00505238(s32, void *, s32); -extern s32 D_0021DE6C; -extern s32 D_003D95AC_[]; -#define D_003D95AC (D_003D95AC_[0]) -extern s8 D_0021F8D8; -s8 D_0021F8DA = 0; -extern s32 D_2217E0[]; -extern s32 D_30A4E0[]; - -/* Calls func_00497980 with 4 or 0xB, clears two flags, then copies 0x30 bytes from table entry D_0021DE6C. */ -void func_004BACD8(s32 arg0) { - s32 *a; - s32 b; - s32 r; - - if (arg0 == 0) { - func_00497980(4); - func_004BAD50(0); - } else { - func_00497980(0xB); - } - a = D_2217E0; - b = D_003D95AC; - D_0021F8DA = 0; - D_0021F8D8 = 0; - r = func_004A1A60(a, b); - func_00505238(r, D_0021DE6C * 0x30 + (u8 *)D_30A4E0, 0x30); -} diff --git a/nonmatching/game/func_004CAEC8.c b/nonmatching/game/func_004CAEC8.c deleted file mode 100644 index 98e03b131..000000000 --- a/nonmatching/game/func_004CAEC8.c +++ /dev/null @@ -1,15 +0,0 @@ -/* Not matching yet: BYTES 15/100 (tools/try_func.py func_004CAEC8 --diff). Not part of the build. */ -extern void func_0049C158(s32 param_a, s32 param_b, s32 source, s32 mode); -extern s32 func_004A1A60(s32 *arg0, s32 arg1); -extern s32 func_00505B20(void); -extern u8 D_003D2618[]; -extern u8 D_2218F8[]; -// Calls func_0049C158 with the result of func_004A1A60 over D_2218F8 and word 0x14 of the 0x20-byte row at arg0. -void func_004CAEC8(s32 arg0) { - s32 temp_s1; - s32 row; - - temp_s1 = func_00505B20(); - row = *(s32 *)(D_003D2618 + (arg0 << 5) + 0x14); - func_0049C158(temp_s1, 0, func_004A1A60((s32 *)D_2218F8, row), 0); -} diff --git a/nonmatching/game/func_004CB078.c b/nonmatching/game/func_004CB078.c deleted file mode 100644 index 560390b36..000000000 --- a/nonmatching/game/func_004CB078.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Not matching yet: BYTES 6/116 (tools/try_func.py func_004CB078 --diff). Not part of the build. */ -extern void func_004CA1D0(int arg0, int arg1); -extern s32 func_004E21D8(u32 index, s32 param_a, s32 param_b); -extern u8 D_0021EE18; -s32 D_0021FA2C = 0; - -// Starts the action selected by arg0, or opens the pause menu when no mode is given, using flag D_0021EE18. -void func_004CB078(s32 arg0) { - int var_a0; - - if (arg0 != 0) { - if (D_0021EE18 != 0) { - D_0021FA2C = 1; - func_004E21D8(0xE, 0, 0); - var_a0 = 2; - } else { - var_a0 = 0xF; - } - func_004CA1D0(var_a0, 0); - return; - } - func_004E21D8(0xC, 0, 0); - func_004CA1D0(1, 0); -} diff --git a/nonmatching/game/func_004D58D0.c b/nonmatching/game/func_004D58D0.c deleted file mode 100644 index b66102674..000000000 --- a/nonmatching/game/func_004D58D0.c +++ /dev/null @@ -1,26 +0,0 @@ -/* Not matching yet: BYTES 2/124 (tools/try_func.py func_004D58D0 --diff). Not part of the build. */ -extern void func_004A1310(void *arg0, s32 arg1); -extern void func_004A1358(void *arg0, s32 arg1); -extern void func_004E0858(void); -extern s32 func_004E21D8(u32 index, s32 param_a, s32 param_b); -extern u8 D_31B9B8[]; -extern u8 D_31CCC4[]; - -// Sets bit 1 of the word at D_31B9B8+4 when the word at D_31CCC4+0x50 is at least 2, after one of two helpers. -void func_004D58D0(s32 arg0) { - u8 *base; - u32 *flags; - - base = D_31CCC4; - if (*(s32 *)(base + 0x50) >= 2) { - if (arg0 != 0) { - func_004A1358(base, arg0); - } else { - func_004A1310(base, arg0); - } - flags = (u32 *)D_31B9B8; - flags[1] = flags[1] | 2; - func_004E21D8(0, 0, 0); - func_004E0858(); - } -} diff --git a/nonmatching/game/func_004D73C8.c b/nonmatching/game/func_004D73C8.c deleted file mode 100644 index e2b4daa54..000000000 --- a/nonmatching/game/func_004D73C8.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Not matching yet: BYTES 2/124 (tools/try_func.py func_004D73C8 --diff). Not part of the build. */ -extern void func_00497980(s32 arg0); -extern s32 func_004D7250(s32 index); -extern void func_00501498(s32 *arg0); -extern void func_00505AD8(s32 a); -extern s32 func_00505B20(void); -extern void func_00505C90(s32); - -u8 D_0021FC11 = 0; - -/* Clears the flag at D_0021FC11 if it is set, otherwise reports 0xB through func_00497980. */ -void func_004D73C8(s32 arg0) { - s32 temp_s1; - - temp_s1 = func_00505B20(); - func_00505AD8(arg0); - func_00501498(func_004D7250(arg0)); - func_00505C90(func_004D7250(arg0)); - func_00505AD8(temp_s1); - if (D_0021FC11 == 0) { - func_00497980(0xB); - } else { - D_0021FC11 = 0; - } -} diff --git a/nonmatching/game/func_004E55C0.c b/nonmatching/game/func_004E55C0.c deleted file mode 100644 index 25e3e40ab..000000000 --- a/nonmatching/game/func_004E55C0.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Not matching yet: BYTES 14/116 (tools/try_func.py func_004E55C0 --diff). Not part of the build. */ -extern void *D_22140C; - -/* Walks 0x100-byte records from D_22140C up to a 0xFF tag; sets or clears bit 0x80 of the u16 at 0x34 for records with flag bit 0x80 clear and type 0x183A or 0x183C. */ -void func_004E55C0(s32 arg0) { - u8 *p; - u8 tag; - s16 type; - u16 v; - - p = D_22140C; - tag = p[0x20]; - if (tag != 0xFF) { - do { - if ((tag & 0x80) == 0) { - type = *(s16 *)(p + 0xBC); - if (type == 0x183A || type == 0x183C) { - v = *(u16 *)(p + 0x34); - if (arg0 != 0) { - v = v | 0x80; - } else { - v = v & 0xFF7F; - } - *(u16 *)(p + 0x34) = v; - } - } - p += 0x100; - tag = p[0x20]; - } while (tag != 0xFF); - } -} diff --git a/nonmatching/game/func_00500F00.c b/nonmatching/game/func_00500F00.c deleted file mode 100644 index 36f5f7b68..000000000 --- a/nonmatching/game/func_00500F00.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Not matching yet: BYTES 3/112 (tools/try_func.py func_00500F00 --diff). Not part of the build. */ -extern s32 D_0021DDCC; -extern void func_004FFEE0(s32 arg0); -extern s32 func_005005D8(s32 *arg0); -extern void func_00503B58(void *arg0, s32 arg1, s32 arg2, s32 arg3); -extern void func_00503D78(s32 arg0, void *arg1); - -/* Calls func_004FFEE0 on the entry at index p[5] of arg0[1]; when the flag at 0x1C4 of D_0021DDCC is set, first passes a local buffer to func_00503B58 and func_00503D78. */ -void func_00500F00(s32 *arg0) { - s32 buf[2]; - s32 s0; - s32 *p; - - p = (s32 *)arg0[1]; - s0 = *(s32 *)((u32)p + (p[5] << 2)); - if (s0 != 0) { - if (*(s32 *)((u32)D_0021DDCC + 0x1C4) != 0) { - func_00503B58(buf, 0, 1, 0x10000); - func_00503D78(func_005005D8(s0), buf); - } - func_004FFEE0(s0); - } -} diff --git a/nonmatching/game/func_00549CA0.c b/nonmatching/game/func_00549CA0.c deleted file mode 100644 index 08b22b8e9..000000000 --- a/nonmatching/game/func_00549CA0.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Not matching yet: BYTES 11/128 (tools/try_func.py func_00549CA0 --diff). Not part of the build. */ -extern s32 func_00549BB8(); -extern s32 func_0054A0C0(s32 arg0, s32 arg1); -extern s32 func_0054A788(s32, s32, s32); - -/* Sums func_0054A788 over indices 2 to 19 where func_0054A0C0 reports a match, starting from the value of func_00549BB8. */ -s32 func_00549CA0(s32 arg0, s32 arg1) { - s32 var_s0; - s32 var_s1; - - var_s1 = func_00549BB8(); - var_s0 = 2; - do { - if (func_0054A0C0(var_s0, arg1) != 0) { - var_s1 += func_0054A788(arg0, var_s0, arg1); - } - var_s0 += 1; - } while (var_s0 < 0x14); - return var_s1; -} diff --git a/src/core/0012C3A8.c b/src/core/0012C3A8.c new file mode 100644 index 000000000..91db79c55 --- /dev/null +++ b/src/core/0012C3A8.c @@ -0,0 +1,10 @@ +/* cflags: -O2 -G8 */ +#include "common.h" + +s32 func_0012C330(s32); + +// Forwards the incoming value to func_0012C330 and returns its result. +s32 func_0012C3A8(s32 value) +{ + return func_0012C330(value); +} diff --git a/src/game/003F6470.c b/src/game/003F6470.c new file mode 100644 index 000000000..a72eef9ea --- /dev/null +++ b/src/game/003F6470.c @@ -0,0 +1,10 @@ +/* cflags: -fno-strength-reduce -fno-schedule-insns2 */ +#include "common.h" +/* XOR eight bytes into the second buffer. */ +unsigned char *func_003F6470(unsigned char *a, unsigned char *b) +{ + int i; + for (i = 0; i < 8; i++) + b[i] ^= a[i]; + return b; +} diff --git a/src/game/003F7478.c b/src/game/003F7478.c new file mode 100644 index 000000000..c775de06c --- /dev/null +++ b/src/game/003F7478.c @@ -0,0 +1,9 @@ +#include "common.h" +/* Initialize five state words. */ +void func_003F7478(unsigned int *p) { + p[0] = 0x67452301; + p[1] = 0xEFCDAB89; + p[2] = 0x98BADCFE; + p[3] = 0x10325476; + p[4] = 0xC3D2E1F0; +} diff --git a/src/game/00414EC8.c b/src/game/00414EC8.c new file mode 100644 index 000000000..04bc306d5 --- /dev/null +++ b/src/game/00414EC8.c @@ -0,0 +1,13 @@ +#include "common.h" +extern float func_00472690(void); +extern void *func_00414D50(void *, float, float, void *, unsigned char, unsigned char); +/* Spawn the object using a generated third vector component. */ +void *func_00414EC8(void *p, unsigned char a, unsigned char b, float x, float y) +{ + float v[4]; + v[2] = func_00472690(); + v[0] = 0.0f; + v[1] = 0.0f; + v[3] = 0.0f; + return func_00414D50(p, x, y, v, a, b); +} diff --git a/src/game/0041AC68.c b/src/game/0041AC68.c new file mode 100644 index 000000000..db490dc99 --- /dev/null +++ b/src/game/0041AC68.c @@ -0,0 +1,17 @@ +#include "common.h" +typedef struct { + short indices[64]; +} List; +extern List D_0026FA38[]; +extern char *D_002213F4; +void *func_0041AC68(int a, int b) +{ + int i; + for (i = 1; i <= D_0026FA38[a].indices[0]; i++) { + char *obj = D_002213F4 + D_0026FA38[a].indices[i] * 256; + char *q = *(char **)(obj + 0xAC); + if (q && *(short *)(q + 0xC2) == b) + return obj; + } + return 0; +} diff --git a/src/game/00424708.c b/src/game/00424708.c new file mode 100644 index 000000000..511c270ca --- /dev/null +++ b/src/game/00424708.c @@ -0,0 +1,12 @@ +#include "common.h" + +extern void func_004255C0(void *); +extern void func_00424600(void *, float); +/* Compute the blend amount and update the object. */ +void func_00424708(char *p) +{ + char *s = *(char **)(p + 0xAC); + float a = 1.0f - (float)(*(int *)(s + 0x54) - 90) / 10.0f; + func_004255C0(p); + func_00424600(p, a); +} diff --git a/src/game/00433318.c b/src/game/00433318.c new file mode 100644 index 000000000..0fa50c5e7 --- /dev/null +++ b/src/game/00433318.c @@ -0,0 +1,12 @@ +#include "common.h" +extern s32 D_0021EDD4; +typedef struct { + char pad[0x18]; + f32 a, b; +} Object; +s32 func_00433318(Object *p) +{ + if (D_0021EDD4 == 1) + return p->a >= 2.2f && p->b >= 1.2f; + return p->a >= 3.5f && p->b >= 1.6f; +} diff --git a/src/game/00433638.c b/src/game/00433638.c new file mode 100644 index 000000000..c8deef10a --- /dev/null +++ b/src/game/00433638.c @@ -0,0 +1,12 @@ +#include "common.h" + +/* Advance a value and wrap it by one at either signed unit boundary. */ +void func_00433638(f32 *p, f32 x) +{ + f32 result = *p + x; + *p = result; + if (result >= 1.0f) + *p = result - 1.0f; + else if (result <= -1.0f) + *p = result + 1.0f; +} diff --git a/src/game/004493E8.c b/src/game/004493E8.c new file mode 100644 index 000000000..24fab622b --- /dev/null +++ b/src/game/004493E8.c @@ -0,0 +1,27 @@ +#include "common.h" +typedef struct Type1 { + void (*f0)(void *); + void *f4; + struct Type1 *f8; + struct Type1 *fC; +} Type1; +extern s32 D_00221254; +extern Type1 D_00238540[]; + +/* Appends a record from the fixed pool to the list. */ +void func_004493E8(Type1 **a, void (*b)(void *), void *c) +{ + Type1 *p; + s32 n = D_00221254; + if (n < 256) { + p = &D_00238540[n]; + D_00221254 = n + 1; + p->f0 = b; + p->f4 = c; + if (*a) + (*a)->fC->f8 = p; + else + *a = p; + (*a)->fC = p; + } +} diff --git a/src/game/0044D1B8.c b/src/game/0044D1B8.c new file mode 100644 index 000000000..b11f3a361 --- /dev/null +++ b/src/game/0044D1B8.c @@ -0,0 +1,15 @@ +/* cflags: -O2 -G8 */ +#include "common.h" +extern int D_00221E20; +extern u64 D_003D76D0[]; +extern u8 D_003D7730[]; +void func_0044D1B8(unsigned int a1) +{ + if (!*(u8 *)a1 || *(u64 *)(a1 + 72) != D_003D76D0[0]) { + *(u32 *)D_00221E20 = 0x30000002; + *(u32 *)(D_00221E20 + 4) = (u32)D_003D7730; + *(u32 *)(D_00221E20 + 8) = 0; + *(u32 *)(D_00221E20 + 12) = 0x50000002; + D_00221E20 += 16; + } +} diff --git a/src/game/0044D938.c b/src/game/0044D938.c new file mode 100644 index 000000000..859136472 --- /dev/null +++ b/src/game/0044D938.c @@ -0,0 +1,19 @@ +#include "common.h" +typedef struct { + const void *a, *b, *c; +} Data; +extern char D_00239540[]; +extern s32 D_002212F8; +extern void func_0044AD28(void); +extern void func_0044D1B8(void *); +extern void func_0044CE08(s32, const void *, const void *, const void *, s32, s32); +void func_0044D938(Data *p, s32 a, s32 b, s32 c) +{ + if (!*(u8 *)D_00239540) + func_0044AD28(); + else if (D_002212F8 != 8) { + func_0044AD28(); + func_0044D1B8(D_00239540); + } + func_0044CE08(a, p->a, p->b, p->c, b, c); +} diff --git a/src/game/0044D9E8.c b/src/game/0044D9E8.c new file mode 100644 index 000000000..b0d0f365e --- /dev/null +++ b/src/game/0044D9E8.c @@ -0,0 +1,15 @@ +#include "common.h" + +extern u8 D_00239540[]; +extern s32 D_002212F8; +extern void func_0044AD28(void), func_0044D1B8(void *), func_0044CE08(s32, const void *, const void *, const void *, s32, s32); +void func_0044D9E8(void *unused, s32 command, const void *a, const void *b, const void *c, s32 flags, s32 mode) +{ + if (!D_00239540[0]) + func_0044AD28(); + else if (D_002212F8 != 8) { + func_0044AD28(); + func_0044D1B8(D_00239540); + } + func_0044CE08(command, a, b, c, flags, mode); +} diff --git a/src/game/0044DAB0.c b/src/game/0044DAB0.c new file mode 100644 index 000000000..163a54217 --- /dev/null +++ b/src/game/0044DAB0.c @@ -0,0 +1,17 @@ +#include "common.h" +typedef struct { + const void *a, *b, *c; +} Args; +extern unsigned char D_00239540[]; +extern int D_002212F8; +extern void func_0044AD28(void), func_0044D1B8(void *), func_0044CE08(s32, const void *, const void *, const void *, s32, s32); +void func_0044DAB0(Args *p, int flags) +{ + if (!D_00239540[0]) + func_0044AD28(); + else if (D_002212F8 != 8) { + func_0044AD28(); + func_0044D1B8(D_00239540); + } + func_0044CE08(4, p->a, p->b, p->c, flags, 1); +} diff --git a/src/game/0044DE80.c b/src/game/0044DE80.c new file mode 100644 index 000000000..c7a997078 --- /dev/null +++ b/src/game/0044DE80.c @@ -0,0 +1,14 @@ +#include "common.h" + +extern u8 D_00239540[]; +extern s32 func_0044DF08(s32, s32, s32); +extern void func_004E7990(s32, s32, s32); + +/* Dispatches according to the flag, query result and forced fallback. */ +void func_0044DE80(s32 a, s32 b, s32 c, s32 d) +{ + if (D_00239540[0] == 0) + func_004E7990(b, c, 0); + else if (func_0044DF08(a, b, c) || d) + func_004E7990(b, c, 1); +} diff --git a/src/game/004572E0.c b/src/game/004572E0.c new file mode 100644 index 000000000..21b0423a0 --- /dev/null +++ b/src/game/004572E0.c @@ -0,0 +1,8 @@ +#include "common.h" +extern void func_00454A70(f32, f32, f32, f32, s32, const void *, s32, s32, s32, u64, f32, f32); +extern s32 func_00454780(const char *, s32, f32); +s32 func_004572E0(s32 x, s32 y, s32 a, const char *b, s32 c) +{ + func_00454A70(x, y, 1.0f, 1.0f, a, b, c, 1, 0, 0x80000000UL, 0.0f, 0.0f); + return (s32)((u32)x - (u32)(func_00454780(b, c, 1.0f) >> 1)); +} diff --git a/src/game/00457388.c b/src/game/00457388.c new file mode 100644 index 000000000..3bcb0ca09 --- /dev/null +++ b/src/game/00457388.c @@ -0,0 +1,15 @@ +#include "common.h" +extern void func_00454A70(f32, f32, f32, f32, u64, const char *, s32, s32, s32, u64, f32, f32); +extern s32 func_00454780(const char *, s32, f32); +extern s32 D_0021DEC4; +extern void func_00454350(s32); +s32 func_00457388(s32 x, s32 y, u64 a, const char *b, s32 c) +{ + s32 old = D_0021DEC4; + s32 result; + func_00454350(0); + func_00454A70(x, y, 1.0f, 1.0f, a, b, c, 1, 0, 0x80000000UL, 0.0f, 0.0f); + result = (s32)((u32)x - (u32)(func_00454780(b, c, 1.0f) >> 1)); + func_00454350(old); + return result; +} diff --git a/src/game/00457478.c b/src/game/00457478.c new file mode 100644 index 000000000..edea42616 --- /dev/null +++ b/src/game/00457478.c @@ -0,0 +1,8 @@ +#include "common.h" + +extern void func_00454A70(f32, f32, f32, f32, s32, void *, s32, s32, s32, u64, f32, f32); +/* Forward integer coordinates as floats with default rendering fields. */ +void func_00457478(s32 x, s32 y, s32 a, void *b, s32 c, f32 scale) +{ + func_00454A70((f32)x, (f32)y, scale, scale, a, b, c, 1, 0, 0x80000000ULL, 0.0f, 0.0f); +} diff --git a/src/game/004574D8.c b/src/game/004574D8.c new file mode 100644 index 000000000..b70ffc50f --- /dev/null +++ b/src/game/004574D8.c @@ -0,0 +1,11 @@ +#include "common.h" +extern s32 D_0021DEC4; +extern void func_00454350(s32); +extern void func_00454A70(f32, f32, f32, f32, s32, void *, s32, s32, s32, u64, f32, f32); +void func_004574D8(s32 x, s32 y, s32 a, void *b, s32 c) +{ + s32 old = D_0021DEC4; + func_00454350(0); + func_00454A70(x, y, 1.0f, 1.0f, a, b, c, 2, 0, 0x80000000UL, 0.0f, 0.0f); + func_00454350(old); +} diff --git a/src/game/00457590.c b/src/game/00457590.c new file mode 100644 index 000000000..b188c2a46 --- /dev/null +++ b/src/game/00457590.c @@ -0,0 +1,11 @@ +#include "common.h" +extern s32 D_0021DEC4; +extern void func_00454350(s32); +extern void func_00454A70(f32, f32, f32, f32, s32, void *, s32, s32, s32, u64, f32, f32); +void func_00457590(s32 x, s32 y, s32 a, void *b, s32 c) +{ + s32 old = D_0021DEC4; + func_00454350(0); + func_00454A70((f32)x, (f32)y, 1.0f, 1.0f, a, b, c, 0, 0, 0x80000000UL, 0.0f, 0.0f); + func_00454350(old); +} diff --git a/src/game/004576A0.c b/src/game/004576A0.c new file mode 100644 index 000000000..7ab95fbe9 --- /dev/null +++ b/src/game/004576A0.c @@ -0,0 +1,8 @@ +#include "common.h" + +extern void func_00455E40(void *, int, int, int, int, int, int, int, int); +/* Forward the nine arguments. */ +void func_004576A0(void *a, int b, int c, int d, int e, int f, int g, int h, int i) +{ + func_00455E40(a, b, c, d, e, f, g, h, i); +} diff --git a/src/game/004576E8.c b/src/game/004576E8.c new file mode 100644 index 000000000..0b369e263 --- /dev/null +++ b/src/game/004576E8.c @@ -0,0 +1,13 @@ +#include "common.h" + +extern void func_00454350(s32); +extern void func_00455E78(f32, f32, void *, s32, void *, s32, u64); +extern s32 D_0021DEC4; +/* Draw using the temporary mode and restore the prior mode. */ +void func_004576E8(void *a, s32 b, void *c, s32 d) +{ + s32 saved = D_0021DEC4; + func_00454350(0); + func_00455E78(1.0f, 1.0f, a, b, c, d, 0x80000000ULL); + func_00454350(saved); +} diff --git a/src/game/00457780.c b/src/game/00457780.c new file mode 100644 index 000000000..5049ceb84 --- /dev/null +++ b/src/game/00457780.c @@ -0,0 +1,9 @@ +/* cflags: -O2 -G0 */ +#include "common.h" + +extern void func_00456918(void *, u64, void *, s32, s32, u64, void *, void *, f32); +/* Forwards arguments with a sign-extended short selector. */ +void func_00457780(void *a, u64 b, void *c, s32 d, s32 e, s32 f, s32 g, u64 h, void *i, void *j, f32 scale) +{ + func_00456918(a, b, c, d, (s16)g, h, i, j, scale); +} diff --git a/src/game/004598E8.c b/src/game/004598E8.c new file mode 100644 index 000000000..fefff4d04 --- /dev/null +++ b/src/game/004598E8.c @@ -0,0 +1,19 @@ +#include "common.h" + +extern void func_004E7830(s32); +extern void func_00458670(void); +extern void func_004588D0(s32, s32, s32, s32, s32, s32); +extern void func_004F8758(void); +extern s32 D_0021DE6C; + +/* Initialize the display, choose its mode bounds and refresh the output. */ +void func_004598E8(void) +{ + func_004E7830(1); + func_00458670(); + if (D_0021DE6C) + func_004588D0(0x200, 0x1A0, 0x280, 0x1C0, 0, 0); + else + func_004588D0(0x200, 0x1A0, 0x200, 0x1C0, 0, 0); + func_004F8758(); +} diff --git a/src/game/0045C7B0.c b/src/game/0045C7B0.c new file mode 100644 index 000000000..98ac1dcb1 --- /dev/null +++ b/src/game/0045C7B0.c @@ -0,0 +1,25 @@ +#include "common.h" + +/* Remove the next pair from the ring and clear the exhausted flag. */ +s32 func_0045C7B0(char *p, s32 *a, s32 *b) +{ + s32 count = *(s32 *)(p + 0x60), index; + s32 *x, *y; + if (!count) + return 0; + count--; + *(s32 *)(p + 0x60) = count; + if (!count) + p[0x6c] = 0; + x = (s32 *)(p + 8); + y = (s32 *)(p + 0xc); + *a = *(s32 *)((u32)x + (*(s32 *)(p + 0x5c) << 3)); + *b = *(s32 *)((u32)y + (*(s32 *)(p + 0x5c) << 3)); + x += *(s32 *)(p + 0x5c) * 2; + *x = -1; + y += *(s32 *)(p + 0x5c) * 2; + *y = -1; + index = *(s32 *)(p + 0x5c) + 1; + *(s32 *)(p + 0x5c) = index == 10 ? 0 : index; + return 1; +} diff --git a/src/game/0045C990.c b/src/game/0045C990.c new file mode 100644 index 000000000..d70da5231 --- /dev/null +++ b/src/game/0045C990.c @@ -0,0 +1,23 @@ +#include "common.h" +extern int D_0021DDB4; +extern int func_0045C7B0(char *, int *, int *), func_0047F568(s32, s32, s32, s32, u8 *); +extern void func_0045C8C8(char *); +int func_0045C990(char *p) +{ + if (*(int *)(p + 0x60)) { + int a = 0, b = 0, status = 0, mode; + *(unsigned char *)(p + 0x64) = 0; + *(unsigned char *)(p + 0x6C) = 1; + func_0045C7B0(p, &a, &b); + mode = (((u32)D_0021DDB4 - 1) <= 1) ? 2 : 1; + *(int *)(p + 0x68) = mode; + if (b == 0) + status = func_0047F568(1, mode, 0, a, 0); + else if (b == 1) + status = func_0047F568(2, mode, a, 0, 0); + if (status < 0) + func_0045C8C8(p); + return status == 0; + } + return 0; +} diff --git a/src/game/0045CEC8.c b/src/game/0045CEC8.c new file mode 100644 index 000000000..d603956de --- /dev/null +++ b/src/game/0045CEC8.c @@ -0,0 +1,25 @@ +#include "common.h" +extern s32 D_0021DE10; +typedef struct { + s32 result, key; +} Pair; +extern Pair D_003DB148[]; +s32 func_0045CEC8(s32 key) +{ + s32 i = 0; + Pair *p; + if (key == 0x2726) { + if (D_0021DE10 == 14 || D_0021DE10 == 34) + return 0x246A; + return 0x2133; + } + if (key == 0x2727) { + if (D_0021DE10 == 14 || D_0021DE10 == 34) + return 0x246D; + return 0x2130; + } + for (; D_003DB148[i].result != -1; i++) + if (key == D_003DB148[i].key) + return D_003DB148[i].result; + return key; +} diff --git a/src/game/0045D7B0.c b/src/game/0045D7B0.c new file mode 100644 index 000000000..47c0afcac --- /dev/null +++ b/src/game/0045D7B0.c @@ -0,0 +1,18 @@ +#include "common.h" + +extern s32 func_0045D888(s16); +extern void func_0045E3D0(s16, s16, s16, s32, f32, f32, f32, f32); +extern s16 D_0023F2AC[]; + +/* Queue an effect if its id is inactive and a free slot remains. */ +s32 func_0045D7B0(s16 id, s16 a, s16 b, s32 c, f32 x, f32 y, f32 z, f32 w) +{ + if (!func_0045D888(id)) { + if (id != -1 && D_0023F2AC[0] < 16) { + func_0045E3D0(id, a, b, c, x, y, z, w); + return 1; + } + return 0; + } + return 0; +} diff --git a/src/game/0045E790.c b/src/game/0045E790.c new file mode 100644 index 000000000..c0594c91b --- /dev/null +++ b/src/game/0045E790.c @@ -0,0 +1,22 @@ +#include "common.h" + +typedef struct Type1 { + s32 f0; + char *f4, *f8; +} Type1; +extern Type1 D_0023F430[]; +extern void func_0045E808(void); + +/* Allocate an aligned block from the initialized linear buffer. */ +void *func_0045E790(s32 size) +{ + char *result; + if (!D_0023F430[0].f4) + func_0045E808(); + if (D_0023F430[0].f8 - D_0023F430[0].f4 < size) + return 0; + result = D_0023F430[0].f4; + size = (size + 15) & ~15u; + D_0023F430[0].f4 += size; + return result; +} diff --git a/src/game/00460CA0.c b/src/game/00460CA0.c new file mode 100644 index 000000000..2be00f1ad --- /dev/null +++ b/src/game/00460CA0.c @@ -0,0 +1,19 @@ +#include "common.h" + +extern s32 func_004600C0(s32, s32); +extern s32 func_00439810(void); +extern u8 D_0021DD52; +extern u8 D_0021DD53; +extern u8 D_0021DD54; + +// When none of the three flags is set, runs func_004600C0(0x8000, 7) and func_00439810, and sets +// the second flag. +void func_00460CA0(void) { + if (D_0021DD52 == 0) { + if (D_0021DD53 == 0 && D_0021DD54 == 0) { + func_004600C0(0x8000, 7); + func_00439810(); + D_0021DD53 = 1; + } + } +} diff --git a/src/game/00461030.c b/src/game/00461030.c new file mode 100644 index 000000000..a2f39a17c --- /dev/null +++ b/src/game/00461030.c @@ -0,0 +1,17 @@ +#include "common.h" + +/* Release the pending state and clear its request flags. */ +extern u8 D_0021DD54; +extern s32 D_0021DD44; +extern char D_00209148[], D_003D08A8[]; +extern void func_00460110(void); +extern void func_00460AA8(void *, s32, void *); +void func_00461030(void) +{ + if (D_0021DD54) { + func_00460110(); + func_00460AA8(D_00209148, 1, D_003D08A8); + D_0021DD44 = 0; + D_0021DD54 = 0; + } +} diff --git a/src/game/004610A8.c b/src/game/004610A8.c new file mode 100644 index 000000000..1403cb674 --- /dev/null +++ b/src/game/004610A8.c @@ -0,0 +1,16 @@ +#include "common.h" + +extern s32 func_004600C0(s32, s32); +extern u8 D_0021DD52; +extern u8 D_0021DD53; +extern u8 D_0021DD54; + +// When none of the three flags is set, runs func_004600C0(0x8000, 7) and sets the first flag. +void func_004610A8(void) { + if (D_0021DD52 == 0) { + if (D_0021DD53 == 0 && D_0021DD54 == 0) { + func_004600C0(0x8000, 7); + D_0021DD52 = 1; + } + } +} diff --git a/src/game/0046D3A0.c b/src/game/0046D3A0.c new file mode 100644 index 000000000..c51b8664b --- /dev/null +++ b/src/game/0046D3A0.c @@ -0,0 +1,35 @@ +/* cflags: */ + +#include "common.h" +#define __int128 long long +#define __int64 long +#define __int16 short +#define __int8 char +typedef int bool; +typedef u8 _BYTE; typedef u16 _WORD; typedef u32 _DWORD; typedef u64 _QWORD; typedef unsigned long long _OWORD; +typedef u8 _BOOL1; typedef u16 _BOOL2; typedef u32 _BOOL4; typedef u64 _BOOL8; +void func_0046D110(void); +int func_0046D198(void); +void func_0046D340(void); +int func_00470BF0(unsigned int arg0, unsigned int arg1, int arg2, int arg3); +int func_004E7450(unsigned int arg0); +extern char D_00117A60[]; +extern int D_002213F4; +int D_00221408 = 0; +extern int D_00221438; +void func_0046D3A0() +{ + int v0; // $a3 + + func_0046D198(); + func_004E7450((unsigned int)D_00117A60); + func_0046D110(); + v0 = 1; + if ( D_00221438 ) + { + D_00221438 = 0; + v0 = 3; + } + D_00221408 = func_00470BF0(D_002213F4, D_00221408, -1, v0); + func_0046D340(); +} diff --git a/src/game/0046EFE0.c b/src/game/0046EFE0.c new file mode 100644 index 000000000..5e8d311e4 --- /dev/null +++ b/src/game/0046EFE0.c @@ -0,0 +1,22 @@ +#include "common.h" + +extern u8 D_00266F00[]; +extern void *D_00266F40[]; +extern char D_00266B00[]; + +/* Reserve a free entry for an eligible object and return its state record. */ +void *func_0046EFE0(u8 *object) +{ + s32 i; + if (!object[0x31] || (object[0x20] & 0x80)) + return 0; + for (i = 0; i < 32; i++) { + u8 *p = D_00266F00 + i; + if (!*p) { + *p = 1; + D_00266F40[i] = object; + return D_00266B00 + (i << 5); + } + } + return 0; +} diff --git a/src/game/0046FB30.c b/src/game/0046FB30.c new file mode 100644 index 000000000..dfe11d223 --- /dev/null +++ b/src/game/0046FB30.c @@ -0,0 +1,22 @@ +#include "common.h" +typedef struct { + short f0, f2; + unsigned char f4, f5; + char pad[2]; +} Entry; +extern Entry D_0026AFC0[]; +extern int D_00221474, D_00221470; +void func_0046FB30(void) +{ + int i; + D_0026AFC0[0].f2 = 512; + D_0026AFC0[0].f5 = 255; + D_00221474 = 1; + D_00221470 = 0; + D_0026AFC0[0].f4 = 0; + D_0026AFC0[0].f0 = 0; + for (i = 1; i < 31; i++) { + D_0026AFC0[i].f5 = i + 1; + } + D_0026AFC0[i].f5 = 255; +} diff --git a/src/game/00470870.c b/src/game/00470870.c new file mode 100644 index 000000000..83990e3e1 --- /dev/null +++ b/src/game/00470870.c @@ -0,0 +1,8 @@ +/* cflags: @ee29 -O2 -G0 */ +#include "common.h" + +s32 func_0046F530(); + +void func_00470870(void) { + func_0046F530(); +} diff --git a/src/game/00472818.c b/src/game/00472818.c new file mode 100644 index 000000000..1710099c0 --- /dev/null +++ b/src/game/00472818.c @@ -0,0 +1,32 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + s32 f0; + s32 (*f4)(Object *); +} Entry; +struct Object { + char pad[0x20]; + u8 type; + char pad21[0x9B]; + s16 index; +}; +typedef struct { + s32 f0; + u32 flags; +} Flags; +extern Entry *func_0046D428(s32, s32, s32); +extern Flags *func_004765F0(Object *); +s32 func_00472818(Object *p) +{ + Entry *e; + Flags *f; + if (!p || p->type == 254 || p->type == 253) + return 1; + e = func_0046D428(p->index, 14, 28); + if (e && e->f4 && e->f4(p)) + return 1; + f = func_004765F0(p); + if (f && (f->flags & 0x100)) + return 1; + return 0; +} diff --git a/src/game/004728B0.c b/src/game/004728B0.c new file mode 100644 index 000000000..a5e94d4e3 --- /dev/null +++ b/src/game/004728B0.c @@ -0,0 +1,19 @@ +/* cflags: -mno-split-addresses */ +#include "common.h" + +extern s16 D_002214A8[]; + +/* Insert a new value into an empty slot unless it is already present. */ +s32 func_004728B0(s32 value) +{ + s32 index; + for (index = 0; index < 8; index++) { + if (!D_002214A8[index]) { + D_002214A8[index] = value; + return 1; + } + if (D_002214A8[index] == value) + return 0; + } + return 0; +} diff --git a/src/game/00472900.c b/src/game/00472900.c new file mode 100644 index 000000000..c5f430fa6 --- /dev/null +++ b/src/game/00472900.c @@ -0,0 +1,19 @@ +/* cflags: -mno-split-addresses */ +#include "common.h" + +extern s16 D_002214A8[]; + +s32 func_00472900(s32 value) +{ + s32 i = 0; + s16 *p; + + p = D_002214A8; + for (; i < 8; i++, p++) { + if (*p == value) { + *p = 0; + return 1; + } + } + return 0; +} diff --git a/src/game/00475D18.c b/src/game/00475D18.c new file mode 100644 index 000000000..e3e4f05d8 --- /dev/null +++ b/src/game/00475D18.c @@ -0,0 +1,12 @@ +/* cflags: -ffast-math */ +#include "common.h" +extern f32 func_00475C68(f32, f32, s32); +extern f32 func_00453B10(f32, f32); +f32 func_00475D18(f32 a, f32 b, f32 *p, s32 mode) +{ + f32 t = func_00475C68(a, *p, mode); + t = t > b ? b : t; + t = t < -b ? -b : t; + *p = func_00453B10(*p, t); + return func_00475C68(a, *p, mode); +} diff --git a/src/game/00477770.c b/src/game/00477770.c new file mode 100644 index 000000000..0ec49a059 --- /dev/null +++ b/src/game/00477770.c @@ -0,0 +1,17 @@ +#include "common.h" + +typedef struct Type1 Type1; +struct Type1 { + char _p0[0xBC]; + s32 fBC; +}; + + +s32 func_00477770(Type1 *arg0) { + s16 temp_a0; + + if ((arg0 != NULL) && ((temp_a0 = arg0->fBC, (temp_a0 == 0x10E)) || (temp_a0 == 0xE7D) || (temp_a0 == 0x1BC3) || (temp_a0 == 0x2569) || (temp_a0 == 0x2692))) { + return 1; + } + return 0; +} diff --git a/src/game/00477A98.c b/src/game/00477A98.c new file mode 100644 index 000000000..aa2ce26e1 --- /dev/null +++ b/src/game/00477A98.c @@ -0,0 +1,15 @@ +#include "common.h" +extern char *D_002213F4; +/* Append the object index when absent and space remains. */ +void func_00477A98(void *p, short *a, short n) +{ + short k = ((int)p - (int)D_002213F4) >> 8; + int i; + for (i = 1; i <= a[0]; i++) + if (a[i] == k) + return; + if (a[0] < n) { + a[0]++; + a[a[0]] = k; + } +} diff --git a/src/game/00477B10.c b/src/game/00477B10.c new file mode 100644 index 000000000..5418b143f --- /dev/null +++ b/src/game/00477B10.c @@ -0,0 +1,13 @@ +#include "common.h" +extern char *D_002213F4; +/* Remove an object index from the short list by replacing it with the last. */ +void func_00477B10(void *p, short *a) +{ + int i; + for (i = 1; i <= a[0]; i++) + if (D_002213F4 + a[i] * 256 == (char *)p) { + a[i] = a[a[0]]; + a[0]--; + return; + } +} diff --git a/src/game/00477FE0.c b/src/game/00477FE0.c new file mode 100644 index 000000000..a893d438f --- /dev/null +++ b/src/game/00477FE0.c @@ -0,0 +1,18 @@ +#include "pal/object_data.h" + +/* Read data word 0x08 only for a valid object, data pointer and flag 0x20. */ +u32 func_00477FE0(PalObject *object) +{ + u32 *data; + if (object != NULL) + goto present; +empty: + return 0; +present: + if (!(object->flags & 0x20)) + goto empty; + data = object->data; + if (data == NULL) + goto empty; + return data[2]; +} diff --git a/src/game/0047BC80.c b/src/game/0047BC80.c new file mode 100644 index 000000000..6b7d58c48 --- /dev/null +++ b/src/game/0047BC80.c @@ -0,0 +1,23 @@ +#include "common.h" + +extern char *func_0047BBD8(void *); +extern char *func_00476690(void *); +/* Release the selected object's references from the owner. */ +void func_0047BC80(void *a) +{ + char *p = func_0047BBD8(a); + if (p && *(void **)(p + 0x10) && *(short *)(p + 0x16) == 2) { + char *q; + int i; + void **s; + *(short *)(p + 0x16) = 1; + q = func_00476690(*(void **)(p + 0x10)); + if (q) { + s = (void **)(q + 0x50); + for (i = 7; i >= 0; i--, s++) + if (*s == a) + *s = 0; + *(int *)(q + 0x4C) -= *(int *)(p + 0x40); + } + } +} diff --git a/src/game/0047D250.c b/src/game/0047D250.c new file mode 100644 index 000000000..63c70993b --- /dev/null +++ b/src/game/0047D250.c @@ -0,0 +1,15 @@ +#include "common.h" + +typedef struct { + u8 bytes[16]; +} Entry; + +extern Entry D_003D8B60[]; + +void * func_0047D250(u32 index) +{ + if (index < 17) { + return &D_003D8B60[index]; + } + return NULL; +} diff --git a/src/game/0047EB60.c b/src/game/0047EB60.c new file mode 100644 index 000000000..d3bf45aef --- /dev/null +++ b/src/game/0047EB60.c @@ -0,0 +1,14 @@ +#include "common.h" +/* Set the object's selected flag field when its resource is enabled. */ +void func_0047EB60(char *p, int a) +{ + unsigned char *q = *(unsigned char **)(p + 0x24); + if (q && q[0xB]) { + unsigned int v = (*(unsigned short *)(p + 0x36) | 0x8000) & 0x87FF; + *(unsigned short *)(p + 0x36) = v; + if (a == 10) + *(unsigned short *)(p + 0x36) = v | 0x5000; + else + *(unsigned short *)(p + 0x36) = v | (a << 11); + } +} diff --git a/src/game/004844E0.c b/src/game/004844E0.c new file mode 100644 index 000000000..64c993a3d --- /dev/null +++ b/src/game/004844E0.c @@ -0,0 +1,27 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0x38]; + u64 *first; + u64 *second; + char pad40[0x1C]; + Object *child; +} Data; +extern Data *func_004765F0(Object *); +extern void func_00484320(Object *, u64 *); +static inline s32 initialized(u64 *p) +{ + return *p != 0; +} +void func_004844E0(Object *p, u64 *first, u64 *second) +{ + Data *d = func_004765F0(p); + if (d) { + d->second = second; + d->first = first; + if (first && !initialized(first)) + func_00484320(p, first); + if (d->child && d->second && !initialized(d->second)) + func_00484320(d->child, d->second); + } +} diff --git a/src/game/00489FA0.c b/src/game/00489FA0.c new file mode 100644 index 000000000..0361ee9b3 --- /dev/null +++ b/src/game/00489FA0.c @@ -0,0 +1,29 @@ +#include "common.h" +typedef struct { + char pad[7]; + u8 flags, active; + char rest[0x47]; +} Entry; +typedef void (*Callback)(void *, f32); +extern Entry D_00355DC0[]; +extern void *func_0011A518(void *, s32, u32); +extern void func_0048A7C8(void *, Entry **, s32, Callback, void *); +s32 func_00489FA0(void *manager, s32 wait, s32 timeout, Callback callback, void *user) +{ + Entry *list[3]; + Entry *p; + Entry **out; + s32 i; + func_0011A518(list, 0, 12); + p = D_00355DC0; + out = list; + for (i = 0; i < 3; i++, p++) { + if (p->active) { + list[i] = p; + p->flags |= 8; + } + } + if (wait) + func_0048A7C8(manager, list, timeout, callback, user); + return 1; +} diff --git a/src/game/0048A3C0.c b/src/game/0048A3C0.c new file mode 100644 index 000000000..70fbf9d14 --- /dev/null +++ b/src/game/0048A3C0.c @@ -0,0 +1,18 @@ +#include "common.h" +typedef struct { + char pad[0x38]; + s32 x; + s32 y; +} Object; +extern Object *func_0048A970(u32); +s32 func_0048A3C0(f32 a, f32 b, void *unused, u32 index) +{ + s32 result = 0; + Object *p = func_0048A970(index); + if (p) { + p->x = (s32)(a * 1024.0f); + p->y = (s32)(b * 1024.0f); + result = 1; + } + return result; +} diff --git a/src/game/0048AC68.c b/src/game/0048AC68.c new file mode 100644 index 000000000..8973cb6e1 --- /dev/null +++ b/src/game/0048AC68.c @@ -0,0 +1,14 @@ +#include "common.h" + +extern char *func_00453EB0(int); +/* Apply the capped gain to the selected resource. */ +void func_0048AC68(void *unused, char *p) +{ + int a = (int)(*(float *)(p + 0x20) * *(float *)(p + 0x24) * 1024.0f); + char *s; + if (a > 1024) + a = 1024; + s = func_00453EB0(*(short *)(p + 0xC)); + if (s) + *(short *)(s + 0xC) = a; +} diff --git a/src/game/0048B968.c b/src/game/0048B968.c new file mode 100644 index 000000000..cfde7441d --- /dev/null +++ b/src/game/0048B968.c @@ -0,0 +1,22 @@ +#include "common.h" + +extern u8 *D_002214D8; +extern void func_00453718(void *, const void *, u32); +extern u8 *func_0048B818(u32, u8 **, const u8 *); + +s32 func_0048B968(const u8 *source, u8 **cursor, const u8 *limit) +{ + s32 i; + + func_00453718(D_002214D8 + 0x3014, source, 4); + source += 4; + (*(u8 **)(D_002214D8 + 0x3018)) = func_0048B818((u32)(*(s32 *)(D_002214D8 + 0x3014)) << 5, cursor, limit); + if ((*(u8 **)(D_002214D8 + 0x3018)) == 0) { + return 1; + } + for (i = 0; i < (*(s32 *)(D_002214D8 + 0x3014)); i++) { + func_00453718((*(u8 **)(D_002214D8 + 0x3018)) + (i << 5), source, 32); + source += 32; + } + return 0; +} diff --git a/src/game/0048F440.c b/src/game/0048F440.c new file mode 100644 index 000000000..900ce2501 --- /dev/null +++ b/src/game/0048F440.c @@ -0,0 +1,15 @@ +#include "pal/object_data.h" + +/* Read data word 0x28 only for a valid object, data pointer and flag 0x20. */ +u32 func_0048F440(PalObject *object) +{ + u32 *data; + if (object == NULL) + return 0; + data = object->data; + if (data == NULL) + return 0; + if (object->flags & 0x20) + return data[10]; + return 0; +} diff --git a/src/game/004954C0.c b/src/game/004954C0.c new file mode 100644 index 000000000..fa1f0927d --- /dev/null +++ b/src/game/004954C0.c @@ -0,0 +1,21 @@ +#include "common.h" + +s32 func_004954C0(s32 *count, s32 current, s32 step, s32 wrap) +{ + if (wrap != 0) { + current = (current + step + *count) % *count; + } else { + current += step; + if (step < 0) { + if (current < 0) { + current = 0; + } + } else { + s32 last = *count - 1; + if (last < current) { + current = last; + } + } + } + return current; +} diff --git a/src/game/00496A78.c b/src/game/00496A78.c new file mode 100644 index 000000000..79922a589 --- /dev/null +++ b/src/game/00496A78.c @@ -0,0 +1,26 @@ +#include "common.h" +typedef struct { + s32 pad; + void *table; +} Manager; +extern Manager D_00222038[]; +extern s32 D_0023F450[]; +extern s32 D_0021EDC4; +u8 D_0021F554 = 0; +extern Manager *func_005010E0(void); +extern s32 func_005012C8(Manager *, s32); +extern void func_00501090(Manager *); +static inline Manager *manager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +void func_00496A78(s32 index) +{ + if (!D_0023F450[0] && D_0021EDC4 != 3 && !D_0021F554) { + func_005012C8(manager(), index); + func_00501090(manager()); + } +} diff --git a/src/game/00496B48.c b/src/game/00496B48.c new file mode 100644 index 000000000..76eed9119 --- /dev/null +++ b/src/game/00496B48.c @@ -0,0 +1,8 @@ +/* cflags: @ee29 -O2 -G0 */ +#include "common.h" + +s32 func_00496B48(char *arg0) { + if (!*(u8*)(arg0+8)) return 0; + *(u8*)(arg0+8)=0; + return 1; +} diff --git a/src/game/004973E0.c b/src/game/004973E0.c new file mode 100644 index 000000000..bb956449b --- /dev/null +++ b/src/game/004973E0.c @@ -0,0 +1,8 @@ +#include "common.h" + +extern f32 func_004757E0(f32 *value, f32 target, f32 fraction, f32 minimum); + +void func_004973E0(f32 *value, s32 target) +{ + func_004757E0(value, (f32)target, 0.2f, 0.01f); +} diff --git a/src/game/00498670.c b/src/game/00498670.c new file mode 100644 index 000000000..12492f9b5 --- /dev/null +++ b/src/game/00498670.c @@ -0,0 +1,12 @@ +#include "common.h" + +extern f32 func_00498580(f32, f32, f32, f32); +extern s32 func_00453C68(s32, s32, f32); + +/* Advances a float and uses the filtered value in the callback. */ +s32 func_00498670(f32 *a, s32 b, s32 c, f32 x) +{ + f32 t = *a + x; + *a = t; + return func_00453C68(b, c, func_00498580(t, 0.5f, 0.2f, 0.3f)); +} diff --git a/src/game/0049B568.c b/src/game/0049B568.c new file mode 100644 index 000000000..0896ddab8 --- /dev/null +++ b/src/game/0049B568.c @@ -0,0 +1,26 @@ +#include "common.h" + +typedef struct Type1 { + f32 f0, f4, f8, fC, f10, f14, f18, f1C, f20; +} Type1; +/* Update the value vector and optional deltas from its previous values. */ +void func_0049B568(Type1 *p, s32 deltas, f32 a, f32 b, f32 c, f32 d) +{ + if (deltas) { + p->f4 = a - p->f14; + p->f8 = b - p->f18; + p->fC = c - p->f1C; + p->f10 = d - p->f20; + p->f0 = 1.0f; + } else { + p->f4 = 0; + p->f8 = 0; + p->fC = 0; + p->f10 = 0; + p->f0 = 0; + } + p->f14 = a; + p->f18 = b; + p->f1C = c; + p->f20 = d; +} diff --git a/src/game/004A0198.c b/src/game/004A0198.c new file mode 100644 index 000000000..ae4669a2c --- /dev/null +++ b/src/game/004A0198.c @@ -0,0 +1,17 @@ +#include "common.h" + +extern s32 func_00505238(s32, const char *); +typedef struct Type1 { + char pad[0x4C]; + const char *f4C; + char pad50[0x1B0]; +} Type1; +extern Type1 D_00307254[]; + +/* Store the indexed label pointer and update its resource handle. */ +void func_004A0198(s32 index, const char *text) +{ + Type1 *p = (Type1 *)((index << 9) + (u32)D_00307254); + p->f4C = text; + func_00505238((index << 6) + 0x14000C, text); +} diff --git a/src/game/004A0D78.c b/src/game/004A0D78.c new file mode 100644 index 000000000..bf1ac9ee2 --- /dev/null +++ b/src/game/004A0D78.c @@ -0,0 +1,23 @@ +#include "common.h" + +typedef struct Type1 { + f32 f0, f4, f8, fC, f10, f14, f18, f1C, f20; +} Type1; + +/* Evaluate the four components, optionally including their velocity. */ +void func_004A0D78(Type1 *p, f32 *a, f32 *b, f32 *c, f32 *d, s32 mode) +{ + *a = p->f4; + *b = p->f8; + *c = p->fC; + *d = p->f10; + if (!mode) { + f32 t = p->f0; + if (t != 0.0f) { + *a += p->f14 * t; + *b += p->f18 * p->f0; + *c += p->f1C * p->f0; + *d += p->f20 * p->f0; + } + } +} diff --git a/src/game/004A1D58.c b/src/game/004A1D58.c new file mode 100644 index 000000000..4c8008a70 --- /dev/null +++ b/src/game/004A1D58.c @@ -0,0 +1,15 @@ +#include "common.h" + +extern void func_0049EF30(s32); +s32 D_0021F658 = 1; + +/* Select the active mode, resetting it when requested. */ +void func_004A1D58(s32 active) +{ + if (active) { + D_0021F658 = 4; + } else { + func_0049EF30(0); + D_0021F658 = 1; + } +} diff --git a/src/game/004A2020.c b/src/game/004A2020.c new file mode 100644 index 000000000..cecf8b13f --- /dev/null +++ b/src/game/004A2020.c @@ -0,0 +1,21 @@ +#include "common.h" +s32 D_0021F668 = 0; +extern s32 func_004A1DE0(void), func_004E0858(void), func_00157F98(void); +extern const char *func_0045E038(s32); +extern void func_004A2148(s32), func_004A22D8(s32), func_0049B1A0(s32, s32); +extern s32 func_004E21D8(s32, s32, void *); +extern void func_0049E790(s32, const char *, void (*)(s32), s32, s32, s32, s32, f32); +void func_004A2020(void) +{ + if (!func_004A1DE0()) { + D_0021F668 = 1; + func_0049E790(0, func_0045E038(0x377F), func_004A2148, 0, 0, 0, 0, -1.0f); + } else { + func_004E21D8(11, 0, 0); + func_004E0858(); + while (func_00157F98()) { + } + func_004A22D8(1); + func_0049B1A0(0, 33); + } +} diff --git a/src/game/004A2958.c b/src/game/004A2958.c new file mode 100644 index 000000000..173100f33 --- /dev/null +++ b/src/game/004A2958.c @@ -0,0 +1,19 @@ +#include "common.h" + +s32 D_002215D4 = 0; +s32 D_002215C8 = 0; +extern void *D_002215CC; +extern s32 D_002215D0; +extern char D_003D1480[]; + +/* Initialize the shared descriptor on its first request. */ +void *func_004A2958(void) +{ + if (!D_002215D4) { + D_002215C8 = 1; + D_002215CC = D_003D1480; + D_002215D4 = 1; + D_002215D0 = 0; + } + return &D_002215C8; +} diff --git a/src/game/004A2A18.c b/src/game/004A2A18.c new file mode 100644 index 000000000..f78e657d5 --- /dev/null +++ b/src/game/004A2A18.c @@ -0,0 +1,14 @@ +#include "common.h" +int D_002215EC = 0, D_002215E0 = 0; +extern char D_003D1420[]; +extern void *D_002215E4; +/* Initialize the shared descriptor and return it. */ +void *func_004A2A18(void) +{ + if (!D_002215EC) { + D_002215E0 = 1; + D_002215E4 = D_003D1420; + D_002215EC = 1; + } + return &D_002215E0; +} diff --git a/src/game/004A52C0.c b/src/game/004A52C0.c new file mode 100644 index 000000000..f3edbe6ef --- /dev/null +++ b/src/game/004A52C0.c @@ -0,0 +1,12 @@ +#include "common.h" +typedef struct { + char p0[0xD0]; + f32 fD0; + char pD4[24]; +} Type1; +extern Type1 D_00307B58[]; +/* Stores the float in the selected record. */ +void func_004A52C0(s32 index, f32 value) +{ + D_00307B58[index].fD0 = value; +} diff --git a/src/game/004A5688.c b/src/game/004A5688.c new file mode 100644 index 000000000..0cb008825 --- /dev/null +++ b/src/game/004A5688.c @@ -0,0 +1,21 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern s32 func_004A1A60(s32 *, s32); +extern s32 func_00505410(s32, f32); +extern s32 func_00504238(s32, f32, f32); +extern s32 D_00221628; +typedef struct Type1 { + char pad[0x4C]; + f32 f4C; +} Type1; +extern Type1 D_00307F68[]; + +/* Apply the selected channel gain and its derived vertical position. */ +void func_004A5688(void) +{ + Type1 *p = D_00307F68 + func_00505B20(); + func_00505410(func_004A1A60(&D_00221628, -1), p->f4C); + func_00504238(func_004A1A60(&D_00221628, -1), 0.5f, + (1.0f - p->f4C) * -0.14423077f + 0.5f); +} diff --git a/src/game/004A79D8.c b/src/game/004A79D8.c new file mode 100644 index 000000000..cf5cb82e9 --- /dev/null +++ b/src/game/004A79D8.c @@ -0,0 +1,24 @@ +#include "common.h" +typedef struct { + char p0[0x34]; + f32 f34; + char p38[128]; +} Type1; +extern Type1 D_00308108[]; +extern s32 func_00505B20(void); +extern s32 func_00498100(s32); +extern s32 func_00498120(s32); +extern s32 func_0049A6E0(f32 *, f32); +extern void func_004A83A8(void); + +/* Interpolates the active record's state and calls its change handler. */ +void func_004A79D8(void) +{ + s32 state = 0; + s32 i = func_00505B20(); + Type1 *p = &D_00308108[i]; + if (!func_00498100(i) || func_00498120(i) != 1) + state = 1; + if (func_0049A6E0(&p->f34, (f32)state)) + func_004A83A8(); +} diff --git a/src/game/004A81D0.c b/src/game/004A81D0.c new file mode 100644 index 000000000..4b19d40e3 --- /dev/null +++ b/src/game/004A81D0.c @@ -0,0 +1,15 @@ +#include "common.h" +extern s32 D_0020C690[][3]; +extern s32 D_00222010; +extern void func_00453718(void *, const void *, s32); +extern s32 func_004FE948(s32 *, s32, s32, s32); +void func_004A81D0(s32 index, s32 count, s32 seed) +{ + s32 values[3]; + s32 *p = D_0020C690[index]; + s32 i; + func_00453718(values, p, count * 4); + for (i = 0; i < count; i++) { + *p++ = values[func_004FE948(&D_00222010, i + seed, 0, count - 1)]; + } +} diff --git a/src/game/004A83A8.c b/src/game/004A83A8.c new file mode 100644 index 000000000..d13b9a92b --- /dev/null +++ b/src/game/004A83A8.c @@ -0,0 +1,15 @@ +#include "common.h" + +extern int func_00505B20(void); +extern char D_00308108[]; +extern int D_00221650; +extern s32 func_00505410(s32, f32); +extern s32 func_00504238(s32, f32, f32); +/* Scale the selected channel and adjust its output values. */ +void func_004A83A8(void) +{ + char *p = D_00308108 + func_00505B20() * 0xB8; + float a = *(float *)(p + 0x30) * *(float *)(p + 0x34); + func_00505410(D_00221650, a); + func_00504238(D_00221650, (1.0f - a) * -0.3f + 0.5f, 0.5f); +} diff --git a/src/game/004A8C28.c b/src/game/004A8C28.c new file mode 100644 index 000000000..9c04c4e1a --- /dev/null +++ b/src/game/004A8C28.c @@ -0,0 +1,14 @@ +#include "common.h" + +extern s32 D_0020C690[][3]; + +s32 func_004A8C28(s32 index) +{ + s32 i; + for (i = 0; i < 3; i++) { + if (D_0020C690[index][i] == 0) { + return i; + } + } + return 3; +} diff --git a/src/game/004A98C0.c b/src/game/004A98C0.c new file mode 100644 index 000000000..52c0d7390 --- /dev/null +++ b/src/game/004A98C0.c @@ -0,0 +1,21 @@ +#include "common.h" +typedef struct { + char pad[0x88]; + f32 value; + char pad8C[0xC]; + u32 flags; + char tail[0x1C]; +} State; +extern State D_00308108[]; +extern s32 D_00221650; +extern s32 func_00505B20(void), func_004A1A60(s32 *, s32); +extern s32 func_00504238(s32, f32, f32), func_00505410(s32, f32); +void func_004A98C0(void) +{ + s32 index = func_00505B20(); + f32 value = ((State *)((u32)index * 0xB8 + (u32)D_00308108))->value; + f32 inv = 1.0f - value; + func_00504238(func_004A1A60(&D_00221650, 1), inv * -0.1f + 0.5f, inv * 0.0f + 0.5f); + func_00505410(func_004A1A60(&D_00221650, 1), value); + D_00308108[index].flags |= 0x100; +} diff --git a/src/game/004AA9E0.c b/src/game/004AA9E0.c new file mode 100644 index 000000000..79ef7c803 --- /dev/null +++ b/src/game/004AA9E0.c @@ -0,0 +1,18 @@ +#include "common.h" +typedef struct { + char p0[12]; + f32 fC; + char p10[0x160]; +} Type1; +extern Type1 D_00308B80[]; +extern s32 func_00505B20(void); +extern s32 func_00505410(s32, f32); +extern s32 func_00504238(s32, f32, f32); + +/* Applies the active record's scalar to two interface properties. */ +void func_004AA9E0(void) +{ + Type1 *p = &D_00308B80[func_00505B20()]; + func_00505410(0x70000, p->fC); + func_00504238(0x70000, 0.5f, (1.0f - p->fC) * 0.2f + 0.5f); +} diff --git a/src/game/004ADA00.c b/src/game/004ADA00.c new file mode 100644 index 000000000..bab45352f --- /dev/null +++ b/src/game/004ADA00.c @@ -0,0 +1,17 @@ +#include "common.h" +typedef struct { + s32 pad; + f32 value; + char rest[0x48]; +} State; +extern State D_003091A0[]; +extern s32 D_00221690; +extern s32 func_00505B20(void); +extern s32 func_00505410(s32, f32); +extern s32 func_00504238(s32, f32, f32); +void func_004ADA00(void) +{ + State *p = &D_003091A0[func_00505B20()]; + func_00505410(D_00221690, p->value); + func_00504238(D_00221690, (1.0f - p->value) * 0.3f + 0.5f, 0.5f); +} diff --git a/src/game/004AE190.c b/src/game/004AE190.c new file mode 100644 index 000000000..e47062085 --- /dev/null +++ b/src/game/004AE190.c @@ -0,0 +1,28 @@ +#include "common.h" +typedef struct { s32 a; s32 b; u8 c; u8 pad[3]; } Entry; +typedef struct { u8 pad[24]; s32 value[4][4]; u8 tail[12]; } Group; +extern Entry D_003D92A0[]; +extern Group D_003092A0[]; +s32 D_0021F738 = 0; +s32 D_0021F73C = 0; +void func_004AE190(void) { + Entry *p; + s32 i, j; + p = D_003D92A0; + do { + p->a = 0; + p->b = 0; + p->c = 0; + p++; + } while ((s32)p < (s32)(D_003D92A0 + 4)); + for (i = 0; i < 2; i++) { + for (j = 0; j < 4; j++) { + D_003092A0[i].value[0][j] = 0; + D_003092A0[i].value[1][j] = 0; + D_003092A0[i].value[2][j] = 0; + D_003092A0[i].value[3][j] = 0; + } + } + D_0021F738 = 0; + D_0021F73C = 2; +} diff --git a/src/game/004AF198.c b/src/game/004AF198.c new file mode 100644 index 000000000..84bc16bca --- /dev/null +++ b/src/game/004AF198.c @@ -0,0 +1,19 @@ +#include "common.h" +f32 D_0021F738 = 0.0f; +s32 D_0021F73C = 0; +extern s32 D_002216B0; +extern s32 func_004A1A60(s32 *, s32); +extern s32 func_00505410(s32, f32), func_00504238(s32, f32, f32); +extern f32 func_004756D0(f32, f32, f32); +void func_004AF198(void) +{ + D_0021F738 -= 0.05f; + func_00505410(func_004A1A60(&D_002216B0, 100), D_0021F738); + if (D_0021F738 <= 0.0f) + D_0021F73C &= ~8; + else if (D_0021F738 < 1.0f) { + s32 id = func_004A1A60(&D_002216B0, 100); + f32 y = func_004756D0(0.74f, 0.7f, D_0021F738); + func_00504238(id, 0.128f, y); + } +} diff --git a/src/game/004B1090.c b/src/game/004B1090.c new file mode 100644 index 000000000..448fbdcbe --- /dev/null +++ b/src/game/004B1090.c @@ -0,0 +1,17 @@ +#include "common.h" +extern void func_004B1F38(void); +extern void func_004B15E8(void); +typedef struct Type1 { + int f0, f4, f8; + char p[0x2C]; + unsigned char f38; +} Type1; +extern Type1 D_00309650[]; +/* Initialize the panel and start its positive selection. */ +void func_004B1090(void) +{ + func_004B1F38(); + D_00309650[0].f38 = D_00309650[0].f8 = 1; + if (D_00309650[0].f4 > 0) + func_004B15E8(); +} diff --git a/src/game/004B1138.c b/src/game/004B1138.c new file mode 100644 index 000000000..a00c8edc3 --- /dev/null +++ b/src/game/004B1138.c @@ -0,0 +1,30 @@ +#include "common.h" + +extern void func_005014B0(void *); +extern void func_004B11B8(void); +extern void func_004B1238(void); +typedef struct Type1 { + char pad[8]; + s32 f8; + char padC[0x2C]; + u8 f38; +} Type1; +extern Type1 D_00309650[]; + +/* Process descriptor state and any deferred refresh. */ +void func_004B1138(void *descriptor) +{ + switch (D_00309650[0].f8) { + case 0: + break; + case 1: + D_00309650[0].f8 = 0; + break; + case 2: + func_005014B0(descriptor); + break; + } + func_004B11B8(); + if (D_00309650[0].f38) + func_004B1238(); +} diff --git a/src/game/004B1678.c b/src/game/004B1678.c new file mode 100644 index 000000000..85ff2505c --- /dev/null +++ b/src/game/004B1678.c @@ -0,0 +1,15 @@ +#include "common.h" +extern s32 func_00498DC8(void), func_0011D920(char *, const char *, ...); +extern s32 func_004A1A60(s32 *, s32), func_00505238(u32, const char *), func_00504F68(u32, s32); +extern s32 D_00221728; +extern char D_00309664[]; +extern const char D_0021F790[], D_0021F7A0[], D_0021F7A8[]; +void func_004B1678(void) +{ + s32 time = func_00498DC8(); + s32 minutes = time / 60000; + s32 seconds = (time % 60000) / 1000; + func_0011D920(D_00309664, D_0021F790, minutes < 10 ? D_0021F7A0 : D_0021F7A8, minutes, seconds < 10 ? D_0021F7A0 : D_0021F7A8, seconds); + func_00505238(func_004A1A60(&D_00221728, 25), D_00309664); + func_00504F68(func_004A1A60(&D_00221728, 25), time != -1); +} diff --git a/src/game/004B5080.c b/src/game/004B5080.c new file mode 100644 index 000000000..a056dc8f1 --- /dev/null +++ b/src/game/004B5080.c @@ -0,0 +1,28 @@ +#include "common.h" +typedef struct { + int f0, f4; + float current, target; + char pad[0x18]; + int timer; + unsigned char changed; +} State; +extern State D_00309840[]; +extern int func_004534D0(int *); +extern f32 func_004757E0(f32 *, f32, f32, f32); +extern void func_004B5138(void); +void func_004B5080(void) +{ + int changed = 0, refresh = 0; + if (D_00309840[0].target != D_00309840[0].current) { + if (D_00309840[0].timer) + func_004534D0(&D_00309840[0].timer); + else + func_004757E0(&D_00309840[0].target, D_00309840[0].current, 0.1f, 0.005f); + refresh = 1; + changed = 1; + } else + D_00309840[0].timer = 30; + if (refresh) + func_004B5138(); + D_00309840[0].changed = changed; +} diff --git a/src/game/004B56F8.c b/src/game/004B56F8.c new file mode 100644 index 000000000..aee268355 --- /dev/null +++ b/src/game/004B56F8.c @@ -0,0 +1,14 @@ +#include "common.h" + +extern s32 D_00221768; +extern s32 func_004A1A60(s32 *, s32), func_00504338(s32, f32); +extern f32 func_005044A8(s32); +void func_004B56F8(void) +{ + s32 handle = func_004A1A60(&D_00221768, 1); + if (func_005044A8(handle) < 0.5f) + func_00504338(handle, func_005044A8(handle) + 0.02f); + handle = func_004A1A60(&D_00221768, 11); + if (func_005044A8(handle) > 0.5f) + func_00504338(handle, func_005044A8(handle) - 0.02f); +} diff --git a/src/game/004BACD8.c b/src/game/004BACD8.c new file mode 100644 index 000000000..ca183acc2 --- /dev/null +++ b/src/game/004BACD8.c @@ -0,0 +1,25 @@ +#include "common.h" +extern void func_00497980(int); +extern void func_004BAD50(int); +extern s32 func_004A1A60(s32 *, s32); +extern s32 func_00505238(s32, const char *); +extern int D_002217E0; +extern int D_003D95AC[]; +unsigned char D_0021F8DA = 0; +extern unsigned char D_0021F8D8; +extern int D_0021DE6C; +extern char D_0030A4E0[]; +/* Select the panel mode and refresh its displayed text. */ +void func_004BACD8(int a) +{ + s32 p; + if (!a) { + func_00497980(4); + func_004BAD50(0); + } else + func_00497980(11); + D_0021F8DA = 0; + D_0021F8D8 = 0; + p = func_004A1A60(&D_002217E0, D_003D95AC[0]); + func_00505238(p, D_0030A4E0 + D_0021DE6C * 48); +} diff --git a/src/game/004BB9E8.c b/src/game/004BB9E8.c new file mode 100644 index 000000000..1df485a16 --- /dev/null +++ b/src/game/004BB9E8.c @@ -0,0 +1,26 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern void func_004A1310(void *); +extern void func_004A1358(void *); +extern void func_00497980(s32); +extern char D_0030A6F0[]; + +/* Change the current selection, play its sound and request an update. */ +void func_004BB9E8(s32 forward) +{ + char *p = D_0030A6F0 + func_00505B20() * 0x534; + char *menu; + if (forward) { + menu = p + 0x4C8; + func_004A1310(menu); + } else { + menu = p + 0x4C8; + func_004A1358(menu); + } + if (*(s32 *)(menu + 0x50) >= 2) + func_00497980(10); + else + func_00497980(4); + *(s32 *)(p + 4) |= 5; +} diff --git a/src/game/004BBA80.c b/src/game/004BBA80.c new file mode 100644 index 000000000..866ebbaa0 --- /dev/null +++ b/src/game/004BBA80.c @@ -0,0 +1,18 @@ +#include "common.h" + +/* Sets the transition flags and schedules mode 21 for the current slot. */ +extern u8 D_0021F939, D_0021F938, D_0021F93A; +u8 D_0021F8E8 = 0; +extern s32 D_0021DE10; +extern s32 func_00505B20(void); +extern void func_0049B1A0(s32, s32); +void func_004BBA80(void) +{ + if ((D_0021F939 || D_0021DE10 != 15) && D_0021DE10 != 35) { + s32 slot = func_00505B20(); + D_0021F938 = 1; + D_0021F93A = 1; + D_0021F8E8 = 1; + func_0049B1A0(slot, 21); + } +} diff --git a/src/game/004BBAE8.c b/src/game/004BBAE8.c new file mode 100644 index 000000000..bfa35ccf4 --- /dev/null +++ b/src/game/004BBAE8.c @@ -0,0 +1,17 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern void func_004A13A0(void *, f32 *, f32 *, f32 *, f32 *); +extern void func_0049BFC0(s32, s32, s32, f32, f32, f32, f32); +extern char D_0030A6F0[]; + +/* Refresh the current rectangle and clear its pending update bit. */ +void func_004BBAE8(void) +{ + f32 a, b, c, d; + s32 index = func_00505B20(); + char *p = D_0030A6F0 + index * 0x534; + func_004A13A0(p + 0x4C8, &a, &b, &c, &d); + func_0049BFC0(index, 0, 0, a, b, c, d); + *(s32 *)(p + 4) &= ~4; +} diff --git a/src/game/004BDD10.c b/src/game/004BDD10.c new file mode 100644 index 000000000..a5071f7b0 --- /dev/null +++ b/src/game/004BDD10.c @@ -0,0 +1,16 @@ +#include "common.h" +u8 D_0021F93B = 0; +s32 D_0021F934 = 0; +extern char D_0030B358[]; +extern s32 func_00505B20(void); +extern void func_0049B1A0(s32, s32); + +/* Marks the mode active and snapshots the selected record value. */ +void func_004BDD10(void) +{ + s32 i = func_00505B20(); + char *p = D_0030B358 + i * 600; + D_0021F93B = 1; + D_0021F934 = *(s32 *)(p + 0x240); + func_0049B1A0(i, 21); +} diff --git a/src/game/004BF2C0.c b/src/game/004BF2C0.c new file mode 100644 index 000000000..e5ed8c6ba --- /dev/null +++ b/src/game/004BF2C0.c @@ -0,0 +1,20 @@ +#include "common.h" +/* Map the supported kind values to consecutive categories. */ +int func_004BF2C0(int a) +{ + int r = 0; + switch (a) { + case 1: + break; + case 2: + r = 1; + break; + case 3: + r = 2; + break; + case 4: + r = 3; + break; + } + return r; +} diff --git a/src/game/004C1068.c b/src/game/004C1068.c new file mode 100644 index 000000000..986bff1f2 --- /dev/null +++ b/src/game/004C1068.c @@ -0,0 +1,17 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern void func_004A13A0(void *, f32 *, f32 *, f32 *, f32 *); +extern void func_0049BFC0(s32, s32, s32, f32, f32, f32, f32); +extern char D_0030B358[]; + +/* Applies four values from the active record and clears its flag. */ +void func_004C1068(void) +{ + s32 i = func_00505B20(); + char *p = D_0030B358 + i * 600; + f32 x0, x1, x2, x3; + func_004A13A0(p + 492, &x0, &x1, &x2, &x3); + func_0049BFC0(i, 0, 0, x0, x1, x2, x3); + *(s32 *)(p + 4) &= ~1; +} diff --git a/src/game/004C2558.c b/src/game/004C2558.c new file mode 100644 index 000000000..0acd45d02 --- /dev/null +++ b/src/game/004C2558.c @@ -0,0 +1,22 @@ +#include "common.h" +typedef struct { + s32 pad0, pad4; + s32 flags; + s32 padC, value; + char pad14[0x50]; + f32 current; + char tail[0xC]; +} State; +extern State D_0030B7F8[]; +extern s32 D_00221888; +extern s32 func_00505B20(void); +extern f32 func_004757E0(f32 *, f32, f32, f32); +extern s32 func_00504238(s32, f32, f32); +void func_004C2558(void) +{ + State *p = D_0030B7F8 + func_00505B20(); + if (func_004757E0(&p->current, (f32)p->value * -0.22596153616905212f, 0.2f, 0.01f) != 0.0f) + func_00504238(D_00221888, 0.5f, p->current + 0.5f); + else + p->flags &= ~8; +} diff --git a/src/game/004C2FF8.c b/src/game/004C2FF8.c new file mode 100644 index 000000000..d15f6614e --- /dev/null +++ b/src/game/004C2FF8.c @@ -0,0 +1,26 @@ +#include "common.h" +typedef struct { + char pad[0xC]; + s32 selection; + char tail[0x64]; +} State; +typedef struct { + s32 first, second, third; +} Resource; +extern State D_0030B7F8[]; +extern Resource D_003D2180[]; +extern s32 D_00221880; +extern s32 func_00505B20(void), func_004A1A60(s32 *, s32); +extern u32 func_004C2EE0(s32, s32); +extern s32 func_00505328(s32, u32); +extern void func_0049C158(s32, s32, s32, s32); +void func_004C2FF8(void) +{ + s32 selected = D_0030B7F8[func_00505B20()].selection; + s32 id = func_004A1A60(&D_00221880, D_003D2180[selected].first); + func_00505328(id, func_004C2EE0(selected, 1)); + { + s32 index = func_00505B20(); + func_0049C158(index, 0, func_004A1A60(&D_00221880, D_003D2180[selected].second), 0); + } +} diff --git a/src/game/004C30B8.c b/src/game/004C30B8.c new file mode 100644 index 000000000..12063826d --- /dev/null +++ b/src/game/004C30B8.c @@ -0,0 +1,24 @@ +#include "common.h" +typedef struct { + char pad[8]; + s32 flags; + s32 choice; + char rest[0x64]; +} State; +extern State D_0030B7F8[]; +extern s32 func_00505B20(void); +extern void func_004C2F78(void); +extern void func_004C2FF8(void); +extern s32 func_004C2F28(s32); +extern s32 func_004976C8(s32 *, s32, s32, void (*)(void), void (*)(void), s32 (*)(s32)); +extern void func_00497980(s32); +extern void func_004C2610(void); +void func_004C30B8(s32 a) +{ + State *p = &D_0030B7F8[func_00505B20()]; + if (func_004976C8(&p->choice, 10, a, func_004C2F78, func_004C2FF8, func_004C2F28)) { + func_00497980(15); + func_004C2610(); + p->flags |= 1; + } +} diff --git a/src/game/004C3250.c b/src/game/004C3250.c new file mode 100644 index 000000000..ef81fd971 --- /dev/null +++ b/src/game/004C3250.c @@ -0,0 +1,21 @@ +#include "common.h" +typedef struct { + s32 f0, f4, flags, fC, selection; + char tail[0x60]; +} State; +extern State D_0030B7F8[]; +extern s32 D_00221888; +extern s32 func_00505B20(void), func_004A1A60(s32 *, s32), func_00506358(u32); +extern void func_004C3140(void), func_004C31A8(void), func_00497980(s32); +extern s32 func_004976C8(s32 *, s32, s32, void (*)(void), void (*)(void), s32 (*)(s32)); +void func_004C3250(s32 reverse) +{ + State *p = D_0030B7F8 + func_00505B20(); + if (func_004976C8(&p->selection, 3, reverse, func_004C3140, func_004C31A8, 0)) { + func_00497980(0); + func_00506358(func_004A1A60(&D_00221888, 83)); + func_00506358(func_004A1A60(&D_00221888, 80)); + func_00506358(func_004A1A60(&D_00221888, 81)); + p->flags |= 8; + } +} diff --git a/src/game/004C3B88.c b/src/game/004C3B88.c new file mode 100644 index 000000000..c6c055dbd --- /dev/null +++ b/src/game/004C3B88.c @@ -0,0 +1,39 @@ +#include "common.h" +typedef struct { + char pad[8]; + s32 flags; + s32 choice; + s32 other; + s32 desired; + char rest[0x5C]; +} State; +typedef struct { + char pad[0x26E4]; + void *equipment; +} Player; +extern State D_0030B7F8[]; +extern s32 func_00505B20(void); +extern Player *func_00510BE8(s32); +extern s32 func_004978C0(s32); +extern s32 func_0054A7E0(void *, s32); +extern s32 func_0054A370(void *, s32, s32); +extern s32 func_0054A608(void *, s32, s32); +extern void func_00497980(s32); +void func_004C3B88(void) +{ + State *p; + Player *player; + s32 item; + s32 index = func_00505B20(); + p = &D_0030B7F8[index]; + player = func_00510BE8(index); + item = func_004978C0(p->choice); + if (func_0054A7E0(player->equipment, item) != p->desired) { + if (p->desired) + func_0054A370(player->equipment, item, p->desired); + else + func_0054A608(player->equipment, item, 1); + func_00497980(22); + p->flags |= 64; + } +} diff --git a/src/game/004C70C0.c b/src/game/004C70C0.c new file mode 100644 index 000000000..966f378b6 --- /dev/null +++ b/src/game/004C70C0.c @@ -0,0 +1,21 @@ +#include "common.h" + +/* Choose the packed color from the three state flags and the selection. */ +typedef struct { + u8 f0, f1, f2; +} Type1; +u32 func_004C70C0(Type1 *p, s32 a) +{ + if (p->f0) + return 0x80404040; + if (a) + return 0x808080F0; + if (p->f2) + return 0x8080F0F0; + { + u32 result = 0x80808080; + if (!p->f1) + result = 0x80D0D0D0; + return result; + } +} diff --git a/src/game/004C72E0.c b/src/game/004C72E0.c new file mode 100644 index 000000000..fd37502de --- /dev/null +++ b/src/game/004C72E0.c @@ -0,0 +1,20 @@ +#include "common.h" +extern int D_0021F198, D_0021EDD4, D_0021EDD8, D_0021DE10; +extern int D_00241B00[]; +extern void func_00497980(int), func_004C73A8(int), func_0049B208(int); +extern const char *func_0045E038(int); +extern int func_00505B20(void); +extern void func_0049E790(int, const char *, void (*)(int), int, int, int, int, float); +void func_004C72E0(void) +{ + if (D_0021F198 != -1) { + int state = 1; + if (!D_0021EDD4 && D_0021EDD8 == 1) + state = 21; + if (D_0021DE10 == state && D_0021F198 < 8 && D_00241B00[0] == 1) { + func_00497980(7); + func_0049E790(4, func_0045E038(0x362E), func_004C73A8, 3, 0, 0, 0, -1.0f); + } else + func_0049B208(func_00505B20()); + } +} diff --git a/src/game/004C77E8.c b/src/game/004C77E8.c new file mode 100644 index 000000000..34d45d887 --- /dev/null +++ b/src/game/004C77E8.c @@ -0,0 +1,13 @@ +#include "common.h" +extern s32 func_00505B20(void); +extern void func_0049B1A0(s32, s32); +extern u8 D_0021F8E8, D_0021F93A, D_0021F938; +/* Set the three entry flags and select the operation for the current slot. */ +void func_004C77E8(void) +{ + s32 slot = func_00505B20(); + D_0021F93A = 1; + D_0021F938 = 1; + D_0021F8E8 = 1; + func_0049B1A0(slot, 21); +} diff --git a/src/game/004C81B0.c b/src/game/004C81B0.c new file mode 100644 index 000000000..710ff1733 --- /dev/null +++ b/src/game/004C81B0.c @@ -0,0 +1,30 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern s32 func_00505AD8(s32); +extern void *func_004C5670(s32); +extern void func_00501498(void *); +extern s32 func_00505C90(void *); +extern void func_00497980(s32); +extern u8 D_0021F8E8; +typedef struct Type1 { + char pad[0x10]; + s32 f10; + char pad14[0xB1C]; +} Type1; +extern Type1 D_0030B9D8[]; + +/* Reset the selected descriptor, restore the slot and mark its state pending. */ +void func_004C81B0(s32 index) +{ + s32 saved = func_00505B20(); + func_00505AD8(index); + func_00501498(func_004C5670(index)); + func_00505C90(func_004C5670(index)); + func_00505AD8(saved); + if (!D_0021F8E8) + func_00497980(5); + else + D_0021F8E8 = 0; + D_0030B9D8[index].f10 |= 4; +} diff --git a/src/game/004C8768.c b/src/game/004C8768.c new file mode 100644 index 000000000..5f56b6f60 --- /dev/null +++ b/src/game/004C8768.c @@ -0,0 +1,31 @@ +#include "common.h" +typedef struct { + s32 mode, flags; + char pad[0x1304]; + char context[0x6C]; +} State; +extern State D_0030D188; +extern void func_004C92C0(void), func_004C8B60(void), func_004C8C70(void), func_004C8EF8(void); +extern void func_005014B0(void *); +extern s32 func_004A1730(void *); +void func_004C8768(void *descriptor) +{ + switch (D_0030D188.mode) { + case 0: + D_0030D188.mode = 2; + break; + case 2: + func_004C92C0(); + break; + case 1: + func_005014B0(descriptor); + break; + } + if (D_0030D188.flags & 1) + func_004C8B60(); + func_004A1730(D_0030D188.context); + if (D_0030D188.flags & 2) + func_004C8C70(); + if (D_0030D188.flags & 4) + func_004C8EF8(); +} diff --git a/src/game/004C91A0.c b/src/game/004C91A0.c new file mode 100644 index 000000000..f97afef07 --- /dev/null +++ b/src/game/004C91A0.c @@ -0,0 +1,17 @@ +#include "common.h" +extern u8 D_0030E532[]; +extern char *func_0045E038(s32); +extern void func_004C9168(s32); +extern void func_0049B208(s32); +extern void func_0049E790(s32, char *, void (*)(s32), s32, + s32, s32, s32, f32); + +/* Opens the confirmation view or restores state depending on the flag. */ +void func_004C91A0(void) +{ + if (D_0030E532[0]) + func_0049E790(0, func_0045E038(0x3515), func_004C9168, + 3, 0, 0, 0, -1.0f); + else + func_0049B208(0); +} diff --git a/src/game/004CA948.c b/src/game/004CA948.c new file mode 100644 index 000000000..77efa93cb --- /dev/null +++ b/src/game/004CA948.c @@ -0,0 +1,33 @@ +#include "common.h" + +typedef struct Type1 { + s32 f0, f4, f8; +} Type1; +extern Type1 D_0030E9D8[]; +extern s32 func_004CAF90(s32); +extern void func_004CAA50(s32), func_004CAEC8(s32), func_0049C248(s32, s32), func_0049C328(s32, s32, s32), func_0049C200(s32, s32); +void func_004CA948(void) +{ + if (D_0030E9D8[0].f8 & 1) { + s32 i; + if (D_0030E9D8[0].f4 != -1) { + if (!func_004CAF90(D_0030E9D8[0].f4)) + D_0030E9D8[0].f4 = -1; + } + i = 0; + do { + func_004CAA50(i); + if (D_0030E9D8[0].f4 == -1 && func_004CAF90(i)) + D_0030E9D8[0].f4 = i; + i++; + } while (i < 4); + if (D_0030E9D8[0].f4 == -1) + func_0049C248(0, 0); + else { + func_0049C328(0, 0, 1); + func_0049C200(0, 0); + } + func_004CAEC8(D_0030E9D8[0].f4); + D_0030E9D8[0].f8 &= ~1; + } +} diff --git a/src/game/004CAEC8.c b/src/game/004CAEC8.c new file mode 100644 index 000000000..0bdf3fd83 --- /dev/null +++ b/src/game/004CAEC8.c @@ -0,0 +1,20 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern s32 func_004A1A60(s32 *, s32); +extern void func_0049C158(s32, s32, s32, s32); +typedef struct Type1 { + char pad[0x14]; + s32 f14; + char pad18[8]; +} Type1; +extern Type1 D_003D2618[]; +extern s32 D_002218F8; + +/* Apply the selected record's handle to the current slot. */ +void func_004CAEC8(s32 index) +{ + s32 slot = func_00505B20(); + s32 handle = func_004A1A60(&D_002218F8, D_003D2618[index].f14); + func_0049C158(slot, 0, handle, 0); +} diff --git a/src/game/004CB078.c b/src/game/004CB078.c new file mode 100644 index 000000000..a67b69cab --- /dev/null +++ b/src/game/004CB078.c @@ -0,0 +1,19 @@ +#include "common.h" +extern unsigned char D_0021EE18; +int D_0021FA2C = 1; +extern int func_004E21D8(int, int, void *); +extern void func_004CA1D0(int, int); +void func_004CB078(int a) +{ + if (a) { + if (D_0021EE18) { + D_0021FA2C = 1; + func_004E21D8(14, 0, 0); + func_004CA1D0(2, 0); + } else + func_004CA1D0(15, 0); + } else { + func_004E21D8(12, 0, 0); + func_004CA1D0(1, 0); + } +} diff --git a/src/game/004CB198.c b/src/game/004CB198.c new file mode 100644 index 000000000..b2860cdac --- /dev/null +++ b/src/game/004CB198.c @@ -0,0 +1,24 @@ +#include "common.h" + +extern void func_004D22E0(s32); +extern s32 func_004E21D8(s32, s32, void *); +extern void func_004CA1D0(s32, s32); +extern s32 D_0021DF64; +s32 D_0021FA28 = -1; + +/* Set up the menu transition for the requested selection. */ +void func_004CB198(s32 selection) +{ + func_004D22E0(0); + if (selection == -1) { + func_004E21D8(8, 0, 0); + func_004CA1D0(1, 0); + } else { + D_0021DF64 = selection; + func_004E21D8(14, 0, 0); + if (!D_0021FA28) + func_004CA1D0(24, 0); + else + func_004CA1D0(15, 0); + } +} diff --git a/src/game/004CC148.c b/src/game/004CC148.c new file mode 100644 index 000000000..d803d3c14 --- /dev/null +++ b/src/game/004CC148.c @@ -0,0 +1,23 @@ +#include "common.h" + +extern s32 D_0021EDD4, D_0021EDD8; +extern s32 D_00221920; +extern s32 D_003D2768[], D_003D2738[]; +extern s32 func_004A1A60(s32 *, s32); +extern void func_004CD620(s32); +extern s32 func_00505B20(void); +extern void func_0049C158(s32, s32, s32, s32); +extern s32 func_00505328(s32, u32); + +/* Set the selection's alpha and resource color for the current slot. */ +void func_004CC148(s32 selection) +{ + s32 active = 1; + s32 index; + if (D_0021EDD4 || D_0021EDD8 != 1) + active = selection >= 8; + func_004CD620(active); + index = func_00505B20(); + func_0049C158(index, 0, func_004A1A60(&D_00221920, D_003D2768[selection]), 0); + func_00505328(func_004A1A60(&D_00221920, D_003D2738[selection]), 0x80D0D0D0u); +} diff --git a/src/game/004CC978.c b/src/game/004CC978.c new file mode 100644 index 000000000..190650ba8 --- /dev/null +++ b/src/game/004CC978.c @@ -0,0 +1,25 @@ +#include "common.h" + +extern int func_00505B20(void); +extern char *func_00510BE8(int); +extern s32 func_00547D58(void *, s32); +/* Choose the resource identifier from the current slot mode. */ +int func_004CC978(void) +{ + int r = 0x75A9; + int s = func_00547D58(*(void **)(func_00510BE8(func_00505B20()) + 0x26E4), 1); + switch (s) { + case 0: + break; + case 1: + r = 0x75AA; + break; + case 2: + r = 0x75AB; + break; + case 3: + r = 0x75AD; + break; + } + return r; +} diff --git a/src/game/004CCB18.c b/src/game/004CCB18.c new file mode 100644 index 000000000..95a883b88 --- /dev/null +++ b/src/game/004CCB18.c @@ -0,0 +1,31 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern char *func_00510BE8(s32); +extern const char *func_0045E038(s32); +extern s32 func_00547D58(void *, s32); + +/* Select the label associated with the current inventory state. */ +const char *func_004CCB18(void) +{ + char *p = func_00510BE8(func_00505B20()); + const char *result = func_0045E038(-1); + switch (func_00547D58(*(void **)(p + 0x26E4), 1)) { + case 0: + result = func_0045E038(0x33B1); + break; + case 1: + result = func_0045E038(0x33B2); + break; + case 2: + result = func_0045E038(0x33B3); + break; + case 3: + result = func_0045E038(0x33B4); + break; + default: + result = func_0045E038(0x33B5); + break; + } + return result; +} diff --git a/src/game/004CCCD0.c b/src/game/004CCCD0.c new file mode 100644 index 000000000..05876f45c --- /dev/null +++ b/src/game/004CCCD0.c @@ -0,0 +1,28 @@ +#include "common.h" +extern s32 func_00505B20(void); +extern char *func_00510BE8(s32); +extern const char *func_0045E038(s32); +extern s32 func_00547D58(void *, s32); +const char *func_004CCCD0(void) +{ + char *p = func_00510BE8(func_00505B20()); + const char *result = func_0045E038(-1); + switch (func_00547D58(*(void **)(p + 0x26E4), 1)) { + case 0: + result = func_0045E038(0x33A9); + break; + case 1: + result = func_0045E038(0x33AA); + break; + case 2: + result = func_0045E038(0x33AB); + break; + case 3: + result = func_0045E038(0x33AC); + break; + default: + result = func_0045E038(0x33AD); + break; + } + return result; +} diff --git a/src/game/004CD620.c b/src/game/004CD620.c new file mode 100644 index 000000000..2eec245e5 --- /dev/null +++ b/src/game/004CD620.c @@ -0,0 +1,27 @@ +#include "common.h" +typedef struct { + char pad[0x23]; + unsigned char alpha; +} Object; +typedef struct { + char pad[0x20]; + Object *a, *b, *c; + char tail[0x38]; +} State; +extern State D_0030EAA0[]; +extern int func_00505B20(void); +void func_004CD620(int flag) +{ + State *p = &D_0030EAA0[func_00505B20()]; + if (p->b && p->c && p->a) { + if (flag) { + p->b->alpha = 0; + p->c->alpha = 0; + p->a->alpha = 128; + } else { + p->b->alpha = 128; + p->c->alpha = 128; + p->a->alpha = 0; + } + } +} diff --git a/src/game/004CD6B0.c b/src/game/004CD6B0.c new file mode 100644 index 000000000..714b13867 --- /dev/null +++ b/src/game/004CD6B0.c @@ -0,0 +1,22 @@ +#include "common.h" + +typedef struct Type1 { + char pad[0x74]; + u16 f74; +} Type1; + +/* Place the selected bit in the appropriate object. */ +void func_004CD6B0(Type1 *first, Type1 *second, u32 bit) +{ + if (bit < 5 || !second) { + first->f74 = 1 << bit; + if (second) + second->f74 = 0; + } else { + bit -= 5; + if (bit < 3) { + first->f74 = 0; + second->f74 = 1 << bit; + } + } +} diff --git a/src/game/004CDFE0.c b/src/game/004CDFE0.c new file mode 100644 index 000000000..05208a9e3 --- /dev/null +++ b/src/game/004CDFE0.c @@ -0,0 +1,16 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern void func_004A13A0(void *, f32 *, f32 *, f32 *, f32 *); +extern void func_0049BFC0(s32, s32, s32, f32, f32, f32, f32); +extern char D_0030ECC0[]; +/* Refresh the current entry rectangle and clear its pending bit. */ +void func_004CDFE0(void) +{ + f32 a, b, c, d; + s32 i = func_00505B20(); + char *p = D_0030ECC0 + i * 0x280; + func_004A13A0(p + 0x210, &a, &b, &c, &d); + func_0049BFC0(i, 0, 0, a, b, c, d); + *(s32 *)(p + 8) &= ~4; +} diff --git a/src/game/004CE098.c b/src/game/004CE098.c new file mode 100644 index 000000000..0bca1985a --- /dev/null +++ b/src/game/004CE098.c @@ -0,0 +1,27 @@ +#include "common.h" +typedef struct { + char p0[0x50]; + s32 f50; +} Type1; +extern char D_0030ECC0[]; +extern s32 func_00505B20(void); +extern void func_004A1358(Type1 *); +extern void func_004A1310(Type1 *); +extern s32 func_004E21D8(s32, s32, s32); +extern s32 func_004E0858(void); + +/* Changes the active selection and marks its record dirty. */ +void func_004CE098(s32 a) +{ + char *p = D_0030ECC0 + func_00505B20() * 640; + Type1 *q = (Type1 *)(p + 0x210); + if (q->f50 >= 2) { + if (a) + func_004A1358(q); + else + func_004A1310(q); + func_004E21D8(0, 0, 0); + func_004E0858(); + *(s32 *)(p + 8) |= 6; + } +} diff --git a/src/game/004CEE70.c b/src/game/004CEE70.c new file mode 100644 index 000000000..3fade9cd5 --- /dev/null +++ b/src/game/004CEE70.c @@ -0,0 +1,16 @@ +#include "common.h" + +extern int func_00505B20(void); +extern char D_0030F820[]; +extern void func_004A13A0(void *, float *, float *, float *, float *); +extern void func_0049BFC0(int, int, int, float, float, float, float); +/* Apply the selected table color and clear its update flag. */ +void func_004CEE70(void) +{ + float a, b, c, d; + int i = func_00505B20(); + char *p = D_0030F820 + i * 0x103C; + func_004A13A0(p + 0xF90, &a, &b, &c, &d); + func_0049BFC0(i, 0, 0, a, b, c, d); + *(int *)(p + 8) &= ~4; +} diff --git a/src/game/004CF860.c b/src/game/004CF860.c new file mode 100644 index 000000000..fa4e2c974 --- /dev/null +++ b/src/game/004CF860.c @@ -0,0 +1,35 @@ +#include "common.h" + +typedef struct Type2 Type2; +typedef struct Type1 Type1; +struct Type1 { + char _p0[0x54]; + s32 f54; +}; +struct Type2 { + char _p0[0x8]; + const char *f8; +}; + +s32 func_004A1A60(s32 *, s32); +s32 func_004CFAC8(const char *); +s32 func_00505238(s32, const char *); +s32 func_00505328(s32, s32); + +/* Updates two properties using the selector-dependent value. */ +void func_004CF860(Type1 *arg0, Type2 *arg1, s32 arg2) +{ + s32 temp_s0; + s32 *temp_s2; + const char *temp_s3; + + temp_s2 = (s32 *)((char *)arg1 + 4); + temp_s3 = arg1->f8; + func_00505238(func_004A1A60(temp_s2, 2), temp_s3); + if (arg2 == arg0->f54) { + func_00505328(func_004A1A60(temp_s2, 2), 0x80D0D0D0); + } else { + temp_s0 = func_004A1A60(temp_s2, 2); + func_00505328(temp_s0, func_004CFAC8(temp_s3)); + } +} diff --git a/src/game/004CFA40.c b/src/game/004CFA40.c new file mode 100644 index 000000000..9e322a8ee --- /dev/null +++ b/src/game/004CFA40.c @@ -0,0 +1,16 @@ +#include "common.h" +extern s32 func_00505B20(void); +extern void func_004A13A0(void *, f32 *, f32 *, f32 *, f32 *); +extern void func_0049BFC0(s32, s32, s32, f32, f32, f32, f32); +extern char D_00316D00[]; + +/* Applies four values from the active record and clears flag four. */ +void func_004CFA40(void) +{ + s32 i = func_00505B20(); + char *p = D_00316D00 + i * 2528; + f32 x0, x1, x2, x3; + func_004A13A0(p + 2420, &x0, &x1, &x2, &x3); + func_0049BFC0(i, 0, 0, x0, x1, x2, x3); + *(s32 *)(p + 8) &= ~4; +} diff --git a/src/game/004D08B0.c b/src/game/004D08B0.c new file mode 100644 index 000000000..8fd114f7a --- /dev/null +++ b/src/game/004D08B0.c @@ -0,0 +1,27 @@ +/* cflags: -mno-split-addresses */ +#include "common.h" +extern void func_004D0038(void *, s32); +extern s32 func_004A1A60(void *, s32); +extern const char *func_0045E038(s32); +extern s32 func_00505238(u32, const char *); +extern u8 D_0021DE30[]; +extern s32 D_002209DC; +void func_004D08B0(char *p, s32 reverse) +{ + func_004D0038(p, reverse); + { + u8 *value = &D_0021DE30[*(s32 *)p]; + if (*value == 8) { + if (!reverse) + ++*value; + else + --*value; + } + } + if (p) { + s32 id = func_004A1A60(*(char **)(p + 0x70) + 4, 2); + const char *text = func_0045E038(*(s32 *)(p + (D_0021DE30[*(s32 *)p] << 2) + 0x1C)); + func_00505238(id, text); + } + D_002209DC = -D_0021DE30[*(s32 *)p]; +} diff --git a/src/game/004D0B48.c b/src/game/004D0B48.c new file mode 100644 index 000000000..0125abeb9 --- /dev/null +++ b/src/game/004D0B48.c @@ -0,0 +1,17 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern void func_004A13A0(void *, f32 *, f32 *, f32 *, f32 *); +extern void func_0049BFC0(s32, s32, s32, f32, f32, f32, f32); +extern char D_0031A960[]; + +/* Applies four values from the active record and clears its flag. */ +void func_004D0B48(void) +{ + s32 i = func_00505B20(); + char *p = D_0031A960 + i * 420; + f32 x0, x1, x2, x3; + func_004A13A0(p + 312, &x0, &x1, &x2, &x3); + func_0049BFC0(i, 0, 0, x0, x1, x2, x3); + *(s32 *)(p + 8) &= ~4; +} diff --git a/src/game/004D1CF8.c b/src/game/004D1CF8.c new file mode 100644 index 000000000..827c01194 --- /dev/null +++ b/src/game/004D1CF8.c @@ -0,0 +1,16 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern void func_004A13A0(void *, f32 *, f32 *, f32 *, f32 *); +extern void func_0049BFC0(s32, s32, s32, f32, f32, f32, f32); +extern char D_0031B050[]; +/* Refresh the current entry rectangle and clear its pending bit. */ +void func_004D1CF8(void) +{ + f32 a, b, c, d; + s32 i = func_00505B20(); + char *p = D_0031B050 + i * 0x15c; + func_004A13A0(p + 0xf0, &a, &b, &c, &d); + func_0049BFC0(i, 0, 0, a, b, c, d); + *(s32 *)(p + 8) &= ~4; +} diff --git a/src/game/004D1DA0.c b/src/game/004D1DA0.c new file mode 100644 index 000000000..ff79eb228 --- /dev/null +++ b/src/game/004D1DA0.c @@ -0,0 +1,24 @@ +#include "common.h" +typedef struct { + s32 state, pad, flags; + char rest[0x150]; +} State; +extern State D_0031B050[]; +extern s32 func_00505B20(void); +extern void func_004A1358(void *), func_004A1310(void *); +extern s32 func_004E21D8(s32, s32, void *); +extern s32 func_004E0858(void); +void func_004D1DA0(s32 forward) +{ + State *p = D_0031B050 + func_00505B20(); + char *context = (char *)p + 0xF0; + if (*(s32 *)(context + 0x50) >= 2) { + if (forward) + func_004A1358(context); + else + func_004A1310(context); + func_004E21D8(0, 0, 0); + func_004E0858(); + p->flags |= 6; + } +} diff --git a/src/game/004D39A8.c b/src/game/004D39A8.c new file mode 100644 index 000000000..8242a050e --- /dev/null +++ b/src/game/004D39A8.c @@ -0,0 +1,21 @@ +#include "common.h" +s32 D_0021FB84 = 0; +extern u8 D_002213E0; +extern s32 func_00465C10(s32, void *, s32 (*)(void), void (*)(void)); +extern s32 func_0047F568(s32, s32, s32, s32, u8 *); +extern void func_004D3EF0(void); +void func_004D39A8(void) +{ + switch (D_0021FB84) { + case 0: + func_00465C10(6, 0, 0, 0); + D_002213E0 = 1; + case 1: + func_0047F568(4, 1, 1, 0, 0); + D_0021FB84++; + break; + case 2: + func_004D3EF0(); + break; + } +} diff --git a/src/game/004D3B78.c b/src/game/004D3B78.c new file mode 100644 index 000000000..e498b2451 --- /dev/null +++ b/src/game/004D3B78.c @@ -0,0 +1,35 @@ +#include "common.h" + +s32 D_0021FB84 = 0, D_0021FB8C = 0; +extern s32 func_00465C08(void), func_00159C28(s32); +extern s32 func_00465C10(s32, void *, s32 (*)(void), void (*)(void)); +extern void func_004D3EF8(void), func_004D4328(void), func_004D3EF0(void); +void func_004D3B78(void) +{ + switch (D_0021FB84) { + case 0: + func_00465C10(1, 0, 0, 0); + func_004D3EF8(); + D_0021FB8C = 30; + D_0021FB84++; + return; + case 1: { + s32 timer; + func_004D3EF8(); + timer = D_0021FB8C; + if (timer > 0) { + timer--; + D_0021FB8C = timer; + } + D_0021FB8C = timer; + if (!timer) + func_004D4328(); + break; + } + case 2: + if (func_00465C08() == 1 || func_00465C08() == 18) + func_00159C28(1); + func_004D3EF0(); + break; + } +} diff --git a/src/game/004D3D00.c b/src/game/004D3D00.c new file mode 100644 index 000000000..e4d91723f --- /dev/null +++ b/src/game/004D3D00.c @@ -0,0 +1,32 @@ +#include "common.h" +s32 D_0021FB84 = 0, D_0021FB90 = 0; +extern s32 func_004690E8(void); +extern s32 func_00465C10(s32, void *, s32 (*)(void), void (*)(void)); +extern void func_004D3EF8(void), func_004D4328(void), func_004D3EF0(void); +void func_004D3D00(void) +{ + switch (D_0021FB84) { + case 0: + func_00465C10(3, 0, func_004690E8, 0); + func_004D3EF8(); + D_0021FB90 = 30; + D_0021FB84++; + break; + case 1: + func_004D3EF8(); + { + s32 count = D_0021FB90; + if (count > 0) { + count--; + D_0021FB90 = count; + } + D_0021FB90 = count; + } + if (!D_0021FB90) + func_004D4328(); + break; + case 2: + func_004D3EF0(); + break; + } +} diff --git a/src/game/004D58D0.c b/src/game/004D58D0.c new file mode 100644 index 000000000..26c3ade61 --- /dev/null +++ b/src/game/004D58D0.c @@ -0,0 +1,25 @@ +#include "common.h" +typedef struct { + char p0[0x50]; + s32 f50; +} Type1; +extern Type1 D_0031CCC4[]; +extern s32 D_0031B9B8[]; +extern void func_004A1358(Type1 *); +extern void func_004A1310(Type1 *); +extern s32 func_004E21D8(s32, s32, s32); +extern s32 func_004E0858(void); + +/* Changes selection, marks the dirty flag and refreshes the view. */ +void func_004D58D0(s32 a) +{ + if (D_0031CCC4[0].f50 >= 2) { + if (a) + func_004A1358(D_0031CCC4); + else + func_004A1310(D_0031CCC4); + D_0031B9B8[1] |= 2; + func_004E21D8(0, 0, 0); + func_004E0858(); + } +} diff --git a/src/game/004D62F0.c b/src/game/004D62F0.c new file mode 100644 index 000000000..999d22db2 --- /dev/null +++ b/src/game/004D62F0.c @@ -0,0 +1,16 @@ +#include "common.h" + +extern int func_00505B20(void); +extern char D_0031D100[]; +extern void func_004A13A0(void *, float *, float *, float *, float *); +extern void func_0049BFC0(int, int, int, float, float, float, float); +/* Apply the selected table color and clear its update flag. */ +void func_004D62F0(void) +{ + float a, b, c, d; + int i = func_00505B20(); + char *p = D_0031D100 + i * 0x528; + func_004A13A0(p + 0x4BC, &a, &b, &c, &d); + func_0049BFC0(i, 0, 0, a, b, c, d); + *(int *)(p + 4) &= ~2; +} diff --git a/src/game/004D6E48.c b/src/game/004D6E48.c new file mode 100644 index 000000000..5e3bd9f6b --- /dev/null +++ b/src/game/004D6E48.c @@ -0,0 +1,24 @@ +#include "common.h" +typedef struct { + s32 f0; + s32 f4; + s32 f8; +} Type1; +/* Finds the last occurrences of two keys and merges their counts. */ +void func_004D6E48(Type1 *a, s32 b, s32 c, s32 n) +{ + s32 x = -1; + s32 y = -1; + s32 i; + for (i = 0; i < n; i++) { + s32 value = a[i].f0; + if (value == b) + x = i; + if (value == c) + y = i; + } + if (x >= 0 && y >= 0) { + a[y].f4 += a[x].f4; + a[x].f8 = 0; + } +} diff --git a/src/game/004D73C8.c b/src/game/004D73C8.c new file mode 100644 index 000000000..fbfb30c38 --- /dev/null +++ b/src/game/004D73C8.c @@ -0,0 +1,23 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern s32 func_00505AD8(s32); +extern void *func_004D7250(s32); +extern void func_00501498(void *); +extern s32 func_00505C90(void *); +extern void func_00497980(s32); +u8 D_0021FC11 = 0; + +/* Reset the selected slot while preserving the active slot and notification flag. */ +void func_004D73C8(s32 index) +{ + s32 saved = func_00505B20(); + func_00505AD8(index); + func_00501498(func_004D7250(index)); + func_00505C90(func_004D7250(index)); + func_00505AD8(saved); + if (!D_0021FC11) + func_00497980(11); + else + D_0021FC11 = 0; +} diff --git a/src/game/004D78F0.c b/src/game/004D78F0.c new file mode 100644 index 000000000..2c260600a --- /dev/null +++ b/src/game/004D78F0.c @@ -0,0 +1,23 @@ +#include "common.h" + +extern s32 func_00505B20(void); +extern void func_004A13A0(void *, f32 *, f32 *, f32 *, f32 *); +extern void func_0049BFC0(s32, s32, s32, f32, f32, f32, f32); +extern void func_0049C248(s32, s32); +extern char D_0031E898[]; +u8 D_0021FC10 = 0; + +/* Refresh or hide the current rectangle and clear its pending bit. */ +void func_004D78F0(void) +{ + f32 a, b, c, d; + s32 index = func_00505B20(); + char *p = D_0031E898 + index * 0x528; + if (D_0021FC10) { + func_004A13A0(p + 0x4BC, &a, &b, &c, &d); + func_0049BFC0(index, 0, 0, a, b, c, d); + } else { + func_0049C248(index, 0); + } + *(s32 *)(p + 4) &= ~2; +} diff --git a/src/game/004DAD30.c b/src/game/004DAD30.c new file mode 100644 index 000000000..e38364f6b --- /dev/null +++ b/src/game/004DAD30.c @@ -0,0 +1,30 @@ +#include "common.h" + +extern void func_004A1358(void *), func_004A1310(void *), func_00497980(s32); +typedef struct Type1 { + char pad[0x50]; + s32 f50, f54; +} Type1; +extern Type1 D_00322EA4[]; +typedef struct Type2 { + s32 f0; + u32 f4; +} Type2; +extern Type2 D_00321B98[]; +void func_004DAD30(s32 direction) +{ + if (D_00322EA4[0].f50 >= 2) { + s32 previous = D_00322EA4[0].f54; + if (direction) + func_004A1358(D_00322EA4); + else + func_004A1310(D_00322EA4); + if (previous == D_00322EA4[0].f54) + func_00497980(4); + else + func_00497980(0); + D_00321B98[0].f4 |= 2; + return; + } + func_00497980(4); +} diff --git a/src/game/004DB150.c b/src/game/004DB150.c new file mode 100644 index 000000000..63a58759b --- /dev/null +++ b/src/game/004DB150.c @@ -0,0 +1,24 @@ +#include "common.h" +typedef struct { + int f0, flags; + char pad[0x1398]; + int id; + unsigned char changed, active; +} State; +extern State D_00321B98[]; +extern int D_0021EDD4, D_0021EDD8; +extern void func_00497980(int); +void func_004DB150(int id) +{ + State *p = D_00321B98; + if (!D_0021EDD4 && D_0021EDD8 == 1 && p->active) { + if (p->id != id) { + p->id = id; + p->flags |= 3; + p->changed = 1; + p->active = 0; + func_00497980(8); + } else + func_00497980(4); + } +} diff --git a/src/game/004E2E30.c b/src/game/004E2E30.c new file mode 100644 index 000000000..451070c57 --- /dev/null +++ b/src/game/004E2E30.c @@ -0,0 +1,40 @@ +#include "common.h" + +/* Applies indexed flag changes to each entry in the sentinel-terminated group table. */ +typedef struct { + u32 flags; + char pad[0x1F]; + u8 index; + char pad24[0xC]; + u32 other; + char tail[0x1C]; +} Entry; +typedef struct { + Entry *entries; + s32 count; +} Group; +typedef struct { + s16 flags, other; +} Change; +extern Group D_00324080[]; +extern Change D_00323D80[]; +void func_004E2E30(void) +{ + Group *g = D_00324080; + while (g->entries) { + Entry *p = g->entries; + if (g->count > 0) { + s32 count = g->count; + do { + Change *c = &D_00323D80[p->index]; + if (c->flags) + p->flags = (p->flags & 0xFFFFC000) | c->flags; + if (c->other) + p->other = (p->other & 0xFFFFC000) | c->other; + p++; + count--; + } while (count != 0); + } + g++; + } +} diff --git a/src/game/004E4C50.c b/src/game/004E4C50.c new file mode 100644 index 000000000..4713ec5b7 --- /dev/null +++ b/src/game/004E4C50.c @@ -0,0 +1,26 @@ +/* cflags: -mno-split-addresses */ +#include "common.h" + +typedef void (*Type1)(void *, f32); +extern s32 func_00489FA0(void *, s32, s32, Type1, void *); +extern void func_004394A8(s32); +extern void func_004E23A0(void); +extern void func_00489368(void); +extern void func_004E0858(void); +extern s32 func_00157F98(void); +extern s32 func_00138D70(s32); +extern char D_002214D0[]; + +/* Flush active work and optionally wait for the transfer engine to finish. */ +void func_004E4C50(s32 wait) +{ + func_00489FA0(D_002214D0, 1, 300, 0, 0); + func_004394A8(1); + func_004E23A0(); + func_00489368(); + func_004E0858(); + if (wait) { + while (func_00157F98()) + func_00138D70(0); + } +} diff --git a/src/game/004E55C0.c b/src/game/004E55C0.c new file mode 100644 index 000000000..5866e79d0 --- /dev/null +++ b/src/game/004E55C0.c @@ -0,0 +1,26 @@ +#include "common.h" +typedef struct { + char p0[32]; + u8 f20; + char p21[19]; + u16 f34; + char p36[134]; + s16 fBC; + char pBE[66]; +} Type1; +extern Type1 *D_0022140C; + +/* Sets bit128 on eligible records until the byte sentinel. */ +void func_004E55C0(s32 enabled) +{ + Type1 *p = D_0022140C; + while (p->f20 != 255) { + if (!(p->f20 & 128) && (p->fBC == 0x183A || p->fBC == 0x183C)) { + if (enabled) + p->f34 |= 128; + else + p->f34 &= 0xFF7F; + } + p++; + } +} diff --git a/src/game/004EA658.c b/src/game/004EA658.c new file mode 100644 index 000000000..d4be25dee --- /dev/null +++ b/src/game/004EA658.c @@ -0,0 +1,17 @@ +#include "common.h" +typedef struct { + int f0, f4, f8, fC; +} Entry; +extern Entry D_00328548[]; +int func_004EA658(int a, int b) +{ + int i; + int result = 1; + for (i = 0; i < 32; i++) { + if (D_00328548[i].f4 == a && D_00328548[i].f0 == b) { + result = 0; + break; + } + } + return result; +} diff --git a/src/game/004EAB80.c b/src/game/004EAB80.c new file mode 100644 index 000000000..20a96e17a --- /dev/null +++ b/src/game/004EAB80.c @@ -0,0 +1,19 @@ +#include "common.h" +extern s32 D_00221E94; +typedef struct { + char p0[8]; + s16 f8; + s16 fA; +} Type1; +extern Type1 D_00327A60[]; +/* Queues changed short selectors unless an update is already pending. */ +void func_004EAB80(s32 a, s32 b) +{ + if (!D_00221E94) { + if (D_00327A60[0].f8 != a || D_00327A60[0].fA != b) { + D_00327A60[0].f8 = a; + D_00327A60[0].fA = b; + D_00221E94 = 45; + } + } +} diff --git a/src/game/004EAF58.c b/src/game/004EAF58.c new file mode 100644 index 000000000..7bd213b4f --- /dev/null +++ b/src/game/004EAF58.c @@ -0,0 +1,15 @@ +#include "common.h" + +extern void func_0046BA60(void *, s32, s32); +extern void func_00453608(void *, s32, s32); +extern void func_004706F0(void *); +/* Preserve and clear object storage, then refresh an enabled object. */ +void func_004EAF58(char *p, s32 arg) +{ + void *saved = *(void **)(p + 0xac); + func_0046BA60(p, arg, 0); + *(void **)(p + 0xac) = saved; + func_00453608(saved, 0, 0x80); + if (!(*(u16 *)(p + 0x34) & 4)) + func_004706F0(p); +} diff --git a/src/game/004EDCE8.c b/src/game/004EDCE8.c new file mode 100644 index 000000000..a3f91f7af --- /dev/null +++ b/src/game/004EDCE8.c @@ -0,0 +1,17 @@ +#include "common.h" +typedef struct { + s16 mode; + s16 value; + f32 factor; + char pad[0x38]; + u8 alpha; +} State; +extern State D_00327A60; +void func_004EDCE8(void) +{ + f32 t = D_00327A60.value * D_00327A60.factor; + if (D_00327A60.mode == 0 || D_00327A60.mode == 6 || D_00327A60.mode == 7) + D_00327A60.alpha = (s32)((1.0f - t) * 128.0f); + else if (D_00327A60.mode == 1) + D_00327A60.alpha = (s32)(t * 128.0f); +} diff --git a/src/game/004EDEA8.c b/src/game/004EDEA8.c new file mode 100644 index 000000000..4998c0507 --- /dev/null +++ b/src/game/004EDEA8.c @@ -0,0 +1,24 @@ +/* cflags: -O2 -G8 */ +#include "common.h" +extern void *func_00548D28(int, int); +void func_004EDEA8(int a1, int a2, int a3) +{ + void *p = func_00548D28(a2, 0); +switch (a2) { + case 2: if (a3 == 9) *(short *)(a1 + 116) = 1; else *(short *)(a1 + 116) = 0; break; + case 3: if (a3 == 9) *(short *)(a1 + 116) = 49; else *(short *)(a1 + 116) = 3; break; + case 6: if (a3 == 9) *(short *)(a1 + 116) = 15; else *(short *)(a1 + 116) = 0; break; + case 7: if (a3 == 9) *(short *)(a1 + 116) = 7; else *(short *)(a1 + 116) = 0; break; + case 4: if (a3 == 9) *(short *)(a1 + 116) = 12; else *(short *)(a1 + 116) = 3; break; + case 8: if (a3 == 9) *(short *)(a1 + 116) = 15; else *(short *)(a1 + 116) = 1; break; + case 5: if (a3 == 9) *(short *)(a1 + 116) = 6; else *(short *)(a1 + 116) = 1; break; + case 15: if (a3 == 9) *(short *)(a1 + 116) = 31; else *(short *)(a1 + 116) = 3; break; + case 9: + if (*(short *)(a1 + 188) == 9458) { + if (a3 == 9) *(short *)(a1 + 116) = 3; else *(short *)(a1 + 116) = 0; + } else if (*(short *)(a1 + 188) == *(short *)((char *)p + 60)) { + if (a3 == 9) *(short *)(a1 + 116) = 7; else *(short *)(a1 + 116) = 6; + } + break; + } +} diff --git a/src/game/004EF6D0.c b/src/game/004EF6D0.c new file mode 100644 index 000000000..88f4438a6 --- /dev/null +++ b/src/game/004EF6D0.c @@ -0,0 +1,43 @@ +/* cflags: -Wuninitialized */ +#include "common.h" +#define __int128 long long +#define __int64 long +#define __int16 short +#define __int8 char +typedef int bool; +typedef u8 _BYTE; typedef u16 _WORD; typedef u32 _DWORD; typedef u64 _QWORD; typedef unsigned long long _OWORD; +typedef u8 _BOOL1; typedef u16 _BOOL2; typedef u32 _BOOL4; typedef u64 _BOOL8; +int func_00159718(unsigned int arg0, int arg1, int arg2, unsigned int arg3, int arg4, unsigned int arg5); +int func_004EF6D0(_DWORD *a1, int a2, int a3, int a4) +{ + int v6; + a1[13] = a2; + a1[16] = a3; + *a1 = 0; + a1[1] = a4; + a1[12] = 0; + a1[14] = 0; + a1[15] = 0; + a1[17] = 0; + a1[20] = 0; + a1[22] = 0; + a1[23] = 0; + if (a4 == 2) + { + a1[19] = 24576; + } + else + if (a4 == 3) + { + a1[19] = 1024; + } + else + { + a1[19] = 49152; + } + v6 = func_00159718((int) a1[19], 4096, 1024, 0, 5, (int) a1[1]); + a1[18] = v6; + if (v6 < 0) + return 0; + return 1; +} diff --git a/src/game/004F1CB8.c b/src/game/004F1CB8.c new file mode 100644 index 000000000..e6b2b8560 --- /dev/null +++ b/src/game/004F1CB8.c @@ -0,0 +1,18 @@ +/* cflags: -mno-split-addresses */ +#include "common.h" + +extern char *D_00221ED4; +extern int func_004F1848(void *, void *); +/* Package the position relative to the owner. */ +int func_004F1CB8(char *p, long a, long b, int c, int d) +{ + struct Type1 { + long a, b; + int c, d; + } s; + s.a = a; + s.b = b; + s.c = c - *(int *)(p + 0x48); + s.d = d; + return func_004F1848(D_00221ED4 + 0x48, &s); +} diff --git a/src/game/004F62E0.c b/src/game/004F62E0.c new file mode 100644 index 000000000..c14d5982e --- /dev/null +++ b/src/game/004F62E0.c @@ -0,0 +1,15 @@ +#include "common.h" +/* Update the object flag after clearing supported object kinds. */ +void func_004F62E0(char *p) +{ + int a = 0; + int k = *(short *)(p + 0xBC); + if (k == 0x216A || k == 0x2567) { + *(int *)(p + 0xA8) = 0; + a = 1; + } + if (a) + *(unsigned short *)(p + 0x34) &= ~2; + else + *(unsigned short *)(p + 0x34) |= 2; +} diff --git a/src/game/004F9CC0.c b/src/game/004F9CC0.c new file mode 100644 index 000000000..c1bbfcac2 --- /dev/null +++ b/src/game/004F9CC0.c @@ -0,0 +1,18 @@ +#include "common.h" +extern u64 D_0020E280[]; +extern int D_0021DF1C; +/* Build the fixed command record and set its byte count. */ +void func_004F9CC0(void) +{ + D_0020E280[0] = 0x1000000000000004ULL; + D_0020E280[1] = 14; + D_0020E280[2] = 0; + D_0020E280[3] = 63; + D_0020E280[4] = 0xA0000000A0ULL; + D_0020E280[5] = 25; + D_0020E280[6] = 96; + D_0020E280[7] = 21; + D_0020E280[8] = 5; + D_0020E280[9] = 9; + D_0021DF1C = 80; +} diff --git a/src/game/004FB940.c b/src/game/004FB940.c new file mode 100644 index 000000000..f5d7dfa9c --- /dev/null +++ b/src/game/004FB940.c @@ -0,0 +1,10 @@ +#include "common.h" +extern s32 *D_00221E20; +/* Writes the command fields and advances the buffer by four words. */ +void func_004FB940(void) +{ + D_00221E20[0] = 0x10000000; + D_00221E20[2] = 0x20000000; + D_00221E20[3] = 0; + D_00221E20 += 4; +} diff --git a/src/game/004FD198.c b/src/game/004FD198.c new file mode 100644 index 000000000..c32591eb5 --- /dev/null +++ b/src/game/004FD198.c @@ -0,0 +1,21 @@ +#include "common.h" + +extern s32 func_004FCE78(s32, s32, s32 *); +/* Count the enabled resource flags. */ +int func_004FD198(void) +{ + int n = 0; + if (func_004FCE78(0x26FA, 0, 0)) + n++; + if (func_004FCE78(0x26FB, 0, 0)) + n++; + if (func_004FCE78(0x26FC, 0, 0)) + n++; + if (func_004FCE78(0x26FD, 0, 0)) + n++; + if (func_004FCE78(0x26FE, 0, 0)) + n++; + if (func_004FCE78(0x2716, 0, 0)) + n++; + return n; +} diff --git a/src/game/004FF4F0.c b/src/game/004FF4F0.c new file mode 100644 index 000000000..bb99e58e1 --- /dev/null +++ b/src/game/004FF4F0.c @@ -0,0 +1,18 @@ +#include "common.h" + +extern int D_00220B70; +typedef struct Type1 { + char p[20]; + int (*f14)(void *, int); +} Type1; +typedef struct Type2 { + char p[8]; + Type1 *f8; +} Type2; +/* Return the object if its virtual predicate succeeds. */ +void *func_004FF4F0(Type2 *p) +{ + if (p && p->f8->f14(p, D_00220B70)) + return p; + return 0; +} diff --git a/src/game/004FF880.c b/src/game/004FF880.c new file mode 100644 index 000000000..4579aeab3 --- /dev/null +++ b/src/game/004FF880.c @@ -0,0 +1,6 @@ +#include "common.h" + +s32 func_004FF880(s32 *arg0,s32 arg1) { + if(arg1<*arg0) return (s32)&arg0[arg1+1]; + return 0; +} diff --git a/src/game/00500F00.c b/src/game/00500F00.c new file mode 100644 index 000000000..e69bd1d62 --- /dev/null +++ b/src/game/00500F00.c @@ -0,0 +1,27 @@ +#include "common.h" +typedef struct { + s32 a, b, c; +} Entry; +typedef struct { + s32 pad; + char *table; +} Manager; +extern char *D_0021DDCC; +extern void func_00503B58(Entry *, s32, s32, s32, s32); +extern void *func_005005D8(void *); +extern s32 func_00503D78(void *, const Entry *); +extern void func_004FFEE0(void *); +void func_00500F00(Manager *manager) +{ + char *state = manager->table; + void *p = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + if (p) { + s32 value = *(s32 *)(D_0021DDCC + 0x1C4); + if (value) { + Entry entry; + func_00503B58(&entry, 0, 1, 0x10000, value); + func_00503D78(func_005005D8(p), &entry); + } + func_004FFEE0(p); + } +} diff --git a/src/game/005011C0.c b/src/game/005011C0.c new file mode 100644 index 000000000..a3ac1705b --- /dev/null +++ b/src/game/005011C0.c @@ -0,0 +1,21 @@ +#include "common.h" + +typedef struct Type1 Type1; +struct Type1 { + char _p0[0x4]; + s32 *f4; +}; + + +s32 func_005011C0(Type1 *arg0, u32 arg1, s32 arg2) { + s32 *temp_v0; + + if (arg1 < 8U) { + temp_v0 = arg0->f4 + arg1; + if (*temp_v0 == 0) { + *temp_v0 = arg2; + return 1; + } + } + return 0; +} diff --git a/src/game/00503D78.c b/src/game/00503D78.c new file mode 100644 index 000000000..c2e29966a --- /dev/null +++ b/src/game/00503D78.c @@ -0,0 +1,21 @@ +#include "common.h" +typedef struct { + s32 a, b, c; +} Entry; +typedef struct { + s32 index; + s32 pad; + s32 count; + s32 padC; + Entry entries[64]; +} Ring; +extern s32 func_00503E18(Ring *); +s32 func_00503D78(Ring *p, Entry *entry) +{ + if (p->count == 64) + func_00503E18(p); + p->entries[p->index] = *entry; + p->index = (p->index + 1) % 64; + p->count++; + return 1; +} diff --git a/src/game/00503E78.c b/src/game/00503E78.c new file mode 100644 index 000000000..0fcdc9788 --- /dev/null +++ b/src/game/00503E78.c @@ -0,0 +1,17 @@ +#include "common.h" +typedef struct { + int a, b, c; +} Record; +typedef struct { + int f0, read, count, fC; + Record records[64]; +} Queue; +extern int func_00503E18(Queue *); +int func_00503E78(Queue *q, Record *out) +{ + if (!q->count) + return 0; + *out = q->records[q->read]; + func_00503E18(q); + return 1; +} diff --git a/src/game/00503EE0.c b/src/game/00503EE0.c new file mode 100644 index 000000000..ad1f2ed0e --- /dev/null +++ b/src/game/00503EE0.c @@ -0,0 +1,50 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0x14]; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220B50; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +extern s32 func_00503FA8(void *, Object *, f32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220B50)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +s32 func_00503EE0(void *context, u32 id, f32 time) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + result = func_00503FA8(context, p, time); + } + return result; +} diff --git a/src/game/00504338.c b/src/game/00504338.c new file mode 100644 index 000000000..ca8d57fa0 --- /dev/null +++ b/src/game/00504338.c @@ -0,0 +1,52 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0x14]; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; + char padC[8]; + f32 value; +}; +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220B50; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220B50)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +s32 func_00504338(u32 id, f32 value) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + p->value = value; + result = 1; + } + return result; +} diff --git a/src/game/005044A8.c b/src/game/005044A8.c new file mode 100644 index 000000000..84fa4efae --- /dev/null +++ b/src/game/005044A8.c @@ -0,0 +1,46 @@ +#include "common.h" + +typedef struct Object Object; +typedef struct Vtable { + void *unused[3]; + u32 (*type)(Object *); + void *f10; + s32 (*supports)(Object *, u32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *vtable; +}; +typedef struct { + s32 f0; + void *context; +} Manager; +extern Manager D_00222038[]; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, s32); +extern u32 D_00220B50; +static inline Object *resolve(s32 handle) +{ + Manager *m; + Object *obj; + void *world; + if (D_00222038[0].context) + m = D_00222038; + else + m = func_005010E0(); + world = 0; + if (m->context) + world = *(void **)((u32)m->context + ((u32) * (s32 *)((char *)m->context + 0x14) << 2)); + obj = func_005005E8(world, handle); + if (obj && obj->vtable->supports(obj, D_00220B50)) + return obj; + return 0; +} +f32 func_005044A8(s32 handle) +{ + f32 result = 255.0f; + Object *obj = resolve(handle); + if (obj) + result = *(f32 *)((char *)obj + 0x14); + return result; +} diff --git a/src/game/00504740.c b/src/game/00504740.c new file mode 100644 index 000000000..825812186 --- /dev/null +++ b/src/game/00504740.c @@ -0,0 +1,52 @@ +#include "common.h" +typedef struct Object Object; +typedef struct Vtable { + void *unused[3]; + u32 (*type)(Object *); + void *f10; + s32 (*supports)(Object *, u32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *vtable; +}; +typedef struct { + s32 f0; + void *context; +} Manager; +extern Manager D_00222038[]; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, s32); +extern u32 D_00220AB8; +static inline Object *resolve(s32 handle) +{ + Manager *m; + Object *obj; + void *world; + if (D_00222038[0].context) + m = D_00222038; + else + m = func_005010E0(); + world = 0; + if (m->context) + world = *(void **)((u32)m->context + ((u32) * (s32 *)((char *)m->context + 0x14) << 2)); + obj = func_005005E8(world, handle); + if (obj && obj->vtable->supports(obj, D_00220AB8)) + return obj; + return 0; +} +typedef s32 (*Callback)(Object *, float *, float *); +extern char D_00336080[]; +extern Callback func_00507A10(void *, u32); +s32 func_00504740(s32 handle, float *a, float *b) +{ + s32 result = 0; + Object *obj = resolve(handle); + if (obj) { + u32 type = obj->vtable->type(obj); + Callback callback = func_00507A10(D_00336080, type); + if (callback) + result = callback(obj, a, b); + } + return result; +} diff --git a/src/game/005048B8.c b/src/game/005048B8.c new file mode 100644 index 000000000..5bdb16282 --- /dev/null +++ b/src/game/005048B8.c @@ -0,0 +1,52 @@ +#include "common.h" +typedef struct Object Object; +typedef struct Vtable { + void *unused[3]; + u32 (*type)(Object *); + void *f10; + s32 (*supports)(Object *, u32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *vtable; +}; +typedef struct { + s32 f0; + void *context; +} Manager; +extern Manager D_00222038[]; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, s32); +extern u32 D_00220AB8; +static inline Object *resolve(s32 handle) +{ + Manager *m; + Object *obj; + void *world; + if (D_00222038[0].context) + m = D_00222038; + else + m = func_005010E0(); + world = 0; + if (m->context) + world = *(void **)((u32)m->context + ((u32) * (s32 *)((char *)m->context + 0x14) << 2)); + obj = func_005005E8(world, handle); + if (obj && obj->vtable->supports(obj, D_00220AB8)) + return obj; + return 0; +} +typedef s32 (*Callback)(Object *, f32, f32); +extern char D_00336778[]; +extern Callback func_00507A80(void *, u32); +s32 func_005048B8(s32 handle, f32 a, f32 b) +{ + s32 result = 0; + Object *obj = resolve(handle); + if (obj) { + u32 type = obj->vtable->type(obj); + Callback callback = func_00507A80(D_00336778, type); + if (callback) + result = callback(obj, a, b); + } + return result; +} diff --git a/src/game/005049B8.c b/src/game/005049B8.c new file mode 100644 index 000000000..d43fa5dfb --- /dev/null +++ b/src/game/005049B8.c @@ -0,0 +1,52 @@ +#include "common.h" +typedef struct Object Object; +typedef struct Vtable { + void *unused[3]; + u32 (*type)(Object *); + void *f10; + s32 (*supports)(Object *, u32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *vtable; +}; +typedef struct { + s32 f0; + void *context; +} Manager; +extern Manager D_00222038[]; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, s32); +extern u32 D_00220AB8; +static inline Object *resolve(s32 handle) +{ + Manager *m; + Object *obj; + void *world; + if (D_00222038[0].context) + m = D_00222038; + else + m = func_005010E0(); + world = 0; + if (m->context) + world = *(void **)((u32)m->context + ((u32) * (s32 *)((char *)m->context + 0x14) << 2)); + obj = func_005005E8(world, handle); + if (obj && obj->vtable->supports(obj, D_00220AB8)) + return obj; + return 0; +} +typedef s32 (*Callback)(Object *, u32); +extern char D_00336230[]; +extern Callback func_00507B00(void *, u32); +s32 func_005049B8(s32 handle, u32 value) +{ + s32 result = 0; + Object *obj = resolve(handle); + if (obj) { + u32 type = obj->vtable->type(obj); + Callback callback = func_00507B00(D_00336230, type); + if (callback) + result = callback(obj, value); + } + return result; +} diff --git a/src/game/00504B90.c b/src/game/00504B90.c new file mode 100644 index 000000000..2ed336d96 --- /dev/null +++ b/src/game/00504B90.c @@ -0,0 +1,61 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0xC]; + u32 (*getType)(Object *); + s32 pad10; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; + +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220AB8; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +typedef s32 (*Callback)(Object *, f32); +extern Callback func_00507BF0(void *, u32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220AB8)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +extern char D_00336668[]; +static inline Callback handler(u32 kind) +{ + return func_00507BF0(D_00336668, kind); +} +s32 func_00504B90(u32 id, f32 amount) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + Callback callback = handler(p->vtable->getType(p)); + if (callback) + result = callback(p, amount); + } + return result; +} diff --git a/src/game/00504C80.c b/src/game/00504C80.c new file mode 100644 index 000000000..2666bd751 --- /dev/null +++ b/src/game/00504C80.c @@ -0,0 +1,61 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0xC]; + u32 (*getType)(Object *); + s32 pad10; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; + +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220AB8; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +typedef s32 (*Callback)(Object *, f32); +extern Callback func_00507BF0(void *, u32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220AB8)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +extern char D_00336470[]; +static inline Callback handler(u32 kind) +{ + return func_00507BF0(D_00336470, kind); +} +s32 func_00504C80(u32 id, f32 amount) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + Callback callback = handler(p->vtable->getType(p)); + if (callback) + result = callback(p, amount); + } + return result; +} diff --git a/src/game/00504D68.c b/src/game/00504D68.c new file mode 100644 index 000000000..20db4ec9c --- /dev/null +++ b/src/game/00504D68.c @@ -0,0 +1,52 @@ +#include "common.h" +typedef struct Object Object; +typedef struct Vtable { + void *unused[3]; + u32 (*type)(Object *); + void *f10; + s32 (*supports)(Object *, u32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *vtable; +}; +typedef struct { + s32 f0; + void *context; +} Manager; +extern Manager D_00222038[]; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, s32); +extern u32 D_00220AB8; +static inline Object *resolve(s32 handle) +{ + Manager *m; + Object *obj; + void *world; + if (D_00222038[0].context) + m = D_00222038; + else + m = func_005010E0(); + world = 0; + if (m->context) + world = *(void **)((u32)m->context + ((u32) * (s32 *)((char *)m->context + 0x14) << 2)); + obj = func_005005E8(world, handle); + if (obj && obj->vtable->supports(obj, D_00220AB8)) + return obj; + return 0; +} +typedef s32 (*Callback)(Object *, float *, float *); +extern char D_003364B8[]; +extern Callback func_00507CD0(void *, u32); +s32 func_00504D68(s32 handle, float *a, float *b) +{ + s32 result = 0; + Object *obj = resolve(handle); + if (obj) { + u32 type = obj->vtable->type(obj); + Callback callback = func_00507CD0(D_003364B8, type); + if (callback) + result = callback(obj, a, b); + } + return result; +} diff --git a/src/game/00504E68.c b/src/game/00504E68.c new file mode 100644 index 000000000..177d169c6 --- /dev/null +++ b/src/game/00504E68.c @@ -0,0 +1,52 @@ +#include "common.h" +typedef struct Object Object; +typedef struct Vtable { + void *unused[3]; + u32 (*type)(Object *); + void *f10; + s32 (*supports)(Object *, u32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *vtable; +}; +typedef struct { + s32 f0; + void *context; +} Manager; +extern Manager D_00222038[]; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, s32); +extern u32 D_00220AB8; +static inline Object *resolve(s32 handle) +{ + Manager *m; + Object *obj; + void *world; + if (D_00222038[0].context) + m = D_00222038; + else + m = func_005010E0(); + world = 0; + if (m->context) + world = *(void **)((u32)m->context + ((u32) * (s32 *)((char *)m->context + 0x14) << 2)); + obj = func_005005E8(world, handle); + if (obj && obj->vtable->supports(obj, D_00220AB8)) + return obj; + return 0; +} +typedef s32 (*Callback)(Object *, float *, float *); +extern char D_00336548[]; +extern Callback func_00507CD0(void *, u32); +s32 func_00504E68(s32 handle, float *a, float *b) +{ + s32 result = 0; + Object *obj = resolve(handle); + if (obj) { + u32 type = obj->vtable->type(obj); + Callback callback = func_00507CD0(D_00336548, type); + if (callback) + result = callback(obj, a, b); + } + return result; +} diff --git a/src/game/00505040.c b/src/game/00505040.c new file mode 100644 index 000000000..4debdd833 --- /dev/null +++ b/src/game/00505040.c @@ -0,0 +1,55 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0x14]; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; + s32 flags; +}; +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220B50; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); + +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220B50)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +s32 func_00505040(u32 id, s32 enabled) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + result = 1; + if (enabled) + p->flags |= 64; + else + p->flags &= ~64; + } + return result; +} diff --git a/src/game/00505410.c b/src/game/00505410.c new file mode 100644 index 000000000..5e43724bc --- /dev/null +++ b/src/game/00505410.c @@ -0,0 +1,61 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0xC]; + u32 (*getType)(Object *); + s32 pad10; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; + +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220AB8; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +typedef s32 (*Callback)(Object *, f32); +extern Callback func_00507BF0(void *, u32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220AB8)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +extern char D_00336158[]; +static inline Callback handler(u32 kind) +{ + return func_00507BF0(D_00336158, kind); +} +s32 func_00505410(u32 id, f32 amount) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + Callback callback = handler(p->vtable->getType(p)); + if (callback) + result = callback(p, amount); + } + return result; +} diff --git a/src/game/005055E0.c b/src/game/005055E0.c new file mode 100644 index 000000000..a275a6a6e --- /dev/null +++ b/src/game/005055E0.c @@ -0,0 +1,52 @@ +#include "common.h" +typedef struct Object Object; +typedef struct Vtable { + void *unused[3]; + u32 (*type)(Object *); + void *f10; + s32 (*supports)(Object *, u32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *vtable; +}; +typedef struct { + s32 f0; + void *context; +} Manager; +extern Manager D_00222038[]; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, s32); +extern u32 D_00220AB8; +static inline Object *resolve(s32 handle) +{ + Manager *m; + Object *obj; + void *world; + if (D_00222038[0].context) + m = D_00222038; + else + m = func_005010E0(); + world = 0; + if (m->context) + world = *(void **)((u32)m->context + ((u32) * (s32 *)((char *)m->context + 0x14) << 2)); + obj = func_005005E8(world, handle); + if (obj && obj->vtable->supports(obj, D_00220AB8)) + return obj; + return 0; +} +typedef s32 (*Callback)(Object *, u32); +extern char D_00336798[]; +extern Callback func_00507F70(void *, u32); +s32 func_005055E0(s32 handle, u32 value) +{ + s32 result = 0; + Object *obj = resolve(handle); + if (obj) { + u32 type = obj->vtable->type(obj); + Callback callback = func_00507F70(D_00336798, type); + if (callback) + result = callback(obj, value); + } + return result; +} diff --git a/src/game/005057E0.c b/src/game/005057E0.c new file mode 100644 index 000000000..7ab015647 --- /dev/null +++ b/src/game/005057E0.c @@ -0,0 +1,52 @@ +#include "common.h" +typedef struct Object Object; +typedef struct Vtable { + void *unused[3]; + u32 (*type)(Object *); + void *f10; + s32 (*supports)(Object *, u32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *vtable; +}; +typedef struct { + s32 f0; + void *context; +} Manager; +extern Manager D_00222038[]; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, s32); +extern u32 D_00220AB8; +static inline Object *resolve(s32 handle) +{ + Manager *m; + Object *obj; + void *world; + if (D_00222038[0].context) + m = D_00222038; + else + m = func_005010E0(); + world = 0; + if (m->context) + world = *(void **)((u32)m->context + ((u32) * (s32 *)((char *)m->context + 0x14) << 2)); + obj = func_005005E8(world, handle); + if (obj && obj->vtable->supports(obj, D_00220AB8)) + return obj; + return 0; +} +typedef s32 (*Callback)(Object *, float *, float *); +extern char D_00336428[]; +extern Callback func_00508060(void *, u32); +s32 func_005057E0(s32 handle, float *a, float *b) +{ + s32 result = 0; + Object *obj = resolve(handle); + if (obj) { + u32 type = obj->vtable->type(obj); + Callback callback = func_00508060(D_00336428, type); + if (callback) + result = callback(obj, a, b); + } + return result; +} diff --git a/src/game/005059D8.c b/src/game/005059D8.c new file mode 100644 index 000000000..6913f83a0 --- /dev/null +++ b/src/game/005059D8.c @@ -0,0 +1,61 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0xC]; + u32 (*getType)(Object *); + s32 pad10; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; + +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220AB8; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +typedef s32 (*Callback)(Object *, f32); +extern Callback func_00507B70(void *, u32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220AB8)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +extern char D_00336738[]; +static inline Callback handler(u32 kind) +{ + return func_00507B70(D_00336738, kind); +} +s32 func_005059D8(u32 id, f32 amount) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + Callback callback = handler(p->vtable->getType(p)); + if (callback) + result = callback(p, amount); + } + return result; +} diff --git a/src/game/00505ED0.c b/src/game/00505ED0.c new file mode 100644 index 000000000..a0bdc2a28 --- /dev/null +++ b/src/game/00505ED0.c @@ -0,0 +1,49 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0x14]; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220B54; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +extern s32 func_0050CAC0(Object *, u32, s32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220B54)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +s32 func_00505ED0(u32 id, u32 child, s32 index) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) + result = func_0050CAC0(p, child, index); + return result; +} diff --git a/src/game/00506358.c b/src/game/00506358.c new file mode 100644 index 000000000..02d55c630 --- /dev/null +++ b/src/game/00506358.c @@ -0,0 +1,52 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0x14]; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220B68; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +extern void func_0050ED88(Object *); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220B68)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +/* Resets the validated object's transient state. */ +s32 func_00506358(u32 id) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + func_0050ED88(p); + result = 1; + } + return result; +} diff --git a/src/game/00506408.c b/src/game/00506408.c new file mode 100644 index 000000000..226c7758c --- /dev/null +++ b/src/game/00506408.c @@ -0,0 +1,55 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0x14]; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220B68; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +extern void func_0050EEF8(Object *, f32); +extern void func_0050EF08(Object *, s32); +extern void func_0050EF18(Object *, s32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220B68)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +s32 func_00506408(u32 id, s32 a, s32 b, f32 value) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + func_0050EEF8(p, value); + func_0050EF08(p, a); + func_0050EF18(p, b); + result = 1; + } + return result; +} diff --git a/src/game/005065F8.c b/src/game/005065F8.c new file mode 100644 index 000000000..0bc26e756 --- /dev/null +++ b/src/game/005065F8.c @@ -0,0 +1,51 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0x14]; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220B68; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +extern void func_0050EF88(Object *, s32, s32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220B68)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +s32 func_005065F8(u32 id, s32 mask, s32 enabled) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + func_0050EF88(p, mask, enabled); + result = 1; + } + return result; +} diff --git a/src/game/005066C0.c b/src/game/005066C0.c new file mode 100644 index 000000000..3ca5bd94f --- /dev/null +++ b/src/game/005066C0.c @@ -0,0 +1,51 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0x14]; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220B68; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +extern void func_0050EF28(Object *, s32, s32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220B68)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +s32 func_005066C0(u32 id, s32 mask, s32 enabled) +{ + s32 result = 0; + Object *p = getTyped(id); + if (p) { + func_0050EF28(p, mask, enabled); + result = 1; + } + return result; +} diff --git a/src/game/00506790.c b/src/game/00506790.c new file mode 100644 index 000000000..ea43cc467 --- /dev/null +++ b/src/game/00506790.c @@ -0,0 +1,18 @@ +#include "common.h" +extern s32 func_005081B0(u32, s32), func_00505328(u32, u32); +extern s32 func_005058E0(u32, f32, f32), func_00504238(u32, f32, f32), func_00504C80(u32, f32); +static inline s32 combine(s32 a, s32 b) +{ + return a & b; +} +s32 func_00506790(u32 id, s32 option, u32 color, f32 x, f32 y, f32 width, f32 height, f32 amount) +{ + s32 first = func_005081B0(id, option); + s32 result = func_00505328(id, color) != 0; + if (!first) + result = 0; + result = combine(result, func_005058E0(id, width, height) != 0); + result = combine(result, func_00504238(id, x, y) != 0); + result = combine(result, func_00504C80(id, amount) != 0); + return result; +} diff --git a/src/game/00506BA8.c b/src/game/00506BA8.c new file mode 100644 index 000000000..8e8fe5fa0 --- /dev/null +++ b/src/game/00506BA8.c @@ -0,0 +1,47 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + char pad[0xC]; + u32 (*getType)(Object *); + s32 pad10; + s32 (*isType)(Object *, u32); +} VTable; +struct Object { + char pad[8]; + VTable *vtable; +}; + +typedef struct { + s32 pad; + char *table; +} Manager; +extern Manager D_00222038[]; +extern u32 D_00220AB8; +extern Manager *func_005010E0(void); +extern Object *func_005005E8(void *, u32); +static inline Manager *getManager(void) +{ + Manager *p = D_00222038; + if (p->table) + return p; + return func_005010E0(); +} +static inline Object *valid(Object *p) +{ + if (p && p->vtable->isType(p, D_00220AB8)) + return p; + return 0; +} +static inline Object *getTyped(u32 id) +{ + Manager *m = getManager(); + char *state = m->table; + void *table = 0; + if (state) + table = *(void **)(state + (*(s32 *)(state + 0x14) << 2)); + return valid(func_005005E8(table, id)); +} +s32 func_00506BA8(u32 id) +{ + return getTyped(id) != 0; +} diff --git a/src/game/00509140.c b/src/game/00509140.c new file mode 100644 index 000000000..4ccc05290 --- /dev/null +++ b/src/game/00509140.c @@ -0,0 +1,40 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + f32 x, y, w, h, a, b; +} Rect; +typedef struct { + char pad[0x14]; + s32 (*supports)(Object *, u32); + char rest[0x10]; + void (*bounds)(Object *, Rect *, Rect *, s32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *v; +}; +extern u32 D_00220B60; +static inline void init(Rect *p) +{ + p->x = 0; + p->y = 0; + p->w = 1; + p->h = 1; + p->a = 0; + p->b = 0; +} +s32 func_00509140(Object *p, f32 *x, f32 *y, f32 *w, f32 *h) +{ + Rect input, output; + if (p->v->supports(p, D_00220B60)) { + init(&input); + init(&output); + p->v->bounds(p, &input, &output, 1); + *x = output.x; + *y = output.y; + *w = output.w; + *h = output.h; + return 1; + } + return 0; +} diff --git a/src/game/00509A30.c b/src/game/00509A30.c new file mode 100644 index 000000000..45802ad4e --- /dev/null +++ b/src/game/00509A30.c @@ -0,0 +1,40 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + f32 x, y, w, h, a, b; +} Rect; +typedef struct { + char pad[0x14]; + s32 (*supports)(Object *, u32); + char rest[0x10]; + void (*bounds)(Object *, Rect *, Rect *, s32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *v; +}; +extern u32 D_00220B68; +static inline void init(Rect *p) +{ + p->x = 0; + p->y = 0; + p->w = 1; + p->h = 1; + p->a = 0; + p->b = 0; +} +s32 func_00509A30(Object *p, f32 *x, f32 *y, f32 *w, f32 *h) +{ + Rect input, output; + if (p->v->supports(p, D_00220B68)) { + init(&input); + init(&output); + p->v->bounds(p, &input, &output, 1); + *x = output.x; + *y = output.y; + *w = output.w; + *h = output.h; + return 1; + } + return 0; +} diff --git a/src/game/0050A3F0.c b/src/game/0050A3F0.c new file mode 100644 index 000000000..29821601b --- /dev/null +++ b/src/game/0050A3F0.c @@ -0,0 +1,40 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + f32 x, y, w, h, a, b; +} Rect; +typedef struct { + char pad[0x14]; + s32 (*supports)(Object *, u32); + char rest[0x10]; + void (*bounds)(Object *, Rect *, Rect *, s32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *v; +}; +extern u32 D_00220B5C; +static inline void init(Rect *p) +{ + p->x = 0; + p->y = 0; + p->w = 1; + p->h = 1; + p->a = 0; + p->b = 0; +} +s32 func_0050A3F0(Object *p, f32 *x, f32 *y, f32 *w, f32 *h) +{ + Rect input, output; + if (p->v->supports(p, D_00220B5C)) { + init(&input); + init(&output); + p->v->bounds(p, &input, &output, 1); + *x = output.x; + *y = output.y; + *w = output.w; + *h = output.h; + return 1; + } + return 0; +} diff --git a/src/game/0050AAE0.c b/src/game/0050AAE0.c new file mode 100644 index 000000000..0a227d259 --- /dev/null +++ b/src/game/0050AAE0.c @@ -0,0 +1,40 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + f32 x, y, w, h, a, b; +} Rect; +typedef struct { + char pad[0x14]; + s32 (*supports)(Object *, u32); + char rest[0x10]; + void (*bounds)(Object *, Rect *, Rect *, s32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *v; +}; +extern u32 D_00220B58; +static inline void init(Rect *p) +{ + p->x = 0; + p->y = 0; + p->w = 1; + p->h = 1; + p->a = 0; + p->b = 0; +} +s32 func_0050AAE0(Object *p, f32 *x, f32 *y, f32 *w, f32 *h) +{ + Rect input, output; + if (p->v->supports(p, D_00220B58)) { + init(&input); + init(&output); + p->v->bounds(p, &input, &output, 1); + *x = output.x; + *y = output.y; + *w = output.w; + *h = output.h; + return 1; + } + return 0; +} diff --git a/src/game/0050B1B8.c b/src/game/0050B1B8.c new file mode 100644 index 000000000..6248a30d0 --- /dev/null +++ b/src/game/0050B1B8.c @@ -0,0 +1,40 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + f32 x, y, w, h, a, b; +} Rect; +typedef struct { + char pad[0x14]; + s32 (*supports)(Object *, u32); + char rest[0x10]; + void (*bounds)(Object *, Rect *, Rect *, s32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *v; +}; +extern u32 D_00220B6C; +static inline void init(Rect *p) +{ + p->x = 0; + p->y = 0; + p->w = 1; + p->h = 1; + p->a = 0; + p->b = 0; +} +s32 func_0050B1B8(Object *p, f32 *x, f32 *y, f32 *w, f32 *h) +{ + Rect input, output; + if (p->v->supports(p, D_00220B6C)) { + init(&input); + init(&output); + p->v->bounds(p, &input, &output, 1); + *x = output.x; + *y = output.y; + *w = output.w; + *h = output.h; + return 1; + } + return 0; +} diff --git a/src/game/0050B6C0.c b/src/game/0050B6C0.c new file mode 100644 index 000000000..3edbb038a --- /dev/null +++ b/src/game/0050B6C0.c @@ -0,0 +1,40 @@ +#include "common.h" +typedef struct Object Object; +typedef struct { + f32 x, y, w, h, a, b; +} Rect; +typedef struct { + char pad[0x14]; + s32 (*supports)(Object *, u32); + char rest[0x10]; + void (*bounds)(Object *, Rect *, Rect *, s32); +} Vtable; +struct Object { + s32 f0, f4; + Vtable *v; +}; +extern u32 D_00220B70; +static inline void init(Rect *p) +{ + p->x = 0; + p->y = 0; + p->w = 1; + p->h = 1; + p->a = 0; + p->b = 0; +} +s32 func_0050B6C0(Object *p, f32 *x, f32 *y, f32 *w, f32 *h) +{ + Rect input, output; + if (p->v->supports(p, D_00220B70)) { + init(&input); + init(&output); + p->v->bounds(p, &input, &output, 1); + *x = output.x; + *y = output.y; + *w = output.w; + *h = output.h; + return 1; + } + return 0; +} diff --git a/src/game/0050CE20.c b/src/game/0050CE20.c new file mode 100644 index 000000000..cedc5b19e --- /dev/null +++ b/src/game/0050CE20.c @@ -0,0 +1,11 @@ +#include "common.h" + +void func_0050CE20(void *object, u32 mask, s32 enable) +{ + u8 *flag = (u8 *)object + 0x1EC; + if (enable) { + *flag |= mask; + } else { + *flag &= ~mask; + } +} diff --git a/src/game/0050DB80.c b/src/game/0050DB80.c new file mode 100644 index 000000000..a1c3b0b3a --- /dev/null +++ b/src/game/0050DB80.c @@ -0,0 +1,48 @@ +#include "common.h" +typedef struct Data Data; +typedef struct { + char pad[0x14]; + s32 (*supports)(Data *, u32); +} Vtable; +typedef struct { + f32 x, y; +} Pair; +struct Data { + s32 f0, f4; + Vtable *v; + s32 fC; + f32 f10; + Pair f14, f1C, f24; + s32 f2C, f30, f34, f38, f3C; + f32 f40; + u32 f44, f48, f4C; + u16 f50, f52; + u8 f54, f55, f56, f57; + void *f58; +}; +extern s32 func_0050BFA8(Data *, Data *); +s32 func_0050DB80(Data *dst, Data *src) +{ + if (src->v->supports(src, 1)) { + func_0050BFA8(dst, src); + dst->fC = src->fC; + dst->f10 = src->f10; + dst->f14 = src->f14; + dst->f1C = src->f1C; + dst->f24 = src->f24; + dst->f30 = src->f30; + dst->f34 = src->f34; + dst->f40 = src->f40; + dst->f44 = src->f44; + dst->f48 = src->f48; + dst->f4C = src->f4C; + dst->f50 = src->f50; + dst->f52 = src->f52; + dst->f54 = src->f54; + dst->f55 = src->f55; + dst->f56 = src->f56; + dst->f58 = src->f58; + return 1; + } + return 0; +} diff --git a/src/game/0050E2B0.c b/src/game/0050E2B0.c new file mode 100644 index 000000000..2487b3d6d --- /dev/null +++ b/src/game/0050E2B0.c @@ -0,0 +1,63 @@ +#include "common.h" + +typedef struct Type2 Type2; +typedef struct Type3 Type3; +typedef struct Type1 Type1; +struct Type3 { + char _p0[0x14]; + s32 (*f14)(); +}; +struct Type1 { + char _p0[0x48]; + s32 f48; + s32 f4C; + s32 f50; + u8 f54; + char _p55[0x3]; + f32 f58; + f32 f5C; + u8 f60; + char _p61[0x3]; + s32 f64; + f32 f68; + f32 f6C; +}; +struct Type2 { + char _p0[0x8]; + Type3 *f8; + char _pC[0x3C]; + s32 f48; + s32 f4C; + s32 f50; + u8 f54; + char _p55[0x3]; + f32 f58; + f32 f5C; + u8 f60; + char _p61[0x3]; + s32 f64; + f32 f68; + f32 f6C; +}; + +s32 func_0050BFA8(void *, void *); + +/* Copies state after the source callback accepts the operation. */ +s32 func_0050E2B0(Type1 *arg0, Type2 *arg1) +{ + if (arg1->f8->f14(arg1, 1) != 0) { + func_0050BFA8(arg0, arg1); + arg0->f48 = (s32)arg1->f48; + arg0->f4C = (s32)arg1->f4C; + arg0->f50 = (s32)arg1->f50; + arg0->f54 = (u8)arg1->f54; + arg0->f58 = (f32)arg1->f58; + arg0->f5C = (f32)arg1->f5C; + arg0->f60 = (u8)arg1->f60; + arg0->f64 = (s32)arg1->f64; + arg0->f68 = (f32)arg1->f68; + arg0->f6C = (f32)arg1->f6C; + return 1; + } + return 0; +} diff --git a/src/game/0050ECE8.c b/src/game/0050ECE8.c new file mode 100644 index 000000000..a544290ff --- /dev/null +++ b/src/game/0050ECE8.c @@ -0,0 +1,46 @@ +#include "common.h" + +typedef struct Allocator Allocator; +typedef struct { + void *unused[3]; + void (*release)(Allocator *, void *); +} AllocatorVtable; +struct Allocator { + AllocatorVtable *vtable; +}; +typedef struct { + void *vtable; + void *context; +} Manager; +typedef struct { + char pad[8]; + void *vtable; + char padC[0x34]; + void *block; +} Object; +extern Manager D_00222038[]; +extern char D_003D3728[], D_003D3508[]; +extern Manager *func_005010E0(void); +extern Allocator *func_005011A8(Manager *, s32); +extern void func_0015DB88(void *); +static inline Manager *manager(void) +{ + Manager *p = D_00222038; + if (p->context) + return p; + return func_005010E0(); +} +/* Releases owned storage and optionally deletes the object itself. */ +void func_0050ECE8(Object *p, u32 flags) +{ + Allocator *allocator; + p->vtable = D_003D3728; + allocator = func_005011A8(manager(), 1); + if (allocator) { + allocator->vtable->release(allocator, p->block); + p->block = 0; + } + p->vtable = D_003D3508; + if (flags & 1) + func_0015DB88(p); +} diff --git a/src/game/0050EF88.c b/src/game/0050EF88.c new file mode 100644 index 000000000..c790e6fed --- /dev/null +++ b/src/game/0050EF88.c @@ -0,0 +1,25 @@ +#include "common.h" +typedef struct { + char pad[0x44]; + u8 f44; +} Object; +extern void func_0050EF28(Object *, s32, s32); +s32 func_0050EF88(Object *a, s32 b, s32 c) +{ + s32 x = 0; + s32 valid = 1; + s32 y = 0; + if (b == 0) { + } else if (b == 1) + x = 1; + else + valid = 0; + if (c == 0) + y = 1; + else if (c != 1) + valid = 0; + func_0050EF28(a, 1, x); + func_0050EF28(a, 2, y); + a->f44 = 1; + return valid; +} diff --git a/src/game/00510458.c b/src/game/00510458.c new file mode 100644 index 000000000..c6fc5941d --- /dev/null +++ b/src/game/00510458.c @@ -0,0 +1,45 @@ +#include "common.h" + +typedef struct Type2 { + char pad[0x34]; + f32 f34, f38; + char pad3C[4]; + u16 f40; + char pad42[14]; + u8 f50; +} Type2; +typedef struct Type1 { + char pad[0x1C]; + f32 f1C, f20; + char pad24[0x1C]; + Type2 *f40; + char pad44[4]; + f32 f48, f4C; +} Type1; +extern void func_00454350(s32), func_0050F080(Type1 *), func_0050F438(Type1 *, f32 *, f32, f32); +s32 func_00510458(Type1 *p) +{ + s32 mode = p->f40->f50; + switch (mode) { + case 1: + func_00454350(1); + break; + case 2: + func_00454350(0); + break; + case 0: + default: + func_00454350(0); + break; + } + if (p->f40->f40 & 4) { + Type2 *state; + func_0050F080(p); + state = p->f40; + if (state->f40 & 0x80) + func_0050F438(p, &state->f34, p->f1C, p->f48); + else + func_0050F438(p, &state->f38, p->f20, p->f4C); + } + return 0; +} diff --git a/src/game/00513278.c b/src/game/00513278.c new file mode 100644 index 000000000..638547ff1 --- /dev/null +++ b/src/game/00513278.c @@ -0,0 +1,11 @@ +#include "common.h" + +/* Updates the object interpolation parameters in the active transition states. */ +extern f32 D_0021DDF4; +extern void func_004795C0(void *, void *, void *, f32, f32, f32); +void func_00513278(char *p) +{ + s32 state = *(s32 *)(p + 0x25CC); + if (state == 0x7E || (state == 0x99 && *(s32 *)(p + 0x25D8) == 0x7E)) + func_004795C0(*(void **)(p + 0x2EF0), p + 0x1C58, p + 0x1C5C, 0.3f, D_0021DDF4 * 6.981317043304443f * *(f32 *)(p + 0x25C4), -1.0f); +} diff --git a/src/game/0051A790.c b/src/game/0051A790.c new file mode 100644 index 000000000..4a26215ba --- /dev/null +++ b/src/game/0051A790.c @@ -0,0 +1,25 @@ +#include "common.h" + +extern void func_0046BDD0(void *); + +/* Release the attached object and restore the default motion factors. */ +void func_0051A790(char *p) +{ + f32 a, b, c, d; + if (*(void **)(p + 0x1C54)) { + func_0046BDD0(*(void **)(p + 0x1C54)); + *(void **)(p + 0x1C54) = 0; + } + if (*(s16 *)(p + 0x3A0)) + *(s16 *)(p + 0x3A0) = 0; + a = 1.05f; + b = 0.7f; + c = 0.45f; + d = 0.2025f; + *(f32 *)(p + 0x1F0) = a; + *(f32 *)(p + 0x1F4) = b; + *(f32 *)(p + 0x204) = c; + *(f32 *)(p + 0x240) = d; + *(f32 *)(p + 0x1F8) = a; + *(f32 *)(p + 0x1FC) = b; +} diff --git a/src/game/005229A0.c b/src/game/005229A0.c new file mode 100644 index 000000000..2df5a404c --- /dev/null +++ b/src/game/005229A0.c @@ -0,0 +1,8 @@ +#include "common.h" + +extern s32 func_00548A18(void *, s32, s32, s32, s32, s32, void *); +/* Forward object fields and indexed data to the operation. */ +s32 func_005229A0(char *p, u8 index, s32 arg, void *last) +{ + return func_00548A18(*(void **)(p + 0x26e4), index, arg, *(u8 *)(p + 0x266d) != 0, *(s32 *)(p + 0x2f28), *(s32 *)(p + index * 0x50 + 0x2318), last); +} diff --git a/src/game/005229E0.c b/src/game/005229E0.c new file mode 100644 index 000000000..a3139ae76 --- /dev/null +++ b/src/game/005229E0.c @@ -0,0 +1,8 @@ +#include "common.h" + +extern s32 func_00548B00(void *, u8, u8, s32, s32, s32, s32, void *); +/* Forward the selected entry and current object parameters. */ +int func_005229E0(char *p, unsigned char i, int a, void *b) +{ + return func_00548B00(*(void **)(p + 0x26E4), i, *(unsigned char *)(p + 0x2F10), a, *(unsigned char *)(p + 0x266D) != 0, *(int *)(p + 0x2F28), *(int *)(p + i * 80 + 0x2318), b); +} diff --git a/src/game/00523210.c b/src/game/00523210.c new file mode 100644 index 000000000..41a1185b5 --- /dev/null +++ b/src/game/00523210.c @@ -0,0 +1,45 @@ +#include "common.h" +/* Pool records occupy 0x20 bytes: 46F948 reads flag+15 and clears0x20. */ +typedef struct Node { + char pad[0x10]; + struct Node *next; + char tail[0xC]; +} Node; +typedef struct { + char pad[0x24]; + char *table; + char gap[0x18]; + char *entry; + f32 position, scale; + u16 value; + char gap4E[2]; + Node *nodes; + u8 index; +} State; +typedef struct { + char pad[0x2EF0]; + State *state; +} Object; +extern void func_0046F068(Node *); +static inline u32 add(u32 offset, u32 base) +{ + return offset + base; +} +void func_00523210(Object *p, s32 index, s32 frame) +{ + State *state = p->state; + Node *node = state->nodes; + while (node) { + func_0046F068(node); + node = node->next; + } + state->index = index; + state->nodes = 0; + { + char *entry = *(char **)(state->table + (index << 2) + 0x48); + state->position = (f32)frame; + state->scale = 1.0f; + state->entry = entry; + state->value = *(u16 *)((char *)add(frame << 2, (u32)entry) + 0x20); + } +} diff --git a/src/game/00525650.c b/src/game/00525650.c new file mode 100644 index 000000000..92fc31187 --- /dev/null +++ b/src/game/00525650.c @@ -0,0 +1,16 @@ +#include "common.h" +void func_00525650(char *p) +{ + float v; + if (*(int *)(p + 0x1AE0) == 1) { + *(float *)(p + 0x1AFC) = 2.0f; + return; + } + if (((*(int *)(p + 0x25CC) == 4 || *(int *)(p + 0x25CC) == 21) && *(int *)(p + 0x1AE0) == 2) || *(unsigned char *)(p + 0x2ECD)) + v = 0.6f; + else + v = 1.15f; + *(float *)(p + 0x1AFC) = v; + if (*(int *)(p + 0x25D4) == 3) + *(float *)(p + 0x1AFC) = 1.75f; +} diff --git a/src/game/005263E0.c b/src/game/005263E0.c new file mode 100644 index 000000000..23629a5f2 --- /dev/null +++ b/src/game/005263E0.c @@ -0,0 +1,19 @@ +#include "common.h" + +extern s32 func_0053CA40(s32 *, s32); +extern void *func_0053C920(s32 *, s32, s32, s32); +extern void func_0053CAA8(void *, void *, s32); + +/* Creates an entry and writes two byte selectors. */ +void func_005263E0(s32 *a, s32 b, s32 c) +{ + u8 x; + void *p; + if (!func_0053CA40(a, 6)) { + p = func_0053C920(a, 6, 0, 0); + x = b; + func_0053CAA8(p, &x, 1); + x = c; + func_0053CAA8(p, &x, 1); + } +} diff --git a/src/game/0053CCF0.c b/src/game/0053CCF0.c new file mode 100644 index 000000000..be3c58362 --- /dev/null +++ b/src/game/0053CCF0.c @@ -0,0 +1,21 @@ +#include "common.h" +extern void *func_0053C9F0(char *, int, int); +extern char *func_0053C920(char *, int, int, int); +extern void func_0053CAA8(void *, const void *, int); +void func_0053CCF0(char *p, int value, unsigned short type, int extra) +{ + char *event; + int data; + if (type == 6 || type == 13) { + if (*(int *)(p + 0x304)) + return; + *(int *)(p + 0x304) = 1; + } + if (func_0053C9F0(p, type, 0)) + return; + event = func_0053C920(p, type, 0, -1); + data = value; + func_0053CAA8(event, &data, 4); + *(int *)(event + 0x50) = extra; + *(int *)(p + 0x320) = 0; +} diff --git a/src/game/0053E0D8.c b/src/game/0053E0D8.c new file mode 100644 index 000000000..13cd957e8 --- /dev/null +++ b/src/game/0053E0D8.c @@ -0,0 +1,19 @@ +#include "common.h" + +int D_00220DA0 = 0; +typedef struct Type1 { + int f0; + char p[0x33C]; +} Type1; +extern Type1 D_00345CC0[]; +/* Find the first table entry with the requested identifier. */ +void *func_0053E0D8(int a) +{ + int i; + for (i = 0; i < D_00220DA0; i++) { + Type1 *p = D_00345CC0 + i; + if (p->f0 == a) + return p; + } + return 0; +} diff --git a/src/game/0053F550.c b/src/game/0053F550.c new file mode 100644 index 000000000..7a538ec6c --- /dev/null +++ b/src/game/0053F550.c @@ -0,0 +1,18 @@ +#include "common.h" + +typedef struct { u8 pad00[0x67]; u8 kind; } Inner; +typedef struct { u8 pad00[0x2B0]; Inner *inner; } Link; +typedef struct { u8 pad00[0x2EF4]; Link *link; } Object; + +s32 func_0053F550(Object *object) +{ + s32 kind; + if (object->link == NULL) { + return 0; + } + kind = object->link->inner->kind; + if ((u32)(kind - 7) < 2 || kind == 10) { + return 1; + } + return 0; +} diff --git a/src/game/00543398.c b/src/game/00543398.c new file mode 100644 index 000000000..02e778000 --- /dev/null +++ b/src/game/00543398.c @@ -0,0 +1,15 @@ +#include "common.h" + +s32 D_00220E4C = 0; +typedef struct Type1 { + char data[0x18]; +} Type1; +extern Type1 D_00354EA0[]; +extern void func_00453718(void *, const void *, s32); + +/* Append a fixed-size record to the shared queue. */ +void func_00543398(const void *record) +{ + func_00453718(&D_00354EA0[D_00220E4C], record, 0x18); + D_00220E4C++; +} diff --git a/src/game/00547BB0.c b/src/game/00547BB0.c new file mode 100644 index 000000000..ce3e2358f --- /dev/null +++ b/src/game/00547BB0.c @@ -0,0 +1,12 @@ +#include "common.h" + +extern int D_003DDE48[][10]; +/* Return an indexed value or the unchanged identity. */ +int func_00547BB0(int a, int b) +{ + if ((unsigned)(b + 1) > 10) + return 0; + if (b == -1) + return a; + return D_003DDE48[a][b]; +} diff --git a/src/game/00549A38.c b/src/game/00549A38.c new file mode 100644 index 000000000..929e53c2e --- /dev/null +++ b/src/game/00549A38.c @@ -0,0 +1,20 @@ +#include "common.h" + +extern const char *func_0045E038(s32); +extern s32 func_0011D920(char *, const char *, ...); +extern void func_00547B08(const char *, s32, s32), func_00496C90(s32, const char *); +extern char D_00220EC8[], D_00355220[]; +extern s32 D_0022206C; +void func_00549A38(s16 id, s32 slot, s32 duration) +{ + char buffer[128]; + const char *format; + if (duration > 0 && id > 0 && slot >= 0) { + const char *label; + format = D_00220EC8; + label = func_0045E038(0x2558); + func_0011D920(buffer, format, label, func_0045E038(id)); + func_00547B08(buffer, slot, duration); + } + func_00496C90(D_0022206C, D_00355220); +} diff --git a/src/game/00549CA0.c b/src/game/00549CA0.c new file mode 100644 index 000000000..1d1f52d9c --- /dev/null +++ b/src/game/00549CA0.c @@ -0,0 +1,12 @@ +#include "common.h" +extern int func_00549BB8(char *, int), func_0054A0C0(int, int), func_0054A788(char *, int, int); +int func_00549CA0(char *a, int b) +{ + int sum = func_00549BB8(a, b); + int i; + for (i = 2; i < 20; i++) { + if (func_0054A0C0(i, b)) + sum += func_0054A788(a, i, b); + } + return sum; +} diff --git a/src/game/0054A190.c b/src/game/0054A190.c new file mode 100644 index 000000000..bdccfe8a5 --- /dev/null +++ b/src/game/0054A190.c @@ -0,0 +1,16 @@ +#include "common.h" +typedef struct { + u8 prefix[9]; + u8 items[10]; + u8 rest[37]; +} Record; +extern Record *func_00549B00(s32); +s32 func_0054A190(s32 id, s32 record) +{ + Record value = *func_00549B00(record); + s32 i; + for (i = 0; i < 10; i++) + if (value.items[i] == id) + return 1; + return 0; +} diff --git a/src/game/0054A400.c b/src/game/0054A400.c new file mode 100644 index 000000000..44b760b27 --- /dev/null +++ b/src/game/0054A400.c @@ -0,0 +1,16 @@ +#include "common.h" +extern char *func_00549B18(int); +extern int func_0054A688(char *, int, int), func_00549C18(char *, int), func_0054A038(char *, int); +int func_0054A400(char *p, int id) +{ + if (((u32)id - 1) < 6) { + int index = *(unsigned char *)(func_00549B18(id) + 8); + func_0054A688(p, index, 1); + if (func_00549C18(p, id) || id == 0) { + *(unsigned char *)(p + index * 0x44 + 0xA40) = id; + func_0054A038(p, id); + return 1; + } + } + return 0; +} diff --git a/src/game/0054AB40.c b/src/game/0054AB40.c new file mode 100644 index 000000000..dd050dba1 --- /dev/null +++ b/src/game/0054AB40.c @@ -0,0 +1,21 @@ +#include "common.h" + +typedef struct { + s32 f00; + u8 pad04[0x2C]; +} Record; + +extern Record D_003E2F48[]; + +s32 func_0054AB40(s32 unused, s32 key) +{ + Record *record = D_003E2F48; + s32 i; + + for (i = 0; i < 189; i++, record++) { + if (record->f00 == key) { + return i; + } + } + return 0; +}