diff --git a/Makefile b/Makefile index 2985aa3f..819011bd 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,9 @@ CC1 := tools/agbcc/bin/agbcc ASFLAGS := -mcpu=arm7tdmi -I . NM_FLAGS := -CPPFLAGS := -nostdinc -I tools/agbcc/include -iquote include -undef -std=gnu17 $(NM_FLAGS) +# Regional builds (tools/scripts/region_build.py) compile the EU sources once more with -DREGION_USA/-DREGION_JP. +REGION_CPPFLAGS := +CPPFLAGS := -nostdinc -I tools/agbcc/include -iquote include -undef -std=gnu17 $(NM_FLAGS) $(REGION_CPPFLAGS) CC1FLAGS := -mthumb-interwork -Wimplicit -Wparentheses -O2 -fhex-asm -fprologue-bugfix SHELL := /bin/bash -o pipefail diff --git a/docs/agents/REGIONS.md b/docs/agents/REGIONS.md index 7ba99097..cc341ace 100644 --- a/docs/agents/REGIONS.md +++ b/docs/agents/REGIONS.md @@ -53,9 +53,9 @@ SHA-256 values are pinned in `tools/config/rom_regions.json`. ## Coverage and limitations -The verified USA build contains 1,257 compiler-backed C intervals (16 same-address -EU, 1,237 relocated EU, 4 region-only) totaling 165,148 bytes; Japan contains -1,250 (16, 1,207 and 27) totaling 162,924 bytes. Consult each generated report for the actual current counts, canonical EU symbols, addresses, +The verified USA build contains 1,983 compiler-backed C intervals (16 same-address +EU, 1,965 relocated EU, 2 region-only) totaling 753,274 bytes; Japan contains +1,272 (16, 1,229 and 27) totaling 164,414 bytes. Consult each generated report for the actual current counts, canonical EU symbols, addresses, sizes and per-function hashes. The admitted intervals include complete function literal pools. Top-level assembly and `INCLUDE_ASM` fallbacks receive no C credit. @@ -148,7 +148,8 @@ python3 tools/scripts/region_symbols.py --region jp `region_symbols.py` pairs each EU C function with the regional address where all non-relocated bytes are identical (tracking the running address shift, with a unique-match search nearby and a pass for functions located by their callers' BL -targets). It then solves each relocation for the regional value of its symbol. +targets, and a pass that retries the shift of the placed functions on either +side). It then solves each relocation for the regional value of its symbol. A symbol with two different regional values is dropped, together with every function that needs it. Functions whose assembly uses a symbol the assembler resolved inside the EU object (no relocation) are skipped. The tables hold @@ -156,7 +157,60 @@ addresses only, never ROM bytes. Functions that are not listed still come from the reference ROM. Their code differs from EU, for example through 16-bit text handling, the 0x454-byte -enemy records or the Japanese player layout. +enemy records or the regional player layouts. + +## Regional layouts in shared EU sources + +The regional build compiles every `src/*.c` a second time with `-DREGION_USA` +or `-DREGION_JP` (`build/regions//variant`, EU link order, Makefile +variable `REGION_CPPFLAGS`). `region_symbols.py` pairs and `region_build.py` +relocates the functions of that build, so a layout difference written once in +the shared source moves every function that uses it. The EU build defines +neither macro and must stay byte-identical (`make compare`). + +`include/region.h` holds the differences, as EU-offset mapping macros: + +| Macro | EU | USA | +| --- | --- | --- | +| `PLAYER_SIZE` | 0x14C | 0x158 | +| `PLAYER_FIELD(o)` | `o` | `o` below 0x0C, `o + 10` below 0x30, then `o + 12` (+0x2E -> +0x38, flags +0x30 -> +0x3C) | +| `ENEMY_SIZE` | 0x2E0 | 0x454 (enemy actor records at `*gUnk_030056F4`) | +| `ENEMY_FIELD(o)` | o | o below 0x206, else o + 0x174 (USA inserts 0x174 bytes at enemy +0x206) | +| `RES_ID(id)` | id | id - 4 (resource ids that USA numbers 4 lower, e.g. 0x5008C; not every archive 5 id moves, so only verified uses) | +| `TEXT_HEADER` | 2 | 4 (header before the string of a text record from `sub_08007290`) | +| `SAVE_FIELD(o)` | `o` | character save record (`gUnk_030034E0`): `o` below 0x0A, `o + 10` below 0x10, then `o + 12` | +| `NameChar` | u8 | u16 (the ten-character name at save +0; source of `SAVE_FIELD`'s first shift) | +| `ITEM_FIELD(o)`, `ITEM_KIND(r)` | `o`, u8 at +0x9B | `o + 0xD8`, u16 at +0x174 (item records of archive 0xB) | +| `EQUIP_FIELD(o)`, `EquipLevel` | `o`, u8 | `o + 0xDC`, u16 (equipment records of archives 0xC/0xD/0xE; glove class/level fields differ, see `sub_0805D2E0`) | +| `TextChar` | u8 (ends 0xFD) | u16 (ends 0xFFFD, bit 15 = control) | +| `TEXT_CTRL(c)` | `c` | `0xFF00 | c` (text control codes) | +| `ENEMY_DATA_FIELD(o)` | `o` | `o + 0x174` (enemy data records: level, experience, ...) | +| `GLOVE_SIZE` | 0xB8 | `EQUIP_FIELD(0xB8) + 4` (archive 0xE records) | + +`struct Player` is written with these macros. Raw offsets into a player record +must be written `PLAYER_FIELD(0x9C)`, its stride `PLAYER_SIZE`, so the USA +build sees the USA layout. Japan is not described yet (player 0x154 bytes, +flags at +0x38). + +Tools (USA; each run after `region_symbols.py --region usa`, then rerun it and +`make REGION=usa compare`): + +- `region_diff.py [FUNC]`: unplaced EU C functions ranked by differing + halfwords against their guessed USA address, or a disassembly diff of FUNC. +- `region_autofix.py [--max-diff N] [FUNC...]`: greedy search wrapping integer + literals of a function in `PLAYER_FIELD`/`SAVE_FIELD`/`PLAYER_SIZE`; keeps a + rewrite only when the variant object equals the USA bytes. +- `region_structs.py [MODULE...]`: resizes the pad arrays of 0x14C-byte struct + views of the player record; keeps a rewrite only when no exact function is + lost and the module moves closer to the USA bytes. +- `region_autofix.py --addresses FILE`: overrides the guessed address with + `NAME 0xADDR` lines (the guess is often wrong after a run of unplaced + functions; pair them with the function starts in the regional gap instead). +- `region_permute.py FUNC ADDR [--time S] [--jobs N]`: decomp-permuter against + the regional bytes of FUNC for register/stack-slot near misses of the same + size; transfer the winning change into an `#ifdef REGION_USA` block by hand. + +The macros are the identity in EU, so these rewrites cannot change the EU ROM. ## Region-only C sources @@ -178,17 +232,23 @@ Naming is the address, as for `sub_`/`gUnk_` in EU: The report lists these intervals separately as `region_only_functions`. -USA (AU2E) currently has four region-only functions in +USA (AU2E) currently has two region-only functions in `src/regions/usa/usa_only.c`, found by aligning the ordered EU and USA function lists (link order is preserved; 2029 of 2033 USA functions pair with an EU function): | USA address | Size | EU relation | | --- | ---: | --- | -| `0801A1C8` | 0x32 | 16-bit-text form of `CountRenderableScriptGlyphs` (`sub_0801A638`); USA text uses halfword glyphs ending in `0xFFFD` | | `0805E02C` | 0x1B0 | No EU counterpart; unreferenced dialogue-task starter with caller-supplied window layout | | `08067CA4` | 0x5C | `EnqueueLinkEntityPosition` (`sub_080663A4`) moved in link order; USA enemy records are 0x454 bytes (EU 0x2E0) | -| `080813D8` | 0xC0 | 16-bit-text form of `ExpandEncodedTextUnsignedNumberToken` (`sub_080850C0`) | + +The 16-bit-text forms of `CountRenderableScriptGlyphs` (USA `0801A1C8`) and +`ExpandEncodedTextUnsignedNumberToken` (USA `080813D8`) are the `REGION_USA` +branches of `sub_0801A638` and `sub_080850C0` themselves. + +Three EU functions have no USA counterpart (their USA neighbours are adjacent): +`sub_0800B7DC` and its wrapper `sub_0800BCFC` (language-offset graphics loader) +and `sub_08091F20` (byte-text number append). Most other USA functions differ from EU only in literal-pool addresses; they are built from the EU source through the relocation table described in diff --git a/include/functions.h b/include/functions.h index 01e93cd8..13d0d263 100644 --- a/include/functions.h +++ b/include/functions.h @@ -748,7 +748,7 @@ s32 sub_0801DF8C(void); u32 sub_08067D74(); s32 sub_08016C88(s32 arg0, s32 arg1, s32 arg2, s32 arg3, u16 arg4); u32 sub_08019DE0(u32 value); -void sub_0801A764(const u8 *script, u16 x, u16 y); +void sub_0801A764(const TextChar *script, u16 x, u16 y); void sub_0805A874(); s32 sub_08028830(); void sub_0805A9F4(); diff --git a/include/global.h b/include/global.h index f89e679c..a13b09f9 100644 --- a/include/global.h +++ b/include/global.h @@ -3,6 +3,7 @@ #include "gba/gba.h" #include "m2c_macros.h" +#include "region.h" #include "m4a.h" #include "structs.h" #include "variables.h" diff --git a/include/region.h b/include/region.h new file mode 100644 index 00000000..dd835d54 --- /dev/null +++ b/include/region.h @@ -0,0 +1,72 @@ +#ifndef GUARD_REGION_H +#define GUARD_REGION_H + +// Regional layout differences of shared EU sources (docs/agents/REGIONS.md). +// The EU build defines neither REGION_USA nor REGION_JP; make REGION=usa compare additionally +// compiles every src/*.c with -DREGION_USA and takes relocated functions from that build. + +// Player record (array gUnk_03003CE0): EU 0x14C bytes, USA 0x158. USA inserts 10 bytes +// before EU +0x0C and 2 more before the u32 flags word (EU +0x2E -> USA +0x38, EU +0x30 -> +0x3C). +// PLAYER_FIELD(o) maps an EU offset to the regional one; a pad that starts right after a member +// ending at such a boundary starts at PLAYER_FIELD(boundary - 1) + 1, not PLAYER_FIELD(boundary). +// Enemy actor records (array at *gUnk_030056F4): EU 0x2E0 bytes, USA 0x454 (ENEMY_SIZE). USA inserts +// 0x174 bytes at EU +0x206 (inside the block at +0x204); ENEMY_FIELD(o) maps EU offsets. +// Character save record (pointer gUnk_030034E0): USA inserts 10 bytes before EU +0x0A and +// keeps the word-aligned block at EU +0x10 (USA +0x1C) aligned. SAVE_FIELD(o) maps EU offsets. +// Resource ids (archive << 16 | entry): many USA archive 5/6/8 entries are numbered 4 lower +// (EU 0x5008C = USA 0x50088), but not all of them; RES_ID(id) marks the uses verified per function. +// Item data records (archive 0xB, sub_08007290): the USA name area is longer; fields from EU +0x9C +// move by 0xD8 (ITEM_FIELD) and the EU u8 kind at +0x9B is a u16 at USA +0x174 (ITEM_KIND). +// Character names (save +0, ten characters) are NameChar strings: bytes in EU, halfwords in USA, +// which is where SAVE_FIELD's 10-byte shift comes from. +// Encoded text strings are TextChar (u8 EU, u16 USA); control codes are TEXT_CTRL(0xFD) etc. +// (EU 0xFD, USA 0xFFFD). +// Enemy data records (stats such as level/experience): ENEMY_DATA_FIELD (USA +0x174, the same +// insertion as ENEMY_FIELD's block). +// Equipment records of archives 0xC/0xD/0xE: EQUIP_FIELD (USA +0xDC); the level requirement +// at EQUIP_FIELD(0xA0) is an EquipLevel (u8 EU, u16 USA). +// Text records (sub_08007290): the string starts after a 2-byte EU, 4-byte USA header (TEXT_HEADER). +#ifdef REGION_USA +#define PLAYER_SIZE 0x158 +#define PLAYER_FIELD(o) ((o) < 0x0C ? (o) : (o) < 0x30 ? (o) + 10 : (o) + 12) +#define SAVE_FIELD(o) ((o) < 0x0A ? (o) : (o) < 0x10 ? (o) + 10 : (o) + 12) +#define ENEMY_SIZE 0x454 +#define ENEMY_FIELD(o) ((o) < 0x206 ? (o) : (o) + 0x174) +#define RES_ID(id) ((id) - 4) +#define TEXT_HEADER 4 +#define ITEM_FIELD(o) ((o) + 0xD8) +#define ITEM_KIND_OFF 0x174 +typedef u16 ItemKind; +#define ITEM_KIND(r) (*(ItemKind *)((u8 *)(r) + ITEM_KIND_OFF)) +typedef u16 NameChar; +typedef u16 TextChar; +#define TEXT_CTRL(c) (0xFF00 | (c)) +#define EQUIP_FIELD(o) ((o) + 0xDC) +/* Archive 0xE records: fields from 0xA4 on sit 0xE0 later (0xA0 widens to a word at +0xDC). */ +#define EQUIP_E_FIELD(o) ((o) + 0xE0) +#define GLOVE_SIZE (EQUIP_FIELD(0xB8) + 4) +#define ENEMY_DATA_FIELD(o) ((o) + 0x174) +typedef u16 EquipLevel; +#else +#define PLAYER_SIZE 0x14C +#define PLAYER_FIELD(o) (o) +#define SAVE_FIELD(o) (o) +#define ENEMY_SIZE 0x2E0 +#define ENEMY_FIELD(o) (o) +#define RES_ID(id) (id) +#define TEXT_HEADER 2 +#define ITEM_FIELD(o) (o) +#define ITEM_KIND_OFF 0x9B +typedef u8 ItemKind; +#define ITEM_KIND(r) (*(ItemKind *)((u8 *)(r) + ITEM_KIND_OFF)) +typedef u8 NameChar; +typedef u8 TextChar; +#define TEXT_CTRL(c) (c) +#define EQUIP_FIELD(o) (o) +#define EQUIP_E_FIELD(o) (o) +#define GLOVE_SIZE 0xB8 +#define ENEMY_DATA_FIELD(o) (o) +typedef u8 EquipLevel; +#endif + +#endif // GUARD_REGION_H diff --git a/include/structs.h b/include/structs.h index 97f34d63..db48ed99 100644 --- a/include/structs.h +++ b/include/structs.h @@ -23,7 +23,7 @@ struct DmaEntry { // placeholder structs: array element of N bytes struct Sz24 { u8 b[24]; }; struct Sz40 { u8 b[40]; }; -struct Sz332 { u8 b[332]; }; +struct Sz332 { u8 b[PLAYER_SIZE]; }; // Tilemap / layer system state (gUnk_03003170) struct Layer { @@ -71,12 +71,13 @@ struct LevelEntry { }; // Character / party member (array gUnk_03003CE0, 0x14C bytes each) +// Offsets are EU; USA moves them through PLAYER_FIELD (include/region.h). struct Player { - char unk_0[0x20]; + char unk_0[PLAYER_FIELD(0x20)]; u16 state; // 0x20 - char unk_22[0xE]; + char unk_22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; // 0x30 - char unk_34[0x14C - 0x34]; + char unk_34[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; // placeholder structs: array element of N bytes @@ -122,26 +123,26 @@ struct V2W12 { s32 x, y; }; // Full view of struct Player (0x14C bytes) used by code_0800CF58 (worker 12) struct PlayerW12 { - u8 pad0[0x1C]; + u8 pad0[PLAYER_FIELD(0x1C)]; u16 w1C; // 0x1C - u8 pad1E[2]; + u8 pad1E[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x1E)]; u16 state; // 0x20 - u8 pad22[2]; + u8 pad22[PLAYER_FIELD(0x24) - PLAYER_FIELD(0x22)]; s16 w24; // 0x24 u16 w26; // 0x26 u16 w28; // 0x28 - u8 pad2A[6]; + u8 pad2A[PLAYER_FIELD(0x30) - (PLAYER_FIELD(0x28) + 0x2)]; u32 flags; // 0x30 - u8 pad34[0xC]; + u8 pad34[PLAYER_FIELD(0x40) - PLAYER_FIELD(0x34)]; s16 w40; // 0x40 - u8 pad42[0x4A]; + u8 pad42[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x42)]; struct V2W12 pos8C; // 0x8C struct V2W12 pos94; // 0x94 - u8 pad9C[0x1A]; + u8 pad9C[PLAYER_FIELD(0xB6) - PLAYER_FIELD(0x9C)]; u16 wB6; // 0xB6 - u8 padB8[0x6A]; + u8 padB8[PLAYER_FIELD(0x122) - PLAYER_FIELD(0xB8)]; u16 w122; // 0x122 - u8 pad124[0x14C - 0x124]; + u8 pad124[PLAYER_SIZE - PLAYER_FIELD(0x124)]; }; #endif // GUARD_STRUCTS_H diff --git a/src/code_08001A50.c b/src/code_08001A50.c index 9fff433f..f6cf7826 100644 --- a/src/code_08001A50.c +++ b/src/code_08001A50.c @@ -113,7 +113,11 @@ void sub_08001B78(void) sub_08001AA4(); sub_0805F1B0(); sub_08092094(); +#ifdef REGION_USA + gUnk_03003470 = 1; /* USA starts with this state set */ +#else gUnk_03003470 = 0; +#endif sub_080003F0(); sub_080003F0(); sub_080003F0(); diff --git a/src/code_08002118.c b/src/code_08002118.c index 0c7b9c12..3115a5f9 100644 --- a/src/code_08002118.c +++ b/src/code_08002118.c @@ -201,6 +201,83 @@ extern void spriteDrawMenu000(void *,s32,s32,u32,s32) asm("sub_08065230"); * waits once and wakes scheduler signal 0x14. The original map is 0,2,1,3,4. A preserved navigation-history * register can be read before a directional path initializes it; no general navigation-state initialization * fix or elapsed-time guarantee is inferred. */ +#ifdef REGION_USA +/* USA: no language selection; a second title screen (0x4A) is shown and faded instead. */ +void sub_0800232C(void) { + s32 sp38; + s32 temp_r0; + u32 zero; + u32 configValue; + u32 i; + + temp_r0 = sub_0801AB24(); + if (temp_r0 == 0) { + sub_08000A34(1, 0, 0, 0, temp_r0); + sub_080009F8(0xF00, 0, 0); + sub_080009C0(0x200, 0, 0); + sp38 = (sp38 & 0xFFFF0000) | 0x1C08; + sub_08000AA8(0U, (u16 *) &sp38); + configValue=0x1D03; + *(u16 *)&sp38 = configValue; + sub_08000AA8(1U, (u16 *) &sp38); + sub_0800BCDC(0x4B, 1, 0x06000000, 0U, 0x10U); + sub_08000940(); + sub_0801AB90(0x14); + } else { + sub_08000A34(1, 0, 0, 0, 1); + sub_080009F8(0xF00, 0, 1); + sub_080009C0(0x200, 0, 1); + zero=0; + configValue=0x1C08; + *(u16 *)&sp38 = configValue; + sub_08000AA8(0U, (u16 *) &sp38); + configValue=0x1D03; + *(u16 *)&sp38 = configValue; + sub_08000AA8(1U, (u16 *) &sp38); + sub_0800BCDC(0x4B, 1, 0x06000000, 0U, 0x10U); + screen000[2] = zero; + screen000[3] = zero; + if (sub_0801AB24() == 2) { + sub_0801AB90(6); + } else { + sub_0801AB50(6); + } + } + while (sub_0801AAE0() == 0) { + sub_080920A0(); + sub_080003F0(); + } + i = 0; + do { + sub_080920A0(); + sub_080003F0(); + i += 1; + } while (i <= 0xB3U); + sub_0801AA8C(0x1E); + while (sub_0801AAE0() == 0) { + sub_080920A0(); + sub_080003F0(); + } + sub_0800BCDC(0x4A, 1, 0x06000000, 0U, 0x10U); + screen000[2] = 0; + screen000[3] = 0; + sub_0801AA34(6); + while (sub_0801AAE0() == 0) { + sub_080003F0(); + } + i = 0; + do { + sub_080003F0(); + i += 1; + } while (i <= 0xB3U); + sub_0801AA8C(0x1E); + while (sub_0801AAE0() == 0) { + sub_080003F0(); + } + sub_080003F0(); + sub_08000420(0x14); +} +#else void sub_0800232C(void) { u32 sprite[13]; s32 sp38; @@ -379,6 +456,7 @@ void sub_0800232C(void) { sub_080003F0(); sub_08000420(0x14); } +#endif /* [StartLanguageSelectionTask] Allocates one 0x400-byte stack, configures task 030027E0 with callback 0232C, * zero destructor and callback argument zero, then starts it. No scheduled-task check or allocation-failure * guard is present. Task field +8 is set to1; no priority scale or delayed start is inferred. */ @@ -406,6 +484,147 @@ extern void bg2694(u16, u32 *) asm("sub_08000AA8"); * title/menu resources, stores mode selection03002838. Mode0 stops cable session and starts loopback; mode1 * uses cable session; both start save-slot screen065B0. Modes2/3 invoke88914/920E4. Exact visible option * strings remain unverified. */ +#ifdef REGION_USA +void sub_08002694(void) +{ + u8 anim[0xA4]; /* USA: larger title animation object */ + u16 frame, tick; + struct { u32 lo:16; u32 hi:16; } cnt; + u16 i; + s32 running, started, link; + + sub_080003F0(); + sub_08006E64(1); + for (;;) { + sub_080003F4(0x14); + if (*(u8 *)&gUnk_0300129C & 0x80) + sub_08000940(); + if (sub_08002228() != 0) + sub_080020E0(); + while (sub_08002228() != 0) + sub_080003F0(); + if (sub_08002228() == 0) + sub_0800208C(1); + link = 0; + sub_080013F8(); + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + sub_08000A34(1, 0, 0, 0, link); + sub_080009F8(0xF00, 0, 1); + sub_080009C0(0x1200, 0, 1); + cnt.lo = 0x1C08; + bg2694(0, (u32 *)&cnt); + cnt.lo = 0x1D00; + bg2694(1, (u32 *)&cnt); + gUnk_03001250[0] = link; + gUnk_03001250[1] = link; + gUnk_03001250[2] = link; + gUnk_03001250[3] = link; + gUnk_03001250[4] = link; + gUnk_03001250[5] = link; + gUnk_03001250[6] = link; + gUnk_03001250[7] = link; + sub_0800BCDC(0x37, 1, 0x06000000, 0, 0x10); + init2694(anim, 0x50000, 0xE, 1, 0); /* single language */ + sub_080003F0(); + sub_080003F0(); + gUnk_03002838 = 0; + running = 1; + started = 0; + frame = 0; + tick = 0; + sub_08006C70(0xC5); + for (i = 0; i <= 0x13; i++) + sub_080003F0(); + if (sub_0801AB24() == 0) + sub_0801AA34(6); + else + sub_0801AB50(6); + while (running != 0) { + if (started != 0) { + if (gUnk_03001308 & 0x80) { + sub_08006D08(0xE); + gUnk_03002838 = 1; + goto draw; + } + if (gUnk_03001308 & 0x40) { + i = 0; + sub_08006D08(0xE); + gUnk_03002838 = i; + goto draw; + } + if (*(u16 *)&gUnk_03001324 & 1) { + if ((gUnk_0300130C & 8) && sub_08092080() != 0) { + gUnk_03002838 = 3; + sub_08006D08(0xF); + goto done; + } + sub_08006D08(0xF); + running = 0; + } + } else if (*(u16 *)&gUnk_03001324 & 8) { + started = 1; + sub_08006D08(0xF); + } + draw: + if (started != 0) { + draw2694(anim, 0x78, 0x82, 0, gUnk_03002838); + } else { + anim2694(anim, 4, &frame, &tick, 1); + draw2694(anim, 0x78, 0x88, 4, frame); + } + sub_080003F0(); + } + done: + sub_08006C30(2); + if (started != 0) { + frame = 0; + tick = 0; + } + sub_0801ABE8(3); + while (sub_0801AAE0() == 0) { + if (started != 0) { + if (link == 0) { + anim2694(anim, gUnk_03002838 + 1, &frame, &tick, 1); + draw2694(anim, 0x78, 0x64, gUnk_03002838 + 1, frame); + } else { + draw2694(anim, 0x78, 0x64, 0, gUnk_03002838); + } + } else { + anim2694(anim, 4, &frame, &tick, 1); + draw2694(anim, 0x78, 0x70, 4, frame); + } + draw2694(anim, 0x78, 0x5A, 3, 0); + sub_080003F0(); + } + sub_08065204(anim); + sub_0805F07C(); + switch (gUnk_03002838) { + case 0: + if (sub_08002228() != 0) + sub_080020E0(); + while (sub_08002228() != 0) + sub_080003F0(); + sub_0800208C(0); + sub_080065B0(); + break; + case 1: + if (sub_08002228() == 0) + sub_0800208C(1); + sub_080065B0(); + break; + case 2: + sub_08088914(); + break; + case 3: + sub_080920E4(); + break; + } + } +} +#else void sub_08002694(void) { u8 anim[0x34]; @@ -562,6 +781,7 @@ void sub_08002694(void) } } } +#endif /* [StartTitleModeSelectionTask] Allocates0x200-byte stack, registers task03002810 callback02694. */ void sub_08002A54(void) { @@ -630,7 +850,11 @@ struct Save2B70 { u8 pad8[4]; u16 fC; u8 padE[2]; +#ifdef REGION_USA + NameChar name[10]; +#else u8 name[0xC]; +#endif s16 f1C; s16 f1E; s16 f20; @@ -779,11 +1003,11 @@ void sub_08002B70_(void) vu16 *w; u32 c; - memcpy2B70(cursor, cursor2B70, 2); + memcpy2B70(cursor, cursor2B70, 2 * sizeof(TextChar)); sub_08002AA0(); sub_080003F0(); sub_080003F0(); - saves = alloc2B70(0x360); + saves = alloc2B70(8 * sizeof(struct Save2B70)); all = loadAll2B70(saves); winOpen2B70(3); state = 0; @@ -810,6 +1034,9 @@ void sub_08002B70_(void) memcpy2B70(objA, blank2B70(), 0x34); cx = tx = pos2B70[slot].x; cy = ty = pos2B70[slot].y; +#ifdef REGION_USA + init2B70(objB, 0x50002, 0, 0x80000000, 0); /* single language */ +#else switch (mode2B70) { case 0: init2B70(objB, 0x50002, 0, 0x80000000, 0); @@ -827,6 +1054,7 @@ void sub_08002B70_(void) init2B70(objB, 0x5015E, 0, 0x80000000, 0); break; } +#endif oldMode = vmode2B70(0x88); oldHandler = handler2B70((u32)sub_08006694); sub_08000D8C(); @@ -844,9 +1072,15 @@ void sub_08002B70_(void) clear2B70(0x11, 2); break; } - text2B70(msg2B70(0x140445) + 2, 1, 0x11); +#ifdef REGION_USA + text2B70(msg2B70(0x140445) + TEXT_HEADER, 2, 0x11); + if (blink) + text2B70(cursor, 0x1B, 0x11); +#else + text2B70(msg2B70(0x140445) + TEXT_HEADER, 1, 0x11); if (blink) text2B70(cursor, 0x1C, 0x11); +#endif if (blinkTimer++ < 0x1E) blink = 1; else if (blinkTimer > 0x1D) @@ -955,9 +1189,9 @@ void sub_08002B70_(void) ty = pos2B70[slot].y; } if (saves[slot].used == 0) - text2B70(msg2B70(0x140449) + 2, 1, 0x11); + text2B70(msg2B70(0x140449) + TEXT_HEADER, 1, 0x11); else - text2B70(msgB2B70(0x14044A) + 2, 1, 0x11); + text2B70(msgB2B70(0x14044A) + TEXT_HEADER, 1, 0x11); break; case 2: if (rep2B70 & 0x20) { @@ -992,7 +1226,7 @@ void sub_08002B70_(void) draw2B70(objB, 0x88, 0x78, 5, noFrame); drawB2B70(objB, 0x68, 0x78, 4, yesFrame); } - text2B70(msg2B70(0x140446) + 2, 2, 0x11); + text2B70(msg2B70(0x140446) + TEXT_HEADER, 2, 0x11); break; case 3: if (rep2B70 & 0x20) { @@ -1023,7 +1257,7 @@ void sub_08002B70_(void) draw2B70(objB, 0x88, 0x78, 5, noFrame); drawB2B70(objB, 0x68, 0x78, 4, yesFrame); } - text2B70(msg2B70(0x140447) + 2, 2, 0x11); + text2B70(msg2B70(0x140447) + TEXT_HEADER, 2, 0x11); break; case 4: sub_08006C14(); @@ -1039,7 +1273,7 @@ void sub_08002B70_(void) case 5: if (keys2B70 != 0) state = 1; - text2B70(msg2B70(0x140448) + 2, 2, 0x11); + text2B70(msg2B70(0x140448) + TEXT_HEADER, 2, 0x11); if (blink) text2B70(cursor, 0x1B, 0x11); if (blinkTimer++ < 0x1E) @@ -1056,7 +1290,7 @@ void sub_08002B70_(void) str = msg2B70(0x14044C); else str = msgB2B70(0x14044B); - text2B70(str + 2, 2, 0x11); + text2B70(str + TEXT_HEADER, 2, 0x11); if (rep2B70 & 0x20) { if (yes == 1) se2B70(0xE); @@ -1229,15 +1463,19 @@ extern struct Resource3984 resource3984[] asm("gUnk_08479140"); * class/palette presentation and editable name at supplied record+0x10. Cleanup normalizes name terminators, * marks record used and wakes the requesting task. No particular default name or encoding is claimed. This C * remains a NONMATCHING draft; the role is independently anchored by original ASM. */ +#ifdef REGION_USA +struct NameRec3984 { u8 pad[0x10]; u16 name[12]; }; +extern u16 menuPos3984[][2] asm("gUnk_08366E0C"); void sub_08003984(u8 *arg0, s32 arg1) { u32 gridResultC5; u32 gridResult2C5; s32 language = 2; + s32 setupZero3984; + u32 vramBase3984; s32 nextChar03984, nextChar13984, nextChar23984, nextChar33984, nextChar43984; s32 drawOffset3984; s32 cursorYStep3984; u32 keyboardGap3984; - s32 setupZero3984; u32 drawOne3984, ninthZero3984; u32 cleanupZero3984, cleanupMask3984, cleanupEnd3984; u32 firstName3984; @@ -1251,7 +1489,7 @@ void sub_08003984(u8 *arg0, s32 arg1) { u16 widths[10], heights[10], x[10], y[4]; struct Sprite3984 icons[9], labels[9]; struct Sprite3984 cursor; - u8 panel[0x34], pair[4], buffer[0x21], rows3984[2][0x21]; + u8 panel[0x34]; u16 pair[2], buffer[0x21]; u16 lastWidth; u16 lastHeight; union Bg3984 bg; @@ -1265,7 +1503,7 @@ void sub_08003984(u8 *arg0, s32 arg1) { s32 cursorX; s32 cursorY; u8 *handle; - u8 *text; + u16 *text; u32 status; s32 item; s32 phase; @@ -1344,49 +1582,41 @@ void sub_08003984(u8 *arg0, s32 arg1) { u32 var_r3_3; u32 var_r8; u8 *temp_r0_15; - u8 *temp_r1_4; - u8 *temp_r1_7; + u16 *temp_r1_4; + u16 *temp_r1_7; u8 *temp_r2_4; u8 *temp_r2_5; - u8 *temp_r2_6; + u16 *temp_r2_6; u8 *temp_r3; - u8 *temp_r3_3; + u16 *temp_r3_3; u8 *temp_r4_19; u8 *temp_r4_7; u8 *temp_r5; - u8 *temp_r5_13; + u16 *temp_r5_13; u8 *temp_r5_2; - u8 *temp_r6_3; + u16 *temp_r6_3; u8 *temp_r6_4; u8 *temp_r6_5; - u8 *var_r0_6; + u16 *var_r0_6; u8 *var_r2_2; u8 *var_r3_2; - u8 *var_r5_3; - u8 *nm; - u8 *var_r7; + u16 *var_r5_3; + struct NameText3984 { u16 n[12]; } *nm; + u16 *var_r7; u32 temp_r0_10; u32 temp_r0_11; u8 temp_r0_16; - u8 temp_r0_17; - u8 temp_r0_22; + u16 temp_r0_17; + u16 temp_r0_22; u8 var_r1_2; void *temp_r0_3; - u32 vramBase3984 = 0x06000000; - u32 zeroElse3984 = 0; - u32 yTable3984 = (u32)&gUnk_08366E0E; - memcpy(&pair[0], &gUnk_080B99D4, 2); - memcpy(&cursor, sub_080653CC(), 0x34); - switch (gUnk_03003470) { - case 0: sub_08065158(panel, 0x50002, 0, 0x80000000, 0); break; - case 1: sub_08065158(panel, 0x5015B, 0, 0x80000000, 0); break; - case 2: sub_08065158(panel, 0x5015C, 0, 0x80000000, 0); break; - case 3: sub_08065158(panel, 0x5015D, 0, 0x80000000, 0); break; - case 4: sub_08065158(panel, 0x5015E, 0, 0x80000000, 0); break; - } + memcpy((u8 *)pair, &gUnk_080B99D4, 4); + + sub_08065158(panel, 0x50002, 0, -1, setupZero3984 = 0); + sub_08065158((u8 *)&cursor, 0x50006, 0, -1, setupZero3984); sub_0801A6D4(0); - reg3984.v0 = setupZero3984 = 0; + reg3984.v0 = setupZero3984; reg3984.h0 = setupZero3984; reg3984.v1 = setupZero3984; reg3984.h1 = setupZero3984; @@ -1399,39 +1629,31 @@ void sub_08003984(u8 *arg0, s32 arg1) { sub_08000AA8(1U, &bg.half); bg.half = 0x1F03; sub_08000AA8(3U, &bg.half); - { - u32 vramC7 = 0x06000000; - register u32 paletteC7 asm("r5") = 0xF; + { u32 vramC7 = 0x06000000; register u32 paletteC7 asm("r5") = 0xF; sub_0800BCDC(0x15, 3, vramC7, 0U, paletteC7); sub_0800BCDC(0x16, 2, vramC7, 0U, paletteC7); sub_0800B650(0x3B, 0x1B, vramC7, 0U, paletteC7); sub_0800B650(0x40000017, 0x1A, vramC7, 0U, paletteC7); sub_0800B650(0x12, 0x19, vramC7, 0U, paletteC7); - sub_0800B650(0x18, 0x18, vramC7, 0U, paletteC7); - } + sub_0800B650(0x18, 0x18, vramC7, 0U, paletteC7); } sub_0800903C(4, 8, 1, 8, 0x10, setupZero3984); sub_080009F8(0x200, 0, 1); - handle = ((u8 *(*)(s32))sub_08007290)(0x10023); + handle = ((u8 *(*)(s32))sub_08007290)(0x10008); var_r6 = 0; do { temp_r5 = (u8 *)&icons[var_r6]; - sub_08065158(temp_r5, var_r6 + 0x5006B, 0, 1, setupZero3984); + sub_08065158(temp_r5, var_r6 + RES_ID(0x5006B), 0, 1, setupZero3984); sub_08065158((u8 *)&labels[var_r6], resource3984[var_r6].id, 0, 1, setupZero3984); M2C_FIELD(temp_r5, s8 *, 0x1C) = var_r6; - temp_r1 = var_r6 * 2; x[var_r6] = setupZero3984; - { - u32 initWidthC8 = (u32)widths; - initWidthC8 += temp_r1; - *(u16 *)initWidthC8 = setupZero3984; - } + widths[var_r6] = setupZero3984; heights[var_r6] = setupZero3984; var_r6 = (u16) (var_r6 + 1); } while ((u32) var_r6 <= 8U); sub_080003F0(); sub_080003F0(); sub_0801AB50(3); - ((u8 *(*)(s32))sub_08007290)(0x140441); + ((u16 *(*)(s32))sub_08007290)(0x140441); substate = 0; index = 0; state = 0; @@ -1458,6 +1680,7 @@ void sub_08003984(u8 *arg0, s32 arg1) { targetX = (s32) M2C_FIELD(((u8 *)&gUnk_08366E0C), u16 *, 0); targetY = newY; sub_08058688(0x71); + vramBase3984 = 0x06000000; while (1) { temp_r0 = sub_0801AAE0(); if (temp_r0 == 0) { @@ -1480,34 +1703,8 @@ void sub_08003984(u8 *arg0, s32 arg1) { sub_080009C0(0x200, 0, 1); sub_08000D8C(); } else { - var_r7 = ((u8 *(*)(s32))sub_08007290)(0x140441); - var_r7 += 2; - rows3984[0][0] = 0; - rows3984[1][0] = 0; - var_r8 = 0; - for (; var_r8 <= 1U; var_r8++) { - var_r6 = 0; - var_r1_2 = *var_r7; - if (var_r1_2 != 0xFD) { - do { - { u8 *baseC13 = (u8 *)rows3984; u32 offC13 = var_r8 * 0x21; *(baseC13 + (var_r6 + offC13)) = var_r1_2; } - if (({ u32 cmpC13; asm("" : "=l"(cmpC13) : "0"(var_r1_2)); cmpC13; }) == 0xFF) { - var_r7++; - break; - } - var_r6++; - var_r7++; - var_r1_2 = *var_r7; - } while (var_r1_2 != 0xFD); - } - rows3984[var_r8][var_r6] = 0xFD; - if (var_r6 == 0) - break; - temp_r4_7 = rows3984[var_r8]; - sub_0801A3D0(temp_r4_7, (u16)(0xF - ((u32)sub_0801A638(temp_r4_7) >> 1)), (u16)(var_r8 * 2)); - if (*var_r7 == 0xFD) - break; - } + var_r7 = ((u16 *(*)(s32))sub_08007290)(0x140441); + sub_0801A3D0((u8 *)(var_r7 + 2), 0U, 0U); if (status++ <= 0x1DU) { item = 1; } else if ((u32) status > 0x1DU) { @@ -1519,7 +1716,10 @@ void sub_08003984(u8 *arg0, s32 arg1) { if (item == 0) { } else { - sub_0801A3D0(&pair[0], 0x1CU, (u16) (var_r8 * 2)); + var_r0_6 = pair; + var_r1_6 = 0x1C; + asm(""); + goto block_206; } } goto block_374; @@ -1666,27 +1866,24 @@ void sub_08003984(u8 *arg0, s32 arg1) { gUnk_03003474 = selectionZeroC6; sub_0801A664(0, 0xA); timer = 3; - var_r7 = ((u8 *(*)(s32))sub_08007290)((state + 0x454) | 0x140000); + var_r7 = ((u16 *(*)(s32))sub_08007290)((state + 0x454) | 0x140000); var_r7 += 2; var_r6 = 0; - firstName3984 = *var_r7; - var_r5_3 = arg0 + 0x10; - if (firstName3984 == 0xFF) { - M2C_FIELD(arg0, u8 *, 0x10) = 0xFD; + if (*var_r7 == 0xFFFF) { + ((struct NameRec3984 *)arg0)->name[0] = 0xFFFD; } else { loop_107: - var_r5_3[var_r6] = *(var_r7 + var_r6); + ((struct NameRec3984 *)arg0)->name[var_r6] = *(var_r7 + var_r6); var_r6 += 1; if ((u32) var_r6 <= 8U) { - if (*(var_r7 + var_r6) == 0xFF) { - var_r5_3[var_r6] = 0xFD; + if (*(var_r7 + var_r6) == 0xFFFF) { + ((struct NameRec3984 *)arg0)->name[var_r6] = 0xFFFD; } else { goto loop_107; } } } - var_r5_3[(nextChar03984 = var_r6 + 1)] = nameZero3984 = 0; - asm("" : : "r"(nameZero3984)); + ((struct NameRec3984 *)arg0)->name[var_r6 + 1] = 0; selection = 0xA; sub_08000E48(); sub_080009F8(0x200, 0, 1); @@ -1694,8 +1891,8 @@ void sub_08003984(u8 *arg0, s32 arg1) { } else { sub_0801A664(0, 2); - reg3984.h0 = nameZero3984; - var_r9 = (u16) sub_0801A638(var_r5_3); + reg3984.h0 = 0; + var_r9 = (u16) sub_0801A638((u8 *)((struct NameRec3984 *)arg0)->name); next = var_r9; current = 0; bg.half = 0xD800; @@ -1720,7 +1917,7 @@ void sub_08003984(u8 *arg0, s32 arg1) { ((void (*)(unsigned long long))sub_08000420)(0x25A112EBFULL); goto epilogue3984; } else { - var_r7 = ((u8 *(*)(s32))sub_08007290)((state + 0x454) | 0x140000); + var_r7 = ((u16 *(*)(s32))sub_08007290)((state + 0x454) | 0x140000); var_r7 += 2; { u32 titleWidthC8; @@ -1729,7 +1926,7 @@ void sub_08003984(u8 *arg0, s32 arg1) { u16 *titleXC8; u16 *titleYC8; s32 titleXValueC8; - titleWidthC8 = sub_0801A638(var_r7); + titleWidthC8 = sub_0801A638((u8 *)var_r7); titleBaseC8 = (u32)&gUnk_08366E0C; titleIndexC8 = state * 4; titleXC8 = (u16 *)(titleIndexC8 + titleBaseC8); @@ -1737,14 +1934,15 @@ void sub_08003984(u8 *arg0, s32 arg1) { titleBaseC8 += 2; titleIndexC8 = titleIndexC8 + titleBaseC8; titleYC8 = (u16 *)titleIndexC8; - ((void (*)(const u8 *, s32, s32))sub_0801A764)(var_r7, titleXValueC8, *titleYC8 - 0x28); + ((void (*)(const u8 *, s32, s32))sub_0801A764)((u8 *)var_r7, titleXValueC8, *titleYC8 - 0x28); newX = *titleXC8; newY = *titleYC8; } temp_r4_11 = state * 2; - var_r7 = ((u8 *(*)(s32))sub_08007290)((temp_r4_11 + 0x42F) | 0x140000); + asm("" : : "r"(temp_r4_11)); + var_r7 = ((u16 *(*)(s32))sub_08007290)((temp_r4_11 + 0x42F) | 0x140000); var_r7 += 2; - sub_0801A3D0(var_r7, (u16) (0xF - ((u32) sub_0801A638(var_r7) >> 1)), 1U); + sub_0801A3D0((u8 *)var_r7, (u16) (0xF - ((u32) sub_0801A638((u8 *)var_r7) >> 1)), 1U); temp_r1_3 = substate; substate = (u32) (u16) (temp_r1_3 + 1); if ((u32) prev <= temp_r1_3) { @@ -1770,10 +1968,10 @@ void sub_08003984(u8 *arg0, s32 arg1) { gUnk_03003474 = (s32) status; var_r6 = 0; do { - (&buffer[0])[var_r6] = 0xFD; + buffer[var_r6] = 0xFFFD; var_r6 += 1; } while ((u32) var_r6 <= 0x1FU); - text = ((u8 *(*)(s32))sub_08007290)((temp_r4_11 + 0x430) | 0x140000); + text = ((u16 *(*)(s32))sub_08007290)((temp_r4_11 + 0x430) | 0x140000); text += 2; selection = state; } @@ -1782,26 +1980,26 @@ void sub_08003984(u8 *arg0, s32 arg1) { if (temp_r0_6 > 2U) { status = 0; temp_r1_4 = text; - if (*temp_r1_4 == 0xFF) { + if (*temp_r1_4 == 0xFFFF) { text = temp_r1_4 + 1; } temp_r3_3 = text; - if (*temp_r3_3 == 0xFE) { + if (*temp_r3_3 == 0xFFFE) { text = temp_r3_3 + 3; } - if (*text == 0xFD) { - text = ((u8 *(*)(s32))sub_08007290)((temp_r4_11 + 0x430) | 0x140000); + if (*text == 0xFFFD) { + text = ((u16 *(*)(s32))sub_08007290)((temp_r4_11 + 0x430) | 0x140000); text += 2; } temp_r4_12 = oldCount; temp_r6_3 = text; - (&buffer[0])[temp_r4_12] = *temp_r6_3; + ((struct NameText3984 *)buffer)->n[temp_r4_12] = *temp_r6_3; text = temp_r6_3 + 1; temp_r4_13 = temp_r4_12 + 1; oldCount = temp_r4_13; if (temp_r4_13 > 0x1FU) { oldCount = 0; - buffer[0x20] = 0xFD; + buffer[0x20] = 0xFFFD; phase = 1; } } @@ -1816,7 +2014,7 @@ void sub_08003984(u8 *arg0, s32 arg1) { status = 0; } } - sub_0801A3D0(&buffer[0], 0U, 4U); + sub_0801A3D0((u8 *)buffer, 0U, 4U); targetX = targetX + ((s32) (temp_r5_9 + (temp_r5_9 >> 0x1F)) >> 1); temp_r3_4 = targetY; temp_r0_8 = newY - temp_r3_4; @@ -1855,7 +2053,7 @@ void sub_08003984(u8 *arg0, s32 arg1) { if (item == 0) { } else { - var_r0_6 = &pair[0]; + var_r0_6 = pair; var_r1_6 = 0x1C; goto block_206; } @@ -1912,154 +2110,34 @@ void sub_08003984(u8 *arg0, s32 arg1) { M2C_FIELD(arg0, s8 *, 2) = 0; } block_175: - var_r7 = ((u8 *(*)(s32))sub_08007290)((M2C_FIELD(arg0, u8 *, 2) + 0x4C5) | 0x140000); + var_r7 = ((u16 *(*)(s32))sub_08007290)((M2C_FIELD(arg0, u8 *, 2) + 0x4C5) | 0x140000); if (state != 2) { - u32 menuIndexC9; - u32 menuLanguageC9; - temp_r5_13 = var_r7 + 2; - { - u32 titleWidthC9; - u32 titleBaseC9; - u32 titleIndexC9; - u32 titleXValueC9; - titleWidthC9 = sub_0801A638(temp_r5_13); - titleBaseC9 = (u32)&gUnk_08366E0C; - titleIndexC9 = state * 4; - titleXValueC9 = titleIndexC9 + titleBaseC9; - titleXValueC9 = *(u16 *)titleXValueC9; - titleXValueC9 -= titleWidthC9 * 4; - titleBaseC9 += 2; - titleBaseC9 = titleIndexC9 + titleBaseC9; - titleBaseC9 = *(u16 *)titleBaseC9; - titleBaseC9 -= 0x28; - ((void (*)(const u8 *, s32, s32))sub_0801A764)(temp_r5_13, titleXValueC9, titleBaseC9); - menuLanguageC9 = gUnk_03003470; - menuIndexC9 = titleIndexC9; - } - switch (menuLanguageC9) { /* switch 5 */ - case 0: - offsetX = 0x23; - offsetY = 0x1D; - break; - case 1: - offsetX = 0x2B; - offsetY = 0x25; - break; - case 2: - offsetX = 0x23; - offsetY = 0x1D; - break; - case 3: - offsetX = 0x2B; - offsetY = 0x25; - break; - case 4: - offsetX = 0x23; - offsetY = 0x1D; - break; - } if ((u32) M2C_FIELD(arg0, u8 *, 2) <= 8U) { - var_r7 = (u8 *)&cursor; - var_r4_2 = (u16 *)&gUnk_08366E0C; - temp_r5_14 = (u16 *)(menuIndexC9 + (u8 *)var_r4_2); - var_r1_7 = *temp_r5_14; - var_r1_7 -= offsetX; - var_r1_7 -= cursorX; - var_r4_2 = (u16 *)((u32)var_r4_2 + 2); - var_r4_2 = (u16 *)(menuIndexC9 + (u32)var_r4_2); - sub_08065230(var_r7, var_r1_7, *var_r4_2 - 0x20, 3U, 2); - var_r1_7 = *temp_r5_14; - var_r1_7 += offsetY; - var_r1_7 += cursorY; + var_r7 += 2; + textWidth3984 = sub_0801A638((u8 *)var_r7); + ((void (*)(const u8 *, s32, s32))sub_0801A764)((u8 *)(var_r7), menuPos3984[state][0] - textWidth3984 * 4, menuPos3984[state][1] - 0x28); + sub_08065230(&cursor, menuPos3984[state][0] - (drawOffset3984 = cursorX + 35), menuPos3984[state][1] - 0x20, 3U, 2); + sub_08065230(&cursor, (drawOffset3984 = cursorY + 29) + menuPos3984[state][0], menuPos3984[state][1] - 0x20, 3U, 1); } else { - s32 selectorStepC10; - var_r7 = (u8 *)&cursor; - var_r4_2 = (u16 *)&gUnk_08366E0C; - temp_r5_14 = (u16 *)(menuIndexC9 + (u8 *)var_r4_2); - var_r1_7 = *temp_r5_14; - var_r1_7 -= offsetX; - var_r1_7 -= (selectorStepC10 = cursorX + 5); - var_r4_2 = (u16 *)((u32)var_r4_2 + 2); - var_r4_2 = (u16 *)(menuIndexC9 + (u32)var_r4_2); - sub_08065230(var_r7, var_r1_7, *var_r4_2 - 0x20, 3U, 2); - var_r1_7 = *temp_r5_14; - var_r1_7 += offsetY; - { - selectorStepC10 = cursorY + 5; - var_r1_7 += selectorStepC10; - } - } - goto block_198; - } else { - switch (gUnk_03003470) { /* switch 6 */ - case 0: /* switch 6 */ - offsetX = 0x23; - offsetY = 0x18; - break; - case 1: /* switch 6 */ - offsetX = 0x2B; - offsetY = 0x28; - break; - case 2: /* switch 6 */ - offsetX = 0x23; - offsetY = 0x18; - break; - case 3: /* switch 6 */ - offsetX = 0x2B; - offsetY = 0x20; - break; - case 4: /* switch 6 */ - offsetX = 0x23; - offsetY = 0x18; - break; + var_r7 += 2; + textWidth3984 = sub_0801A638((u8 *)var_r7); + ((void (*)(const u8 *, s32, s32))sub_0801A764)((u8 *)(var_r7), menuPos3984[state][0] - textWidth3984 * 4, menuPos3984[state][1] - 0x28); + sub_08065230(&cursor, menuPos3984[state][0] - (drawOffset3984 = cursorX + 40), menuPos3984[state][1] - 0x20, 3U, 2); + sub_08065230(&cursor, (drawOffset3984 = cursorY + 34) + menuPos3984[state][0], menuPos3984[state][1] - 0x20, 3U, 1); } + } else { if ((u32) M2C_FIELD(arg0, u8 *, 2) <= 8U) { - { - register u8 *shortTextC10 asm("r0"); - u32 shortBaseC10; - register u32 shortIndexC10 asm("r4"); - register s32 shortXC10 asm("r1"); - shortTextC10 = var_r7 + 2; - shortBaseC10 = (u32)&gUnk_08366E0C; - shortIndexC10 = state * 4; - temp_r5_14 = (u16 *)(shortIndexC10 + shortBaseC10); - shortXC10 = *temp_r5_14 - 9; - shortBaseC10 += 2; - var_r4_2 = (u16 *)(shortIndexC10 + shortBaseC10); - ((void (*)(const u8 *, s32, s32))sub_0801A764)(shortTextC10, shortXC10, *var_r4_2 - 0x28); - } - var_r7 = (u8 *)&cursor; - sub_08065230(var_r7, *temp_r5_14 - (drawOffset3984 = cursorX + 0x10), *var_r4_2 - 0x20, 3U, 2); - var_r1_7 = offsetY + 0x18; - asm("" : : "r"(var_r1_7)); - { register u32 heightC11 asm("r5") = *temp_r5_14; var_r1_7 += heightC11; } - var_r1_7 += cursorY; -block_198: - sub_08065230(var_r7, var_r1_7, *var_r4_2 - 0x20, 3U, 1); - goto after198; - } - var_r7 = var_r7 + 2; - textWidth3984 = sub_0801A638(var_r7); - { - u32 longBaseC9; - u32 longStateC9; - register u32 longIndexC9 asm("r4"); - s32 longXC9; - longBaseC9 = (u32)&gUnk_08366E0C; - longStateC9 = state; - longIndexC9 = longStateC9 * 4; - temp_r5_14 = (u16 *)(longIndexC9 + longBaseC9); - longXC9 = *temp_r5_14 - (drawOffset3984 = textWidth3984 * 4 - 0x18); - longBaseC9 += 2; - var_r4_2 = (u16 *)(longIndexC9 + longBaseC9); - ((void (*)(const u8 *, s32, s32))sub_0801A764)(var_r7, longXC9, *var_r4_2 - 0x28); + textWidth3984 = sub_0801A638((u8 *)(var_r7 + 2)); + ((void (*)(const u8 *, s32, s32))sub_0801A764)((u8 *)(var_r7 + 2), menuPos3984[2][0] - (drawOffset3984 = textWidth3984 * 4 - 19), menuPos3984[2][1] - 0x28); + sub_08065230(&cursor, menuPos3984[2][0] - (drawOffset3984 = cursorX + 16), menuPos3984[2][1] - 0x20, 3U, 2); + sub_08065230(&cursor, (drawOffset3984 = cursorY + 48) + menuPos3984[2][0], menuPos3984[2][1] - 0x20, 3U, 1); + } else { + textWidth3984 = sub_0801A638((u8 *)(var_r7 + 2)); + ((void (*)(const u8 *, s32, s32))sub_0801A764)((u8 *)(var_r7 + 2), menuPos3984[2][0] - (drawOffset3984 = textWidth3984 * 4 - 24), menuPos3984[2][1] - 0x28); + sub_08065230(&cursor, menuPos3984[2][0] - (drawOffset3984 = cursorX + 16), menuPos3984[2][1] - 0x20, 3U, 2); + sub_08065230(&cursor, (drawOffset3984 = cursorY + 56) + menuPos3984[2][0], menuPos3984[2][1] - 0x20, 3U, 1); } - var_r7 = (u8 *)&cursor; - sub_08065230(var_r7, *temp_r5_14 - (drawOffset3984 = cursorX + 0x10), *var_r4_2 - 0x20, 3U, 2); - var_r7 = (u8 *)&cursor; - sub_08065230(var_r7, (drawOffset3984 = offsetY + 0x18) + *temp_r5_14 + (cursorYStep3984 = cursorY + 9), *var_r4_2 - 0x20, 3U, 1); - } -after198: + } if (!(gUnk_03002344 & 3)) { temp_r6_6 = cursorX; if (temp_r6_6 != 0) { @@ -2070,11 +2148,11 @@ void sub_08003984(u8 *arg0, s32 arg1) { cursorY = (s32) (u16) (temp_r3_5 - 1); } } - var_r7 = ((u8 *(*)(s32))sub_08007290)(0x140442); + var_r7 = ((u16 *(*)(s32))sub_08007290)(0x140442); var_r0_6 = var_r7 + 2; var_r1_6 = 0; block_206: - sub_0801A3D0(var_r0_6, var_r1_6, 0U); + sub_0801A3D0((u8 *)var_r0_6, var_r1_6, 0U); } goto block_374; case 4: /* switch 2 */ @@ -2110,18 +2188,18 @@ void sub_08003984(u8 *arg0, s32 arg1) { sub_08065230(&panel[0], 0xE2, 0x8E, 5U, y[1]); sub_08065264(&panel[0], 0xC2, 0x8E, 4, y[0]); } - sub_0801A3D0(((u8 *(*)(s32))sub_08007290)(0x140443) + 2, 2U, 0x12U); + sub_0801A3D0((u8 *)(((u16 *(*)(s32))sub_08007290)(0x140443) + 2), 2U, 0x12U); ((void (*)(const u8 *, s32, s32))sub_0801A764)(arg0 + 0x10, 0x58U, 0x10U); goto block_374; case 5: /* switch 2 */ sub_08000C08(8, 2); if (keys3984 & 0x100) { - nm = arg0 + 0x10; + if (var_r9 <= 6) { /* Keep the test and store addresses separate through GCSE. */ - if (next == var_r9 || nm[-(-(u32)var_r9 + 1) + 1] == 0xFD) { - nm[var_r9] = 0x51; - nm[(nextChar13984 = var_r9 + 1)] = 0xFD; + if (next == var_r9 || ((struct NameRec3984 *)arg0)->name[var_r9] == 0xFFFD) { + ((struct NameRec3984 *)arg0)->name[var_r9] = 0x51; + ((struct NameRec3984 *)arg0)->name[var_r9 + 1] = 0xFFFD; var_r9++; next = var_r9; } else { @@ -2130,14 +2208,14 @@ void sub_08003984(u8 *arg0, s32 arg1) { sub_0805865C(0xE); } } else if (keys3984 & 0x200) { - nm = arg0 + 0x10; + if (var_r9 != 0) { var_r9--; sub_0805865C(0xE); } } else if (gUnk_03001308 & 0x40) { sub_0805865C(0x62); - nm = arg0 + 0x10; + switch (language) { case 0: case 1: @@ -2147,15 +2225,15 @@ void sub_08003984(u8 *arg0, s32 arg1) { current -= 20; break; case 2: - if (current < 24) - current += 120; + if (current < 14) + current += 56; else - current -= 24; + current -= 14; break; } } else if (gUnk_03001308 & 0x80) { sub_0805865C(0x62); - nm = arg0 + 0x10; + switch (language) { case 0: case 1: @@ -2165,15 +2243,15 @@ void sub_08003984(u8 *arg0, s32 arg1) { current += 20; break; case 2: - if (current >= 120) - current -= 120; + if (current >= 56) + current -= 56; else - current += 24; + current += 14; break; } } else if (gUnk_03001308 & 0x10) { sub_0805865C(0x62); - nm = arg0 + 0x10; + switch (language) { case 0: case 1: @@ -2183,15 +2261,15 @@ void sub_08003984(u8 *arg0, s32 arg1) { current++; break; case 2: - if ((u16)(current % 24) > 22) - current -= 23; + if ((u16)(current % 14) > 12) + current -= 13; else current++; break; } } else if ((u16)(gUnk_03001308 & 0x20)) { sub_0805865C(0x62); - nm = arg0 + 0x10; + switch (language) { case 0: case 1: @@ -2201,8 +2279,8 @@ void sub_08003984(u8 *arg0, s32 arg1) { current--; break; case 2: - if ((u16)(current % 24) == 0) - current += 23; + if ((u16)(current % 14) == 0) + current += 13; else current--; break; @@ -2211,40 +2289,37 @@ void sub_08003984(u8 *arg0, s32 arg1) { sub_0805865C(0xF); switch (language) { case 0: - { u8 *p = arg0 + 0x10; - p[var_r9] = gUnk_08366E34[current]; } + ((struct NameRec3984 *)arg0)->name[var_r9] = gUnk_08366E34[current]; break; case 1: - { u8 *p = arg0 + 0x10; - p[var_r9] = gUnk_08366EFC[current]; } + ((struct NameRec3984 *)arg0)->name[var_r9] = gUnk_08366EFC[current]; break; case 2: - { u8 *p = arg0 + 0x10; - p[var_r9] = gUnk_08366FC4[current]; } + ((struct NameRec3984 *)arg0)->name[var_r9] = gUnk_08366FC4[current]; break; } - nm = arg0 + 0x10; + if (var_r9 <= 6) { var_r9++; if (var_r9 > next) { - nm[var_r9] = 0xFD; + ((struct NameRec3984 *)arg0)->name[var_r9] = 0xFFFD; next = var_r9; } } else { - nm[(nextChar23984 = var_r9 + 1)] = 0xFD; + ((struct NameRec3984 *)arg0)->name[var_r9 + 1] = 0xFFFD; } } else if (keys3984 == 2) { sub_0805865C(0x10); if (var_r9 == next) { - u8 *name = arg0 + 0x10; - name[var_r9] = 0xFD; - name[(nextChar33984 = var_r9 + 1)] = 0; + + ((struct NameRec3984 *)arg0)->name[var_r9] = 0xFFFD; + ((struct NameRec3984 *)arg0)->name[var_r9 + 1] = 0; var_r9--; deleteMaskC6 = var_r9 & 0x8000; - nm = name; + if (deleteMaskC6) { var_r9 = 0; - if (arg0[0x10] == 0xFD) { + if (((struct NameRec3984 *)arg0)->name[0] == 0xFFFD) { timer = 3; sub_080009F8(0x200, 0, 1); sub_0800903C(4, 8, 1, 8, 0x10, var_r9); @@ -2258,9 +2333,9 @@ void sub_08003984(u8 *arg0, s32 arg1) { } next = var_r9; } else { - u8 *name = arg0 + 0x10; - u8 c = name[var_r9]; - nm = name; + + u16 c = ((struct NameRec3984 *)arg0)->name[var_r9]; + if (c == 0x51) { var_r9--; if (var_r9 & 0x8000) { @@ -2276,7 +2351,7 @@ void sub_08003984(u8 *arg0, s32 arg1) { var_r9 = 0; } } else { - nm[var_r9] = 0x51; + ((struct NameRec3984 *)arg0)->name[var_r9] = 0x51; if (var_r9 == 0) { timer = 3; sub_080009F8(0x200, 0, 1); @@ -2291,22 +2366,22 @@ void sub_08003984(u8 *arg0, s32 arg1) { } } } else { - nm = arg0 + 0x10; + if (keys3984 == 8) { - if (sub_0801A638(nm) != 0) { + if (sub_0801A638((u8 *)((struct NameRec3984 *)arg0)->name) != 0) { var_r3_3 = 0; var_r6 = 0; - if (arg0[0x10] != 0x51) { - var_r3_3 = arg0[0x10] != 0xFD; + if (((struct NameRec3984 *)arg0)->name[0] != 0x51) { + var_r3_3 = ((struct NameRec3984 *)arg0)->name[0] != 0xFFFD; } else { loop8_3984: var_r6++; if (var_r6 <= 7) { - u8 *q = arg0 + 0x10; - temp_r0_17 = q[var_r6]; + + temp_r0_17 = ((struct NameRec3984 *)arg0)->name[var_r6]; if (temp_r0_17 == 0x51) goto loop8_3984; - if (temp_r0_17 != 0xFD) + if (temp_r0_17 != 0xFFFD) var_r3_3++; } } @@ -2345,12 +2420,12 @@ void sub_08003984(u8 *arg0, s32 arg1) { newY = ((u32) (((u32) current / 20U) << 0x10) >> 0xC) + 0x30; break; case 2: - temp_r0_18 = ((u32) current % 24U) << 0x10; - newX = (temp_r0_18 >> 0xD) + (keyboardGap3984 = (((temp_r0_18 >> 0x14) * 0x10) + 0x10)); - newY = ((u32) (((u32) current / 24U) << 0x10) >> 0xC) + 0x30; + temp_r0_19 = (u16) ((u32) current % 14U); + newX = (temp_r0_19 * 8) + (keyboardGap3984 = (((u32) ((temp_r0_19 / 7U) << 0x10) >> 0xC) + 0x37)); + newY = ((u32) (((u32) current / 14U) << 0x10) >> 0xC) + 0x30; break; } - ((void (*)(const u8 *, s32, s32))sub_0801A764)(arg0 + 0x10, 0x58U, 0x10U); + ((void (*)(const u8 *, s32, s32))sub_0801A764)((u8 *)((struct NameRec3984 *)arg0)->name, 0x58U, 0x10U); sub_08065370(&cursor, 5U, (s32) &lastWidth, (s32) &lastHeight, 1); sub_080659BC(&cursor, (var_r9 * 8) + 0x58, 0x18, 5U, (s32) lastWidth, 1); targetX += (newX - targetX) / 2; @@ -2366,14 +2441,1230 @@ void sub_08003984(u8 *arg0, s32 arg1) { case 6: /* switch 2 */ var_r3_4 = 0; var_r6 = 8; - temp_r2_6 = arg0 + 0x10; + nm = (void *)(arg0 + 0x10); + cleanupEnd3984 = 0xFFFD; cleanupZero3984 = 0; cleanupMask3984 = 0x8000; - cleanupEnd3984 = 0xFD; loop_363: - temp_r1_7 = &temp_r2_6[var_r6]; - temp_r0_22 = M2C_FIELD(temp_r1_7, u8 *, 0); - if (temp_r0_22 == 0xFD) { + if (nm->n[var_r6] == cleanupEnd3984) { + var_r3_4 = 1; + asm("" : : "r"(var_r3_4)); + goto block_368; + } + if (var_r3_4 == 1) { + if (nm->n[var_r6] == 0x51) { + nm->n[var_r6] = cleanupEnd3984; + nm->n[var_r6 + 1] = cleanupZero3984; + goto block_368; + } + } else { +block_368: + var_r6 -= 1; + if (!(var_r6 & cleanupMask3984)) { + goto loop_363; + } + } + sub_0801ABE8(6); + sub_080003F0(); + sub_080003F0(); + while (sub_0801AAE0() == 0) { + sub_080003F0(); + } + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + sub_08006544(); + sub_0801A664(0, 0x13); + sub_080003F0(); + *arg0 = 1; + goto finish3984; + } +finish3984: + /* Preserve caller ABI; the scheduler consumes only the low32 signal tag. */ + ((void (*)(unsigned long long))sub_08000420)(0x25A112EBFULL); + goto epilogue3984; +block_374: + for (var_r6 = 0; var_r6 <= 7; var_r6++) { + if ((u32) (u16) (timer - 4) > 2U) { + if (state == var_r6) { + x[var_r6] = 1; + sub_08000AF0(var_r6 + 0x10, labels[var_r6].data + (M2C_FIELD(arg0, u8 *, 2) << 5), 1U); + sub_08065370((u8 *)&icons[var_r6], x[var_r6], (s32) &widths[var_r6], (s32) &heights[var_r6], 0); + } else { + x[var_r6] = 0; + sub_08000AF0(var_r6 + 0x10, labels[var_r6].data, 1U); + sub_08065370((u8 *)&icons[var_r6], x[var_r6], (s32) &widths[var_r6], (s32) &heights[var_r6], 1); + } + } + sub_080659BC((u8 *)&icons[var_r6], menuPos3984[var_r6][0], menuPos3984[var_r6][1], x[var_r6], widths[var_r6], 1); + } + if (arg1 != 0) { + if ((u32) (u16) (timer - 4) > 2U) { + if (state == var_r6) { + x[var_r6] = 1; + sub_08000AF0(var_r6 + 0x10, labels[var_r6].data + (M2C_FIELD(arg0, u8 *, 2) << 5), 1U); + sub_08065370((u8 *)&icons[var_r6], x[var_r6], (s32) &widths[var_r6], (s32) &heights[var_r6], 0); + } else { + x[var_r6] = 0; + sub_08000AF0(var_r6 + 0x10, labels[var_r6].data, 1U); + sub_08065370((u8 *)&icons[var_r6], x[var_r6], (s32) &widths[var_r6], (s32) &heights[var_r6], 1); + } + } + sub_080659BC((u8 *)&icons[var_r6], menuPos3984[var_r6][0], menuPos3984[var_r6][1], x[var_r6], widths[var_r6], 1); + } + sub_080003F0(); + continue; + + } +epilogue3984: + return; +} +#else +void sub_08003984(u8 *arg0, s32 arg1) { + u32 gridResultC5; + u32 gridResult2C5; + s32 language = 2; + s32 nextChar03984, nextChar13984, nextChar23984, nextChar33984, nextChar43984; + s32 drawOffset3984; + s32 cursorYStep3984; + u32 keyboardGap3984; + s32 setupZero3984; + u32 drawOne3984, ninthZero3984; + u32 cleanupZero3984, cleanupMask3984, cleanupEnd3984; + u32 firstName3984; + u32 deleteChar3984; + u32 deleteMaskC6; + u32 selectionZeroC6; + u32 nameZero3984; + s32 textWidth3984; + u32 input3984; + u32 confirmKeys3984; + u16 widths[10], heights[10], x[10], y[4]; + struct Sprite3984 icons[9], labels[9]; + struct Sprite3984 cursor; + u8 panel[0x34], pair[4], buffer[0x21], rows3984[2][0x21]; + u16 lastWidth; + u16 lastHeight; + union Bg3984 bg; + u16 state; + u16 selection; + u16 current; + u16 next; + u16 index; + u16 substate; + u32 prev; + s32 cursorX; + s32 cursorY; + u8 *handle; + u8 *text; + u32 status; + s32 item; + s32 phase; + u32 count; + u32 oldCount; + u16 timer; + s32 targetX; + s32 targetY; + s32 offsetX; + s32 offsetY; + s32 newX; + s32 newY; + u16 *var_r1_8; + s32 temp_r0; + s32 temp_r1; + s32 temp_r1_6; + s32 temp_r2; + s32 temp_r3_2; + s32 temp_r3_4; + s32 temp_r3_5; + s32 temp_r4_11; + s32 temp_r4_15; + s32 temp_r4_16; + s32 temp_r4_18; + s32 temp_r4_9; + s32 temp_r6_6; + s32 var_r0_2; + s32 var_r0_7; + s32 var_r1_7; + s32 var_r3; + s32 var_r3_4; + s32 var_r5; + u16 var_r6; + u16 *temp_r4_10; + u16 *temp_r5_14; + u16 *temp_r5_3; + u16 *temp_r5_4; + u16 *temp_r5_5; + u16 *temp_r5_6; + u16 *var_r4_2; + u16 temp_r0_12; + u16 temp_r0_13; + u16 temp_r0_14; + u16 temp_r0_19; + u16 temp_r0_4; + u16 temp_r0_5; + u16 temp_r1_5; + u16 temp_r4_14; + u16 temp_r4_22; + u32 temp_r5_10; + u16 var_r0_10; + u16 var_r0_11; + u16 var_r0_12; + u16 var_r0_13; + u16 var_r0_14; + u16 var_r0_8; + u16 var_r0_9; + u16 var_r1_6; + u16 var_r2_3; + u16 var_r9; + u32 temp_r0_18; + u32 temp_r0_6; + u32 temp_r0_7; + u32 temp_r0_8; + u32 temp_r0_9; + u32 temp_r1_3; + u32 temp_r4_12; + u32 temp_r4_13; + u32 temp_r4_20; + u32 temp_r4_21; + u32 temp_r4_2; + u32 temp_r5_9; + u32 temp_r6; + u32 temp_r6_7; + u32 temp_r6_8; + u32 var_r3_3; + u32 var_r8; + u8 *temp_r0_15; + u8 *temp_r1_4; + u8 *temp_r1_7; + u8 *temp_r2_4; + u8 *temp_r2_5; + u8 *temp_r2_6; + u8 *temp_r3; + u8 *temp_r3_3; + u8 *temp_r4_19; + u8 *temp_r4_7; + u8 *temp_r5; + u8 *temp_r5_13; + u8 *temp_r5_2; + u8 *temp_r6_3; + u8 *temp_r6_4; + u8 *temp_r6_5; + u8 *var_r0_6; + u8 *var_r2_2; + u8 *var_r3_2; + u8 *var_r5_3; + u8 *nm; + u8 *var_r7; + u32 temp_r0_10; + u32 temp_r0_11; + u8 temp_r0_16; + u8 temp_r0_17; + u8 temp_r0_22; + u8 var_r1_2; + void *temp_r0_3; + u32 vramBase3984 = 0x06000000; + u32 zeroElse3984 = 0; + u32 yTable3984 = (u32)&gUnk_08366E0E; + + memcpy(&pair[0], &gUnk_080B99D4, 2); + memcpy(&cursor, sub_080653CC(), 0x34); + switch (gUnk_03003470) { + case 0: sub_08065158(panel, 0x50002, 0, 0x80000000, 0); break; + case 1: sub_08065158(panel, 0x5015B, 0, 0x80000000, 0); break; + case 2: sub_08065158(panel, 0x5015C, 0, 0x80000000, 0); break; + case 3: sub_08065158(panel, 0x5015D, 0, 0x80000000, 0); break; + case 4: sub_08065158(panel, 0x5015E, 0, 0x80000000, 0); break; + } + sub_0801A6D4(0); + reg3984.v0 = setupZero3984 = 0; + reg3984.h0 = setupZero3984; + reg3984.v1 = setupZero3984; + reg3984.h1 = setupZero3984; + reg3984.v2 = setupZero3984; + reg3984.h2 = setupZero3984; + reg3984.v3 = setupZero3984; + reg3984.h3 = setupZero3984; + sub_0801A664(2, 0x11); + bg.bits.cnt = 0x1B00; + sub_08000AA8(1U, &bg.half); + bg.half = 0x1F03; + sub_08000AA8(3U, &bg.half); + { + u32 vramC7 = 0x06000000; + register u32 paletteC7 asm("r5") = 0xF; + sub_0800BCDC(0x15, 3, vramC7, 0U, paletteC7); + sub_0800BCDC(0x16, 2, vramC7, 0U, paletteC7); + sub_0800B650(0x3B, 0x1B, vramC7, 0U, paletteC7); + sub_0800B650(0x40000017, 0x1A, vramC7, 0U, paletteC7); + sub_0800B650(0x12, 0x19, vramC7, 0U, paletteC7); + sub_0800B650(0x18, 0x18, vramC7, 0U, paletteC7); + } + sub_0800903C(4, 8, 1, 8, 0x10, setupZero3984); + sub_080009F8(0x200, 0, 1); + handle = ((u8 *(*)(s32))sub_08007290)(0x10023); + var_r6 = 0; + do { + temp_r5 = (u8 *)&icons[var_r6]; + sub_08065158(temp_r5, var_r6 + 0x5006B, 0, 1, setupZero3984); + sub_08065158((u8 *)&labels[var_r6], resource3984[var_r6].id, 0, 1, setupZero3984); + M2C_FIELD(temp_r5, s8 *, 0x1C) = var_r6; + temp_r1 = var_r6 * 2; + x[var_r6] = setupZero3984; + { + u32 initWidthC8 = (u32)widths; + initWidthC8 += temp_r1; + *(u16 *)initWidthC8 = setupZero3984; + } + heights[var_r6] = setupZero3984; + var_r6 = (u16) (var_r6 + 1); + } while ((u32) var_r6 <= 8U); + sub_080003F0(); + sub_080003F0(); + sub_0801AB50(3); + ((u8 *(*)(s32))sub_08007290)(0x140441); + substate = 0; + index = 0; + state = 0; + selection = 0xA; + prev = 8; + timer = 0; + lastHeight = (u16) state; + lastWidth = (u16) state; + temp_r3 = ((u8 *)&y[2]); + M2C_FIELD(temp_r3, u16 *, 0) = (u16) state; + temp_r5_2 = ((u8 *)&y[0]); + M2C_FIELD(temp_r5_2, u16 *, 0) = (u16) state; + M2C_FIELD(temp_r3, u16 *, 2) = (u16) state; + M2C_FIELD(temp_r5_2, u16 *, 2) = (u16) state; + current = 0; + cursorX = 0; + cursorY = 0; + phase = 0; + item = 0; + status = 0; + oldCount = 0; + newX = (s32) M2C_FIELD(((u8 *)&gUnk_08366E0C), u16 *, 0); + newY = (s32) M2C_FIELD(((u8 *)&gUnk_08366E0C), u16 *, 2); + targetX = (s32) M2C_FIELD(((u8 *)&gUnk_08366E0C), u16 *, 0); + targetY = newY; + sub_08058688(0x71); + while (1) { + temp_r0 = sub_0801AAE0(); + if (temp_r0 == 0) { + keys3984 = (u16) temp_r0; + } + sub_08000AF0(0x19U, cursor.data + 0x120, 1U); + temp_r4_2 = timer; + if (temp_r4_2 > 6U) goto block_374; + switch (temp_r4_2) { /* switch 2 */ + case 0: /* switch 2 */ + if (keys3984 == 1) { + sub_0805865C(0xF); + reg3984.h0 = 0; + timer = 1; + sub_0801A664(0, 5); + sub_08001108(0x1FU); + sub_0800115C((u32) sub_080066A8); + bg.half = 0x1B00; + sub_08000AA8(1U, &bg.half); + sub_080009C0(0x200, 0, 1); + sub_08000D8C(); + } else { + var_r7 = ((u8 *(*)(s32))sub_08007290)(0x140441); + var_r7 += 2; + rows3984[0][0] = 0; + rows3984[1][0] = 0; + var_r8 = 0; + for (; var_r8 <= 1U; var_r8++) { + var_r6 = 0; + var_r1_2 = *var_r7; + if (var_r1_2 != 0xFD) { + do { + { u8 *baseC13 = (u8 *)rows3984; u32 offC13 = var_r8 * 0x21; *(baseC13 + (var_r6 + offC13)) = var_r1_2; } + if (({ u32 cmpC13; asm("" : "=l"(cmpC13) : "0"(var_r1_2)); cmpC13; }) == 0xFF) { + var_r7++; + break; + } + var_r6++; + var_r7++; + var_r1_2 = *var_r7; + } while (var_r1_2 != 0xFD); + } + rows3984[var_r8][var_r6] = 0xFD; + if (var_r6 == 0) + break; + temp_r4_7 = rows3984[var_r8]; + sub_0801A3D0(temp_r4_7, (u16)(0xF - ((u32)sub_0801A638(temp_r4_7) >> 1)), (u16)(var_r8 * 2)); + if (*var_r7 == 0xFD) + break; + } + if (status++ <= 0x1DU) { + item = 1; + } else if ((u32) status > 0x1DU) { + item = 0; + } + if ((u32) status > 0x28U) { + status = 0; + } + if (item == 0) { + + } else { + sub_0801A3D0(&pair[0], 0x1CU, (u16) (var_r8 * 2)); + } + } + goto block_374; + case 1: /* switch 2 */ + switch (state) { /* menu cursor */ + case 0: + if ((u16)(gUnk_03001308 & 0x10)) { + state = 1; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x60)) { + state = 6; + if (arg1 != 0) + state = 8; + widths[state] = heights[state] = 0; + sub_0805865C(0xE); + } else if ((u16)(gUnk_03001308 & 0x80)) { + state = 4; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } + break; + case 1: + if ((u16)(gUnk_03001308 & 0x10)) { + state = 5; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x20)) { + state = 0; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x80)) { + state = 7; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } + break; + case 2: + if ((u16)(gUnk_03001308 & 0x50)) { + state = 6; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x80)) { + state = 3; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } + break; + case 3: + if ((u16)(gUnk_03001308 & 0x10)) { + state = 4; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x20)) { + state = 2; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x40)) { + state = 4; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } + break; + case 4: + if ((u16)(gUnk_03001308 & 0x10)) { + state = 0; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x20)) { + state = 2; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x40)) { + state = 6; + if (arg1 != 0) + state = 8; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x80)) { + state = 3; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } + break; + case 5: + if ((u16)(gUnk_03001308 & 0x20)) { + state = 1; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x80)) { + state = 7; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } + break; + case 6: + if ((u16)(gUnk_03001308 & 0x20)) { + state = 2; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x10)) { + state = arg1 != 0 ? 8 : 0; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x80)) { + state = 4; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } + break; + case 7: + if ((u16)(gUnk_03001308 & 0x20)) { + state = 1; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x40)) { + state = 5; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } + break; + case 8: + if ((u16)(gUnk_03001308 & 0x10)) { + state = 0; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x20)) { + state = 6; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } else if ((u16)(gUnk_03001308 & 0x80)) { + state = 4; + sub_0805865C(0xE); + widths[state] = heights[state] = 0; + } + break; + } + confirmKeys3984 = keys3984; + if (confirmKeys3984 == 1) { + sub_0805865C(0xF); + selectionZeroC6 = 0; + M2C_FIELD(arg0, u8 *, 1) = (u8) state; + reg3984.h0 = selectionZeroC6; + gUnk_03003474 = selectionZeroC6; + sub_0801A664(0, 0xA); + timer = 3; + var_r7 = ((u8 *(*)(s32))sub_08007290)((state + 0x454) | 0x140000); + var_r7 += 2; + var_r6 = 0; + firstName3984 = *var_r7; + var_r5_3 = arg0 + 0x10; + if (firstName3984 == 0xFF) { + M2C_FIELD(arg0, u8 *, 0x10) = 0xFD; + } else { +loop_107: + var_r5_3[var_r6] = *(var_r7 + var_r6); + var_r6 += 1; + if ((u32) var_r6 <= 8U) { + if (*(var_r7 + var_r6) == 0xFF) { + var_r5_3[var_r6] = 0xFD; + } else { + goto loop_107; + } + } + } + var_r5_3[(nextChar03984 = var_r6 + 1)] = nameZero3984 = 0; + asm("" : : "r"(nameZero3984)); + selection = 0xA; + sub_08000E48(); + sub_080009F8(0x200, 0, 1); + if (state != 8) { + + } else { + sub_0801A664(0, 2); + reg3984.h0 = nameZero3984; + var_r9 = (u16) sub_0801A638(var_r5_3); + next = var_r9; + current = 0; + bg.half = 0xD800; + sub_08000AA8(1U, &bg.half); + sub_080009C0(0x200, 0, 1); + sub_0800903C(0xC, 0x28, 1, 8, 6, (s32) current); + sub_08006550(0x10, 9, 0x32); + timer = 5; + } + goto block_374; + } else if (confirmKeys3984 == 2) { + sub_080009F8(0x200, 0, 1); + sub_0805865C(0x10); + sub_0801A664(0, 0xA); + sub_0801ABE8(6); + while (sub_0801AAE0() == 0) { + sub_080003F0(); + } + sub_08000E48(); + sub_080003F0(); + sub_080003F0(); + ((void (*)(unsigned long long))sub_08000420)(0x25A112EBFULL); + goto epilogue3984; + } else { + var_r7 = ((u8 *(*)(s32))sub_08007290)((state + 0x454) | 0x140000); + var_r7 += 2; + { + u32 titleWidthC8; + u32 titleBaseC8; + s32 titleIndexC8; + u16 *titleXC8; + u16 *titleYC8; + s32 titleXValueC8; + titleWidthC8 = sub_0801A638(var_r7); + titleBaseC8 = (u32)&gUnk_08366E0C; + titleIndexC8 = state * 4; + titleXC8 = (u16 *)(titleIndexC8 + titleBaseC8); + titleXValueC8 = *titleXC8 - titleWidthC8 * 4; + titleBaseC8 += 2; + titleIndexC8 = titleIndexC8 + titleBaseC8; + titleYC8 = (u16 *)titleIndexC8; + ((void (*)(const u8 *, s32, s32))sub_0801A764)(var_r7, titleXValueC8, *titleYC8 - 0x28); + newX = *titleXC8; + newY = *titleYC8; + } + temp_r4_11 = state * 2; + var_r7 = ((u8 *(*)(s32))sub_08007290)((temp_r4_11 + 0x42F) | 0x140000); + var_r7 += 2; + sub_0801A3D0(var_r7, (u16) (0xF - ((u32) sub_0801A638(var_r7) >> 1)), 1U); + temp_r1_3 = substate; + substate = (u32) (u16) (temp_r1_3 + 1); + if ((u32) prev <= temp_r1_3) { + substate = 0; + temp_r0_5 = index + 1; + index = (u32) temp_r0_5; + if ((u32) temp_r0_5 > 7U) { + index = 0; + prev = sub_080008C8(); + prev &= 7; + prev += 1; + } + } + if (substate == 0) { + { u32 off; sub_08001348(handle + ((index << 7) + (off = 0x7000)), (void *)(vramBase3984 + off), 0x80U); } + } + temp_r5_9 = newX - targetX; + if (selection != state) { + count = 0; + phase = 0; + status = 0; + oldCount = 0; + gUnk_03003474 = (s32) status; + var_r6 = 0; + do { + (&buffer[0])[var_r6] = 0xFD; + var_r6 += 1; + } while ((u32) var_r6 <= 0x1FU); + text = ((u8 *(*)(s32))sub_08007290)((temp_r4_11 + 0x430) | 0x140000); + text += 2; + selection = state; + } + temp_r0_6 = status; + status = temp_r0_6 + 1; + if (temp_r0_6 > 2U) { + status = 0; + temp_r1_4 = text; + if (*temp_r1_4 == 0xFF) { + text = temp_r1_4 + 1; + } + temp_r3_3 = text; + if (*temp_r3_3 == 0xFE) { + text = temp_r3_3 + 3; + } + if (*text == 0xFD) { + text = ((u8 *(*)(s32))sub_08007290)((temp_r4_11 + 0x430) | 0x140000); + text += 2; + } + temp_r4_12 = oldCount; + temp_r6_3 = text; + (&buffer[0])[temp_r4_12] = *temp_r6_3; + text = temp_r6_3 + 1; + temp_r4_13 = temp_r4_12 + 1; + oldCount = temp_r4_13; + if (temp_r4_13 > 0x1FU) { + oldCount = 0; + buffer[0x20] = 0xFD; + phase = 1; + } + } + if (phase != 0) { + gUnk_03003474 += 1; + temp_r0_7 = count + 1; + count = temp_r0_7; + if (temp_r0_7 > 7U) { + count = 0; + status = 0xA; + } else { + status = 0; + } + } + sub_0801A3D0(&buffer[0], 0U, 4U); + targetX = targetX + ((s32) (temp_r5_9 + (temp_r5_9 >> 0x1F)) >> 1); + temp_r3_4 = targetY; + temp_r0_8 = newY - temp_r3_4; + targetY = temp_r3_4 + ((s32) (temp_r0_8 + (temp_r0_8 >> 0x1F)) >> 1); + if (__builtin_abs(newX - targetX) <= 1) { + targetX = newX; + } + if (__builtin_abs(newY - targetY) <= 1) { + targetY = newY; + } + if (state == 7) { + sub_08065230(&cursor, targetX - 0xA, targetY - 4, 0x15U, 0); + } else { + sub_08065230(&cursor, targetX, targetY, 0xBU, 0); + } + goto block_374; + } + break; + case 2: /* switch 2 */ + if (keys3984 == 1) { + sub_0805865C(0xF); + reg3984.h0 = 0; + timer = 3; + sub_0801A664(0, 5); + } else { + temp_r0_9 = status; + status = temp_r0_9 + 1; + if (temp_r0_9 <= 0x1DU) { + item = 1; + } else if ((u32) status > 0x1DU) { + item = 0; + } + if ((u32) status > 0x28U) { + status = 0; + } + if (item == 0) { + + } else { + var_r0_6 = &pair[0]; + var_r1_6 = 0x1C; + goto block_206; + } + } + goto block_374; + case 3: /* switch 2 */ + temp_r5_10 = 0x20 & gUnk_03001308; + if (temp_r5_10 != 0) { + cursorX = 5; + sub_0805865C(0xE); + temp_r6_4 = arg0; + temp_r0_10 = M2C_FIELD(temp_r6_4, u8 *, 2) - 1; + M2C_FIELD(temp_r6_4, u8 *, 2) = temp_r0_10; + if (!(temp_r0_10 & 0x80)) { + + } else { + M2C_FIELD(temp_r6_4, u8 *, 2) = 9U; + } + goto block_175; + } + temp_r4_14 = 0x10 & gUnk_03001308; + if (temp_r4_14 != 0) { + cursorY = 5; + sub_0805865C(0xE); + temp_r6_5 = arg0; + temp_r0_11 = M2C_FIELD(temp_r6_5, u8 *, 2) + 1; + M2C_FIELD(temp_r6_5, u8 *, 2) = temp_r0_11; + if ((u32) (u8) temp_r0_11 > 9U) { + M2C_FIELD(temp_r6_5, u8 *, 2) = (u8) temp_r5_10; + } + goto block_175; + } + if (keys3984 == 1) { + sub_0805865C(0xF); + sub_0801A664(0, 2); + reg3984.h0 = temp_r4_14; + asm("" : "=r"(var_r9) : "0"(0)); + temp_r0_12 = (u16) sub_0801A638(arg0 + 0x10); + next = (u32) temp_r0_12; + if ((u32) temp_r0_12 > 7U) { + next = 7; + } + bg.half = 0xD800; + sub_08000AA8(1U, &bg.half); + sub_080009C0(0x200, 0, 1); + sub_0800903C(0xC, 0x28, 1, 8, 6, var_r9); + sub_08006550(0x10, 9, 0x32); + timer = 5; + current = var_r9; + } else { + if (keys3984 == 2) { + sub_0805865C(0x10); + timer = 0; + M2C_FIELD(arg0, s8 *, 2) = 0; + } +block_175: + var_r7 = ((u8 *(*)(s32))sub_08007290)((M2C_FIELD(arg0, u8 *, 2) + 0x4C5) | 0x140000); + if (state != 2) { + u32 menuIndexC9; + u32 menuLanguageC9; + temp_r5_13 = var_r7 + 2; + { + u32 titleWidthC9; + u32 titleBaseC9; + u32 titleIndexC9; + u32 titleXValueC9; + titleWidthC9 = sub_0801A638(temp_r5_13); + titleBaseC9 = (u32)&gUnk_08366E0C; + titleIndexC9 = state * 4; + titleXValueC9 = titleIndexC9 + titleBaseC9; + titleXValueC9 = *(u16 *)titleXValueC9; + titleXValueC9 -= titleWidthC9 * 4; + titleBaseC9 += 2; + titleBaseC9 = titleIndexC9 + titleBaseC9; + titleBaseC9 = *(u16 *)titleBaseC9; + titleBaseC9 -= 0x28; + ((void (*)(const u8 *, s32, s32))sub_0801A764)(temp_r5_13, titleXValueC9, titleBaseC9); + menuLanguageC9 = gUnk_03003470; + menuIndexC9 = titleIndexC9; + } + switch (menuLanguageC9) { /* switch 5 */ + case 0: + offsetX = 0x23; + offsetY = 0x1D; + break; + case 1: + offsetX = 0x2B; + offsetY = 0x25; + break; + case 2: + offsetX = 0x23; + offsetY = 0x1D; + break; + case 3: + offsetX = 0x2B; + offsetY = 0x25; + break; + case 4: + offsetX = 0x23; + offsetY = 0x1D; + break; + } + if ((u32) M2C_FIELD(arg0, u8 *, 2) <= 8U) { + var_r7 = (u8 *)&cursor; + var_r4_2 = (u16 *)&gUnk_08366E0C; + temp_r5_14 = (u16 *)(menuIndexC9 + (u8 *)var_r4_2); + var_r1_7 = *temp_r5_14; + var_r1_7 -= offsetX; + var_r1_7 -= cursorX; + var_r4_2 = (u16 *)((u32)var_r4_2 + 2); + var_r4_2 = (u16 *)(menuIndexC9 + (u32)var_r4_2); + sub_08065230(var_r7, var_r1_7, *var_r4_2 - 0x20, 3U, 2); + var_r1_7 = *temp_r5_14; + var_r1_7 += offsetY; + var_r1_7 += cursorY; + } else { + s32 selectorStepC10; + var_r7 = (u8 *)&cursor; + var_r4_2 = (u16 *)&gUnk_08366E0C; + temp_r5_14 = (u16 *)(menuIndexC9 + (u8 *)var_r4_2); + var_r1_7 = *temp_r5_14; + var_r1_7 -= offsetX; + var_r1_7 -= (selectorStepC10 = cursorX + 5); + var_r4_2 = (u16 *)((u32)var_r4_2 + 2); + var_r4_2 = (u16 *)(menuIndexC9 + (u32)var_r4_2); + sub_08065230(var_r7, var_r1_7, *var_r4_2 - 0x20, 3U, 2); + var_r1_7 = *temp_r5_14; + var_r1_7 += offsetY; + { + selectorStepC10 = cursorY + 5; + var_r1_7 += selectorStepC10; + } + } + goto block_198; + } else { + switch (gUnk_03003470) { /* switch 6 */ + case 0: /* switch 6 */ + offsetX = 0x23; + offsetY = 0x18; + break; + case 1: /* switch 6 */ + offsetX = 0x2B; + offsetY = 0x28; + break; + case 2: /* switch 6 */ + offsetX = 0x23; + offsetY = 0x18; + break; + case 3: /* switch 6 */ + offsetX = 0x2B; + offsetY = 0x20; + break; + case 4: /* switch 6 */ + offsetX = 0x23; + offsetY = 0x18; + break; + } + if ((u32) M2C_FIELD(arg0, u8 *, 2) <= 8U) { + { + register u8 *shortTextC10 asm("r0"); + u32 shortBaseC10; + register u32 shortIndexC10 asm("r4"); + register s32 shortXC10 asm("r1"); + shortTextC10 = var_r7 + 2; + shortBaseC10 = (u32)&gUnk_08366E0C; + shortIndexC10 = state * 4; + temp_r5_14 = (u16 *)(shortIndexC10 + shortBaseC10); + shortXC10 = *temp_r5_14 - 9; + shortBaseC10 += 2; + var_r4_2 = (u16 *)(shortIndexC10 + shortBaseC10); + ((void (*)(const u8 *, s32, s32))sub_0801A764)(shortTextC10, shortXC10, *var_r4_2 - 0x28); + } + var_r7 = (u8 *)&cursor; + sub_08065230(var_r7, *temp_r5_14 - (drawOffset3984 = cursorX + 0x10), *var_r4_2 - 0x20, 3U, 2); + var_r1_7 = offsetY + 0x18; + asm("" : : "r"(var_r1_7)); + { register u32 heightC11 asm("r5") = *temp_r5_14; var_r1_7 += heightC11; } + var_r1_7 += cursorY; +block_198: + sub_08065230(var_r7, var_r1_7, *var_r4_2 - 0x20, 3U, 1); + goto after198; + } + var_r7 = var_r7 + 2; + textWidth3984 = sub_0801A638(var_r7); + { + u32 longBaseC9; + u32 longStateC9; + register u32 longIndexC9 asm("r4"); + s32 longXC9; + longBaseC9 = (u32)&gUnk_08366E0C; + longStateC9 = state; + longIndexC9 = longStateC9 * 4; + temp_r5_14 = (u16 *)(longIndexC9 + longBaseC9); + longXC9 = *temp_r5_14 - (drawOffset3984 = textWidth3984 * 4 - 0x18); + longBaseC9 += 2; + var_r4_2 = (u16 *)(longIndexC9 + longBaseC9); + ((void (*)(const u8 *, s32, s32))sub_0801A764)(var_r7, longXC9, *var_r4_2 - 0x28); + } + var_r7 = (u8 *)&cursor; + sub_08065230(var_r7, *temp_r5_14 - (drawOffset3984 = cursorX + 0x10), *var_r4_2 - 0x20, 3U, 2); + var_r7 = (u8 *)&cursor; + sub_08065230(var_r7, (drawOffset3984 = offsetY + 0x18) + *temp_r5_14 + (cursorYStep3984 = cursorY + 9), *var_r4_2 - 0x20, 3U, 1); + } +after198: + if (!(gUnk_03002344 & 3)) { + temp_r6_6 = cursorX; + if (temp_r6_6 != 0) { + cursorX = (s32) (u16) (temp_r6_6 - 1); + } + temp_r3_5 = cursorY; + if (temp_r3_5 != 0) { + cursorY = (s32) (u16) (temp_r3_5 - 1); + } + } + var_r7 = ((u8 *(*)(s32))sub_08007290)(0x140442); + var_r0_6 = var_r7 + 2; + var_r1_6 = 0; +block_206: + sub_0801A3D0(var_r0_6, var_r1_6, 0U); + } + goto block_374; + case 4: /* switch 2 */ + if (keys3984 & 0x20) { + if (current != 0) + sub_0805865C(0xC6); + current = 0; + } else if (keys3984 & 0x10) { + if (current == 0) + sub_0805865C(0xC7); + current = 1; + } else if (keys3984 == 1) { + sub_0805865C(0xF); + timer = 5; + if (current == 0) + timer = 6; + sub_0801A664(0x12, 2); + goto block_374; + } else if (keys3984 == 2) { + sub_0805865C(0x10); + timer = 5; + sub_0801A664(0x12, 2); + goto block_374; + } + sub_08065370(&panel[0], 4U, (s32) &y[0], (s32) &y[2], 1); + sub_08065370(&panel[0], 5U, (s32) &y[1], (s32) &y[3], 1); + if (current != 0) { + sub_08065230(&panel[0], 0xD2, 0x8E, 9U, 0); + sub_08065264(&panel[0], 0xE2, 0x8E, 5, y[1]); + sub_08065230(&panel[0], 0xC2, 0x8E, 4U, y[0]); + } else { + sub_08065230(&panel[0], 0xD2, 0x8E, 8U, current); + sub_08065230(&panel[0], 0xE2, 0x8E, 5U, y[1]); + sub_08065264(&panel[0], 0xC2, 0x8E, 4, y[0]); + } + sub_0801A3D0(((u8 *(*)(s32))sub_08007290)(0x140443) + 2, 2U, 0x12U); + ((void (*)(const u8 *, s32, s32))sub_0801A764)(arg0 + 0x10, 0x58U, 0x10U); + goto block_374; + case 5: /* switch 2 */ + sub_08000C08(8, 2); + if (keys3984 & 0x100) { + nm = arg0 + 0x10; + if (var_r9 <= 6) { + /* Keep the test and store addresses separate through GCSE. */ + if (next == var_r9 || nm[-(-(u32)var_r9 + 1) + 1] == 0xFD) { + nm[var_r9] = 0x51; + nm[(nextChar13984 = var_r9 + 1)] = 0xFD; + var_r9++; + next = var_r9; + } else { + var_r9++; + } + sub_0805865C(0xE); + } + } else if (keys3984 & 0x200) { + nm = arg0 + 0x10; + if (var_r9 != 0) { + var_r9--; + sub_0805865C(0xE); + } + } else if (gUnk_03001308 & 0x40) { + sub_0805865C(0x62); + nm = arg0 + 0x10; + switch (language) { + case 0: + case 1: + if (current < 20) + current += 80; + else + current -= 20; + break; + case 2: + if (current < 24) + current += 120; + else + current -= 24; + break; + } + } else if (gUnk_03001308 & 0x80) { + sub_0805865C(0x62); + nm = arg0 + 0x10; + switch (language) { + case 0: + case 1: + if (current >= 80) + current -= 80; + else + current += 20; + break; + case 2: + if (current >= 120) + current -= 120; + else + current += 24; + break; + } + } else if (gUnk_03001308 & 0x10) { + sub_0805865C(0x62); + nm = arg0 + 0x10; + switch (language) { + case 0: + case 1: + if ((u16)(current % 20) == 19) + current -= 19; + else + current++; + break; + case 2: + if ((u16)(current % 24) > 22) + current -= 23; + else + current++; + break; + } + } else if ((u16)(gUnk_03001308 & 0x20)) { + sub_0805865C(0x62); + nm = arg0 + 0x10; + switch (language) { + case 0: + case 1: + if ((u16)(current % 20) == 0) + current += 19; + else + current--; + break; + case 2: + if ((u16)(current % 24) == 0) + current += 23; + else + current--; + break; + } + } else if (keys3984 == 1) { + sub_0805865C(0xF); + switch (language) { + case 0: + { u8 *p = arg0 + 0x10; + p[var_r9] = gUnk_08366E34[current]; } + break; + case 1: + { u8 *p = arg0 + 0x10; + p[var_r9] = gUnk_08366EFC[current]; } + break; + case 2: + { u8 *p = arg0 + 0x10; + p[var_r9] = gUnk_08366FC4[current]; } + break; + } + nm = arg0 + 0x10; + if (var_r9 <= 6) { + var_r9++; + if (var_r9 > next) { + nm[var_r9] = 0xFD; + next = var_r9; + } + } else { + nm[(nextChar23984 = var_r9 + 1)] = 0xFD; + } + } else if (keys3984 == 2) { + sub_0805865C(0x10); + if (var_r9 == next) { + u8 *name = arg0 + 0x10; + name[var_r9] = 0xFD; + name[(nextChar33984 = var_r9 + 1)] = 0; + var_r9--; + deleteMaskC6 = var_r9 & 0x8000; + nm = name; + if (deleteMaskC6) { + var_r9 = 0; + if (arg0[0x10] == 0xFD) { + timer = 3; + sub_080009F8(0x200, 0, 1); + sub_0800903C(4, 8, 1, 8, 0x10, var_r9); + sub_08006544(); + if (arg0[1] == 8) { + sub_0801A664(0, 2); + timer = 0; + sub_08000C08(0x10, 8); + } + } + } + next = var_r9; + } else { + u8 *name = arg0 + 0x10; + u8 c = name[var_r9]; + nm = name; + if (c == 0x51) { + var_r9--; + if (var_r9 & 0x8000) { + timer = 3; + sub_080009F8(0x200, 0, 1); + sub_0800903C(4, 8, 1, 8, 0x10, 0); + sub_08006544(); + if (arg0[1] == 8) { + sub_0801A664(0, 2); + timer = 0; + sub_08000C08(0x10, 8); + } + var_r9 = 0; + } + } else { + nm[var_r9] = 0x51; + if (var_r9 == 0) { + timer = 3; + sub_080009F8(0x200, 0, 1); + sub_0800903C(4, 8, 1, 8, 0x10, var_r9); + sub_08006544(); + if (arg0[1] == 8) { + sub_0801A664(0, 2); + timer = 0; + sub_08000C08(0x10, 8); + } + } + } + } + } else { + nm = arg0 + 0x10; + if (keys3984 == 8) { + if (sub_0801A638(nm) != 0) { + var_r3_3 = 0; + var_r6 = 0; + if (arg0[0x10] != 0x51) { + var_r3_3 = arg0[0x10] != 0xFD; + } else { + loop8_3984: + var_r6++; + if (var_r6 <= 7) { + u8 *q = arg0 + 0x10; + temp_r0_17 = q[var_r6]; + if (temp_r0_17 == 0x51) + goto loop8_3984; + if (temp_r0_17 != 0xFD) + var_r3_3++; + } + } + if (({ register u32 flagC11 asm("r3") = var_r3_3; asm("" : "=r"(flagC11) : "0"(flagC11)); flagC11; }) != 0) { + sub_08000C08(0x10, 8); + timer = 4; + current = 0; + sub_0805865C(0xDC); + } else { + sub_0805865C(0x61); + } + } else { + sub_0805865C(0x61); + } + } + } + switch (language) { /* switch 8; irregular */ + case 0: /* switch 8 */ + reg3984.h1 = language; + reg3984.v1 = language; + break; + case 1: /* switch 8 */ + reg3984.h1 = 0x100; + reg3984.v1 = 0; + break; + case 2: /* switch 8 */ + reg3984.h1 = 0; + reg3984.v1 = 0x100; + break; + } + switch (language) { + case 0: + case 1: + temp_r0_19 = (u16) ((u32) current % 20U); + newX = (temp_r0_19 * 8) + (keyboardGap3984 = (((u32) ((temp_r0_19 / 5U) << 0x10) >> 0xC) + 0xF)); + newY = ((u32) (((u32) current / 20U) << 0x10) >> 0xC) + 0x30; + break; + case 2: + temp_r0_18 = ((u32) current % 24U) << 0x10; + newX = (temp_r0_18 >> 0xD) + (keyboardGap3984 = (((temp_r0_18 >> 0x14) * 0x10) + 0x10)); + newY = ((u32) (((u32) current / 24U) << 0x10) >> 0xC) + 0x30; + break; + } + ((void (*)(const u8 *, s32, s32))sub_0801A764)(arg0 + 0x10, 0x58U, 0x10U); + sub_08065370(&cursor, 5U, (s32) &lastWidth, (s32) &lastHeight, 1); + sub_080659BC(&cursor, (var_r9 * 8) + 0x58, 0x18, 5U, (s32) lastWidth, 1); + targetX += (newX - targetX) / 2; + targetY += (newY - targetY) / 2; + if (__builtin_abs(newX - targetX) <= 1) { + targetX = newX; + } + if (__builtin_abs(newY - targetY) <= 1) { + targetY = newY; + } + sub_08065230(&cursor, targetX, targetY, 0x10U, 0); + goto block_374; + case 6: /* switch 2 */ + var_r3_4 = 0; + var_r6 = 8; + temp_r2_6 = arg0 + 0x10; + cleanupZero3984 = 0; + cleanupMask3984 = 0x8000; + cleanupEnd3984 = 0xFD; +loop_363: + temp_r1_7 = &temp_r2_6[var_r6]; + temp_r0_22 = M2C_FIELD(temp_r1_7, u8 *, 0); + if (temp_r0_22 == 0xFD) { var_r3_4 = 1; goto block_368; } @@ -2484,6 +3775,7 @@ void sub_08003984(u8 *arg0, s32 arg1) { epilogue3984: return; } +#endif struct FadeColor5A24 { u32 red:5; u32 green:5; u32 blue:5; }; struct FadeDest5A24 { u16 red:5; u16 green:5; u16 blue:5; }; extern void fadeCopy5A24(const void *, void *, u32) asm("CpuSet"); @@ -2548,36 +3840,253 @@ void sub_08005A24(u32 range, s32 percent) dest = (struct FadeDest5A24 *)((u8 *)dest + 2); source = (struct FadeColor5A24 *)((u8 *)source + 2); } - sub_08000B38(); - } + sub_08000B38(); + } + sub_080003F0(); + sub_08001538((s32)backup); +} +extern u16 pressed5B asm("gUnk_03001324"); +extern void finish5B(unsigned long long) asm("sub_08000420"); +struct Menu5B { u8 pad[5], f5, f6, f7; }; +struct Task5B {u32 f0,f4,f8,fC,f10,f14,f18,f1C,f20,f24;}; +extern struct Task5B task5B asm("gUnk_03002840"); +extern u16 data5B asm("gUnk_080B99D4"); +extern u8 *resource5B(u32) asm("sub_08007290"); +extern s32 sprite5B(void *,u32,s32,s32,s32) asm("sub_08065158"); +extern void text5B(u8 *,u16,u16) asm("sub_0801A3D0"); +extern void copy5B(void *,const void *,u32) asm("memcpy"); +extern void mode5B(s32) asm("sub_0801A6D4"); +extern s32 fade5B(s32,s32) asm("sub_0801A664"); +extern void reg5B(s32,s32,s32) asm("sub_080009F8"); +extern void start5B(s32) asm("sub_0801AB50"); +extern void callback5B(void) asm("sub_08002B70"); +extern u16 keys5B asm("gUnk_03001308"); +extern void sub_080066A8(void); +void menu5B(struct Menu5B *) asm("sub_08005B88"); +/* [RunTwoChoiceSaveMenu] Initializes sprites50002/50006 and background scroll, installs temporary display + * callbacks, suppresses pressed keys during transition, streams resource text through a32-byte scrolling + * buffer, and animates a cursor. Up/down selects0/1. Confirming1 optionally opens a left/right subchoice when + * record byte+5 is nonzero; otherwise forces side0. Normal exit writes choice to record+6 and side to+7 then + * signals0x25A112EBF. Base cancel restores callbacks and restarts02B70 using unchecked0x1000 allocation + * without signaling or updating record. Subchoice confirm restores callbacks; direct base confirmation does + * not locally restore them. */ +#ifdef REGION_USA +void menu5B(struct Menu5B *arg) { + u16 sp4[2], sp8[2]; + u8 spC[0x34], sp40[0x34], sp74[4]; + TextChar sp78[33]; + s32 sel, prev; + u32 timer; + s32 scroll; + u32 count, pos; + s32 x, y, tx, ty; + u32 vblank; + u8 vcount; + s32 state; + u8 side; + s32 dy, dx; + TextChar *p, *d; register TextChar *buf asm("r4"); + u32 i, j, n, row; + s32 r, d1, d2; + + copy5B(sp74, &data5B, 2 * sizeof(TextChar)); + sprite5B(sp40, 0x50002, 0, -1, 0); + sprite5B(spC, 0x50006, 0, -1, 0); + mode5B(0); + gUnk_03001250[1] = 0; + gUnk_03001250[0] = 0; + gUnk_03001250[3] = 0; + gUnk_03001250[2] = 0; + gUnk_03001250[5] = 0; + gUnk_03001250[4] = 0; + gUnk_03001250[7] = 0; + gUnk_03001250[6] = 0; + fade5B(0, 0x13); + reg5B(0xE00, 0, 1); + start5B(3); + sel = 0; + prev = 10; + { + u16 *b, *a; + a = sp4; + b = sp8; + b[0] = sel; + a[0] = sel; + b[1] = sel; + a[1] = sel; + asm("" : : "r"(a)); + } + scroll = 0; + timer = 0; + pos = 0; + ty = 0x3C; + tx = 0x18; + x = 0x18; + y = 0x3C; + side = arg->f7; + state = 0; + vcount = (u8)sub_08001108(0x6E); + vblank = sub_0800115C((u32)sub_080066A8); + sub_08000D8C(); + do { + r = sub_0801AAE0(); + if (r == 0) + pressed5B = r; + switch (state) { + case 0: + if (pressed5B == 1) { + if (sel == 1) { + if (arg->f5 == 0) { + state = 3; + side = 0; + } else { + state = 1; + ty = 0x62; + tx = 0x3C; + } + } else { + state = 3; + } + sub_0805865C(0xF); + } else if (sel == 1 && (pressed5B & 0x40)) { + sub_0805865C(0xE); + ty = 0x3C; + sel = 0; + } else if (sel == 0 && (pressed5B & 0x80)) { + sub_0805865C(0xE); + ty = 0x52; + sel = 1; + } else if (pressed5B == 2) { + sub_0805865C(0x10); + sub_0801ABE8(6); + while (sub_0801AAE0() == 0) + sub_080003F0(); + if (sub_08000470((u32)&task5B) != 0) + sub_080003A8((s32)&task5B); + { + u32 stack = (u32)sub_08001494(0x1000); + task5B.fC = (u32)callback5B; + task5B.f10 = stack + 0xFFC; + task5B.f20 = stack; + task5B.f8 = 1; + task5B.f24 = 0; + } + sub_08000274(&task5B, 0); + sub_08000E48(); + sub_0800115C(vblank); + sub_08001108(vcount); + fade5B(0, 0x14); + sub_080003F0(); + return; + } + break; + case 1: + if (keys5B & 0x20) { + if (sel == 1 && side == 1) + sub_0805865C(0xE); + side = 0; + } else if (keys5B & 0x10) { + if (sel == 1 && side == 0) + sub_0805865C(0xE); + side = 1; + } else if (pressed5B == 1) { + state = 3; + sub_0805865C(0xF); + fade5B(0, 0xA); + sub_08000E48(); + vblank = sub_0800115C(vblank); + sub_08001108(vcount); + reg5B(0x200, 0, 1); + } else if (pressed5B == 2) { + state = 0; + tx = 0x18; + sub_0805865C(0x10); + ty = 0x52; + if (sel == 0) + ty = 0x3C; + } + break; + } + if (arg->f5 != 0) { + sub_08065230(spC, 0x50, 0x64, 0x26, side != 0); + sub_08065230(spC, 0x78, 0x64, 0x27, side == 0); + } + buf = sp78; + dy = ty - y; + dx = tx - x; + if (prev != sel) { + count = 0; + scroll = 0; + timer = 0; + pos = 0; + gUnk_03003474 = 0; + d = buf; + { u32 fill = TEXT_CTRL(0xFD); + for (n = 0; n <= 0x1F; n++) + d[n] = fill; } + p = (TextChar *)resource5B((sel + 0x451) | 0x140000); + p = (TextChar *)((u8 *)p + TEXT_HEADER); + prev = sel; + } + if (timer++ > 2) { + timer = 0; + if (*p == TEXT_CTRL(0xFF)) + p++; + if (*p == TEXT_CTRL(0xFE)) + p += 3; + if (*p == TEXT_CTRL(0xFD)) { + p = resource5B((sel + 0x451) | 0x140000); + p += 2; + } + { register TextChar *q asm("r0") = &buf[pos]; *q = *p++; } + if (++pos > 0x1F) { + pos = 0; + sp78[32] = TEXT_CTRL(0xFD); + scroll = 1; + } + } + if (scroll != 0) { + gUnk_03003474++; + if (++count > 7) { + count = 0; + timer = 10; + } else { + timer = 0; + } + } + text5B((u8 *)buf, 0, 0xE); + y += dy / 2; + d1 = ty - y; + if (d1 < 0) + d1 = -d1; + if (d1 <= 1) + y = ty; + x += dx / 2; + d2 = tx - x; + if (d2 < 0) + d2 = -d2; + if (d2 <= 1) + x = tx; + sub_08065230(spC, x, y, 0x15, 0); + text5B(resource5B(0x14044D) + TEXT_HEADER, 4, 6); + text5B(resource5B(0x14044E) + TEXT_HEADER, 4, 9); + sub_080003F0(); + } while (state != 3); + sub_0801ABE8(6); + while (sub_0801AAE0() == 0) + sub_080003F0(); + fade5B(0, 0x14); sub_080003F0(); - sub_08001538((s32)backup); + fade5B(0, 0x14); + sub_080003F0(); + if (sel == 0) + arg->f6 = 0; + else + arg->f6 = 1; + arg->f7 = side; + finish5B(0x25A112EBFULL); } -extern u16 pressed5B asm("gUnk_03001324"); -extern void finish5B(unsigned long long) asm("sub_08000420"); -struct Menu5B { u8 pad[5], f5, f6, f7; }; -struct Task5B {u32 f0,f4,f8,fC,f10,f14,f18,f1C,f20,f24;}; -extern struct Task5B task5B asm("gUnk_03002840"); -extern u16 data5B asm("gUnk_080B99D4"); -extern u8 *resource5B(u32) asm("sub_08007290"); -extern s32 sprite5B(void *,u32,s32,s32,s32) asm("sub_08065158"); -extern void text5B(u8 *,u16,u16) asm("sub_0801A3D0"); -extern void copy5B(void *,const void *,u32) asm("memcpy"); -extern void mode5B(s32) asm("sub_0801A6D4"); -extern s32 fade5B(s32,s32) asm("sub_0801A664"); -extern void reg5B(s32,s32,s32) asm("sub_080009F8"); -extern void start5B(s32) asm("sub_0801AB50"); -extern void callback5B(void) asm("sub_08002B70"); -extern u16 keys5B asm("gUnk_03001308"); -extern void sub_080066A8(void); -void menu5B(struct Menu5B *) asm("sub_08005B88"); -/* [RunTwoChoiceSaveMenu] Initializes sprites50002/50006 and background scroll, installs temporary display - * callbacks, suppresses pressed keys during transition, streams resource text through a32-byte scrolling - * buffer, and animates a cursor. Up/down selects0/1. Confirming1 optionally opens a left/right subchoice when - * record byte+5 is nonzero; otherwise forces side0. Normal exit writes choice to record+6 and side to+7 then - * signals0x25A112EBF. Base cancel restores callbacks and restarts02B70 using unchecked0x1000 allocation - * without signaling or updating record. Subchoice confirm restores callbacks; direct base confirmation does - * not locally restore them. */ +#else void menu5B(struct Menu5B *arg) { u16 sp4[2], sp8[2]; u8 spC[0x34], sp40[0x34], sp74[4], sp78[33], sp9C[36]; @@ -2809,6 +4318,7 @@ void menu5B(struct Menu5B *arg) { arg->f7 = side; finish5B(0x25A112EBFULL); } +#endif extern u16 pressed6C asm("gUnk_03001324"); extern void finish6C(unsigned long long) asm("sub_08000420"); struct Menu6C { u8 pad[5], f5, f6, f7; }; @@ -2834,6 +4344,221 @@ void menu6C(struct Menu6C *) asm("sub_0800608C"); * exit writes record+6=1 and signals0x25A112EBF. Base cancel restores callbacks and restarts02B70 with * unchecked0x1000 allocation; no signal or record update. Normal direct base confirmation does not locally * restore callbacks. */ +#ifdef REGION_USA +void menu6C(struct Menu6C *arg) { + u16 sp4[2], sp8[2]; + u8 spC[0x34], sp40[0x34], sp74[4]; + TextChar sp78[33]; + s32 sel, prev; + u32 timer; + s32 scroll; + u32 count, pos; + s32 x, y, tx, ty; + u32 vblank; + u8 vcount; + s32 state; + u8 side; + s32 dy, dx; + TextChar *p, *d; register TextChar *buf asm("r4"); + u32 i, j, n, row; + s32 r, d1, d2; + + copy6C(sp74, &data6C, 2 * sizeof(TextChar)); + sprite6C(sp40, 0x50002, 0, -1, 0); + sprite6C(spC, 0x50006, 0, -1, 0); + mode6C(0); + gUnk_03001250[1] = 0; + gUnk_03001250[0] = 0; + gUnk_03001250[3] = 0; + gUnk_03001250[2] = 0; + gUnk_03001250[5] = 0; + gUnk_03001250[4] = 0; + gUnk_03001250[7] = 0; + gUnk_03001250[6] = 0; + fade6C(0, 0x13); + reg6C(0xE00, 0, 1); + start6C(3); + sel = 0; + prev = 10; + { + u16 *b, *a; + a = sp4; + b = sp8; + b[0] = sel; + a[0] = sel; + b[1] = sel; + a[1] = sel; + asm("" : : "r"(a)); + } + scroll = 0; + timer = 0; + pos = 0; + ty = 0x52; + tx = 0x18; + x = 0x18; + y = 0x52; + side = arg->f7; + state = 0; + sel = 1; + vcount = (u8)sub_08001108(0x6E); + vblank = sub_0800115C((u32)sub_080066A8); + sub_08000D8C(); + do { + r = sub_0801AAE0(); + if (r == 0) + pressed6C = r; + switch (state) { + case 0: + if (pressed6C == 1) { + if (sel == 1) { + if (arg->f5 == 0) { + state = 3; + } else { + state = 1; + ty = 0x62; + tx = 0x3C; + } + } else { + state = 3; + } + sub_0805865C(0xF); + } else if (pressed6C == 2) { + sub_0805865C(0x10); + sub_0801ABE8(6); + while (sub_0801AAE0() == 0) + sub_080003F0(); + sub_08000E48(); + sub_0800115C(vblank); + sub_08001108(vcount); + if (sub_08000470((u32)&task6C) != 0) + sub_080003A8((s32)&task6C); + { + u32 stack = (u32)sub_08001494(0x1000); + task6C.fC = (u32)callback6C; + task6C.f10 = stack + 0xFFC; + task6C.f20 = stack; + task6C.f8 = 1; + task6C.f24 = 0; + } + sub_08000274(&task6C, 0); + fade6C(0, 0x14); + sub_080003F0(); + return; + } + break; + case 1: + if (keys6C & 0x20) { + if (sel == 1 && side == 1) + sub_0805865C(0xE); + side = 0; + } else if (keys6C & 0x10) { + if (sel == 1 && side == 0) + sub_0805865C(0xE); + side = 1; + } else if (pressed6C == 1) { + state = 3; + side = 0; + sub_0805865C(0xF); + fade6C(0, 0xA); + sub_08000E48(); + vblank = sub_0800115C(vblank); + sub_08001108(vcount); + reg6C(0x200, 0, 1); + } else if (pressed6C == 2) { + state = 0; + tx = 0x18; + sub_0805865C(0x10); + ty = 0x52; + } + break; + } + if (arg->f5 != 0) { + sub_08065230(spC, 0x50, 0x64, 0x26, side != 0); + sub_08065230(spC, 0x78, 0x64, 0x27, side == 0); + } + buf = sp78; + dy = ty - y; + dx = tx - x; + if (prev != sel) { + count = 0; + scroll = 0; + timer = 0; + pos = 0; + gUnk_03003474 = 0; + d = buf; + { u32 fill = TEXT_CTRL(0xFD); + for (n = 0; n <= 0x1F; n++) + d[n] = fill; } + p = (TextChar *)resource6C(0x140453); + p = (TextChar *)((u8 *)p + TEXT_HEADER); + prev = sel; + } + if (timer++ > 2) { + timer = 0; + if (*p == TEXT_CTRL(0xFF)) + p++; + if (*p == TEXT_CTRL(0xFE)) + p += 3; + if (*p == TEXT_CTRL(0xFD)) { + p = (TextChar *)resource6C(0x140453); + p = (TextChar *)((u8 *)p + TEXT_HEADER); + } + { register TextChar *q asm("r0") = &buf[pos]; *q = *p++; } + if (++pos > 0x1F) { + pos = 0; + sp78[32] = TEXT_CTRL(0xFD); + scroll = 1; + } + } + if (scroll != 0) { + gUnk_03003474++; + if (++count > 7) { + count = 0; + timer = 10; + } else { + timer = 0; + } + } + text6C((u8 *)buf, 0, 0xE); + y += dy / 2; + d1 = ty - y; + if (d1 < 0) + d1 = -d1; + if (d1 <= 1) + y = ty; + x += dx / 2; + d2 = tx - x; + if (d2 < 0) + d2 = -d2; + if (d2 <= 1) + x = tx; + sub_08065230(spC, x, y, 0x15, 0); + text6C(resource6C(0x14044F) + TEXT_HEADER, 4, 6); + text6C(resource6C(0x140450) + TEXT_HEADER, 4, 9); + sub_080003F0(); + } while (state != 3); + sub_0801ABE8(6); + while (sub_0801AAE0() == 0) + sub_080003F0(); + gUnk_03001250[1] = 0; + gUnk_03001250[0] = 0; + gUnk_03001250[3] = 0; + gUnk_03001250[2] = 0; + gUnk_03001250[5] = 0; + gUnk_03001250[4] = 0; + gUnk_03001250[7] = 0; + gUnk_03001250[6] = 0; + fade6C(0, 0x14); + sub_080003F0(); + fade6C(0, 0x14); + sub_080003F0(); + if (sel == 0) + arg->f6 = 0; + else + arg->f6 = 1; + finish6C(0x25A112EBFULL); +} +#else void menu6C(struct Menu6C *arg) { u16 sp4[2], sp8[2]; u8 spC[0x34], sp40[0x34], sp74[4], sp78[33], sp9C[36]; @@ -3063,6 +4788,7 @@ void menu6C(struct Menu6C *arg) { arg->f6 = 1; finish6C(0x25A112EBFULL); } +#endif /* [ReleasePaletteDimmingHold] Writes zero to the entire shared palette-dimming hold word 0300001C. This * releases the post-dimming wait in task 05A24; it does not cancel the task or interrupt its earlier factor * loop, and it does not itself restore palette bytes. */ diff --git a/src/code_08006D24.c b/src/code_08006D24.c index 7701ad60..414a1600 100644 --- a/src/code_08006D24.c +++ b/src/code_08006D24.c @@ -170,16 +170,33 @@ s32 sub_08006EE0(s32 value, s32 *archive) case 9: resource = (u8 *)header + header->offsets[3]; break; case 0: case 1: case 2: case 3: case 4: case 5: case 6: resource = (u8 *)header + header->offsets[kind]; break; - case 11: resource = gUnk_084506D0 + 0xC4 * (value & 0xFFFF); break; - case 12: resource = gUnk_08434738 + 0xB8 * (value & 0xFFFF); break; - case 13: resource = gUnk_0843B8C8 + 0xB8 * (value & 0xFFFF); break; - case 14: resource = gUnk_08442498 + 0xB8 * (value & 0xFFFF); break; - case 15: resource = gUnk_084303B8 + 0xB4 * (value & 0xFFFF); break; - case 16: resource = gUnk_0844A820 + 0xAC * (value & 0xFFFF); break; - case 17: resource = gUnk_0844EB50 + 0xB0 * (value & 0xFFFF); break; - case 18: resource = gUnk_0842A6D4 + 0xA4 * (value & 0xFFFF); break; - case 19: resource = gUnk_084742BC + 0xB0 * (value & 0xFFFF); break; + case 11: resource = gUnk_084506D0 + ITEM_FIELD(0xC4) * (value & 0xFFFF); break; + case 12: resource = gUnk_08434738 + EQUIP_FIELD(0xB8) * (value & 0xFFFF); break; + case 13: resource = gUnk_0843B8C8 + EQUIP_FIELD(0xB8) * (value & 0xFFFF); break; + case 14: resource = gUnk_08442498 + GLOVE_SIZE * (value & 0xFFFF); break; + case 15: resource = gUnk_084303B8 + ITEM_FIELD(0xB4) * (value & 0xFFFF); break; + case 16: resource = gUnk_0844A820 + ITEM_FIELD(0xAC) * (value & 0xFFFF); break; + case 17: resource = gUnk_0844EB50 + ITEM_FIELD(0xB0) * (value & 0xFFFF); break; + case 18: resource = gUnk_0842A6D4 + ITEM_FIELD(0xA4) * (value & 0xFFFF); break; + case 19: resource = gUnk_084742BC + ITEM_FIELD(0xB0) * (value & 0xFFFF); break; case 20: +#ifdef REGION_USA + /* USA has a sixth text table, without an EU counterpart. */ + { + u8 **table; + switch ((u32)gUnk_03003470) { + case 0: table = gUnk_0838AFF0; break; + case 1: table = gUnk_084009A4; break; + case 2: table = gUnk_08428C38; break; + case 3: table = gUnk_083D8AEC; break; + case 4: table = gUnk_083B0B4C; break; + case 5: table = (u8 **)0x083DB468; break; + default: goto done20; + } + resource = table[value & 0xFFFF]; + } + done20: +#else switch ((u32)gUnk_03003470) { case 0: resource = gUnk_0838AFF0[value & 0xFFFF]; break; case 1: resource = gUnk_084009A4[value & 0xFFFF]; break; @@ -187,8 +204,9 @@ s32 sub_08006EE0(s32 value, s32 *archive) case 4: resource = gUnk_083B0B4C[value & 0xFFFF]; break; case 3: resource = gUnk_083D8AEC[value & 0xFFFF]; break; } +#endif break; - case 21: resource = gUnk_0842A38C + 0xA8 * (value & 0xFFFF); break; + case 21: resource = gUnk_0842A38C + ITEM_FIELD(0xA8) * (value & 0xFFFF); break; case 22: resource = gUnk_0847838C; break; default: return 0; } diff --git a/src/code_08009088.c b/src/code_08009088.c index b43166bf..896461ec 100644 --- a/src/code_08009088.c +++ b/src/code_08009088.c @@ -99,7 +99,9 @@ void sub_08009138(s32 *arg0, s32 arg1) { } else sub_08000AF0(0,palette,15); if (gUnk_03003170.curLevel == 4 && sub_0800CDC0()) sub_080009C0(0x1b00,0,1); else if (gUnk_03003170.curLevel != 13) sub_080009C0(0x1f00,0,1); - sub_08001538(alloc); +#ifndef REGION_USA + sub_08001538(alloc); /* USA no longer frees this stale pointer */ +#endif done9138 = 0; sub_080003F0(); } @@ -1145,7 +1147,7 @@ void sub_0800A34C(u32 music, s32 previous, s32 changed) { } } } -struct T06PlayerA998 {u8 pad[0x8C];s32 x,y;u8 tail[0xB8];}; +struct T06PlayerA998 {u8 pad[PLAYER_FIELD(0x8C)];s32 x,y;u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x94)];}; struct T06SysA998 { u8 pad[0x60];void *header,*allocation;u16 *map0,*map1; u16 width0,pad72,width1,pad76,mapW,mapH;s16 scrollX,scrollY; @@ -2190,15 +2192,15 @@ struct CurBEC0 { }; struct PlayerBEC0 { u16 f0; - u8 p2[0x1A]; + u8 p2[PLAYER_FIELD(0x1C) - 0x2]; u16 f1C; - u8 p1E[0x10]; + u8 p1E[PLAYER_FIELD(0x2E) - PLAYER_FIELD(0x1E)]; u16 f2E; - u8 p30[0x80]; + u8 p30[PLAYER_FIELD(0xB0) - (PLAYER_FIELD(0x2F) + 1)]; u16 fB0; u16 fB2; s16 fB4; - u8 pB6[0x8E]; + u8 pB6[PLAYER_FIELD(0x144) - PLAYER_FIELD(0xB6)]; struct CurBEC0 *p144; struct CurBEC0 *p148; }; @@ -2316,7 +2318,7 @@ void sub_0800BEC0(void) regsBEC0[7] = 0; regsBEC0[2] = 0; regsBEC0[3] = 0; - initBEC0(&sprB, 0x500C3, 4, 0xC, 0); + initBEC0(&sprB, RES_ID(0x500C3), 4, 0xC, 0); sub_080003F0(); sub_080003F0(); sub_080003F0(); @@ -2544,7 +2546,7 @@ while (1) { if (!((flagsBEC0 >> 8) & 1)) { if (sel != 0xFF) { s = strBEC0((sel + 0x4A9) | 0x140000); - s += 2; + s += TEXT_HEADER; textBEC0(s, 0xF - lenBEC0(s) / 2, 0x12); } else { msgBEC0(0x12, 2); diff --git a/src/code_0800CF58.c b/src/code_0800CF58.c index 99129aee..d283c4e9 100644 --- a/src/code_0800CF58.c +++ b/src/code_0800CF58.c @@ -163,9 +163,9 @@ s32 sub_0800D1B0(void) { s32 idx; u8 *pl; idx = sub_080020F4(); - pl = (u8 *) gUnk_03003CE0 + idx * 0x14C; + pl = (u8 *) gUnk_03003CE0 + idx * PLAYER_SIZE; r4 = 0; - if (pl[0x68] == 0 || (*(u32 *) (pl + 0x30) & 0x400) || *(u16 *) (pl + 0x20) == 0xC || sub_08058DB0() || sub_0800D11C() || sub_0800CCCC() || sub_0800CDF8()) { + if (pl[PLAYER_FIELD(0x68)] == 0 || (*(u32 *) (pl + PLAYER_FIELD(0x30)) & 0x400) || *(u16 *) (pl + PLAYER_FIELD(0x20)) == 0xC || sub_08058DB0() || sub_0800D11C() || sub_0800CCCC() || sub_0800CDF8()) { r4 = 1; } if (sub_0800CF80() != 0 && sub_08056E50() != 0) { @@ -225,38 +225,38 @@ void sub_0800D2F4(void) { } block_a: p = gUnk_030034E0; - if (*(u16 *) (p + 0x50) != 0) { - u16 v = sub_0801E0AC(p + 0x30, 7); + if (*(u16 *) (p + SAVE_FIELD(0x50)) != 0) { + u16 v = sub_0801E0AC(p + SAVE_FIELD(0x30), 7); sub_08067FE0(7, v); } return; block_c: p = gUnk_030034E0; - if (*(u16 *) (p + 0x4C) != 0) { - u16 v = sub_0801E0AC(p + 0x30, 6); + if (*(u16 *) (p + SAVE_FIELD(0x4C)) != 0) { + u16 v = sub_0801E0AC(p + SAVE_FIELD(0x30), 6); sub_08067FE0(6, v); } } static inline u16 D368_Level(u8 *p) { s32 i; - s32 h = (s8)p[0x6C] * 5; + s32 h = (s8)p[PLAYER_FIELD(0x6C)] * 5; for (i = 7; i >= 0; i--) { u16 t = gUnk_0847ACE8[i] + h * 2; if ((s16)t < 0) t = 0; - if (*(s16 *)(p + 0xC2) >= (s16)t) + if (*(s16 *)(p + PLAYER_FIELD(0xC2)) >= (s16)t) return i; } return 0; } static inline u16 D368_Level2(u8 *p) { s32 i; - s32 h = (s8)p[0x6C] * 5; + s32 h = (s8)p[PLAYER_FIELD(0x6C)] * 5; for (i = 7; i >= 0; i--) { u16 t = gUnk_0847ACE8[i] + h * 2; if ((s16)t < 0) t = 0; - if (*(s16 *)(p + 0xC2) >= (s16)t) + if (*(s16 *)(p + PLAYER_FIELD(0xC2)) >= (s16)t) return i; } return 0; @@ -265,14 +265,18 @@ static inline u16 D368_Level2(u8 *p) { first (r3) at the third call site, like the ROM; the two tie at priority 0.722 vs 0.717 otherwise. */ static inline u16 D368_Level3(u8 *p) { s32 i; - s32 h = (s8)p[0x6C] * 5; + s32 h = (s8)p[PLAYER_FIELD(0x6C)] * 5; i = 7; asm(""); for (; i >= 0; i--) { +#ifdef REGION_USA + u16 t = ({ u16 *entry = &gUnk_0847ACE8[i]; h * 2 + *entry; }); +#else u16 t = gUnk_0847ACE8[i] + h * 2; +#endif if ((s16)t < 0) t = 0; - if (*(s16 *)(p + 0xC2) >= (s16)t) + if (*(s16 *)(p + PLAYER_FIELD(0xC2)) >= (s16)t) return i; } return 0; @@ -447,10 +451,10 @@ void sub_0800D368(void *arg0) { extern u32 d368_sub_0801DEB8() asm("sub_0801DEB8"); struct Copy36D368 { u32 words[9]; }; union HistPtrD368 { u16 *ptr; u16 half[2]; }; - struct PlayerD368 { u16 f0; u8 f2; u8 pad3[9]; u16 fC; u8 padE[2]; u16 f10; u16 f12; u16 f14; u16 f16; u16 f18; u16 f1A; u16 f1C; u8 pad1E[2]; u16 f20; u16 f22; u16 f24; u16 f26; u16 f28; u8 pad2A[2]; u16 f2C; u16 f2E; u32 f30; u16 * f34; u16 f38; u8 pad3A[2]; s16 f3C; u8 pad3E[2]; s16 f40; u8 pad42[6]; s32 f48; u8 pad4C[18]; s16 f5E; u16 f60; u16 f62; u16 f64; u8 f66; u8 f67; u8 f68; u8 pad69[3]; u8 f6C; u8 pad6D[3]; u8 f70; u8 f71; u8 pad72[7]; u8 f79; u8 pad7A[14]; u32 f88; s32 f8C; s32 f90; s32 f94; u8 pad98[4]; s32 f9C; s32 fA0; s32 fA4; u8 padA8[4]; union HistPtrD368 fAC; u16 fB0; u16 fB2; u16 fB4; u16 fB6; u16 fB8; u16 fBA; u16 fBC; u16 fBE; u16 fC0; u16 fC2; u16 fC4; s16 fC6; u8 padC8[16]; s32 fD8; s32 fDC; s32 fE0; u8 padE4[44]; u32 f110; u16 f114; u8 pad116[8]; u16 f11E; u8 pad120[2]; u16 f122; s16 f124; u16 f126[5]; u16 f130; u16 f132; u16 f134; u16 f136; u8 pad138[4]; u16 * f13C; void * f140; void * f144; void * f148; }; - struct InvD368 { u8 pad0[0x54]; u16 f54; u16 f56[8]; }; + struct PlayerD368 { u16 f0; TextChar f2; u8 pad3[PLAYER_FIELD(0xC) - 2 - sizeof(TextChar)]; u16 fC; u8 padE[2]; u16 f10; u16 f12; u16 f14; u16 f16; u16 f18; u16 f1A; u16 f1C; u8 pad1E[2]; u16 f20; u16 f22; u16 f24; u16 f26; u16 f28; u8 pad2A[2]; u16 f2C; u16 f2E; u32 f30; u16 * f34; u16 f38; u8 pad3A[2]; s16 f3C; u8 pad3E[2]; s16 f40; u8 pad42[6]; s32 f48; u8 pad4C[18]; s16 f5E; u16 f60; u16 f62; u16 f64; u8 f66; u8 f67; u8 f68; u8 pad69[3]; u8 f6C; u8 pad6D[3]; u8 f70; u8 f71; u8 pad72[7]; u8 f79; u8 pad7A[14]; u32 f88; s32 f8C; s32 f90; s32 f94; u8 pad98[4]; s32 f9C; s32 fA0; s32 fA4; u8 padA8[4]; union HistPtrD368 fAC; u16 fB0; u16 fB2; u16 fB4; u16 fB6; u16 fB8; u16 fBA; u16 fBC; u16 fBE; u16 fC0; u16 fC2; u16 fC4; s16 fC6; u8 padC8[16]; s32 fD8; s32 fDC; s32 fE0; u8 padE4[44]; u32 f110; u16 f114; u8 pad116[8]; u16 f11E; u8 pad120[2]; u16 f122; s16 f124; u16 f126[5]; u16 f130; u16 f132; u16 f134; u16 f136; u8 pad138[4]; u16 * f13C; void * f140; void * f144; void * f148; }; + struct InvD368 { u8 pad0[SAVE_FIELD(0x54)]; u16 f54; u16 f56[8]; }; struct EffectD368 { s16 f0; u16 f2, f4, f6; u8 pad8[16]; s32 f18; u8 tail[12]; }; - struct PeerD368 { u8 f0; u8 pad1[0xB]; s16 fC; u8 padE[6]; s32 f14; s32 f18; u8 pad1C[0x2E]; u16 f4A; s32 f4C; u8 pad50[4]; s32 f54; u16 f58; u16 f5A; u8 pad5C[6]; s16 f62; u8 pad64[0x28]; struct EffectD368 effects[8]; u8 pad1CC[0x10]; u8 f1DC; u8 tail[0x2E0 - 0x1DD]; }; + struct PeerD368 { u8 f0; u8 pad1[0xB]; s16 fC; u8 padE[6]; s32 f14; s32 f18; u8 pad1C[0x2E]; u16 f4A; s32 f4C; u8 pad50[4]; s32 f54; u16 f58; u16 f5A; u8 pad5C[6]; s16 f62; u8 pad64[0x28]; struct EffectD368 effects[8]; u8 pad1CC[0x10]; u8 f1DC; u8 tail[ENEMY_SIZE - 0x1DD]; }; extern struct PeerD368 *peersD368 asm("gUnk_030056F4"); union RecordD368 { struct { u32 value:4; } w0_b0_n4; struct { u32 gap:4; u32 value:12; } w0_b4_n12; struct { u32 gap:16; u32 value:12; } w0_b16_n12; struct { u32 gap:28; u32 value:4; } w0_b28_n4; struct { u32 word0; u32 value:6; } w1_b0_n6; struct { u32 word0; u32 gap:6; u32 value:1; } w1_b6_n1; struct { u32 word0; u32 gap:6; u32 value:4; } w1_b6_n4; struct { u32 word0; u32 gap:6; u32 value:6; } w1_b6_n6; struct { u32 word0; u32 gap:6; u32 value:8; } w1_b6_n8; struct { u32 word0; u32 gap:10; u32 value:1; } w1_b10_n1; struct { u32 word0; u32 gap:11; u32 value:8; } w1_b11_n8; struct { u32 word0; u32 gap:12; u32 value:6; } w1_b12_n6; struct { u32 word0; u32 gap:14; u32 value:3; } w1_b14_n3; struct { u32 word0; u32 gap:17; u32 value:3; } w1_b17_n3; struct { u32 word0; u32 gap:18; u32 value:4; } w1_b18_n4; struct { u32 word0; u32 gap:19; u32 value:5; } w1_b19_n5; struct { u32 word0; u32 gap:20; u32 value:5; } w1_b20_n5; struct { u32 word0; u32 gap:22; u32 value:1; } w1_b22_n1; struct { u32 word0; u32 gap:23; u32 value:1; } w1_b23_n1; struct { u32 word0; u32 gap:25; u32 value:3; } w1_b25_n3; struct { u32 word0; u32 gap:28; u32 value:1; } w1_b28_n1; }; struct AnimD368 sp10; @@ -526,7 +530,7 @@ void sub_0800D368(void *arg0) { extern u8 byteTable6410D368[] asm("gUnk_03006410"); extern u8 actorByteState315D368[] asm("gUnk_03006430"); extern struct PlayerD368 effectOwnerTableD368[] asm("gUnk_03003CE0"); - extern u32 ownerWords366D368[][83] asm("gUnk_03003CE0"); + extern u32 ownerWords366D368[][PLAYER_SIZE / 4] asm("gUnk_03003CE0"); extern const u16 effectThresholdTableD368[] asm("gUnk_0847ACF8"); extern const u8 directionTableD368[] asm("gUnk_084790B4"); extern const s16 colorWaveTableD368[] asm("gUnk_080B9704"); @@ -670,8 +674,15 @@ void sub_0800D368(void *arg0) { s32 var_r1_8; s32 var_r1_9; s32 var_r4_11; +#ifdef REGION_USA + register u32 maskA asm("r5"); + u32 maskZ; + register s32 var_r5_7 asm("r6"); + register s32 var_r5_8 asm("r6"); +#else s32 var_r5_7; s32 var_r5_8; +#endif s32 directionD36874; s32 var_r0_31; u16 *temp_r0_90; @@ -870,6 +881,10 @@ void sub_0800D368(void *arg0) { u32 var_r3_12; u32 var_r4_10; u32 var_r5; +#ifndef REGION_USA +#define maskA var_r5 +#define maskZ var_r5 +#endif u32 var_r5_s1; u32 var_r6_8; s32 temp_r0_111; @@ -1030,19 +1045,19 @@ void sub_0800D368(void *arg0) { void *var_r3_7; void *var_r5_6; - d368_sub_08065158(&sp44, 0x5008C, 0, -1, (0)); + d368_sub_08065158(&sp44, RES_ID(0x5008C), 0, -1, (0)); sp44.f1C = 7; sp44.f1D = 8; - d368_sub_08065158(&spAC, 0x5008B, 0, -1, (0)); + d368_sub_08065158(&spAC, RES_ID(0x5008B), 0, -1, (0)); spAC.f1C = 7; spAC.f1D = 8; coordFA = 0; coordF8 = 0; - d368_sub_08065158(&sp78, 0x50010, 0, -1, (0)); + d368_sub_08065158(&sp78, RES_ID(0x50010), 0, -1, (0)); sp178 = d368_sub_080653CC(); d368_sub_0807A064(((struct PlayerD368 *)arg0)->f0); ((struct PlayerD368 *)arg0)->fB4 = 0U; - temp_r0 = (arg0 + 0xB4) - 2; + temp_r0 = (arg0 + PLAYER_FIELD(0xB4)) - 2; *temp_r0 = 0; *(temp_r0 - 0x1) = 0; ((struct PlayerD368 *)arg0)->fB8 = 0xFFFFU; @@ -1066,7 +1081,11 @@ void sub_0800D368(void *arg0) { sp1A4 = 0; sp148 = 0; sp16C = 0x64; + #ifdef REGION_USA + sp168 = (u8) ((struct PlayerD368 *)arg0)->f1C; +#else sp168 = (u32) M2C_FIELD(&((struct PlayerD368 *)arg0)->f1C, u8 *, 0); +#endif sp194 = 0xFFFF; sp170 = 0; sp12C = ((struct PlayerD368 *)arg0)->f140; @@ -1080,7 +1099,7 @@ void sub_0800D368(void *arg0) { ((struct PlayerD368 *)arg0)->fDC = (s32) ((u32) ((struct PlayerD368 *)arg0)->f0 << 0x18); sp128 = 0; do { - ((u32 *)(arg0 + 0xE4))[sp128] = 0; + ((u32 *)(arg0 + PLAYER_FIELD(0xE4)))[sp128] = 0; temp_r2 = sp128 + 1; sp128 = temp_r2; } while (temp_r2 <= 4U); @@ -1089,7 +1108,7 @@ void sub_0800D368(void *arg0) { d368_sub_08060DB0(1); d368_sub_08061688(1); d368_sub_08015E00(arg0); - ownerWords366D368[d368_sub_080020F4()][12] |= 1; + ownerWords366D368[d368_sub_080020F4()][PLAYER_FIELD(0x30) / 4] |= 1; ((struct PlayerD368 *)arg0)->f30 = (u32) (((struct PlayerD368 *)arg0)->f30 | 0x800); d368_sub_0800D2F4(); d368_sub_08067B50(); @@ -1189,7 +1208,7 @@ void sub_0800D368(void *arg0) { ((struct PlayerD368 *)arg0)->f14 = temp_r5; if (((u32) temp_r0_5 << 0x10) == 0) { ((struct PlayerD368 *)arg0)->f30 = (u32) (((struct PlayerD368 *)arg0)->f30 & ~0x24); - ownerWords366D368[d368_sub_080020F4()][12] |= 1; + ownerWords366D368[d368_sub_080020F4()][PLAYER_FIELD(0x30) / 4] |= 1; } } else { u16 *historyIndexD368, *historySlotD368, *historyArrayD368, *historyControllerD368; @@ -1396,13 +1415,13 @@ void sub_0800D368(void *arg0) { } else { var_r4_11 = d368_sub_0805D548(temp_r0_8 - 1); if (d368_sub_0801DE60() == 0) { - var_r2_2 = d368_sub_0801E0AC(d368_gUnk_030034E0 + 0x30, 5); + var_r2_2 = d368_sub_0801E0AC(d368_gUnk_030034E0 + SAVE_FIELD(0x30), 5); } else { var_r2_2 = 0; } if (var_r4_11 == -1) { - } else if (d368_sub_0805BD5C(d368_gUnk_030034E0 + ((var_r4_11 * 0x10) + 0x150), var_r2_2) == 0) { + } else if (d368_sub_0805BD5C(d368_gUnk_030034E0 + ((var_r4_11 * 0x10) + SAVE_FIELD(0x150)), var_r2_2) == 0) { } else { d368_sub_0805D580(var_r4_11); @@ -1463,7 +1482,7 @@ void sub_0800D368(void *arg0) { } else if ((u32) (sp128 - 2) <= 8U) { } else { - ownerWords366D368[d368_sub_080020F4()][12] |= 1; + ownerWords366D368[d368_sub_080020F4()][PLAYER_FIELD(0x30) / 4] |= 1; ((struct PlayerD368 *)arg0)->f14 = temp_r0_11; ((struct PlayerD368 *)arg0)->f12 = temp_r0_11; d368_sub_08065654(); @@ -1502,11 +1521,14 @@ void sub_0800D368(void *arg0) { sp128 = 1; break; } - if ((d368_sub_0800CF80() == 0) && (sp128 == 1) && (temp_r0_9 = ((struct PlayerD368 *)arg0)->f20, (temp_r0_9 != 4)) && (temp_r0_9 != 3) && (temp_r0_9 != 0xA) && (temp_r0_9 != 9) && (temp_r0_9 != 5) && (temp_r0_9 != 0xC) && (M2C_FIELD(d368_gUnk_030034E0, u8 *, 0x13A) != 0) && (d368_sub_0800CCCC() == 0) && (sp174 > 5U) && (d368_sub_0800CD8C() == 0)) { - if ((((struct PlayerD368 *)arg0)->f20 != 0xE) && (var_r5 = ((struct PlayerD368 *)arg0)->f30 & 0x01803400, (var_r5 == 0)) && ((gUnk_03003170.curLevel != 0xB) || (gUnk_03003170.f90 != 0)) && ((lookupStats = (void *) d368_sub_08007290(M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x132) | 0x110000)), ((u32) ((struct PlayerD368 *)arg0)->fC6 >= (u32) (M2C_FIELD(lookupStats, s32 *, 0xA0) + (s8) ((struct PlayerD368 *)arg0)->f79))) && ((u32) ((struct PlayerD368 *)arg0)->f64 <= 9U)) { - ((struct PlayerD368 *)arg0)->f68 = var_r5; + if ((d368_sub_0800CF80() == 0) && (sp128 == 1) && (temp_r0_9 = ((struct PlayerD368 *)arg0)->f20, (temp_r0_9 != 4)) && (temp_r0_9 != 3) && (temp_r0_9 != 0xA) && (temp_r0_9 != 9) && (temp_r0_9 != 5) && (temp_r0_9 != 0xC) && (M2C_FIELD(d368_gUnk_030034E0, u8 *, SAVE_FIELD(0x13A)) != 0) && (d368_sub_0800CCCC() == 0) && (sp174 > 5U) && (d368_sub_0800CD8C() == 0)) { + if ((((struct PlayerD368 *)arg0)->f20 != 0xE) && (maskA = ((struct PlayerD368 *)arg0)->f30 & 0x01803400, (maskA == 0)) && ((gUnk_03003170.curLevel != 0xB) || (gUnk_03003170.f90 != 0)) && ((lookupStats = (void *) d368_sub_08007290(M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x132)) | 0x110000)), ((u32) ((struct PlayerD368 *)arg0)->fC6 >= (u32) (M2C_FIELD(lookupStats, s32 *, ITEM_FIELD(0xA0)) + (s8) ((struct PlayerD368 *)arg0)->f79))) && ((u32) ((struct PlayerD368 *)arg0)->f64 <= 9U)) { +#ifdef REGION_USA + maskZ = maskA; +#endif + ((struct PlayerD368 *)arg0)->f68 = maskZ; ((struct PlayerD368 *)arg0)->f20 = 0xEU; - ((struct PlayerD368 *)arg0)->fC6 = (s16) var_r5; + ((struct PlayerD368 *)arg0)->fC6 = (s16) maskZ; d368_sub_0806617C(); } else { d368_sub_0805865C(0x61); @@ -1536,7 +1558,7 @@ void sub_0800D368(void *arg0) { case 1: case 4: case 6: - var_r2_3 = d368_sub_0801E0AC(d368_gUnk_030034E0 + 0x30, 7); + var_r2_3 = d368_sub_0801E0AC(d368_gUnk_030034E0 + SAVE_FIELD(0x30), 7); break; default: var_r2_3 = 0; @@ -1619,7 +1641,7 @@ void sub_0800D368(void *arg0) { case 6: case 8: if (var_r6->f4 == 4 && (d368_sub_0800CCCC() != 0 || d368_sub_0801DF8C() != 0 || d368_sub_08056E90() != 0)) { - d368_sub_0805AD78(M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x68)); + d368_sub_0805AD78(M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x68))); var_r6->f0 = 0; ((struct PlayerD368 *)arg0)->f64 = (u16) ((struct PlayerD368 *)arg0)->fC; d368_sub_0806617C(); @@ -1682,7 +1704,7 @@ void sub_0800D368(void *arg0) { temp_r5_4 = (var_r6->f18 * 0xA) + 0x64; M2C_FIELD(&((struct PlayerD368 *)arg0)->f88, u16 *, 0) = (u16) (M2C_FIELD(&((struct PlayerD368 *)arg0)->f88, u16 *, 0) + ((s32) (temp_r5_4 * var_r6->f6) / 100)); ((struct PlayerD368 *)arg0)->fE0 = 6; - d368_sub_08069224(6, (u16) ((s32) (temp_r5_4 * var_r6->f6) / 100), d368_gUnk_030034E0 + 0x24); + d368_sub_08069224(6, (u16) ((s32) (temp_r5_4 * var_r6->f6) / 100), d368_gUnk_030034E0 + SAVE_FIELD(0x24)); } if (var_r6->f0 == 1) { d368_sub_0805867C(0x73); @@ -1694,7 +1716,7 @@ void sub_0800D368(void *arg0) { temp_r5_4 = (var_r6->f18 * 0xA) + 0x64; M2C_FIELD(&((struct PlayerD368 *)arg0)->f88, u16 *, 0) = (u16) (M2C_FIELD(&((struct PlayerD368 *)arg0)->f88, u16 *, 0) + ((s32) (temp_r5_4 * var_r6->f6) / 100)); ((struct PlayerD368 *)arg0)->fE0 = 6; - d368_sub_08069224(6, (u16) ((s32) (temp_r5_4 * var_r6->f6) / 100), d368_gUnk_030034E0 + 0x24); + d368_sub_08069224(6, (u16) ((s32) (temp_r5_4 * var_r6->f6) / 100), d368_gUnk_030034E0 + SAVE_FIELD(0x24)); } if (var_r6->f0 == 1) { d368_sub_0805867C(0x73); @@ -1767,7 +1789,7 @@ void sub_0800D368(void *arg0) { ((struct PlayerD368 *)arg0)->f26 = temp_r1_18; ((struct PlayerD368 *)arg0)->f24 = temp_r1_18; sp130 = 0; - sp134 = (s32) (u16) ((s32) (M2C_FIELD((void *) d368_sub_08007290(M2C_FIELD((d368_gUnk_030034E0 + (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x68) << 4)), u16 *, 0x72) | 0xB0000), u16 *, 0xAA) * (s8) ((struct PlayerD368 *)arg0)->f71) / 10); + sp134 = (s32) (u16) ((s32) (M2C_FIELD((void *) d368_sub_08007290(M2C_FIELD((d368_gUnk_030034E0 + (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x68)) << 4)), u16 *, SAVE_FIELD(0x72)) | 0xB0000), u16 *, ITEM_FIELD(0xAA)) * (s8) ((struct PlayerD368 *)arg0)->f71) / 10); ((struct PlayerD368 *)arg0)->fDC += 1; goto state0TailD368; } @@ -1778,7 +1800,7 @@ void sub_0800D368(void *arg0) { temp_r1 = (u16 *)((u32)temp_r1 + (u32)temp_r0_29), temp_r0_29 = *temp_r1, (temp_r0_29 != 0)) && (temp_r2_9 = d368_sub_0805D548(temp_r0_29 - 1), temp_r2_9 != -1)) { - sp194 = (s32) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x54); + sp194 = (s32) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x54)); ((struct PlayerD368 *)arg0)->f20 = 6U; ((struct PlayerD368 *)arg0)->f26 = var_r4_11; ((struct PlayerD368 *)arg0)->f24 = var_r4_11; @@ -1882,7 +1904,7 @@ void sub_0800D368(void *arg0) { ((struct PlayerD368 *)arg0)->f26 = temp_r1_21; ((struct PlayerD368 *)arg0)->f24 = temp_r1_21; sp130 = 0; - sp134 = (s32) (u16) ((s32) (M2C_FIELD((void *) d368_sub_08007290(M2C_FIELD((d368_gUnk_030034E0 + (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x68) << 4)), u16 *, 0x72) | 0xB0000), u16 *, 0xAA) * (s8) ((struct PlayerD368 *)arg0)->f71) / 10); + sp134 = (s32) (u16) ((s32) (M2C_FIELD((void *) d368_sub_08007290(M2C_FIELD((d368_gUnk_030034E0 + (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x68)) << 4)), u16 *, SAVE_FIELD(0x72)) | 0xB0000), u16 *, ITEM_FIELD(0xAA)) * (s8) ((struct PlayerD368 *)arg0)->f71) / 10); ((struct PlayerD368 *)arg0)->fDC += 1; } else if ((d368_sub_0800CCCC() == 0) && (var_r4_11 = ((struct PlayerD368 *)arg0)->f30 & 0x3400, (var_r4_11 == 0)) && (sp158 > 0x14U) && (temp_r1 = (u16 *)d368_gUnk_030034E0, temp_r0_33 = ((struct InvD368 *)temp_r1)->f54 * sizeof(u16), @@ -1890,7 +1912,7 @@ void sub_0800D368(void *arg0) { temp_r1 = (u16 *)((u32)temp_r1 + (u32)temp_r0_33), temp_r0_33 = *temp_r1, (temp_r0_33 != 0)) && (temp_r2_12 = d368_sub_0805D548(temp_r0_33 - 1), temp_r2_12 != -1)) { - sp194 = (s32) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x54); + sp194 = (s32) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x54)); ((struct PlayerD368 *)arg0)->f20 = 6U; ((struct PlayerD368 *)arg0)->f26 = var_r4_11; ((struct PlayerD368 *)arg0)->f24 = var_r4_11; @@ -2098,7 +2120,7 @@ void sub_0800D368(void *arg0) { } } ((struct PlayerD368 *)arg0)->fB4 = 0U; - *(u16 *)((arg0 + 0xB4) - 2) = 0; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = 0; sp144 = 0; break; state3ZeroStageD368: @@ -2356,7 +2378,7 @@ void sub_0800D368(void *arg0) { } } ((struct PlayerD368 *)arg0)->fB4 = 0U; - *(u16 *)((arg0 + 0xB4) - 2) = 0; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = 0; sp144 = 0; /* ROM keeps this tail separate */ break; @@ -2507,12 +2529,19 @@ void sub_0800D368(void *arg0) { if (((struct PlayerD368 *)arg0)->f10 != 3) { goto state5Zero66; } +#ifdef REGION_USA + if (directionD36874 == 0) { + goto state5Zero66; + } + goto state5Moving66; +#else goto state5Move66; +#endif case 5: if ((((struct PlayerD368 *)arg0)->f10 == 8) && (directionD36874 != 0)) { ((struct PlayerD368 *)arg0)->f1C = (s16) (directionD36874 - 1); - state5Destination67 = arg0 + 0x94; - var_r5_6 = arg0 + 0x8C; + state5Destination67 = arg0 + PLAYER_FIELD(0x94); + var_r5_6 = arg0 + PLAYER_FIELD(0x8C); *(struct PairD36867 *)state5Destination67 = *(struct PairD36867 *)var_r5_6; d368_sub_08013E90((s32) ((u32) (u16) ((struct PlayerD368 *)arg0)->f40 << 0x10) >> 0x11, var_r5_6, (u16) ((struct PlayerD368 *)arg0)->f1C, (u16) d368_sub_0800CCCC(), (((struct PlayerD368 *)arg0)->f30 & 0x20)); } @@ -2520,10 +2549,15 @@ void sub_0800D368(void *arg0) { break; case 7: if (((struct PlayerD368 *)arg0)->f10 == 1) { +#ifndef REGION_USA state5Move66: +#endif if (directionD36874 != 0) { - state5Destination67 = arg0 + 0x94; - var_r5_6 = arg0 + 0x8C; +#ifdef REGION_USA +state5Moving66: +#endif + state5Destination67 = arg0 + PLAYER_FIELD(0x94); + var_r5_6 = arg0 + PLAYER_FIELD(0x8C); *(struct PairD36867 *)state5Destination67 = *(struct PairD36867 *)var_r5_6; d368_sub_08013E90((s32) ((u32) (u16) ((struct PlayerD368 *)arg0)->f40 << 0x10) >> 0x11, var_r5_6, (u16) (directionD36874 - 1), (u16) d368_sub_0800CCCC(), (((struct PlayerD368 *)arg0)->f30 & 0x20)); } @@ -2584,7 +2618,7 @@ void sub_0800D368(void *arg0) { sp190 = (s32) (u16) (((struct InvD368 *)d368_gUnk_030034E0)->f56[((struct InvD368 *)d368_gUnk_030034E0)->f54] - 1); ((struct PlayerD368 *)arg0)->f20 = 8U; ((struct PlayerD368 *)arg0)->fB4 = temp_r2_14; - *(u16 *)((arg0 + 0xB4) - 2) = temp_r2_14; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = temp_r2_14; sp144 = 0; } else { sp190 = 0xFFFE; @@ -2722,7 +2756,7 @@ void sub_0800D368(void *arg0) { sp190 = (s32) (u16) (((struct InvD368 *)d368_gUnk_030034E0)->f56[((struct InvD368 *)d368_gUnk_030034E0)->f54] - 1); ((struct PlayerD368 *)arg0)->f20 = 8U; ((struct PlayerD368 *)arg0)->fB4 = temp_r2_16; - *(u16 *)((arg0 + 0xB4) - 2) = temp_r2_16; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = temp_r2_16; sp144 = 0; sp158 = 0; } else { @@ -2886,7 +2920,7 @@ void sub_0800D368(void *arg0) { if (((struct PlayerD368 *)arg0)->f10 == 4) { temp_r2_18 = ((struct PlayerD368 *)arg0)->fB2; if (temp_r2_18 != 0) { - if (M2C_FIELD((arg0 + 0xB2), u16 *, 2) == 1) { + if (M2C_FIELD((arg0 + PLAYER_FIELD(0xB2)), u16 *, 2) == 1) { ((struct PlayerD368 *)arg0)->fD8 = 0x200; } var_r1_8 = ((struct PlayerD368 *)arg0)->fD8; @@ -3028,7 +3062,7 @@ void sub_0800D368(void *arg0) { if (temp_r0_77 != 0) { ((struct PlayerD368 *)arg0)->fB8 = 0xFFFDU; ((struct PlayerD368 *)arg0)->fB4 = 0U; - *(u16 *)((arg0 + 0xB4) - 2) = 0; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = 0; ((struct PlayerD368 *)arg0)->f20 = 0xBU; ((struct PlayerD368 *)arg0)->f64 = (u16) ((struct PlayerD368 *)arg0)->fC; if ((d368_sub_0800CCCC() == 0) && (d368_sub_0800CD34() == 0)) { @@ -3053,7 +3087,7 @@ void sub_0800D368(void *arg0) { sp128 = temp_r0_81; switch (temp_r0_81) { case 0: - retryRecord630 = d368_gUnk_030034E0 + 0x100; + retryRecord630 = d368_gUnk_030034E0 + SAVE_FIELD(0x100); if (*(u16 *)retryRecord630 == 0) { sp128 = 3; var_r0_23 = 1; @@ -3061,7 +3095,7 @@ void sub_0800D368(void *arg0) { } goto retry63_0_call; case 1: - retryRecord630 = d368_gUnk_030034E0 + 0x110; + retryRecord630 = d368_gUnk_030034E0 + SAVE_FIELD(0x110); if (*(u16 *)retryRecord630 == 0) { sp128 = 3; var_r0_23 = 2; @@ -3069,7 +3103,7 @@ void sub_0800D368(void *arg0) { } goto retry63_0_call; case 2: - retryRecord630 = d368_gUnk_030034E0 + 0x120; + retryRecord630 = d368_gUnk_030034E0 + SAVE_FIELD(0x120); if (*(u16 *)retryRecord630 == 0) { goto retry63_0_thirdReject; } @@ -3115,33 +3149,33 @@ void sub_0800D368(void *arg0) { temp_r0_83 = ((struct PlayerD368 *)arg0)->fE0 - 1; switch (temp_r0_83) { /* switch 13 */ case 0: /* switch 13 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x24) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x24) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x24) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x24)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x24)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x24)) - 1); } break; case 1: /* switch 13 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x26) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x26) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x26) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x26)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x26)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x26)) - 1); } break; case 2: /* switch 13 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x28) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x28) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x28) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x28)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x28)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x28)) - 1); } break; case 3: /* switch 13 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2A) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2A) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2A) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2A)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2A)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2A)) - 1); } break; case 4: /* switch 13 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2C) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2C) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2C) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2C)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2C)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2C)) - 1); } break; case 5: /* switch 13 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2E) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2E) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2E) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2E)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2E)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2E)) - 1); } break; } @@ -3150,12 +3184,12 @@ void sub_0800D368(void *arg0) { ((struct PlayerD368 *)arg0)->f20 = temp_r0_77; ((struct PlayerD368 *)arg0)->f114 = 0x14U; var_r4_11 = d368_sub_0801DE60(); - if ((var_r4_11 == 5) && !(((struct PlayerD368 *)arg0)->f30 & 0x20000) && (d368_sub_0801E0AC(d368_gUnk_030034E0 + 0x30, 5) != 0) && ((resourceLimitWord319D368 = (u32) ((struct PlayerD368 *)arg0)->f62 << 0x10, (s32) (s16) ((struct PlayerD368 *)arg0)->fC4 < ((s32) resourceLimitWord319D368 >> 0x11)))) { + if ((var_r4_11 == 5) && !(((struct PlayerD368 *)arg0)->f30 & 0x20000) && (d368_sub_0801E0AC(d368_gUnk_030034E0 + SAVE_FIELD(0x30), 5) != 0) && ((resourceLimitWord319D368 = (u32) ((struct PlayerD368 *)arg0)->f62 << 0x10, (s32) (s16) ((struct PlayerD368 *)arg0)->fC4 < ((s32) resourceLimitWord319D368 >> 0x11)))) { var_r6_8 = d368_sub_0801E164(arg0, 5); if (var_r6_8 != 0) { M2C_FIELD(var_r6_8, u16 *, 2) = (u16) ((struct PlayerD368 *)arg0)->f0; M2C_FIELD(var_r6_8, s16 *, 4) = (s16) var_r4_11; - M2C_FIELD(var_r6_8, u16 *, 6) = d368_sub_0801E0AC(d368_gUnk_030034E0 + 0x30, 5); + M2C_FIELD(var_r6_8, u16 *, 6) = d368_sub_0801E0AC(d368_gUnk_030034E0 + SAVE_FIELD(0x30), 5); ((struct EffectD368 *)var_r6_8)->f0 = 0x708; ((struct PlayerD368 *)arg0)->f30 = (u32) (((struct PlayerD368 *)arg0)->f30 | 0x20000); d368_sub_0805867C(0x16F); @@ -3280,8 +3314,8 @@ void sub_0800D368(void *arg0) { } else { if (((struct PlayerD368 *)arg0)->fD8 != 0) { { - struct PairD36867 *previousPairD368 = (struct PairD36867 *)(arg0 + 0x94); - temp_r5_9 = arg0 + 0x8C; + struct PairD36867 *previousPairD368 = (struct PairD36867 *)(arg0 + PLAYER_FIELD(0x94)); + temp_r5_9 = arg0 + PLAYER_FIELD(0x8C); *previousPairD368 = *(struct PairD36867 *)temp_r5_9; } temp_r3_7 = (u16) d368_sub_0800CCCC(); @@ -3292,7 +3326,7 @@ void sub_0800D368(void *arg0) { } d368_sub_080140AC(arg0); if (d368_sub_0800CC98() == 0) { - d368_sub_0800AD04(arg0 + 0x8C, arg0 + 0x90, d368_sub_0800CCCC()); + d368_sub_0800AD04(arg0 + PLAYER_FIELD(0x8C), arg0 + PLAYER_FIELD(0x90), d368_sub_0800CCCC()); } if ((sp13C == 0) && ((s32) ((struct PlayerD368 *)arg0)->f88 != 0)) { sp14C = 0x14; @@ -3346,7 +3380,7 @@ void sub_0800D368(void *arg0) { } else { ((struct PlayerD368 *)arg0)->fB8 = 0xFFFDU; ((struct PlayerD368 *)arg0)->fB4 = temp_r2_19; - temp_r0_90 = (arg0 + 0xB4) - 2; + temp_r0_90 = (arg0 + PLAYER_FIELD(0xB4)) - 2; *temp_r0_90 = temp_r2_19; temp_r1_41 = ((struct PlayerD368 *)arg0)->fC; *(temp_r0_90 - 0x27) = temp_r1_41; @@ -3374,7 +3408,7 @@ void sub_0800D368(void *arg0) { sp128 = temp_r0_91; switch (temp_r0_91) { case 0: - retryRecord631 = d368_gUnk_030034E0 + 0x100; + retryRecord631 = d368_gUnk_030034E0 + SAVE_FIELD(0x100); if (*(u16 *)retryRecord631 != 4) { sp128 = 3; var_r0_27 = 1; @@ -3382,7 +3416,7 @@ void sub_0800D368(void *arg0) { } goto retry63_1_call; case 1: - retryRecord631 = d368_gUnk_030034E0 + 0x110; + retryRecord631 = d368_gUnk_030034E0 + SAVE_FIELD(0x110); if (*(u16 *)retryRecord631 != 3) { sp128 = 3; var_r0_27 = 2; @@ -3390,7 +3424,7 @@ void sub_0800D368(void *arg0) { } goto retry63_1_call; case 2: - retryRecord631 = d368_gUnk_030034E0 + 0x120; + retryRecord631 = d368_gUnk_030034E0 + SAVE_FIELD(0x120); if (*(u16 *)retryRecord631 != 5) { goto retry63_1_thirdReject; } @@ -3412,7 +3446,7 @@ void sub_0800D368(void *arg0) { if (var_r5_8 != 7) { d368_sub_080137A0(sp128); } - d368_sub_0805AD78(M2C_FIELD(sp12C, u16 *, 0x68)); + d368_sub_0805AD78(M2C_FIELD(sp12C, u16 *, SAVE_FIELD(0x68))); d368_sub_0805D094(); d368_sub_0805D0E8(); d368_sub_0805D13C(); @@ -3431,33 +3465,33 @@ void sub_0800D368(void *arg0) { temp_r0_93 = ((struct PlayerD368 *)arg0)->fE0 - 1; switch (temp_r0_93) { /* switch 15 */ case 0: /* switch 15 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x24) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x24) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x24) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x24)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x24)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x24)) - 1); } break; case 1: /* switch 15 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x26) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x26) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x26) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x26)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x26)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x26)) - 1); } break; case 2: /* switch 15 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x28) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x28) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x28) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x28)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x28)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x28)) - 1); } break; case 3: /* switch 15 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2A) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2A) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2A) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2A)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2A)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2A)) - 1); } break; case 4: /* switch 15 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2C) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2C) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2C) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2C)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2C)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2C)) - 1); } break; case 5: /* switch 15 */ - if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2E) > 0) { - M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2E) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x2E) - 1); + if ((s32) (s16) M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2E)) > 0) { + M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2E)) = (u16) (M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x2E)) - 1); } break; } @@ -3610,9 +3644,9 @@ void sub_0800D368(void *arg0) { } else { ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b20_n5.value = ((u32) (0)) >> 4; } - var_r5_10 = arg0 + 0x144; + var_r5_10 = arg0 + PLAYER_FIELD(0x144); ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b14_n3.value = ((u32) (0)) >> 14; - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x3C); + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x3C)); temp_r4_27 = *var_r5_10; temp_r0_102 = d368_sub_0800CCCC(); temp_r0_102 = ((s32) ((0U - (u32) temp_r0_102) | (u32) temp_r0_102) >> 0x1F) & 0x20; @@ -3718,13 +3752,13 @@ void sub_0800D368(void *arg0) { ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b14_n3.value = ((struct PlayerD368 *)arg0)->f26; switch (((struct PlayerD368 *)arg0)->f10) { case 1: - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x3C); + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x3C)); break; case 2: - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x38); + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x38)); break; case 3: - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x34); + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x34)); break; } temp_r4_27 = ((struct PlayerD368 *)arg0)->f144; @@ -3739,17 +3773,17 @@ void sub_0800D368(void *arg0) { ((union RecordD368 *)temp_r4_30)->w1_b0_n6.value = ((s32) ((0U - (u32) temp_r0_107) | (u32) temp_r0_107) >> 0x1F) & 0x20; switch (((struct PlayerD368 *)arg0)->f10) { case 6: - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x34); + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x34)); break; case 8: - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x38); + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x38)); break; } break; case 3: /* switch 18 */ - var_r5_10 = arg0 + 0x144; + var_r5_10 = arg0 + PLAYER_FIELD(0x144); ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b14_n3.value = ((struct PlayerD368 *)arg0)->f26; - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x38); + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x38)); temp_r4_27 = *var_r5_10; temp_r0_102 = d368_sub_0800CCCC(); temp_r0_102 = ((s32) ((0U - (u32) temp_r0_102) | (u32) temp_r0_102) >> 0x1F) & 0x20; @@ -3762,9 +3796,9 @@ void sub_0800D368(void *arg0) { } break; case 2: /* switch 18 */ - var_r5_10 = arg0 + 0x144; + var_r5_10 = arg0 + PLAYER_FIELD(0x144); ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b14_n3.value = ((struct PlayerD368 *)arg0)->f26; - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x3C); + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x3C)); ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b20_n5.value = ((u32) (0)) >> 4; temp_r4_27 = *var_r5_10; temp_r0_102 = d368_sub_0800CCCC(); @@ -3778,9 +3812,9 @@ void sub_0800D368(void *arg0) { } break; case 1: /* switch 18 */ - var_r5_10 = arg0 + 0x144; + var_r5_10 = arg0 + PLAYER_FIELD(0x144); ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b14_n3.value = ((struct PlayerD368 *)arg0)->f26; - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x3C); + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x3C)); temp_r4_27 = *var_r5_10; temp_r0_102 = d368_sub_0800CCCC(); temp_r0_102 = ((s32) ((0U - (u32) temp_r0_102) | (u32) temp_r0_102) >> 0x1F) & 0x20; @@ -3795,7 +3829,7 @@ void sub_0800D368(void *arg0) { case 7: /* switch 18 */ ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b14_n3.value = ((struct PlayerD368 *)arg0)->f26; if (((struct PlayerD368 *)arg0)->f10 == 1) { - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x3C); + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x3C)); } temp_r4_27 = ((struct PlayerD368 *)arg0)->f144; temp_r0_100 = d368_sub_0800CCCC(); @@ -3817,7 +3851,7 @@ void sub_0800D368(void *arg0) { ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b20_n5.value = ((struct PlayerD368 *)arg0)->f26; break; case 9: /* switch 16 */ - var_r5_10 = arg0 + 0x144; + var_r5_10 = arg0 + PLAYER_FIELD(0x144); temp_r2_42 = *var_r5_10; ((union RecordD368 *)temp_r2_42)->w0_b0_n4.value = temp_r3_8; ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w0_b4_n12.value = (s32) ((struct PlayerD368 *)arg0)->f8C >> 8; @@ -3829,7 +3863,7 @@ void sub_0800D368(void *arg0) { } else { ((union RecordD368 *)*var_r5_10)->w1_b25_n3.value = 0; } - var_r5_10 = arg0 + 0x144; + var_r5_10 = arg0 + PLAYER_FIELD(0x144); ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b14_n3.value = ((struct PlayerD368 *)arg0)->f26; recordCallValue1 = d368_sub_0801CCC8(); ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b17_n3.value = recordCallValue1; @@ -3860,7 +3894,7 @@ void sub_0800D368(void *arg0) { case 3: if (d368_sub_0800CDC0() != 0) { - } else if (M2C_FIELD(sp12C, u16 *, 0x48) == 0) { + } else if (M2C_FIELD(sp12C, u16 *, SAVE_FIELD(0x48)) == 0) { } else if (sp19C != 0) { @@ -3869,7 +3903,7 @@ void sub_0800D368(void *arg0) { } else { sp19C = 1; temp_r4_38 = d368_sub_080008C8() % 100U; - if (temp_r4_38 >= (u32) ((d368_sub_0801E0AC(d368_gUnk_030034E0 + 0x30, 5) * 5) + 0xA)) { + if (temp_r4_38 >= (u32) ((d368_sub_0801E0AC(d368_gUnk_030034E0 + SAVE_FIELD(0x30), 5) * 5) + 0xA)) { } else { if (((s32) ((s16) ((struct PlayerD368 *)arg0)->fC4 - M2C_FIELD(&((struct PlayerD368 *)arg0)->f88, u16 *, 0)) > 0) && (temp_r0_114 = ((struct PlayerD368 *)arg0)->f110, (temp_r0_114 != 0))) { @@ -3884,7 +3918,7 @@ void sub_0800D368(void *arg0) { } else { ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b6_n1.value = ((u32) (0)) >> 6; } - var_r1_14 = arg0 + 0x110; + var_r1_14 = arg0 + PLAYER_FIELD(0x110); goto block_1293; } } @@ -3894,7 +3928,7 @@ void sub_0800D368(void *arg0) { sp1A8 = temp_r0_112; if (temp_r0_112 != 0) { - } else if (M2C_FIELD(sp12C, u16 *, 0x44) == 0) { + } else if (M2C_FIELD(sp12C, u16 *, SAVE_FIELD(0x44)) == 0) { } else if ((d368_sub_0800CB9C() != 0) && (gUnk_03003170.curLevel == 0xB)) { @@ -3926,20 +3960,20 @@ void sub_0800D368(void *arg0) { } ((struct PlayerD368 *)arg0)->f110 = (u32) sp1A8; } else { - temp_r1_45 = (0x14C * temp_r2_48) + (u8 *)&d368_gUnk_03003CE0; - temp_r1_44 = M2C_FIELD(temp_r1_45, u8 *, 0x68); + temp_r1_45 = (PLAYER_SIZE * temp_r2_48) + (u8 *)&d368_gUnk_03003CE0; + temp_r1_44 = M2C_FIELD(temp_r1_45, u8 *, PLAYER_FIELD(0x68)); if ((temp_r1_44 != 0) && (temp_r1_44 == ((struct PlayerD368 *)arg0)->f68)) { ((struct LByteD368 { u8 b0, b1, b2, b3; u16 w; } *)&localRecord)->w = ((struct PlayerD368 *)arg0)->f38; ((struct LByteD368 *)&localRecord)->b1 = 0; ((struct LByteD368 *)&localRecord)->b2 = 0x20; - temp_r2_49 = M2C_FIELD(temp_r1_45, void **, 0x148); + temp_r2_49 = M2C_FIELD(temp_r1_45, void **, PLAYER_FIELD(0x148)); angleWordD368 = ((u32) ArcTan2((s16) (((u16) M2C_FIELD(temp_r2_49, u16 *, 0) >> 4) - ((s32) ((struct PlayerD368 *)arg0)->f8C >> 8)), (s16) (((u32) ((u32) M2C_FIELD(temp_r2_49, u16 *, 2) << 0x14) >> 0x14) - ((s32) ((struct PlayerD368 *)arg0)->f90 >> 8))) << 0x10); ((struct LByteD368 *)&localRecord)->b3 = directionTableD368[(angleWordD368 >> 0x1C)]; - ((struct { u8 pad[0xF8]; u32 fF8[4]; } *)temp_r1_45)->fF8[((struct PlayerD368 *)arg0)->f0] = ((struct PlayerD368 *)arg0)->fDC; + ((struct { u8 pad[PLAYER_FIELD(0xF8)]; u32 fF8[4]; } *)temp_r1_45)->fF8[((struct PlayerD368 *)arg0)->f0] = ((struct PlayerD368 *)arg0)->fDC; ((struct LByteD368 *)&localRecord)->b0 = M2C_FIELD(temp_r1_45, u16 *, 0); d368_sub_080660EC((s32 *)&localRecord); } - var_r1_14 = arg0 + 0x110; + var_r1_14 = arg0 + PLAYER_FIELD(0x110); goto block_1293; } @@ -3948,7 +3982,7 @@ void sub_0800D368(void *arg0) { } } else { temp_r4_37 = d368_sub_080008C8() % 100U; - if (temp_r4_37 >= (u32) (d368_sub_0801E0AC(d368_gUnk_030034E0 + 0x30, 4) * 7)) { + if (temp_r4_37 >= (u32) (d368_sub_0801E0AC(d368_gUnk_030034E0 + SAVE_FIELD(0x30), 4) * 7)) { } else if (((s32) ((s16) ((struct PlayerD368 *)arg0)->fC4 - M2C_FIELD(&((struct PlayerD368 *)arg0)->f88, u16 *, 0)) > 0) && (temp_r0_113 = ((struct PlayerD368 *)arg0)->f110, (temp_r0_113 != 0))) { sp19C = 1; @@ -3969,14 +4003,14 @@ void sub_0800D368(void *arg0) { case 7: if (d368_sub_0800CDC0() != 0) { - } else if (M2C_FIELD(sp12C, u16 *, 0x4C) == 0) { + } else if (M2C_FIELD(sp12C, u16 *, SAVE_FIELD(0x4C)) == 0) { } else if (sp19C != 0) { } else { sp19C = 1; temp_r4_39 = (s16) (d368_sub_0800086C() % 100); - if ((s32) temp_r4_39 >= (s32) (d368_sub_0801E0AC(d368_gUnk_030034E0 + 0x30, 6) * 8)) { + if ((s32) temp_r4_39 >= (s32) (d368_sub_0801E0AC(d368_gUnk_030034E0 + SAVE_FIELD(0x30), 6) * 8)) { } else { if (((s32) ((s16) ((struct PlayerD368 *)arg0)->fC4 - M2C_FIELD(&((struct PlayerD368 *)arg0)->f88, u16 *, 0)) > 0) && (temp_r0_115 = ((struct PlayerD368 *)arg0)->f110, (temp_r0_115 != 0))) { @@ -3989,7 +4023,7 @@ void sub_0800D368(void *arg0) { } else { ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b6_n1.value = ((u32) (0)) >> 6; } - var_r1_14 = arg0 + 0x110; + var_r1_14 = arg0 + PLAYER_FIELD(0x110); block_1293: *var_r1_14 = 0; } @@ -4037,11 +4071,11 @@ void sub_0800D368(void *arg0) { temp_r4_46 = ((struct PlayerD368 *)arg0)->f144; temp_r0_119 = d368_sub_0800CCCC(); ((union RecordD368 *)temp_r4_46)->w1_b0_n6.value = ((s32) ((0U - (u32) temp_r0_119) | (u32) temp_r0_119) >> 0x1F) & 0x20; - temp_r0_120 = (void *) d368_sub_08007290(M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x132) | 0x110000); + temp_r0_120 = (void *) d368_sub_08007290(M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x132)) | 0x110000); asm("" : "+r"(temp_r0_120)); { u8 *stD368 = temp_r0_120; - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b11_n8.value = M2C_FIELD(stD368, u32 *, 0xA4) & 0xF; - ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b19_n5.value = (u32) M2C_FIELD(stD368, u32 *, 0xA4) >> 4; } + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b11_n8.value = M2C_FIELD(stD368, u32 *, ITEM_FIELD(0xA4)) & 0xF; + ((union RecordD368 *)((struct PlayerD368 *)arg0)->f144)->w1_b19_n5.value = (u32) M2C_FIELD(stD368, u32 *, ITEM_FIELD(0xA4)) >> 4; } break; } } @@ -4115,7 +4149,7 @@ void sub_0800D368(void *arg0) { sp114 = (u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C; temp_r1_50 = (u8) M2C_FIELD(sp180, u8 *, 3) >> 4; ((struct PlayerD368 *)arg0)->fB0 = (u16) temp_r1_50; - M2C_FIELD((arg0 + 0xB0), s16 *, 8) = (s16) temp_r1_50; + M2C_FIELD((arg0 + PLAYER_FIELD(0xB0)), s16 *, 8) = (s16) temp_r1_50; sp1A4 = (u32) ((u32) M2C_FIELD(sp180, u16 *, 4) << 0x16) >> 0x1C; sp124 = 1; temp_r0_126 = (u8) M2C_FIELD(sp180, u8 *, 6) >> 3; @@ -4148,21 +4182,21 @@ void sub_0800D368(void *arg0) { switch (temp_r0_128) { /* switch 20 */ case 0: /* switch 20 */ if (((struct PlayerD368 *)arg0)->f10 == 9) { - var_r1_17 = 0x50029; + var_r1_17 = RES_ID(0x50029); } else { goto selectorLoad49; } goto selectorCall49; case 5: /* switch 20 */ if (((struct PlayerD368 *)arg0)->f10 == 9) { - var_r1_17 = 0x5001B; + var_r1_17 = RES_ID(0x5001B); } else { goto selectorLoad49; } goto selectorCall49; case 1: /* switch 20 */ if (((struct PlayerD368 *)arg0)->f10 == 9) { - var_r1_17 = 0x5009D; + var_r1_17 = RES_ID(0x5009D); } else { goto selectorLoad49; } @@ -4170,14 +4204,14 @@ void sub_0800D368(void *arg0) { case 6: /* switch 20 */ temp_r1_51 = ((struct PlayerD368 *)arg0)->f10; if (temp_r1_51 == 9) { - var_r1_17 = 0x5009C; + var_r1_17 = RES_ID(0x5009C); } else { var_r1_17 = animationRows338D368[((struct PlayerD368 *)arg0)->f64][temp_r1_51]; } goto selectorCall49; case 7: /* switch 20 */ if (((struct PlayerD368 *)arg0)->f10 == 9) { - var_r1_17 = 0x50088; + var_r1_17 = RES_ID(0x50088); } else { goto selectorLoad49; } @@ -4196,7 +4230,7 @@ void sub_0800D368(void *arg0) { sp114 = (u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C; temp_r1_52 = (u8) M2C_FIELD(sp180, u8 *, 3) >> 4; ((struct PlayerD368 *)arg0)->fB0 = (u16) temp_r1_52; - M2C_FIELD((arg0 + 0xB0), s16 *, 8) = (s16) temp_r1_52; + M2C_FIELD((arg0 + PLAYER_FIELD(0xB0)), s16 *, 8) = (s16) temp_r1_52; sp1A4 = (u32) ((u32) M2C_FIELD(sp180, u16 *, 4) << 0x16) >> 0x1C; sp124 = 1; break; @@ -4207,7 +4241,7 @@ void sub_0800D368(void *arg0) { sp114 = (u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C; temp_r1_53 = ((u8) M2C_FIELD(sp180, u8 *, 3) >> 4) + 8; ((struct PlayerD368 *)arg0)->fB0 = temp_r1_53; - M2C_FIELD((arg0 + 0xB0), u16 *, 8) = temp_r1_53; + M2C_FIELD((arg0 + PLAYER_FIELD(0xB0)), u16 *, 8) = temp_r1_53; sp124 = 1; sp1A4 = (u32) ((u32) M2C_FIELD(sp180, u16 *, 4) << 0x16) >> 0x1C; break; @@ -4217,7 +4251,7 @@ void sub_0800D368(void *arg0) { } else { d368_sub_08065158(&sp10, animationRows343D368[((struct PlayerD368 *)arg0)->f64].second[((struct PlayerD368 *)arg0)->f10], 0, -1, (0)); ((struct PlayerD368 *)arg0)->fB4 = 0U; - *(u16 *)((arg0 + 0xB4) - 2) = 0; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = 0; sp114 = (u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C; temp_r0_129 = (u8) M2C_FIELD(sp180, u8 *, 3) >> 4; ((struct PlayerD368 *)arg0)->fB0 = (u16) temp_r0_129; @@ -4277,7 +4311,7 @@ void sub_0800D368(void *arg0) { } else if (temp_r0_134 != 9) { } else { - d368_sub_08065158(&sp10, 0x5011A, 0, -1, (0)); + d368_sub_08065158(&sp10, RES_ID(0x5011A), 0, -1, (0)); } sp1A4 = ((union RecordD368 *)sp180)->w1_b6_n4.value; break; @@ -4299,7 +4333,7 @@ void sub_0800D368(void *arg0) { } break; case 9: - d368_sub_08065158(&sp10, 0x5011D, 0, -1, (0)); + d368_sub_08065158(&sp10, RES_ID(0x5011D), 0, -1, (0)); break; } break; @@ -4310,7 +4344,7 @@ void sub_0800D368(void *arg0) { temp_r0_136 = ((struct PlayerD368 *)arg0)->f10; if (temp_r0_136 != 5) { if (temp_r0_136 == 9) { - d368_sub_08065158(&sp10, 0x500E9, 0, -1, (0)); + d368_sub_08065158(&sp10, RES_ID(0x500E9), 0, -1, (0)); } } @@ -4323,7 +4357,7 @@ void sub_0800D368(void *arg0) { temp_r0_137 = ((struct PlayerD368 *)arg0)->f10; if (temp_r0_137 != 5) { if (temp_r0_137 == 9) { - d368_sub_08065158(&sp10, 0x500F5, 0, -1, (0)); + d368_sub_08065158(&sp10, RES_ID(0x500F5), 0, -1, (0)); } } @@ -4342,7 +4376,7 @@ void sub_0800D368(void *arg0) { } break; case 9: - d368_sub_08065158(&sp10, 0x5012C, 0, -1, (0)); + d368_sub_08065158(&sp10, RES_ID(0x5012C), 0, -1, (0)); break; } break; @@ -4350,7 +4384,7 @@ void sub_0800D368(void *arg0) { temp_r0_139 = ((struct PlayerD368 *)arg0)->f10; if (temp_r0_139 != 5) { if (temp_r0_139 == 9) { - d368_sub_08065158(&sp10, 0x50128, 0, -1, (0)); + d368_sub_08065158(&sp10, RES_ID(0x50128), 0, -1, (0)); } } @@ -4393,7 +4427,7 @@ void sub_0800D368(void *arg0) { } d368_sub_08065158(&sp10, animationRows343D368[((struct PlayerD368 *)arg0)->f64].second[((struct PlayerD368 *)arg0)->f10], 0, -1, (0)); ((struct PlayerD368 *)arg0)->fB4 = 0U; - *(u16 *)((arg0 + 0xB4) - 2) = 0; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = 0; sp114 = (u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C; ((struct PlayerD368 *)arg0)->fB0 = (u16) ((u8) M2C_FIELD(sp180, u8 *, 3) >> 4); temp_r0_140 = ((struct PlayerD368 *)arg0)->fC; @@ -4511,7 +4545,7 @@ void sub_0800D368(void *arg0) { } else { d368_sub_08065158(&sp10, animationRows338D368[((struct PlayerD368 *)arg0)->f64][((struct PlayerD368 *)arg0)->f10], 0, -1, (0)); ((struct PlayerD368 *)arg0)->fB4 = 0U; - *(u16 *)((arg0 + 0xB4) - 2) = 0; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = 0; sp114 = (u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C; temp_r0_147 = (u8) M2C_FIELD(sp180, u8 *, 3) >> 4; ((struct PlayerD368 *)arg0)->fB0 = (u16) temp_r0_147; @@ -4537,7 +4571,7 @@ void sub_0800D368(void *arg0) { } else { d368_sub_08065158(&sp10, animationRows343D368[((struct PlayerD368 *)arg0)->f64].second[((struct PlayerD368 *)arg0)->f10], 0, -1, (0)); ((struct PlayerD368 *)arg0)->fB4 = 0U; - *(u16 *)((arg0 + 0xB4) - 2) = 0; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = 0; sp114 = (u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C; temp_r0_149 = ((u8) M2C_FIELD(sp180, u8 *, 3) >> 4) + 8; ((struct PlayerD368 *)arg0)->fB0 = temp_r0_149; @@ -4557,7 +4591,7 @@ void sub_0800D368(void *arg0) { } else { d368_sub_08065158(&sp10, animationRows338D368[((struct PlayerD368 *)arg0)->f64][((struct PlayerD368 *)arg0)->f10], 0, -1, (0)); ((struct PlayerD368 *)arg0)->fB4 = 0U; - *(u16 *)((arg0 + 0xB4) - 2) = 0; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = 0; sp114 = (u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C; temp_r0_151 = ((u8) M2C_FIELD(sp180, u8 *, 3) >> 4) + 0x10; ((struct PlayerD368 *)arg0)->fB0 = temp_r0_151; @@ -4582,10 +4616,10 @@ void sub_0800D368(void *arg0) { } } else if (temp_r0_153 == 8) { block_1544: - d368_sub_08065158(&sp10, 0x500DA, 0, -1, (0)); + d368_sub_08065158(&sp10, RES_ID(0x500DA), 0, -1, (0)); } } else { - d368_sub_08065158(&sp10, 0x500D9, 0, -1, (sp124)); + d368_sub_08065158(&sp10, RES_ID(0x500D9), 0, -1, (sp124)); } temp_r0_154 = (u8) M2C_FIELD(sp180, u8 *, 3) >> 4; ((struct PlayerD368 *)arg0)->fB0 = (u16) temp_r0_154; @@ -4604,7 +4638,7 @@ void sub_0800D368(void *arg0) { if ((((struct PlayerD368 *)arg0)->fB0 != ((struct PlayerD368 *)arg0)->fB8) || (((u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C) != sp114)) { d368_sub_08065158(&sp10, animationRows338D368[((struct PlayerD368 *)arg0)->f64][((struct PlayerD368 *)arg0)->f10], 0, -1, (0)); ((struct PlayerD368 *)arg0)->fB4 = 0U; - *(u16 *)((arg0 + 0xB4) - 2) = 0; + *(u16 *)((arg0 + PLAYER_FIELD(0xB4)) - 2) = 0; sp114 = (u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C; temp_r0_155 = ((u8) M2C_FIELD(sp180, u8 *, 3) >> 4) + 0x18; ((struct PlayerD368 *)arg0)->fB0 = temp_r0_155; @@ -4631,7 +4665,7 @@ void sub_0800D368(void *arg0) { } if (((struct PlayerD368 *)arg0)->f30 & 0x2000) { ((struct PlayerD368 *)arg0)->fA4 = -1; - M2C_FIELD((arg0 + 0xA4), s32 *, 4) = -1; + M2C_FIELD((arg0 + PLAYER_FIELD(0xA4)), s32 *, 4) = -1; } } d368_sub_080657C4(((struct PlayerD368 *)arg0)->f0, 0); @@ -4698,7 +4732,7 @@ void sub_0800D368(void *arg0) { } else if (d368_sub_0800CD8C() != 0) { } else if (sp15C == 1) { - lookupStats = (void *) d368_sub_08007290(M2C_FIELD(d368_gUnk_030034E0, u16 *, 0x132) | 0x110000); + lookupStats = (void *) d368_sub_08007290(M2C_FIELD(d368_gUnk_030034E0, u16 *, SAVE_FIELD(0x132)) | 0x110000); temp_r1_55 = ((struct PlayerD368 *)arg0)->f148; if (((u8) M2C_FIELD(temp_r1_55, u8 *, 6) >> 3) == 6) { var_r5 = 1; @@ -4709,9 +4743,9 @@ void sub_0800D368(void *arg0) { } var_r4_11 = 0; for (sp128 = 0; sp128 < d368_sub_08002164(); sp128++) { - u8 *plD = (u8 *)&d368_gUnk_03003CE0; temp_r1_56 = 0x14C * sp128; - temp_r2_63 = *(void **)(temp_r1_56 + ((u8 *)&d368_gUnk_03003CE0 + 0x148)); - if ((((u32) ((u32) M2C_FIELD(temp_r2_63, u8 *, 0) << 0x1C) >> 0x1C) == 0xE) && (*(u16 *)(temp_r1_56 + plD + 0xB6) != 0)) { + u8 *plD = (u8 *)&d368_gUnk_03003CE0; temp_r1_56 = PLAYER_SIZE * sp128; + temp_r2_63 = *(void **)(temp_r1_56 + ((u8 *)&d368_gUnk_03003CE0 + PLAYER_FIELD(0x148))); + if ((((u32) ((u32) M2C_FIELD(temp_r2_63, u8 *, 0) << 0x1C) >> 0x1C) == 0xE) && (*(u16 *)(temp_r1_56 + plD + PLAYER_FIELD(0xB6)) != 0)) { if (((u8) M2C_FIELD(temp_r2_63, u8 *, 6) >> 3) == 6) { var_r4_11 += 1; if (var_r5 != 0) { @@ -4723,7 +4757,7 @@ void sub_0800D368(void *arg0) { } } if (var_r4_11 == d368_sub_0800CBCC()) { - d368_sub_08067F94((u32) M2C_FIELD(lookupStats, u32 *, 0xA4) >> 4, var_r6_8, var_r4_11); + d368_sub_08067F94((u32) M2C_FIELD(lookupStats, u32 *, ITEM_FIELD(0xA4)) >> 4, var_r6_8, var_r4_11); d368_sub_0800CBEC(); } } @@ -4732,7 +4766,7 @@ void sub_0800D368(void *arg0) { d368_sub_08065158(&sp10, animationRows338D368[((struct PlayerD368 *)arg0)->f64][0], 0, -1, (0)); sp114 = (u32) ((u32) M2C_FIELD(sp180, u8 *, 0) << 0x1C) >> 0x1C; ((struct PlayerD368 *)arg0)->fB0 = 0x21U; - M2C_FIELD((arg0 + 0xB0), s16 *, 8) = 0x21; + M2C_FIELD((arg0 + PLAYER_FIELD(0xB0)), s16 *, 8) = 0x21; sp124 = 1; break; } @@ -4759,7 +4793,7 @@ void sub_0800D368(void *arg0) { } else { sp10.f1C = (s8) ((struct PlayerD368 *)arg0)->f0; if (!(0x200 & M2C_FIELD(d368_gUnk_03005CF4, u16 *, 4))) { - ((struct PlayerD368 *)arg0)->fB6 = (u16) d368_sub_08065370(&sp10, ((struct PlayerD368 *)arg0)->fB0, arg0 + 0xB2, arg0 + 0xB4, (sp124)); + ((struct PlayerD368 *)arg0)->fB6 = (u16) d368_sub_08065370(&sp10, ((struct PlayerD368 *)arg0)->fB0, arg0 + PLAYER_FIELD(0xB2), arg0 + PLAYER_FIELD(0xB4), (sp124)); } if (((struct PlayerD368 *)arg0)->f20 != 0xD) { if (((struct PlayerD368 *)arg0)->f11E != 0) { @@ -4796,13 +4830,13 @@ void sub_0800D368(void *arg0) { temp_r0_162 = M2C_FIELD(d368_gUnk_03006440, u32 *, 0); switch (temp_r0_162) { case 1: - d368_sub_08007870(0x5C, 0x48, ((struct PlayerD368 *)arg0)->fB0, M2C_FIELD((arg0 + 0xB0), u16 *, 2), 3, &sp10.f1C, sp10.f8, sp10.f0); + d368_sub_08007870(0x5C, 0x48, ((struct PlayerD368 *)arg0)->fB0, M2C_FIELD((arg0 + PLAYER_FIELD(0xB0)), u16 *, 2), 3, &sp10.f1C, sp10.f8, sp10.f0); break; case 2: case 3: case 4: case 6: - d368_sub_08007870(0x24, 0x54, ((struct PlayerD368 *)arg0)->fB0, M2C_FIELD((arg0 + 0xB0), u16 *, 2), 3, &sp10.f1C, sp10.f8, sp10.f0); + d368_sub_08007870(0x24, 0x54, ((struct PlayerD368 *)arg0)->fB0, M2C_FIELD((arg0 + PLAYER_FIELD(0xB0)), u16 *, 2), 3, &sp10.f1C, sp10.f8, sp10.f0); break; } } @@ -5419,10 +5453,10 @@ void sub_0800D368(void *arg0) { * +0x34 -> 8 x 0x28 byte slots, +0xAC -> 0x100 byte buffer, +0x13C/+0x140 -> local player template data, * +0x144 -> this slot's link SEND block (sub_08002118), +0x148 -> RECV block (sub_08002238). * The entity runs as task sub_0800D368 (per-player update), stack 0x680 (remote) or gUnk_03003590 (local). */ -struct T6Template135C4 { u8 pad[10]; u16 fA, fC; }; +struct T6Template135C4 { u8 pad[SAVE_FIELD(0xA)]; u16 fA, fC; }; extern struct T6Template135C4 *t6_template135 asm("gUnk_030034E0"); struct T6Slot135 { u16 f0; u8 pad[6]; u8 f8[0x20]; }; -struct T6Player135 { u16 f0; u8 f2; u8 pad3[9]; u16 fC, fE; u8 pad10[0x10]; u16 f20; u8 pad22[0x12]; struct T6Slot135 *f34; u8 pad38[0x74]; void *fAC; u8 padB0[0x86]; u16 f136; u8 pad138[4]; void *f13C; void *f140; void *f144, *f148; }; +struct T6Player135 { u16 f0; NameChar f2; u8 pad3[PLAYER_FIELD(0xC) - 2 - sizeof(NameChar)]; u16 fC, fE; u8 pad10[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x10)]; u16 f20; u8 pad22[PLAYER_FIELD(0x34) - PLAYER_FIELD(0x22)]; struct T6Slot135 *f34; u8 pad38[PLAYER_FIELD(0xAC) - PLAYER_FIELD(0x38)]; void *fAC; u8 padB0[PLAYER_FIELD(0x136) - PLAYER_FIELD(0xB0)]; u16 f136; u8 pad138[PLAYER_FIELD(0x13C) - PLAYER_FIELD(0x138)]; void *f13C; void *f140; void *f144, *f148; }; extern struct T6Player135 t6_players135[] asm("gUnk_03003CE0"); struct T6Task135 { u32 f0, f4, f8; void (*fC)(void); u8 *f10; u32 f14, f18, f1C; void *f20; u32 f24; }; extern struct T6Task135 t6_tasks135[] asm("gUnk_030034F0"); @@ -5448,7 +5482,7 @@ void sub_080135C4(u16 id) { stack = sub_08001494(0x680); t6_tasks135[id].f20 = stack; t6_players135[id].f13C = 0; - pl->f2 = 0xFE; + pl->f2 = TEXT_CTRL(0xFE); } else { t6_players135[id].f140 = t6_template135; pl->f20 = 0; @@ -5475,7 +5509,7 @@ void sub_080135C4(u16 id) { t6_tasks135[id].f24 = 0; t6_start135(&t6_tasks135[id], &t6_players135[id]); } -struct Team6State137A0 { u8 pad[0x100]; u16 a, b; u8 c[12]; u16 d, e; u8 f[12]; u16 g, h; u8 j[12]; }; +struct Team6State137A0 { u8 pad[PLAYER_FIELD(0x100)]; u16 a, b; u8 c[12]; u16 d, e; u8 f[12]; u16 g, h; u8 j[12]; }; extern struct Team6State137A0 *team6_state137A0 asm("gUnk_030034E0"); /* [ClearSelectedEquipmentRecord] Writes zero type/id halfwords plus12 bytes at local save100/110/120 for * selectors0/1/2 respectively. */ @@ -5504,10 +5538,10 @@ void sub_080137A0(u32 arg0) { } struct Rec13850 { u16 a, b; u8 c[12]; }; struct State13850 { - u8 b0[10]; + NameChar b0[10]; u16 wA; u16 wC; - u16 padE; + u8 padE[SAVE_FIELD(0x10) - SAVE_FIELD(0xE)]; u16 w10, w12, w14, w16, w18, w1A; u8 pad1C[8]; u8 o24[0xC]; @@ -5536,12 +5570,12 @@ struct Data13850 { u8 b1C6[10],b1D0[10]; }; struct P13850 { - u16 h0; u8 p2[0x10]; u16 h12, h14; u8 p16[6]; u16 h1C; u8 p1E[2]; u16 h20, h22, h24; u8 p26[4]; u16 h2A; - u8 p2C[4]; u32 l30; u8 p34[4]; u16 h38, h3A, h3C, h3E, h40; u8 p42[10]; u8 o4C[0xC]; - u16 h58, h5A; u8 p5C[4]; u16 h60, h62, h64; u8 b66; u8 p67[0x10]; u8 b77, b78; u8 p79[3]; - u8 o7C[0x10]; u32 l8C, l90; u8 p94[0xC2-0x94]; u16 hC2, hC4, hC6, hC8, hCA; u8 pCC[0xDC-0xCC]; - u32 lDC; u8 pE0[4]; u32 e4[5]; u32 f8[4]; u8 p108[0x116-0x108]; u16 h116; u8 p118[0x138-0x118]; - u32 l138; u8 p13C[4]; u32 l140; u32 l144; u8 p148[4]; + u16 h0; u8 p2[PLAYER_FIELD(0x12) - 0x2]; u16 h12, h14; u8 p16[PLAYER_FIELD(0x1C) - PLAYER_FIELD(0x16)]; u16 h1C; u8 p1E[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x1E)]; u16 h20, h22, h24; u8 p26[PLAYER_FIELD(0x2A) - PLAYER_FIELD(0x26)]; u16 h2A; + u8 p2C[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x2C)]; u32 l30; u8 p34[PLAYER_FIELD(0x38) - PLAYER_FIELD(0x34)]; u16 h38, h3A, h3C, h3E, h40; u8 p42[PLAYER_FIELD(0x4C) - PLAYER_FIELD(0x42)]; u8 o4C[0xC]; + u16 h58, h5A; u8 p5C[PLAYER_FIELD(0x60) - PLAYER_FIELD(0x5C)]; u16 h60, h62, h64; u8 b66; u8 p67[PLAYER_FIELD(0x77) - PLAYER_FIELD(0x67)]; u8 b77, b78; u8 p79[PLAYER_FIELD(0x7C) - PLAYER_FIELD(0x79)]; + u8 o7C[0x10]; u32 l8C, l90; u8 p94[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0x94)]; u16 hC2, hC4, hC6, hC8, hCA; u8 pCC[PLAYER_FIELD(0xDC) - PLAYER_FIELD(0xCC)]; + u32 lDC; u8 pE0[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xE0)]; u32 e4[5]; u32 f8[4]; u8 p108[PLAYER_FIELD(0x116) - PLAYER_FIELD(0x108)]; u16 h116; u8 p118[PLAYER_FIELD(0x138) - PLAYER_FIELD(0x118)]; + u32 l138; u8 p13C[PLAYER_FIELD(0x140) - PLAYER_FIELD(0x13C)]; u32 l140; u32 l144; u8 p148[PLAYER_SIZE - PLAYER_FIELD(0x148)]; }; extern struct P13850 pl13850[] asm("gUnk_03003CE0"); extern struct State13850 *st13850 asm("gUnk_030034E0"); @@ -5557,7 +5591,7 @@ void sub_08013850(void) u32 i, j, k; sub_08001538((s32)st13850); sub_08001538((s32)dt13850); - st13850 = sub_08001494(0xCA4); + st13850 = sub_08001494(SAVE_FIELD(0xCA4)); dt13850 = sub_08001494(0x51C); s = st13850; for (i = 0; i < 4; i++) { @@ -5595,7 +5629,7 @@ void sub_08013850(void) p->l90 = 0; p->lDC = 0; p->h116 = 0; - *(u16 *)((u8 *)p + 0x88) = 0; + *(u16 *)((u8 *)p + PLAYER_FIELD(0x88)) = 0; p->l140 = 0; p->l144 = 0; p->l138 = 0; @@ -5692,27 +5726,27 @@ s32 sub_08013BC0(u8 *arg0) { s32 m; r = sub_0800D1B0(); if (r == 0) { - p = (u16 *)(arg0 + 0xC4); - q = (u16 *)(arg0 + 0x88); + p = (u16 *)(arg0 + PLAYER_FIELD(0xC4)); + q = (u16 *)(arg0 + PLAYER_FIELD(0x88)); *p = *p - *q; - s = (u16 *)(arg0 + 0x8A); + s = (u16 *)(arg0 + PLAYER_FIELD(0x8A)); *p = *p - *s; *q = r; *s = r; m = *(s16 *)p & 0x8000; if (m != 0 || *(s16 *)p == 0) { - if ((*(u32 *)(arg0 + 0x30) & 0x100000) == 0) { + if ((*(u32 *)(arg0 + PLAYER_FIELD(0x30)) & 0x100000) == 0) { *p = 0; return 1; } *p = 1; return 0; } - *(u32 *)(arg0 + 0xE0) = m; + *(u32 *)(arg0 + PLAYER_FIELD(0xE0)) = m; return 0; } else { - *(u16 *)(arg0 + 0x88) = 0; - *(u16 *)(arg0 + 0x8A) = 0; + *(u16 *)(arg0 + PLAYER_FIELD(0x88)) = 0; + *(u16 *)(arg0 + PLAYER_FIELD(0x8A)) = 0; } return 0; } @@ -5724,11 +5758,11 @@ void sub_08013C3C(u8 *arg0) { u16 i = 0; u32 one = 1; u32 lim = 0x800; - u8 *base = arg0 + 0x126; + u8 *base = arg0 + PLAYER_FIELD(0x126); do { if (((gUnk_03002344 & one) == (i & one)) && (gUnk_030056FC & (one << i))) { - u16 a = ArcTan2((*(s32 *)(p + 0x14) - *(s32 *)(arg0 + 0x8C)) << 8 >> 16, - (*(s32 *)(p + 0x18) - *(s32 *)(arg0 + 0x90)) << 8 >> 16); + u16 a = ArcTan2((*(s32 *)(p + 0x14) - *(s32 *)(arg0 + PLAYER_FIELD(0x8C))) << 8 >> 16, + (*(s32 *)(p + 0x18) - *(s32 *)(arg0 + PLAYER_FIELD(0x90))) << 8 >> 16); if ((a & 0xFFF) > lim) { *(u16 *)(base + (i << 1)) = (a >> 12) + 1; } else { @@ -5737,7 +5771,7 @@ void sub_08013C3C(u8 *arg0) { *(u16 *)(base + (i << 1)) &= 0xF; } i++; - p += 0x2E0; + p += ENEMY_SIZE; } while (i <= 4); } struct Box13CEC { u32 w:16; u32 h:16; }; @@ -5757,11 +5791,11 @@ void sub_08013CEC(u8 *arg0) u32 hit; s32 busy; *(u32 *)&size = 0x00100010; - if (*(u32 *)(arg0 + 0x30) & 0x20) + if (*(u32 *)(arg0 + PLAYER_FIELD(0x30)) & 0x20) return; busy = sub_0800CCCC(); - pos = (s32 *)(arg0 + 0x8C); - if (busy == 0 && !(*(u32 *)(arg0 + 0x30) & 0x40000)) { + pos = (s32 *)(arg0 + PLAYER_FIELD(0x8C)); + if (busy == 0 && !(*(u32 *)(arg0 + PLAYER_FIELD(0x30)) & 0x40000)) { e = gUnk_030056F4; i = 0; do { @@ -5769,51 +5803,51 @@ void sub_08013CEC(u8 *arg0) goto next; if ((u16)(*(u16 *)(e + 0xC) - 0xB) <= 1) goto next; - box.w = e[0x22E]; + box.w = e[ENEMY_FIELD(0x22E)]; if (box.w == 0) goto next; - box.h = e[0x22F]; + box.h = e[ENEMY_FIELD(0x22F)]; if (test13CEC(pos, (s32 *)(e + 0x14), &size, &box) == 0) goto next; hit = 0; - switch (*(s16 *)(arg0 + 0x1C)) { + switch (*(s16 *)(arg0 + PLAYER_FIELD(0x1C))) { case 0: - if (*(s32 *)(arg0 + 0x90) < *(s32 *)(e + 0x18)) hit = 1; + if (*(s32 *)(arg0 + PLAYER_FIELD(0x90)) < *(s32 *)(e + 0x18)) hit = 1; break; case 1: - if (*(s32 *)(arg0 + 0x90) < *(s32 *)(e + 0x18) && *pos > *(s32 *)(e + 0x14)) hit = 1; + if (*(s32 *)(arg0 + PLAYER_FIELD(0x90)) < *(s32 *)(e + 0x18) && *pos > *(s32 *)(e + 0x14)) hit = 1; break; case 2: if (*pos > *(s32 *)(e + 0x14)) hit = 1; break; case 3: - if (*(s32 *)(arg0 + 0x90) > *(s32 *)(e + 0x18) && *pos > *(s32 *)(e + 0x14)) hit = 1; + if (*(s32 *)(arg0 + PLAYER_FIELD(0x90)) > *(s32 *)(e + 0x18) && *pos > *(s32 *)(e + 0x14)) hit = 1; break; case 4: - if (*(s32 *)(arg0 + 0x90) > *(s32 *)(e + 0x18)) hit = 1; + if (*(s32 *)(arg0 + PLAYER_FIELD(0x90)) > *(s32 *)(e + 0x18)) hit = 1; break; case 5: - if (*(s32 *)(arg0 + 0x90) > *(s32 *)(e + 0x18) && *pos < *(s32 *)(e + 0x14)) hit = 1; + if (*(s32 *)(arg0 + PLAYER_FIELD(0x90)) > *(s32 *)(e + 0x18) && *pos < *(s32 *)(e + 0x14)) hit = 1; break; case 6: if (*pos < *(s32 *)(e + 0x14)) hit = 1; break; case 7: - if (*(s32 *)(arg0 + 0x90) < *(s32 *)(e + 0x18) && *pos < *(s32 *)(e + 0x14)) hit = 1; + if (*(s32 *)(arg0 + PLAYER_FIELD(0x90)) < *(s32 *)(e + 0x18) && *pos < *(s32 *)(e + 0x14)) hit = 1; break; } if (hit) { - *pos = *(s32 *)(arg0 + 0x94); - *(s32 *)(arg0 + 0x90) = *(s32 *)(arg0 + 0x98); + *pos = *(s32 *)(arg0 + PLAYER_FIELD(0x94)); + *(s32 *)(arg0 + PLAYER_FIELD(0x90)) = *(s32 *)(arg0 + PLAYER_FIELD(0x98)); } next: i = (u16)(i + 1); - e += 0x2E0; + e += ENEMY_SIZE; } while (i <= 4); } if (blk13CEC(pos)) { - *pos = *(s32 *)(arg0 + 0x94); - *(s32 *)(arg0 + 0x90) = *(s32 *)(arg0 + 0x98); + *pos = *(s32 *)(arg0 + PLAYER_FIELD(0x94)); + *(s32 *)(arg0 + PLAYER_FIELD(0x90)) = *(s32 *)(arg0 + PLAYER_FIELD(0x98)); } } /* [MovePositionWithMapCollision] Computes sine-based candidate using divisor304 for vertical directions0/4 @@ -5874,43 +5908,43 @@ void sub_080140AC(u8 *arg0) { u16 t; s32 v; s16 r; - if ((*(u16 *)(arg0 + 0xC8)) != 0) { - sub_08013E90((*(s16 *)(arg0 + 0xCC)), arg0 + 0x8C, (*(u16 *)(arg0 + 0xCA)), (u16)sub_0800CCCC(), 0); - (*(u16 *)(arg0 + 0xC8))--; + if ((*(u16 *)(arg0 + PLAYER_FIELD(0xC8))) != 0) { + sub_08013E90((*(s16 *)(arg0 + PLAYER_FIELD(0xCC))), arg0 + PLAYER_FIELD(0x8C), (*(u16 *)(arg0 + PLAYER_FIELD(0xCA))), (u16)sub_0800CCCC(), 0); + (*(u16 *)(arg0 + PLAYER_FIELD(0xC8)))--; } - if ((*(u16 *)(arg0 + 0xCE)) != 0) { - sub_08013E90((*(s16 *)(arg0 + 0xD2)), arg0 + 0x8C, (*(u16 *)(arg0 + 0xD0)), (u16)sub_0800CCCC(), 0); - v = (*(u16 *)(arg0 + 0xCE)) - 1; - (*(u16 *)(arg0 + 0xCE)) = v; + if ((*(u16 *)(arg0 + PLAYER_FIELD(0xCE))) != 0) { + sub_08013E90((*(s16 *)(arg0 + PLAYER_FIELD(0xD2))), arg0 + PLAYER_FIELD(0x8C), (*(u16 *)(arg0 + PLAYER_FIELD(0xD0))), (u16)sub_0800CCCC(), 0); + v = (*(u16 *)(arg0 + PLAYER_FIELD(0xCE))) - 1; + (*(u16 *)(arg0 + PLAYER_FIELD(0xCE))) = v; t = (u16)v; if (t == 0) { - if ((*(s16 *)(arg0 + 0xD4)) != 0) { - (*(u16 *)(arg0 + 0xCE)) = (*(s16 *)(arg0 + 0xD4)) / 2; - if ((*(u16 *)(arg0 + 0xCE)) > 3) (*(u16 *)(arg0 + 0xCE)) = 4; - (*(s16 *)(arg0 + 0xD4)) = t; + if ((*(s16 *)(arg0 + PLAYER_FIELD(0xD4))) != 0) { + (*(u16 *)(arg0 + PLAYER_FIELD(0xCE))) = (*(s16 *)(arg0 + PLAYER_FIELD(0xD4))) / 2; + if ((*(u16 *)(arg0 + PLAYER_FIELD(0xCE))) > 3) (*(u16 *)(arg0 + PLAYER_FIELD(0xCE))) = 4; + (*(s16 *)(arg0 + PLAYER_FIELD(0xD4))) = t; r = 0x200; goto end; } - } else if ((*(s16 *)(arg0 + 0xD4)) != 0) { + } else if ((*(s16 *)(arg0 + PLAYER_FIELD(0xD4))) != 0) { return; } - (*(s16 *)(arg0 + 0xD2)) = (u16)(*(s16 *)(arg0 + 0xD2)) << 16 >> 17; - if ((*(s16 *)(arg0 + 0xD2)) <= 0x3F) { + (*(s16 *)(arg0 + PLAYER_FIELD(0xD2))) = (u16)(*(s16 *)(arg0 + PLAYER_FIELD(0xD2))) << 16 >> 17; + if ((*(s16 *)(arg0 + PLAYER_FIELD(0xD2))) <= 0x3F) { r = 0x40; end: - (*(s16 *)(arg0 + 0xD2)) = r; + (*(s16 *)(arg0 + PLAYER_FIELD(0xD2))) = r; } } } struct Actor14170 { - u8 pad0[0x10]; + u8 pad0[PLAYER_FIELD(0x10)]; u16 f10; - u8 pad12[0xE]; + u8 pad12[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x12)]; u16 f20; u8 pad22[0x2]; u16 f24; u16 f26; - u8 pad28[0x8]; + u8 pad28[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x28)]; u32 f30; u8 pad34[0x2C]; s16 f60; @@ -5952,6 +5986,393 @@ void hud14170(struct Actor14170 *arg0) asm("sub_08014170"); * the displays. */ void hud14170(struct Actor14170 *arg0) { +#ifdef REGION_USA + u8 spr1[0x34]; + u8 spr2[0x34]; + u8 pad[8]; + struct Nib14170 a; + struct Nib14170 b; + struct Nib14170 c; + s16 sx; + s16 sy; + u16 tile; + u16 tmp; + struct Rgb14170 color; + struct Tile14170 *buf1; + struct Tile14170 *buf2; + struct Tile14170 *buf3; + s32 pal; + s32 gfx; + u16 fade; + u16 blink; + u16 dhp, dmp, dx3; + u16 mhp, mmp, mx3; + + u16 i; + u16 lim; + u32 k; + register u32 loadedCapacity asm("r0"); + u16 j; + u32 *stats; + u32 max; + s16 d; + s16 cur; + s32 hcur; + s32 v; + + /* Emit nothing; the instruction count sets the GCSE hash size, which orders the spill slots. */ +#define PAD9 asm(""); asm(""); asm(""); asm(""); asm(""); asm(""); asm(""); asm(""); asm(""); + PAD9 PAD9 PAD9 PAD9 PAD9 PAD9 +#undef PAD9 + t071Init(spr1, RES_ID(0x50061), 0, 0x80000000, 0); + t071Init(spr2, RES_ID(0x50060), 0, 0x80000000, 0); + pal = sub_08007290(0x40000002); +#ifdef REGION_USA + gfx = sub_08007290(0x10010003); +#else + gfx = sub_08007290(gUnk_03003470 + 0x10010003); +#endif + sub_080653CC(); + buf1 = sub_08001494(0xA0); + buf2 = sub_08001494(0xA0); + buf3 = sub_08001494(0x60); + CpuFastSet((void *)(gfx + 0x60), buf1, 0x28); + CpuFastSet((void *)(gfx + 0x160), buf2, 0x28); + CpuFastSet((void *)(gfx + 0x260), buf3, 0x18); + blink = 0; + mhp = mmp = dhp = dmp = 0xFFFF; + while (sub_0800CB78() == 0 && sub_0800CD00() == 0) { + while ((sub_0800CD8C() != 0 || sub_0800CFB8() != 0) && sub_0800CB78() == 0 && sub_0800CD00() == 0) { + mhp = mmp = dhp = dmp = 0xFFFF; + sub_080003F0(); + } + while (sub_0800CD34() != 0 || sub_0800CDF8() != 0) { + mhp = mmp = dhp = dmp = 0xFFFF; + fade14170(0, 2); + sub_080003F0(); + } + + i = (s16)dhp != arg0->fC4; + if ((s16)mhp != arg0->f62) + i = 1; + if (i) { + u16 n; + + if (arg0->fC4 > arg0->f62) { + arg0->fC4 = arg0->f62; + dhp = arg0->fC4; + } + if ((s16)dhp > arg0->f62) + dhp = arg0->f62; + mhp = arg0->f62; + d = dhp; + if (d > 0) { + u16 diff; + s16 delta; + s32 r; + if (d < arg0->fC4) { + diff = arg0->fC4 - d; + if ((s16)diff > 1) + diff = (s16)diff / 2; + delta = diff; + r = d + delta; + } else { + diff = d - arg0->fC4; + if ((s16)diff > 1) + diff = (s16)diff / 2; + delta = diff; + r = d - delta; + } + dhp = r; + } else { + dhp = arg0->fC4; + } + hcur = arg0->fC4; + n = (s16)dhp * 40 / arg0->f62; + if (hcur > 0 && n == 0) + n = 1; + /* The do/while(0) nesting raises the loop-depth weight of the + hoisted bound copy so it is allocated before n (r2 vs r3). */ + { + for (i = 0; i < n >> 3; i++) { + buf1[i].w[2] = 0x44444444; + buf1[i].w[3] = 0x44444444; + buf1[i].w[4] = 0x44444444; + buf1[i].w[5] = 0x44444444; + } + } + if (n & 7) { + a.cnt = n & 7; + a.nib = 4; + b.nib = 0x33333330; + a.val = 0; + b.val = 0; + c.val = 0; + for (j = 0; j < a.cnt; j++) { + a.val |= a.nib << (j * 4); + b.val = b.nib << (j * 4); + } + buf1[i].w[2] = a.val | b.val; + buf1[i].w[3] = a.val | b.val; + buf1[i].w[4] = a.val | b.val; + buf1[i].w[5] = a.val | b.val; + i++; + } + for (; i <= 4; i++) { + buf1[i].w[2] = 0x33333333; + buf1[i].w[3] = 0x33333333; + buf1[i].w[4] = 0x33333333; + buf1[i].w[5] = 0x33333333; + } + sub_08001348(buf1, (void *)0x06008060, 0xA0); + } + + i = (s16)dmp != arg0->fC2; + if ((s16)mmp != arg0->f60) + i = 1; + if (i) { + u16 n; + + if (arg0->fC2 > arg0->f60) + arg0->fC2 = arg0->f60; + cur = dmp = arg0->fC2; + mmp = arg0->f60; + hcur = cur; + v = dmp; + if (hcur <= 0) + v = 0; + n = v * 40 / arg0->f60; + if (hcur > 0 && n == 0) + n = 1; + { + { + for (i = 0; i < n >> 3; i++) { + buf2[i].w[2] = 0xAAAAAAAA; + buf2[i].w[3] = 0xAAAAAAAA; + buf2[i].w[4] = 0xAAAAAAAA; + buf2[i].w[5] = 0xAAAAAAAA; + } + } + } + if (n & 7) { + a.cnt = n & 7; + a.nib = 0xA; + b.nib = 0x33333330; + a.val = 0; + b.val = 0; + for (j = 0; j < a.cnt; j++) { + a.val |= a.nib << (j * 4); + b.val = b.nib << (j * 4); + } + buf2[i].w[2] = a.val | b.val; + buf2[i].w[3] = a.val | b.val; + buf2[i].w[4] = a.val | b.val; + buf2[i].w[5] = a.val | b.val; + i++; + } + for (; i <= 4; i++) { + buf2[i].w[2] = 0x33333333; + buf2[i].w[3] = 0x33333333; + buf2[i].w[4] = 0x33333333; + buf2[i].w[5] = 0x33333333; + } + sub_08001348(buf2, (void *)0x06008160, 0xA0); + } + + i = (s16)dx3 != arg0->fC6; + stats = (u32 *)sub_08007290(*(u16 *)(gSave14170 + SAVE_FIELD(0x132)) | 0x110000); + if ((s16)mx3 != stats[ITEM_FIELD(0xA0) / 4] + arg0->f79) + i = 1; + if (arg0->fC6 >= stats[ITEM_FIELD(0xA0) / 4] + arg0->f79) { + fade -= 8; + fade &= 0xFF; + color.r = (u32)(fade * 0xF00) >> 16; + color.g = (u32)(fade * 0x1F00) >> 16; + color.b = 0; + gPal14170[0xFF] = *(u16 *)&color; + sub_08000B38(); + } else { + color.r = 15; + color.g = 31; + color.b = 0; + gPal14170[0xFF] = *(u16 *)&color; + } + if (i) { + u16 n; + + { + /* Reassigning p in the clamp block makes cse1 invalidate it + when it skips the block, so the reload after the join + computes a fresh address instead of reusing p. v keeps the + loaded value in r3. */ + s16 *p = &arg0->fC6; + v = *p; + if (v > stats[ITEM_FIELD(0xA0) / 4] + arg0->f79) { + p = &arg0->fC6; + *p = stats[ITEM_FIELD(0xA0) / 4] + arg0->f79; + } + } + cur = dx3 = arg0->fC6; + max = stats[ITEM_FIELD(0xA0) / 4]; max += arg0->f79; mx3 = max; + if (cur <= 0) v = 0; else v = dx3; + n = v * 24 / max; + if (cur > 0 && n == 0) + n = 1; + { + { + for (i = 0; i < n >> 3; i++) { + buf3[i].w[2] = 0xFFFFFFFF; + buf3[i].w[3] = 0xFFFFFFFF; + buf3[i].w[4] = 0xFFFFFFFF; + buf3[i].w[5] = 0xFFFFFFFF; + } + } + } + if (n & 7) { + a.cnt = n & 7; + a.nib = 0xF; + b.nib = 0x33333330; + a.val = 0; + b.val = 0; + for (j = 0; j < a.cnt; j++) { + a.val |= a.nib << (j * 4); + b.val = b.nib << (j * 4); + } + buf3[i].w[2] = a.val | b.val; + buf3[i].w[3] = a.val | b.val; + buf3[i].w[4] = a.val | b.val; + buf3[i].w[5] = a.val | b.val; + i++; + } + for (; i <= 2; i++) { + buf3[i].w[2] = 0x33333333; + buf3[i].w[3] = 0x33333333; + buf3[i].w[4] = 0x33333333; + buf3[i].w[5] = 0x33333333; + } + } + sub_08001348(buf3, (void *)0x06008260, 0x60); + + if (sub_0800CC98() == 0) { + if ((u16)(arg0->f20 - 3) <= 1) { + t071Coords((arg0->f8C << 8) >> 16, (arg0->f90 << 8) >> 16, &sx, &sy, 0x30, 0); + if (arg0->f10 != 9) { + i = lv14170(); + { + s32 ret; + s32 b5 = (s8)arg0->f6C * 5; + /* hcur doubles as the level counter. Loading the table + base and b5 * 2 into locals inside the body lengthens + the doubled value's lifetime, so loop.c hoists it in + its first pass (lsls r6 before the table-pointer giv). */ + for (hcur = 7; hcur >= 0; hcur--) { + u16 *tbl = gUnk_0847ACE8; + s32 bb = b5 * 2; + s32 t = tbl[hcur]; + u16 threshold = bb + t; + if ((s16)threshold < 0) + threshold = 0; + if (arg0->fC2 >= (s16)threshold) { + ret = hcur; + goto found; + } + } + ret = 0; + found: + j = ret; + } + if (i > j) { + loadedCapacity = arg0->f26; + goto clampLevel14170; + } + loadedCapacity = arg0->f26; + goto checkCapacity14170; + } else { + i = lv14170(); + j = sub_08079FD0(sub_0801DEB8()) - 1; + if (i > j) { + loadedCapacity = arg0->f26; + clampLevel14170: + i = j; + checkCapacity14170: + /* Both lookup paths share the original capacity check. */ + k = loadedCapacity; + if (i <= k) + goto validate14170; + goto inactive14170; + } + { + register u16 capacity asm("r0") = arg0->f26; + k = capacity; + } + if (i > k) + i = 0; + } + validate14170: + if (i != 0) { + if (k <= 0xF && arg0->f20 != 5) { + anim14170(spr1, k + 6, &tile, &tmp, 1); + draw14170(spr1, sx, sy - 0x20, arg0->f26 + 6, tile); + } + } else { + inactive14170: + if (arg0->f20 != 5) { + draw14170(spr1, sx, sy - 0x20, arg0->f26 & 0xFFFF, arg0->f24 >> 1); + } + } + } else if ((u16)(arg0->f20 - 6) <= 1) { + t071Coords((arg0->f8C << 8) >> 16, (arg0->f90 << 8) >> 16, &sx, &sy, 0x30, 0); + if (arg0->f67 != 0) { + if (arg0->f26 > 0x10) { + anim14170(spr2, 7, &tile, &tmp, 1); + draw14170(spr2, sx, sy - 0x20, 7, tile); + } else { + draw14170(spr2, sx, sy - 0x20, 0, arg0->f26 >> 1); + } + } else if (arg0->f26 > 7) { + if (arg0->f20 != 8) { + anim14170(spr2, 7, &tile, &tmp, 1); + draw14170(spr2, sx, sy - 0x20, 7, tile); + } + } else if (arg0->f20 != 8) { + draw14170(spr2, sx, sy - 0x20, 0, arg0->f26); + } + } + } + + if (!(arg0->f30 & 0x80)) { + CpuFastSet((void *)(pal + 4), gBg14170, 0x20); + if (sub_0800CC98() == 0) { + if ((arg0->f30 & 8) && blink < 0x28) { + gBg14170[0x17] = 0xF017; + gBg14170[0x18] = 0xF018; + gBg14170[0x19] = 0xF019; + gBg14170[0x1A] = 0xF01A; + } else { + gBg14170[0x1A] = 0; + gBg14170[0x19] = 0; + gBg14170[0x18] = 0; + gBg14170[0x17] = 0; + } + blink++; + if (blink > 0x3C) + blink = 0; + } + fade14170(0, 2); + num14170(6, 1, arg0->f62, 0); + num14170(2, 1, arg0->fC4, 0); + num14170(0xE, 1, arg0->f60 / 10, 0); + if (arg0->fC2 != 0) + num14170(0xA, 1, arg0->fC2 / 10, 0); + else + num14170(0xA, 1, 0, 0); + } + sub_080003F0(); + } + sub_08001538((s32)buf1); + sub_08001538((s32)buf2); + sub_08001538((s32)buf3); +#else u8 spr1[0x34]; u8 spr2[0x34]; u8 pad[8]; @@ -5985,10 +6406,14 @@ void hud14170(struct Actor14170 *arg0) s32 hcur; register s32 v asm("r3"); - t071Init(spr1, 0x50061, 0, 0x80000000, 0); - t071Init(spr2, 0x50060, 0, 0x80000000, 0); + t071Init(spr1, RES_ID(0x50061), 0, 0x80000000, 0); + t071Init(spr2, RES_ID(0x50060), 0, 0x80000000, 0); pal = sub_08007290(0x40000002); +#ifdef REGION_USA + gfx = sub_08007290(0x10010003); +#else gfx = sub_08007290(gUnk_03003470 + 0x10010003); +#endif sub_080653CC(); buf1 = sub_08001494(0xA0); buf2 = sub_08001494(0xA0); @@ -6137,10 +6562,10 @@ void hud14170(struct Actor14170 *arg0) } i = (s16)dx3 != arg0->fC6; - stats = (u32 *)sub_08007290(*(u16 *)(gSave14170 + 0x132) | 0x110000); - if ((s16)mx3 != stats[0xA0 / 4] + arg0->f79) + stats = (u32 *)sub_08007290(*(u16 *)(gSave14170 + SAVE_FIELD(0x132)) | 0x110000); + if ((s16)mx3 != stats[ITEM_FIELD(0xA0) / 4] + arg0->f79) i = 1; - if (arg0->fC6 >= stats[0xA0 / 4] + arg0->f79) { + if (arg0->fC6 >= stats[ITEM_FIELD(0xA0) / 4] + arg0->f79) { fade -= 8; fade &= 0xFF; color.r = (u32)(fade * 0xF00) >> 16; @@ -6164,13 +6589,13 @@ void hud14170(struct Actor14170 *arg0) loaded value in r3. */ s16 *p = &arg0->fC6; v = *p; - if (v > stats[0xA0 / 4] + arg0->f79) { + if (v > stats[ITEM_FIELD(0xA0) / 4] + arg0->f79) { p = &arg0->fC6; - *p = stats[0xA0 / 4] + arg0->f79; + *p = stats[ITEM_FIELD(0xA0) / 4] + arg0->f79; } } cur = dx3 = arg0->fC6; - max = stats[0xA0 / 4]; max += arg0->f79; mx3 = max; + max = stats[ITEM_FIELD(0xA0) / 4]; max += arg0->f79; mx3 = max; v = dx3; if (cur <= 0) v = 0; @@ -6331,6 +6756,7 @@ void hud14170(struct Actor14170 *arg0) sub_08001538((s32)buf1); sub_08001538((s32)buf2); sub_08001538((s32)buf3); +#endif } /* [TaskRunClass0ChargedLunge] Moves local charged attacker at table speed plus modifier and resolves collision * until animation completes or state changes; preserves states14/10/11 and spectator before normal reset and @@ -6407,8 +6833,8 @@ void sub_08014C8C(void) { next = 0x50; step = 1; while (p->wB6 == 0 && p->state == 5) { - u16 *type = (u16 *)((u8 *)p + 0xB2); - u32 *counter = (u32 *)((u8 *)p + 0xDC); + u16 *type = (u16 *)((u8 *)p + PLAYER_FIELD(0xB2)); + u32 *counter = (u32 *)((u8 *)p + PLAYER_FIELD(0xDC)); if (next != *type && *type == step) { next = *type; (*counter)++; @@ -6429,7 +6855,7 @@ void sub_08014C8C(void) { -struct PlrKind14 { u8 pad0[0x10]; u16 kind; u8 pad12[0x14C - 0x12]; }; +struct PlrKind14 { u8 pad0[PLAYER_FIELD(0x10)]; u16 kind; u8 pad12[PLAYER_SIZE - PLAYER_FIELD(0x12)]; }; extern struct PlrKind14 kinds14[] asm("gUnk_03003CE0"); extern struct Task tasks14[] asm("gUnk_03003C40"); /* [StartClassZeroChargedAttack] Normalized class0 charge starter dispatches weapon kinds1/3 to @@ -6471,29 +6897,29 @@ void sub_08014D60(void) struct Info14 { u32 kind:4; u32 mid:24; u32 top:4; u32 lo:14; u32 level:3; u32 power:3; u32 hi:12; }; struct Plr14 { u16 id; - u8 pad2[0x10]; + u8 pad2[PLAYER_FIELD(0x12) - PLAYER_FIELD(0x2)]; u16 keys; - u8 pad14[8]; + u8 pad14[PLAYER_FIELD(0x1C) - PLAYER_FIELD(0x14)]; s16 dir; - u8 pad1E[2]; + u8 pad1E[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x1E)]; u16 state; - u8 pad22[2]; + u8 pad22[PLAYER_FIELD(0x24) - PLAYER_FIELD(0x22)]; s16 w24; u16 w26; u16 w28; - u8 pad2A[6]; + u8 pad2A[PLAYER_FIELD(0x30) - (PLAYER_FIELD(0x28) + 0x2)]; u32 flags; - u8 pad34[0xB0 - 0x34]; + u8 pad34[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x34)]; u16 wB0; u16 wB2; u16 wB4; u16 wB6; u16 wB8; - u8 padBA[0xDC - 0xBA]; + u8 padBA[PLAYER_FIELD(0xDC) - PLAYER_FIELD(0xBA)]; s32 counterDC; - u8 padE0[0x122 - 0xE0]; + u8 padE0[PLAYER_FIELD(0x122) - PLAYER_FIELD(0xE0)]; u16 w122; - u8 pad124[0x144 - 0x124]; + u8 pad124[PLAYER_FIELD(0x144) - PLAYER_FIELD(0x124)]; struct Info14 *pos; struct Info14 *info; }; @@ -6610,10 +7036,10 @@ void sub_08015150(void) { struct PlayerW12 *p = (struct PlayerW12 *)&gUnk_03003CE0[sub_080020F4()]; while (p->wB6 == 0 && p->state == 5) { - u32 *counter = (u32 *)((u8 *)p + 0xDC); - u16 type = *(u16 *)((u8 *)p + 0xB2); + u32 *counter = (u32 *)((u8 *)p + PLAYER_FIELD(0xDC)); + u16 type = *(u16 *)((u8 *)p + PLAYER_FIELD(0xB2)); if (type == 1 || type == 4 || type == 5) { - if (*(u16 *)((u8 *)p + 0xB4) == 0) + if (*(u16 *)((u8 *)p + PLAYER_FIELD(0xB4)) == 0) (*counter)++; } sub_080003F0(); @@ -6633,7 +7059,7 @@ void sub_08015150(void) extern void sub_08015090(void); extern void sub_08015150(void); -struct View151E {u8 pad0[16];u16 mode;u8 pad12[14];u16 state;u8 pad22[14];u32 flags;u8 pad34[0x118];}; +struct View151E {u8 pad0[PLAYER_FIELD(0x10)];u16 mode;u8 pad12[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x12)];u16 state;u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 pad34[PLAYER_SIZE - PLAYER_FIELD(0x34)];}; extern struct View151E players151E[] asm("gUnk_03003CE0"); /* [StartClassThreeChargedAttack] Normalized class3 charge starter selects scaled lunge for kind2 and hit * counter for kind4, returning for other kinds. Duplicate task triggers guarded state reset; otherwise @@ -6692,13 +7118,13 @@ void sub_080152CC(void) (s32 *)&p->pos8C, p->w1C, direction, 0); sub_08013CEC((u8 *)p); { - u32 type = *(u16 *)((u8 *)p + 0xB2); + u32 type = *(u16 *)((u8 *)p + PLAYER_FIELD(0xB2)); switch (type) { case 1: case 3: - if (type == 3 && *(u16 *)((u8 *)p + 0xB4) == 1) - (*(u32 *)((u8 *)p + 0xDC))++; + if (type == 3 && *(u16 *)((u8 *)p + PLAYER_FIELD(0xB4)) == 1) + (*(u32 *)((u8 *)p + PLAYER_FIELD(0xDC)))++; break; } } diff --git a/src/code_080153A4.c b/src/code_080153A4.c index dfe930f4..80384770 100644 --- a/src/code_080153A4.c +++ b/src/code_080153A4.c @@ -69,12 +69,12 @@ void sub_08015464(void) } while (initial == 0 && p->state == 5) { - u32 *counter = (u32 *)((u8 *)p + 0xDC); - switch (*(u16 *)((u8 *)p + 0xB2)) { + u32 *counter = (u32 *)((u8 *)p + PLAYER_FIELD(0xDC)); + switch (*(u16 *)((u8 *)p + PLAYER_FIELD(0xB2))) { case 2: case 5: case 7: - if (*(u16 *)((u8 *)p + 0xB4) == 1) + if (*(u16 *)((u8 *)p + PLAYER_FIELD(0xB4)) == 1) (*counter)++; break; } @@ -94,39 +94,39 @@ void sub_08015464(void) extern struct Task tasks15[] asm("gUnk_03003C40"); -struct PlrKind15 { u8 pad0[0xC]; u16 sub; u8 padE[2]; u16 kind; u8 pad12[0x14C - 0x12]; }; +struct PlrKind15 { u8 pad0[PLAYER_FIELD(0xC)]; u16 sub; u8 padE[PLAYER_FIELD(0x10) - PLAYER_FIELD(0xE)]; u16 kind; u8 pad12[PLAYER_SIZE - PLAYER_FIELD(0x12)]; }; extern struct PlrKind15 kinds15[] asm("gUnk_03003CE0"); void sub_080156FC(); void sub_080152CC(); struct Info15 { u32 kind:4; u32 mid:24; u32 top:4; u32 lo:14; u32 level:3; u32 hi:15; }; struct Plr15 { u16 id; - u8 pad2[0x1A]; + u8 pad2[PLAYER_FIELD(0x1C) - 0x2]; u16 w1C; - u8 pad1E[2]; + u8 pad1E[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x1E)]; u16 state; - u8 pad22[2]; + u8 pad22[PLAYER_FIELD(0x24) - PLAYER_FIELD(0x22)]; s16 w24; u16 w26; u16 w28; - u8 pad2A[6]; + u8 pad2A[PLAYER_FIELD(0x30) - (PLAYER_FIELD(0x28) + 0x2)]; u32 flags; - u8 pad34[0xC]; + u8 pad34[PLAYER_FIELD(0x40) - PLAYER_FIELD(0x34)]; s16 w40; - u8 pad42[0x4A]; + u8 pad42[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x42)]; struct V2W12 pos8C; struct V2W12 pos94; - u8 pad9C[0xB0 - 0x9C]; + u8 pad9C[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x9C)]; u16 wB0; u16 wB2; u16 wB4; u16 wB6; u16 wB8; - u8 padBA[0xDC - 0xBA]; + u8 padBA[PLAYER_FIELD(0xDC) - PLAYER_FIELD(0xBA)]; s32 counterDC; - u8 padE0[0x122 - 0xE0]; + u8 padE0[PLAYER_FIELD(0x122) - PLAYER_FIELD(0xE0)]; u16 w122; - u8 pad124[0x148 - 0x124]; + u8 pad124[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x124)]; struct Info15 *info; }; extern struct Plr15 players15[] asm("gUnk_03003CE0"); @@ -419,10 +419,10 @@ void sub_08015C38(void) { void sub_08015C5C(s32 arg0, s32 arg1) { void *temp_r2; - temp_r2 = (&((struct Sz332 *)&gUnk_03003CE0)[sub_080020F4()]); - M2C_FIELD(temp_r2, s32 *, 0x9C) = arg0; - M2C_FIELD((temp_r2 + 0x9C), s32 *, 4) = arg1; - M2C_FIELD(temp_r2, s32 *, 0x30) = (s32) (M2C_FIELD(temp_r2, s32 *, 0x30) | 0x24); + temp_r2 = &gUnk_03003CE0[sub_080020F4()]; + M2C_FIELD(temp_r2, s32 *, PLAYER_FIELD(0x9C)) = arg0; + M2C_FIELD((temp_r2 + PLAYER_FIELD(0x9C)), s32 *, 4) = arg1; + M2C_FIELD(temp_r2, s32 *, PLAYER_FIELD(0x30)) = (s32) (M2C_FIELD(temp_r2, s32 *, PLAYER_FIELD(0x30)) | 0x24); } /* [SetLocalPlayerSpriteHideFlag] Queries the local player index, selects the 0x14C-byte runtime record, ORs * 0x80000 into its full 32-bit flags at +0x30 and then calls EnqueueLinkPlayerFlags. Preserves other flag bits @@ -550,11 +550,11 @@ void sub_08015E3C(u8 *arg0, s32 arg1) { u16 *p; s32 r1; - r3 = (u16)(*(s8 *)(arg0 + 0x6C) * 10 + gUnk_0847ACE8[arg1]); + r3 = (u16)(*(s8 *)(arg0 + PLAYER_FIELD(0x6C)) * 10 + gUnk_0847ACE8[arg1]); if ((s16)r3 < 0) { r3 = 0; } - p = (u16 *)(arg0 + 0xC2); + p = (u16 *)(arg0 + PLAYER_FIELD(0xC2)); r1 = *p - (s16)r3; *p = r1; if ((s16)r1 < 0) { @@ -568,7 +568,7 @@ extern u16 gUnk_0847ACE8[]; * represents an affordable index-zero tier. Does not spend energy or validate the player pointer. */ u32 sub_08015E84(u8 *arg0) { - register s32 signedByte asm("r2") = (s8)arg0[0x6C]; + register s32 signedByte asm("r2") = (s8)arg0[PLAYER_FIELD(0x6C)]; register s32 half asm("r1"); half = signedByte * 5; @@ -580,7 +580,7 @@ u32 sub_08015E84(u8 *arg0) s16 *value; table += 7; - value = (s16 *)(arg0 + 0xC2); + value = (s16 *)(arg0 + PLAYER_FIELD(0xC2)); for (; i >= 0; table--, i--) { u16 threshold = delta + *table; s32 current; @@ -692,7 +692,7 @@ void sub_08016114(void) u32 i; u32 z; u32 *q; - gP030056F4 = (u8 *)sub_08001494(0xE60); + gP030056F4 = (u8 *)sub_08001494(5 * ENEMY_SIZE); gW030056FC = 0; gW030056F8 = 0; gH03005724 = 0; @@ -701,7 +701,7 @@ void sub_08016114(void) p = gP030056F4; i = 0; z = 0; - for (; i <= 4; i++, p += 0x2E0) { + for (; i <= 4; i++, p += ENEMY_SIZE) { sub_0807A064(i + 4); *(u16 *)(p + 0) = z; *(u16 *)(p + 8) = z; @@ -808,11 +808,11 @@ struct Obj1623C { u8 pad200; u8 b201; u8 pad202[2]; - u8 data[0xD8]; + u8 data[ENEMY_DATA_FIELD(0xD8)]; }; struct Gs1623C { u8 pad0[0x40]; u32 f40; }; extern struct Gs1623C *gs1623C asm("gUnk_03005CF4"); -extern u8 tables1623C[][0xD8] asm("gUnk_0847AD3C"); +extern u8 tables1623C[][ENEMY_DATA_FIELD(0xD8)] asm("gUnk_0847AD3C"); extern void cpuset1623C(const void *, void *, u32) asm("CpuSet"); extern void memcpy1623C(void *, const void *, u32) asm("memcpy"); /* [InitializeActorFromSceneDefinition] Uses indexed scene entry flags low12bits minus1 (plus0xC5 in alternate @@ -836,7 +836,7 @@ void sub_0801623C(struct Obj1623C *obj, struct Src1623C *src, u32 idx) obj->x24 = entry[1].x << 3; obj->y28 = entry[1].y << 3; obj->src = src; - memcpy1623C(obj->data, table, 0xD8); + memcpy1623C(obj->data, table, ENEMY_DATA_FIELD(0xD8)); obj->w8 = entry[1].wE; obj->w84 = 0; obj->w5A = 0; @@ -932,7 +932,7 @@ struct Obj1641C { u8 pad200; u8 f201; /* 0x201 */ u16 f202; /* 0x202 */ - u8 data[0xD8]; /* 0x204 */ + u8 data[ENEMY_DATA_FIELD(0xD8)]; /* 0x204 */ u8 *src; /* 0x2DC */ }; extern u32 poolFlags1641C asm("gUnk_030056FC"); @@ -943,7 +943,7 @@ extern u8 stacks1641C[] asm("gUnk_030046EC"); extern void taskMain1641C(void) asm("sub_0801801C"); extern void startTask1641C(void *, void *) asm("sub_08000274"); extern void cpuset1641C(const void *, void *, u32) asm("CpuSet"); -struct Plr1641C { u8 pad0[0x2C]; u16 w2C; u8 pad2E[0x14C - 0x2E]; }; +struct Plr1641C { u8 pad0[PLAYER_FIELD(0x2C)]; u16 w2C; u8 pad2E[PLAYER_SIZE - PLAYER_FIELD(0x2D) - 1]; }; extern struct Plr1641C players1641C[] asm("gUnk_03003CE0"); /* [TryCreateEnemyFromSpawnState] Returns0 if all five bits of actor mask 030056FC are occupied. Searches slots * ascending normally, descending underCDC0; on success marks one slot and initializes its 0x2E0-byte actor in @@ -990,9 +990,9 @@ s32 sub_0801641C(struct Src1641C *src) index = (src->flags & 0xFFF) - 1; if (sub_0800CE30() != 0) index += 0xC5; - data = table1641C + index * 0xD8; - if ((src->f10 & 0x80) && ((s8 *)data)[0x47] != 0) - data += 0xD8; + data = table1641C + index * ENEMY_DATA_FIELD(0xD8); + if ((src->f10 & 0x80) && ((s8 *)data)[ENEMY_DATA_FIELD(0x47)] != 0) + data += ENEMY_DATA_FIELD(0xD8); obj->src = data; obj->id = slot; zero8 = 0; @@ -1008,7 +1008,7 @@ s32 sub_0801641C(struct Src1641C *src) obj->f28 = src->y << 3; obj->prev = obj->pos; obj->f2C = src->f14; - memcpy(obj->data, data, 0xD8); + memcpy(obj->data, data, ENEMY_DATA_FIELD(0xD8)); obj->f8 = src->f8; obj->f84 = src->f10 & 0xFF7F; obj->f86 = src->f12; @@ -1106,7 +1106,7 @@ s32 sub_0801674C(s32 arg0, s32 arg1) if (slot < 0) return 0; poolFlags014 |= 1 << slot; - object = poolObjects014 + slot * 0x2E0; + object = poolObjects014 + slot * ENEMY_SIZE; zero = 0; *(u16 *)object = slot; *(u32 *)(object + 0x50) = (slot + 4) << 24; @@ -1274,12 +1274,16 @@ void sub_080169C8(void) { task = (u8 *)&gUnk_03004220 + taskOffset; if (sub_08000470((u32)task) != 0) { sub_080003A8((s32)task); +#ifdef REGION_USA + { u8 *base = gP030056F4; u32 off = i * ENEMY_SIZE; object = (u8 *)(off + (u32)base); } +#else object = (u8 *)(objectOffset + (u32)gP030056F4); +#endif *(u16 *)(object + 0x5C) = 0; *(u16 *)(object + 0xC) = 11; sound169C8(object[0x86], object[0x84], 3); } - objectOffset += 0x2E0; taskOffset += 0x28; i++; + objectOffset += ENEMY_SIZE; taskOffset += 0x28; i++; } while (i <= 4); j = 0; secondBase = &gUnk_030056F0; secondOffset = 0; do { @@ -1300,7 +1304,7 @@ void sub_080169C8(void) { *word1 = zero; *word2 = zero; } -struct Obj16A7C { u8 pad0[0x2C]; s32 owner; u8 pad30[0x7A - 0x30]; u16 flags; u8 pad7C[0x2E0 - 0x7C]; }; +struct Obj16A7C { u8 pad0[0x2C]; s32 owner; u8 pad30[0x7A - 0x30]; u16 flags; u8 pad7C[ENEMY_SIZE - 0x7C]; }; struct Rec16A7C { s32 owner; u8 kind; u8 pad[3]; }; extern struct Obj16A7C *objects16A7C asm("gUnk_030056F4"); extern u32 active16A7C asm("gUnk_030056FC"); @@ -1340,7 +1344,7 @@ void sub_08016A7C(s32 owner) } struct Pos16B30 { u32 kind:4; u32 x:12; u32 y:12; u32 pad2:4; u32 f4:6; u32 f4b:2; }; struct Dist16B30 { s32 dist; s32 index; }; -struct Plr16B30 { u16 id; u8 pad2[0x2E]; u32 flags; u8 pad34[0x30]; u16 kind; u8 pad66[0xE2]; struct Pos16B30 *pos; }; +struct Plr16B30 { u16 id; u8 pad2[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x2)]; u32 flags; u8 pad34[PLAYER_FIELD(0x64) - PLAYER_FIELD(0x34)]; u16 kind; u8 pad66[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x66)]; struct Pos16B30 *pos; }; extern struct Plr16B30 players16B30[] asm("gUnk_03003CE0"); /* [SelectNearestPlayerForEnemy] Uses a four-entry local distance/index array with loops bounded by participant * count 02164, without a count clamp. Origin is enemy live Q8 coordinates+0x14/+0x18 shifted8; candidate @@ -1499,12 +1503,16 @@ void sub_08016D40(u8 *object, u16 arg) { u32 count; u16 *counter; if (object[0x201] & 2) { - source = gP030056F4 + (object[0x1FC] >> 4) * 0x2E0; +#ifdef REGION_USA + { u8 **bp = &gP030056F4; u32 off = object[0x1FC] >> 4; off *= ENEMY_SIZE; source = *bp + off; } +#else + source = gP030056F4 + (object[0x1FC] >> 4) * ENEMY_SIZE; +#endif *(s32 *)(object + 0x24) = *(s32 *)(source + 0x14) >> 8; *(s32 *)(object + 0x28) = *(s32 *)(source + 0x18) >> 8; } else { - source = (u8 *)gUnk_03003CE0 + (object[0x1FC] >> 4) * 0x14C; - packed = (u16 *volatile *)(source + 0x148); + source = (u8 *)gUnk_03003CE0 + (object[0x1FC] >> 4) * PLAYER_SIZE; + packed = (u16 *volatile *)(source + PLAYER_FIELD(0x148)); *(s32 *)(object + 0x24) = (*packed)[0] >> 4; *(s32 *)(object + 0x28) = ((u32)(*packed)[1] << 20) >> 20; } @@ -1590,11 +1598,11 @@ void sub_08016ECC_u16(u16 arg0) } } struct Pos16F28 { u32 kind:4; u32 x:12; u32 y:12; u32 pad2:4; u32 f4:6; u32 f4b:2; }; -struct Plr16F28 { u8 pad0[0x148]; struct Pos16F28 *pos; }; +struct Plr16F28 { u8 pad0[PLAYER_FIELD(0x148)]; struct Pos16F28 *pos; }; extern struct Plr16F28 players16F28[] asm("gUnk_03003CE0"); struct Roll16F28 { u8 result; u8 chance; u8 pad[2]; }; struct AI16F28 { - u8 pad0[0x10]; + u8 pad0[ENEMY_FIELD(0x214) - 0x204]; s32 f10; /* 0x214 */ u8 pad14[0xC]; u16 f20; /* 0x224 */ @@ -1604,7 +1612,7 @@ struct AI16F28 { u16 hp4C; /* 0x250 */ u16 f4E; /* 0x252 */ struct Roll16F28 tables[11][3]; /* 0x254 */ - u8 pad2D8[8]; + u8 pad2D8[ENEMY_SIZE - ENEMY_FIELD(0x2D8)]; }; struct Obj16F28 { u16 id; @@ -1652,7 +1660,7 @@ struct GS16F28 { u8 pad0[0xC]; u16 fC; }; extern struct GS16F28 *gs16F28 asm("gUnk_03005CF4"); extern u32 used16F28 asm("gUnk_030056FC"); extern struct Obj16F28 *objs16F28 asm("gUnk_030056F4"); -struct Lead16F28 { u8 pad0[0x20]; s32 f20; }; +struct Lead16F28 { u8 pad0[SAVE_FIELD(0x20)]; s32 f20; }; extern struct Lead16F28 *lead16F28 asm("gUnk_030034E0"); extern u8 dirs16F28[] asm("gUnk_084790B4"); extern u8 dirIdx16F28[] asm("gUnk_084790C4"); @@ -1689,6 +1697,31 @@ static inline u8 roll16F28(struct Roll16F28 *t) return res; } +#ifdef REGION_USA +/* Same roll with a real loop: the first test is duplicated in front of it. */ +static inline u8 rollw16F28(struct Roll16F28 *t) +{ + u32 i; + register u32 r asm("r2"); + u8 sum; + u8 res; + r = (u8)(sub_080008C8() % 100U); + res = 0xFF; + i = 0; + sum = t->chance; + while (r >= sum) { + i++; + t++; + if (i > 2) + goto end; + sum += t->chance; + } + res = t->result; +end: + return res; +} +#endif + struct Vec16F28 { s32 x, y; }; #define TGT(o) (((u8 *)(o))[0x1FC]) @@ -1726,6 +1759,387 @@ static inline void seek16F28(struct Obj16F28 *self, u16 *range, u32 tx, u32 ty) * unchecked. Counter uses ++f8A > 900; zero-start expiry is the 901st update. */ void sub_08016F28(struct Obj16F28 *self) { +#ifdef REGION_USA + u8 act; + s32 dist; + u32 active; + u32 dir; + struct Obj16F28 *e; + u32 tx, ty; + struct AI16F28 *ai; + + ai = &self->ai; + act = 0xFF; + + if (self->flags & 2) { + if (++self->f8A > 900) { + self->flags &= ~2; + gs16F28->fC = 0; + self->f8A = 0; + } + } + { + u32 r = sub_08002204(); + active = (-r | r) >> 31; + } + if (active) { + if (self->state == 10 && self->f6E != 0) { + act = roll16F28(ai->tables[0]); + self->flags |= 1; + } + if (self->action == 0xE) { + if (self->phase > 1 && act == 0xFF && self->f74 == 1) { + act = roll16F28(ai->tables[1]); + self->flags |= 1; + } + } else if (act == 0xFF && self->f74 == 1) { + act = roll16F28(ai->tables[1]); + self->flags |= 1; + } + if (self->f62 == 10) + self->flags &= ~1; + } + if (self->flags & 1) { + if (active) { + if (act == 0xFF) { + dist = 0xF0; + if (self->flags & 2) { + { + s32 *dp = &dist; + s32 bestD = 0xFFFF; + u32 i; + u32 off; + u32 r; + struct Obj16F28 **objsp; + u32 bi; + bi = -1; + i = 0; + asm("" : "=r"(objsp) : "0"(&objs16F28)); + nearLoop: + { + struct Obj16F28 *o; + u32 m = 1 << i; + register u32 *up asm("r2") = &used16F28; + if ((*up & m) && (o = (struct Obj16F28 *)((u8 *)*objsp + i * ENEMY_SIZE)) != self) { + s32 dx = (o->x - self->x) >> 8; + s32 dy = (o->y - self->y) >> 8; + u16 d = Sqrt(dx * dx + dy * dy); + if (bestD > d) { + bestD = d; + bi = i; + } + } + } + i++; + if (i <= 4) goto nearLoop; + asm("" : : "r"(bestD), "r"(bestD), "r"(bi)); + if (bi == -1) + r = 0xFF; + else { + asm("" : : "r"(dp)); + *dp = bestD; + r = bi; + } + { u8 *p = &TGT(self); r <<= 4; *p = (*p & 0xF) | r; } + } + } else { + self->thi = nearest16F28(self, &dist); + } + if (self->thi <= 9) { + s32 diff; + if (self->flags & 2) + diff = objs16F28[self->thi].ai.f10 - ai->f10; + else + diff = lead16F28->f20 - ai->f10; + if (ai->f4E < diff) { + if (dist < ai->near48) + act = rollw16F28(ai->tables[8]); + else if (dist < ai->mid4A) + act = rollw16F28(ai->tables[9]); + else + act = roll16F28(ai->tables[10]); + } + if (act == 0xFF) { + u16 pct = self->hp * 100 / self->maxhp; + if (ai->hp4C > pct) { + if (dist < ai->near48) + act = rollw16F28(ai->tables[5]); + else if (dist < ai->mid4A) + act = rollw16F28(ai->tables[6]); + else + act = roll16F28(ai->tables[7]); + } + if (act == 0xFF) { + struct Roll16F28 *t; + register u32 r asm("r2"); + u32 n; + u8 sum; + u8 res; + if (dist <= ai->near48) { + t = ai->tables[2]; + r = (u8)(sub_080008C8() % 100U); + res = 0xFF; + n = 0; + sum = t->chance; + while (r >= sum) { + n++; + t++; + if (n > 2) + goto rolled; + sum += t->chance; + } + setAct: + res = t->result; + } else if (dist <= ai->mid4A) { + t = ai->tables[3]; + r = (u8)(sub_080008C8() % 100U); + res = 0xFF; + n = 0; + sum = t->chance; + while (r >= sum) { + n++; + t++; + if (n > 2) + goto rolled; + sum += t->chance; + } + goto setAct; + } else { + t = ai->tables[4]; + r = (u8)(sub_080008C8() % 100U); + res = 0xFF; + n = 0; + sum = t->chance; + goto test4; + loop4: + n++; + t++; + if (n > 2) + goto rolled; + sum += t->chance; + test4: + if (r >= sum) + goto loop4; + goto setAct; + } + rolled: + act = res; + } + } + } else { + act = 1; + TGT(self) &= 0xF; + } + } + asm("" : : "r"(act)); + if (act == 0xD && self->f74 < ai->f20 && self->action != 0xFF) + act = self->action; + if (act != 0xFF) { + self->flags &= ~1; + if (self->action != act) { + self->phase = 0; + self->action = act; + if (self->flags & 2) { + e = &objs16F28[self->thi]; + dir = dir16F28(self, e->x >> 8, e->y >> 8); + self->dir = dir; + } else { + struct Plr16F28 *pl; + u32 prod = self->thi * sizeof(struct Plr16F28); + pl = players16F28; + pl = (struct Plr16F28 *)((u8 *)pl + prod); + if ((s32)(*((u8 *)pl->pos + 4) << 26) < 0) + self->flags |= 1; + dir = dir16F28(self, pl->pos->x, pl->pos->y); + self->dir = dir; + } + { + u32 i; + u32 off; + u32 *usedp; + struct Obj16F28 **objsp; + i = 0; + usedp = &used16F28; + objsp = &objs16F28; + for (off = 0; i <= 4; off += ENEMY_SIZE, i++) { + if (self->id != i && (*usedp & (1 << i))) { + e = (struct Obj16F28 *)((u8 *)*objsp + i * ENEMY_SIZE); + if (self->dir == e->dir) { + self->dir++; + if (self->dir > 15) + self->dir = 0; + } + } + } + } + notify16F28(self->id); + } + } else { + self->action = 0; + } + } + self->phase = 0; + } + if (self->flags & 2) { + e = &objs16F28[self->thi]; + do { dir = dir16F28(self, e->x >> 8, e->y >> 8); } while (0); + tx = (u32)(e->x << 8) >> 16; + ty = (u32)(e->y << 8) >> 16; + } else { + struct Plr16F28 *pl; + u32 prod = self->thi * sizeof(struct Plr16F28); + pl = players16F28; + pl = (struct Plr16F28 *)((u8 *)pl + prod); + if ((s32)(*((u8 *)pl->pos + 4) << 26) < 0) + self->flags |= 1; + do { dir = dir16F28(self, pl->pos->x, pl->pos->y); } while (0); + tx = pl->pos->x; + ty = pl->pos->y; + } + switch (self->action) { + case 1: + self->f6 = 0; + self->input = 0; + self->f42 = 0; + if (!active) + break; + if (++self->phase > 30) + self->flags |= 1; + break; + case 2: + self->f6 = 0; + self->input = 0; + self->f42 = 0; + if (!active) + break; + if (++self->phase > 60) + self->flags |= 1; + break; + case 3: + self->f6 = 0; + self->input = 0; + self->f42 = 0; + if (!active) + break; + if (++self->phase > 90) + self->flags |= 1; + break; + case 4: + follow16F28(self, ai->near48); + self->f6 = 0; + if (!active) + break; + if (self->f7A & 0x20) + self->input = 0; + if (self->input == 0) { + self->flags |= 1; + self->f8 = dirs16F28[dir]; + } + break; + case 5: + follow16F28(self, ai->mid4A); + self->f6 = 0; + if (!active) + break; + if (self->f7A & 0x20) + self->input = 0; + if (self->input == 0) { + self->flags |= 1; + self->f8 = dirs16F28[dir]; + } + break; + case 6: + seek16F28(self, &ai->near48, tx, ty); + if (++self->f44 > 180) { + self->f44 = 0; + self->input = 0; + } + self->f6 = 0; + if (!active) + break; + if (self->f7A & 0x20) + self->input = 0; + if (self->input == 0) { + self->flags |= 1; + self->f8 = dirs16F28[dir]; + } + break; + case 7: + seek16F28(self, &ai->mid4A, tx, ty); + if (++self->f44 > 180) { + self->f44 = 0; + self->input = 0; + } + self->f6 = 0; + if (!active) + break; + if (self->f7A & 0x20) + self->input = 0; + if (self->input == 0) { + self->flags |= 1; + self->f8 = dirs16F28[dir]; + } + break; + case 8: case 9: case 10: case 11: case 12: + case 15: case 16: case 17: + case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: + break; + case 13: + self->f8 = dirs16F28[dir]; + self->f6 = 1; + self->input = 1; + self->f42 = 0; + if (!active) + break; + if (self->f74 > self->ai.f20) + self->flags |= 1; + break; + case 14: + self->f6 = 1; + self->input = 1; + self->f42 = 0; + if (!active) + break; + switch (self->phase) { + case 0: + self->f8 = dirs16F28[dir]; + if (self->f74 > self->ai.f20) + self->phase++; + break; + case 1: + if (self->state == 0) + self->phase = 2; + break; + case 2: + self->flags |= 1; + break; + } + break; + case 18: case 19: case 20: case 21: + self->f8 = dirs16F28[dir]; + self->f6 = 2; + self->input = 2; + self->f42 = 0; + if (!active) + break; + if (self->f74 > self->ai.f20) + self->flags |= 1; + break; + case 31: case 32: case 33: case 34: case 35: case 36: case 37: case 38: case 39: case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: case 58: case 59: case 60: case 61: case 62: case 63: case 64: case 65: case 66: case 67: case 68: case 69: case 70: case 71: case 72: case 73: case 74: case 75: case 76: case 77: case 78: case 79: case 80: case 81: case 82: case 83: case 84: case 85: case 86: case 87: case 88: case 89: case 90: case 91: case 92: case 93: case 94: case 95: case 96: case 97: case 98: case 99: case 100: case 101: case 102: case 103: case 104: case 105: case 106: case 107: case 108: case 109: case 110: case 111: case 112: case 113: case 114: + self->f8 = dirs16F28[dir]; + self->f6 = 2; + self->input = 2; + if (!active) + break; + if (self->f74 > self->ai.f20) + self->flags |= 1; + break; + default: + if (!(self->f7A & 4)) + self->flags |= 1; + break; + } +#else u8 act; s32 dist; u32 active; @@ -1778,9 +2192,9 @@ void sub_08016F28(struct Obj16F28 *self) u32 r; struct Obj16F28 **objsp = &objs16F28; tx = -1; - for (i = 0, off = 0; i <= 4; off += 0x2E0, i++) { + for (i = 0, off = 0; i <= 4; off += ENEMY_SIZE, i++) { struct Obj16F28 *o; - if ((used16F28 & (1 << i)) && (o = (struct Obj16F28 *)((u8 *)*objsp + off)) != self) { + if ((used16F28 & (1 << i)) && (o = (struct Obj16F28 *)((u8 *)*(objsp) + (off))) != self) { s32 dx = (o->x - self->x) >> 8; s32 dy = (o->y - self->y) >> 8; u16 d = Sqrt(dx * dx + dy * dy); @@ -1868,9 +2282,9 @@ void sub_08016F28(struct Obj16F28 *self) i = 0; usedp = &used16F28; objsp = &objs16F28; - for (off = 0; i <= 4; off += 0x2E0, i++) { + for (off = 0; i <= 4; off += ENEMY_SIZE, i++) { if (self->id != i && (*usedp & (1 << i))) { - e = (struct Obj16F28 *)((u8 *)*objsp + off); + e = (struct Obj16F28 *)((u8 *)*(objsp) + (off)); if (self->dir == e->dir) { self->dir++; if (self->dir > 15) @@ -2046,8 +2460,9 @@ void sub_08016F28(struct Obj16F28 *self) self->flags |= 1; break; } +#endif } -struct T015CEntity { u16 id; u8 pad2[0xA]; u16 kind; u8 padE[6]; s32 x,y; u8 pad1C[0x5A]; u16 cursor; u8 pad78[2]; u16 flags; u8 pad7C[0x194]; u32 active; u8 pad214[0x1A]; u8 radius; }; +struct T015CEntity { u16 id; u8 pad2[0xA]; u16 kind; u8 padE[6]; s32 x,y; u8 pad1C[0x5A]; u16 cursor; u8 pad78[2]; u16 flags; u8 pad7C[ENEMY_FIELD(0x210) - 0x7C]; u32 active; u8 pad214[ENEMY_FIELD(0x22E) - ENEMY_FIELD(0x214)]; u8 radius; }; extern struct T015CEntity *T015CEntities asm("gUnk_030056F4"); extern u8 T015CDirections[] asm("gUnk_084790B4"); extern u8 T015CAngles[] asm("gUnk_0849E730"); @@ -2058,6 +2473,81 @@ extern u16 T015CProbe(u8,s32,s32,s32) asm("sub_0800B118"); * for nonzero probe result. Advances cursor, resetting to actor id+1 when beyond range; parity mismatch * preserves cursor/flags. Radius temporary narrows to byte. */ void sub_08017C6C(struct T015CEntity *p) { +#ifdef REGION_USA + s32 x, y, px, py, ax, ay; + s16 c, dx, dy, dist, ang, delta; + u16 hit; + u32 rad; + u32 r, raw, raw2, raw3, mask; + u16 *cp; + u16 *fp; + u32 flags; + s32 cs; + u32 *fl; + s32 draw, d2, a, idx; + s16 *sines; + u8 *angles; + u32 minus; + struct T015CEntity *q; + x = p->x; + y = p->y; + cp = &p->cursor; + c = *cp; + if ((u16)c > 4) goto reset; + if ((gUnk_03002344 & 1) != (p->id & 1)) return; + fp = &p->flags; + flags = *fp & 0xFFEF; + *fp = flags; + + raw = p->radius << 16; + r = raw >> 16; + if (raw == 0 || p->active == 0xFF) goto next; + q = (struct T015CEntity *)((u8 *)T015CEntities + c * ENEMY_SIZE); + fl = &gUnk_030056FC; + mask = 1 << c; + if (!(*fl & mask) || p->kind == 0xB) goto next; + raw2 = (q->radius + r) << 16; + rad = raw2 >> 16; + if (raw2 == 0) goto next; + asm("");asm(""); + dx = (s16)((x - q->x) >> 8); + dy = (s16)((y - q->y) >> 8); + ax = dx; + if (dx < 0) ax = -dx; + if (ax > 7) goto next; + ay = dy; + if (dy < 0) ay = -dy; + if (ay > 7) goto next; + { register u32 bit asm("r0"); register u32 mk asm("r1"); mk = 0x10; bit = flags; bit |= mk; *fp = bit; } + dist = Sqrt(dx * dx + dy * dy); + ang = (u16)ArcTan2(dx, dy) >> 8; + draw = (({ s32 e = rad << 16; asm("" : "+r"(e)); e >> 16; }) - (s16)dist) << 16; + cs = gUnk_080B9704[ang + 0x40]; + d2 = draw >> 17; + px = x + cs * d2; + py = y + gUnk_080B9704[ang] * d2; + raw3 = T015CProbe(T015CDirections[(u16)ang >> 4], px, py, 0) << 16; + hit = raw3 >> 16; + if (raw3) { + register u32 h asm("r0"); + h = hit << 16; + angles = T015CAngles; + minus = 0xFFFF0000; + h = (s32)(h + minus) >> 15; + ang = *(u16 *)(h + (u32)angles) << 4; + px = x + gUnk_080B9704[ang + 0x40] * d2; + py = y + gUnk_080B9704[ang] * d2; + p->x = px; + p->y = py; + } + +next: + cp = &p->cursor; + *cp = *cp + 1; + if (*cp <= 5) return; +reset: + *cp = p->id + 1; +#else s32 x; s32 y; s32 dx,ax; @@ -2125,7 +2615,7 @@ void sub_08017C6C(struct T015CEntity *p) { if (!radiusraw || p->active==0xFF) goto next; baseptr=&T015CEntities; index=(s32)cursorraw >> 16; - offset=index*0x2E0; + offset=index*ENEMY_SIZE; base=*baseptr; q=(struct T015CEntity *)((u8 *)base+offset); flagptr=&gUnk_030056FC; @@ -2182,6 +2672,7 @@ void sub_08017C6C(struct T015CEntity *p) { if((u16)nextvalue<=5) return; reset: *cp=p->id+1; +#endif } @@ -2211,7 +2702,7 @@ s32 sub_08017E34(s32 *arg0) { if (result < n) { base = gUnk_03003E28; do { - u8 *p = *(u8 **) (base + i * 0x14C); + u8 *p = *(u8 **) (base + i * PLAYER_SIZE); if (!(((u32) (p[4] << 0x1A) >> 0x1A) & 0x20) && (u16) (buf.a + 0x3F) <= 0x16A) { if (*pb > -0x40) { if (*pb <= 0xC7) { @@ -2226,7 +2717,7 @@ s32 sub_08017E34(s32 *arg0) { } struct T015ERect { u32 x:16; u32 y:16; }; struct T015EPos { u16 x, y; u8 flags:6; u8 rest:2; }; -struct T015EPlayer { u8 pad[0x148]; struct T015EPos *pos; }; +struct T015EPlayer { u8 pad[PLAYER_FIELD(0x148)]; struct T015EPos *pos; }; extern struct T015EPlayer T015EPlayers[] asm("gUnk_03003CE0"); extern s32 T015ETest(s32 *, void *, s32 *, u32 *) asm("sub_08021FE0"); /* [ShouldKeepEnemyActive] Enemy flags 0x7A bit 6 forces true. */ @@ -2243,9 +2734,9 @@ s32 sub_08017EC8(u8 *arg0) u32 high; if (*(u16 *)(arg0 + 0x7A) & 0x40) return 1; size = 0x014001E0; - lo = arg0 + 0x22E; + lo = arg0 + ENEMY_FIELD(0x22E); - high = arg0[0x22F] << 16; + high = arg0[ENEMY_FIELD(0x22F)] << 16; rect = *lo | high; found = 0; diff --git a/src/code_08017F7C.c b/src/code_08017F7C.c index c8d2a126..78e3bcc2 100644 --- a/src/code_08017F7C.c +++ b/src/code_08017F7C.c @@ -14,7 +14,7 @@ extern const u8 gUnk_080B9AD0[]; struct T015Rect { u32 x:16; u32 y:16; }; struct T015Pos { u16 x, y; u8 flags:6; u8 rest:2; }; -struct T015Player { u8 pad[0x148]; struct T015Pos *pos; }; +struct T015Player { u8 pad[PLAYER_FIELD(0x148)]; struct T015Pos *pos; }; extern struct T015Player T015Players[] asm("gUnk_03003CE0"); extern s32 T015Test(s32 *, void *, s32 *, u32 *) asm("sub_08021FE0"); /* [IsSpawnPositionInAnyPlayerActivationBox] Tests the supplied Q8 position against the packed positions of all @@ -59,9 +59,9 @@ s32 sub_08017F7C(void *arg0) -struct T015LPollPlayer { u8 pad[0x2C]; u16 field2C; }; +struct T015LPollPlayer { u8 pad[PLAYER_FIELD(0x2C)]; u16 field2C; }; extern struct T015LPollPlayer T015L_poll_players[] asm("gUnk_03003CE0"); -struct T015LActor { u16 f0; u16 f2; u16 f4; u16 f6; u16 f8; u8 padA[0x2]; u16 fC; u16 fE; u8 pad10[0x4]; s32 f14; s32 f18; s32 f1C; s32 f20; u8 pad24[0xC]; s32 f30; s32 f34; u8 pad38[0x4]; s32 f3C; u8 pad40[0x2]; s16 f42; s16 f44; u8 pad46[0x4]; s16 f4A; s32 f4C; s32 f50; s32 f54; u8 pad58[0x2]; u16 f5A; s16 f5C; s16 f5E; s16 f60; u16 f62; u16 f64; u16 f66; u16 f68; s16 f6A; s16 f6C; u16 f6E; u16 f70; u16 f72; u16 f74; u8 pad76[0x6]; u16 f7C; u16 f7E; s16 f80; s16 f82; u8 f84; u8 pad85[0x1]; u8 f86; u8 pad87[0x1]; u16 f88; u8 pad8A[0x14A]; s16 f1D4; s16 f1D6; u8 pad1D8[0x4]; s8 f1DC; u8 pad1DD[0x1F]; u8 f1FC; u8 f1FD; u8 f1FE; u8 pad1FF[0x2]; u8 f201; u8 pad202[0x24]; u8 f226; u8 pad227[0x1]; u16 f228; u8 pad22A[0xB6]; }; +struct T015LActor { u16 f0; u16 f2; u16 f4; u16 f6; u16 f8; u8 padA[0x2]; u16 fC; u16 fE; u8 pad10[0x4]; s32 f14; s32 f18; s32 f1C; s32 f20; u8 pad24[0xC]; s32 f30; s32 f34; u8 pad38[0x4]; s32 f3C; u8 pad40[0x2]; s16 f42; s16 f44; u8 pad46[0x4]; s16 f4A; s32 f4C; s32 f50; s32 f54; u8 pad58[0x2]; u16 f5A; s16 f5C; s16 f5E; s16 f60; u16 f62; u16 f64; u16 f66; u16 f68; s16 f6A; s16 f6C; u16 f6E; u16 f70; u16 f72; u16 f74; u8 pad76[0x6]; u16 f7C; u16 f7E; s16 f80; s16 f82; u8 f84; u8 pad85[0x1]; u8 f86; u8 pad87[0x1]; u16 f88; u8 pad8A[0x14A]; s16 f1D4; s16 f1D6; u8 pad1D8[0x4]; s8 f1DC; u8 pad1DD[0x1F]; u8 f1FC; u8 f1FD; u8 f1FE; u8 pad1FF[0x2]; u8 f201; u8 pad202[ENEMY_FIELD(0x226) - 0x202]; u8 f226; u8 pad227[0x1]; u16 f228; u8 pad22A[0xB6]; }; struct T015LAnim { s32 f0,f4,f8,fC,f10,f14,f18; s8 data[24]; }; struct T015LStack { u32 packet[4]; struct T015LAnim main,auxA,auxB,base; s16 x,y; u16 step; s16 state; u16 phase,phase2; s32 rng; }; #define T015L_FIELD(p,t,o) (*(t)((u8 *)(p)+(o))) @@ -88,12 +88,12 @@ extern void T015L_sub_0807854C(u16, s16) asm("sub_0807854C"); extern void T015L_sub_08078B24(u16, s16) asm("sub_08078B24"); extern u8 T015L_gUnk_08479140[] asm("gUnk_08479140"); extern u8 T015L_gUnk_0848FA0C[] asm("gUnk_0848FA0C"); -struct T015LData { s16 f0; u8 p2[2]; s16 f4; s16 f6; s16 f8; u8 pA[0x16]; u16 f20; u8 p22[4]; u8 f26; u8 p27[0x1D]; u8 f44; s8 f45; s8 f46; u8 p47[0x8D]; u16 fD4; u16 fD6; }; +struct T015LData { u8 pName[ENEMY_DATA_FIELD(0)]; s16 f0; u8 p2[2]; s16 f4; s16 f6; s16 f8; u8 pA[0x16]; u16 f20; u8 p22[4]; u8 f26; u8 p27[0x1D]; u8 f44; s8 f45; s8 f46; u8 p47[0x8D]; u16 fD4; u16 fD6; }; struct T015LAnimDef { u32 a; u8 p4[0x28]; u32 b; u8 p30[0x28]; }; struct T015LScale { u32 a, b, c; }; extern struct T015LAnimDef T015L_anims[] asm("gUnk_08479140"); extern struct T015LScale T015L_scales[] asm("gUnk_0848FA0C"); -struct T015LPl { u16 f0; u8 p2[0x2E]; u32 f30; u8 p34[0x92]; u16 fC6; u8 pC8[0x84]; }; +struct T015LPl { u16 f0; u8 p2[PLAYER_FIELD(0x30) - 2]; u32 f30; u8 p34[0x92]; u16 fC6; u8 pC8[0x84]; }; extern struct T015LPl T015L_players[] asm("gUnk_03003CE0"); #define T015L_DRAW ((void (*)(s32, s32, u16, u16, u32, void *, u32, u32))T015L_sub_08007870) #define T015L_F7A T015L_FIELD(arg0, u16 *, 0x7A) @@ -125,6 +125,9 @@ void sub_0801801C(struct T015LActor *arg0) { s32 h; struct T015LAnim *anim; u16 w; +#ifdef REGION_USA + u32 nul; +#endif register s32 st asm("r2"); /* ROM loads the switch value straight into r2 */ sp118 = (struct T015LData *)((u8 *)arg0 + 0x204); @@ -146,10 +149,10 @@ void sub_0801801C(struct T015LActor *arg0) { { register u32 blk asm("r6"); - T015L_sub_08065158(&stack.base.f0, 0x50010, 0, -1, 0); - T015L_sub_08065158(&stack.auxA.f0, 0x5008C, 0, -1, 0); + T015L_sub_08065158(&stack.base.f0, RES_ID(0x50010), 0, -1, 0); + T015L_sub_08065158(&stack.auxA.f0, RES_ID(0x5008C), 0, -1, 0); pb = &stack.auxB; - T015L_sub_08065158(&pb->f0, 0x5008B, 0, -1, 0); + T015L_sub_08065158(&pb->f0, RES_ID(0x5008B), 0, -1, 0); asm("" : : "r"(blk)); } if (sub_0800CCCC() == 0 && sub_0800CC98() == 0) @@ -199,10 +202,17 @@ void sub_0801801C(struct T015LActor *arg0) { arg0->f42 = 0; arg0->f44 = 0; { +#ifdef REGION_USA + struct { s16 v; } *p60; +#endif u32 off; stack.state = 0; do { stack.step = 0; } while (0); +#ifdef REGION_USA + do { p60 = (void *)&arg0->f60; p60->v = 0xFFC4; } while (0); +#else do { arg0->f60 = 0xFFC4; } while (0); +#endif arg0->f4C = 0; local104 = 0; arg0->f4A = 0; @@ -218,6 +228,9 @@ void sub_0801801C(struct T015LActor *arg0) { } asm("" : : "r"(blk)); } +#ifdef REGION_USA + asm("" : "=g"(sp118) : "0"(sp118)); +#endif arg0->f5C = arg0->f1D6 = sp118->f6 * 3; arg0->f5E = arg0->f1D4 = ((sp118->f4 << 1) * 4 + (sp118->f4 << 1)) * 2; local124 = 1; @@ -614,7 +627,11 @@ void sub_0801801C(struct T015LActor *arg0) { if (sub_0800CC88() != 0) bg = gUnk_030034A8; { +#ifdef REGION_USA + asm("" : "=r"(nul) : "0"(0)); +#else register u32 nul asm("sl") = 0; +#endif anim = &stack.main; anim->data[0] = local114; anim->data[1] = local114; @@ -807,7 +824,7 @@ void sub_0801801C(struct T015LActor *arg0) { } } sub_0801E4CC((u8 *)gUnk_030034E0, obj); - if (T015L_FIELD(gUnk_030034E0, u8 *, 0x13A) != 0) + if (T015L_FIELD(gUnk_030034E0, u8 *, SAVE_FIELD(0x13A)) != 0) T015L_players[sub_080020F4()].fC6++; } } @@ -819,6 +836,15 @@ void sub_0801801C(struct T015LActor *arg0) { arg0->f1C = arg0->f14; arg0->f20 = arg0->f18; gUnk_030056FC &= ~(1 << arg0->f0); +#ifdef REGION_USA + /* No code: makes nul a global pseudo whose long live range ranks it below the loop-wide pseudos, + so it is placed in r9 by the retry pass like the ROM. */ +#define PAD8 asm(""); asm(""); asm(""); asm(""); asm(""); asm(""); asm(""); asm(""); + asm volatile("" : "=r"(nul)); + PAD8 PAD8 PAD8 PAD8 + asm("" : : "r"(nul)); +#undef PAD8 +#endif sub_08016ECC(local114); } #undef T015L_F7A @@ -839,7 +865,7 @@ void *sub_08019BF8(u16 id) u32 *flags = (u32 *)&gUnk_030056FC; u32 one = 1; u32 mask = *flags; - for (; i < 5; i++, entry += 0x2E0) + for (; i < 5; i++, entry += ENEMY_SIZE) if ((mask & (one << i)) != 0 && *(u16 *)(entry + 2) == id) return entry; return 0; @@ -856,7 +882,7 @@ u32 sub_08019C3C(void) u32 i = 0; u32 one = 1; u32 mask = gUnk_030056FC; - u32 step = 0x2E0; + u32 step = ENEMY_SIZE; u8 *entry = base + 0x4A; do { if ((mask & (one << i)) && *(s16 *)(entry + 0x12) - *(u16 *)entry > 0) @@ -923,8 +949,8 @@ u32 sub_08019CE8(u8 *obj) } return 0; } -u32 sub_08019D34(value) -u16 value; +u32 hasActor19D34(u16 value) asm("sub_08019D34"); +u32 hasActor19D34(u16 value) { u8 *entry; u32 i; @@ -937,7 +963,7 @@ u16 value; flags = (u32 *)&gUnk_030056FC; one = 1; active = *flags; - for (; i <= 4; i++, entry += 0x2E0) { + for (; i <= 4; i++, entry += ENEMY_SIZE) { if ((active & (one << i)) && *(u16 *)(entry + 2) == value) return 1; } return 0; @@ -973,7 +999,7 @@ u32 sub_08019DE0(u32 value) u32 *pf = (u32 *)&gUnk_030056FC; u32 one = 1; s32 flags = *pf; - for (; i <= 4; i++, entry += 0x2E0) { + for (; i <= 4; i++, entry += ENEMY_SIZE) { if (((one << i) & flags) && *(u32 *)(entry + 0x2C) == value) return 1; } return 0; @@ -1004,7 +1030,7 @@ s32 sub_08019E30(s32 arg0) var_r4 |= temp_r1; } var_r2 += 1; - var_r3 += 0x2E0; + var_r3 += ENEMY_SIZE; } while (var_r2 <= 4U); return var_r4; @@ -1040,7 +1066,7 @@ void sub_08019EB8(u16 key, u16 value) goto test; loop: i++; - entry += 0x2E0; + entry += ENEMY_SIZE; if (i > 4) goto end; bit = 1 << i; test: @@ -1076,7 +1102,7 @@ void sub_08019F04(void) } } i++; - player += 0x2E0; + player += ENEMY_SIZE; if (i <= 4) goto loop; } /* [ScaleActorStatPairForPlayerCount] Uses the connected-player count from sub_08002164 to index three-word @@ -1088,8 +1114,17 @@ void sub_08019F60(s16 *data) struct Rate { u32 a, b, c; }; extern const struct Rate rates[] asm("gUnk_0848FA0C"); u32 index = sub_08002164(); +#ifdef REGION_USA + s16 *third = (s16 *)((u8 *)data + ENEMY_DATA_FIELD(6)); + *third = *third * rates[index].a / 100; + if (index > 1) { + s16 *first = (s16 *)((u8 *)data + ENEMY_DATA_FIELD(0)); + *first = (*first + 2) * rates[index].b / 100; + } +#else data[3] = data[3] * rates[index].a / 100; if (index > 1) data[0] = (data[0] + 2) * rates[index].b / 100; +#endif } /* [HasFreeEnemySpawnRequestSlot] Checks only bits 0 and 1 of request mask 03005724 and returns exactly 1 when * either is clear, otherwise 0. It does not reserve a slot or inspect the separate five-enemy actor mask @@ -1143,7 +1178,7 @@ void sub_0801A050(u16 key) asm("" : "+r"(z)); zero = z; } asm("" : : "r"(zero)); - for (; i <= 4; i++, entry += 0x2E0) { + for (; i <= 4; i++, entry += ENEMY_SIZE) { s32 bit = one << i; if ((*flags & bit) && *(u16 *)(entry + 2) == key) { *(u16 *)(entry + 0x7A) |= one; @@ -1171,7 +1206,7 @@ void sub_0801A0BC(u16 key, u16 value) i = 0; flags = &gUnk_030056FC; one = 1; - for (; i <= 4; i++, entry += 0x2E0) { + for (; i <= 4; i++, entry += ENEMY_SIZE) { s32 bit = one << i; if ((*flags & bit) && *(u16 *)(entry + 2) == key) { entry[0x1DC] = value; @@ -1205,6 +1240,37 @@ void sub_0801A120(u8 *obj, u32 value, u16 offset) * coordinate differences right by 8, computes integer Sqrt distance, truncates it to u16 and selects the first * strictly smallest distance below 65535. Returns the slot and writes distance, or returns 0xFF without * writing distance when none qualifies. */ +#ifdef REGION_USA +u32 sub_0801A1C8(u8 *obj, s32 *distance) +{ + s32 nearest = 0xFFFF; + s32 selected = -1; + u32 i = 0; + s32 *flags = &gUnk_030056FC; + u8 **base = (u8 **)&gUnk_030056F4; + for (; i <= 4; i++) { + s32 bit = 1 << i; + if (*flags & bit) { + u8 *other = *base + i * ENEMY_SIZE; + if (other != obj) { + s32 dx = (*(s32 *)(other + 0x14) - *(s32 *)(obj + 0x14)) >> 8; + s32 dy = (*(s32 *)(other + 0x18) - *(s32 *)(obj + 0x18)) >> 8; + u32 length = (u16)Sqrt(dx * dx + dy * dy); + if (nearest > (s32)length) { + nearest = length; + selected = i; + } + } + } + } + { + u32 result; + if (selected != -1) { *distance = nearest; result = (u16)selected; } + else result = 0xFF; + return result; + } +} +#else u32 sub_0801A1C8(u8 *obj, s32 *distance) { s32 nearest = 0xFFFF; @@ -1213,7 +1279,7 @@ u32 sub_0801A1C8(u8 *obj, s32 *distance) u8 **base = (u8 **)&gUnk_030056F4; u32 offset = 0; s32 *flags = &gUnk_030056FC; - for (; i <= 4; offset += 0x2E0, i++) { + for (; i <= 4; offset += ENEMY_SIZE, i++) { s32 bit = 1 << i; if (*flags & bit) { u8 *other = *base + offset; @@ -1235,6 +1301,7 @@ u32 sub_0801A1C8(u8 *obj, s32 *distance) return result; } } +#endif /* [FindFreeActorSlot] Returns the first clear bit index from 0 through 4 in actor activity bitmap 0x030056FC, * or -1 if all slots are occupied. It does not allocate or initialize the slot. */ s32 sub_0801A270(void) @@ -1339,11 +1406,11 @@ void sub_0801A388(u32 index) u8 state1FD; u8 pad3[3]; u8 state201; - u8 pad4[0xDE]; + u8 pad4[ENEMY_SIZE - 0x202]; }; extern struct Entity *entities asm("gUnk_030056F4"); struct Entity *base = entities; - struct Entity *entry = (struct Entity *)(index * 0x2E0 + (u32)base); + struct Entity *entry = (struct Entity *)(index * ENEMY_SIZE + (u32)base); entry->flags |= 4; entry->state201 = 0; entities[index].state1FD = 0xFF; @@ -1379,6 +1446,57 @@ static inline void FlushRows16(u32 index, u32 count) * queues64bytes fromfont+glyph*128 toVRAM0600B000+uploadcursor via01348, writes two consecutive maptiles and * advancescursor64. This proves256slotstride128 and used64B per glyph; byte0 maps255, not a Cstring * terminator. No full script encoding map claimed. */ +#ifdef REGION_USA +void sub_0801A3D0(const TextChar *script, u16 x, u32 row) +{ + register u32 column asm("sl") = x; + volatile u32 savedRow = (u16)row; + u16 tile; + FlushRows16((u16)row, 2); + tile = (gUnk_03005C54 >> 5) + 0x180; + while (1) { + register u32 scratch asm("r1"); + u32 xOffset; + register u32 rowOffset asm("r3"); + register u32 rowLoad asm("r2"); + u16 *map; + register u32 mapBaseNext asm("r2"); + u32 glyph; + u8 *font; + if (*script == TEXT_CTRL(0xFD)) break; + if (*script & 0x8000) break; + scratch = (u32)(*script - 1) << 16; + { u32 page = scratch >> 24; font = (u8 *)gUnk_03005CA0[page]; } + glyph = 0xFF0000; + glyph &= scratch; + xOffset = column * 2; + rowLoad = savedRow; + rowOffset = rowLoad * 64; + rowOffset = xOffset + rowOffset; + scratch = (u32)gUnk_03005740; + map = (u16 *)(rowOffset + scratch); + { + u16 oldTile = tile++; + scratch = 0xF000; + *map = oldTile | scratch; + } + scratch = savedRow + 1; + scratch *= 64; + xOffset += scratch; + mapBaseNext = (u32)gUnk_03005740; + xOffset += mapBaseNext; + { + u16 oldTile = tile++; + scratch = 0xF000; + *(u16 *)xOffset = oldTile | scratch; + } + sub_08001348(font + (glyph >> 9), (void *)(0x0600B000 + gUnk_03005C54), 64); + gUnk_03005C54 += 64; + column = (u16)(column + 1); + script++; + } +} +#else void sub_0801A3D0(const u8 *script, u16 x, u32 row) { register u32 column asm("sl") = x; @@ -1428,6 +1546,7 @@ void sub_0801A3D0(const u8 *script, u16 x, u32 row) script++; } } +#endif /* [UnusedNoOpStub4] Lines 1338-1340 define an empty variadic function between glyph tile queuing and text * initialization. */ void sub_0801A500(u32 a, u32 b, u32 c, ...) @@ -1503,6 +1622,19 @@ void sub_0801A62C(void) { } /* [CountRenderableScriptGlyphs] Counts bytes until 0xFD or a value above 0xF1. Zero counts as a glyph; this is * not a zero-terminated string length. */ +#ifdef REGION_USA +/* USA 16-bit text: stops at 0xFFFD or any control halfword (bit 15 set). */ +s32 sub_0801A638(u8 *text) +{ + TextChar *p = (TextChar *)text; + u32 n = 0; + while (*p != TEXT_CTRL(0xFD) && !(*p & 0x8000)) { + n++; + p++; + } + return n; +} +#else s32 sub_0801A638(u8 *p) { s32 n = 0; @@ -1515,6 +1647,7 @@ s32 sub_0801A638(u8 *p) } return n; } +#endif /* [UpdateSharedHalfwordMinimum] Body compares (u32)global > arg0, then conditionally stores(u16)arg0. This is * unsigned minimum update, not signed clamp or unconditional truncation. */ void sub_0801A650(u32 arg0) @@ -1564,7 +1697,7 @@ void sub_0801A6D4(u32 mode) u32 resource; switch (mode) { case 0: resource = 0x80006; goto load; - case 1: resource = 0x8004A; + case 1: resource = RES_ID(0x8004A); load: base = (u8 *)sub_08006EE0(resource, (void *)&gUnk_08518938); } @@ -1580,12 +1713,26 @@ void sub_0801A70C(void) count = sub_08007164(4); for (i = 0; i < count; i++) gUnk_03005CA0[i] = sub_08007290(i | 0x40000); - sub_08065158(gUnk_03005C60, 0x5004A, 0, -1, 0); + sub_08065158(gUnk_03005C60, RES_ID(0x5004A), 0, -1, 0); } /* [DrawScriptGlyphStringAsSprites] Walks bytes until 0xFD or a value above 0xF1, passes frame (u16)(byte - 1) * to 65230 using descriptor 03005C60, and advances X by 8 with 16-bit wrap. Byte zero passes frame 65535 * rather than terminating the string. */ -void sub_0801A764(const u8 *script, u16 x, u16 y) +#ifdef REGION_USA +/* USA text is halfword characters: 0xFFFD ends the string, codes with bit 15 set are controls. */ +void sub_0801A764(const TextChar *script, u16 x, u16 y) +{ + u32 count; + while (*script != 0xFFFD && !(*script & 0x8000)) { + /* The ROM reloads the character after the control test. */ + count = (u16)(*(volatile const TextChar *)script - 1); + sub_08065230(gUnk_03005C60, x, y, 0, count); + x = (u16)(x + 8); + script++; + } +} +#else +void sub_0801A764(const TextChar *script, u16 x, u16 y) { u32 count; while (1) { @@ -1597,6 +1744,7 @@ void sub_0801A764(const u8 *script, u16 x, u16 y) script++; } } +#endif /* Preserve the blend-call argument evaluation order of the original inlines. */ static inline void blendA16(s32 a, s32 b, s32 c) { diff --git a/src/code_0801AAF8.c b/src/code_0801AAF8.c index a0be6029..70d8b7aa 100644 --- a/src/code_0801AAF8.c +++ b/src/code_0801AAF8.c @@ -200,7 +200,7 @@ void sub_0801ACB8(void) u16 *selected; templates = (struct S17Stats32 *)gUnk_0848FA48; - *(struct S17Stats32 *)(state + 0x10) = templates[*(u16 *)(state + 0xA)]; + *(struct S17Stats32 *)(state + SAVE_FIELD(0x10)) = templates[*(u16 *)(state + SAVE_FIELD(0xA))]; switch (sub_0801DE60()) { case 0: sub_0805D064(gUnk_0848FB84, 0); @@ -300,11 +300,11 @@ void sub_0801ACB8(void) sub_0805D190(); sub_0805D1E0(); i = 0; - selected = (u16 *)(state + 0x68); - energy = (s16 *)(player + 0xC2); - maxEnergy = (s16 *)(player + 0x60); - hp = (s16 *)(player + 0xC4); - maxHp = (s16 *)(player + 0x62); + selected = (u16 *)(state + SAVE_FIELD(0x68)); + energy = (s16 *)(player + SAVE_FIELD(0xC2)); + maxEnergy = (s16 *)(player + SAVE_FIELD(0x60)); + hp = (s16 *)(player + SAVE_FIELD(0xC4)); + maxHp = (s16 *)(player + SAVE_FIELD(0x62)); do { *(u32 *)&effect.value = 0; effect.id = gUnk_0848FB68[i].id; @@ -316,8 +316,8 @@ void sub_0801ACB8(void) } while (i <= 4); sub_0805CFF8(0x18, gUnk_0848FB7C); switch (sub_0802A9B0()) { - case 0: *(u16 *)(state + 0x12) += 5; break; - case 1: *(u16 *)(state + 0x24) += 30; break; + case 0: *(u16 *)(state + SAVE_FIELD(0x12)) += 5; break; + case 1: *(u16 *)(state + SAVE_FIELD(0x24)) += 30; break; case 2: effect.type = 6; effect.id = 0x5E; @@ -336,10 +336,10 @@ void sub_0801ACB8(void) effect.b7 = 0; sub_0805AB20(&effect); break; - case 4: *(u16 *)(state + 0x10) += 5; break; - case 5: *(u16 *)(state + 0x26) += 30; break; - case 6: *(u16 *)(state + 0x16) += 5; break; - case 7: *(u16 *)(state + 0x2E) += 30; break; + case 4: *(u16 *)(state + SAVE_FIELD(0x10)) += 5; break; + case 5: *(u16 *)(state + SAVE_FIELD(0x26)) += 30; break; + case 6: *(u16 *)(state + SAVE_FIELD(0x16)) += 5; break; + case 7: *(u16 *)(state + SAVE_FIELD(0x2E)) += 30; break; case 8: effect.type = 4; effect.id = 0x95; @@ -349,8 +349,8 @@ void sub_0801ACB8(void) effect.b7 = 0; sub_0805AB20(&effect); break; - case 9: *(u16 *)(state + 0x2A) += 30; break; - case 10: *(u16 *)(state + 0x2C) += 30; break; + case 9: *(u16 *)(state + SAVE_FIELD(0x2A)) += 30; break; + case 10: *(u16 *)(state + SAVE_FIELD(0x2C)) += 30; break; case 11: effect.type = 6; effect.id = 0x5F; @@ -361,8 +361,8 @@ void sub_0801ACB8(void) sub_0805AB20(&effect); break; case 12: - *(u16 *)(state + 0x14) += 5; - *(u16 *)(state + 0x28) += 30; + *(u16 *)(state + SAVE_FIELD(0x14)) += 5; + *(u16 *)(state + SAVE_FIELD(0x28)) += 30; break; } *selected = 0; @@ -531,7 +531,7 @@ s32 sub_0801B58C(u8 *item, s32 stats, u16 value, u16 kind) register s32 factor asm("r4"); switch (kind) { case 0: - switch (item[0x9B]) { + switch (ITEM_KIND(item)) { case 2: factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 1); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 1) + ((s16)value * ((u16)factor + 10)) / 10; @@ -547,17 +547,17 @@ s32 sub_0801B58C(u8 *item, s32 stats, u16 value, u16 kind) } break; case 3: - if (item[0x9B] == 2) { + if (ITEM_KIND(item) == 2) { factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0) + ((s16)value * ((u16)factor + 10)) / 10; - } else if (item[0x9B] == 4) { + } else if (ITEM_KIND(item) == 4) { factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 1); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 1) + ((s16)value * ((u16)factor + 10)) / 10; } break; case 2: - if (item[0x9B] != 3) { - if (item[0x9B] == 7) { + if (ITEM_KIND(item) != 3) { + if (ITEM_KIND(item) == 7) { factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0) + ((s16)value * ((u16)factor + 10)) / 10; } @@ -567,34 +567,34 @@ s32 sub_0801B58C(u8 *item, s32 stats, u16 value, u16 kind) } break; case 5: - if (item[0x9B] == 6) { + if (ITEM_KIND(item) == 6) { factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0) + ((s16)value * ((u16)factor + 10)) / 10; - } else if (item[0x9B] == 8) { + } else if (ITEM_KIND(item) == 8) { factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 1); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 1) + ((s16)value * ((u16)factor + 10)) / 10; } break; case 4: - if (item[0x9B] == 4) { + if (ITEM_KIND(item) == 4) { factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 1); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 1) + ((s16)value * ((u16)factor * 8 + 100)) / 100; - } else if (item[0x9B] == 5) { + } else if (ITEM_KIND(item) == 5) { factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0) + ((s16)value * ((u16)factor + 10)) / 10; } break; case 7: - if (item[0x9B] == 1) { + if (ITEM_KIND(item) == 1) { factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0) + ((s16)value * ((u16)factor + 10)) / 10; - } else if (item[0x9B] == 8) { + } else if (ITEM_KIND(item) == 8) { factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 1); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 1) + ((s16)value * ((u16)factor + 10)) / 10; } break; case 1: case 6: case 8: - if (item[0x9B] == 5) { + if (ITEM_KIND(item) == 5) { factor = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0); value = ((s32 (*)(s32, s32))sub_0801E0AC)(stats, 0) + ((s16)value * ((u16)factor + 10)) / 10; } @@ -629,11 +629,22 @@ void sub_0801B720(s16 *p, s16 delta) { p[4] = p[4] - delta; p[5] = p[5] - delta; } -struct S17ItemC4 { u8 data[0xC4]; }; -struct S17ItemB8 { u8 data[0xB8]; }; -struct S17ItemB4 { u8 data[0xB4]; }; -struct S17ItemB0 { u8 data[0xB0]; }; +struct S17ItemC4 { u8 data[ITEM_FIELD(0xC4)]; }; +struct S17ItemB8 { u8 data[EQUIP_FIELD(0xB8)]; }; +#ifdef REGION_USA +struct S17ItemGlove { u8 data[EQUIP_FIELD(0xB8) + 4]; }; /* USA glove records are 4 bytes longer */ +#define S17_GLOVE_FIELD(o) (EQUIP_FIELD(o) + 4) +#else +#define S17_GLOVE_FIELD(o) (o) +struct S17ItemGlove { u8 data[0xB8]; }; +#endif +struct S17ItemB4 { u8 data[ITEM_FIELD(0xB4)]; }; +struct S17ItemB0 { u8 data[ITEM_FIELD(0xB0)]; }; +#ifdef REGION_USA +struct S17Set { u8 pad[0x174]; u16 slots[6]; }; /* USA set names are halfword text */ +#else struct S17Set { u8 pad[0x136]; u16 slots[6]; }; +#endif /* [MatchesEquipmentSetRequirements] Checks six required resource-index halfwords at set record +0x136. Value * 65535 ignores that requirement; otherwise the corresponding supplied resource pointer must be nonnull and * its resource-array index must equal the requirement. Returns exactly 1 when every required position matches, @@ -661,7 +672,7 @@ s32 sub_0801B74C(struct S17Set *set, struct S17ItemC4 *a, struct S17ItemB8 *b, s matched++; break; case 3: - if (d && d - (struct S17ItemB8 *)sub_08007290(0xE0000) == set->slots[i]) + if (d && (struct S17ItemGlove *)d - (struct S17ItemGlove *)sub_08007290(0xE0000) == set->slots[i]) matched++; break; case 4: @@ -680,7 +691,13 @@ s32 sub_0801B74C(struct S17Set *set, struct S17ItemC4 *a, struct S17ItemB8 *b, s return 0; } +#ifdef REGION_USA +struct S17SetEntry { u8 data[0x18C]; }; +#define S17_SET_BONUS 0x180 +#else struct S17SetEntry { u8 data[0x150]; }; +#define S17_SET_BONUS 0x144 +#endif extern struct S17SetEntry gUnk_08490120[]; struct S17State { u8 pad[0x5B4]; struct S17SetEntry *active; }; extern struct S17State *s17_state asm("gUnk_03006440"); @@ -695,52 +712,52 @@ s32 sub_0801B8A8(struct S17ItemC4 *a, struct S17ItemB8 *b, struct S17ItemB8 *c, if (s17_state) s17_state->active = 0; - if (a && *(u16 *)(a->data + 0xC2)) { - set = &gUnk_08490120[*(u16 *)(a->data + 0xC2)]; + if (a && *(u16 *)(a->data + ITEM_FIELD(0xC2))) { + set = &gUnk_08490120[*(u16 *)(a->data + ITEM_FIELD(0xC2))]; if (sub_0801B74C((struct S17Set *)set, a, b, c, d, e, f)) { if (s17_state) s17_state->active = set; - return (s32)(set->data + 0x144); + return (s32)(set->data + S17_SET_BONUS); } } - if (b && *(u16 *)(b->data + 0xB4)) { - set = &gUnk_08490120[*(u16 *)(b->data + 0xB4)]; + if (b && *(u16 *)(b->data + EQUIP_FIELD(0xB4))) { + set = &gUnk_08490120[*(u16 *)(b->data + EQUIP_FIELD(0xB4))]; if (sub_0801B74C((struct S17Set *)set, a, b, c, d, e, f)) { if (s17_state) s17_state->active = set; - return (s32)(set->data + 0x144); + return (s32)(set->data + S17_SET_BONUS); } } - if (c && *(u16 *)(c->data + 0xB4)) { - set = &gUnk_08490120[*(u16 *)(c->data + 0xB4)]; + if (c && *(u16 *)(c->data + EQUIP_FIELD(0xB4))) { + set = &gUnk_08490120[*(u16 *)(c->data + EQUIP_FIELD(0xB4))]; if (sub_0801B74C((struct S17Set *)set, a, b, c, d, e, f)) { if (s17_state) s17_state->active = set; - return (s32)(set->data + 0x144); + return (s32)(set->data + S17_SET_BONUS); } } - if (d && *(u16 *)(d->data + 0xB4)) { - set = &gUnk_08490120[*(u16 *)(d->data + 0xB4)]; + if (d && *(u16 *)(d->data + S17_GLOVE_FIELD(0xB4))) { + set = &gUnk_08490120[*(u16 *)(d->data + S17_GLOVE_FIELD(0xB4))]; if (sub_0801B74C((struct S17Set *)set, a, b, c, d, e, f)) { if (s17_state) s17_state->active = set; - return (s32)(set->data + 0x144); + return (s32)(set->data + S17_SET_BONUS); } } - if (e && *(u16 *)(e->data + 0xB0)) { - set = &gUnk_08490120[*(u16 *)(e->data + 0xB0)]; + if (e && *(u16 *)(e->data + ITEM_FIELD(0xB0))) { + set = &gUnk_08490120[*(u16 *)(e->data + ITEM_FIELD(0xB0))]; if (sub_0801B74C((struct S17Set *)set, a, b, c, d, e, f)) { if (s17_state) s17_state->active = set; - return (s32)(set->data + 0x144); + return (s32)(set->data + S17_SET_BONUS); } } - if (f && *(u16 *)(f->data + 0xAC)) { - set = &gUnk_08490120[*(u16 *)(f->data + 0xAC)]; + if (f && *(u16 *)(f->data + ITEM_FIELD(0xAC))) { + set = &gUnk_08490120[*(u16 *)(f->data + ITEM_FIELD(0xAC))]; if (sub_0801B74C((struct S17Set *)set, a, b, c, d, e, f)) { if (s17_state) s17_state->active = set; - return (s32)(set->data + 0x144); + return (s32)(set->data + S17_SET_BONUS); } } return 0; @@ -749,11 +766,26 @@ s32 sub_0801B8A8(struct S17ItemC4 *a, struct S17ItemB8 *b, struct S17ItemB8 *c, struct BA74Res { s16 v[6]; }; struct BA74Stats { s16 f0, f2, f4, f6; s16 f8; u16 fA[5]; struct BA74Res res; }; struct BA74Slot { u16 f0; u16 id; u16 sub; u8 bonus; u8 f7; u8 broken; u8 valid; u8 padA[6]; }; +#ifdef REGION_USA +#define T5_FLAG_BA74 (*(u32 *)(t5 + EQUIP_FIELD(0xA0))) +#else +#define T5_FLAG_BA74 (t5[0xA0]) +#endif +#ifdef REGION_USA +#define ITEM_LV_BA74(r) (*(s16 *)((u8 *)(r) + ITEM_KIND_OFF + 2)) +#else +#define ITEM_LV_BA74(r) (((u8 *)(r))[0x9C]) +#endif +#ifdef REGION_USA +#define KIND_S_BA74(r) (*(s16 *)((u8 *)(r) + ITEM_KIND_OFF)) +#else +#define KIND_S_BA74(r) ITEM_KIND(r) +#endif struct BA74Save { - u8 pad0[0xA]; + NameChar pad0[0xA]; u16 fA; u16 fC; - u8 padE[2]; + u8 padE[SAVE_FIELD(0x10) - SAVE_FIELD(0xE)]; struct BA74Stats stats; u8 pad30[0x24]; u16 f54; @@ -775,6 +807,7 @@ struct BA74Mod { struct BA74Ent { s16 f0; u16 f2; u16 f4; u16 f6; s16 f8, fA, fC, fE; u16 f10; u8 pad12[0xA]; s16 f1C; u8 pad1E[0xA]; }; struct BA74Pos { u16 f0; u16 f2; }; struct BA74Job { + u8 pre[ENEMY_DATA_FIELD(0)]; s16 f0, f2, f4, f6; u16 f8; u16 fA; @@ -788,25 +821,25 @@ struct BA74Job { }; struct BA74Unit { u16 f0; - u8 pad2[0xA]; + u8 pad2[PLAYER_FIELD(0xC) - PLAYER_FIELD(0x2)]; u16 fC; - u8 padE[2]; + u8 padE[PLAYER_FIELD(0x10) - PLAYER_FIELD(0xE)]; u16 f10; - u8 pad12[0x1E]; + u8 pad12[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x12)]; u32 f30; struct BA74Ent *f34; - u8 pad38[0x2C]; + u8 pad38[PLAYER_FIELD(0x64) - PLAYER_FIELD(0x38)]; u16 f64; u8 f66; u8 pad67; u8 f68; - u8 pad69[0x23]; + u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 f8C[0x29]; - u8 pad130[2]; + u8 pad130[PLAYER_FIELD(0x132) - PLAYER_FIELD(0x130)]; u16 f132; - u8 pad134[4]; + u8 pad134[PLAYER_FIELD(0x138) - PLAYER_FIELD(0x134)]; struct BA74Job *f138; - u8 pad13C[0xC]; + u8 pad13C[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x13C)]; struct BA74Pos *f148; }; struct BA74Cls { u8 pad0[8]; s16 f8; u8 padA[0x16]; }; @@ -864,7 +897,11 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat s32 w; struct BA74Save *p; u8 *sub; +#ifdef REGION_USA + s32 v; +#else u16 v; +#endif s32 x; struct BA74Ent *e; s32 tmp; @@ -965,9 +1002,9 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat sub = (u8 *)sub_08007290((arg1->sub - 1) | 0x130000); else sub = 0; - arg3->f6 = t2[0xA4]; - sub_0801B264(t2 + 0xB0, (u16 *)arg2, (u8 *)arg3); - sub_0801B264(sub + 0xA0, (u16 *)arg2, (u8 *)arg3); + arg3->f6 = t2[ITEM_FIELD(0xA4)]; + sub_0801B264(t2 + ITEM_FIELD(0xB0), (u16 *)arg2, (u8 *)arg3); + sub_0801B264(sub + ITEM_FIELD(0xA0), (u16 *)arg2, (u8 *)arg3); } if (t3 != 0) { if (arg1 == 0 || arg1->type != 3) { @@ -979,8 +1016,8 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat sub = (u8 *)sub_08007290((arg1->sub - 1) | 0x130000); else sub = 0; - sub_0801B264(t3 + 0xA4, (u16 *)arg2, (u8 *)arg3); - sub_0801B264(sub + 0xA0, (u16 *)arg2, (u8 *)arg3); + sub_0801B264(t3 + EQUIP_FIELD(0xA4), (u16 *)arg2, (u8 *)arg3); + sub_0801B264(sub + ITEM_FIELD(0xA0), (u16 *)arg2, (u8 *)arg3); } if (t4 != 0) { if (arg1 == 0 || arg1->type != 4) { @@ -992,8 +1029,8 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat sub = (u8 *)sub_08007290((arg1->sub - 1) | 0x130000); else sub = 0; - sub_0801B264(t4 + 0xA4, (u16 *)arg2, (u8 *)arg3); - sub_0801B264(sub + 0xA0, (u16 *)arg2, (u8 *)arg3); + sub_0801B264(t4 + EQUIP_FIELD(0xA4), (u16 *)arg2, (u8 *)arg3); + sub_0801B264(sub + ITEM_FIELD(0xA0), (u16 *)arg2, (u8 *)arg3); } if (t5 != 0) { if (arg1 == 0 || arg1->type != 5) { @@ -1005,16 +1042,16 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat sub = (u8 *)sub_08007290((arg1->sub - 1) | 0x130000); else sub = 0; - sub_0801B264(t5 + 0xA4, (u16 *)arg2, (u8 *)arg3); - sub_0801B264(sub + 0xA0, (u16 *)arg2, (u8 *)arg3); - if (t5[0xA0] != 0) { + sub_0801B264(t5 + EQUIP_E_FIELD(0xA4), (u16 *)arg2, (u8 *)arg3); + sub_0801B264(sub + ITEM_FIELD(0xA0), (u16 *)arg2, (u8 *)arg3); + if (T5_FLAG_BA74 != 0) { w = arg3->f15; sub_0801DE60(); arg3->f16 += BA74_atk(w, arg4); } } if (t6 != 0) - sub_0801B264(t6 + 0xA0, (u16 *)arg2, (u8 *)arg3); + sub_0801B264(t6 + ITEM_FIELD(0xA0), (u16 *)arg2, (u8 *)arg3); halve = 0; arg0->f132 = 0; @@ -1096,11 +1133,11 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat arg0->f64 = job->fD4 + 10; arg0->f66 = job->fD6; t2 = (u8 *)sub_08007290(job->f28 | 0xB0000); - arg0->f10 = t2[0x9B]; + arg0->f10 = ITEM_KIND(t2); t3 = 0; t4 = 0; t5 = 0; - arg3->f6 = t2[0xA4]; + arg3->f6 = t2[ITEM_FIELD(0xA4)]; bonus += job->fA; arg2->f0 += job->f0; arg2->f2 += job->f2 >> 1; @@ -1170,7 +1207,11 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat if (tmp != 0) sub_0801B264((void *)tmp, (u16 *)arg2, (u8 *)arg3); if (t2 != 0) { - arg3->f0 += ((u16 (*)(u8 *, s32, u16, u16))sub_0801B58C)(t2, arg4, t2[0x9C], sub_0801DE60()); +#ifdef REGION_USA + arg3->f0 += ((u16 (*)(u8 *, s32, s32, u16))sub_0801B58C)(t2, arg4, ITEM_LV_BA74(t2), sub_0801DE60()); +#else + arg3->f0 += ((u16 (*)(u8 *, s32, u16, u16))sub_0801B58C)(t2, arg4, ITEM_LV_BA74(t2), sub_0801DE60()); +#endif if (arg1 != 0 && arg1->type == 2) arg3->f0 += arg1->bonus; else @@ -1178,7 +1219,7 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat } arg3->f0 += arg2->f0; if (t3 != 0) { - v = t3[0x9B]; + v = KIND_S_BA74(t3); sub_0801DE60(); bonus += BA74_def(v, arg4, 4, 3); if (arg1 != 0 && arg1->type == 3) @@ -1186,14 +1227,14 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat else bonus += gBA74Save->slots[10].bonus; } - if (t2 != 0 && t2[0x9B] == 9) { + if (t2 != 0 && ITEM_KIND(t2) == 9) { if (arg1 != 0 && arg1->type == 2) bonus += arg1->bonus; else bonus += gBA74Save->slots[gBA74Save->f68].bonus; } if (t4 != 0) { - v = t4[0x9B]; + v = KIND_S_BA74(t4); sub_0801DE60(); bonus += BA74_def(v, arg4, 4, 3); if (arg1 != 0 && arg1->type == 4) @@ -1202,12 +1243,12 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat bonus += gBA74Save->slots[9].bonus; } if (t5 != 0) { - if (t5[0xA0] != 0) { - v = t5[0x9B]; + if (T5_FLAG_BA74 != 0) { + v = KIND_S_BA74(t5); sub_0801DE60(); bonus += BA74_def(v, arg4, 3, 2); } else { - v = t5[0x9B]; + v = KIND_S_BA74(t5); sub_0801DE60(); bonus += BA74_def(v, arg4, 4, 3); } @@ -1228,6 +1269,10 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat if (arg2->f4 <= 0) arg2->f4 = 0; arg3->fA += arg2->f6 * 3; +#ifdef REGION_USA + if ((s16)arg3->fA > 998) + arg3->fA = 999; +#endif { s32 t = arg2->f4; s32 u = t << 1; @@ -1253,8 +1298,8 @@ void BA74_StatsCalc(struct BA74Unit *arg0, struct BA74Sel *arg1, struct BA74Stat } if (t2 != 0) { arg3->f6 -= arg2->f2 / 20; - if (arg3->f6 < t2[0xA4] >> 1) - arg3->f6 = t2[0xA4] >> 1; + if (arg3->f6 < t2[ITEM_FIELD(0xA4)] >> 1) + arg3->f6 = t2[ITEM_FIELD(0xA4)] >> 1; } if (halve & 1) { arg3->f2 >>= 1; @@ -1327,11 +1372,11 @@ u8 pad1D0[45]; u8 field1FD; u8 pad1FE[3]; u8 field201; -u8 pad202[2]; +u8 pad202[2 + (ENEMY_FIELD(0x206) - 0x206)]; u16 field204; -u8 pad206[32]; +u8 pad206[ENEMY_FIELD(0x226) - ENEMY_FIELD(0x206)]; u8 field226; -u8 pad227[181]; +u8 pad227[ENEMY_FIELD(0x2DC) - ENEMY_FIELD(0x227)]; u16 * link; }; struct RescueC8F0Slot { s16 timer; u16 source, kind, value; u8 pad[0x10]; s32 scale; u8 tail[0xc]; }; @@ -1350,7 +1395,14 @@ void sub_0801C8F0(struct RescueC8F0Entity *arg0) { s16 *var_r1; s16 temp_r1; s32 var_r0_2; +#ifdef REGION_USA + s32 temp_r0; + register s32 value4A asm("r4"); +#define VALUE4A_C8F0 value4A +#else +#define VALUE4A_C8F0 temp_r0 register s32 temp_r0 asm("r4"); +#endif s32 temp_r0_5; s32 temp_r2; u32 baseAddress; @@ -1364,21 +1416,38 @@ void sub_0801C8F0(struct RescueC8F0Entity *arg0) { u32 temp_r0_9; register u32 clampZero18 asm("r1"); u32 temp_r0_4; +#ifdef REGION_USA + register u32 var_r6 asm("r7"); +#else u32 var_r6; - u8 temp_r0_2; +#endif + ItemKind temp_r0_2; u8 **temp_r1_3; u8 *temp_r1_2; u8 *temp_r6; +#ifdef REGION_USA + register struct RescueC8F0Slot *var_r5 asm("r5"); +#else struct RescueC8F0Slot *var_r5; +#endif - temp_r6 = (u8 *)arg0 + 0x204; +#ifdef REGION_USA + temp_r0 = sub_08007290((*(u16 *)((u8 *)&arg0->field204 + 0x28)) | 0xB0000); + sub_0801B264((void *)(temp_r0 + ITEM_FIELD(0xB0)), &arg0->field204, (void *)((u8 *)arg0 + 0x1CC)); +#else + temp_r6 = (u8 *)&arg0->field204; temp_r0 = sub_08007290((*(u16 *)(temp_r6 + 0x28)) | 0xB0000); - sub_0801B264((void *)(temp_r0 + 0xB0), temp_r6, (void *)((u8 *)arg0 + 0x1CC)); - temp_r0_2 = (*(u8 *)(temp_r0 + 0x9C)); + sub_0801B264((void *)(temp_r0 + ITEM_FIELD(0xB0)), temp_r6, (void *)((u8 *)arg0 + 0x1CC)); +#endif + temp_r0_2 = (*(ItemKind *)(temp_r0 + ITEM_KIND_OFF + sizeof(ItemKind))); zero = 0; arg0->field1CC = (u16) temp_r0_2; arg0->field1CC += arg0->field204; +#ifdef REGION_USA + arg0->field1CE = (u16) (*(u16 *)((u8 *)&arg0->field204 + 0xA)); +#else arg0->field1CE = (u16) (*(u16 *)(temp_r6 + 0xA)); +#endif arg0->status = zero; if (2 & arg0->field201) { arg0->status = 8; @@ -1399,15 +1468,15 @@ void sub_0801C8F0(struct RescueC8F0Entity *arg0) { baseAddress = (u32)rescueC8F0Records; srcEdge18 = temp_r0_3; asm("" : : "r"(srcEdge18)); - temp_r2 = 0x14C * srcEdge18; + temp_r2 = PLAYER_SIZE * srcEdge18; temp_r1_2 = (u8 *)(temp_r2 + baseAddress); - temp_r0_6 = (*(u16 *)(temp_r1_2 + 0xC)); + temp_r0_6 = (*(u16 *)(temp_r1_2 + PLAYER_FIELD(0xC))); switch (temp_r0_6) { /* switch 1; irregular */ case 3: /* switch 1 */ temp_r0_7 = var_r5->kind; switch (temp_r0_7) { /* switch 2; irregular */ case 4: /* switch 2 */ - temp_r0_8 = (*(u16 *)(temp_r1_2 + 0x10)); + temp_r0_8 = (*(u16 *)(temp_r1_2 + PLAYER_FIELD(0x10))); switch (temp_r0_8) { /* switch 3; irregular */ case 2: /* switch 3 */ var_r2 = &arg0->field1CE; @@ -1428,7 +1497,7 @@ void sub_0801C8F0(struct RescueC8F0Entity *arg0) { } break; case 6: /* switch 2 */ - temp_r1_3 = (u8 **)(baseAddress + 0x148); + temp_r1_3 = (u8 **)(baseAddress + PLAYER_FIELD(0x148)); temp_r1_3 = (u8 **)(temp_r2 + (u32)temp_r1_3); pos[0] = ((u16) (*(u16 *)(*temp_r1_3)) >> 4) << 8; pos[1] = (u32) ((*(u16 *)(*temp_r1_3 + 2)) << 0x14) >> 0xC; @@ -1482,8 +1551,8 @@ void sub_0801C8F0(struct RescueC8F0Entity *arg0) { break; case 4: /* switch 4 */ arg0->status = 0xC; - var_r0 = (s32) (arg0->link[1] << 0x10) >> 0x11; - var_r1 = (s16 *)((u8 *)arg0 + 0x206); + var_r0 = (s32) (*(u16 *)((u8 *)arg0->link + ENEMY_DATA_FIELD(2)) << 0x10) >> 0x11; + var_r1 = (s16 *)((u8 *)arg0 + ENEMY_FIELD(0x206)); *var_r1 = (s16)var_r0; goto processed; case 5: arg0->status = 0xD; @@ -1505,16 +1574,16 @@ void sub_0801C8F0(struct RescueC8F0Entity *arg0) { } break; case 0: /* switch 4 */ - if ((var_r5->timer == 0) && ((var_r1_2 = arg0->limit5C), (temp_r0 = (s32)&arg0->value4A), (var_r1_2 -= *(u16 *)temp_r0) > 0) && (arg0->state != 0xB) && (arg0->field66 == 0)) { + if ((var_r5->timer == 0) && ((var_r1_2 = arg0->limit5C), (VALUE4A_C8F0 = (s32)&arg0->value4A), (var_r1_2 -= *(u16 *)VALUE4A_C8F0) > 0) && (arg0->state != 0xB) && (arg0->field66 == 0)) { sub_08021DC4(arg0->id + 4); - *(u16 *)temp_r0 += var_r5->value; + *(u16 *)VALUE4A_C8F0 += var_r5->value; arg0->value4C = (s32) var_r5->value; } break; case 3: /* switch 4 */ - if ((var_r5->timer == 0) && ((var_r1_2 = arg0->limit5C), (temp_r0 = (s32)&arg0->value4A), (var_r1_2 -= *(u16 *)temp_r0) > 0) && (arg0->state != 0xB) && (arg0->field66 == 0)) { + if ((var_r5->timer == 0) && ((var_r1_2 = arg0->limit5C), (VALUE4A_C8F0 = (s32)&arg0->value4A), (var_r1_2 -= *(u16 *)VALUE4A_C8F0) > 0) && (arg0->state != 0xB) && (arg0->field66 == 0)) { sub_08022180(arg0->id + 4); - *(u16 *)temp_r0 += var_r5->value; + *(u16 *)VALUE4A_C8F0 += var_r5->value; arg0->value4C = (s32) var_r5->value; var_r1 = (s16 *)&arg0->status; var_r0 = 0xB; @@ -1524,9 +1593,18 @@ void sub_0801C8F0(struct RescueC8F0Entity *arg0) { } } processed: +#ifdef REGION_USA + { + u16 previousTimer = var_r5->timer; + if (var_r5->timer != -2) { + var_r5->timer = (s16) (previousTimer - 1); + } + } +#else if (var_r5->timer != -2) { var_r5->timer = (s16) ((u16) var_r5->timer - 1); } +#endif } var_r6 += 1; var_r5++; @@ -1551,9 +1629,9 @@ void sub_0801CC10(u32 arg0, s32 arg1) u16 dy; s16 *c; s16 *c1; - x = (*((s32 *) (p + 0x8C))) << 5; - y = ((u32) ((*((s32 *) (p + 0x90))) << 5)) >> 16; - t = *((u16 **) (q + 0x148)); + x = (*((s32 *) (p + PLAYER_FIELD(0x8C)))) << 5; + y = ((u32) ((*((s32 *) (p + PLAYER_FIELD(0x90)))) << 5)) >> 16; + t = *((u16 **) (q + PLAYER_FIELD(0x148))); t0 = t[0]; dy = ((u32) (t[1] << 20)) >> 23; d = (x >> 16) - (t0 >> 7); @@ -1570,7 +1648,7 @@ void sub_0801CC10(u32 arg0, s32 arg1) dy = d; if (p == q) { - c1 = (s16 *) (p + 0xC4); + c1 = (s16 *) (p + PLAYER_FIELD(0xC4)); c = c1; dx = *((u16 *) c1); if (((s16) dx) > 0) @@ -1581,17 +1659,17 @@ void sub_0801CC10(u32 arg0, s32 arg1) else { ; - if (((((s16) dx) <= 13) && (((s16) dy) <= 9)) && ((*((s16 *) (p + 0xC4))) > 0)) + if (((((s16) dx) <= 13) && (((s16) dy) <= 9)) && ((*((s16 *) (p + PLAYER_FIELD(0xC4)))) > 0)) { - *((u16 *) ((s16 *) (p + 0xC4))) = (*((u16 *) ((s16 *) (p + 0xC4)))) + arg1; + *((u16 *) ((s16 *) (p + PLAYER_FIELD(0xC4)))) = (*((u16 *) ((s16 *) (p + PLAYER_FIELD(0xC4))))) + arg1; } } - if ((*((s16 *) (p + 0xC4))) > (*((s16 *) (p + 0x62)))) + if ((*((s16 *) (p + PLAYER_FIELD(0xC4)))) > (*((s16 *) (p + PLAYER_FIELD(0x62))))) { - *((u16 *) ((s16 *) (p + 0xC4))) = *((u16 *) (p + 0x62)); + *((u16 *) ((s16 *) (p + PLAYER_FIELD(0xC4)))) = *((u16 *) (p + PLAYER_FIELD(0x62))); } } -struct RescueCCC8Record { u8 pad[0x10]; u16 kind; u8 tail[0x13a]; }; +struct RescueCCC8Record { u8 pad[PLAYER_FIELD(0x10)]; u16 kind; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x12)]; }; extern struct RescueCCC8Record rescueCCC8Records[] asm("gUnk_03003CE0"); extern u8 *rescueCCC8Current asm("gUnk_030034E0"); /* [ReadLocalPlayerActionSkillLevel] Reads a class-mapped raw skill-level halfword from the current character @@ -1606,112 +1684,112 @@ s32 sub_0801CCC8(void) { u8 cls, v; u8 *q, *item; p = &rescueCCC8Records[sub_080020F4()]; - kind = *(u16 *)(rescueCCC8Current + 0xa); + kind = *(u16 *)(rescueCCC8Current + SAVE_FIELD(0xa)); if (kind == 8) kind = 6; cls = kind; switch (cls) { case 0: switch (p->kind) { -case 1: return *(u16 *)(rescueCCC8Current + 52); -case 2: return *(u16 *)(rescueCCC8Current + 56); -case 3: return *(u16 *)(rescueCCC8Current + 60); +case 1: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(52)); +case 2: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(56)); +case 3: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(60)); } break; case 2: switch (p->kind) { -case 7: return *(u16 *)(rescueCCC8Current + 52); -case 3: return *(u16 *)(rescueCCC8Current + 56); +case 7: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(52)); +case 3: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(56)); case 9: -q = rescueCCC8Current + *(u16 *)(rescueCCC8Current + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; -if (v == 7) return *(u16 *)(rescueCCC8Current + 0x48); +q = rescueCCC8Current + *(u16 *)(rescueCCC8Current + SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; +if (v == 7) return *(u16 *)(rescueCCC8Current + SAVE_FIELD(0x48)); break; } break; case 3: switch (p->kind) { -case 2: return *(u16 *)(rescueCCC8Current + 52); -case 4: return *(u16 *)(rescueCCC8Current + 56); +case 2: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(52)); +case 4: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(56)); } break; case 1: switch (p->kind) { -case 5: return *(u16 *)(rescueCCC8Current + 52); +case 5: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(52)); case 9: -q = rescueCCC8Current + *(u16 *)(rescueCCC8Current + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueCCC8Current + *(u16 *)(rescueCCC8Current + SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 1: return *(u16 *)(rescueCCC8Current + 56); -case 2: return *(u16 *)(rescueCCC8Current + 60); -case 3: return *(u16 *)(rescueCCC8Current + 64); -case 4: return *(u16 *)(rescueCCC8Current + 68); -case 5: return *(u16 *)(rescueCCC8Current + 72); -case 6: return *(u16 *)(rescueCCC8Current + 76); +case 1: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(56)); +case 2: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(60)); +case 3: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(64)); +case 4: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(68)); +case 5: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(72)); +case 6: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(76)); } break; } break; case 6: switch (p->kind) { -case 5: return *(u16 *)(rescueCCC8Current + 52); +case 5: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(52)); case 9: -q = rescueCCC8Current + *(u16 *)(rescueCCC8Current + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueCCC8Current + *(u16 *)(rescueCCC8Current + SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 13: return *(u16 *)(rescueCCC8Current + 56); -case 14: return *(u16 *)(rescueCCC8Current + 60); -case 15: return *(u16 *)(rescueCCC8Current + 64); -case 16: return *(u16 *)(rescueCCC8Current + 68); -case 17: return *(u16 *)(rescueCCC8Current + 72); -case 18: return *(u16 *)(rescueCCC8Current + 76); +case 13: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(56)); +case 14: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(60)); +case 15: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(64)); +case 16: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(68)); +case 17: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(72)); +case 18: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(76)); } break; } break; case 4: switch (p->kind) { -case 5: return *(u16 *)(rescueCCC8Current + 52); -case 4: return *(u16 *)(rescueCCC8Current + 56); +case 5: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(52)); +case 4: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(56)); case 9: -q = rescueCCC8Current + *(u16 *)(rescueCCC8Current + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueCCC8Current + *(u16 *)(rescueCCC8Current + SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 8: return *(u16 *)(rescueCCC8Current + 60); -case 9: return *(u16 *)(rescueCCC8Current + 64); -case 10: return *(u16 *)(rescueCCC8Current + 68); -case 11: return *(u16 *)(rescueCCC8Current + 72); -case 12: return *(u16 *)(rescueCCC8Current + 76); +case 8: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(60)); +case 9: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(64)); +case 10: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(68)); +case 11: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(72)); +case 12: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(76)); } break; } break; case 5: switch (p->kind) { -case 6: return *(u16 *)(rescueCCC8Current + 52); -case 8: return *(u16 *)(rescueCCC8Current + 56); +case 6: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(52)); +case 8: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(56)); } break; case 7: switch (p->kind) { -case 1: return *(u16 *)(rescueCCC8Current + 52); -case 8: return *(u16 *)(rescueCCC8Current + 56); +case 1: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(52)); +case 8: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(56)); case 9: -q = rescueCCC8Current + *(u16 *)(rescueCCC8Current + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueCCC8Current + *(u16 *)(rescueCCC8Current + SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 19: return *(u16 *)(rescueCCC8Current + 64); -case 21: return *(u16 *)(rescueCCC8Current + 68); -case 20: return *(u16 *)(rescueCCC8Current + 72); +case 19: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(64)); +case 21: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(68)); +case 20: return *(u16 *)(rescueCCC8Current + SAVE_FIELD(72)); } break; } @@ -1730,112 +1808,112 @@ s32 sub_0801D028(u16 arg0) { u16 kind; u8 cls, v; u8 *q, *item; - kind = *(u16 *)(rescueD028Current + 0xa); + kind = *(u16 *)(rescueD028Current + SAVE_FIELD(0xa)); if (kind == 8) kind = 6; cls = kind; switch (cls) { case 0: switch (arg0) { -case 1: return *(u16 *)(rescueD028Current + 52); -case 2: return *(u16 *)(rescueD028Current + 56); -case 3: return *(u16 *)(rescueD028Current + 60); +case 1: return *(u16 *)(rescueD028Current + SAVE_FIELD(52)); +case 2: return *(u16 *)(rescueD028Current + SAVE_FIELD(56)); +case 3: return *(u16 *)(rescueD028Current + SAVE_FIELD(60)); } break; case 2: switch (arg0) { -case 7: return *(u16 *)(rescueD028Current + 52); -case 3: return *(u16 *)(rescueD028Current + 56); +case 7: return *(u16 *)(rescueD028Current + SAVE_FIELD(52)); +case 3: return *(u16 *)(rescueD028Current + SAVE_FIELD(56)); case 9: -q = rescueD028Current + *(u16 *)(rescueD028Current + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; -if (v == 7) return *(u16 *)(rescueD028Current + 0x48); +q = rescueD028Current + *(u16 *)(rescueD028Current + SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; +if (v == 7) return *(u16 *)(rescueD028Current + SAVE_FIELD(0x48)); break; } break; case 3: switch (arg0) { -case 2: return *(u16 *)(rescueD028Current + 52); -case 4: return *(u16 *)(rescueD028Current + 56); +case 2: return *(u16 *)(rescueD028Current + SAVE_FIELD(52)); +case 4: return *(u16 *)(rescueD028Current + SAVE_FIELD(56)); } break; case 1: switch (arg0) { -case 5: return *(u16 *)(rescueD028Current + 52); +case 5: return *(u16 *)(rescueD028Current + SAVE_FIELD(52)); case 9: -q = rescueD028Current + *(u16 *)(rescueD028Current + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueD028Current + *(u16 *)(rescueD028Current + SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 1: return *(u16 *)(rescueD028Current + 56); -case 2: return *(u16 *)(rescueD028Current + 60); -case 3: return *(u16 *)(rescueD028Current + 64); -case 4: return *(u16 *)(rescueD028Current + 68); -case 5: return *(u16 *)(rescueD028Current + 72); -case 6: return *(u16 *)(rescueD028Current + 76); +case 1: return *(u16 *)(rescueD028Current + SAVE_FIELD(56)); +case 2: return *(u16 *)(rescueD028Current + SAVE_FIELD(60)); +case 3: return *(u16 *)(rescueD028Current + SAVE_FIELD(64)); +case 4: return *(u16 *)(rescueD028Current + SAVE_FIELD(68)); +case 5: return *(u16 *)(rescueD028Current + SAVE_FIELD(72)); +case 6: return *(u16 *)(rescueD028Current + SAVE_FIELD(76)); } break; } break; case 6: switch (arg0) { -case 5: return *(u16 *)(rescueD028Current + 52); +case 5: return *(u16 *)(rescueD028Current + SAVE_FIELD(52)); case 9: -q = rescueD028Current + *(u16 *)(rescueD028Current + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueD028Current + *(u16 *)(rescueD028Current + SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 13: return *(u16 *)(rescueD028Current + 56); -case 14: return *(u16 *)(rescueD028Current + 60); -case 15: return *(u16 *)(rescueD028Current + 64); -case 16: return *(u16 *)(rescueD028Current + 68); -case 17: return *(u16 *)(rescueD028Current + 72); -case 18: return *(u16 *)(rescueD028Current + 76); +case 13: return *(u16 *)(rescueD028Current + SAVE_FIELD(56)); +case 14: return *(u16 *)(rescueD028Current + SAVE_FIELD(60)); +case 15: return *(u16 *)(rescueD028Current + SAVE_FIELD(64)); +case 16: return *(u16 *)(rescueD028Current + SAVE_FIELD(68)); +case 17: return *(u16 *)(rescueD028Current + SAVE_FIELD(72)); +case 18: return *(u16 *)(rescueD028Current + SAVE_FIELD(76)); } break; } break; case 4: switch (arg0) { -case 5: return *(u16 *)(rescueD028Current + 52); -case 4: return *(u16 *)(rescueD028Current + 56); +case 5: return *(u16 *)(rescueD028Current + SAVE_FIELD(52)); +case 4: return *(u16 *)(rescueD028Current + SAVE_FIELD(56)); case 9: -q = rescueD028Current + *(u16 *)(rescueD028Current + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueD028Current + *(u16 *)(rescueD028Current + SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 8: return *(u16 *)(rescueD028Current + 60); -case 9: return *(u16 *)(rescueD028Current + 64); -case 10: return *(u16 *)(rescueD028Current + 68); -case 11: return *(u16 *)(rescueD028Current + 72); -case 12: return *(u16 *)(rescueD028Current + 76); +case 8: return *(u16 *)(rescueD028Current + SAVE_FIELD(60)); +case 9: return *(u16 *)(rescueD028Current + SAVE_FIELD(64)); +case 10: return *(u16 *)(rescueD028Current + SAVE_FIELD(68)); +case 11: return *(u16 *)(rescueD028Current + SAVE_FIELD(72)); +case 12: return *(u16 *)(rescueD028Current + SAVE_FIELD(76)); } break; } break; case 5: switch (arg0) { -case 6: return *(u16 *)(rescueD028Current + 52); -case 8: return *(u16 *)(rescueD028Current + 56); +case 6: return *(u16 *)(rescueD028Current + SAVE_FIELD(52)); +case 8: return *(u16 *)(rescueD028Current + SAVE_FIELD(56)); } break; case 7: switch (arg0) { -case 1: return *(u16 *)(rescueD028Current + 52); -case 8: return *(u16 *)(rescueD028Current + 56); +case 1: return *(u16 *)(rescueD028Current + SAVE_FIELD(52)); +case 8: return *(u16 *)(rescueD028Current + SAVE_FIELD(56)); case 9: -q = rescueD028Current + *(u16 *)(rescueD028Current + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueD028Current + *(u16 *)(rescueD028Current + SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 19: return *(u16 *)(rescueD028Current + 64); -case 21: return *(u16 *)(rescueD028Current + 68); -case 20: return *(u16 *)(rescueD028Current + 72); +case 19: return *(u16 *)(rescueD028Current + SAVE_FIELD(64)); +case 21: return *(u16 *)(rescueD028Current + SAVE_FIELD(68)); +case 20: return *(u16 *)(rescueD028Current + SAVE_FIELD(72)); } break; } @@ -1844,7 +1922,7 @@ break; return 0; } -struct RescueD34CRecord { u8 pad[0x10]; u16 kind; u8 tail[0x13a]; }; +struct RescueD34CRecord { u8 pad[PLAYER_FIELD(0x10)]; u16 kind; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x12)]; }; extern struct RescueD34CRecord rescueD34CRecords[] asm("gUnk_03003CE0"); extern u8 *rescueD34CCurrent asm("gUnk_030034E0"); /* [GetClassActionCappedValue] Maps saved class8 to6, switches local runtime action kind and class to selected @@ -1859,112 +1937,112 @@ s32 sub_0801D34C(void) { u8 *q, *item; p = &rescueD34CRecords[sub_080020F4()]; cap = (u8 *)sub_0805AD18(); - kind = *(u16 *)(rescueD34CCurrent + 0xa); + kind = *(u16 *)(rescueD34CCurrent+SAVE_FIELD(0xa)); if (kind == 8) kind = 6; cls = kind; switch (cls) { case 0: switch (p->kind) { -case 1: return *(u16 *)(rescueD34CCurrent + 52); -case 2: return *(u16 *)(rescueD34CCurrent + 56); -case 3: return *(u16 *)(rescueD34CCurrent + 60); +case 1: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(52)); +case 2: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(56)); +case 3: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(60)); } break; case 2: switch (p->kind) { -case 7: return *(u16 *)(rescueD34CCurrent + 52); -case 3: return *(u16 *)(rescueD34CCurrent + 56); +case 7: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(52)); +case 3: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(56)); case 9: -q = rescueD34CCurrent + *(u16 *)(rescueD34CCurrent + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; -if (v == 7) return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 0x48) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 0x48); +q = rescueD34CCurrent + *(u16 *)(rescueD34CCurrent+SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; +if (v == 7) return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(0x48)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(0x48)); break; } break; case 3: switch (p->kind) { -case 2: return *(u16 *)(rescueD34CCurrent + 52); -case 4: return *(u16 *)(rescueD34CCurrent + 56); +case 2: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(52)); +case 4: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(56)); } break; case 1: switch (p->kind) { -case 5: return *(u16 *)(rescueD34CCurrent + 52); +case 5: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(52)); case 9: -q = rescueD34CCurrent + *(u16 *)(rescueD34CCurrent + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueD34CCurrent + *(u16 *)(rescueD34CCurrent+SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 1: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 56) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 56); -case 2: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 60) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 60); -case 3: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 64) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 64); -case 4: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 68) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 68); -case 5: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 72) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 72); -case 6: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 76) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 76); +case 1: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(56)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(56)); +case 2: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(60)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(60)); +case 3: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(64)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(64)); +case 4: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(68)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(68)); +case 5: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(72)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(72)); +case 6: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(76)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(76)); } break; } break; case 6: switch (p->kind) { -case 5: return *(u16 *)(rescueD34CCurrent + 52); +case 5: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(52)); case 9: -q = rescueD34CCurrent + *(u16 *)(rescueD34CCurrent + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueD34CCurrent + *(u16 *)(rescueD34CCurrent+SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 13: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 56) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 56); -case 14: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 60) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 60); -case 15: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 64) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 64); -case 16: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 68) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 68); -case 17: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 72) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 72); -case 18: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 76) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 76); +case 13: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(56)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(56)); +case 14: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(60)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(60)); +case 15: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(64)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(64)); +case 16: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(68)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(68)); +case 17: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(72)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(72)); +case 18: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(76)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(76)); } break; } break; case 4: switch (p->kind) { -case 5: return *(u16 *)(rescueD34CCurrent + 52); -case 4: return *(u16 *)(rescueD34CCurrent + 56); +case 5: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(52)); +case 4: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(56)); case 9: -q = rescueD34CCurrent + *(u16 *)(rescueD34CCurrent + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueD34CCurrent + *(u16 *)(rescueD34CCurrent+SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 8: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 60) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 60); -case 9: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 64) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 64); -case 10: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 68) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 68); -case 11: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 72) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 72); -case 12: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 76) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 76); +case 8: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(60)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(60)); +case 9: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(64)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(64)); +case 10: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(68)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(68)); +case 11: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(72)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(72)); +case 12: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(76)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(76)); } break; } break; case 5: switch (p->kind) { -case 6: return *(u16 *)(rescueD34CCurrent + 52); -case 8: return *(u16 *)(rescueD34CCurrent + 56); +case 6: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(52)); +case 8: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(56)); } break; case 7: switch (p->kind) { -case 1: return *(u16 *)(rescueD34CCurrent + 52); -case 8: return *(u16 *)(rescueD34CCurrent + 56); +case 1: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(52)); +case 8: return *(u16 *)(rescueD34CCurrent+SAVE_FIELD(56)); case 9: -q = rescueD34CCurrent + *(u16 *)(rescueD34CCurrent + 0x68) * 0x10; - if (q[0x79] == 0) item = 0; - else item = (u8 *)sub_08007290(*(u16 *)(q + 0x72) | 0xb0000); - if (item[0x9b] == 9) v = item[0xa7]; else v = 0; +q = rescueD34CCurrent + *(u16 *)(rescueD34CCurrent+SAVE_FIELD(0x68)) * 0x10; + if (q[SAVE_FIELD(0x79)] == 0) item = 0; + else item = (u8 *)sub_08007290(*(u16 *)(q + SAVE_FIELD(0x72)) | 0xb0000); + if (ITEM_KIND(item) == 9) v = item[ITEM_FIELD(0xa7)]; else v = 0; switch (v) { -case 19: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 64) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 64); -case 21: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 68) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 68); -case 20: return *(u16 *)(cap + 0xac) < *(u16 *)(rescueD34CCurrent + 72) ? *(u16 *)(cap + 0xac) : *(u16 *)(rescueD34CCurrent + 72); +case 19: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(64)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(64)); +case 21: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(68)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(68)); +case 20: return *(u16 *)(cap + ITEM_FIELD(0xac)) < *(u16 *)(rescueD34CCurrent+SAVE_FIELD(72)) ? *(u16 *)(cap + ITEM_FIELD(0xac)) : *(u16 *)(rescueD34CCurrent+SAVE_FIELD(72)); } break; } @@ -1974,7 +2052,7 @@ return 0; } struct RescueD7ACSlot { s16 timer; u16 source, kind, value; u8 pad[0x20]; }; -struct RescueD7ACRecord { u8 pad0[0xc]; u16 state; u8 padE[0x26]; struct RescueD7ACSlot *slots; u8 pad38[0x30]; u8 team; u8 tail[0xe3]; }; +struct RescueD7ACRecord { u8 pad0[PLAYER_FIELD(0xC)]; u16 state; u8 padE[PLAYER_FIELD(0x34) - PLAYER_FIELD(0xE)]; struct RescueD7ACSlot *slots; u8 pad38[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x38)]; u8 team; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x69)]; }; extern struct RescueD7ACRecord rescueD7ACRecords[] asm("gUnk_03003CE0"); extern u32 rescueD7ACEntities asm("gUnk_030056F4"); extern u32 rescueD7ACMask asm("gUnk_030056FC"); @@ -1993,7 +2071,7 @@ void sub_0801D7AC(s32 source, s32 target, u32 kind, s32 value) { volatile u16 zero; u32 subtype, mask; u8 *entity; - p = (struct RescueD7ACRecord *)(baseAddress + source * 0x14c); + p = (struct RescueD7ACRecord *)(baseAddress + source * PLAYER_SIZE); switch (p->state) { case 0: if (rescueD7ACRecords[target].team != p->team) return; @@ -2054,7 +2132,11 @@ if ((kind & mask) == 4) { } else { for (j = 0; j < 5; j++) { if (rescueD7ACMask & (1 << j)) { - entity = (u8 *)(j * 0x2e0 + rescueD7ACEntities); +#ifdef REGION_USA + { u8 *base = (u8 *)rescueD7ACEntities; entity = (u8 *)(j * ENEMY_SIZE + (u32)base); } +#else + entity = (u8 *)(j * ENEMY_SIZE + rescueD7ACEntities); +#endif if (subtype == *(u16 *)(entity + 2)) { slot = (struct RescueD7ACSlot *)(entity + 0x8c); for (i = 0; i < 8; i++, slot++) { @@ -2096,8 +2178,8 @@ void sub_0801DB94(s32 owner,void *record,s32 status) register u32 random; u32 duration; s32 hp; - if((u32)owner<=3) player=(u8 *)gUnk_03003CE0+(u32)owner*0x14C; - else monster=(u8 *)gUnk_030056F4+((u32)owner*0x2E0-0xB80); + if((u32)owner<=3) player=(u8 *)gUnk_03003CE0+(u32)owner*PLAYER_SIZE; + else monster=(u8 *)gUnk_030056F4+((u32)owner*ENEMY_SIZE-(4 * ENEMY_SIZE)); entry->category=100; switch((u32)status-1) { case 0: @@ -2130,7 +2212,7 @@ void sub_0801DB94(s32 owner,void *record,s32 status) duration=4; goto finish; case 5: - if((u32)owner<=3) hp=*(s16 *)(player+0x62); + if((u32)owner<=3) hp=*(s16 *)(player+PLAYER_FIELD(0x62)); else hp=*(s16 *)(monster+0x1D6); amount=hp/25; if(!sub_0800CCCC() && !sub_0800CD34()) sub_0805865C(0x183); @@ -2141,7 +2223,7 @@ void sub_0801DB94(s32 owner,void *record,s32 status) duration=random*60-1; goto finish; case 6: - if((u32)owner<=3) hp=*(s16 *)(player+0x62); + if((u32)owner<=3) hp=*(s16 *)(player+PLAYER_FIELD(0x62)); else hp=*(s16 *)(monster+0x1D6); amount=hp*8/100; if(!sub_0800CCCC() && !sub_0800CD34()) sub_0805865C(0x183); @@ -2168,32 +2250,32 @@ void sub_0801DD9C(void) { * via CpuSet, eight 32-bit units. Does not recalculate effective player stats, validate the pointer or * synchronize any appearance changes. */ void sub_0801DDB8(s32 arg0) { - CpuSet(gUnk_030034E0 + 0x10, arg0, 0x04000008); + CpuSet(gUnk_030034E0 + SAVE_FIELD(0x10), arg0, 0x04000008); } /* [CopyCharacterBaseStatsFromBuffer] Copies 32 bytes from the supplied buffer into current character save * +0x10 via CpuSet, eight 32-bit units. Does not validate field values, recalculate the runtime player or * update the save storage on its own. */ void sub_0801DDD4(s32 arg0) { - CpuSet(arg0, gUnk_030034E0 + 0x10, 0x04000008); + CpuSet(arg0, gUnk_030034E0 + SAVE_FIELD(0x10), 0x04000008); } /* [CopyLocalPlayerEffectiveAttributesToBuffer] Copies the local runtime player 32-byte effective attribute * block at player +0x38 to the caller buffer. Selects player using 020F4 and stride 0x14C; CpuSet uses eight * words. Does not fetch the save base block or recalculate attributes before copying them. */ void sub_0801DDF0(void *arg0) { - CpuSet(gUnk_03003D18 + sub_080020F4() * 0x14C, arg0, 0x04000008); + CpuSet(gUnk_03003D18 + sub_080020F4() * PLAYER_SIZE, arg0, 0x04000008); } /* [CopyLocalPlayerDerivedStatsToBuffer] Copies the entire local runtime player 48-byte derived-parameter block * at player +0x58 to the supplied buffer. Selects player using 020F4 and stride 0x14C; CpuSet uses 24 * halfwords. Performs no recalculation or field filtering before the transfer. */ void sub_0801DE18(void *arg0) { - CpuSet(gUnk_03003D38 + sub_080020F4() * 0x14C, arg0, 0x18); + CpuSet(gUnk_03003D38 + sub_080020F4() * PLAYER_SIZE, arg0, 0x18); } /* [CopyLocalPlayerDerivedStatsFromBuffer] Copies 48 bytes from the supplied buffer into the local runtime * player derived-parameter block at +0x58. Selects player using 020F4 and stride 0x14C; CpuSet uses 24 * halfwords. Does not validate individual values, clamp current energy/health against new maxima, recalculate * attributes or enqueue appearance synchronization. */ void sub_0801DE3C(void *arg0) { - CpuSet(arg0, gUnk_03003D38 + sub_080020F4() * 0x14C, 0x18); + CpuSet(arg0, gUnk_03003D38 + sub_080020F4() * PLAYER_SIZE, 0x18); } /* [GetNormalizedCharacterClassIndex] Reads character save halfword+0xA and maps8 to6, returning other values * truncated tou8. Consumers5D210/5D278/5D2E0 use result to select class bit in equipment-permission mask, @@ -2201,7 +2283,7 @@ void sub_0801DE3C(void *arg0) { u8 sub_0801DE60(void) { u16 temp_r0; - temp_r0 = *((u16 *) (((s8 *) gUnk_030034E0) + 0xA)); + temp_r0 = *((u16 *) (((s8 *) gUnk_030034E0) + SAVE_FIELD(0xA))); if (temp_r0 != 8) { return (u8) temp_r0; @@ -2220,44 +2302,44 @@ u8 sub_0801DE60(void) * consumes its entries. */ void sub_0801DE78(void *arg0) { struct S36 { u32 w[9]; } *dst = arg0; - struct S36 *src = (struct S36 *) ((u8 *) gUnk_030034E0 + 0x30); + struct S36 *src = (struct S36 *) ((u8 *) gUnk_030034E0 + SAVE_FIELD(0x30)); *dst = *src; } /* [CopyCharacterSkillTableFromBuffer] Copies36 bytes from caller buffer to current character save+0x30; * inverse data transfer of1DE78. Does not recalculate derived stats or validate individual skill values. */ void sub_0801DE98(void *arg0) { struct S36 { u32 w[9]; } *src = arg0; - struct S36 *dst = (struct S36 *) ((u8 *) gUnk_030034E0 + 0x30); + struct S36 *dst = (struct S36 *) ((u8 *) gUnk_030034E0 + SAVE_FIELD(0x30)); *dst = *src; } /* [GetEquippedItemAbilityId] Uses selected equipment slot at save offset 0x68 and item stride 16. */ u32 sub_0801DEB8(void) { u8 *table = (u8 *)gUnk_030034E0; - u8 *item = table + *(u16 *)(table + 0x68) * 0x10; + u8 *item = table + *(u16 *)(table + SAVE_FIELD(0x68)) * 0x10; u8 *resource; - if (item[0x79] == 0) + if (item[SAVE_FIELD(0x79)] == 0) resource = 0; else - resource = (u8 *)sub_08007290(*(u16 *)(item + 0x72) | 0xB0000); - if (resource[0x9B] == 9) - return resource[0xA7]; + resource = (u8 *)sub_08007290(*(u16 *)(item + SAVE_FIELD(0x72)) | 0xB0000); + if (ITEM_KIND(resource) == 9) + return resource[ITEM_FIELD(0xA7)]; return 0; } /* [RestoreLocalPlayerVitalState] Copies maximum health 0x62 to current health 0xC4. */ void sub_0801DF08(void) { u8 *p = (u8 *) &gUnk_03003CE0[sub_080020F4()]; - u16 v = *(u16 *) (p + 0x62); - *(u16 *) (p + 0xC4) = v; + u16 v = *(u16 *) (p + PLAYER_FIELD(0x62)); + *(u16 *) (p + PLAYER_FIELD(0xC4)) = v; if (sub_0801DE60() == 1) { - u16 w = *(u16 *) (p + 0x60); - *(u16 *) (p + 0xC2) = w; + u16 w = *(u16 *) (p + PLAYER_FIELD(0x60)); + *(u16 *) (p + PLAYER_FIELD(0xC2)) = w; } - *(u16 *) (p + 0x20) = 0; - *(u32 *) (p + 0x30) = 0x40; + *(u16 *) (p + PLAYER_FIELD(0x20)) = 0; + *(u32 *) (p + PLAYER_FIELD(0x30)) = 0x40; } -struct MonDF4C { u16 f0; u16 id; u8 pad[0x2DC]; }; +struct MonDF4C { u16 f0; u16 id; u8 pad[ENEMY_SIZE - 0x4]; }; extern struct MonDF4C *monstersDF4C asm("gUnk_030056F4"); /* [ScanActorIds] Searches five records using u32 loop index. */ void sub_0801DF4C(u32 id) @@ -2282,16 +2364,16 @@ s32 sub_0801DF80(void) { * does not subtract damage, clear flags or transition the player state. */ s32 sub_0801DF8C(void) { u8 *p = (u8 *) &gUnk_03003CE0[sub_080020F4()]; - u32 flags = *(u32 *) (p + 0x30); + u32 flags = *(u32 *) (p + PLAYER_FIELD(0x30)); s32 r4; if (!(flags & 0x100000)) { r4 = 0; - if (*(u16 *) (p + 0x20) == 0xB) { + if (*(u16 *) (p + PLAYER_FIELD(0x20)) == PLAYER_FIELD(0xB)) { r4 = 1; - } else if (*(s16 *) (p + 0xC4) == 0) { + } else if (*(s16 *) (p + PLAYER_FIELD(0xC4)) == 0) { r4 = 1; - } else if ((s16) (*(u16 *) (p + 0xC4) - *(u16 *) (p + 0x88)) <= 0) { + } else if ((s16) (*(u16 *) (p + PLAYER_FIELD(0xC4)) - *(u16 *) (p + PLAYER_FIELD(0x88))) <= 0) { r4 = 1; } else if (flags & 0x2000) { r4 = 1; @@ -2321,20 +2403,20 @@ void sub_0801E024(void *arg0) { u16 temp_r7; u8 temp_r8; - temp_r7 = M2C_FIELD(arg0, u16 *, 0x64); - temp_r8 = M2C_FIELD(arg0, u8 *, 0x66); - sub_0801BA74(arg0, 0, arg0 + 0x38, arg0 + 0x58, gUnk_030034E0 + 0x30); - if ((s32) M2C_FIELD(arg0, s16 *, 0xC4) > (s32) (s16) M2C_FIELD(arg0, u16 *, 0x62)) { - M2C_FIELD(arg0, s16 *, 0xC4) = (s16) M2C_FIELD(arg0, u16 *, 0x62); + temp_r7 = M2C_FIELD(arg0, u16 *, SAVE_FIELD(0x64)); + temp_r8 = M2C_FIELD(arg0, u8 *, SAVE_FIELD(0x66)); + sub_0801BA74(arg0, 0, arg0 + SAVE_FIELD(0x38), arg0 + SAVE_FIELD(0x58), gUnk_030034E0 + SAVE_FIELD(0x30)); + if ((s32) M2C_FIELD(arg0, s16 *, SAVE_FIELD(0xC4)) > (s32) (s16) M2C_FIELD(arg0, u16 *, SAVE_FIELD(0x62))) { + M2C_FIELD(arg0, s16 *, SAVE_FIELD(0xC4)) = (s16) M2C_FIELD(arg0, u16 *, SAVE_FIELD(0x62)); } - if ((temp_r7 != M2C_FIELD(arg0, u16 *, 0x64)) || (temp_r8 != M2C_FIELD(arg0, u8 *, 0x66))) { + if ((temp_r7 != M2C_FIELD(arg0, u16 *, SAVE_FIELD(0x64))) || (temp_r8 != M2C_FIELD(arg0, u8 *, SAVE_FIELD(0x66)))) { sub_0806617C(); - sub_0805AD78(M2C_FIELD(gUnk_030034E0, u16 *, 0x68)); + sub_0805AD78(M2C_FIELD(gUnk_030034E0, u16 *, SAVE_FIELD(0x68))); } } /* [GetSavedPlayerPaletteIndex] Reads save-record halfword 0xC. */ u16 sub_0801E0A0(void) { - return M2C_FIELD(gUnk_030034E0, u16 *, 0xC); + return M2C_FIELD(gUnk_030034E0, u16 *, SAVE_FIELD(0xC)); } /* [ReadEffectiveIndexedSkillLevel] Reads halfword at skill-table base+4+((u16)index)*4 and maps stored7 to8. * Numerous class-specific attack/defense calculations in1BA74 and1E378/1E3D8 consume it as skill level. No @@ -2421,7 +2503,7 @@ s32 sub_0801E164(void *arg0, s32 arg1) s16 temp_r0; u32 var_r1; void *var_r2; - var_r2 = *((void **) (((s8 *) arg0) + 0x34)); + var_r2 = *((void **) (((s8 *) arg0) + PLAYER_FIELD(0x34))); var_r1 = 0; do { loop_1: temp_r0 = *((s16 *) (((s8 *) var_r2) + 0)); if ((temp_r0 == (-1)) || (((temp_r0 == (-2)) && ((*((u16 *) (((s8 *) var_r2) + 4))) == arg1)) && ((*((u16 *) (((s8 *) arg0) + 0))) == (*((u16 *) (((s8 *) var_r2) + 2)))))) { return (s32) var_r2; } var_r1 += 1; var_r2 += 0x28; if (var_r1 > 7U) { return 0; } } while (0); goto loop_1; @@ -2429,7 +2511,7 @@ s32 sub_0801E164(void *arg0, s32 arg1) /* [FindPlayerStatusEffectByKey] Scans eight records through actor+0x34; requires counter not-1, supplied key * at+4 and status category100 at+2. Returns first match or null. */ void *sub_0801E1A4(u8 *arg0, s32 arg1) { - u8 *p = *(u8 **) (arg0 + 0x34); + u8 *p = *(u8 **) (arg0 + PLAYER_FIELD(0x34)); u32 i = 0; do { @@ -2448,7 +2530,7 @@ s32 sub_0801E1D8(void *arg0, s32 arg1, s32 arg2) u32 var_r1; int new_var; void *var_r3; - var_r3 = *((void **) (((s8 *) arg0) + 0x34)); + var_r3 = *((void **) (((s8 *) arg0) + PLAYER_FIELD(0x34))); var_r1 = 0; new_var = -1; loop_1: diff --git a/src/code_0801E244.c b/src/code_0801E244.c index e99bcf14..c5be4541 100644 --- a/src/code_0801E244.c +++ b/src/code_0801E244.c @@ -35,7 +35,7 @@ void sub_0801E278(s32 arg0,u32 arg1) register s32 invalid=-1; again: - entry=*(u8 **)(arg0+0x34); + entry=*(u8 **)(arg0+PLAYER_FIELD(0x34)); i=0; scan: if(*(s16 *)entry!=invalid && *(u16 *)(entry+4)==arg1 && type==*(u16 *)(entry+2)) { @@ -81,7 +81,7 @@ void sub_0801E2CC(s32 arg0,u32 arg1) } } struct RemoveEntry019 { u16 id:16; u16 type,key; u8 pad[34]; }; -struct RemovePlayer019 { u8 pad[0x34]; struct RemoveEntry019 *entries; u8 tail[0x114]; }; +struct RemovePlayer019 { u8 pad[PLAYER_FIELD(0x34)]; struct RemoveEntry019 *entries; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x38)]; }; extern struct RemovePlayer019 removePlayers019[] asm("gUnk_03003CE0"); extern void removeEntries019(u32,u32,u32) asm("sub_0801E324"); /* [RemovePlayerEffectsByTypeAndKey] Selects player effect list via playerIndex, scans eight records for @@ -169,8 +169,8 @@ s32 sub_0801E46C(void *arg0, void *arg1) { s32 var_r1; sub_080020F4(); - temp_r3 = M2C_FIELD(arg1, s32 *, 0x10); - temp_r1 = M2C_FIELD(arg0, s32 *, 0x20); + temp_r3 = M2C_FIELD(arg1, s32 *, ENEMY_DATA_FIELD(0x10)); + temp_r1 = M2C_FIELD(arg0, s32 *, SAVE_FIELD(0x20)); temp_r2 = temp_r1 + 1; var_r0 = temp_r2 * 3; temp_r1_2 = temp_r1 + 0xD; @@ -182,8 +182,8 @@ s32 sub_0801E46C(void *arg0, void *arg1) { } else { var_r1 = temp_r3 * 3; } - if (M2C_FIELD(arg1, u8 *, 0x22) == 3) { - var_r1 *= 0xA; + if (M2C_FIELD(arg1, u8 *, ENEMY_DATA_FIELD(0x22)) == 3) { + var_r1 *= 10; } return var_r1; } @@ -191,9 +191,9 @@ s32 sub_0801E46C(void *arg0, void *arg1) { * accumulated experience word+0x1C.1E4CC uses these same fields/table when awarding experience and advancing * level. */ s32 sub_0801E4B0(void) { - s32 *p = (s32 *) gUnk_030034E0; - s32 idx = p[8]; - return gUnk_0848FF54[idx] - p[7]; + u8 *p = (u8 *) gUnk_030034E0; + s32 idx = *(s32 *)(p + SAVE_FIELD(0x20)); + return gUnk_0848FF54[idx] - *(s32 *)(p + SAVE_FIELD(0x1C)); } /* [AddExperienceAndAdvanceOneLevel] Rejects when local runtime player flags contain0x2000 or unsigned saved * level>198. Adds supplied amount to experience+0x1C; if threshold table value reached, increments level once, @@ -208,18 +208,18 @@ s32 sub_0801E4CC(u8 *arg0, s32 arg1) { if (flags & 0x2000) { return 0; } - n = *(s32 *) (arg0 + 0x20); + n = *(s32 *) (arg0 + SAVE_FIELD(0x20)); if ((u32) n > 0xC6) { return 0; } - *(s32 *) (arg0 + 0x1C) += arg1; + *(s32 *) (arg0 + SAVE_FIELD(0x1C)) += arg1; limit = gUnk_0848FF54[n]; - if (*(u32 *) (arg0 + 0x1C) < limit) { + if (*(u32 *) (arg0 + SAVE_FIELD(0x1C)) < limit) { return 0; } - *(s32 *) (arg0 + 0x20) = n + 1; - *(u16 *) (arg0 + 0x1A) += 4; - *(u16 *) (arg0 + 0x30) += 1; + *(s32 *) (arg0 + SAVE_FIELD(0x20)) = n + 1; + *(u16 *) (arg0 + SAVE_FIELD(0x1A)) += 4; + *(u16 *) (arg0 + PLAYER_FIELD(0x30)) += 1; sub_08061830(&gUnk_03003CE0[sub_080020F4()]); return 1; } @@ -254,8 +254,8 @@ void sub_0801E550(s32 arg0, s32 arg1, s32 arg2, s32 arg3) s32 off; base = (u8 *) gUnk_03003CE0; - off = arg1 * 0x14C; - base = base + 0x34; + off = arg1 * PLAYER_SIZE; + base = base + PLAYER_FIELD(0x34); p = *(u8 **) (base + off); i = 0; do { @@ -288,8 +288,8 @@ void sub_0801E594(void *arg0) } while (i <= 7); } -struct Atk5B0 { u8 pad0[0x10]; u16 kind; u8 pad12[0xA]; u16 dir; u8 pad1E[2]; u16 type; u8 pad22[4]; u16 skill; u16 magic; u8 pad2A[6]; u32 flags; u8 pad34[8]; u16 bonus; u8 pad3E[0x1A]; s16 base; u8 pad5A[2]; s16 evade; u8 pad5E[0x54]; u16 level; u8 padB4[0x6E]; u16 mind; u8 pad124[0x1C]; u8 *ctx; }; -struct Tgt5B0 { u8 pad0[2]; u16 id; u8 pad4[4]; u16 dir; u8 padA[2]; u16 kind; u8 padE[6]; s32 x, y; u8 pad1C[0x1B2]; u16 defense; u8 pad1D0[0x48]; u16 resist[6]; }; +struct Atk5B0 { u8 pad0[PLAYER_FIELD(0x10)]; u16 kind; u8 pad12[PLAYER_FIELD(0x1C) - (PLAYER_FIELD(0x11) + 1)]; u16 dir; u8 pad1E[PLAYER_FIELD(0x20) - (PLAYER_FIELD(0x1D) + 1)]; u16 type; u8 pad22[PLAYER_FIELD(0x26) - (PLAYER_FIELD(0x21) + 1)]; u16 skill; u16 magic; u8 pad2A[PLAYER_FIELD(0x30) - (PLAYER_FIELD(0x29) + 1)]; u32 flags; u8 pad34[PLAYER_FIELD(0x3C) - (PLAYER_FIELD(0x33) + 1)]; u16 bonus; u8 pad3E[PLAYER_FIELD(0x58) - (PLAYER_FIELD(0x3D) + 1)]; s16 base; u8 pad5A[PLAYER_FIELD(0x5C) - (PLAYER_FIELD(0x59) + 1)]; s16 evade; u8 pad5E[PLAYER_FIELD(0xB2) - (PLAYER_FIELD(0x5D) + 1)]; u16 level; u8 padB4[PLAYER_FIELD(0x122) - (PLAYER_FIELD(0xB3) + 1)]; u16 mind; u8 pad124[PLAYER_FIELD(0x140) - (PLAYER_FIELD(0x123) + 1)]; u8 *ctx; }; +struct Tgt5B0 { u8 pad0[ENEMY_FIELD(0x2)]; u16 id; u8 pad4[ENEMY_FIELD(0x8) - (ENEMY_FIELD(0x3) + 1)]; u16 dir; u8 padA[ENEMY_FIELD(0xC) - (ENEMY_FIELD(0x9) + 1)]; u16 kind; u8 padE[ENEMY_FIELD(0x14) - (ENEMY_FIELD(0xD) + 1)]; s32 x; s32 y; u8 pad1C[ENEMY_FIELD(0x1CE) - (ENEMY_FIELD(0x1B) + 1)]; u16 defense; u8 pad1D0[ENEMY_FIELD(0x218) - (ENEMY_FIELD(0x1CF) + 1)]; u16 resist[6]; }; extern u8 *combat5B0 asm("gUnk_030034E0"); extern u32 notify5B0(u16, u16) asm("sub_08067FE0"); static inline s32 inl_08021C74(u16 arg0, u16 arg1, u16 arg2) { @@ -452,9 +452,9 @@ s32 sub_0801E5B0(struct Atk5B0 *atk, struct Tgt5B0 *tgt, u8 *record, s32 noCrit) power = (u16)atk->base; } result = inl_08021C74(power, defense, divisor); - if (ctx[*(u16 *)(ctx + 0x68) * 16 + 0x79] == 1) { + if (ctx[*(u16 *)(ctx+SAVE_FIELD(0x68)) * 16 + SAVE_FIELD(0x79)] == 1) { { - u32 fw = inl_08021D00(*(u16 *)(record + 0xBC), result, (u8 *)tgt, 0x218); + u32 fw = inl_08021D00(*(u16 *)(record+ITEM_FIELD(0xBC)), result, (u8 *)tgt, ENEMY_FIELD(0x218)); asm("" : "+r"(fw)); fw <<= 16; result = fw >> 16; @@ -462,14 +462,14 @@ s32 sub_0801E5B0(struct Atk5B0 *atk, struct Tgt5B0 *tgt, u8 *record, s32 noCrit) result = 1; } } - if (!sub_0801DE60() && *(u16 *)(combat5B0 + 0x4C) && tgt->kind == 2) { + if (!sub_0801DE60() && *(u16 *)(combat5B0+SAVE_FIELD(0x4C)) && tgt->kind == 2) { u32 cur = result; - result = inl_08021CE4(cur, sub_0801E0AC((s32)(combat5B0 + 0x30), 6) * 2 + 10); + result = inl_08021CE4(cur, sub_0801E0AC((s32)(combat5B0+SAVE_FIELD(0x30)), 6) * 2 + 10); sub_0805865C(0x27); } - if (sub_0801DE60() == 3 && *(u16 *)(combat5B0 + 0x44)) - notify5B0((tgt->id << 8) | 4, sub_0801E0AC((s32)(combat5B0 + 0x30), 4)); - if (sub_0801DE60() == 7 && *(u16 *)(combat5B0 + 0x50)) { + if (sub_0801DE60() == 3 && *(u16 *)(combat5B0+SAVE_FIELD(0x44))) + notify5B0((tgt->id << 8) | 4, sub_0801E0AC((s32)(combat5B0+SAVE_FIELD(0x30)), 4)); + if (sub_0801DE60() == 7 && *(u16 *)(combat5B0+SAVE_FIELD(0x50))) { if ((s16)atk->dir > 4) a = atk->dir - 8; else @@ -482,12 +482,12 @@ s32 sub_0801E5B0(struct Atk5B0 *atk, struct Tgt5B0 *tgt, u8 *record, s32 noCrit) if (d < 0) d = -d; if (d <= 1) - result = (u16)((s16)result * (sub_0801E0AC((s32)(combat5B0 + 0x30), 7) * 3 + 10) / 10); + result = (u16)((s16)result * (sub_0801E0AC((s32)(combat5B0+SAVE_FIELD(0x30)), 7) * 3 + 10) / 10); } return result; } struct Pos988 { u16 a; u8 b, c; }; -struct Tgt988 { u16 id; u8 pad2[0x1E]; u16 kind; u8 pad22[0x38]; u16 defense; u8 pad5C[0x20]; u16 resist[6]; u8 pad88[0xC0]; struct Pos988 *pos; }; +struct Tgt988 { u16 id; u8 pad2[PLAYER_FIELD(0x20) - 0x2]; u16 kind; u8 pad22[PLAYER_FIELD(0x5A) - PLAYER_FIELD(0x22)]; u16 defense; u8 pad5C[PLAYER_FIELD(0x7C) - PLAYER_FIELD(0x5C)]; u16 resist[6]; u8 pad88[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x88)]; struct Pos988 *pos; }; /* [ComputePlayerAttackPlayerDamage] Critical roll and feedback choose divisor 100/200; nonzero noCrit selects * 1000. */ s32 sub_0801E988(struct Atk5B0 *atk, struct Tgt988 *tgt, u8 *record, s32 noCrit) @@ -595,9 +595,9 @@ s32 sub_0801E988(struct Atk5B0 *atk, struct Tgt988 *tgt, u8 *record, s32 noCrit) power = (u16)atk->base; } result = inl_08021C74(power, defense, divisor); - if (ctx[*(u16 *)(ctx + 0x68) * 16 + 0x79] == 1) { + if (ctx[*(u16 *)(ctx+SAVE_FIELD(0x68)) * 16 + SAVE_FIELD(0x79)] == 1) { { - u32 fw = inl_08021D00(*(u16 *)(record + 0xBC), result, (u8 *)tgt, 0x7C); + u32 fw = inl_08021D00(*(u16 *)(record+ITEM_FIELD(0xBC)), result, (u8 *)tgt, PLAYER_FIELD(0x7C)); asm("" : "+r"(fw)); fw <<= 16; result = fw >> 16; @@ -607,13 +607,13 @@ s32 sub_0801E988(struct Atk5B0 *atk, struct Tgt988 *tgt, u8 *record, s32 noCrit) } if (atk->type == 5) result = inl_08021CE4(result, 10); - if (!sub_0801DE60() && *(u16 *)(combat5B0 + 0x4C) && tgt->kind == 2) { + if (!sub_0801DE60() && *(u16 *)(combat5B0+SAVE_FIELD(0x4C)) && tgt->kind == 2) { u32 cur = result; - result = inl_08021CE4(cur, sub_0801E0AC((s32)(combat5B0 + 0x30), 6) * 2 + 10); + result = inl_08021CE4(cur, sub_0801E0AC((s32)(combat5B0+SAVE_FIELD(0x30)), 6) * 2 + 10); } - if (sub_0801DE60() == 3 && *(u16 *)(combat5B0 + 0x44)) - notify5B0((tgt->id << 8) | 4, sub_0801E0AC((s32)(combat5B0 + 0x30), 4)); - if (sub_0801DE60() == 7 && *(u16 *)(combat5B0 + 0x50)) { + if (sub_0801DE60() == 3 && *(u16 *)(combat5B0+SAVE_FIELD(0x44))) + notify5B0((tgt->id << 8) | 4, sub_0801E0AC((s32)(combat5B0+SAVE_FIELD(0x30)), 4)); + if (sub_0801DE60() == 7 && *(u16 *)(combat5B0+SAVE_FIELD(0x50))) { if ((s16)atk->dir > 4) a = atk->dir - 8; else @@ -626,7 +626,7 @@ s32 sub_0801E988(struct Atk5B0 *atk, struct Tgt988 *tgt, u8 *record, s32 noCrit) if (d < 0) d = -d; if (d <= 1) - result = (u16)((s16)result * (sub_0801E0AC((s32)(combat5B0 + 0x30), 7) * 3 + 10) / 10); + result = (u16)((s16)result * (sub_0801E0AC((s32)(combat5B0+SAVE_FIELD(0x30)), 7) * 3 + 10) / 10); } { register s32 fin asm("r5") = (u16)((s16)result / 4); @@ -635,7 +635,7 @@ s32 sub_0801E988(struct Atk5B0 *atk, struct Tgt988 *tgt, u8 *record, s32 noCrit) return fin; } } -struct CombatCtxD8C { u8 pad[0x14]; u16 resist[6]; u8 pad20[8]; u16 key; }; +struct CombatCtxD8C { u8 pad[ENEMY_FIELD(0x218) - 0x204]; u16 resist[6]; u8 pad20[8]; u16 key; }; struct CombatActorD8C { u8 pad[0x1CC]; u16 attack,defense; s16 evade; u8 pad1D2[0x32]; struct CombatCtxD8C ctx; }; struct TargetD8C { u8 pad[0xC]; u16 kind; u8 padE[0x6E]; u16 resist[6]; u8 pad88[0x4A]; u16 f5A_dummy; }; static inline s32 inl_ED8C(u16 arg0, u16 arg1, u32 arg2) { @@ -674,10 +674,10 @@ u32 sub_0801ED8C(void *arg0, void *arg1) struct CombatCtxD8C *ctx = &src->ctx; record = (u8 *) sub_08007290(ctx->key | 0xB0000); } - defense = *((u16 *) (dst + 0x5A)); + defense = *((u16 *) (dst + PLAYER_FIELD(0x5A))); if (((s32) (sub_080008C8() & 0x7F)) <= (src->evade + 1)) { - sub_0802247C(*((u32 *) (dst + 0x8C)), *((u32 *) (dst + 0x90))); + sub_0802247C(*((u32 *) (dst + PLAYER_FIELD(0x8C))), *((u32 *) (dst + PLAYER_FIELD(0x90)))); divisor = 100; } else @@ -685,9 +685,9 @@ u32 sub_0801ED8C(void *arg0, void *arg1) divisor = 200; } firstDamage = inl_ED8C(src->attack, defense, divisor); - element = *((u16 *) (record + 0xBC)); + element = *((u16 *) (record + ITEM_FIELD(0xBC))); damage = firstDamage; - resists = (u16 *) (dst + 0x7C); + resists = (u16 *) (dst + PLAYER_FIELD(0x7C)); switch (element - 1U) { case 0: @@ -739,13 +739,13 @@ u32 sub_0801ED8C(void *arg0, void *arg1) sub_0805865C(0x27); } else - if ((*((u16 *) (dst + 0xC))) == 8) + if ((*((u16 *) (dst + PLAYER_FIELD(0xC)))) == 8) { sub_0805865C(0x4B); } else { - sub_0805865C((*((u16 *) (dst + 0xC))) + 0x45); + sub_0805865C((*((u16 *) (dst + PLAYER_FIELD(0xC)))) + 0x45); } return (u16)result; } @@ -753,7 +753,7 @@ u32 sub_0801ED8C(void *arg0, void *arg1) { u32 hi = 0x8000; hi |= result; return hi; } return result; } -struct CombatCtx019 { u8 pad[0x14]; u16 resist[6]; u8 pad20[8]; u16 key; }; +struct CombatCtx019 { u8 pad[ENEMY_FIELD(0x218) - 0x204]; u16 resist[6]; u8 pad20[8]; u16 key; }; struct CombatActor019 { u8 pad[0x1CC]; u16 attack,defense; u8 pad1D0[0x34]; struct CombatCtx019 ctx; }; /* [ComputeElementalAttackDamage] Loads unsigned 16-bit attack and defense from actor +0x1CC/+0x1CE. Casts * NextRandom32 to u16 before modulo 50, then adds 100 for variance. Computes signed division of the low-32-bit @@ -789,7 +789,7 @@ s32 sub_0801EF14(void *arg0,void *arg1) firstDamage=quotient/10U; } if(!firstDamage) firstDamage=1; - element=*(u16 *)(record+0xBC); + element=*(u16 *)(record+ITEM_FIELD(0xBC)); damage=firstDamage; resists=dst->ctx.resist; switch(element-1U) { @@ -846,7 +846,7 @@ s32 sub_0801F024(u8 *obj, u16 dir, s32 *pos, s32 *target, u32 w, u32 h) s32 box[2]; struct SizeF024 size; struct SizeF024 other; - u8 kind = obj[0x9B]; + ItemKind kind = ITEM_KIND(obj); if (kind == 3) goto check2; if (kind == 8) { @@ -859,17 +859,17 @@ s32 sub_0801F024(u8 *obj, u16 dir, s32 *pos, s32 *target, u32 w, u32 h) other.w = w; other.h = h; box[1] = pos[1] - 0x400; - box[0] = pos[0] + sinF024[dirF024[dir] * 16 + 0x40] * obj[0xA5]; - box[1] += sinF024[dirF024[dir] * 16] * obj[0xA5]; - size.w = size.h = obj[0xA6]; + box[0] = pos[0] + sinF024[dirF024[dir] * 16 + 0x40] * obj[ITEM_FIELD(0xA5)]; + box[1] += sinF024[dirF024[dir] * 16] * obj[ITEM_FIELD(0xA5)]; + size.w = size.h = obj[ITEM_FIELD(0xA6)]; if (overlapF024(box, target, (u16 *)&size, (u16 *)&other)) return 1; - if (obj[0x9B] == 9) + if (ITEM_KIND(obj) == 9) return 0; box[1] = pos[1] - 0x400; - box[0] = pos[0] + sinF024[dirF024[dir] * 16 + 0x40] * obj[0xA7]; - box[1] += sinF024[dirF024[dir] * 16] * obj[0xA7]; - size.w = size.h = obj[0xA8]; + box[0] = pos[0] + sinF024[dirF024[dir] * 16 + 0x40] * obj[ITEM_FIELD(0xA7)]; + box[1] += sinF024[dirF024[dir] * 16] * obj[ITEM_FIELD(0xA7)]; + size.w = size.h = obj[ITEM_FIELD(0xA8)]; if (overlapF024(box, target, (u16 *)&size, (u16 *)&other)) return 1; return 0; @@ -913,7 +913,7 @@ void sub_0801F1C4(void *position, u8 *object, u16 amount) if (check & 0x80) *(u32 *)&packet &= 0xFF00FFFF; } - if (*(u32 *)(object + 0x210) == 0xFF) + if (*(u32 *)(object + ENEMY_FIELD(0x210)) == 0xFF) *(u32 *)&packet &= 0xFF00FFFF; sub_0801F2CC(object, (u8 *)&packet); { @@ -927,7 +927,7 @@ void sub_0801F1C4(void *position, u8 *object, u16 amount) u16 *flags = (u16 *)(object + 0x5A); u32 players = (u32)gUnk_03003CE0; - *flags |= 1 << *(u16 *)(players + selected * 0x14C); + *flags |= 1 << *(u16 *)(players + selected * PLAYER_SIZE); } sub_080660EC(&packet); } @@ -966,7 +966,7 @@ void sub_0801F2CC(u8 *object, u8 *data) ((struct Sh20F2CC *)object)->direction = value; } } -struct Sh20F320 { u32 alignment; u8 pad[0xCA]; u16 duration; s16 direction; u16 speed; u16 value; }; +struct Sh20F320 { u32 alignment; u8 pad[PLAYER_FIELD(0xCE) - 0x4]; u16 duration; s16 direction; u16 speed; u16 value; }; struct Sh20F320Data { u8 pad[2]; u8 value; s32 direction:8; }; /* [ConfigurePlayerKnockbackFromHit] Writes player knockback duration +0xCE; lines 932-939 write speed, * magnitude and signed direction. */ @@ -1035,65 +1035,65 @@ void sub_0801F374(u8 *source,u8 *target,u8 *attack,s32 flags) packet.impulse=0; packet.direction=0; } else { - *(u16 *)(target+0xC)=10; + *(u16 *)(target+ENEMY_FIELD(0xC))=10; packet.amount=amount02074(source,target,attack,0); - packet.impulse=attack[0xA9]; - packet.impulse+=source[0x72]; - packet.impulse-=*(u32 *)(target+0x210); + packet.impulse=attack[ITEM_FIELD(0xA9)]; + packet.impulse+=source[PLAYER_FIELD(0x72)]; + packet.impulse-=*(u32 *)(target+ENEMY_FIELD(0x210)); if(packet.impulse&0x80) packet.impulse=0; - if(*(u32 *)(target+0x210)==0xFF) packet.impulse=0; - angle=ArcTan2((s32)((*(s32 *)(target+0x14)-*(s32 *)(source+0x8C))<<8)>>16,(s32)((*(s32 *)(target+0x18)-*(s32 *)(source+0x90))<<8)>>16); + if(*(u32 *)(target+ENEMY_FIELD(0x210))==0xFF) packet.impulse=0; + angle=ArcTan2((s32)((*(s32 *)(target+ENEMY_FIELD(0x14))-*(s32 *)(source+PLAYER_FIELD(0x8C)))<<8)>>16,(s32)((*(s32 *)(target+ENEMY_FIELD(0x18))-*(s32 *)(source+PLAYER_FIELD(0x90)))<<8)>>16); packet.direction=directions02074[angle>>12]; - if(*(u16 *)(source+0x20)==5 && *(u16 *)(source+0x10)==8) - packet.amount=(s32)(packet.amount*(((u32)(*(u32 *)(*(u8 **)(source+0x148)+4)<<15)>>29)+5))/10; - if(target[0x226]==1 && source[0x76]!=0) - packet.amount=(s32)(packet.amount*source[0x76])/10; - if(target[0x226]==2 && source[0x75]!=0) - packet.amount=(s32)(packet.amount*source[0x75])/10; - if(*(u16 *)(source+0xC)==2) { - if(target[0x226]==1) - packet.amount=(s32)(packet.amount*((u16)sub_0801E0AC((s32)(inventory02074+0x30),4)*4+10))/10; - chance=(s32)(100*sub_0801E0AC((s32)(inventory02074+0x30),3))/((s16)(*(s16 *)(target+0x208)/5)+50); + if(*(u16 *)(source+PLAYER_FIELD(0x20))==5 && *(u16 *)(source+PLAYER_FIELD(0x10))==8) + packet.amount=(s32)(packet.amount*(((u32)(*(u32 *)(*(u8 **)(source+PLAYER_FIELD(0x148))+4)<<15)>>29)+5))/10; + if(target[ENEMY_FIELD(0x226)]==1 && source[PLAYER_FIELD(0x76)]!=0) + packet.amount=(s32)(packet.amount*source[PLAYER_FIELD(0x76)])/10; + if(target[ENEMY_FIELD(0x226)]==2 && source[PLAYER_FIELD(0x75)]!=0) + packet.amount=(s32)(packet.amount*source[PLAYER_FIELD(0x75)])/10; + if(*(u16 *)(source+PLAYER_FIELD(0xC))==2) { + if(target[ENEMY_FIELD(0x226)]==1) + packet.amount=(s32)(packet.amount*((u16)sub_0801E0AC((s32)(inventory02074+SAVE_FIELD(0x30)),4)*4+10))/10; + chance=(s32)(100*sub_0801E0AC((s32)(inventory02074+SAVE_FIELD(0x30)),3))/((s16)(*(s16 *)(target+ENEMY_FIELD(0x208))/5)+50); if((u32)chance>sub_080008C8()%100U) { critical=1; sub_0805865C(0x132); } } - *(u16 *)(source+0xC4)+=(s32)((dealt=packet.amount)*(s8)source[0x6A])/100; - *(u16 *)(source+0xC2)+=((s32)(dealt*(s8)source[0x6B])/100)*10; - if(*(s16 *)(source+0xC4)>*(s16 *)(source+0x62)) *(u16 *)(source+0xC4)=*(u16 *)(source+0x62); - if(*(s16 *)(source+0xC2)>*(s16 *)(source+0x60)) *(u16 *)(source+0xC2)=*(u16 *)(source+0x60); + *(u16 *)(source+PLAYER_FIELD(0xC4))+=(s32)((dealt=packet.amount)*(s8)source[PLAYER_FIELD(0x6A)])/100; + *(u16 *)(source+PLAYER_FIELD(0xC2))+=((s32)(dealt*(s8)source[PLAYER_FIELD(0x6B)])/100)*10; + if(*(s16 *)(source+PLAYER_FIELD(0xC4))>*(s16 *)(source+PLAYER_FIELD(0x62))) *(u16 *)(source+PLAYER_FIELD(0xC4))=*(u16 *)(source+PLAYER_FIELD(0x62)); + if(*(s16 *)(source+PLAYER_FIELD(0xC2))>*(s16 *)(source+PLAYER_FIELD(0x60))) *(u16 *)(source+PLAYER_FIELD(0xC2))=*(u16 *)(source+PLAYER_FIELD(0x60)); } - hit02074(&packet,target+0x218,0,*(u16 *)(attack+0xBC),(u16)(*(u16 *)target+4)); + hit02074(&packet,target+ENEMY_FIELD(0x218),0,*(u16 *)(attack+ITEM_FIELD(0xBC)),(u16)(*(u16 *)target+ENEMY_FIELD(4))); status=sub_0801E244((s32)target,packet.power); - if(status!=0) sub_0801DB94(*(u16 *)target+4,(void *)status,packet.power); + if(status!=0) sub_0801DB94(*(u16 *)target+ENEMY_FIELD(4),(void *)status,packet.power); else { other=lookup02074(target,0); - if(other!=0) sub_0801DB94(*(u16 *)target+4,other,packet.power); + if(other!=0) sub_0801DB94(*(u16 *)target+ENEMY_FIELD(4),other,packet.power); } - if(packet.power==3) sub_08021E44(*(u16 *)target+4,1); - packet.player=*(u16 *)(target+2); - { u32 i=sub_080020F4(); u16 *p=(u16 *)(target+0x5A); u8 *pl=players02074; *p|=1<<*(u16 *)(pl+i*0x14C); } + if(packet.power==3) sub_08021E44(*(u16 *)target+ENEMY_FIELD(4),1); + packet.player=*(u16 *)(target+ENEMY_FIELD(2)); + { u32 i=sub_080020F4(); u16 *p=(u16 *)(target+ENEMY_FIELD(0x5A)); u8 *pl=players02074; *p|=1<<*(u16 *)(pl+i*PLAYER_SIZE); } - *(u32 *)(target+0x54)=*(u32 *)(source+0xDC); - *(u16 *)(target+0x4A)+=packet.amount&0x7FFF; - *(u32 *)(target+0x4C)=packet.amount; - { u8 pw=packet.power; *(u16 *)(target+0x62)=pw; } - if(target[0x226]!=3) { - *(u16 *)(target+0x6C)=0; - *(u16 *)(target+0x6A)=0; - {u16 *q=(u16 *)(target+0x68); u16 k=0xFFFE; *q=k;} + *(u32 *)(target+ENEMY_FIELD(0x54))=*(u32 *)(source+PLAYER_FIELD(0xDC)); + *(u16 *)(target+ENEMY_FIELD(0x4A))+=packet.amount&0x7FFF; + *(u32 *)(target+ENEMY_FIELD(0x4C))=packet.amount; + { u8 pw=packet.power; *(u16 *)(target+ENEMY_FIELD(0x62))=pw; } + if(target[ENEMY_FIELD(0x226)]!=3) { + *(u16 *)(target+ENEMY_FIELD(0x6C))=0; + *(u16 *)(target+ENEMY_FIELD(0x6A))=0; + {u16 *q=(u16 *)(target+ENEMY_FIELD(0x68)); u16 k=0xFFFE; *q=k;} } sub_0801F2CC(target,(u8 *)&packet); - { u16 sid=*(u16 *)source; *(u16 *)(target+0x58)=sid; } + { u16 sid=*(u16 *)source; *(u16 *)(target+ENEMY_FIELD(0x58))=sid; } notify02074(&packet); - display02074(target+0x218,*(u16 *)(target+0x4A),0,*(u16 *)source,*(u16 *)target+4,*(u16 *)(attack+0xBC)); - if(*(u16 *)(source+0xC)==5) { - chance=sub_0801E0AC((s32)(inventory02074+0x30),6); - if((u32)chance>(sub_080008C8()&0x3F)) status02074(*(u16 *)(target+2),6); + display02074(target+ENEMY_FIELD(0x218),*(u16 *)(target+ENEMY_FIELD(0x4A)),0,*(u16 *)source,*(u16 *)target+ENEMY_FIELD(4),*(u16 *)(attack+ITEM_FIELD(0xBC))); + if(*(u16 *)(source+PLAYER_FIELD(0xC))==5) { + chance=sub_0801E0AC((s32)(inventory02074+SAVE_FIELD(0x30)),6); + if((u32)chance>(sub_080008C8()&0x3F)) status02074(*(u16 *)(target+ENEMY_FIELD(2)),6); } - if(critical) critical02074(*(u16 *)(target+2)); + if(critical) critical02074(*(u16 *)(target+ENEMY_FIELD(2))); } extern u8 directions02079[] asm("gUnk_084790B4"); extern u16 amount02079(void *,void *,void *,s32) asm("sub_0801E988"); @@ -1122,27 +1122,27 @@ void sub_0801F79C(u8 *source,u8 *target,u8 *attack,s32 flags) packet.direction=0; } else { packet.amount=amount02079(source,target,attack,0); - packet.impulse=attack[0xA9]; - position=*(u8 **)(target+0x148); - angle=ArcTan2((s16)((*(u16 *)position>>4)-(*(s32 *)(source+0x8C)>>8)),(s16)(((u32)((u32)*(u16 *)(position+2)<<20)>>20)-(*(s32 *)(source+0x90)>>8))); + packet.impulse=attack[ITEM_FIELD(0xA9)]; + position=*(u8 **)(target+PLAYER_FIELD(0x148)); + angle=ArcTan2((s16)((*(u16 *)position>>4)-(*(s32 *)(source+PLAYER_FIELD(0x8C))>>8)),(s16)(((u32)((u32)*(u16 *)(position+2)<<20)>>20)-(*(s32 *)(source+PLAYER_FIELD(0x90))>>8))); packet.direction=directions02079[angle>>12]; - if(*(u16 *)(source+0x20)==5 && *(u16 *)(source+0x10)==8) - packet.amount=(s32)(packet.amount*(((u32)(*(u32 *)(*(u8 **)(source+0x148)+4)<<15)>>29)+5))/10; + if(*(u16 *)(source+PLAYER_FIELD(0x20))==5 && *(u16 *)(source+PLAYER_FIELD(0x10))==8) + packet.amount=(s32)(packet.amount*(((u32)(*(u32 *)(*(u8 **)(source+PLAYER_FIELD(0x148))+4)<<15)>>29)+5))/10; } packetAddress=&packet; - display=target+0x4C; - hit02079(packetAddress,display,1,*(u16 *)(attack+0xBC),*(u16 *)target); - *(u16 *)(source+0xC4)+=(s32)((packetAddress->amount&0xFFFF7FFF)*(s8)source[0x6A])/100; - *(u16 *)(source+0xC2)+=((s32)((packetAddress->amount&0xFFFF7FFF)*((s32)((u32)source[0x6B]<<24)>>24))/100)*10; - if(*(s16 *)(source+0xC4)>*(s16 *)(source+0x62)) *(u16 *)(source+0xC4)=*(u16 *)(source+0x62); - if(*(s16 *)(source+0xC2)>*(s16 *)(source+0x60)) *(u16 *)(source+0xC2)=*(u16 *)(source+0x60); + display=target+PLAYER_FIELD(0x4C); + hit02079(packetAddress,display,1,*(u16 *)(attack+ITEM_FIELD(0xBC)),*(u16 *)target); + *(u16 *)(source+PLAYER_FIELD(0xC4))+=(s32)((packetAddress->amount&0xFFFF7FFF)*(s8)source[PLAYER_FIELD(0x6A)])/100; + *(u16 *)(source+PLAYER_FIELD(0xC2))+=((s32)((packetAddress->amount&0xFFFF7FFF)*((s32)((u32)source[PLAYER_FIELD(0x6B)]<<24)>>24))/100)*10; + if(*(s16 *)(source+PLAYER_FIELD(0xC4))>*(s16 *)(source+PLAYER_FIELD(0x62))) *(u16 *)(source+PLAYER_FIELD(0xC4))=*(u16 *)(source+PLAYER_FIELD(0x62)); + if(*(s16 *)(source+PLAYER_FIELD(0xC2))>*(s16 *)(source+PLAYER_FIELD(0x60))) *(u16 *)(source+PLAYER_FIELD(0xC2))=*(u16 *)(source+PLAYER_FIELD(0x60)); historyIndex=*(u16 *)source*4; - history=(u32 *)(target+0xF8); + history=(u32 *)(target+PLAYER_FIELD(0xF8)); - *(u32 *)((u8 *)history+historyIndex)=*(u32 *)(source+0xDC); + *(u32 *)((u8 *)history+historyIndex)=*(u32 *)(source+PLAYER_FIELD(0xDC)); packetAddress->player=*(u16 *)target; notify02079(packetAddress); - display02079(display,packetAddress->amount&0x7FFF,0,*(u16 *)source,*(u16 *)target,*(u16 *)(attack+0xBC)); + display02079(display,packetAddress->amount&0x7FFF,0,*(u16 *)source,*(u16 *)target,*(u16 *)(attack+ITEM_FIELD(0xBC))); } @@ -1155,7 +1155,7 @@ extern u8 *scene02099 asm("gUnk_03005CF4"); extern void damage02099(u32,u32,u8) asm("sub_08028368"); struct Size02099 { u32 width:16; u32 height:16; }; struct Item02099 { s32 x,y; u8 pad8[8]; u16 hp; u16 f12; u16 state; u8 pad16[10]; u8 *data; }; -struct Player02099 { u8 pad0[0x58]; u16 power; u8 pad5A[0x14C-0x5A]; }; +struct Player02099 { u8 pad0[PLAYER_FIELD(0x58)]; u16 power; u8 pad5A[PLAYER_SIZE-PLAYER_FIELD(0x5A)]; }; extern struct Player02099 gPl02099[] asm("gUnk_03003CE0"); static inline s32 coll02099(s32 *pos,struct Item02099 *item,u16 *box,struct Size02099 *sz) { @@ -1179,12 +1179,12 @@ s32 sub_0801F99C(s32 *pos, u16 *box) item=(struct Item02099 *)(scene02099+0x58C); for(index=0;index<*(u32 *)(scene02099+0x48);index++,item++) { if((u16)(item->state-10)<=2) continue; - if(item->data[6]&3) continue; - size.width=*(u16 *)(item->data+0xC); - size.height=*(u16 *)(item->data+0xE); + if(item->data[ENEMY_DATA_FIELD(6)]&3) continue; + size.width=*(u16 *)(item->data+ENEMY_DATA_FIELD(0xC)); + size.height=*(u16 *)(item->data+ENEMY_DATA_FIELD(0xE)); if(coll02099(pos,item,box,&size)) { power=gPl02099[sub_080020F4()].power; - defense=*(u16 *)(item->data+2); + defense=*(u16 *)(item->data+ENEMY_DATA_FIELD(2)); random=((((u16)sub_080008C8()%50U)<<16)+0x640000)>>16; dm=(u16)((u16)((s32)(random*((s32)(power*power*10)/(s32)(power+defense)))/100)/10U); if(dm==0) dm=1; @@ -1245,14 +1245,14 @@ s32 sub_0801FB14(void *arg0, void *arg1, s32 damage) if(indexitems[((struct InvFDD0 *)invFDD0)->sel].b[7]; + pos=*(struct PosFDD0 *)(p+PLAYER_FIELD(0x8C)); + switch(*(u16 *)(p+PLAYER_FIELD(0x20))) { + case 2: + if(*(u16 *)(p+PLAYER_FIELD(0x122))<=15) *(u32 *)(p+PLAYER_FIELD(0x30))|=0x200000; + if(*(u16 *)(p+PLAYER_FIELD(0x64))>9) { + if(*(u16 *)(*(u8 **)(p+PLAYER_FIELD(0x138))+ENEMY_DATA_FIELD(0x24))!=*(u16 *)(p+PLAYER_FIELD(0xB2))) return; + } else if(limAFDD0[(u8)sub_0801DE60()]!=*(u16 *)(p+PLAYER_FIELD(0xB2))) return; + if(*(u16 *)(p+PLAYER_FIELD(0xB4))!=1) return; + if(*(u32 *)(p+PLAYER_FIELD(0x30))&0x200000) atkS_FDD0.a9+=0x18; + power=*(s16 *)(p+PLAYER_FIELD(0x3A)); + break; + case 5: + power=*(s16 *)(p+PLAYER_FIELD(0x3A))*3; + switch((u8)sub_0801DE60()) { + case 0: + if(limBFDD0[0]>*(u16 *)(p+PLAYER_FIELD(0xB2))) return; + if(*(u16 *)(p+PLAYER_FIELD(0xB4))!=1) return; + tk=atkS_FDD0.kind; + if(tk==2) { COPY4(cEC_FDD0); atkS_FDD0.a9+=10; } + else if(tk==1) { atkS_FDD0.a9+=8; COPY4(cE4_FDD0); } + else if(tk==3) COPY4(cE8_FDD0); + break; + case 3: + if(limBFDD0[3]>*(u16 *)(p+PLAYER_FIELD(0xB2))) return; + if(*(u16 *)(p+PLAYER_FIELD(0xB4))!=1) return; + tk=atkS_FDD0.kind; + if(tk==2) { COPY4(c38_FDD0); atkS_FDD0.a9+=10; } + else if(tk==4) { + if(*(u16 *)(p+PLAYER_FIELD(0xB2))<=4) { + atkS_FDD0.a9=0; + COPY4(c30_FDD0); + pos.x+=offFDD0[*(s16 *)(p+PLAYER_FIELD(0x1C))].x<<8; + pos.y+=offFDD0[*(s16 *)(p+PLAYER_FIELD(0x1C))].y<<8; + } else COPY4(c34_FDD0); + } + break; + case 4: + tk=atkS_FDD0.kind; + if(tk==4) { + if(*(u16 *)(p+PLAYER_FIELD(0xB2))!=0 && *(u16 *)(p+PLAYER_FIELD(0xB2))!=3) return; + COPY4(c3C_FDD0); + } else if(tk==5) { + if(limBFDD0[(u8)sub_0801DE60()]>*(u16 *)(p+PLAYER_FIELD(0xB2))) return; + if(*(u16 *)(p+PLAYER_FIELD(0xB4))!=1) return; + atkS_FDD0.a9+=0x10; + COPY4(c40_FDD0); + } + break; + case 5: + tk=atkS_FDD0.kind; + if(tk==6) { + if(*(u16 *)(p+PLAYER_FIELD(0xB2))==1) { + if(*(u16 *)(p+PLAYER_FIELD(0xB4))!=1) return; + } else { + COPY4(c44_FDD0); + atkS_FDD0.a9+=8; + } + } else if(tk==8) COPY4(c48_FDD0); + break; + case 1: + switch(*(u16 *)(p+PLAYER_FIELD(0xB2))) { + case 2: case 5: case 7: break; + default: return; + } + if(*(u16 *)(p+PLAYER_FIELD(0xB4))!=1) return; + COPY4(c4C_FDD0); + if(atkS_FDD0.kind!=5) return; + break; + case 6: + if(limBFDD0[(u8)sub_0801DE60()]>*(u16 *)(p+PLAYER_FIELD(0xB2))) return; + if(*(u16 *)(p+PLAYER_FIELD(0xB4))!=1) return; + if(atkS_FDD0.kind!=5) return; + COPY4(c50_FDD0); + atkS_FDD0.a9+=0x10; + break; + case 7: + if(*(u16 *)(p+PLAYER_FIELD(0xB2))!=4) return; + atkS_FDD0.a9+=8; + break; + default: + return; + } + break; + default: + return; + } + sub_0801FD64(p); + kind=*(u16 *)(p+PLAYER_FIELD(0x1C)); + i=0; + goto echeck; +eloop: + if(!(maskFDD0&(1<=r) h=1; else h=0;} + if(h) { + hitEFDD0(p,e,atkFDD0,0); + sub_0805865C(0x1A); + if(*(u32 *)(p+PLAYER_FIELD(0x30))&0x200000) sub_08022100(*(u16 *)e+4); + } else { register u32 b asm("r1")=sub_0800086C()&1; if(!b) { + hitEFDD0(p,e,atkFDD0,1); + sub_0805865C(0x1A); + } else { + missFDD0(*(s32 *)(e+0x14),*(s32 *)(e+0x18)); + *(u32 *)(e+0x54)=*id; + sub_0805865C(0x55); + } } +enext: + i++; +echeck: + if(i<=4 && sub_0800CD8C()==0) goto eloop; + item=sceneFDD0+0x58C; + for(i=0;i<*(u32 *)(sceneFDD0+0x48);i++,item+=0x24) { + if((u16)(*(u16 *)(item+0x14)-10)<=2) continue; + if((*(u8 **)(item+0x20))[ENEMY_DATA_FIELD(6)]&3) continue; + if(testFDD0(atkFDD0,kind,&pos,item,*(u16 *)(*(u8 **)(item+0x20)+ENEMY_DATA_FIELD(0xC)),*(u16 *)(*(u8 **)(item+0x20)+ENEMY_DATA_FIELD(0xE)))==0) continue; + pw=*(u16 *)(p+PLAYER_FIELD(0x58)); + def=*(u16 *)(*(u8 **)(item+0x20)+ENEMY_DATA_FIELD(2)); + random=((((u16)sub_080008C8()%50U)<<16)+0x640000)>>16; + dm=(u16)((u16)((s32)(random*((s32)(pw*pw*10)/(s32)(pw+def)))/100)/10U); + if(dm==0) dm=1; + damage=dm; + *(u16 *)(item+0x10)-=damage; + *(u16 *)(item+0x12)=(u8)sub_0801DE60(); + dmgFDD0(i,damage,sub_0801DE60()); + if(*(u16 *)(item+0x10)&0x8000) *(u16 *)(item+0x10)=0; + *(u16 *)(item+0x14)=10; + switch((*(u8 **)(item+0x20))[ENEMY_DATA_FIELD(7)]) { + case 0: sub_0805865C(0x29); break; + case 1: sub_0805865C(0x2A); break; + case 2: sub_0805865C(0x2B); break; + } + } + if(p[PLAYER_FIELD(0x68)]<=2) return; + {u32 st=PLAYER_SIZE; for(q=playersFDD0,i=0,qh=q+PLAYER_FIELD(0xF8);i>28==14) continue; + if(((u32)(spr[0]<<28)>>28)-11<=1) continue; + id2=(u32 *)(p+PLAYER_FIELD(0xDC)); + ok=*id2!=(*(u32 *)(qh+(*(u16 *)p<<2))); + if(!ok) continue; + qpos.x=(((u16 *)spr)[0]>>4)<<8; + qpos.y=(u32)((*(u16 **)(qh+0x50))[1]<<20)>>12; + if(testFDD0(atkFDD0,kind,&pos,&qpos,16,32)!=0) { + {s16 *d=(s16 *)(q+PLAYER_FIELD(0x3A)); {register u16 c asm("r4")=((((s16)power+10)*125)/((s16)power+*d+20)); chance=c;}} + {u16 r=(u16)((u16)sub_080008C8()%100); if((s16)chance>=r) h=1; else h=0;} + if(h) { + hitPFDD0(p,q,atkFDD0,0); + sub_0805865C(0x1A); + } else if(!(sub_0800086C()&1)) { + hitPFDD0(p,q,atkFDD0,1); + sub_0805865C(0x1A); + } else { + missFDD0(*(s32 *)(q+PLAYER_FIELD(0x8C)),*(s32 *)(q+PLAYER_FIELD(0x90))); + (*(u32 *)(qh+(*(u16 *)p<<2)))=*id2; + sub_0805865C(0x55); + } + } else { + switch(ITEM_KIND(tmpl)) { + case 8: if((u8)sub_0801DE60()==7) continue; (*(u32 *)(qh+(*(u16 *)p<<2)))=*id2; break; + case 3: if((u8)sub_0801DE60()==2) continue; (*(u32 *)(qh+(*(u16 *)p<<2)))=*id2; break; + default: (*(u32 *)(qh+(*(u16 *)p<<2)))=*id2; break; + } + } + }} +#else struct PosFDD0 pos; struct PosFDD0 qpos; u8 *tmpl; @@ -1642,7 +1862,7 @@ void sub_0801FDD0(u8 *p) goto echeck; eloop: if(!(maskFDD0&(1<>16,(s32)((*(s32 *)(t+0x18)-*(s32 *)(e+0x18))<<8)>>16); + if(*(u32 *)(t+ENEMY_FIELD(0x210))==0xFF) packet.impulse=0; + angle=ArcTan2((s32)((*(s32 *)(t+ENEMY_FIELD(0x14))-*(s32 *)(e+ENEMY_FIELD(0x14)))<<8)>>16,(s32)((*(s32 *)(t+ENEMY_FIELD(0x18))-*(s32 *)(e+ENEMY_FIELD(0x18)))<<8)>>16); packet.direction=dirs20680[angle>>12]; - *(u16 *)(t+0xC)=10; - *(u32 *)(t+0x54)=*(u32 *)(e+0x50); - packet.player=t[2]; - *(u16 *)(t+0x4A)+=packet.amount; - *(u32 *)(t+0x4C)=packet.amount; - {u16 *a=(u16 *)(t+0x68); u16 v=0xFFFE; *a=v;} - hit20680(&packet,disp,0,*(u16 *)(atk+0xBC),(u16)(*(u16 *)e+4)); - {u8 pw=packet.power; *(u16 *)(t+0x62)=pw;} + *(u16 *)(t+ENEMY_FIELD(0xC))=10; + *(u32 *)(t+ENEMY_FIELD(0x54))=*(u32 *)(e+ENEMY_FIELD(0x50)); + packet.player=t[ENEMY_FIELD(2)]; + *(u16 *)(t+ENEMY_FIELD(0x4A))+=packet.amount; + *(u32 *)(t+ENEMY_FIELD(0x4C))=packet.amount; + {u16 *a=(u16 *)(t+ENEMY_FIELD(0x68)); u16 v=0xFFFE; *a=v;} + hit20680(&packet,disp,0,*(u16 *)(atk+ITEM_FIELD(0xBC)),(u16)(*(u16 *)e+ENEMY_FIELD(4))); + {u8 pw=packet.power; *(u16 *)(t+ENEMY_FIELD(0x62))=pw;} apply20680(t,&packet); - {u16 sid=*(u16 *)e; *(u16 *)(t+0x58)=sid;} - *(u16 *)(t+0x5A)|=1<hist[*(u16 *)e]!=*(u32 *)(e+0x50); - hist=(u32 *)(p+0xE4); + ok=((struct PH20680 *)p)->hist[*(u16 *)e]!=*(u32 *)(e+ENEMY_FIELD(0x50)); + hist=(u32 *)(p+PLAYER_FIELD(0xE4)); if(!ok) return; - atk=atk20680(*(u16 *)(e+0x22C)|0xB0000); - if(test20680(atk,*(u16 *)(e+8),e+0x14,p+0x8C,16,16)==0) return; - if(roll20680((s16 *)(e+0x206),(s16 *)(p+0x3A))) { + atk=atk20680(*(u16 *)(e+ENEMY_FIELD(0x22C))|0xB0000); + if(test20680(atk,*(u16 *)(e+ENEMY_FIELD(8)),e+ENEMY_FIELD(0x14),p+PLAYER_FIELD(0x8C),16,16)==0) return; + if(roll20680((s16 *)(e+ENEMY_FIELD(0x206)),(s16 *)(p+PLAYER_FIELD(0x3A)))) { r=sub_080008C8()%100; - if(p[0x6E]==0 || r>=p[0x6E]) { - *(u16 *)(p+0x20)=10; - {u16 *a=(u16 *)(p+0xB0); u16 v=0xFFFE; *a=v;} + if(p[PLAYER_FIELD(0x6E)]==0 || r>=p[PLAYER_FIELD(0x6E)]) { + *(u16 *)(p+PLAYER_FIELD(0x20))=10; + {u16 *a=(u16 *)(p+PLAYER_FIELD(0xB0)); u16 v=0xFFFE; *a=v;} dmg=amtB20680(e,p); if(dmg&0x8000) { sub_0805865C(0x27); dmg&=0x7FFF; } else { sub_0805865C(0x1A); - {u16 w=*(u16 *)(p+0xC); if(w==8) sub_0805865C(0x4B); + {u16 w=*(u16 *)(p+PLAYER_FIELD(0xC)); if(w==8) sub_0805865C(0x4B); else sub_0805865C(w+0x45);} } - *(u16 *)(p+0x88)+=dmg; - hist[*(u16 *)e]=*(u32 *)(e+0x50); - *(u32 *)(p+0x110)=*(u16 *)e+5; - packet.impulse=atk[0xA9]; + *(u16 *)(p+PLAYER_FIELD(0x88))+=dmg; + hist[*(u16 *)e]=*(u32 *)(e+ENEMY_FIELD(0x50)); + *(u32 *)(p+PLAYER_FIELD(0x110))=*(u16 *)e+ENEMY_FIELD(5); + packet.impulse=atk[ITEM_FIELD(0xA9)]; applyB20680(p,&packet); - {u16 a8=*(u16 *)(e+8); *(u16 *)(p+0xD0)=a8;} - hit20680(&packet,p+0x4C,0,*(u16 *)(atk+0xBC),*(u16 *)p); - *(u32 *)(p+0xE0)=packet.power; - exp20680(packet.power,dmg,inv20680+0x24); + {u16 a8=*(u16 *)(e+ENEMY_FIELD(8)); *(u16 *)(p+PLAYER_FIELD(0xD0))=a8;} + hit20680(&packet,p+PLAYER_FIELD(0x4C),0,*(u16 *)(atk+ITEM_FIELD(0xBC)),*(u16 *)p); + *(u32 *)(p+PLAYER_FIELD(0xE0))=packet.power; + exp20680(packet.power,dmg,inv20680+SAVE_FIELD(0x24)); st=statA20680(p,packet.power); if(st!=0) stat20680(*(u16 *)p,st,packet.power); else { st=statB20680(p,0); if(st!=0) stat20680(*(u16 *)p,st,packet.power); } - disp20680(p+0x4C,dmg,0,*(u16 *)e+4,*(u16 *)p,*(u16 *)(atk+0xBC)); + disp20680(p+PLAYER_FIELD(0x4C),dmg,0,*(u16 *)e+ENEMY_FIELD(4),*(u16 *)p,*(u16 *)(atk+ITEM_FIELD(0xBC))); return; } - counter20680(*(u32 *)(p+0x8C),*(u32 *)(p+0x90)); + counter20680(*(u32 *)(p+PLAYER_FIELD(0x8C)),*(u32 *)(p+PLAYER_FIELD(0x90))); dmg=amtB20680(e,p); if(dmg&0x8000) dmg&=0x7FFF; { /* Original keeps the counter address in r0, the sum in r1 and zz live in r4. */ - register u16 *hp asm("r0") = (u16 *)(p+0x8A); + register u16 *hp asm("r0") = (u16 *)(p+PLAYER_FIELD(0x8A)); register u32 v asm("r1"); register u32 cur asm("r2") = *hp; if (dmg>>2) v = cur + (dmg>>2); @@ -1894,29 +2115,29 @@ void sub_08020680(u8 *e) asm("" : "+r"(zz)); *hp = v; } - hist[*(u16 *)e]=*(u32 *)(e+0x50); - *(u32 *)(p+0x110)=*(u16 *)e+5; + hist[*(u16 *)e]=*(u32 *)(e+ENEMY_FIELD(0x50)); + *(u32 *)(p+PLAYER_FIELD(0x110))=*(u16 *)e+ENEMY_FIELD(5); sub_0805865C(0x164); r=sub_080008C8()%100; - if(p[0x6F]==0 || r>p[0x6F]) return; + if(p[PLAYER_FIELD(0x6F)]==0 || r>p[PLAYER_FIELD(0x6F)]) return; packet.amount=dmg-(dmg>>2); packet.power=zz; packet.impulse=zz; packet.direction=zz; - *(u16 *)(e+0xC)=10; - *(u32 *)(e+0x54)=*(u32 *)(p+0xDC); - packet.player=*(u16 *)(e+2); - *(u16 *)(e+0x4A)+=packet.amount; - *(u32 *)(e+0x4C)=packet.amount; - {u8 pw=packet.power; *(u16 *)(e+0x62)=pw;} + *(u16 *)(e+ENEMY_FIELD(0xC))=10; + *(u32 *)(e+ENEMY_FIELD(0x54))=*(u32 *)(p+PLAYER_FIELD(0xDC)); + packet.player=*(u16 *)(e+ENEMY_FIELD(2)); + *(u16 *)(e+ENEMY_FIELD(0x4A))+=packet.amount; + *(u32 *)(e+ENEMY_FIELD(0x4C))=packet.amount; + {u8 pw=packet.power; *(u16 *)(e+ENEMY_FIELD(0x62))=pw;} apply20680(e,&packet); - {u16 sid=*(u16 *)p; *(u16 *)(e+0x58)=sid;} - *(u16 *)(e+0x5A)|=1<<*(u16 *)p; - if(e[0x226]!=3) {u16 *a=(u16 *)(e+0x68); u16 v=0xFFFE; *a=v;} + {u16 sid=*(u16 *)p; *(u16 *)(e+ENEMY_FIELD(0x58))=sid;} + *(u16 *)(e+ENEMY_FIELD(0x5A))|=1<<*(u16 *)p; + if(e[ENEMY_FIELD(0x226)]!=3) {u16 *a=(u16 *)(e+ENEMY_FIELD(0x68)); u16 v=0xFFFE; *a=v;} asm("" : : "r"(zz)); notify20680(&packet); } else { - ((struct PH20680 *)p)->hist[*(u16 *)e]=*(u32 *)(e+0x50); + ((struct PH20680 *)p)->hist[*(u16 *)e]=*(u32 *)(e+ENEMY_FIELD(0x50)); sub_0805865C(0x55); } } @@ -1947,9 +2168,9 @@ void t21_20D40(s32 arg0, s32 arg1) gUnk_03005CE4 &= ~(1 << arg1); } struct T21Anim20E08 { u32 a; u32 unused; u32 b; void *palette; u8 pad[12]; u8 sprite[24]; }; -struct T21Player20E08 { u16 *position; u8 pad[0x148]; }; +struct T21Player20E08 { u16 *position; u8 pad[PLAYER_SIZE - 4]; }; extern struct T21Player20E08 t21_players20E08[] asm("gUnk_03003E28"); -struct T21Entity20E08 { u8 pad[0x14]; s32 x, y; u8 tail[0x2C4]; }; +struct T21Entity20E08 { u8 pad[0x14]; s32 x, y; u8 tail[ENEMY_SIZE - 0x1C]; }; extern struct T21Entity20E08 *t21_entities20E08 asm("gUnk_030056F4"); extern s32 t21_init20E08(void *, u32, s32, s32, s32) asm("sub_08065158"); extern void t21_7870(s32, s32, s32, s32, u32, void *, u32, u32) asm("sub_08007870"); @@ -1968,7 +2189,7 @@ void t21_20E08(u32 arg0, s32 arg1) u32 playerAddr; u16 *pos; struct T21Entity20E08 *entity; - t21_init20E08(&data, 0x5008C, 1, -1, 0); + t21_init20E08(&data, RES_ID(0x5008C), 1, -1, 0); sub_08000AF0(23, data.palette, 2); data.sprite[0] = 7; data.sprite[1] = 8; @@ -1981,16 +2202,16 @@ void t21_20E08(u32 arg0, s32 arg1) state = sub_08065370(&data, 8, (s32)&a, (s32)&b, state); if (sub_0800CC98() == 0 && sub_0800CD8C() == 0 && sub_0800CCCC() == 0) { if (arg0 <= 3) { - playerAddr = arg0 * 0x14C; + playerAddr = arg0 * PLAYER_SIZE; playerAddr += (u32)t21_players20E08; pos = *(u16 **)playerAddr; px = pos[0] >> 4; py = (u32)(pos[1] << 20) >> 20; } else { entity = t21_entities20E08; - addr = arg0 * 0x2E0; + addr = arg0 * ENEMY_SIZE; addr += (u32)entity; - addr -= 0xB80; + addr -= (4 * ENEMY_SIZE); px = *(s32 *)(addr + 0x14) >> 8; py = *(s32 *)(addr + 0x18) >> 8; } @@ -2018,7 +2239,7 @@ void t21_20F74(s32 arg0, s32 arg1) s32 zero; u32 tile; s32 dx, dy, sx; - t21_init20F74(&data, 0x5008C, 1, -1, 0); + t21_init20F74(&data, RES_ID(0x5008C), 1, -1, 0); sub_08000AF0(23, data.palette, 2); data.sprite[0] = 7; data.sprite[1] = 8; @@ -2043,9 +2264,9 @@ void t21_20F74(s32 arg0, s32 arg1) gUnk_03005CE4 &= ~(1 << arg1); } struct T21Anim210A8 { u32 a; u32 unused; u32 b; void *palette; u8 pad[12]; u8 sprite[24]; }; -struct T21Player210A8 { u8 pad[0x148]; u16 *position; }; +struct T21Player210A8 { u8 pad[PLAYER_FIELD(0x148)]; u16 *position; }; extern struct T21Player210A8 t21_players210A8[] asm("gUnk_03003CE0"); -struct T21Entity210A8 { u8 pad[0x14]; s32 x, y; u8 tail[0x2C4]; }; +struct T21Entity210A8 { u8 pad[0x14]; s32 x, y; u8 tail[ENEMY_SIZE - 0x1C]; }; extern struct T21Entity210A8 *t21_entities210A8 asm("gUnk_030056F4"); extern s32 t21_init210A8(void *, u32, s32, s32, s32) asm("sub_08065158"); void t21_210A8(u32 arg0, s32 arg1) asm("sub_080210A8"); @@ -2063,7 +2284,7 @@ void t21_210A8(u32 arg0, s32 arg1) u32 shifted, saved; u16 *pos; struct T21Entity210A8 *entity; - t21_init210A8(&data, 0x50074, 1, -1, 0); + t21_init210A8(&data, RES_ID(0x50074), 1, -1, 0); sub_08000AF0(23, data.palette, 2); data.sprite[0] = 7; data.sprite[1] = 8; @@ -2085,9 +2306,9 @@ void t21_210A8(u32 arg0, s32 arg1) py = (u32)(pos[1] << 20) >> 20; } else { entity = t21_entities210A8; - addr = arg0 * 0x2E0; + addr = arg0 * ENEMY_SIZE; addr += (u32)entity; - addr -= 0xB80; + addr -= (4 * ENEMY_SIZE); px = *(s32 *)(addr + 0x14) >> 8; py = *(s32 *)(addr + 0x18) >> 8; } @@ -2115,7 +2336,7 @@ void t21_21214(u32 arg0, u32 arg1) u16 id; s32 zero; u32 tile; - t21_init21214(&data, 0x50074, 1, -1, 0); + t21_init21214(&data, RES_ID(0x50074), 1, -1, 0); sub_08000AF0(23, data.palette, 2); data.sprite[0] = 7; data.sprite[1] = 8; @@ -2140,9 +2361,9 @@ void t21_21214(u32 arg0, u32 arg1) gUnk_03005CE4 &= ~(1 << bit); } struct T21Anim2133C { u32 a; u32 unused; u32 b; void *palette; u8 pad[12]; u8 sprite[24]; }; -struct T21Player2133C { u8 pad[0x148]; u16 *position; }; +struct T21Player2133C { u8 pad[PLAYER_FIELD(0x148)]; u16 *position; }; extern struct T21Player2133C t21_players2133C[] asm("gUnk_03003CE0"); -struct T21Entity2133C { u8 pad[0x14]; s32 x, y; u8 tail[0x2C4]; }; +struct T21Entity2133C { u8 pad[0x14]; s32 x, y; u8 tail[ENEMY_SIZE - 0x1C]; }; extern struct T21Entity2133C *t21_entities2133C asm("gUnk_030056F4"); extern s32 t21_init2133C(void *, u32, s32, s32, s32) asm("sub_08065158"); void t21_2133C(u32 arg0, s32 arg1) asm("sub_0802133C"); @@ -2158,7 +2379,7 @@ void t21_2133C(u32 arg0, s32 arg1) u32 tile, addr; u16 *pos; struct T21Entity2133C *entity; - t21_init2133C(&data, 0x5008C, 1, -1, 0); + t21_init2133C(&data, RES_ID(0x5008C), 1, -1, 0); data.sprite[0] = 7; data.sprite[1] = 8; sub_08000AF0(23, data.palette, 2); @@ -2171,9 +2392,9 @@ void t21_2133C(u32 arg0, s32 arg1) py = (u32)(pos[1] << 20) >> 20; } else { entity = t21_entities2133C; - addr = arg0 * 0x2E0; + addr = arg0 * ENEMY_SIZE; addr += (u32)entity; - addr -= 0xB80; + addr -= (4 * ENEMY_SIZE); px = *(s32 *)(addr + 0x14) >> 8; py = *(s32 *)(addr + 0x18) >> 8; } @@ -2189,9 +2410,9 @@ void t21_2133C(u32 arg0, s32 arg1) gUnk_03005CE4 &= ~(1 << arg1); } struct T21Anim21490 { u32 a; u32 unused; u32 b; void *palette; u8 pad[12]; u8 sprite[24]; }; -struct T21Player21490 { u8 pad[0x148]; u16 *position; }; +struct T21Player21490 { u8 pad[PLAYER_FIELD(0x148)]; u16 *position; }; extern struct T21Player21490 t21_players21490[] asm("gUnk_03003CE0"); -struct T21Entity21490 { u8 pad[0x14]; s32 x, y; u8 tail[0x2C4]; }; +struct T21Entity21490 { u8 pad[0x14]; s32 x, y; u8 tail[ENEMY_SIZE - 0x1C]; }; extern struct T21Entity21490 *t21_entities21490 asm("gUnk_030056F4"); extern s32 t21_init21490(void *, u32, s32, s32, s32) asm("sub_08065158"); void t21_21490(u32 arg0, s32 arg1) asm("sub_08021490"); @@ -2207,7 +2428,7 @@ void t21_21490(u32 arg0, s32 arg1) u32 tile, addr; u16 *pos; struct T21Entity21490 *entity; - t21_init21490(&data, 0x5008C, 1, -1, 0); + t21_init21490(&data, RES_ID(0x5008C), 1, -1, 0); sub_08000AF0(23, data.palette, 2); data.sprite[0] = 7; data.sprite[1] = 8; @@ -2224,9 +2445,9 @@ void t21_21490(u32 arg0, s32 arg1) py = (u32)(pos[1] << 20) >> 20; } else { entity = t21_entities21490; - addr = arg0 * 0x2E0; + addr = arg0 * ENEMY_SIZE; addr += (u32)entity; - addr -= 0xB80; + addr -= (4 * ENEMY_SIZE); px = *(s32 *)(addr + 0x14) >> 8; py = *(s32 *)(addr + 0x18) >> 8; } @@ -2287,7 +2508,7 @@ void t21_216BC(s32 arg0, s32 arg1) s32 zero; u8 tile; s32 dx, dy; - t21_init216BC(&data, 0x5008C, 1, -1, 0); + t21_init216BC(&data, RES_ID(0x5008C), 1, -1, 0); sub_08000AF0(23, data.palette, 2); data.sprite[0] = 7; data.sprite[1] = 8; @@ -2310,9 +2531,9 @@ void t21_216BC(s32 arg0, s32 arg1) gUnk_03005CE4 &= ~(1 << arg1); } struct T21Anim217D8 { u32 a; u32 unused; u32 b; void *palette; u8 pad[12]; u8 sprite[24]; }; -struct T21Player217D8 { u8 pad[0x148]; u16 *position; }; +struct T21Player217D8 { u8 pad[PLAYER_FIELD(0x148)]; u16 *position; }; extern struct T21Player217D8 t21_players217D8[] asm("gUnk_03003CE0"); -struct T21Entity217D8 { u8 pad[0x14]; s32 x, y; u8 tail[0x2C4]; }; +struct T21Entity217D8 { u8 pad[0x14]; s32 x, y; u8 tail[ENEMY_SIZE - 0x1C]; }; extern struct T21Entity217D8 *t21_entities217D8 asm("gUnk_030056F4"); extern s32 t21_init217D8(void *, u32, s32, s32, s32) asm("sub_08065158"); void t21_217D8(u32 arg0, s32 arg1) asm("sub_080217D8"); @@ -2338,7 +2559,7 @@ void t21_217D8(u32 arg0, s32 arg1) u16 id; u16 *pos; struct T21Entity217D8 *entity; - t21_init217D8(&data, 0x5008C, 1, -1, 0); + t21_init217D8(&data, RES_ID(0x5008C), 1, -1, 0); data.sprite[0] = 7; data.sprite[1] = 8; sub_08000AF0(23, data.palette, 2); @@ -2351,9 +2572,9 @@ void t21_217D8(u32 arg0, s32 arg1) py = (u32)(pos[1] << 20) >> 20; } else { entity = t21_entities217D8; - addr = index * 0x2E0; + addr = index * ENEMY_SIZE; addr += (u32)entity; - addr -= 0xB80; + addr -= (4 * ENEMY_SIZE); px = *(s32 *)(addr + 0x14) >> 8; py = *(s32 *)(addr + 0x18) >> 8; } @@ -2374,9 +2595,9 @@ void t21_217D8(u32 arg0, s32 arg1) } gUnk_03005CE4 &= ~(1 << arg1); } struct T21Anim21960 { u32 a; u32 unused; u32 b; void *palette; u8 pad[12]; u8 sprite[24]; }; -struct T21Player21960 { u8 pad[0x148]; u16 *position; }; +struct T21Player21960 { u8 pad[PLAYER_FIELD(0x148)]; u16 *position; }; extern struct T21Player21960 t21_players21960[] asm("gUnk_03003CE0"); -struct T21Entity21960 { u8 pad[0x14]; s32 x, y; u8 tail[0x2C4]; }; +struct T21Entity21960 { u8 pad[0x14]; s32 x, y; u8 tail[ENEMY_SIZE - 0x1C]; }; extern struct T21Entity21960 *t21_entities21960 asm("gUnk_030056F4"); extern s32 t21_init21960(void *, u32, s32, s32, s32) asm("sub_08065158"); void t21_21960(u32 arg0, s32 arg1) asm("sub_08021960"); @@ -2400,7 +2621,7 @@ void t21_21960(u32 arg0, s32 arg1) u32 tile, addr; u16 *pos; struct T21Entity21960 *entity; - t21_init21960(&data, 0x5008C, 1, -1, 0); + t21_init21960(&data, RES_ID(0x5008C), 1, -1, 0); data.sprite[0] = 7; data.sprite[1] = 8; sub_08000AF0(23, data.palette, 2); @@ -2413,9 +2634,9 @@ void t21_21960(u32 arg0, s32 arg1) py = (u32)(pos[1] << 20) >> 20; } else { entity = t21_entities21960; - addr = index * 0x2E0; + addr = index * ENEMY_SIZE; addr += (u32)entity; - addr -= 0xB80; + addr -= (4 * ENEMY_SIZE); px = *(s32 *)(addr + 0x14) >> 8; py = *(s32 *)(addr + 0x18) >> 8; } @@ -2458,7 +2679,7 @@ void t21_21AD8(u32 arg0, u32 arg1) u8 tile; zero = sub_0800CD34(); if (zero != 0) return; - t21_init21AD8(&data, 0x5008C, 1, -1, zero); + t21_init21AD8(&data, RES_ID(0x5008C), 1, -1, zero); data.sprite[0] = 7; data.sprite[1] = 8; sub_08000AF0(23, data.palette, 2); diff --git a/src/code_08021DC4.c b/src/code_08021DC4.c index 51530748..f671b6b4 100644 --- a/src/code_08021DC4.c +++ b/src/code_08021DC4.c @@ -192,13 +192,13 @@ s32 sub_08021FE0(s32 *arg0, s32 *arg1, u16 *arg2, u16 *arg3) { * reaches it after player-active/state/flag checks, scene predicates and inclusive21FE0 overlap on one * alternate branch. */ void sub_08022028(u8 *arg0, u8 *arg1, u16 arg2) { - ArcTan2((s16)((*(s32 *)(arg1 + 0x8C) - *(s32 *)(arg0 + 0)) << 8 >> 16), - (s16)((*(s32 *)(arg1 + 0x90) - *(s32 *)(arg0 + 4)) << 8 >> 16)); - *(u16 *)(arg1 + 0xCC) = 0; - *(u16 *)(arg1 + 0xD0) = 0; - *(u16 *)(arg1 + 0xCE) = 0; - *(u16 *)(arg1 + 0x88) += arg2; - *(u16 *)(arg1 + 0x20) = 0xA; + ArcTan2((s16)((*(s32 *)(arg1 + PLAYER_FIELD(0x8C)) - *(s32 *)(arg0 + 0)) << 8 >> 16), + (s16)((*(s32 *)(arg1 + PLAYER_FIELD(0x90)) - *(s32 *)(arg0 + 4)) << 8 >> 16)); + *(u16 *)(arg1 + PLAYER_FIELD(0xCC)) = 0; + *(u16 *)(arg1 + PLAYER_FIELD(0xD0)) = 0; + *(u16 *)(arg1 + PLAYER_FIELD(0xCE)) = 0; + *(u16 *)(arg1 + PLAYER_FIELD(0x88)) += arg2; + *(u16 *)(arg1 + PLAYER_FIELD(0x20)) = PLAYER_FIELD(0xA); } /* [StartWorldSprite14Task] Scans32 effect mask bits for first clear slot, allocates0x400 stack, installs * world-sprite14 callback, controlword0x46 and null destructor; packs arithmetic-shifted x/y into one @@ -612,7 +612,7 @@ struct T22Copy32 { u32 w[8]; }; struct T22Copy40 { u32 w[10]; }; struct T22TaskRec { u32 a,b,c; }; extern struct T22State226A4 *t22_gs asm("gUnk_03005CF4"); -struct T22Player226A4 { u8 pad0[0x2C]; u16 f2C,f2E; u8 pad30[4]; struct T22Inv226A4 *f34; u8 pad38[0x54]; s32 f8C,f90; u8 pad94[16]; struct T22Copy8 fA4; u8 padAC[0x16]; u16 fC2,fC4,fC6; u8 padC8[0x84]; }; +struct T22Player226A4 { u8 pad0[PLAYER_FIELD(0x2C)]; u16 f2C,f2E; u8 pad30[PLAYER_FIELD(0x34) - (PLAYER_FIELD(0x2F) + 1)]; struct T22Inv226A4 *f34; u8 pad38[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x38)]; s32 f8C,f90; u8 pad94[PLAYER_FIELD(0xA4) - PLAYER_FIELD(0x94)]; struct T22Copy8 fA4; u8 padAC[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xAC)]; u16 fC2,fC4,fC6; u8 padC8[PLAYER_SIZE - PLAYER_FIELD(0xC8)]; }; extern struct T22Player226A4 t22_players[] asm("gUnk_03003CE0"); extern struct T22TaskRec t22_tasks[] asm("gUnk_03005700"); extern u16 t22_seq asm("gUnk_03005D5C"); @@ -730,8 +730,13 @@ void sub_080226A4(void) { t22_gs->f36=0; asm("" : : "r"(t22_players)); selected=player; +#ifdef REGION_USA + t22_players[selected].fA4=t22_gs->fA0; + pl=&t22_players[selected]; +#else pl=&t22_players[selected]; pl->fA4=t22_gs->fA0; +#endif pl->f2E=t22_gs->f8C; pl->f2C=t22_gs->f8E; pl->fC4=t22_gs->f90; @@ -740,7 +745,11 @@ void sub_080226A4(void) { i=0; do { t22_players[selected].f34[i]=t22_gs->inv[i]; i++; } while(i<=7); { register u16 *seqPtr asm("r4"); u32 next; +#ifdef REGION_USA + t22_seq=1; i=0; { register struct T22Save226A4 **cache asm("r5")=&t22_save226A4; asm("" : : "r"(cache)); { register struct T22Save226A4 **c2 asm("ip")=cache; asm("" : : "r"(c2)); } } seqPtr=&t22_seq; +#else t22_seq=1; i=0; { register struct T22Save226A4 **savedAddr asm("r7")=&t22_save226A4; { register struct T22Save226A4 **cache asm("ip")=&t22_save226A4; asm("" : : "r"(cache)); } } seqPtr=&t22_seq; +#endif do { t22_items226A4[i]=t22_save226A4->items[i]; item=(struct T22Item226A4 *)((i<<5)+(u32)t22_items226A4); @@ -1553,7 +1562,7 @@ struct Slot23A3C { u16 active; u8 pad[6]; }; struct Area23A3C { s16 x, y; u16 w, h; struct Slot23A3C slots[5]; u16 mode; }; struct State23A3C { u16 mode, pad2, pad4, pad6, sequence, count; u8 padC[0x1BC]; u8 states[0x55C]; s32 entries[32]; }; struct Pos23A3C { u16 x; u16 pad:3, y:9, pad2:4; u8 f4:6; }; -struct Unit23A3C { u8 pad[0x30]; u32 flags; u8 pad34[0x114]; struct Pos23A3C *pos; }; +struct Unit23A3C { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 pad34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; struct Pos23A3C *pos; }; extern struct State23A3C *state23A3C asm("gUnk_03005CF4"); extern struct Unit23A3C units23A3C[] asm("gUnk_03003CE0"); extern u32 gUnk_03002344; @@ -1911,16 +1920,16 @@ struct Ent2413C { u32 b7hi:3; }; struct Player2413C { - u8 pad0[0x20]; + u8 pad0[PLAYER_FIELD(0x20)]; u16 state; - u8 pad22[2]; + u8 pad22[PLAYER_FIELD(0x24) - PLAYER_FIELD(0x22)]; s16 w24; s16 w26; - u8 pad28[8]; + u8 pad28[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x28)]; u32 flags; - u8 pad34[0x34]; + u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 b68; - u8 pad69[0x148 - 0x69]; + u8 pad69[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x69)]; struct Ent2413C *ent; }; extern struct Player2413C gPlayers2413C[] asm("gUnk_03003CE0"); @@ -2115,7 +2124,7 @@ void sub_08024538(s32 arg0) { (void)sub_08057624(1); } if (sub_0800CF80() == 0) { - *((u8 *)p + 0x68) = 1; + *((u8 *)p + PLAYER_FIELD(0x68)) = 1; } while (sub_0806617C() == 0) { (void)sub_08057624(1); @@ -2130,7 +2139,7 @@ void sub_08024538(s32 arg0) { struct Task245CC { u8 bytes[0x28]; }; struct Remote245CC { u16 x,y; u8 flags,p5,p6,flags7; }; struct Input245CC { u16 x,y,destination,flags; }; -struct Player245CC { u8 pad0[0x14]; u16 w14; u8 pad16[10]; u16 state; s16 w22,w24,w26; u8 pad28[8]; u32 flags; u8 pad34[0x58]; s32 x,y; u8 pad94[0x3a]; s16 wCE; u8 padD0[8]; s32 wD8; u8 padDC[0x6c]; struct Remote245CC *remote; }; +struct Player245CC { u8 pad0[PLAYER_FIELD(0x14)]; u16 w14; u8 pad16[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x16)]; u16 state; s16 w22,w24,w26; u8 pad28[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x28)]; u32 flags; u8 pad34[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x34)]; s32 x,y; u8 pad94[PLAYER_FIELD(0xCE) - PLAYER_FIELD(0x94)]; s16 wCE; u8 padD0[PLAYER_FIELD(0xD8) - PLAYER_FIELD(0xD0)]; s32 wD8; u8 padDC[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xDC)]; struct Remote245CC *remote; }; struct State245CC { u16 mode,p2,flags; u8 p6[0x3a]; s32 destination; u32 transition; u8 p48[0x180]; u8 states[100]; }; struct Map245CC { u8 p0[14]; u16 wE; }; struct Level245CC { u8 p0[0x8c]; u16 curLevel; u8 p8e[2]; u16 f90; u8 p92[0x1e]; struct Map245CC *map; }; @@ -2316,9 +2325,9 @@ void sub_080245CC(struct Input245CC *arg0) { spC0 = 0; local245CC_gUnk_03005CF0 = 0; if ((spC8 == 0) && (spA4 != 0)) { - local245CC_sub_08065158(&sp44, 0x5014FU, 0xC, -1, 0); + local245CC_sub_08065158(&sp44, RES_ID(0x5014FU), 0xC, -1, 0); } else { - local245CC_sub_08065158(&sp44, 0x50150U, 0xC, -1, 0); + local245CC_sub_08065158(&sp44, RES_ID(0x50150U), 0xC, -1, 0); } sp88 = local245CC_sub_08007290(0x1403D1U); temp_r8 = &local245CC_gUnk_03003CE0[local245CC_sub_080020F4()]; @@ -2449,7 +2458,7 @@ void sub_080245CC(struct Input245CC *arg0) { temp_r8->flags = temp_r1 | 0x800000; } if (local245CC_sub_0805F184() == 0) { - temp_r4 = sp88 + 2; + temp_r4 = sp88 + TEXT_HEADER; local245CC_sub_0801A3D0(temp_r4, (u16) (0xF - (local245CC_sub_0801A638(temp_r4) >> 1)), 0x12); } if (1 & temp_r8->w14) { @@ -2872,7 +2881,7 @@ afterPlayerBounds245CC: ; temp_r8->flags = temp_r1_9 | 0x800000; } if (local245CC_sub_0805F184() == 0) { - temp_r4_2 = sp88 + 2; + temp_r4_2 = sp88 + TEXT_HEADER; local245CC_sub_0801A3D0(temp_r4_2, (u16) (0xF - (local245CC_sub_0801A638(temp_r4_2) >> 1)), 0x12); } if (1 & temp_r8->w14) { @@ -3080,12 +3089,12 @@ retry: sub_080003F0(); struct T24Net25890 { u16 unk0, unk2; u8 unk4:6; u8 pad5[2]; u8 unk7; }; -struct T24Player25890 { u8 pad0[0x14]; u16 unk14; u8 pad16[10]; u16 state; s16 unk22; u16 unk24; s16 unk26; u8 pad28[6]; s16 unk2E; u32 flags; u8 pad34[0x58]; s32 unk8C, unk90; u8 pad94[0x44]; u32 unkD8; u8 padDC[0x6C]; struct T24Net25890 *net; }; +struct T24Player25890 { u8 pad0[PLAYER_FIELD(0x14)]; u16 unk14; u8 pad16[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x16)]; u16 state; s16 unk22; u16 unk24; s16 unk26; u8 pad28[PLAYER_FIELD(0x2E) - PLAYER_FIELD(0x28)]; s16 unk2E; u8 gap30[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x2F) - 1]; u32 flags; u8 pad34[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x34)]; s32 unk8C, unk90; u8 pad94[PLAYER_FIELD(0xD8) - PLAYER_FIELD(0x94)]; u32 unkD8; u8 padDC[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xDC)]; struct T24Net25890 *net; }; struct T24Sprite25890 { u32 f0,f4,f8,fC; u8 pad10[12]; u8 payload[5]; u8 byte21,byte22,byte23; u8 pad24[16]; }; struct T24State25890 { u16 unk0,pad2,unk4; u8 pad6[0x3A]; u32 unk40; u8 pad44[0x184]; u8 grid[20][5]; u8 pad22C[0x4F0]; u32 unk71C; }; extern struct T24Player25890 t24_players25890[] asm("gUnk_03003CE0"); -extern struct { u32 flags; u8 pad[0x148]; } t24_playerFlags25890[] asm("gUnk_03003D10"); -extern struct { struct T24Net25890 *net; u8 pad[0x148]; } t24_playerNets25890[] asm("gUnk_03003E28"); +extern struct { u32 flags; u8 pad[PLAYER_SIZE - 4]; } t24_playerFlags25890[] asm("gUnk_03003D10"); +extern struct { struct T24Net25890 *net; u8 pad[PLAYER_SIZE - 4]; } t24_playerNets25890[] asm("gUnk_03003E28"); extern struct T24State25890 *t24_state25890 asm("gUnk_03005CF4"); extern struct { u8 pad[0x8C]; u16 curLevel; } t24_scene25890 asm("gUnk_03003170"); extern u16 t24_keys25890 asm("gUnk_03001324"); @@ -3134,7 +3143,7 @@ void t24_gate25890(u16 *arg0) { ready = 0; text = t24_text25890(0x1403D2); player = &t24_players25890[sub_080020F4()]; - sub_08065158(&sprite, 0x500D1, 0xE, -1, ready); + sub_08065158(&sprite, RES_ID(0x500D1), 0xE, -1, ready); if (t24_state25890->unk0 == 0x15) { sub_08000AF0(0x14, (void *)(sprite.fC + 0xC0), 2); sprite.byte22 = 4; @@ -3243,7 +3252,7 @@ void t24_gate25890(u16 *arg0) { u8 *s; player->flags = flags | 0x800000; - s = text + 2; + s = text + TEXT_HEADER; sub_0801A3D0(s, (u16)(0xF - (t24_width25890(s) >> 1)), 0x12); if (player->unk14 & 1) { player->flags = (player->flags | 0x403) & 0xFF7FFFFF; @@ -3441,7 +3450,7 @@ void sub_08026338(void *arg) { sub_08000274((M2C_UNK *) (base + off), (s32) arg); } struct T24Net080263B4 { u16 unk0, unk2; u8 pad4[3]; u8 unk7; }; -struct T24Player080263B4 { u8 pad0[0x14]; u16 unk14; u8 pad16[10]; u16 state; u8 pad22[14]; u32 flags; u8 pad34[0x58]; u32 unk8C, unk90; u8 pad94[0x44]; u32 unkD8; u8 padDC[0x6C]; struct T24Net080263B4 *net; }; +struct T24Player080263B4 { u8 pad0[PLAYER_FIELD(0x14)]; u16 unk14; u8 pad16[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x16)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x34)]; u32 unk8C, unk90; u8 pad94[PLAYER_FIELD(0xD8) - PLAYER_FIELD(0x94)]; u32 unkD8; u8 padDC[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xDC)]; struct T24Net080263B4 *net; }; struct T24Sprite080263B4 { u32 f0, f4, f8, fC; u8 pad10[12]; u8 payload[15]; u8 f2B; u8 pad2C[8]; }; struct T24State080263B4 { u32 f0; u16 unk4; u8 pad6[0x3A]; u32 unk40; u8 pad44[0x184]; u8 grid[100]; }; extern struct T24Player080263B4 t24_players080263B4[] asm("gUnk_03003CE0"); @@ -3504,7 +3513,7 @@ void sub_080263B4(void) { text = t24_call08007290_080263B4(0x1403D3); { u32 index = sub_080020F4(); - u32 stride = 0x14C; + u32 stride = PLAYER_SIZE; stride *= index; { @@ -3514,7 +3523,7 @@ void sub_080263B4(void) { } } - sub_08065158(&sprite, 0x5000D, 0xE, -1, zero); + sub_08065158(&sprite, RES_ID(0x5000D), 0xE, -1, zero); sub_08000AF0(0x1EU, sprite.fC + 0x1E0, 1U); sprite.f2B = 0xE; t24_state080263B4->unk4 = (u16) (0x100 | t24_state080263B4->unk4); @@ -3542,7 +3551,7 @@ void sub_080263B4(void) { if (var_r0_2 <= 0xF) { if ((sub_0800CCCC() != 0) && (t24_scene080263B4.scene == 0)) { temp_r6->flags |= 0x800000; - temp_r4 = text + 2; + temp_r4 = text + TEXT_HEADER; sub_0801A3D0(temp_r4, (u16) (0xF - ((u32) t24_call0801A638_080263B4(temp_r4) >> 1)), 0x12); temp_r2 = temp_r6->flags; temp_r4_2 = 0x400 & temp_r2; @@ -3722,7 +3731,7 @@ void sub_080267DC(void) { sub_08000274((M2C_UNK *) (base + off), (s32) sub_0805A6A0); } struct T24Net08026858 { u16 unk0, unk2; u8 pad4[3]; u8 unk7; }; -struct T24Player08026858 { u8 pad0[0x14]; u16 unk14; u8 pad16[10]; u16 state; u8 pad22[14]; u32 flags; u8 pad34[0x58]; u32 unk8C, unk90; u8 pad94[0x44]; u32 unkD8; u8 padDC[0x6C]; struct T24Net08026858 *net; }; +struct T24Player08026858 { u8 pad0[PLAYER_FIELD(0x14)]; u16 unk14; u8 pad16[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x16)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x34)]; u32 unk8C, unk90; u8 pad94[PLAYER_FIELD(0xD8) - PLAYER_FIELD(0x94)]; u32 unkD8; u8 padDC[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xDC)]; struct T24Net08026858 *net; }; struct T24Sprite08026858 { u32 f0, f4, f8, fC; u8 pad10[12]; u8 payload[15]; u8 f2B; u8 pad2C[8]; }; struct T24State08026858 { u32 f0; u16 unk4; u8 pad6[0x3A]; u32 unk40; u8 pad44[0x184]; u8 grid[100]; }; extern struct T24Player08026858 t24_players08026858[] asm("gUnk_03003CE0"); @@ -3780,7 +3789,7 @@ void sub_08026858(void) { text = t24_call08007290_08026858(0x1403D4); { u32 index = sub_080020F4(); - u32 stride = 0x14C; + u32 stride = PLAYER_SIZE; stride *= index; { @@ -3790,7 +3799,7 @@ void sub_08026858(void) { } } - sub_08065158(&sprite, 0x5000D, 0xE, -1, var_sl); + sub_08065158(&sprite, RES_ID(0x5000D), 0xE, -1, var_sl); sub_08000AF0(0x1EU, sprite.fC + 0x1E0, 1U); sprite.f2B = 0xE; if (sub_0800CF48() != 0) { @@ -3855,7 +3864,7 @@ void sub_08026858(void) { } if (var_r0_2 <= 0xF) { if ((sub_0800CCCC() != 0) && (t24_scene08026858.scene == 0x13)) { - temp_r4 = text + 2; + temp_r4 = text + TEXT_HEADER; sub_0801A3D0(temp_r4, (u16) (0xF - ((u32) t24_call0801A638_08026858(temp_r4) >> 1)), 0x12); temp_r2 = temp_r6->flags; temp_r4_2 = 0x400 & temp_r2; @@ -4266,7 +4275,7 @@ void t025Select(s32 arg0, s32 arg1, s32 arg2) { } struct T025Block270 { u32 w[10]; }; struct T025Packet270 { u16 f0, f2; s32 f4; u8 p8[8]; }; -struct T025Player270 { u16 unk0; u8 p2[0x1A]; u16 unk1C; u8 p1E[2]; u16 unk20, unk22; u8 p24[6]; u16 unk2A; u8 p2C[4]; u32 flags; void *unk34; u8 p38[0x30]; u8 unk68; u8 p69[0x23]; struct V2W12 pos8C,pos94; u8 p9C[8]; struct V2W12 posA4; u8 pAC[0x16]; u16 unkC2,unkC4,unkC6; u8 pC8[0x80]; void *unk148; }; +struct T025Player270 { u16 unk0; u8 p2[PLAYER_FIELD(0x1C) - 2]; u16 unk1C; u8 p1E[2]; u16 unk20, unk22; u8 p24[6]; u16 unk2A; u8 p2C[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x2C)]; u32 flags; void *unk34; u8 p38[0x30]; u8 unk68; u8 p69[0x23]; struct V2W12 pos8C,pos94; u8 p9C[8]; struct V2W12 posA4; u8 pAC[0x16]; u16 unkC2,unkC4,unkC6; u8 pC8[0x80]; void *unk148; }; struct T025State270 { u16 f0,f2,f4; u8 p6[6]; u16 fC; u8 pE[2]; u16 f10; u8 p12[0x10]; u16 f22[11]; s32 f38,f3C,f40,f44,f48; u8 p4C[4]; s32 f50; u8 p54[0x18]; s32 f6C,f70; u8 p74[0x1C]; u16 f90,f92,f94; u8 p96[2]; s32 f98,f9C,fA0,fA4; u8 pA8[0xA0]; u16 f148; u8 p14A[0x5D2]; u16 *f71C; }; extern struct T025State270 *t025State270 asm("gUnk_03005CF4"); extern struct T025Player270 t025Players270[] asm("gUnk_03003CE0"); @@ -4400,11 +4409,15 @@ void sub_0802704C(s32 input) { if (temp_r1 == 4) { t025State270->f38 = (s32) t025State270->f98; t025State270->f3C = (s32) t025State270->f98; +#ifdef REGION_USA + t025Players270[sub_080020F4()].posA4 = M2C_FIELD(t025State270, struct V2W12 *, 0xA0); +#else restoreId = sub_080020F4(); restoreBase = t025Players270; - restoreStride = 0x14C; + restoreStride = PLAYER_SIZE; temp_r2_4 = (u8 *)restoreBase + restoreId * restoreStride; M2C_FIELD(temp_r2_4, struct V2W12 *, 0xA4) = M2C_FIELD(t025State270, struct V2W12 *, 0xA0); +#endif temp_r4_3 = sub_080020F4(); t025Players270[temp_r4_3].pos8C = t025Players270[sub_080020F4()].posA4; restoreIndex = sub_080020F4(); @@ -4484,9 +4497,9 @@ void sub_0802704C(s32 input) { } flagIndex = sub_080020F4(); flagBase = (u8 *)t025Players270; - flagOffset = 0x14C; + flagOffset = PLAYER_SIZE; flagOffset *= flagIndex; - flagBase += 0x30; + flagBase += PLAYER_FIELD(0x30); flagTarget = (s32 *)(flagOffset + (u32)flagBase); *flagTarget &= 0xFFFFFBFF; sub_0800BB40(); @@ -4598,14 +4611,14 @@ void sub_0802704C(s32 input) { t025State270->f2 = (s16) t025State270->f40; temp_r0 = sub_080020F4(); endBase = t025Players270; - temp_r1 = temp_r0 * 0x14C; + temp_r1 = temp_r0 * PLAYER_SIZE; endFlags = (s32 *)&endBase->flags; temp_r1_9 = (s32 *)(temp_r1 + (u32)endFlags); temp_r0 = *temp_r1_9; endMask = 0x2000; *temp_r1_9 = temp_r0 & endMask; endBase[sub_080020F4()].unk2A = (s16) t025State270->f40; - if (!(*(s32 *)((u32)endFlags + sub_080020F4() * 0x14C) & endMask)) { + if (!(*(s32 *)((u32)endFlags + sub_080020F4() * PLAYER_SIZE) & endMask)) { endBase[sub_080020F4()].unk68 = 1; } sub_08015C38(); @@ -4630,7 +4643,7 @@ void sub_0802704C(s32 input) { } struct T025Packet277 { u16 f0, f2; s32 f4; u8 p8[8]; }; -struct T025Player277 { u8 p0[0x2C]; u16 unk2C, unk2E; u8 p30[0x74]; s32 unkA4, unkA8; u8 pAC[0xA0]; }; +struct T025Player277 { u8 p0[PLAYER_FIELD(0x2C)]; u16 unk2C, unk2E; u8 p30[PLAYER_FIELD(0xA4) - (PLAYER_FIELD(0x2F) + 1)]; s32 unkA4, unkA8; u8 pAC[PLAYER_SIZE - PLAYER_FIELD(0xAC)]; }; extern struct T025Player277 t025Players277[] asm("gUnk_03003CE0"); struct T025State277 { u16 f0; u8 p2[2]; u16 f4; u8 p6[6]; u16 fC; u8 pE[2]; u16 f10; u8 p12[10]; u16 f1C; u8 p1E[4]; u16 f22[11]; s32 f38, f3C, f40, f44, f48; u8 p4C[0x71C-0x4C]; u16 *f71C; }; extern struct T025State277 *t025State277 asm("gUnk_03005CF4"); @@ -4892,7 +4905,7 @@ s32 sub_08027B50(s32 arg0) { skip: level = sub_080020F4(); base = gUnk_03003CE0; - offset = 0x14C * level; + offset = PLAYER_SIZE * level; flags = (s32 *)&base->flags; p = (s32 *)(offset + (u32)flags); *p &= ~2; @@ -4904,7 +4917,11 @@ s32 sub_08027B50(s32 arg0) { return 0; } struct T025Packet27C { u16 f0, f2; u32 rest[3]; }; -struct T025Resource27C { u16 f0; u8 p2[4]; u8 f6, f7; u16 f8; u8 pA[6]; u16 f10; u8 p12[14]; }; +struct T025Resource27C { +#ifdef REGION_USA + u8 names[0x174]; +#endif + u16 f0; u8 p2[4]; u8 f6, f7; u16 f8; u8 pA[6]; u16 f10; u8 p12[14]; }; struct T025Effect27C { struct V2W12 pos; u16 f8, fA, fC, fE, f10, f12, f14, f16, f18, f1A, f1C; u8 p1E[2]; struct T025Resource27C *res; }; struct T025Entry27C { u16 x, y, kind, spawn; }; struct T025Group27C { struct T025Entry27C e[4]; u32 tail; }; @@ -4916,9 +4933,11 @@ struct T025World27C { struct T025Effect27C effects[10]; u8 p6F4[0x1E4C - 0x6F4]; u32 f1E4C; struct T025Slot27C f1E50[4]; }; struct T025Sprite27C { u32 f0; u32 f4; u8 *f8; u32 fC; u8 p10[0xC]; u8 f1C[0x18]; }; -struct T025Player27C { u8 p0[0x2C]; u16 f2C; u8 p2E[0x14C - 0x2E]; }; +struct T025Player27C { u8 p0[PLAYER_FIELD(0x2C)]; u16 f2C; u8 p2E[PLAYER_SIZE - PLAYER_FIELD(0x2D) - 1]; }; extern struct T025World27C *t025World27C asm("gUnk_03005CF4"); -extern struct T025Resource27C t025Resources27C[] asm("gUnk_0849E760"); +/* Records indexed from 1: the table proper starts 0x10 after gUnk_0849E770. */ +extern u8 t025ResourceData27C[] asm("gUnk_0849E770"); +#define t025Resources27C ((struct T025Resource27C *)(t025ResourceData27C + 0x10) - 1) extern struct T025Config27C t025Configs27C[] asm("gUnk_084B1860"); extern struct T025Player27C t025Players27C[] asm("gUnk_03003CE0"); extern s32 t025Init27C(void *, s32, s32, s32, s32) asm("sub_08065158"); @@ -5002,14 +5021,28 @@ void t025Effects27C(u16 *arg0) } else { eff->pos = t025World27C->pos160[i]; } +#ifdef REGION_USA + eff->res = &t025Resources27C[entry->kind]; + eff->f10 = eff->res->f0 * 3; +#else res = &t025Resources27C[entry->kind]; eff->res = res; eff->f10 = res->f0 * 3; +#endif eff->f16 = entry->spawn; +#ifdef REGION_USA + if (eff->res->f8 > 1) + t025Init27C(&sprites[i], t025Configs27C[eff->res->f8].f0, 0xD, 1, 0); +#else if (res->f8 > 1) t025Init27C(&sprites[i], t025Configs27C[res->f8].f0, 0xD, 1, 0); +#endif else +#ifdef REGION_USA + t025Init27C(&sprites[i], t025Configs27C[eff->res->f8].f0, 0xD, -1, 0); +#else t025Init27C(&sprites[i], t025Configs27C[res->f8].f0, 0xD, -1, 0); +#endif eff->f14 = t025World27C->active22C[i]; eff->f8 = t025Configs27C[eff->res->f8].f4; eff->fA = 0; @@ -5049,19 +5082,39 @@ void t025Effects27C(u16 *arg0) } else { eff->pos = t025World27C->pos160[i]; } +#ifdef REGION_USA + eff->res = &t025Resources27C[entry->kind]; + eff->f10 = eff->res->f0 * 3; +#else res = &t025Resources27C[entry->kind]; eff->res = res; eff->f10 = res->f0 * 3; +#endif eff->f16 = entry->spawn; +#ifdef REGION_USA + if (eff->res->f8 > 1) + t025Init27C(&sprites[i], t025Configs27C[eff->res->f8].f0, 0xD, 1, 0); +#else if (res->f8 > 1) t025Init27C(&sprites[i], t025Configs27C[res->f8].f0, 0xD, 1, 0); +#endif else +#ifdef REGION_USA + t025Init27C(&sprites[i], t025Configs27C[eff->res->f8].f0, 0xD, -1, 0); +#else t025Init27C(&sprites[i], t025Configs27C[res->f8].f0, 0xD, -1, 0); +#endif eff->f14 = t025World27C->active22C[i]; eff->f8 = t025Configs27C[eff->res->f8].f4; +#ifdef REGION_USA + eff->fA = 0; + eff->fC = 0; + eff->fE = 0; +#else eff->fA = zr; eff->fC = zr; eff->fE = zr; +#endif eff->f18 = 1; eff->f1A = t025Configs27C[eff->res->f8].f8; eff->f1C = t025Configs27C[eff->res->f8].fC; @@ -5195,7 +5248,11 @@ void t025Effects27C(u16 *arg0) if (z != 0) { eff->f8 = t025Configs27C[res->f8].f4 + 2; } else { +#ifdef REGION_USA + t025Init27C(&sprites[g], RES_ID(0x50053), 0xD, -1, z); +#else t025Init27C(&sprites[g], 0x50053, 0xD, -1, z); +#endif eff->f8 = 6; } mode = 0; @@ -5362,7 +5419,7 @@ struct Ent0284F4 { u32 f44; }; struct Kind0284F4 { u32 res; u32 kind; }; -struct Ply0284F4 { u8 p0[0x14]; u16 f14; u8 p16[6]; s16 dir; u8 p1E[0x12]; u32 f30; u8 p34[0x58]; struct Pt0284F4 pos; u8 p94[0xB8]; }; +struct Ply0284F4 { u8 p0[PLAYER_FIELD(0x14)]; u16 f14; u8 p16[PLAYER_FIELD(0x1C) - PLAYER_FIELD(0x16)]; s16 dir; u8 p1E[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x1E)]; u32 f30; u8 p34[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x34)]; struct Pt0284F4 pos; u8 p94[PLAYER_SIZE - PLAYER_FIELD(0x94)]; }; struct State0284F4 { u8 p0[4]; u16 f4; }; struct Loc0284F4 { s16 sx, sy; u16 u, v; struct Pt0284F4 pos; struct Size0284F4 size; s32 done; }; extern struct Kind0284F4 kinds0284F4[] asm("gUnk_084B19F0"); @@ -5430,7 +5487,7 @@ void sub_080284F4_v(struct Ent0284F4 *e) e->f40 = done; } animA.data[kinds0284F4[e->f4].kind] = e->f40; - animInit0284F4(&animB, 0x50010, e->f40, -1, 0); + animInit0284F4(&animB, RES_ID(0x50010), e->f40, -1, 0); while (e->f36 != 4) { if (!(p->f30 & 0x2000) && (p->f14 & 1) && !(u8)((state0284F4->f4 >> 7) & 1) && e->f44 != 0) { pos = p->pos; @@ -5476,7 +5533,7 @@ void sub_080284F4_v(struct Ent0284F4 *e) e->id = 0; } struct Pos028830 { u16 x; u16 y; }; -struct Ply028830 { u8 pad0[0x148]; struct Pos028830 *pos; }; +struct Ply028830 { u8 pad0[PLAYER_FIELD(0x148)]; struct Pos028830 *pos; }; struct Box028830 { s32 a, b; }; struct Arg028830 { struct Box028830 box; u32 c; s32 d, e; }; extern struct Ply028830 players028830[] asm("gUnk_03003CE0"); diff --git a/src/code_08028AAC.c b/src/code_08028AAC.c index 853c54ba..86dd4b0b 100644 --- a/src/code_08028AAC.c +++ b/src/code_08028AAC.c @@ -10,8 +10,8 @@ typedef struct { s32 x, y; } Vec028AAC; struct Actor028AAC { u32 id; u8 p4[4]; Vec028AAC pos, target; u8 p18[0x58]; }; struct Obj028AAC { Vec028AAC pos; u8 p8[0x12]; u16 f1A, f1C; u8 p1E[6]; }; struct State028AAC { u8 p0[0x7A4]; struct Actor028AAC actors[15]; }; -struct Enemy028AAC { u8 p0[0x14]; Vec028AAC pos, prev, target; u8 p2C[0x2B4]; }; -struct Player028AAC { u8 p0[0x8C]; Vec028AAC pos, prev, target; u8 pA4[0xA8]; }; +struct Enemy028AAC { u8 p0[0x14]; Vec028AAC pos, prev, target; u8 p2C[ENEMY_SIZE - 0x2C]; }; +struct Player028AAC { u8 p0[PLAYER_FIELD(0x8C)]; Vec028AAC pos, prev, target; u8 pA4[PLAYER_SIZE - PLAYER_FIELD(0xA4)]; }; extern struct State028AAC *state028AAC asm("gUnk_03005CF4"); extern struct Enemy028AAC *enemies028AAC asm("gUnk_030056F4"); extern struct Player028AAC players028AAC[] asm("gUnk_03003CE0"); @@ -105,8 +105,13 @@ void sub_08028AAC_v(u32 who, s32 ax, s32 ay, s32 af) if (frames != 0) { t = 0; step = 0x400 / frames; +#ifdef REGION_USA + (&enemies028AAC[who])->target.x = x << 8; + (&enemies028AAC[who])->target.y = y << 8; +#else e->target.x = x << 8; e->target.y = y << 8; +#endif s = e->pos; do { lerp028AAC(&e->pos.x, s.x, e->target.x, t); @@ -151,8 +156,8 @@ typedef struct { s32 x, y; } Vec028D98; struct Actor028D98 { u32 id; u8 p4[4]; Vec028D98 pos, target; u8 p18[0x58]; }; struct Obj028D98 { Vec028D98 pos; u8 p8[0x12]; u16 f1A, f1C; u8 p1E[6]; }; struct State028D98 { u8 p0[0x7A4]; struct Actor028D98 actors[15]; }; -struct Enemy028D98 { u8 p0[0x14]; Vec028D98 pos, prev, target; u8 p2C[0x2B4]; }; -struct Player028D98 { u8 p0[0x8C]; Vec028D98 pos, prev, target; u8 pA4[0xA8]; }; +struct Enemy028D98 { u8 p0[0x14]; Vec028D98 pos, prev, target; u8 p2C[ENEMY_SIZE - 0x2C]; }; +struct Player028D98 { u8 p0[PLAYER_FIELD(0x8C)]; Vec028D98 pos, prev, target; u8 pA4[PLAYER_SIZE - PLAYER_FIELD(0xA4)]; }; extern struct State028D98 *state028D98 asm("gUnk_03005CF4"); extern struct Enemy028D98 *enemies028D98 asm("gUnk_030056F4"); extern struct Player028D98 players028D98[] asm("gUnk_03003CE0"); @@ -288,9 +293,9 @@ void sub_08028D98_v(u32 who, s32 ax, s32 ay, s32 af) } } extern u8 *scene026E4 asm("gUnk_03005CF4"); -struct Monster026E4 {u8 pad[8];u16 value;u8 tail[0x2D6];}; +struct Monster026E4 {u8 pad[8];u16 value;u8 tail[ENEMY_SIZE - 0xA];}; extern struct Monster026E4 *monsters026E4 asm("gUnk_030056F4"); -struct Player026E4 {u8 pad[0x1C];u16 value;u8 tail[0x12E];}; +struct Player026E4 {u8 pad[PLAYER_FIELD(0x1C)];u16 value;u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x1E)];}; extern struct Player026E4 players026E4[] asm("gUnk_03003CE0"); void task026E4(u32,u32) asm("sub_080290E4"); /* [SetSceneEntityFacing] Writes direction at actor +0x24, enemy +8, or local player +0x1C. Actor path requests @@ -339,12 +344,12 @@ void task026E4(u32 id,u32 value) key--; if(key<=4) { monsterAddress=&monsters026E4; - offset=key*0x2E0; + offset=key*ENEMY_SIZE; *(u16 *)((u8 *)*monsterAddress+offset+8)=savedValue; } } else { - playerIndex=sub_080020F4()*0x14C; + playerIndex=sub_080020F4()*PLAYER_SIZE; playerBase=players026E4; ((struct Player026E4 *)(playerIndex+(u32)playerBase))->value=savedValue; @@ -354,8 +359,8 @@ void task026E4(u32 id,u32 value) } struct Actor029174 { u32 id; u8 p4[0x20]; u16 f24; u8 p26[6]; u16 f2C, f2E, f30, f32, f34; u8 p36[2]; u16 f38; u8 p3A[0x36]; }; struct State029174 { u8 p0[0x7A4]; struct Actor029174 actors[15]; }; -struct Enemy029174 { u8 p0[0xC]; u16 fC, fE; u8 p10[0x5A]; u16 f6A, f6C, f6E, f70, f72; u8 p74[0x26C]; }; -struct Player029174 { u8 p0[0x10]; u16 f10; u8 p12[0xE]; u16 f20, f22; u8 p24[0x92]; u16 fB6; u8 pB8[2]; u16 fBA, fBC, fBE, fC0; u8 pC2[0x8A]; }; +struct Enemy029174 { u8 p0[0xC]; u16 fC, fE; u8 p10[0x5A]; u16 f6A, f6C, f6E, f70, f72; u8 p74[ENEMY_SIZE - 0x74]; }; +struct Player029174 { u8 p0[PLAYER_FIELD(0x10)]; u16 f10; u8 p12[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x12)]; u16 f20, f22; u8 p24[PLAYER_FIELD(0xB6) - PLAYER_FIELD(0x24)]; u16 fB6; u8 pB8[PLAYER_FIELD(0xBA) - PLAYER_FIELD(0xB8)]; u16 fBA, fBC, fBE, fC0; u8 pC2[PLAYER_SIZE - PLAYER_FIELD(0xC2)]; }; extern struct State029174 *state029174 asm("gUnk_03005CF4"); extern struct Enemy029174 *enemies029174 asm("gUnk_030056F4"); extern struct Player029174 players029174[] asm("gUnk_03003CE0"); @@ -533,8 +538,8 @@ void sub_0802939C_v(u32 target, u16 val) struct Vec02949C { s32 x, y; }; struct ActorPos02949C { u32 id; u8 p4[4]; struct Vec02949C pos; u8 p10[0x14]; s16 dir; u16 goal; u8 p28[0x48]; }; struct State02949C { u8 p0[0x7A4]; struct ActorPos02949C actors[15]; }; -struct EnemyPos02949C { u8 p0[8]; s16 dir; u16 goal; u8 pC[8]; struct Vec02949C pos; u8 p1C[0x2C4]; }; -struct PlayerPos02949C { u8 p0[0x1C]; s16 dir; u16 goal; u8 p20[0x6C]; struct Vec02949C pos; u8 p94[0xB8]; }; +struct EnemyPos02949C { u8 p0[8]; s16 dir; u16 goal; u8 pC[8]; struct Vec02949C pos; u8 p1C[ENEMY_SIZE - 0x1C]; }; +struct PlayerPos02949C { u8 p0[PLAYER_FIELD(0x1C)]; s16 dir; u16 goal; u8 p20[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x20)]; struct Vec02949C pos; u8 p94[PLAYER_SIZE - PLAYER_FIELD(0x94)]; }; extern struct State02949C *state02949C asm("gUnk_03005CF4"); extern struct EnemyPos02949C *enemies02949C asm("gUnk_030056F4"); extern struct PlayerPos02949C players02949C[] asm("gUnk_03003CE0"); @@ -686,8 +691,8 @@ void sub_0802949C(u32 who, u32 toward) } struct Actor029788 { u32 id; u8 p4[0x20]; s16 dir; u16 goal; u8 p28[0x48]; }; struct State029788 { u8 p0[0x7A4]; struct Actor029788 actors[15]; }; -struct Enemy029788 { u8 p0[8]; s16 dir; u8 pA[0x2D6]; }; -struct Player029788 { u8 p0[0x1C]; s16 dir; u16 goal; u8 p20[0x12C]; }; +struct Enemy029788 { u8 p0[8]; s16 dir; u8 pA[ENEMY_SIZE - 0xA]; }; +struct Player029788 { u8 p0[PLAYER_FIELD(0x1C)]; s16 dir; u16 goal; u8 p20[PLAYER_SIZE - PLAYER_FIELD(0x20)]; }; extern struct State029788 *state029788 asm("gUnk_03005CF4"); extern struct Enemy029788 *enemies029788 asm("gUnk_030056F4"); extern struct Player029788 players029788[] asm("gUnk_03003CE0"); @@ -799,7 +804,7 @@ void sub_08029788_v(u32 target) } while (p->dir != goal); } } -struct P96C { u16 id; u8 pad2[0x2E]; u32 flags; u8 pad34[0x2C]; u16 f60; u16 f62; u8 pad64[4]; u8 f68; u8 pad69[0x59]; u16 fC2; u16 fC4; u8 tail[0x14C-0xC6]; }; +struct P96C { u16 id; u8 pad2[PLAYER_FIELD(0x30) - 2]; u32 flags; u8 pad34[0x2C]; u16 f60; u16 f62; u8 pad64[4]; u8 f68; u8 pad69[0x59]; u16 fC2; u16 fC4; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0xC6)]; }; extern struct P96C players96C[] asm("gUnk_03003CE0"); #define DRAIN_96C(n) p=&players96C[index]; do { h=(void*)sub_0801E1D8(p,n,100); if(h) {sub_0801DB94(p->id,h,0); asm("":"+r"(h));} } while(h) /* [RestoreLocalPlayerVitals] Copies local player maximum fields+0x62 and+0x60 to current HP+0xC4 and MP+0xC2, @@ -836,20 +841,20 @@ void sub_08029A7C(u32 action,u32 amount,s32 argument) u8 result[8]; u8 *res; u8 *player; u32 flags; s32 handle; u16 kind; player=(u8*)&gUnk_03003CE0[sub_080020F4()]; if(sub_0800CDF8()==0 && sub_08058DB0()==0){ - kind=H_A7(player,0x20); - if(kind!=14 && player[0x68]!=0 && kind!=11){ - flags=W_A7(player,0x30)&0x2000; - if(flags==0 && kind!=10){ - amount=scaleA7C(amount,H_A7(player,0x5A),200); + kind=H_A7(player,PLAYER_FIELD(0x20)); + if(kind!=14 && player[PLAYER_FIELD(0x68)]!=0 && kind!=PLAYER_FIELD(11)){ + flags=W_A7(player,PLAYER_FIELD(0x30))&0x2000; + if(flags==0 && kind!=PLAYER_FIELD(10)){ + amount=scaleA7C(amount,H_A7(player,PLAYER_FIELD(0x5A)),200); res=result; - initA7C(result,player+0x4C,argument,action,H_A7(player,0)); + initA7C(result,player+PLAYER_FIELD(0x4C),argument,action,H_A7(player,0)); handle=sub_0801E164(player,0); if(handle)sub_0801DB94(H_A7(player,0),(void*)handle,res[1]); - amount=valueA7C(action,amount,player+0x4C); - H_A7(player,0x20)=10; H_A7(player,0x88)+=amount; - W_A7(player,0x110)=flags; H_A7(player,0xC8)=flags; H_A7(player,0xCA)=flags; W_A7(player,0xE0)=flags; - if(H_A7(player,0xC)==8)sub_0805865C(0x4B); else sub_0805865C(H_A7(player,0xC)+0x45); - runA7C(player+0x4C,amount,argument,0,H_A7(player,0),action); + amount=valueA7C(action,amount,player+PLAYER_FIELD(0x4C)); + H_A7(player,PLAYER_FIELD(0x20))=PLAYER_FIELD(10); H_A7(player,PLAYER_FIELD(0x88))+=amount; + W_A7(player,PLAYER_FIELD(0x110))=flags; H_A7(player,PLAYER_FIELD(0xC8))=flags; H_A7(player,PLAYER_FIELD(0xCA))=flags; W_A7(player,PLAYER_FIELD(0xE0))=flags; + if(H_A7(player,PLAYER_FIELD(0xC))==8)sub_0805865C(0x4B); else sub_0805865C(H_A7(player,PLAYER_FIELD(0xC))+0x45); + runA7C(player+PLAYER_FIELD(0x4C),amount,argument,0,H_A7(player,0),action); } } } @@ -874,16 +879,16 @@ void sub_08029B98(s32 index,u32 action,u32 amount,u32 argument,u16 arg4,u16 arg5 { struct ResultB98 result; struct ResultB98 *res; struct ResultB98 *res1; u8 *object; void *handle; if(((u32)gUnk_030056FC & (1<b); } - amount=valueB98(action,amount,object+0x218); + amount=valueB98(action,amount,object+ENEMY_FIELD(0x218)); H_B9(object,0xC)=10; res=&result; res->value=amount;res->a=H_B9(object,2);res->c=arg4;res->d=arg5; @@ -891,7 +896,7 @@ void sub_08029B98(s32 index,u32 action,u32 amount,u32 argument,u16 arg4,u16 arg5 H_B9(object,0x58)=sub_080020F4(); H_B9(object,0x4A)=amount;W_B9(object,0x4C)=amount; H_B9(object,0x5A)|=1<value,argument,index,index+4,action); + if(object[ENEMY_FIELD(0x226)]!=3)runB98(object+ENEMY_FIELD(0x218),res->value,argument,index,index+4,action); } } #define H_CE(p,n) (*(u16*)((p)+(n))) @@ -913,19 +918,19 @@ void sub_08029CEC(u32 action,u32 amount,s32 argument) u8 result[8]; u8 *res; u8 *player; u32 flags; s32 handle; u16 kind; player=(u8*)&gUnk_03003CE0[sub_080020F4()]; if(sub_0800CDF8()==0 && sub_08058DB0()==0){ - kind=H_CE(player,0x20); - if(kind!=14 && player[0x68]!=0 && kind!=11){ - flags=W_CE(player,0x30)&0x2000; - if(flags==0 && kind!=10){ + kind=H_CE(player,PLAYER_FIELD(0x20)); + if(kind!=14 && player[PLAYER_FIELD(0x68)]!=0 && kind!=PLAYER_FIELD(11)){ + flags=W_CE(player,PLAYER_FIELD(0x30))&0x2000; + if(flags==0 && kind!=PLAYER_FIELD(10)){ res=result; - initCEC(result,player+0x4C,argument,action,H_CE(player,0)); + initCEC(result,player+PLAYER_FIELD(0x4C),argument,action,H_CE(player,0)); handle=sub_0801E164(player,0); if(handle)sub_0801DB94(H_CE(player,0),(void*)handle,res[1]); - amount=valueCEC(action,amount,player+0x4C); - W_CE(player,0xE0)=action; extraCEC(action,amount,stateCEC+0x24); H_CE(player,0x20)=10; H_CE(player,0x88)+=amount; - W_CE(player,0x110)=flags; H_CE(player,0xC8)=flags; H_CE(player,0xCA)=flags; - if(H_CE(player,0xC)==8)sub_0805865C(0x4B); else sub_0805865C(H_CE(player,0xC)+0x45); - runCEC(player+0x4C,amount,argument,0,H_CE(player,0),action); + amount=valueCEC(action,amount,player+PLAYER_FIELD(0x4C)); + W_CE(player,PLAYER_FIELD(0xE0))=action; extraCEC(action,amount,stateCEC+SAVE_FIELD(0x24)); H_CE(player,PLAYER_FIELD(0x20))=PLAYER_FIELD(10); H_CE(player,PLAYER_FIELD(0x88))+=amount; + W_CE(player,PLAYER_FIELD(0x110))=flags; H_CE(player,PLAYER_FIELD(0xC8))=flags; H_CE(player,PLAYER_FIELD(0xCA))=flags; + if(H_CE(player,PLAYER_FIELD(0xC))==8)sub_0805865C(0x4B); else sub_0805865C(H_CE(player,PLAYER_FIELD(0xC))+0x45); + runCEC(player+PLAYER_FIELD(0x4C),amount,argument,0,H_CE(player,0),action); } } } @@ -948,25 +953,25 @@ void sub_08029E0C(s32 index,u32 action,u32 amount,u32 argument,u16 arg4,u16 arg5 { u8 zero; struct ResultE0C result; struct ResultE0C *res; struct ResultE0C *res1; u8 *object; void *handle; if(((u32)gUnk_030056FC & (1<b); } - amount=valueE0C(action,amount,object+0x218); + amount=valueE0C(action,amount,object+ENEMY_FIELD(0x218)); zero=0; H_E0(object,0xC)=10+zero; H_E0(object,0x4A)=amount; W_E0(object,0x4C)=amount; res=&result; res->value=amount;res->c=arg4;res->a=H_E0(object,2);res->d=arg5; if(res->c&0x80)res->c=zero; - if(W_E0(object,0x210)==0xFF)res->c=zero; + if(W_E0(object,ENEMY_FIELD(0x210))==0xFF)res->c=zero; sub_0801F2CC(object,(u8*)&result); H_E0(object,0x58)=sub_080020F4(); finishE0C(&result); - if(object[0x226]!=3)runE0C(object+0x218,res->value,argument,index,index+4,action); + if(object[ENEMY_FIELD(0x226)]!=3)runE0C(object+ENEMY_FIELD(0x218),res->value,argument,index,index+4,action); } } struct PackedF54 {u16 low:4;u16 x:12;u16 y:12;u16 high:4;u8 flags:6;u8 unused:2;}; @@ -1004,7 +1009,7 @@ void sub_08029F54(s32 x,s32 y,u32 low,s32 high,volatile u32 callback) index=0; base=refsF54; while(indexposition->x<<8; player.y=reference->position->y<<8; hit=overlapF54(&player,¢er,&mask,&range); @@ -1051,7 +1056,7 @@ void sub_0802A01C(void) *((u16 *) (p + 0x7A)) &= 0xFFF7; } i++; - p += 0x2E0; + p += ENEMY_SIZE; } while (i <= 4); } @@ -1089,7 +1094,7 @@ void sub_0802A080(s32 x,s32 y,u32 low,s32 high) wait=1; index=0; while(indexposition->x<<8; player.y=reference->position->y<<8; flag=reference->position->flags; flag&=0x20; @@ -1400,6 +1405,42 @@ extern void drawA644(u8*,s32,u32) asm("sub_0801A3D0"); * zero-terminated substitution bytes at 03003CE2. OriginalA67E..684 preincrementvalue>5 * meansoneencodedbyte/actionevery7outeriterations;FE180-yieldpause021A8can * shorten;postFDunconditional180-yieldholdthen clear(15,4),oneyield. */ +#ifdef REGION_USA +void sub_0802A644(s32 id) +{ + TextChar text[4][0x20]; TextChar *stream,*line; u32 row,column,tick,i,y; u16 wait; u16 nameIndex; NameChar *names; + stream=(TextChar *)((u8*)sub_08007290(0x140000|id)+TEXT_HEADER); + row=0;column=0;tick=0;nameIndex=0;text[0][0]=TEXT_CTRL(0xFD);names=(NameChar *)nameA644;text[1][0]=TEXT_CTRL(0xFD); + while(*stream!=TEXT_CTRL(0xFD)){ + if(tick++>5){ + if(*stream==TEXT_CTRL(0xFF)){ + column=0;row++; + if(row>1){text[0][0]=TEXT_CTRL(0xFD);text[1][0]=TEXT_CTRL(0xFD);row=0;} + else text[row][0]=TEXT_CTRL(0xFD); + stream++; + } else if(*stream==TEXT_CTRL(0xFC)){ + text[row][column]=names[nameIndex];column++;text[row][column]=TEXT_CTRL(0xFD); + nameIndex++; + if(names[nameIndex]==0){stream++;nameIndex=0;column--;} + } else if(*stream==TEXT_CTRL(0xFE)){ + text[0][0]=TEXT_CTRL(0xFD);text[1][0]=TEXT_CTRL(0xFD);row=0;column=0;stream+=3; + for(wait=180;wait;wait--){sub_080003F0();if(sub_080021A8())break;} + } else { + text[row][column]=*stream;stream++;column++;text[row][column]=TEXT_CTRL(0xFD); + } + tick=0; + } + for(i=0;i<=1;i++)drawA644((u8 *)text[i],1,(u16)(i*2+15)); + sub_080003F0(); + } + tick=179; + do{ + i=0;if(i>16);y+=0x20000;line+=0x20;i++;}while(iflags |= 2; sub_08067D74(); - *((u32 *) (((u8 *) (&gUnk_03003CE0[sub_080020F4()])) + 0x8C)) = 0x12C00; + *((u32 *) (((u8 *) (&gUnk_03003CE0[sub_080020F4()])) + PLAYER_FIELD(0x8C))) = 0x12C00; for (wait = 10; wait; wait--) { sub_080003F0(); @@ -1548,6 +1590,48 @@ void sub_0802A7DC(void) * contain byte 0xFD at exactly that length. Returns the first matched resource index 0..12, or -1. Does not * hash/randomize a name, change stats itself, enforce a maximum name length or validate resource * pointers/terminators. */ +#ifdef REGION_USA +s32 sub_0802A9B0(void) { + u32 var_r5 = 0x533; + register TextChar **seqAddr asm("r6"); + register TextChar **globalAddr asm("r0"); + TextChar *seq; + s32 var_r7; + TextChar *attrs; + register s32 var_r3 asm("r3"); + register TextChar temp_r2 asm("r2"); + register u32 endMark asm("r8") = TEXT_CTRL(0xFF); + register u32 nameEnd asm("r9") = TEXT_CTRL(0xFD); + register u32 off asm("r1"); + do { + u8 *temp_r0 = (u8 *)sub_08007290(0x140000 | var_r5); + attrs = (TextChar *)(temp_r0 + TEXT_HEADER); + var_r7 = 1; + var_r3 = 0; + temp_r2 = *(TextChar *)(temp_r0 + TEXT_HEADER); + if (temp_r2 != endMark) { + globalAddr = (TextChar **)&gUnk_030034E0; + seq = *globalAddr; + seqAddr = globalAddr; + if (temp_r2 != seq[0]) goto block_9; + do { + var_r3++; + off = var_r3 * sizeof(TextChar); + temp_r2 = *(TextChar *)(off + (u32)attrs); + if (temp_r2 == endMark) break; + if (temp_r2 != *(TextChar *)((u8 *)*seqAddr + off)) { + var_r7 = 0; + break; + } + } while (1); + } + if (var_r7 != 0) { u32 g = *(u32 *)&gUnk_030034E0; off = var_r3 * sizeof(TextChar); if (*(TextChar *)(g + off) == nameEnd) return var_r5 - 0x533; } +block_9: + var_r5++; + } while (var_r5 <= 0x53F); + return -1; +} +#else s32 sub_0802A9B0(void) { u32 var_r5 = 0x533; register u8 **seqAddr asm("r6"); @@ -1586,6 +1670,7 @@ s32 sub_0802A9B0(void) { } while (var_r5 <= 0x53F); return -1; } +#endif extern u8 *stateAA28 asm("gUnk_03005CF4"); /* Second name for the same slot: keeps the relocation but stops CSE with stateAA28. */ extern u8 *sceneAA28 asm("gUnk_03005CF4"); @@ -3021,7 +3106,7 @@ doneTask114:; player028=sub_080020F4(); count028 = 0; index028 = 0; - var_r1_13 = (u8 *)gUnk_030034E0 + 0x150; + var_r1_13 = (u8 *)gUnk_030034E0 + SAVE_FIELD(0x150); do { if ((*(u16 *)((u8 *)var_r1_13 + 0x0) == 1) && (*(u16 *)((u8 *)var_r1_13 + 0x2) == 0x29)) { count028 += 1; @@ -3032,7 +3117,7 @@ doneTask114:; saved028=count028; count028 = 0; index028 = 0; - var_r1_14 = (u8 *)gUnk_030034E0 + 0x2E0; + var_r1_14 = (u8 *)gUnk_030034E0 + SAVE_FIELD(0x2E0); do { if ((*(u16 *)((u8 *)var_r1_14 + 0x0) == 1) && (*(u16 *)((u8 *)var_r1_14 + 0x2) == 0x29)) { count028 += 1; @@ -3076,12 +3161,12 @@ inventoryDone028:; u32 stride028; u32 playerRet028=sub_080020F4(); - stride028=0x14C; + stride028=PLAYER_SIZE; playerOffset028=playerRet028; playerOffset028 *= stride028; temp_r2_2=(void *)(playerOffset028+(u32)gUnk_03003CE0); - *(u32 *)((u8 *)temp_r2_2+0x30) |= 1; + *(u32 *)((u8 *)temp_r2_2+SAVE_FIELD(0x30)) |= 1; } sub_0800D0F4(); temp_r7 = sub_080289C0(0x31, 0xF0, 0x190); @@ -3265,7 +3350,7 @@ void sub_0802C144(void) { void (*callback)(void); struct Player *player; register u32 offset asm("r2"); - offset = 0x14C * sub_080020F4(); + offset = PLAYER_SIZE * sub_080020F4(); player = (struct Player *)(offset + (u32)gUnk_03003CE0); @@ -3313,7 +3398,7 @@ void sub_0802C144(void) { sub_080003F0(); } done: - offset = 0x14C * sub_080020F4(); + offset = PLAYER_SIZE * sub_080020F4(); player = (struct Player *)(offset + (u32)gUnk_03003CE0); @@ -4057,8 +4142,8 @@ finalCbStore028c:; sub_080003F0(); checkWait238: if(sub_0801AAE0()==0) goto loop_238; - temp_r2 = (void *)(0x14C * sub_080020F4() + (u32)gUnk_03003CE0); - *(u32 *)((u8 *)temp_r2 + 0x30) = (s32) (*(u32 *)((u8 *)temp_r2 + 0x30) & ~1); + temp_r2 = (void *)(PLAYER_SIZE * sub_080020F4() + (u32)gUnk_03003CE0); + *(u32 *)((u8 *)temp_r2 + PLAYER_FIELD(0x30)) = (s32) (*(u32 *)((u8 *)temp_r2 + PLAYER_FIELD(0x30)) & ~1); sub_0800D108(); return; } @@ -6588,7 +6673,7 @@ extern void sub_0802939C(s32, s32); extern void sub_0802F424(s32); struct TaskP30F2 { u32 f0, f4, f8, fC, f10, f14, f18, f1C, f20, f24; }; extern void taskStart30F2(void *, u32) asm("sub_08000274"); -struct Entry30F2 { u8 pad[12]; u16 state; u8 end[0x2E0 - 14]; }; +struct Entry30F2 { u8 pad[12]; u16 state; u8 end[ENEMY_SIZE - 14]; }; /* [RunObjectThirtyThreeRelease] Clears mode-selected byte mask0x8, sets player flag1 and creates kind0x21; * transitions, signals0x09999000, runs timed animation/message0x1401F9 sequence and starts helper task * from30-slot pool with allocation retry. Full pool skips helper. Clears player flag1, resets active actor @@ -6824,7 +6909,7 @@ void sub_0802F578(void) u32 dialog; u32 value; offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; sub_0800D0F4(); @@ -6945,7 +7030,7 @@ void sub_0802F578(void) } } offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; sub_0800D108(); @@ -6972,7 +7057,7 @@ void sub_0802FA80(void) u32 dialog; u32 value; offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; sub_0800D0F4(); @@ -7069,7 +7154,7 @@ void sub_0802FA80(void) } } offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; sub_0800D108(); diff --git a/src/code_0802FEA0.c b/src/code_0802FEA0.c index 82394853..601585ad 100644 --- a/src/code_0802FEA0.c +++ b/src/code_0802FEA0.c @@ -36,7 +36,7 @@ void sub_0802FEA0(s32 arg) u32 dialog; u32 value; offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; sub_0800D0F4(); @@ -181,7 +181,7 @@ void sub_0802FEA0(s32 arg) } sub_08029788(arg); offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; sub_0800D108(); @@ -206,7 +206,7 @@ void sub_08030480(s32 arg) u32 dialog; u32 value; offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; sub_0800D0F4(); @@ -305,7 +305,7 @@ void sub_08030480(s32 arg) } sub_08029788(arg); offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; sub_0800D108(); @@ -324,7 +324,7 @@ void sub_080308B4(void) u32 dialog; register u32 value asm("r4"); offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; sub_0800D0F4(); @@ -382,7 +382,7 @@ void sub_080308B4(void) break; } offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; sub_0800D108(); @@ -402,7 +402,7 @@ void sub_08030B28(s32 arg) u32 dialog; u32 value; offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; sub_0800D0F4(); @@ -500,7 +500,7 @@ void sub_08030B28(s32 arg) } } offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; sub_0800D108(); @@ -517,7 +517,7 @@ void sub_08030F54(void) u32 dialog; s32 v; - ((struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0))->flags |= 1; + ((struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0))->flags |= 1; sub_0800D0F4(); if (sub_0800CE30()) field = *(u32 *)(gUnk_03005CF4 + 0x7C); @@ -645,7 +645,7 @@ void sub_08030F54(void) sub_080003F0(); } } - ((struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0))->flags &= ~1; + ((struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0))->flags &= ~1; sub_0800D108(); } extern u8 *state32 asm("gUnk_03005CF4"); @@ -665,13 +665,13 @@ void sub_0803145C(void) s32 raw; s32 one; firstIndex = sub_080020F4(); - stride = 0x14C; + stride = PLAYER_SIZE; stride *= firstIndex; firstPlayer = players32 + stride; - flags = *(u32 *)(firstPlayer + 0x30); + flags = *(u32 *)(firstPlayer + PLAYER_FIELD(0x30)); one = 1; flags |= one; - *(u32 *)(firstPlayer + 0x30) = flags; + *(u32 *)(firstPlayer + PLAYER_FIELD(0x30)) = flags; sub_0800D0F4(); if (sub_0800CE30()) flag = state32 + 0x1C6; else flag = state32 + 0x1BA; @@ -696,10 +696,10 @@ void sub_0803145C(void) } } lastOffset = sub_080020F4(); - stride = 0x14C; + stride = PLAYER_SIZE; lastOffset *= stride; player = players32 + lastOffset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } /* [ShowEvent26Messages369And370] 1BA/1C6 bit2 selects resources140171/140172; both branches wait busy slots @@ -717,13 +717,13 @@ void sub_08031580(void) s32 raw; s32 one; firstIndex = sub_080020F4(); - stride = 0x14C; + stride = PLAYER_SIZE; stride *= firstIndex; firstPlayer = players32 + stride; - flags = *(u32 *)(firstPlayer + 0x30); + flags = *(u32 *)(firstPlayer + PLAYER_FIELD(0x30)); one = 1; flags |= one; - *(u32 *)(firstPlayer + 0x30) = flags; + *(u32 *)(firstPlayer + PLAYER_FIELD(0x30)) = flags; sub_0800D0F4(); if (sub_0800CE30()) flag = state32 + 0x1C6; else flag = state32 + 0x1BA; @@ -748,10 +748,10 @@ void sub_08031580(void) } } lastOffset = sub_080020F4(); - stride = 0x14C; + stride = PLAYER_SIZE; lastOffset *= stride; player = players32 + lastOffset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } /* [RunAzieDialogue] Sets local player flags bit 0 (input suppression), calls BeginLocalPlayerEventLock and @@ -765,7 +765,7 @@ void sub_080316A4(s32 arg) { u32 dialog; - ((struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0))->flags |= 1; + ((struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0))->flags |= 1; sub_0800D0F4(); sub_0802949C(arg, 0); while (sub_0805F184()) @@ -812,7 +812,7 @@ void sub_080316A4(s32 arg) } } sub_08029788(arg); - ((struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0))->flags &= ~1; + ((struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0))->flags &= ~1; sub_0800D108(); } #define MENU_FLAGS_VALUE_31() (sub_0800CE30() ? *(u8 *)(gUnk_03005CF4 + 0x1C5) : *(u8 *)(gUnk_03005CF4 + 0x1B9)) @@ -863,7 +863,7 @@ void sub_0803188C(void) sub_0800CE54(); while (!sub_0801AAE0()) sub_080003F0(); - ((struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0))->flags &= ~1; + ((struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0))->flags &= ~1; sub_0800D108(); } /* [OpenCollectionMenu6PreservingCamera] Locks local player and scene input; conditionally consumes menu flag @@ -912,7 +912,7 @@ void sub_080319F0(void) sub_0800CE54(); while (!sub_0801AAE0()) sub_080003F0(); - ((struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0))->flags &= ~1; + ((struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0))->flags &= ~1; sub_0800D108(); } /* [OpenCollectionMenu1PreservingCamera] Locks local player and scene input; conditionally consumes menu flag @@ -961,7 +961,7 @@ void sub_08031B54(void) sub_0800CE54(); while (!sub_0801AAE0()) sub_080003F0(); - ((struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0))->flags &= ~1; + ((struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0))->flags &= ~1; sub_0800D108(); } extern u8 gS03003170[] asm("gUnk_03003170"); @@ -1101,7 +1101,7 @@ void sub_08031F28(void) sub_0800D108(); } struct Rec1FF8 { u16 a, b; u8 pad[12]; }; -struct Recs1FF8 { u8 pad[0x150]; struct Rec1FF8 r[25]; }; +struct Recs1FF8 { u8 pad[SAVE_FIELD(0x150)]; struct Rec1FF8 r[25]; }; /* [RunWanbyDialogue] Sets local player flags bit 0 (input suppression) and BeginLocalPlayerEventLock, with no * facing change. Counts bag records (character +0x150, 25 slots) with kind 6 and ID 0x59. When * LinkCountConnectedPlayers is exactly 1 and at least one exists, it clears the first matching record and @@ -1120,11 +1120,11 @@ void sub_08031FF8(void) register u8 *p asm("r1"); s32 mask; - ((struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0))->flags |= 1; + ((struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0))->flags |= 1; sub_0800D0F4(); count = 0; i = 0; - e = (u16 *)(gUnk_030034E0 + 0x150); + e = (u16 *)(gUnk_030034E0 + SAVE_FIELD(0x150)); do { if (e[0] == 6 && e[1] == 0x59) count++; @@ -1280,7 +1280,7 @@ void sub_08031FF8(void) } } } - ((struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0))->flags &= ~1; + ((struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0))->flags &= ~1; sub_0800D108(); } struct Msg598 { u16 a, b; u8 data[12]; }; @@ -1430,7 +1430,7 @@ void sub_0803294C(u32 arg0) { u32 arg=arg0; u32 field; u32 dialog; - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags |= 1;} + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags |= 1;} sub_0800D0F4();sub_0802949C(arg,0); if(sub_0800CE30()) field=*(u32 *)(state3294C+0x7C); else field=*(u32 *)(state3294C+0x74); @@ -1501,7 +1501,7 @@ void sub_0803294C(u32 arg0) { while(!sub_0805EEFC((void *)dialog)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} } sub_08029788(arg); - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} sub_0800D108(); } struct Item32DE4 { u16 kind,id; u8 data[12]; }; @@ -1518,7 +1518,7 @@ extern void sub_0805990C(void); void sub_08032DE4(u32 arg0) { u8 *slot; u32 actor; u8 **itemsbase; u32 v1; u32 off; register s32 raw asm("r0"); u32 zero; u8 *selected; - {struct Player *p; register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags|=1;} + {struct Player *p; register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags|=1;} sub_0800D0F4();sub_0802949C(arg,0); if(sub_0800CE30()) {raw=(s32)(state32DE4+0x80);v1=16;raw=*(u32 *)raw;} else {raw=(s32)state32DE4;v1=16;raw=*(u32 *)(raw+0x78);} @@ -1536,15 +1536,19 @@ extern void sub_0805990C(void); void sub_08032DE4(u32 arg0) { task=sub_0805DF38(1,15,2,0,-1,0x140220); while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} if(sub_080020F4()) goto done; - count=0;i=0;raw=(s32)items32DE4;flag=0x150;item=(struct Item32DE4 *)(raw+flag); + count=0;i=0;raw=(s32)items32DE4;flag=SAVE_FIELD(0x150);item=(struct Item32DE4 *)(raw+flag); do {if(load32DE4(&item->kind)==1 && item->id==0x29)count++;item++;i++;}while(i<=24); if(count<=0)goto done; sub_08028D98(arg,0,-3,3);sub_08028D98(arg,0,3,3); actor=arg;flag=3;if(actor>0x100000) { found=find32DE4(actor); if(found) *(u16 *)(found+0x42)=flag; - } else if(arg) {actor=arg-1;if(actor<=4){u8 **base=(u8 **)&gUnk_030056F4;raw=actor*0x2E0;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} - else {raw=sub_080020F4()*0x14C;{u8 *base=(u8 *)gUnk_03003CE0;raw+=(s32)base;v1=0x11E;raw+=v1;*(u16 *)raw=flag;}} +#ifdef REGION_USA + } else if(arg) {actor=arg-1;if(actor<=4){u8 **table=(u8 **)&gUnk_030056F4;u32 eo=actor*ENEMY_SIZE;u8 *e=*table;e+=eo;sub_08019EB8(*(u16 *)(e+2),3);}} +#else + } else if(arg) {actor=arg-1;if(actor<=4){u8 **base=(u8 **)&gUnk_030056F4;raw=actor*ENEMY_SIZE;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} +#endif + else {raw=sub_080020F4()*PLAYER_SIZE;{u8 *base=(u8 *)gUnk_03003CE0;raw+=(s32)base;v1=PLAYER_FIELD(0x11E);raw+=v1;*(u16 *)raw=flag;}} sub_08068070((u32)sub_0805990C,1); while(sub_0805F184())sub_080003F0(); while(sub_0805EF90())sub_080003F0(); @@ -1552,7 +1556,7 @@ extern void sub_0805990C(void); void sub_08032DE4(u32 arg0) { while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} left=1;j=0;itemsbase=&items32DE4;zero=0; loopRemove:raw=(s32)*itemsbase;slot=(u8 *)raw+j*16; - if(*(u16 *)(slot+0x150)!=1 || *(u16 *)(slot+0x152)!=0x29 || (left--,*(u16 *)(slot+0x150)=zero,*(u16 *)(slot+0x152)=zero,left!=0)) {j++;if(j<=24)goto loopRemove;} + if(*(u16 *)(slot+SAVE_FIELD(0x150))!=1 || *(u16 *)(slot+SAVE_FIELD(0x152))!=0x29 || (left--,*(u16 *)(slot+SAVE_FIELD(0x150))=zero,*(u16 *)(slot+SAVE_FIELD(0x152))=zero,left!=0)) {j++;if(j<=24)goto loopRemove;} goto done; stateOne: while(sub_0805F184())sub_080003F0(); @@ -1572,7 +1576,7 @@ extern void sub_0805990C(void); void sub_08032DE4(u32 arg0) { task=sub_0805DF38(1,15,2,0,-1,0x14021F); while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} done: - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); } extern u8 *state33198 asm("gUnk_03005CF4"); struct Cmd33198 { u16 kind, value; u8 data[12]; }; @@ -1611,7 +1615,7 @@ void sub_08033198(void) { register u32 b asm("r2"); u32 dialog; first = sub_080020F4(); - offset = 0x14C; + offset = PLAYER_SIZE; offset *= first; start = (struct Player *)((u8 *)gUnk_03003CE0 + offset); first = start->flags; @@ -1713,7 +1717,7 @@ void sub_08033198(void) { } done: last = sub_080020F4(); - last *= 0x14C; + last *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + last); p->flags &= ~1; sub_0800D108(); @@ -1798,7 +1802,7 @@ void sub_08033650(u32 arg0) { register u32 b asm("r2"); struct Cmd33650 *c; u32 dialog; - {u32 idx; u32 v;register struct Player *p asm("r1");v=sub_080020F4();idx=0x14C;idx*=v;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);v=p->flags;one=1;p->flags=v|one;} + {u32 idx; u32 v;register struct Player *p asm("r1");v=sub_080020F4();idx=PLAYER_SIZE;idx*=v;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);v=p->flags;one=1;p->flags=v|one;} sub_0800D0F4();sub_0802949C(arg,0); arg=sub_080020F4(); if(sub_0800CE30()){base=state33650;off=0x1C6;}else{base=state33650;off=0x1BA;} @@ -1879,7 +1883,7 @@ void sub_08033650(u32 arg0) { dialog=sub_0805DF38(1,15,2,0,-1,0x140273); while(!sub_0805EEFC((void *)dialog)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} done: - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); } /* [ShowLevelDependentMessages424And425] Signed32 save+20 comparison>0xC6 selects resources1401A9/1401A8; both * completion loops have suspension escape. */ @@ -1893,7 +1897,7 @@ void sub_08033B3C(void) new_var2[1] = new_var2[0]; new_var2[1]->flags = new_var2[1]->flags | 1; sub_0800D0F4(); - if ((*((s32 *) (gUnk_030034E0 + 0x20))) > 0xC6) + if ((*((s32 *) (gUnk_030034E0 + SAVE_FIELD(0x20)))) > 0xC6) { while (sub_0805F184() != 0) { @@ -1950,7 +1954,7 @@ void sub_08033C40(u32 arg0){ u8 *data; u32 dialog; u8 *selected;u32 value; - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags|=1;} + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags|=1;} sub_0800D0F4(); if(sub_0800CE30()){base=state33C40;field=0x1BF;selected=base+field;}else{off=0x1B3;selected=state33C40+off;} switch(*selected){case 0:goto case0;case 1:goto case1;case 2:goto case2;case 3:goto case3;case 4:goto case4;case 5:goto case5;default:goto done;} @@ -2088,7 +2092,7 @@ goto done; dialog=sub_0805DF38(1,15,2,0,-1,0x1401C5); while(!sub_0805EEFC((void *)dialog)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} done: - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); } extern void sub_08029174(s32,s32); extern void sub_0802926C(s32,s32); @@ -2410,13 +2414,13 @@ void sub_08034900(void) { value |= highValue; frame.bits = value; } - { u32 index = sub_080020F4(); u32 stride = 0x14c; struct Player *base; stride*=index; base=gUnk_03003CE0; temp_r5=(struct Player *)(stride + (u32)base); } + { u32 index = sub_080020F4(); u32 stride = PLAYER_SIZE; struct Player *base; stride*=index; base=gUnk_03003CE0; temp_r5=(struct Player *)(stride + (u32)base); } bits=&frame.bits; goto test3; loop_3: sub_080003F0(); test3: - if (t034Range((s32 *)((u8 *)temp_r5 + 0x8C), &frame.pos.x, (u16 *)ptr10, (u16 *)bits) == 0) { + if (t034Range((s32 *)((u8 *)temp_r5 + PLAYER_FIELD(0x8C)), &frame.pos.x, (u16 *)ptr10, (u16 *)bits) == 0) { goto loop_3; } if (sub_0800CE30() != 0) { @@ -2881,7 +2885,7 @@ void sub_08035A88(s32 arg0) { } } struct Cmd35B18 { u16 unk0, unk2; u8 data[12]; }; -struct Inv35B18 { u8 pad[0x150]; u16 unk150, unk152; }; +struct Inv35B18 { u8 pad[SAVE_FIELD(0x150)]; u16 unk150, unk152; }; extern u8 *inv35B18 asm("gUnk_030034E0"); extern u8 *state35B18 asm("gUnk_03005CF4"); extern u32 flags35B18 asm("gUnk_030027D0"); @@ -3017,7 +3021,7 @@ while (sub_0805EF90() != 0) { sub_080003F0(); } while (sub_0805EEFC((void *) temp_r4_3) == 0) { if (sub_0800CDF8() != 0) { sub_0805EFBC(); break; } sub_080003F0(); } var_r3 = 0; var_r2 = 0; - var_r1_2 = (struct Cmd35B18 *)(inv35B18 + 0x150); + var_r1_2 = (struct Cmd35B18 *)(inv35B18 + SAVE_FIELD(0x150)); do { if ((*(u16 *)var_r1_2 == 8) && (*(u16 *)((u8 *)var_r1_2 + 2) == 6)) { var_r3 += 1; @@ -3037,9 +3041,9 @@ while (sub_0805EEFC((void *) temp_r4_4) == 0) { sub_080003F0(); } left=3;scan=0;data=sp8.data;inventory=&inv35B18;zero=0; do { u8 *slot; register u8 *v asm("r0"); u32 k; u16 *kind; - v=*inventory;slot=v+scan*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+scan*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=8)goto next1; - { u16 *value; k=0x152;value=(u16 *)(slot+k);if(*value!=6)goto next1;left--;*kind=zero;*value=zero;if(!left)goto removed1; } + { u16 *value; k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=6)goto next1;left--;*kind=zero;*value=zero;if(!left)goto removed1; } next1: scan++; }while(scan<=24); removed1: @@ -3071,7 +3075,7 @@ while (sub_0805EF90() != 0) { sub_080003F0(); } while (sub_0805EEFC((void *) temp_r4_7) == 0) { if (sub_0800CDF8() != 0) { sub_0805EFBC(); break; } sub_080003F0(); } var_r3_3 = 0; var_r2_2 = 0; - var_r1_4 = (struct Cmd35B18 *)(inv35B18 + 0x150); + var_r1_4 = (struct Cmd35B18 *)(inv35B18 + SAVE_FIELD(0x150)); do { if ((*(u16 *)var_r1_4 == 8) && (*(u16 *)((u8 *)var_r1_4 + 2) == 0x23)) { var_r3_3 += 1; @@ -3091,9 +3095,9 @@ while (sub_0805EEFC((void *) temp_r4_8) == 0) { sub_080003F0(); } left=3;scan=0;data=sp8.data;inventory=&inv35B18;zero=0; do { u8 *slot; register u8 *v asm("r0"); u32 k; u16 *kind; - v=*inventory;slot=v+scan*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+scan*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=8)goto next2; - { u16 *value; k=0x152;value=(u16 *)(slot+k);if(*value!=0x23)goto next2;left--;*kind=zero;*value=zero;if(!left)goto removed2; } + { u16 *value; k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x23)goto next2;left--;*kind=zero;*value=zero;if(!left)goto removed2; } next2: scan++; }while(scan<=24); removed2: @@ -3125,7 +3129,7 @@ while (sub_0805EF90() != 0) { sub_080003F0(); } while (sub_0805EEFC((void *) temp_r4_11) == 0) { if (sub_0800CDF8() != 0) { sub_0805EFBC(); break; } sub_080003F0(); } var_r3_5 = 0; var_r2_3 = 0; - var_r1_6 = (struct Cmd35B18 *)(inv35B18 + 0x150); + var_r1_6 = (struct Cmd35B18 *)(inv35B18 + SAVE_FIELD(0x150)); do { if ((*(u16 *)var_r1_6 == 8) && (*(u16 *)((u8 *)var_r1_6 + 2) == 0x41)) { var_r3_5 += 1; @@ -3145,9 +3149,9 @@ while (sub_0805EEFC((void *) temp_r4_12) == 0) { sub_080003F0(); } left=3;scan=0;data=sp8.data;inventory=&inv35B18;zero=0; do { u8 *slot; register u8 *v asm("r0"); u32 k; u16 *kind; - v=*inventory;slot=v+scan*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+scan*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=8)goto next3; - { u16 *value; k=0x152;value=(u16 *)(slot+k);if(*value!=0x41)goto next3;left--;*kind=zero;*value=zero;if(!left)goto removed3; } + { u16 *value; k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x41)goto next3;left--;*kind=zero;*value=zero;if(!left)goto removed3; } next3: scan++; }while(scan<=24); removed3: @@ -3179,7 +3183,7 @@ while (sub_0805EF90() != 0) { sub_080003F0(); } while (sub_0805EEFC((void *) temp_r4_15) == 0) { if (sub_0800CDF8() != 0) { sub_0805EFBC(); break; } sub_080003F0(); } var_r3_7 = 0; var_r2_4 = 0; - var_r1_8 = (struct Cmd35B18 *)(inv35B18 + 0x150); + var_r1_8 = (struct Cmd35B18 *)(inv35B18 + SAVE_FIELD(0x150)); do { if ((*(u16 *)var_r1_8 == 8) && (*(u16 *)((u8 *)var_r1_8 + 2) == 0x59)) { var_r3_7 += 1; @@ -3199,9 +3203,9 @@ while (sub_0805EEFC((void *) temp_r4_16) == 0) { sub_080003F0(); } left=3;scan=0;data=sp8.data;inventory=&inv35B18;asm("" : "+r"(inventory));zero=0; do { u8 *slot; register u8 *v asm("r0"); u32 k; u16 *kind; - v=*inventory;slot=v+scan*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+scan*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=8)goto next4; - { u16 *value; k=0x152;value=(u16 *)(slot+k);if(*value!=0x59)goto next4;left--;*kind=zero;*value=zero;if(!left)goto removed4; } + { u16 *value; k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x59)goto next4;left--;*kind=zero;*value=zero;if(!left)goto removed4; } next4: scan++; }while(scan<=24); removed4: @@ -3233,7 +3237,7 @@ while (sub_0805EF90() != 0) { sub_080003F0(); } while (sub_0805EEFC((void *) temp_r4_19) == 0) { if (sub_0800CDF8() != 0) { sub_0805EFBC(); break; } sub_080003F0(); } var_r3_9 = 0; var_r2_5 = 0; - var_r1_10 = (struct Cmd35B18 *)(inv35B18 + 0x150); + var_r1_10 = (struct Cmd35B18 *)(inv35B18 + SAVE_FIELD(0x150)); do { if ((*(u16 *)var_r1_10 == 8) && (*(u16 *)((u8 *)var_r1_10 + 2) == 0x6F)) { var_r3_9 += 1; @@ -3251,9 +3255,9 @@ while (sub_0805EEFC((void *) temp_r4_21) == 0) { sub_080003F0(); } left=3;scan=0;data=sp8.data;inventory=&inv35B18;zero=0; do { u8 *slot; register u8 *v asm("r0"); u32 k; u16 *kind; - v=*inventory;slot=v+scan*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+scan*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=8)goto next5; - { u16 *value; k=0x152;value=(u16 *)(slot+k);if(*value!=0x6F)goto next5;left--;*kind=zero;*value=zero;if(!left)goto removed5; } + { u16 *value; k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x6F)goto next5;left--;*kind=zero;*value=zero;if(!left)goto removed5; } next5: scan++; }while(scan<=24); removed5: @@ -3323,7 +3327,7 @@ while (sub_0805EEFC((void *) temp_r4_28) == 0) { if (sub_0800CDF8() != 0) { sub_ sub_0800D108(); } struct Cmd368F4 { u16 unk0, unk2; u8 data[12]; }; -struct Inv368F4 { u8 pad[0x150]; u16 unk150, unk152; }; +struct Inv368F4 { u8 pad[SAVE_FIELD(0x150)]; u16 unk150, unk152; }; extern u8 *inv368F4 asm("gUnk_030034E0"); extern u8 *state368F4 asm("gUnk_03005CF4"); extern u32 flags368F4 asm("gUnk_030027D0"); @@ -3460,7 +3464,7 @@ while (sub_0805EF90() != 0) { sub_080003F0(); } while (sub_0805EEFC((void *) temp_r4_3) == 0) { if (sub_0800CDF8() != 0) { sub_0805EFBC(); break; } sub_080003F0(); } var_r3 = 0; var_r2 = 0; - var_r1_2 = (struct Cmd368F4 *)(inv368F4 + 0x150); + var_r1_2 = (struct Cmd368F4 *)(inv368F4 + SAVE_FIELD(0x150)); do { if ((*(u16 *)var_r1_2 == 8) && (*(u16 *)((u8 *)var_r1_2 + 2) == 0)) { var_r3 += 1; @@ -3480,9 +3484,9 @@ while (sub_0805EEFC((void *) temp_r4_4) == 0) { sub_080003F0(); } left=3;scan=0;data=sp8.data;inventoryFirst=&inv368F4; do { u8 *slot; register u8 *v asm("r0"); u32 k; u16 *kind; - v=*inventoryFirst;slot=v+scan*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventoryFirst;slot=v+scan*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=8)goto next1; - { register u16 *value asm("r1"); k=0x152;value=(u16 *)(slot+k);k=*value;if(k!=0)goto next1;left--;*kind=k;*value=k;if(!left)goto removed1; } + { register u16 *value asm("r1"); k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);k=*value;if(k!=0)goto next1;left--;*kind=k;*value=k;if(!left)goto removed1; } next1: scan++; }while(scan<=24); removed1: @@ -3514,7 +3518,7 @@ while (sub_0805EF90() != 0) { sub_080003F0(); } while (sub_0805EEFC((void *) temp_r4_7) == 0) { if (sub_0800CDF8() != 0) { sub_0805EFBC(); break; } sub_080003F0(); } var_r3_3 = 0; var_r2_2 = 0; - var_r1_4 = (struct Cmd368F4 *)(inv368F4 + 0x150); + var_r1_4 = (struct Cmd368F4 *)(inv368F4 + SAVE_FIELD(0x150)); do { if ((*(u16 *)var_r1_4 == 8) && (*(u16 *)((u8 *)var_r1_4 + 2) == 0x2B)) { var_r3_3 += 1; @@ -3534,9 +3538,9 @@ while (sub_0805EEFC((void *) temp_r4_8) == 0) { sub_080003F0(); } left=3;scan=0;data=sp8.data;inventory=&inv368F4;zero=0; do { u8 *slot; register u8 *v asm("r0"); u32 k; u16 *kind; - v=*inventory;slot=v+scan*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+scan*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=8)goto next2; - { u16 *value; k=0x152;value=(u16 *)(slot+k);if(*value!=0x2B)goto next2;left--;*kind=zero;*value=zero;if(!left)goto removed2; } + { u16 *value; k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x2B)goto next2;left--;*kind=zero;*value=zero;if(!left)goto removed2; } next2: scan++; }while(scan<=24); removed2: @@ -3568,7 +3572,7 @@ while (sub_0805EF90() != 0) { sub_080003F0(); } while (sub_0805EEFC((void *) temp_r4_11) == 0) { if (sub_0800CDF8() != 0) { sub_0805EFBC(); break; } sub_080003F0(); } var_r3_5 = 0; var_r2_3 = 0; - var_r1_6 = (struct Cmd368F4 *)(inv368F4 + 0x150); + var_r1_6 = (struct Cmd368F4 *)(inv368F4 + SAVE_FIELD(0x150)); do { if ((*(u16 *)var_r1_6 == 8) && (*(u16 *)((u8 *)var_r1_6 + 2) == 0x50)) { var_r3_5 += 1; @@ -3588,9 +3592,9 @@ while (sub_0805EEFC((void *) temp_r4_12) == 0) { sub_080003F0(); } left=3;scan=0;data=sp8.data;inventory=&inv368F4;zero=0; do { u8 *slot; register u8 *v asm("r0"); u32 k; u16 *kind; - v=*inventory;slot=v+scan*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+scan*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=8)goto next3; - { u16 *value; k=0x152;value=(u16 *)(slot+k);if(*value!=0x50)goto next3;left--;*kind=zero;*value=zero;if(!left)goto removed3; } + { u16 *value; k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x50)goto next3;left--;*kind=zero;*value=zero;if(!left)goto removed3; } next3: scan++; }while(scan<=24); removed3: @@ -3622,7 +3626,7 @@ while (sub_0805EF90() != 0) { sub_080003F0(); } while (sub_0805EEFC((void *) temp_r4_15) == 0) { if (sub_0800CDF8() != 0) { sub_0805EFBC(); break; } sub_080003F0(); } var_r3_7 = 0; var_r2_4 = 0; - var_r1_8 = (struct Cmd368F4 *)(inv368F4 + 0x150); + var_r1_8 = (struct Cmd368F4 *)(inv368F4 + SAVE_FIELD(0x150)); do { if ((*(u16 *)var_r1_8 == 8) && (*(u16 *)((u8 *)var_r1_8 + 2) == 0x5C)) { var_r3_7 += 1; @@ -3642,9 +3646,9 @@ while (sub_0805EEFC((void *) temp_r4_16) == 0) { sub_080003F0(); } left=3;scan=0;data=sp8.data;inventory=&inv368F4;zero=0; do { u8 *slot; register u8 *v asm("r0"); u32 k; u16 *kind; - v=*inventory;slot=v+scan*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+scan*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=8)goto next4; - { u16 *value; k=0x152;value=(u16 *)(slot+k);if(*value!=0x5C)goto next4;left--;*kind=zero;*value=zero;if(!left)goto removed4; } + { u16 *value; k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x5C)goto next4;left--;*kind=zero;*value=zero;if(!left)goto removed4; } next4: scan++; }while(scan<=24); removed4: @@ -3676,7 +3680,7 @@ while (sub_0805EF90() != 0) { sub_080003F0(); } while (sub_0805EEFC((void *) temp_r4_19) == 0) { if (sub_0800CDF8() != 0) { sub_0805EFBC(); break; } sub_080003F0(); } var_r3_9 = 0; var_r2_5 = 0; - var_r1_10 = (struct Cmd368F4 *)(inv368F4 + 0x150); + var_r1_10 = (struct Cmd368F4 *)(inv368F4 + SAVE_FIELD(0x150)); do { if ((*(u16 *)var_r1_10 == 8) && (*(u16 *)((u8 *)var_r1_10 + 2) == 0x65)) { var_r3_9 += 1; @@ -3694,9 +3698,9 @@ while (sub_0805EEFC((void *) temp_r4_21) == 0) { sub_080003F0(); } left=3;scan=0;data=sp8.data;inventory=&inv368F4;asm("" : "+r"(inventory));zero=0; do { u8 *slot; register u8 *v asm("r0"); u32 k; u16 *kind; - v=*inventory;slot=v+scan*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+scan*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=8)goto next5; - { u16 *value; k=0x152;value=(u16 *)(slot+k);if(*value!=0x65)goto next5;left--;*kind=zero;*value=zero;if(!left)goto removed5; } + { u16 *value; k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x65)goto next5;left--;*kind=zero;*value=zero;if(!left)goto removed5; } next5: scan++; }while(scan<=24); removed5: @@ -3778,7 +3782,7 @@ static inline u32 t36ATest(u8 *p, u32 one) { s32 v = *p; return (v >> 7) & one; static inline u32 t36AHalf(u16 *p) { u32 v = *p; return v; } static inline void t36AInit(struct T36ACmd *pp, u32 aa, u32 bb) { register struct T36ACmd *p asm("r0"); register u32 a asm("r1")=aa; u32 b=bb; asm("" : "+r"(a), "+r"(b)); p=pp; p->unk0=a; p->unk2=b; } static inline u32 t36ALock(u32 idx) { - u32 off = idx * 0x14C; + u32 off = idx * PLAYER_SIZE; u32 base; struct Player *p; u32 flags; @@ -3797,8 +3801,8 @@ static inline u32 t36ALock(u32 idx) { static inline u32 t36AMask(u32 *p) { register u32 m asm("r1")=0x100000; return *p & m; } static inline void t36ASet80(void) { register u32 *p asm("r1")=(u32 *)(t36AState+0x80); u32 m=0x100000; *p |= m; } static inline void t36ASet78(void) { u8 *p=t36AState; u32 m=0x100000; *(u32 *)(p+0x78) |= m; } -static inline void t36APose(u32 idx, u32 value) { u32 scaled=idx*0x14C; u8 *p; u32 off; p=(u8 *)gUnk_03003CE0+scaled; off=0x11E; *(u16 *)(p+off)=value; } -static inline void t36AOtherPose(u32 idx) { u8 **pp=&t36AOther; u32 off; u8 *p; off=idx*0x2E0; p=*pp; p=p+off; sub_08019EB8(*(u16 *)(p+2), 3); } +static inline void t36APose(u32 idx, u32 value) { u32 scaled=idx*PLAYER_SIZE; u8 *p; u32 off; p=(u8 *)gUnk_03003CE0+scaled; off=PLAYER_FIELD(0x11E); *(u16 *)(p+off)=value; } +static inline void t36AOtherPose(u32 idx) { u8 **pp=&t36AOther; u32 off; u8 *p; off=idx*ENEMY_SIZE; p=*pp; p=p+off; sub_08019EB8(*(u16 *)(p+2), 3); } static inline u32 t36ACount(u32 n) { return n; } static inline void t36AEmitMany(struct T36ACmd *p,u32 n) { u32 i=0; do { t36AEmit(p); i++; } while (iunk0) == 1) && (var_r1->unk2 == 0x2D)) { var_r3 += 1; @@ -3931,7 +3939,7 @@ void t36AScript(u32 input) { zero = 0; loop_57: temp_r1_2 = t36AItemAddr(*inventory, var_r3_3); - if (((*(u16 *)(temp_r1_2 + 0x150)) != 1) || ((*(u16 *)(temp_r1_2 + 0x152)) != 0x2D) || (var_r4 -= 1, (*(u16 *)(temp_r1_2 + 0x150)) = zero, (*(u16 *)(temp_r1_2 + 0x152)) = zero, (var_r4 != 0))) { + if (((*(u16 *)(temp_r1_2 + SAVE_FIELD(0x150))) != 1) || ((*(u16 *)(temp_r1_2 + SAVE_FIELD(0x152))) != 0x2D) || (var_r4 -= 1, (*(u16 *)(temp_r1_2 + SAVE_FIELD(0x150))) = zero, (*(u16 *)(temp_r1_2 + SAVE_FIELD(0x152))) = zero, (var_r4 != 0))) { var_r3_3 += 1; if (var_r3_3 <= 0x18U) { goto loop_57; @@ -3992,7 +4000,7 @@ void t36AScript(u32 input) { } -struct T36Player { u8 pad0[0x20]; u16 unk20; u8 pad22[14]; u32 unk30; u8 pad34[0x118]; }; +struct T36Player { u8 pad0[PLAYER_FIELD(0x20)]; u16 unk20; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 unk30; u8 pad34[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; struct T36Task { u32 f0, f4, unk8, unkC; u8 *unk10; u32 f14, f18, f1c; u8 *unk20; u32 unk24; }; struct T36Actor { s32 id; u8 pad4[0x40]; u32 unk44; u8 pad48[0x28]; }; extern struct T36Player t36Players[] asm("gUnk_03003CE0"); @@ -4215,7 +4223,7 @@ static inline u32 t36CTest6(u8 *p) { register s32 v asm("r0")=*p; s32 shifted; u static inline u32 t36CAvailable(void) { s32 v=sub_0805CFA0(); register u32 ok asm("r1")=1; if(v<0)ok=0; return ok; } static inline u32 t36CCount(u32 n) { return n; } static inline void t36CInit(struct T36CCmd *pp,u32 aa,u32 bb) { struct T36CCmd *p; register u32 a asm("r1")=aa; u32 b=bb; asm("" : "+r"(a), "+r"(b)); p=pp; p->unk0=a; p->unk2=b; } -static inline u8 *t36CInvBase(u8 *base) { register u8 *p asm("r0")=base; u32 off; off=0xC10; return p+off; } +static inline u8 *t36CInvBase(u8 *base) { register u8 *p asm("r0")=base; u32 off; off=SAVE_FIELD(0xC10); return p+off; } /* [HandleFullMarkerSetReward] Sets player flag1 and faces entity; tests145 saved marker bytes, mode-selected * completion bits and local player index. Host with all markers and no completion bit shows113 then, if * capacity helper succeeds, attempts inventory insertion of descriptor6:0x1E, requests callback5990C(0x26), @@ -4535,7 +4543,7 @@ void sub_0803898C(s32 arg) { register u32 last asm("r2"); struct Player *p; u32 dialog; - first=sub_080020F4(); offset=0x14C; offset*=first; + first=sub_080020F4(); offset=PLAYER_SIZE; offset*=first; start=(struct Player *)((u8 *)gUnk_03003CE0+offset); first=start->flags; one=1; first|=one; start->flags=first; sub_0800D0F4(); sub_0802949C(arg,0); @@ -4615,7 +4623,7 @@ void sub_0803898C(s32 arg) { } done: sub_08029788(arg); - last=sub_080020F4(); last*=0x14C; + last=sub_080020F4(); last*=PLAYER_SIZE; p=(struct Player *)((u8 *)gUnk_03003CE0+last); p->flags &= ~1; sub_0800D108(); } @@ -4643,21 +4651,25 @@ void sub_08038D18(u32 arg){ register u8 *data asm("r6");u32 left;u32 j;u8 **inventory;u32 zero; u32 a;register u32 b asm("r2");struct Cmd38D18 *c;u32 n; u32 dialog; - raw=sub_080020F4();offset=0x14C;offset*=raw;p=(struct Player *)((u8 *)gUnk_03003CE0+offset);raw=p->flags;one=1;raw|=one;p->flags=raw; + raw=sub_080020F4();offset=PLAYER_SIZE;offset*=raw;p=(struct Player *)((u8 *)gUnk_03003CE0+offset);raw=p->flags;one=1;raw|=one;p->flags=raw; sub_0800D0F4(); if(sub_0800CE30()){raw=(s32)state38D18;off1=0x1C4;selected=(u8 *)raw+off1;}else{raw=(s32)state38D18;off3=0x1B8;selected=(u8 *)raw+off3;} raw=*selected;raw>>=5;raw&=one;if(raw)goto progressed; while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0(); dialog=sub_0805DF38(1,15,2,0,-1,0x14022C); while(!sub_0805EEFC((void *)dialog)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} - count=0;i=0;{u8 *v;v=items38D18;one=0x150;item=v+one;} + count=0;i=0;{u8 *v;v=items38D18;one=SAVE_FIELD(0x150);item=v+one;} do{if(*(u16 *)item==1 && *(u16 *)(item+2)==0x2A)count++;item+=16;i++;}while(i<=24); if(count<=0)goto done; if(sub_080020F4())goto other; actor=arg;flag=3; if(actor>0x100000){found=find38D18(actor);if(found)*(u16 *)(found+0x42)=flag;} - else if(arg){actor=arg-1;if(actor<=4){register u8 **base asm("r1")=(u8 **)&gUnk_030056F4;raw=actor*0x2E0;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} - else{raw=sub_080020F4()*0x14C;{register u8 *base asm("r1")=(u8 *)gUnk_03003CE0;raw+=(s32)base;off1=0x11E;raw+=off1;*(u16 *)raw=flag;}} +#ifdef REGION_USA + else if(arg){actor=arg-1;if(actor<=4){u8 **table=(u8 **)&gUnk_030056F4;u32 eo=actor*ENEMY_SIZE;u8 *e=*table;e+=eo;sub_08019EB8(*(u16 *)(e+2),3);}} +#else + else if(arg){actor=arg-1;if(actor<=4){register u8 **base asm("r1")=(u8 **)&gUnk_030056F4;raw=actor*ENEMY_SIZE;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} +#endif + else{raw=sub_080020F4()*PLAYER_SIZE;{register u8 *base asm("r1")=(u8 *)gUnk_03003CE0;raw+=(s32)base;off1=PLAYER_FIELD(0x11E);raw+=off1;*(u16 *)raw=flag;}} data=cmd.data; while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0(); dialog=sub_0805DF38(1,15,2,0,-1,0x14022D); @@ -4665,9 +4677,9 @@ void sub_08038D18(u32 arg){ left=1;j=0;inventory=&items38D18;zero=0; do{ u8 *slot;register u8 *v asm("r0");u32 k;u16 *kind; - v=*inventory;slot=v+j*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+j*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=1)goto next; - {u16 *value;k=0x152;value=(u16 *)(slot+k);if(*value!=0x2A)goto next;left--;*kind=zero;*value=zero;if(!left)goto removed;} + {u16 *value;k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x2A)goto next;left--;*kind=zero;*value=zero;if(!left)goto removed;} next:j++; }while(j<=24); removed: @@ -4721,7 +4733,7 @@ next:j++; dialog=sub_0805DF38(1,15,2,0,-1,0x140230); while(!sub_0805EEFC((void *)dialog)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} done: - {struct Player *v;register u32 index asm("r2");index=sub_080020F4();index*=0x14C;v=(struct Player *)((u8 *)gUnk_03003CE0+index);v->flags &=~1;}sub_0800D108(); + {struct Player *v;register u32 index asm("r2");index=sub_080020F4();index*=PLAYER_SIZE;v=(struct Player *)((u8 *)gUnk_03003CE0+index);v->flags &=~1;}sub_0800D108(); } extern u8 *state392B4 asm("gUnk_03005CF4"); @@ -4746,7 +4758,7 @@ void sub_080392B4(u32 arg){ register s16 *data asm("r6");s16 *out;u32 value;register u32 kind asm("r6");u32 sends;register u32 left asm("r4");u32 j;u8 **inventory;register u32 zero asm("r5"); u32 a;u32 b;struct Cmd392B4 *c;u32 n; u8 **inventoryFirst;u32 dialog;u32 callback; - {struct Player *v;register u32 index asm("r2");index=sub_080020F4();index*=0x14C;v=(struct Player *)((u8 *)gUnk_03003CE0+index);v->flags |=1;} + {struct Player *v;register u32 index asm("r2");index=sub_080020F4();index*=PLAYER_SIZE;v=(struct Player *)((u8 *)gUnk_03003CE0+index);v->flags |=1;} sub_0800D0F4();sub_0802949C(arg,0); if(sub_0800CE30()){raw=(s32)state392B4;raw+=0x80;off1=8;raw=*(u32 *)raw;}else{raw=(s32)state392B4;off1=8;raw=*(u32 *)(raw+0x78);}raw &=off1;if(raw)goto enabled; while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0(); @@ -4759,14 +4771,18 @@ void sub_080392B4(u32 arg){ while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0(); dialog=sub_0805DF38(1,15,2,0,-1,0x140264); while(!sub_0805EEFC((void *)dialog)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} - count=0;i=0;{u8 *v;v=items392B4;one=0x150;item=v+one;} + count=0;i=0;{u8 *v;v=items392B4;one=SAVE_FIELD(0x150);item=v+one;} do{if(*(u16 *)item==1 && *(u16 *)(item+2)==0x2F)count++;item+=16;i++;}while(i<=24); if(count<=0)goto done; if(sub_080020F4())goto other; actor=arg;flag=3; if(actor>0x100000){found=find392B4(actor);if(found)*(u16 *)(found+0x42)=flag;} - else if(arg){actor=arg-1;if(actor<=4){register u8 **base asm("r1")=(u8 **)&gUnk_030056F4;raw=actor*0x2E0;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} - else{raw=sub_080020F4()*0x14C;{register u8 *base asm("r1")=(u8 *)gUnk_03003CE0;raw+=(s32)base;off1=0x11E;raw+=off1;*(u16 *)raw=flag;}} +#ifdef REGION_USA + else if(arg){actor=arg-1;if(actor<=4){u8 **table=(u8 **)&gUnk_030056F4;u32 eo=actor*ENEMY_SIZE;u8 *e=*table;e+=eo;sub_08019EB8(*(u16 *)(e+2),3);}} +#else + else if(arg){actor=arg-1;if(actor<=4){register u8 **base asm("r1")=(u8 **)&gUnk_030056F4;raw=actor*ENEMY_SIZE;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} +#endif + else{raw=sub_080020F4()*PLAYER_SIZE;{register u8 *base asm("r1")=(u8 *)gUnk_03003CE0;raw+=(s32)base;off1=PLAYER_FIELD(0x11E);raw+=off1;*(u16 *)raw=flag;}} while(sub_0805F184())sub_080003F0();dialog=sub_0805DF38(1,15,2,0,-2,0x140265); while(!sub_0805EEFC((void *)dialog))sub_080003F0();flag=sub_0805EF14((u8 *)dialog);if(!flag)goto rejected; @@ -4777,9 +4793,9 @@ void sub_080392B4(u32 arg){ inventoryFirst=&items392B4;zero=0; do{ u8 *slot;register u8 *v asm("r0");u32 k;u16 *kind; - v=*inventoryFirst;slot=v+j*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventoryFirst;slot=v+j*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=1)goto next; - {u16 *value;k=0x152;value=(u16 *)(slot+k);if(*value!=0x2F)goto next;left--;*kind=zero;*value=zero;if(!left)goto removed;} + {u16 *value;k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x2F)goto next;left--;*kind=zero;*value=zero;if(!left)goto removed;} next:j++; }while(j<=24); removed: sub_08068070(callback,4);goto done; @@ -4792,9 +4808,9 @@ removed: sub_08068070(callback,4);goto done; left=1;j=0;inventory=&items392B4;zero=0; do{ u8 *slot;register u8 *v asm("r0");u32 k;u16 *kind; - v=*inventory;slot=v+j*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+j*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=1)goto nextA; - {u16 *value;k=0x152;value=(u16 *)(slot+k);if(*value!=0x2F)goto nextA;left--;*kind=zero;*value=zero;if(!left)goto removedA;} + {u16 *value;k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x2F)goto nextA;left--;*kind=zero;*value=zero;if(!left)goto removedA;} nextA:j++; }while(j<=24); removedA: value=3000;sends=0;out=data;kind=10; @@ -4808,9 +4824,9 @@ removedA: value=3000;sends=0;out=data;kind=10; left=1;j=0;inventory=&items392B4;zero=0; do{ u8 *slot;register u8 *v asm("r0");u32 k;u16 *kind; - v=*inventory;slot=v+j*16;k=0x150;kind=(u16 *)(slot+k); + v=*inventory;slot=v+j*16;k=SAVE_FIELD(0x150);kind=(u16 *)(slot+k); if(*kind!=1)goto nextB; - {u16 *value;k=0x152;value=(u16 *)(slot+k);if(*value!=0x2F)goto nextB;left--;*kind=zero;*value=zero;if(!left)goto removedB;} + {u16 *value;k=SAVE_FIELD(0x152);value=(u16 *)(slot+k);if(*value!=0x2F)goto nextB;left--;*kind=zero;*value=zero;if(!left)goto removedB;} nextB:j++; }while(j<=24); removedB: value=10000;sends=0;out=data;kind=10; @@ -4852,7 +4868,7 @@ removedB: value=10000;sends=0;out=data;kind=10; dialog=sub_0805DF38(1,15,2,0,-1,0x140263); while(!sub_0805EEFC((void *)dialog)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} done: - {struct Player *v;register u32 index asm("r2");index=sub_080020F4();index*=0x14C;v=(struct Player *)((u8 *)gUnk_03003CE0+index);v->flags &=~1;}sub_0800D108(); + {struct Player *v;register u32 index asm("r2");index=sub_080020F4();index*=PLAYER_SIZE;v=(struct Player *)((u8 *)gUnk_03003CE0+index);v->flags &=~1;}sub_0800D108(); } extern u8 *state399E4 asm("gUnk_03005CF4"); /* [RunGalicDialogue] Sets local player flags bit 0 (input suppression), calls BeginLocalPlayerEventLock and @@ -4867,7 +4883,7 @@ void sub_080399E4(u32 arg0) { u32 off; register s32 flag asm("r1"); u32 dialog; - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags |= 1;} + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags |= 1;} sub_0800D0F4();sub_0802949C(arg,0); if(sub_0800CE30()) field=*(u32 *)(state399E4+0x7C); else field=*(u32 *)(state399E4+0x74); @@ -4946,7 +4962,7 @@ void sub_080399E4(u32 arg0) { while(!sub_0805EEFC((void *)dialog)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} } sub_08029788(arg); - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} sub_0800D108(); } extern u8 *state39F00 asm("gUnk_03005CF4"); @@ -4980,14 +4996,14 @@ void sub_08039F00(s32 arg) { u32 a; register u32 b asm("r2"); struct Cmd39F00 *c; u32 dialog; - {struct Player *p; register u32 index asm("r2"); index=sub_080020F4();index*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+index);p->flags |=1;} + {struct Player *p; register u32 index asm("r2"); index=sub_080020F4();index*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+index);p->flags |=1;} sub_0800D0F4(); sub_08028AAC(arg,0x6F,0xDD,0);sub_0802949C(arg,0); player=sub_080020F4(); if(sub_0800CE30()){base=state39F00;off=0x1BD;}else{base=state39F00;off=0x1B1;} {register u32 v asm("r0");v=base[off];asm("" : "+r"(v));total=v;} if(total>9) goto complete; if(player) goto other; - count=0;idx=0;{u8 *v;u32 n;v=inv39F00;n=0x150;item=v+n;} + count=0;idx=0;{u8 *v;u32 n;v=inv39F00;n=SAVE_FIELD(0x150);item=v+n;} do {if(*(u16 *)item==1 && *(u16 *)(item+2)==0x2E) count++;item+=16;idx++;}while(idx<=24); saved=count; if(saved<=0) goto missing; while(sub_0805F184())sub_080003F0(); @@ -5002,9 +5018,9 @@ void sub_08039F00(s32 arg) { left=saved;scan=0;inventory=&inv39F00;zero=0; do { u8 *slot;u8 *v;u32 n;u16 *kind; - v=*inventory;slot=v+scan*16;n=0x150;kind=(u16 *)(slot+n); + v=*inventory;slot=v+scan*16;n=SAVE_FIELD(0x150);kind=(u16 *)(slot+n); if(*kind!=1)goto next; - {u16 *value;n=0x152;value=(u16 *)(slot+n);if(*value!=0x2E)goto next;left--;*kind=zero;*value=zero;if(left==0)goto removed;} + {u16 *value;n=SAVE_FIELD(0x152);value=(u16 *)(slot+n);if(*value!=0x2E)goto next;left--;*kind=zero;*value=zero;if(left==0)goto removed;} next: scan++; }while(scan<=24); removed: @@ -5038,7 +5054,7 @@ next: scan++; dialog=sub_0805DF38(1,15,2,0,-1,0x140260); while(!sub_0805EEFC((void *)dialog)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} rewardDone: - {struct Player *p; register u32 index asm("r2"); index=sub_080020F4();index*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+index);p->flags &=~1;} + {struct Player *p; register u32 index asm("r2"); index=sub_080020F4();index*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+index);p->flags &=~1;} sub_0800D108(); goto end; rejected: @@ -5078,7 +5094,7 @@ rejectedYield: sub_080003F0(); while(!sub_0805EEFC((void *)dialog)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} } done: - {struct Player *p; register u32 index asm("r2"); index=sub_080020F4();index*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+index);p->flags &=~1;} + {struct Player *p; register u32 index asm("r2"); index=sub_080020F4();index*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+index);p->flags &=~1;} sub_0800D108(); end:; } @@ -5090,9 +5106,9 @@ void sub_0803A460(s32 arg0) { u8 *p; u32 flags; u32 msg; - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)|=1; + *(u32 *)(p+PLAYER_FIELD(0x30))|=1; sub_0800D0F4(); sub_0802949C(arg0,0); if(sub_0800CE30()) flags=*(u32 *)((u8 *)gUnk_03005CF4+0x7C); @@ -5186,9 +5202,9 @@ void sub_0803A460(s32 arg0) { sub_080003F0(); } } - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)&=~1; + *(u32 *)(p+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); } /* [ShowCompletionDialogs293] Locks local player/input and displays one cancellable message140125..14012F @@ -5199,9 +5215,9 @@ void sub_0803A8F0(void) { u8 *p; u32 flags; u32 msg; - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)|=1; + *(u32 *)(p+PLAYER_FIELD(0x30))|=1; sub_0800D0F4(); if(sub_0800CE30()) flags=*(u32 *)((u8 *)gUnk_03005CF4+0x7C); else flags=*(u32 *)((u8 *)gUnk_03005CF4+0x74); @@ -5294,9 +5310,9 @@ void sub_0803A8F0(void) { sub_080003F0(); } } - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)&=~1; + *(u32 *)(p+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); } /* [RunSceneMessages290And291] Begins local-player event/input lock and waits for free dialogue/text slots. */ @@ -5305,9 +5321,9 @@ void sub_0803AD74(void) { u32 msg; register u32 offset asm("r2"); offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (u8 *)gUnk_03003CE0 + offset; - *(u32 *)(p + 0x30) |= 1; + *(u32 *)(p + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184() != 0) sub_080003F0(); while (sub_0805EF90() != 0) sub_080003F0(); @@ -5330,9 +5346,9 @@ void sub_0803AD74(void) { sub_080003F0(); } offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (u8 *)gUnk_03003CE0 + offset; - *(u32 *)(p + 0x30) &= ~1; + *(u32 *)(p + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } static inline u32 t38_getAE6C(u32 mask) { @@ -5352,7 +5368,11 @@ static inline u8 *t38_findAE6C(u32 arg) { } static inline void t38_setAE6C(u32 arg) { u32 value; +#ifdef REGION_USA + register u32 key asm("r1")=arg; +#else register u32 key asm("r2")=arg; +#endif u8 *p; u32 idx; value=3; @@ -5362,9 +5382,9 @@ static inline void t38_setAE6C(u32 arg) { u8 *entry; u32 off; idx=arg-1; - if(idx<5) {address=(u8 **)&gUnk_030056F4;off=idx*0x2E0;entry=*address;entry+=off;sub_08019EB8(*(u16 *)(entry+2),3);} + if(idx<5) {address=(u8 **)&gUnk_030056F4;off=idx*ENEMY_SIZE;entry=*address;entry+=off;sub_08019EB8(*(u16 *)(entry+2),3);} } - else {register u32 off asm("r0");off=sub_080020F4()*0x14C;p=(u8 *)gUnk_03003CE0+off;*(u16 *)(p+0x11E)=value;} + else {register u32 off asm("r0");off=sub_080020F4()*PLAYER_SIZE;p=(u8 *)gUnk_03003CE0+off;*(u16 *)(p+PLAYER_FIELD(0x11E))=value;} } static inline u32 t38_getFirstAE6C(u32 mask) { u8 *base; @@ -5392,8 +5412,8 @@ void sub_0803AE6C(u32 arg0) { register u32 endOffset asm("r2"); {register u32 off asm("r1");u32 bits;u8 *base; - off=0x14C * sub_080020F4();base=(u8 *)gUnk_03003CE0;temp_r1=(u8 *)off;temp_r1+= (u32)base; - bits=*(u32 *)(temp_r1+0x30);one=1;bits|=one;*(u32 *)(temp_r1+0x30)=bits;} + off=PLAYER_SIZE * sub_080020F4();base=(u8 *)gUnk_03003CE0;temp_r1=(u8 *)off;temp_r1+= (u32)base; + bits=*(u32 *)(temp_r1+PLAYER_FIELD(0x30));one=1;bits|=one;*(u32 *)(temp_r1+PLAYER_FIELD(0x30))=bits;} sub_0800D0F4(); var_r4=t38_getFirstAE6C(one); var_r0=t38_getAE6C(0x100); @@ -5450,9 +5470,9 @@ void sub_0803AE6C(u32 arg0) { sub_08029788(arg0); sub_0802939C(arg0, 3); endOffset = sub_080020F4(); - endOffset *= 0x14C; + endOffset *= PLAYER_SIZE; temp_r2_2 = (u8 *)gUnk_03003CE0 + endOffset; - (*(u32 *)(temp_r2_2 + 0x30)) = (s32) ((*(u32 *)(temp_r2_2 + 0x30)) & ~1); + (*(u32 *)(temp_r2_2 + PLAYER_FIELD(0x30))) = (s32) ((*(u32 *)(temp_r2_2 + PLAYER_FIELD(0x30))) & ~1); sub_0800D108(); } /* [ShowProgressionDialogue321] Locks input and selects cancellable message0x14014C when progression @@ -5468,9 +5488,9 @@ void sub_0803B194(void) { register s32 raw asm("r0"); s32 shifted; register u32 one asm("r0"); - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)|=1; + *(u32 *)(p+PLAYER_FIELD(0x30))|=1; sub_0800D0F4(); if(sub_0800CE30()) flags=*(u32 *)((u8 *)gUnk_03005CF4+0x7C); else flags=*(u32 *)((u8 *)gUnk_03005CF4+0x74); @@ -5574,8 +5594,8 @@ void sub_0803B194(void) { sub_080003F0(); } } - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)&=~1; + *(u32 *)(p+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); } diff --git a/src/code_0803B69C.c b/src/code_0803B69C.c index e926ea90..cdd487b4 100644 --- a/src/code_0803B69C.c +++ b/src/code_0803B69C.c @@ -40,9 +40,9 @@ void sub_0803B720(s32 arg0) { register s32 raw asm("r0"); s32 shifted; register u32 one asm("r0"); - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)|=1; + *(u32 *)(p+PLAYER_FIELD(0x30))|=1; sub_0800D0F4(); sub_0802949C(arg0,0); if(sub_0800CE30()) flags=*(u32 *)((u8 *)gUnk_03005CF4+0x7C); @@ -148,9 +148,9 @@ void sub_0803B720(s32 arg0) { } } sub_08029788(arg0); - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)&=~1; + *(u32 *)(p+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); } extern void sub_0805990C(void); @@ -200,7 +200,7 @@ void sub_0803BC3C(u32 arg0) { u32 id; u32 mode; register u32 offset asm("r2"); - mul=0x14C*sub_080020F4();player=(u8 *)gUnk_03003CE0+mul;flags=*(u32 *)(player+0x30);one=1;*(u32 *)(player+0x30)=flags|one; + mul=PLAYER_SIZE*sub_080020F4();player=(u8 *)gUnk_03003CE0+mul;flags=*(u32 *)(player+PLAYER_FIELD(0x30));one=1;*(u32 *)(player+PLAYER_FIELD(0x30))=flags|one; sub_0800D0F4();sub_0802949C(arg0,0); if(sub_0800CE30()) selected=(u8 *)gUnk_03005CF4+0x1C4; else {register u32 off asm("r3");selected=(u8 *)gUnk_03005CF4;off=0x1B8;selected+=off;} @@ -209,12 +209,16 @@ void sub_0803BC3C(u32 arg0) { while(sub_0805EF90()) sub_080003F0(); msg=sub_0805DF38(1,15,2,0,-1,0x14028B); while(!sub_0805EEFC((void *)msg)) {if(sub_0800CDF8()) {sub_0805EFBC();break;} sub_080003F0();} - total=0;idx=0;item=(struct T39BC3CItem *)((u8 *)gUnk_030034E0+0x150); + total=0;idx=0;item=(struct T39BC3CItem *)((u8 *)gUnk_030034E0+SAVE_FIELD(0x150)); do {if(t39_bc3c_id((u8 *)item)==1&&item->kind==0x30) total++;item++;idx++;} while(idx<=24); if(total>0 && sub_080020F4()==0) { id=arg0;mode=3;if(id>0x100000) {slot=t39_bc3c_find(id);if(slot)slot->state=mode;} - else if(arg0) {id=arg0-1;if(id<=4){entityGlobal=(u8 **)&gUnk_030056F4;entityOffset=id*0x2E0;base1=*entityGlobal+entityOffset;sub_08019EB8(*(u16 *)(base1+2),3);}} - else {entityOffset=sub_080020F4()*0x14C;base0=(u8 *)gUnk_03003CE0+entityOffset;mul=0x11E;*(u16 *)(base0+mul)=mode;} +#ifdef REGION_USA + else if(arg0) {id=arg0-1;if(id<=4){u8 **table=(u8 **)&gUnk_030056F4;u32 eo=id*ENEMY_SIZE;u8 *e=*table;e+=eo;sub_08019EB8(*(u16 *)(e+2),3);}} +#else + else if(arg0) {id=arg0-1;if(id<=4){entityGlobal=(u8 **)&gUnk_030056F4;entityOffset=id*ENEMY_SIZE;base1=*entityGlobal+entityOffset;sub_08019EB8(*(u16 *)(base1+2),3);}} +#endif + else {entityOffset=sub_080020F4()*PLAYER_SIZE;base0=(u8 *)gUnk_03003CE0+entityOffset;mul=PLAYER_FIELD(0x11E);*(u16 *)(base0+mul)=mode;} dat=req.data;while(sub_0805F184()) sub_080003F0(); while(sub_0805EF90()) sub_080003F0(); msg=sub_0805DF38(1,15,2,0,-1,0x14028C); @@ -222,7 +226,7 @@ while(!sub_0805EEFC((void *)msg)) {if(sub_0800CDF8()) {sub_0805EFBC();break;} su left=1;scan=0;items=(u8 **)&gUnk_030034E0;zero=0; again: base0=*items;base1=base0+scan*16; - fieldOff=0x150;entryId=base1+fieldOff;if(t39_bc3c_id(entryId)==1 && (fieldOff=0x152,base1+=fieldOff,*(u16 *)base1)==0x30) { + fieldOff=SAVE_FIELD(0x150);entryId=base1+fieldOff;if(t39_bc3c_id(entryId)==1 && (fieldOff=SAVE_FIELD(0x152),base1+=fieldOff,*(u16 *)base1)==0x30) { left--;*(u16 *)entryId=zero;*(u16 *)base1=zero;if(!left)goto done; } scan++;if(scan<=24)goto again; @@ -248,8 +252,8 @@ while(!sub_0805EEFC((void *)msg)) {if(sub_0800CDF8()) {sub_0805EFBC();break;} su while(sub_0805EF90()) sub_080003F0(); msg=sub_0805DF38(1,15,2,0,-1,0x14028F); while(!sub_0805EEFC((void *)msg)) {if(sub_0800CDF8()) {sub_0805EFBC();break;} sub_080003F0();} } - offset=sub_080020F4();offset*=0x14C;p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)&=~1;sub_0800D108(); + offset=sub_080020F4();offset*=PLAYER_SIZE;p=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(p+PLAYER_FIELD(0x30))&=~1;sub_0800D108(); } struct T39C008Item {u16 id,pad;s32 count;u32 a,b;}; static inline s32 t39_c008_byte(u8 *p) { return *p; } @@ -273,9 +277,9 @@ void sub_0803C008(void) { register s32 total asm("r3"); register s32 n asm("r1"); struct T39C008Item *item; - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)|=1; + *(u32 *)(p+PLAYER_FIELD(0x30))|=1; sub_0800D0F4(); one=sub_08002164(); if(one==1) { @@ -293,10 +297,10 @@ while(!sub_0805EEFC((void *)msg)) sub_080003F0(); } while(sub_0805EF14((u8 *)msg msg=sub_0805DF38(1,15,2,0,-2,0x1401E4); while(!sub_0805EEFC((void *)msg)) sub_080003F0(); if(sub_0805EF14((u8 *)msg)==1) { - total=0;gpLoad=(u8 **)&gUnk_030034E0;base=*gpLoad;firstOff=0x150;asm("" : "+r"(firstOff));item=(struct T39C008Item *)(base+firstOff);gp=gpLoad;n=24; + total=0;gpLoad=(u8 **)&gUnk_030034E0;base=*gpLoad;firstOff=SAVE_FIELD(0x150);asm("" : "+r"(firstOff));item=(struct T39C008Item *)(base+firstOff);gp=gpLoad;n=24; do {if(item->id==10) total+=item->count; n--;item++;} while(n>=0); - base=*gp;item=(struct T39C008Item *)(base+0x2E0); - count=15 * *(u16 *)(base+0x6A); + base=*gp;item=(struct T39C008Item *)(base+SAVE_FIELD(0x2E0)); + count=15 * *(u16 *)(base+SAVE_FIELD(0x6A)); if(count>0) {n=count;do {if(item->id==10) total+=item->count; n--;item++;} while(n);} if(total>99) { while(sub_0805F184()) sub_080003F0(); @@ -323,9 +327,9 @@ while(!sub_0805EEFC((void *)msg)) {if(sub_0800CDF8()) {sub_0805EFBC();break;} su while(sub_0805EF90()) sub_080003F0(); msg=sub_0805DF38(1,15,2,0,-1,0x1401F5); while(!sub_0805EEFC((void *)msg)) {if(sub_0800CDF8()) {sub_0805EFBC();break;} sub_080003F0();} } - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)&=~1; + *(u32 *)(p+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); } extern void sub_0803C4C0(void); @@ -340,9 +344,9 @@ void sub_0803C3C8(void) { u8 *p; register u32 offset asm("r2"); offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (u8 *)gUnk_03003CE0 + offset; - *(u32 *)(p + 0x30) |= 1; + *(u32 *)(p + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); msg = sub_0805DF38(1,15,2,0,-2,0x140203); @@ -359,9 +363,9 @@ void sub_0803C3C8(void) { sub_080003F0(); } offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (u8 *)gUnk_03003CE0 + offset; - *(u32 *)(p + 0x30) &= ~1; + *(u32 *)(p + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } /* [StageDialogs517Then516] Locks input, fades screen, closes dialog, positions actor0 at x236 plus multiplayer @@ -376,9 +380,9 @@ void sub_0803C4C0(void) { u8 *p; u8 *last; s32 mask; - offset=sub_080020F4(); offset*=0x14C; + offset=sub_080020F4(); offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)|=1; + *(u32 *)(p+PLAYER_FIELD(0x30))|=1; sub_0800D0F4(); sub_0801AA8C(30); while(!sub_0801AAE0()) sub_080003F0(); @@ -414,12 +418,12 @@ void sub_0803C4C0(void) { if(sub_0800CDF8()) {sub_0805EFBC();break;} sub_080003F0(); } - offset=sub_080020F4();offset*=0x14C; + offset=sub_080020F4();offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)&=~1; + *(u32 *)(p+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); - last=(u8 *)gUnk_03003CE0+0x14C*sub_080020F4(); - *(u16 *)(last+0x20)=0; + last=(u8 *)gUnk_03003CE0+PLAYER_SIZE*sub_080020F4(); + *(u16 *)(last+PLAYER_FIELD(0x20))=0; } struct T39C698Item {u16 id,pad;s32 count;u32 a,b;}; struct T39C698Req {u16 id,kind;u8 data[12];}; @@ -458,8 +462,8 @@ void sub_0803C698(s32 arg0) { register u8 **gp asm("r4"); struct T39C698Item *item; u32 i,valid; - offset=sub_080020F4();offset*=0x14C;p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)|=1;sub_0800D0F4();sub_0802939C(arg0,2); + offset=sub_080020F4();offset*=PLAYER_SIZE;p=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(p+PLAYER_FIELD(0x30))|=1;sub_0800D0F4();sub_0802939C(arg0,2); while(sub_0805F184()) sub_080003F0(); while(sub_0805EF90()) sub_080003F0(); firstMsg=sub_0805DF38(1,15,2,0,-1,0x140292); @@ -499,11 +503,11 @@ msg=sub_0805DF38(1,15,2,0,-2,0x14029F); while(!sub_0805EEFC((void *)msg))sub_080003F0(); answer=sub_0805EF14((u8 *)msg);break; } if(answer!=0) { - total=0;gpLoad=(u8 **)&gUnk_030034E0;base=*gpLoad;firstOff=0x150;asm("" : "+r"(firstOff));item=(struct T39C698Item *)(base+firstOff);gp=gpLoad; + total=0;gpLoad=(u8 **)&gUnk_030034E0;base=*gpLoad;firstOff=SAVE_FIELD(0x150);asm("" : "+r"(firstOff));item=(struct T39C698Item *)(base+firstOff);gp=gpLoad; next=level+1;n=24; do {if(item->id==10)total+=item->count;n--;item++;}while(n>=0); - base=*gp;item=(struct T39C698Item *)(base+0x2E0); - count=15 * *(u16 *)(base+0x6A); + base=*gp;item=(struct T39C698Item *)(base+SAVE_FIELD(0x2E0)); + count=15 * *(u16 *)(base+SAVE_FIELD(0x6A)); if(count>0){n=count;do {if(item->id==10)total+=item->count;n--;item++;}while(n);} if(total>=(s32)(100*next)) { valid=t39_c698_valid(); @@ -530,8 +534,8 @@ while(sub_0805EF90()) sub_080003F0(); msg=sub_0805DF38(1,15,2,0,-1,0x140293); while(!sub_0805EEFC((void *)msg)) {if(sub_0800CDF8()) {sub_0805EFBC();break;} sub_080003F0();}} sub_0802939C(arg0,0); - offset=sub_080020F4();offset*=0x14C;p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)&=~1;sub_0800D108(); + offset=sub_080020F4();offset*=PLAYER_SIZE;p=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(p+PLAYER_FIELD(0x30))&=~1;sub_0800D108(); } /* [ConfirmProgressStageAdvance] Sets player flag1, faces entity and picks yes/no message0x1404EE..4F7 from * highest progress bit256..1/default. Confirmation ORs next bit into mode-selected progress word; noninitial @@ -561,8 +565,8 @@ void sub_0803CC50(s32 arg0) { u8 *temp_r2; u8 *temp_r2_2; - offset=sub_080020F4();offset*=0x14C;temp_r2=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2+0x30) = (s32) (*(u32 *)(temp_r2+0x30) | 1); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2+PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); sub_0802949C(arg0, 0); if (sub_0800CE30() != 0) { @@ -753,8 +757,8 @@ void sub_0803CC50(s32 arg0) { } } sub_08029788(arg0); - offset=sub_080020F4();offset*=0x14C;temp_r2_2=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2_2+0x30) = (s32) (*(u32 *)(temp_r2_2+0x30) & ~1); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2_2=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2_2+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2_2+PLAYER_FIELD(0x30)) & ~1); sub_0800D108(); } @@ -772,9 +776,9 @@ void sub_0803D1F8(s32 arg0) { u32 field; register u32 raw asm("r2"); register u32 mask asm("r0"); - offset=sub_080020F4(); offset*=0x14C; + offset=sub_080020F4(); offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)|=1; + *(u32 *)(p+PLAYER_FIELD(0x30))|=1; sub_0800D0F4(); sub_0802949C(arg0,0); while(sub_0805F184()!=0) sub_080003F0(); dialog=sub_0805DF38(1,15,2,0,-2,0x1404F8); @@ -797,9 +801,9 @@ void sub_0803D1F8(s32 arg0) { if(!(gUnk_030027D0&0x20)) sub_08006D08(0x32); } sub_08029788(arg0); - offset=sub_080020F4(); offset*=0x14C; + offset=sub_080020F4(); offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)&=~1; + *(u32 *)(p+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); } extern void sub_0802949C(s32, s32); @@ -814,9 +818,9 @@ void sub_0803D36C(s32 arg0) { u8 *state; u32 field; offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (u8 *)gUnk_03003CE0 + offset; - *(u32 *)(p + 0x30) |= 1; + *(u32 *)(p + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); sub_0802949C(arg0, 0); while (sub_0805F184() != 0) sub_080003F0(); @@ -837,9 +841,9 @@ void sub_0803D36C(s32 arg0) { } sub_08029788(arg0); offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (u8 *)gUnk_03003CE0 + offset; - *(u32 *)(p + 0x30) &= ~1; + *(u32 *)(p + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } @@ -860,9 +864,9 @@ void sub_0803D454(s32 arg0) { u32 flags; - offset=sub_080020F4(); offset*=0x14C; + offset=sub_080020F4(); offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)|=1; + *(u32 *)(p+PLAYER_FIELD(0x30))|=1; sub_0800D0F4(); sub_0802949C(arg0,0); while(sub_0805F184()!=0) sub_080003F0(); dialog=sub_0805DF38(1,15,2,0,-2,0x1404FB); @@ -923,13 +927,13 @@ void sub_0803D454(s32 arg0) { end: sub_0805C7B8(0); sub_08029788(arg0); - offset=sub_080020F4(); offset*=0x14C; + offset=sub_080020F4(); offset*=PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(p+0x30)&=~1; + *(u32 *)(p+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); } struct CmdD99C {u16 one,kind; u8 data[12];}; -struct PlayerD99C {u8 pad[32];u16 value;}; +struct PlayerD99C {u8 pad[PLAYER_FIELD(0x20)];u16 value;}; struct TaskD99C {u32 f0,f4,f8,fC;void *f10;u32 f14,f18,f1C;u8 *f20;u32 f24;}; extern u8 *gStateD99C asm("gUnk_03005CF4"); extern s32 sub_0801AB24(void); @@ -991,8 +995,8 @@ void sub_0803D99C(void) { u8 *temp_r2_3; - offset=sub_080020F4(); offset*=0x14C; temp_r2=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2+0x30) = (s32) (*(u32 *)(temp_r2+0x30) | 1); + offset=sub_080020F4(); offset*=PLAYER_SIZE; temp_r2=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2+PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); temp_r5 = sub_080289C0(0x6000D, 0x101, 0x4E); var_r2_2=findD99C(temp_r5); @@ -1022,8 +1026,8 @@ void sub_0803D99C(void) { break; } sub_08028AAC(0, (u16)var_r4, 0x52, 0); - offset=sub_080020F4(); offset*=0x14C; temp_r2_2=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2_2+0x30) = (s32) (*(u32 *)(temp_r2_2+0x30) & ~2); + offset=sub_080020F4(); offset*=PLAYER_SIZE; temp_r2_2=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2_2+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2_2+PLAYER_FIELD(0x30)) & ~2); sub_08067D74(); sub_080290E4(0, 0); sub_08029174(0, 0x25); @@ -1116,13 +1120,13 @@ taskNext: var_r4_2++; var_r5_6++; var_r1_3 += 1; } while (var_r1_3 <= 0xBU); while(sub_08067B9C(0x3B00U, 0x7D00U, &cmd) == 0) sub_080003F0(); - offset=sub_080020F4(); offset*=0x14C; temp_r2_3=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2_3+0x30) = (s32) (*(u32 *)(temp_r2_3+0x30) & ~1); + offset=sub_080020F4(); offset*=PLAYER_SIZE; temp_r2_3=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2_3+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2_3+PLAYER_FIELD(0x30)) & ~1); sub_0800D108(); - ((struct PlayerD99C *)((u8 *)gUnk_03003CE0+0x14C*sub_080020F4()))->value=0; + ((struct PlayerD99C *)((u8 *)gUnk_03003CE0+PLAYER_SIZE*sub_080020F4()))->value=0; } -struct PlayerDE84 {u8 pad[32];u16 value;}; +struct PlayerDE84 {u8 pad[PLAYER_FIELD(0x20)];u16 value;}; struct TaskDE84 {u32 f0,f4,f8,fC;void *f10;u32 f14,f18,f1C;u8 *f20;u32 f24;}; extern u8 *gStateDE84 asm("gUnk_03005CF4"); extern void sub_08019EB8(u16,s32); @@ -1150,7 +1154,11 @@ static inline u8 *findSetDE84(u32 arg) { } static inline void setDE84(u32 arg) { u32 value; +#ifdef REGION_USA + register u32 key asm("r1")=arg; +#else register u32 key asm("r2")=arg; +#endif u8 *p; u32 idx; value=3; @@ -1160,9 +1168,9 @@ static inline void setDE84(u32 arg) { u8 *entry; u32 off; idx=arg-1; - if(idx<5) {address=(u8 **)&gUnk_030056F4;off=idx*0x2E0;entry=*address;entry+=off;sub_08019EB8(*(u16 *)(entry+2),3);} + if(idx<5) {address=(u8 **)&gUnk_030056F4;off=idx*ENEMY_SIZE;entry=*address;entry+=off;sub_08019EB8(*(u16 *)(entry+2),3);} } - else {register u32 off asm("r0");off=sub_080020F4()*0x14C;p=(u8 *)gUnk_03003CE0+off;*(u16 *)(p+0x11E)=value;} + else {register u32 off asm("r0");off=sub_080020F4()*PLAYER_SIZE;p=(u8 *)gUnk_03003CE0+off;*(u16 *)(p+PLAYER_FIELD(0x11E))=value;} } /* [RunBokenAreaEntryEvent] Sets local player flags bit 0 (input suppression) and BeginLocalPlayerEventLock. * Spawns actor A with SpawnSceneObjectAndWaitForStartupStateChange(0xF, 0x42, 0xC0), sets its extents 8x4 and @@ -1206,8 +1214,8 @@ void sub_0803DE84(void) { register volatile u32 *flagsAddress asm("r5"); u32 musicValue; - offset=sub_080020F4();offset*=0x14C;temp_r2=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2+0x30) = (s32) (*(u32 *)(temp_r2+0x30) | 1); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2+PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); temp_r7 = sub_080289C0(0xF, 0x42, 0xC0); var_r2_2=findDE84(temp_r7); @@ -1261,10 +1269,10 @@ void sub_0803DE84(void) { if (!(gUnk_030027D0 & 0x20)) { sub_08006CB4(0xA5U); } - offset=sub_080020F4();offset*=0x14C;temp_r2_3=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2_3+0x30) = (s32) (*(u32 *)(temp_r2_3+0x30) & ~1); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2_3=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2_3+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2_3+PLAYER_FIELD(0x30)) & ~1); sub_0800D108(); - ((struct PlayerDE84 *)((u8 *)gUnk_03003CE0+0x14C*sub_080020F4()))->value = 0; + ((struct PlayerDE84 *)((u8 *)gUnk_03003CE0+PLAYER_SIZE*sub_080020F4()))->value = 0; { u8 *var_r2_4; u32 var_r3_2; @@ -1278,7 +1286,7 @@ void sub_0803DE84(void) { *(u16 *)(var_r2_4+0xC) = loopZero; } var_r3_2 += 1; - stride=0x2E0;var_r2_4+=stride; + stride=ENEMY_SIZE;var_r2_4+=stride; } while (var_r3_2 <= 4U); } sub_08019F04(); @@ -1294,8 +1302,8 @@ void sub_0803DE84(void) { musicDE84(gUnk_03005CF8); gUnk_03005CF8 = (s32) var_r5; sub_08015D74(); - offset=sub_080020F4();offset*=0x14C;temp_r2_4=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2_4+0x30) = (s32) (*(u32 *)(temp_r2_4+0x30) | 1); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2_4=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2_4+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2_4+PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); while(sub_0805F184() != 0) sub_080003F0(); while(sub_0805EF90() != 0) sub_080003F0(); @@ -1309,17 +1317,17 @@ void sub_0803DE84(void) { *(u32 *)(var_r0_3+0x44) = callback; } } - offset=sub_080020F4();offset*=0x14C;temp_r2_5=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2_5+0x30) = (s32) (*(u32 *)(temp_r2_5+0x30) & ~1); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2_5=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2_5+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2_5+PLAYER_FIELD(0x30)) & ~1); sub_0800D108(); sp10 = 0; pos.x = 0x7E00; pos.y = 0x8600; sp14 = 0x100040; - temp_r4_4 = (u8 *)gUnk_03003CE0+0x14C*sub_080020F4(); - while(sub_08021FE0(temp_r4_4 + 0x8C, &pos.x, &sp10, &sp14) == 0) sub_080003F0(); - offset=sub_080020F4();offset*=0x14C;temp_r2_6=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2_6+0x30) = (s32) (*(u32 *)(temp_r2_6+0x30) | 1); + temp_r4_4 = (u8 *)gUnk_03003CE0+PLAYER_SIZE*sub_080020F4(); + while(sub_08021FE0(temp_r4_4 + PLAYER_FIELD(0x8C), &pos.x, &sp10, &sp14) == 0) sub_080003F0(); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2_6=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2_6+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2_6+PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); taskCallback=(u32)sub_08059890; var_r4_2 = (struct TaskDE84 *)(gStateDE84 + 0xE34); @@ -1345,8 +1353,8 @@ taskNext: var_r5_2++;var_r4_2++; if (!(gUnk_030027D0 & 0x20)) { sub_08006D08(0x65U); } - offset=sub_080020F4();offset*=0x14C;temp_r2_7=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2_7+0x30) = (s32) (*(u32 *)(temp_r2_7+0x30) | 2); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2_7=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2_7+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2_7+PLAYER_FIELD(0x30)) | 2); sub_08067D74(); sub_08068070((u32) sub_0803E5D8, 0U); do { @@ -1366,10 +1374,10 @@ taskNext: var_r5_2++;var_r4_2++; *(u16 *)(var_r1_5+0x36) = 4; } sub_0802A228(0xC, 1); - ((struct PlayerDE84 *)((u8 *)gUnk_03003CE0+0x14C*sub_080020F4()))->value = 0; + ((struct PlayerDE84 *)((u8 *)gUnk_03003CE0+PLAYER_SIZE*sub_080020F4()))->value = 0; } -struct E510Player { u8 pad[0x20]; u16 value; }; +struct E510Player { u8 pad[PLAYER_FIELD(0x20)]; u16 value; }; extern void sub_08029174(s32, s32); /* [RunActorMessage1257] Sets local-player flag0/event lock, requests player animation0 and actor facing toward * selector0. */ @@ -1378,9 +1386,9 @@ void sub_0803E510(s32 arg0) { u8 *p; u32 dialog; offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (u8 *)gUnk_03003CE0 + offset; - *(u32 *)(p + 0x30) |= 1; + *(u32 *)(p + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); sub_08029174(0, 0); sub_0802949C(arg0, 0); @@ -1396,11 +1404,11 @@ void sub_0803E510(s32 arg0) { } sub_08029788(arg0); offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; p = (u8 *)gUnk_03003CE0 + offset; - *(u32 *)(p + 0x30) &= ~1; + *(u32 *)(p + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); - ((struct E510Player *)((u8 *)gUnk_03003CE0 + sub_080020F4() * 0x14C))->value = 0; + ((struct E510Player *)((u8 *)gUnk_03003CE0 + sub_080020F4() * PLAYER_SIZE))->value = 0; } @@ -1442,7 +1450,11 @@ void sub_0803E638(void) { s32 out[4]; u8 *setPointerE638; u8 *setResultE638; +#ifdef REGION_USA + register u32 setKeyE638 asm("r1"); +#else register u32 setKeyE638 asm("r2"); +#endif u32 setValueE638; u32 setIndexE638; @@ -1512,10 +1524,10 @@ void sub_0803E638(void) { u8 *temp_r2; u8 *var_r1_3; - initZero=0;*(u16 *)(gConfigE638+0x68)=initZero; + initZero=0;*(u16 *)(gConfigE638+PLAYER_FIELD(0x68))=initZero; sub_0805AD78(0); - offset=sub_080020F4();offset*=0x14C;temp_r2=(u8 *)gUnk_03003CE0+offset; - *(u32 *)(temp_r2+0x30) = (s32) (*(u32 *)(temp_r2+0x30) | 1); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2=(u8 *)gUnk_03003CE0+offset; + *(u32 *)(temp_r2+PLAYER_FIELD(0x30)) = (s32) (*(u32 *)(temp_r2+PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); sub_0800CF90(); var_r4 = 1; @@ -1541,7 +1553,7 @@ void sub_0803E638(void) { case 2:sub_08028AAC(0,0x24,0x14A,0);sub_080290E4(0,6);break; case 3:sub_08028AAC(0,0x2F,0x141,0);sub_080290E4(0,6);break; } - playerOffset=sub_080020F4();playerBase=(u8 *)gUnk_03003CE0;offset=0x14C;playerOffset*=offset;playerBase+=0x90;playerOffset+=(u32)playerBase; + playerOffset=sub_080020F4();playerBase=(u8 *)gUnk_03003CE0;offset=PLAYER_SIZE;playerOffset*=offset;playerBase+=PLAYER_FIELD(0x90);playerOffset+=(u32)playerBase; temp_r0_3=(*(s32 *)playerOffset>>8)-0x93; sp1C = temp_r0_3; temp_r0_3=-temp_r0_3; @@ -1700,12 +1712,12 @@ taskNext4: var_r5_5++;var_r4_11++; u8 *entryE638; u32 offE638; playerIndexE638=(u32)temp_r0-1; - if(playerIndexE638<5) {addressE638=(u8 **)&gUnk_030056F4;offE638=playerIndexE638*0x2E0;entryE638=*addressE638;entryE638+=offE638;sub_08019EB8(*(u16 *)(entryE638+2),3);} + if(playerIndexE638<5) {addressE638=(u8 **)&gUnk_030056F4;offE638=playerIndexE638*ENEMY_SIZE;entryE638=*addressE638;entryE638+=offE638;sub_08019EB8(*(u16 *)(entryE638+2),3);} } else { register u32 offE638 asm("r0"); - offE638=sub_080020F4()*0x14C; + offE638=sub_080020F4()*PLAYER_SIZE; setResultE638=(u8 *)gUnk_03003CE0+offE638; - *(u16 *)(setResultE638+0x11E)=setValueE638; + *(u16 *)(setResultE638+PLAYER_FIELD(0x11E))=setValueE638; } sub_0802939C(temp_r0, 0x11); sub_08028D98(temp_r0, 0x24, 0, 4); @@ -1765,7 +1777,7 @@ void sub_0803EE88(void) { struct Player *temp_r2; struct Player *temp_r2_2; - offset=sub_080020F4();offset*=0x14C;temp_r2=(struct Player *)((u8 *)gUnk_03003CE0+offset); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2=(struct Player *)((u8 *)gUnk_03003CE0+offset); temp_r2->flags = (s32) (temp_r2->flags | 1); sub_0800D0F4(); temp_r0 = sub_080289C0(0x20, 0x78, 0x141); @@ -1872,7 +1884,7 @@ while (sub_0801AAE0() == 0) sub_080003F0(); } finalFlags=*var_r2_3;finalOne=1;finalOne |= finalFlags;*var_r2_3=finalOne; sub_0802A228(0, 0); - offset=sub_080020F4();offset*=0x14C;temp_r2_2=(struct Player *)((u8 *)gUnk_03003CE0+offset); + offset=sub_080020F4();offset*=PLAYER_SIZE;temp_r2_2=(struct Player *)((u8 *)gUnk_03003CE0+offset); temp_r2_2->flags = (s32) (temp_r2_2->flags & ~1); sub_0800D108(); } @@ -1915,8 +1927,8 @@ void sub_0803F18C(s32 arg0) { sub_08028D98(0, 0, -0x12C, 0x12C); break; } - q = (u8 *)gUnk_03003CE0 + sub_080020F4() * 0x14C; - *(u16 *)(q + 0x20) = 0; + q = (u8 *)gUnk_03003CE0 + sub_080020F4() * PLAYER_SIZE; + *(u16 *)(q + PLAYER_FIELD(0x20)) = 0; } /* [RunActorAnimationSoundTriplet] Three29174(arg,16) requests each conditionally start85, followed after10 * by29174(arg,10); countdowns58,58,40. */ @@ -2336,7 +2348,7 @@ done183: ; while (n != 0) {sub_080003F0();if(sub_080021A8())break;n=decF454(n);} break; } - var_r0=sub_080020F4();var_r1=0x14C;var_r0*=var_r1;var_r1=(s32)gUnk_03003CE0;var_r0+=var_r1;var_r1=0;*(u16 *)(var_r0+0x20)=var_r1; + var_r0=sub_080020F4();var_r1=PLAYER_SIZE;var_r0*=var_r1;var_r1=(s32)gUnk_03003CE0;var_r0+=var_r1;var_r1=0;*(u16 *)(var_r0+PLAYER_FIELD(0x20))=var_r1; } static inline u32 firstFE34(u8 *base) {u32 bit=1;register u32 result asm("r0")=*(u32 *)(base+0x38);result &= bit;if(result)result=1;return result;} static inline u8 testFE34(u32 value, u32 mask) {u32 result=value & mask; if(result)result=1;return result;} @@ -2530,7 +2542,7 @@ void sub_080400D4(void) { s32 step; u16 n; u32 task; s32 result; struct Player *p; s32 player; register s32 offset asm("r2"); - offset = sub_080020F4(); offset *= 0x14C; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; + offset = sub_080020F4(); offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; sub_0800D0F4(); result = sub_080020F4(); player = result; if (result == 1) goto case1; @@ -2579,7 +2591,7 @@ case3: sub_08028AAC(0, 0x9C, 0xF5, 0); sub_080003F0(); } sub_0800CFA4(); - offset = sub_080020F4(); offset *= 0x14C; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; + offset = sub_080020F4(); offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; sub_0800D108(); gUnk_03003CE0[sub_080020F4()].state = 0; } @@ -2606,7 +2618,7 @@ void sub_080402F4(void) { s32 step; u16 n; u32 task; s32 result; struct Player *p; s32 player; register s32 offset asm("r2"); - offset = sub_080020F4(); offset *= 0x14C; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; + offset = sub_080020F4(); offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; sub_0800D0F4(); result = sub_080020F4(); player = result; if (result == 1) goto case1; @@ -2623,7 +2635,7 @@ case2: sub_08028AAC(0, 0x54, 0x80, 0); goto endSwitch; case3: sub_08028AAC(0, 0x9C, 0x80, 0); endSwitch: sub_080290E4(0, 4); - offset = sub_080020F4(); offset *= 0x14C; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~2; + offset = sub_080020F4(); offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~2; sub_08067D74(); n = 2; py = &out[1]; px2 = &out[2]; py2 = &out[3]; goto poll402F4; while (n != 0) { poll402F4: sub_080003F0(); if (sub_080021A8()) break; n--; } @@ -2658,7 +2670,7 @@ case3: sub_08028AAC(0, 0x9C, 0x80, 0); camera402F4((s16)out[2], (s16)out[3]); sub_080003F0(); } - offset = sub_080020F4(); offset *= 0x14C; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; + offset = sub_080020F4(); offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; sub_0800D108(); } extern void camera40530(s32, s32) asm("sub_0800BB80"); @@ -2679,7 +2691,7 @@ void sub_08040530(void) { s32 step; u16 n; u32 task; s32 result; struct Player *p; s32 player; register s32 offset asm("r2"); - offset = sub_080020F4(); offset *= 0x14C; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; + offset = sub_080020F4(); offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags |= 1; sub_0800D0F4(); result = sub_080020F4(); player = result; if (result == 1) goto case1; @@ -2696,7 +2708,7 @@ case2: sub_08028AAC(0, 0x54, 0x80, 0); goto endSwitch; case3: sub_08028AAC(0, 0x9C, 0x80, 0); endSwitch: sub_080290E4(0, 4); - offset = sub_080020F4(); offset *= 0x14C; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~2; + offset = sub_080020F4(); offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~2; sub_08067D74(); n = 2; py = &out[1]; px2 = &out[2]; py2 = &out[3]; goto poll40530; while (n != 0) { poll40530: sub_080003F0(); if (sub_080021A8()) break; n--; } @@ -2731,7 +2743,7 @@ case3: sub_08028AAC(0, 0x9C, 0x80, 0); camera40530((s16)out[2], (s16)out[3]); sub_080003F0(); } - offset = sub_080020F4(); offset *= 0x14C; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; + offset = sub_080020F4(); offset *= PLAYER_SIZE; p = (struct Player *)((u8 *)gUnk_03003CE0 + offset); p->flags &= ~1; sub_0800D108(); } extern void t42_camera(s32,s32) asm("sub_0800BB80"); @@ -2827,7 +2839,7 @@ void sub_0804076C(s32 arg0) { struct Player *temp_r2_3; sp38 = arg0; - temp_r2 = (struct Player *)((0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0); + temp_r2 = (struct Player *)((PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0); temp_r2->flags = (s32) (temp_r2->flags | 1); sub_0800D0F4(); temp_r0 = sub_080020F4(); @@ -2838,7 +2850,7 @@ void sub_0804076C(s32 arg0) { case 3: sub_08028AAC(0,0x9C,0x80,0); break; } sub_080290E4(0, 4); - temp_r2_2 = (struct Player *)((0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0); + temp_r2_2 = (struct Player *)((PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0); temp_r2_2->flags = (s32) (temp_r2_2->flags & ~2); sub_08067D74(); var_r4 = 2; @@ -3158,7 +3170,7 @@ foundCbB: var_r0_2=var_r1_4; goto contCbB; sub_080003F0(); var_r4_9 += stepFinal; } while (var_r4_9 <= 0x400); - temp_r2_3 = (struct Player *)((0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0); + temp_r2_3 = (struct Player *)((PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0); temp_r2_3->flags = (s32) (temp_r2_3->flags & ~1); sub_0800D108(); } @@ -3202,7 +3214,11 @@ void sub_08041030(s32 arg0, s32 arg1) { register void (*cbInit)(void) asm("r5"); s32 *var_r0; register void (*cbFinal)(void) asm("r4"); +#ifdef REGION_USA + register s32 rawPose asm("r1"); +#else register s32 rawPose asm("r2"); +#endif u16 poseVal; s32 *var_r0_3; s32 *var_r0_5; @@ -3263,7 +3279,7 @@ void sub_08041030(s32 arg0, s32 arg1) { actor=arg0; saved = arg1; - temp_r2 = (struct Player *)((0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0); + temp_r2 = (struct Player *)((PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0); temp_r2->flags = (s32) (temp_r2->flags | 1); sub_0800D0F4(); temp_r4 = sub_080289C0(0x1003B, 0x78, 0x52); @@ -3307,7 +3323,7 @@ foundInit: var_r2_2=var_r1; goto contInit; case 3: sub_08028AAC(0,0x9C,0x80,0); break; } sub_080290E4(0, 4); - temp_r2_2 = (struct Player *)((0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0); + temp_r2_2 = (struct Player *)((PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0); temp_r2_2->flags = (s32) (temp_r2_2->flags & ~2); sub_08067D74(); var_r4 = 2; @@ -3425,7 +3441,7 @@ foundPoseA: var_r0_5=var_r1_6; goto poseContA; rawPose=actor-1; if ((u32)rawPose<=4) { u8 **base=(u8 **)&gUnk_030056F4; - s32 off=rawPose*0x2E0; + s32 off=rawPose*ENEMY_SIZE; u8 *row; row=*base+off; sub_08019EB8(*(u16 *)(row+2),4); @@ -3436,8 +3452,8 @@ foundActorA: var_r2_6=var_r1_7; goto contActorA; foundActorCbA: var_r0_7=var_r1_8; goto contActorCbA; localPoseA: { s32 index=sub_080020F4(); u32 base; u8 *ptr; s32 offset; - index*=0x14C; base=(u32)gUnk_03003CE0; index+=base; ptr=(u8 *)index; - offset=0x11E; ptr+=offset; var_r0_6=(s16 *)ptr; } + index*=PLAYER_SIZE; base=(u32)gUnk_03003CE0; index+=base; ptr=(u8 *)index; + offset=PLAYER_FIELD(0x11E); ptr+=offset; var_r0_6=(s16 *)ptr; } poseStoreA: *var_r0_6=poseVal; } @@ -3561,15 +3577,15 @@ foundPoseB: var_r0_3=var_r1_4; goto poseContB; rawPose=actor-1; if ((u32)rawPose<=4) { u8 **base=(u8 **)&gUnk_030056F4; - s32 off=rawPose*0x2E0; + s32 off=rawPose*ENEMY_SIZE; u8 *row; row=*base+off; sub_08019EB8(*(u16 *)(row+2),4); } } else { { s32 index=sub_080020F4(); u32 base; u8 *ptr; s32 offset; - index*=0x14C; base=(u32)gUnk_03003CE0; index+=base; ptr=(u8 *)index; - offset=0x11E; ptr+=offset; var_r0_4=(s16 *)ptr; } + index*=PLAYER_SIZE; base=(u32)gUnk_03003CE0; index+=base; ptr=(u8 *)index; + offset=PLAYER_FIELD(0x11E); ptr+=offset; var_r0_4=(s16 *)ptr; } poseStoreB: *var_r0_4=poseVal; } @@ -3637,7 +3653,7 @@ foundPoseB: var_r0_3=var_r1_4; goto poseContB; if (sub_0800CE30() != 0) { u8 *base=(u8 *)gUnk_03005CF4; s32 off=0x1C5; var_r2_9=base+off; } else { register u8 *base asm("r0")=(u8 *)gUnk_03005CF4; s32 off=0x1B9; var_r2_9=base+off; } { u8 *ptr=var_r2_9; u32 value=*ptr; u32 bits=32; bits |= value; *ptr=bits; } - temp_r2_5 = (struct Player *)((0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0); + temp_r2_5 = (struct Player *)((PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0); temp_r2_5->flags = (s32) (temp_r2_5->flags & ~1); sub_0800D108(); } @@ -3707,8 +3723,8 @@ void sub_08041B7C(s32 arg0) { u8 *temp_r2_2; u8 *temp_r2_3; - temp_r2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2 + 0x30) = (s32) (*(s32 *)(temp_r2 + 0x30) | 1); + temp_r2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); t43_schedule1b7c(sub_080020F4()); sub_080290E4(0, 4); @@ -3725,8 +3741,8 @@ void sub_08041B7C(s32 arg0) { if (selected != 0) *((u8 *)gUnk_03005CF4+0x1BE)=0; else *((u8 *)gUnk_03005CF4+0x1B2)=selected; } - temp_r2_2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_2 + 0x30) = (s32) (*(s32 *)(temp_r2_2 + 0x30) & ~2); + temp_r2_2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) & ~2); sub_08067D74(); var_r4 = 2; while (var_r4 != 0) { @@ -3758,8 +3774,8 @@ void sub_08041B7C(s32 arg0) { sub_080003F0(); } t43_move1b7c(34,0,0); - temp_r2_3 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_3 + 0x30) &= ~1; + temp_r2_3 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_3 + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } struct T43Tile { u8 pad[0x80]; s16 x,y; }; @@ -3804,13 +3820,13 @@ void sub_08041E8C(void) { u8 *temp_r2_2; u8 *temp_r2_3; - temp_r2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2 + 0x30) = (s32) (*(s32 *)(temp_r2 + 0x30) | 1); + temp_r2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); t43_schedule1e8c(sub_080020F4()); sub_080290E4(0, 4); - temp_r2_2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_2 + 0x30) = (s32) (*(s32 *)(temp_r2_2 + 0x30) & ~2); + temp_r2_2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) & ~2); sub_08067D74(); var_r4 = 2; while (var_r4 != 0) { @@ -3842,8 +3858,8 @@ void sub_08041E8C(void) { sub_080003F0(); } t43_move1e8c(34,0,0); - temp_r2_3 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_3 + 0x30) = (s32) (*(s32 *)(temp_r2_3 + 0x30) & ~1); + temp_r2_3 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_3 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_3 + PLAYER_FIELD(0x30)) & ~1); sub_0800D108(); } struct T43Tile20c8 { u8 pad[0x80]; s16 x,y; }; @@ -3889,8 +3905,8 @@ void sub_080420C8(void) { u8 *temp_r2_2; u8 *temp_r2_3; - temp_r2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2 + 0x30) = (s32) (*(s32 *)(temp_r2 + 0x30) | 1); + temp_r2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); switch (sub_080020F4()) { case 0: sub_08028AAC(0,0x6C,0x80,0); break; @@ -3899,8 +3915,8 @@ void sub_080420C8(void) { case 3: sub_08028AAC(0,0x9C,0x80,0); break; } sub_080290E4(0, 4); - temp_r2_2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_2 + 0x30) = (s32) (*(s32 *)(temp_r2_2 + 0x30) & ~2); + temp_r2_2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) & ~2); sub_08067D74(); var_r4 = 2; while (var_r4 != 0) { @@ -3942,8 +3958,8 @@ void sub_080420C8(void) { } } t43_move20c8(34,0,0); - temp_r2_3 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_3 + 0x30) = (s32) (*(s32 *)(temp_r2_3 + 0x30) & ~1); + temp_r2_3 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_3 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_3 + PLAYER_FIELD(0x30)) & ~1); sub_0800D108(); } struct T43Tile2390 { u8 pad[0x80]; s16 x,y; }; @@ -3988,13 +4004,13 @@ void sub_08042390(void) { u8 *temp_r2_2; u8 *temp_r2_3; - temp_r2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2 + 0x30) = (s32) (*(s32 *)(temp_r2 + 0x30) | 1); + temp_r2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); t43_schedule2390(sub_080020F4()); sub_080290E4(0, 4); - temp_r2_2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_2 + 0x30) = (s32) (*(s32 *)(temp_r2_2 + 0x30) & ~2); + temp_r2_2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) & ~2); sub_08067D74(); var_r4 = 2; while (var_r4 != 0) { @@ -4026,8 +4042,8 @@ void sub_08042390(void) { sub_080003F0(); } t43_move2390(34,0,0); - temp_r2_3 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_3 + 0x30) = (s32) (*(s32 *)(temp_r2_3 + 0x30) & ~1); + temp_r2_3 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_3 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_3 + PLAYER_FIELD(0x30)) & ~1); sub_0800D108(); } struct T43Slot25cc { s32 id; u8 p04[0x14]; u16 f18,f1a; u8 p1c[0x1a]; u16 f36; u32 f38,f3c,f40; void (*f44)(void); u8 p48[0x28]; }; @@ -4098,13 +4114,13 @@ void sub_080425CC(s32 arg0) { u8 *temp_r2_2; u8 *temp_r2_3; - temp_r2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2 + 0x30) = (s32) (*(s32 *)(temp_r2 + 0x30) | 1); + temp_r2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); t43_schedule25cc(sub_080020F4()); sub_080290E4(0, 4); - temp_r2_2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_2 + 0x30) = (s32) (*(s32 *)(temp_r2_2 + 0x30) & ~2); + temp_r2_2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) & ~2); sub_08067D74(); var_r4 = 2; while (var_r4 != 0) { @@ -4152,8 +4168,8 @@ void sub_080425CC(s32 arg0) { } t43_move25cc(34,0,0); { register u32 value asm("r4")=2; *t43_select25cc()=value; } - temp_r2_3 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_3 + 0x30) &= ~1; + temp_r2_3 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_3 + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } struct T43Slot2938 { s32 id; u8 p04[0x14]; u16 f18,f1a; u8 p1c[0x1a]; u16 f36; u32 f38,f3c,f40; void (*f44)(void); u8 p48[0x28]; }; @@ -4228,8 +4244,8 @@ void sub_08042938(s32 arg0) { u8 *temp_r2; u8 *temp_r2_2; - temp_r2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2 + 0x30) = (s32) (*(s32 *)(temp_r2 + 0x30) | 1); + temp_r2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); t43_schedule2938(sub_080020F4()); sub_080290E4(0, 4); @@ -4242,8 +4258,8 @@ void sub_08042938(s32 arg0) { } t43_callback2938(temp_r4, sub_080308B4); { register u32 value asm("r4") = 1; *t43_select2938() = value; } - temp_r2_2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_2 + 0x30) = (s32) (*(s32 *)(temp_r2_2 + 0x30) & ~2); + temp_r2_2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) & ~2); sub_08067D74(); var_r4 = 2; while (var_r4 != 0) { @@ -4493,8 +4509,8 @@ void sub_08042BB0(void) { t43_flag2bb0((u8 *)var_r2_14, 0x10); } t43_callback2bb0(temp_r4_5, sub_080443EC); - temp_r2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2 + 0x30) = (s32) (*(s32 *)(temp_r2 + 0x30) | 1); + temp_r2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2 + PLAYER_FIELD(0x30)) | 1); sub_0800D0F4(); { register s32 index asm("r1")=sub_080020F4(); switch (index) { @@ -4505,8 +4521,8 @@ void sub_08042BB0(void) { } } sub_080290E4(0, 4); - temp_r2_2 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_2 + 0x30) = (s32) (*(s32 *)(temp_r2_2 + 0x30) & ~2); + temp_r2_2 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_2 + PLAYER_FIELD(0x30)) & ~2); sub_08067D74(); var_r4_3 = 2; while (var_r4_3 != 0) { @@ -4615,8 +4631,8 @@ void sub_08042BB0(void) { while (sub_0801AAE0() == 0) sub_080003F0(); t43_move2bb0(34,0,0); t43_task2bb0(sub_080435C4); - temp_r2_3 = (0x14C * sub_080020F4()) + (u8 *)gUnk_03003CE0; - *(s32 *)(temp_r2_3 + 0x30) = (s32) (*(s32 *)(temp_r2_3 + 0x30) & ~1); + temp_r2_3 = (PLAYER_SIZE * sub_080020F4()) + (u8 *)gUnk_03003CE0; + *(s32 *)(temp_r2_3 + PLAYER_FIELD(0x30)) = (s32) (*(s32 *)(temp_r2_3 + PLAYER_FIELD(0x30)) & ~1); sub_0800D108(); { u32 *base = (u32 *)&gUnk_03005CF4; @@ -4684,10 +4700,10 @@ void sub_080435C4(void) value |= mode; config = value; } - player = players35C4 + sub_080020F4() * 0x14C; - while (move35C4(player + 0x8C, &position, statePtr, configPtr) == 0) + player = players35C4 + sub_080020F4() * PLAYER_SIZE; + while (move35C4(player + PLAYER_FIELD(0x8C), &position, statePtr, configPtr) == 0) sub_080003F0(); - sub_08028D98(0, 0, (s16)(0xED - (*(s32 *)(heights + sub_080020F4() * 0x14C) >> 8)), 0); + sub_08028D98(0, 0, (s16)(0xED - (*(s32 *)(heights + sub_080020F4() * PLAYER_SIZE) >> 8)), 0); goto loop; } void callback5990C44(u32) asm("sub_0805990C"); @@ -4712,13 +4728,13 @@ void sub_08043664_ptr(void *arg0) s32 raw; u32 message,id; index=sub_080020F4(); - stride=0x14C; + stride=PLAYER_SIZE; stride*=index; playerFirst=players44+stride; - flags=*(u32 *)(playerFirst+0x30); + flags=*(u32 *)(playerFirst+PLAYER_FIELD(0x30)); one=1; flags|=one; - *(u32 *)(playerFirst+0x30)=flags; + *(u32 *)(playerFirst+PLAYER_FIELD(0x30))=flags; sub_0800D0F4(); if(sub_0800CE30()) flag=state44+0x1C6; else flag=state44+0x1BA; @@ -4761,8 +4777,8 @@ void sub_08043664_ptr(void *arg0) } } } - player=players44+0x14C*sub_080020F4(); - *(u32 *)(player+0x30)&=~1; + player=players44+PLAYER_SIZE*sub_080020F4(); + *(u32 *)(player+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); } extern u8 *state44 asm("gUnk_03005CF4"); @@ -4789,17 +4805,21 @@ static inline void t44_markActor(u32 actor) { u8 *slot; u32 record; +#ifdef REGION_USA + register u32 key asm("r1")=actor; +#else register u32 key asm("r2")=actor; +#endif u16 one=1; if(actor>0x100000U) { slot=t44_findSlot(key); if(slot)*(u16 *)(slot+0x42)=one; } else if(actor) { record=actor-1; - if(record<=4){u8 **address=(u8 **)&records44; u32 off=record*0x2E0; u8 *entry=*address; entry+=off; sub_08019EB8(*(u16 *)(entry+2),1);} + if(record<=4){u8 **address=(u8 **)&records44; u32 off=record*ENEMY_SIZE; u8 *entry=*address; entry+=off; sub_08019EB8(*(u16 *)(entry+2),1);} } else { - u8 *player=players44+0x14C*sub_080020F4(); - *(u16 *)(player+0x11E)=one; + u8 *player=players44+PLAYER_SIZE*sub_080020F4(); + *(u16 *)(player+PLAYER_FIELD(0x11E))=one; } } /* [RunActor41TimedAnimationSequence] Finds first active actor resource0x41 among15 slots (returns handle0 if @@ -4831,8 +4851,8 @@ void sub_08043850(void) for(timer=250;timer!=0;timer--){sub_080003F0();if(sub_080021A8())break;} sub_0802926C(actor,7); sub_0802A7DC(); - player=players44+0x14C*sub_080020F4(); - *(u32 *)(player+0x30)|=1; + player=players44+PLAYER_SIZE*sub_080020F4(); + *(u32 *)(player+PLAYER_FIELD(0x30))|=1; sub_0800D0F4(); } extern u8 *state44 asm("gUnk_03005CF4"); @@ -4860,10 +4880,10 @@ void sub_08043A4C(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -4873,10 +4893,10 @@ void sub_08043A4C(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } @@ -4903,10 +4923,10 @@ void sub_08043B20(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -4916,10 +4936,10 @@ void sub_08043B20(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } @@ -4946,10 +4966,10 @@ void sub_08043BF4(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -4959,10 +4979,10 @@ void sub_08043BF4(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } @@ -4989,10 +5009,10 @@ void sub_08043CC8(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -5002,10 +5022,10 @@ void sub_08043CC8(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } @@ -5032,10 +5052,10 @@ void sub_08043D9C(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -5045,10 +5065,10 @@ void sub_08043D9C(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } @@ -5075,10 +5095,10 @@ void sub_08043E70(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -5088,10 +5108,10 @@ void sub_08043E70(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } @@ -5118,10 +5138,10 @@ void sub_08043F44(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -5131,10 +5151,10 @@ void sub_08043F44(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } @@ -5161,10 +5181,10 @@ void sub_08044018(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -5174,10 +5194,10 @@ void sub_08044018(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } @@ -5204,10 +5224,10 @@ void sub_080440EC(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -5217,10 +5237,10 @@ void sub_080440EC(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } @@ -5253,13 +5273,13 @@ void sub_080441C0(void) bit &= one; if (bit != 0) return; index = sub_080020F4(); - stride = 0x14C; + stride = PLAYER_SIZE; stride *= index; playerFirst = players44 + stride; - flags = *(u32 *)(playerFirst + 0x30); + flags = *(u32 *)(playerFirst + PLAYER_FIELD(0x30)); one2 = 1; flags |= one2; - *(u32 *)(playerFirst + 0x30) = flags; + *(u32 *)(playerFirst + PLAYER_FIELD(0x30)) = flags; sub_0800D0F4(); if (sub_0800CE30()) flag = state44 + 0x1C5; @@ -5287,10 +5307,10 @@ void sub_080441C0(void) } } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } /* [ShowEventGatedMessage534] Selects advanced+0x1C6 or normal+0x1BA and tests bit4, equivalent to event28 in @@ -5316,10 +5336,10 @@ void sub_08044318(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -5329,10 +5349,10 @@ void sub_08044318(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } diff --git a/src/code_080443EC.c b/src/code_080443EC.c index 71f2866c..b6d73a9d 100644 --- a/src/code_080443EC.c +++ b/src/code_080443EC.c @@ -27,10 +27,10 @@ void sub_080443EC(void) bit &= one; if (bit == 0) { offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) |= 1; + *(u32 *)(player + PLAYER_FIELD(0x30)) |= 1; sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); while (sub_0805EF90()) sub_080003F0(); @@ -40,10 +40,10 @@ void sub_080443EC(void) sub_080003F0(); } offset = sub_080020F4(); - multiplier = 0x14C; + multiplier = PLAYER_SIZE; offset *= multiplier; player = players44 + offset; - *(u32 *)(player + 0x30) &= ~1; + *(u32 *)(player + PLAYER_FIELD(0x30)) &= ~1; sub_0800D108(); } } @@ -108,14 +108,14 @@ struct Trade44 { u32 rewardType, rewardId, rewardCount, flag, once; }; struct Slot44 { u16 type, id; u8 pad[12]; }; -struct Inv44 { u8 pad[0x150]; struct Slot44 slots[25]; }; +struct Inv44 { u8 pad[SAVE_FIELD(0x150)]; struct Slot44 slots[25]; }; struct GrantM44 {s16 type,id;u8 payload[12];}; struct CurrencyM44 {s16 type;u16 padding;s32 amount;u8 extra[8];}; extern const struct Trade44 trades44[] asm("gUnk_084B1C50"); extern u8 *state5E8 asm("gUnk_03005CF4"); -struct Player44 { u8 pad[0x30]; u32 flags; u8 pad2[0x11E - 0x34]; u16 mark; u8 pad3[0x14C-0x120]; }; +struct Player44 { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 pad2[0x11E - 0x34]; u16 mark; u8 pad3[PLAYER_SIZE-PLAYER_FIELD(0x120)]; }; extern struct Player44 players5E8[] asm("gUnk_03003CE0"); -struct Rec44 { u16 a, id; u8 pad[0x2DC]; }; +struct Rec44 { u16 a, id; u8 pad[ENEMY_SIZE - 4]; }; extern struct Rec44 *records5E8 asm("gUnk_030056F4"); extern struct Inv44 *inventory5E8 asm("gUnk_030034E0"); extern u32 audioFlags5E8 asm("gUnk_030027D0"); @@ -144,19 +144,25 @@ static inline u32 ask5E8(u16 id) static inline u8 *find5E8(u32 actor) { u8 *p; +#ifdef REGION_USA + register u32 key asm("r1") = actor; +#else +#define key actor +#endif register u32 i asm("r3"); s32 raw = (s32)state5E8; u32 off = 0x7A4; p = (u8 *)raw + off; i = 0; do { - if (*(u32 *)p == actor) return p; + if (*(u32 *)p == key) return p; i++; p += 0x70; } while (i <= 14); sub_080003F0(); return NULL; } +#undef key static inline u32 count5E8(u32 type, u32 id) { u32 count = 0; @@ -215,17 +221,24 @@ static inline void mark5E8(u32 target) u32 actor = target; u16 v; +#ifdef REGION_USA + asm("" : "+r"(actor)); +#endif v = 3; if (target > 0x100000) { u8 *p = find5E8(actor); if (p) *(u16 *)(p + 0x42) = v; } else if (target != 0) { u32 i = target - 1; - if (i <= 4) { register u8 **base asm("r1") = (u8 **)&records5E8; s32 raw = i * 0x2E0; base = (u8 **)((u8 *)*base + raw); rec5E8(*(u16 *)((u8 *)base + 2), 3); } +#ifdef REGION_USA + if (i <= 4) { u8 **table = (u8 **)&records5E8; u32 off = i * ENEMY_SIZE; u8 *e = *table; e += off; rec5E8(*(u16 *)(e + 2), 3); } +#else + if (i <= 4) { register u8 **base asm("r1") = (u8 **)&records5E8; s32 raw = i * ENEMY_SIZE; base = (u8 **)((u8 *)*base + raw); rec5E8(*(u16 *)((u8 *)base + 2), 3); } +#endif } else { - s32 raw = sub_080020F4() * 0x14C; + s32 raw = sub_080020F4() * PLAYER_SIZE; s32 v1; - { u8 *base = (u8 *)players5E8; raw += (s32)base; v1 = 0x11E; raw += v1; *(u16 *)raw = v; } + { u8 *base = (u8 *)players5E8; raw += (s32)base; v1 = PLAYER_FIELD(0x11E); raw += v1; *(u16 *)raw = v; } } } static inline void mark2_5E8(u32 target) @@ -239,11 +252,15 @@ static inline void mark2_5E8(u32 target) if (p) *(u16 *)(p + 0x42) = v; } else if (target != 0) { u32 i = target - 1; - if (i <= 4) { register u8 **base asm("r1") = (u8 **)&records5E8; s32 raw = i * 0x2E0; base = (u8 **)((u8 *)*base + raw); rec5E8(*(u16 *)((u8 *)base + 2), 3); } +#ifdef REGION_USA + if (i <= 4) { u8 **table = (u8 **)&records5E8; u32 off = i * ENEMY_SIZE; u8 *e = *table; e += off; rec5E8(*(u16 *)(e + 2), 3); } +#else + if (i <= 4) { register u8 **base asm("r1") = (u8 **)&records5E8; s32 raw = i * ENEMY_SIZE; base = (u8 **)((u8 *)*base + raw); rec5E8(*(u16 *)((u8 *)base + 2), 3); } +#endif } else { - s32 raw = sub_080020F4() * 0x14C; + s32 raw = sub_080020F4() * PLAYER_SIZE; s32 v1; - { u8 *base = (u8 *)players5E8; raw += (s32)base; v1 = 0x11E; raw += v1; *(u16 *)raw = v; } + { u8 *base = (u8 *)players5E8; raw += (s32)base; v1 = PLAYER_FIELD(0x11E); raw += v1; *(u16 *)raw = v; } } } @@ -258,7 +275,7 @@ void sub_080445E8(s32 arg0, u32 arg1) u32 count, i; s32 result; - { u8 *pl = (u8 *)players5E8 + sub_080020F4() * 0x14C; *(u32 *)(pl + 0x30) |= 1; } + { u8 *pl = (u8 *)players5E8 + sub_080020F4() * PLAYER_SIZE; *(u32 *)(pl + PLAYER_FIELD(0x30)) |= 1; } sub_0800D0F4(); second = sub_080020F4(); if (second == 0) @@ -303,7 +320,7 @@ void sub_080445E8(s32 arg0, u32 arg1) break; } end: - { u8 *pl = (u8 *)players5E8 + sub_080020F4() * 0x14C; *(u32 *)(pl + 0x30) &= ~1; } + { u8 *pl = (u8 *)players5E8 + sub_080020F4() * PLAYER_SIZE; *(u32 *)(pl + PLAYER_FIELD(0x30)) &= ~1; } sub_0800D108(); } struct Actor566045 { u32 id; u8 p4[0x14]; u16 x, y; u8 p1C[0x20]; u32 flags; u8 p40[4]; u32 callback; u8 p48[0x28]; }; @@ -441,7 +458,7 @@ static inline void fxEB445(u8 **st) { struct Actor566045 *a; \ sub_0805EFBC(); \ do { sub_080003F0(); } while (sub_0805F184()); \ - { struct Player *pp = (struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0); pp->flags |= one; } \ + { struct Player *pp = (struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0); pp->flags |= one; } \ sub_0800D0F4(); \ fxEB445(st); \ sub_08028AAC(id, 0x78, 0xFA, 0); \ @@ -465,7 +482,7 @@ static inline void fxEB445(u8 **st) { if (ap) { ap->x = x; ap->y = y; ap->flags |= 0x10; } \ setcb566045(st, id, (u32)cbFEA0EB445); \ sub_08068070((u32)cb990CEB445, 0x17); \ - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} \ + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} \ sub_0800D108(); \ } /* [WatchProgressionDialogueChanges] Continuously watches progression bits6/7 in the selected byte1B8/1C4. @@ -555,7 +572,7 @@ void sub_0804534C(void) { u32 a; u32 b; register struct Cmd534C45 *c asm("r0"); - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags |= 1;} + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags |= 1;} sub_0800D0F4(); while (sub_0805F184()) sub_080003F0(); dlg = sub_0805DF38(1, 15, 2, 0, -2, 0x14021C); @@ -594,7 +611,7 @@ void sub_0804534C(void) { FX534C45(next2, check2); } done: - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} sub_0800D108(); } /* [TrackEvent20EntityPosition] Reads1B9/1C5 bit4 and calls28AAC with duration0 in both branches; one-count @@ -790,7 +807,7 @@ void sub_08045B68(u32 arg0) { } while (!bit3B6845(st, one)); } sub_0805EFBC(); do { sub_080003F0(); } while (sub_0805F184()); - { struct Player *pp = (struct Player *)(sub_080020F4() * 0x14C + (u32)gUnk_03003CE0); pp->flags |= 1; } + { struct Player *pp = (struct Player *)(sub_080020F4() * PLAYER_SIZE + (u32)gUnk_03003CE0); pp->flags |= 1; } sub_0800D0F4(); fxB6845(); sub_08068070((u32)cb9968B6845, 0x10); @@ -819,7 +836,7 @@ void sub_08045B68(u32 arg0) { sub_08028AAC(id, 0x78, 0xF0, 0x28); a = find2B6845(id); if (a) *(u16 *)((u8 *)a + 0x36) = 4; - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} sub_0800D108(); } extern void callback5E3845(void) asm("sub_0803898C"); @@ -848,9 +865,9 @@ void sub_08045E38(void) { if (a) { a->x = x; a->y = y; a->flags |= 0x10; } setcb566045(st, id, (u32)callback5E3845); } -struct PlF4445 { u8 p0[0x30]; u32 flags; u8 p34[0x58]; s32 f8C; u8 p90[0x8E]; u16 f11E; u8 p120[0x2C]; }; +struct PlF4445 { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x34)]; s32 f8C; u8 p90[PLAYER_FIELD(0x11E) - PLAYER_FIELD(0x90)]; u16 f11E; u8 p120[PLAYER_SIZE - PLAYER_FIELD(0x120)]; }; struct ItemF4445 { u16 kind, value; u8 pad[12]; }; -struct RecF4445 { u16 f0, f2; u8 pad[0x2DC]; }; +struct RecF4445 { u16 f0, f2; u8 pad[ENEMY_SIZE - 0x4]; }; struct CmdF4445 { u16 kind, value; u8 data[12]; }; extern struct PlF4445 playersF4445[] asm("gUnk_03003CE0"); extern u8 *invF4445 asm("gUnk_030034E0"); @@ -888,7 +905,11 @@ static inline u32 countF4445(u32 n) { return n; } } static inline void setlvF4445(u32 id, u16 v) { struct Actor566045 *ap; +#ifdef REGION_USA + register u32 key asm("r1") = id; +#else register u32 key asm("r2") = id; +#endif u32 level; level = v; @@ -904,7 +925,7 @@ static inline void setlvF4445(u32 id, u16 v) { sub_08019EB8(((struct RecF4445 *)(*table + offset))->f2, v); } } else { - ((struct PlF4445 *)(sub_080020F4() * 0x14C + (u32)playersF4445))->f11E = level; + ((struct PlF4445 *)(sub_080020F4() * PLAYER_SIZE + (u32)playersF4445))->f11E = level; } } /* [RunHamasanDialogue] Sets local player flags bit 0 (input suppression) and BeginLocalPlayerEventLock. Plays @@ -927,7 +948,7 @@ void sub_08045F44(u32 inputId) { struct ItemF4445 *it; struct Actor566045 *ap; - ((struct PlF4445 *)(sub_080020F4() * 0x14C + (u32)playersF4445))->flags |= 1; + ((struct PlF4445 *)(sub_080020F4() * PLAYER_SIZE + (u32)playersF4445))->flags |= 1; sub_0800D0F4(); { s32 coord = playersF4445[sub_080020F4()].f8C; a = coord >> 8; } if (a > 0x1E7) sub_08029174(id, 6); @@ -950,7 +971,7 @@ void sub_08045F44(u32 inputId) { u8 *entry; count = 0; k = 0; - entry = invF4445 + 0x150; + entry = invF4445 + SAVE_FIELD(0x150); do { if (*(u16 *)entry == 5 && *(u16 *)(entry + 2) == 0xA6) count++; @@ -987,10 +1008,10 @@ void sub_08045F44(u32 inputId) { scaled = i * 16; e = base + scaled; - if (*(u16 *)(e + 0x150) == 5 && *(u16 *)(e + 0x152) == 0xA6) { + if (*(u16 *)(e + SAVE_FIELD(0x150)) == 5 && *(u16 *)(e + SAVE_FIELD(0x152)) == 0xA6) { n--; - *(u16 *)(e + 0x150) = clear; - *(u16 *)(e + 0x152) = clear; + *(u16 *)(e + SAVE_FIELD(0x150)) = clear; + *(u16 *)(e + SAVE_FIELD(0x152)) = clear; if (n == 0) goto removedItem; } } @@ -1017,7 +1038,7 @@ void sub_08045F44(u32 inputId) { } end: sub_0802939C(id, 0); - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;} sub_0800D108(); } #undef READ_BIT_F4445 @@ -1042,7 +1063,7 @@ void sub_08046490(u32 arg0){ u8 *data; u32 task; u8 *entity; u8 *found; u32 j; s32 left; u8 *slot; u32 actor; u8 **itemsbase; register u32 v1 asm("r1"); u32 v2; u8 *cmdaddr; u8 *dataptr; u32 off; u32 n; register s32 raw asm("r0"); register u32 zero asm("r5"); s32 b2; s32 b3; s32 b4; s32 b5;register s32 bit asm("r0");u32 off4;u32 off1;register s32 savedCount asm("r6");register s32 playerIndex asm("r5"); - {u32 stride; u8 *base;struct Player *p;register u32 idx asm("r2");register s32 pos asm("r6"); idx=sub_080020F4();stride=0x14C;idx*=stride;base=(u8 *)gUnk_03003CE0;p=(struct Player *)(idx+(u32)base);p->flags|=1;sub_0800D0F4();raw=sub_080020F4()*stride;base+=0x8C;raw=*(s32 *)(raw+(u32)base);pos=raw>>8;if(pos>0x1CD)sub_08029174(arg,6);else sub_08029174(arg,2); } + {u32 stride; u8 *base;struct Player *p;register u32 idx asm("r2");register s32 pos asm("r6"); idx=sub_080020F4();stride=PLAYER_SIZE;idx*=stride;base=(u8 *)gUnk_03003CE0;p=(struct Player *)(idx+(u32)base);p->flags|=1;sub_0800D0F4();raw=sub_080020F4()*stride;base+=PLAYER_FIELD(0x8C);raw=*(s32 *)(raw+(u32)base);pos=raw>>8;if(pos>0x1CD)sub_08029174(arg,6);else sub_08029174(arg,2); } if(sub_0800CE30()) {raw=(s32)state46490;off1=0x1C7;selected=(u8 *)raw+off1;}else {raw=(s32)state46490;off=0x1BB;selected=(u8 *)raw+off;} raw=*selected;b2=raw>>2;bit=1;b2 &= bit; if(sub_0800CE30()) {raw=(s32)state46490;off4=0x1C7;selected=(u8 *)raw+off4;}else {raw=(s32)state46490;off1=0x1BB;selected=(u8 *)raw+off1;} @@ -1059,19 +1080,23 @@ while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub goto finish;} exchange: while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub_0805DF38(1,15,2,0,-1,0x1402AA);while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} - count=0;i=0;item=(struct Item46490 *)(items46490+0x150); + count=0;i=0;item=(struct Item46490 *)(items46490+SAVE_FIELD(0x150)); do {if(load46490(&item->kind)==3 && item->id==0x15)count++;item++;i++;}while(i<=24); savedCount=count;playerIndex=sub_080020F4();if(savedCount && !playerIndex){ actor=arg;flag=3;if(arg>0x100000) { found=find46490(actor); if(found) *(u16 *)(found+0x42)=flag; - } else if(arg) {actor=arg-1;if(actor<=4){u8 **base=(u8 **)&gUnk_030056F4;raw=actor*0x2E0;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} - else {raw=sub_080020F4()*0x14C;{u8 *base=(u8 *)gUnk_03003CE0;raw+=(s32)base;v1=0x11E;raw+=v1;*(u16 *)raw=flag;}} +#ifdef REGION_USA + } else if(arg) {actor=arg-1;if(actor<=4){u8 **table=(u8 **)&gUnk_030056F4;u32 eo=actor*ENEMY_SIZE;u8 *e=*table;e+=eo;sub_08019EB8(*(u16 *)(e+2),3);}} +#else + } else if(arg) {actor=arg-1;if(actor<=4){u8 **base=(u8 **)&gUnk_030056F4;raw=actor*ENEMY_SIZE;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} +#endif + else {raw=sub_080020F4()*PLAYER_SIZE;{u8 *base=(u8 *)gUnk_03003CE0;raw+=(s32)base;v1=PLAYER_FIELD(0x11E);raw+=v1;*(u16 *)raw=flag;}} while(sub_0805F184())sub_080003F0();task=sub_0805DF38(1,15,2,0,-2,0x1402AB);while(!sub_0805EEFC((void *)task))sub_080003F0();flag=sub_0805EF14((u8 *)task);if(flag){data=cmd.data; while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub_0805DF38(1,15,2,0,-1,0x1402AD);while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} left=1;j=0;itemsbase=&items46490;zero=0; loopRemove:raw=(s32)*itemsbase;slot=(u8 *)raw+j*16; - if(*(u16 *)(slot+0x150)!=3 || *(u16 *)(slot+0x152)!=0x15 || (left--,*(u16 *)(slot+0x150)=zero,*(u16 *)(slot+0x152)=zero,left!=0)) {j++;if(j<=24)goto loopRemove;} + if(*(u16 *)(slot+SAVE_FIELD(0x150))!=3 || *(u16 *)(slot+SAVE_FIELD(0x152))!=0x15 || (left--,*(u16 *)(slot+SAVE_FIELD(0x150))=zero,*(u16 *)(slot+SAVE_FIELD(0x152))=zero,left!=0)) {j++;if(j<=24)goto loopRemove;} v1=1;v2=0x1E;cmdaddr=(u8 *)&cmd;*(u16 *)cmdaddr=v1;*(u16 *)(cmdaddr+2)=v2; n=0;dataptr=data;v2=0;do{dataptr[n]=v2;n++;}while(n<=11); @@ -1083,7 +1108,7 @@ while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub_0805DF38(1,15,2,0,-1,0x1402AC);while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} }} finish:sub_0802939C(arg,0); - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); } struct Item469DC { u16 kind,id; u8 data[12]; }; extern u8 *state469DC asm("gUnk_03005CF4"); @@ -1105,7 +1130,7 @@ void sub_080469DC(u32 arg0){ u8 *data; u32 task; u8 *entity; u8 *found; u32 j; s32 left; u8 *slot; u32 actor; u8 **itemsbase; register u32 v1 asm("r1"); u32 v2; u8 *cmdaddr; u8 *dataptr; u32 off; u32 n; register s32 raw asm("r0"); register u32 zero asm("r5"); s32 b2; s32 b3; s32 b4; s32 b5;register s32 bit asm("r0");u32 off4;u32 off1;register s32 savedCount asm("r6");register s32 playerIndex asm("r5"); - {u32 stride; u8 *base;struct Player *p;register u32 idx asm("r2");register s32 pos asm("r6"); idx=sub_080020F4();stride=0x14C;idx*=stride;base=(u8 *)gUnk_03003CE0;p=(struct Player *)(idx+(u32)base);p->flags|=1;sub_0800D0F4();raw=sub_080020F4()*stride;base+=0x8C;raw=*(s32 *)(raw+(u32)base);pos=raw>>8;if(pos>0x224)sub_08029174(arg,5);else sub_08029174(arg,3); } + {u32 stride; u8 *base;struct Player *p;register u32 idx asm("r2");register s32 pos asm("r6"); idx=sub_080020F4();stride=PLAYER_SIZE;idx*=stride;base=(u8 *)gUnk_03003CE0;p=(struct Player *)(idx+(u32)base);p->flags|=1;sub_0800D0F4();raw=sub_080020F4()*stride;base+=PLAYER_FIELD(0x8C);raw=*(s32 *)(raw+(u32)base);pos=raw>>8;if(pos>0x224)sub_08029174(arg,5);else sub_08029174(arg,3); } if(sub_0800CE30()) {raw=(s32)state469DC;off1=0x1C7;selected=(u8 *)raw+off1;}else {raw=(s32)state469DC;off=0x1BB;selected=(u8 *)raw+off;} raw=*selected;b2=raw>>2;bit=1;b2 &= bit; if(sub_0800CE30()) {raw=(s32)state469DC;off4=0x1C7;selected=(u8 *)raw+off4;}else {raw=(s32)state469DC;off1=0x1BB;selected=(u8 *)raw+off1;} @@ -1122,19 +1147,23 @@ while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub goto finish;} exchange: while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub_0805DF38(1,15,2,0,-1,0x1402B3);while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} - count=0;i=0;item=(struct Item469DC *)(items469DC+0x150); + count=0;i=0;item=(struct Item469DC *)(items469DC+SAVE_FIELD(0x150)); do {if(load469DC(&item->kind)==4 && item->id==3)count++;item++;i++;}while(i<=24); savedCount=count;playerIndex=sub_080020F4();if(savedCount && !playerIndex){ actor=arg;flag=3;if(arg>0x100000) { found=find469DC(actor); if(found) *(u16 *)(found+0x42)=flag; - } else if(arg) {actor=arg-1;if(actor<=4){u8 **base=(u8 **)&gUnk_030056F4;raw=actor*0x2E0;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} - else {raw=sub_080020F4()*0x14C;{u8 *base=(u8 *)gUnk_03003CE0;raw+=(s32)base;v1=0x11E;raw+=v1;*(u16 *)raw=flag;}} +#ifdef REGION_USA + } else if(arg) {actor=arg-1;if(actor<=4){u8 **table=(u8 **)&gUnk_030056F4;u32 eo=actor*ENEMY_SIZE;u8 *e=*table;e+=eo;sub_08019EB8(*(u16 *)(e+2),3);}} +#else + } else if(arg) {actor=arg-1;if(actor<=4){u8 **base=(u8 **)&gUnk_030056F4;raw=actor*ENEMY_SIZE;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} +#endif + else {raw=sub_080020F4()*PLAYER_SIZE;{u8 *base=(u8 *)gUnk_03003CE0;raw+=(s32)base;v1=PLAYER_FIELD(0x11E);raw+=v1;*(u16 *)raw=flag;}} while(sub_0805F184())sub_080003F0();task=sub_0805DF38(1,15,2,0,-2,0x1402B4);while(!sub_0805EEFC((void *)task))sub_080003F0();flag=sub_0805EF14((u8 *)task);if(flag){data=cmd.data; while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub_0805DF38(1,15,2,0,-1,0x1402B6);while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} left=1;j=0;itemsbase=&items469DC;zero=0; loopRemove:raw=(s32)*itemsbase;slot=(u8 *)raw+j*16; - if(*(u16 *)(slot+0x150)!=4 || *(u16 *)(slot+0x152)!=3 || (left--,*(u16 *)(slot+0x150)=zero,*(u16 *)(slot+0x152)=zero,left!=0)) {j++;if(j<=24)goto loopRemove;} + if(*(u16 *)(slot+SAVE_FIELD(0x150))!=4 || *(u16 *)(slot+SAVE_FIELD(0x152))!=3 || (left--,*(u16 *)(slot+SAVE_FIELD(0x150))=zero,*(u16 *)(slot+SAVE_FIELD(0x152))=zero,left!=0)) {j++;if(j<=24)goto loopRemove;} v1=1;v2=0x1E;cmdaddr=(u8 *)&cmd;*(u16 *)cmdaddr=v1;*(u16 *)(cmdaddr+2)=v2; n=0;dataptr=data;v2=0;do{dataptr[n]=v2;n++;}while(n<=11); @@ -1146,7 +1175,7 @@ while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub_0805DF38(1,15,2,0,-1,0x1402B5);while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} }} finish:sub_0802939C(arg,0); - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); } struct Item46F28 { u16 kind,id; u8 data[12]; }; extern u8 *state46F28 asm("gUnk_03005CF4"); @@ -1168,7 +1197,7 @@ void sub_08046F28(u32 arg0){ u8 *data; u32 task; u8 *entity; u8 *found; u32 j; s32 left; u8 *slot; u32 actor; u8 **itemsbase; register u32 v1 asm("r1"); u32 v2; u8 *cmdaddr; u8 *dataptr; u32 off; u32 n; register s32 raw asm("r0"); register u32 zero asm("r5"); s32 b2; s32 b3; s32 b4; s32 b5;register s32 bit asm("r0");u32 off4;u32 off1;register s32 savedCount asm("r6");register s32 playerIndex asm("r5"); - {u32 stride; u8 *base;struct Player *p;register u32 idx asm("r2");register s32 pos asm("r6"); idx=sub_080020F4();stride=0x14C;idx*=stride;base=(u8 *)gUnk_03003CE0;p=(struct Player *)(idx+(u32)base);p->flags|=1;sub_0800D0F4();raw=sub_080020F4()*stride;base+=0x8C;raw=*(s32 *)(raw+(u32)base);pos=raw>>8;if(pos>0x1AF)sub_08029174(arg,6);else sub_08029174(arg,2); } + {u32 stride; u8 *base;struct Player *p;register u32 idx asm("r2");register s32 pos asm("r6"); idx=sub_080020F4();stride=PLAYER_SIZE;idx*=stride;base=(u8 *)gUnk_03003CE0;p=(struct Player *)(idx+(u32)base);p->flags|=1;sub_0800D0F4();raw=sub_080020F4()*stride;base+=PLAYER_FIELD(0x8C);raw=*(s32 *)(raw+(u32)base);pos=raw>>8;if(pos>0x1AF)sub_08029174(arg,6);else sub_08029174(arg,2); } if(sub_0800CE30()) {raw=(s32)state46F28;off1=0x1C7;selected=(u8 *)raw+off1;}else {raw=(s32)state46F28;off=0x1BB;selected=(u8 *)raw+off;} raw=*selected;b2=raw>>2;bit=1;b2 &= bit; if(sub_0800CE30()) {raw=(s32)state46F28;off4=0x1C7;selected=(u8 *)raw+off4;}else {raw=(s32)state46F28;off1=0x1BB;selected=(u8 *)raw+off1;} @@ -1185,19 +1214,23 @@ while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub goto finish;} exchange: while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub_0805DF38(1,15,2,0,-1,0x1402BC);while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} - count=0;i=0;item=(struct Item46F28 *)(items46F28+0x150); + count=0;i=0;item=(struct Item46F28 *)(items46F28+SAVE_FIELD(0x150)); do {if(load46F28(&item->kind)==2 && item->id==0x38)count++;item++;i++;}while(i<=24); savedCount=count;playerIndex=sub_080020F4();if(savedCount && !playerIndex){ actor=arg;flag=3;if(arg>0x100000) { found=find46F28(actor); if(found) *(u16 *)(found+0x42)=flag; - } else if(arg) {actor=arg-1;if(actor<=4){u8 **base=(u8 **)&gUnk_030056F4;raw=actor*0x2E0;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} - else {raw=sub_080020F4()*0x14C;{u8 *base=(u8 *)gUnk_03003CE0;raw+=(s32)base;v1=0x11E;raw+=v1;*(u16 *)raw=flag;}} +#ifdef REGION_USA + } else if(arg) {actor=arg-1;if(actor<=4){u8 **table=(u8 **)&gUnk_030056F4;u32 eo=actor*ENEMY_SIZE;u8 *e=*table;e+=eo;sub_08019EB8(*(u16 *)(e+2),3);}} +#else + } else if(arg) {actor=arg-1;if(actor<=4){u8 **base=(u8 **)&gUnk_030056F4;raw=actor*ENEMY_SIZE;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} +#endif + else {raw=sub_080020F4()*PLAYER_SIZE;{u8 *base=(u8 *)gUnk_03003CE0;raw+=(s32)base;v1=PLAYER_FIELD(0x11E);raw+=v1;*(u16 *)raw=flag;}} while(sub_0805F184())sub_080003F0();task=sub_0805DF38(1,15,2,0,-2,0x1402BD);while(!sub_0805EEFC((void *)task))sub_080003F0();flag=sub_0805EF14((u8 *)task);if(flag){data=cmd.data; while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub_0805DF38(1,15,2,0,-1,0x1402BF);while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} left=1;j=0;itemsbase=&items46F28;zero=0; loopRemove:raw=(s32)*itemsbase;slot=(u8 *)raw+j*16; - if(*(u16 *)(slot+0x150)!=2 || *(u16 *)(slot+0x152)!=0x38 || (left--,*(u16 *)(slot+0x150)=zero,*(u16 *)(slot+0x152)=zero,left!=0)) {j++;if(j<=24)goto loopRemove;} + if(*(u16 *)(slot+SAVE_FIELD(0x150))!=2 || *(u16 *)(slot+SAVE_FIELD(0x152))!=0x38 || (left--,*(u16 *)(slot+SAVE_FIELD(0x150))=zero,*(u16 *)(slot+SAVE_FIELD(0x152))=zero,left!=0)) {j++;if(j<=24)goto loopRemove;} v1=1;v2=0x1E;cmdaddr=(u8 *)&cmd;*(u16 *)cmdaddr=v1;*(u16 *)(cmdaddr+2)=v2; n=0;dataptr=data;v2=0;do{dataptr[n]=v2;n++;}while(n<=11); @@ -1209,7 +1242,7 @@ while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub while(sub_0805F184())sub_080003F0();while(sub_0805EF90())sub_080003F0();task=sub_0805DF38(1,15,2,0,-1,0x1402BE);while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} }} finish:sub_0802939C(arg,0); - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); } struct Item47474 { u16 kind,id; u8 data[12]; }; extern u8 *state47474 asm("gUnk_03005CF4"); @@ -1231,7 +1264,7 @@ void sub_08047474(u32 arg0) { struct Player *player; u8 *selected; s32 count; u32 i; struct Item47474 *item; register u8 *data asm("r6"); u32 task; u8 *entity; u8 *found; u32 j; s32 left; u8 *slot; u32 actor; u8 **itemsbase; register u32 v1 asm("r1"); u32 v2; u8 *cmdaddr; register u8 *dataptr asm("r1"); u32 off; u32 n; register s32 raw asm("r0"); register u32 zero asm("r5"); - offset=sub_080020F4();offset*=0x14C;player=(struct Player *)((u8 *)gUnk_03003CE0+offset);raw=player->flags;flag=1;player->flags=raw|flag; + offset=sub_080020F4();offset*=PLAYER_SIZE;player=(struct Player *)((u8 *)gUnk_03003CE0+offset);raw=player->flags;flag=1;player->flags=raw|flag; sub_0800D0F4();sub_0802949C(arg,0); if(sub_0800CE30()) selected=state47474+0x1C4;else {off=0x1B8;selected=state47474+off;} raw=*selected;asm("" : "+r"(raw));raw>>=5;raw &= flag; @@ -1240,21 +1273,25 @@ void sub_08047474(u32 arg0) { while(sub_0805EF90())sub_080003F0(); task=sub_0805DF38(1,15,2,0,-1,0x14022B); while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} - count=0;i=0;item=(struct Item47474 *)(items47474+0x150); + count=0;i=0;item=(struct Item47474 *)(items47474+SAVE_FIELD(0x150)); do {if(load47474(&item->kind)==1 && item->id==0x2A)count++;item++;i++;}while(i<=24); if(count>0) { actor=arg;flag=3;if(actor>0x100000) { found=find47474(actor);data=cmd.data; if(found) *(u16 *)(found+0x42)=flag; - } else if(arg) {actor=arg-1;data=cmd.data;if(actor<=4){u8 **base=(u8 **)&gUnk_030056F4;raw=actor*0x2E0;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} - else {raw=sub_080020F4()*0x14C;{u8 *base=(u8 *)gUnk_03003CE0;raw+=(s32)base;v1=0x11E;raw+=v1;*(u16 *)raw=flag;}data=cmd.data;} +#ifdef REGION_USA + } else if(arg) {actor=arg-1;data=cmd.data;if(actor<=4){u8 **table=(u8 **)&gUnk_030056F4;u32 eo=actor*ENEMY_SIZE;u8 *e=*table;e+=eo;sub_08019EB8(*(u16 *)(e+2),3);}} +#else + } else if(arg) {actor=arg-1;data=cmd.data;if(actor<=4){u8 **base=(u8 **)&gUnk_030056F4;raw=actor*ENEMY_SIZE;base=(u8 **)((u8 *)*base+raw);sub_08019EB8(*(u16 *)((u8 *)base+2),3);}} +#endif + else {raw=sub_080020F4()*PLAYER_SIZE;{u8 *base=(u8 *)gUnk_03003CE0;raw+=(s32)base;v1=PLAYER_FIELD(0x11E);raw+=v1;*(u16 *)raw=flag;}data=cmd.data;} while(sub_0805F184())sub_080003F0(); while(sub_0805EF90())sub_080003F0(); task=sub_0805DF38(1,15,2,0,-1,0x14022D); while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} left=1;j=0;itemsbase=&items47474;zero=0; loopRemove:raw=(s32)*itemsbase;slot=(u8 *)raw+j*16; - if(*(u16 *)(slot+0x150)!=1 || *(u16 *)(slot+0x152)!=0x2A || (left--,*(u16 *)(slot+0x150)=zero,*(u16 *)(slot+0x152)=zero,left!=0)) {j++;if(j<=24)goto loopRemove;} + if(*(u16 *)(slot+SAVE_FIELD(0x150))!=1 || *(u16 *)(slot+SAVE_FIELD(0x152))!=0x2A || (left--,*(u16 *)(slot+SAVE_FIELD(0x150))=zero,*(u16 *)(slot+SAVE_FIELD(0x152))=zero,left!=0)) {j++;if(j<=24)goto loopRemove;} v1=1;v2=0x2B;cmdaddr=(u8 *)&cmd;*(u16 *)cmdaddr=v1;*(u16 *)(cmdaddr+2)=v2; n=0;dataptr=data;v2=0;do{dataptr[n]=v2;n++;}while(n<=11); @@ -1271,7 +1308,7 @@ void sub_08047474(u32 arg0) { task=sub_0805DF38(1,15,2,0,-1,0x140230); while(!sub_0805EEFC((void *)task)){if(sub_0800CDF8()){sub_0805EFBC();break;}sub_080003F0();} } - {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=0x14C;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); + {struct Player *p;register u32 idx asm("r2");idx=sub_080020F4();idx*=PLAYER_SIZE;p=(struct Player *)((u8 *)gUnk_03003CE0+idx);p->flags &= ~1;}sub_0800D108(); } struct Camera778C { u8 pad[0x80]; s16 x,y; }; struct Task778C { u32 f0,f4,f8,fC; u8 *f10; u32 f14,f18,f1C; u8 *f20; u32 f24; }; @@ -1289,7 +1326,7 @@ void sub_0804778C(void) { struct Task778C *t; u32 n; u32 j; u8 *p; s32 flag; register s32 mask asm("r4"); register s32 offset asm("r1"); struct Player *player; u32 cb; u32 one; register u32 *bits asm("r5"); u32 zero; s32 raw; s32 bit; mask=1;flag=bool778C(state778C,0); if(flag) goto already; - offset=sub_080020F4();offset*=0x14C;player=(struct Player *)((u8 *)gUnk_03003CE0+offset);player->flags |= mask; + offset=sub_080020F4();offset*=PLAYER_SIZE;player=(struct Player *)((u8 *)gUnk_03003CE0+offset);player->flags |= mask; sub_0800D0F4(); step=0x400; sx=((struct Camera778C *)&gUnk_03003170)->x; sy=((struct Camera778C *)&gUnk_03003170)->y; i=0; py=&out[1]; tx.all=0; ty.all=0xFF880000; @@ -1313,7 +1350,7 @@ void sub_0804778C(void) { while(sub_0801AAE0()==0)sub_080003F0(); } p=gUnk_030056F4;j=0;bits=(u32 *)&gUnk_030056FC;one=1;zero=0; - do {bit=one<f24=0; sub_08000274(task,6); end6: - index=sub_080020F4(); scale=0x14C;offset=index;offset*=scale;actor=t47DActors+offset; - *(u32 *)(actor+0x30)&=~1; + index=sub_080020F4(); scale=PLAYER_SIZE;offset=index;offset*=scale;actor=t47DActors+offset; + *(u32 *)(actor+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); timer=60; goto wait65; @@ -2277,15 +2314,15 @@ void sub_08048570(s32 arg0) p=t47DPlayers; j=0;mask=&t47DMask;one=1;zero=0; do { if(((one<> 5) & mask; other = sub_080020F4(); - count=0; i=0; loaded=(s32)t48Items; off1=0x150; p=(struct T48Item *)((u8 *)loaded+off1); + count=0; i=0; loaded=(s32)t48Items; off1=SAVE_FIELD(0x150); p=(struct T48Item *)((u8 *)loaded+off1); do { if (t48id(p)==1 && p->kind==0x2A) count++; p++; i++; } while(i<=24); - saved=count; count2=0; j=0; bits=flag|other; loaded=(s32)t48Items; off=0x2E0; q=(struct T48Item *)((u8 *)loaded+off); + saved=count; count2=0; j=0; bits=flag|other; loaded=(s32)t48Items; off=SAVE_FIELD(0x2E0); q=(struct T48Item *)((u8 *)loaded+off); do { if (t48id(q)==1 && q->kind==0x2A) count2++; q++; j++; @@ -3406,8 +3443,8 @@ static inline void t48musicE(u32 track) { register u32 v asm("r1")=track; gUnk_ * increment34, starts song11, sets scene halfword+4 bit5 and unlocks. */ void sub_08049EBC(void) { s32 off; u16 n; s32 v; u32 req; u8 *p; register s32 idx asm("r2"); s32 mask; u8 *gp; register u8 *gp2 asm("r2"); u32 word; u32 req3; register u32 hv asm("r1"); - idx=sub_080020F4()*0x14C; p=(u8 *)gUnk_03003CE0+idx; - *(u32 *)(p+0x30)|=1; + idx=sub_080020F4()*PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+idx; + *(u32 *)(p+PLAYER_FIELD(0x30))|=1; sub_0800D0F4(); if(sub_08002164()==1) off=0; else switch(sub_080020F4()) { case 0: off=-12; break; case 1: off=12; break; case 2: off=-36; break; case 3: off=36; break; } @@ -3425,7 +3462,7 @@ void sub_08049EBC(void) { t48moveE(34,0,0); t48musicE(11); hv=*(u16 *)(t48stateE+4); word=hv|32; *(u16 *)(t48stateE+4)=word; - idx=sub_080020F4()*0x14C; p=(u8 *)gUnk_03003CE0+idx; *(u32 *)(p+0x30)&=~1; + idx=sub_080020F4()*PLAYER_SIZE; p=(u8 *)gUnk_03003CE0+idx; *(u32 *)(p+PLAYER_FIELD(0x30))&=~1; sub_0800D108(); } @@ -3464,13 +3501,13 @@ void sub_0804A188(void){ u32 bit;u8 *player;u8 *base;register u32 one asm("r4");register s32 *flags asm("r5"); u8 *p; u32 i; u32 shifted; register u32 stride asm("r0"); base=t48stateA;one=1;bit=t48boolA(base,one); asm("" : "+r"(bit)); if(!bit){ - player=(u8 *)gUnk_03003CE0+0x14c*sub_080020F4();*(u32 *)(player+0x30)|=one;sub_0800D0F4();*(u32 *)(t48stateA+0x38)|=one; + player=(u8 *)gUnk_03003CE0+PLAYER_SIZE*sub_080020F4();*(u32 *)(player+PLAYER_FIELD(0x30))|=one;sub_0800D0F4();*(u32 *)(t48stateA+0x38)|=one; t48moveA(0x400,0,-60);t48taskA(sub_0804A478,0);t48waitA(2);t48modeA();t48musicA(196); return; } t48modeA();sub_0802A080(140,130,200,100);t48taskA(sub_0804A89C,5);t48taskA(sub_0804A89C,6);t48waitA(30); - p=t48objA;i=0;flags=&gUnk_030056FC;do{shifted=1<unk2==35)count++;p++;i++;}while(i<=24);var_r3=count;}var_r3_2=t48countSecondB(0x2E0,74); + {s32 count;u32 i;struct T48ItemB *p;u8 **slot;u8 *base;u32 off;count=0;i=0;pad=sp8.pad;slot=&t48itemsB;base=*slot;off=SAVE_FIELD(0x150);p=(struct T48ItemB *)(base+off);do{if(t48idB(p)==1&&p->unk2==35)count++;p++;i++;}while(i<=24);var_r3=count;}var_r3_2=t48countSecondB(SAVE_FIELD(0x2E0),74); if (sub_0800CE30() != 0) { var_r0 = t48stateB+0x1C5; } else { @@ -3713,7 +3750,7 @@ void t48implB(u32 arg0) { sub_0802949C(1, 0); return; case 6: - obj=t48objB;off6=0x2E0;sub_08019EB8(*(u16 *)(obj+off6+2), 3); + obj=t48objB;off6=ENEMY_SIZE;sub_08019EB8(*(u16 *)(obj+off6+2), 3); sub_0802949C(2, 0); return; } @@ -3849,7 +3886,7 @@ void sub_0804B054(s32 arg0) break; } } -struct T49EntityB100 { u8 pad[12]; u16 state; u8 padE[0x22]; u32 x, y; void *callback; u32 arg; u8 tail[0x2A0]; }; +struct T49EntityB100 { u8 pad[12]; u16 state; u8 padE[0x22]; u32 x, y; void *callback; u32 arg; u8 tail[ENEMY_SIZE - 0x40]; }; extern struct T49EntityB100 *t49_entitiesB100 asm("gUnk_030056F4"); extern u8 *t49_gsB100 asm("gUnk_03005CF4"); extern void t49_cbB100(void) asm("sub_0804B32C"); @@ -3867,13 +3904,17 @@ static inline void t49_bindB100(void *callback, u32 arg, s16 index) u32 i; s32 slot = index; u32 offset; +#ifdef REGION_USA + register struct T49EntityB100 **table asm("r2"); +#else register struct T49EntityB100 **table asm("r1"); +#endif struct T49EntityB100 *entity; s32 *bits; u32 one; t49_waitMaskB100(arg); table = &t49_entitiesB100; - offset = slot * 0x2E0; + offset = slot * ENEMY_SIZE; p = *table; entity = (struct T49EntityB100 *)((u8 *)p + offset); entity->callback = callback; @@ -4372,7 +4413,7 @@ extern u8 *t49_gsBC38 asm("gUnk_03005CF4"); extern void t49_taskBC38(void) asm("sub_0805A874"); void sub_0804BEF8(u32 arg0); struct T49EntryBC38 { u32 id, kind; u8 pad[0x3A]; u16 state; u8 tail[0x2C]; }; -struct T49EntityBC38 { u16 f0,id; u8 pad[0x2DC]; }; +struct T49EntityBC38 { u16 f0,id; u8 pad[ENEMY_SIZE - 4]; }; extern struct T49EntityBC38 *t49_entitiesBC38 asm("gUnk_030056F4"); static inline void t49_lockBC38(void) { struct Player *p = &gUnk_03003CE0[sub_080020F4()]; p->flags |= 1; } @@ -4428,7 +4469,11 @@ static inline struct T49EntryBC38 *t49_findBC38(u32 actor) static inline void t49_stateBC38(u32 actor) { register u32 current asm("r5")=actor; +#ifdef REGION_USA + register u32 savedActor asm("r1")=current; +#else register u32 savedActor asm("r2")=current; +#endif u16 state; struct T49EntryBC38 *p; state=3; @@ -4439,14 +4484,18 @@ static inline void t49_stateBC38(u32 actor) u32 index=current-1; if(index<=4) { struct T49EntityBC38 **table=&t49_entitiesBC38; - register u32 offset asm("r0")=index*0x2E0; +#ifdef REGION_USA + u32 offset=index*ENEMY_SIZE; +#else + register u32 offset asm("r0")=index*ENEMY_SIZE; +#endif struct T49EntityBC38 *entity=*table; entity=(struct T49EntityBC38 *)((u8 *)entity+offset); sub_08019EB8(entity->id,3); } } else { u32 index=sub_080020F4(); - u32 stride=0x14C; + u32 stride=PLAYER_SIZE; u8 *player; u8 *players; u32 offset; @@ -4454,7 +4503,7 @@ static inline void t49_stateBC38(u32 actor) players=(u8 *)gUnk_03003CE0; index+=(u32)players; player=(u8 *)index; - offset=0x11E; + offset=PLAYER_FIELD(0x11E); player+=offset; *(u16 *)player=state; } @@ -4598,7 +4647,7 @@ void sub_0804BEF8(u32 arg0) sub_0800D0F4(); count = 0; i = 0; - p = (u16 *)(t49_itemsBEF8 + 0x150); + p = (u16 *)(t49_itemsBEF8 + SAVE_FIELD(0x150)); do { if (p[0] == 1 && p[1] == 0x22) count++; p += 8; @@ -5270,7 +5319,7 @@ void sub_0804CBBC(void){ entry=gUnk_030056F4;idx=0;entryFlags=&gUnk_030056FC;callback=1;zero=0; clearFirst: if((*entryFlags & (bitTemp=callback<flags |= 32; @@ -1023,7 +1023,21 @@ void sub_0804EABC(void) { waitOne = 1; do { sub_080003F0(); } while (!(*waitFlags & waitOne)); } +#ifdef REGION_USA + { + u8 **table = (u8 **)&entities51EA; + u32 eo = ENEMY_SIZE; + u32 idx = 0; + u8 *e; + asm("" : "+r"(idx)); + eo *= idx; + e = *table; + e += eo; + entity = (struct Entity51EA *)e; + } +#else entity = entities51EA; +#endif entity->f38 = var_r7; entity->f3C = fieldOne; zero = 0; @@ -1344,7 +1358,7 @@ extern void sub_08029174(s32,s32); extern void callback51F128(s32) asm("sub_0804F390"); struct Task51F1 { u32 f0,f4,f8,fC,f10,f14,f18,f1C,f20,f24; }; extern void taskStart51F1(void *,u32) asm("sub_08000274"); -struct Player51F1 { u8 a[0x11E]; u16 f11E; u8 b[0x14C-0x120]; }; +struct Player51F1 { u8 a[PLAYER_FIELD(0x11E)]; u16 f11E; u8 b[PLAYER_SIZE-PLAYER_FIELD(0x120)]; }; extern struct Player51F1 players51F1[] asm("gUnk_03003CE0"); struct Flag51F1 { u32 pad; u16 flags; }; /* [StageActor1Dialogue93] Locks input, offsets actor0 by multiplayer position, places actor1(120,240), @@ -1927,7 +1941,7 @@ void sub_0804FA68(s32 arg0) { break; } } -struct PlayerFB0C { u8 pad[0x30]; u32 flags; u8 tail[0x14C-0x34]; }; +struct PlayerFB0C { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; struct StateFB0C { u8 pad[4]; u16 flags; }; extern struct PlayerFB0C playersFB0C[] asm("gUnk_03003CE0"); extern struct StateFB0C *stateFB0C asm("gUnk_03005CF4"); @@ -1986,7 +2000,7 @@ while (sub_0805EEFC((void *) temp_r4) == 0) sub_080003F0(); sub_0800D108(); } -struct PlayerFC3C { u8 pad[0x30]; u32 flags; u8 tail[0x14C-0x34]; }; +struct PlayerFC3C { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; struct StateFC3C { u8 pad[4]; u16 flags; u8 pad6[0x38-6]; u32 eventFlags; }; extern struct PlayerFC3C playersFC3C[] asm("gUnk_03003CE0"); extern struct StateFC3C *stateFC3C asm("gUnk_03005CF4"); @@ -2146,8 +2160,8 @@ while (sub_0805EEFC((void *) handle) == 0) sub_080003F0(); sub_0800D108(); } -struct PlayerFF04 { u8 pad[0x30]; u32 flags; u8 tail[0x14C-0x34]; }; -struct EntityFF04 { u8 pad[0xC]; u16 state; u8 tail[0x2E0-0xE]; }; +struct PlayerFF04 { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; +struct EntityFF04 { u8 pad[0xC]; u16 state; u8 tail[ENEMY_SIZE-0xE]; }; struct StateFF04 { u8 pad[0x38]; u32 events; }; extern struct PlayerFF04 playersFF04[] asm("gUnk_03003CE0"); extern struct EntityFF04 *entitiesFF04 asm("gUnk_030056F4"); @@ -2290,7 +2304,7 @@ while (sub_0805EEFC((void *) temp_r4) == 0) sub_080003F0(); var_r2_3->state = entityZero; } var_r3_3 += 1; - flag0=0x2E0; var_r2_3=(struct EntityFF04 *)((u8 *)var_r2_3+flag0); + flag0=ENEMY_SIZE; var_r2_3=(struct EntityFF04 *)((u8 *)var_r2_3+flag0); } while (var_r3_3 <= 4U); } else { temp_r2_3 = &playersFF04[sub_080020F4()]; @@ -2312,7 +2326,7 @@ while (sub_0805EEFC((void *) temp_r4) == 0) sub_080003F0(); var_r2_2->state = entityZero; } var_r3_2 += 1; - a1=0x2E0; var_r2_2=(struct EntityFF04 *)((u8 *)var_r2_2+a1); + a1=ENEMY_SIZE; var_r2_2=(struct EntityFF04 *)((u8 *)var_r2_2+a1); } while (var_r3_2 <= 4U); } sub_08019F04(); @@ -2352,7 +2366,7 @@ while (sub_0801AAE0() == 0) sub_080003F0(); var_r2->state = entityZero; } var_r3 += 1; - flag0=0x2E0; var_r2=(struct EntityFF04 *)((u8 *)var_r2+flag0); + flag0=ENEMY_SIZE; var_r2=(struct EntityFF04 *)((u8 *)var_r2+flag0); } while (var_r3 <= 4U); sub_08019F04(); @@ -2361,7 +2375,7 @@ while (sub_0801AAE0() == 0) sub_080003F0(); return; } -struct Player502DC { u8 pad[0x30]; u32 flags; u8 tail[0x14C-0x34]; }; +struct Player502DC { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; struct Slot502DC { s32 id; u8 pad[0x32]; u16 state; u8 tail[0x38]; }; struct State502DC { u8 pad0[4]; u16 flags; u8 pad6[0x7A4-6]; struct Slot502DC slots[15]; }; extern struct State502DC *state502DC asm("gUnk_03005CF4"); @@ -2395,7 +2409,7 @@ void sub_080502DC(void) { else wait = 1; } while (wait != 0); offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; player = (struct Player502DC *)((u8 *)players502DC + offset); player->flags |= 1; sub_0800D0F4(); @@ -2441,7 +2455,7 @@ void sub_080502DC(void) { } if (slot != 0) slot->state = 4; offset = sub_080020F4(); - offset *= 0x14C; + offset *= PLAYER_SIZE; player = (struct Player502DC *)((u8 *)players502DC + offset); player->flags &= ~1; sub_0800D108(); @@ -2538,7 +2552,7 @@ void sub_08050524(s32 arg0) { } } struct State505C8 { u8 pad[0x38]; u32 flags; }; -struct Entity505C8 { u8 pad[0xC]; u16 state; u8 tail[0x2E0-0xE]; }; +struct Entity505C8 { u8 pad[0xC]; u16 state; u8 tail[ENEMY_SIZE-0xE]; }; extern struct State505C8 *state505C8 asm("gUnk_03005CF4"); extern struct Entity505C8 *entities505C8 asm("gUnk_030056F4"); /* [ResetEnemiesAfterConditionalDelay] Body's flags4 test gates30-signal wait; final five-slot active-mask scan @@ -2588,12 +2602,12 @@ void sub_080505C8(void) { bit = one << i; if ((*bits & bit) && entity->state == 12) entity->state = zero; i++; - stride = 0x2E0; + stride = ENEMY_SIZE; entity = (struct Entity505C8 *)((u8 *)entity + stride); } while (i <= 4); sub_08019F04(); } -struct PlayerF50688 { u8 pad[0x30]; u32 flags; u8 tail[0x14C-0x34]; }; +struct PlayerF50688 { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; struct SlotF50688 { s32 id; u8 pad[0x32]; u16 state; u8 tail[0x38]; }; struct StateF50688 { u8 pad[4]; u16 flags; u8 pad6[0x38-6]; u32 eventFlags; u8 pad3C[0x7A4-0x3C]; struct SlotF50688 slots[15]; }; extern struct PlayerF50688 playersF50688[] asm("gUnk_03003CE0"); @@ -2772,8 +2786,8 @@ while (sub_0805EEFC((void *) handle) == 0) sub_080003F0(); sub_0800D108(); } -struct Player509A8 { u8 pad[0x30]; u32 flags; u8 tail[0x14C-0x34]; }; -struct Entity509A8 { u8 pad[0xC]; u16 state; u8 tail[0x2E0-0xE]; }; +struct Player509A8 { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; +struct Entity509A8 { u8 pad[0xC]; u16 state; u8 tail[ENEMY_SIZE-0xE]; }; struct Task509A8 { u32 f0,f4,flags; void (*callback)(void); u8 *stack; u32 f14,f18,f1C; u8 *memory; u32 data; }; struct State509A8 { u8 pad0[0x38]; u32 events; u8 pad3C[0xE34-0x3C]; struct Task509A8 tasks[30]; }; extern struct Player509A8 players509A8[] asm("gUnk_03003CE0"); @@ -2873,7 +2887,7 @@ while ((temp_r0_2 = sub_08001494(0x400U), var_r4->memory = temp_r0_2, temp_r0_2 } var_r9 = var_r0_2; if (var_r0_2 != 0) goto already; - flag0=sub_080020F4(); a1=0x14C; a1 *= flag0; + flag0=sub_080020F4(); a1=PLAYER_SIZE; a1 *= flag0; a0=(s32 *)players509A8; temp_r1=(struct Player509A8 *)(a1+(u32)a0); temp_r1->flags |= initialOne; sub_0800D0F4(); @@ -3024,7 +3038,7 @@ while (sub_0801AAE0() == 0) sub_080003F0(); var_r2_2->state = entityZero; } var_r3_2 += 1; - a1=0x2E0; var_r2_2=(struct Entity509A8 *)((u8 *)var_r2_2+a1); + a1=ENEMY_SIZE; var_r2_2=(struct Entity509A8 *)((u8 *)var_r2_2+a1); } while (var_r3_2 <= 4U); sub_08019F04(); return; @@ -3055,12 +3069,12 @@ while (sub_0801AAE0() == 0) sub_080003F0(); var_r2->state = entityZero; } var_r3 += 1; - flag0=0x2E0; var_r2=(struct Entity509A8 *)((u8 *)var_r2+flag0); + flag0=ENEMY_SIZE; var_r2=(struct Entity509A8 *)((u8 *)var_r2+flag0); } while (var_r3 <= 4U); sub_08019F04(); return; } -struct T53Entity0E48 { u16 f0,id; u8 pad[8]; u16 state; u8 tail[0x2D2]; }; +struct T53Entity0E48 { u16 f0,id; u8 pad[8]; u16 state; u8 tail[ENEMY_SIZE - 0xE]; }; extern struct T53Entity0E48 *t53_entities0E48 asm("gUnk_030056F4"); struct T53Task0E48 { u32 f0, f4, flags, callback, stack, f14, f18, f1C, memory, arg; }; extern u8 *t53_gs0E48 asm("gUnk_03005CF4"); @@ -3270,7 +3284,7 @@ void sub_08051A78(void) pos.y=0x5800; pos.packed=0x180010; p=&gUnk_03003CE0[sub_080020F4()]; - while(!t53_transformA78((u8 *)p+0x8C,&pos.x,&pos.zero,&pos.packed))sub_080003F0(); + while(!t53_transformA78((u8 *)p+PLAYER_FIELD(0x8C),&pos.x,&pos.zero,&pos.packed))sub_080003F0(); {struct Player *q=&gUnk_03003CE0[sub_080020F4()]; value=q->flags; one=1; @@ -3298,7 +3312,7 @@ void sub_08051A78(void) t53_unlockA78(); sub_0800D108(); } -struct T53EntityBFC { u16 f0,id; u8 pad[8]; u16 state; u8 tail[0x2D2]; }; +struct T53EntityBFC { u16 f0,id; u8 pad[8]; u16 state; u8 tail[ENEMY_SIZE - 0xE]; }; extern struct T53EntityBFC *t53_entitiesBFC asm("gUnk_030056F4"); extern u8 *t53_gsBFC asm("gUnk_03005CF4"); static inline void t53_waitBFC(u16 value) @@ -3386,7 +3400,7 @@ static inline void t53_startCE4(void *cb, u32 value, u32 mode) sub_080003F0(); sub_080003F0(); } -struct T53EntityCE4 { u16 f0,id; u8 pad[8]; u16 state; u8 tail[0x2D2]; }; +struct T53EntityCE4 { u16 f0,id; u8 pad[8]; u16 state; u8 tail[ENEMY_SIZE - 0xE]; }; extern struct T53EntityCE4 *t53_entitiesCE4 asm("gUnk_030056F4"); static inline void t53_clearCE4(u16 one) { @@ -3945,7 +3959,7 @@ void sub_08053120(s32 arg0) break; } } -struct P31C4 { u8 pad[0x64]; u16 state; u8 rest[0x14C - 0x66]; }; +struct P31C4 { u8 pad[PLAYER_FIELD(0x64)]; u16 state; u8 rest[PLAYER_SIZE - PLAYER_FIELD(0x66)]; }; extern struct P31C4 t53_players31C4[] asm("gUnk_03003CE0"); static inline u8 t53_busy31C4(void) { @@ -4167,7 +4181,7 @@ extern u32 gW03005CF8 asm("gUnk_03005CF8"); extern u32 gW030027D0 asm("gUnk_030027D0"); extern u8 *gP030056F4 asm("gUnk_030056F4"); extern u32 gM030056FC asm("gUnk_030056FC"); -struct E2E0a { u8 b[0xC]; u16 hC; u8 r[0x2E0 - 0xE]; }; +struct E2E0a { u8 b[0xC]; u16 hC; u8 r[ENEMY_SIZE - 0xE]; }; static inline void SetMode53A80(u32 m) { gW03005CF8 = m; @@ -4177,7 +4191,7 @@ static inline void SetMode53A80(u32 m) static inline void Clr53A80(u8 *p) { u32 i; - for (i = 0; i <= 4; i++, p += 0x2E0) + for (i = 0; i <= 4; i++, p += ENEMY_SIZE) if ((gM030056FC & (1 << i)) && *(u16 *)(p + 0xC) == 0xC) *(u16 *)(p + 0xC) = 0; } @@ -4280,7 +4294,7 @@ void sub_08053C5C(void) base = gUnk_030056F4; sub_08019EB8(*(u16 *)(base + 2), 3); base = gUnk_030056F4; - nextOffset = 0x2E0; + nextOffset = ENEMY_SIZE; base += nextOffset; sub_08019EB8(*(u16 *)(base + 2), 3); if (!(gUnk_030027D0 & 0x20)) @@ -4296,7 +4310,7 @@ void sub_08053C5C(void) if ((*flags & (one << i)) && *(u16 *)(entity + 0xC) == 12) *(u16 *)(entity + 0xC) = zero; i++; - stride = 0x2E0; + stride = ENEMY_SIZE; entity += stride; } while (i <= 4); sub_08019F04(); @@ -4366,7 +4380,7 @@ static inline void bind53E(void (*cb)(s32), s16 mask, s16 slot) if ((gUnk_030056FC & m) == 0) { do { sub_080003F0(); } while ((gUnk_030056FC & mask) == 0); } - e = gP030056F4 + i * 0x2E0; + e = gP030056F4 + i * ENEMY_SIZE; *(void (**)(s32))(e + 0x38) = f; *(u32 *)(e + 0x3C) = m; *(u32 *)(e + 0x30) = 0; diff --git a/src/code_080542C4.c b/src/code_080542C4.c index 21eade14..9510de6b 100644 --- a/src/code_080542C4.c +++ b/src/code_080542C4.c @@ -159,7 +159,7 @@ extern u32 gW03005CF8 asm("gUnk_03005CF8"); extern u32 gW030027D0 asm("gUnk_030027D0"); extern u8 *gP030056F4 asm("gUnk_030056F4"); extern u32 gM030056FC asm("gUnk_030056FC"); -struct E2E0a { u8 b[0xC]; u16 hC; u8 r[0x2E0 - 0xE]; }; +struct E2E0a { u8 b[0xC]; u16 hC; u8 r[ENEMY_SIZE - 0xE]; }; static inline void SetMode53A80(u32 m) { gW03005CF8 = m; @@ -169,7 +169,7 @@ static inline void SetMode53A80(u32 m) static inline void Clr53A80(u8 *p) { u32 i; - for (i = 0; i <= 4; i++, p += 0x2E0) + for (i = 0; i <= 4; i++, p += ENEMY_SIZE) if ((gM030056FC & (1 << i)) && *(u16 *)(p + 0xC) == 0xC) *(u16 *)(p + 0xC) = 0; } @@ -963,7 +963,7 @@ static inline void Walk56(u32 x, u32 y, u32 a, u32 b) b <<= 16; packed = (a >> 16) | b; entry = (u8 *)&gUnk_03003CE0[sub_080020F4()]; - while (sub_08021FE0(entry + 0x8C, pos, &result, &packed) == 0) + while (sub_08021FE0(entry + PLAYER_FIELD(0x8C), pos, &result, &packed) == 0) sub_080003F0(); } /* [RunRepeatingRegionDamage] Waits until local player intersects table-selected rectangle, calls29CEC with @@ -997,8 +997,8 @@ static inline s32 Walk98(u32 x, u32 y, u32 a, u32 b) b <<= 16; packed = (a >> 16) | b; entry = (u8 *)&gUnk_03003CE0[sub_080020F4()]; - while (sub_08021FE0(entry + 0x8C, pos, &result, &packed) == 0 || - !(*(u16 *)(entry + 0x14) & 1)) { + while (sub_08021FE0(entry + PLAYER_FIELD(0x8C), pos, &result, &packed) == 0 || + !(*(u16 *)(entry + PLAYER_FIELD(0x14)) & 1)) { if (sub_08058608()) return 0; sub_080003F0(); } @@ -1026,10 +1026,10 @@ void sub_0805664C(s32 arg0) spawn56(sub_0805664C, arg0); } } -struct StatePlayer567D4 { u8 pad[0x11E]; u16 state; u8 tail[0x2C]; }; +struct StatePlayer567D4 { u8 pad[PLAYER_FIELD(0x11E)]; u16 state; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x120)]; }; extern struct StatePlayer567D4 statePlayers567D4[] asm("gUnk_03003CE0"); struct Item567D4 { u16 item, kind; u8 rest[12]; }; -struct Inv567D4 { u8 pad[0x150]; struct Item567D4 slots[25]; }; +struct Inv567D4 { u8 pad[SAVE_FIELD(0x150)]; struct Item567D4 slots[25]; }; extern struct Inv567D4 *inv567D4 asm("gUnk_030034E0"); struct Gate567D4 { u32 x, y, w, h, item, kind, need, flag, bitflag, param, event; }; extern struct Gate567D4 gates567D4[] asm("gUnk_084B23A8"); @@ -1132,17 +1132,17 @@ void sub_080567D4(s32 id) ybase = -(-ybase + 1) + 1; do { Wait567D4(); - x = *(s32 *)(xbase + sub_080020F4() * 0x14C) >> 8; - y = *(s32 *)(ybase + sub_080020F4() * 0x14C) >> 8; + x = *(s32 *)(xbase + sub_080020F4() * PLAYER_SIZE) >> 8; + y = *(s32 *)(ybase + sub_080020F4() * PLAYER_SIZE) >> 8; } while (x >= gates567D4[id].x - hw && x <= gates567D4[id].x + hw && y >= gates567D4[id].y - hh && y <= gates567D4[id].y + hh); } do { Wait567D4(); - x = *(s32 *)(playerX567D4 + sub_080020F4() * 0x14C) >> 8; + x = *(s32 *)(playerX567D4 + sub_080020F4() * PLAYER_SIZE) >> 8; /* The Y base goes through a pointer local, which puts it in r7 like ROM. */ flags = playerY567D4; - y = *(s32 *)(flags + sub_080020F4() * 0x14C) >> 8; + y = *(s32 *)(flags + sub_080020F4() * PLAYER_SIZE) >> 8; } while (x < gates567D4[id].x - hw || x > gates567D4[id].x + hw || y < gates567D4[id].y - hh || y > gates567D4[id].y + hh); ret = sub_0800CCCC(); @@ -1259,13 +1259,13 @@ u32 sub_08056D80(s16 *pos, u16 rx, u16 ry) return 0; for (i = 0; i < n; i++) { u8 *p = (u8 *)&gUnk_03003CE0[i]; - struct Bits56D80 *b = *(struct Bits56D80 **)(p + 0x148); + struct Bits56D80 *b = *(struct Bits56D80 **)(p + PLAYER_FIELD(0x148)); s32 d; s32 e; f = b->f; if (f & 0x20) continue; - if (*(u32 *)(p + 0x30) & 0x2000) + if (*(u32 *)(p + PLAYER_FIELD(0x30)) & 0x2000) continue; { u32 bx = b->x; diff --git a/src/code_08057CAC.c b/src/code_08057CAC.c index c71b05e9..f2633aba 100644 --- a/src/code_08057CAC.c +++ b/src/code_08057CAC.c @@ -208,7 +208,7 @@ void sub_08057F18(u32 x, u32 y, u16 type, u16 value, u32 arg4, u32 arg5) * then call19EB8; selector0 writes player11E. */ void sub_08057FBC(u32 selector, u32 value) { - struct PlayerValue { u8 pad[0x11E]; u16 value; u8 tail[0x2C]; }; + struct PlayerValue { u8 pad[PLAYER_FIELD(0x11E)]; u16 value; u8 tail[0x2C]; }; u16 *target; if (selector > 0x100000) { u8 *entry = (u8 *)gUnk_03005CF4 + 0x7A4; @@ -230,7 +230,7 @@ void sub_08057FBC(u32 selector, u32 value) selector--; if (selector <= 4) { void **address = &gUnk_030056F4; - u32 offset = selector * 0x2E0; + u32 offset = selector * ENEMY_SIZE; u8 *slot = *address; slot += offset; sub_08019EB8(*(u16 *)(slot + 2), (u16)value); @@ -238,9 +238,9 @@ void sub_08057FBC(u32 selector, u32 value) return; } else { u32 index = sub_080020F4(); - index *= 0x14C; + index *= PLAYER_SIZE; target = (u16 *)(index + (u32)gUnk_03003CE0); - target = (u16 *)((u8 *)target + 0x11E); + target = (u16 *)((u8 *)target + PLAYER_FIELD(0x11E)); } *target = value; } @@ -284,7 +284,7 @@ s32 sub_08058094(void) register s32 *saved asm("r4"); total = 0; state = &gUnk_030034E0; - entry = (u8 *)*state + 0x150; + entry = (u8 *)*state + SAVE_FIELD(0x150); saved = state; i = 24; do { @@ -293,8 +293,8 @@ s32 sub_08058094(void) i--; entry += 16; } while (i >= 0); - other = (u8 *)*saved + 0x2E0; - temp = *(u16 *)((u8 *)*saved + 0x6A) * 15; + other = (u8 *)*saved + SAVE_FIELD(0x2E0); + temp = *(u16 *)((u8 *)*saved + SAVE_FIELD(0x6A)) * 15; if (temp > 0) { j = temp; do { @@ -323,10 +323,10 @@ u32 sub_080580F8(u32 a, u32 b) u32 count = 0; u32 i = 0; u8 *initial = (u8 *)gUnk_030034E0; - u16 *first = (u16 *)(initial + 0x2e0); + u16 *first = (u16 *)(initial + SAVE_FIELD(0x2e0)); u8 *base = initial; for (; i <= 0x4a; first += 8, base += 16, i++) - if (*first == a && *(u16 *)(base + 0x2e2) == b) + if (*first == a && *(u16 *)(base + SAVE_FIELD(0x2e2)) == b) count++; return count; } @@ -338,10 +338,10 @@ u32 sub_0805813C(u32 a, u32 b) u32 count = 0; u32 i = 0; u8 *initial = (u8 *)gUnk_030034E0; - u16 *first = (u16 *)(initial + 0x150); + u16 *first = (u16 *)(initial + SAVE_FIELD(0x150)); u8 *base = initial; for (; i <= 0x18; first += 8, base += 16, i++) - if (*first == a && *(u16 *)(base + 0x152) == b) + if (*first == a && *(u16 *)(base + SAVE_FIELD(0x152)) == b) count++; return count; } @@ -381,10 +381,10 @@ void sub_080581E4(u32 a, u32 b, u32 count) u32 address = gUnk_030034E0; u32 offset = i * 16; u8 *base = (u8 *)(address + offset); - if (*(u16 *)(base + 0x150) == a && *(u16 *)(base + 0x152) == b) { + if (*(u16 *)(base + SAVE_FIELD(0x150)) == a && *(u16 *)(base + SAVE_FIELD(0x152)) == b) { count--; - *(u16 *)(base + 0x150) = 0; - *(u16 *)(base + 0x152) = 0; + *(u16 *)(base + SAVE_FIELD(0x150)) = 0; + *(u16 *)(base + SAVE_FIELD(0x152)) = 0; if (!count) break; } @@ -398,8 +398,8 @@ s32 sub_08058240(void) { u32 i = sub_080020F4(); u8 *base = (u8 *)gUnk_03003CE0; - i *= 0x14C; - base += 0x8C; + i *= PLAYER_SIZE; + base += PLAYER_FIELD(0x8C); return *(s32 *)(i + (u32)base) >> 8; } /* [GetLocalPlayerWorldPixelY] Queries the local player index, selects its 0x14C-byte runtime record at @@ -409,8 +409,8 @@ s32 sub_08058260(void) { u32 i = sub_080020F4(); u8 *base = (u8 *)gUnk_03003CE0; - i *= 0x14C; - base += 0x90; + i *= PLAYER_SIZE; + base += PLAYER_FIELD(0x90); return *(s32 *)(i + (u32)base) >> 8; } /* [ResetActiveEnemyScriptStates] Scans exactly5 slots, only active and state12 records get state0. */ @@ -419,7 +419,7 @@ void sub_08058280(void) u8 *entry = (u8 *)gUnk_030056F4; u32 i; s32 mask; - for (i = 0; i <= 4; i++, entry += 0x2E0) { + for (i = 0; i <= 4; i++, entry += ENEMY_SIZE) { mask = gUnk_030056FC & (1u << i); if (mask && *(u16 *)(entry + 0xC) == 0xC) *(u16 *)(entry + 0xC) = 0; @@ -462,7 +462,7 @@ void sub_08058334(u32 x, u32 y, u16 a, u16 b, u32 callback) u32 pos[2]; u32 info; u32 packed; - u8 *player = (u8 *)&gUnk_03003D6C + sub_080020F4() * 0x14C; + u8 *player = (u8 *)&gUnk_03003D6C + sub_080020F4() * PLAYER_SIZE; info = 0x00200018; pos[0] = x << 8; pos[1] = y << 8; @@ -554,7 +554,7 @@ void sub_08058498(u32 x, u32 y, u32 a, u32 b) packed = (a >> 16) | b; entry = &((struct PlayerW12 *)gUnk_03003CE0)[sub_080020F4()]; while (sub_08021FE0(&entry->pos8C, pos, &result, &packed) == 0 || - !(*(u16 *)((u8 *)entry + 0x14) & 1)) { + !(*(u16 *)((u8 *)entry + PLAYER_FIELD(0x14)) & 1)) { if (sub_08058608()) return; sub_080003F0(); } @@ -702,7 +702,7 @@ void sub_080586EC(u32 index, u32 x, u32 y) sub_080003F0(); ready = gUnk_030056FC & (1u << index); } - entry = (u8 *)gUnk_030056F4 + index * 0x2E0; + entry = (u8 *)gUnk_030056F4 + index * ENEMY_SIZE; *(u32 *)(entry + 0x30) = x; *(u32 *)(entry + 0x34) = y; *(u32 *)(entry + 0x38) = 0; diff --git a/src/code_08058790.c b/src/code_08058790.c index f030fff8..5a8276be 100644 --- a/src/code_08058790.c +++ b/src/code_08058790.c @@ -63,7 +63,7 @@ u32 sub_08058844(void) { u32 count = 0; u32 i = 0; - u8 *base = (u8 *)gUnk_030034E0 + 0xC10; + u8 *base = (u8 *)gUnk_030034E0 + SAVE_FIELD(0xC10); for (; i <= 0x90; i++) if (base[i] != 0) count++; if (count == 0x91) return 1; @@ -234,7 +234,7 @@ u32 sub_08058A80(void) /* [HasConnectedPlayerAppearance6Or8] Scans connected-player count with0x14C-byte records and tests+64 for6/8. */ u32 sub_08058AD0(void) { - struct Player { u8 pad[0x64]; u16 state; u8 rest[0xE6]; }; + struct Player { u8 pad[PLAYER_FIELD(0x64)]; u16 state; u8 rest[0xE6]; }; u32 count = sub_08002164(); u32 i; for (i = 0; i < count; i++) @@ -309,7 +309,7 @@ void sub_08058C08(u16 arg0, u16 arg1) } /* [SelectAndActivateWeaponSlot] Writes supplied halfword to inventory manager+0x68. */ void sub_08058C74(s16 arg0) { - M2C_FIELD(gUnk_030034E0, s16 *, 0x68) = arg0; + M2C_FIELD(gUnk_030034E0, s16 *, SAVE_FIELD(0x68)) = arg0; sub_0805AD78(); } /* [StartTrackedSongUnlessMultiplayer] When multiplayer-world-scene bit 1 is clear and mute/status word @@ -353,7 +353,7 @@ u32 sub_08058D4C(u32 key) { int new_var; u32 i; - u8 *base = *((u8 **) 0x03005CF4); + u8 *base = *((u8 **) &gUnk_03005CF4); u8 *entry = base + 0x7A4; u32 mask; for (i = 0; i <= 0xE; i++, entry += 0x70) @@ -392,7 +392,7 @@ s32 sub_08058D98(s32 value) /* [HasCoordinatedAttackState] Normalizes the coordinated-attack phase query to boolean. */ s32 sub_08058DB0(void) { - struct Player { u8 *item; u8 pad[0x148]; }; + struct Player { u8 *item; u8 pad[PLAYER_FIELD(0x148)]; }; s32 value = sub_0800CD8C(); u32 found = (u32)(value | -value) >> 31; u8 *players = (u8 *)gUnk_03003CE0; @@ -400,7 +400,7 @@ s32 sub_08058DB0(void) if (((struct PlayerW12 *)players)[sub_080020F4()].state == 0xE) found = 1; i = 0; - players += 0x148; + players += PLAYER_FIELD(0x148); for (; i < sub_08002164(); i++) { u32 kind = *(u8 *)((struct Player *)players)[i].item; if ((kind << 28) >> 28 == 0xE) { @@ -412,7 +412,7 @@ s32 sub_08058DB0(void) } /* [GetLocalCharacterLevel] Returns save-record word at offset 0x20. */ s32 sub_08058E08(void) { - return M2C_FIELD(gUnk_030034E0, s32 *, 0x20); + return M2C_FIELD(gUnk_030034E0, s32 *, SAVE_FIELD(0x20)); } /* [AcquireSceneCallbackGuard] Sets bit arg of guard mask scene state +0x6C, the mask * StartGuardedSceneCallbackTask tests and sets and ReleaseSceneCallbackGuard clears. It starts no task. */ diff --git a/src/code_08059534.c b/src/code_08059534.c index 28eb7d9a..7f26b448 100644 --- a/src/code_08059534.c +++ b/src/code_08059534.c @@ -479,7 +479,7 @@ void sub_0805A088(u32 arg) pos[1] = 0xE100; packed = 0x0028000A; entry = (u8 *)&((struct PlayerW12 *)gUnk_03003CE0)[sub_080020F4()]; - while (sub_08021FE0(entry + 0x8C, pos, &result, &packed) == 0) + while (sub_08021FE0(entry + PLAYER_FIELD(0x8C), pos, &result, &packed) == 0) sub_080003F0(); sub_08068070((u32)sub_0804BC38, arg); } @@ -501,10 +501,10 @@ void sub_0805A0EC(u32 owner) { u8 *base = *map; u8 *slot = base + i * 16; - u32 offset = 0x150; + u32 offset = SAVE_FIELD(0x150); u16 *status = (u16 *)(slot + offset); if (*status == 1) { - offset = 0x152; + offset = SAVE_FIELD(0x152); slot += offset; if (*(u16 *)slot == 0x22) { remaining--; @@ -602,7 +602,7 @@ void sub_0805A2E4(void) * or8. */ u32 sub_0805A318(void) { - struct PlayerKinds { u8 pad[0x64]; u16 kind; u8 tail[0xE6]; }; + struct PlayerKinds { u8 pad[PLAYER_FIELD(0x64)]; u16 kind; u8 tail[0xE6]; }; u32 count = sub_08002164(); u32 i; for (i = 0; i < count; i++) { diff --git a/src/code_0805A630.c b/src/code_0805A630.c index 3686aab4..afcb12a2 100644 --- a/src/code_0805A630.c +++ b/src/code_0805A630.c @@ -191,7 +191,7 @@ u32 sub_0805A7C4(u32 id, u32 x, u32 y) void sub_0805A874(const u32 *args, u32 mode) { extern u8 playerPositions[] asm("gUnk_03003D6C"); - u8 *state = playerPositions + sub_080020F4() * 0x14C; + u8 *state = playerPositions + sub_080020F4() * PLAYER_SIZE; u32 data[4]; u32 callback; u32 value; @@ -254,7 +254,7 @@ void *sub_0805A8F8(u32 arg0, u32 callback) * null. */ void *sub_0805A960(u32 value) { - u8 *entry = *(u8 **)0x03005CF4 + 0x7A4; + u8 *entry = *(u8 **)&gUnk_03005CF4 + 0x7A4; u32 i; for (i=0; i<=0xE; i++, entry+=0x70) if (*(u32 *)entry == value) return entry; @@ -280,7 +280,7 @@ void sub_0805A994(u32 index, u32 a, u32 b) do { sub_080003F0(); } while ((*savedFlags & savedBit) == 0); } } - entry = (u8 *)gUnk_030056F4 + index * 0x2E0; + entry = (u8 *)gUnk_030056F4 + index * ENEMY_SIZE; *(u32 *)(entry + 0x38) = a; *(u32 *)(entry + 0x3C) = b; *(u32 *)(entry + 0x30) = 0; @@ -374,9 +374,9 @@ void sub_0805AAB8(u32 packed) } struct ItemSlot { u16 type; u16 pad; u32 count; u32 c; u32 d; }; struct ItemTable { - u8 pad[0x6A]; + u8 pad[SAVE_FIELD(0x6A)]; u16 rows; - u8 pad2[0x150 - 0x6C]; + u8 pad2[SAVE_FIELD(0x150) - SAVE_FIELD(0x6C)]; struct ItemSlot field[25]; struct ItemSlot stash[25]; }; @@ -539,13 +539,18 @@ u32 sub_0805AD18(void) extern u8 *mapObjects asm("gUnk_030034E0"); u8 *state = (u8 *)&((struct PlayerW12 *)gUnk_03003CE0)[sub_080020F4()]; register u32 id asm("r0"); - if (*(u16 *)(state + 0xC) != *(u16 *)(state + 0x64)) { - id = *(u16 *)(*(u32 *)(state + 0x138) + 0x28); + if (*(u16 *)(state + PLAYER_FIELD(0xC)) != *(u16 *)(state + PLAYER_FIELD(0x64))) { +#ifdef REGION_USA + /* The record behind player +0x138 keeps this id at +0x19C in USA (+0x28 in EU). */ + id = *(u16 *)(*(u32 *)(state + PLAYER_FIELD(0x138)) + 0x19C); +#else + id = *(u16 *)(*(u32 *)(state + PLAYER_FIELD(0x138)) + 0x28); +#endif } else { - u8 *entry = mapObjects + *(u16 *)(mapObjects + 0x68) * 0x10; - if (*(u8 *)(entry + 0x79) == 0) + u8 *entry = mapObjects + *(u16 *)(mapObjects + SAVE_FIELD(0x68)) * 0x10; + if (*(u8 *)(entry + SAVE_FIELD(0x79)) == 0) return 0; - id = *(u16 *)(entry + 0x72); + id = *(u16 *)(entry + SAVE_FIELD(0x72)); } id |= 0xB0000; return sub_08007290(id); @@ -569,43 +574,43 @@ s32 impl_0805AD78(u32 index) u8 *playerBase; u8 **owner; u8 *table; - for (; i < players[sub_080020F4() * 0x14C + 0x77]; i++) { + for (; i < players[sub_080020F4() * PLAYER_SIZE + SAVE_FIELD(0x77)]; i++) { u8 *slot = mapItems; slot = slot + i * 0x10; - slot += 0x79; + slot += SAVE_FIELD(0x79); *slot = 0; } owner = &mapItems; table = *owner; offset = index * 0x10; item = table + offset; - if (*(u16 *)(item + 0x70) == 2) { - valid = sub_0805AE34(table + (offset + 0x70)); + if (*(u16 *)(item + SAVE_FIELD(0x70)) == 2) { + valid = sub_0805AE34(table + (offset + SAVE_FIELD(0x70))); if (valid) { u8 *resource; u8 *slot = *owner; slot += offset; - slot += 0x79; + slot += SAVE_FIELD(0x79); *slot = 1; - resource = (u8 *)sub_08007290(*(u16 *)(mapItems + offset + 0x72) | 0xB0000); + resource = (u8 *)sub_08007290(*(u16 *)(mapItems + offset + SAVE_FIELD(0x72)) | 0xB0000); player = sub_080020F4(); playerBase = (u8 *)gUnk_03003CE0; - player *= 0x14C; + player *= PLAYER_SIZE; states = (u8 *)player + (u32)playerBase; - *(u16 *)(states + 0x10) = resource[0x9B]; + *(u16 *)(states + PLAYER_FIELD(0x10)) = ITEM_KIND(resource); } else { player = sub_080020F4(); playerBase = (u8 *)gUnk_03003CE0; - player *= 0x14C; + player *= PLAYER_SIZE; states = (u8 *)player + (u32)playerBase; - *(u16 *)(states + 0x10) = valid; + *(u16 *)(states + PLAYER_FIELD(0x10)) = valid; } } else { player = sub_080020F4(); playerBase = (u8 *)gUnk_03003CE0; - player *= 0x14C; + player *= PLAYER_SIZE; states = (u8 *)player + (u32)playerBase; - *(u16 *)(states + 0x10) = 0; + *(u16 *)(states + PLAYER_FIELD(0x10)) = 0; } return sub_08065DAC(); } @@ -620,14 +625,15 @@ u32 sub_0805AE34(const u8 *item) u32 state; u32 raw; u32 needed; - register u8 *kind asm("r1"); + register ItemKind *kind asm("r1"); if (item == 0 || *(u16 *)item != 2 || item[8] != 0) goto reject; resource = (u8 *)sub_08007290(*(u16 *)(item + 2) | 0xB0000); state = sub_0801DE60(); - if (((*(u16 *)(resource + 0xAE) >> (u8)state) & 1) == 0) goto reject; - kind = resource + 0x9B; + if (((*(u16 *)(resource + ITEM_FIELD(0xAE)) >> (u8)state) & 1) == 0) goto reject; + kind = (ItemKind *)(resource + ITEM_KIND_OFF); if (*kind == 9) goto accept; - resource += 0xAC; + asm("" ::: "r2"); + resource += ITEM_FIELD(0xAC); raw = sub_0801D028(); needed = *(u16 *)resource; if (needed > (u16)raw) goto reject; @@ -653,38 +659,38 @@ u32 sub_0805AE94(u8 *item) u32 multiplier = 10; switch (*(u16 *)item) { case 1: - value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0x100000) + 0x9C); + value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0x100000) + ITEM_FIELD(0x9C)); break; case 2: - value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0xB0000) + 0xA0); + value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0xB0000) + ITEM_FIELD(0xA0)); flag = item[8]; level = item[6]; quality = item[7]; if (*(u16 *)(item + 4) != 0) - multiplier = *(u16 *)((u8 *)sub_08007290((*(u16 *)(item + 4) - 1) | 0x130000) + 0x9C); + multiplier = *(u16 *)((u8 *)sub_08007290((*(u16 *)(item + 4) - 1) | 0x130000) + ITEM_FIELD(0x9C)); break; case 3: - value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0xC0000) + 0x9C); + value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0xC0000) + EQUIP_FIELD(0x9C)); flag = item[8]; level = item[6]; quality = item[7]; if (*(u16 *)(item + 4) != 0) - multiplier = *(u16 *)((u8 *)sub_08007290((*(u16 *)(item + 4) - 1) | 0x130000) + 0x9C); + multiplier = *(u16 *)((u8 *)sub_08007290((*(u16 *)(item + 4) - 1) | 0x130000) + ITEM_FIELD(0x9C)); break; case 4: - value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0xD0000) + 0x9C); + value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0xD0000) + EQUIP_FIELD(0x9C)); flag = item[8]; level = item[6]; quality = item[7]; if (*(u16 *)(item + 4) != 0) - multiplier = *(u16 *)((u8 *)sub_08007290((*(u16 *)(item + 4) - 1) | 0x130000) + 0x9C); + multiplier = *(u16 *)((u8 *)sub_08007290((*(u16 *)(item + 4) - 1) | 0x130000) + ITEM_FIELD(0x9C)); break; case 7: - value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0x110000) + 0x9C); + value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0x110000) + ITEM_FIELD(0x9C)); flag = 0; level = 0; break; case 5: - value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0xE0000) + 0x9C); + value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0xE0000) + EQUIP_FIELD(0x9C)); flag = item[8]; level = item[6]; quality = item[7]; if (*(u16 *)(item + 4) != 0) - multiplier = *(u16 *)((u8 *)sub_08007290((*(u16 *)(item + 4) - 1) | 0x130000) + 0x9C); + multiplier = *(u16 *)((u8 *)sub_08007290((*(u16 *)(item + 4) - 1) | 0x130000) + ITEM_FIELD(0x9C)); break; case 6: - value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0xF0000) + 0x9C); + value = *(u32 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0xF0000) + ITEM_FIELD(0x9C)); flag = 0; level = 0; quality = 0; break; case 9: @@ -701,7 +707,7 @@ u32 sub_0805AE94(u8 *item) value = *(u32 *)(item + 4); break; case 8: - value = *(u16 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0x120000) + 0x9C); + value = *(u16 *)((u8 *)sub_08007290(*(u16 *)(item + 2) | 0x120000) + ITEM_FIELD(0x9C)); break; } if (flag != 0) @@ -725,7 +731,7 @@ u32 sub_0805B068(const u8 *item) switch (*(u16 *)item) { case 2: resource = (u8 *)sub_08007290(*(u16 *)(item + 2) | 0xB0000); - value = *(u32 *)(resource + 0xA0); + value = *(u32 *)(resource + ITEM_FIELD(0xA0)); break; case 3: id = *(u16 *)(item + 2); @@ -741,7 +747,7 @@ u32 sub_0805B068(const u8 *item) common: id |= category; resource = (u8 *)sub_08007290(id); - value = *(u32 *)(resource + 0x9C); + value = *(u32 *)(resource + EQUIP_FIELD(0x9C)); break; } divisor = 10; @@ -770,7 +776,7 @@ u32 sub_0805B0F0(void) u32 secondOffset; map = &mapObjects; base = *map; - firstOffset = 0x150; + firstOffset = SAVE_FIELD(0x150); entry = base + firstOffset; do { if (*(u16 *)entry == 0xA) first += *(u32 *)(entry + 4); @@ -780,7 +786,7 @@ u32 sub_0805B0F0(void) i = 0; map = &mapObjects; base = *map; - secondOffset = 0x2E0; + secondOffset = SAVE_FIELD(0x2E0); entry = base + secondOffset; do { if (*(u16 *)entry == 0xA) second += *(u32 *)(entry + 4); @@ -1136,14 +1142,14 @@ struct B688Shape { }; struct B688Player { u16 id; - u8 pad2[0x1E]; + u8 pad2[PLAYER_FIELD(0x20) - 0x2]; u16 state; - u8 pad22[0xE]; + u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; - u8 pad34[0x114]; + u8 pad34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; struct B688Shape *shape; }; -struct B688Obj { u8 pad0[0xA0]; u16 kind; u8 padA2[2]; u32 hitMask; u8 gfx; }; +struct B688Obj { u8 pad0[ITEM_FIELD(0xA0)]; u16 kind; u8 padA2[2]; u32 hitMask; u8 gfx; }; extern struct B688Player b688Players[] asm("gUnk_03003CE0"); extern u8 *b688Map asm("gUnk_030034E0"); extern u8 *b688Enemies asm("gUnk_030056F4"); @@ -1172,7 +1178,11 @@ void sub_0805B688(u16 who, u16 itemId) struct B688Pos other; struct B688Size size; struct B688Size size2; +#ifdef REGION_USA + struct B688Size *enemySize; +#else register struct B688Size *enemySize asm("sl"); +#endif s32 x, y; struct B688Player *player; struct B688Obj *obj; @@ -1192,11 +1202,15 @@ void sub_0805B688(u16 who, u16 itemId) u32 ok; u32 pal; s32 z; +#ifdef REGION_USA + u32 lvl; u32 st; +#else u32 lvl; +#endif player = &b688Players[who]; me = (u16)sub_080020F4(); - b688_sub_08065158(&anim, 0x500F1, 0, 0x80000000, 0); + b688_sub_08065158(&anim, RES_ID(0x500F1), 0, 0x80000000, 0); lvl = player->shape->power; item.kind = 1; item.id = itemId; @@ -1215,7 +1229,7 @@ void sub_0805B688(u16 who, u16 itemId) x += ((gUnk_080B9704[(s16)angle + 0x40] << 1) * speed) / 10; y += ((gUnk_080B9704[(s16)angle] << 1) * speed) / 10; if (sub_0801DE60() == 0) - power = sub_0801E0AC((s32)(b688Map + 0x30), 5); + power = sub_0801E0AC((s32)(b688Map + SAVE_FIELD(0x30)), 5); else power = 0; @@ -1279,22 +1293,34 @@ void sub_0805B688(u16 who, u16 itemId) return; if (obj->hitMask & 0x3E) { i = 0; +#ifndef REGION_USA enemySize = &size2; +#endif for (; i <= 4; i++) { if (((u32)gUnk_030056FC & (1 << i)) == 0) continue; - enemy = b688Enemies + i * 0x2E0; + enemy = b688Enemies + i * ENEMY_SIZE; if (*(u16 *)(enemy + 0xC) == 0xC) continue; if (enemy[0x1DC] == 0 && !(obj->hitMask & 0x3C)) continue; { +#ifdef REGION_USA + struct B688Size *es = &size2; +#else struct B688Size *es; - u8 w = enemy[0x22E]; +#endif + u8 w = enemy[ENEMY_FIELD(0x22E)]; +#ifndef REGION_USA es = enemySize; +#endif es->w = w; - es->h = enemy[0x22F]; +#ifdef REGION_USA + asm("" : : "r"(es)); + +#endif + es->h = enemy[ENEMY_FIELD(0x22F)]; if (!b688_sub_08021FE0(&pos, enemy + 0x14, &size, es)) continue; } @@ -1306,29 +1332,45 @@ void sub_0805B688(u16 who, u16 itemId) if (!ok) continue; if (enemy[0x1DC] == 0) { - switch (enemy[0x226]) { + switch (enemy[ENEMY_FIELD(0x226)]) { case 4: if (!(obj->hitMask & 4)) continue; +#ifdef REGION_USA + st = 0xC; *(u16 *)(enemy + 0xC) = st; +#else *(u16 *)(enemy + 0xC) = 0xC; +#endif *(u16 *)(enemy + 0xE) = 8; break; case 5: if (!(obj->hitMask & 8)) continue; +#ifdef REGION_USA + st = 0xC; *(u16 *)(enemy + 0xC) = st; +#else *(u16 *)(enemy + 0xC) = 0xC; +#endif *(u16 *)(enemy + 0xE) = 8; break; case 6: if (!(obj->hitMask & 0x10)) continue; +#ifdef REGION_USA + st = 0xC; *(u16 *)(enemy + 0xC) = st; +#else *(u16 *)(enemy + 0xC) = 0xC; +#endif *(u16 *)(enemy + 0xE) = 8; break; case 7: if (!(obj->hitMask & 0x20)) continue; +#ifdef REGION_USA + st = 0xC; *(u16 *)(enemy + 0xC) = st; +#else *(u16 *)(enemy + 0xC) = 0xC; +#endif *(u16 *)(enemy + 0xE) = 8; break; } @@ -1428,23 +1470,23 @@ void sub_0805B688(u16 who, u16 itemId) } struct BD5CPlayer { u16 id; - u8 pad2[0x1E]; + u8 pad2[PLAYER_FIELD(0x20) - 2]; u16 state; u16 f22; - u8 pad24[0xC]; + u8 pad24[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x24)]; u32 flags; - u8 pad34[0x2C]; + u8 pad34[PLAYER_FIELD(0x60) - PLAYER_FIELD(0x34)]; s16 maxMp; s16 maxHp; u16 f64; u8 pad66[2]; u8 f68; - u8 pad69[0x59]; + u8 pad69[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0x69)]; s16 mp; s16 hp; - u8 padC6[0x86]; + u8 padC6[PLAYER_SIZE - PLAYER_FIELD(0xC6)]; }; -struct BD5CMap { u8 pad0[0x10]; s16 stat10; s16 stat12; s16 stat14; s16 stat16; }; +struct BD5CMap { u8 pad0[SAVE_FIELD(0x10)]; s16 stat10; s16 stat12; s16 stat14; s16 stat16; }; extern struct BD5CPlayer bd5cPlayers[] asm("gUnk_03003CE0"); extern struct BD5CMap *bd5cMap asm("gUnk_030034E0"); extern u32 sub_080665B0(u32); @@ -1458,9 +1500,15 @@ extern void sub_08074DE8(u32, s32); s32 sub_0805BD5C(u16 *item, s32 level) { struct BD5CPlayer *player; +#ifdef REGION_USA + register u32 kind asm("r9"); + u32 zero; + register u8 *obj asm("r8"); +#else u8 *obj; u32 zero; u16 kind; +#endif s32 amount; u8 *p; @@ -1477,10 +1525,10 @@ s32 sub_0805BD5C(u16 *item, s32 level) if (item[0] != 1) return 0; obj = (u8 *)sub_08007290(item[1] | 0x100000); - kind = *(u16 *)(obj + 0xA0); + kind = *(u16 *)(obj + ITEM_FIELD(0xA0)); if (kind == 1 || kind == 0x13) { amount = level * 40 + 100; - amount = *(u16 *)(obj + 0xA2) * amount / 100; + amount = *(u16 *)(obj + ITEM_FIELD(0xA2)) * amount / 100; if (player->hp >= player->maxHp) goto fail; player->hp += amount; @@ -1488,7 +1536,7 @@ s32 sub_0805BD5C(u16 *item, s32 level) player->hp = player->maxHp; else if (player->hp < 0) player->hp = zero; - if (*(u16 *)(obj + 0xA2) != 0) + if (*(u16 *)(obj + ITEM_FIELD(0xA2)) != 0) sub_08074DE8(player->id, 8); if ((player->flags & 0x20000) && player->hp >= player->maxHp >> 1) player->flags &= ~0x20000; @@ -1497,7 +1545,7 @@ s32 sub_0805BD5C(u16 *item, s32 level) if (player->mp >= player->maxMp) goto fail; amount = level * 40 + 100; - amount = *(u16 *)(obj + 0xA2) * amount / 100; + amount = *(u16 *)(obj + ITEM_FIELD(0xA2)) * amount / 100; player->mp += amount * 10; if (player->maxMp < player->mp) player->mp = player->maxMp; @@ -1606,14 +1654,14 @@ s32 sub_0805BD5C(u16 *item, s32 level) sub_0805865C(0x61); return 0; } else if (kind == 0x10) { - sub_080665B0(*(u16 *)(obj + 0xA2)); + sub_080665B0(*(u16 *)(obj + ITEM_FIELD(0xA2))); return 0; } else if (kind == 0x11) { player->mp = player->maxMp; player->hp = player->maxHp; } else if (kind == 0x12) { amount = level * 40 + 100; - amount = *(u16 *)(obj + 0xA2) * amount / 100; + amount = *(u16 *)(obj + ITEM_FIELD(0xA2)) * amount / 100; if (player->hp >= player->maxHp) goto fail; player->hp += amount; @@ -1621,7 +1669,7 @@ s32 sub_0805BD5C(u16 *item, s32 level) player->hp = player->maxHp; else if (player->hp < 0) player->hp = 0; - if (*(u16 *)(obj + 0xA2) != 0) + if (*(u16 *)(obj + ITEM_FIELD(0xA2)) != 0) sub_08074DE8(player->id, 8); if ((player->flags & 0x20000) && player->hp >= player->maxHp >> 1) player->flags &= ~0x20000; @@ -1654,6 +1702,212 @@ struct C208Range { u16 value; u16 upper; }; * clear. */ s32 sub_0805C208(void *arg0, s32 arg1) { +#ifdef REGION_USA + u8 *o0; + u8 *o1; + u8 *o2; + u8 *o3; + struct C208Slot *slot; + u32 flags; + u32 rollElement; + u32 rollBonus; + u32 rollLevel; + struct C208Range *table; + u32 count; + register u32 upper asm("r3"); + u32 low; + u32 i; + u32 r; + u8 *p; + + slot = arg0; + flags = arg1; + rollElement = 0; + rollBonus = 0; + rollLevel = 0; + switch (slot->type) { + case 2: + o0 = (u8 *)sub_08007290(slot->arg | 0xB0000); + if (ITEM_KIND(o0) == 9) { + table = (struct C208Range *)gUnk_08478044; + r = sub_080008C8(); + if ((r & 0xF) <= 7) { + rollBonus = 1; + rollLevel = 1; + } else { + rollBonus = 1; + } + } else { + table = (struct C208Range *)gUnk_08477F3C; + r = sub_080008C8(); + r &= 0xF; + if (r <= 2) { + rollLevel = 1; + rollElement = 1; + rollBonus = 1; + } else if (r <= 7) { + r = sub_080008C8(); + r &= 0xF; + if (r <= 4) { + rollBonus = 1; + rollLevel = 1; + } else if (r <= 10) { + rollLevel = 1; + rollElement = 1; + } else { + rollElement = 1; + rollBonus = 1; + } + } else { + r = sub_080008C8(); + r &= 0xF; + if (r <= 4) + rollLevel = 1; + else if (r <= 9) + rollBonus = 1; + else + rollElement = 1; + } + } + break; + case 5: + o1 = (u8 *)sub_08007290(slot->arg | 0xE0000); + if (*(u32 *)(o1 + 0x17C)) + table = (struct C208Range *)gUnk_08478220; + else + table = (struct C208Range *)gUnk_08478158; + rollLevel = 0; + break; + case 3: + o3 = (u8 *)sub_08007290(slot->arg | 0xC0000); + table = (struct C208Range *)gUnk_08478158; + rollLevel = 0; + break; + case 4: + o2 = (u8 *)sub_08007290(slot->arg | 0xD0000); + table = (struct C208Range *)gUnk_08478158; + rollLevel = 0; + break; + default: + return 1; + } + switch (slot->type) { + case 3: + case 4: + case 5: + r = sub_080008C8(); + r &= 0xF; + if (r <= 7) { + r = sub_080008C8(); + r &= 0xF; + if (r <= 7) + rollBonus = 1; + else + rollElement = 1; + } else { + rollBonus = 1; + rollElement = 1; + } + } + if (rollBonus) { + count = table[0].value; + r = sub_080008C8(); + r %= table[0].upper; + table++; + for (low = 0, i = 0; i < count; i++, low = upper, table++) { + upper = table->upper; + if (low <= r && upper >= r) { + slot->bonus = table->value; + break; + } + } + } + if (rollLevel) { + table = (struct C208Range *)gUnk_084782F4; + count = table[0].value + 1; + r = sub_080008C8(); + r %= table[0].upper + 1; + table++; + for (low = 0, i = 0; i < count; i++, low = upper + 1, table++) { + upper = table->upper; + if (low <= r && upper >= r) { + slot->level = table->value; + break; + } + } + } + if (rollElement) { + if (flags & 1) + table = (struct C208Range *)gUnk_08478378; + else if (sub_0800CE30()) + table = (struct C208Range *)gUnk_08478338; + else + table = (struct C208Range *)gUnk_08478310; + count = table[0].value + 1; + r = sub_080008C8(); + r %= table[0].upper + 1; + table++; + for (low = 0, i = 0; i < count; i++, low = upper + 1, table++) { + upper = table->upper; + if (low <= r && upper >= r) { + slot->element = table->value; + break; + } + } + } + switch (slot->type) { + case 2: + for (i = 0; i <= 2; i++) { + if (*(u16 *)(o0 + 0x188 + i * 4) != 0) { + slot->bonus = 0; + slot->element = 0; + slot->level = 0; + flags = 1; + break; + } + } + break; + case 3: + for (i = 0; i <= 2; i++) { + if (*(u16 *)(o3 + 0x180 + i * 4) != 0) { + slot->bonus = 0; + slot->element = 0; + slot->level = 0; + flags = 1; + break; + } + } + break; + case 4: + for (i = 0; i <= 2; i++) { + if (*(u16 *)(o2 + 0x180 + i * 4) != 0) { + slot->bonus = 0; + slot->element = 0; + slot->level = 0; + flags = 1; + break; + } + } + break; + case 5: + for (i = 0; i <= 2; i++) { + if (*(u16 *)(o1 + 0x184 + i * 4) != 0) { + slot->bonus = 0; + slot->element = 0; + slot->level = 0; + flags = 1; + break; + } + } + break; + } + if (*(u32 *)&slot->bonus != 0) { + if (flags & 1) + slot->flag = 0; + else + slot->flag = 1; + } +#else u8 *o0; u8 *o1; u8 *o2; @@ -1679,7 +1933,7 @@ s32 sub_0805C208(void *arg0, s32 arg1) switch (slot->type) { case 2: o0 = (u8 *)sub_08007290(slot->arg | 0xB0000); - if (o0[0x9B] == 9) { + if (ITEM_KIND(o0) == 9) { table = (struct C208Range *)gUnk_08478044; r = sub_080008C8(); asm("" : : "r"(r)); @@ -1874,6 +2128,7 @@ s32 sub_0805C208(void *arg0, s32 arg1) slot->flag = v; } /* Only unknown slot types return a value (1); callers ignore it. */ +#endif } struct LootT { u16 chance; u16 pad; u16 *groups[8]; }; extern struct LootT gUnk_084E6DD8[]; @@ -1933,7 +2188,7 @@ u32 sub_0805C4FC(u8 *out, u32 count, u32 category) return 1; } struct DropC620 { u16 type, val; u32 hi; }; -struct ExC620 { u8 pad[0x2C]; struct DropC620 drops[3]; }; +struct ExC620 { u8 pad[ENEMY_DATA_FIELD(0x2C)]; struct DropC620 drops[3]; }; /* [GenerateActorDropRecord] Zeros16 output bytes, tries three cumulative configured drop intervals using * a16-bit random roll and returns1 on a permitted configured result. Otherwise clamps entity player-index * field, rolls against player/player-count chance and optionally calls category generator with mode-dependent @@ -1964,14 +2219,14 @@ u32 sub_0805C620(u8 *entity, u16 *out) out[0] = extra->drops[i].type; out[1] = extra->drops[i].val; if (extra->drops[i].type == 9) - out[2] = *(u32 *)(entity + 0x214); + out[2] = *(u32 *)(entity + ENEMY_FIELD(0x214)); break; } low = (u16)(extra->drops[i].hi + 1); } } if (out[0] != 0) { - if (out[0] == 10 && !(entity[0x227] & 1)) { + if (out[0] == 10 && !(entity[ENEMY_FIELD(0x227)] & 1)) { out[0] = 0; out[1] = 0; return 0; @@ -1982,7 +2237,7 @@ u32 sub_0805C620(u8 *entity, u16 *out) ok = 0; if (*(u16 *)(entity + 0x58) > 3) *(u16 *)(entity + 0x58) = 0; - { u8 (*pb)[] = &c620Players; low = (*pb)[4 * (83 * *(u16 *)(entity + 0x58)) + 0x74]; } + { u8 (*pb)[] = &c620Players; low = (*pb)[4 * ((PLAYER_SIZE / 4) * *(u16 *)(entity + 0x58)) + PLAYER_FIELD(0x74)]; } switch (sub_08002164()) { case 1: low = (u16)(low + 0x10); break; case 2: low = (u16)(low + 0x15); break; @@ -2007,9 +2262,9 @@ u32 sub_0805C620(u8 *entity, u16 *out) ok = sub_0805C4FC((u8 *)out, category, 0); tail: if (out[0] == 9) { - out[2] = *(u32 *)(entity + 0x214); + out[2] = *(u32 *)(entity + ENEMY_FIELD(0x214)); } else if (out[0] == 10) { - if (!(entity[0x227] & 1)) { + if (!(entity[ENEMY_FIELD(0x227)] & 1)) { out[0] = 0; out[1] = 0; return 0; @@ -2055,14 +2310,14 @@ void c7b8_void(u32 mode) if (sub_0800CE30()) { count = 10; - slotsA = (struct C7B8Slot *)(c7b8Map + 0x9D0); - slotsB = (struct C7B8Slot *)(c7b8Map + 0xA90); - slotsC = (struct C7B8Slot *)(c7b8Map + 0xB50); + slotsA = (struct C7B8Slot *)(c7b8Map + SAVE_FIELD(0x9D0)); + slotsB = (struct C7B8Slot *)(c7b8Map + SAVE_FIELD(0xA90)); + slotsC = (struct C7B8Slot *)(c7b8Map + SAVE_FIELD(0xB50)); } else { count = 0; - slotsA = (struct C7B8Slot *)(c7b8Map + 0x790); - slotsB = (struct C7B8Slot *)(c7b8Map + 0x850); - slotsC = (struct C7B8Slot *)(c7b8Map + 0x910); + slotsA = (struct C7B8Slot *)(c7b8Map + SAVE_FIELD(0x790)); + slotsB = (struct C7B8Slot *)(c7b8Map + SAVE_FIELD(0x850)); + slotsC = (struct C7B8Slot *)(c7b8Map + SAVE_FIELD(0x910)); } bits = sub_08057CEC(); for (i = 1; i <= 9; i++) @@ -2515,7 +2770,7 @@ s32 sub_0805CDF8(void) { s32 sub_0805CFA0(void) { u32 i; u8 *p; - for(i=0,p=(u8 *)gUnk_030034E0+0x150;i<=24;p+=16,i++) if(*(u16 *)p==0) return i; + for(i=0,p=(u8 *)gUnk_030034E0+SAVE_FIELD(0x150);i<=24;p+=16,i++) if(*(u16 *)p==0) return i; return -1; } /* [FindFirstEmptyStashSlotInFirst25] Returns the first kind-zero entry index among only the first 25 stash @@ -2524,7 +2779,7 @@ s32 sub_0805CFA0(void) { s32 sub_0805CFCC(void) { u32 i; u8 *p; - for(i=0,p=(u8 *)gUnk_030034E0+0x2E0;i<=24;p+=16,i++) if(*(u16 *)p==0) return i; + for(i=0,p=(u8 *)gUnk_030034E0+SAVE_FIELD(0x2E0);i<=24;p+=16,i++) if(*(u16 *)p==0) return i; return -1; } /* [CopyItemToBagSlot] Narrows the supplied index to one byte, substitutes index zero when greater than 24, and @@ -2532,16 +2787,16 @@ s32 sub_0805CFCC(void) { void sub_0805CFF8(u8 index, const struct Entry61 *src) { if(index>24) index=0; - *(struct Entry61 *)((u8 *)gUnk_030034E0+0x150+index*16)=*src; + *(struct Entry61 *)((u8 *)gUnk_030034E0+SAVE_FIELD(0x150)+index*16)=*src; } /* [CopyItemToStashSlot] Narrows the index to one byte. If index is at least manager halfword +0x6A times 15, * substitutes zero, then copies all 16 bytes to stash +0x2E0 + index*16. A zero configured count still writes * slot zero. No null, empty-slot check or independent physical-capacity clamp. */ void sub_0805D028(u8 index,const struct Entry61 *src) { u8 *base=(u8 *)gUnk_030034E0; - s32 count=*(u16 *)(base+0x6A); + s32 count=*(u16 *)(base+SAVE_FIELD(0x6A)); if(index>=count*15) index=0; - *(struct Entry61 *)(base+index*16+0x2E0)=*src; + *(struct Entry61 *)(base+index*16+SAVE_FIELD(0x2E0))=*src; } /* [CopyWeaponItemToSelectionSlot] Accepts only kind-2 items, copies all 16 bytes into manager +0x70 + index*16 * and returns 1; otherwise returns 0. Does not validate index, select the slot or refresh activation. Weapon @@ -2551,5 +2806,5 @@ u32 sub_0805D064(const struct Entry61 *src,u32 index) { struct Entry61 *dst; register u32 offset asm("r0"); - switch(*(const u16 *)src) { case 2: dst=(void *)gUnk_030034E0; offset=savedIndex*16; dst=(void *)((u8 *)dst+offset); dst=(void *)((u8 *)dst+0x70); *dst=*src; return 1; default:return 0; } + switch(*(const u16 *)src) { case 2: dst=(void *)gUnk_030034E0; offset=savedIndex*16; dst=(void *)((u8 *)dst+offset); dst=(void *)((u8 *)dst+SAVE_FIELD(0x70)); *dst=*src; return 1; default:return 0; } } diff --git a/src/code_0805D094.c b/src/code_0805D094.c index 9fc3ffdf..075512ff 100644 --- a/src/code_0805D094.c +++ b/src/code_0805D094.c @@ -4,9 +4,9 @@ extern void sub_0805E0C4(void); extern void sub_0805D854(void); extern void sub_0805B688(void); extern u32 gUnk_03005D60; -struct PlayerReset61 {u8 pad[0xC6];u16 reset;u8 tail[0x84];}; +struct PlayerReset61 {u8 pad[PLAYER_FIELD(0xC6)];u16 reset;u8 tail[PLAYER_SIZE - PLAYER_FIELD(0xC8)];}; extern struct PlayerReset61 gReset61[] asm("gUnk_03003CE0"); -struct Player61 { u8 pad[0x38]; s16 limit; u8 rest[0x112]; }; +struct Player61 { u8 pad[PLAYER_FIELD(0x38)]; s16 limit; u8 rest[PLAYER_SIZE - PLAYER_FIELD(0x3A)]; }; extern struct Player61 gParty61[] asm("gUnk_03003CE0"); extern u32 sub_0805D2E0(void *); extern u32 sub_0805D278(void *); @@ -27,46 +27,46 @@ extern u8 gUnk_03005D6C; * remove the item. No useful return-value contract is established by the original body. */ s32 sub_0805D094(void) { u8 *base=(u8 *)gUnk_030034E0; - if(*(u16 *)(base+0x100)==4) { - if(sub_0805D210(base+0x100)!=0) M2C_FIELD((void *)gUnk_030034E0,u8 *,0x109)=1; - else M2C_FIELD((void *)gUnk_030034E0,u8 *,0x109)=0; - } else *(u8 *)(base+0x109)=0; + if(*(u16 *)(base+SAVE_FIELD(0x100))==4) { + if(sub_0805D210(base+SAVE_FIELD(0x100))!=0) M2C_FIELD((void *)gUnk_030034E0,u8 *,SAVE_FIELD(0x109))=1; + else M2C_FIELD((void *)gUnk_030034E0,u8 *,SAVE_FIELD(0x109))=0; + } else *(u8 *)(base+SAVE_FIELD(0x109))=0; } /* [RefreshBodyEquipmentActivation] For the equipped record at manager +0x110, writes activation byte +9 to 1 * exactly when its kind is 3 and validator 0805D278 accepts it; otherwise writes zero. Does not copy, swap or * remove the item. No useful return-value contract is established by the original body. */ s32 sub_0805D0E8(void) { u8 *base=(u8 *)gUnk_030034E0; - if(*(u16 *)(base+0x110)==3) { - if(sub_0805D278(base+0x110)!=0) M2C_FIELD((void *)gUnk_030034E0,u8 *,0x119)=1; - else M2C_FIELD((void *)gUnk_030034E0,u8 *,0x119)=0; - } else *(u8 *)(base+0x119)=0; + if(*(u16 *)(base+SAVE_FIELD(0x110))==3) { + if(sub_0805D278(base+SAVE_FIELD(0x110))!=0) M2C_FIELD((void *)gUnk_030034E0,u8 *,SAVE_FIELD(0x119))=1; + else M2C_FIELD((void *)gUnk_030034E0,u8 *,SAVE_FIELD(0x119))=0; + } else *(u8 *)(base+SAVE_FIELD(0x119))=0; } /* [RefreshGloveActivation] For the equipped record at manager +0x120, writes activation byte +9 to 1 exactly * when its kind is 5 and validator 0805D2E0 accepts it; otherwise writes zero. Does not copy, swap or remove * the item. No useful return-value contract is established by the original body. */ s32 sub_0805D13C(void) { u8 *base=(u8 *)gUnk_030034E0; - if(*(u16 *)(base+0x120)==5) { - if(sub_0805D2E0(base+0x120)!=0) M2C_FIELD((void *)gUnk_030034E0,u8 *,0x129)=1; - else M2C_FIELD((void *)gUnk_030034E0,u8 *,0x129)=0; - } else *(u8 *)(base+0x129)=0; + if(*(u16 *)(base+SAVE_FIELD(0x120))==5) { + if(sub_0805D2E0(base+SAVE_FIELD(0x120))!=0) M2C_FIELD((void *)gUnk_030034E0,u8 *,SAVE_FIELD(0x129))=1; + else M2C_FIELD((void *)gUnk_030034E0,u8 *,SAVE_FIELD(0x129))=0; + } else *(u8 *)(base+SAVE_FIELD(0x129))=0; } /* [UpdateTypeSevenActivation] Saved record+0x130 type7 sets activation byte+0x13A to1; otherwise clears that * byte and local runtime halfword+0xC6. Function has signed return declaration but no C return expression; no * status return contract claimed. */ s32 sub_0805D190(void) { u8 *base=(u8 *)gUnk_030034E0; - if(*(u16 *)(base+0x130)==7) *(u8 *)(base+0x13A)=1; - else { gReset61[sub_080020F4()].reset=0; M2C_FIELD((void *)gUnk_030034E0,u8 *,0x13A)=0; } + if(*(u16 *)(base+SAVE_FIELD(0x130))==7) *(u8 *)(base+SAVE_FIELD(0x13A))=1; + else { gReset61[sub_080020F4()].reset=0; M2C_FIELD((void *)gUnk_030034E0,u8 *,SAVE_FIELD(0x13A))=0; } } /* [RefreshRingActivation] Sets equipped manager +0x140 record activation byte +9 to 1 when its kind is 6, * otherwise zero. No class, requirement or broken-item check is made here; no useful return contract is * inferred. */ s32 sub_0805D1E0(void) { u8 *base=(u8 *)gUnk_030034E0; - if(*(u16 *)(base+0x140)==6) *(u8 *)(base+0x149)=1; - else *(u8 *)(base+0x149)=0; + if(*(u16 *)(base+SAVE_FIELD(0x140))==6) *(u8 *)(base+SAVE_FIELD(0x149))=1; + else *(u8 *)(base+SAVE_FIELD(0x149))=0; } /* [CanEquipHeadgearItem] Returns 0 for null, kind other than 4, or nonzero item byte +8. Resolves category D, * requires the class permission bit in record halfword +0xA2 indexed by the low byte of 1DE60, then requires @@ -75,15 +75,19 @@ s32 sub_0805D1E0(void) { u32 sub_0805D210(void *state) { u8 *resource; s32 offset; +#ifdef REGION_USA + register struct Player61 *player asm("r0"); +#else register struct Player61 *player asm("r1"); +#endif if(state!=0 && *(u16 *)state==4 && M2C_FIELD(state,u8 *,8)==0) { resource=(u8 *)sub_08007290(M2C_FIELD(state,u16 *,2)|0xD0000); - if((*(u16 *)(resource+0xA2)>>sub_0801DE60())&1) { + if((*(u16 *)(resource+EQUIP_FIELD(0xA2))>>sub_0801DE60())&1) { offset=sizeof(struct Player61)*sub_080020F4(); asm volatile("" : "+r" (offset)); player=(void *)((u8 *)gParty61+offset); - if(resource[0xA0]<=player->limit) return 1; + if(*(EquipLevel *)(resource+EQUIP_FIELD(0xA0))<=player->limit) return 1; } } return 0; @@ -95,15 +99,19 @@ u32 sub_0805D210(void *state) { u32 sub_0805D278(void *state) { u8 *resource; s32 offset; +#ifdef REGION_USA + register struct Player61 *player asm("r0"); +#else register struct Player61 *player asm("r1"); +#endif if(state!=0 && *(u16 *)state==3 && M2C_FIELD(state,u8 *,8)==0) { resource=(u8 *)sub_08007290(M2C_FIELD(state,u16 *,2)|0xC0000); - if((*(u16 *)(resource+0xA2)>>sub_0801DE60())&1) { + if((*(u16 *)(resource+EQUIP_FIELD(0xA2))>>sub_0801DE60())&1) { offset=sizeof(struct Player61)*sub_080020F4(); asm volatile("" : "+r" (offset)); player=(void *)((u8 *)gParty61+offset); - if(resource[0xA0]<=player->limit) return 1; + if(*(EquipLevel *)(resource+EQUIP_FIELD(0xA0))<=player->limit) return 1; } } return 0; @@ -112,6 +120,25 @@ u32 sub_0805D278(void *state) { * requires the class permission bit in record halfword +0xA2 indexed by the low byte of 1DE60, then requires * record byte +0xA1 not exceed signed local-player halfword +0x38. Returns 1 only when all tests pass. The * player field is not renamed as an unrelated stat. */ +#ifdef REGION_USA +/* USA glove records (archive E) keep the class bits at +0x182 and a halfword level at +0x180. */ +u32 sub_0805D2E0(void *state) { + u8 *resource; + s32 offset; + register struct Player61 *player asm("r0"); + if(state!=0 && *(u16 *)state==5 && M2C_FIELD(state,u8 *,8)==0) { + resource=(u8 *)sub_08007290(M2C_FIELD(state,u16 *,2)|0xE0000); + if((*(u16 *)(resource+0x182)>>sub_0801DE60())&1) { + offset=sizeof(struct Player61)*sub_080020F4(); + asm volatile("" : "+r" (offset)); + player=(void *)((u8 *)gParty61+offset); + + if(*(u16 *)(resource+0x180)<=player->limit) return 1; + } + } + return 0; +} +#else u32 sub_0805D2E0(void *arg0) { s32 temp_r4; s32 player; @@ -123,7 +150,7 @@ u32 sub_0805D2E0(void *arg0) { temp_r4 = sub_08007290(M2C_FIELD(arg0, u16 *, 2) | 0xE0000); if ((((s32) M2C_FIELD(temp_r4, u16 *, 0xA2) >> sub_0801DE60()) & 1) != 0) { player = sub_080020F4(); - limitPtr = (s16 *)((u8 *)gUnk_03003CE0 + player * 0x14C); + limitPtr = (s16 *)((u8 *)gUnk_03003CE0 + player * PLAYER_SIZE); resourceValue = *(u8 *)((u8 *)temp_r4 + 0xA1); limit = *(s16 *)((u8 *)limitPtr + 0x38); if (resourceValue <= limit) { @@ -133,11 +160,12 @@ u32 sub_0805D2E0(void *arg0) { } return 0U; } +#endif /* [HasNonfullBagCurrencyStack] Returns 1 if any of the 25 bag records is kind 10 with unsigned count at most * 99999; otherwise 0. It does not accept an empty bag slot as a substitute and does not check stash stacks. */ u32 sub_0805D348(void) { - u8 *entry = ((u8 *) gUnk_030034E0) + 0x150; + u8 *entry = ((u8 *) gUnk_030034E0) + SAVE_FIELD(0x150); int i; for (i = 0; i <= 0x18; i++, entry += 0x10) { @@ -181,7 +209,7 @@ s32 sub_0805D3D4(void) { var_r3 = 0; var_r2 = 0; - var_r1 = gUnk_030034E0 + 0x150; + var_r1 = gUnk_030034E0 + SAVE_FIELD(0x150); do { if (M2C_FIELD(var_r1, u16 *, 0) == 0xA) { var_r3 += M2C_FIELD(var_r1, s32 *, 4); @@ -200,7 +228,7 @@ s32 sub_0805D404(void) { var_r3 = 0; var_r2 = 0; - var_r1 = gUnk_030034E0 + 0x2E0; + var_r1 = gUnk_030034E0 + SAVE_FIELD(0x2E0); do { if (M2C_FIELD(var_r1, u16 *, 0) == 0xA) { var_r3 += M2C_FIELD(var_r1, s32 *, 4); @@ -318,7 +346,7 @@ s32 sub_0805D548(s32 arg0) { void *var_r1; var_r2 = 0; - var_r1 = gUnk_030034E0 + 0x150; + var_r1 = gUnk_030034E0 + SAVE_FIELD(0x150); loop_1: if ((M2C_FIELD(var_r1, u16 *, 0) == 1) && (M2C_FIELD(var_r1, u16 *, 2) == arg0)) { return (s32) var_r2; @@ -339,7 +367,7 @@ void sub_0805D580(u32 index) if (index <= 0x18) { new_var2 = gUnk_030034E0; - new_var = (s8 *) ((((u8 *) new_var2) + (8 * (2 * index))) + 0x150); + new_var = (s8 *) ((((u8 *) new_var2) + (8 * (2 * index))) + SAVE_FIELD(0x150)); *((u16 *) (new_var + 0)) = 0; } } @@ -354,7 +382,7 @@ u32 sub_0805D5A0(void) { u32 i; u32 result; u8 *entry; - for(j=0,entry=(u8 *)gUnk_030034E0+0x150;j<=24;entry+=16,j++) + for(j=0,entry=(u8 *)gUnk_030034E0+SAVE_FIELD(0x150);j<=24;entry+=16,j++) if(*(u16 *)entry==10) total+=*(u32 *)(entry+4); result=total>>1; for(i=0;i<=24;i++) { @@ -363,7 +391,7 @@ u32 sub_0805D5A0(void) { base+=offset; - if(*(u16 *)(base+0x150)==10) sub_0805D580(i); + if(*(u16 *)(base+SAVE_FIELD(0x150))==10) sub_0805D580(i); } return result; } @@ -378,7 +406,7 @@ s32 sub_0805D5F4(s32 start) { s32 index; s32 bestValue; if(bestIndex<0) bestIndex=0; - entry=(u8 *)gUnk_030034E0+(bestIndex*16+0x150); + entry=(u8 *)gUnk_030034E0+(bestIndex*16+SAVE_FIELD(0x150)); bestValue=-1; for(index=bestIndex;index<=24;index++,entry+=16) if(*(u16 *)entry==10) { @@ -406,10 +434,10 @@ s32 sub_0805D650(s32 arg0) { if (var_r4 < 0) { var_r4 = 0; } - var_r3 = (u8 *)gUnk_030034E0 + ((var_r4 * 0x10) + 0x2E0); + var_r3 = (u8 *)gUnk_030034E0 + ((var_r4 * 0x10) + SAVE_FIELD(0x2E0)); var_r5 = -1; var_r2 = var_r4; - temp_r0 = M2C_FIELD((void *)gUnk_030034E0,u16 *,0x6A) * 0xF; + temp_r0 = M2C_FIELD((void *)gUnk_030034E0,u16 *,SAVE_FIELD(0x6A)) * 0xF; if (var_r4 < temp_r0) { s32 excluded=100000; @@ -875,6 +903,9 @@ u32 sub_0805DF38(u32 unused0,u32 unused1,u32 unused2,u32 unused3,s32 duration,u3 task[0x70]=index; M2C_FIELD(task,u32 *,0x28)=sub_0805D720(0,14,27,3); if(duration==-2) { +#ifdef REGION_USA + sub_08065158(task+0x2C,0x50002,0,0x80000000,0); +#else switch(gUnk_03003470) { case 0: sub_08065158(task+0x2C,0x50002,0,0x80000000,0); break; case 1: sub_08065158(task+0x2C,0x5015B,0,0x80000000,0); break; @@ -882,6 +913,7 @@ u32 sub_0805DF38(u32 unused0,u32 unused1,u32 unused2,u32 unused3,s32 duration,u3 case 3: sub_08065158(task+0x2C,0x5015D,0,0x80000000,0); break; case 4: sub_08065158(task+0x2C,0x5015E,0,0x80000000,0); break; } +#endif } else if(duration>0) duration=140; if(M2C_FIELD(task,u32 *,0x28)==0) return 0; address=task+0x69; @@ -950,8 +982,591 @@ extern void text0C4(u8 *, u16, u32) asm("sub_0801A3D0"); extern void sub_08065264(void *, s32, s32, u16, u16); extern s32 anim0C4(void *, u16, u16 *, u16 *, s32) asm("sub_08065370"); extern u16 keys0C4 asm("gUnk_03001324"); +#ifdef REGION_USA +struct Char0C4 { u16 v; }; +struct Text0C4 { u16 c[14]; }; +struct Party0C4 { u16 name[PLAYER_SIZE / 2]; }; +extern struct Party0C4 party0C4[] asm("gUnk_03003CE2"); +extern u8 gUnk_084EBD48[]; +extern void draw0C4(void *, s32, s32, u32, s32) asm("sub_08065230"); + +void e0c4Impl(struct Task0C4 *task) asm("sub_0805E0C4"); +/* [TaskDialogueScriptWindow] Window task interprets byte script controls, resolves player-name/numeric + * substitutions and portrait resources, advances text according to timing/input, and draws buffered lines. + * Exact script opcode names and complete encoding remain unassigned. This C remains a NONMATCHING draft; the + * role is independently anchored by original ASM. */ +void e0c4Impl(struct Task0C4 *task) +{ + u16 lines[2][30]; + struct Asset0C4 asset; + u16 numBuf[10]; + u16 nameBuf[14]; + s32 value; + u32 skip; + u16 scroll; + u16 line; + u32 drawFlag; + u16 sfx; + u8 delay; + u8 speed; + u32 hold; + u32 blink; + /* Original first reads uninitialized frame slot SP+0xB8 at 0805EA88. */ + u8 blinkTimer; + u16 numIdx; + u16 strIdx; + u16 idx0; + u16 idx1; + u16 idx2; + u16 idx3; + u16 nameIdx; + u16 *playerName; + u32 voice; + u16 *script; + u16 *n0; + u16 *n1 = party0C4[1].name; + u16 *n2 = party0C4[2].name; + u16 *n3 = party0C4[3].name; + u32 portrait; + s32 *pValue; + s32 i; + s32 j; + s32 k; + s32 first; + u32 started; + /* One r4 pointer in the ROM: script + 1, the &value conversion pointer + and task->str in both text paths. */ + register u16 *next asm("r4"); + u16 c; + u16 attr; + u16 cf; + + script = (u16 *)task->script; + drawFlag = 0; + sfx = 0; + idx1 = 0; + idx2 = 0; + idx3 = 0; + pValue = &value; + for (i = 0; i < 2; i++) { + for (line = 0; line < 18; line++) + lines[i][line] = 0xFFFD; + } + if (*script != 0) + portrait = *script - 1; + else + portrait = 0xFFFF; + script++; + voice = *script; + script++; + if (sub_0800CE30() != 0) { + if (portrait != 0xFFFF) { + if (portrait < 0x10) { + sub_08065158(&asset, RES_ID(0x500A8), 0xF, -1, 0); + } else if (portrait < 0x20) { + sub_08065158(&asset, RES_ID(0x500A7), 0xF, -1, 0); + portrait -= 0x10; + } else { + sub_08065158(&asset, RES_ID(0x500C1), 0xF, -1, 0); + portrait -= 0x20; + } + } + } else { + if (portrait != 0xFFFF) { + if (portrait < 0x10) { + sub_08065158(&asset, RES_ID(0x500A8), 0xF, -1, 0); + } else if (portrait < 0x20) { + sub_08065158(&asset, RES_ID(0x500A7), 0xF, -1, 0); + portrait -= 0x10; + } else { + sub_08065158(&asset, RES_ID(0x500C1), 0xF, -1, 0); + portrait -= 0x20; + } + } + } + *pValue = sub_0801E4B0(); + /* The loop end stops cse1 from folding *(s32 *)next back to &value. */ + do { + next = (u16 *)&value; + } while (0); + /* i is cleared between the first call and its store (ROM movs r5,#0). */ + numBuf[i = 0] = sub_08000498((s32 *)next, 10000000); + numBuf[1] = sub_08000498((s32 *)next, 1000000); + numBuf[2] = sub_08000498((s32 *)next, 100000); + numBuf[3] = sub_08000498((s32 *)next, 10000); + numBuf[4] = sub_08000498((s32 *)next, 1000); + numBuf[5] = sub_08000498((s32 *)next, 100); + numBuf[6] = sub_08000498((s32 *)next, 10); + numBuf[7] = *(s32 *)next; + numBuf[8] = 0; + numIdx = 0; + first = 0; + for (i = 0; i <= 8; i++) { + if (numBuf[i] == 0 && numIdx == 0) { + numBuf[i] = 0xFF; + } else { + numBuf[i] += 0x41; + if (numIdx == 0) + first = i; + numIdx = 1; + } + } + for (i = 0; first <= 7; first++, i++) { + numBuf[i] = numBuf[first]; + } + { + /* ROM: num + i first, then the 0 in a register, then the 0xFFFD. */ + numBuf[i] = 0xFFFD; + numBuf[i + 1] = 0; + } + + playerName = party0C4[sub_080020F4()].name; + n0 = party0C4[0].name; + for (i = 0; i <= 9; i++) { + nameBuf[i] = n0[i]; + if (nameBuf[i] == 0xFFFD) + break; + } + if (sub_08002204() == 0) { + u16 *p, *t; + p = (u16 *)sub_08007290(0x1404DF); + for (j = 0; i <= 12; i++, j++) { + t = nameBuf; + k = j + 2; + if ((t[i] = p[k]) & 0x8000) { + goto found; + } + } + goto done; + found: + { s32 kz = 0xFFFD; t[i] = kz; } + { + s32 kk = i + 1; + nameBuf[kk] = 0; + } + } else { + s32 kk = i + 1; + nameBuf[kk] = 0; + } +done: + strIdx = 0; + numIdx = 0; + idx0 = 0; + nameIdx = 0; + attr = 0; + delay = 1; + hold = 0; + blink = 0; + skip = 0; + speed = 1; + sub_080653CC(); + + for (;;) { + switch (task->state) { + case 0: + gUnk_03005D6C &= ~(1 << task->index); + sub_0800035C(); + case 1: + { + struct Window0C4 *w = task->window; + u32 r = 0; + if (w->state == 3) + r = 1; + if (r) { + line = 0; + drawFlag = 1; + scroll = 0; + task->state = 3; + } + break; + } + case 2: + break; + case 3: + if (*script == 0xFFFE) { + task->state = 4; + break; + } + if (*script == 0xFFFF) { + if (line >= task->maxLines) { + task->state = 4; + script++; + break; + } + line++; + task->col = 0; + script++; + break; + } + if (*script == 0xFFFA) { + speed = 10; + script++; + } else if (*script == 0xFFF9) { + speed = 20; + script++; + } else if (*script == 0xFFF8) { + speed = 1; + script++; + } else if (*script == 0xFFFD) { + task->state = 6; + break; + } + if (--delay != 0xFF && (keys0C4 & 3) == 0) + break; + if ((sfx++ & 3) == 0) { + if (voice != 0) + sub_0805865C(voice + 0xC7); + else + sub_0805865C(0xC8); + } + if (*script == 0xFFFC) { + lines[line][task->col] = playerName[strIdx]; + strIdx++; + if (playerName[strIdx] == 0) { + script++; + strIdx = 0; + task->col--; + } + } else if (*script == 0xFFF6) { + lines[line][task->col] = n0[idx0]; + idx0++; + if (n0[idx0] == 0) { + script++; + idx0 = 0; + task->col--; + } + } else if (*script == 0xFFF4) { + lines[line][task->col] = n1[idx1]; + idx1++; + if (n1[idx1] == 0) { + script++; + idx1 = 0; + task->col--; + } + } else if (*script == 0xFFF3) { + lines[line][task->col] = n2[idx2]; + idx2++; + if (n2[idx2] == 0) { + script++; + idx2 = 0; + task->col--; + } + } else if (*script == 0xFFF2) { + lines[line][task->col] = n3[idx3]; + idx3++; + if (n3[idx3] == 0) { + script++; + idx3 = 0; + task->col--; + } + } else if (*script == 0xFFF5) { + lines[line][task->col] = nameBuf[nameIdx]; + nameIdx++; + if (nameBuf[nameIdx] == 0) { + script++; + nameIdx = 0; + task->col--; + } + } else if (*script == 0xFFFB) { + lines[line][task->col] = numBuf[numIdx]; + numIdx++; + if (numBuf[numIdx] == 0) { + script++; + numIdx = 0; + task->col--; + } + } else if ((next = task->str) != 0) { + lines[line][task->col] = next[strIdx]; + strIdx++; + if (next[strIdx] == 0) { + task->str = 0; + strIdx = 0; + task->col--; + } + } else { + lines[line][task->col] = *script; + script++; + } + task->col++; + lines[line][task->col] = 0xFFFD; + if (task->timer < 0 && (keys0C4 & 3) != 0) { + cf = *script; + if ((u16)(cf + 3) > 2) { + /* Copied at their use (no code emitted) so loop.c hoists + them after the &col / line*30 copies, as in the ROM. */ + struct Text0C4 *fastName; + u16 *fastNum; + u32 kFC = 0xFFFC; + do { + u32 cc = cf; asm("" : "+r"(cc)); + if (cc == kFC || strIdx != 0) { + lines[line][task->col] = playerName[strIdx]; + strIdx++; + if (playerName[strIdx] == 0) { + script++; + strIdx = 0; + task->col--; + } + } else if (cc == 0xFFF6 || idx0 != 0) { + lines[line][task->col] = n0[idx0]; + idx0++; + if (playerName[idx0] == 0) { + script++; + idx0 = 0; + task->col--; + } + } else if (cc == 0xFFF5 || nameIdx != 0) { + asm("" : "=g"(fastName) : "0"(nameBuf)); + lines[line][task->col] = fastName->c[nameIdx]; + nameIdx++; + if (fastName->c[nameIdx] == 0) { + script++; + nameIdx = 0; + task->col--; + } + } else if (cc == 0xFFFB || numIdx != 0) { + /* "=g": the spilled copy needs no in/out reload + register, leaving ldr r4 / str r4 as in the ROM. */ + asm("" : "=r"(fastNum) : "0"(numBuf)); + lines[line][task->col] = fastNum[numIdx]; + numIdx++; + if (fastNum[numIdx] == 0) { + script++; + numIdx = 0; + task->col--; + } + } else if ((next = task->str) != 0) { + lines[line][task->col] = next[strIdx]; + strIdx++; + if (next[strIdx] == 0) { + task->str = 0; + strIdx = 0; + task->col--; + } + } else { + u32 high = 0x8000; + high &= cf; + if (high) + script++; + lines[line][task->col] = *script; + script++; + } + task->col++; + cf = *script; + } while ((u16)(cf + 3) > 2); + } + lines[line][task->col] = 0xFFFD; + delay = speed; + } else { + delay = speed; + } + break; + case 4: + if (task->timer >= 0) { + skip = 1; + } else if (task->timer == -2) { + if (keys0C4 & 1) { + hold = 0x8D; + skip = 1; + } + } else { + if (keys0C4 & 1) { + skip = 1; + hold = 0x8D; + } + } + if (skip != 0 && hold++ > 0x8C) { + if (*script == 0xFFFE) { + script++; + if (*script == 0) + portrait = 0xFFFF; + else + portrait = *script - 1; + script++; + asm("" : : "r"(portrait), "r"(portrait), "r"(portrait), "r"(portrait), "r"(portrait), "r"(portrait), "r"(portrait), "r"(portrait)); + voice = *script; + if (sub_0800CE30() != 0) { + if (portrait != 0xFFFF) { + if (portrait < 0x10) { + sub_08065158(&asset, RES_ID(0x500A8), 0xF, -1, 0); + } else if (portrait < 0x20) { + sub_08065158(&asset, RES_ID(0x500A7), 0xF, -1, 0); + portrait -= 0x10; + } else { + sub_08065158(&asset, RES_ID(0x500C1), 0xF, -1, 0); + portrait -= 0x20; + } + } + } else { + if (portrait != 0xFFFF) { + if (portrait < 0x10) { + sub_08065158(&asset, RES_ID(0x500A8), 0xF, -1, 0); + } else if (portrait < 0x20) { + sub_08065158(&asset, RES_ID(0x500A7), 0xF, -1, 0); + portrait -= 0x10; + } else { + sub_08065158(&asset, RES_ID(0x500C1), 0xF, -1, 0); + portrait -= 0x20; + } + } + } + } + skip = 0; + hold = 0; + lines[0][0] = 0xFFFD; + lines[1][0] = 0xFFFD; + line = 0; + task->state = 3; + scroll = 0; + script++; + task->col = line; + delay = speed; + blink = 0; + break; + } + if (task->timer < 0) { + if (blinkTimer++ <= 0x1D) + blink = 1; + else if (blinkTimer > 0x1D) + blink = 0; + if (blinkTimer > 0x28) + blinkTimer = 0; + } + break; + case 5: + if (--scroll == 0) + task->state = 3; + break; + case 6: + if (task->timer == -1) { + if (keys0C4 & 1) { + drawFlag = 0; + task->state = 7; + { + struct Window0C4 *w = task->window; + if ((gUnk_03005D70 >> w->index) & 1) { + if (w->state == 1 || w->state == 3 || w->state == 4 || w->state == 2) { + w->state = 4; + sub_0805865C(0xDD); + } + } + } + blink = 0; + break; + } + if (blinkTimer++ <= 0x1D) + blink = 1; + else if (blinkTimer > 0x1D) + blink = 0; + if (blinkTimer > 0x28) + blinkTimer = 0; + break; + } + if (task->timer == -2) { + if (sub_08058DB0() == 0 && (keys0C4 & 0x20)) { + if (task->cursor != 0) + sub_0805865C(0xC6); + task->cursor = 0; + break; + } + if (sub_08058DB0() == 0 && (keys0C4 & 0x10)) { + if (task->cursor != 1) + sub_0805865C(0xC7); + task->cursor = 1; + break; + } + if (sub_08058DB0() == 0 && (keys0C4 & 1)) { + sub_0805865C(0xF); + drawFlag = 0; + task->state = 7; + { + struct Window0C4 *w = task->window; + if ((gUnk_03005D70 >> w->index) & 1) { + if (w->state == 1 || w->state == 3 || w->state == 4 || w->state == 2) { + w->state = 4; + sub_0805865C(0xDD); + } + } + } + break; + } + if (sub_08058DB0() == 0 && (keys0C4 & 2)) { + sub_0805865C(0x10); + task->cursor = 1; + drawFlag = 0; + task->state = 7; + { + struct Window0C4 *w = task->window; + if ((gUnk_03005D70 >> w->index) & 1) { + if (w->state == 1 || w->state == 3 || w->state == 4 || w->state == 2) { + w->state = 4; + sub_0805865C(0xDD); + } + } + } + break; + } + break; + } + if (task->timer-- <= 0) { + drawFlag = 0; + blink = 0; + { + struct Window0C4 *w = task->window; + if ((gUnk_03005D70 >> w->index) & 1) { + if (w->state == 1 || w->state == 3 || w->state == 4 || w->state == 2) { + w->state = 4; + sub_0805865C(0xDD); + } + } + } + task->state = 7; + } + break; + case 7: + { + u32 r; + struct Window0C4 *w; + drawFlag = 0; + w = task->window; + r = 0; + if (w->state == 0) + r = 1; + if (r) + task->state = drawFlag; + break; + } + } + if (sub_0800CC98() == 0 && drawFlag != 0) { + for (i = 0; i <= line; i++) + text0C4((u8 *)lines[i], task->x | attr, (u16)(scroll + task->y + i * 2)); + if (blink != 0) + text0C4(gUnk_084EBD48, 0x1C, 0x11); + if (portrait != 0xFFFF) { + sub_08000AF0(0x1F, asset.unkC + portrait * 32, 1); + asset.remap[portrait] = 0xF; + draw0C4(&asset, task->x * 8 + 0x18, task->y * 8 - 0x28, (u16)portrait, 0); + } + if (task->state == 6 && task->timer == -2) { + if (task->cursor != 0) { + anim0C4(&task->text, 5, &task->unk7A, &task->unk7E, 1); + sub_08065230(&task->text, 0x78, task->y * 8 - 0x18, 9, 0); + sub_08065264(&task->text, 0x88, task->y * 8 - 0x18, 5, task->unk7A); + sub_08065230(&task->text, 0x68, task->y * 8 - 0x18, 4, task->unk78); + } else { + anim0C4(&task->text, 4, &task->unk78, &task->unk7C, 1); + sub_08065230(&task->text, 0x78, task->y * 8 - 0x18, 8, 0); + sub_08065230(&task->text, 0x88, task->y * 8 - 0x18, 5, task->unk7A); + sub_08065264(&task->text, 0x68, task->y * 8 - 0x18, 4, task->unk78); + } + } + } + sub_080003F0(); + } +} +#else /* Party entries are 0x14C bytes; the name starts at gUnk_03003CE0 + 2. */ -struct Party0C4 { u8 name[0x14C]; }; +struct Party0C4 { u8 name[PLAYER_SIZE]; }; extern struct Party0C4 party0C4[] asm("gUnk_03003CE2"); extern u8 name1C4[] asm("gUnk_03003E2E"); extern u8 name2C4[] asm("gUnk_03003F7A"); @@ -1562,6 +2177,7 @@ void e0c4Impl(struct Task0C4 *task) sub_080003F0(); } } +#endif /* [TryRequestDialogueWindowClose] Returns 1 for null. For window state 3, requests state 4 when its used bit * is set, plays sound 0xDD, sets dialogue state +0x74 to 7, and returns 1. Window state 0 also returns 1; * other states return 0. */ @@ -1719,7 +2335,12 @@ void sub_0805EFBC_impl(void) * pool or allocate the distinct dialogue-task pool. */ void sub_0805F020(void) { +#ifdef REGION_USA + /* USA has a single language: no language index in the resource id. */ + void *src = sub_08007290((void *)0x10010003); +#else void *src = sub_08007290((u8 *)(uintptr_t)gUnk_03003470 + 0x10010003); +#endif CpuFastSet(src, (void *)0x06008000, 0x1000); { u8 *palette=sub_08007290((void *)0x70003); @@ -1737,7 +2358,11 @@ void sub_0805F020(void) * submissions when full, so this routine does not establish unconditional completed hardware upload or a fixed * elapsed-video-frame wait. */ void sub_0805F07C(void) { +#ifdef REGION_USA + sub_08001348(sub_08007290(0x10010003), 0x06008000, 0x4000); +#else sub_08001348(sub_08007290(gUnk_03003470 + 0x10010003), 0x06008000, 0x4000); +#endif sub_08000AF0(0xF, sub_08007290(0x70003) + 0x1E0, 1); sub_080003F0(); } @@ -1848,10 +2473,13 @@ void sub_0805F1B0_void(void) asm("sub_0805F1B0"); * sequence, and on any null stops only that asset setup. Success optionally uploads palette, sets * identity16-entry remap and initializes bounds. Invalid selector leaves selected asset unchanged. */ void sub_0805F1B0_void(void) { - load62(0x5000B,&asset62_03006040,9,-1,&gUnk_08518938); + load62(RES_ID(0x5000B),&asset62_03006040,9,-1,&gUnk_08518938); load62(0x50003,&asset62_03006074,9,-1,&gUnk_08518938); load62(0x50004,&asset62_030060A8,9,-1,&gUnk_08518938); load62(0x50005,&asset62_030060DC,9,-1,&gUnk_08518938); +#ifdef REGION_USA + load62(0x50006,&asset62_03005D80,9,4,&gUnk_08518938); +#else switch(gUnk_03003470) { case 0: load62(0x50006,&asset62_03005D80,9,4,&gUnk_08518938); @@ -1869,17 +2497,18 @@ void sub_0805F1B0_void(void) { load62(0x5000a,&asset62_03005D80,9,4,&gUnk_08518938); break; } - load62(0x500A3,&asset62_03005DC0,9,-1,&gUnk_08518938); - load62(0x500A1,&asset62_03005DF4,9,-1,&gUnk_08518938); - load62(0x500A4,&asset62_03005E28,9,-1,&gUnk_08518938); - load62(0x500A2,&asset62_03005E5C,9,-1,&gUnk_08518938); - load62(0x500DB,&asset62_03005E90,9,-1,&gUnk_08518938); - load62(0x500DC,&asset62_03005EC4,9,-1,&gUnk_08518938); - load62(0x500DE,&asset62_03005EF8,9,-1,&gUnk_08518938); - load62(0x500DD,&asset62_03005F2C,9,-1,&gUnk_08518938); - load62(0x500BD,&asset62_03005F60,9,-1,&gUnk_08518938); - load62(0x500AF,&asset62_03005F94,9,-1,&gUnk_08518938); - load62(0x500F1,&asset62_03005FC8,9,-1,&gUnk_08518938); +#endif + load62(RES_ID(0x500A3),&asset62_03005DC0,9,-1,&gUnk_08518938); + load62(RES_ID(0x500A1),&asset62_03005DF4,9,-1,&gUnk_08518938); + load62(RES_ID(0x500A4),&asset62_03005E28,9,-1,&gUnk_08518938); + load62(RES_ID(0x500A2),&asset62_03005E5C,9,-1,&gUnk_08518938); + load62(RES_ID(0x500DB),&asset62_03005E90,9,-1,&gUnk_08518938); + load62(RES_ID(0x500DC),&asset62_03005EC4,9,-1,&gUnk_08518938); + load62(RES_ID(0x500DE),&asset62_03005EF8,9,-1,&gUnk_08518938); + load62(RES_ID(0x500DD),&asset62_03005F2C,9,-1,&gUnk_08518938); + load62(RES_ID(0x500BD),&asset62_03005F60,9,-1,&gUnk_08518938); + load62(RES_ID(0x500AF),&asset62_03005F94,9,-1,&gUnk_08518938); + load62(RES_ID(0x500F1),&asset62_03005FC8,9,-1,&gUnk_08518938); } struct NumAsset63 { u32 f0, f4, f8; u8 data[40]; }; extern struct NumAsset63 numAssets63[] asm("gUnk_03006040"); diff --git a/src/code_0805FB7C.c b/src/code_0805FB7C.c index 70d0839b..a714d1a1 100644 --- a/src/code_0805FB7C.c +++ b/src/code_0805FB7C.c @@ -105,7 +105,7 @@ void sub_0805FC80(struct IconPosition63 pos, u16 *item, u32 flags) default: return; case 1: - descriptor = (u8 *)sub_08007290(entry[1] | 0x100000) + 0xA8; + descriptor = (u8 *)sub_08007290(entry[1] | 0x100000) + ITEM_FIELD(0xA8); packed = *(u16 *)descriptor; frame = *descriptor; group = packed >> 8; @@ -113,7 +113,7 @@ void sub_0805FC80(struct IconPosition63 pos, u16 *item, u32 flags) case 2: { u16 packed2; resource = (u8 *)sub_08007290(entry[1] | 0xB0000); - icon = resource + 0xBE; + icon = resource + ITEM_FIELD(0xBE); packed2 = *(u16 *)icon; frame = *icon; group = packed2 >> 8; @@ -122,12 +122,12 @@ void sub_0805FC80(struct IconPosition63 pos, u16 *item, u32 flags) alternate++; } else { overlay = ((u8 *)entry)[7]; - if (overlay == 0) overlay = *(u16 *)(resource + 0xBC); + if (overlay == 0) overlay = *(u16 *)(resource + ITEM_FIELD(0xBC)); } break; } case 3: - descriptor = (u8 *)sub_08007290(entry[1] | 0xC0000) + 0xB0; + descriptor = (u8 *)sub_08007290(entry[1] | 0xC0000) + EQUIP_FIELD(0xB0); packed = *(u16 *)descriptor; frame = *descriptor; group = packed >> 8; @@ -139,7 +139,7 @@ void sub_0805FC80(struct IconPosition63 pos, u16 *item, u32 flags) } break; case 4: - descriptor = (u8 *)sub_08007290(entry[1] | 0xD0000) + 0xB0; + descriptor = (u8 *)sub_08007290(entry[1] | 0xD0000) + EQUIP_FIELD(0xB0); packed = *(u16 *)descriptor; frame = *descriptor; group = packed >> 8; @@ -151,7 +151,7 @@ void sub_0805FC80(struct IconPosition63 pos, u16 *item, u32 flags) } break; case 5: - descriptor = (u8 *)sub_08007290(entry[1] | 0xE0000) + 0xB0; + descriptor = (u8 *)sub_08007290(entry[1] | 0xE0000) + EQUIP_E_FIELD(0xB0); packed = *(u16 *)descriptor; frame = *descriptor; group = packed >> 8; @@ -161,37 +161,44 @@ void sub_0805FC80(struct IconPosition63 pos, u16 *item, u32 flags) } break; case 7: - descriptor = (u8 *)sub_08007290(entry[1] | 0x110000) + 0xA8; + descriptor = (u8 *)sub_08007290(entry[1] | 0x110000) + ITEM_FIELD(0xA8); packed = *(u16 *)descriptor; frame = *descriptor; group = packed >> 8; break; case 6: - descriptor = (u8 *)sub_08007290(entry[1] | 0xF0000) + 0xAC; + descriptor = (u8 *)sub_08007290(entry[1] | 0xF0000) + ITEM_FIELD(0xAC); packed = *(u16 *)descriptor; frame = *descriptor; group = packed >> 8; break; case 9: - descriptor = (u8 *)sub_08007290(entry[1] | 0x150000) + 0xA0; + descriptor = (u8 *)sub_08007290(entry[1] | 0x150000) + ITEM_FIELD(0xA0); packed = *(u32 *)descriptor; frame = *descriptor; group = packed >> 8; break; case 10: - descriptor = (u8 *)sub_08007290(0x160000) + 0x9C; + descriptor = (u8 *)sub_08007290(0x160000) + ITEM_FIELD(0x9C); packed = *(u32 *)descriptor; frame = *descriptor; group = packed >> 8; break; case 8: - descriptor = (u8 *)sub_08007290(entry[1] | 0x120000) + 0xA0; + descriptor = (u8 *)sub_08007290(entry[1] | 0x120000) + ITEM_FIELD(0xA0); packed = *(u16 *)descriptor; frame = *descriptor; group = packed >> 8; break; } if (mode & 1) { +#ifdef REGION_USA + s32 rawY; + s32 cameraX; + s32 camera = sub_0800CCCC(); + worldX = pos.x >> 8; + cameraX = (s16)worldX; +#else /* Preserve the ROM's coordinate lifetimes and narrowing order. */ register s32 rawX asm("r2"); s32 rawY; @@ -202,6 +209,7 @@ void sub_0805FC80(struct IconPosition63 pos, u16 *item, u32 flags) rawX >>= 8; worldX = rawX; cameraX = (s16)rawX; +#endif rawY = pos.y; asm("" : : "r"(rawY)); @@ -265,6 +273,258 @@ extern s32 divFF63(s32 *, u32) asm("sub_08000498"); * independently anchored by original ASM. */ void sub_0805FFBC(s32 x, s32 y, struct ItemName63 *item, s32 flags) { +#ifdef REGION_USA + TextChar buf[30]; + TextChar numeric[30]; + s32 value; + u8 *res; + u8 *suffix; + s32 broken; + u32 level; + u32 grade; + s32 cursed; + u32 mode; + TextChar *name; + s32 n; + u8 i; + u32 k; + s16 off; + + if (item == NULL) + goto clear; + suffix = NULL; + broken = 0; + level = 0; + grade = 0; + cursed = 0; + mode = flags & 0x7FFFFFFF; + switch (item->kind) { + case 1: + res = resFF63(item->id | 0x100000); + name = (TextChar *)(res + gUnk_03003470 * 31 * sizeof(TextChar)); + broken = 0; + level = 0; + grade = 0; + break; + /* Cases 2-5 each load the suffix name themselves (not a shared label): + the per-case copies are cross-jumped into one, but each copy's reloads + advance the reload-register rotation the way the ROM's do. */ + case 2: + { + u8 *r = resFF63(item->id | 0xB0000); + name = (TextChar *)(r + gUnk_03003470 * 31 * sizeof(TextChar)); + broken = item->broken; + level = item->level; + grade = item->grade; + if (grade == 0) + grade = *(u16 *)(r + 0x194); + if (item->suffix != 0) + suffix = resFF63((item->suffix - 1) | 0x130000); + break; + } + case 3: + name = (TextChar *)(resFF63(item->id | 0xC0000) + gUnk_03003470 * 31 * sizeof(TextChar)); + broken = item->broken; + level = item->level; + grade = item->grade; + if (item->suffix != 0) + suffix = resFF63((item->suffix - 1) | 0x130000); + break; + case 4: + name = (TextChar *)(resFF63(item->id | 0xD0000) + gUnk_03003470 * 31 * sizeof(TextChar)); + broken = item->broken; + level = item->level; + grade = item->grade; + if (item->suffix != 0) + suffix = resFF63((item->suffix - 1) | 0x130000); + break; + case 7: + name = (TextChar *)(resFF63(item->id | 0x110000) + gUnk_03003470 * 31 * sizeof(TextChar)); + broken = 0; + level = 0; + break; + case 5: + { + u8 *r = resFF63(item->id | 0xE0000); + name = (TextChar *)(r + gUnk_03003470 * 31 * sizeof(TextChar)); + broken = item->broken; + level = item->level; + grade = item->grade; + if (*(u32 *)(r + 0x17C) != 0) + cursed = 1; + } + if (item->suffix != 0) + suffix = resFF63((item->suffix - 1) | 0x130000); + break; + case 6: + name = (TextChar *)(resFF63(item->id | 0xF0000) + gUnk_03003470 * 31 * sizeof(TextChar)); + broken = 0; + level = 0; + grade = 0; + break; + case 9: + name = (TextChar *)(resFF63(item->id | 0x150000) + gUnk_03003470 * 31 * sizeof(TextChar)); + break; + case 10: + if (sub_0800CC98() == 0) { + u32 *div; + TextChar *out; + s32 started; + register s32 *valuePtr asm("sl"); + value = *(s32 *)&item->suffix; + div = digitDivFF63; + out = numeric; + started = 0; + /* k is the function-scope counter also used as the name index in + mode 1; sharing it makes caller-saving unprofitable, so it takes r8. */ + k = 0; + valuePtr = &value; + for (; k <= 5; k++, div++) { + *out = divFF63(valuePtr, *div) + 0x41; + if (started != 0 || *out != 0x41) { + out++; + started = 1; + } + } + out[0] = 7; + out[1] = 0; + name = numeric; + } else { + name = (TextChar *)(resFF63(0x160000) + gUnk_03003470 * 31 * sizeof(TextChar)); + } + break; + case 8: + name = (TextChar *)(resFF63(item->id | 0x120000) + gUnk_03003470 * 31 * sizeof(TextChar)); + break; + default: + clear: + clearFF63(y, 2); + return; + } + + switch (mode) { + case 0: + if (broken != 0) { + TextChar *src, *dst; + buf[0] = 0x101; + n = 0; + if (*name != 0) { + src = name; + dst = buf + 1; + do { + *dst++ = *src++; + n++; + } while (*src != 0); + } + buf[n + 1] = TEXT_CTRL(0xFD); + break; + } + if (grade != 0) { + if (grade == 7) + grade = 6; + buf[0] = grade + 0x101; + n = 1; + } else { + n = 0; + } + if (cursed != 0) { + buf[n] = 0x12D; + n++; + } + for (i = 0; name[i] != 0 && i <= 0xF; i++) + buf[i + n] = name[i]; + n += i; + i = 0; + if (suffix != NULL) { + buf[n] = 0x51; + n++; + if (*(TextChar *)(suffix + ({ u32 o = ((gUnk_03003470 << 5) - gUnk_03003470) * 2; o; })) != 0) { + do { + buf[i + n] = *(TextChar *)(suffix + ({ u32 o = ((gUnk_03003470 << 5) - gUnk_03003470) * 2; u32 c = i * 2; c += o; c; })); + i++; + } while (*(TextChar *)(suffix + ({ u32 o = ((gUnk_03003470 << 5) - gUnk_03003470) * 2; u32 c = i * 2; c += o; c; })) != 0); + } + } + i = i + n; + if (level != 0) { + if (level <= 9) { + u32 tens; + buf[i++] = 0x4C; + tens = level / 10; + level = level % 10; + if (tens != 0) + buf[i++] = tens + 0x41; + buf[i++] = level + 0x41; + } else { + buf[i++] = 0x4C; + buf[i++] = level + 0x10C; + } + buf[i] = TEXT_CTRL(0xFD); + } + buf[i] = TEXT_CTRL(0xFD); + break; + case 1: + i = 0; + if (broken != 0) { + buf[0] = 0x101; + i = 1; + } else if (item->kind == 1) { + if (*(u16 *)(res + 0x178) == 1) { + u32 v; + if (checkFF63() == 0) + v = *(u16 *)(res + 0x17A) * (*(u16 *)(gUnk_030034E0 + SAVE_FIELD(0x48)) << 2); + else + v = *(u16 *)(res + 0x17A); + for (i = 0; name[i] != TEXT_CTRL(0xFD) && name[i] != 0xEF; i++) + buf[i] = name[i]; + k = i + 3; + if (name[i] != TEXT_CTRL(0xFD)) { + n = v / 100; + v = v % 100; + if (n != 0) + buf[i++] = n + 0xEF; + n = v / 10; + v = v % 10; + buf[i++] = n + 0xEF; + buf[i++] = v + 0xEF; + } + for (; name[k] != 0; k++, i++) + buf[i] = name[k]; + } else { + while (name[i] != TEXT_CTRL(0xFD)) { + buf[i] = name[i]; + i++; + } + } + } else { + while (name[i] != 0) { + buf[i] = name[i]; + i++; + } + } + buf[i] = TEXT_CTRL(0xFD); + break; + case 2: + i = 0; + if (broken != 0) { + buf[0] = 0x101; + i = 1; + } else { + while (name[i] != TEXT_CTRL(0xFD)) { + buf[i] = name[i]; + i++; + } + } + buf[i] = 0; + break; + } + off = 0; + if (flags < 0) { + n = widthFF63((u8 *)buf) >> 1; + off = -n; + } + textFF63((u8 *)buf, off + x, y); +#else u8 buf[32]; u8 numeric[32]; s32 value; @@ -292,7 +552,7 @@ void sub_0805FFBC(s32 x, s32 y, struct ItemName63 *item, s32 flags) switch (item->kind) { case 1: res = resFF63(item->id | 0x100000); - name = res + gUnk_03003470 * 31; + name = res + gUnk_03003470 * 31 * sizeof(TextChar); broken = 0; level = 0; grade = 0; @@ -303,7 +563,7 @@ void sub_0805FFBC(s32 x, s32 y, struct ItemName63 *item, s32 flags) case 2: { u8 *r = resFF63(item->id | 0xB0000); - name = r + gUnk_03003470 * 31; + name = r + gUnk_03003470 * 31 * sizeof(TextChar); broken = item->broken; level = item->level; grade = item->grade; @@ -314,7 +574,7 @@ void sub_0805FFBC(s32 x, s32 y, struct ItemName63 *item, s32 flags) break; } case 3: - name = resFF63(item->id | 0xC0000) + gUnk_03003470 * 31; + name = resFF63(item->id | 0xC0000) + gUnk_03003470 * 31 * sizeof(TextChar); broken = item->broken; level = item->level; grade = item->grade; @@ -322,7 +582,7 @@ void sub_0805FFBC(s32 x, s32 y, struct ItemName63 *item, s32 flags) suffix = resFF63((item->suffix - 1) | 0x130000); break; case 4: - name = resFF63(item->id | 0xD0000) + gUnk_03003470 * 31; + name = resFF63(item->id | 0xD0000) + gUnk_03003470 * 31 * sizeof(TextChar); broken = item->broken; level = item->level; grade = item->grade; @@ -330,14 +590,14 @@ void sub_0805FFBC(s32 x, s32 y, struct ItemName63 *item, s32 flags) suffix = resFF63((item->suffix - 1) | 0x130000); break; case 7: - name = resFF63(item->id | 0x110000) + gUnk_03003470 * 31; + name = resFF63(item->id | 0x110000) + gUnk_03003470 * 31 * sizeof(TextChar); broken = 0; level = 0; break; case 5: { u8 *r = resFF63(item->id | 0xE0000); - name = r + gUnk_03003470 * 31; + name = r + gUnk_03003470 * 31 * sizeof(TextChar); broken = item->broken; level = item->level; grade = item->grade; @@ -348,13 +608,13 @@ void sub_0805FFBC(s32 x, s32 y, struct ItemName63 *item, s32 flags) suffix = resFF63((item->suffix - 1) | 0x130000); break; case 6: - name = resFF63(item->id | 0xF0000) + gUnk_03003470 * 31; + name = resFF63(item->id | 0xF0000) + gUnk_03003470 * 31 * sizeof(TextChar); broken = 0; level = 0; grade = 0; break; case 9: - name = resFF63(item->id | 0x150000) + gUnk_03003470 * 31; + name = resFF63(item->id | 0x150000) + gUnk_03003470 * 31 * sizeof(TextChar); break; case 10: if (sub_0800CC98() == 0) { @@ -381,11 +641,11 @@ void sub_0805FFBC(s32 x, s32 y, struct ItemName63 *item, s32 flags) out[1] = 0; name = numeric; } else { - name = resFF63(0x160000) + gUnk_03003470 * 31; + name = resFF63(0x160000) + gUnk_03003470 * 31 * sizeof(TextChar); } break; case 8: - name = resFF63(item->id | 0x120000) + gUnk_03003470 * 31; + name = resFF63(item->id | 0x120000) + gUnk_03003470 * 31 * sizeof(TextChar); break; default: clear: @@ -554,24 +814,25 @@ void sub_0805FFBC(s32 x, s32 y, struct ItemName63 *item, s32 flags) off = -n; } textFF63(buf, off + x, y); +#endif } struct HudPlayer63 { - u8 pad0[0x20]; + u8 pad0[PLAYER_FIELD(0x20)]; u16 state; - u8 pad22[2]; + u8 pad22[PLAYER_FIELD(0x24) - PLAYER_FIELD(0x22)]; s16 f24; s16 f26; - u8 pad28[8]; + u8 pad28[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x28)]; u32 flags; - u8 pad34[0x34]; + u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 f68; - u8 pad69[0xE]; + u8 pad69[PLAYER_FIELD(0x77) - PLAYER_FIELD(0x69)]; u8 count; u8 f78; - u8 pad79[0x14C - 0x79]; + u8 pad79[PLAYER_SIZE - PLAYER_FIELD(0x79)]; }; struct HudSlot63 { u8 b[0x10]; }; -struct HudMgr63 { u8 pad0[0x68]; u16 sel; u8 pad6A[6]; struct HudSlot63 slots[1]; }; +struct HudMgr63 { u8 pad0[PLAYER_FIELD(0x68)]; u16 sel; u8 pad6A[PLAYER_FIELD(0x70) - PLAYER_FIELD(0x6A)]; struct HudSlot63 slots[1]; }; struct HudPos63 { s16 x, y; }; extern struct HudPlayer63 hudPlayers63[] asm("gUnk_03003CE0"); extern struct HudMgr63 *hudMgr63 asm("gUnk_030034E0"); @@ -826,7 +1087,7 @@ void sub_08060DB0(s32 index) sub_08000274(&tasks63[index], index); } struct HudSlotE63 { u16 kind; u16 id; u8 pad4[0xC]; }; -struct HudMgrE63 { u8 pad0[0x54]; u16 sel; u16 list[0x7D]; struct HudSlotE63 bag[25]; }; +struct HudMgrE63 { u8 pad0[SAVE_FIELD(0x54)]; u16 sel; u16 list[0x7D]; struct HudSlotE63 bag[25]; }; extern struct HudMgrE63 *hudMgrE63 asm("gUnk_030034E0"); extern u16 hudFrameE63[4][8] asm("gUnk_084EBDC8"); extern struct HudPos63 hudPosE63[] asm("gUnk_084EBE08"); @@ -1139,7 +1400,7 @@ void sub_0806171C(void *raw,s32 value) NumberDraw64(&numberSprite64,screenX-6,screenY-8,4,6); } /* SS1 player_rise_effect.c (52c0fa73870fab238941e32be7eff172e9bad71f), adapted to SS2 ASM. */ -struct RisePlayer64 { u8 pad0[0x30]; u32 flags; u8 pad34[0x58]; s32 x,y; }; +struct RisePlayer64 { u8 pad0[PLAYER_FIELD(0x30)]; u32 flags; u8 pad34[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x34)]; s32 x,y; }; struct RiseSprite64 { u32 base,unused,data; u8 padC[0x10]; u8 attr[24]; }; extern struct RiseSprite64 riseSprite64 asm("gUnk_03005D80"); extern u32 riseCoords64(s32,s32,s16 *,s16 *,u32,u32) asm("sub_0800BC08"); @@ -1454,7 +1715,7 @@ extern u8 *saveData64 asm("gUnk_03004210"); struct SaveFile64 { u8 pad[0xD8]; u16 hD8, hDA; u16 h[10]; u8 padF0[0x1DC-0xF0]; struct SaveItem64 items[16]; struct SaveEntry64 ent[8]; }; extern u8 *saveStats64 asm("gUnk_03005CF4"); extern u8 *saveItems64 asm("gUnk_03005D58"); -struct SavePlayer64 { u8 pad0[0x2C]; u16 f2C,f2E; u8 pad30[0xC2-0x30]; u16 fC2,fC4,fC6; u8 padC8[0x14C-0xC8]; }; +struct SavePlayer64 { u8 pad0[PLAYER_FIELD(0x2C)]; u16 f2C,f2E; u8 pad30[PLAYER_FIELD(0xC2) - (PLAYER_FIELD(0x2F) + 1)]; u16 fC2,fC4,fC6; u8 padC8[PLAYER_SIZE - PLAYER_FIELD(0xC8)]; }; extern struct SavePlayer64 savePlayers64[] asm("gUnk_03003CE0"); extern u8 savePlayerPtr64[] asm("gUnk_03003D14"); extern u8 saveMap64[] asm("gUnk_03003170"); @@ -1518,7 +1779,11 @@ if (savePlayers64[sub_080020F4()].f2E == 0){ *(u32 *)(dp+0x28) = *(u32 *)(stats+0x38);} (*(u16 *)((u8 *)(saveData64)+0x1C)) = (u16) savePlayers64[sub_080020F4()].f2E; (*(u16 *)((u8 *)(saveData64)+0x1E)) = (u16) savePlayers64[sub_080020F4()].f2C; -{u32 id=sub_080020F4(); u8 *d=saveData64; u8 *p=(u8 *)&savePlayers64[id]; *(struct SavePair64 *)(d+0x30)=*(struct SavePair64 *)(p+0xA4);} +#ifdef REGION_USA +{u32 id=sub_080020F4(); u8 *d=saveData64; *(struct SavePair64 *)(d+0x30)=*(struct SavePair64 *)(id*PLAYER_SIZE+((u8 *)savePlayers64+PLAYER_FIELD(0xA4)));} +#else +{u32 id=sub_080020F4(); u8 *d=saveData64; u8 *p=(u8 *)&savePlayers64[id]; *(struct SavePair64 *)(d+0x30)=*(struct SavePair64 *)(p+PLAYER_FIELD(0xA4));} +#endif (*(u16 *)((u8 *)(saveData64)+0x20)) = (u16) savePlayers64[sub_080020F4()].fC4; (*(u16 *)((u8 *)(saveData64)+0x22)) = (u16) savePlayers64[sub_080020F4()].fC2; {u32 id=sub_080020F4(); u8 *d=saveData64; *(u16*)(d+0x24)=savePlayers64[id].fC6; *(u32*)(d+0x2C)=saveFlags64 & 0xFFFFFEFF;} @@ -1528,7 +1793,7 @@ if (savePlayers64[sub_080020F4()].f2E == 0){ {u8 *d=saveData64; u32 o; u8 *s; o=var_r5*2; d+=0xDC; d+=o; s=saveStats64+0x22; *(u16*)d=*(u16*)(s+o);} var_r5 += 1; } while (var_r5 <= 9U); - {register u8 *pp asm("r6"); var_r5=0; pp=savePlayerPtr64; var_r4_2=0; do { *(struct SaveEntry64 *)(saveData64+var_r4_2+0x3DC)=*(struct SaveEntry64 *)(var_r4_2+*(u32 *)(pp+0x14C*sub_080020F4())); var_r4_2+=40; var_r5++; } while(var_r5<=7);} + {register u8 *pp asm("r6"); var_r5=0; pp=savePlayerPtr64; var_r4_2=0; do { *(struct SaveEntry64 *)(saveData64+var_r4_2+0x3DC)=*(struct SaveEntry64 *)(var_r4_2+*(u32 *)(pp+PLAYER_SIZE*sub_080020F4())); var_r4_2+=40; var_r5++; } while(var_r5<=7);} } } else { data=saveData64;stats=saveStats64; @@ -1540,7 +1805,11 @@ if (savePlayers64[sub_080020F4()].f2E == 0){ (*(u16 *)((u8 *)(saveData64)+0x20)) = (u16) savePlayers64[sub_080020F4()].fC4; (*(u16 *)((u8 *)(saveData64)+0x22)) = (u16) savePlayers64[sub_080020F4()].fC2; (*(u16 *)((u8 *)(saveData64)+0x24)) = (u16) savePlayers64[sub_080020F4()].fC6; -{u32 id=sub_080020F4(); u8 *d=saveData64; u8 *p=(u8 *)&savePlayers64[id]; *(struct SavePair64 *)(d+0x30)=*(struct SavePair64 *)(p+0x8C);} +#ifdef REGION_USA +{u32 id=sub_080020F4(); u8 *d=saveData64; *(struct SavePair64 *)(d+0x30)=*(struct SavePair64 *)(id*PLAYER_SIZE+((u8 *)savePlayers64+PLAYER_FIELD(0x8C)));} +#else +{u32 id=sub_080020F4(); u8 *d=saveData64; u8 *p=(u8 *)&savePlayers64[id]; *(struct SavePair64 *)(d+0x30)=*(struct SavePair64 *)(p+PLAYER_FIELD(0x8C));} +#endif (*(u32 *)((u8 *)(saveData64)+0x2C)) = (s32) (saveFlags64 & 0xFFFFFEFF); var_r5=0; do { {u8 *d = saveData64; ((struct SaveFile64 *)d)->items[var_r5]=((struct SaveItem64 *)saveItems64)[var_r5];} var_r5++; } while(var_r5<=15); var_r5 = 0; @@ -1548,7 +1817,7 @@ if (savePlayers64[sub_080020F4()].f2E == 0){ {u8 *d=saveData64; u32 o; u8 *s; o=var_r5*2; d+=0xDC; d+=o; s=saveStats64+0x22; *(u16*)d=*(u16*)(s+o);} var_r5 += 1; } while (var_r5 <= 9U); - {register u8 *pp asm("r6"); var_r5=0; pp=savePlayerPtr64; var_r4=0; do { *(struct SaveEntry64 *)(saveData64+var_r4+0x3DC)=*(struct SaveEntry64 *)(var_r4+*(u32 *)(pp+0x14C*sub_080020F4())); var_r4+=40; var_r5++; } while(var_r5<=7);} + {register u8 *pp asm("r6"); var_r5=0; pp=savePlayerPtr64; var_r4=0; do { *(struct SaveEntry64 *)(saveData64+var_r4+0x3DC)=*(struct SaveEntry64 *)(var_r4+*(u32 *)(pp+PLAYER_SIZE*sub_080020F4())); var_r4+=40; var_r5++; } while(var_r5<=7);} } if (saveWrite64() == 0) { sub_08006BF8(); @@ -1785,6 +2054,320 @@ static inline void DrawScaled624(struct Spr624 *p, s32 x, s32 y, u16 id, u16 fra void sub_080624D8_(void) asm("sub_080624D8"); void sub_080624D8_(void) { +#ifdef REGION_USA + struct Menu624 m; + u32 sel; + u16 k; + s16 scale, step; + u8 *win; + u16 i; + s32 t, u, t1; + s16 w; + s16 x; + s32 sx, sy; + struct TileSys *ts; + s16 *px, *py; + u32 ok; + u8 *p; + struct Pt624 *d; + s32 *dy; + + if (sub_0800CD8C() || sub_0800D11C() || sub_0805EF90()) + goto out; + Load624(0x50002, &m.spr, 0xB, -1, res624); + Scale624(&m.spr, 0x120, 0xE0, 8); + for (i = 0; i <= 3; i++) + m.text[i] = (u8 *)sub_08007290(msg624[i]); + while (sub_0801AC78() == 0) + sub_080003F0(); + sub_0800CE40(); + t1 = 0; + d = dst624; + dy = dstY624; + sub_0805865C(0x12); + do { + sub_08015C14(); + for (i = 0; i <= 3; i++) { + u = 0x400 - t1; + Lerp624(&m.x[i], src624[i].x, d[i].x, t1, u); + Lerp624(&m.y[i], src624[i].y, dy[i * 2], t1, u); + if (i == 1 && (PLAYER_FLAGS() & 8)) + Draw624(&m.spr, m.x[1] >> 8, m.y[1] >> 8, 7, 0); + else + Draw624(&m.spr, m.x[i] >> 8, m.y[i] >> 8, i, 0); + } + t1 += 0x80; + sub_080003F0(); + } while (t1 <= 0x3FF); + + sub_0801A664(0x12, 2); + win = window624(9, 0xF, 9, 1); + k = gUnk_03003170.curLevel; + sel = 1; + if (k != 0xC) + sel = 0; + step = 8; + scale = 0x100; + for (;;) { + sub_08015C14(); + scale += step; + if (step > 0 && scale > 0x120) + step = -8; + if (step < 0 && scale < 0xE0) + step = 8; + for (i = 0; i <= 3; i++) { + Size624(&m.spr, i, &m.w[i], &m.h[i], 1); + if (sel == i) { + if (i == 1 && (PLAYER_FLAGS() & 8)) + DrawScaled624(&m.spr, dst624[1].x >> 8, dst624[1].y >> 8, 7, m.w[1]); + else + DrawScaled624(&m.spr, dst624[i].x >> 8, dy[i * 2] >> 8, i, m.w[i]); + } else { + if (i == 1 && (PLAYER_FLAGS() & 8)) + Draw624(&m.spr, dst624[1].x >> 8, dst624[1].y >> 8, 7, m.w[1]); + else + Draw624(&m.spr, dst624[i].x >> 8, dy[i * 2] >> 8, i, m.w[i]); + } + } + w = (u32)sub_0801A638(m.text[sel] + TEXT_HEADER) >> 1; + x = -w; + text624(m.text[sel] + TEXT_HEADER, (u16)(x + 15), 16); + sub_080003F0(); + if (BUSY()) + keys624 = 2; + if (sub_0800CD8C()) { + keys624 = 0; + held624 = 0; + } + if (keys624 & 1) { + if (sel > 2) { + u16 *c = (u16 *)(state624 + 0x14A); + u32 n = *c + 1; + u32 zero = 0; + *c = n; + if ((u16)n > 7) + *c = zero; + sub_0805865C(0xF); + continue; + } + sub_0805865C(0xF); + goto confirm; + } + if (keys624 & 2) { + sub_0805865C(0x10); + if (sub_0800CDF8() == 0) { + t = 0x400; + do { + for (i = 0; i <= 3; i++) { + u = 0x400 - t; + Lerp624(&m.x[i], src624[i].x, dst624[i].x, t, u); + Lerp624(&m.y[i], src624[i].y, dst624[i].y, t, u); + if (i == 1 && (PLAYER_FLAGS() & 8)) + Draw624(&m.spr, m.x[1] >> 8, m.y[1] >> 8, 7, 0); + else + Draw624(&m.spr, m.x[i] >> 8, m.y[i] >> 8, i, 0); + } + t -= 0x80; + sub_080003F0(); + } while (t > 0); + } + while (sub_0805EEDC(win) == 0) + sub_080003F0(); + sub_0805F0F0(win); + while (sub_0805EEEC(win) == 0) + sub_080003F0(); + if (sub_0800CD8C() == 0 && sub_0800D11C() == 0) + sub_08015C38(); + out: + sub_0800CE54(); + sub_0800D04C(); + return; + } + if (keys624 & 0x40) { + if (gUnk_03003170.curLevel == 0xC) + goto buzz; + if (sel != 0) + sub_0805865C(0x62); + sel = 0; + continue; + } + if (keys624 & 0x20) { + if (sub_0800CDC0()) + goto buzz; + if (sel != 1) + sub_0805865C(0x62); + sel = 1; + continue; + } + if (keys624 & 0x80) { + if (sub_0800CDC0() && !sub_0800CCCC()) + goto buzz; + if (sub_08002204() == 0) + continue; + ok = 1; + switch (gUnk_03003170.curLevel) { + case 2: + if (gUnk_03003170.f90 == 4 || gUnk_03003170.f90 == 7) + ok = 0; + break; + case 4: + if (gUnk_03003170.f90 == 6) + ok = 0; + break; + case 5: + if (gUnk_03003170.f90 == 0 || gUnk_03003170.f90 == 10) + ok = 0; + break; + case 1: + case 3: + case 7: + if (gUnk_03003170.f90 == 4) + ok = 0; + break; + case 8: + if (gUnk_03003170.f90 == 0) + ok = 0; + break; + case 19: + if (gUnk_03003170.f90 == 2) + ok = 0; + break; + case 11: + case 12: + case 13: + ok = 0; + break; + } + if (ok == 0) + goto buzz; + if (sel != 2) + sub_0805865C(0x62); + sel = 2; + continue; + buzz: + sub_0805865C(0x61); + continue; + } + if (keys624 & 0x10) { + if (sel != 3) + sub_0805865C(0x62); + sel = 3; + } + } + +confirm: + while (sub_0805EEDC(win) == 0) { + if (BUSY()) + sel = 4; + sub_080003F0(); + } + if (BUSY()) + sel = 4; + sub_080003F0(); + if (BUSY()) + sel = 4; + sub_080003F0(); + if (BUSY()) + sel = 4; + sub_0805F0F0(win); + if (sel != 2) + sub_0801ABE8(6); + t = 0x400; + do { + for (i = 0; i <= 3; i++) { + u = 0x400 - t; + Lerp624(&m.x[i], src624[i].x, dst624[i].x, t, u); + Lerp624(&m.y[i], src624[i].y, dst624[i].y, t, u); + if (i == 1 && (PLAYER_FLAGS() & 8)) + Draw624(&m.spr, m.x[1] >> 8, m.y[1] >> 8, 7, 0); + else + Draw624(&m.spr, m.x[i] >> 8, m.y[i] >> 8, i, 0); + } + t -= 0x80; + if (BUSY2()) + sel = 4; + sub_080003F0(); + } while (t > 0 || sub_0801AAE0() == 0); + while (sub_0805EEEC(win) == 0) { + if (BUSY2()) + sel = 4; + sub_080003F0(); + } + switch (sel) { + case 0: + sub_0800BB54(); + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + ts = &gUnk_03003170; + sx = (s16)ts->scrollX; + sy = (s16)ts->scrollY; + sub_0800CCA8(); + sub_08084F24(); + sub_080003F4(0x11201100); + ts->scrollX = sx; + ts->scrollY = sy; + for (i = 0; i <= 0x18; i++) { + p = party624; p += i * 16; + if (*(u16 *)(p + SAVE_FIELD(0x150)) == 7) + *(u16 *)(p + SAVE_FIELD(0x156)) = 0; + } + sub_0800CCB8(); + goto reset; + case 1: + sub_0800BB54(); + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + sub_0800CCA8(); + ts = &gUnk_03003170; + px = (s16 *)&ts->scrollX; + sx = *px; + py = (s16 *)&ts->scrollY; + sy = *py; + sub_08084EAC(); + goto restore; + case 2: + sub_08061E44(0); + break; + case 3: + sub_0800BB54(); + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + sub_0800CCA8(); + ts = &gUnk_03003170; + px = (s16 *)&ts->scrollX; + sx = *px; + py = (s16 *)&ts->scrollY; + sy = *py; + restore: + sub_080003F4(0x11201100); + *px = sx; + *py = sy; + sub_0800CCB8(); + gUnk_03003CE0[sub_080020F4()].flags &= ~8; + reset: + sub_08000420(0x514C8); + break; + case 4: + sub_0801AB50(6); + break; + } + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + sub_080003F0(); + while (sub_0801AAE0() == 0) + sub_080003F0(); + if (sub_0800CD8C() == 0 && sub_0800D11C() == 0 && sub_0800D060() == 0) + sub_08015C38(); + sub_0800D04C(); + sub_0800CE54(); +#else struct Menu624 m; u32 sel; u16 k; @@ -2116,6 +2699,7 @@ void sub_080624D8_(void) sub_08015C38(); sub_0800D04C(); sub_0800CE54(); +#endif } struct T65Draw { u32 base; u32 unk4; u8 *data; u32 unkC; u8 pad[12]; u8 style; u8 rest[23]; }; struct T65Level { u16 count; u8 pad[114]; }; @@ -2137,8 +2721,8 @@ static inline u16 t65_readLevel(u16 *p) {register u16 *p1 asm("r1")=p; return *p static inline void t65_flags(void) { u32 id=sub_080020F4(); u8 *base=(u8 *)t65_players; - u32 offset=0x14C; - offset*=id; base+=0x30; offset+=(u32)base; + u32 offset=PLAYER_SIZE; + offset*=id; base+=PLAYER_FIELD(0x30); offset+=(u32)base; { u32 *p=(u32 *)offset; *p &= ~0x80; } } static inline u16 t65_width(struct T65Pair *p) {register struct T65Pair *p1 asm("r1")=p; return p1->x;} @@ -2234,7 +2818,7 @@ void t65_popupImplementation(u32 packed,u32 arg) register s16 *yPtr asm("r5"); u32 done; u32 i; - {register u32 resource asm("r4")=0x50130; + {register u32 resource asm("r4")=RES_ID(0x50130); register void *table asm("r9"); register struct T65Popup *descriptor asm("sl"); u32 style;s32 mode;register void *base asm("r2"); @@ -2285,7 +2869,7 @@ void t65_popupImplementation(u32 packed,u32 arg) *(u32 *)((u8 *)sub_0800048C()+8)=0; } struct T65CPopup { u32 base, unk4; u8 *data; u32 sound, resource, style, mode; u8 palette[24]; }; -struct T65CPlayer { u8 bytes[0x14C]; }; +struct T65CPlayer { u8 bytes[PLAYER_SIZE]; }; struct T65CResource { u32 id; u8 pad[84]; }; struct T65CState { u8 pad[0x90]; u16 area; }; extern struct T65CPlayer t65C_players[] asm("gUnk_03003CE0"); @@ -2298,7 +2882,7 @@ extern u32 t65C_position(s32,s32,s16 *,s16 *,u32,u32) asm("sub_0800BC08"); extern struct DrawNode005 *t65C_overlay(s32,s32,u32,u32,u32,void *,u8 *,u32) asm("sub_08008E74"); #define T65C_H(p,o) (*(u16 *)((p)+(o))) #define T65C_W(p,o) (*(u32 *)((p)+(o))) -#define T65C_ENTITY(p) (*(u8 **)((p)+0x148)) +#define T65C_ENTITY(p) (*(u8 **)((p)+PLAYER_FIELD(0x148))) static inline s32 t65C_init(struct T65CPopup *obj,u32 resource,s32 index,s32 size) { void *table = t65C_resources; @@ -2343,7 +2927,7 @@ void t65C_impl(s32 index) u32 text; s32 zero,cc,z2; u8 *p=t65C_players[index].bytes; - t65C_init(&label,0x5005E,5,-1); + t65C_init(&label,RES_ID(0x5005E),5,-1); label.palette[0]=15; worldY=((struct Remote65C *)T65C_ENTITY(p))->y; worldX=((struct Remote65C *)T65C_ENTITY(p))->x; @@ -2357,7 +2941,7 @@ void t65C_impl(s32 index) h0=heightZero; } frame=text; - t65C_init(&sprite,t65C_resourceTable[T65C_H(p,0x64)].id,0,-1); + t65C_init(&sprite,t65C_resourceTable[T65C_H(p,PLAYER_FIELD(0x64))].id,0,-1); sprite.palette[0]=T65C_H(p,0); zero=sub_0800CF80(); if (zero) goto cleanup; @@ -2365,11 +2949,11 @@ void t65C_impl(s32 index) text=0x21; if (index==sub_080020F4()) { sub_0805865C(0x75); - T65C_H(p,0x1C)=zero; + T65C_H(p,PLAYER_FIELD(0x1C))=zero; } while (frame<=159) { t65C_position((s16)worldX,(s16)worldY,&x,&y,0x30,0); - T65C_H(p,0xB6)=t65C_measure(0x21,&w0,&h0,(*(u8 **)((u8 *)&sprite+8))); + T65C_H(p,PLAYER_FIELD(0xB6))=t65C_measure(0x21,&w0,&h0,(*(u8 **)((u8 *)&sprite+8))); t65C_measure(0,&w1,&h1,label.data); t65C_measure(1,&w2,&h2,label.data); if (sub_0800CC98()) goto skipDraw; @@ -2384,19 +2968,19 @@ void t65C_impl(s32 index) drawTest: if ((((struct Remote65C *)T65C_ENTITY(p))->byte4.region.value&~0x20U)!=t65C_state.area) goto skipDraw; sub_08000AF0(0x1F,(void *)label.sound,1); - if (T65C_W(p,0x30)&0x2000) { + if (T65C_W(p,PLAYER_FIELD(0x30))&0x2000) { if (!(t65C_flags&1)) { t65C_draw(x,y-frame,text,w0,1,sprite.palette,(*(u8 **)((u8 *)&sprite+8)),sprite.base); sub_08000AF0(T65C_H(p,0)+16,(void *)(sprite.sound+0x1C0),1); } } else { t65C_draw(x,y-frame,text,w0,1,sprite.palette,(*(u8 **)((u8 *)&sprite+8)),sprite.base); - if (T65C_H(p,0x64)==9) { + if (T65C_H(p,PLAYER_FIELD(0x64))==9) { sub_08000AF0(T65C_H(p,0)+16,(void *)sprite.sound,1); } else { - sub_08000AF0(T65C_H(p,0)+16,(void *)(sprite.sound+(p[0x66]<<5)),1); + sub_08000AF0(T65C_H(p,0)+16,(void *)(sprite.sound+(p[PLAYER_FIELD(0x66)]<<5)),1); } - sub_08000AF0(T65C_H(p,0)+16,(void *)(sprite.sound+(p[0x66]<<5)),1); + sub_08000AF0(T65C_H(p,0)+16,(void *)(sprite.sound+(p[PLAYER_FIELD(0x66)]<<5)),1); } t65C_draw(x,y-24-frame,0,w1,1,label.palette,label.data,label.base); if (t65C_flags&1) t65C_overlay(x,y,1,w2,3,label.palette,label.data,label.base); @@ -2411,14 +2995,14 @@ void t65C_impl(s32 index) while ((z2=sub_0800D098())!=0) sub_080003F0(); if (index!=sub_080020F4()) return; sub_0805867C(0x75); - p[0x68]=1; + p[PLAYER_FIELD(0x68)]=1; cc=sub_0800CCCC(); if (cc) { - sub_08056FB8(T65C_H(p,0x2E),T65C_H(p,0x2C)); - T65C_H(p,0x2E)=z2;T65C_H(p,0x2C)=z2; + sub_08056FB8(T65C_H(p,PLAYER_FIELD(0x2E)),T65C_H(p,PLAYER_FIELD(0x2C))); + T65C_H(p,PLAYER_FIELD(0x2E))=z2;T65C_H(p,PLAYER_FIELD(0x2C))=z2; return; } - if (T65C_W(p,0x30)&0x2000) { + if (T65C_W(p,PLAYER_FIELD(0x30))&0x2000) { if (!sub_0800CF80()) { sub_08056FB8(0,4); T65C_H(t65C_game,0x36)=3; @@ -2437,7 +3021,7 @@ void t65C_impl(s32 index) #undef T65C_W #undef T65C_ENTITY struct T65BPopup { u32 base, unk4; u8 *data; u32 sound, resource, style, mode; u8 palette[24]; }; -struct T65BPlayer { u8 pad0[0x14]; u16 buttons; u8 pad16[10]; u16 state, substate; u8 pad24[12]; u32 flags; u8 pad34[0x114]; u8 *entity; }; +struct T65BPlayer { u8 pad0[PLAYER_FIELD(0x14)]; u16 buttons; u8 pad16[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x16)]; u16 state, substate; u8 pad24[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x24)]; u32 flags; u8 pad34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; u8 *entity; }; extern struct T65BPlayer t65B_players[] asm("gUnk_03003CE0"); extern u8 t65B_resources[] asm("gUnk_08518938"); extern u16 t65B_blocked asm("gUnk_03003200"); @@ -2495,7 +3079,7 @@ void t65B_impl(s32 index) u8 *palettePtr; register struct T65BPlayer *player asm("r8"); { - u32 stride65 = 0x14C; + u32 stride65 = PLAYER_SIZE; register u32 idx65 asm("r2"); register u32 product65 asm("r1"); @@ -2507,7 +3091,7 @@ void t65B_impl(s32 index) player = (struct T65BPlayer *)((u8 *)t65B_players + product65); } {void *table; - u32 resource65=0x5005E; + u32 resource65=RES_ID(0x5005E); u32 style65; s32 mode65; struct T65BPopup *descriptor=&draw; @@ -2534,8 +3118,8 @@ void t65B_impl(s32 index) asm("" : : "r"(busy1), "r"(busy2), "r"(busy3), "r"(heightPtr)); } if(first) { - u32 lowResource=0x5E; - second=sub_08006EE0(0x6005E,table);draw.base=second; + u32 lowResource=RES_ID(0x5E); + second=sub_08006EE0(RES_ID(0x6005E),table);draw.base=second; if(second) { lowResource |= 0x80000; mem=sub_08006EE0(lowResource,table);draw.sound=mem; @@ -2600,7 +3184,7 @@ void t65B_impl(s32 index) if (testedIndex == currentPlayer) { if ((({register u16 *p asm("r1")=&t65B_blocked;*p;})==0 && ({register s32 *boxArg asm("r0"); u8 *playerArg; s32 *widthArg; boxArg=boxPtr; - playerArg=(u8 *)player+0x8C; asm("" : "+r"(playerArg)); + playerArg=(u8 *)player+PLAYER_FIELD(0x8C); asm("" : "+r"(playerArg)); widthArg=box+2; t65B_intersect(boxArg,playerArg,widthArg,box+3);})) || ({register u32 prior65 asm("r2")=dialog;asm("" : "+r"(prior65));prior65;}) != 0) { if (({register u32 now65 asm("r3")=dialog;now65;}) == 0) { @@ -2641,7 +3225,7 @@ void t65B_impl(s32 index) sub_0800CF34(); } struct T65EPopup { u32 base, unk4; u8 *data; u32 sound, resource, style, mode; u8 palette[24]; }; -struct T65EPlayer { u8 bytes[0x14C]; }; +struct T65EPlayer { u8 bytes[PLAYER_SIZE]; }; struct T65EResource { u32 id; u8 pad[84]; }; struct T65EPoint { s32 x,y; }; struct T65EVideo { u16 h0,h2,h4,h6,h8,hA,hC,hE; }; @@ -2654,7 +3238,7 @@ extern u8 t65E_resources[] asm("gUnk_08518938"); extern void t65E_bg(u32,u32,u32) asm("sub_080009F8"); #define T65E_H(p,o) (*(u16 *)((p)+(o))) struct T65EEntity { u32 kind:4; u32 kindHi:4; u8 pad[3]; }; -#define T65E_ENTITY(p) (*(struct T65EEntity **)((p)+0x148)) +#define T65E_ENTITY(p) (*(struct T65EEntity **)((p)+PLAYER_FIELD(0x148))) static inline s32 t65E_init(struct T65EPopup *obj,u32 resource,s32 index,s32 size) { void *table = t65E_resources; @@ -2720,7 +3304,7 @@ void sub_08063E30(void) for (playerIndex=0;playerIndexkind==14) { - t65E_init(sprites+n,t65E_resourceTable[T65E_H(p,0x64)].id,0,-1); + t65E_init(sprites+n,t65E_resourceTable[T65E_H(p,PLAYER_FIELD(0x64))].id,0,-1); sprites[n].palette[0]=playerIndex; delays[n]=n*10+10; velocities[n].x=0;velocities[n].y=0; @@ -2754,7 +3338,7 @@ void sub_08063E30(void) } else delays[n]--; if (trails[n][4].y<0) finished++; for (j=0;j<5;j++) { - t65E_draw(&sprites[n],trails[n][j].x>>8,trails[n][j].y>>8,T65E_H(p,0xB0),T65E_H(p,0xB2),0); + t65E_draw(&sprites[n],trails[n][j].x>>8,trails[n][j].y>>8,T65E_H(p,PLAYER_FIELD(0xB0)),T65E_H(p,PLAYER_FIELD(0xB2)),0); } n++; } @@ -2780,7 +3364,7 @@ void sub_08063E30(void) /* Dead store kept: it leaves the original unused trail load. */ if (trails[n][4].y<0) finished=1; for (j=0;j<5;j++) { - t65E_draw(&sprites[n],trails[n][j].x>>8,trails[n][j].y>>8,T65E_H(p,0xB0),T65E_H(p,0xB2),0); + t65E_draw(&sprites[n],trails[n][j].x>>8,trails[n][j].y>>8,T65E_H(p,PLAYER_FIELD(0xB0)),T65E_H(p,PLAYER_FIELD(0xB2)),0); } n++; } @@ -2801,14 +3385,14 @@ void sub_08063E30(void) #undef T65E_H #undef T65E_ENTITY struct Chr441 { u32 kind:4; u32 kindHi:28; u32 lo:11; u32 level:8; u32 cls:5; u32 hi:8; }; -struct PL441 { u8 pad0[0x20]; u16 state; u8 pad22[0xE]; u32 flags; u8 pad34[0x34]; u8 b68; u8 pad69[0x5D]; u16 hC6; u8 padC8[0x80]; struct Chr441 *chr; }; -struct PE441 { struct Chr441 *chr; u8 pad[0x148]; }; +struct PL441 { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 b68; u8 pad69[PLAYER_FIELD(0xC6) - PLAYER_FIELD(0x69)]; u16 hC6; u8 padC8[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xC8)]; struct Chr441 *chr; }; +struct PE441 { struct Chr441 *chr; u8 pad[PLAYER_SIZE - 0x4]; }; struct TS441 { u8 pad0[0x7C]; s16 scrollX; s16 scrollY; u8 pad80[0xC]; u16 curLevel; u16 pad8E; u16 f90; }; struct Obj441 { s32 f0, f4, f8, fC, f10, f14, f18; u8 data[16]; }; struct Pop441 { s32 base, unk4, data, sound, resource, style, mode; u8 palette[24]; }; struct Res441 { u32 b0:8; u32 b1:8; u32 b2:8; s32 b3:8; u16 h4; u16 h6; }; struct Ene441 { u16 h0; u16 h2; u8 pad4[8]; u16 hC; u8 padE[0x3C]; u16 h4A; u32 w4C; u8 pad50[8]; u16 h58; u16 h5A; u8 pad5C[6]; u16 h62; u8 pad64[0x18]; u16 h7C; u16 h7E; - u8 pad80[0x14E]; s16 h1CE; u8 pad1D0[0xC]; u8 b1DC; u8 pad1DD[0x3B]; u8 b218[0xE]; u8 b226; }; + u8 pad80[0x14E]; s16 h1CE; u8 pad1D0[0xC]; u8 b1DC; u8 pad1DD[ENEMY_FIELD(0x218) - 0x1DD]; u8 b218[0xE]; u8 b226; }; struct Tbl441 { u16 a; u16 b; }; extern struct PL441 pl441[] asm("gUnk_03003CE0"); extern struct PE441 pe441[] asm("gUnk_03003E28"); @@ -2984,7 +3568,7 @@ void BattleResult441(u16 *arg0, u32 arg1) ts441.scrollY = sy; sub_0805F07C(); f441_sub_08000AF0(obj441.f14 + 0x10, obj441.fC + (obj441.f14 << 5), obj441.f18); - init441(&obj, 0x5008C, 0, -1); + init441(&obj, RES_ID(0x5008C), 0, -1); f441_sub_08000AF0(0x17, obj.sound, 2); f441_sub_0801A6D4(0); f441_sub_0801A664(0, 0x14); @@ -3055,7 +3639,7 @@ void BattleResult441(u16 *arg0, u32 arg1) if (*arg0 == sub_080020F4()) { i = 0; do { - if ((eneMask441 & (1 << i)) && (e = (struct Ene441 *)(ene441 + i * 0x2E0), e->b1DC != 0)) { + if ((eneMask441 & (1 << i)) && (e = (struct Ene441 *)(ene441 + i * ENEMY_SIZE), e->b1DC != 0)) { switch (arg1) { default: f441_sub_08069388(&res, e->b218, tblB441[classes[*arg0]].a, type, e->h0 + 4); @@ -3102,7 +3686,7 @@ void BattleResult441(u16 *arg0, u32 arg1) i = 0; do { if (eneMask441 & (1 << i)) { - e = (struct Ene441 *)(ene441 + i * 0x2E0); + e = (struct Ene441 *)(ene441 + i * ENEMY_SIZE); e->h5A |= mask; } i++; @@ -3527,7 +4111,7 @@ void sub_080655CC(s32 x, s32 y, u16 *data, s32 align) default: return; } offset = 0; - text = base + gUnk_03003470 * 31; + text = base + gUnk_03003470 * 31 * sizeof(TextChar); if (align < 0) offset = -(((u32)sub_0801A638((u8 *)text) * 13) >> 1); { s32 t = (s16)offset; textDraw66(text, (u16)(t + x), (u16)y); } @@ -3733,7 +4317,7 @@ void sub_08065918(u32 a, u32 b) sub_08000274(&gUnk_030061E0, a, b); } } -struct P148 { u8 pad[0x148]; u8 *p; }; +struct P148 { u8 pad[PLAYER_FIELD(0x148)]; u8 *p; }; extern struct P148 gP148[] asm("gUnk_03003CE0"); /* [HasCoordinatedAttackParticipant] Scans the counted player list and returns exactly 1 on the first player * whose packet pointer +0x148 references a byte with low nibble 0xE, otherwise 0. Does not query task diff --git a/src/code_080659B0.c b/src/code_080659B0.c index e3de9340..75af8f85 100644 --- a/src/code_080659B0.c +++ b/src/code_080659B0.c @@ -63,12 +63,12 @@ void sub_08065A1C(u32 a, s32 frames) { s32 color = 15; s32 text = sub_08007290(0x140000 | a); - s32 offset = -((u32)sub_0801A638((u8 *)(text + 2)) >> 1); + s32 offset = -((u32)sub_0801A638((u8 *)(text + TEXT_HEADER)) >> 1); frames--; if (frames != -1) { do { if (sub_0805F184() == 0 && sub_0800CC98() == 0) - sub_0801A3D0(text + 2, offset + 15, color); + sub_0801A3D0(text + TEXT_HEADER, offset + 15, color); sub_080003F0(); frames--; } while (frames != -1); @@ -165,7 +165,7 @@ void ss2_08065BD0(s32 index, s32 frames) if (frames != -1) { do { if (sub_0800CC98() == 0) { - data = *(u16 **)(player + 0x148); + data = *(u16 **)(player + PLAYER_FIELD(0x148)); sub_0800BC08(data[0] >> 4, (u32)(data[1] << 20) >> 20, &x, &y, 0x30, 1); draw66(player + 2, x - sub_0801A638(player + 2) * 4, y - 0x30); } @@ -251,6 +251,23 @@ void sub_08065CA8(void) } /* [EnqueueLinkPlayerName] Matched producer sub_08065D50 enqueues tag 0x81 in the 0x88-byte link queue; 2 * eight-byte chunks. Payload: bytes+0..9 = current save record+0..9. */ +#ifdef REGION_USA +u32 sub_08065D50(void) +{ + u8 *entry; + if (gUnk_03006338 <= 0x31) { + entry = (u8 *)(uintptr_t)gUnk_03006300 + gUnk_03006338 * 0x88; + *(u32 *)(entry + 4) = 1; + entry[0] = 0x81; + /* USA names are ten halfword characters, copied as five words. */ + CpuSet((void *)gUnk_030034E0, entry + 8, 0x04000005); + entry[1] = 3; + gUnk_03006338++; + return 1; + } + return 0; +} +#else u32 sub_08065D50(void) { u8 *entry; @@ -268,7 +285,8 @@ u32 sub_08065D50(void) gUnk_03006338++; return 1; } -struct Root67Player10 {u8 pad[0x10];u16 w10;u8 pad2[0x14C-0x12];}; +#endif +struct Root67Player10 {u8 pad[PLAYER_FIELD(0x10)];u16 w10;u8 pad2[PLAYER_SIZE - PLAYER_FIELD(0x12)];}; /* [TryEnqueueLocalWeaponSubtypeUpdate] Rejects outgoing count greater than 49 before searching existing * records. Otherwise scans the current count of 0x88-byte entries for the first whose word+4 is exactly 1 and * tag is 0x83. If found, overwrites only entry+8 (payload word 0) with the zero-extended local player @@ -365,10 +383,10 @@ void removeAllRingMessages67(s32 needle) * Profile pair and entity IDs use one 8-byte chunk; state block uses three. */ u32 sub_08065FE8(void) { - u32 *n = (u32 *)0x03006338; + u32 *n = (u32 *)&gUnk_03006338; u8 *entry; if (*n <= 0x31) { - entry = *(u8 **)0x03006300 + *n * 0x88; + entry = *(u8 **)&gUnk_03006300 + *n * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0x85; CpuSet((u8 *)gUnk_03005CF4 + 0x22, entry + 8, 0xA); @@ -464,7 +482,7 @@ u32 queuePlayerBlob067(void) register u32 limit asm("r1") = n; do { if (*(u32 *)(p + 4) == 1 && p[0] == 0x8E) { - CpuSet(root67Payload + sub_080020F4() * 0x14C, p + 8, 0x0400000C); + CpuSet(root67Payload + sub_080020F4() * PLAYER_SIZE, p + 8, 0x0400000C); goto done; } i++; p += 0x88; @@ -473,7 +491,7 @@ u32 queuePlayerBlob067(void) p = (u8 *)(uintptr_t)gUnk_03006300 + gUnk_03006338 * 0x88; *(u32 *)(p + 4) = 1; *p = 0x8E; - CpuSet(root67Payload + sub_080020F4() * 0x14C, p + 8, 0x0400000C); + CpuSet(root67Payload + sub_080020F4() * PLAYER_SIZE, p + 8, 0x0400000C); p[1] = 6; gUnk_03006338++; done: @@ -501,7 +519,7 @@ u32 queuePlayerState067(void) register u32 limit asm("r1") = n; do { if (*(u32 *)(p + 4) == 1 && p[0] == 0x8F) { - CpuSet(root67Player38Payload + sub_080020F4() * 0x14C, p + 8, 0x04000008); + CpuSet(root67Player38Payload + sub_080020F4() * PLAYER_SIZE, p + 8, 0x04000008); goto done; } i++; p += 0x88; @@ -510,7 +528,7 @@ u32 queuePlayerState067(void) p = (u8 *)(uintptr_t)gUnk_03006300 + gUnk_03006338 * 0x88; *(u32 *)(p + 4) = 1; *p = 0x8F; - CpuSet(root67Player38Payload + sub_080020F4() * 0x14C, p + 8, 0x04000008); + CpuSet(root67Player38Payload + sub_080020F4() * PLAYER_SIZE, p + 8, 0x04000008); p[1] = 4; gUnk_03006338++; done: @@ -529,6 +547,65 @@ extern struct EntityC467 *entitiesC467 asm("gUnk_030056F4"); * returns 1 without count growth. Otherwise appends a status 1/tag 0x91/one-chunk record, copies * actor+0x1FC..0x203, increments count and returns 1. It does not update status 2 records, validate the * signed/full-width slot index or copy world coordinates. */ +#ifdef REGION_USA +u32 sub_080662C4(s32 index) +{ + register s32 idx asm("r9") = index; + register struct PacketC467 *p asm("r5"); + register u32 n asm("r2"); + register u32 i asm("r4"); + register void *payload asm("r1"); + struct EntityC467 *ent; + register u32 rawOffset asm("r0"); + register u32 *countAddr asm("r8"); + register struct EntityC467 **entityAddr asm("sl"); + { u32 *c=(u32 *)&gUnk_03006338; n=*c; countAddr=c; } + if(n>49)return 0; + p=packetsC467; + i=0; + { register struct EntityC467 **t asm("r3"); t=&entitiesC467; asm("" : "+r"(t)); entityAddr=t; } + if(iactive==1 && scan->tag==0x91) { + payload=&p->payload; + { register struct EntityC467 **addr asm("r3")=loopAddr; + register u32 base asm("r0")=(u32)*addr; t=offset; ent=(struct EntityC467 *)(t+base); } + { register u32 a asm("r0")=scan->payload.id; t=ent->id; if(a==t) { + CpuSet(ent->velocity,payload,0x04000002); + return 1; + } } + } + i++;scan++;p++; + }while(iactive=1;p->tag=0x91; + { + u32 entityOffset; + register u32 payloadOffset asm("r7"); + entityOffset=idx*ENEMY_SIZE; + { register struct EntityC467 **a2 asm("r3")=entityAddr; rawOffset=(u32)*a2+entityOffset; } + payloadOffset=0x1FC;asm("" : "+r"(payloadOffset));rawOffset+=payloadOffset; + payload=&p->payload; + CpuSet((void *)rawOffset,payload,0x04000002); + } + p->length=1; + { register u32 *c asm("r1") = countAddr; (*c)++; } + return 1; +} +#else u32 sub_080662C4(s32 idx) { struct PacketC467 *p; @@ -559,7 +636,7 @@ u32 sub_080662C4(s32 idx) payload=&p->payload; { register struct EntityC467 **addr asm("r3")=entityAddr; ent=(struct EntityC467 *)(offset+(u32)*addr); } - if(scan->payload.id==ent->id) { + if(scan->payload.id==({ register u32 eid asm("r7") = ent->id; eid; })) { CpuSet(ent->velocity,payload,0x04000002); return 1; } @@ -586,6 +663,7 @@ u32 sub_080662C4(s32 idx) {u32 *finishCount=&gUnk_03006338;asm("" : : "l"(finishCount) : "r0","r1","r2","r3","r4","r5","r6");(*finishCount)++;} return 1; } +#endif extern volatile u32 root67Count asm("gUnk_03006338"); extern u8 *root67Entries asm("gUnk_03006300"); extern u8 *root67Sources asm("gUnk_030056F4"); @@ -600,6 +678,7 @@ u32 sub_080663A4(u32 index) entry = root67Entries + count * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0x92; + /* EU stride on purpose: the USA form is usa_sub_08067CA4 (src/regions/usa). */ { u8 *base = root67Sources; source = (u8 *)(index * 0x2E0 + (u32)base); } *(u32 *)(entry + 8) = *(u16 *)(source + 2); @@ -947,20 +1026,21 @@ extern u8 *gRxMiscP asm("gUnk_03006440"); extern u8 gRxByteA asm("gUnk_0300636C"); extern u8 gRxByteB asm("gUnk_03006224"); extern u8 gRxByteC asm("gUnk_03006228"); -#define RX_PL(i) ((u8 *)gUnk_03003CE0 + (i) * 0x14C) +#define RX_PL(i) ((u8 *)gUnk_03003CE0 + (i) * PLAYER_SIZE) struct RxRec { u8 p0[4]; u8 kind:6; }; struct RxBlk32 { u32 w[8]; }; struct RxPlayer { u8 p0[2]; - u8 name[10]; + NameChar name[10]; u16 fC; u16 fE; u16 f10; - u8 p12[0xE]; + u8 p12[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x12)]; u16 f20; - u8 p22[0xA]; + u8 p22[PLAYER_FIELD(0x2C) - PLAYER_FIELD(0x22)]; u16 f2C; u16 f2E; + u8 p30[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x2F) - 1]; u32 f30; u8 p34[4]; u8 f38[0x20]; @@ -987,6 +1067,7 @@ struct RxPlayer { u16 f11E; u8 p120[0x148 - 0x120]; struct RxRec *f148; + u8 p14C[PLAYER_SIZE - PLAYER_FIELD(0x14C)]; }; extern struct RxPlayer gRxPlayers[] asm("gUnk_03003CE0"); struct RxEnt { @@ -1013,12 +1094,13 @@ struct RxEnt { u8 p8C[0x1FC - 0x8C]; struct RxV2 { u32 a; u8 b0, b1, b2, b3; } f1FC; u16 f204; + u8 gap206[ENEMY_FIELD(0x206) - 0x206]; u16 f206; u16 f208; s16 f20A; u8 p20C[0x226 - 0x20C]; u8 f226; - u8 p227[0x2E0 - 0x227]; + u8 p227[ENEMY_SIZE - ENEMY_FIELD(0x227)]; }; extern struct RxEnt *gRxEnts asm("gUnk_030056F4"); extern u8 gRxPl58[] asm("gUnk_03003D38"); @@ -1033,7 +1115,7 @@ struct RxGs { extern struct RxGs *gRxGs asm("gUnk_03005CF4"); struct RxGs2 { u8 p0[0x1B0]; struct { u8 a[7]; u8 b[5]; } grp[2]; }; extern struct RxGs2 *gRxGs2 asm("gUnk_03005CF4"); -#define RX_ENT(i) (gRxEntities + (i) * 0x2E0) +#define RX_ENT(i) (gRxEntities + (i) * ENEMY_SIZE) #define RX_ENQ(tag, chunks, e) \ do { \ if (gRxQueueCount < 0x32) { \ @@ -1133,11 +1215,15 @@ void sub_0806690C(u32 peer) sub_0800224C(); switch (tag - 0x81) { case 0: /* profile: 10 bytes -> Player+2 */ +#ifdef REGION_USA + CpuSet(d, gRxPlayers[peer].name, 10); +#else { u8 *src = (u8 *)d; for (j = 0; j < 10; j++) gRxPlayers[peer].name[j] = src[j]; } +#endif break; case 1: /* two u16 at Player+0xC; remote also +0x64/+0x66 */ gRxPlayers[peer].fC = d[0]; @@ -1291,11 +1377,11 @@ void sub_0806690C(u32 peer) break; case 0xD: if (peer != sub_080020F4()) - CpuSet(d, gRxPl58 + peer * 0x14C, 0x0400000C); + CpuSet(d, gRxPl58 + peer * PLAYER_SIZE, 0x0400000C); break; case 0xE: if (peer != sub_080020F4()) - CpuSet(d, gRxPl38 + peer * 0x14C, 0x04000008); + CpuSet(d, gRxPl38 + peer * PLAYER_SIZE, 0x04000008); break; case 0xF: *(u32 *)(gRxGameState + 0x38) |= d[0]; @@ -1474,25 +1560,25 @@ void sub_0806690C(u32 peer) u8 *item = (u8 *)x_sub_08007290((d[0] & 0xFFFF) | 0x100000); u8 *effect; s32 limit; - switch (*(u16 *)(item + 0xA0) - 1) { + switch (*(u16 *)(item + ITEM_FIELD(0xA0)) - 1) { case 0: case 18: - limit = (s32)((d[1] * 40 + 100) * *(u16 *)(item + 0xA2)) / 100; + limit = (s32)((d[1] * 40 + 100) * *(u16 *)(item + ITEM_FIELD(0xA2))) / 100; *(u16 *)(target + 0x5C) += limit; - if (*(s16 *)(target + 0x5C) > *(s16 *)(target + 0x20A) * 3) - *(u16 *)(target + 0x5C) = *(s16 *)(target + 0x20A) * 3; + if (*(s16 *)(target + 0x5C) > *(s16 *)(target + ENEMY_DATA_FIELD(0x20A)) * 3) + *(u16 *)(target + 0x5C) = *(s16 *)(target + ENEMY_DATA_FIELD(0x20A)) * 3; break; case 5: - *(u16 *)(target + 0x204) += *(u16 *)(item + 0xA2); + *(u16 *)(target + ENEMY_DATA_FIELD(0x204)) += *(u16 *)(item + ITEM_FIELD(0xA2)); break; case 6: - *(u16 *)(target + 0x206) += *(u16 *)(item + 0xA2); + *(u16 *)(target + ENEMY_DATA_FIELD(0x206)) += *(u16 *)(item + ITEM_FIELD(0xA2)); break; case 8: - *(u16 *)(target + 0x20A) += *(u16 *)(item + 0xA2); + *(u16 *)(target + ENEMY_DATA_FIELD(0x20A)) += *(u16 *)(item + ITEM_FIELD(0xA2)); break; case 7: - *(u16 *)(target + 0x208) += *(u16 *)(item + 0xA2); + *(u16 *)(target + ENEMY_DATA_FIELD(0x208)) += *(u16 *)(item + ITEM_FIELD(0xA2)); break; case 9: effect = (u8 *)x_sub_0801E104(target, 0); @@ -1553,9 +1639,16 @@ void sub_0806690C(u32 peer) pls = gRxPlayers; off = 0; dur = 0x168; +#ifdef REGION_USA + for (; i < 5; i++) { + struct RxEnt *ent; u8 *b; + if ((gRxEntityMask & (1 << i)) && (b = (u8 *)gRxEnts, d[0] == (ent = (struct RxEnt *)(ENEMY_SIZE * i + (u32)b))->f2)) { + struct RxEff *effect = (struct RxEff *)x_sub_0801E104(ent, d[1]); +#else for (; i < 5; off += sizeof(struct RxEnt), i++) { if ((gRxEntityMask & (1 << i)) && d[0] == ((struct RxEnt *)(off + (u32)gRxEnts))->f2) { struct RxEff *effect = (struct RxEff *)x_sub_0801E104((struct RxEnt *)(off + (u32)gRxEnts), d[1]); +#endif if (effect != 0) { effect->f4 = d[1]; effect->f2 = peer; @@ -1597,12 +1690,12 @@ void sub_0806690C(u32 peer) sub_0806617C(); x_sub_08022200(*(u16 *)&gRxPlayers[myId], gRxPlayers[myId].fE0); switch (gRxPlayers[myId].fE0 - 1) { - case 0: *(u16 *)(gRxProfile + 0x24) += 1; break; - case 1: *(u16 *)(gRxProfile + 0x26) += 1; break; - case 2: *(u16 *)(gRxProfile + 0x28) += 1; break; - case 3: *(u16 *)(gRxProfile + 0x2A) += 1; break; - case 4: *(u16 *)(gRxProfile + 0x2C) += 1; break; - case 5: *(u16 *)(gRxProfile + 0x2E) += 1; break; + case 0: *(u16 *)(gRxProfile + SAVE_FIELD(0x24)) += 1; break; + case 1: *(u16 *)(gRxProfile + SAVE_FIELD(0x26)) += 1; break; + case 2: *(u16 *)(gRxProfile + SAVE_FIELD(0x28)) += 1; break; + case 3: *(u16 *)(gRxProfile + SAVE_FIELD(0x2A)) += 1; break; + case 4: *(u16 *)(gRxProfile + SAVE_FIELD(0x2C)) += 1; break; + case 5: *(u16 *)(gRxProfile + SAVE_FIELD(0x2E)) += 1; break; } } x_sub_0805865C(0x91); diff --git a/src/code_08067B4C.c b/src/code_08067B4C.c index de252c97..9aedfea0 100644 --- a/src/code_08067B4C.c +++ b/src/code_08067B4C.c @@ -26,7 +26,7 @@ u32 sub_08067B50(void) *(u32 *)(entry + 4) = 1; entry[0] = 0x82; source = (u8 *)gUnk_030034E0; - *(u32 *)(entry + 8) = *(u16 *)(source + 0xA) | ((u32)*(u16 *)(source + 0xC) << 16); + *(u32 *)(entry + 8) = *(u16 *)(source + SAVE_FIELD(0xA)) | ((u32)*(u16 *)(source + SAVE_FIELD(0xC)) << 16); entry[1] = 1; (*count)++; return 1; @@ -83,10 +83,10 @@ s32 sub_08067C18(void) { u32 sub_08067C28(const u32 *arg0) { u8 *entry; - u32 *n = (u32 *)0x03006338; + u32 *n = (u32 *)&gUnk_03006338; if (*n > 0x31) return 0; - entry = *(u8 **)0x03006300 + *n * 0x88; + entry = *(u8 **)&gUnk_03006300 + *n * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0x87; *(u32 *)(entry + 8) = *arg0; @@ -132,10 +132,10 @@ s32 sub_08067CA8(s32 arg0) u32 sub_08067CE8(void *arg0) { u8 *entry; - u32 *n = (u32 *)0x03006338; + u32 *n = (u32 *)&gUnk_03006338; if (*n > 0x31) return 0; - entry = *(u8 **)0x03006300 + *n * 0x88; + entry = *(u8 **)&gUnk_03006300 + *n * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0xB0; *(void **)(entry + 8) = arg0; @@ -148,9 +148,9 @@ u32 sub_08067CE8(void *arg0) u32 sub_08067D28(const void *source) { u8 *entry; - u32 *count = (u32 *)0x03006338; + u32 *count = (u32 *)&gUnk_03006338; if (*count <= 0x31) { - entry = *(u8 **)0x03006300 + *count * 0x88; + entry = *(u8 **)&gUnk_03006300 + *count * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0x8B; CpuSet(source, entry + 8, 0x04000002); @@ -335,10 +335,10 @@ u32 sub_08067FE0(u16 value, u16 handle) * enqueue else0, no coalescing/wait. One8-byte chunk declared but only4bytes initialized. */ u32 sub_08068030(u32 value) { - u32 *count = (u32 *)0x03006338; + u32 *count = (u32 *)&gUnk_03006338; u8 *entry; if (*count > 0x31) return 0; - entry = *(u8 **)0x03006300 + *count * 0x88; + entry = *(u8 **)&gUnk_03006300 + *count * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0xA1; *(u32 *)(entry + 8) = value; @@ -348,20 +348,20 @@ u32 sub_08068030(u32 value) } /* [EnqueueLinkSceneCallbackTask] Enqueues tag 0xA3, one 8-byte chunk: payload word 0=a(callback), word * 1=b(argument). */ -u32 sub_08068070(u32 a, u32 b) { u32 *n=(u32 *)0x03006338; u8 *e; if(*n>0x31)return 0; e=*(u8 **)0x03006300+*n*0x88; *(u32 *)(e+4)=1;e[0]=0xA3;*(u32 *)(e+8)=a;*(u32 *)(e+0xC)=b;e[1]=1;(*n)++;return 1; } +u32 sub_08068070(u32 a, u32 b) { u32 *n=(u32 *)&gUnk_03006338; u8 *e; if(*n>0x31)return 0; e=*(u8 **)&gUnk_03006300+*n*0x88; *(u32 *)(e+4)=1;e[0]=0xA3;*(u32 *)(e+8)=a;*(u32 *)(e+0xC)=b;e[1]=1;(*n)++;return 1; } /* [TryEnqueueEnemyEffectByKey] Returns 0 when outgoing count exceeds 49. Otherwise writes a 0x88-byte queue * record with tag 0xA2, word+4=1, the complete first argument at entry+8 (payload word 0) and complete second * argument at entry+0xC (payload word 1), chunk count 1, then increments count and returns 1. These two words * fill one eight-byte wire chunk. The producer does not narrow either value or synchronously modify an enemy. */ -u32 sub_080680B4(u32 a, u32 b) { u32 *n=(u32 *)0x03006338; u8 *e; if(*n>0x31)return 0; e=*(u8 **)0x03006300+*n*0x88; *(u32 *)(e+4)=1;e[0]=0xA2;*(u32 *)(e+8)=a;*(u32 *)(e+0xC)=b;e[1]=1;(*n)++;return 1; } +u32 sub_080680B4(u32 a, u32 b) { u32 *n=(u32 *)&gUnk_03006338; u8 *e; if(*n>0x31)return 0; e=*(u8 **)&gUnk_03006300+*n*0x88; *(u32 *)(e+4)=1;e[0]=0xA2;*(u32 *)(e+8)=a;*(u32 *)(e+0xC)=b;e[1]=1;(*n)++;return 1; } /* [EnqueueLinkEligiblePlayerCentroidAreaAttack] Matched producer enqueues tag 0xA5 after 0CFF0 gate and 0CFC8 * update. It writes caller value but receiver does not use that payload. */ u32 sub_080680F8(u32 value) { u8 *entry; - u32 *count = (u32 *)0x03006338; + u32 *count = (u32 *)&gUnk_03006338; if (*count <= 0x31 && sub_0800CFF0() == 0) { - entry = *(u8 **)0x03006300 + *count * 0x88; + entry = *(u8 **)&gUnk_03006300 + *count * 0x88; sub_0800CFC8(); *(u32 *)(entry + 4) = 1; entry[0] = 0xA5; @@ -381,9 +381,9 @@ u32 sub_080680F8(u32 value) u32 sub_08068144(u32 value) { u8 *entry; - u32 *count = (u32 *)0x03006338; + u32 *count = (u32 *)&gUnk_03006338; if (*count <= 0x31 && sub_0800CFF0() == 0) { - entry = *(u8 **)0x03006300 + *count * 0x88; + entry = *(u8 **)&gUnk_03006300 + *count * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0xA7; *(u32 *)(entry + 8) = value; @@ -398,9 +398,9 @@ u32 sub_08068144(u32 value) s32 sub_0806818C(u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4) { u8 *entry; - u32 *count = (u32 *)0x03006338; + u32 *count = (u32 *)&gUnk_03006338; if (*count <= 0x31 && sub_0800CFF0() == 0) { - entry = *(u8 **)0x03006300 + *count * 0x88; + entry = *(u8 **)&gUnk_03006300 + *count * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0xA8; *(u32 *)(entry + 8) = (arg1 << 16) | arg0; @@ -423,9 +423,9 @@ s32 sub_0806818C(u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4) u32 sub_080681F4(u32 callback) { u8 *entry; - u32 *count = (u32 *)0x03006338; + u32 *count = (u32 *)&gUnk_03006338; if (*count <= 0x31 && sub_0800CFF0() == 0) { - entry = *(u8 **)0x03006300 + *count * 0x88; + entry = *(u8 **)&gUnk_03006300 + *count * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0xA9; *(u32 *)(entry + 8) = callback; @@ -554,7 +554,7 @@ s32 sub_080683DC(s32 callback) * No parent, peer, enemy ID, sentinel or action-range validation occurs here. It initializes only the first * four payload bytes of the eight-byte chunk; the trailing word is not promised zero. Enqueue success is not a * delivery or synchronization guarantee. */ -u32 sub_08068450(u8 value) { u32 *n=(u32 *)0x03006338; u8 *e; if(*n>0x31)return 0; e=*(u8 **)0x03006300+*n*0x88; *(u32 *)(e+4)=1;e[0]=0xAC;*(u32 *)(e+8)=value;e[1]=1;(*n)++;return 1; } +u32 sub_08068450(u8 value) { u32 *n=(u32 *)&gUnk_03006338; u8 *e; if(*n>0x31)return 0; e=*(u8 **)&gUnk_03006300+*n*0x88; *(u32 *)(e+4)=1;e[0]=0xAC;*(u32 *)(e+8)=value;e[1]=1;(*n)++;return 1; } /* [GetSharedEnemyActionChoice] Returns the unsigned byte latch 0300636C unchanged, without clearing or * consuming it. It is one shared global latch, not a per-player or per-enemy queue. Value 0xFF is the waiting * sentinel in the inspected enemy consumers; this getter accepts every stored byte and imposes no global @@ -573,7 +573,7 @@ u32 sub_0806849C(u32 a) } /* [EnqueueLinkByte173] Checks queue count <=49, appends active tag 0xAD entry at stride 0x88, zero-extends u8 * payload, sets chunk count one and increments the queue. */ -u32 sub_080684A8(u8 value) { u32 *n=(u32 *)0x03006338; u8 *e; if(*n>0x31)return 0; e=*(u8 **)0x03006300+*n*0x88; *(u32 *)(e+4)=1;e[0]=0xAD;*(u32 *)(e+8)=value;e[1]=1;(*n)++;return 1; } +u32 sub_080684A8(u8 value) { u32 *n=(u32 *)&gUnk_03006338; u8 *e; if(*n>0x31)return 0; e=*(u8 **)&gUnk_03006300+*n*0x88; *(u32 *)(e+4)=1;e[0]=0xAD;*(u32 *)(e+8)=value;e[1]=1;(*n)++;return 1; } /* [GetReceivedLinkByte173] Returns u8 global 03006224. */ u8 sub_080684E8(void) { return gUnk_03006224; @@ -585,7 +585,7 @@ unsigned int sub_080684F4(void) } /* [EnqueueLinkByte174] Checks queue count <=49, appends active tag 0xAE entry at stride 0x88, zero-extends u8 * payload, sets chunk count one and increments the queue. */ -u32 sub_08068500(u8 value) { u32 *n=(u32 *)0x03006338; u8 *e; if(*n>0x31)return 0; e=*(u8 **)0x03006300+*n*0x88; *(u32 *)(e+4)=1;e[0]=0xAE;*(u32 *)(e+8)=value;e[1]=1;(*n)++;return 1; } +u32 sub_08068500(u8 value) { u32 *n=(u32 *)&gUnk_03006338; u8 *e; if(*n>0x31)return 0; e=*(u8 **)&gUnk_03006300+*n*0x88; *(u32 *)(e+4)=1;e[0]=0xAE;*(u32 *)(e+8)=value;e[1]=1;(*n)++;return 1; } /* [GetReceivedLinkByte174] Returns u8 global 03006228. */ u8 sub_08068540(void) { return gUnk_03006228; diff --git a/src/code_08068670.c b/src/code_08068670.c index 29f17252..72381a6e 100644 --- a/src/code_08068670.c +++ b/src/code_08068670.c @@ -21,9 +21,9 @@ void sub_08068670(void) { u32 sub_080686A4(const void *src) { u8 *entry; - u32 *n = (u32 *)0x03006338; + u32 *n = (u32 *)&gUnk_03006338; if (*n <= 0x31) { - entry = *(u8 **)0x03006300 + *n * 0x88; + entry = *(u8 **)&gUnk_03006300 + *n * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0x98; CpuSet(src, entry + 8, 0x04000008); @@ -60,8 +60,8 @@ u32 sub_08068758(u16 lo, u16 hi, const u8 *src) { u32 *count; u8 *e; - count=(u32 *)0x03006338; if(*count>0x31)return 0; - e=*(u8 **)0x03006300+*count*0x88; + count=(u32 *)&gUnk_03006338; if(*count>0x31)return 0; + e=*(u8 **)&gUnk_03006300+*count*0x88; *(u32 *)(e+4)=1; e[0]=0x9A; *(u32 *)(e+8)=((u32)hi<<16)|lo; *(u32 *)(e+0xC)=*(const u16 *)(src+0xC); e[1]=1; (*count)++; return 1; } @@ -70,10 +70,10 @@ u32 sub_08068758(u16 lo, u16 hi, const u8 *src) u32 sub_080687A8(const u8 *arg0) { u8 *entry; - u32 *n = (u32 *)0x03006338; + u32 *n = (u32 *)&gUnk_03006338; if (*n > 0x31) return 0; - entry = *(u8 **)0x03006300 + *n * 0x88; + entry = *(u8 **)&gUnk_03006300 + *n * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0x9B; *(u32 *)(entry + 8) = *(const u16 *)(arg0 + 0xC); @@ -101,10 +101,10 @@ s32 sub_080687E8(void) u32 sub_08068820(void *a, void *b, void *c) { u8 *entry; - u32 *n = (u32 *)0x03006338; + u32 *n = (u32 *)&gUnk_03006338; if (*n > 0x31) return 0; - entry = *(u8 **)0x03006300 + *n * 0x88; + entry = *(u8 **)&gUnk_03006300 + *n * 0x88; *(u32 *)(entry + 4) = 1; entry[0] = 0xA4; *(void **)(entry + 8) = a; @@ -218,7 +218,7 @@ s32 sub_0806898C(s32 arg0, s32 arg1) u8 *table; s32 offset; - player = (u8 *)gUnk_03003CE0 + sub_080020F4() * 0x14C; + player = (u8 *)gUnk_03003CE0 + sub_080020F4() * PLAYER_SIZE; if (arg1 == 0) return 0; @@ -227,13 +227,13 @@ s32 sub_0806898C(s32 arg0, s32 arg1) offset = arg1 * 2 + arg0 * 24; table += 6; cost = (s16 *)(offset + table); - value = *(s8 *)(player + 0x6C) * 5; value = *cost + value * 2; + value = *(s8 *)(player + PLAYER_FIELD(0x6C)) * 5; value = *cost + value * 2; /* The game truncates to 16 bits before testing the sign. */ candidate = value; if ((s32)(value << 16) < 0) candidate = 0; result = candidate; - if (*(s16 *)(player + 0xC2) - result < 0) + if (*(s16 *)(player + PLAYER_FIELD(0xC2)) - result < 0) return 0; return (s16)(result + 1); } @@ -246,6 +246,200 @@ struct Position68 { s32 x, y; }; * authority/history blocks processing. Local caster, or enemy caster on host path, may overwrite descriptor * target with enemy.id+4 and call 694AC; special kinds 4/7 instead call 29B98 directly. */ s32 sub_08068A00(struct Position68 pos, u8 *attack) { +#ifdef REGION_USA + struct Pl68 { u16 id; u8 p2[PLAYER_FIELD(0x20) - 2]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 team; u8 p69[PLAYER_FIELD(0xDC) - PLAYER_FIELD(0x69)]; u32 counter; u8 pE0[4]; u32 ehist[5]; u32 phist[4]; u8 p108[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x108)]; struct Po68 { u32 kind : 4, x : 12, y : 12, dir : 4; u8 flags : 6; } *pos; }; + struct En68 { u16 id; u8 p2[10]; u16 state; u8 pE[6]; s32 x, y; u8 p1C[0x34]; u32 counter, lastHit; u16 owner, mask; u8 p5C[0x180]; u8 active; u8 p1DD[ENEMY_FIELD(0x226) - 0x1DD]; u8 kind; u8 p227[ENEMY_SIZE - ENEMY_FIELD(0x227)]; }; + struct At68 { u32 owner, bit, target, kind, f10, level; }; + void sub_08029A7C(u32, s32, s32); + void sub_08029B98(u32, u32, s32, s32, s32, s32); + s16 damage68_raw(void *, s32) asm("sub_08068F9C"); + void sub_080694AC(void *); + void sub_08069A30(s32, s32, u32, u16, u16); + extern struct Pl68 pl68[] asm("gUnk_03003CE0"); + extern struct En68 *en68 asm("gUnk_030056F4"); + extern u8 gUnk_084EBF1C[]; + extern u16 attackEffect asm("gUnk_084EBF7E"); + extern u16 effects[] asm("gUnk_084EC14C"); + extern u16 radii[] asm("gUnk_084EC17C"); + extern u32 enemyActive asm("gUnk_030056FC"); + struct At68 *at = (struct At68 *)attack; + struct En68 *srcEnemy; + struct Pl68 *src; + struct Pl68 *p; + struct En68 *e; + s16 radius; + u32 local; + u32 hit; + u32 i; + u32 count; + s16 dx, dy; + register s32 ax asm("r2"); + s32 ay; + register s32 bx asm("r1"); + u16 eff; + + local = (u16)sub_080020F4(); + if (sub_08058DB0() != 0 || sub_0800CDF8() != 0) + return 0; + if (at->owner <= 3) + src = &pl68[at->owner]; + else + srcEnemy = &en68[at->owner - 4]; + hit = 0; + switch (at->kind) { + case 13: + radius = 22; + break; + case 12: + radius = 32; + break; + default: + radius = radii[at->level]; + break; + } + if (at->target > 3) { + for (i = 0; i <= 4; i++) { + if (!(enemyActive & (1 << i))) + continue; + e = &en68[i]; + if (e->active == 0 || e->state == 11) + continue; + bx = (e->x - pos.x) << 8; + dy = (u32)((e->y - pos.y) << 8) >> 16; + bx >>= 16; + if (bx < 0) bx = -bx; + if (bx > radius) continue; + ay = dy; + if (ay < 0) ay = -ay; + if (ay > radius) continue; + if (local == at->owner) { + if (e->lastHit != src->counter) { + at->target = e->id + 4; + switch (at->kind) { + case 4: + if (e->kind == 1) + { s32 dmg = damage68_raw(at, 0) * 15 / 10; u32 id = e->id; register u16 *ep asm("r3") = &attackEffect; u32 ef = *ep; sub_08029B98(id, ef, dmg, at->level, 0, 0); } + else + { s32 dmg = damage68_raw(at, 0); u32 id = e->id; register u16 *ep asm("r3") = &attackEffect; u32 ef = *ep; sub_08029B98(id, ef, dmg, at->level, 0, 0); } + e->lastHit = src->counter; + e->mask |= 1 << local; + break; + case 7: + sub_08029B98(e->id, effects[at->level], damage68_raw(at, 0), at->level, 0, 0); + e->lastHit = src->counter; + e->mask |= 1 << local; + break; + default: + sub_080694AC(at); + break; + } + if (sub_0800CCCC() == 0 && sub_0800CD34() == 0) + sub_0805865C(0x1A); + sub_08069A30(pos.x, pos.y, at->owner, at->kind, at->level); + hit = 2; + } + } else if (sub_08002204() != 0 && at->owner > 3 && e->state != 11 && e->lastHit != src->counter) { + e->owner = 0; + at->target = e->id + 4; + switch (at->kind) { + case 4: + { s32 dmg = damage68_raw(at, 0); u32 id = e->id; register u16 *ep asm("r3") = &attackEffect; u32 ef = *ep; sub_08029B98(id, ef, dmg, at->level, 0, 0); } + { register struct En68 *se asm("r1") = srcEnemy; asm("" : "+r"(se)); e->lastHit = se->counter; } + e->mask |= 1 << local; + break; + case 7: + sub_08029B98(e->id, effects[at->level], damage68_raw(at, 0), at->level, 0, 0); + e->lastHit = srcEnemy->counter; + e->mask |= 1 << local; + break; + default: + sub_080694AC(at); + break; + } + if (sub_0800CCCC() == 0 && sub_0800CD34() == 0) + sub_0805865C(0x1A); + sub_08069A30(pos.x, pos.y, at->owner, at->kind, at->level); + hit = 2; + } + hit |= 1; + } + } + if (hit == 0) { + count = sub_08002164(); + if (at->owner <= 3) { + for (i = 0; i < count; i++) { + p = &pl68[i]; + if (p->team == src->team) + continue; + if (p->pos->kind == 14 || p->pos->kind == 11 || p->pos->kind == 10 || p->team == 0 || (((u32)(((u8 *)p->pos)[4] << 26) >> 26) & 0x20)) + continue; + ax = p->pos->x - (pos.x >> 8); + dy = p->pos->y - (pos.y >> 8); + ax = (s16)ax; + if (ax < 0) ax = -ax; + if (ax > radius) continue; + ay = dy; + if (ay < 0) ay = -ay; + if (ay > radius) continue; + if (local == i && p->state != 11 && p->phist[src->id] != src->counter) { + at->target = p->id; + switch (at->kind) { + case 4: + { u8 *eb = gUnk_084EBF1C; eb += 0x62; eff = *(u16 *)eb; } + sub_08029A7C(eff, damage68_raw(at, 0), at->level); + break; + case 7: + eff = effects[at->level]; + sub_08029A7C(eff, damage68_raw(at, 0), at->level); + break; + default: + sub_080694AC(at); + break; + } + p->phist[src->id] = src->counter; + if (sub_0800CCCC() == 0 && sub_0800CD34() == 0) + sub_0805865C(0x1A); + sub_08069A30(pos.x, pos.y, at->owner, at->kind, at->level); + hit = 2; + } + hit |= 1; + } + } else { + for (i = 0; i < count; i++) { + p = &pl68[i]; + if (p->flags & 0x2000) + continue; + if (p->flags & 0x400) + continue; + if (p->pos->kind == 14 || p->pos->kind == 11 || p->pos->kind == 10 || p->team == 0) + continue; + ax = p->pos->x - (pos.x >> 8); + dy = p->pos->y - (pos.y >> 8); + ax = (s16)ax; + if (ax < 0) ax = -ax; + if (ax > radius) continue; + ay = dy; + if (ay < 0) ay = -ay; + if (ay > radius) continue; + if (local == i && sub_0800CCCC() == 0 && p->state != 11 && p->ehist[srcEnemy->id] != srcEnemy->counter) { + at->target = p->id; + if (at->kind == 4) { + { u8 *eb = gUnk_084EBF1C; eb += 0x62; eff = *(u16 *)eb; } + sub_08029A7C(eff, damage68_raw(at, 0), at->level); + } else { + sub_080694AC(at); + } + p->ehist[srcEnemy->id] = srcEnemy->counter; + if (sub_0800CCCC() == 0 && sub_0800CD34() == 0) + sub_0805865C(0x1A); + hit = 2; + } + hit |= 1; + } + } + } + return hit; +#else void sub_08029A7C(u32, s32, s32); void sub_08029B98(u32, u32, s32, s32, s32, s32); s16 damage68_raw(void *,s32) asm("sub_08068F9C"); @@ -327,9 +521,9 @@ s32 sub_08068A00(struct Position68 pos, u8 *attack) { } temp_r2 = M2C_FIELD(attack, u32 *, 0x0); if (temp_r2 <= 3U) { - sourcePlayer = (0x14C * temp_r2) + (u8 *)gUnk_03003CE0; + sourcePlayer = (PLAYER_SIZE * temp_r2) + (u8 *)gUnk_03003CE0; } else { - sourceEnemy = (u8 *)gUnk_030056F4 + ((temp_r2 * 0x2E0) + 0xFFFFF480); + sourceEnemy = (u8 *)gUnk_030056F4 + ((temp_r2 * ENEMY_SIZE) - 4 * ENEMY_SIZE); } hitFlags = 0; temp_r0 = M2C_FIELD(attack, u32 *, 0xC); @@ -356,7 +550,7 @@ radiusStore: radius=var_r0; if (!(enemyActive & (1 << enemyIndex))) { } else { - targetEnemy = (u8 *)gUnk_030056F4 + (enemyIndex * 0x2E0); + targetEnemy = (u8 *)gUnk_030056F4 + (enemyIndex * ENEMY_SIZE); if (M2C_FIELD(targetEnemy, u8 *, 0x1DC) == 0) { } else if (M2C_FIELD(targetEnemy, u16 *, 0xC) == 0xB) { @@ -498,7 +692,7 @@ radiusStore: radius=var_r0; } else { loop_69: - targetPlayerAlly = (0x14C * playerIndexAlly) + (u8 *)gUnk_03003CE0; + targetPlayerAlly = (PLAYER_SIZE * playerIndexAlly) + (u8 *)gUnk_03003CE0; targetStatus68 = targetPlayerAlly + 0x68; sourceStatus = sourcePlayer + 0x68; temp_r2_3 = *targetStatus68; @@ -584,7 +778,7 @@ radiusStore: radius=var_r0; } else { loop_105: - targetPlayerEnemy = (0x14C * playerIndexEnemy) + (u8 *)gUnk_03003CE0; + targetPlayerEnemy = (PLAYER_SIZE * playerIndexEnemy) + (u8 *)gUnk_03003CE0; temp_r1 = M2C_FIELD(targetPlayerEnemy, u32 *, 0x30); id=0x2000; id &= temp_r1; if (id) goto nextEnemyPlayer; @@ -648,9 +842,10 @@ radiusStore: radius=var_r0; } return (s32) hitFlags; +#endif } struct Attack69 {u32 attacker,unk4,unk8,kind,power,level;}; -struct AttackPlayer69 {u8 pad0[0x3C];s16 value;u8 pad3E[0x14C-0x3E];}; +struct AttackPlayer69 {u8 pad0[PLAYER_FIELD(0x3C)];s16 value;u8 pad3E[PLAYER_SIZE-PLAYER_FIELD(0x3E)];}; struct AttackTable69 {s16 power;u16 effect;u8 pad4[20];}; extern struct AttackPlayer69 attackPlayers69[] asm("gUnk_03003CE0"); extern u8 *attackEnemies69 asm("gUnk_030056F4"); @@ -676,8 +871,8 @@ s32 sub_08068F9C(struct Attack69 *a,s32 target) u32 index; u16 *special; index=a->attacker; - if(index<=3) value=((struct AttackPlayer69 *)(index*0x14C+(u32)attackPlayers69))->value; - else { u32 address; u8 **base; base=&attackEnemies69; address=index*0x2E0; address+=(u32)*base; address-=0x978; value=*(s16 *)address; } + if(index<=3) value=((struct AttackPlayer69 *)(index*PLAYER_SIZE+(u32)attackPlayers69))->value; + else { u32 address; u8 **base; base=&attackEnemies69; address=index*ENEMY_SIZE; address+=(u32)*base; address-=4*ENEMY_SIZE-ENEMY_FIELD(0x208); value=*(s16 *)address; } random=sub_080008C8()%20U+100; if(a->kind!=19) { root=attackRoot69(value+15); @@ -693,8 +888,8 @@ s32 sub_08068F9C(struct Attack69 *a,s32 target) return (s16)result; } struct Resist69 {s16 a;u8 pad2[4];s16 b;}; -struct EffectPlayer69 {u8 id;u8 pad1[0x72];s8 modifier;u8 pad74[0x6C];u32 state;u8 padE4[0x14C-0xE4];}; -struct EffectEnemy69 {u8 pad0[2];u8 id;u8 pad3[0x223];u8 state;}; +struct EffectPlayer69 {u8 id;u8 pad1[PLAYER_FIELD(0x73) - 0x1];s8 modifier;u8 pad74[PLAYER_FIELD(0xE0) - PLAYER_FIELD(0x74)];u32 state;u8 padE4[PLAYER_SIZE - PLAYER_FIELD(0xE4)];}; +struct EffectEnemy69 {u8 pad0[2];u8 id;u8 pad3[ENEMY_FIELD(0x226)-3];u8 state;}; struct Payload69 {union {u32 raw;struct {u32 who:8,kind:8,upper:16;} bits;} control;union {u32 raw;struct {u32 value:16,upper:16;} bits;} amount;}; extern struct EffectPlayer69 effectPlayers69[] asm("gUnk_03003CE0"); extern u8 *effectEnemies69 asm("gUnk_030056F4"); @@ -703,7 +898,11 @@ extern u32 effectApply69(struct Payload69 *) asm("sub_08067D28"); extern void effectFeedback69(u32,u32,void *) asm("sub_08069224"); /* [TryQueueScaledStatusEffect] Kinds1/4 use resistance indices0/3 and distinct probability divisors 25/50; all * other kinds return. */ +#ifdef REGION_USA +void sub_08069080(struct Resist69 *res,u32 magIn,u32 level,u32 unused,u32 target,s32 kind) +#else void sub_08069080(struct Resist69 *res,u16 magnitude,u32 level,u32 unused,u32 target,s32 kind) +#endif { /* The original preserves the incoming stack bits outside the fields written. */ struct Payload69 packet; @@ -712,6 +911,12 @@ void sub_08069080(struct Resist69 *res,u16 magnitude,u32 level,u32 unused,u32 ta u8 who; struct EffectEnemy69 *enemy; struct EffectPlayer69 *player; +#ifdef REGION_USA + register u32 tgt69 asm("r9") = target; + u16 magnitude; + magnitude = magIn; +#define target tgt69 +#endif random=sub_080008C8()%100U; switch(kind) { case 1: probability=(100-res->a)*((level*10)+5)/25U; break; @@ -734,7 +939,7 @@ afterModify:; if(target<=3) { player=&effectPlayers69[target];who=player->id; } else { - { u8 **base; u32 offset; base=&effectEnemies69; offset=target*0x2E0; offset-=0xB80; enemy=(struct EffectEnemy69 *)((u32)*base+offset); } + { u8 **base; u32 offset; base=&effectEnemies69; offset=target*ENEMY_SIZE; offset-=(4 * ENEMY_SIZE); enemy=(struct EffectEnemy69 *)((u32)*base+offset); } if(enemy->state==3)return; who=enemy->id; @@ -743,9 +948,12 @@ afterModify:; { register u32 word asm("r1"); word=packet.amount.raw&0xFFFF0000; word|=magnitude; packet.amount.raw=word; } effectApply69(&packet); if(target==sub_080020F4() && !sub_0800CF80()) { - effectFeedback69(packet.control.bits.kind,magnitude,effectStats69+0x24); + effectFeedback69(packet.control.bits.kind,magnitude,effectStats69+SAVE_FIELD(0x24)); player->state=kind; } +#ifdef REGION_USA +#undef target +#endif } /* [TryIncreaseEffectResistanceStat] Returns0 immediately when sub_0800CF80 is nonzero; otherwise RNG unsigned * remainder100 and full incoming kind choose signed halfword stats[kind-1], with kinds6/7 sharing stats[5]. @@ -784,7 +992,7 @@ s32 sub_08069224(u32 kind,u16 magnitude,s16 *stats) } return kind; } -struct ResistPlayer69 {u8 pad0[0x73];s8 modifier;u8 pad74[0x14C-0x74];}; +struct ResistPlayer69 {u8 pad0[PLAYER_FIELD(0x73)];s8 modifier;u8 pad74[PLAYER_SIZE - PLAYER_FIELD(0x74)];}; extern struct ResistPlayer69 resistPlayers69[] asm("gUnk_03003CE0"); extern u8 *resistEnemies69 asm("gUnk_030056F4"); /* [RollTargetStatusEffectKind] Machine ABI: r0 output packet, r1 signed-halfword resistance array, r2 low16 @@ -822,7 +1030,7 @@ void sub_08069388(u8 *out,s16 *res,u16 magnitude,u16 kind,u16 target) if(target==sub_080020F4() || (sub_0800CF80() && target<=3)) probability=((u32)probability*resistPlayers69[target].modifier)/100U; out[1]=((u32)probability>random)?kind:0; - if(target>3 && *(u8 *)((u32)resistEnemies69+target*0x2E0-0x95A)==3) out[1]=0; + if(target>3 && *(u8 *)((u32)resistEnemies69+target*ENEMY_SIZE-(4*ENEMY_SIZE-ENEMY_FIELD(0x226)))==3) out[1]=0; } struct HitAttack69 {u32 attacker,unk4,target,kind,power,level;}; struct HitPacket69 {union {u32 word;u8 byte[4];struct {u32 who:8,kind:8,flags:8; s32 direction:8;} bits;} control;union {u32 word;u16 half[2];struct {u32 amount:16,upper:16;} bits;} value;}; @@ -882,20 +1090,20 @@ void sub_080694AC(struct HitAttack69 *arg0) { packet.control.word &= 0xFFFF00FF; temp_r2 = arg0->attacker; if (temp_r2 <= 3U) { - var_r8 = (0x14C * temp_r2) + hitPlayers69; + var_r8 = (PLAYER_SIZE * temp_r2) + hitPlayers69; } else { - var_r9 = hitEnemies69 + ((temp_r2 * 0x2E0) + 0xFFFFF480); + var_r9 = hitEnemies69 + ((temp_r2 * ENEMY_SIZE) - 4 * ENEMY_SIZE); } temp_r2_2 = arg0->target; if (temp_r2_2 <= 3U) { - var_r7 = (0x14C * temp_r2_2) + hitPlayers69; - var_sl = (u8 *)(0x7C+(u32)var_r7); + var_r7 = (PLAYER_SIZE * temp_r2_2) + hitPlayers69; + var_sl = (u8 *)(PLAYER_FIELD(0x7C)+(u32)var_r7); var_r4 = 8; - (*(u32 *)((u8 *)(var_r7)+0x110)) = 0; - var_r0 = var_r7 + 0x68; + (*(u32 *)((u8 *)(var_r7)+SAVE_FIELD(0x110))) = 0; + var_r0 = var_r7 + SAVE_FIELD(0x68); } else { - { u8 **base; register u32 offset asm("r0"); base=&hitEnemies69; offset=temp_r2_2*0x2E0; offset-=0xB80; var_r5=(u8 *)((u32)*base+offset); } - var_sl = var_r5 + 0x218; + { u8 **base; register u32 offset asm("r0"); base=&hitEnemies69; offset=temp_r2_2*ENEMY_SIZE; offset-=(4 * ENEMY_SIZE); var_r5=(u8 *)((u32)*base+offset); } + var_sl = var_r5 + ENEMY_FIELD(0x218); var_r4 = 1; var_r0 = var_r5 + 0x1DC; } @@ -910,26 +1118,26 @@ void sub_080694AC(struct HitAttack69 *arg0) { } } if (arg0->kind == 0xC) { - if ((*(u32 *)((u8 *)(var_r5)+0x210)) == 0xFF) { + if ((*(u32 *)((u8 *)(var_r5)+ENEMY_FIELD(0x210))) == 0xFF) { packet.control.word &= 0xFF00FFFF; } else { packet.control.word = (packet.control.word & 0xFF00FFFF) | 0x100000; } if ((u32) arg0->attacker <= 3U) { if ((u32) arg0->target <= 3U) { - temp_r2_3 = (*(u32 *)((u8 *)(var_r7)+0x148)); - var_r0_2 = (s16)(((u16) (*(u16 *)((u8 *)(temp_r2_3)+0x0)) >> 4) - ((s32) (*(u32 *)((u8 *)(var_r8)+0x8C)) >> 8)); - var_r1 = (((u32) ((*(u16 *)((u8 *)(temp_r2_3)+0x2)) << 0x14) >> 0x14) - ((s32) (*(u32 *)((u8 *)(var_r8)+0x90)) >> 8)) << 0x10; + temp_r2_3 = (*(u32 *)((u8 *)(var_r7)+SAVE_FIELD(0x148))); + var_r0_2 = (s16)(((u16) (*(u16 *)((u8 *)(temp_r2_3)+0x0)) >> 4) - ((s32) (*(u32 *)((u8 *)(var_r8)+SAVE_FIELD(0x8C))) >> 8)); + var_r1 = (((u32) ((*(u16 *)((u8 *)(temp_r2_3)+0x2)) << 0x14) >> 0x14) - ((s32) (*(u32 *)((u8 *)(var_r8)+SAVE_FIELD(0x90))) >> 8)) << 0x10; } else { - var_r0_2 = (s16) ((s32) (((*(u32 *)((u8 *)(var_r5)+0x14)) - (*(u32 *)((u8 *)(var_r8)+0x8C))) << 8) >> 0x10); - { register u32 *base asm("r2"); base=(u32 *)(var_r8+0x90); var_r1_2=*(u32 *)(var_r5+0x18); var_r2=*base; } + var_r0_2 = (s16) ((s32) (((*(u32 *)((u8 *)(var_r5)+0x14)) - (*(u32 *)((u8 *)(var_r8)+SAVE_FIELD(0x8C)))) << 8) >> 0x10); + { register u32 *base asm("r2"); base=(u32 *)(var_r8+SAVE_FIELD(0x90)); var_r1_2=*(u32 *)(var_r5+0x18); var_r2=*base; } goto block_27; } } else { if ((u32) arg0->target <= 3U) { - var_r0_2 = (s16) ((s32) (((*(u32 *)((u8 *)(var_r7)+0x8C)) - (*(u32 *)((u8 *)(var_r9)+0x14))) << 8) >> 0x10); - { u32 *source; u32 *target; source=(u32 *)(var_r7+0x90); target=(u32 *)(var_r8+0x90); var_r1_2=*source; var_r2=*target; } + var_r0_2 = (s16) ((s32) (((*(u32 *)((u8 *)(var_r7)+SAVE_FIELD(0x8C))) - (*(u32 *)((u8 *)(var_r9)+0x14))) << 8) >> 0x10); + { u32 *source; u32 *target; source=(u32 *)(var_r7+SAVE_FIELD(0x90)); target=(u32 *)(var_r8+SAVE_FIELD(0x90)); var_r1_2=*source; var_r2=*target; } } else { var_r0_2 = (s16) ((s32) (((*(u32 *)((u8 *)(var_r5)+0x14)) - (*(u32 *)((u8 *)(var_r9)+0x14))) << 8) >> 0x10); var_r1_2 = (*(u32 *)((u8 *)(var_r5)+0x18)); @@ -947,8 +1155,8 @@ void sub_080694AC(struct HitAttack69 *arg0) { if ((u32) arg0->target <= 3U) { packet.control.bits.who=*(u8 *)var_r7; if (arg0->target == sub_080020F4()) { - (*(u16 *)((u8 *)(var_r7)+0x20)) = 0xA; - (*(u16 *)((u8 *)(var_r7)+0x88)) = (u16) (packet.value.half[0] + (*(u16 *)((u8 *)(var_r7)+0x88))); + (*(u16 *)((u8 *)(var_r7)+PLAYER_FIELD(0x20))) = 0xA; + (*(u16 *)((u8 *)(var_r7)+SAVE_FIELD(0x88))) = (u16) (packet.value.half[0] + (*(u16 *)((u8 *)(var_r7)+SAVE_FIELD(0x88)))); sub_0801F320(var_r7, (u8 *) &packet); } hitStatus69(&packet, var_sl, (u16) arg0->level, hitTable69[arg0->kind].effect, (s32) (u16) arg0->target); @@ -956,10 +1164,10 @@ void sub_080694AC(struct HitAttack69 *arg0) { packet.control.byte[1] = 0U; } if ((u32) arg0->attacker <= 3U) { - { u32 index; u8 *base; index=*(u16 *)var_r8; index<<=2; base=var_r7+0xF8; base+=index; var_r1_3=(s32 *)base; } - var_r0_4 = (*(u32 *)((u8 *)(var_r8)+0xDC)); + { u32 index; u8 *base; index=*(u16 *)var_r8; index<<=2; base=var_r7+SAVE_FIELD(0xF8); base+=index; var_r1_3=(s32 *)base; } + var_r0_4 = (*(u32 *)((u8 *)(var_r8)+SAVE_FIELD(0xDC))); } else { - { u32 index; register u8 *base asm("r1"); index=*(u16 *)var_r9; index<<=2; base=var_r7+0xE4; base+=index; var_r1_3=(s32 *)base; } + { u32 index; register u8 *base asm("r1"); index=*(u16 *)var_r9; index<<=2; base=var_r7+SAVE_FIELD(0xE4); base+=index; var_r1_3=(s32 *)base; } var_r0_4 = (*(u32 *)((u8 *)(var_r9)+0x50)); } *var_r1_3 = var_r0_4; @@ -976,8 +1184,8 @@ void sub_080694AC(struct HitAttack69 *arg0) { } temp_r4_2 = (u16) (*(u16 *)((u8 *)(var_r7)+0x0)); if (temp_r4_2 == sub_080020F4()) { - (*(u32 *)((u8 *)(var_r7)+0xE0)) = (s32) hitTable69[arg0->kind].effect; - hitRecover69(packet.control.byte[1], packet.value.half[0], hitStats69 + 0x24); + (*(u32 *)((u8 *)(var_r7)+SAVE_FIELD(0xE0))) = (s32) hitTable69[arg0->kind].effect; + hitRecover69(packet.control.byte[1], packet.value.half[0], hitStats69 + SAVE_FIELD(0x24)); } } else { (*(u16 *)((u8 *)(var_r5)+0xC)) = 0xA; @@ -986,7 +1194,7 @@ void sub_080694AC(struct HitAttack69 *arg0) { (*(u32 *)((u8 *)(var_r5)+0x4C)) = record->value.half[0]; sub_0801F2CC(var_r5,(u8 *)record); } if ((u32) arg0->attacker <= 3U) { - var_r0_3 = (*(u32 *)((u8 *)(var_r8)+0xDC)); + var_r0_3 = (*(u32 *)((u8 *)(var_r8)+SAVE_FIELD(0xDC))); } else { { register u8 *source asm("r1"); source=var_r9; asm("" : "+r"(source)); var_r0_3=*(u32 *)(source+0x50); } } @@ -997,7 +1205,7 @@ void sub_080694AC(struct HitAttack69 *arg0) { if (arg0->kind == 0x12) { packet.control.byte[1] = 0U; } - { register u32 stateOffset asm("r2"); register u8 *stateAddress asm("r0"); stateOffset=0x226; asm("" : "+r"(stateOffset)); stateAddress=var_r5+stateOffset; + { register u32 stateOffset asm("r2"); register u8 *stateAddress asm("r0"); stateOffset=ENEMY_FIELD(0x226); asm("" : "+r"(stateOffset)); stateAddress=var_r5+stateOffset; if (*stateAddress != 3) { temp_r0 = sub_0801E244((s32) var_r5, (s32) packet.control.byte[1]); if (temp_r0 != 0) { @@ -1044,7 +1252,7 @@ void sub_080698D4(struct StatusPosition69 *pos) kind=pos->kind; x=pos->x; y=pos->y; - statusInit69(&obj,0x5008C,8,-1,0); + statusInit69(&obj,RES_ID(0x5008C),8,-1,0); obj.style[0]=7; obj.style[1]=8; switch(kind-1U) { @@ -1199,8 +1407,8 @@ void sub_08069BBC(u32 a, u32 b) } struct Z069S {u32 f0,f4,f8,fC;u8 pad10[12];u8 f1C,f1D;u8 pad1E[22];}; struct Z069A {u32 player,bit,target,value,f10,level;}; -struct Z069P {u16 id;u8 pad2[30];u16 state;u8 pad22[14];u32 flags;u8 pad34[52];u8 team;u8 pad69[89];u16 resource;u8 padC4[24];u32 counter;u8 padE0[4];u32 ehist[5];u32 phist[4];u8 pad108[64];u16 *sprite;}; -struct Z069E {u16 id,target;u8 pad4[4];s16 dir;u8 padA[2];u16 state;u8 padE[6];s32 x,y;u8 pad1C[52];u32 counter,lastHit;u16 owner;u8 pad5A[4];u16 resource;u8 pad60[10];u16 wait;u8 pad6C[368];u8 active;u8 pad1DD[78];u8 threshold;u8 pad22C[180];}; +struct Z069P {u16 id;u8 pad2[PLAYER_FIELD(0x20) - 0x2];u16 state;u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)];u8 team;u8 pad69[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0x69)];u16 resource;u8 padC4[PLAYER_FIELD(0xDC) - PLAYER_FIELD(0xC4)];u32 counter;u8 padE0[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xE0)];u32 ehist[5];u32 phist[4];u8 pad108[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x108)];u16 *sprite;}; +struct Z069E {u16 id,target;u8 pad4[4];s16 dir;u8 padA[2];u16 state;u8 padE[6];s32 x,y;u8 pad1C[52];u32 counter,lastHit;u16 owner;u8 pad5A[4];u16 resource;u8 pad60[10];u16 wait;u8 pad6C[368];u8 active;u8 pad1DD[ENEMY_FIELD(0x22B) - 0x1DD];u8 threshold;u8 pad22C[ENEMY_SIZE - ENEMY_FIELD(0x22C)];}; struct Z069Off {s16 x,y;}; extern struct Z069P z069P[] asm("gUnk_03003CE0"); extern u8 *z069EBase asm("gUnk_030056F4"); @@ -1266,7 +1474,7 @@ void sub_08069C44(struct Z069A *arg) { p=&z069P[player]; saved=p->counter; } else { - enemy=(struct Z069E *)(z069EBase+(player*0x2E0+0xFFFFF480)); + enemy=(struct Z069E *)(z069EBase+(player*ENEMY_SIZE-4*ENEMY_SIZE)); while(enemy->waitthreshold) { if(sub_08056E90()!=0 || sub_0800BA6C()==0 || enemy->state==10 || enemy->state==11) { z069F[player]&=~(1<=count) target=0xFFFF; } else { for(i=0;i<=4;i++) { - e=(struct Z069E *)(z069EBase+i*0x2E0); + e=(struct Z069E *)(z069EBase+i*ENEMY_SIZE); if((z069EMask&(1<target==target) break; } if(i>4) target=0xFFFF; @@ -1320,10 +1528,10 @@ void sub_08069C44(struct Z069A *arg) { x+=z069Sin[((s16)angle)+0x40]*4; y+=z069Sin[((s16)angle)]*4; if(level<=5) { - z069Init(&sprite,0x50049,8,-1,0); + z069Init(&sprite,RES_ID(0x50049),8,-1,0); level=(u16)(level-1); } else { - z069Init(&sprite,0x50048,8,-1,0); + z069Init(&sprite,RES_ID(0x50048),8,-1,0); level=(u16)(level-6); } level=(u16)(level<<3); @@ -1353,6 +1561,9 @@ void sub_08069C44(struct Z069A *arg) { } x+=z069Sin[((s16)angle)+0x40]*2; y+=z069Sin[((s16)angle)]*2; +#ifdef REGION_USA + asm("" : : "r"(x), "r"(y)); +#endif z069Coords((s16)(x>>8),(s16)(y>>8),&dx,&dy,0x30,t); shade=sub_0800BC44(x>>8,y>>8,0); { @@ -1423,7 +1634,7 @@ void sub_0806A19C(struct Z069A *arg) { if(player<=3) { p=&z069P[player]; } else { - enemy=(struct Z069E *)(z069EBase+(player*0x2E0+0xFFFFF480)); + enemy=(struct Z069E *)(z069EBase+(player*ENEMY_SIZE-4*ENEMY_SIZE)); while(enemy->waitthreshold) { if(sub_08056E90()!=0 || sub_0800BA6C()==0 || enemy->state==10 || enemy->state==11) { z069F[player]&=~(1<3) && sub_0800CCCC()==0 && sub_0800CD34()==0) sub_0805865C(level+0x115); retarget: if(level<=5) { - z069Init(&sprite,0x50091,8,-1,0); + z069Init(&sprite,RES_ID(0x50091),8,-1,0); level=(u16)(level-1); } else { - z069Init(&sprite,0x5008E,8,-1,0); + z069Init(&sprite,RES_ID(0x5008E),8,-1,0); level=(u16)(level-6); } sprite.f1C=7; sprite.f1D=8; @@ -1479,7 +1690,7 @@ void sub_0806A19C(struct Z069A *arg) { if(i>=count) target=0xFFFF; } else { for(i=0;i<=4;i++) { - e=(struct Z069E *)(z069EBase+i*0x2E0); + e=(struct Z069E *)(z069EBase+i*ENEMY_SIZE); if((z069EMask&(1<target==target) break; } if(i>4) target=0xFFFF; @@ -1554,8 +1765,8 @@ void sub_0806A19C(struct Z069A *arg) { z069F[player]&=~(1<player; bit=arg->bit; level=(u16)arg->level; initialLevel=level; if(player<=3) p=&t070Players[player]; - else enemy=(struct T070Enemy *)((u8 *)t070Enemies+(player*0x2E0+0xFFFFF480)); + else enemy=(struct T070Enemy *)((u8 *)t070Enemies+(player*ENEMY_SIZE-4*ENEMY_SIZE)); frame=0; phase=0; counter=0; if(sub_080020F4()!=player) { if(player>3) { @@ -1621,7 +1832,7 @@ void sub_0806A88C(struct T070Args *arg) { if((s16)costPlayer->resource<0) costPlayer->resource=counter; } if(sub_080020F4()==player && sub_0800CCCC()==0 && sub_0800CD34()==0) sub_0805865C(0x169); - t070Init(&sprite,0x5008C,8,-1,0); + t070Init(&sprite,RES_ID(0x5008C),8,-1,0); sprite.f1C=7; sprite.f1D=8; frame=0;phase=0;timeout=0xB4; for (;;) { @@ -1659,8 +1870,8 @@ void sub_0806A88C(struct T070Args *arg) { } struct T071S {u32 f0,f4,f8,fC;u8 pad10[12];u8 f1C,f1D;u8 pad1E[22];}; struct T071A {u32 player,bit,target,value,f10,level;}; -struct T071P {u16 id;u8 pad2[30];u16 state;u8 pad22[14];u32 flags;u8 pad34[52];u8 team;u8 pad69[89];u16 resource;u8 padC4[24];u32 counter;u8 padE0[4];u32 ehist[5];u32 phist[4];u8 pad108[64];u16 *sprite;}; -struct T071E {u16 id,target;u8 pad4[4];s16 dir;u8 padA[2];u16 state;u8 padE[6];s32 x,y;u8 pad1C[52];u32 counter,lastHit;u16 owner;u8 pad5A[4];u16 resource;u8 pad60[10];u16 wait;u8 pad6C[368];u8 active;u8 pad1DD[78];u8 threshold;u8 pad22C[180];}; +struct T071P {u16 id;u8 pad2[PLAYER_FIELD(0x20)-2];u16 state;u8 pad22[PLAYER_FIELD(0x30)-PLAYER_FIELD(0x22)];u32 flags;u8 pad34[52];u8 team;u8 pad69[89];u16 resource;u8 padC4[24];u32 counter;u8 padE0[4];u32 ehist[5];u32 phist[4];u8 pad108[64];u16 *sprite;u8 pad14C[PLAYER_SIZE-PLAYER_FIELD(0x14C)];}; +struct T071E {u16 id,target;u8 pad4[4];s16 dir;u8 padA[2];u16 state;u8 padE[6];s32 x,y;u8 pad1C[52];u32 counter,lastHit;u16 owner;u8 pad5A[4];u16 resource;u8 pad60[10];u16 wait;u8 pad6C[368];u8 active;u8 pad1DD[ENEMY_FIELD(0x22B) - 0x1DD];u8 threshold;u8 pad22C[ENEMY_SIZE - ENEMY_FIELD(0x22C)];}; extern struct T071P t071P[] asm("gUnk_03003CE0"); extern u8 *t071EBase asm("gUnk_030056F4"); extern u32 t071EMask asm("gUnk_030056FC"); @@ -1732,7 +1943,7 @@ void sub_0806ABC0(struct T071A *arg) { if(i>=count) target=0xFFFF; } else { for(i=0;i<=4;i++) { - enemy=(struct T071E *)(t071EBase+i*0x2E0); + enemy=(struct T071E *)(t071EBase+i*ENEMY_SIZE); if((t071EMask&(1<target==target) break; } if(i>4) target=0xFFFF; @@ -1745,7 +1956,7 @@ void sub_0806ABC0(struct T071A *arg) { dir=((u8 *)p->sprite)[3]>>4; angle=tbl[dir]; } else { - enemy=(struct T071E *)(t071EBase+(player*0x2E0+0xFFFFF480)); + enemy=(struct T071E *)(t071EBase+(player*ENEMY_SIZE-4*ENEMY_SIZE)); x=enemy->x; y=enemy->y; dir=(u16)enemy->dir; angle=tbl[enemy->dir]; @@ -1780,13 +1991,13 @@ void sub_0806ABC0(struct T071A *arg) { x+=t071Sin[((s16)angle)+0x40]*4; y+=t071Sin[((s16)angle)]*4; if(level<=4) { - x071Init(&sprite,0x50051,8,-1,0); + x071Init(&sprite,RES_ID(0x50051),8,-1,0); level=(u16)(level-1); } else if(level<=6) { - x071Init(&sprite,0x50054,8,-1,0); + x071Init(&sprite,RES_ID(0x50054),8,-1,0); level=(u16)(level-5); } else { - x071Init(&sprite,0x5005F,8,-1,0); + x071Init(&sprite,RES_ID(0x5005F),8,-1,0); level=(u16)(level-7); } level=(u16)(level<<3); @@ -1802,7 +2013,7 @@ void sub_0806ABC0(struct T071A *arg) { if(target>3) { for(i=0;i<=4;i++) { if(!(t071EMask&(1<active) continue; dx=(u32)(e->x-x)>>8; dy=(u32)(e->y-y)>>8; @@ -1868,8 +2079,8 @@ void sub_0806ABC0(struct T071A *arg) { } struct Y073S {u32 f0,f4,f8,fC;u8 pad10[12];u8 f1C,f1D;u8 pad1E[22];}; struct Y073A {u32 player,bit,target,value,f10,level;}; -struct Y073P {u16 id;u8 pad2[30];u16 state;u8 pad22[14];u32 flags;u8 pad34[52];u8 team;u8 pad69[77];u16 fB6;u8 padB8[10];u16 resource;u8 padC4[132];u8 *sprite;}; -struct Y073E {u16 id,target;u8 pad4[4];s16 dir;u8 padA[2];u16 state;u8 padE[6];s32 x,y;u8 pad1C[66];u16 resource;u8 pad60[10];u16 wait;u8 pad6C[368];u8 active;u8 pad1DD[78];u8 threshold;u8 pad22C[180];}; +struct Y073P {u16 id;u8 pad2[PLAYER_FIELD(0x20) - 0x2];u16 state;u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)];u8 team;u8 pad69[PLAYER_FIELD(0xB6) - PLAYER_FIELD(0x69)];u16 fB6;u8 padB8[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB8)];u16 resource;u8 padC4[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xC4)];u8 *sprite;}; +struct Y073E {u16 id,target;u8 pad4[4];s16 dir;u8 padA[2];u16 state;u8 padE[6];s32 x,y;u8 pad1C[66];u16 resource;u8 pad60[10];u16 wait;u8 pad6C[368];u8 active;u8 pad1DD[ENEMY_FIELD(0x22B) - 0x1DD];u8 threshold;u8 pad22C[ENEMY_SIZE - ENEMY_FIELD(0x22C)];}; struct Y073R {s16 x,y;}; extern struct Y073P y073P[] asm("gUnk_03003CE0"); extern u8 *y073EBase asm("gUnk_030056F4"); @@ -1930,7 +2141,7 @@ void sub_0806B3C4(struct Y073A *arg) { local=(u16)sub_080020F4(); player=arg->player; bit=arg->bit; level=(u16)arg->level; if(player<=3) p=&y073P[player]; - else enemy=(struct Y073E *)(y073EBase+(player*0x2E0+0xFFFFF480)); + else enemy=(struct Y073E *)(y073EBase+(player*ENEMY_SIZE-4*ENEMY_SIZE)); if(local!=player) { if(player>3) { costBase=y073Cost; @@ -1999,7 +2210,7 @@ void sub_0806B3C4(struct Y073A *arg) { } else { for(i=0;i<=4;i++) { if(!(y073EMask&(1<state==11) continue; if(!e->active) continue; dx=(u32)(e->x-x)>>8; @@ -2015,7 +2226,7 @@ void sub_0806B3C4(struct Y073A *arg) { } } } - y073Init(&sprite,0x50074,8,-1,0); + y073Init(&sprite,RES_ID(0x50074),8,-1,0); sprite.f1C=7; sprite.f1D=8; if(level>6) level=6; if(nhits==0) { @@ -2066,7 +2277,7 @@ void sub_0806B3C4(struct Y073A *arg) { } } else { for(i=0;ix>>8),(s16)(e->y>>8),&dx,&dy,0x30,0); shade=sub_0800BC44(x>>8,y>>8,0); if(delay[i]==0) { @@ -2104,8 +2315,8 @@ void sub_0806B3C4(struct Y073A *arg) { y073F[player]&=~(1<wait; u8 *tp = &e->threshold; u16 w = *wp; off = player * 4; if (w <= *tp) do { if (sub_08056E90() != 0 || sub_0800BA6C() == 0 || e->state == 10 || e->state == 11) { *(u32 *)(off + (u8 *)fBE) &= ~(1 << bit); @@ -2230,7 +2441,7 @@ void sub_0806BE24(struct ArgBE *arg) target = 0xFFFF; } else { for (i = 0; i <= 4; i++) { - e2 = (struct EneBE *)(eBEBase + i * 0x2E0); + e2 = (struct EneBE *)(eBEBase + i * ENEMY_SIZE); if ((eBEMask & (1 << i)) && e2->uid == target) break; } @@ -2272,7 +2483,7 @@ void sub_0806BE24(struct ArgBE *arg) sub_0805865C(level + 0x123); } cool = 0; - initBE(&spr, 0x50097, 8, -1, 0); + initBE(&spr, RES_ID(0x50097), 8, -1, 0); spr.f1C = 7; spr.f1D = 8; for (;;) { @@ -2361,8 +2572,8 @@ void sub_0806BE24(struct ArgBE *arg) *(u32 *)(off + (u8 *)fBE) &= ~(1 << bit); } struct SprC568 { u32 f0, f4, f8, fC; u8 pad10[12]; u8 f1C, f1D; u8 pad1E[22]; }; -struct PlyC568 { u16 id; u8 pad2[0x1E]; u16 state; u8 pad22[0x46]; u8 team; u8 pad69[0x49]; u16 fB2; u8 padB4[2]; u16 fB6; u8 padB8[10]; u16 resource; u8 padC4[0x84]; u16 *sprite; }; -struct EneC568 { u16 id; u8 pad2[6]; s16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x3C]; u16 f58; u8 pad5A[4]; u16 resource; u8 pad60[10]; u16 wait; u8 pad6C[0x170]; u8 active; u8 pad1DD[0x4E]; u8 threshold; u8 pad22C[0xB4]; }; +struct PlyC568 { u16 id; u8 pad2[PLAYER_FIELD(0x20) - 0x2]; u16 state; u8 pad22[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x22)]; u8 team; u8 pad69[PLAYER_FIELD(0xB2) - PLAYER_FIELD(0x69)]; u16 fB2; u8 padB4[PLAYER_FIELD(0xB6) - PLAYER_FIELD(0xB4)]; u16 fB6; u8 padB8[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB8)]; u16 resource; u8 padC4[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xC4)]; u16 *sprite; }; +struct EneC568 { u16 id; u8 pad2[6]; s16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x3C]; u16 f58; u8 pad5A[4]; u16 resource; u8 pad60[10]; u16 wait; u8 pad6C[0x170]; u8 active; u8 pad1DD[ENEMY_FIELD(0x22B) - 0x1DD]; u8 threshold; u8 pad22C[ENEMY_SIZE - ENEMY_FIELD(0x22C)]; }; struct RangeC568 { s16 x, y; }; struct ArgC568 { u32 player, bit, target, value, f10, level; }; extern struct PlyC568 pC568[] asm("gUnk_03003CE0"); @@ -2430,7 +2641,7 @@ void sub_0806C568(struct ArgC568 *arg) if (player <= 3) { p = &pC568[player]; } else { - e = (struct EneC568 *)(eC568Base + (player * 0x2E0 + 0xFFFFF480)); + e = (struct EneC568 *)(eC568Base + (player * ENEMY_SIZE - 4 * ENEMY_SIZE)); while (e->wait < e->threshold) { if (sub_08056E90() != 0 || sub_0800BA6C() == 0 || e->state == 10 || e->state == 11) { fC568[player] &= ~(1 << bit); @@ -2561,7 +2772,7 @@ void sub_0806C568(struct ArgC568 *arg) for (i = 0; i <= 4; i++) { if (!((1 << i) & eC568Mask)) continue; - e2 = (struct EneC568 *)(eC568Base + i * 0x2E0); + e2 = (struct EneC568 *)(eC568Base + i * ENEMY_SIZE); if (e2->state == 11) continue; if (e2->active == 0) @@ -2587,7 +2798,7 @@ void sub_0806C568(struct ArgC568 *arg) level = 6; if (local == player && sub_0800CCCC() == 0 && sub_0800CD34() == 0) sub_0805865C(level + 0x155); - initC568(&desc, 0x5009E, 8, -1, 0); + initC568(&desc, RES_ID(0x5009E), 8, -1, 0); desc.f1C = 7; desc.f1D = 8; if (nhit == 0) { @@ -2621,7 +2832,7 @@ void sub_0806C568(struct ArgC568 *arg) } } else { for (i = 0; i < count; i++) { - e2 = (struct EneC568 *)(eC568Base + targets[i] * 0x2E0); + e2 = (struct EneC568 *)(eC568Base + targets[i] * ENEMY_SIZE); coordsC568((s16)(e2->x >> 8), (s16)(e2->y >> 8), &dx, &dy, 0x30, 0); shade = sub_0800BC44(e2->x >> 8, e2->y >> 8, 0); if (timers[i] == 0) { @@ -2659,7 +2870,7 @@ void sub_0806C568(struct ArgC568 *arg) } } else { for (i = 0; i < count; i++) { - e2 = (struct EneC568 *)(eC568Base + targets[i] * 0x2E0); + e2 = (struct EneC568 *)(eC568Base + targets[i] * ENEMY_SIZE); if (local == player) { arg->target = e2->id + 4; sendC568(arg); @@ -2691,25 +2902,25 @@ void sub_0806C568(struct ArgC568 *arg) extern u8 *t71Save asm("gUnk_030034E0"); struct T71CDFPlayer { u16 f0; - u8 pad2[0x1E]; + u8 pad2[PLAYER_FIELD(0x20) - 0x2]; u16 f20; - u8 pad22[0x2]; + u8 pad22[PLAYER_FIELD(0x24) - PLAYER_FIELD(0x22)]; u16 f24; u16 f26; - u8 pad28[0x8]; + u8 pad28[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x28)]; u32 f30; - u8 pad34[0x2E]; + u8 pad34[PLAYER_FIELD(0x62) - PLAYER_FIELD(0x34)]; u16 f62; - u8 pad64[0x4]; + u8 pad64[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x64)]; u8 f68; - u8 pad69[0x4B]; + u8 pad69[PLAYER_FIELD(0xB4) - PLAYER_FIELD(0x69)]; u16 fB4; - u8 padB6[0xC]; + u8 padB6[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB6)]; u16 fC2; u16 fC4; - u8 padC6[0x1A]; + u8 padC6[PLAYER_FIELD(0xE0) - PLAYER_FIELD(0xC6)]; u32 fE0; - u8 padE4[0x64]; + u8 padE4[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xE4)]; u8 * f148; }; extern struct T71CDFPlayer t71CDFPlayers[] asm("gUnk_03003CE0"); @@ -2815,10 +3026,10 @@ void sub_0806CDF0(void *arg0) sp28 = temp_r0 * 4; goto block_12; } - var_r7 = gUnk_030056F4 + ((temp_r0 * 0x2E0) + 0xFFFFF480); + var_r7 = gUnk_030056F4 + ((temp_r0 * ENEMY_SIZE) - 4 * ENEMY_SIZE); { u16 *ap = (u16 *) (((u8 *) var_r7) + 0x6A); - u8 *bp = ((u8 *) var_r7) + 0x22B; + u8 *bp = ((u8 *) var_r7) + ENEMY_FIELD(0x22B); u32 a = *ap; temp_r2_2 = temp_r0 * 4; sp28 = temp_r2_2; @@ -2834,7 +3045,7 @@ void sub_0806CDF0(void *arg0) } sub_080003F0(); - if (((u32) (*((u16 *) (((u8 *) var_r7) + 0x6A)))) >= ((u32) (*((u8 *) (((u8 *) var_r7) + 0x22B))))) + if (((u32) (*((u16 *) (((u8 *) var_r7) + 0x6A)))) >= ((u32) (*((u8 *) (((u8 *) var_r7) + ENEMY_FIELD(0x22B)))))) { goto block_12; } @@ -2926,8 +3137,14 @@ void sub_0806CDF0(void *arg0) if (t071EMask & (1 << var_r5_2)) { { - s32 o = var_r5_2 * 0x2E0; +#ifdef REGION_USA + typeof(pg) table = &gUnk_030056F4; + s32 o = var_r5_2 * ENEMY_SIZE; + temp_r4_4 = *table + o; +#else + s32 o = var_r5_2 * ENEMY_SIZE; temp_r4_4 = *pg + o; +#endif } var_r5_4 = 0x18; { @@ -2981,11 +3198,15 @@ void sub_0806CDF0(void *arg0) } if (sp1C == temp_r0) { +#ifdef REGION_USA + temp_r0_6 = (var_r9->fC4 += t71Heal[temp_r2]); +#else { u16 *hp = &var_r9->fC4; temp_r0_6 = t71Heal[temp_r2] + (var_r5_2 = *hp); } var_r9->fC4 = temp_r0_6; +#endif if (((s32) ((s16) temp_r0_6)) > ((s32) ((s16) var_r9->f62))) { var_r9->fC4 = (u16) var_r9->f62; @@ -3078,12 +3299,12 @@ void sub_0806CDF0(void *arg0) if (((u32) temp_r2) > 6U) { var_r1_2 = var_r6->f62; - var_r0_6 = (((u8 *) var_r6) + 0x62) + 0x62; + var_r0_6 = (((u8 *) var_r6) + PLAYER_FIELD(0x62)) + (PLAYER_FIELD(0xC4) - PLAYER_FIELD(0x62)); } else { var_r1_2 = (s16) var_r6->f62; if (var_r1_2 < 0) var_r1_2 += 3; var_r1_2 >>= 2; - var_r0_6 = ((u8 *) var_r6) + 0xC4; + var_r0_6 = ((u8 *) var_r6) + PLAYER_FIELD(0xC4); } *var_r0_6 = var_r1_2; temp_r0_8 = var_r6->f20; @@ -3100,27 +3321,27 @@ void sub_0806CDF0(void *arg0) switch (temp_r0_9) { case 0: - *((u16 *) (((u8 *) t71Save) + 0x24)) = (u16) ((*((u16 *) (((u8 *) t71Save) + 0x24))) + 1); + *((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x24))) = (u16) ((*((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x24)))) + 1); break; case 1: - *((u16 *) (((u8 *) t71Save) + 0x26)) = (u16) ((*((u16 *) (((u8 *) t71Save) + 0x26))) + 1); + *((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x26))) = (u16) ((*((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x26)))) + 1); break; case 2: - *((u16 *) (((u8 *) t71Save) + 0x28)) = (u16) ((*((u16 *) (((u8 *) t71Save) + 0x28))) + 1); + *((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x28))) = (u16) ((*((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x28)))) + 1); break; case 3: - *((u16 *) (((u8 *) t71Save) + 0x2A)) = (u16) ((*((u16 *) (((u8 *) t71Save) + 0x2A))) + 1); + *((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x2A))) = (u16) ((*((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x2A)))) + 1); break; case 4: - *((u16 *) (((u8 *) t71Save) + 0x2C)) = (u16) ((*((u16 *) (((u8 *) t71Save) + 0x2C))) + 1); + *((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x2C))) = (u16) ((*((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x2C)))) + 1); break; case 5: - *((u16 *) (((u8 *) t71Save) + 0x2E)) = (u16) ((*((u16 *) (((u8 *) t71Save) + 0x2E))) + 1); + *((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x2E))) = (u16) ((*((u16 *) (((u8 *) t71Save) + SAVE_FIELD(0x2E)))) + 1); break; } @@ -3145,7 +3366,7 @@ void sub_0806CDF0(void *arg0) { if ((t071EMask & (1 << var_r5_4)) && ((*(sp0 + var_r5_4)) == (var_r5_4 + 4))) { - temp_r4_4 = gUnk_030056F4 + (var_r5_4 * 0x2E0); + temp_r4_4 = gUnk_030056F4 + (var_r5_4 * ENEMY_SIZE); temp_r2 = (u16) (((s32) (t71Heal[sp10] * 0x78)) / ((s32) (sp4[var_r5_4] + 0x78))); { u16 *hp = (u16 *) (((u8 *) temp_r4_4) + 0x5C); @@ -3190,7 +3411,7 @@ void sub_0806CDF0(void *arg0) } struct T072D4Effect { s16 timer; u16 owner, kind, level, a, b, c, d; u8 pad[24]; }; -struct T072D4Player { u8 pad0[0x20]; u16 state; u8 pad22[2]; u16 x24, x26; u8 pad28[12]; struct T072D4Effect *effects; u8 pad38[0x2c]; u16 mode; u8 pad66[2]; u8 team; u8 pad69[0x4b]; u16 wait; u8 padB6[12]; s16 resource; u8 padC4[0x84]; u16 *sprite; }; +struct T072D4Player { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x24) - PLAYER_FIELD(0x22)]; u16 x24, x26; u8 pad28[PLAYER_FIELD(0x34) - PLAYER_FIELD(0x28)]; struct T072D4Effect *effects; u8 pad38[PLAYER_FIELD(0x64) - PLAYER_FIELD(0x38)]; u16 mode; u8 pad66[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x66)]; u8 team; u8 pad69[PLAYER_FIELD(0xB4) - PLAYER_FIELD(0x69)]; u16 wait; u8 padB6[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB6)]; s16 resource; u8 padC4[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xC4)]; u16 *sprite; }; struct T072D4Args { u32 player, bit, f8, value, f10, level; }; extern struct T072D4Player t072D4Players[] asm("gUnk_03003CE0"); extern u32 t072D4Flags[] asm("gUnk_030063E0"); @@ -3348,7 +3569,7 @@ void sub_0806D4A4(struct T072D4Args *arg) { t072D4Flags[player] &= ~(1 << bit); } struct T072Effect { s16 timer; u16 owner, kind, level, a, b, c, d; u8 pad[24]; }; -struct T072Player { u8 pad0[0x20]; u16 state; u8 pad22[2]; u16 x24, x26; u8 pad28[12]; struct T072Effect *effects; u8 pad38[0x2c]; u16 mode; u8 pad66[2]; u8 team; u8 pad69[0x4b]; u16 wait; u8 padB6[12]; s16 resource; u8 padC4[0x84]; u16 *sprite; }; +struct T072Player { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x24) - PLAYER_FIELD(0x22)]; u16 x24, x26; u8 pad28[PLAYER_FIELD(0x34) - PLAYER_FIELD(0x28)]; struct T072Effect *effects; u8 pad38[PLAYER_FIELD(0x64) - PLAYER_FIELD(0x38)]; u16 mode; u8 pad66[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x66)]; u8 team; u8 pad69[PLAYER_FIELD(0xB4) - PLAYER_FIELD(0x69)]; u16 wait; u8 padB6[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB6)]; s16 resource; u8 padC4[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xC4)]; u16 *sprite; }; struct T072Args { u32 player, bit, f8, value, f10, level; }; extern struct T072Player t072Players[] asm("gUnk_03003CE0"); extern u32 t072Flags[] asm("gUnk_030063E0"); @@ -3503,7 +3724,7 @@ void sub_0806D7EC(struct T072Args *arg) { t072Flags[player] &= ~(1 << bit); } struct T072DBEffect { s16 timer; u16 owner, kind, level, a, b, c, d; s16 strength; u8 pad[22]; }; -struct T072DBPlayer { u8 pad0[0x20]; u16 state; u8 pad22[2]; u16 x24, x26; u8 pad28[12]; struct T072DBEffect *effects; u8 pad38[0x2c]; u16 mode; u8 pad66[2]; u8 team; u8 pad69[0x4b]; u16 wait; u16 ready; u8 padB8[10]; s16 resource; u8 padC4[0x84]; u16 *sprite; }; +struct T072DBPlayer { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x24) - PLAYER_FIELD(0x22)]; u16 x24, x26; u8 pad28[PLAYER_FIELD(0x34) - PLAYER_FIELD(0x28)]; struct T072DBEffect *effects; u8 pad38[PLAYER_FIELD(0x64) - PLAYER_FIELD(0x38)]; u16 mode; u8 pad66[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x66)]; u8 team; u8 pad69[PLAYER_FIELD(0xB4) - PLAYER_FIELD(0x69)]; u16 wait; u16 ready; u8 padB8[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB8)]; s16 resource; u8 padC4[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xC4)]; u16 *sprite; }; struct T072DBArgs { u32 player, bit, f8, value, f10, level; }; extern struct T072DBPlayer t072DBPlayers[] asm("gUnk_03003CE0"); extern u32 t072DBFlags[] asm("gUnk_030063E0"); @@ -3658,8 +3879,8 @@ void sub_0806DB1C(struct T072DBArgs *arg) { ((u32 *)t072DBFlags)[player] &= ~(1 << bit); } struct T072DESprite { u32 f0, f4, f8, fC; u8 pad10[12]; u8 f1C, f1D; u8 pad1E[22]; }; -struct T072DEPlayer { u16 id; u8 pad2[0x1e]; u16 state; u8 pad22[0x46]; u8 team; u8 pad69[0x49]; u16 phase, wait, ready; u8 padB8[10]; s16 resource; u8 padC4[24]; u32 counter; u8 padE0[0x64]; u8 *config; u16 *sprite; }; -struct T072DEEnemy { u16 id; u8 pad2[6]; s16 direction; u8 padA[2]; u16 state; u8 padE[6]; s32 x,y; u8 pad1C[0x42]; s16 resource; u8 pad60[10]; u16 wait; u8 pad6C[0x170]; u8 active; u8 pad1DD[0x4e]; u8 threshold; u8 pad22C[0xb4]; }; +struct T072DEPlayer { u16 id; u8 pad2[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x2)]; u16 state; u8 pad22[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x22)]; u8 team; u8 pad69[PLAYER_FIELD(0xB2) - PLAYER_FIELD(0x69)]; u16 phase, wait, ready; u8 padB8[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB8)]; s16 resource; u8 padC4[PLAYER_FIELD(0xDC) - PLAYER_FIELD(0xC4)]; u32 counter; u8 padE0[PLAYER_FIELD(0x144) - PLAYER_FIELD(0xE0)]; u8 *config; u16 *sprite; }; +struct T072DEEnemy { u16 id; u8 pad2[6]; s16 direction; u8 padA[2]; u16 state; u8 padE[6]; s32 x,y; u8 pad1C[0x42]; s16 resource; u8 pad60[10]; u16 wait; u8 pad6C[0x170]; u8 active; u8 pad1DD[ENEMY_FIELD(0x22B) - 0x1DD]; u8 threshold; u8 pad22C[ENEMY_SIZE - ENEMY_FIELD(0x22C)]; }; struct T072DEBits { u8 kind:4; u8 r0:4; u8 p1[3]; u32 flags:6; }; struct T072DEArgs { u32 player, bit, target, value, f10, level; }; extern struct T072DEPlayer t072DEPlayers[] asm("gUnk_03003CE0"); @@ -3705,6 +3926,11 @@ void sub_0806DE94(struct T072DEArgs *arg) { u8 *delayDst, *delayPrev; u32 random; s16 *costEntry; +#ifdef REGION_USA + u32 odd; + u16 *ready; + s32 active; +#endif local = sub_080020F4(); player = arg->player; bit = arg->bit; level = arg->level; originalLevel = level; @@ -3766,7 +3992,13 @@ void sub_0806DE94(struct T072DEArgs *arg) { facing = (u16)(t072DEDirections[caster->direction] * 2); } selected = 0; total = 0; +#ifdef REGION_USA + active = sub_0800CDF8(); + ready = &p->ready; + if (active == 0) { +#else if (sub_0800CDF8() == 0) { +#endif if (arg->target <= 3) { nplayers = sub_08002164(); for (i = 0; i < nplayers; i++) { @@ -3795,6 +4027,9 @@ void sub_0806DE94(struct T072DEArgs *arg) { } } else { for (i = 0; i <= 4 && sub_0800CD8C() == 0; i++) { +#ifdef REGION_USA + asm("" : : "r"(i)); +#endif if (!((u32)gUnk_030056FC & (1 << i))) continue; enemy = &t072DEEnemies[i]; if (enemy->state == 11 || enemy->active == 0) continue; @@ -3817,7 +4052,7 @@ void sub_0806DE94(struct T072DEArgs *arg) { } } if ((local == player || player > 3) && sub_0800CCCC() == 0 && sub_0800CD34() == 0) sub_0805865C(level + 0x140); - t072DEInit(&sprite,0x5008B,8,-1,0); + t072DEInit(&sprite,RES_ID(0x5008B),8,-1,0); sprite.f1C = 7; sprite.f1D = 8; if (level > 6) level = 6; if (selected == 0) { @@ -3881,11 +4116,19 @@ void sub_0806DE94(struct T072DEArgs *arg) { } else if (delays[i] != 240) delays[i]--; } } +#ifdef REGION_USA + if (sub_0800CC98() == 0 && sub_0800CD8C() == 0 && sub_0800CCCC() == 0 && (gUnk_03002344 & 1) == (odd = player & 1)) sub_08000AF0(23,sprite.fC,2); +#else if (sub_0800CC98() == 0 && sub_0800CD8C() == 0 && sub_0800CCCC() == 0 && (gUnk_03002344 & 1) == (player & 1)) sub_08000AF0(23,sprite.fC,2); +#endif sub_080003F0(); } } +#ifdef REGION_USA + while (*ready == 0) sub_080003F0(); +#else while (p->ready == 0) sub_080003F0(); +#endif if (player <= 3 && player != local) p->counter++; t072DEFlags[player] &= ~(1 << bit); } @@ -3893,8 +4136,8 @@ void sub_0806DE94(struct T072DEArgs *arg) { struct ArgE7D4 { u32 player, bit, target, value, f10, level; }; struct SprE7D4 { u32 f0, f4, f8, fC; u8 pad10[12]; u8 f1C, f1D; u8 pad1E[22]; }; struct SprBitsE7D4 { u8 lo:4; u8 hi:4; u8 b1, b2, b3; u8 b4:6; u8 b4hi:2; }; -struct PlyE7D4 { u16 id; u8 pad2[0x1E]; u16 state; u8 pad22[0x46]; u8 team; u8 pad69[0x49]; u16 fB2; u8 padB4[2]; u16 fB6; u8 padB8[10]; u16 resource; u8 padC4[0x84]; u16 *sprite; }; -struct EneE7D4 { u16 id; u8 pad2[6]; s16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x42]; u16 resource; u8 pad60[10]; u16 wait; u8 pad6C[0x170]; u8 team; u8 pad1DD[0x4E]; u8 threshold; u8 pad22C[2]; u8 w, h; u8 pad230[0xB0]; }; +struct PlyE7D4 { u16 id; u8 pad2[PLAYER_FIELD(0x20) - 0x2]; u16 state; u8 pad22[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x22)]; u8 team; u8 pad69[PLAYER_FIELD(0xB2) - PLAYER_FIELD(0x69)]; u16 fB2; u8 padB4[PLAYER_FIELD(0xB6) - PLAYER_FIELD(0xB4)]; u16 fB6; u8 padB8[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB8)]; u16 resource; u8 padC4[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xC4)]; u16 *sprite; }; +struct EneE7D4 { u16 id; u8 pad2[6]; s16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x42]; u16 resource; u8 pad60[10]; u16 wait; u8 pad6C[0x170]; u8 team; u8 pad1DD[ENEMY_FIELD(0x22B) - 0x1DD]; u8 threshold; u8 pad22C[2]; u8 w, h; u8 pad230[ENEMY_SIZE - ENEMY_FIELD(0x230)]; }; struct BoxE7D4 { u32 w:16; u32 h:16; }; struct PosE7D4 { s32 x, y; }; extern struct PlyE7D4 pE7D4[] asm("gUnk_03003CE0"); @@ -3963,7 +4206,7 @@ void sub_0806E7D4(struct ArgE7D4 *arg) if (player <= 3) { p = &pE7D4[player]; } else { - e = (struct EneE7D4 *)(eE7D4Base + (player * 0x2E0 + 0xFFFFF480)); + e = (struct EneE7D4 *)(eE7D4Base + (player * ENEMY_SIZE - 4 * ENEMY_SIZE)); while (e->wait < e->threshold) { if (sub_08056E90() != 0 || sub_0800BA6C() == 0 || e->state == 10 || e->state == 11) { fE7D4[player] &= ~(1 << bit); @@ -4049,7 +4292,7 @@ void sub_0806E7D4(struct ArgE7D4 *arg) for (i = 0; i <= 4; i++) { if (!(eE7D4Mask & (1 << i))) continue; - e2 = (struct EneE7D4 *)(eE7D4Base + i * 0x2E0); + e2 = (struct EneE7D4 *)(eE7D4Base + i * ENEMY_SIZE); if (e2->state == 11) continue; if (e2->team == 0) @@ -4065,7 +4308,7 @@ void sub_0806E7D4(struct ArgE7D4 *arg) } if ((local == player || player > 3) && sub_0800CCCC() == 0 && sub_0800CD34() == 0) sub_0805865C(level + 0x140); - initE7D4(&spr, 0x5008B, 8, -1, 0); + initE7D4(&spr, RES_ID(0x5008B), 8, -1, 0); spr.f1C = 7; spr.f1D = 8; if (level > 6) @@ -4128,7 +4371,7 @@ void sub_0806E7D4(struct ArgE7D4 *arg) } } else { for (i = 0; i < count; i++) { - e2 = (struct EneE7D4 *)(eE7D4Base + hits[i] * 0x2E0); + e2 = (struct EneE7D4 *)(eE7D4Base + hits[i] * ENEMY_SIZE); coordsE7D4((s16)(e2->x >> 8), (s16)(e2->y >> 8), &dx, &dy, 0x30, 0); shadeB = sub_0800BC44(e2->x >> 8, e2->y >> 8, 0); if (delay[i] == 0) { @@ -4144,10 +4387,18 @@ void sub_0806E7D4(struct ArgE7D4 *arg) spawnE7D4(e2->x, e2->y, player, 15, level); } if (sub_0800CC98() == 0 && sub_0800CD8C() == 0 && sub_0800CCCC() == 0) { +#ifdef REGION_USA + u32 levelFour = 4; +#else +#define levelFour 4 +#endif if (!(flagsE7D4 & 1)) palE7D4(0x17, spr.fC, 2); - if (gUnk_03003170.curLevel == 4 && sub_0800CDC0()) + if (gUnk_03003170.curLevel == levelFour && sub_0800CDC0()) shadeB = 0; +#ifndef REGION_USA +#undef levelFour +#endif if (sub_0800CB9C() != 0) { /* The ROM keeps the parity mask in r1 and the frame flags in r2. */ u32 f = flagsE7D4; @@ -4178,8 +4429,8 @@ void sub_0806E7D4(struct ArgE7D4 *arg) } struct ArgF0CC { u32 player, bit, target, value, f10, level; }; struct SprF0CC { u32 f0, f4, f8, fC; u8 pad10[12]; u8 f1C, f1D; u8 pad1E[22]; }; -struct PlyF0CC { u16 id; u8 pad2[0x1E]; u16 state; u8 pad22[0xE]; u32 flags; u8 pad34[0x2E]; s16 maxhp; u8 pad64[4]; u8 team; u8 pad69[0x13]; u8 f7C[0x10]; s32 x8C, y90; u8 pad94[0x2E]; u16 resource; u16 hp; u8 padC6[0x16]; u32 fDC; u8 padE0[0x68]; u16 *sprite; }; -struct EneF0CC { u16 id; u16 f2; u8 pad4[4]; u16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x40]; u16 hp; u16 resource; u8 pad60[10]; u16 wait; u8 pad6C[0x16A]; s16 maxhp; u8 pad1D8[4]; u8 team; u8 pad1DD[0x3B]; u8 f218[0x13]; u8 threshold; u8 pad22C[0xB4]; }; +struct PlyF0CC { u16 id; u8 pad2[PLAYER_FIELD(0x20) - 0x2]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x62) - PLAYER_FIELD(0x34)]; s16 maxhp; u8 pad64[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x64)]; u8 team; u8 pad69[PLAYER_FIELD(0x7C) - PLAYER_FIELD(0x69)]; u8 f7C[0x10]; s32 x8C, y90; u8 pad94[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0x94)]; u16 resource; u16 hp; u8 padC6[PLAYER_FIELD(0xDC) - PLAYER_FIELD(0xC6)]; u32 fDC; u8 padE0[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xE0)]; u16 *sprite; }; +struct EneF0CC { u16 id; u16 f2; u8 pad4[4]; u16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x40]; u16 hp; u16 resource; u8 pad60[10]; u16 wait; u8 pad6C[0x16A]; s16 maxhp; u8 pad1D8[4]; u8 team; u8 pad1DD[ENEMY_FIELD(0x218) - 0x1DD]; u8 f218[0x13]; u8 threshold; u8 pad22C[ENEMY_SIZE - ENEMY_FIELD(0x22C)]; }; struct OffF0CC { s16 x, y; }; struct PosF0CC { s32 x, y; }; extern struct PlyF0CC pF0CC[] asm("gUnk_03003CE0"); @@ -4276,7 +4527,7 @@ void sub_0806F0CC(struct ArgF0CC *arg) if (player <= 3) { p = &pF0CC[player]; } else { - e = (struct EneF0CC *)(eF0CCBase + (player * 0x2E0 + 0xFFFFF480)); + e = (struct EneF0CC *)(eF0CCBase + (player * ENEMY_SIZE - 4 * ENEMY_SIZE)); while (e->wait < e->threshold) { if (sub_08056E90() != 0 || sub_0800BA6C() == 0 || e->state == 10 || e->state == 11) { fF0CC[player] &= ~(1 << bit); @@ -4326,7 +4577,7 @@ void sub_0806F0CC(struct ArgF0CC *arg) target = 0xFFFF; } else { for (i = 0; i <= 4; i++) { - e2 = (struct EneF0CC *)(eF0CCBase + i * 0x2E0); + e2 = (struct EneF0CC *)(eF0CCBase + i * ENEMY_SIZE); if (!(eF0CCMask & (1 << i))) continue; if (e2->f2 == target) @@ -4375,7 +4626,7 @@ void sub_0806F0CC(struct ArgF0CC *arg) } x += sinF0CC[(s16)angle + 0x40] * 4; y += sinF0CC[(s16)angle] * 4; - initF0CC(&spr, 0x500D0, 8, -1, 0); + initF0CC(&spr, RES_ID(0x500D0), 8, -1, 0); spr.f1C = 7; spr.f1D = 8; frame = 0; @@ -4395,7 +4646,7 @@ void sub_0806F0CC(struct ArgF0CC *arg) for (i = 0; i <= 4; i++) { if (!(eF0CCMask & (1 << i))) continue; - e3 = (struct EneF0CC *)(eF0CCBase + i * 0x2E0); + e3 = (struct EneF0CC *)(eF0CCBase + i * ENEMY_SIZE); if (e3->team == 0) continue; dx = (u32)(e3->x - x) >> 8; @@ -4577,7 +4828,7 @@ void sub_0806F0CC(struct ArgF0CC *arg) p->fDC++; fF0CC[player] &= ~(1 << bit); } -struct T06FE1CPlayer { u8 pad0[0x24]; u16 x24, x26; u8 pad28[0x8e]; u16 wait; u8 padB8[10]; s16 resource; u8 padC4[0x88]; }; +struct T06FE1CPlayer { u8 pad0[PLAYER_FIELD(0x24)]; u16 x24, x26; u8 pad28[PLAYER_FIELD(0xB6) - PLAYER_FIELD(0x28)]; u16 wait; u8 padB8[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB8)]; s16 resource; u8 padC4[PLAYER_SIZE - PLAYER_FIELD(0xC4)]; }; struct T06FE1CArgs { u32 player, bit, f8, value, f10, level; }; extern struct T06FE1CPlayer t06FE1CPlayers[] asm("gUnk_03003CE0"); extern u32 t06FE1CFlags[] asm("gUnk_030063E0"); @@ -4650,8 +4901,8 @@ void t6f_sub_0805865C(s32) asm("sub_0805865C"); s32 t6f_sub_08058DB0() asm("sub_08058DB0"); s32 t6f_sub_0806898C(s32, s32) asm("sub_0806898C"); struct T6fPos { u32 kind : 4; u32 x : 12; u32 y : 12; u32 dir : 4; u32 f4 : 6; }; -struct T6fPl { u16 id; u8 p2[0x20 - 2]; u16 state; u8 p22[0x30 - 0x22]; u32 flags; u8 p34[0x68 - 0x34]; u8 team; u8 p69[0xC2 - 0x69]; u16 hp; u8 pC4[0xDC - 0xC4]; s32 hits; u8 pE0[0x148 - 0xE0]; struct T6fPos *pos; }; -struct T6fEn { u16 id; u16 uid; u8 p4[8 - 4]; s16 dir; u8 pA[0xC - 0xA]; u16 state; u8 pE[0x14 - 0xE]; s32 x; s32 y; u8 p1C[0x50 - 0x1C]; s32 hits; u8 p54[0x5A - 0x54]; u16 hitMask; u8 p5C[0x5E - 0x5C]; u16 mp; u8 p60[0x6A - 0x60]; u16 h6A; u8 p6C[0x1DC - 0x6C]; u8 alive; u8 p1DD[0x22B - 0x1DD]; u8 b22B; u8 p22C[0x2E0 - 0x22C]; }; +struct T6fPl { u16 id; u8 p2[PLAYER_FIELD(0x20) - 0x2]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 team; u8 p69[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0x69)]; u16 hp; u8 pC4[PLAYER_FIELD(0xDC) - PLAYER_FIELD(0xC4)]; s32 hits; u8 pE0[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xE0)]; struct T6fPos *pos; }; +struct T6fEn { u16 id; u16 uid; u8 p4[8 - 4]; s16 dir; u8 pA[0xC - 0xA]; u16 state; u8 pE[0x14 - 0xE]; s32 x; s32 y; u8 p1C[0x50 - 0x1C]; s32 hits; u8 p54[0x5A - 0x54]; u16 hitMask; u8 p5C[0x5E - 0x5C]; u16 mp; u8 p60[0x6A - 0x60]; u16 h6A; u8 p6C[0x1DC - 0x6C]; u8 alive; u8 p1DD[ENEMY_FIELD(0x22B) - 0x1DD]; u8 b22B; u8 p22C[ENEMY_SIZE - ENEMY_FIELD(0x22C)]; }; struct T6fArg { u32 owner; s32 bit; u16 target; u8 pA[2]; s32 kind; u8 p10[4]; s32 level; }; struct T6fDesc { u32 f0; u32 f4; u32 f8; u32 fC; u8 p10[0xC]; u8 f1C; u8 f1D; u8 p1E[0x34 - 0x1E]; }; struct T6fTile { u8 p0[0x8C]; u16 h8C; }; @@ -4693,6 +4944,7 @@ u8 t6fTerrain(s32, s32, s32) asm("sub_0800AE50"); * Target sentinels0xFF/0xFFFF differ across branches; enemy-owner branches use pl pointer uninitialized in C, * and return-origin uses tracked enemy pointer rather than guaranteed owner. */ void sub_0806FF1C(struct T6fArg *arg0) { +#ifdef REGION_USA struct T6fDesc desc; s16 f0, f1; s16 x, y; @@ -4729,7 +4981,7 @@ void sub_0806FF1C(struct T6fArg *arg0) { s16 idx; struct T6fPos *pos; - asm(""); asm(""); asm(""); asm(""); myId = t6f_sub_080020F4(); + asm("");asm("");asm("");asm(""); myId = t6f_sub_080020F4(); bit = arg0->bit; owner = arg0->owner; if (gT6fBusy[owner]) { @@ -4780,7 +5032,7 @@ void sub_0806FF1C(struct T6fArg *arg0) { } if ((myId == owner || owner > 3) && t6f_sub_0800CCCC() == 0 && t6f_sub_0800CD34() == 0) t6f_sub_0805865C(arg0->level + 0x15C); - t6fInit(&desc, 0x500A5, 8, -1, 0); + t6fInit(&desc, RES_ID(0x500A5), 8, -1, 0); switch (base) { case 0: case 1: @@ -4893,14 +5145,14 @@ void sub_0806FF1C(struct T6fArg *arg0) { if (target <= 3) { tp = &gT6fPlayers[target]; } else { - for (i = 0; i <= 4; i++) { - if (gT6fEnemyMask & (1 << i)) { - if (gT6fEnemies[i].uid == target) { - te = &gT6fEnemies[i]; - goto tracked; - } - } + struct T6fEn *e; + i = 0; + while (!(gT6fEnemyMask & (1 << i)) || (e = (struct T6fEn *)({ u8 *m = (u8 *)gT6fEnemies; u32 o = i * ENEMY_SIZE; o + (u32)m; }))->uid != target) { + i++; + if (i > 4) + goto tracked; } + te = e; } tracked: stuck = 0; @@ -4914,7 +5166,7 @@ void sub_0806FF1C(struct T6fArg *arg0) { if (target > 3) { for (i = 0; i <= 4; i++) { if ((1 << i) & gT6fEnemyMask) { - u32 off; register struct T6fEn *e asm("r4"); struct T6fEn **pp = &gT6fEnemies; { register int a asm("r4"); asm("" : "=r"(a)); off = i * sizeof(struct T6fEn); asm("" :: "r"(a)); } { register u32 b asm("r1") = (u32)*pp; e = (struct T6fEn *)(b + off); } + u32 off; register struct T6fEn *e asm("r4"); struct T6fEn **pp = &gT6fEnemies; { register int a asm("r4"); asm("" : "=r"(a)); { register u32 o1 asm("r1") = i; off = o1 * sizeof(struct T6fEn); } asm("" :: "r"(a)); } { register u32 b asm("r0") = (u32)*pp; e = (struct T6fEn *)(b + off); } if (e->alive) { x = (e->x - sx) >> 8; y = (e->y - sy) >> 8; @@ -5008,7 +5260,7 @@ void sub_0806FF1C(struct T6fArg *arg0) { if (target != 0xFFFF && target > 3) { for (i = 0; i <= 4; i++) { if ((1 << i) & gT6fEnemyMask) { - u32 off; register struct T6fEn *e asm("r4"); struct T6fEn **pp = &gT6fEnemies; { register int a asm("r4"); asm("" : "=r"(a)); off = i * sizeof(struct T6fEn); asm("" :: "r"(a)); } { register u32 b asm("r1") = (u32)*pp; e = (struct T6fEn *)(b + off); } + u32 off; register struct T6fEn *e asm("r4"); struct T6fEn **pp = &gT6fEnemies; { register int a asm("r4"); asm("" : "=r"(a)); { register u32 o1 asm("r1") = i; off = o1 * sizeof(struct T6fEn); } asm("" :: "r"(a)); } { register u32 b asm("r0") = (u32)*pp; e = (struct T6fEn *)(b + off); } if (e->alive) { x = (e->x - sx) >> 8; y = (e->y - sy) >> 8; @@ -5165,69 +5417,55 @@ void sub_0806FF1C(struct T6fArg *arg0) { end: gT6fBusy[owner] = 0; gT6fFlags[owner] &= ~(1 << bit); -} -extern u8 gT6gBusy[] asm("gUnk_03006410"); -extern s16 gT6gRadius[] asm("gUnk_084EC1D0"); -extern u16 gT6gDirs[] asm("gUnk_0849E730"); -u16 t6gSeekEn(u16, s32, s32, s32) asm("sub_0807A040"); -void t6gBurst(s32, s32, void *) asm("sub_08068A00"); -s32 t6gSolo(void) asm("sub_0800CB9C"); -s32 t6gAnim(void *, u32, s16 *, s16 *, s32) asm("sub_08065370"); - -struct T6gXY { s32 x, y; }; -/* [RunOrbitingTargetStrikeSprite] Rejects a busy owner by clearing the requested flag; otherwise claims the - * owner busy byte. Waits for enemy readiness with scene/state aborts, applies owner-specific resource cost, - * and initializes a level-selected directional sprite. It follows an offset rotating around its owner until a - * target is found, pursues a target subject to terrain timeout, plays strike animation and dispatches the - * burst helper on completion, then returns and repeats for a finite level-derived count. Abort/normal end - * clears busy and the requested owner flag. */ -void sub_080710DC(struct T6fArg *arg0) { +#else struct T6fDesc desc; s16 f0, f1; s16 x, y; struct T6fEn *te; - struct T6fEn *en; struct T6fPl *pl; + struct T6fEn *en; struct T6fPl *tp; u16 target; u16 base; u16 count; - u16 level; - s32 sx; + u16 hitBase; + u16 dir; + u16 spin; u16 frame; u32 myId; - s32 sy; s32 dd1; s32 dd2; s32 dd3; s32 dd4; s32 dd5; s32 dd6; s32 dd7; s32 dd8; s32 dd9; s32 dd10; s32 dd11; s32 dd12; s32 dd13; s32 dd14; s32 dd15; s32 dd16; - u32 owner; + s32 hitFrame; s32 bit; - u32 timer; - u32 seek; - struct T6gXY c; - u16 dir; - u16 orbit; + u32 stuck; + u32 owner; + s32 sx, sy; u16 i; u32 num; s32 hit; + s32 hit2; u8 pal; u16 a; u8 ang; s32 turn; - s32 dx, dy; - s32 done; + s32 dx; + s32 dy; + u16 done; + u16 fr; u8 t; s16 idx; - s32 so; - struct T6fPl *p; + struct T6fPos *pos; + asm(""); asm(""); asm(""); asm(""); myId = t6f_sub_080020F4(); bit = arg0->bit; - if (gT6gBusy[arg0->owner]) { - gT6fFlags[arg0->owner] &= ~(1 << bit); + owner = arg0->owner; + if (gT6fBusy[owner]) { + gT6fFlags[owner] &= ~(1 << bit); return; } - owner = arg0->owner; - gT6gBusy[owner] = 1; + gT6fBusy[owner] = 1; target = arg0->target; - { u32 lv = *(u16 *)&arg0->level; count = lv; level = lv; base = lv; } - myId = t6f_sub_080020F4(); + { u32 lv = *(u16 *)&arg0->level; count = lv; asm(""); base = lv; } + f0 = 0; + f1 = 0; if (owner <= 3) { pl = &gT6fPlayers[owner]; } else { @@ -5235,21 +5473,19 @@ void sub_080710DC(struct T6fArg *arg0) { while (en->h6A < en->b22B) { if (t6f_sub_08056E90() != 0 || t6f_sub_0800BA6C() == 0 || en->state == 10 || en->state == 11) { gT6fFlags[owner] &= ~(1 << bit); - gT6gBusy[owner] = 0; + gT6fBusy[owner] = 0; return; } t6f_sub_080003F0(); } } - f0 = 0; - f1 = 0; - if (t6f_sub_080020F4() != owner) { + if (myId != owner) { if (owner > 3) { { u8 *cb = (u8 *)gT6fCostS; u32 off = base * 2 + arg0->kind * 24; s16 *cp; s32 v; cb += 6; cp = (s16 *)(off + (u32)cb); v = en->mp - *cp; en->mp = v; } if ((s16)en->mp < 0) { gT6fFlags[owner] &= ~(1 << bit); + gT6fBusy[owner] = 0; en->mp = 0; - gT6gBusy[owner] = 0; return; } } @@ -5260,30 +5496,44 @@ void sub_080710DC(struct T6fArg *arg0) { if ((s16)me->hp < 0) me->hp = 0; } - if (target <= 3) { - num = t6f_sub_08002164(); - for (i = 0; i < num && (t6f_sub_080020F4() == i || (tp = &gT6fPlayers[i])->id != target); i++) - ; - if (i >= num) - target = 0xFFFF; + if (owner <= 3) { + frame = pl->pos->dir; + dir = gT6fDirs[(s16)frame]; } else { - for (i = 0; i <= 4; i++) { - te = &gT6fEnemies[i]; - if ((gT6fEnemyMask & (1 << i)) && te->uid == target) - break; - } - if (i > 4) - target = 0xFFFF; + frame = en->dir; + dir = gT6fDirs[(s16)frame]; } - if (base <= 6) { - t6fInit(&desc, 0x5008F, 8, -1, 0); - base = base - 1; - } else { - t6fInit(&desc, 0x50090, 8, -1, 0); + if ((myId == owner || owner > 3) && t6f_sub_0800CCCC() == 0 && t6f_sub_0800CD34() == 0) + t6f_sub_0805865C(arg0->level + 0x15C); + t6fInit(&desc, 0x500A5, 8, -1, 0); + switch (base) { + case 0: + case 1: + case 2: base = 0; + break; + case 3: + base = 1; + break; + case 4: + base = 2; + break; + case 5: + base = 3; + break; + case 6: + base = 4; + break; + case 7: + base = 5; + break; } + hitBase = base; + count += 2; desc.f1C = 7; desc.f1D = 8; + f0 = 0; + f1 = 0; if (target <= 3) { num = t6f_sub_08002164(); for (i = 0; i < num; i++) { @@ -5302,51 +5552,1003 @@ void sub_080710DC(struct T6fArg *arg0) { if (i > 4) target = 0xFFFF; } - f0 = 0; - f1 = 0; base <<= 3; - count += 4; - if (owner <= 3) { - c.x = pl->pos->x << 8; - c.y = pl->pos->y << 8; - } else { - c = *(struct T6gXY *)&en->x; - } - sx = c.x; - sy = c.y; - timer = 0x3C; - if ((t6f_sub_080020F4() == owner || owner > 3) && t6f_sub_0800CCCC() == 0 && t6f_sub_0800CD34() == 0) - t6f_sub_0805865C(level + 0x139); restart: - orbit = 0x80; - seek = 0; - for (;;) { - if (timer++ > 0x3C) { - u16 r; + { + for (;;) { + if (owner == myId) { + if (t6f_sub_08058DB0() != 0 || t6f_sub_0801DF8C() != 0 || pl->state == 11 || pl->state == 12 || t6f_sub_0800D11C() != 0) + goto end; + } if (owner <= 3) { - c.x = pl->pos->x << 8; - c.y = pl->pos->y << 8; - frame = pl->pos->dir; - dir = gT6gDirs[frame] * 16; - if (seek++ <= 5) - goto orbit; - seek = 0; - if (owner == myId) - r = t6fSeekMe(0x20, 0x64); - else - r = t6fSeekPl(&gT6fPlayers[owner], 0x20, 0x64); - goto store; + sx = pl->pos->x << 8; + sy = pl->pos->y << 8; + if (owner == myId) { + if ((gT6fFrame & 1) == (owner & 1)) { + target = t6fSeekMe(0x20, 0x64); + if (target != 0xFF) + goto found; + } + } else if ((gT6fFrame & 1) == (owner & 1)) { + target = t6fSeekPl(&gT6fPlayers[owner], 0x20, 0x64); + if (target != 0xFF) + goto found; + } } else { - c = *(struct T6gXY *)&en->x; - { u16 *d = gT6gDirs; frame = en->dir; dir = d[en->dir] * 16; } + sx = en->x; + sy = en->y; if (target <= 3) { if (!(gT6fPlayers[target].pos->f4 & 0x20)) goto found; } else { - r = t6gSeekEn(en->id + 4, 0xFF, sx, sy); - store: - target = r; + target = t6fSeekEn(en->id + 4, 0xFF, sx, sy, 100); + if (target != 0xFF) + goto found; + } + } + idx = spin; + sx += gT6fSin[idx + 0x40] * 16; + { s32 dy = gT6fSin[idx] * 8 - 0x800; sy += dy; } + { s32 m = (idx + 8) << 16; spin = (u32)(0xFF0000 & m) >> 16; asm(""::"r"(m)); } + if (!(gT6fCtl->h4 & 4)) { + u8 *p; + t6fAnim(&desc, base, &f0, &f1, 1); + if (t6f_sub_0800CC98() == 0 && t6f_sub_0800CD8C() == 0 && (p = t6f_sub_0800CCCC()) == 0) { + if (!(gT6fFrame & 1)) + t6f_sub_08000AF0(0x17, desc.fC, 2); + t6fCoords((s16)(sx >> 8), (s16)(sy >> 8), &x, &y, 0x30, (s32)p); + pal = t6fPal(sx >> 8, sy >> 8, 0); + if (gT6fTile.h8C == 4 && t6f_sub_0800CDC0() != 0) + pal = 0; + if ((gT6fFrame & 1) == (owner & 1)) + t6fDraw(x, y, base, f0, pal, &desc.f1C, desc.f8, desc.f0); + } + } + t6f_sub_080003F0(); + if (t6f_sub_08056E90() != 0) + goto end; + if (owner <= 3 && (gT6fPlayers[owner].flags & 2)) + goto end; + if (pl->pos->kind == 0xC || t6f_sub_08058DB0() != 0 || (gT6fPlayers[owner].flags & 0x2400) || t6f_sub_0800CF10() != 0 || t6f_sub_0800D11C() != 0) + goto end; + } + + found: + if (target <= 3) { + tp = &gT6fPlayers[target]; + } else { + for (i = 0; i <= 4; i++) { + if (gT6fEnemyMask & (1 << i)) { + if (gT6fEnemies[i].uid == target) { + te = &gT6fEnemies[i]; + goto tracked; + } + } + } + } + tracked: + stuck = 0; + for (;;) { + if (owner == myId) { + if (t6f_sub_08058DB0() != 0 || t6f_sub_0801DF8C() != 0 || pl->state == 11 || pl->state == 12 || t6f_sub_0800D11C() != 0) + goto end; + } + hit = 0; + if (target != 0xFF) { + if (target > 3) { + for (i = 0; i <= 4; i++) { + if ((1 << i) & gT6fEnemyMask) { + u32 off; register struct T6fEn *e asm("r4"); struct T6fEn **pp = &gT6fEnemies; { register int a asm("r4"); asm("" : "=r"(a)); off = i * sizeof(struct T6fEn); asm("" :: "r"(a)); } { register u32 b asm("r1") = (u32)*pp; e = (struct T6fEn *)(b + off); } + if (e->alive) { + x = (e->x - sx) >> 8; + y = (e->y - sy) >> 8; + dx = x; + if (dx < 0) dx = -dx; + if (dx <= 7) { + dy = y; + if (dy < 0) dy = -dy; + if (dy <= 7) + hit = 1; + } + } + } + } + } + } + if (target != 0xFF) { + if (hit) + goto strike; + if (target <= 3 && tp->team != pl->team && tp->pos->kind != 0xE && tp->team != 0) { + x = tp->pos->x - (sx >> 8); + y = tp->pos->y - (sy >> 8); + dx = x; + if (dx < 0) dx = -dx; + if (dx <= 15) { + dy = y; + if (dy < 0) dy = -dy; + if (dy <= 15) + hit = 1; + } + } + } + if (hit) + goto strike; + if (t6f_sub_08056E90() != 0) + goto end; + if (owner <= 3 && (gT6fPlayers[owner].flags & 2)) + goto end; + if (pl->pos->kind == 0xC || t6f_sub_08058DB0() != 0 || (gT6fPlayers[owner].flags & 0x2400) || t6f_sub_0800CF10() != 0 || t6f_sub_0800D11C() != 0) + goto end; + if (target <= 3) { + x = tp->pos->x - (sx >> 8); + y = tp->pos->y - (sy >> 8); + } else { + x = (te->x - sx) >> 8; + y = (te->y - sy) >> 8; + } + if (t6fSqrt(x * x + y * y) <= 7) + goto strike; + a = (u32)(ArcTan2(x, y) << 16) >> 24; + ang = a; + turn = ang - (s16)dir; + if (turn > 0x80) + a = ang - 0x100; + else if (turn < -0x80) + a = ang | 0x100; + { s16 sa = a; s16 sd = dir; s16 dd = sa - sd; dir = sd + dd; } + { s16 t2 = dir; if (t2 < 0) dir = t2 + 0x100; } + { s16 t2 = dir; if (t2 > 0x100) dir = t2 - 0x100; } + dir &= 0xFF; + idx = dir; + frame = gT6fFrames[idx >> 4]; + t = t6fTerrain(sx, sy, 0); + if (!(t & 0xF) || (t & 0x10)) { + sx += gT6fSin[idx + 0x40] * 3; + sy += gT6fSin[idx] * 3; + } else if (stuck++ > 0x78) { + goto lost; + } + t6fCoords((s16)(sx >> 8), (s16)(sy >> 8), &x, &y, 0x30, 0); + pal = t6fPal(sx >> 8, sy >> 8, 0); + t6fAnim(&desc, (u16)(base + gT6fFrames[(s16)dir >> 4]), &f0, &f1, 1); + if (!(gT6fCtl->h4 & 4) && t6f_sub_0800CC98() == 0 && t6f_sub_0800CD8C() == 0 && t6f_sub_0800CCCC() == 0) { + if (!(gT6fFrame & 1)) + t6f_sub_08000AF0(0x17, desc.fC, 2); + if (gT6fTile.h8C == 4 && t6f_sub_0800CDC0() != 0) + pal = 0; + if ((gT6fFrame & 1) == (owner & 1)) + t6fDraw(x, y, (u16)(base + frame), f0, pal, &desc.f1C, desc.f8, desc.f0); + } + t6f_sub_080003F0(); + } + + strike: + if ((s16)frame <= 3) + hitFrame = 0x3F; + else + hitFrame = 0x46; + for (;;) { + hit2 = 0; + if (target != 0xFFFF && target > 3) { + for (i = 0; i <= 4; i++) { + if ((1 << i) & gT6fEnemyMask) { + u32 off; register struct T6fEn *e asm("r4"); struct T6fEn **pp = &gT6fEnemies; { register int a asm("r4"); asm("" : "=r"(a)); off = i * sizeof(struct T6fEn); asm("" :: "r"(a)); } { register u32 b asm("r1") = (u32)*pp; e = (struct T6fEn *)(b + off); } + if (e->alive) { + x = (e->x - sx) >> 8; + y = (e->y - sy) >> 8; + dx = x; + if (dx < 0) dx = -dx; + if (dx <= 0x1F) { + dy = y; + if (dy < 0) dy = -dy; + if (dy <= 0x1F) + hit2 = 1; + } + } + } + } + } + if (target != 0xFF && !hit2) { + if (target <= 3 && tp->team != pl->team && tp->pos->kind != 0xE && tp->team != 0) { + x = tp->pos->x - (sx >> 8); + y = tp->pos->y - (sy >> 8); + dx = x; + if (dx < 0) dx = -dx; + if (dx <= 15) { + dy = y; + if (dy < 0) dy = -dy; + if (dy <= 15) + hit2 = 1; + } + } + } + if (!hit2) + goto lost; + t6fCoords((s16)(sx >> 8), (s16)(sy >> 8), &x, &y, 0x30, 0); + pal = t6fPal(sx >> 8, sy >> 8, 0); + done = t6fAnim(&desc, (u16)(hitBase + hitFrame), &f0, &f1, 0); + if (!(gT6fCtl->h4 & 4) && t6f_sub_0800CC98() == 0 && t6f_sub_0800CD8C() == 0 && t6f_sub_0800CCCC() == 0) { + if (!(gT6fFrame & 1)) + t6f_sub_08000AF0(0x17, desc.fC, 2); + if (gT6fTile.h8C == 4 && t6f_sub_0800CDC0() != 0) + pal = 0; + if ((gT6fFrame & 1) == (owner & 1)) + t6fDraw(x, y, (u16)(hitBase + hitFrame), f0, 0, &desc.f1C, desc.f8, desc.f0); + } + t6f_sub_080003F0(); + if (t6f_sub_08056E90() != 0) + goto end; + if (owner <= 3 && (gT6fPlayers[owner].flags & 2)) + goto end; + if (pl->pos->kind == 0xC || t6f_sub_08058DB0() != 0 || (gT6fPlayers[owner].flags & 0x2400) || t6f_sub_0800CF10() != 0 || t6f_sub_0800D11C() != 0) + goto end; + if (done) { + if (target <= 3) { + if (target == myId) + t6fPlHit(gT6fKinds[0xCD], t6fCalc(arg0, 0), base); + } else if (owner == myId) { + t6fEnHit(te->id, gT6fKinds[0xCD], t6fCalc(arg0, 0), base, 0, 0); + te->hitMask |= 1 << owner; + } + if (owner <= 3) + pl->hits++; + else + en->hits++; + } + if ((target <= 3 ? tp->pos->kind : te->state) == 0xB) + goto lost; + if (done) { + count--; + f1 = 0; + f0 = 0; + if (count != 0) + goto lost; + goto end; + } + } + lost: + if (count == 0) + goto end; + relaunch: + if ((myId == owner || owner > 3) && t6f_sub_0800CCCC() == 0 && t6f_sub_0800CD34() == 0) + t6f_sub_0805865C(arg0->level + 0x15C); + for (;;) { + if (owner == myId) { + if (t6f_sub_08058DB0() != 0 || t6f_sub_0801DF8C() != 0 || pl->state == 11 || pl->state == 12 || t6f_sub_0800D11C() != 0) + goto end; + } + if (!(gT6fCtl->h4 & 4)) { + u8 *p; + t6fAnim(&desc, (u16)(base + frame), &f0, &f1, 1); + if (t6f_sub_0800CC98() == 0 && t6f_sub_0800CD8C() == 0 && (p = t6f_sub_0800CCCC()) == 0) { + if (!(gT6fFrame & 1)) + t6f_sub_08000AF0(0x17, desc.fC, 2); + t6fCoords((s16)(sx >> 8), (s16)(sy >> 8), &x, &y, 0x30, (s32)p); + pal = t6fPal(sx >> 8, sy >> 8, 0); + if (gT6fTile.h8C == 4 && t6f_sub_0800CDC0() != 0) + pal = 0; + if ((gT6fFrame & 1) == (owner & 1)) + t6fDraw(x, y, (u16)(base + frame), f0, pal, &desc.f1C, desc.f8, desc.f0); + } + } + if (owner <= 3) { + if (owner == myId) { + pos = pl->pos; + x = pos->x - (sx >> 8); + y = pos->y - (sy >> 8); + } else { + pos = gT6fPlayers[owner].pos; + x = pos->x - (sx >> 8); + y = pos->y - (sy >> 8); + } + } else { + x = (te->x - sx) >> 8; + y = (te->y - sy) >> 8; + } + t6f_sub_080003F0(); + if (t6fSqrt(x * x + y * y) <= 7) + goto home; + a = (u32)(ArcTan2(x, y) << 16) >> 24; + ang = a; + turn = ang - (s16)dir; + if (turn > 0x80) + a = ang - 0x100; + else if (turn < -0x80) + a = ang | 0x100; + { s16 sa = a; s16 sd = dir; s16 dd = sa - sd; dir = sd + dd; } + { s16 t2 = dir; if (t2 < 0) dir = t2 + 0x100; } + { s16 t2 = dir; if (t2 > 0x100) dir = t2 - 0x100; } + dir &= 0xFF; + idx = dir; + frame = gT6fFrames[idx >> 4]; + sx += gT6fSin[idx + 0x40] * 3; + sy += gT6fSin[idx] * 3; + if (t6f_sub_08056E90() != 0) + goto end; + if (owner <= 3 && (gT6fPlayers[owner].flags & 2)) + goto end; + if (pl->pos->kind == 0xC || t6f_sub_08058DB0() != 0 || (gT6fPlayers[owner].flags & 0x2400) || t6f_sub_0800CF10() != 0 || t6f_sub_0800D11C() != 0) + goto end; + } + home: + if (owner <= 3) { + if (owner == myId) { + x = (sx >> 8) - pl->pos->x; + y = (sy >> 8) - pl->pos->y; + } else { + x = (sx >> 8) - gT6fPlayers[owner].pos->x; + y = (sy >> 8) - gT6fPlayers[owner].pos->y; + } + } else { + x = (sx - te->x) >> 8; + y = (sy - te->y) >> 8; + } + spin = (u32)(ArcTan2(x, y) << 16) >> 24; + goto restart; + } +end: + gT6fBusy[owner] = 0; + gT6fFlags[owner] &= ~(1 << bit); +#endif +} +extern u8 gT6gBusy[] asm("gUnk_03006410"); +extern s16 gT6gRadius[] asm("gUnk_084EC1D0"); +extern u16 gT6gDirs[] asm("gUnk_0849E730"); +u16 t6gSeekEn(u16, s32, s32, s32) asm("sub_0807A040"); +void t6gBurst(s32, s32, void *) asm("sub_08068A00"); +s32 t6gSolo(void) asm("sub_0800CB9C"); +s32 t6gAnim(void *, u32, s16 *, s16 *, s32) asm("sub_08065370"); + +struct T6gXY { s32 x, y; }; +/* [RunOrbitingTargetStrikeSprite] Rejects a busy owner by clearing the requested flag; otherwise claims the + * owner busy byte. Waits for enemy readiness with scene/state aborts, applies owner-specific resource cost, + * and initializes a level-selected directional sprite. It follows an offset rotating around its owner until a + * target is found, pursues a target subject to terrain timeout, plays strike animation and dispatches the + * burst helper on completion, then returns and repeats for a finite level-derived count. Abort/normal end + * clears busy and the requested owner flag. */ +void sub_080710DC(struct T6fArg *arg0) { +#ifdef REGION_USA + struct T6fDesc desc; + s16 f0, f1; + s16 x, y; + struct T6fEn *te; + struct T6fEn *en; + struct T6fPl *pl; + struct T6fPl *tp; + u16 target; + u16 base; + u16 count; + u16 level; + s32 sx; + u16 frame; + u32 myId; + s32 sy; s32 dd1; s32 dd2; s32 dd3; s32 dd4; s32 dd5; s32 dd6; s32 dd7; s32 dd8; s32 dd9; s32 dd10; s32 dd11; s32 dd12; s32 dd13; s32 dd14; s32 dd15; s32 dd16; + u32 owner; + s32 bit; + u32 timer; + u32 seek; + struct T6gXY c; + u16 dir; + u16 orbit; + u16 i; + u32 num; + s32 hit; + u8 pal; + u16 a; + u8 ang; + s32 turn; + s32 dx, dy; + s32 done; + u8 t; + s16 idx; + s32 so; + struct T6fPl *p; + + bit = arg0->bit; + if (gT6gBusy[arg0->owner]) { + gT6fFlags[arg0->owner] &= ~(1 << bit); + return; + } + owner = arg0->owner; + gT6gBusy[owner] = 1; + target = arg0->target; + { u32 lv = *(u16 *)&arg0->level; count = lv; level = lv; base = lv; } + myId = t6f_sub_080020F4(); + if (owner <= 3) { + pl = &gT6fPlayers[owner]; + } else { + en = &gT6fEnemies[owner - 4]; + while (en->h6A < en->b22B) { + if (t6f_sub_08056E90() != 0 || t6f_sub_0800BA6C() == 0 || en->state == 10 || en->state == 11) { + gT6fFlags[owner] &= ~(1 << bit); + gT6gBusy[owner] = 0; + return; + } + t6f_sub_080003F0(); + } + } + f0 = 0; + f1 = 0; + if (t6f_sub_080020F4() != owner) { + if (owner > 3) { + { u8 *cb = (u8 *)gT6fCostS; u32 off = base * 2 + arg0->kind * 24; s16 *cp; s32 v; cb += 6; cp = (s16 *)(off + (u32)cb); v = en->mp - *cp; en->mp = v; } + if ((s16)en->mp < 0) { + gT6fFlags[owner] &= ~(1 << bit); + en->mp = 0; + gT6gBusy[owner] = 0; + return; + } + } + } else { + struct T6fPl *me = &gT6fPlayers[t6f_sub_080020F4()]; + u32 power = (u16)(t6f_sub_0806898C(arg0->kind, arg0->level) - 1); + me->hp -= power; + if ((s16)me->hp < 0) + me->hp = 0; + } + if (target <= 3) { + num = t6f_sub_08002164(); + for (i = 0; i < num && (t6f_sub_080020F4() == i || (tp = &gT6fPlayers[i])->id != target); i++) + ; + if (i >= num) + target = 0xFFFF; + } else { + for (i = 0; i <= 4; i++) { + te = &gT6fEnemies[i]; + if ((gT6fEnemyMask & (1 << i)) && te->uid == target) + break; + } + if (i > 4) + target = 0xFFFF; + } + if (base <= 6) { + t6fInit(&desc, RES_ID(0x5008F), 8, -1, 0); + base = base - 1; + } else { + t6fInit(&desc, RES_ID(0x50090), 8, -1, 0); + base = 0; + } + desc.f1C = 7; + desc.f1D = 8; + if (target <= 3) { + num = t6f_sub_08002164(); + for (i = 0; i < num; i++) { + tp = &gT6fPlayers[i]; + if (tp->id == target) + break; + } + if (i >= num) + target = 0xFFFF; + } else { + for (i = 0; i <= 4; i++) { + te = &gT6fEnemies[i]; + if ((gT6fEnemyMask & (1 << i)) && te->uid == target) + break; + } + if (i > 4) + target = 0xFFFF; + } + f0 = 0; + f1 = 0; + base <<= 3; + count += 4; + if (owner <= 3) { + c.x = pl->pos->x << 8; + c.y = pl->pos->y << 8; + } else { + c = *(struct T6gXY *)&en->x; + } + sx = c.x; + sy = c.y; + asm("" : : "r"(sy)); + timer = 0x3C; + if ((t6f_sub_080020F4() == owner || owner > 3) && t6f_sub_0800CCCC() == 0 && t6f_sub_0800CD34() == 0) + t6f_sub_0805865C(level + 0x139); + +restart: + orbit = 0x80; + seek = 0; + for (;;) { + if (timer++ > 0x3C) { + u16 r; + if (owner <= 3) { + c.x = pl->pos->x << 8; + c.y = pl->pos->y << 8; + frame = pl->pos->dir; + dir = gT6gDirs[frame] * 16; + if (seek++ <= 5) + goto orbit; + seek = 0; + if (owner == myId) + r = t6fSeekMe(0x20, 0x64); + else + r = t6fSeekPl(&gT6fPlayers[owner], 0x20, 0x64); + goto store; + } else { + c = *(struct T6gXY *)&en->x; + { u16 *d = gT6gDirs; frame = en->dir; dir = d[en->dir] * 16; } + if (target <= 3) { + if (!(gT6fPlayers[target].pos->f4 & 0x20)) + goto found; + } else { + r = t6gSeekEn(en->id + 4, 0xFF, sx, sy); + store: + target = r; + if (target != 0xFF) + goto found; + } + } + } + orbit: + { s32 sd = (s16)dir; s32 o2 = orbit << 16; dir = sd + (o2 >> 16); } + { s16 t2 = dir; if (t2 > 0xFF) dir = t2 - 0x100; } + { s16 t2 = dir; if (t2 < 0) dir = t2 + 0x100; } + idx = dir; + c.x += gT6fSin[idx + 0x40] * gT6gRadius[level]; + c.y += gT6fSin[idx] * gT6gRadius[level]; + x = (u32)(c.x - sx) >> 8; + y = (u32)((c.y - sy) << 8) >> 16; + { u8 ang1; s32 turn1; a = (u32)(ArcTan2(x, y) << 16) >> 24; + ang1 = a; + turn1 = ang1 - idx; + if (turn1 > 0x80) + a = ang1 - 0x100; + else if (turn1 < -0x80) + { a = ang1; a |= 0x100; } } + { s16 sa = a; s16 sd = dir; s16 dd = sa - sd; dir = sd + dd; } + { s16 t2 = dir; if (t2 < 0) dir = t2 + 0x100; } + { s16 t2 = dir; if (t2 > 0x100) dir = t2 - 0x100; } + dir &= 0xFF; + idx = dir; + frame = gT6fFrames[idx >> 4]; + if (t6fSqrt(x * x + y * y) > 8) { + sx += gT6fSin[idx + 0x40] * 8 / 10; + sy += gT6fSin[idx] * 8 / 10; + } + orbit = (u32)((orbit << 16) + 0x40000) >> 16; + orbit &= 0xFF; + if (!(gT6fCtl->h4 & 4)) { + u8 *q; + t6fAnim(&desc, (u16)(base + frame), &f0, &f1, 1); + if (t6f_sub_0800CC98() == 0 && t6f_sub_0800CD8C() == 0 && (q = t6f_sub_0800CCCC()) == 0) { + if (!(gT6fFrame & 1)) + t6f_sub_08000AF0(0x17, desc.fC, 2); + t6fCoords((s16)(sx >> 8), (s16)(sy >> 8), &x, &y, 0x30, (s32)q); + pal = t6fPal(sx >> 8, sy >> 8, 0); + if (gT6fTile.h8C == 4 && t6f_sub_0800CDC0() != 0) + pal = 0; + if (t6gSolo() != 0) { + if ((gT6fFrame & 1) == (owner & 1)) + t6fDraw(x, y, (u16)(base + frame), f0, pal, &desc.f1C, desc.f8, desc.f0); + } else { + t6fDraw(x, y, (u16)(base + frame), f0, pal, &desc.f1C, desc.f8, desc.f0); + } + } + } + t6f_sub_080003F0(); + if (owner == myId) { + if (t6f_sub_08058DB0() != 0 || t6f_sub_0801DF8C() != 0 || pl->state == 11 || t6f_sub_0800D11C() != 0) + goto end; + } + if (t6f_sub_08056E90() != 0) + goto end; + if (owner <= 3 && (gT6fPlayers[owner].flags & 2)) + goto end; + if (t6f_sub_0800D11C() != 0 || pl->pos->kind == 0xC || t6f_sub_08058DB0() != 0 || (gT6fPlayers[owner].flags & 0x2400) || t6f_sub_0800CF10() != 0) + goto end; + } + +found: + if (target <= 3) { + tp = &gT6fPlayers[target]; + } else { + struct T6fEn *e; + i = 0; + if (!(gT6fEnemyMask & (1 << i))) + goto nextEn; + e = &gT6fEnemies[i]; + goto chkEn; + nextEn: + i++; + if (i > 4) + goto tracked; + if (!(gT6fEnemyMask & (1 << i))) + goto nextEn; + e = (struct T6fEn *)({ u8 *m = (u8 *)gT6fEnemies; u32 o = i * ENEMY_SIZE; o + (u32)m; }); + chkEn: + if (e->uid != target) + goto nextEn; + te = e; + } +tracked: + timer = 0; + for (;;) { + if (owner == myId) { + if (t6f_sub_08058DB0() != 0 || t6f_sub_0801DF8C() != 0 || pl->state == 11 || t6f_sub_0800D11C() != 0) + goto end; + } + hit = 0; + if (target == 0xFFFF) + goto check; + if (target > 3) { + for (i = 0; i <= 4; i++) { + if ((1 << i) & gT6fEnemyMask) { + struct T6fEn *e = &gT6fEnemies[i]; + if (e->alive) { + x = (e->x - sx) >> 8; + y = (e->y - sy) >> 8; + dx = x; + if (dx < 0) dx = -dx; + if (dx <= 7) { + dy = y; + if (dy < 0) dy = -dy; + if (dy <= 7) + hit = 1; + } + } + } + } + } + if (target == 0xFFFF) + goto check; + if (hit) + goto strike; + num = t6f_sub_08002164(); + if (arg0->owner <= 3) { + for (i = 0; i < num; i++) { + p = &gT6fPlayers[i]; + if (p->team != pl->team && p->pos->kind != 0xE && p->team != 0) { + x = p->pos->x - (sx >> 8); + y = p->pos->y - (sy >> 8); + dx = x; + if (dx < 0) dx = -dx; + if (dx <= 0xB) { + dy = y; + if (dy < 0) dy = -dy; + if (dy <= 0xB) + hit = 1; + } + } + } + } else { + for (i = 0; i < num; i++) { + p = &gT6fPlayers[i]; + if (!(p->flags & 0x2000) && p->pos->kind != 0xE && p->team != 0) { + x = p->pos->x - (sx >> 8); + y = p->pos->y - (sy >> 8); + dx = x; + if (dx < 0) dx = -dx; + if (dx <= 0xB) { + dy = y; + if (dy < 0) dy = -dy; + if (dy <= 0xB) + hit = 1; + } + } + } + } + check: + if (hit) + goto strike; + if (t6f_sub_08056E90() != 0 && owner <= 3 && (gT6fPlayers[owner].flags & 2)) + goto end; + if (t6f_sub_0800D11C() != 0 || pl->pos->kind == 0xC || t6f_sub_08058DB0() != 0 || (gT6fPlayers[owner].flags & 0x2400) || t6f_sub_0800CF10() != 0) + goto end; + if (target <= 3) { + x = tp->pos->x - (sx >> 8); + y = tp->pos->y - (sy >> 8); + } else { + x = (te->x - sx) >> 8; + y = (te->y - sy) >> 8; + } + if (t6fSqrt(x * x + y * y) <= 7) + goto strike; + a = (u32)(ArcTan2(x, y) << 16) >> 24; + ang = a; + turn = ang - (s16)dir; + if (turn > 0x80) + a = ang - 0x100; + else if (turn < -0x80) + a = ang | 0x100; + { s16 sa = a; s16 sd = dir; s16 dd = sa - sd; dir = sd + dd; } + { s16 t2 = dir; if (t2 < 0) dir = t2 + 0x100; } + { s16 t2 = dir; if (t2 > 0x100) dir = t2 - 0x100; } + { register s32 m asm("r1") = dir << 16; dir = (u32)(0xFF0000 & m) >> 16; } + idx = dir; + frame = gT6fFrames[idx >> 4]; + t = t6fTerrain(sx, sy, 0); + if (!(t & 0xF) || (t & 0x10)) { + sx += gT6fSin[idx + 0x40] * 3; + sy += gT6fSin[idx] * 3; + timer = 0; + } else if (timer++ > 0x78) { + { register u32 z asm("r3") = 0; asm("" : "+r"(z)); timer = z; } + goto lost; + } + t6fCoords((s16)(sx >> 8), (s16)(sy >> 8), &x, &y, 0x30, 0); + pal = t6fPal(sx >> 8, sy >> 8, 0); + t6fAnim(&desc, (u16)(base + frame), &f0, &f1, 1); + if (!(gT6fCtl->h4 & 4) && t6f_sub_0800CC98() == 0 && t6f_sub_0800CD8C() == 0 && t6f_sub_0800CCCC() == 0) { + if (!(gT6fFrame & 1)) + t6f_sub_08000AF0(0x17, desc.fC, 2); + if (gT6fTile.h8C == 4 && t6f_sub_0800CDC0() != 0) + pal = 0; + if (t6gSolo() != 0) { + if ((gT6fFrame & 1) == (owner & 1)) + t6fDraw(x, y, (u16)(base + frame), f0, pal, &desc.f1C, desc.f8, desc.f0); + } else { + t6fDraw(x, y, (u16)(base + frame), f0, pal, &desc.f1C, desc.f8, desc.f0); + } + } + t6f_sub_080003F0(); + } + +strike: + for (;;) { + t6fCoords((s16)(sx >> 8), (s16)(sy >> 8), &x, &y, 0x30, 0); + pal = t6fPal(sx >> 8, sy >> 8, 0); + done = t6gAnim(&desc, (u16)(base + frame), &f0, &f1, 0); + asm(""::"r"((u32)(base + frame) << 16)); + if (!(gT6fCtl->h4 & 4) && t6f_sub_0800CC98() == 0 && t6f_sub_0800CD8C() == 0 && t6f_sub_0800CCCC() == 0) { + if (!(gT6fFrame & 1)) + t6f_sub_08000AF0(0x17, desc.fC, 2); + if (gT6fTile.h8C == 4 && t6f_sub_0800CDC0() != 0) + pal = 0; + if (t6gSolo() != 0) { + if ((gT6fFrame & 1) == (owner & 1)) + t6fDraw(x, y, (u16)(base + frame), f0, pal, &desc.f1C, desc.f8, desc.f0); + } else { + t6fDraw(x, y, (u16)(base + frame), f0, pal, &desc.f1C, desc.f8, desc.f0); + } + } + t6f_sub_080003F0(); + if (t6f_sub_08056E90() != 0) + goto end; + if (owner <= 3 && (gT6fPlayers[owner].flags & 2)) + goto end; + if (t6f_sub_0800D11C() != 0 || pl->pos->kind == 0xC || t6f_sub_08058DB0() != 0 || (gT6fPlayers[owner].flags & 0x2400) || t6f_sub_0800CF10() != 0) + goto end; + if (done) { + t6gBurst(sx, sy, arg0); + if (owner <= 3) + pl->hits++; + else + en->hits++; + } + if ((target <= 3 ? tp->pos->kind : te->state) == 0xB) + goto lost; + if (done) { + count--; + f1 = 0; + f0 = 0; + goto lost; + } + } + +lost: + if (count == 0) + goto end; + for (;;) { + if (owner <= 3) { + x = pl->pos->x - (sx >> 8); + y = pl->pos->y - (sy >> 8); + } else { + x = (te->x - sx) >> 8; + y = (te->y - sy) >> 8; + } + if (t6fSqrt(x * x + y * y) <= 7) + goto restart; + a = (u32)(ArcTan2(x, y) << 16) >> 24; + ang = a; + turn = ang - (s16)dir; + if (turn > 0x80) + a = ang - 0x100; + else if (turn < -0x80) + a = ang | 0x100; + { s16 sa = a; s16 sd = dir; s16 dd = sa - sd; dir = sd + dd; } + { s16 t2 = dir; if (t2 < 0) dir = t2 + 0x100; } + { s16 t2 = dir; if (t2 > 0x100) dir = t2 - 0x100; } + { register s32 m asm("r1") = dir << 16; dir = (u32)(0xFF0000 & m) >> 16; } + idx = dir; + frame = gT6fFrames[idx >> 4]; + sx += gT6fSin[idx + 0x40] * 3; + sy += gT6fSin[idx] * 3; + if (!(gT6fCtl->h4 & 4)) { + u8 *q; + t6fAnim(&desc, (u16)(base + frame), &f0, &f1, 1); + if (t6f_sub_0800CC98() == 0 && t6f_sub_0800CD8C() == 0 && (q = t6f_sub_0800CCCC()) == 0) { + if (!(gT6fFrame & 1)) + t6f_sub_08000AF0(0x17, desc.fC, 2); + t6fCoords((s16)(sx >> 8), (s16)(sy >> 8), &x, &y, 0x30, (s32)q); + pal = t6fPal(sx >> 8, sy >> 8, 0); + if (gT6fTile.h8C == 4 && t6f_sub_0800CDC0() != 0) + pal = 0; + if (t6gSolo() != 0) { + if ((gT6fFrame & 1) == (owner & 1)) + t6fDraw(x, y, (u16)(base + frame), f0, pal, &desc.f1C, desc.f8, desc.f0); + } else { + t6fDraw(x, y, (u16)(base + frame), f0, pal, &desc.f1C, desc.f8, desc.f0); + } + } + } + t6f_sub_080003F0(); + if (t6f_sub_08056E90() != 0) + goto end; + if (owner <= 3 && (gT6fPlayers[owner].flags & 2)) + goto end; + if (t6f_sub_0800D11C() != 0 || pl->pos->kind == 0xC || t6f_sub_08058DB0() != 0 || (gT6fPlayers[owner].flags & 0x2400) || t6f_sub_0800CF10() != 0) + goto end; + } +end: + gT6gBusy[owner] = 0; + gT6fFlags[owner] &= ~(1 << bit); +#else + struct T6fDesc desc; + s16 f0, f1; + s16 x, y; + struct T6fEn *te; + struct T6fEn *en; + struct T6fPl *pl; + struct T6fPl *tp; + u16 target; + u16 base; + u16 count; + u16 level; + s32 sx; + u16 frame; + u32 myId; + s32 sy; s32 dd1; s32 dd2; s32 dd3; s32 dd4; s32 dd5; s32 dd6; s32 dd7; s32 dd8; s32 dd9; s32 dd10; s32 dd11; s32 dd12; s32 dd13; s32 dd14; s32 dd15; s32 dd16; + u32 owner; + s32 bit; + u32 timer; + u32 seek; + struct T6gXY c; + u16 dir; + u16 orbit; + u16 i; + u32 num; + s32 hit; + u8 pal; + u16 a; + u8 ang; + s32 turn; + s32 dx, dy; + s32 done; + u8 t; + s16 idx; + s32 so; + struct T6fPl *p; + + bit = arg0->bit; + if (gT6gBusy[arg0->owner]) { + gT6fFlags[arg0->owner] &= ~(1 << bit); + return; + } + owner = arg0->owner; + gT6gBusy[owner] = 1; + target = arg0->target; + { u32 lv = *(u16 *)&arg0->level; count = lv; level = lv; base = lv; } + myId = t6f_sub_080020F4(); + if (owner <= 3) { + pl = &gT6fPlayers[owner]; + } else { + en = &gT6fEnemies[owner - 4]; + while (en->h6A < en->b22B) { + if (t6f_sub_08056E90() != 0 || t6f_sub_0800BA6C() == 0 || en->state == 10 || en->state == 11) { + gT6fFlags[owner] &= ~(1 << bit); + gT6gBusy[owner] = 0; + return; + } + t6f_sub_080003F0(); + } + } + f0 = 0; + f1 = 0; + if (t6f_sub_080020F4() != owner) { + if (owner > 3) { + { u8 *cb = (u8 *)gT6fCostS; u32 off = base * 2 + arg0->kind * 24; s16 *cp; s32 v; cb += 6; cp = (s16 *)(off + (u32)cb); v = en->mp - *cp; en->mp = v; } + if ((s16)en->mp < 0) { + gT6fFlags[owner] &= ~(1 << bit); + en->mp = 0; + gT6gBusy[owner] = 0; + return; + } + } + } else { + struct T6fPl *me = &gT6fPlayers[t6f_sub_080020F4()]; + u32 power = (u16)(t6f_sub_0806898C(arg0->kind, arg0->level) - 1); + me->hp -= power; + if ((s16)me->hp < 0) + me->hp = 0; + } + if (target <= 3) { + num = t6f_sub_08002164(); + for (i = 0; i < num && (t6f_sub_080020F4() == i || (tp = &gT6fPlayers[i])->id != target); i++) + ; + if (i >= num) + target = 0xFFFF; + } else { + for (i = 0; i <= 4; i++) { + te = &gT6fEnemies[i]; + if ((gT6fEnemyMask & (1 << i)) && te->uid == target) + break; + } + if (i > 4) + target = 0xFFFF; + } + if (base <= 6) { + t6fInit(&desc, 0x5008F, 8, -1, 0); + base = base - 1; + } else { + t6fInit(&desc, 0x50090, 8, -1, 0); + base = 0; + } + desc.f1C = 7; + desc.f1D = 8; + if (target <= 3) { + num = t6f_sub_08002164(); + for (i = 0; i < num; i++) { + tp = &gT6fPlayers[i]; + if (tp->id == target) + break; + } + if (i >= num) + target = 0xFFFF; + } else { + for (i = 0; i <= 4; i++) { + te = &gT6fEnemies[i]; + if ((gT6fEnemyMask & (1 << i)) && te->uid == target) + break; + } + if (i > 4) + target = 0xFFFF; + } + f0 = 0; + f1 = 0; + base <<= 3; + count += 4; + if (owner <= 3) { + c.x = pl->pos->x << 8; + c.y = pl->pos->y << 8; + } else { + c = *(struct T6gXY *)&en->x; + } + sx = c.x; + sy = c.y; + timer = 0x3C; + if ((t6f_sub_080020F4() == owner || owner > 3) && t6f_sub_0800CCCC() == 0 && t6f_sub_0800CD34() == 0) + t6f_sub_0805865C(level + 0x139); + +restart: + orbit = 0x80; + seek = 0; + for (;;) { + if (timer++ > 0x3C) { + u16 r; + if (owner <= 3) { + c.x = pl->pos->x << 8; + c.y = pl->pos->y << 8; + frame = pl->pos->dir; + dir = gT6gDirs[frame] * 16; + if (seek++ <= 5) + goto orbit; + seek = 0; + if (owner == myId) + r = t6fSeekMe(0x20, 0x64); + else + r = t6fSeekPl(&gT6fPlayers[owner], 0x20, 0x64); + goto store; + } else { + c = *(struct T6gXY *)&en->x; + { u16 *d = gT6gDirs; frame = en->dir; dir = d[en->dir] * 16; } + if (target <= 3) { + if (!(gT6fPlayers[target].pos->f4 & 0x20)) + goto found; + } else { + r = t6gSeekEn(en->id + 4, 0xFF, sx, sy); + store: + target = r; if (target != 0xFF) goto found; } @@ -5646,11 +6848,12 @@ void sub_080710DC(struct T6fArg *arg0) { end: gT6gBusy[owner] = 0; gT6fFlags[owner] &= ~(1 << bit); +#endif } struct T39Pos { u16 h0; u16 h2; }; struct T39Rng { s16 x, y; }; -struct T39Pl { u16 h0; u8 p2[0x20 - 2]; u16 state; u8 p22[0x4C - 0x22]; u8 b4C[0x68 - 0x4C]; u8 team; u8 p69[0xB2 - 0x69]; u16 ready; u8 pB4[2]; u16 done; u8 pB8[0xC2 - 0xB8]; u16 hp; u8 pC4[0x148 - 0xC4]; struct T39Pos *pos; u8 p14C[0x14C - 0x14C]; }; -struct T39En { u16 h0; u8 p2[0xC - 2]; u16 state; u8 pE[0x14 - 0xE]; s32 x; s32 y; u8 p1C[0x1DC - 0x1C]; u8 alive; u8 p1DD[0x218 - 0x1DD]; u8 b218[0x2E0 - 0x218]; }; +struct T39Pl { u16 h0; u8 p2[PLAYER_FIELD(0x20) - 0x2]; u16 state; u8 p22[PLAYER_FIELD(0x4C) - PLAYER_FIELD(0x22)]; u8 b4C[0x68 - 0x4C]; u8 team; u8 p69[PLAYER_FIELD(0xB2) - PLAYER_FIELD(0x69)]; u16 ready; u8 pB4[PLAYER_FIELD(0xB6) - PLAYER_FIELD(0xB4)]; u16 done; u8 pB8[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB8)]; u16 hp; u8 pC4[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xC4)]; struct T39Pos *pos; u8 p14C[0x14C - 0x14C]; }; +struct T39En { u16 h0; u8 p2[0xC - 2]; u16 state; u8 pE[0x14 - 0xE]; s32 x; s32 y; u8 p1C[0x1DC - 0x1C]; u8 alive; u8 p1DD[ENEMY_FIELD(0x218) - 0x1DD]; u8 b218[ENEMY_SIZE - ENEMY_FIELD(0x218)]; }; struct T39Arg { u32 owner; u32 bit; u32 mode; s32 fC; u8 p10[4]; u32 w14; }; struct T39Desc { u32 f0; u32 f4; u32 f8; u32 fC; u8 p10[0xC]; u8 f1C; u8 f1D; u8 p1E[0x34 - 0x1E]; }; extern struct T39Pl gT39Players[] asm("gUnk_03003CE0"); @@ -5689,6 +6892,22 @@ void sub_08072390(struct T39Arg *arg0) { u32 pal; u16 n; u32 myId, owner, bit, hi; +#ifdef REGION_USA + struct T39Pl *p; + struct T39Pos *pos; + struct T39En *e; + u32 lv; + u32 i; + struct T39Pl **pAddr; + u16 count; + u32 num; + s32 dx; + s16 idx; + u32 raw; + s32 dy; + u16 chance; +#define P39 (*pAddr) +#else struct T39Pl *p; struct T39En *e; struct T39Pos *pos; @@ -5701,6 +6920,8 @@ void sub_08072390(struct T39Arg *arg0) { s16 idx; u32 raw; u16 chance; +#define P39 p +#endif { u16 t = sub_080020F4(); myId = t; } owner = arg0->owner; @@ -5782,7 +7003,7 @@ void sub_08072390(struct T39Arg *arg0) { } } } - t39Init(&desc, 0x5008D, 8, -1, 0); + t39Init(&desc, RES_ID(0x5008D), 8, -1, 0); desc.f1C = 7; desc.f1D = 8; if ((myId == owner || owner > 3) && sub_0800CCCC() == 0 && sub_0800CD34() == 0) @@ -5821,6 +7042,9 @@ void sub_08072390(struct T39Arg *arg0) { p = &gT39Players[*tp]; t39Coords(p->pos->h0 >> 4, (u32)(p->pos->h2 << 20) >> 20, &x, &y, 0x30, 0); { u8 c = sub_0800BC44(sx >> 8, sy >> 8, 0); pal = c; } +#ifdef REGION_USA + pAddr = &p; +#endif if (delays[i] == 0) { heights[i] -= speeds[i]; speeds[i] += 0x20; @@ -5829,12 +7053,12 @@ void sub_08072390(struct T39Arg *arg0) { delays[i] = 0xF0; heights[i] = 10; if (myId == *tp) { - arg0->mode = p->h0; + arg0->mode = P39->h0; chance = gT39Chances[arg0->w14]; if (chance >= sub_080008C8() % 100) - t39PlHit(3, t39Calc(arg0, p->b4C), 100); + t39PlHit(3, t39Calc(arg0, P39->b4C), 100); else - t39PlHit(gT39Kinds[0xE5], t39Calc(arg0, p->b4C), kind); + t39PlHit(gT39Kinds[0xE5], t39Calc(arg0, P39->b4C), kind); if (sub_0800CCCC() == 0 && sub_0800CD34() == 0) sub_0805865C(0x1A); } @@ -5901,11 +7125,12 @@ void sub_08072390(struct T39Arg *arg0) { while (player->done == 0) sub_080003F0(); gT39Flags[owner] &= ~(1 << bit); +#undef P39 } struct T75Pos { u16 h0; u16 h2; }; struct T75Rng { s16 x, y; }; -struct T75Pl { u8 p0[0x20]; u16 state; u8 p22[0x3C - 0x22]; s16 s3C; u8 p3E[0x48 - 0x3E]; s32 w48; u8 p4C[0x68 - 0x4C]; u8 team; u8 p69[0xB2 - 0x69]; u16 ready; u8 pB4[2]; u16 done; u8 pB8[0xC2 - 0xB8]; u16 hp; u8 pC4[0x148 - 0xC4]; struct T75Pos *pos; }; -struct T75En { u8 p0[0xC]; u16 state; u8 pE[0x14 - 0xE]; s32 x; s32 y; u8 p1C[0x208 - 0x1C]; s16 s208; u8 p20A[0x214 - 0x20A]; s32 w214; u8 p218[0x2E0 - 0x218]; }; +struct T75Pl { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x3C) - PLAYER_FIELD(0x22)]; s16 s3C; u8 p3E[PLAYER_FIELD(0x48) - PLAYER_FIELD(0x3E)]; s32 w48; u8 p4C[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x4C)]; u8 team; u8 p69[PLAYER_FIELD(0xB2) - PLAYER_FIELD(0x69)]; u16 ready; u8 pB4[PLAYER_FIELD(0xB6) - PLAYER_FIELD(0xB4)]; u16 done; u8 pB8[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0xB8)]; u16 hp; u8 pC4[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xC4)]; struct T75Pos *pos; }; +struct T75En { u8 p0[0xC]; u16 state; u8 pE[0x14 - 0xE]; s32 x; s32 y; u8 p1C[ENEMY_FIELD(0x208) - 0x1C]; s16 s208; u8 p20A[ENEMY_FIELD(0x214) - ENEMY_FIELD(0x20A)]; s32 w214; u8 p218[ENEMY_SIZE - ENEMY_FIELD(0x218)]; }; struct T75Arg { u32 owner; u32 bit; u32 mode; s32 fC; u8 p10[4]; u16 level; }; struct T75Desc { u32 f0; u32 f4; u32 f8; u32 fC; u8 p10[0xC]; u8 f1C; u8 f1D; u8 p1E[0x34 - 0x1E]; }; struct T75Eff { u16 h0; u16 h2; u16 h4; u16 h6; }; @@ -5927,6 +7152,229 @@ s32 t75Draw(s32, s32, s32, u32, u32, void *, u32, u32) asm("sub_08007870"); * applies/upgrades kind4 timed slots only on authoritative local target/owner. No targets draws forward * fallback. Final owner-done wait precedes flagclear; invalid owner>3 may leave player pointer uninitialized. */ void sub_08072D5C(struct T75Arg *arg0) { +#ifdef REGION_USA + struct T75Desc desc; + u8 targets[8]; + u8 delays[8]; + u16 xs[6]; + u16 ys[6]; + s16 x, y; + struct T75Pl *player; + u16 lv; + s32 sx, sy; + u16 hits, n; + u32 myId, owner, bit; + struct T75Pl *p; + struct T75En *e; + struct T75Pos *pos; + struct T75Eff *eff; + u16 i, count; + u32 kind; + u32 num; + u8 pal; + s32 dx; + s16 idx; + u32 power; + char ten; + + asm("");asm("");asm("");asm("");asm("");asm("");asm("");asm(""); + myId = (u16)sub_080020F4(); + owner = arg0->owner; + bit = arg0->bit; + lv = arg0->level; + kind = lv; + if (owner <= 3) + player = &gT75Players[owner]; + if (myId == owner) { + struct T75Pl *me = &gT75Players[sub_080020F4()]; + power = (u16)(sub_0806898C(arg0->fC, *(s32 *)&arg0->level) - 1); + me->hp -= power; + if ((s16)me->hp < 0) + me->hp = 0; + } + xs[0] = 0; + ys[0] = 0; + delays[0] = 0; + for (i = 1; i <= 4; i++) { + xs[i] = 0; + ys[i] = 0; + delays[i] = delays[i - 1] + (u8)(sub_080008C8() % 20 + 10); + } + if (kind != 0) + player->ready = 2; + if (player->ready <= 1) { + do { + if (player->state == 10 || !(gGameState->flags & 2)) { + gT75Flags[owner] &= ~(1 << bit); + return; + } + sub_080003F0(); + } while (player->ready <= 1); + } + sx = (player->pos->h0 >> 4) << 8; + sy = (u32)(player->pos->h2 << 20) >> 12; + count = 0; + n = 0; + if (sub_0800CDF8() == 0) { + if (arg0->mode <= 3) { + num = sub_08002164(); + for (i = 0; i < num && sub_0800CD8C() == 0; i++) { + p = &gT75Players[i]; + pos = p->pos; + if ((u32)(((u8 *)pos)[0] << 28) >> 28 == 0xE || p->team == player->team || p->state == 0xB || p->team == 0) + continue; + x = (pos->h0 >> 4) - (sx >> 8); + y = ((u32)(pos->h2 << 20) >> 20) - (sy >> 8); + dx = x; + if (dx < 0) dx = -dx; + if (dx >= gT75Ranges[kind].x) continue; + dx = y; + if (dx < 0) dx = -dx; + if (dx >= gT75Ranges[kind].y) continue; + if ((u32)((s32)(lv * 2000 - 1000) / (p->w48 + p->s3C)) > sub_080008C8() % 100) { + targets[n++] = i; + count++; + } + } + } else { + for (i = 0; i <= 4 && sub_0800CD8C() == 0; i++) { + if (((u32)gUnk_030056FC & (1 << i)) == 0) + continue; + e = &gT75Enemies[i]; + if (e->state == 0xB || ((u8 *)e)[0x1DC] == 0) + continue; + x = (u32)(e->x - sx) >> 8; + y = (u32)((e->y - sy) << 8) >> 16; + dx = x; + if (dx < 0) dx = -dx; + if (dx >= gT75Ranges[kind].x) continue; + dx = y; + if (dx < 0) dx = -dx; + if (dx >= gT75Ranges[kind].y) continue; + if ((u32)((s32)(lv * 2000 - 1000) / (e->w214 + e->s208)) > sub_080008C8() % 100) { + targets[n++] = i; + count++; + } + } + } + } + if ((myId == owner || owner > 3) && sub_0800CCCC() == 0 && sub_0800CD34() == 0) + sub_0805865C(0x16B); + t75Init(&desc, RES_ID(0x5008D), 8, -1, 0); + desc.f1C = 7; + desc.f1D = 8; + if (count == 0) { + idx = (s16)(gT75Dirs[((u8 *)player->pos)[3] >> 4] << 4); + sx += gUnk_080B9704[idx + 0x40] * 30; + sy += gUnk_080B9704[idx] * 30; + hits = 0; + do { + t75Coords((s16)(sx >> 8), (s16)(sy >> 8), &x, &y, 0x30, 0); + pal = sub_0800BC44(sx >> 8, sy >> 8, 0); + if (sub_08065370(&desc, 10, (s32)&xs[0], (s32)&ys[0], 0)) + hits++; + if (sub_0800CC98() == 0 && sub_0800CD8C() == 0 && sub_0800CCCC() == 0) { + if (!(gUnk_03002344 & 1)) + sub_08000AF0(0x17, (void *)desc.fC, 2); + t75Draw(x, y, 10, xs[0], pal, &desc.f1C, desc.f8, desc.f0); + } + sub_080003F0(); + } while (hits == 0); + } else { + hits = 0; + while (hits < n && (owner != sub_080020F4() || ((u16)(player->state - 0xB) > 1 && sub_0800D11C() == 0))) { + if (arg0->mode <= 3) { + for (i = 0; i < n; i++) { + u8 *tp = &targets[i]; + u8 *d; + p = &gT75Players[*tp]; + t75Coords(p->pos->h0 >> 4, (u32)(p->pos->h2 << 20) >> 20, &x, &y, 0x30, 0); + pal = sub_0800BC44(sx >> 8, sy >> 8, 0); + d = &delays[i]; + asm("");asm("");asm("");asm(""); + if (*d == 0) { + ten = 10; if (sub_08065370(&desc, ten, (s32)&xs[i], (s32)&ys[i], 0)) { + hits++; + *d = 0xF0; + if (myId == *tp) { + eff = t75Find(p, 4, myId); + if (eff != NULL) { + if (eff->h6 < lv) { + eff->h6 = lv; + eff->h0 = (lv + 5) * 30; + eff->h2 = myId; + if (sub_0800CCCC() == 0 && sub_0800CD34() == 0) + sub_0805865C(0x1A); + } + } else { + eff = t75Alloc(p, 4); + if (eff != NULL) { + eff->h6 = lv; + eff->h0 = (lv + 5) * 30; + eff->h2 = myId; + eff->h4 = 4; + } + } + } + } + if (sub_0800CC98() == 0 && sub_0800CD8C() == 0 && sub_0800CCCC() == 0) { + if (!(gUnk_03002344 & 1)) + sub_08000AF0(0x17, (void *)desc.fC, 2); + t75Draw(x, y, ten, xs[i], pal, &desc.f1C, desc.f8, desc.f0); + } + } else if (*d != 0xF0) { + (*d)--; + } + } + } else { + for (i = 0; i < n; i++) { + u8 *d; + e = &gT75Enemies[targets[i]]; + t75Coords((e->x << 8) >> 16, (e->y << 8) >> 16, &x, &y, 0x30, 0); + pal = sub_0800BC44(sx >> 8, sy >> 8, 0); + d = &delays[i]; + if (*d == 0) { + ten = 10; if (sub_08065370(&desc, ten, (s32)&xs[i], (s32)&ys[i], 0)) { + hits++; + *d = 0xF0; + if (myId == owner) { + eff = t75FindE(e, 4, owner); + if (eff != NULL) { + if (eff->h6 < lv) { + eff->h6 = lv; + eff->h0 = (lv + 5) * 30; + eff->h2 = owner; + if (sub_0800CCCC() == 0 && sub_0800CD34() == 0) + sub_0805865C(0x1A); + } + } else { + eff = t75AllocE(e, 4); + if (eff != NULL) { + eff->h6 = lv; + eff->h0 = (lv + 5) * 30; + eff->h2 = owner; + eff->h4 = 4; + } + } + } + } + if (sub_0800CC98() == 0 && sub_0800CD8C() == 0 && sub_0800CCCC() == 0) { + if (!(gUnk_03002344 & 1)) + sub_08000AF0(0x17, (void *)desc.fC, 2); + t75Draw(x, y, ten, xs[i], pal, &desc.f1C, desc.f8, desc.f0); + } + } else if (*d != 0xF0) { + (*d)--; + } + } + } + sub_080003F0(); + } + } + while (player->done == 0) + sub_080003F0(); + gT75Flags[owner] &= ~(1 << bit); +#else struct T75Desc desc; u8 targets[8]; u8 delays[8]; @@ -6148,10 +7596,11 @@ void sub_08072D5C(struct T75Arg *arg0) { while (player->done == 0) sub_080003F0(); gT75Flags[owner] &= ~(1 << bit); +#endif } struct Buff07356C { s16 timer; u16 owner; u16 type; u16 level; u8 pad8[0x20]; }; struct Pos07356C { u16 x; u16 y; u8 f4; }; -struct Ply07356C { u8 pad0[0x24]; u16 f24; u16 f26; u8 pad28[0xC]; struct Buff07356C *buffs; u8 pad38[0x2C]; u16 state; u8 pad66[2]; u8 team; u8 pad69[0x59]; u16 mp; u8 padC4[0x84]; struct Pos07356C *pos; }; +struct Ply07356C { u8 pad0[PLAYER_FIELD(0x24)]; u16 f24; u16 f26; u8 pad28[PLAYER_FIELD(0x34) - PLAYER_FIELD(0x28)]; struct Buff07356C *buffs; u8 pad38[PLAYER_FIELD(0x64) - PLAYER_FIELD(0x38)]; u16 state; u8 pad66[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x66)]; u8 team; u8 pad69[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0x69)]; u16 mp; u8 padC4[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xC4)]; struct Pos07356C *pos; }; struct Arg07356C { u32 owner; u32 bit; u8 pad8[4]; s32 fC; u8 pad10[4]; u32 level; }; extern struct Ply07356C players07656C[] asm("gUnk_03003CE0"); extern u32 flags07656C[] asm("gUnk_030063E0"); @@ -6336,6 +7785,12 @@ static inline struct Task07386C *task07386C(u32 who, u32 i) * player halfword+C2, clamps signed-negative result0, searches8 effect slots stride0x28 for active type6 from * same owner or free timer=-1, and installs/upgrades level from player+26 with halfword * duration(level*10+40)*60. */ +/* The USA version gives these tasks a 0xC00-byte stack. */ +#ifdef REGION_USA +#define TASK_STACK_0807386C 0xC00 +#else +#define TASK_STACK_0807386C 0x800 +#endif void sub_0807386C(s32 who, s32 kind, s32 c, s32 d, s32 e) { struct Ply07356C *player; @@ -6467,12 +7922,12 @@ void sub_0807386C(s32 who, s32 kind, s32 c, s32 d, s32 e) task07386C(who, i)->fC = (u32)callback076072D5C; break; } - mem = sub_08001494(0x800); + mem = sub_08001494(TASK_STACK_0807386C); t = task07386C(who, i); t->f20 = mem; if (mem != 0) { t->f8 = 0x34; - t->f10 = mem + 0x7FC; + t->f10 = mem + TASK_STACK_0807386C - 4; t->f24 = (u32)sub_0807A120; start07686C(t, args07686C[who] + i * 0x18); flags07386C[who] |= 1 << i; @@ -6503,7 +7958,7 @@ void sub_08073CF4(u32 *arg0) s32 paused; u16 animation; - init076CF4(&sprite, 0x5008C, 1, -1, 0); + init076CF4(&sprite, RES_ID(0x5008C), 1, -1, 0); sprite.f1C = 7; sprite.f1D = 8; sub_08000AF0(23, (void *)sprite.fC, 2); diff --git a/src/code_08073E2C.c b/src/code_08073E2C.c index 1c060bcf..42980fb8 100644 --- a/src/code_08073E2C.c +++ b/src/code_08073E2C.c @@ -64,8 +64,8 @@ void sub_08073E2C_v(u32 a, u32 b, u32 c, u32 d) gMask3E2C |= 1 << i; } struct Pos076EE8 { u16 x; u16 y; }; -struct Ply076EE8 { u16 f0; u8 pad2[0x66]; u8 team; u8 pad69[0x23]; s32 x; s32 y; u8 pad94[0xB4]; struct Pos076EE8 *pos; }; -struct Ene076EE8 { u8 pad0[2]; u16 f2; u8 pad4[8]; u16 state; u8 padE[6]; s32 x; s32 y; u8 pad1C[0x40]; s16 hp; u8 pad5E[0x17E]; u8 alive; u8 pad1DD[0x103]; }; +struct Ply076EE8 { u16 f0; u8 pad2[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x2)]; u8 team; u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x; s32 y; u8 pad94[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x94)]; struct Pos076EE8 *pos; }; +struct Ene076EE8 { u8 pad0[2]; u16 f2; u8 pad4[8]; u16 state; u8 padE[6]; s32 x; s32 y; u8 pad1C[0x40]; s16 hp; u8 pad5E[0x17E]; u8 alive; u8 pad1DD[ENEMY_SIZE - 0x1DD]; }; extern struct Ply076EE8 players076EE8[] asm("gUnk_03003CE0"); extern struct Ene076EE8 *enemies076EE8 asm("gUnk_030056F4"); extern u16 directions076EE8[] asm("gUnk_0849E730"); @@ -119,14 +119,22 @@ u16 sub_08073EE8(u16 width, s32 range) d = diffEE8(angEE8(dx, dy), dirEE8(&player->pos)); { /* The ROM reloads the spilled limits into r2/r3 here. */ +#ifdef REGION_USA + register u32 w asm("r3") = width; +#else register u32 w asm("r2") = width; +#endif asm("" : "+r"(w)); if (d > (s32)w) continue; } dist = Sqrt(dx * dx + dy * dy); { +#ifdef REGION_USA + register u32 rg asm("r1") = range; +#else register u32 rg asm("r3") = range; +#endif asm("" : "+r"(rg)); if (rg <= dist) continue; @@ -142,13 +150,36 @@ u16 sub_08073EE8(u16 width, s32 range) return cand->f0; } } +#ifdef REGION_USA + { + register u32 reset asm("r3") = 0xFFFF; + register u32 none asm("r0"); + asm("" : "+r"(reset)); + best = reset; + none = -1; + asm("" : "+r"(none)); + nearest = none; + } + i = 0; +#else best = 0xFFFF; nearest = -1; i = 0; offset = 0; +#endif do { if (active076EE8 & (1 << i)) { +#ifdef REGION_USA + { + u8 **table = (u8 **)&enemies076EE8; + u32 eo = i * ENEMY_SIZE; + u8 *p = *table; + p += eo; + e = (struct Ene076EE8 *)p; + } +#else e = (struct Ene076EE8 *)((u8 *)enemies076EE8 + offset); +#endif if (e->state != 11 && e->hp != 0 && e->alive != 0) { dx = (e->x - player->x) >> 8; dy = (e->y - player->y) >> 8; @@ -162,7 +193,9 @@ u16 sub_08073EE8(u16 width, s32 range) } } } +#ifndef REGION_USA offset += sizeof(struct Ene076EE8); +#endif i++; } while (i <= 4); if (nearest == -1) @@ -174,7 +207,11 @@ extern struct Ply076EE8 players07614C[] asm("gUnk_03003CE0"); extern struct Ene076EE8 *enemies07614C asm("gUnk_030056F4"); extern u32 active07614C asm("gUnk_030056FC"); extern u16 directions07614C[] asm("gUnk_0849E730"); +#ifdef REGION_USA +static inline u16 dir414C(struct Pos076EE8 **pos) { register u16 *table asm("r2") = directions07614C; return table[((u8 *)*pos)[3] >> 4]; } +#else static inline u16 dir414C(struct Pos076EE8 **pos) { return directions07614C[((u8 *)*pos)[3] >> 4]; } +#endif static inline u32 ang414C(s32 dx, s32 dy) { return (u16)ArcTan2(dx, dy) + 0x400; } static inline s32 diff414C(u32 a, u16 b) { u16 angle = (a >> 12) - b; s32 d; @@ -182,12 +219,22 @@ static inline s32 diff414C(u32 a, u16 b) { { s32 t = (s16)angle; if (t < -8) angle = t + 16; } d = (s16)angle; if (d < 0) d = -d; return d; } +#ifdef REGION_USA +static inline s32 diffB414C(u32 a, u16 b) { + register u32 bb asm("r1") = b; u16 angle = (a >> 12) - bb; s32 d; + { s32 t = (s16)angle; if (t > 8) angle = t - 16; } + { register s32 t asm("r0") = (s16)angle; register s32 low asm("r3") = -8; if (t < low) { t += 16; angle = t; } } + asm("" : : "r"(bb)); + d = (s16)angle; if (d < 0) d = -d; + return d; } +#else static inline s32 diffB414C(u32 a, u16 b) { u16 angle = (a >> 12) - b; s32 d; { s32 t = (s16)angle; if (t > 8) angle = t - 16; } { register s32 t asm("r0") = (s16)angle; if (t < -8) { t += 16; angle = t; } } d = (s16)angle; if (d < 0) d = -d; return d; } +#endif /* [SelectPlayerFacingConeTarget] Selects a facing-cone target for a supplied player pointer. Uses that player * packet position/facing via +0x148, unlike the local-live-coordinate sibling 73EE8. Applies the same * battle-enabled differently grouped nonzero-peer priority, then five-enemy fallback, returning player ID, @@ -215,7 +262,11 @@ s32 sub_0807414C(struct Ply076EE8 *player, u16 width, u32 range) d = diffB414C(ang414C(dx, dy), dir414C(&player->pos)); { /* The ROM reloads the spilled limits into r2/r1/r2 here. */ +#ifdef REGION_USA + register u32 w asm("r1") = width; +#else register u32 w asm("r2") = width; +#endif asm("" : "+r"(w)); if (d > (s32)w) continue; @@ -267,7 +318,7 @@ s32 sub_0807414C(struct Ply076EE8 *player, u16 width, u32 range) return e->f2; } struct Position076398 {u16 x,y;}; -struct Player076398 {u16 id;u8 pad2[0x66];u8 team;u8 pad69[0xDF];struct Position076398 *position;}; +struct Player076398 {u16 id;u8 pad2[PLAYER_FIELD(0x68)-2];u8 team;u8 pad69[PLAYER_FIELD(0x148)-PLAYER_FIELD(0x69)];struct Position076398 *position;u8 pad14C[PLAYER_SIZE-PLAYER_FIELD(0x14C)];}; extern struct Player076398 players076398[] asm("gUnk_03003CE0"); extern u8 *enemies076398 asm("gUnk_030056F4"); #define F_076398(p,t,o) (*(t*)((u8*)(p)+(o))) @@ -277,7 +328,11 @@ extern u32 active076398 asm("gUnk_030056FC"); s32 nearest076398(u32 inputSelf,u32 inputExcluded,s32 x,s32 y,s32 range) { u32 self=(u16)inputSelf; +#ifdef REGION_USA + register u32 best asm("r8"),nearest asm("sl"),index asm("r4"); +#else register u32 best asm("r9"),nearest asm("r8"),index asm("r4"); +#endif u32 count; u8 **enemyAddress; u8 *team; @@ -298,11 +353,11 @@ s32 nearest076398(u32 inputSelf,u32 inputExcluded,s32 x,s32 y,s32 range) index=0; if(index>8; dy=(F_076398(enemy,s32,0x18)-y)>>8; @@ -363,7 +425,7 @@ s32 nearest076398(u32 inputSelf,u32 inputExcluded,s32 x,s32 y,s32 range) } } } - offset+=0x2E0; + offset+=ENEMY_SIZE; index++; } while(index<=4); @@ -372,11 +434,17 @@ s32 nearest076398(u32 inputSelf,u32 inputExcluded,s32 x,s32 y,s32 range) if(nearest!=-1U){ u8 **address=&enemies076398; u32 selected=nearest; +#ifdef REGION_USA + u32 eo=nearest*ENEMY_SIZE; u8 *object=*address+eo; + enemy=object; + result=F_076398(enemy,u16,2); +#else register u32 offset asm("r0"); u32 object; - offset=nearest*0x2E0; + offset=nearest*ENEMY_SIZE; object=(u32)*address+offset; result=F_076398(object,u16,2); +#endif goto finish; } result=0xFF; @@ -386,8 +454,8 @@ s32 nearest076398(u32 inputSelf,u32 inputExcluded,s32 x,s32 y,s32 range) } struct EffectSprite77 { u32 base, unused4; void *data; void *paletteResource; u32 resource, style; s32 mode; u8 palette[16]; s16 scale, step, upper, lower; }; struct EffectEntity77 { u16 xRaw,yRaw; }; -struct EffectPlayer77 { u8 pad[0x148]; struct EffectEntity77 *entity; }; -struct EffectEnemy77 { u8 pad[0x14]; s32 x,y; u8 rest[0x2C4]; }; +struct EffectPlayer77 { u8 pad[PLAYER_FIELD(0x148)]; struct EffectEntity77 *entity; }; +struct EffectEnemy77 { u8 pad[0x14]; s32 x,y; u8 rest[ENEMY_SIZE - 0x1C]; }; extern struct EffectPlayer77 effectPlayers77[] asm("gUnk_03003CE0"); extern struct EffectEnemy77 *effectEnemies77 asm("gUnk_030056F4"); extern u32 effectMasks77[] asm("gUnk_030063E0"); @@ -413,7 +481,7 @@ void sub_08074530(u32 who,u32 slot) struct EffectEnemy77 *enemy; u16 done; frame=0;timer=0; - effectInit77(&sprite,0x5008C,8,-1,0); + effectInit77(&sprite,RES_ID(0x5008C),8,-1,0); sprite.palette[0]=7;sprite.palette[1]=8; done=0; if(who<4) player=&effectPlayers77[who]; @@ -450,7 +518,7 @@ void sub_080746A4(u32 who,u32 slot) struct EffectEnemy77 *enemy; u16 done; frame=0;timer=0; - effectInit77(&sprite,0x5008C,8,-1,0); + effectInit77(&sprite,RES_ID(0x5008C),8,-1,0); sprite.palette[0]=7;sprite.palette[1]=8; done=0; if(who<4) player=&effectPlayers77[who]; @@ -487,7 +555,7 @@ void sub_08074818(u32 who,u32 slot) struct EffectEnemy77 *enemy; u16 done; frame=0;timer=0; - effectInit77(&sprite,0x5008C,8,-1,0); + effectInit77(&sprite,RES_ID(0x5008C),8,-1,0); sprite.palette[0]=7;sprite.palette[1]=8; done=0; if(who<4) player=&effectPlayers77[who]; @@ -524,7 +592,7 @@ void sub_0807498C(u32 who,u32 slot) struct EffectEnemy77 *enemy; u16 done; frame=0;timer=0; - effectInit77(&sprite,0x5008C,8,-1,0); + effectInit77(&sprite,RES_ID(0x5008C),8,-1,0); sprite.palette[0]=7;sprite.palette[1]=8; done=0; if(who<4) player=&effectPlayers77[who]; @@ -561,7 +629,7 @@ void sub_08074B00(u32 who,u32 slot) struct EffectEnemy77 *enemy; u16 done; frame=0;timer=0; - effectInit77(&sprite,0x5008C,8,-1,0); + effectInit77(&sprite,RES_ID(0x5008C),8,-1,0); sprite.palette[0]=7;sprite.palette[1]=8; done=0; if(who<4) player=&effectPlayers77[who]; @@ -597,7 +665,7 @@ void sub_08074C74(u32 who,u32 slot) struct EffectEnemy77 *enemy; u16 done; frame=0;timer=0; - effectInit77(&sprite,0x5008D,8,-1,0); + effectInit77(&sprite,RES_ID(0x5008D),8,-1,0); sprite.palette[0]=7;sprite.palette[1]=8; done=0; if(who<4) player=&effectPlayers77[who]; @@ -716,8 +784,8 @@ void sub_08074DE8(u32 who, s32 type) } struct Spr5088 { u32 base, unused4; void *data; void *paletteResource; u32 resource, style; s32 mode; u8 palette[16]; s16 scale, step, upper, lower; }; struct Ent5088 { u16 xRaw, yRaw; }; -struct Ply5088 { u8 pad0[0x20]; u16 state; u8 pad22[0xE]; u32 flags; u8 pad34[0xA8]; u32 serial; u8 padE0[0x68]; struct Ent5088 *entity; }; -struct Ene5088 { u16 id; u8 pad2[0xA]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x30]; u32 dmg; u32 f50; u32 serial; u16 owner, hitMask; u8 pad5C[0x284]; }; +struct Ply5088 { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0xDC) - PLAYER_FIELD(0x34)]; u32 serial; u8 padE0[PLAYER_FIELD(0x148) - PLAYER_FIELD(0xE0)]; struct Ent5088 *entity; }; +struct Ene5088 { u16 id; u8 pad2[0xA]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x30]; u32 dmg; u32 f50; u32 serial; u16 owner, hitMask; u8 pad5C[ENEMY_SIZE - 0x5C]; }; extern struct Ply5088 p5088[] asm("gUnk_03003CE0"); extern struct Ene5088 *e5088Base asm("gUnk_030056F4"); extern u32 e5088Mask asm("gUnk_030056FC"); @@ -752,6 +820,12 @@ void sub_08075088(u32 who, u32 slot) u16 done[3]; u16 cnt[3]; s16 sx, sy; +#ifdef REGION_USA + struct Ene5088 **eAddr; +#define E5088 (*eAddr) +#else +#define E5088 e +#endif struct Ply5088 *p; u16 i; u16 serial; @@ -768,7 +842,7 @@ void sub_08075088(u32 who, u32 slot) spd = 2; local = sub_080020F4(); - init5088(&spr, 0x5008C, 8, -1, 0); + init5088(&spr, RES_ID(0x5008C), 8, -1, 0); spr.palette[0] = 7; spr.palette[1] = 8; p = &p5088[who]; @@ -785,7 +859,7 @@ void sub_08075088(u32 who, u32 slot) p->flags |= 1; serial = p->serial++; dmg = rand5088() % 50; - dmg = dmg + (u16)sub_0801E0AC((s32)party5088 + 0x30, 5) * 50; + dmg = dmg + (u16)sub_0801E0AC((s32)party5088 + SAVE_FIELD(0x30), 5) * 50; } while (1) { count = 0; @@ -822,9 +896,13 @@ void sub_08075088(u32 who, u32 slot) continue; e->dmg = dmg; hit5088(e->id, 1, dmg, 1, 0x20, dirIdx); - e->owner = who; + +#ifdef REGION_USA + eAddr = &e; +#endif + E5088->owner = who; e->serial = serial; - e->hitMask |= 1 << local; + E5088->hitMask |= 1 << local; } } if (done[i] != 0) @@ -838,6 +916,7 @@ void sub_08075088(u32 who, u32 slot) if (local == who && !sub_0800CC98() && !sub_0800CE68() && !sub_0800CD8C()) p->flags &= ~1; m5088[who] &= ~(1 << slot); +#undef E5088 } struct Task5494 { u32 f0, f4, f8, fC, f10, f14, f18, f1C, f20, f24; }; extern u32 gMasks5494[] asm("gUnk_030063E0"); @@ -884,7 +963,7 @@ void sub_08075494(u32 who) gMasks5494[who] |= 1 << i; } struct EffectBits77 { u32 kind:4; u32 x:12; u32 y:12; u32 pad:4; u32 low:5; u32 flag:1; }; -struct EffectHolder77 { u8 pad[0x148]; struct EffectBits77 *entity; }; +struct EffectHolder77 { u8 pad[PLAYER_FIELD(0x148)]; struct EffectBits77 *entity; }; /* [RunPlayerVanishAnimationAndTemporaryVisibilityEffect] Complete original 08075520..080756EC reviewed. ABI r0 * player index/r1 task bit; waits while packed entity kind low4 is10, then advances resource5008D animation8 * at the live player position. Once animation completes, sets player word +30 bit18 (0x40000) for current @@ -900,7 +979,7 @@ void sub_08075520(u32 who,u32 slot) u16 done,i; u8 visible; frame=0;timer=0; - effectInit77(&sprite,0x5008D,8,-1,0); + effectInit77(&sprite,RES_ID(0x5008D),8,-1,0); sprite.palette[0]=7;sprite.palette[1]=8; done=0; player=(struct EffectHolder77 *)&gUnk_03003CE0[who]; @@ -966,8 +1045,8 @@ void sub_080756EC(u32 who) struct Arg5778 { u32 who; u32 slot; u16 target; u16 pad; u32 fC; u32 count; u32 flags; }; struct Spr5778 { u32 f0, f4, f8, fC; u8 pad10[16]; u8 f20; u8 pad21[19]; }; struct Ent5778 { u16 xRaw, yRaw; }; -struct Ply5778 { u16 id; u8 pad2[0x1E]; u16 state; u8 pad22[4]; u16 f26; u8 pad28[8]; u32 flags; u8 pad34[6]; s16 power; u8 pad3C[0x2C]; u8 team; u8 pad69[0x23]; s32 x, y; u8 pad94[0x1E]; u16 ready; u8 padB4[0x28]; u32 serial; u8 padE0[0x18]; u32 hist[0x14]; struct Ent5778 *entity; }; -struct Ene5778 { u16 id; u16 f2; u8 pad4[8]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x38]; u32 serial; u16 owner, hitMask; u8 pad5C[0x180]; u8 team; u8 pad1DD[0x29]; s16 power; u8 pad208[0x26]; u8 w, h; u8 pad230[0xB0]; }; +struct Ply5778 { u16 id; u8 pad2[PLAYER_FIELD(0x20) - 2]; u16 state; u8 pad22[4]; u16 f26; u8 pad28[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x28)]; u32 flags; u8 pad34[6]; s16 power; u8 pad3C[0x2C]; u8 team; u8 pad69[0x23]; s32 x, y; u8 pad94[0x1E]; u16 ready; u8 padB4[0x28]; u32 serial; u8 padE0[0x18]; u32 hist[0x14]; struct Ent5778 *entity; u8 pad14C[PLAYER_SIZE - PLAYER_FIELD(0x14C)];}; +struct Ene5778 { u16 id; u16 f2; u8 pad4[8]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x38]; u32 serial; u16 owner, hitMask; u8 pad5C[0x180]; u8 team; u8 pad1DD[ENEMY_FIELD(0x206) - 0x1DD]; s16 power; u8 pad208[ENEMY_FIELD(0x22E) - ENEMY_FIELD(0x208)]; u8 w, h; u8 pad230[ENEMY_SIZE - ENEMY_FIELD(0x230)]; }; struct Box5778 { u32 w:16; u32 h:16; }; struct Pos5778 { s32 x, y; }; extern struct Ply5778 p5778[] asm("gUnk_03003CE0"); @@ -1016,8 +1095,9 @@ static inline s32 wait5778(struct Ply5778 *p, u32 n) * cumulatively adds 0x18 to attack byte+A9 on successful rolls. */ void sub_08075778(struct Arg5778 *arg) { +#ifdef REGION_USA struct Spr5778 spr; - u8 atk[0xC4]; + u8 atk[ITEM_FIELD(0xC4)]; s16 dx, dy; u16 frame, timer; u16 ang; @@ -1052,6 +1132,7 @@ void sub_08075778(struct Arg5778 *arg) u32 shade; s32 sx, sy; s32 spd; + u32 bit1; spd = 45; local = sub_080020F4(); @@ -1061,10 +1142,11 @@ void sub_08075778(struct Arg5778 *arg) kind = (u8)arg->flags; n = arg->count; ok = 0; + bit1 = 1; timer = 0; frame = 0; big = (u32)-(arg->flags & 0x8000) >> 31; - init5778(&spr, 0x5001E, 0, -1, 0); + init5778(&spr, RES_ID(0x5001E), 0, -1, 0); spr.f20 = arg->who; p = &p5778[who]; x = (p->entity->xRaw >> 4) << 8; @@ -1075,12 +1157,12 @@ void sub_08075778(struct Arg5778 *arg) serial = (u16)p->serial; { void *src = tmpl5778(); - memcpy(atk, src, 0xC4); + memcpy(atk, src, ITEM_FIELD(0xC4)); } - if (*(u16 *)(atk + 0xBC) == 0) { + if (*(u16 *)(atk + ITEM_FIELD(0xBC)) == 0) { u8 *b = inv5778; - b += *(u16 *)(b + 0x68) * 16; - *(u16 *)(atk + 0xBC) = b[0x77]; + b += *(u16 *)(b + SAVE_FIELD(0x68)) * 16; + *(u16 *)(atk + ITEM_FIELD(0xBC)) = b[SAVE_FIELD(0x77)]; } if (kind != 0) power = p->power * 3; @@ -1089,14 +1171,12 @@ void sub_08075778(struct Arg5778 *arg) } if (target > 3) { for (j = 0; j <= 4; j++) { - if (e5778Mask & (1 << j)) { + if (e5778Mask & (bit1 << j)) { e = &e5778Base[j]; - if (e->state != 11) - if (e->f2 == target) - goto found; + if (e->state != 11 && e->f2 == target) + break; } } - found: if (j > 4) target = 0xFFFF; } else { @@ -1126,9 +1206,8 @@ void sub_08075778(struct Arg5778 *arg) ang = sb - 0x100; } } else { - struct Ent5778 *te = p5778[target].entity; - dx = (te->xRaw >> 4) - (x >> 8); - dy = ((u32)(te->yRaw << 20) >> 20) - (y >> 8); + dx = (p5778[target].entity->xRaw >> 4) - (x >> 8); + dy = ((u32)(p5778[target].entity->yRaw << 20) >> 20) - (y >> 8); d = (u16)atan5778(dx, dy) >> 8; t = (u8)d; if (t > 0x80) @@ -1200,7 +1279,7 @@ void sub_08075778(struct Arg5778 *arg) continue; if (roll5778(power, q->power)) { if (big) { - atk[0xA9] += 0x18; + atk[ITEM_FIELD(0xA9)] += 0x18; sub_08022100(q->id); p->flags |= 0x200000; } @@ -1264,7 +1343,7 @@ void sub_08075778(struct Arg5778 *arg) continue; if (roll5778(power, e2->power)) { if (big) { - atk[0xA9] += 0x18; + atk[ITEM_FIELD(0xA9)] += 0x18; sub_08022100(e2->id + 4); p->flags |= 0x200000; } @@ -1310,6 +1389,7 @@ void sub_08075778(struct Arg5778 *arg) sub_0805865C(0x55); } } + asm("" : : "g"(bit1)); hit = 1; break; } @@ -1346,197 +1426,82 @@ void sub_08075778(struct Arg5778 *arg) } end: m5778[who] &= ~(1 << slot); -} -struct Task60E8 { u32 f0, f4, f8, fC, f10, f14, f18, f1C, f20, f24; }; -struct Info60E8 { u32 who, i, a, pad, c, b; }; -extern u32 gMasks60E8[] asm("gUnk_030063E0"); -extern u8 *gLists60E8[] asm("gUnk_030063B0"); -extern u8 *gInfo60E8[] asm("gUnk_03006380"); -extern void sub_08000274_2(void *, void *) asm("sub_08000274"); -extern void sub_08075778(); -/* [StartPlayerFastAimedAttackProjectile] ABI r0=owner,r1=target word,r2=flags word,r3=lifetime parameter. - * Searches16 owner occupancy bits; full pool returns. Allocates0x3C0, stores task+20 pointer even on failure; - * zero returns. On success fills24-byte descriptor owner+0,slot+4,target WORD+8 (callback reads - * halfword),flags+14,parameter+10, leaving +C untouched; task priority0x34,callback75778,stack - * allocation+3BC,cleanup0. Scheduler ABI r0=task,r1=descriptor,then occupancy set. Starts asynchronous player - * projectile; no hit/completion status. Complete original configured body inspected and equal to local EU - * ROM/supplied verified-main ELF; static research only, no worker build or runtime testing. */ -void sub_080760E8(u32 who, u32 a, u32 b, u32 c) -{ - u32 i = 0; - vu32 *m; - u32 mem; - struct Task60E8 *t; - struct Info60E8 *e; - { - vu32 *mb = gMasks60E8; - m = &mb[who]; - } - while (*m & (1 << i)) { - i++; - if (i > 0xF) - return; - } - if (i > 0xF) - return; - mem = sub_08001494(0x3C0); - { - u8 *p = gLists60E8[who]; - t = (struct Task60E8 *)(i * 0x28 + (u32)p); - } - t->f20 = mem; - if (mem == 0) - return; - { - u8 *p = gInfo60E8[who]; - e = (struct Info60E8 *)(i * 0x18 + (u32)p); - } - e->who = who; - e->i = i; - e->a = a; - e->b = b; - e->c = c; - t->f8 = 0x34; - t->fC = (u32)sub_08075778; - t->f10 = mem + 0x3BC; - t->f24 = 0; - sub_08000274_2(t, e); - gMasks60E8[who] |= 1 << i; -} -struct Arg61A4 { u32 who; u32 slot; u16 target; u16 pad; u32 fC; s32 n; u32 flags; }; -struct Spr61A4 { u32 base, unused4; void *data; void *paletteResource; u32 resource, style; s32 mode; u8 palette[16]; s16 scale, step, upper, lower; }; -struct Ent61A4 { u16 xRaw, yRaw; }; -struct Ply61A4 { u16 id; u8 pad2[0x1E]; u16 state; u8 pad22[4]; u16 f26; u16 f28; u8 pad2A[6]; u32 flags; u8 pad34[6]; s16 power; u8 pad3C[0x2C]; u8 team; u8 pad69[0x23]; s32 x, y; u8 pad94[0x1E]; u16 ready; u8 padB4[0x28]; u32 serial; u8 padE0[0x18]; u32 hist[0xA]; u16 f120; u16 f122; u8 pad124[0x24]; struct Ent61A4 *entity; }; -struct Ene61A4 { u16 id; u16 f2; u8 pad4[8]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x2E]; u16 dmg; u8 pad4C[8]; u32 serial; u16 owner, hitMask; s16 hp; u8 pad5E[0x17E]; u8 team; u8 pad1DD[0x29]; s16 power; u8 pad208[0x26]; u8 w, h; u8 pad230[0xB0]; }; -struct Box61A4 { u32 w:16; u32 h:16; }; -struct Pos61A4 { s32 x, y; }; -extern struct Ply61A4 p61A4[] asm("gUnk_03003CE0"); -extern struct Ene61A4 *e61A4Base asm("gUnk_030056F4"); -extern u32 e61A4Mask asm("gUnk_030056FC"); -extern u32 m61A4[] asm("gUnk_030063E0"); -extern u8 *inv61A4 asm("gUnk_030034E0"); -extern u16 dir61A4[] asm("gUnk_0847AD0A"); -extern s16 sin61A4[] asm("gUnk_080B9704"); -extern s16 off61A4[][2] asm("gUnk_084EBEBC"); -extern s32 init61A4(void *, u32, u32, u32, u32) asm("sub_08065158"); -extern u16 step61A4(void *, u32, u16 *, u16 *, u32) asm("sub_08065370"); -extern u32 pos61A4(s32, s32, s16 *, s16 *, u32, u32) asm("sub_0800BC08"); -extern s32 draw61A4(s32, s32, u16, u16, u8, void *, void *, u32) asm("sub_08007870"); -extern void *tmpl61A4(void) asm("sub_0805AD18"); -extern s32 roll61A4(s32, s32) asm("sub_080223A4"); -extern s32 test61A4(struct Pos61A4 *, void *, struct Box61A4 *, struct Box61A4 *) asm("sub_08021FE0"); -extern s32 wall61A4(struct Pos61A4 *, struct Box61A4 *) asm("sub_0801F99C"); -extern void hitE61A4(void *, void *, void *, s32) asm("sub_0801F374"); -extern void hitP61A4(void *, void *, void *, s32) asm("sub_0801F79C"); -extern void pre61A4(void *) asm("sub_0801FD64"); -extern s16 atan61A4(s16, s16) asm("ArcTan2"); - -static inline s32 move61A4(s32 v, s32 spd) -{ - return v * spd; -} - -static inline s32 wait61A4(struct Ply61A4 *p, u32 n) -{ - while (p->ready < n) { - if (p->state == 10) - return 1; - sub_080003F0(); - } - return 0; -} - -void sub_080761A4_c(struct Arg61A4 *arg) asm("sub_080761A4"); -/* [RunPlayerAttackProjectileWithPiercingVariants] Descriptor pointer in r0: owner word+0, slot word+4, target - * halfword+8, parameter word+10, flags word+14. Player owner only; no owner bounds checks. Takes initial - * packed player coordinates and computes aim once toward target, falling back to facing; restored original - * target selects player-versus-enemy collision domain. Only local owner initializes attack template 0xC4 - * bytes, low16 serial from player+DC and power from signed halfword+3A (tripled when kind nonzero); remote - * paths may still read these uninitialized spills before authority checks. Flags bit15 enables a temporary - * player flag 0x200000 and cumulatively adds 0x18 to attack byte+A9 on successful rolls. */ -void sub_080761A4_c(struct Arg61A4 *arg) -{ - struct Spr61A4 spr; +#else + struct Spr5778 spr; u8 atk[0xC4]; s16 dx, dy; u16 frame, timer; u16 ang; - struct Pos61A4 pos; - struct Pos61A4 opos; - struct Box61A4 box; - struct Box61A4 box2; - struct Ene61A4 *e; + struct Pos5778 pos; + struct Pos5778 opos; + struct Box5778 box; + struct Box5778 box2; + struct Ene5778 *e; u16 target; u32 lo; u32 serial; u32 kind; s32 x, y; + u32 n; s32 iter; u32 dirIdx; u16 local; - u32 base; - u32 big; + u32 slot; s32 power; + u32 big; u32 who; - s32 n; - struct Ply61A4 *p; - struct Ply61A4 *q; - struct Ene61A4 *e2; - s32 d; + struct Ply5778 *p; + struct Ply5778 *q; + struct Ene5778 *e2; + u32 d; u16 j; u32 cnt; s32 t; s32 hit; s32 ok; u8 c; - u8 shade; + u32 shade; s32 sx, sy; s32 spd; - u32 delay; - spd = 4; + spd = 45; local = sub_080020F4(); target = arg->target; who = arg->who; + slot = arg->slot; kind = (u8)arg->flags; - n = arg->n; - p = &p61A4[who]; + n = arg->count; ok = 0; timer = 0; frame = 0; big = (u32)-(arg->flags & 0x8000) >> 31; + init5778(&spr, 0x5001E, 0, -1, 0); + spr.f20 = arg->who; + p = &p5778[who]; x = (p->entity->xRaw >> 4) << 8; y = (u32)(p->entity->yRaw << 20) >> 12; + dirIdx = ((u8 *)p->entity)[3] >> 4; lo = (u32)(((u8 *)p->entity)[0] << 28) >> 28; if (who == local) { serial = (u16)p->serial; { - void *src = tmpl61A4(); + void *src = tmpl5778(); memcpy(atk, src, 0xC4); } if (*(u16 *)(atk + 0xBC) == 0) { - u8 *iv = inv61A4; - iv += *(u16 *)(iv + 0x68) * 16; - *(u16 *)(atk + 0xBC) = iv[0x77]; + u8 *b = inv5778; + b += *(u16 *)(b + 0x68) * 16; + *(u16 *)(atk + 0xBC) = b[0x77]; } if (kind != 0) power = p->power * 3; else power = p->power; } - if (kind == 0) { - init61A4(&spr, 0x50021, 0, 0x80000000, 0); - base = 0x10; - } else { - init61A4(&spr, 0x500C9, 0, 0x80000000, 0); - base = (u16)((kind - 1) * 8); - } - spr.palette[0] = who; - delay = 2; if (target > 3) { for (j = 0; j <= 4; j++) { - if (e61A4Mask & (1 << j)) { - e = &e61A4Base[j]; + if (e5778Mask & (1 << j)) { + e = &e5778Base[j]; if (e->state != 11) if (e->f2 == target) goto found; @@ -1544,18 +1509,23 @@ void sub_080761A4_c(struct Arg61A4 *arg) } found: if (j > 4) - target = 0xFF; + target = 0xFFFF; + } else { + cnt = sub_08002164(); + for (j = 0; j < cnt && (q = &p5778[j])->id != target; j++) + ; + if (j >= cnt || target == who) + target = 0xFFFF; } - if (target != 0xFF) { + if (target != 0xFFFF) { if (target > 3) { dx = (e->x - x) >> 8; dy = (e->y - y) >> 8; - /* hit doubles as the angle temporary (ROM keeps it in r4). */ - hit = (u16)atan61A4(dx, dy) >> 8; - t = (u8)hit; + d = (u16)atan5778(dx, dy) >> 8; + t = (u8)d; if (t > 0x80) - hit = (u16)(t - 0x100); - ang = hit; + d = (u16)(t - 0x100); + ang = d; { s16 sa = ang; if (sa < 0) @@ -1567,14 +1537,14 @@ void sub_080761A4_c(struct Arg61A4 *arg) ang = sb - 0x100; } } else { - struct Ent61A4 *te = p61A4[target].entity; + struct Ent5778 *te = p5778[target].entity; dx = (te->xRaw >> 4) - (x >> 8); dy = ((u32)(te->yRaw << 20) >> 20) - (y >> 8); - hit = (u16)atan61A4(dx, dy) >> 8; - t = (u8)hit; + d = (u16)atan5778(dx, dy) >> 8; + t = (u8)d; if (t > 0x80) - hit = (u16)(t - 0x100); - ang = hit; + d = (u16)(t - 0x100); + ang = d; { s16 sa = ang; if (sa < 0) @@ -1587,22 +1557,776 @@ void sub_080761A4_c(struct Arg61A4 *arg) } } } else { - ang = dir61A4[((u8 *)p->entity)[3] >> 4]; + ang = dir5778[((u8 *)p->entity)[3] >> 4]; } - if (target == 0xFF) - target = arg->target; - x += move61A4(sin61A4[(s16)ang + 0x40] * 2, spd); - y += move61A4(sin61A4[(s16)ang] * 2, spd); - while (p->ready < delay) { - if (p->state == 10) { - m61A4[who] &= ~(1 << arg->slot); - return; - } - sub_080003F0(); + { + /* FAKE: an empty value held in r4 across the target check keeps r4 out of the reload + rotation there (the ROM reloads target into r6 and arg into r0). */ + register u32 z asm("r4"); + asm("" : "=r"(z)); + if (target == 0xFFFF) + target = arg->target; + asm("" : : "r"(z)); } - iter = n * 18 / 10 + 10; - if (p->state != 13 && !sub_0800CCCC() && !sub_0800CD34() && n > 0) - sub_0805865C(n + 0x100); + x += move5778(sin5778[(s16)ang + 0x40] * 2, spd); + y += move5778(sin5778[(s16)ang] * 2, spd); + if (wait5778(p, 1)) + goto end; + if (p->state != 13 && !sub_0800CCCC() && !sub_0800CD34()) + sub_0805865C(0x17); + if (who == local) + pre5778(&p5778[who]); + iter = (s32)(n * 17) / 10 + 9; + while (iter-- != 0 && !sub_08056E90() && p->state != 11 && p->state != 12 && !sub_0800D11C()) { + hit = 0; + pos.x = x; + pos.y = y; + box.w = 8; + box.h = 8; + if (target <= 3) { + box2.w = 0x10; + box2.h = 0x10; + cnt = sub_08002164(); + for (j = 0; j < cnt; j++) { + if (who == j) + continue; + if (sub_0800CDF8()) + break; + q = &p5778[j]; + if (q->team == p->team || q->team == 0) + continue; + if (sub_0800CD8C()) + break; + if ((u32)(((u8 *)q->entity)[0] << 28) >> 28 == 14) + continue; + opos.x = (q->entity->xRaw >> 4) << 8; + opos.y = (u32)(q->entity->yRaw << 20) >> 12; + if (!test5778(&pos, &opos, &box, &box2)) + continue; + if (q->state != 11 && q->hist[who] != serial && !(q->flags & 0x2000)) + ok = 1; + else + ok = 0; + if (!ok) + continue; + if (roll5778(power, q->power)) { + if (big) { + atk[0xA9] += 0x18; + sub_08022100(q->id); + p->flags |= 0x200000; + } + if (who == local) { + u16 s = p->state; + u16 t; + p->state = lo; + t = p->f26; + p->f26 = kind; + hitP5778(p, q, atk, 0); + p->state = s; + p->f26 = t; + q->hist[p->id] = serial; + sub_0805865C(0x1A); + } + if (big) + p->flags &= ~0x200000; + } else if (!(sub_0800086C() & 1)) { + if (who == local) { + u16 s = p->state; + u16 t; + p->state = lo; + t = p->f26; + p->f26 = kind; + hitP5778(p, q, atk, 1); + sub_0805865C(0x1A); + p->state = s; + p->f26 = t; + q->hist[p->id] = serial; + } + } else if (who == sub_080020F4()) { + sub_080223F4(q->x, q->y); + q->hist[p->id] = serial; + if (!sub_0800CCCC() && !sub_0800CD34()) + sub_0805865C(0x55); + } + hit = 1; + } + } else { + for (j = 0; j <= 4 && !hit; j++) { + if (!(e5778Mask & (1 << j))) + continue; + e2 = &e5778Base[j]; + if (sub_0800CD8C()) + break; + if (sub_0800CDF8()) + break; + if (e2->team == p->team || e2->team == 0) + continue; + box2.w = e2->w; + box2.h = e2->h; + if (!test5778(&pos, &e2->x, &box, &box2)) + continue; + { + u16 st = e2->state; + ok = 0; + if (st != 11) + ok = e2->serial != serial; + } + if (!ok) + continue; + if (roll5778(power, e2->power)) { + if (big) { + atk[0xA9] += 0x18; + sub_08022100(e2->id + 4); + p->flags |= 0x200000; + } + if (who == sub_080020F4()) { + u16 s = p->state; + u16 t; + p->state = lo; + t = p->f26; + p->f26 = kind; + hitE5778(p, e2, atk, 0); + sub_0805865C(0x1A); + p->state = s; + p->f26 = t; + e2->owner = local; + e2->hitMask |= 1 << local; + } + if (big) + p->flags &= ~0x200000; + } else { + /* FAKE: the call result stays live in r0 (a hard reg), so reload copies the + constant 1 (r7) into the and destination instead of the call result. */ + register u32 r asm("r0") = sub_0800086C(); + u32 b = r & 1; + asm("" : : "r"(r)); + if (!b) { + if (who == sub_080020F4()) { + u16 s = p->state; + u16 t; + p->state = lo; + t = p->f26; + p->f26 = kind; + hitE5778(p, e2, atk, 1); + sub_0805865C(0x1A); + p->state = s; + p->f26 = t; + e2->owner = local; + e2->hitMask |= 1 << local; + } + } else if (who == sub_080020F4()) { + sub_080223F4(e2->x, e2->y); + e2->serial = serial; + if (!sub_0800CCCC() && !sub_0800CD34()) + sub_0805865C(0x55); + } + } + hit = 1; + break; + } + } + if (who == local && wall5778(&pos, &box)) + hit = 1; + if (hit) + break; + c = sub_0800AE50(x, y, 0); + if ((c & 0xF) && !(c & 0x10)) + break; + /* FAKE: c stays live past the 0x10 test, so regmove ties that and to the constant. */ + asm("" : : "r"(c)); + x += move5778(sin5778[(s16)ang + 0x40], spd); + y += move5778(sin5778[(s16)ang], spd); + if (!sub_0800CC98() && !sub_0800CD8C() && !sub_0800CCCC()) { + pos5778((s16)(shade = x >> 8), (s16)(sy = y >> 8), &dx, &dy, 0x30, 0); + shade = (u8)sub_0800BC44(shade, sy, 0); + d = dirIdx; + /* FAKE: c (a global pseudo) holds the mode bit so d gets no r1 preference from the + step argument; otherwise ang inherits it at `ang = d` and takes r1 instead of r3. */ + c = 0x40; + step5778(&spr, c | d, &frame, &timer, 1); + if (gUnk_03003170.curLevel == 4 && sub_0800CDC0()) + shade = 0; + if (sub_0800CB9C()) { + if ((flags5778 & 1) == (who & 1)) + draw5778(&spr, dx + offX5778[(s16)d][0], dy + offX5778[(s16)d][1], (s16)d + 0x40, frame, shade); + } else { + draw5778(&spr, dx + offX5778[(s16)d][0], dy + offX5778[(s16)d][1], (s16)d + 0x40, frame, shade); + } + } + sub_080003F0(); + } +end: + m5778[who] &= ~(1 << slot); +#endif +} +struct Task60E8 { u32 f0, f4, f8, fC, f10, f14, f18, f1C, f20, f24; }; +struct Info60E8 { u32 who, i, a, pad, c, b; }; +extern u32 gMasks60E8[] asm("gUnk_030063E0"); +extern u8 *gLists60E8[] asm("gUnk_030063B0"); +extern u8 *gInfo60E8[] asm("gUnk_03006380"); +extern void sub_08000274_2(void *, void *) asm("sub_08000274"); +extern void sub_08075778(); +/* [StartPlayerFastAimedAttackProjectile] ABI r0=owner,r1=target word,r2=flags word,r3=lifetime parameter. + * Searches16 owner occupancy bits; full pool returns. Allocates0x3C0, stores task+20 pointer even on failure; + * zero returns. On success fills24-byte descriptor owner+0,slot+4,target WORD+8 (callback reads + * halfword),flags+14,parameter+10, leaving +C untouched; task priority0x34,callback75778,stack + * allocation+3BC,cleanup0. Scheduler ABI r0=task,r1=descriptor,then occupancy set. Starts asynchronous player + * projectile; no hit/completion status. Complete original configured body inspected and equal to local EU + * ROM/supplied verified-main ELF; static research only, no worker build or runtime testing. */ +void sub_080760E8(u32 who, u32 a, u32 b, u32 c) +{ + u32 i = 0; + vu32 *m; + u32 mem; + struct Task60E8 *t; + struct Info60E8 *e; + { + vu32 *mb = gMasks60E8; + m = &mb[who]; + } + while (*m & (1 << i)) { + i++; + if (i > 0xF) + return; + } + if (i > 0xF) + return; + mem = sub_08001494(0x3C0); + { + u8 *p = gLists60E8[who]; + t = (struct Task60E8 *)(i * 0x28 + (u32)p); + } + t->f20 = mem; + if (mem == 0) + return; + { + u8 *p = gInfo60E8[who]; + e = (struct Info60E8 *)(i * 0x18 + (u32)p); + } + e->who = who; + e->i = i; + e->a = a; + e->b = b; + e->c = c; + t->f8 = 0x34; + t->fC = (u32)sub_08075778; + t->f10 = mem + 0x3BC; + t->f24 = 0; + sub_08000274_2(t, e); + gMasks60E8[who] |= 1 << i; +} +struct Arg61A4 { u32 who; u32 slot; u16 target; u16 pad; u32 fC; s32 n; u32 flags; }; +struct Spr61A4 { u32 base, unused4; void *data; void *paletteResource; u32 resource, style; s32 mode; u8 palette[16]; s16 scale, step, upper, lower; }; +struct Ent61A4 { u16 xRaw, yRaw; }; +struct Ply61A4 { u16 id; u8 pad2[PLAYER_FIELD(0x20) - 2]; u16 state; u8 pad22[4]; u16 f26; u16 f28; u8 pad2A[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x2A)]; u32 flags; u8 pad34[6]; s16 power; u8 pad3C[0x2C]; u8 team; u8 pad69[0x23]; s32 x, y; u8 pad94[0x1E]; u16 ready; u8 padB4[0x28]; u32 serial; u8 padE0[0x18]; u32 hist[0xA]; u16 f120; u16 f122; u8 pad124[0x24]; struct Ent61A4 *entity; u8 pad14C[PLAYER_SIZE - PLAYER_FIELD(0x14C)];}; +struct Ene61A4 { u16 id; u16 f2; u8 pad4[8]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x2E]; u16 dmg; u8 pad4C[8]; u32 serial; u16 owner, hitMask; s16 hp; u8 pad5E[0x17E]; u8 team; u8 pad1DD[ENEMY_FIELD(0x206) - 0x1DD]; s16 power; u8 pad208[ENEMY_FIELD(0x22E) - ENEMY_FIELD(0x208)]; u8 w, h; u8 pad230[ENEMY_SIZE - ENEMY_FIELD(0x230)]; }; +struct Box61A4 { u32 w:16; u32 h:16; }; +struct Pos61A4 { s32 x, y; }; +extern struct Ply61A4 p61A4[] asm("gUnk_03003CE0"); +extern struct Ene61A4 *e61A4Base asm("gUnk_030056F4"); +extern u32 e61A4Mask asm("gUnk_030056FC"); +extern u32 m61A4[] asm("gUnk_030063E0"); +extern u8 *inv61A4 asm("gUnk_030034E0"); +extern u16 dir61A4[] asm("gUnk_0847AD0A"); +extern s16 sin61A4[] asm("gUnk_080B9704"); +extern s16 off61A4[][2] asm("gUnk_084EBEBC"); +extern s32 init61A4(void *, u32, u32, u32, u32) asm("sub_08065158"); +extern u16 step61A4(void *, u32, u16 *, u16 *, u32) asm("sub_08065370"); +extern u32 pos61A4(s32, s32, s16 *, s16 *, u32, u32) asm("sub_0800BC08"); +extern s32 draw61A4(s32, s32, u16, u16, u8, void *, void *, u32) asm("sub_08007870"); +extern void *tmpl61A4(void) asm("sub_0805AD18"); +extern s32 roll61A4(s32, s32) asm("sub_080223A4"); +extern s32 test61A4(struct Pos61A4 *, void *, struct Box61A4 *, struct Box61A4 *) asm("sub_08021FE0"); +extern s32 wall61A4(struct Pos61A4 *, struct Box61A4 *) asm("sub_0801F99C"); +extern void hitE61A4(void *, void *, void *, s32) asm("sub_0801F374"); +extern void hitP61A4(void *, void *, void *, s32) asm("sub_0801F79C"); +extern void pre61A4(void *) asm("sub_0801FD64"); +extern s16 atan61A4(s16, s16) asm("ArcTan2"); + +static inline s32 move61A4(s32 v, s32 spd) +{ + return v * spd; +} + +static inline s32 wait61A4(struct Ply61A4 *p, u32 n) +{ + while (p->ready < n) { + if (p->state == 10) + return 1; + sub_080003F0(); + } + return 0; +} + +void sub_080761A4_c(struct Arg61A4 *arg) asm("sub_080761A4"); +/* [RunPlayerAttackProjectileWithPiercingVariants] Descriptor pointer in r0: owner word+0, slot word+4, target + * halfword+8, parameter word+10, flags word+14. Player owner only; no owner bounds checks. Takes initial + * packed player coordinates and computes aim once toward target, falling back to facing; restored original + * target selects player-versus-enemy collision domain. Only local owner initializes attack template 0xC4 + * bytes, low16 serial from player+DC and power from signed halfword+3A (tripled when kind nonzero); remote + * paths may still read these uninitialized spills before authority checks. Flags bit15 enables a temporary + * player flag 0x200000 and cumulatively adds 0x18 to attack byte+A9 on successful rolls. */ +void sub_080761A4_c(struct Arg61A4 *arg) +{ +#ifdef REGION_USA + struct Spr61A4 spr; + u8 atk[ITEM_FIELD(0xC4)]; + s16 dx, dy; + u16 frame, timer; + u16 ang; + struct Pos61A4 pos; + struct Pos61A4 opos; + struct Box61A4 box; + struct Box61A4 box2; + struct Ene61A4 *e; + u16 target; + u32 lo; + u32 serial; + u32 kind; + s32 x, y; + s32 iter; + u32 dirIdx; + u16 local; + u32 base; + u32 big; + s32 power; + u32 who; + s32 n; + struct Ply61A4 *p; + struct Ply61A4 *q; + struct Ene61A4 *e2; + s32 d; + u16 j; + u32 cnt; + s32 t; + s32 hit; + s32 ok; + u8 c; + u8 shade; + s32 sx, sy; + s32 spd; + u32 delay; + + spd = 4; + local = sub_080020F4(); + target = arg->target; + who = arg->who; + kind = (u8)arg->flags; + n = arg->n; + p = &p61A4[who]; + ok = 0; + timer = 0; + frame = 0; + big = (u32)-(arg->flags & 0x8000) >> 31; + x = (p->entity->xRaw >> 4) << 8; + y = (u32)(p->entity->yRaw << 20) >> 12; + lo = (u32)(((u8 *)p->entity)[0] << 28) >> 28; + if (who == local) { + serial = (u16)p->serial; + { + void *src = tmpl61A4(); + memcpy(atk, src, ITEM_FIELD(0xC4)); + } + if (*(u16 *)(atk + ITEM_FIELD(0xBC)) == 0) { + u8 *iv = inv61A4; + iv += *(u16 *)(iv + SAVE_FIELD(0x68)) * 16; + *(u16 *)(atk + ITEM_FIELD(0xBC)) = iv[SAVE_FIELD(0x77)]; + } + if (kind != 0) + power = p->power * 3; + else + power = p->power; + } + if (kind == 0) { + init61A4(&spr, RES_ID(0x50021), 0, 0x80000000, 0); + base = 0x10; + } else { + init61A4(&spr, RES_ID(0x500C9), 0, 0x80000000, 0); + base = (u16)((kind - 1) * 8); + } + spr.palette[0] = who; + delay = 2; + if (target > 3) { + for (j = 0; j <= 4; j++) { + if (e61A4Mask & (1 << j)) { + e = &e61A4Base[j]; + if (e->state != 11 && e->f2 == target) + break; + } + } + if (j > 4) + target = 0xFF; + } + if (target != 0xFF) { + if (target > 3) { + dx = (e->x - x) >> 8; + dy = (e->y - y) >> 8; + /* d doubles as the angle temporary (ROM keeps it in r4). */ + d = (u16)atan61A4(dx, dy) >> 8; + t = (u8)d; + if (t > 0x80) + d = (u16)(t - 0x100); + ang = d; + { + s16 sa = ang; + if (sa < 0) + ang = sa + 0x100; + } + { + s16 sb = ang; + if (sb > 0x100) + ang = sb - 0x100; + } + } else { + dx = (p61A4[target].entity->xRaw >> 4) - (x >> 8); + dy = ((u32)(p61A4[target].entity->yRaw << 20) >> 20) - (y >> 8); + d = (u16)atan61A4(dx, dy) >> 8; + t = (u8)d; + if (t > 0x80) + d = (u16)(t - 0x100); + ang = d; + { + s16 sa = ang; + if (sa < 0) + ang = sa + 0x100; + } + { + s16 sb = ang; + if (sb > 0x100) + ang = sb - 0x100; + } + } + } else { + ang = dir61A4[((u8 *)p->entity)[3] >> 4]; + } + if (target == 0xFF) + target = arg->target; + x += move61A4(sin61A4[(s16)ang + 0x40] * 2, spd); + y += move61A4(sin61A4[(s16)ang] * 2, spd); + while (p->ready < delay) { + if (p->state == 10) { + m61A4[who] &= ~(1 << arg->slot); + return; + } + sub_080003F0(); + } + iter = n * 18 / 10 + 10; + if (p->state != 13 && !sub_0800CCCC() && !sub_0800CD34() && n > 0) + sub_0805865C(n + 0x100); + if (who == local) + pre61A4(&p61A4[who]); + dirIdx = ((u8 *)p->entity)[3] >> 4; + while (iter-- != 0 && !sub_08056E90() && p->state != 11 && p->state != 12 && !sub_0800D11C()) { + hit = 0; + pos.x = x; + pos.y = y; + box.w = 8; + box.h = 8; + if (target <= 3) { + box2.w = 0x10; + box2.h = 0x10; + cnt = sub_08002164(); + for (j = 0; j < cnt; j++) { + if (who == j) + continue; + if (sub_0800CDF8()) + break; + q = &p61A4[j]; + if (q->team == p->team || q->team == 0) + continue; + if ((u32)(((u8 *)q->entity)[0] << 28) >> 28 == 14) + continue; + opos.x = (q->entity->xRaw >> 4) << 8; + opos.y = (u32)(q->entity->yRaw << 20) >> 12; + if (!test61A4(&pos, &opos, &box, &box2)) + continue; + if (q->state != 11 && q->hist[who] != serial && !(q->flags & 0x2000)) + ok = 1; + else + ok = 0; + if (!ok) + continue; + if (roll61A4(power, q->power)) { + if (big) { + atk[ITEM_FIELD(0xA9)] += 0x18; + sub_08022100(q->id); + p->flags |= 0x200000; + } + if (who == sub_080020F4()) { + u16 s = p->state; + u16 f; + p->state = lo; + f = p->f26; + p->f26 = kind; + hitP61A4(p, q, atk, 0); + p->state = s; + p->f26 = f; + q->hist[p->id] = serial; + sub_0805865C(0x1A); + } + if (big) + p->flags &= ~0x200000; + hit = 1; + } else if (!(sub_0800086C() & 1)) { + if (who == sub_080020F4()) { + u16 s = p->state; + u16 f; + p->state = lo; + f = p->f26; + p->f26 = kind; + hitP61A4(p, q, atk, 1); + p->state = s; + p->f26 = f; + q->hist[p->id] = serial; + sub_0805865C(0x1A); + } + hit = 1; + } else { + if (who == sub_080020F4()) { + sub_080223F4(q->x, q->y); + q->hist[p->id] = serial; + if (!sub_0800CCCC() && !sub_0800CD34()) + sub_0805865C(0x55); + } + hit = 1; + } + } + } else { + for (j = 0; j <= 4 && !sub_0800CDF8(); j++) { + if (!(e61A4Mask & (1 << j))) + continue; + e2 = &e61A4Base[j]; + if (e2->team == p->team || e2->team == 0) + continue; + box2.w = e2->w; + box2.h = e2->h; + if (!test61A4(&pos, &e2->x, &box, &box2)) + continue; + if (e2->state != 11 && e2->serial != serial && !((e2->hp - e2->dmg) & 0x8000) && e2->hp != e2->dmg) + ok = 1; + else + ok = 0; + if (!ok) + continue; + if (roll61A4(power, e2->power)) { + if (big) { + atk[ITEM_FIELD(0xA9)] += 0x18; + sub_08022100(e->id + 4); + p->flags |= 0x200000; + } + if (who == local) { + u16 s = p->state; + u16 f; + p->state = lo; + f = p->f26; + p->f26 = kind; + hitE61A4(p, e2, atk, 0); + p->state = s; + p->f26 = f; + e2->owner = who; + e2->hitMask |= 1 << who; + sub_0805865C(0x1A); + } + if (big) + p->flags &= ~0x200000; + } else if (who == local) { + register u32 b asm("r1") = sub_0800086C() & 1; + if (!b) { + u16 s = p->state; + u16 f; + p->state = lo; + f = p->f26; + p->f26 = kind; + hitE61A4(p, e2, atk, 1); + p->state = s; + p->f26 = f; + e2->owner = who; + e2->hitMask |= 1 << who; + sub_0805865C(0x1A); + } else { + sub_080223F4(e2->x, e2->y); + e2->serial = serial; + if (!sub_0800CCCC() && !sub_0800CD34()) + sub_0805865C(0x55); + } + } + hit = 1; + } + } + if (who == local && wall61A4(&pos, &box)) + hit = 1; + if (kind == 0 && hit) + break; + c = sub_0800AE50(x, y, 0); + if ((c & 0xF) && !(c & 0x10)) + break; + x += move61A4(sin61A4[(s16)ang + 0x40], spd); + y += move61A4(sin61A4[(s16)ang], spd); + if (!sub_0800CC98() && !sub_0800CD8C() && !sub_0800CCCC()) { + pos61A4((s16)(sx = x >> 8), (s16)(sy = y >> 8), &dx, &dy, 0x30, 0); + shade = sub_0800BC44(sx, sy, 0); + d = dirIdx; + step61A4(&spr, (u16)(base + d), &frame, &timer, 1); + if (gUnk_03003170.curLevel == 4 && sub_0800CDC0()) + shade = 0; + draw61A4(dx + off61A4[(s16)d][0], dy + off61A4[(s16)d][1], base + d, frame, shade, spr.palette, spr.data, spr.base); + } + sub_080003F0(); + } + if (who == local && p->state == 5) { + p->state = 0; + p->f122 = 0; + p->f28 = kind; + } + m61A4[who] &= ~(1 << arg->slot); +#else + struct Spr61A4 spr; + u8 atk[0xC4]; + s16 dx, dy; + u16 frame, timer; + u16 ang; + struct Pos61A4 pos; + struct Pos61A4 opos; + struct Box61A4 box; + struct Box61A4 box2; + struct Ene61A4 *e; + u16 target; + u32 lo; + u32 serial; + u32 kind; + s32 x, y; + s32 iter; + u32 dirIdx; + u16 local; + u32 base; + u32 big; + s32 power; + u32 who; + s32 n; + struct Ply61A4 *p; + struct Ply61A4 *q; + struct Ene61A4 *e2; + s32 d; + u16 j; + u32 cnt; + s32 t; + s32 hit; + s32 ok; + u8 c; + u8 shade; + s32 sx, sy; + s32 spd; + u32 delay; + + spd = 4; + local = sub_080020F4(); + target = arg->target; + who = arg->who; + kind = (u8)arg->flags; + n = arg->n; + p = &p61A4[who]; + ok = 0; + timer = 0; + frame = 0; + big = (u32)-(arg->flags & 0x8000) >> 31; + x = (p->entity->xRaw >> 4) << 8; + y = (u32)(p->entity->yRaw << 20) >> 12; + lo = (u32)(((u8 *)p->entity)[0] << 28) >> 28; + if (who == local) { + serial = (u16)p->serial; + { + void *src = tmpl61A4(); + memcpy(atk, src, 0xC4); + } + if (*(u16 *)(atk + 0xBC) == 0) { + u8 *iv = inv61A4; + iv += *(u16 *)(iv + 0x68) * 16; + *(u16 *)(atk + 0xBC) = iv[0x77]; + } + if (kind != 0) + power = p->power * 3; + else + power = p->power; + } + if (kind == 0) { + init61A4(&spr, 0x50021, 0, 0x80000000, 0); + base = 0x10; + } else { + init61A4(&spr, 0x500C9, 0, 0x80000000, 0); + base = (u16)((kind - 1) * 8); + } + spr.palette[0] = who; + delay = 2; + if (target > 3) { + for (j = 0; j <= 4; j++) { + if (e61A4Mask & (1 << j)) { + e = &e61A4Base[j]; + if (e->state != 11) + if (e->f2 == target) + goto found; + } + } + found: + if (j > 4) + target = 0xFF; + } + if (target != 0xFF) { + if (target > 3) { + dx = (e->x - x) >> 8; + dy = (e->y - y) >> 8; + /* hit doubles as the angle temporary (ROM keeps it in r4). */ + hit = (u16)atan61A4(dx, dy) >> 8; + t = (u8)hit; + if (t > 0x80) + hit = (u16)(t - 0x100); + ang = hit; + { + s16 sa = ang; + if (sa < 0) + ang = sa + 0x100; + } + { + s16 sb = ang; + if (sb > 0x100) + ang = sb - 0x100; + } + } else { + struct Ent61A4 *te = p61A4[target].entity; + dx = (te->xRaw >> 4) - (x >> 8); + dy = ((u32)(te->yRaw << 20) >> 20) - (y >> 8); + hit = (u16)atan61A4(dx, dy) >> 8; + t = (u8)hit; + if (t > 0x80) + hit = (u16)(t - 0x100); + ang = hit; + { + s16 sa = ang; + if (sa < 0) + ang = sa + 0x100; + } + { + s16 sb = ang; + if (sb > 0x100) + ang = sb - 0x100; + } + } + } else { + ang = dir61A4[((u8 *)p->entity)[3] >> 4]; + } + if (target == 0xFF) + target = arg->target; + x += move61A4(sin61A4[(s16)ang + 0x40] * 2, spd); + y += move61A4(sin61A4[(s16)ang] * 2, spd); + while (p->ready < delay) { + if (p->state == 10) { + m61A4[who] &= ~(1 << arg->slot); + return; + } + sub_080003F0(); + } + iter = n * 18 / 10 + 10; + if (p->state != 13 && !sub_0800CCCC() && !sub_0800CD34() && n > 0) + sub_0805865C(n + 0x100); if (who == local) pre61A4(&p61A4[who]); dirIdx = ((u8 *)p->entity)[3] >> 4; @@ -1769,10 +2493,11 @@ void sub_080761A4_c(struct Arg61A4 *arg) p->f28 = kind; } m61A4[who] &= ~(1 << arg->slot); +#endif } struct TaskA88 { u32 f0, f4, f8, fC, f10, f14, f18, f1C, f20, f24; }; struct InfoA88 { u32 who, i, a, pad, c, b; }; -struct PlayerA88 { u8 pad[0x20]; u16 state; u8 pad22[6]; u16 f28; u8 pad2a[0xf8]; u16 f122; u8 pad124[0x28]; }; +struct PlayerA88 { u8 pad[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x28) - PLAYER_FIELD(0x22)]; u16 f28; u8 pad2a[PLAYER_FIELD(0x122) - (PLAYER_FIELD(0x28) + 0x2)]; u16 f122; u8 pad124[PLAYER_SIZE - PLAYER_FIELD(0x124)]; }; extern u32 masksA88[] asm("gUnk_030063E0"); extern u8 *listsA88[] asm("gUnk_030063B0"); extern u8 *infoA88[] asm("gUnk_03006380"); @@ -1857,8 +2582,8 @@ void sub_08076A88(u32 who, u32 a, u32 b, u32 c) { struct Arg6BA0 { u32 who; u32 slot; u16 target; u16 pad; u32 fC; u16 f10; u16 spread; u32 flags; }; struct Spr6BA0 { u32 base, unused4; void *data; void *paletteResource; u32 resource, style; s32 mode; u8 palette[16]; s16 scale, step, upper, lower; }; struct Ent6BA0 { u16 xRaw, yRaw; }; -struct Ply6BA0 { u16 id; u8 pad2[0x1E]; u16 state; u8 pad22[4]; u16 f26; u8 pad28[8]; u32 flags; u8 pad34[6]; s16 power; u8 pad3C[0x2C]; u8 team; u8 pad69[0x23]; s32 x, y; u8 pad94[0x1E]; u16 ready; u8 padB4[0x28]; u32 serial; u8 padE0[0x18]; u32 hist[0x13]; struct Ent6BA0 *entity2; struct Ent6BA0 *entity; }; -struct Ene6BA0 { u16 id; u16 f2; u8 pad4[8]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x2E]; u16 dmg; u8 pad4C[8]; u32 serial; u16 owner, hitMask; s16 hp; u8 pad5E[0x17E]; u8 team; u8 pad1DD[0x29]; s16 power; u8 pad208[0x26]; u8 w, h; u8 pad230[0xB0]; }; +struct Ply6BA0 { u16 id; u8 pad2[PLAYER_FIELD(0x20) - 2]; u16 state; u8 pad22[4]; u16 f26; u8 pad28[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x28)]; u32 flags; u8 pad34[6]; s16 power; u8 pad3C[0x2C]; u8 team; u8 pad69[0x23]; s32 x, y; u8 pad94[0x1E]; u16 ready; u8 padB4[0x28]; u32 serial; u8 padE0[0x18]; u32 hist[0x13]; struct Ent6BA0 *entity2; struct Ent6BA0 *entity; u8 pad14C[PLAYER_SIZE - PLAYER_FIELD(0x14C)];}; +struct Ene6BA0 { u16 id; u16 f2; u8 pad4[8]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x2E]; u16 dmg; u8 pad4C[8]; u32 serial; u16 owner, hitMask; s16 hp; u8 pad5E[0x17E]; u8 team; u8 pad1DD[ENEMY_FIELD(0x206) - 0x1DD]; s16 power; u8 pad208[ENEMY_FIELD(0x22E) - ENEMY_FIELD(0x208)]; u8 w, h; u8 pad230[ENEMY_SIZE - ENEMY_FIELD(0x230)]; }; struct Box6BA0 { u32 w:16; u32 h:16; }; struct Pos6BA0 { s32 x, y; }; extern struct Ply6BA0 p6BA0[] asm("gUnk_03003CE0"); @@ -1897,7 +2622,7 @@ void sub_08076BA0(struct Arg6BA0 *arg) { s16 ang; /* declared first: orders the GCSE copies of ang and who*4 on the stack as in ROM */ struct Spr6BA0 spr; - u8 atk[0xC4]; + u8 atk[ITEM_FIELD(0xC4)]; s16 dx, dy; struct Pos6BA0 pos; struct Pos6BA0 opos; @@ -1932,7 +2657,7 @@ void sub_08076BA0(struct Arg6BA0 *arg) spd = 5; local = sub_080020F4(); - init6BA0(&spr, 0x5002E, 0, 0x80000000, 0); + init6BA0(&spr, RES_ID(0x5002E), 0, 0x80000000, 0); target = arg->target; who = arg->who; slot = arg->slot; @@ -1951,12 +2676,12 @@ void sub_08076BA0(struct Arg6BA0 *arg) serial = (u16)p->serial; { void *src = tmpl6BA0(); - memcpy(atk, src, 0xC4); + memcpy(atk, src, ITEM_FIELD(0xC4)); } - if (*(u16 *)(atk + 0xBC) == 0) { + if (*(u16 *)(atk + ITEM_FIELD(0xBC)) == 0) { u8 *iv = inv6BA0; - iv += *(u16 *)(iv + 0x68) * 16; - *(u16 *)(atk + 0xBC) = iv[0x77]; + iv += *(u16 *)(iv + SAVE_FIELD(0x68)) * 16; + *(u16 *)(atk + ITEM_FIELD(0xBC)) = iv[SAVE_FIELD(0x77)]; } if (kind != 0) power = p->power * 3; @@ -1967,12 +2692,19 @@ void sub_08076BA0(struct Arg6BA0 *arg) for (j = 0; j <= 4; j++) { if (e6BA0Mask & (1 << j)) { e = &e6BA0Base[j]; +#ifdef REGION_USA + if (e->state != 11 && e->f2 == target) + break; +#else if (e->state != 11) if (e->f2 == target) goto found; +#endif } } +#ifndef REGION_USA found: +#endif if (j > 4) target = 0xFF; } @@ -1996,9 +2728,14 @@ void sub_08076BA0(struct Arg6BA0 *arg) ang = sa - 0x100; } } else { +#ifdef REGION_USA + dx = (p6BA0[target].entity->xRaw >> 4) - (x >> 8); + dy = ((u32)(p6BA0[target].entity->yRaw << 20) >> 20) - (y >> 8); +#else struct Ent6BA0 *te = p6BA0[target].entity; dx = (te->xRaw >> 4) - (x >> 8); dy = ((u32)(te->yRaw << 20) >> 20) - (y >> 8); +#endif hit = (u16)atan6BA0(dx, dy) >> 8; t = (u8)hit; if (t > 0x80) @@ -2087,7 +2824,7 @@ void sub_08076BA0(struct Arg6BA0 *arg) goto pnext; if (roll6BA0(power, q->power)) { if (big) { - atk[0xA9] += 0x18; + atk[ITEM_FIELD(0xA9)] += 0x18; sub_08022100(q->id); p->flags |= 0x200000; } @@ -2148,7 +2885,7 @@ void sub_08076BA0(struct Arg6BA0 *arg) continue; if (roll6BA0(power, e2->power)) { if (big) { - atk[0xA9] += 0x18; + atk[ITEM_FIELD(0xA9)] += 0x18; sub_08022100(e->id + 4); p->flags |= 0x200000; } @@ -2268,8 +3005,8 @@ void sub_08077444(u32 who, u32 a, u32 b, u32 c, u32 d) gMasks7444[who] |= 1 << i; } struct Spr7508 { u32 f0, f4, f8, fC; u8 pad10[12]; u8 f1C, f1D; u8 pad1E[2]; u8 f20; u8 pad21[19]; }; -struct Ply7508 { u8 pad0[0xC]; u16 fC; u8 padE[0x12]; u16 state; u8 pad22[0xE]; u32 flags; u8 pad34[6]; s16 f3A; u8 pad3C[0x2C]; u8 team; u8 pad69[5]; u8 f6E; u8 pad6F[0x19]; u16 f88, f8A; s32 x, y; u8 pad94[0x50]; u32 hist[11]; u32 f110; u8 pad114[0x34]; u16 *pos; }; -struct Ene7508 { u16 id; u8 f2; u8 pad3[5]; s16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x2E]; u16 f4A; u32 f4C; u32 f50; u32 f54; u16 f58, f5A; u8 pad5C[6]; u16 f62; u8 pad64[6]; u16 wait; u8 pad6C[0xE]; u16 f7A; u16 f7C, f7E; u8 pad80[0x15C]; u8 active; u8 pad1DD[0x29]; s16 f206; u8 pad208[0x1E]; u8 f226; u8 pad227[4]; u8 threshold; u16 f22C; u8 pad22E[0xAA]; u16 f2D8, f2DA; u8 pad2DC[4]; }; +struct Ply7508 { u8 pad0[PLAYER_FIELD(0xC)]; u16 fC; u8 padE[PLAYER_FIELD(0x20) - PLAYER_FIELD(0xE)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x3A) - PLAYER_FIELD(0x34)]; s16 f3A; u8 pad3C[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x3C)]; u8 team; u8 pad69[PLAYER_FIELD(0x6E) - PLAYER_FIELD(0x69)]; u8 f6E; u8 pad6F[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x6F)]; u16 f88, f8A; s32 x, y; u8 pad94[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0x94)]; u32 hist[11]; u32 f110; u8 pad114[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x114)]; u16 *pos; }; +struct Ene7508 { u16 id; u8 f2; u8 pad3[5]; s16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x2E]; u16 f4A; u32 f4C; u32 f50; u32 f54; u16 f58, f5A; u8 pad5C[6]; u16 f62; u8 pad64[6]; u16 wait; u8 pad6C[0xE]; u16 f7A; u16 f7C, f7E; u8 pad80[0x15C]; u8 active; u8 pad1DD[ENEMY_FIELD(0x206) - 0x1DD]; s16 f206; u8 pad208[ENEMY_FIELD(0x226) - ENEMY_FIELD(0x208)]; u8 f226; u8 pad227[4]; u8 threshold; u16 f22C; u8 pad22E[ENEMY_FIELD(0x2D8) - ENEMY_FIELD(0x22E)]; u16 f2D8, f2DA; u8 pad2DC[ENEMY_SIZE - ENEMY_FIELD(0x2DC)]; }; struct Tbl7508 { u8 pad0[0x2C]; u32 anim; u8 pad30[0x28]; }; struct Pkt7508 { u8 kind:8; u8 val:8; u8 b2:8; s8 b3:8; u32 dmg:16; u32 rest:16; }; extern struct Ply7508 p7508[] asm("gUnk_03003CE0"); @@ -2334,12 +3071,12 @@ void sub_08077508(u32 who, u32 arg) if (e->f226 != 3) { init7508(&spr, tbl7508[e->f2D8 + 10].anim, 0, -1, 0); spr.f1C = sub_08019D7C(e->f2D8, e->f2DA); - if (tbl7508[e->f2D8 + 10].anim == 0x500C0) + if (tbl7508[e->f2D8 + 10].anim == RES_ID(0x500C0)) pal = 0x10; else pal = 8; } else { - init7508(&spr, 0x5001E, 0, -1, 0); + init7508(&spr, RES_ID(0x5001E), 0, -1, 0); spr.f20 = who; pal = 0x40; } @@ -2487,7 +3224,7 @@ void sub_08077508(u32 who, u32 arg) if (sub_08002204() != 0) { te->state = 10; pkt.dmg = dmgE7508(e, te); - pkt.val = cfg[0xBC]; + pkt.val = cfg[ITEM_FIELD(0xBC)]; pkt.b2 = 0; pkt.b3 = 0; te->f54 = e->f50; @@ -2576,8 +3313,8 @@ void sub_08077D04(u32 who, u32 b) gMasks7D04[who] |= 1 << i; } struct Spr7DAC { u32 f0, f4, f8, fC; u8 pad10[12]; u8 f1C, f1D; u8 pad1E[22]; }; -struct Ply7DAC { u8 pad0[0x20]; u16 state; u8 pad22[0xE]; u32 flags; u8 pad34[6]; s16 f3A; u8 pad3C[0x2C]; u8 team; u8 pad69[5]; u8 f6E; u8 pad6F[0x19]; u16 f88, f8A; s32 x, y; u8 pad94[0x50]; u32 hist[11]; u32 f110; u8 pad114[0x34]; u8 *sprite; }; -struct Ene7DAC { u16 id; u8 f2; u8 pad3[5]; s16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x2E]; u16 f4A; u32 f4C; u32 f50; u32 f54; u16 f58, f5A; u8 pad5C[6]; u16 f62; u8 pad64[6]; u16 wait; u8 pad6C[0xE]; u16 f7A; u16 f7C, f7E; u8 pad80[0x15C]; u8 active; u8 pad1DD[0x29]; s16 f206; u8 pad208[0x23]; u8 threshold; u16 f22C; u8 pad22E[0xAA]; u16 f2D8, f2DA; u8 pad2DC[4]; }; +struct Ply7DAC { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x3A) - PLAYER_FIELD(0x34)]; s16 f3A; u8 pad3C[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x3C)]; u8 team; u8 pad69[PLAYER_FIELD(0x6E) - PLAYER_FIELD(0x69)]; u8 f6E; u8 pad6F[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x6F)]; u16 f88, f8A; s32 x, y; u8 pad94[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0x94)]; u32 hist[11]; u32 f110; u8 pad114[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x114)]; u8 *sprite; }; +struct Ene7DAC { u16 id; u8 f2; u8 pad3[5]; s16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x2E]; u16 f4A; u32 f4C; u32 f50; u32 f54; u16 f58, f5A; u8 pad5C[6]; u16 f62; u8 pad64[6]; u16 wait; u8 pad6C[0xE]; u16 f7A; u16 f7C, f7E; u8 pad80[0x15C]; u8 active; u8 pad1DD[ENEMY_FIELD(0x206) - 0x1DD]; s16 f206; u8 pad208[ENEMY_FIELD(0x22B) - ENEMY_FIELD(0x208)]; u8 threshold; u16 f22C; u8 pad22E[ENEMY_FIELD(0x2D8) - ENEMY_FIELD(0x22E)]; u16 f2D8, f2DA; u8 pad2DC[ENEMY_SIZE - ENEMY_FIELD(0x2DC)]; }; struct Tbl7DAC { u8 pad0[0x2C]; u32 anim; u8 pad30[0x28]; }; struct Pkt7DAC { u8 kind:8; u8 val:8; u8 b2:8; s8 b3:8; u32 dmg:16; u32 rest:16; }; extern struct Ply7DAC p7DAC[] asm("gUnk_03003CE0"); @@ -2645,7 +3382,7 @@ void sub_08077DAC(u32 who, u32 arg) e = &e7DACBase[who]; init7DAC(&spr, tbl7DAC[e->f2D8 + 10].anim, 0, -1, 0); spr.f1C = sub_08019D7C(e->f2D8, e->f2DA); - if (tbl7DAC[e->f2D8 + 10].anim == 0x500C0) + if (tbl7DAC[e->f2D8 + 10].anim == RES_ID(0x500C0)) pal = 0x10; else pal = 8; @@ -2761,7 +3498,7 @@ void sub_08077DAC(u32 who, u32 arg) if (roll7DAC(e->f206, te->f206) != 0) { te->state = 10; pkt.dmg = dmgE7DAC(e, te); - pkt.val = cfg[0xBC]; + pkt.val = cfg[ITEM_FIELD(0xBC)]; pkt.b2 = 0; pkt.b3 = 0; te->f54 = e->f50; @@ -2857,8 +3594,8 @@ void sub_0807854C(u32 who, u32 b) } struct Spr85F4 { u32 f0, f4, f8, fC; u8 pad10[12]; u8 f1C, f1D; u8 pad1E[22]; }; struct Pos85F4 { u16 h0; u16 h2; }; -struct Ply85F4 { u8 pad0[0x30]; u32 flags; u8 pad34[0x34]; u8 team; u8 pad69[0x23]; s32 x, y; u8 pad94[0xB4]; struct Pos85F4 *pos; }; -struct Ene85F4 { u16 id; u8 pad2[6]; s16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x4E]; u16 wait; u8 pad6C[0xE]; u16 f7A; u8 pad7C[0x160]; u8 active; u8 pad1DD[0x20]; u8 f1FD; u8 pad1FE[0x2D]; u8 threshold; u16 f22C; u8 pad22E[0xAA]; u16 f2D8, f2DA; u8 pad2DC[4]; }; +struct Ply85F4 { u8 pad0[PLAYER_FIELD(0x30)]; u32 flags; u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 team; u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x, y; u8 pad94[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x94)]; struct Pos85F4 *pos; }; +struct Ene85F4 { u16 id; u8 pad2[6]; s16 dir; u8 padA[2]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x4E]; u16 wait; u8 pad6C[0xE]; u16 f7A; u8 pad7C[0x160]; u8 active; u8 pad1DD[0x20]; u8 f1FD; u8 pad1FE[ENEMY_FIELD(0x22B) - 0x1FE]; u8 threshold; u16 f22C; u8 pad22E[ENEMY_FIELD(0x2D8) - ENEMY_FIELD(0x22E)]; u16 f2D8, f2DA; u8 pad2DC[ENEMY_SIZE - ENEMY_FIELD(0x2DC)]; }; struct Off85F4 { s16 x, y; }; extern struct Ply85F4 p85F4[] asm("gUnk_03003CE0"); extern struct Ene85F4 *e85F4Base asm("gUnk_030056F4"); @@ -2909,7 +3646,7 @@ void sub_080785F4(u32 who, u32 arg) local = (u16)sub_080020F4(); e = &e85F4Base[who]; - init85F4(&spr, 0x500AF, 0, 0x80000000, 0); + init85F4(&spr, RES_ID(0x500AF), 0, 0x80000000, 0); spr.f1C = sub_08019D7C(e->f2D8, e->f2DA); if (e->f1FD == 0x14) { kind = 0; @@ -3086,9 +3823,9 @@ void sub_08078B24(u32 who, u32 b) gMasks7D04[who] |= 1 << i; } struct AttrBCC { u32 kind:4; u32 x:12; u32 y:12; u32 pad:4; u32 flags:6; u32 pad2:4; u32 on:1; u32 power:8; u32 pad3:13; }; -struct PlayerBCC { u16 id; u8 pad02[0x1e]; u16 state; u8 pad22[0xe]; u32 flags; u8 pad34[0x34]; u8 team; u8 pad69[0x1f]; u16 hp; u8 pad8a[2]; s32 pos[2]; u8 pad94[0x2e]; u16 unkC2; s16 unkC4; u8 padc6[0x32]; s32 tags[15]; u16 unk134; u8 pad136[0x12]; struct AttrBCC *attr; }; +struct PlayerBCC { u16 id; u8 pad02[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x2)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 team; u8 pad69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; u16 hp; u8 pad8a[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x8A)]; s32 pos[2]; u8 pad94[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0x94)]; u16 unkC2; s16 unkC4; u8 padc6[PLAYER_FIELD(0xF8) - PLAYER_FIELD(0xC6)]; s32 tags[15]; u16 unk134; u8 pad136[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x136)]; struct AttrBCC *attr; }; struct SpriteBCC { u32 f0, f4, f8; void *fC; u8 pad10[12]; u8 unk1C, unk1D; u8 pad1e[22]; }; -struct EnemyBCC { u16 id; u8 unk2; u8 pad03[9]; u16 state; u8 pad0e[6]; s32 pos[2]; u8 pad1c[0x2e]; u16 hp; u32 dmg; u8 pad50[4]; s32 tag; u16 unk58, unk5A; s16 unk5C; u8 pad5e[4]; u16 unk62; u8 pad64[0x18]; u16 unk7C; s16 unk7E; u8 pad80[0x15c]; u8 team; u8 pad1dd[0x51]; u8 w, h; u8 pad230[0xb0]; }; +struct EnemyBCC { u16 id; u8 unk2; u8 pad03[9]; u16 state; u8 pad0e[6]; s32 pos[2]; u8 pad1c[0x2e]; u16 hp; u32 dmg; u8 pad50[4]; s32 tag; u16 unk58, unk5A; s16 unk5C; u8 pad5e[4]; u16 unk62; u8 pad64[0x18]; u16 unk7C; s16 unk7E; u8 pad80[0x15c]; u8 team; u8 pad1dd[ENEMY_FIELD(0x22E) - 0x1DD]; u8 w, h; u8 pad230[ENEMY_SIZE - ENEMY_FIELD(0x230)]; }; struct BoxBCC { u16 w, h; }; struct VecBCC { s32 x, y; }; struct PacketBCC { u8 player:8; u8 power:8; u8 impulse:8; s8 direction:8; u32 amount:16; u32 unused:16; }; @@ -3143,8 +3880,14 @@ void sub_08078BCC(s32 who, s32 bit) s32 r; s32 mode; /* constant 0, rematerialized as `movs r3, #0; cmp r3, #0` */ +#ifdef REGION_USA + /* Emit nothing; the instruction count sets the GCSE hash size, which orders the spill slots. */ +#define PAD8 asm(""); asm(""); asm(""); asm(""); asm(""); asm(""); asm(""); asm(""); + PAD8 PAD8 PAD8 PAD8 asm(""); asm(""); +#undef PAD8 +#endif local = sub_080020F4(); - initBCC(&spr, 0x500A9, 8, -1, 0); + initBCC(&spr, RES_ID(0x500A9), 8, -1, 0); spr.unk1C = 7; spr.unk1D = 8; for (i = 0; i < 2; i++) @@ -3442,8 +4185,8 @@ struct Info458 { u32 who, i, a, c, d, b; }; extern u32 gMasks458[] asm("gUnk_030063E0"); struct Spr458 { u32 f0, f4, f8, fC; u8 p10[12]; u8 f1C, f1D; u8 p1E[22]; }; struct Box458 { u16 w, h; }; -struct Pl458 { u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; u8 p34[0x34]; u8 active; u8 p69[5]; u8 b6E; u8 p6F[0x1D]; s32 pos[2]; u8 p94[0x74]; u32 lastHit; u8 p10C[0x40]; }; -struct En458 { u8 p0[0x14]; s32 pos[2]; u8 p1C[0x38]; u32 lastHit; u8 p58[0x184]; u8 active; u8 p1DD[0x51]; u8 bw, bh; u8 p230[0xB0]; }; +struct Pl458 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 p69[PLAYER_FIELD(0x6E) - PLAYER_FIELD(0x69)]; u8 b6E; u8 p6F[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x6F)]; s32 pos[2]; u8 p94[PLAYER_FIELD(0x108) - PLAYER_FIELD(0x94)]; u32 lastHit; u8 p10C[PLAYER_SIZE - PLAYER_FIELD(0x10C)]; }; +struct En458 { u8 p0[0x14]; s32 pos[2]; u8 p1C[0x38]; u32 lastHit; u8 p58[0x184]; u8 active; u8 p1DD[ENEMY_FIELD(0x22E) - 0x1DD]; u8 bw, bh; u8 p230[ENEMY_SIZE - ENEMY_FIELD(0x230)]; }; extern struct Pl458 gPl458[] asm("gUnk_03003CE0"); extern struct En458 *gEn458 asm("gUnk_030056F4"); extern s32 sub_08065158_458(void *, u32, u32, u32, u32) asm("sub_08065158"); @@ -3474,7 +4217,11 @@ void sub_08079458(struct Info458 *info) u16 dmg; u32 k, who, i, big, local; u8 *obj; +#ifdef REGION_USA + register s32 timer asm("sl"); +#else s32 timer; +#endif u32 shade; u16 j; @@ -3490,7 +4237,7 @@ void sub_08079458(struct Info458 *info) i = info->i; phase = 0; frame = 0; - sub_08065158_458(&spr, 0x500AF, 0, 0x80000000, 0); + sub_08065158_458(&spr, RES_ID(0x500AF), 0, 0x80000000, 0); switch (info->c) { case 0: timer = 0xB4; @@ -3541,7 +4288,7 @@ void sub_08079458(struct Info458 *info) big = 1; break; } - k = obj[0xA8]; + k = obj[ITEM_FIELD(0xA8)]; asm(""::"r"(pp)); asm(""::"r"(pp)); asm(""::"r"(pp)); @@ -3665,8 +4412,8 @@ void sub_08079888(u32 who, u32 a, u32 b, u32 c, u32 d) } struct Spr948 { u32 f0, f4, f8, fC; u8 p10[12]; u8 f1C, f1D; u8 p1E[22]; }; struct Box948 { u16 w, h; }; -struct Pl948 { u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; u8 p34[0x34]; u8 active; u8 p69[0x23]; s32 pos[2]; u8 p94[0x74]; u32 lastHit; u8 p10C[0x40]; }; -struct En948 { u8 p0[0x14]; s32 pos[2]; u8 p1C[0x38]; u32 lastHit; u8 p58[0x184]; u8 active; u8 p1DD[0x51]; u8 bw, bh; u8 p230[0xB0]; }; +struct Pl948 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 p69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 pos[2]; u8 p94[PLAYER_FIELD(0x108) - PLAYER_FIELD(0x94)]; u32 lastHit; u8 p10C[PLAYER_SIZE - PLAYER_FIELD(0x10C)]; }; +struct En948 { u8 p0[0x14]; s32 pos[2]; u8 p1C[0x38]; u32 lastHit; u8 p58[0x184]; u8 active; u8 p1DD[ENEMY_FIELD(0x22E) - 0x1DD]; u8 bw, bh; u8 p230[ENEMY_SIZE - ENEMY_FIELD(0x230)]; }; extern struct Pl948 gPl948[] asm("gUnk_03003CE0"); extern struct En948 *gEn948 asm("gUnk_030056F4"); extern s32 sub_08065158_948(void *, u32, u32, u32, u32) asm("sub_08065158"); @@ -3705,7 +4452,7 @@ void sub_08079948(struct Info9888 *info) frame = 0; size = 0x00180020; counter = 0x88800000; - sub_08065158_948(&spr, 0x500AF, 0, 0x80000000, 0); + sub_08065158_948(&spr, RES_ID(0x500AF), 0, 0x80000000, 0); if (sub_0800CCCC() == 0 && sub_0800CD34() == 0) sub_0805865C(0x35); timer = 4; @@ -3714,7 +4461,7 @@ void sub_08079948(struct Info9888 *info) sub_08007870_948(dx, dy, 8, frame, shade, &spr.f1C, spr.f8, spr.f0); sub_080003F0(); } while (timer-- != 0); - sub_08065158_948(&spr, 0x5008C, 0, 0x80000000, 0); + sub_08065158_948(&spr, RES_ID(0x5008C), 0, 0x80000000, 0); sub_08000AF0(0x17, (void *)spr.fC, 2); spr.f1C = 7; spr.f1D = 8; @@ -3840,7 +4587,7 @@ void sub_08079D84(struct Info9888 *info, u32 packed) s32 y; u8 k; sub_080020F4(); - sub_08065158_5(&s, 0x5008C, 1, -1, 0); + sub_08065158_5(&s, RES_ID(0x5008C), 1, -1, 0); sub_08000AF0(0x17, (void *)s.fC, 2); s.b1C[0] = 7; s.b1C[1] = 8; @@ -3918,7 +4665,7 @@ s32 sub_08079FD0(s32 arg0) { var_r5 = 0x80000; loop_1: temp_r1 = sub_0806898C(arg0, var_r4) - 1; - if (((s32) temp_r1 >= 0) && ((s32) M2C_FIELD(temp_r6, s16 *, 0xC2) >= (s32) temp_r1)) { + if (((s32) temp_r1 >= 0) && ((s32) M2C_FIELD(temp_r6, s16 *, PLAYER_FIELD(0xC2)) >= (s32) temp_r1)) { return (s32) (var_r5 >> 0x10); } var_r5 += 0xFFFF0000; @@ -3986,7 +4733,7 @@ void sub_0807A0E0(void *arg0) { u8 *p = (u8 *)&gUnk_03003CE0[sub_080020F4()]; u16 d = sub_0806898C(M2C_FIELD(arg0, s32 *, 0xC), M2C_FIELD(arg0, s32 *, 0x14)) - 1; - u16 *f = (u16 *)(p + 0xC2); + u16 *f = (u16 *)(p + PLAYER_FIELD(0xC2)); u32 n = *f - d; *f = n; if ((s16)n < 0) @@ -4020,15 +4767,15 @@ u32 sub_0807A124(void) u8 *p = sub_08001494(sz); u8 *q = sub_08001494(sz); u32 r; - memcpy(p, (void *)gUnk_030034E0, 0xCA4); + memcpy(p, (void *)gUnk_030034E0, SAVE_FIELD(0xCA4)); memcpy(q, gUnk_03004210, 0x51C); - p[0xCA4] = Sum_A124(p, 0xCA4); + p[SAVE_FIELD(0xCA4)] = Sum_A124(p, SAVE_FIELD(0xCA4)); q[0x51C] = Sum_A124(q, 0x51C); - sub_08001B14(*(u16 *)(gUnk_030034E0 + 0xE), p); - r = (u16)sub_08001B14(*(u16 *)(gUnk_030034E0 + 0xE) + 8, q); + sub_08001B14(*(u16 *)(gUnk_030034E0 + SAVE_FIELD(0xE)), p); + r = (u16)sub_08001B14(*(u16 *)(gUnk_030034E0 + SAVE_FIELD(0xE)) + 8, q); if (r == 0) { - r = sub_08001B54(*(u16 *)(gUnk_030034E0 + 0xE), p); - r |= sub_08001B54(*(u16 *)(gUnk_030034E0 + 0xE) + 8, q); + r = sub_08001B54(*(u16 *)(gUnk_030034E0 + SAVE_FIELD(0xE)), p); + r |= sub_08001B54(*(u16 *)(gUnk_030034E0 + SAVE_FIELD(0xE)) + 8, q); if (r == 0) { sub_08001538((s32)p); sub_08001538((s32)q); @@ -4062,8 +4809,8 @@ s32 sub_0807A20C(u8 a) u8 *q = sub_08001494(sz); sub_08001B04_4(a, 0, p, sz); sub_08001B04_4(a + 8, 0, q, sz); - if (p[0xCA4] == Sum_A20C(p, 0xCA4) && q[0x51C] == Sum_A20C(q, 0x51C)) { - memcpy((void *)gUnk_030034E0, p, 0xCA4); + if (p[SAVE_FIELD(0xCA4)] == Sum_A20C(p, SAVE_FIELD(0xCA4)) && q[0x51C] == Sum_A20C(q, 0x51C)) { + memcpy((void *)gUnk_030034E0, p, SAVE_FIELD(0xCA4)); memcpy(gUnk_03004210, q, 0x51C); sub_08001538((s32)p); sub_08001538((s32)q); @@ -4081,13 +4828,13 @@ s32 sub_0807A20C(u8 a) * verification call follows. These buffers do not establish that every byte of each full flash sector is zero. */ s32 sub_0807A2E0(u8 a) { - u8 *p = sub_08001494(0xCA8); + u8 *p = sub_08001494(SAVE_FIELD(0xCA8)); u8 *q = sub_08001494(0x520); u8 *t; u32 i; - for (t = p, i = 0; i <= 0xCA7; i++) + for (t = p, i = 0; i <= SAVE_FIELD(0xCA7); i++) *t++ = 0; - p[0xCA4] = 0; + p[SAVE_FIELD(0xCA4)] = 0; while ((u16)sub_08001B14(a, p)) ; for (t = q, i = 0; i <= 0x51F; i++) @@ -4099,14 +4846,20 @@ s32 sub_0807A2E0(u8 a) sub_08001538((s32)q); return 1; } -struct Save378 { u32 w0; u8 p4[6]; u16 hA, hC; u8 pE[0xE]; u32 w1C, w20; u8 p24[8]; u32 w2C; }; -struct Sum378 { u8 valid, b1, b2, b3, b4, b5, b6, b7; u32 w8; u16 hC, hE; u8 name[12]; u32 a1C[8]; u32 a3C[12]; }; +struct Save378 { u32 w0; u8 p4[SAVE_FIELD(0xA) - 4]; u16 hA, hC; u8 pE[SAVE_FIELD(0x1C) - SAVE_FIELD(0xE)]; u32 w1C, w20; u8 p24[8]; u32 w2C; }; +struct Sum378 { u8 valid, b1, b2, b3, b4, b5, b6, b7; u32 w8; u16 hC, hE; +#ifdef REGION_USA + NameChar name[10]; +#else + NameChar name[12]; +#endif + u32 a1C[8]; u32 a3C[12]; }; struct Blk20_378 { u32 w[8]; }; struct Blk30_378 { u32 w[12]; }; extern struct Save378 *gSave378 asm("gUnk_030034E0"); struct Opt378 { u32 w0, w4; u8 p8[0x14]; u16 h1C, h1E; u8 p20[0xC]; u32 w2C; }; extern struct Opt378 *gSave4210_378 asm("gUnk_03004210"); -struct Pl378 { u8 p0[0x58]; struct Blk30_378 b58; u8 p88[0xC4]; }; +struct Pl378 { u8 p0[PLAYER_FIELD(0x58)]; struct Blk30_378 b58; u8 p88[PLAYER_SIZE - PLAYER_FIELD(0x88)]; }; extern struct Pl378 gPl378[] asm("gUnk_03003CE0"); extern s32 sub_0807A20C(u8); extern void sub_08013850(); @@ -4131,7 +4884,7 @@ u32 sub_0807A378(struct Sum378 *e) do { if (sub_0807A20C(i) == 0) { vu16 z = 0; - CpuSet_378((void *)&z, e, 0x01000036); + CpuSet_378((void *)&z, e, 0x01000000 | sizeof(struct Sum378) / 2); i++; } else { struct Save378 *s; @@ -4164,12 +4917,12 @@ u32 sub_0807A378(struct Sum378 *e) } sub_0801E024(&gPl378[sub_080020F4()]); sub_0801DD9C(); - *(struct Blk20_378 *)e->a1C = *(struct Blk20_378 *)((u8 *)gSave378 + 0x10); + *(struct Blk20_378 *)e->a1C = *(struct Blk20_378 *)((u8 *)gSave378 + SAVE_FIELD(0x10)); *(struct Blk30_378 *)e->a3C = gPl378[sub_080020F4()].b58; j = 0; i++; do { - e->name[j] = ((u8 *)gSave378)[j]; + { u32 off = j * sizeof(NameChar); e->name[j] = *(NameChar *)((u8 *)gSave378 + off); } j++; } while (j <= 9); } @@ -4199,10 +4952,14 @@ u32 sub_0807A4B4(struct Sum378 *entries, u8 index) flag = &entries->b4; save->hA = entries[index].b1; save->hC = entries[index].b2; - *(u16 *)((u8 *)save + 0xE) = index; + *(u16 *)((u8 *)save + SAVE_FIELD(0xE)) = index; *flag = 0; for (i = 0; i <= 9; i++) - ((u8 *)gSave378)[i] = entries[index].name[i]; +#ifdef REGION_USA + { register NameChar *dst asm("r0") = (NameChar *)gSave378; register NameChar ch asm("r1"); asm("" : "+r"(dst)); dst += i; ch = entries[index].name[i]; *dst = ch; } +#else + ((NameChar *)gSave378)[i] = entries[index].name[i]; +#endif sub_0801ACB8(); } else { if (entries[index].b7 != 0) @@ -4243,10 +5000,10 @@ static inline u8 Sum_A56C(const u8 *data, u32 length) * unchecked. */ u32 sub_0807A56C(u8 sector) { - u32 sz = 0xCA8; + u32 sz = SAVE_FIELD(0xCA8); u8 *data = (u8 *)sub_08001494(sz); sub_08001B04_4(sector, 0, data, sz); - if (data[0xCA4] != Sum_A56C(data, 0xCA4)) { + if (data[SAVE_FIELD(0xCA4)] != Sum_A56C(data, SAVE_FIELD(0xCA4))) { sub_08001538(data); return 0; } diff --git a/src/code_0807A5D4.c b/src/code_0807A5D4.c index 6c5d36a8..d4d19f78 100644 --- a/src/code_0807A5D4.c +++ b/src/code_0807A5D4.c @@ -46,7 +46,7 @@ struct StatsA5D4 { s16 v[5]; u16 points; s16 rest[10]; }; struct ResultA5D4 { s16 v[0x18]; }; struct DataA5D4 { u8 *name; - u8 pad4[0xC]; + u8 pad4[SAVE_FIELD(0x10) - 4]; struct StatsA5D4 stats; /* 0x10 */ struct SkillsA5D4 skills; /* 0x30 */ }; @@ -63,7 +63,7 @@ struct MgrA5D4 { u8 sprite[0x68]; u32 f620; }; -struct PlayerA5D4 { u8 pad[0x30]; u32 flags; u8 pad34[4]; s16 stat[4]; u8 pad40[0x20]; u16 f60, f62; u8 pad64[0x14C - 0x64]; }; +struct PlayerA5D4 { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 pad34[PLAYER_FIELD(0x38) - PLAYER_FIELD(0x34)]; s16 stat[4]; u8 pad40[PLAYER_FIELD(0x60) - PLAYER_FIELD(0x40)]; u16 f60, f62; u8 pad64[PLAYER_SIZE - PLAYER_FIELD(0x64)]; }; struct StageA5D4 { u8 pad[0x1FA]; u16 value; }; struct IndexA5D4 { u8 pad[0x14A]; u16 value; }; union BgA5D4 { u32 word; u16 half[2]; }; @@ -163,6 +163,9 @@ void sub_0807A5D4_v(void) sub_0800903C(4, 0x38, 1, 10, 7, 0); sub_08000AF0(0xE, (void *)(sub_08007290(0x70003) + 0x1C0), 1); stageA5D4.value = tableA5D4Stage[indexA5D4->value]; +#ifdef REGION_USA + sub_08065158(mgrA5D4->sprite, 0x50006, 0, -1, 0); /* single language */ +#else switch (gUnk_03003470) { case 0: sub_08065158(mgrA5D4->sprite, 0x50006, 0, -1, 0); break; case 1: sub_08065158(mgrA5D4->sprite, 0x50007, 0, -1, 0); break; @@ -170,6 +173,7 @@ void sub_0807A5D4_v(void) case 3: sub_08065158(mgrA5D4->sprite, 0x50009, 0, -1, 0); break; case 4: sub_08065158(mgrA5D4->sprite, 0x5000A, 0, -1, 0); break; } +#endif sub_08000990(0, 1); sub_080009C0(0x1F00, 0, 1); bg.word = (bg.word & 0xFFFF0000) | 0x1D01; @@ -324,7 +328,7 @@ void sub_0807A5D4_v(void) sub_0805865C(0x62); break; case 3: - if (saved.v[3] > 332) + if (saved.v[3] > 0x14C) break; stats.v[3]++; saved.v[3]++; @@ -510,12 +514,14 @@ void sub_0807A5D4_v(void) case 3: if (stats.v[3] != 0) sub_08065230(mgrA5D4->sprite, 0x20, 0x47, 3, 2); break; } text = (u8 *)sub_08007290((mgrA5D4->cursor + 1000) | 0x140000); - p = text + 2; + p = text + TEXT_HEADER; sub_0801A3D0(p, (u16)(15 - ((u32)sub_0801A638(p) >> 1)), 0x11); dirty = 1; break; case 3: { +#ifndef REGION_USA register u32 one asm("r5"); +#endif if (mgrA5D4->cursor != mgrA5D4->prev) { from = mgrA5D4->prev * 8 + 0x2F; to = mgrA5D4->cursor * 8 + 0x2F; @@ -540,9 +546,14 @@ void sub_0807A5D4_v(void) case 6: text = (u8 *)sub_08007290((mgrA5D4->cursor + 0x41D) | 0x140000); break; case 7: text = (u8 *)sub_08007290((mgrA5D4->cursor + 0x425) | 0x140000); break; } - p = text + 2; + p = text + TEXT_HEADER; +#ifdef REGION_USA + sub_0801A3D0(p, (u16)(15 - ((u32)sub_0801A638(p) >> 1)), 0x11); + sub_080659BC(mgrA5D4->sprite, 0x70, anim, 0x16, 1, 2); +#else { u16 x; w = sub_0801A638_s16(p); x = -(w / 2 + (w & ({ one = 1; one; }))); sub_0801A3D0(p, (u16)(x + 15), 0x11); } sub_080659BC(mgrA5D4->sprite, 0x70, anim, 0x16, one, 2); +#endif dirty = 1; break; } @@ -563,8 +574,8 @@ void sub_0807A5D4_v(void) scroll += 0x40; gUnk_03001250[7] = scroll >> 8; sub_0801A3D0((u8 *)dataA5D4, 0x11, 0xE); - sub_0805FB7C(0xC, 0xB, *(s32 *)((u8 *)dataA5D4 + 0x20) + 1, 0); - sub_08065504(0x1C, 1, *(s32 *)((u8 *)dataA5D4 + 0x1C), 0, 10); + sub_0805FB7C(0xC, 0xB, *(s32 *)((u8 *)dataA5D4 + SAVE_FIELD(0x20)) + 1, 0); + sub_08065504(0x1C, 1, *(s32 *)((u8 *)dataA5D4 + SAVE_FIELD(0x1C)), 0, 10); { state = mgrA5D4->state; if (state != 3) { @@ -707,7 +718,7 @@ struct Stage7B7B4 { u8 pad[0x1FA]; u16 value; }; struct Index7B7B4 { u8 pad[0x14A]; u16 value; }; extern struct Stage7B7B4 stage7B7B4 asm("gUnk_03001F40"); extern struct Index7B7B4 *index7B7B4 asm("gUnk_03005CF4"); -struct Player7B7B4 { u8 pad[0x30]; u32 flags; u8 pad34[0x30]; u16 f64; u8 pad66[0x14C - 0x66]; }; +struct Player7B7B4 { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 pad34[0x30]; u16 f64; u8 pad66[PLAYER_SIZE - PLAYER_FIELD(0x66)]; }; extern struct Player7B7B4 players7B7B4[] asm("gUnk_03003CE0"); extern struct Mgr7B7B4 *mgr7B7B4 asm("gUnk_03006440"); extern u16 table7B7B4Stage[] asm("gUnk_084EBD38"); @@ -758,7 +769,11 @@ void sub_0807B7B4_v(void) mgr7B7B4->f0 = 2; sub_080009F8(0x1F00, 0, 1); +#ifdef REGION_USA + player = (struct Player *)&players7B7B4[sub_080020F4()]; +#else player = &gUnk_03003CE0[sub_080020F4()]; +#endif gUnk_03001250[1] = 0; gUnk_03001250[0] = 0; gUnk_03001250[3] = 0; @@ -772,6 +787,9 @@ void sub_0807B7B4_v(void) sub_0800B650(0x40000004, 0x1F, 0x06000000, 0, 0xE); sub_08000AF0(0xE, (void *)(sub_08007290(0x70003) + 0x1C0), 1); stage7B7B4.value = table7B7B4Stage[index7B7B4->value]; +#ifdef REGION_USA + sub_08065158(mgr7B7B4->f5B8, 0x50006, 0, -1, 0); /* single language */ +#else switch (gUnk_03003470) { case 0: sub_08065158(mgr7B7B4->f5B8, 0x50006, 0, -1, 0); break; case 1: sub_08065158(mgr7B7B4->f5B8, 0x50007, 0, -1, 0); break; @@ -779,6 +797,7 @@ void sub_0807B7B4_v(void) case 3: sub_08065158(mgr7B7B4->f5B8, 0x50009, 0, -1, 0); break; case 4: sub_08065158(mgr7B7B4->f5B8, 0x5000A, 0, -1, 0); break; } +#endif sub_08000990(0, 1); bg.word = (bg.word & 0xFFFF0000) | 0x1D03; sub_08000AA8(1, bg.half); @@ -823,7 +842,7 @@ void sub_0807B7B4_v(void) mgr7B7B4->f52 = 0; mgr7B7B4->f68 = 5; mgr7B7B4->f6A = 100; - lastLevel = *(u16 *)(gUnk_030034E0 + 0x68); + lastLevel = *(u16 *)(gUnk_030034E0 + SAVE_FIELD(0x68)); lastCount = 0xFFFFFF; for (i = 0; i <= 5; i++) { mgr7B7B4->rows[i].a = 0; @@ -841,19 +860,19 @@ void sub_0807B7B4_v(void) } if (lastCount != players7B7B4[sub_080020F4()].f64 || mgr7B7B4->f6A != mgr7B7B4->f4 - || lastLevel != *(u16 *)(gUnk_030034E0 + 0x68)) { + || lastLevel != *(u16 *)(gUnk_030034E0 + SAVE_FIELD(0x68))) { if (mgr7B7B4->f68++ > 5) { if (mgr7B7B4->f1C == 0x16) { if (mgr7B7B4->f18 != 7) { sub_0805FFBC(0xF, 0x12, mgr7B7B4->fF0, 0x80000000); } else { - text = (u8 *)sub_08007290(table7B7B4Text[mgr7B7B4->f4] | 0x140000) + 2; + text = (u8 *)sub_08007290(table7B7B4Text[mgr7B7B4->f4] | 0x140000) + TEXT_HEADER; sub_0801A3D0(text, (u16)(15 - ((u32)sub_0801A638(text) >> 1)), 0x12); } } else { sub_0805FFBC(0xF, 0x12, &mgr7B7B4->fF4, 0x80000000); } - lastLevel = *(u16 *)(gUnk_030034E0 + 0x68); + lastLevel = *(u16 *)(gUnk_030034E0 + SAVE_FIELD(0x68)); sub_080811E0(player); mgr7B7B4->f68 = 0; mgr7B7B4->f6A = mgr7B7B4->f4; @@ -915,28 +934,28 @@ void sub_0807BD78(u32 kind, u32 index) case 0: { u8 *base = (u8 *)gUnk_030034E0; u32 offset = index * 16; - *(u16 *)(base + offset + 0x150) = 0; + *(u16 *)(base + offset + SAVE_FIELD(0x150)) = 0; break; } case 1: { u8 *base = (u8 *)gUnk_030034E0; u8 *dest = base + index * 16; - *(u16 *)(dest + 0x70) = 0; - if (index == *(u16 *)(base + 0x68)) sub_0805AD78(index); + *(u16 *)(dest + SAVE_FIELD(0x70)) = 0; + if (index == *(u16 *)(base + SAVE_FIELD(0x68))) sub_0805AD78(index); break; } case 2: - *(u16 *)((u8 *)gUnk_030034E0 + 0x100) = 0; + *(u16 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x100)) = 0; sub_0805D094(); break; case 3: - *(u16 *)((u8 *)gUnk_030034E0 + 0x120) = 0; + *(u16 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x120)) = 0; sub_0805D13C(); break; case 4: - *(u16 *)((u8 *)gUnk_030034E0 + 0x110) = 0; + *(u16 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x110)) = 0; sub_0805D0E8(); break; case 5: - *(u16 *)((u8 *)gUnk_030034E0 + 0x130) = 0; + *(u16 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x130)) = 0; sub_0805D190(); break; case 6: - *(u16 *)((u8 *)gUnk_030034E0 + 0x140) = 0; + *(u16 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x140)) = 0; sub_0805D1E0(); break; case 11: case 13: case 16: { u8 *base = (u8 *)gUnk_03006440; @@ -958,31 +977,31 @@ void sub_0807BEA0(u32 kind, u32 index, struct Copy7BEA0 *item) { u8 *base = (u8 *)gUnk_030034E0; u32 offset = index * 16; base += offset; - base += 0x150; + base += SAVE_FIELD(0x150); *(struct Copy7BEA0 *)base = *item; } break; case 1: { u8 *base = (u8 *)gUnk_030034E0; u32 offset = index * 16; base += offset; - base += 0x70; + base += SAVE_FIELD(0x70); *(struct Copy7BEA0 *)base = *item; } - if (index == *(u16 *)((u8 *)gUnk_030034E0 + 0x68)) sub_0805AD78(index); + if (index == *(u16 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x68))) sub_0805AD78(index); break; case 2: - *(struct Copy7BEA0 *)((u8 *)gUnk_030034E0 + 0x100) = *item; + *(struct Copy7BEA0 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x100)) = *item; sub_0805D094(); break; case 3: - *(struct Copy7BEA0 *)((u8 *)gUnk_030034E0 + 0x120) = *item; + *(struct Copy7BEA0 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x120)) = *item; sub_0805D13C(); break; case 4: - *(struct Copy7BEA0 *)((u8 *)gUnk_030034E0 + 0x110) = *item; + *(struct Copy7BEA0 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x110)) = *item; sub_0805D0E8(); break; case 5: - *(struct Copy7BEA0 *)((u8 *)gUnk_030034E0 + 0x130) = *item; - *(u16 *)((u8 *)gUnk_030034E0 + 0x136) = 0; + *(struct Copy7BEA0 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x130)) = *item; + *(u16 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x136)) = 0; sub_0805D190(); break; case 6: - *(struct Copy7BEA0 *)((u8 *)gUnk_030034E0 + 0x140) = *item; + *(struct Copy7BEA0 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x140)) = *item; sub_0805D1E0(); break; case 13: case 16: { u8 *base = (u8 *)gUnk_03006440; @@ -1023,10 +1042,10 @@ void sub_0807C014(u32 arg0) i = 0; ptr1 = inventory2; base = (u8 *)*ptr1; - count = (u32 *)(base + 0x154); + count = (u32 *)(base + SAVE_FIELD(0x154)); cursor = (u8 *)*ptr1; do { - register u32 fieldOffset asm("r7") = 0x150; + register u32 fieldOffset asm("r7") = SAVE_FIELD(0x150); if (*(u16 *)(cursor + fieldOffset) == 10) { u32 value = *count; if (value < minimum) { selected = i; minimum = value; } @@ -1042,7 +1061,7 @@ void sub_0807C014(u32 arg0) ptr1 = inventory; item = (u32 *)*ptr1; value = selected * 16; - item = (u32 *)((u8 *)item + 0x154); + item = (u32 *)((u8 *)item + SAVE_FIELD(0x154)); item = (u32 *)((u8 *)item + value); value = *item - amount; *item = value; @@ -1053,7 +1072,7 @@ void sub_0807C014(u32 arg0) ptr7 = inventory2; base = (u8 *)*ptr7; index = selected * 16; - base += 0x154; + base += SAVE_FIELD(0x154); base += index; amount -= *(u32 *)base; sub_0805D580(selected); @@ -1061,7 +1080,7 @@ void sub_0807C014(u32 arg0) } } else { selected = 75; - if (*(u32 *)gUnk_03006440 != 4) { ptr7 = inventory; base = (u8 *)*ptr7; cursor = base + 0x2E0; } + if (*(u32 *)gUnk_03006440 != 4) { ptr7 = inventory; base = (u8 *)*ptr7; cursor = base + SAVE_FIELD(0x2E0); } else { offset = 0x104; cursor = (u8 *)gUnk_03006440 + offset; } i = 0; do { @@ -1186,12 +1205,17 @@ extern s16 gUnk_084ECBB0[]; extern s16 gUnk_084ECBBC[]; extern u32 gUnk_084ECBC8[]; struct Item82 { u16 kind; u16 sub; u32 count; u8 flag; u8 flag2; u8 pad[6]; }; -struct Inv82 { u8 pad0[0x54]; u16 f54; u16 f56[9]; u16 equip; u16 f6A; u8 pad6C[4]; struct Item82 belt[9]; struct Item82 equipA, equipB, equipC, equipD, equipE; struct Item82 items[25]; struct Item82 bank[75]; }; +struct Inv82 { u8 pad0[SAVE_FIELD(0x54)]; u16 f54; u16 f56[9]; u16 equip; u16 f6A; u8 pad6C[4]; struct Item82 belt[9]; struct Item82 equipA, equipB, equipC, equipD, equipE; struct Item82 items[25]; struct Item82 bank[75]; }; +#ifdef REGION_USA +#define SHOP82_PRICES 0x174 +#else +#define SHOP82_PRICES 0x136 +#endif struct Mgr82 { u32 mode; u32 cursor; u32 prev; u32 fC; s32 f10; u32 f14; u32 state; u32 heldFrom; u32 heldIdx; s32 f24; u32 flags; u32 f2C; u32 f30; s32 f34; u32 f38; s32 f3C; u32 f40; u32 page; u32 f48; u8 pad4C[0x54 - 0x4C]; u32 f54; u32 f58; u32 f5C; u32 f60; u8 pad64[4]; u16 f68; s16 f6A; u32 f6C; u32 f70; struct { u32 t, n; } anim[6]; u8 padA4[0xE0 - 0xA4]; s32 fE0; s32 fE4; s32 posX; s32 posY; - struct Item82 *cur; struct Item82 held; struct Item82 stock[75]; struct { u8 pad[0x136]; u16 f136[6]; } *f5B4; u8 sprite[4]; + struct Item82 *cur; struct Item82 held; struct Item82 stock[75]; struct { u8 pad[SHOP82_PRICES]; u16 f136[6]; } *f5B4; u8 sprite[4]; }; struct Pos82 { s16 x, y; }; struct C82 { u32 c; }; /* one u32 field: stores through it stay MEM_IN_STRUCT_P */ @@ -1208,7 +1232,7 @@ static inline void Drop82P(vu32 *z, struct Mgr82 **g) { *z = 0; CpuSet((void *)z /* Drop82PH: CpuSet's destination is the held pointer already in a register (ROM: mov r1, r9); z remains the zero source. */ static inline void Drop82PH(vu32 *z, struct Item82 *h, struct Mgr82 **g) { *z = 0; CpuSet((void *)z, h, 0x05000004); (*g)->heldFrom = 0x16; (*g)->heldIdx = 0; } #define REFRESH82() { sub_0805AD78(gInv82->equip); sub_0805D094(); sub_0805D0E8(); sub_0805D13C(); } -struct Player82 { u8 pad[0x77]; u8 f77; u8 f78; u8 pad79[0x8C - 0x79]; s32 f8C; s32 f90; u8 pad94[0xC6 - 0x94]; u16 fC6; u8 rest[0x14C - 0xC8]; }; +struct Player82 { u8 pad[PLAYER_FIELD(0x77)]; u8 f77; u8 f78; u8 pad79[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x79)]; s32 f8C; s32 f90; u8 pad94[PLAYER_FIELD(0xC6) - PLAYER_FIELD(0x94)]; u16 fC6; u8 rest[PLAYER_SIZE - PLAYER_FIELD(0xC8)]; }; extern struct Player82 gPlayers82[] asm("gUnk_03003CE0"); /* Second name for the gMgr82 slot: GCC does not merge it with gMgr82, but it still assembles to a gUnk_03006440 relocation like the ROM. */ extern struct Mgr82 *gMgr82Slot082 asm("gUnk_03006440"); @@ -1260,7 +1284,7 @@ void sub_0807C29C(void) { case 2: if (gMgr82->held.kind == 1) { if (cur <= 14) { - if (*(u32 *)(sub_08007290(gMgr82->held.sub | 0x100000) + 0xA4) == 0) + if (*(u32 *)(sub_08007290(gMgr82->held.sub | 0x100000) + ITEM_FIELD(0xA4)) == 0) break; gMgr82->state = 8; gMgr82->cursor = 0; @@ -1441,7 +1465,7 @@ void sub_0807C29C(void) { struct Item82 *it; u8 *inventoryBase; inventoryBase = (u8 *)gInv82; - it = (struct Item82 *)(inventoryBase + gMgr82->cursor * 16 + 0x150); + it = (struct Item82 *)(inventoryBase + gMgr82->cursor * 16 + SAVE_FIELD(0x150)); if (it->kind == 0) break; if (it->kind != 10) { @@ -1522,15 +1546,15 @@ void sub_0807C29C(void) { /* (gInv82 + cursor*16) + 0x150 / + 0x158: ROM shares the base-first sum */ switch (gInv82->items[gMgr82->cursor].kind) { case 2 ... 5: - if (*((u8 *)gInv82 + gMgr82->cursor * 16 + 0x158) != 0) { - *((u8 *)gInv82 + gMgr82->cursor * 16 + 0x158) = 0; + if (*((u8 *)gInv82 + gMgr82->cursor * 16 + SAVE_FIELD(0x158)) != 0) { + *((u8 *)gInv82 + gMgr82->cursor * 16 + SAVE_FIELD(0x158)) = 0; gMgr82->f6A = 100; sub_0807BD78(gMgr82->heldFrom, gMgr82->heldIdx); DROP82(); sub_0805865C(0x18C); break; } - item = (struct Item82 *)((u8 *)gInv82 + gMgr82->cursor * 16 + 0x150); + item = (struct Item82 *)((u8 *)gInv82 + gMgr82->cursor * 16 + SAVE_FIELD(0x150)); *(struct Item82 *)sp4 = *item; sub_0807BEA0(0, gMgr82->cursor, (void *)hd); sub_0807BEA0(gMgr82->heldFrom, gMgr82->heldIdx, (void *)sp4); @@ -1563,7 +1587,7 @@ void sub_0807C29C(void) { /* ROM computes &held, then loads gInv82, before the item address */ struct Item82 *hh = &gMgr82->held; struct Inv82 *iv = gInv82; - dit = (struct Item82 *)((u8 *)iv + gMgr82->cursor * 16 + 0x150); + dit = (struct Item82 *)((u8 *)iv + gMgr82->cursor * 16 + SAVE_FIELD(0x150)); if (hh->kind != dit->kind) { sub_0805865C(0x61); break; @@ -1615,7 +1639,7 @@ void sub_0807C29C(void) { } /* holding money, tg0 slot occupied */ if (gInv82->items[gMgr82->heldIdx].count == gMgr82->held.count) { - item = (struct Item82 *)((u8 *)gInv82 + gMgr82->cursor * 16 + 0x150); + item = (struct Item82 *)((u8 *)gInv82 + gMgr82->cursor * 16 + SAVE_FIELD(0x150)); if (item->kind == 10) { u32 vb; /* own money sum (ROM r0; v0 sat in r1 and pushed cursor/cursor*16 to r3/r1). The count loop above uses val. */ vb = gInv82->items[gMgr82->cursor].count + gMgr82->held.count; @@ -2534,7 +2558,7 @@ void sub_0807C29C(void) { } else if ((keys29_03001324 & 1) && gMgr82->heldFrom != 0x16) { u16 arg; if ((u8)sub_0801DE60() == 0) - arg = sub_0801E0AC((u8 *)gInv82 + 0x30, 5); + arg = sub_0801E0AC((u8 *)gInv82 + SAVE_FIELD(0x30), 5); else arg = 0; if (sub_0805BD5C(&gMgr82->held, arg) && gMgr82->held.kind == 1) { @@ -2562,7 +2586,7 @@ void sub_0807C29C(void) { } else { u16 kind = gMgr82->held.kind; if (kind != 10) - if (kind == 1 && *(u32 *)(sub_08007290(gMgr82->held.sub | 0x100000) + 0xA4) != 0) { + if (kind == 1 && *(u32 *)(sub_08007290(gMgr82->held.sub | 0x100000) + ITEM_FIELD(0xA4)) != 0) { gMgr82->state = 8; gMgr82->cursor = 0; gMgr82->prev = kind; @@ -3565,7 +3589,7 @@ void sub_0807C29C(void) { gMgr82->prev = gMgr82->cursor; } if (gMgr82->cursor == gMgr82->f48 && gMgr82->cursor <= 4) { - text = (u8 *)sub_08007290(0x140189) + 2; + text = (u8 *)sub_08007290(0x140189) + TEXT_HEADER; sub_0801A3D0(text, (u16)(15 - (u32)sub_0801A638(text) / 2), 0x12); } sub_0801A664(0xE, 3); @@ -3573,7 +3597,7 @@ void sub_0807C29C(void) { break; case 15: sub_0807C1D8(); - text = (u8 *)sub_08007290(0x14018A) + 2; + text = (u8 *)sub_08007290(0x14018A) + TEXT_HEADER; sub_0801A3D0(text, (u16)(15 - (u32)(sub_0801A638(text) + 1) / 2), 0x12); break; case 16: @@ -3604,7 +3628,7 @@ void sub_0807C29C(void) { } } gMgr82->posY = gMgr82->f54 + 0x60; - text = (u8 *)sub_08007290(0x140186) + 2; + text = (u8 *)sub_08007290(0x140186) + TEXT_HEADER; sub_0801A3D0(text, (u16)(15 - (u32)(sub_0801A638(text) + 1) / 2), 0x12); break; case 19: @@ -3858,7 +3882,7 @@ void sub_08080A78(void) u32 r; u16 buf[8]; - item = INV + 0x150; + item = INV + SAVE_FIELD(0x150); for (i = 0; i <= 0x18; i++, item += 0x10) { mode = 8; switch (*(u16 *)item) { @@ -3879,9 +3903,9 @@ void sub_08080A78(void) { struct A78Pos { s16 x, y; }; u32 first; - first = (u16)(F16(INV, 0x68) / 3) * 3; + first = (u16)(F16(INV, SAVE_FIELD(0x68)) / 3) * 3; end = first + 3; - item = INV + (first * 0x10 + 0x70); + item = INV + (first * 0x10 + SAVE_FIELD(0x70)); for (i = first; i < end; i++, item += 0x10) { mode = 8; if (sub_0805AE34(item) == 0) @@ -3889,7 +3913,7 @@ void sub_08080A78(void) if (F32(MGR, 0x1C) == 1 && F32(MGR, 0x20) == i) { if (gUnk_03002344 & 1) sub_0805FC80(((struct A78Pos *)gUnk_084ECBBC)[i - first].x + 0x38, ((struct A78Pos *)gUnk_084ECBBC)[i - first].y + 0x10, item, mode); - } else if (F16(INV, 0x68) == i) { + } else if (F16(INV, SAVE_FIELD(0x68)) == i) { { s32 x = ((struct A78Pos *)gUnk_084ECBBC)[i - first].x + 0x38; s32 y = ((struct A78Pos *)gUnk_084ECBBC)[i - first].y; s32 sc = *(s32 *)(MGR + 0x74) - 0x10; sub_0805FC80(x, y - sc, item, mode); } } else { sub_0805FC80(((struct A78Pos *)gUnk_084ECBBC)[i - first].x + 0x38, ((struct A78Pos *)gUnk_084ECBBC)[i - first].y + 0x10, item, mode); @@ -3898,7 +3922,7 @@ void sub_08080A78(void) } if (F32(MGR, 0) != 5) { - item = INV + 0x100; + item = INV + SAVE_FIELD(0x100); mode = 0; if (sub_0805D210(item) == 0) mode = 2; @@ -3908,7 +3932,7 @@ void sub_08080A78(void) } else sub_0805FC80(0x40, 0x30 - F32(MGR, 0x7C), item, mode); - item = INV + 0x120; + item = INV + SAVE_FIELD(0x120); mode = 0; if (sub_0805D2E0(item) == 0) mode = 2; @@ -3918,7 +3942,7 @@ void sub_08080A78(void) } else sub_0805FC80(0x3C, 0x60 - F32(MGR, 0x8C), item, mode); - item = INV + 0x110; + item = INV + SAVE_FIELD(0x110); mode = 0; if (sub_0805D278(item) == 0) mode = 2; @@ -3930,22 +3954,22 @@ void sub_08080A78(void) if (F32(MGR, 0x1C) == 5) { if (gUnk_03002344 & 1) - sub_0805FC80(0xC, 0x40 - F32(MGR, 0x9C), INV + 0x130, 8); + sub_0805FC80(0xC, 0x40 - F32(MGR, 0x9C), INV + SAVE_FIELD(0x130), 8); } else - sub_0805FC80(0xC, 0x40 - F32(MGR, 0x9C), INV + 0x130, 8); + sub_0805FC80(0xC, 0x40 - F32(MGR, 0x9C), INV + SAVE_FIELD(0x130), 8); if (F32(MGR, 0x1C) == 6) { if (gUnk_03002344 & 1) - sub_0805FC80(0x10, 0x60 - F32(MGR, 0x94), INV + 0x140, 8); + sub_0805FC80(0x10, 0x60 - F32(MGR, 0x94), INV + SAVE_FIELD(0x140), 8); } else - sub_0805FC80(0x10, 0x60 - F32(MGR, 0x94), INV + 0x140, 8); + sub_0805FC80(0x10, 0x60 - F32(MGR, 0x94), INV + SAVE_FIELD(0x140), 8); } if (F32(MGR, 0) == 2) { - struct A78Ids { u8 pad[0x56]; u16 ids[3]; }; + struct A78Ids { u8 pad[SAVE_FIELD(0x56)]; u16 ids[3]; }; s16 *tx = gUnk_084ECBB0; s16 *ty = gUnk_084ECBB2; - u32 first = (u16)(F16(INV, 0x54) / 3) * 3; + u32 first = (u16)(F16(INV, SAVE_FIELD(0x54)) / 3) * 3; end = first + 3; for (i = first; i < end; i++) { { @@ -3955,10 +3979,10 @@ void sub_08080A78(void) found = sub_0805D548(((struct A78Ids *)INV)->ids[i] - 1); if (found != -1) { u32 j; - item = INV + (found * 0x10 + 0x150); + item = INV + (found * 0x10 + SAVE_FIELD(0x150)); count = 0; for (j = 0; j <= 0x18; j++) { - if (F16(INV, j * 0x10 + 0x150) == 1 && F16(item, 2) == F16(INV, j * 0x10 + 0x152)) + if (F16(INV, j * 0x10 + SAVE_FIELD(0x150)) == 1 && F16(item, 2) == F16(INV, j * 0x10 + SAVE_FIELD(0x152))) count++; } } else { @@ -4104,42 +4128,42 @@ void sub_080811E0(u8 *arg0) { var_r1=*(u8 **)(manager811+0xf0); switch(*(u16 *)var_r1) { case 1: - sub_0801BA74(arg0,0,sp4,sp24,(s32)(bank811+0x30)); + sub_0801BA74(arg0,0,sp4,sp24,(s32)(bank811+SAVE_FIELD(0x30))); var_r0=*(u16 *)(*(u8 **)(manager811+0xf0)+2); switch(var_r0) {case 8:sp4[0]++;break;case 9:sp4[1]++;break;case 10:sp4[3]++;break;case 11:sp4[2]++;break;} break; case 2:case 3:case 4:case 5: if (*((u8 *)var_r1+8)==0) { - sub_0801BA74(arg0,(s32)var_r1,sp4,sp24,(s32)(bank811+0x30)); + sub_0801BA74(arg0,(s32)var_r1,sp4,sp24,(s32)(bank811+SAVE_FIELD(0x30))); } else { - sub_0801BA74(arg0,0,sp4,sp24,(s32)(bank811+0x30)); + sub_0801BA74(arg0,0,sp4,sp24,(s32)(bank811+SAVE_FIELD(0x30))); } break; default: - sub_0801BA74(arg0,(s32)*(u8 **)(manager811+0xf0),sp4,sp24,(s32)(bank811+0x30));break; + sub_0801BA74(arg0,(s32)*(u8 **)(manager811+0xf0),sp4,sp24,(s32)(bank811+SAVE_FIELD(0x30)));break; } } else { var_r1=manager811+0xf4; switch(*(u16 *)var_r1) { case 2:case 3:case 4:case 5: if(manager811[0xfc]==0) { - sub_0801BA74(arg0,(s32)var_r1,sp4,sp24,(s32)(bank811+0x30)); + sub_0801BA74(arg0,(s32)var_r1,sp4,sp24,(s32)(bank811+SAVE_FIELD(0x30))); } else { - sub_0801BA74(arg0,0,sp4,sp24,(s32)(bank811+0x30)); + sub_0801BA74(arg0,0,sp4,sp24,(s32)(bank811+SAVE_FIELD(0x30))); } break; case 1: - sub_0801BA74(arg0,0,sp4,sp24,(s32)(bank811+0x30)); + sub_0801BA74(arg0,0,sp4,sp24,(s32)(bank811+SAVE_FIELD(0x30))); var_r0=*(u16 *)(manager811+0xf6); switch(var_r0) {case 8:sp4[0]++;break;case 9:sp4[1]++;break;case 10:sp4[3]++;break;case 11:sp4[2]++;break;} break; default: - sub_0801BA74(arg0,(s32)(manager811+0xf4),sp4,sp24,(s32)(bank811+0x30));break; + sub_0801BA74(arg0,(s32)(manager811+0xf4),sp4,sp24,(s32)(bank811+SAVE_FIELD(0x30)));break; } } draw: temp_r1 = sp24[0].first; - temp_r0_3 = *(s16 *)(arg0+0x58); + temp_r0_3 = *(s16 *)(arg0+PLAYER_FIELD(0x58)); if ((s32) temp_r1 > (s32) temp_r0_3) { var_r3 = 2; } else { @@ -4149,7 +4173,7 @@ void sub_080811E0(u8 *arg0) { } } sub_0805FB7C(6, 0xE, sp24[0].first, var_r3); - temp_r1_2 = *(s16 *)(arg0+0x5A); + temp_r1_2 = *(s16 *)(arg0+PLAYER_FIELD(0x5A)); temp_r0_4 = (s16) sp24[0].second; if ((s32) temp_r0_4 > (s32) temp_r1_2) { var_r3_2 = 2; @@ -4161,7 +4185,7 @@ void sub_080811E0(u8 *arg0) { } sub_0805FB7C(6, 0xF, (s16) sp24[0].second, var_r3_2); temp_r1_3 = sp24[9].first; - temp_r0_5 = *(s16 *)(arg0+0x7C); + temp_r0_5 = *(s16 *)(arg0+PLAYER_FIELD(0x7C)); if ((s32) temp_r1_3 > (s32) temp_r0_5) { var_r3_3 = 2; } else { @@ -4172,7 +4196,7 @@ void sub_080811E0(u8 *arg0) { } sub_0805FB7C(0x16, 0xE, sp24[9].first, var_r3_3); temp_r1_4 = (s16) sp24[9].second; - temp_r0_6 = *(s16 *)(arg0+0x7E); + temp_r0_6 = *(s16 *)(arg0+PLAYER_FIELD(0x7E)); if ((s32) temp_r1_4 > (s32) temp_r0_6) { var_r3_4 = 2; } else { @@ -4183,7 +4207,7 @@ void sub_080811E0(u8 *arg0) { } sub_0805FB7C(0x16, 0xF, (s16) sp24[9].second, var_r3_4); temp_r1_5 = sp24[10].first; - temp_r0_7 = *(s16 *)(arg0+0x80); + temp_r0_7 = *(s16 *)(arg0+PLAYER_FIELD(0x80)); if ((s32) temp_r1_5 > (s32) temp_r0_7) { var_r3_5 = 2; } else { @@ -4194,7 +4218,7 @@ void sub_080811E0(u8 *arg0) { } sub_0805FB7C(0x16, 0x10, sp24[10].first, var_r3_5); temp_r1_6 = (s16) sp24[10].second; - temp_r0_8 = *(s16 *)(arg0+0x82); + temp_r0_8 = *(s16 *)(arg0+PLAYER_FIELD(0x82)); if ((s32) temp_r1_6 > (s32) temp_r0_8) { var_r3_6 = 2; } else { @@ -4205,7 +4229,7 @@ void sub_080811E0(u8 *arg0) { } sub_0805FB7C(0x1D, 0xE, (s16) sp24[10].second, var_r3_6); temp_r1_7 = sp24[11].first; - temp_r0_9 = *(s16 *)(arg0+0x84); + temp_r0_9 = *(s16 *)(arg0+PLAYER_FIELD(0x84)); if ((s32) temp_r1_7 > (s32) temp_r0_9) { var_r3_7 = 2; } else { @@ -4216,7 +4240,7 @@ void sub_080811E0(u8 *arg0) { } sub_0805FB7C(0x1D, 0xF, sp24[11].first, var_r3_7); temp_r1_8 = (s16) sp24[11].second; - temp_r0_10 = *(s16 *)(arg0+0x86); + temp_r0_10 = *(s16 *)(arg0+PLAYER_FIELD(0x86)); if ((s32) temp_r1_8 > (s32) temp_r0_10) { var_r3_8 = 2; } else { @@ -4227,7 +4251,7 @@ void sub_080811E0(u8 *arg0) { } sub_0805FB7C(0x1D, 0x10, (s16) sp24[11].second, var_r3_8); temp_r1_9 = (s16) sp4[0]; - temp_r0_11 = *(s16 *)(arg0+0x38); + temp_r0_11 = *(s16 *)(arg0+PLAYER_FIELD(0x38)); if ((s32) temp_r1_9 > (s32) temp_r0_11) { var_r3_9 = 2; } else { @@ -4238,7 +4262,7 @@ void sub_080811E0(u8 *arg0) { } sub_0805FB7C(0xF, 0xE, (s16) sp4[0], var_r3_9); temp_r1_10 = (s16) sp4[3]; - temp_r0_12 = *(s16 *)(arg0+0x3E); + temp_r0_12 = *(s16 *)(arg0+PLAYER_FIELD(0x3E)); if ((s32) temp_r1_10 > (s32) temp_r0_12) { var_r3_10 = 2; } else { @@ -4249,7 +4273,7 @@ void sub_080811E0(u8 *arg0) { } sub_0805FB7C(6, 0x10, (s16) sp4[3], var_r3_10); temp_r1_11 = (s16) sp4[2]; - temp_r0_13 = *(s16 *)(arg0+0x3C); + temp_r0_13 = *(s16 *)(arg0+PLAYER_FIELD(0x3C)); if ((s32) temp_r1_11 > (s32) temp_r0_13) { var_r3_11 = 2; } else { @@ -4259,8 +4283,17 @@ void sub_080811E0(u8 *arg0) { } } sub_0805FB7C(0xF, 0x10, (s16) sp4[2], var_r3_11); +#ifdef REGION_USA + { + s16 *stats = sp4; + s16 *field = (s16 *)(arg0+PLAYER_FIELD(0x3A)); + temp_r1_12 = stats[1]; + temp_r0_14 = *field; + } +#else temp_r1_12 = (s16) sp4[1]; - temp_r0_14 = *(s16 *)(arg0+0x3A); + temp_r0_14 = *(s16 *)(arg0+PLAYER_FIELD(0x3A)); +#endif if ((s32) temp_r1_12 > (s32) temp_r0_14) { var_r3_12 = 2; } else { @@ -4281,6 +4314,105 @@ extern void sub_0801A3D0(u8 *, u32, u32); * final digit; copies other bytes until0xFD. Builds local32-byte text, u16 length with no bounds validation, * terminates0xFD and draws via0x0801A3D0 at u16(x-(width>>1)) when centered, else x. No text-capacity check or * bounded search for a missing source terminator; not ASCII formatting. */ +#ifdef REGION_USA +void sub_08081518(u32 arg0, u32 arg1, u8 *arg2, u32 arg3, volatile s32 arg4) +{ + struct { + TextChar text[30]; + s32 number; + u32 x; + u32 y; + /* Preserve the two caller-clobbered pointers in the original spill slots. */ + TextChar *volatile source; + s32 *volatile num; + } frame; + register u32 savedNumber asm("r9"); + register u32 length asm("r8"); + register TextChar *source asm("r2"); + s32 *num; + register u32 token asm("r3"); + TextChar *out; + u16 digit; + register s32 *divisor asm("r6"); + u32 started; + u16 offset; + + frame.x = (u16)arg0; + frame.y = (u16)arg1; + savedNumber = (u16)arg3; + source = (TextChar *)(arg2 + TEXT_HEADER); + length = 0; + token = *source; + if (token != TEXT_CTRL(0xFD)) { + u32 end = TEXT_CTRL(0xFD); + do { + if (token == ({ register u32 code asm("r1") = TEXT_CTRL(0xF7); code; })) { + register u32 numberCopy asm("r4") = savedNumber; + asm("" : "+r"(numberCopy)); + frame.number = numberCopy; + divisor = decimalDivisors8518; + out = frame.text + length; + started = 0; + digit = 0; + num = &frame.number; + source++; + do { + u32 value; + s32 denominator = *divisor; + s32 *callNum = num; + asm("" : "+r"(denominator), "+r"(callNum)); + frame.source = source; + frame.num = num; + value = sub_08000498(callNum, denominator) + 0x41; + *out = value; + source = frame.source; + num = frame.num; + asm("" : "+r"(divisor), "+r"(out)); + if (started || (TextChar)value != 0x41 || digit == 5) { + out++; + started = 1; + length = (u16)(length + 1); + } + { + u32 nextDigit = digit + 1; + digit = (u16)nextDigit; + } + divisor++; + } while (digit <= 5); + } else { + u32 oldLength = length; + length = (u16)(oldLength + 1); + frame.text[oldLength] = token; + source++; + } + token = *source; + } while (token != end); + } + { register u32 len asm("r2") = length; register u32 t3 asm("r3"); asm("" : "=r"(t3)); frame.text[len] = TEXT_CTRL(0xFD); asm("" : : "r"(len), "r"(t3)); } + { + u32 mask = 1; + register u32 flags asm("r1"); + + flags = arg4; + flags &= mask; + if (flags) + offset = -((u32)sub_0801A638((u8 *)frame.text) >> 1); + else + offset = 0; + } + { + /* A byte offset keeps agbcc's base/offset operand order; never dereferenced. */ + register u8 *xCopy asm("r2") = (u8 *)frame.x; + u32 drawX; + TextChar *drawText; + asm("" : "+r"(xCopy)); + drawX = (u16)(u32)(xCopy + offset); + drawText = frame.text; + asm("" : "+r"(drawText) : "r"(drawX)); + sub_0801A3D0((u8 *)drawText, drawX, frame.y); + } +} +#else void sub_08081518(u32 arg0, u32 arg1, u8 *arg2, u32 arg3, volatile s32 arg4) { struct { @@ -4384,6 +4516,7 @@ void sub_08081518(u32 arg0, u32 arg1, u8 *arg2, u32 arg3, volatile s32 arg4) sub_0801A3D0(drawText, drawX, frame.y); } } +#endif extern u8 text85[] asm("gUnk_03000128"); extern u8 table85[] asm("gUnk_08479140"); extern u32 divisors85[] asm("gUnk_084EBD5C"); @@ -4392,6 +4525,498 @@ struct DetailEntry815F4 { u16 kind, value; }; /* These callers pass sub_0801DE60() in r2. */ u16 local815F4_sub_0801E378(s32, u16, u8) asm("sub_0801E378"); u16 local815F4_sub_0801E3D8(s32, u16, u8) asm("sub_0801E3D8"); +#ifdef REGION_USA +extern u16 *expand815F4(u16 *, u16, u16 *) asm("sub_080850C0"); +extern u16 text85U[][0x20] asm("gUnk_03000128"); +extern u16 localU_E378(s32, s32, u8) asm("sub_0801E378"); +extern u16 localU_E3D8(s32, s32, u8) asm("sub_0801E3D8"); + +#define CENTER815F4(T, Y) sub_0801A3D0((u8 *)(T), (u16) (0xF - ((u32) sub_0801A638((u8 *)(T)) >> 1)), Y) +/* USA: one language, 16-bit text, and the number tokens expand through the 0x080813D8 helper. */ +void sub_080815F4(void *arg0) { + struct Icon815F4 { + u32 field0, field4, field8, palette, resource, index, count; + u8 data[16]; + s16 field2C, field2E, field30, field32; + } icons[10]; + u8 *arg; + s32 weapon, armor, helmet, shield; + struct DetailEntry815F4 *detail; + s32 mask; + u32 bonus; + s32 desc; + u16 *res; + u16 *p; + u16 *q; + + u32 x; + u32 n; + u32 count; + s32 id; + s32 v; + s32 item; + void *icon; + u32 kind; + s32 a1, a2, a3; + u32 y; + arg = arg0; + sub_0805FFBC(0xF, 0x12, arg, 0x80000000); + sub_0805FC80(0x78, 0x20, arg, 8); + switch (*(u16 *)arg - 1) { + case 0: + item = sub_08007290(*(u16 *)(arg + 2) | 0x100000); + mask = 0; + detail = (struct DetailEntry815F4 *)(item + 0x178); + res = (u16 *)sub_08007290(*(u16 *)(item + 0x182) | 0x140000); + p = res + 2; + text85U[0][0] = mask; + text85U[1][0] = mask; + for (n = 0; n <= 1; n++) { + u16 c; + x = 0; + while ((c = *p) != 0xFFFD) { + text85U[n][x] = c; + if (c == 0xFFFF) { + p++; + break; + } + x++; + p++; + } + text85U[n][x] = 0xFFFD; + if (x == 0) + break; + CENTER815F4(text85U[n], (u16)(n * 2 + 0xB)); + if (*p == 0xFFFD) + break; + } + break; + case 1: + weapon = sub_08007290(*(u16 *)(arg + 2) | 0xB0000); + desc = *(u16 *)(weapon + 0x198); + mask = *(u16 *)(weapon + 0x186); + if (*(u16 *)(arg + 4) != 0) { + detail = (struct DetailEntry815F4 *)(sub_08007290((*(u16 *)(arg + 4) - 1) | 0x130000) + 0x178); + } else { + detail = (struct DetailEntry815F4 *)(weapon + 0x188); + } + break; + case 2: + armor = sub_08007290(*(u16 *)(arg + 2) | 0xC0000); + desc = *(u16 *)(armor + 0x18E); + mask = *(u16 *)(armor + 0x17E); + if (*(u16 *)(arg + 4) != 0) { + detail = (struct DetailEntry815F4 *)(sub_08007290((*(u16 *)(arg + 4) - 1) | 0x130000) + 0x178); + } else { + detail = (struct DetailEntry815F4 *)(armor + 0x180); + } + break; + case 3: + helmet = sub_08007290(*(u16 *)(arg + 2) | 0xD0000); + desc = *(u16 *)(helmet + 0x18E); + mask = *(u16 *)(helmet + 0x17E); + if (*(u16 *)(arg + 4) != 0) { + detail = (struct DetailEntry815F4 *)(sub_08007290((*(u16 *)(arg + 4) - 1) | 0x130000) + 0x178); + } else { + detail = (struct DetailEntry815F4 *)(helmet + 0x180); + } + break; + case 6: + item = sub_08007290(*(u16 *)(arg + 2) | 0x110000); + mask = 0xFF; + detail = NULL; + res = (u16 *)sub_08007290(*(u16 *)(item + 0x182) | 0x140000); + p = res + 2; + CENTER815F4(p, 7); + break; + case 4: + shield = sub_08007290(*(u16 *)(arg + 2) | 0xE0000); + desc = *(u16 *)(shield + 0x192); + mask = *(u16 *)(shield + 0x182); + if (*(u16 *)(arg + 4) != 0) { + detail = (struct DetailEntry815F4 *)(sub_08007290((*(u16 *)(arg + 4) - 1) | 0x130000) + 0x178); + } else { + detail = (struct DetailEntry815F4 *)(shield + 0x184); + } + break; + case 5: + item = sub_08007290(*(u16 *)(arg + 2) | 0xF0000); + mask = 0xFF; + detail = (struct DetailEntry815F4 *)(item + 0x178); + break; + case 8: + item = sub_08007290(*(u16 *)(arg + 2) | 0x150000); + mask = 0; + detail = NULL; + res = (u16 *)sub_08007290(*(s32 *)(item + 0x17C) | 0x140000); + p = res + 2; + x = 0; + n = 0; + while (*p != 0xFFFD) { + if (*p == 0xFFFF) { + text85U[x][n] = 0xFFFD; + x++; + n = 0; + } else { + text85U[x][n] = *p; + n++; + } + p++; + } + text85U[x][n] = 0xFFFD; + CENTER815F4(text85U, 9); + q = text85U[1]; + CENTER815F4(q, 11); + break; + case 9: + mask = 0; + detail = NULL; + break; + case 7: + item = sub_08007290(*(u16 *)(arg + 2) | 0x120000); + mask = 0; + detail = NULL; + res = (u16 *)sub_08007290(*(u16 *)(item + 0x17A) | 0x140000); + p = res + 2; + x = 0; + n = 0; + while (*p != 0xFFFD) { + if (*p == 0xFFFF) { + text85U[x][n] = 0xFFFD; + x++; + n = 0; + } else { + text85U[x][n] = *p; + n++; + } + p++; + } + text85U[x][n] = 0xFFFD; + CENTER815F4(text85U, 9); + q = text85U[1]; + CENTER815F4(q, 11); + break; + default: + return; + } + switch (*(u16 *)arg) { + case 2: + if (*(u8 *)(arg + 8) != 0) { + mask = 0; + break; + } + switch (*(u16 *)(weapon + 0x174)) { + default: + bonus = (u16)sub_0801B58C(weapon, (s32)gUnk_030034E0 + 0x3C, *(u16 *)(weapon + 0x176), sub_0801DE60()); + bonus = (u16)(bonus - *(u16 *)(weapon + 0x176)); + if (0x8000 & bonus) + bonus = 0; + break; + case 9: + bonus = (u16)sub_0801B58C(weapon, (s32)gUnk_030034E0 + 0x3C, *(u16 *)(weapon + 0x176), sub_0801DE60()); + bonus = (u16)(bonus - *(u16 *)(weapon + 0x176)); + res = (u16 *)sub_08007290(0x140328); + p = expand815F4(res, *(u16 *)(weapon + 0x176) + *(u8 *)(arg + 6), text85U[0]); + *p = 0x51; + if (bonus != 0) { + *++p = 0x51; + *++p = 0x51; + } + if (*(u16 *)(weapon + 0x184) == 7) { + res = (u16 *)sub_08007290((*(u8 *)(weapon + 0x17F) * 2 + 0x33A) | 0x140000); + expand815F4(res, *(u16 *)(weapon + 0x184), p + 1); + } else { + res = (u16 *)sub_08007290((*(u8 *)(weapon + 0x17F) * 2 + 0x339) | 0x140000); + expand815F4(res, *(u16 *)(weapon + 0x184), p + 1); + } + sub_0801A3D0((u8 *)text85U, (u16) (0xF - ((u32) sub_0801A638((u8 *)text85U) >> 1)), 5U); + if (bonus != 0) { + x = (u8 *)p - (u8 *)text85U; + if (((bonus / 100U) << 0x10) == 0) { + if (((bonus / 10U) << 0x10) == 0) { + x -= 1; + n = 1; + } else { + n = 2; + } + } else { + x += 1; + n = 3; + } + { + s32 w; + v = sub_0801A638((u8 *)text85U); + w = x + 0xF; + sub_0805FB7C(w - ((u32) v >> 1), 6, bonus, 2); + res = (u16 *)sub_080653CC(); + sub_08065230(res, ((w - ((u32) sub_0801A638((u8 *)text85U) >> 1)) - n) * 8, 0x38, 0x1AU, 0); + } + } + goto icons; + case 10: + desc |= 0x140000; + res = (u16 *)sub_08007290(desc); + p = res + 2; + x = 0; + n = 0; + while (*p != 0xFFFD) { + if (*p == 0xFFFF) { + text85U[x][n] = 0xFFFD; + x++; + n = 0; + } else { + text85U[x][n] = *p; + n++; + } + p++; + } + text85U[x][n] = 0xFFFD; + CENTER815F4(text85U, 7); + q = text85U[1]; + CENTER815F4(q, 9); + goto icons; + } + res = (u16 *)sub_08007290(0x140328); + p = expand815F4(res, *(u16 *)(weapon + 0x176) + *(u8 *)(arg + 6), text85U[0]); + *p = 0x51; + if (bonus != 0) { + *++p = 0x51; + *++p = 0x51; + } + if (*(u16 *)(weapon + 0x184) == 7) { + res = (u16 *)sub_08007290((*(u16 *)(weapon + 0x174) * 2 + 0x32A) | 0x140000); + expand815F4(res, *(u16 *)(weapon + 0x184), p + 1); + } else { + res = (u16 *)sub_08007290((*(u16 *)(weapon + 0x174) * 2 + 0x329) | 0x140000); + expand815F4(res, *(u16 *)(weapon + 0x184), p + 1); + } + sub_0801A3D0((u8 *)text85U, (u16) (0xF - ((u32) sub_0801A638((u8 *)text85U) >> 1)), 5U); + if (bonus != 0) { + x = p - text85U[0]; + if (((bonus / 100U) << 0x10) == 0) { + if (((bonus / 10U) << 0x10) == 0) { + x -= 1; + n = 1; + } else { + n = 2; + } + } else { + x += 1; + n = 3; + } + { + s32 w; + v = sub_0801A638((u8 *)text85U); + w = x + 0xF; + sub_0805FB7C(w - ((u32) v >> 1), 6, bonus, 2); + res = (u16 *)sub_080653CC(); + sub_08065230(res, ((w - ((u32) sub_0801A638((u8 *)text85U) >> 1)) - n) * 8, 0x38, 0x1AU, 0); + } + } + break; + case 3: + if (*(u8 *)(arg + 8) != 0) { + mask = 0; + break; + } + bonus = localU_E378((s32)gUnk_030034E0 + 0x3C, *(s32 *)(armor + 0x174), sub_0801DE60()); + bonus = (u16)(bonus - *(s32 *)(armor + 0x174)); + res = (u16 *)sub_08007290(0x140329); + p = expand815F4(res, *(s32 *)(armor + 0x174) + *(u8 *)(arg + 6), text85U[0]); + *p = 0x51; + if (bonus != 0) { + *++p = 0x51; + *++p = 0x51; + } + res = (u16 *)sub_08007290(0x14032A); + expand815F4(res, *(u16 *)(armor + 0x17C), p + 1); + sub_0801A3D0((u8 *)text85U, (u16) (0xF - ((u32) sub_0801A638((u8 *)text85U) >> 1)), 5U); + if (bonus != 0) { + x = p - text85U[0]; + if (((bonus / 100U) << 0x10) == 0) { + if (((bonus / 10U) << 0x10) == 0) { + x -= 1; + n = 1; + } else { + n = 2; + } + } else { + x += 1; + n = 3; + } + { + s32 w; + v = sub_0801A638((u8 *)text85U); + w = x + 0xF; + sub_0805FB7C(w - ((u32) v >> 1), 6, bonus, 2); + res = (u16 *)sub_080653CC(); + sub_08065230(res, ((w - ((u32) sub_0801A638((u8 *)text85U) >> 1)) - n) * 8, 0x38, 0x1AU, 0); + } + } + break; + case 4: + if (*(u8 *)(arg + 8) != 0) { + mask = 0; + break; + } + bonus = localU_E378((s32)gUnk_030034E0 + 0x3C, *(s32 *)(helmet + 0x174), sub_0801DE60()); + bonus = (u16)(bonus - *(s32 *)(helmet + 0x174)); + res = (u16 *)sub_08007290(0x140329); + p = expand815F4(res, *(s32 *)(helmet + 0x174) + *(u8 *)(arg + 6), text85U[0]); + *p = 0x51; + if (bonus != 0) { + *++p = 0x51; + *++p = 0x51; + } + res = (u16 *)sub_08007290(0x14032A); + expand815F4(res, *(u16 *)(helmet + 0x17C), p + 1); + sub_0801A3D0((u8 *)text85U, (u16) (0xF - ((u32) sub_0801A638((u8 *)text85U) >> 1)), 5U); + if (bonus != 0) { + x = p - text85U[0]; + if (((bonus / 100U) << 0x10) == 0) { + if (((bonus / 10U) << 0x10) == 0) { + x -= 1; + n = 1; + } else { + n = 2; + } + } else { + x += 1; + n = 3; + } + { + s32 w; + v = sub_0801A638((u8 *)text85U); + w = x + 0xF; + sub_0805FB7C(w - ((u32) v >> 1), 6, bonus, 2); + res = (u16 *)sub_080653CC(); + sub_08065230(res, ((w - ((u32) sub_0801A638((u8 *)text85U) >> 1)) - n) * 8, 0x38, 0x1AU, 0); + } + } + break; + case 5: + if (*(u8 *)(arg + 8) != 0) { + mask = 0; + break; + } + if (*(s32 *)(shield + 0x17C) != 0) { + bonus = localU_E3D8((s32)gUnk_030034E0 + 0x3C, *(s32 *)(shield + 0x174), sub_0801DE60()); + } else { + bonus = localU_E378((s32)gUnk_030034E0 + 0x3C, *(s32 *)(shield + 0x174), sub_0801DE60()); + } + bonus = (u16)(bonus - *(s32 *)(shield + 0x174)); + res = (u16 *)sub_08007290(0x140329); + p = expand815F4(res, *(s32 *)(shield + 0x174) + *(u8 *)(arg + 6), text85U[0]); + *p = 0x51; + if (bonus != 0) { + *++p = 0x51; + *++p = 0x51; + } + res = (u16 *)sub_08007290(0x14032A); + expand815F4(res, *(u16 *)(shield + 0x180), p + 1); + sub_0801A3D0((u8 *)text85U, (u16) (0xF - ((u32) sub_0801A638((u8 *)text85U) >> 1)), 5U); + if (bonus != 0) { + x = p - text85U[0]; + if (((bonus / 100U) << 0x10) == 0) { + if (((bonus / 10U) << 0x10) == 0) { + x -= 1; + n = 1; + } else { + n = 2; + } + } else { + x += 1; + n = 3; + } + { + s32 w; + v = sub_0801A638((u8 *)text85U); + w = x + 0xF; + sub_0805FB7C(w - ((u32) v >> 1), 6, bonus, 2); + res = (u16 *)sub_080653CC(); + sub_08065230(res, ((w - ((u32) sub_0801A638((u8 *)text85U) >> 1)) - n) * 8, 0x38, 0x1AU, 0); + } + } + break; + } +icons: + n = 0; + for (x = 0; x <= 9; x++) { + if ((mask >> x) & 1) { + u8 *e_ = table85; + icon = &icons[n]; + sub_08065158(icon, *(u32 *)(e_ + 0x58 * x), 1, -1, 0); + sub_08000AF0(n + 0x10, (void *)icons[n].palette, 1U); + *((s8 *)icon + 0x1C) = n; + n += 1; + } + } + for (x = 0; x < n; x++) { + sub_08065230(&icons[x], 0x84 - n * 0xC + x * 0x18, 0x81, 0U, 0); + } + kind = *(u16 *)arg; + switch ((s32)kind) { + case 8: + case 9: + return; + case 1: + if (detail->kind == 0) + return; + res = (u16 *)sub_08007290((detail->kind + 0x314) | 0x140000); + v = detail->value; + asm("" : "+r"(v)); + sub_08081518(0xF, 7U, (s32)res, (u16)v, kind); + return; + case 10: + sub_0805FFBC(0xF, 6, arg, 0x80000000); + return; + default: + if (mask != 0) { + count = 0; + for (x = 0; x <= 2 && detail != NULL; x++) { + if (detail[x].kind != 0 && detail[x].kind != 0x29) + count += 1; + } + for (x = 0; x <= 2 && detail != NULL; detail++, x++) { + if (detail->kind != 0 && detail->kind != 0x29) { + if (detail->value & 0x8000) { + res = (u16 *)sub_08007290((detail->kind * 2 + 0x2C4) | 0x140000); + } else { + res = (u16 *)sub_08007290((detail->kind * 2 + 0x2C3) | 0x140000); + } + switch (count) { + case 1: + a1 = (s16)detail->value; + if (a1 < 0) + a1 = -a1; + sub_08081518(0xF, 9U, (s32)res, (u16)a1, count); + break; + case 2: + y = (u16)(x * 2 + 8); + a2 = (s16)detail->value; + if (a2 < 0) + a2 = -a2; + sub_08081518(0xF, y, (s32)res, (u16)a2, 1); + break; + case 3: + y = (u16)(x * 2 + 7); + a3 = (s16)detail->value; + if (a3 < 0) + a3 = -a3; + sub_08081518(0xF, y, (s32)res, (u16)a3, 1); + break; + } + } + } + } else { + res = (u16 *)sub_08007290(0x140365); + p = res + 2; + CENTER815F4(p, 9); + } + break; + } +} +#else /* Expanded twelve times: each block-local v_ gets its own frame slot (0x20C..0x238 in code order). res85 is one function-scope pointer shared by every resource lookup, so global-alloc keeps the ROM's `adds r2, r0, #0` copy after each sub_08007290 call. d_ is taken after the value, so a @@ -4753,7 +5378,7 @@ void sub_080815F4(void *arg0) { sp254 = 0; break; } - switch (*(u8 *)(sp240 + 0x9B)) { + switch (ITEM_KIND(sp240)) { default: temp_r4_8 = gUnk_030034E0 + 0x30; temp_r6_3 = (*((u8 *)((u8 *)(sp240) + (0x9C)))); @@ -4819,9 +5444,9 @@ void sub_080815F4(void *arg0) { *++var_r6 = 0x51; } if ((*((u16 *)((u8 *)(sp240) + (0xAC)))) == 7) { - FMT815F4(var_r8_12, var_r6 + 1, ((*(u8 *)(sp240 + 0x9B) * 2) + 0x32A) | 0x140000, (s32) (*((u16 *)((u8 *)(sp240) + (0xAC))))); + FMT815F4(var_r8_12, var_r6 + 1, ((ITEM_KIND(sp240) * 2) + 0x32A) | 0x140000, (s32) (*((u16 *)((u8 *)(sp240) + (0xAC))))); } else { - FMT815F4(var_r8_12, var_r6 + 1, ((*(u8 *)(sp240 + 0x9B) * 2) + 0x329) | 0x140000, (s32) (*((u16 *)((u8 *)(sp240) + (0xAC))))); + FMT815F4(var_r8_12, var_r6 + 1, ((ITEM_KIND(sp240) * 2) + 0x329) | 0x140000, (s32) (*((u16 *)((u8 *)(sp240) + (0xAC))))); } sub_0801A3D0(text85, (u16) (0xF - ((u32) sub_0801A638(text85) >> 1)), 5U); if (sp258 == 0) { @@ -4853,10 +5478,10 @@ void sub_080815F4(void *arg0) { sp254 = 0; } else { temp_r4 = gUnk_030034E0 + 0x30; - temp_r5 = (*((u8 *)((u8 *)(sp244) + (0x9B)))); + temp_r5 = ITEM_KIND(sp244); sp25C = (u32) local815F4_sub_0801E378(temp_r4, (u16) temp_r5, sub_0801DE60()); - sp25C = (u32) (u16) (sp25C - (*((u8 *)((u8 *)(sp244) + (0x9B))))); - FMT1_815F4(var_r8_2, (text85), 0x140329, (*((u8 *)((u8 *)(sp244) + (0x9B)))) + (*((u8 *)((u8 *)(sp23C) + (6)))), var_r6); + sp25C = (u32) (u16) (sp25C - ITEM_KIND(sp244)); + FMT1_815F4(var_r8_2, (text85), 0x140329, ITEM_KIND(sp244) + (*((u8 *)((u8 *)(sp23C) + (6)))), var_r6); (*((u8 *)((u8 *)(var_r6) + (0)))) = 0x51; if (sp25C != 0) { *++var_r6 = 0x51; @@ -4895,10 +5520,10 @@ void sub_080815F4(void *arg0) { break; } temp_r4_3 = gUnk_030034E0 + 0x30; - temp_r5_3 = (*((u8 *)((u8 *)(sp248) + (0x9B)))); + temp_r5_3 = ITEM_KIND(sp248); sp25C = (u32) local815F4_sub_0801E378(temp_r4_3, (u16) temp_r5_3, sub_0801DE60()); - sp25C = (u32) (u16) (sp25C - (*((u8 *)((u8 *)(sp248) + (0x9B))))); - FMT1_815F4(var_r8_5, (text85), 0x140329, (*((u8 *)((u8 *)(sp248) + (0x9B)))) + (*((u8 *)((u8 *)(sp23C) + (6)))), var_r6); + sp25C = (u32) (u16) (sp25C - ITEM_KIND(sp248)); + FMT1_815F4(var_r8_5, (text85), 0x140329, ITEM_KIND(sp248) + (*((u8 *)((u8 *)(sp23C) + (6)))), var_r6); (*((u8 *)((u8 *)(var_r6) + (0)))) = 0x51; if (sp25C != 0) { *++var_r6 = 0x51; @@ -4938,12 +5563,12 @@ void sub_080815F4(void *arg0) { if ((*((u8 *)((u8 *)(sp24C) + (0xA0)))) != 0) { temp_r4_4 = gUnk_030034E0 + 0x30; var_r6 = sp24C + 0x9B; - temp_r5_5 = (*((u8 *)((u8 *)(sp24C) + (0x9B)))); + temp_r5_5 = ITEM_KIND(sp24C); sp25C = local815F4_sub_0801E3D8(temp_r4_4, (u16) temp_r5_5, sub_0801DE60()); } else { temp_r4_5 = gUnk_030034E0 + 0x30; var_r6 = sp24C + 0x9B; - temp_r5_6 = (*((u8 *)((u8 *)(sp24C) + (0x9B)))); + temp_r5_6 = ITEM_KIND(sp24C); sp25C = local815F4_sub_0801E378(temp_r4_5, (u16) temp_r5_6, sub_0801DE60()); } sp25C = (u32) (u16) (sp25C - *var_r6); @@ -5067,10 +5692,15 @@ void sub_080815F4(void *arg0) { break; } } +#endif struct Icon82960 { u16 unk0; s16 unk2; u32 zero; u8 flag; u8 pad[7]; }; struct Stat82960 { volatile u16 unk0; u16 unk2; }; struct Manager82960 { u8 pad[0x74]; struct { s32 y; s32 pad; } entries[6]; }; +#ifdef REGION_USA +struct Record82960 { u16 names[6][31]; u16 items[6]; struct Stat82960 stats[3]; }; +#else struct Record82960 { u16 names[5][31]; u16 items[6]; u16 pad; struct Stat82960 stats[3]; }; +#endif /* [DrawLocalizedEquipmentSetSummary] r0 record pointer; null returns with no drawing. Draws title * resource0x1403EC at row3, localized record name selected by global0x03003470 (31 halfwords per language), * truncating each character to byte, ending at low-byte zero or after31 characters then0xFD. Draws six @@ -5078,6 +5708,7 @@ struct Record82960 { u16 names[5][31]; u16 items[6]; u16 pad; struct Stat82960 s * mapping2,4,3,5,6,7, centered icon row with manager animation offsets. Scans three4-byte modifiers at+0x144, * excluding type0/41, selects positive/negative text resource from signed value bit15, draws absolute u16 * magnitude via0x08081518 with layout based on total valid modifiers. */ +#ifdef REGION_USA void sub_08082960(struct Record82960 *arg0) { s32 var_r4; u32 var_r5; @@ -5086,7 +5717,7 @@ void sub_08082960(struct Record82960 *arg0) { u32 stat_y; s32 icon_x; struct Icon82960 sp4; - u8 sp14[40]; + TextChar sp14[40]; s16 var_r0; s32 var_r3; s32 var_r3_2; @@ -5096,24 +5727,24 @@ void sub_08082960(struct Record82960 *arg0) { s32 var_r0_2; u32 work1; - u16 temp_r0; - u16 temp_r0_2; + u32 temp_r0; + u32 temp_r0_2; u16 temp_r0_3; u16 temp_r0_4; - u8 *var_r2; + TextChar *var_r2; if (arg0 == 0) { return; } temp_r2_2 = sub_08007290(0x1403EC); - var_r4 = temp_r2_2 + 2; + var_r4 = temp_r2_2 + TEXT_HEADER; sub_0801A3D0(((u8 *)var_r4), (u16) (0xF - ((u32) sub_0801A638(((u8 *)var_r4)) >> 1)), 3); var_r2 = sp14; var_r5 = 0; temp_r0 = arg0->names[gUnk_03003470][0]; *var_r2 = temp_r0; - first_byte = (u32)temp_r0 << 24; - + asm("" : "+r"(temp_r0)); + first_byte = temp_r0 << 16; var_r4 = (s32)var_r2; if (first_byte != 0) { do { @@ -5122,14 +5753,15 @@ void sub_08082960(struct Record82960 *arg0) { if (var_r5 > 30) break; temp_r0_2 = arg0->names[gUnk_03003470][var_r5]; *var_r2 = temp_r0_2; - } while (*var_r2 != 0); + asm("" : "+r"(temp_r0_2)); + } while ((u16)temp_r0_2 != 0); } - *var_r2 = 0xFD; + *var_r2 = TEXT_CTRL(0xFD); sub_0801A3D0(((u8 *)var_r4), (u16) (0xF - ((u32) sub_0801A638(((u8 *)var_r4)) >> 1)), 0x12); var_r4 = 0; var_r5 = 0; var_r3 = 0x8000; - var_r2 = (u8 *)arg0->items; + var_r2 = (TextChar *)arg0->items; do { work1 = *(u16 *)var_r2; var_r0_2 = var_r3 & work1; @@ -5137,7 +5769,7 @@ void sub_08082960(struct Record82960 *arg0) { if (!var_r0_2) { var_r4 += 1; } - var_r2 += 2; + var_r2 += 2 / sizeof(TextChar); var_r5 += 1; } while (var_r5 <= 5U); sp4.zero = 0; @@ -5236,8 +5868,168 @@ do { } } } - - +#else +void sub_08082960(struct Record82960 *arg0) { + s32 var_r4; + u32 var_r5; + u32 var_r6; + u32 first_byte; + u32 stat_y; + s32 icon_x; + struct Icon82960 sp4; + u8 sp14[40]; + s16 var_r0; + s32 var_r3; + s32 var_r3_2; + s32 var_r3_3; + s32 temp_r2; + s32 temp_r2_2; + s32 var_r0_2; + u32 work1; + + u16 temp_r0; + u16 temp_r0_2; + u16 temp_r0_3; + u16 temp_r0_4; + u8 *var_r2; + + if (arg0 == 0) { + return; + } + temp_r2_2 = sub_08007290(0x1403EC); + var_r4 = temp_r2_2 + 2; + sub_0801A3D0(((u8 *)var_r4), (u16) (0xF - ((u32) sub_0801A638(((u8 *)var_r4)) >> 1)), 3); + var_r2 = sp14; + var_r5 = 0; + temp_r0 = arg0->names[gUnk_03003470][0]; + *var_r2 = temp_r0; + first_byte = (u32)temp_r0 << 24; + + var_r4 = (s32)var_r2; + if (first_byte != 0) { + do { + var_r5++; + var_r2++; + if (var_r5 > 30) break; + temp_r0_2 = arg0->names[gUnk_03003470][var_r5]; + *var_r2 = temp_r0_2; + } while (*var_r2 != 0); + } + *var_r2 = 0xFD; + sub_0801A3D0(((u8 *)var_r4), (u16) (0xF - ((u32) sub_0801A638(((u8 *)var_r4)) >> 1)), 0x12); + var_r4 = 0; + var_r5 = 0; + var_r3 = 0x8000; + var_r2 = (u8 *)arg0->items; + do { + work1 = *(u16 *)var_r2; + var_r0_2 = var_r3 & work1; + asm("" : "+r"(work1), "+r"(var_r0_2)); + if (!var_r0_2) { + var_r4 += 1; + } + var_r2 += 2; + var_r5 += 1; + } while (var_r5 <= 5U); + sp4.zero = 0; + sp4.flag = 0; + var_r6 = 0; + var_r5 = 0; + do { + temp_r2 = var_r5 * 2; + if (!(0x8000 & arg0->items[var_r5])) { + switch (var_r5) { + case 0: sp4.unk0 = 2; break; + case 2: sp4.unk0 = 3; break; + case 1: sp4.unk0 = 4; break; + case 3: sp4.unk0 = 5; break; + case 4: sp4.unk0 = 6; break; + case 5: sp4.unk0 = 7; break; + } + sp4.unk2 = (u16) arg0->items[var_r5]; + icon_x = (var_r6 * 0x10) + 0x80; + sub_0805FC80(icon_x - (var_r4 * 8), 0x38 - ((struct Manager82960 *)gUnk_03006440)->entries[var_r5].y, &sp4, 0); + var_r6 += 1; + } + var_r5 += 1; + } while (var_r5 <= 5U); + var_r4 = (s32)arg0->stats; + var_r6 = 0; + var_r5 = 0; + if (((struct Stat82960 *)var_r4) != NULL) { + work1 = (u32)var_r4; +loop_24: + temp_r0_3 = *(u16 *)work1; + if ((temp_r0_3 != 0) && (temp_r0_3 != 0x29)) { + var_r6 += 1; + } + work1 += 4; + var_r5 += 1; + if ((var_r5 <= 2U) && (((struct Stat82960 *)var_r4) != NULL)) { + goto loop_24; + } + var_r5 = 0; + if (((struct Stat82960 *)var_r4) != NULL) { +do { +loop_30: + temp_r0_4 = ((struct Stat82960 *)var_r4)->unk0; + if ((temp_r0_4 != 0) && (temp_r0_4 != 0x29)) { + var_r0_2 = ((struct Stat82960 *)var_r4)->unk2; + temp_r2_2 = 0x8000; + work1 = temp_r2_2; + asm("" : "+r"(temp_r2_2), "+&r"(work1)); + if (var_r0_2 & work1) { + var_r0_2 = ((struct Stat82960 *)var_r4)->unk0 * 2; + var_r3 = 0x2C4; + asm("" : "+r"(var_r3), "+r"(var_r0_2)); + var_r0_2 += var_r3; + } else { + var_r0_2 = ((struct Stat82960 *)var_r4)->unk0 * 2; + work1 = 0x2C3; + + var_r0_2 += work1; + } + work1 = 0x140000; + var_r0_2 |= work1; + temp_r2_2 = sub_08007290(var_r0_2); + switch (var_r6) { /* switch 2; irregular */ + case 1: /* switch 2 */ + var_r3 = (s16) ((struct Stat82960 *)var_r4)->unk2; + if ((s32) var_r3 < 0) { + var_r3 = 0 - var_r3; + } + sub_08081518(0xF, 0xBU, temp_r2_2, (u16) var_r3, var_r6); + break; + case 2: /* switch 2 */ + stat_y = (u32) ((var_r5 << 0x11) + 0xA0000) >> 0x10; + var_r3_2 = (s16) ((struct Stat82960 *)var_r4)->unk2; + if ((s32) var_r3_2 < 0) { + var_r3_2 = 0 - var_r3_2; + } + sub_08081518(0xF, stat_y, temp_r2_2, (u16) var_r3_2, 1U); + break; + case 3: /* switch 2 */ + stat_y = (u32) ((var_r5 << 0x11) + 0x90000) >> 0x10; + var_r3_3 = (s16) ((struct Stat82960 *)var_r4)->unk2; + if ((s32) var_r3_3 < 0) { + var_r3_3 = 0 - var_r3_3; + } + sub_08081518(0xF, stat_y, temp_r2_2, (u16) var_r3_3, 1U); + break; + } + } + } while (0); + var_r4 += 4; + var_r5 += 1; + if ((var_r5 <= 2U) && (((struct Stat82960 *)var_r4) != NULL)) { + goto loop_30; + } + } + } +} +#endif + + @@ -5254,7 +6046,8 @@ void sub_08082BB0_u32(u32 arg0) asm("sub_08082BB0"); * current/held items or detailed record view, refreshes signed stat preview and inventory contents, with * variant-specific collection background updates. */ void sub_08082BB0_u32(u32 arg0) { - struct PlayerWords82BB0 { u8 pad[0x8C]; u32 w8C, w90; u8 tail[0x14C - 0x94]; }; +#ifdef REGION_USA + struct PlayerWords82BB0 { u8 pad[PLAYER_FIELD(0x8C)]; u32 w8C, w90; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x94)]; }; extern struct PlayerWords82BB0 players82BB0[] asm("gUnk_03003CE0"); extern u32 sub_08001108_word82BB0(u32) asm("sub_08001108"); struct Index82BB0 { u8 pad[0x14A]; u16 value; }; @@ -5287,6 +6080,7 @@ void sub_08082BB0_u32(u32 arg0) { u32 sp48; s32 sp4C; s32 sp50; + u16 var_sl; u32 sp54; s32 temp_r4; s32 temp_r0_13; @@ -5317,7 +6111,6 @@ void sub_08082BB0_u32(u32 arg0) { u16 temp_r0_22; s32 temp_r1_3; u16 temp_r1_4; - u16 var_sl; u32 temp_r0; u32 temp_r0_14; u32 temp_r4_4; @@ -5366,7 +6159,7 @@ void sub_08082BB0_u32(u32 arg0) { switch (arg0) { /* switch 1; irregular */ case 7: /* switch 1 */ (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x0)) = 4; - temp_r0 = (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + 0x6A)) - 1; + temp_r0 = (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + SAVE_FIELD(0x6A))) - 1; switch (temp_r0) { case 0: sub_0800B650(0x4000001B, 0x1D, 0x06000000, 0U, 0xFU); break; case 1: sub_0800B650(0x4000001C, 0x1D, 0x06000000, 0U, 0xFU); break; @@ -5396,6 +6189,9 @@ void sub_08082BB0_u32(u32 arg0) { } stage82BB0.value = table82BB0Stage[index82BB0->value]; sub_0800B650(0x10, 0x1F, 0x06000000, 0U, 0xEU); +#ifdef REGION_USA + sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x50006, 0, -1, 0); /* single language */ +#else switch (gUnk_03003470) { case 0: sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x50006, 0, -1, 0); break; case 1: sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x50007, 0, -1, 0); break; @@ -5403,7 +6199,8 @@ void sub_08082BB0_u32(u32 arg0) { case 3: sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x50009, 0, -1, 0); break; case 4: sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x5000A, 0, -1, 0); break; } - sub_08065158(((u8 *)manager82BB0) + 0x5EC, 0x5007A, 0, -1, 0); +#endif + sub_08065158(((u8 *)manager82BB0) + 0x5EC, RES_ID(0x5007A), 0, -1, 0); sub_08000AF0(0x1EU, (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x5F8)), 1U); (*(u8 *)((u8 *)(((u8 *)manager82BB0)) + 0x608)) = 0xE; if (arg0 == 7) { @@ -5469,13 +6266,13 @@ void sub_08082BB0_u32(u32 arg0) { (*(s32 *)((u8 *)(postsetup82BB0) + 0x40)) = 0; (*(s32 *)((u8 *)(postsetup82BB0) + 0x44)) = 0; bank_setup82BB0 = (u8 *)bank82BB0; - (*(s32 *)((u8 *)(postsetup82BB0) + 0x48)) = (s32) (*(u16 *)((u8 *)(bank_setup82BB0) + 0x6A)); + (*(s32 *)((u8 *)(postsetup82BB0) + 0x48)) = (s32) (*(u16 *)((u8 *)(bank_setup82BB0) + SAVE_FIELD(0x6A))); (*(s32 *)((u8 *)(postsetup82BB0) + 0x54)) = 0; (*(s32 *)((u8 *)(postsetup82BB0) + 0x5C)) = 0; sp50 = 0; var_r9 = 0; (*(u16 *)((u8 *)(postsetup82BB0) + 0x6A)) = 0x64U; - var_sl = (*(u16 *)((u8 *)(bank_setup82BB0) + 0x68)); + var_sl = (*(u16 *)((u8 *)(bank_setup82BB0) + SAVE_FIELD(0x68))); init_halves = (u16 *)(postsetup82BB0 + 0x4C); *init_halves++ = 0; *init_halves++ = 0; @@ -5485,31 +6282,25 @@ void sub_08082BB0_u32(u32 arg0) { (*(u32 *)((u8 *)(postsetup82BB0) + 0x6C)) = 3; var_r6 = 0; sp54 = arg0 - 1; - do { - row82BB0 = (u32 *)manager82BB0; - temp_r2 = var_r6 * 8; - rowzero82BB0 = (u32 *)((u8 *)row82BB0 + 0x74); - - *(u32 *)((u8 *)rowzero82BB0 + temp_r2) = 0; - row82BB0 = (u32 *)((u8 *)row82BB0 + 0x78); - - row82BB0 = (u32 *)((u8 *)row82BB0 + temp_r2); - *row82BB0 = var_r6 % 5U; + { + struct Rows82 { u8 p[0x74]; struct { s32 t; u32 n; } r[6]; }; + u8 *m; + s32 zero; + rowLoop: + m = (u8 *)manager82BB0; + ((struct Rows82 *)m)->r[var_r6].t = zero = 0; + ((struct Rows82 *)m)->r[var_r6].n = var_r6 % 5U; + asm("" : : "r"(zero)); var_r6 += 1; - } while (var_r6 <= 5U); - switch (gUnk_03003470) { - case 0: sub_08065158((u8 *)manager82BB0 + 0xA4, 0x50002, 0, 0x80000000, 0); break; - case 1: sub_08065158((u8 *)manager82BB0 + 0xA4, 0x5015B, 0, 0x80000000, 0); break; - case 2: sub_08065158((u8 *)manager82BB0 + 0xA4, 0x5015C, 0, 0x80000000, 0); break; - case 3: sub_08065158((u8 *)manager82BB0 + 0xA4, 0x5015D, 0, 0x80000000, 0); break; - case 4: sub_08065158((u8 *)manager82BB0 + 0xA4, 0x5015E, 0, 0x80000000, 0); break; + if (var_r6 <= 5U) goto rowLoop; + sub_08065158(m + 0xA4, 0x50002, 0, 0x80000000, zero); } switch (sp54) { /* switch 5; irregular */ case 0: /* switch 5 */ if (sub_0800CE30() != 0) { - var_r0_5 = ((u8 *)bank82BB0) + 0xB50; + var_r0_5 = ((u8 *)bank82BB0) + SAVE_FIELD(0xB50); } else { - var_r0_5 = ((u8 *)bank82BB0) + 0x910; + var_r0_5 = ((u8 *)bank82BB0) + SAVE_FIELD(0x910); } goto block_60; case 1: /* switch 5 */ @@ -5529,43 +6320,33 @@ void sub_08082BB0_u32(u32 arg0) { goto block_61; case 4: /* switch 5 */ if (sub_0800CE30() != 0) { - var_r0_5 = ((u8 *)bank82BB0) + 0x9D0; + var_r0_5 = ((u8 *)bank82BB0) + SAVE_FIELD(0x9D0); } else { - var_r0_5 = ((u8 *)bank82BB0) + 0x790; + var_r0_5 = ((u8 *)bank82BB0) + SAVE_FIELD(0x790); } goto block_60; case 5: /* switch 5 */ if (sub_0800CE30() != 0) { - var_r0_5 = ((u8 *)bank82BB0) + 0xA90; + var_r0_5 = ((u8 *)bank82BB0) + SAVE_FIELD(0xA90); } else { - var_r0_5 = ((u8 *)bank82BB0) + 0x850; + var_r0_5 = ((u8 *)bank82BB0) + SAVE_FIELD(0x850); } block_60: sub_080852CC(var_r0_5); setup82BB0 = (u8 *)manager82BB0; block_61: *(s32 *)(setup82BB0 + 0x18) = 0xB; - common_words82BB0 = (s32 *)(setup82BB0 + 0xE0); - temp_r2 = 0xB8; - *common_words82BB0 = temp_r2; - asm("" : "+r"(common_words82BB0)); - common_words82BB0++; - temp_r1 = 0x20; - *common_words82BB0 = temp_r1; - asm("" : "+r"(common_words82BB0)); - common_words82BB0++; - *common_words82BB0 = temp_r2; - asm("" : "+r"(common_words82BB0)); - common_words82BB0++; - asm("" : "+r"(common_words82BB0)); - *common_words82BB0 = temp_r1; + *(s32 *)(setup82BB0 + 0xE0) = 0xB8; + *(s32 *)(setup82BB0 + 0xE4) = 0x20; + *(s32 *)(setup82BB0 + 0xE8) = 0xB8; + *(s32 *)(setup82BB0 + 0xEC) = 0x20; break; case 6: /* switch 5 */ mode_slot82BB0 = &bank82BB0; mode_index82BB0 = *(s32 *)((u8 *)manager82BB0 + 0x44); mode_offset82BB0 = mode_index82BB0 * 0xF0; - mode_offset82BB0 += 0x2E0; + mode_offset82BB0 += SAVE_FIELD(0x2E0); { s32 slot82BB0 = (s32)*mode_slot82BB0; register s32 sum82BB0 asm("r0") = slot82BB0; sum82BB0 = slot82BB0 + mode_offset82BB0; sub_080852CC(sum82BB0); } break; @@ -5623,7 +6404,7 @@ void sub_08082BB0_u32(u32 arg0) { } } else { resource_word82BB0 = sub_08007290(table82BB0Text[*(s32 *)((u8 *)manager82BB0 + 4)] | 0x140000); - temp_r4_2 = (u8 *)(resource_word82BB0 + 2); + temp_r4_2 = (u8 *)(resource_word82BB0 + TEXT_HEADER); sub_0801A3D0(temp_r4_2, (u16) (0xF - ((u32) sub_0801A638(temp_r4_2) >> 1)), 0x12); } @@ -5636,13 +6417,13 @@ void sub_08082BB0_u32(u32 arg0) { } } } - if ((((*(u16 *)((u8 *)(((u8 *)manager82BB0)) + 0x6A)) != (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x4))) || (var_sl != (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + 0x68)))) && ((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x18)) != 0xE)) { + if ((((*(u16 *)((u8 *)(((u8 *)manager82BB0)) + 0x6A)) != (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x4))) || (var_sl != (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + SAVE_FIELD(0x68))))) && ((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x18)) != 0xE)) { if ((u32) ((*(u16 *)((u8 *)manager82BB0 + 0x68))++) > 5U) { sub_080811E0(sp44); refresh82BB0 = (struct Refresh82BB0 *)manager82BB0; refresh82BB0->w68 = 0U; refresh82BB0->w6A = (u16) refresh82BB0->w4; - var_sl = (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + 0x68)); + var_sl = (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + SAVE_FIELD(0x68))); } } sub_08080A78(); @@ -5665,7 +6446,7 @@ void sub_08082BB0_u32(u32 arg0) { } } if (((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x0)) == 4) && ((sp50 != (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x44))) || (var_r9 != (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x48))))) { - temp_r0_14 = (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + 0x6A)) - 1; + temp_r0_14 = (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + SAVE_FIELD(0x6A))) - 1; switch (temp_r0_14) { /* switch 6 */ case 0: /* switch 6 */ var_r6 = 0x4000001B; @@ -5700,11 +6481,11 @@ void sub_08082BB0_u32(u32 arg0) { fade_y82BB0 = (fade_y82BB0 >> 5) + *(s32 *)((u8 *)manager82BB0 + 0x54) + 0x60; sub_08065230(fade_sprite82BB0, fade_x82BB0, fade_y82BB0, 2U, temp_r5); temp_r0_15 = (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x18)); - if (((temp_r0_15 == 0) || (temp_r0_15 == 0x11)) && (temp_r0_15 != 0x12)) { + if (temp_r0_15 != 0x12) { resource_word82BB0 = sub_08007290(0x140185); - temp_r4_3 = (u8 *)(resource_word82BB0 + 2); + temp_r4_3 = (u8 *)(resource_word82BB0 + TEXT_HEADER); - sub_0801A3D0(temp_r4_3, (u16) (0xF - ((u32) sub_0801A638(temp_r4_3) >> 1)), 0x12); + sub_0801A3D0(temp_r4_3, (u16) (0x10 - ((u32) sub_0801A638(temp_r4_3) >> 1)), 0x12); } } else { var_r8 = 0x40; @@ -5728,9 +6509,9 @@ void sub_08082BB0_u32(u32 arg0) { switch (sp54) { /* switch 7; irregular */ case 0: /* switch 7 */ if (sub_0800CE30() != 0) { - var_r0_6 = ((u8 *)bank82BB0) + 0xB50; + var_r0_6 = ((u8 *)bank82BB0) + SAVE_FIELD(0xB50); } else { - var_r0_6 = ((u8 *)bank82BB0) + 0x910; + var_r0_6 = ((u8 *)bank82BB0) + SAVE_FIELD(0x910); } var_r6 = 9; do { @@ -5742,9 +6523,9 @@ void sub_08082BB0_u32(u32 arg0) { break; case 4: /* switch 7 */ if (sub_0800CE30() != 0) { - var_r0_7 = ((u8 *)bank82BB0) + 0x9D0; + var_r0_7 = ((u8 *)bank82BB0) + SAVE_FIELD(0x9D0); } else { - var_r0_7 = ((u8 *)bank82BB0) + 0x790; + var_r0_7 = ((u8 *)bank82BB0) + SAVE_FIELD(0x790); } var_r6 = 9; do { @@ -5756,9 +6537,9 @@ void sub_08082BB0_u32(u32 arg0) { break; case 5: /* switch 7 */ if (sub_0800CE30() != 0) { - var_r0_8 = ((u8 *)bank82BB0) + 0xA90; + var_r0_8 = ((u8 *)bank82BB0) + SAVE_FIELD(0xA90); } else { - var_r0_8 = ((u8 *)bank82BB0) + 0x850; + var_r0_8 = ((u8 *)bank82BB0) + SAVE_FIELD(0x850); } var_r6 = 9; do { @@ -5769,15 +6550,15 @@ void sub_08082BB0_u32(u32 arg0) { } while (var_r6 <= 0xBU); break; case 6: - for (var_r6 = 0; var_r6 < (u32)(*(u16 *)((u8 *)bank82BB0 + 0x6A) * 0xF); var_r6++) { + for (var_r6 = 0; var_r6 < (u32)(*(u16 *)((u8 *)bank82BB0 + SAVE_FIELD(0x6A)) * 0xF); var_r6++) { temp_r1_6 = (u8 *)bank82BB0; - var_r8 = 0x2E0; + var_r9 = SAVE_FIELD(0x2E0); temp_r2_2 = var_r6 * 0x10; temp_r1_7 = temp_r1_6 + temp_r2_2; - asm("" : "+r"(temp_r1_7) : "r"(var_r8)); + asm("" : "+r"(temp_r1_7) : "r"(var_r9)); temp_r0_24 = (u8 *)manager82BB0 + temp_r2_2; asm("" : "+r"(temp_r0_24) : "r"(temp_r1_7)); - *(struct Record82BB0 *)(temp_r1_7 + var_r8) = *(struct Record82BB0 *)(temp_r0_24 + 0x104); + *(struct Record82BB0 *)(temp_r1_7 + var_r9) = *(struct Record82BB0 *)(temp_r0_24 + 0x104); } break; case 8: /* switch 7 */ @@ -5796,2239 +6577,3695 @@ void sub_08082BB0_u32(u32 arg0) { } sub_08085398(); sub_08000420(0x11201100); -} -/* [RunItemMenuMessageDialogue] Full-word r0 indexes sprite/message tables0x084ECBDC/0x084ECC04 without bounds - * check. Initializes local descriptor, picks palette source variant for indices3/4/9, sets manager word+0x28 - * bit1. Expands message byte0xFC from save-state name stream at0x030034E0 into local32-byte buffer with u16 - * indices; no capacity checks. Slides descriptor to(240,136), reveals text progressively centered on row18, - * then waits for input halfword0x03001324 bit0 while blinking0xA0 marker. On acknowledgement plays song15 and - * slides away, yielding throughout. Suspend-request or link-error exits skip animation; all exits clear - * manager bit1. Does not claim debounce, exact input-newness or explicit text erase. */ -void sub_0808381C(u32 index) -{ - /* Empty constraints preserve the original register lifetimes and truncations. */ - u32 descriptorWords[13]; - u8 text[32]; - u8 liveText[32]; - volatile u32 visible; - u8 *source; - u8 *manager; - u16 sourceOffset; - u16 textLength; - register u32 dictionaryOffset asm("ip"); - - u32 countdown; - s16 amount; - u16 x; - extern u16 keys8381C asm("gUnk_03001324"); - - sub_08065158(((u8 *)descriptorWords), gUnk_084ECBDC[index], 0, -1, 0); - if (index == 9 || index == 3 || index == 4) { - sub_08000AF0(0x1E, (const void *)*(u32 *)(((u8 *)descriptorWords) + 0x0C), 1); - ((u8 *)descriptorWords)[0x1C] = 0x0E; - } else { - sub_08000AF0(0x1E, (u8 *)*(u32 *)(((u8 *)descriptorWords) + 0x0C) + 0x1C0, 1); - } - - source = (u8 *)sub_08007290(gUnk_084ECC04[index] | 0x140000); - manager = (u8 *)gUnk_03006440; - *(u32 *)(manager + 0x28) |= 2; - - countdown = 0x40; - textLength = 0; - dictionaryOffset = 0; - sourceOffset = 0; - if (source[2] != 0xFD) { - do { - if (*(u8 *)((u32)source + ({ s32 offset = sourceOffset + 2; offset; })) == 0xFC) { - u8 *destination; - u8 *dictionary; - u32 previous; - destination = text + textLength++; - dictionary = (u8 *)gUnk_030034E0; - - previous = dictionaryOffset; - dictionaryOffset = (u16)(previous + 1); - *destination = dictionary[previous]; - if (dictionary[dictionaryOffset] == 0xFD) - sourceOffset++; - } else { - text[textLength++] = *({ u8 *pointer = source + ({ s32 offset = sourceOffset++ + 2; offset; }); pointer; }); - } - } while (*(u8 *)((u32)source + ({ s32 offset = sourceOffset + 2; offset; })) != 0xFD); - } - text[textLength] = 0xFD; - - if ((s16)countdown > 0) do { - if (sub_0800CDF8() != 0 || sub_080021A8() != 0) - goto done; - if (countdown == 1) - countdown = 0; - { - s32 scaled = countdown << 16; - s32 initial = scaled >> 16; - - amount = initial - (scaled >> 17); - } - countdown = (u16)amount; - sub_08065230(((u8 *)descriptorWords), amount + 0xF0, 0x88, 0, 0); - sub_080003F0(); - } while (amount > 0); - - { - register u32 i asm("r5"); - register u32 lastIndex asm("ip"); - u32 blink; - for (i = 0; i <= (u32)sub_0801A638(text);) { - if (sub_0800CDF8() != 0 || sub_080021A8() != 0) - goto done; - liveText[i] = text[i]; - { - register u32 next asm("r1") = i + 1; - liveText[next] = 0xFD; - - i = (u16)next; - } - sub_08065230(((u8 *)descriptorWords), 0xF0, 0x88, 0, 0); - x = 0x0F - ((u32)sub_0801A638(text) >> 1); - sub_0801A3D0(liveText, x, 0x12); - sub_080003F0(); - } - - { - register u32 previous asm("r0") = i - 1; - - lastIndex = (u16)previous; - } - blink = 0; - if ((keys8381C & 1) == 0) { - - u8 *cursor; - u8 *cursorEnd; - { - u8 *base = liveText; - u32 previous; - - previous = lastIndex; - cursor = base + previous; - cursorEnd = base + (previous + 1); - } +#else + struct PlayerWords82BB0 { u8 pad[0x8C]; u32 w8C, w90; u8 tail[PLAYER_SIZE - 0x94]; }; + extern struct PlayerWords82BB0 players82BB0[] asm("gUnk_03003CE0"); + extern u32 sub_08001108_word82BB0(u32) asm("sub_08001108"); + struct Index82BB0 { u8 pad[0x14A]; u16 value; }; + extern struct Index82BB0 *index82BB0 asm("gUnk_03005CF4"); + extern u16 table82BB0Stage[] asm("gUnk_084EBD38"); + extern u16 table82BB0Text[] asm("gUnk_084ECB98"); + extern struct Keys82BB0 keys82BB0 asm("gUnk_03001250"); + u8 scratch82BB0[60]; + extern struct Stage82BB0 stage82BB0 asm("gUnk_03001F40"); + struct ManagerView82BB0; + struct BankView82BB0; + struct BankView82BB0 **mode_slot82BB0; + s32 mode_index82BB0, mode_offset82BB0; + extern struct ManagerView82BB0 *manager82BB0 asm("gUnk_03006440"); + extern struct BankView82BB0 *bank82BB0 asm("gUnk_030034E0"); + u8 *setup82BB0; + u8 *bank_setup82BB0; + u8 *postsetup82BB0; + struct Refresh82BB0 { u8 pad0[4]; s32 w4; u8 pad8[0x60]; u16 w68, w6A; }; + struct Refresh82BB0 *refresh82BB0; + u8 *confirm82BB0; + s32 init_result82BB0; + u32 *row82BB0; + u32 *rowzero82BB0; + s32 *init_words; + s32 *common_words82BB0; + u16 *init_halves; + union Config82BB0 sp40; + struct Player *sp44; + u32 sp48; + s32 sp4C; + s32 sp50; + u32 sp54; + s32 temp_r4; + s32 temp_r0_13; + s32 temp_r0_15; + s32 temp_r1; + s32 temp_r1_2; + s32 temp_r1_5; + s32 temp_r2; + s32 temp_r2_2; + s32 temp_r5; + s32 var_r0; + s32 var_r0_2; + s32 var_r0_3; + s32 var_r0_4; + s32 var_r0_5; + s32 var_r0_6; + s32 var_r0_7; + s32 var_r0_8; + s32 var_r1; + s32 var_r1_2; + s32 var_r5; + s32 var_r9; + s32 first_flags82BB0; + s32 resource_word82BB0; + void *fade_sprite82BB0; + s32 fade_x82BB0; + s32 fade_y82BB0; + u16 temp_r0_22; + s32 temp_r1_3; + u16 temp_r1_4; + u16 var_sl; + u32 temp_r0; + u32 temp_r0_14; + u32 temp_r4_4; + u32 var_r6; + u32 var_r8; + u8 *temp_r4_2; + u8 *temp_r4_3; + u8 temp_r3; + void *temp_r0_10; + void *temp_r0_11; + void *temp_r0_12; + void *temp_r0_16; + void *temp_r0_17; + void *temp_r0_18; + void *temp_r0_19; + void *temp_r0_20; + void *temp_r0_21; + void *temp_r0_23; + void *temp_r0_24; + void *temp_r0_2; + void *temp_r0_3; + void *temp_r0_4; + void *temp_r0_5; + void *temp_r0_6; + void *temp_r0_7; + void *temp_r0_8; + void *temp_r0_9; + void *temp_r1_6; + void *temp_r1_7; + void *var_r2; + void *var_r2_2; + void *var_r2_3; - for (;;) { - if (sub_0800CDF8() != 0 || sub_080021A8() != 0) - goto done; - { - register u32 previousBlink asm("r1") = blink; - u32 nextBlink = previousBlink + 1; - - blink = (u16)nextBlink; - if (previousBlink <= 0x1D) - visible = ({ register u32 value asm("r1") = 1; value; }); - else if (blink > 0x1D) - visible = ({ register u32 value asm("r0") = 0; value; }); - } - if (blink > 0x28) - blink = 0; - if (({ register u32 value asm("r1") = visible; asm("" : "+r"(value) : "r"(cursor), "r"(cursorEnd) : "r4", "r8", "r10"); value; })) { - *cursor = 0xA0; - *cursorEnd = 0xFD; - } else { - *cursor = 0xFD; - } - { - register u8 *liveBase asm("r4") = liveText; - - sub_08065230(((u8 *)descriptorWords), 0xF0, 0x88, 0, 0); - x = 0x0F - ((u32)sub_0801A638(text) >> 1); - sub_0801A3D0(liveBase, x, 0x12); - sub_080003F0(); - } - if (keys8381C & 1) - break; - } + /* Original r8 has no dominating initialization before its first flag-4 use. */ + + sp44 = &gUnk_03003CE0[sub_080020F4()]; + sub_080009F8(0x1F00, 0, 1); + keys82BB0.x2 = 0; + keys82BB0.x0 = 0; + keys82BB0.x6 = 0; + keys82BB0.x4 = 0; + keys82BB0.xA = 0; + keys82BB0.x8 = 0; + keys82BB0.xE = 0; + keys82BB0.xC = 0; + switch (arg0) { /* switch 1; irregular */ + case 7: /* switch 1 */ + (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x0)) = 4; + temp_r0 = (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + 0x6A)) - 1; + switch (temp_r0) { + case 0: sub_0800B650(0x4000001B, 0x1D, 0x06000000, 0U, 0xFU); break; + case 1: sub_0800B650(0x4000001C, 0x1D, 0x06000000, 0U, 0xFU); break; + case 2: sub_0800B650(0x4000001E, 0x1D, 0x06000000, 0U, 0xFU); break; + case 3: sub_0800B650(0x40000021, 0x1D, 0x06000000, 0U, 0xFU); break; + case 4: sub_0800B650(0x40000025, 0x1D, 0x06000000, 0U, 0xFU); break; } - + sub_0800B7DC(0x2B, 0x1A, 0x06000000, 0U, 0xFU); + sub_0800B7DC(0x40000005, 0x1B, 0x06000000, 0U, 0xFU); + break; + case 8: + (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x0)) = 5; + sub_0800B7DC(0x1A, 0x1A, 0x06000000, 0U, 0xFU); + sub_0800B7DC(0x40000005, 0x1B, 0x06000000, 0U, 0xFU); + break; + case 9: + (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x0)) = 6; + sub_0800B7DC(0x2A, 0x1A, 0x06000000, 0U, 0xFU); + sub_0800B7DC(0x40000005, 0x1B, 0x06000000, 0U, 0xFU); + break; + default: /* switch 1 */ + (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x0)) = 3; + sub_0800B7DC(0x11, 0x1A, 0x06000000, 0U, 0xFU); + sub_0800B7DC(0x40000005, 0x1B, 0x06000000, 0U, 0xFU); + sub_08000AF0(0xEU, sub_08007290(0x70003) + 0x1C0, 1U); + break; } - - countdown = 0; - sub_0805865C(0x0F); - for (;;) { - if (sub_0800CDF8() != 0 || sub_080021A8() != 0) - goto done; - if (countdown == 0x9F) - countdown = 0xA0; - { - s32 initial = countdown << 16; - initial >>= 16; - - amount = initial - ((initial - 0xA0) >> 1); - } - countdown = (u16)amount; - sub_08065230(((u8 *)descriptorWords), amount + 0xF0, 0x88, 0, 0); - sub_080003F0(); - if (amount > 0x9F) - break; - } - sub_080003F0(); - sub_080003F0(); - -done: - manager = (u8 *)gUnk_03006440; - *(u32 *)(manager + 0x28) &= ~2u; -} -/* [RunItemMenuMessageWithVariantPanels] Full-word r0 message-table index. Chooses visual mode from - * flag-query0x08057AE8(21) only when current area0, otherwise mode2. Mode0 initializes three descriptor - * resources0x500CC/CB/CA, mode1 middleCB, mode2 rightCA; uses palette variants and eased panel slide-in/out, - * setting manager+0x28 bit1 while active. Looks up message via0x084ECC04[index]|0x140000, skips2-byte header, - * progressively copies into32-byte local text with u16 indices, draws centered row18, then waits - * input0x03001324 bit0 with blinking0xA0 marker. A acknowledgement plays sound15; suspend request/link error - * skips to cleanup, and all paths clear manager bit1. No binary choice result or item mutation here. */ -void sub_08083AE8(u32 input) - -{ - u32 param_1 = input; - /* Preserve the original 208-byte frame, including its outgoing argument. */ - extern u32 gUnk_084ECC04[]; - extern u16 sub_08057AE8(s32); - extern u16 keys83AE8 asm("gUnk_03001324"); - u8 frameStorage83AE8[204]; - register u8 *stack asm("sp"); - /* Empty constraints retain the original register and stack lifetimes. */ - s32 uVar1; - u16 uVar2; - u8 *puVar3; - int iVar4; - u32 uVar5; - u32 uVar6; - u32 uVar7; - short sVar8; - u32 uVar9; - short sVar10; - u16 uVar11; - u32 uVar12; - u32 unaff_r9; - register u32 unaff_r10 asm("r10"); - u32 in_lr; - - - if (gUnk_03003170.curLevel == 0) uVar1 = sub_08057AE8(0x15); - else uVar1 = 2; - switch ((s32)uVar1) { - case 1: - { - u8 *panel = stack + 0x38; - - sub_08065158(panel, 0x500CB, 0, -1, 0); - sub_08000AF0(0x15, *(u32 *)(panel + 0xC) + 0x1C0, 1); - unaff_r9 = ({ register u32 value asm("r1") = 0x77; asm("" : "+r"(value)); value; }); - goto setCountdown; + stage82BB0.value = table82BB0Stage[index82BB0->value]; + sub_0800B650(0x10, 0x1F, 0x06000000, 0U, 0xEU); +#ifdef REGION_USA + sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x50006, 0, -1, 0); /* single language */ +#else + switch (gUnk_03003470) { + case 0: sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x50006, 0, -1, 0); break; + case 1: sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x50007, 0, -1, 0); break; + case 2: sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x50008, 0, -1, 0); break; + case 3: sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x50009, 0, -1, 0); break; + case 4: sub_08065158(((u8 *)manager82BB0) + 0x5B8, 0x5000A, 0, -1, 0); break; } - case 2: - { - u8 *panel = stack + 0x6C; - - sub_08065158(panel, 0x500CA, 0, -1, 0); - { - u32 palette = *(u32 *)(panel + 0xC); - - sub_08000AF0(0x15, palette + ({ u32 offset = 0x1C0; offset; }), 1); - } - unaff_r10 = ({ register u32 value asm("r1") = 0x77; asm("" : "+r"(value)); value; }); +#endif + sub_08065158(((u8 *)manager82BB0) + 0x5EC, 0x5007A, 0, -1, 0); + sub_08000AF0(0x1EU, (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x5F8)), 1U); + (*(u8 *)((u8 *)(((u8 *)manager82BB0)) + 0x608)) = 0xE; + if (arg0 == 7) { + sub_080009C0(0x1F00, 0, 1); + } else { + sub_080009C0(0x1D00, 0, 1); } -setCountdown: - *(u32 *)(stack + 0xC4) = ({ register u32 value asm("r2") = 0x77; value; }); - break; - case 0: - { - u8 *middle; - u8 *right; - sub_08065158(frameStorage83AE8, 0x500CC, 0, -1, 0); - middle = stack + 0x38; - - sub_08065158(middle, 0x500CB, 0, -1, 0); - right = stack + 0x6C; - - sub_08065158(right, 0x500CA, 0, -1, 0); - sub_08000AF0(0x14, *(u32 *)(stack + 0x10) + 0x1C0, 1); - sub_08000AF0(0x15, *(u32 *)(middle + 0xC) + 0x1C0, 1); - sub_08000AF0(0x1E, *(u32 *)(right + 0xC) + 0x1C0, 1); - *(u32 *)(stack + 0xC4) = ({ u32 value = 0x77; value; }); - unaff_r9 = ({ register u32 value asm("r1") = 0xAE; asm("" : "+r"(value)); value; }); - unaff_r10 = ({ register u32 value asm("r2") = 0x40; asm("" : "+r"(value)); value; }); + sp40.word = (sp40.word & 0xFFFF0000) | 0x1D03; + sub_08000AA8(1U, (u16 *) &sp40); + sp40.half[0] = 0x9A01; + sub_08000AA8(2U, (u16 *) &sp40); + sp40.half[0] = 0x1F03; + sub_08000AA8(3U, (u16 *) &sp40); + sub_08060DB0(0); + sp4C = (s32) (u8) sub_08001108_word82BB0(0x88U); + sp48 = sub_0800115C((u32) sub_0808528C); + sub_08000D8C(); + sub_08000C08(8, 2); + if (sub_0800CB9C() != 0) { + if ((sub_0800CF48() == 0) && (sub_0800D154() == 0)) { + sub_08058688(0xD7); + } + } else { + sub_08058688(0xD7); } - break; - } - (*(u8 *)((stack + 4) + 0x2A)) = 4; - (*(u8 *)((stack + 4) + 0x5E)) = 5; - (*(u32 *)((stack + 4) + 0xBC)) = sub_08007290(({ register u32 *table asm("r1") = gUnk_084ECC04; register u32 index asm("r2"); register u32 *entry asm("r0"); index = param_1; asm("" : "+r"(index)); entry = (u32 *)((index << 2) + (u32)table); *entry; }) | 0x140000); - *(u32 *)(*(int *)((u32)&gUnk_03006440) + 0x28) = *(u32 *)(*(int *)((u32)&gUnk_03006440) + 0x28) | 2; - if (({ register u32 raw asm("r1") = *(u32 *)(stack + 0xC4); register s32 scaled asm("r0"); scaled = raw << 16; scaled; }) > 0) { - u8 *middle = stack + 0x38; - u32 paletteOffset = 0x1C0; - s32 shiftedCount; - + setup82BB0 = (u8 *)manager82BB0; + (*(s32 *)((u8 *)(setup82BB0) + 0x4)) = 0; + (*(s32 *)((u8 *)(setup82BB0) + 0x8)) = 0; + (*(s32 *)((u8 *)(setup82BB0) + 0x18)) = 0; + (*(s32 *)((u8 *)(setup82BB0) + 0x1C)) = 0x16; + (*(s32 *)((u8 *)(setup82BB0) + 0x20)) = 0; + (*(s32 *)((u8 *)(setup82BB0) + 0x24)) = 1; + (*(s32 *)((u8 *)(setup82BB0) + 0x28)) = 0; + init_words = (s32 *)(setup82BB0 + 0xD8); + *init_words = 0; + asm("" : "+r"(init_words)); + init_words++; + *init_words = 0; + asm("" : "+r"(init_words)); + init_words++; + *init_words = 0x58; + asm("" : "+r"(init_words)); + init_words++; + *init_words = 0x20; + asm("" : "+r"(init_words)); + init_words++; + *init_words = 0x58; + asm("" : "+r"(init_words)); + init_words++; + *init_words = 0x20; + asm("" : "+r"(init_words)); + init_words++; + *init_words = 0; + asm("" : "+r"(init_words)); + init_words++; + *(u16 *)init_words = 0; + (*(s32 *)((u8 *)(setup82BB0) + 0x2C)) = 0; + (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x34)) = sub_0805D3D4(); + init_result82BB0 = sub_0805D404(); + postsetup82BB0 = (u8 *)manager82BB0; + (*(s32 *)((u8 *)(postsetup82BB0) + 0x3C)) = init_result82BB0; + (*(s32 *)((u8 *)(postsetup82BB0) + 0x38)) = 0; + (*(s32 *)((u8 *)(postsetup82BB0) + 0x40)) = 0; + (*(s32 *)((u8 *)(postsetup82BB0) + 0x44)) = 0; + bank_setup82BB0 = (u8 *)bank82BB0; + (*(s32 *)((u8 *)(postsetup82BB0) + 0x48)) = (s32) (*(u16 *)((u8 *)(bank_setup82BB0) + 0x6A)); + (*(s32 *)((u8 *)(postsetup82BB0) + 0x54)) = 0; + (*(s32 *)((u8 *)(postsetup82BB0) + 0x5C)) = 0; + sp50 = 0; + var_r9 = 0; + (*(u16 *)((u8 *)(postsetup82BB0) + 0x6A)) = 0x64U; + var_sl = (*(u16 *)((u8 *)(bank_setup82BB0) + 0x68)); + init_halves = (u16 *)(postsetup82BB0 + 0x4C); + *init_halves++ = 0; + *init_halves++ = 0; + *init_halves++ = 0; + *init_halves = 0; + (*(u16 *)((u8 *)(postsetup82BB0) + 0x68)) = 5U; + (*(u32 *)((u8 *)(postsetup82BB0) + 0x6C)) = 3; + var_r6 = 0; + sp54 = arg0 - 1; do { - s32 zero; - if (sub_0800CDF8() != 0) goto LAB_080841de; - zero = sub_080021A8(); - - if (zero != 0) goto LAB_080841de; - if (({ register u32 raw asm("r1") = *(u32 *)(stack + 0xC4); register s32 scaled asm("r0"); scaled = raw << 16; scaled >> 16; }) == 1) *(u32 *)(stack + 0xC4) = ({ register u32 value asm("r0") = 0; value; }); - { - register u32 raw asm("r1") = *(u32 *)(stack + 0xC4); - s32 scaled; - register s32 signedValue asm("r1"); - - scaled = raw << 16; - signedValue = scaled >> 16; - - signedValue = (u16)(signedValue - (scaled >> 17)); - - *(u32 *)(stack + 0xC4) = signedValue; - } - if (({ register u32 raw asm("r1") = unaff_r9; register s32 scaled asm("r0"); scaled = raw << 16; scaled >> 16; }) == 1) unaff_r9 = ({ register u32 value asm("r0") = 0; value; }); - { - u32 raw = unaff_r9; - s32 scaled; - register s32 signedValue asm("r1"); + row82BB0 = (u32 *)manager82BB0; + temp_r2 = var_r6 * 8; + rowzero82BB0 = (u32 *)((u8 *)row82BB0 + 0x74); - scaled = raw << 16; - signedValue = scaled >> 16; + *(u32 *)((u8 *)rowzero82BB0 + temp_r2) = 0; + row82BB0 = (u32 *)((u8 *)row82BB0 + 0x78); - signedValue = (u16)(signedValue - (scaled >> 17)); + row82BB0 = (u32 *)((u8 *)row82BB0 + temp_r2); + *row82BB0 = var_r6 % 5U; + var_r6 += 1; + } while (var_r6 <= 5U); + switch (gUnk_03003470) { + case 0: sub_08065158((u8 *)manager82BB0 + 0xA4, 0x50002, 0, 0x80000000, 0); break; + case 1: sub_08065158((u8 *)manager82BB0 + 0xA4, 0x5015B, 0, 0x80000000, 0); break; + case 2: sub_08065158((u8 *)manager82BB0 + 0xA4, 0x5015C, 0, 0x80000000, 0); break; + case 3: sub_08065158((u8 *)manager82BB0 + 0xA4, 0x5015D, 0, 0x80000000, 0); break; + case 4: sub_08065158((u8 *)manager82BB0 + 0xA4, 0x5015E, 0, 0x80000000, 0); break; + } + switch (sp54) { /* switch 5; irregular */ + case 0: /* switch 5 */ + if (sub_0800CE30() != 0) { + var_r0_5 = ((u8 *)bank82BB0) + 0xB50; + } else { + var_r0_5 = ((u8 *)bank82BB0) + 0x910; + } + goto block_60; + case 1: /* switch 5 */ + sub_0805CB04(2, ((u8 *)manager82BB0) + 0x104); + setup82BB0 = (u8 *)manager82BB0; - unaff_r9 = signedValue; - } - if (({ register u32 raw asm("r1") = unaff_r10; register s32 scaled asm("r0"); scaled = raw << 16; scaled >> 16; }) == 1) unaff_r10 = ({ register u32 value asm("r0") = 0; value; }); - { - register u32 raw asm("r1") = unaff_r10; - s32 scaled; - register s32 signedValue asm("r1"); - - scaled = raw << 16; - signedValue = scaled >> 16; - - signedValue = (u16)(signedValue - (scaled >> 17)); - - unaff_r10 = signedValue; - } - { - register u8 *panel asm("r0"); - register s32 x asm("r1"); - if (uVar1 == 1) goto phase1Middle; - if (uVar1 > 1) goto phase1Greater; - if (uVar1 == 0) goto phase1All; - shiftedCount = ({ register u32 value asm("r2") = *(u32 *)(stack + 0xC4); value; }) << 16; - goto phase1Yield; -phase1Greater: - if (uVar1 == 2) goto phase1Right; - goto phase1SingleEnd; -phase1Middle: - x = ({ register u32 raw asm("r0") = unaff_r9; register s32 x asm("r1"); x = raw << 16; x >>= 16; x + 0xB9; }); - *(u32 *)stack = zero; - - panel = middle; - goto phase1Single; -phase1Right: - x = ({ register u32 raw asm("r0") = unaff_r10; register s32 x asm("r1"); x = raw << 16; x >>= 16; x + 0xB9; }); - *(u32 *)stack = zero; - - panel = stack + 0x6C; -phase1Single: - sub_08065230(panel, x, 0x88, 0, *(u32 *)stack); - { - u32 palette = *(u32 *)(middle + 0xC); - register u32 paletteOffset asm("r2"); - - paletteOffset = 0x1C0; - asm("" : "+r"(paletteOffset)); - sub_08000AF0(0x15, palette + paletteOffset, 1); - } -phase1SingleEnd: - shiftedCount = ({ u32 value = *(u32 *)(stack + 0xC4); value; }) << 16; - goto phase1Yield; -phase1All: - { - u8 *right; - sub_08000AF0(0x14, *(u32 *)(stack + 0x10) + paletteOffset, 1); - sub_08000AF0(0x15, *(u32 *)(middle + 0xC) + paletteOffset, 1); - right = stack + 0x6C; - - sub_08000AF0(0x1E, *(u32 *)(right + 0xC) + paletteOffset, 1); - sub_08065230(right, ({ register u32 raw asm("r2") = unaff_r10; s32 x; asm("" : "+r"(raw)); x = raw << 16; x >>= 16; x + 0xF0; }), 0x88, 0, 0); - sub_08065230(middle, ({ register u32 raw asm("r0") = unaff_r9; s32 x; x = raw << 16; x >>= 16; x + 0x82; }), 0x88, 0, 0); - shiftedCount = ({ register u32 value asm("r1") = *(u32 *)(stack + 0xC4); value; }) << 16; - sub_08065230(frameStorage83AE8, (shiftedCount >> 16) + 0xB9, 0x88, 0, 0); - } - } -phase1Yield: - sub_080003F0(); - } while (shiftedCount > 0); - } - { - u32 revealIndex; - u32 lastIndex; - u32 blink; - revealIndex = ({ register u32 value asm("r2") = 0; asm("" : "+r"(value)); value; }); - *(u32 *)(stack + 0xCC) = *(u32 *)(stack + 0xC0) + 2; - while (revealIndex <= (u32)sub_0801A638(*(u8 **)(stack + 0xCC))) { - s32 zero; - if (sub_0800CDF8() != 0) goto LAB_080841de; - zero = sub_080021A8(); - - if (zero != 0) goto LAB_080841de; - switch (uVar1) { - case 1: - { - u8 *middle = stack + 0x38; - - sub_08065230(middle, 0xB9, 0x88, 0, zero); - { u32 palette = *(u32 *)(middle + 0xC); register u32 offset asm("r2"); offset = 0x1C0; asm("" : "+r"(offset)); palette += offset; sub_08000AF0(0x15, palette, 1); } + goto block_61; + case 2: /* switch 5 */ + sub_0805CB04(3, ((u8 *)manager82BB0) + 0x104); + setup82BB0 = (u8 *)manager82BB0; + asm("" : "+r"(setup82BB0) : "i"(3)); + goto block_61; + case 3: /* switch 5 */ + sub_0805CB04(4, ((u8 *)manager82BB0) + 0x104); + setup82BB0 = (u8 *)manager82BB0; + asm("" : "+r"(setup82BB0) : "i"(4)); + goto block_61; + case 4: /* switch 5 */ + if (sub_0800CE30() != 0) { + var_r0_5 = ((u8 *)bank82BB0) + 0x9D0; + } else { + var_r0_5 = ((u8 *)bank82BB0) + 0x790; } - break; - case 2: - sub_08065230(stack + 0x6C, 0xB9, 0x88, 0, zero); - { u32 palette = *(u32 *)(stack + 0x44); u32 offset; offset = 0x1C0; palette += offset; sub_08000AF0(0x15, palette, 1); } - break; - case 0: - { - u8 *middle; - u8 *right; - register u32 paletteOffset asm("r4"); - u32 palette = *(u32 *)(stack + 0x10); - - paletteOffset = 0x1C0; - - sub_08000AF0(0x14, palette + paletteOffset, 1); - middle = stack + 0x38; - - sub_08000AF0(0x15, *(u32 *)(middle + 0xC) + paletteOffset, 1); - right = stack + 0x6C; - - sub_08000AF0(0x1E, *(u32 *)(right + 0xC) + paletteOffset, 1); - sub_08065230(right, 0xF0, 0x88, 0, 0); - sub_08065230(middle, 0x82, 0x88, 0, 0); - sub_08065230(frameStorage83AE8, 0xB9, 0x88, 0, 0); + goto block_60; + case 5: /* switch 5 */ + if (sub_0800CE30() != 0) { + var_r0_5 = ((u8 *)bank82BB0) + 0xA90; + } else { + var_r0_5 = ((u8 *)bank82BB0) + 0x850; } +block_60: + sub_080852CC(var_r0_5); + setup82BB0 = (u8 *)manager82BB0; +block_61: + *(s32 *)(setup82BB0 + 0x18) = 0xB; + common_words82BB0 = (s32 *)(setup82BB0 + 0xE0); + temp_r2 = 0xB8; + *common_words82BB0 = temp_r2; + asm("" : "+r"(common_words82BB0)); + common_words82BB0++; + temp_r1 = 0x20; + *common_words82BB0 = temp_r1; + asm("" : "+r"(common_words82BB0)); + common_words82BB0++; + *common_words82BB0 = temp_r2; + asm("" : "+r"(common_words82BB0)); + common_words82BB0++; + asm("" : "+r"(common_words82BB0)); + *common_words82BB0 = temp_r1; break; - } - { - u8 *buffer = stack + 0xA0; - register u32 old asm("r2"); - u8 *destination; - u32 offset; - register u8 *source asm("r2"); - register u8 *address asm("r0"); - u32 next; - - old = revealIndex; - asm("" : "+r"(old)); - destination = buffer + old; - - offset = revealIndex + 2; - - source = *(u8 **)(stack + 0xC0); - - address = source + offset; + case 6: /* switch 5 */ + mode_slot82BB0 = &bank82BB0; + mode_index82BB0 = *(s32 *)((u8 *)manager82BB0 + 0x44); + mode_offset82BB0 = mode_index82BB0 * 0xF0; - *destination = *address; - next = revealIndex + 1; - buffer[next] = 0xFD; + mode_offset82BB0 += 0x2E0; - revealIndex = (u16)next; - sub_0801A3D0(buffer, (u16)(0xF - ((u32)sub_0801A638(*(u8 **)(stack + 0xCC)) >> 1)), 0x12); - sub_080003F0(); - } - } - { - u32 previous = revealIndex - 1; - - lastIndex = (u16)previous; + { s32 slot82BB0 = (s32)*mode_slot82BB0; register s32 sum82BB0 asm("r0") = slot82BB0; sum82BB0 = slot82BB0 + mode_offset82BB0; sub_080852CC(sum82BB0); } + break; + case 8: /* switch 5 */ + var_r6 = 0; + do { + ((struct ManagerRecords82BB0 *)manager82BB0)->records[var_r6].w0 = 0; + var_r6 += 1; + } while (var_r6 <= 2U); + ((struct ManagerRecords82BB0 *)manager82BB0)->records[var_r6].w0 = 0; + break; } - blink = ({ register u32 value asm("r0") = 0; asm("" : "+r"(value)); value; }); - if ((keys83AE8 & 1) == 0) { - u8 *buffer; - u8 *middle; - { - register u8 *base asm("r1") = stack + 0xA0; - - buffer = base; - } - middle = stack + 0x38; - - do { - if (sub_0800CDF8() != 0) goto LAB_080841de; - if (({ s32 status = sub_080021A8(); status; }) != 0) goto LAB_080841de; - { - register u32 previous asm("r1") = blink; - u32 next = previous + 1; - - blink = (u16)next; - if (previous <= 0x1D) *(u32 *)(stack + 0xC8) = ({ register u32 value asm("r2") = 1; value; }); - else if (({ u32 value = blink; value; }) > 0x1D) *(u32 *)(stack + 0xC8) = ({ register u32 value asm("r1") = 0; value; }); + sub_0808536C(); + sub_080853DC(arg0); + sub_080003F0(); + sub_0801AB50(6); + while (((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x24)) != 0) && (sub_080021A8() == 0)) { + first_flags82BB0 = *(s32 *)((u8 *)manager82BB0 + 0x28); + temp_r4 = 2; + if (!(first_flags82BB0 & temp_r4)) { + sub_0807C29C(); } - if (({ register u32 value asm("r2") = blink; asm("" : "+r"(value)); value; }) > 0x28) blink = ({ register u32 value asm("r0") = 0; asm("" : "+r"(value)); value; }); - if (({ register u32 value asm("r1") = *(u32 *)(stack + 0xC8); value; })) { - buffer[lastIndex] = 0xA0; - { - u32 next = lastIndex + 1; - register u8 *end asm("r0"); - u32 terminator; - - end = buffer + next; - - terminator = 0xFD; - - *end = terminator; - } - } else buffer[lastIndex] = 0xFD; - { - register u8 *drawBuffer asm("r6") = frameStorage83AE8 + 0x9C; - - switch (uVar1) { - case 1: - sub_08065230(middle, 0xB9, 0x88, 0, 0); - { u32 palette = *(u32 *)(middle + 0xC); register u32 offset asm("r2"); offset = 0x1C0; asm("" : "+r"(offset)); palette += offset; sub_08000AF0(0x15, palette, 1); } - break; - case 2: - sub_08065230(frameStorage83AE8 + 0x68, 0xB9, 0x88, 0, 0); - { u32 palette = *(u32 *)(middle + 0xC); u32 offset; offset = 0x1C0; palette += offset; sub_08000AF0(0x15, palette, 1); } - break; - case 0: - { - u8 *right; - { u32 palette = *(u32 *)(stack + 0x10); register u32 offset asm("r2"); offset = 0x1C0; asm("" : "+r"(offset)); palette += offset; sub_08000AF0(0x14, palette, 1); } - { u32 palette = *(u32 *)(middle + 0xC); u32 offset; offset = 0x1C0; asm("" : "+r"(offset)); palette += offset; sub_08000AF0(0x15, palette, 1); } - right = stack + 0x6C; - - { u32 palette = *(u32 *)(right + 0xC); register u32 offset asm("r2"); offset = 0x1C0; asm("" : "+r"(offset)); palette += offset; sub_08000AF0(0x1E, palette, 1); } - sub_08065230(right, 0xF0, 0x88, 0, 0); - sub_08065230(middle, 0x82, 0x88, 0, 0); - sub_08065230(frameStorage83AE8, 0xB9, 0x88, 0, 0); + temp_r1 = (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x28)); + if (!(temp_r1 & 1)) { + temp_r4 &= temp_r1; + if (temp_r4 != 0) { + + } else { + keys82BB0.xA = temp_r4; + if ((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x1C)) == 0x16) { + temp_r1_2 = (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x18)); + if ((u32) (temp_r1_2 - 0x11) <= 2U) { + + } else { + if (((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x0)) != 5) || (temp_r1_2 == 7)) { + sub_08065230(((u8 *)manager82BB0) + 0x5B8, (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE0)), (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE4)), 0xBU, (s32) temp_r4); + } else { + temp_r0_12 = (*(u8 * *)((u8 *)(((u8 *)manager82BB0)) + 0xF0)); + temp_r1_3 = (*(u16 *)((u8 *)(temp_r0_12) + 0x0)); + if (((s32) temp_r1_3 <= 5) && ((s32) temp_r1_3 >= temp_r4 + 2)) { + temp_r3 = (*(u8 *)((u8 *)(temp_r0_12) + 0x8)); + if (temp_r3 != 0) { + sub_08065264(((u8 *)manager82BB0) + 0x5B8, (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE0)), (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE4)), 9, (s32) temp_r4); + } else { + sub_08065230(((u8 *)manager82BB0) + 0x5B8, (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE0)), (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE4)), 9U, (s32) temp_r3); + } + } else { + sub_08065230(((u8 *)manager82BB0) + 0x5B8, (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE0)), (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE4)), 9U, 0); + } + } + temp_r0_13 = (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x18)); + if (temp_r0_13 != 7) { + if ((u32) (temp_r0_13 - 0xE) > 1U) { + sub_0805FFBC(0xF, 0x12, (*(u8 * *)((u8 *)(((u8 *)manager82BB0)) + 0xF0)), 0x80000000); + } + } else { + resource_word82BB0 = sub_08007290(table82BB0Text[*(s32 *)((u8 *)manager82BB0 + 4)] | 0x140000); + temp_r4_2 = (u8 *)(resource_word82BB0 + 2); + + sub_0801A3D0(temp_r4_2, (u16) (0xF - ((u32) sub_0801A638(temp_r4_2) >> 1)), 0x12); + } + } + } else { + sub_08065230(((u8 *)manager82BB0) + 0x5B8, (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE0)), (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE4)) - 4, 0xBU, 1); + sub_0805FC80((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE0)), (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0xE4)) - 4, ((u8 *)manager82BB0) + 0xF4, 8); + if ((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x18)) != 0x11) { + sub_0805FFBC(0xF, 0x12, ((u8 *)manager82BB0) + 0xF4, 0x80000000); + } + } + } + if ((((*(u16 *)((u8 *)(((u8 *)manager82BB0)) + 0x6A)) != (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x4))) || (var_sl != (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + 0x68)))) && ((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x18)) != 0xE)) { + if ((u32) ((*(u16 *)((u8 *)manager82BB0 + 0x68))++) > 5U) { + sub_080811E0(sp44); + refresh82BB0 = (struct Refresh82BB0 *)manager82BB0; + refresh82BB0->w68 = 0U; + refresh82BB0->w6A = (u16) refresh82BB0->w4; + var_sl = (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + 0x68)); + } + } + sub_08080A78(); + if ((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x2C)) != 0) { + sub_0801A664(2, 0x12); + (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x2C)) = 0; + } + } else { + confirm82BB0 = (u8 *)manager82BB0; + (*(u16 *)((u8 *)(confirm82BB0) + 0x6A)) = 0x64U; + (*(s32 *)((u8 *)(confirm82BB0) + 0x2C)) = 1; + sub_0801A664(2, 0x12); + keys82BB0.xA = 0x100; + if ((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x18)) == 9) { + sub_08082960((*(u8 * *)((u8 *)(((u8 *)manager82BB0)) + 0x5B4))); + } else if ((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x1C)) == 0x16) { + sub_080815F4((*(u8 * *)((u8 *)(((u8 *)manager82BB0)) + 0xF0))); + } else { + sub_080815F4(((u8 *)manager82BB0) + 0xF4); } - break; - } - sub_0801A3D0(drawBuffer, (u16)(0xF - ((u32)sub_0801A638(*(u8 **)(stack + 0xCC)) >> 1)), 0x12); - sub_080003F0(); - } - } while ((keys83AE8 & 1) == 0); - } - } - { - register u32 zero asm("r0") = 0; - - *(u32 *)(stack + 0xC4) = zero; - unaff_r9 = zero; - unaff_r10 = zero; - } - sub_0805865C(0xF); - switch (uVar1) { - case 1: - { - u8 *panel = stack + 0x38; - s32 amount; - - do { - s32 zero; - if (sub_0800CDF8() != 0) goto LAB_080841de; - zero = sub_080021A8(); - - if (zero != 0) goto LAB_080841de; - { - u32 raw = unaff_r9; - register s32 value asm("r0"); - s32 delta; - - value = raw << 16; - value >>= 16; - - delta = value - 0x77; - delta >>= 1; - - value = (u16)(value - delta); - - unaff_r9 = value; } - - { - u32 palette = *(u32 *)(panel + 0xC); - register u32 paletteOffset asm("r2"); - - paletteOffset = 0x1C0; - asm("" : "+r"(paletteOffset)); - sub_08000AF0(0x15, palette + paletteOffset, 1); + if (((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x0)) == 4) && ((sp50 != (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x44))) || (var_r9 != (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x48))))) { + temp_r0_14 = (*(u16 *)((u8 *)(((u8 *)bank82BB0)) + 0x6A)) - 1; + switch (temp_r0_14) { /* switch 6 */ + case 0: /* switch 6 */ + var_r6 = 0x4000001B; + break; + case 1: /* switch 6 */ + var_r6 = 0x4000001C; + break; + case 2: /* switch 6 */ + var_r6 = 0x4000001E; + break; + case 3: /* switch 6 */ + var_r6 = 0x40000021; + break; + case 4: /* switch 6 */ + var_r6 = 0x40000025; + break; + } + var_r6 += (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x44)); + sub_0800B974(var_r6, 0x1DU); + sp50 = (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x44)); + var_r9 = (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x48)); } - { - register u32 raw asm("r0") = unaff_r9; - - amount = raw << 16; - - amount >>= 16; + temp_r1_5 = (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x28)); + temp_r5 = 1 & temp_r1_5; + if ((temp_r5 == 0) && ((*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x18)) != 0x13)) { + if (temp_r1_5 & 4) { + var_r8 = var_r8 >> 1; + fade_sprite82BB0 = (u8 *)manager82BB0 + 0x5EC; + fade_x82BB0 = var_r8 + 0xD0; + fade_y82BB0 = gUnk_080B9704[*(s32 *)((u8 *)manager82BB0 + 0x5C)]; + + fade_y82BB0 = (fade_y82BB0 >> 5) + *(s32 *)((u8 *)manager82BB0 + 0x54) + 0x60; + sub_08065230(fade_sprite82BB0, fade_x82BB0, fade_y82BB0, 2U, temp_r5); + temp_r0_15 = (*(s32 *)((u8 *)(((u8 *)manager82BB0)) + 0x18)); + if (((temp_r0_15 == 0) || (temp_r0_15 == 0x11)) && (temp_r0_15 != 0x12)) { + resource_word82BB0 = sub_08007290(0x140185); + temp_r4_3 = (u8 *)(resource_word82BB0 + 2); + + sub_0801A3D0(temp_r4_3, (u16) (0xF - ((u32) sub_0801A638(temp_r4_3) >> 1)), 0x12); + } + } else { + var_r8 = 0x40; + } } - sub_08065230(panel, amount + 0xB9, 0x88, 0, zero); sub_080003F0(); - } while (amount != 0x77); } - break; - case 2: - { - u8 *panel = stack + 0x6C; - s32 amount; - - do { - s32 zero; - if (sub_0800CDF8() != 0) goto LAB_080841de; - zero = sub_080021A8(); - - if (zero != 0) goto LAB_080841de; - { - register u32 raw asm("r1") = unaff_r10; - register s32 value asm("r0"); - s32 delta; - - value = raw << 16; - value >>= 16; - - delta = value - 0x77; - delta >>= 1; - - value = (u16)(value - delta); - - unaff_r10 = value; - } + sub_0806617C(); + sub_080586B4(0); + sub_0801ABE8(6); + while (sub_0801AAE0() == 0) { + sub_080003F0(); + } - { - u32 palette = *(u32 *)(panel + 0xC); - register u32 paletteOffset asm("r2"); - - paletteOffset = 0x1C0; - asm("" : "+r"(paletteOffset)); - sub_08000AF0(0x15, palette + paletteOffset, 1); + sub_08000E48(); + sub_0800115C(sp48); + sub_08001108_word82BB0(sp4C); + sub_080653D4(0); + sub_08000C08(0x10, 8); + sub_0801A664(2, 0x12); + switch (sp54) { /* switch 7; irregular */ + case 0: /* switch 7 */ + if (sub_0800CE30() != 0) { + var_r0_6 = ((u8 *)bank82BB0) + 0xB50; + } else { + var_r0_6 = ((u8 *)bank82BB0) + 0x910; } - { - register u32 raw asm("r0") = unaff_r10; - - amount = raw << 16; - - amount >>= 16; + var_r6 = 9; + do { + temp_r0_16 = ((u8 *)manager82BB0) + (var_r6 * 0x10); + temp_r0_17 = temp_r0_16 + 0x104; + ((struct Record82BB0 *)var_r0_6)[var_r6] = *(struct Record82BB0 *)temp_r0_17; + var_r6 += 1; + } while (var_r6 <= 0xBU); + break; + case 4: /* switch 7 */ + if (sub_0800CE30() != 0) { + var_r0_7 = ((u8 *)bank82BB0) + 0x9D0; + } else { + var_r0_7 = ((u8 *)bank82BB0) + 0x790; } - sub_08065230(panel, amount + 0xB9, 0x88, 0, zero); - sub_080003F0(); - } while (amount != 0x77); - } - break; - case 0: - for (;;) { - register s32 zero asm("r8"); - s32 shiftedCount; - s32 firstCount; - s32 secondCount; - s32 thirdCount; - u8 *middle; - u8 *right; - if (sub_0800CDF8() != 0) goto LAB_080841de; - { - s32 status = sub_080021A8(); - zero = status; - - if (status != 0) goto LAB_080841de; - } - { - register u32 raw asm("r1") = *(u32 *)(stack + 0xC4); - s32 delta; - - shiftedCount = raw << 16; - shiftedCount >>= 16; - - delta = shiftedCount - 0x77; - delta >>= 1; - - shiftedCount -= delta; - - shiftedCount <<= 16; - - } - { - u32 raw = unaff_r9; - register s32 value asm("r0"); - s32 delta; - - value = raw << 16; - value >>= 16; - - delta = value - 0xAE; - delta >>= 1; - - value = (u16)(value - delta); - - unaff_r9 = value; + var_r6 = 9; + do { + temp_r0_18 = ((u8 *)manager82BB0) + (var_r6 * 0x10); + temp_r0_19 = temp_r0_18 + 0x104; + ((struct Record82BB0 *)var_r0_7)[var_r6] = *(struct Record82BB0 *)temp_r0_19; + var_r6 += 1; + } while (var_r6 <= 0xBU); + break; + case 5: /* switch 7 */ + if (sub_0800CE30() != 0) { + var_r0_8 = ((u8 *)bank82BB0) + 0xA90; + } else { + var_r0_8 = ((u8 *)bank82BB0) + 0x850; } - { - register u32 raw asm("r1") = unaff_r10; - register s32 value asm("r0"); - s32 delta; - asm("" : "+r"(raw)); - value = raw << 16; - value >>= 16; - - delta = value - 0x40; - delta >>= 1; - - value = (u16)(value - delta); - - unaff_r10 = value; + var_r6 = 9; + do { + temp_r0_20 = ((u8 *)manager82BB0) + (var_r6 * 0x10); + temp_r0_21 = temp_r0_20 + 0x104; + ((struct Record82BB0 *)var_r0_8)[var_r6] = *(struct Record82BB0 *)temp_r0_21; + var_r6 += 1; + } while (var_r6 <= 0xBU); + break; + case 6: + for (var_r6 = 0; var_r6 < (u32)(*(u16 *)((u8 *)bank82BB0 + 0x6A) * 0xF); var_r6++) { + temp_r1_6 = (u8 *)bank82BB0; + var_r8 = 0x2E0; + temp_r2_2 = var_r6 * 0x10; + temp_r1_7 = temp_r1_6 + temp_r2_2; + asm("" : "+r"(temp_r1_7) : "r"(var_r8)); + temp_r0_24 = (u8 *)manager82BB0 + temp_r2_2; + asm("" : "+r"(temp_r0_24) : "r"(temp_r1_7)); + *(struct Record82BB0 *)(temp_r1_7 + var_r8) = *(struct Record82BB0 *)(temp_r0_24 + 0x104); } - *(u32 *)(stack + 0xC4) = (u32)shiftedCount >> 16; - shiftedCount >>= 16; - { - register s32 delta asm("r0") = shiftedCount - 0x77; - if (delta < 0) delta = -delta; - if (delta == 1) *(u32 *)(stack + 0xC4) = ({ register u32 value asm("r1") = 0x77; value; }); - } - { - register u32 raw asm("r2") = unaff_r9; - register s32 delta asm("r0"); - asm("" : "+r"(raw)); - delta = raw << 16; - delta >>= 16; - - delta -= 0xAE; - if (delta < 0) delta = -delta; - if (delta == 1) unaff_r9 = ({ u32 value = 0xAE; value; }); - } - { - register u32 raw asm("r1") = unaff_r10; - register s32 delta asm("r0"); - - delta = raw << 16; - delta >>= 16; - - delta -= 0x40; - if (delta < 0) delta = -delta; - if (delta == 1) unaff_r10 = ({ register u32 value asm("r2") = 0x40; asm("" : "+r"(value)); value; }); - } - { - register u32 paletteOffset asm("r4"); - u32 palette = *(u32 *)(stack + 0x10); - - paletteOffset = 0x1C0; - - sub_08000AF0(0x14, palette + paletteOffset, 1); - middle = stack + 0x38; - - sub_08000AF0(0x15, *(u32 *)(middle + 0xC) + paletteOffset, 1); - right = stack + 0x6C; - - sub_08000AF0(0x1E, *(u32 *)(right + 0xC) + paletteOffset, 1); - } - { - register u32 raw asm("r1") = unaff_r10; - register s32 scaled asm("r0"); - - scaled = raw << 16; - - thirdCount = scaled >> 16; - } - { - s32 x = thirdCount + 0xF0; - register u32 stackZero asm("r2"); - - stackZero = zero; - asm("" : "+r"(stackZero)); - sub_08065230(right, x, 0x88, 0, stackZero); - } - { - register u32 raw asm("r1") = unaff_r9; - register s32 scaled asm("r0"); - - scaled = raw << 16; - - secondCount = scaled >> 16; - } - { - s32 x = secondCount + 0x82; - register u32 stackZero asm("r2"); - - stackZero = zero; - asm("" : "+r"(stackZero)); - sub_08065230(middle, x, 0x88, 0, stackZero); - } - { - register u32 raw asm("r0") = *(u32 *)(stack + 0xC4); - - firstCount = raw << 16; - firstCount >>= 16; - - } - { - s32 x = firstCount + 0xB9; - register u32 stackZero asm("r2"); - - stackZero = zero; - asm("" : "+r"(stackZero)); - sub_08065230(frameStorage83AE8, x, 0x88, 0, stackZero); - } - sub_080003F0(); - if (firstCount == 0x77 && secondCount == 0xAE && thirdCount == 0x40) break; + break; + case 8: /* switch 7 */ + var_r6 = 0; + do { + if ((((struct ManagerRecords82BB0 *)manager82BB0)->records[var_r6].w0 != 0) && (sub_0805AB20(&((struct ManagerRecords82BB0 *)manager82BB0)->records[var_r6]) == 0)) { + temp_r4_4 = players82BB0[sub_080020F4()].w8C; + sub_08066490(temp_r4_4, players82BB0[sub_080020F4()].w90, &((struct ManagerRecords82BB0 *)manager82BB0)->records[var_r6]); + } + var_r6 += 1; + } while (var_r6 <= 2U); + if ((*(u16 *)((u8 *)(((u8 *)manager82BB0)) + 0x134)) != 0) { + sub_0805AB20(((u8 *)manager82BB0) + 0x134); + } + break; } - break; - } - sub_080003F0(); - sub_080003F0(); -LAB_080841de: - *(u32 *)(*(int *)((u32)&gUnk_03006440) + 0x28) = *(u32 *)(*(int *)((u32)&gUnk_03006440) + 0x28) & 0xfffffffd; - return; + sub_08085398(); + sub_08000420(0x11201100); +#endif } -/* [ClassifyThreeItemSubtypePattern] r0 points to three16-byte item records. Requires unsigned kind halfwords - * at+0/+16/+32 all9 or returns0. Reads subtype halfwords+2/+18/+34 and returns a pure ordered-pattern - * code:000=>1,222=>2,111=>3, - * all-distinct0..2=>4;020/101/010/121/212/202=>5..10;002/110/001/112/221/220/200/011/100/211/122/022=>11..22;333=>23,444=>24. - * Everything else returns0, including mixed3/4. No side effects, RNG or validation of pointed storage. Does - * not guess material names for kind9 or subtype values. Complete original configured body audited against ROM; - * copied verified-main ELF static equality, no local build or runtime test. */ -u32 sub_08084200(const u8 *arg0) +/* [RunItemMenuMessageDialogue] Full-word r0 indexes sprite/message tables0x084ECBDC/0x084ECC04 without bounds + * check. Initializes local descriptor, picks palette source variant for indices3/4/9, sets manager word+0x28 + * bit1. Expands message byte0xFC from save-state name stream at0x030034E0 into local32-byte buffer with u16 + * indices; no capacity checks. Slides descriptor to(240,136), reveals text progressively centered on row18, + * then waits for input halfword0x03001324 bit0 while blinking0xA0 marker. On acknowledgement plays song15 and + * slides away, yielding throughout. Suspend-request or link-error exits skip animation; all exits clear + * manager bit1. Does not claim debounce, exact input-newness or explicit text erase. */ +void sub_0808381C(u32 index) { - u16 b; - u16 c; - - if (*(const u16 *)(arg0 + 0x00) != 9 || - *(const u16 *)(arg0 + 0x10) != 9 || - *(const u16 *)(arg0 + 0x20) != 9) - return 0; - +#ifdef REGION_USA + struct Desc8381C { u32 w0, w4, w8; u8 *pal; u8 p10[0xC]; u8 f1C; u8 p1D[0x17]; }; + struct Desc8381C desc; + TextChar text[32]; + TextChar liveText[32]; + u32 visible; + TextChar *source; + u16 countdown; + u16 textLength; + u16 dictionaryOffset; + u16 i; + u16 last; + u32 zero; + extern u16 keys8381C asm("gUnk_03001324"); - if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 0 && *(const u16 *)(arg0 + 0x22) == 0) return 1; - if (*(const u16 *)(arg0 + 0x02) == 2 && *(const u16 *)(arg0 + 0x12) == 2 && *(const u16 *)(arg0 + 0x22) == 2) return 2; - if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 1) return 3; - if ((u32)*(const u16 *)(arg0 + 0x02) <= 2 && (u32)(b = *(const u16 *)(arg0 + 0x12)) <= 2 && (u32)(c = *(const u16 *)(arg0 + 0x22)) <= 2 && *(const u16 *)(arg0 + 0x02) != b && *(const u16 *)(arg0 + 0x02) != c && b != c) return 4; - if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 2 && *(const u16 *)(arg0 + 0x22) == 0) return 5; - if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 0 && *(const u16 *)(arg0 + 0x22) == 1) return 6; - if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 0) return 7; - if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 2 && *(const u16 *)(arg0 + 0x22) == 1) return 8; - { - /* Keep the original halfword extensions across the shared tests. */ - u32 d; - register u32 raw asm("r0"); - if (*(const u16 *)(arg0 + 0x02) == 2 && - ({ - raw = *(const u16 *)(arg0 + 0x12); - asm("" : "+r"(raw)); - d = raw; - - d; - }) == 1 && *(const u16 *)(arg0 + 0x22) == 2) return 9; - if (*(const u16 *)(arg0 + 0x02) == 2 && - ({ - raw = d << 16; - - raw; - }) == 0 && *(const u16 *)(arg0 + 0x22) == 2) return 10; - } - if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 0 && *(const u16 *)(arg0 + 0x22) == 2) return 11; - if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 0) return 12; - if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 0 && *(const u16 *)(arg0 + 0x22) == 1) return 13; - if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 2) return 14; - { - /* Keep the original halfword extensions across the shared tests. */ - u32 d; - register u32 raw asm("r0"); - if (*(const u16 *)(arg0 + 0x02) == 2 && - ({ - raw = *(const u16 *)(arg0 + 0x12); - asm("" : "+r"(raw)); - d = raw; - - d; - }) == 2 && *(const u16 *)(arg0 + 0x22) == 1) return 15; - if (*(const u16 *)(arg0 + 0x02) == 2 && - ({ - raw = (u16)d; - asm("" : "+r"(raw), "+r"(d)); - raw; - }) == 2 && *(const u16 *)(arg0 + 0x22) == 0) return 16; - if (*(const u16 *)(arg0 + 0x02) == 2 && - ({ - raw = d << 16; - - raw; - }) == 0 && *(const u16 *)(arg0 + 0x22) == 0) return 17; - } - if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 1) return 18; - if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 0 && *(const u16 *)(arg0 + 0x22) == 0) return 19; - if (*(const u16 *)(arg0 + 0x02) == 2 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 1) return 20; - if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 2 && *(const u16 *)(arg0 + 0x22) == 2) return 21; - if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 2 && *(const u16 *)(arg0 + 0x22) == 2) return 22; - if (*(const u16 *)(arg0 + 0x02) == 3 && *(const u16 *)(arg0 + 0x12) == 3 && *(const u16 *)(arg0 + 0x22) == 3) return 23; - if (*(const u16 *)(arg0 + 0x02) == 4 && *(const u16 *)(arg0 + 0x12) == 4 && *(const u16 *)(arg0 + 0x22) == 4) return 24; - return 0; -} -/* [SynthesizeRandomItemFromThreeInputs] r0 points to at least three16-byte item records PLUS metadata word - * at+0x34; r1 points to16-byte output. Randomly permutes three inputs via rejection sampling. Classifies - * original ordered triple through0x08084200; nonzero class and RNG low16<=saved-state word+0x6C can select - * class/tier recipe tables, tier from summed unsigned values with boundaries100/300/500. Fallback uses first - * randomized equipment record or random nonempty saved stock entries for kind9; empty stock can loop - * indefinitely. Further randomized property/value inheritance uses other two records and compatibility flags, - * with an inherited r9 path for unsupported kinds. */ -void sub_0808441C(u16 *param_1, u32 *param_2) -{ - /* Combine three randomized records and update the shared success value. */ - extern const u32 table8441C_084EC1E0[] asm("gUnk_084EC1E0"); - extern const u32 table8441C_084EC288[] asm("gUnk_084EC288"); - extern const u32 table8441C_084EC330[] asm("gUnk_084EC330"); - extern const u32 table8441C_084EC3D8[] asm("gUnk_084EC3D8"); - extern const u32 table8441C_084EC480[] asm("gUnk_084EC480"); - extern const u32 table8441C_084EC4E0[] asm("gUnk_084EC4E0"); - extern const u32 table8441C_084EC540[] asm("gUnk_084EC540"); - extern const u32 table8441C_084EC5A0[] asm("gUnk_084EC5A0"); - extern const u32 table8441C_084EC600[] asm("gUnk_084EC600"); - extern const u32 table8441C_084EC660[] asm("gUnk_084EC660"); - extern const u32 table8441C_084EC6C0[] asm("gUnk_084EC6C0"); - extern const u32 table8441C_084EC6E4[] asm("gUnk_084EC6E4"); - extern const u32 table8441C_084EC708[] asm("gUnk_084EC708"); - extern const u32 table8441C_084EC72C[] asm("gUnk_084EC72C"); - extern const u32 table8441C_084EC750[] asm("gUnk_084EC750"); - extern const u32 table8441C_084EC774[] asm("gUnk_084EC774"); - extern const u32 table8441C_084EC798[] asm("gUnk_084EC798"); - extern const u32 table8441C_084EC7BC[] asm("gUnk_084EC7BC"); - extern const u32 table8441C_084EC7E0[] asm("gUnk_084EC7E0"); - extern const u32 table8441C_084EC804[] asm("gUnk_084EC804"); - extern const u32 table8441C_084EC828[] asm("gUnk_084EC828"); - extern const u32 table8441C_084EC84C[] asm("gUnk_084EC84C"); - extern const u32 table8441C_084EC870[] asm("gUnk_084EC870"); - extern const u32 table8441C_084EC8B0[] asm("gUnk_084EC8B0"); - extern const u32 table8441C_084EC8F0[] asm("gUnk_084EC8F0"); - extern const u32 table8441C_084EC920[] asm("gUnk_084EC920"); - extern const u32 table8441C_084EC950[] asm("gUnk_084EC950"); - extern const u32 table8441C_084EC9A0[] asm("gUnk_084EC9A0"); - extern const u32 table8441C_084EC9F0[] asm("gUnk_084EC9F0"); - extern const u32 table8441C_084ECA40[] asm("gUnk_084ECA40"); - extern const u32 table8441C_084ECA90[] asm("gUnk_084ECA90"); - extern const u32 table8441C_084ECAE0[] asm("gUnk_084ECAE0"); - extern const u32 table8441C_084ECB30[] asm("gUnk_084ECB30"); - extern const u32 table8441C_084ECB84[] asm("gUnk_084ECB84"); - extern u32 sub_0805AE94(const void *); - extern void *copy8441C(void *, const void *, u32) asm("memcpy"); - extern u32 sub_08084200(const u8 *); - struct Triple8441C { u32 a, b, c; }; - struct Record8441C { u16 type, subtype, value; u8 byte6, byte7; u32 word8, wordC; }; - /* Preserve the original frame, including partially initialized records. */ - u8 frameStorage8441C[128]; - register u8 *stack asm("sp"); - register struct Record8441C *result; - struct Record8441C *second; - register struct Record8441C *third asm("r8"); - u32 firstIndex; - u32 secondIndex; - register u32 thirdIndex asm("r6"); - register u32 tier asm("r6"); - u32 randomIndex; - const u16 *entry; - const u32 *tripleTable; - s32 classification; - u32 unaff_r9; - - *(u16 **)(stack + 0x5C) = param_1; - *(u32 **)(stack + 0x60) = param_2; - { - register u32 zeroHalf asm("r4") = 0; - struct Record8441C *initial = (struct Record8441C *)(stack + 0x30); - u32 zeroByte = 0; - - initial->type = zeroHalf; - initial->subtype = zeroHalf; - initial->byte6 = zeroByte; - initial->byte7 = zeroByte; - initial->value = zeroHalf; - firstIndex = 0; - result = initial; + sub_08065158(&desc, gUnk_084ECBDC[index], 0, -1, 0); + if (index == 9 || index == 3 || index == 4) { + sub_08000AF0(0x1E, desc.pal, 1); + desc.f1C = 0x0E; + } else { + sub_08000AF0(0x1E, desc.pal + 0x1C0, 1); } - second = ({ struct Record8441C *p = (struct Record8441C *)(stack + 0x10); p; }); - third = ({ register struct Record8441C *p asm("r1") = (struct Record8441C *)(stack + 0x20); p; }); - { - register u8 *temporary asm("r2") = stack; - asm("" : "+r"(temporary)); - temporary += 0x40; - *(u8 **)(stack + 0x78) = temporary; + source = (TextChar *)sub_08007290(gUnk_084ECC04[index] | 0x140000); + *(u32 *)((u8 *)gUnk_03006440 + 0x28) |= 2; + countdown = 0x40; + textLength = 0; + dictionaryOffset = 0; + i = 0; + while (({ u32 k = (i + 2) * 2; *(TextChar *)((u32)source + k); }) != TEXT_CTRL(0xFD)) { + if (({ u32 k = (i + 2) * 2; *(TextChar *)((u32)source + k); }) == TEXT_CTRL(0xFC)) { + TextChar *dictionary; + TextChar *destination = &text[textLength++]; + dictionary = (TextChar *)gUnk_030034E0; + { u32 k = dictionaryOffset++ * 2; *destination = *(TextChar *)((u32)dictionary + k); } + if (({ u32 k = dictionaryOffset * 2; *(TextChar *)((u32)dictionary + k); }) == TEXT_CTRL(0xFD)) + i++; + } else { + { TextChar *d = &text[textLength++]; u32 k = (i++ + 2) * 2; *d = *(TextChar *)((u32)source + k); } + } } - { - u8 *bytes = stack + 0x34; - register u32 zero asm("r2") = 0; - - do { bytes[firstIndex] = zero; firstIndex++; } while (firstIndex <= 0xB); + text[textLength] = TEXT_CTRL(0xFD); + while ((s16)countdown > 0) { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + if (countdown == 1) + countdown = 0; + { s32 sc = countdown << 16; s32 v = sc >> 16; countdown = v - (sc >> 17); } + sub_08065230(&desc, (s16)countdown + 0xF0, 0x88, 0, 0); + sub_080003F0(); } - firstIndex = (u32)sub_080008C8() % 3; - { - u32 offset = firstIndex << 4; - register struct Record8441C *destination asm("r1"); - register struct Record8441C *input asm("r3"); - struct Record8441C *source; - - destination = (struct Record8441C *)stack; - asm("" : "+r"(destination)); - input = *(struct Record8441C **)(stack + 0x5C); - - source = (struct Record8441C *)(offset + (u32)input); - - *destination = *source; - input++; - *(struct Record8441C **)(stack + 0x7C) = input; + for (i = 0; i <= (u32)sub_0801A638((u8 *)text);) { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + { TextChar *d = &liveText[i]; zero = 0; *d = text[i]; } + asm("" : : "r"(zero));asm("" : : "r"(zero)); + liveText[i + 1] = -3; + i++; + sub_08065230(&desc, 0xF0, 0x88, 0, 0); + sub_0801A3D0((u8 *)liveText, (u16)(0xF - ((u32)sub_0801A638((u8 *)text) >> 1)), 0x12); + sub_080003F0(); + asm(""); + asm(""); + asm(""); + asm(""); + asm(""); + asm(""); + } + last = i - 1; + i = 0; + while ((keys8381C & 1) == 0) { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + if (i++ <= 0x1D) + visible = 1; + else if (i > 0x1D) + visible = 0; + if (i > 0x28) + i = 0; + if (visible) { + liveText[last] = 0xFF; + liveText[last + 1] = -3; + } else { + liveText[last] = -3; + } + sub_08065230(&desc, 0xF0, 0x88, 0, 0); + sub_0801A3D0((u8 *)liveText, (u16)(0xF - ((u32)sub_0801A638((u8 *)text) >> 1)), 0x12); + sub_080003F0(); } - { - register u8 *next asm("r3") = *(u8 **)(stack + 0x5C); - - next += 0x20; - *(u8 **)(stack + 0x74) = next; + countdown = 0; + sub_0805865C(0x0F); + do { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + if (countdown == 0x9F) + countdown = 0xA0; + { s32 v = (s16)countdown; countdown = v - ((v - 0xA0) >> 1); } + sub_08065230(&desc, (s16)countdown + 0xF0, 0x88, 0, 0); + sub_080003F0(); + } while ((s16)countdown <= 0x9F); + sub_080003F0(); + sub_080003F0(); +done: + *(u32 *)((u8 *)gUnk_03006440 + 0x28) &= ~2u; +#else + /* Empty constraints preserve the original register lifetimes and truncations. */ + u32 descriptorWords[13]; + u8 text[32]; + u8 liveText[32]; + volatile u32 visible; + u8 *source; + u8 *manager; + u16 sourceOffset; + u16 textLength; + register u32 dictionaryOffset asm("ip"); + + u32 countdown; + s16 amount; + u16 x; + extern u16 keys8381C asm("gUnk_03001324"); + + sub_08065158(((u8 *)descriptorWords), gUnk_084ECBDC[index], 0, -1, 0); + if (index == 9 || index == 3 || index == 4) { + sub_08000AF0(0x1E, (const void *)*(u32 *)(((u8 *)descriptorWords) + 0x0C), 1); + ((u8 *)descriptorWords)[0x1C] = 0x0E; + } else { + sub_08000AF0(0x1E, (u8 *)*(u32 *)(((u8 *)descriptorWords) + 0x0C) + 0x1C0, 1); } - do { secondIndex = (u32)sub_080008C8() % 3; } while (firstIndex == secondIndex); - { - u32 offset = secondIndex << 4; - register struct Record8441C *destination asm("r1"); - register struct Record8441C *input asm("r6"); - struct Record8441C *source; - - destination = second; - asm("" : "+r"(destination)); - input = *(struct Record8441C **)(stack + 0x5C); - - source = (struct Record8441C *)(offset + (u32)input); - - *destination = *source; + source = (u8 *)sub_08007290(gUnk_084ECC04[index] | 0x140000); + manager = (u8 *)gUnk_03006440; + *(u32 *)(manager + 0x28) |= 2; + + countdown = 0x40; + textLength = 0; + dictionaryOffset = 0; + sourceOffset = 0; + if (source[2] != 0xFD) { + do { + if (*(u8 *)((u32)source + ({ s32 offset = sourceOffset + 2; offset; })) == 0xFC) { + u8 *destination; + u8 *dictionary; + u32 previous; + destination = text + textLength++; + dictionary = (u8 *)gUnk_030034E0; + + previous = dictionaryOffset; + dictionaryOffset = (u16)(previous + 1); + *destination = dictionary[previous]; + if (dictionary[dictionaryOffset] == 0xFD) + sourceOffset++; + } else { + text[textLength++] = *({ u8 *pointer = source + ({ s32 offset = sourceOffset++ + 2; offset; }); pointer; }); + } + } while (*(u8 *)((u32)source + ({ s32 offset = sourceOffset + 2; offset; })) != 0xFD); } - do { thirdIndex = (u32)sub_080008C8() % 3; } while (firstIndex == thirdIndex || secondIndex == thirdIndex); + text[textLength] = 0xFD; + + if ((s16)countdown > 0) do { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + if (countdown == 1) + countdown = 0; + { + s32 scaled = countdown << 16; + s32 initial = scaled >> 16; + + amount = initial - (scaled >> 17); + } + countdown = (u16)amount; + sub_08065230(((u8 *)descriptorWords), amount + 0xF0, 0x88, 0, 0); + sub_080003F0(); + } while (amount > 0); + { - u32 offset = thirdIndex << 4; - register struct Record8441C *destination asm("r1"); - struct Record8441C *input; - register struct Record8441C *source asm("r0"); - - destination = third; - asm("" : "+r"(destination)); - input = *(struct Record8441C **)(stack + 0x5C); - - source = (struct Record8441C *)(offset + (u32)input); - asm("" : "+r"(source)); - *destination = *source; - asm("" : : "r"(input)); + register u32 i asm("r5"); + register u32 lastIndex asm("ip"); + u32 blink; + for (i = 0; i <= (u32)sub_0801A638(text);) { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + liveText[i] = text[i]; + { + register u32 next asm("r1") = i + 1; + liveText[next] = 0xFD; + + i = (u16)next; + } + sub_08065230(((u8 *)descriptorWords), 0xF0, 0x88, 0, 0); + x = 0x0F - ((u32)sub_0801A638(text) >> 1); + sub_0801A3D0(liveText, x, 0x12); + sub_080003F0(); + } + + { + register u32 previous asm("r0") = i - 1; + + lastIndex = (u16)previous; + } + blink = 0; + if ((keys8381C & 1) == 0) { + + u8 *cursor; + u8 *cursorEnd; + { + u8 *base = liveText; + u32 previous; + + previous = lastIndex; + cursor = base + previous; + cursorEnd = base + (previous + 1); + } + + for (;;) { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + { + register u32 previousBlink asm("r1") = blink; + u32 nextBlink = previousBlink + 1; + + blink = (u16)nextBlink; + if (previousBlink <= 0x1D) + visible = ({ register u32 value asm("r1") = 1; value; }); + else if (blink > 0x1D) + visible = ({ register u32 value asm("r0") = 0; value; }); + } + if (blink > 0x28) + blink = 0; + if (({ register u32 value asm("r1") = visible; asm("" : "+r"(value) : "r"(cursor), "r"(cursorEnd) : "r4", "r8", "r10"); value; })) { + *cursor = 0xA0; + *cursorEnd = 0xFD; + } else { + *cursor = 0xFD; + } + { + register u8 *liveBase asm("r4") = liveText; + + sub_08065230(((u8 *)descriptorWords), 0xF0, 0x88, 0, 0); + x = 0x0F - ((u32)sub_0801A638(text) >> 1); + sub_0801A3D0(liveBase, x, 0x12); + sub_080003F0(); + } + if (keys8381C & 1) + break; + } + } + } - classification = sub_08084200(*(u8 **)(stack + 0x5C)); - if (classification == 0) goto LAB_0808481c; - if (((u32)sub_080008C8() & 0xFFFF) > *(u32 *)((u32)gUnk_030034E0 + 0x6C)) goto LAB_0808481c; - { - register struct Record8441C *input asm("r6") = *(struct Record8441C **)(stack + 0x5C); - - tier = (u32)input[0].value + (u32)input[1].value + (u32)input[2].value; + + countdown = 0; + sub_0805865C(0x0F); + for (;;) { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + if (countdown == 0x9F) + countdown = 0xA0; + { + s32 initial = countdown << 16; + initial >>= 16; + + amount = initial - ((initial - 0xA0) >> 1); + } + countdown = (u16)amount; + sub_08065230(((u8 *)descriptorWords), amount + 0xF0, 0x88, 0, 0); + sub_080003F0(); + if (amount > 0x9F) + break; } - if (tier <= 99) goto lowTier8441C; - if (tier - 100 <= 199) tier = 0; - else { - u32 range = tier - 300; - tier = 2; - if (range <= 199) tier = 1; + sub_080003F0(); + sub_080003F0(); + +done: + manager = (u8 *)gUnk_03006440; + *(u32 *)(manager + 0x28) &= ~2u; +#endif +} +/* [RunItemMenuMessageWithVariantPanels] Full-word r0 message-table index. Chooses visual mode from + * flag-query0x08057AE8(21) only when current area0, otherwise mode2. Mode0 initializes three descriptor + * resources0x500CC/CB/CA, mode1 middleCB, mode2 rightCA; uses palette variants and eased panel slide-in/out, + * setting manager+0x28 bit1 while active. Looks up message via0x084ECC04[index]|0x140000, skips2-byte header, + * progressively copies into32-byte local text with u16 indices, draws centered row18, then waits + * input0x03001324 bit0 with blinking0xA0 marker. A acknowledgement plays sound15; suspend request/link error + * skips to cleanup, and all paths clear manager bit1. No binary choice result or item mutation here. */ +void sub_08083AE8(u32 input) + +{ +#ifdef REGION_USA + extern u32 gUnk_084ECC04[]; + extern u16 sub_08057AE8(s32); + extern u16 keys83AE8 asm("gUnk_03001324"); + struct Pan83 { u32 w0, w4, w8, pal; u8 p10[0x1A]; u8 f2A; u8 p2B[9]; }; + struct Pan83 left; + struct Pan83 middle; + struct Pan83 right; + TextChar text[30]; + u16 last; + u8 *msg; + u16 slide0, slide1, slide2; + u32 on; + s32 zr; + s32 e0, e1, e2; + struct Pan83 *rp; + u32 mode; + u16 i; + u8 *str; + asm("" : : "r"(input)); + asm("" : : "r"(input)); + asm("" : : "r"(input)); + asm("" : : "r"(input)); + asm("" : : "r"(input)); + asm("" : : "r"(input)); + if (gUnk_03003170.curLevel == 0) + mode = sub_08057AE8(0x15); + else + mode = 2; + switch ((s32)mode) { + case 1: + sub_08065158(&middle, RES_ID(0x500CB), 0, -1, 0); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + slide1 = 0x77; + slide0 = 0x77; + break; + case 2: + sub_08065158(&right, RES_ID(0x500CA), 0, -1, 0); + sub_08000AF0(0x15, right.pal + 0x1C0, 1); + slide2 = 0x77; + slide0 = 0x77; + break; + case 0: + sub_08065158(&left, RES_ID(0x500CC), 0, -1, 0); + sub_08065158(&middle, RES_ID(0x500CB), 0, -1, 0); + sub_08065158(&right, RES_ID(0x500CA), 0, -1, 0); + sub_08000AF0(0x14, left.pal + 0x1C0, 1); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + sub_08000AF0(0x1E, right.pal + 0x1C0, 1); + slide0 = 0x77; + slide1 = 0xAE; + slide2 = 0x40; + break; } - switch (classification) { + left.f2A = 4; + middle.f2A = 5; + msg = (u8 *)sub_08007290(gUnk_084ECC04[input] | 0x140000); + *(u32 *)((u8 *)gUnk_03006440 + 0x28) |= 2; + while ((s16)slide0 > 0) { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + if ((s16)slide0 == 1) slide0 = 0; + { s32 sc = slide0 << 16; s32 v = sc >> 16; slide0 = v - (sc >> 17); } + if ((s16)slide1 == 1) slide1 = 0; + { s32 sc = slide1 << 16; s32 v = sc >> 16; slide1 = v - (sc >> 17); } + if ((s16)slide2 == 1) slide2 = 0; + { s32 sc = slide2 << 16; s32 v = sc >> 16; slide2 = v - (sc >> 17); } + switch ((s32)mode) { + case 1: + sub_08065230(&middle, (s16)slide1 + 0xB9, 0x88, 0, 0); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + break; + case 2: + sub_08065230(&right, (s16)slide2 + 0xB9, 0x88, 0, 0); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + break; + case 0: + sub_08000AF0(0x14, left.pal + 0x1C0, 1); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + { register struct Pan83 *r4 asm("r4") = &right; asm("" : "+r"(r4)); rp = r4; } + sub_08000AF0(0x1E, rp->pal + 0x1C0, 1); + sub_08065230(rp, (s16)slide2 + 0xF0, 0x88, 0, 0); + sub_08065230(&middle, (s16)slide1 + 0x82, 0x88, 0, 0); + sub_08065230(&left, (s16)slide0 + 0xB9, 0x88, 0, 0); + break; + } + sub_080003F0(); + } + i = 0; + str = msg + TEXT_HEADER; + goto check2; +body2: + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + switch ((s32)mode) { + case 1: + sub_08065230(&middle, 0xB9, 0x88, 0, 0); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + break; + case 2: + sub_08065230(&right, 0xB9, 0x88, 0, 0); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + break; + case 0: + sub_08000AF0(0x14, left.pal + 0x1C0, 1); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + sub_08000AF0(0x1E, right.pal + 0x1C0, 1); + sub_08065230(&right, 0xF0, 0x88, 0, 0); + sub_08065230(&middle, 0x82, 0x88, 0, 0); + sub_08065230(&left, 0xB9, 0x88, 0, 0); + break; + } + { TextChar *dst = &text[i]; u32 k = (i + 2) * 2; *dst = *(TextChar *)((u32)msg + k); } + text[i + 1] = TEXT_CTRL(0xFD); + i++; + asm("" : : "r"(str)); + sub_0801A3D0((u8 *)text, (u16)(0xF - ((u32)sub_0801A638(str) >> 1)), 0x12); + sub_080003F0(); +check2: + if (i <= (u32)sub_0801A638(str)) + goto body2; + last = i - 1; + i = 0; + while ((keys83AE8 & 1) == 0) { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + if (i++ <= 0x1D) + on = 1; + else if (i > 0x1D) + on = 0; + if (i > 0x28) + i = 0; + if (on) { + text[last] = 0xFF; + text[last + 1] = -3; + } else { + text[last] = -3; + } + switch ((s32)mode) { + case 1: + sub_08065230(&middle, 0xB9, 0x88, 0, 0); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + break; + case 2: + sub_08065230(&right, 0xB9, 0x88, 0, 0); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + break; + case 0: + sub_08000AF0(0x14, left.pal + 0x1C0, 1); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + sub_08000AF0(0x1E, right.pal + 0x1C0, 1); + sub_08065230(&right, 0xF0, 0x88, 0, 0); + sub_08065230(&middle, 0x82, 0x88, 0, 0); + sub_08065230(&left, 0xB9, 0x88, 0, 0); + break; + } + asm("" : : "r"(str)); + sub_0801A3D0((u8 *)text, (u16)(0xF - ((u32)sub_0801A638(str) >> 1)), 0x12); + sub_080003F0(); + } + slide0 = 0; + slide1 = 0; + slide2 = 0; + sub_0805865C(0xF); + switch ((s32)mode) { case 1: - randomIndex = (u32)sub_080008C8() % 14; - { const u32 *table = table8441C_084EC1E0; - u32 index = randomIndex << 2; - u32 row = tier * 56; - entry = (const u16 *)(index + row + (u32)table); - } - goto applyEntry8441C; + do { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + { s32 v = (s16)slide1; slide1 = v - ((v - 0x77) >> 1); } + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + sub_08065230(&middle, (s16)slide1 + 0xB9, 0x88, 0, 0); + sub_080003F0(); + } while ((s16)slide1 != 0x77); + break; case 2: - randomIndex = (u32)sub_080008C8() % 14; - { const u32 *table = table8441C_084EC288; - u32 index = randomIndex << 2; - u32 row = tier * 56; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(randomIndex), "r"(table), "i"(2)); } - goto applyEntry8441C; - case 3: - randomIndex = (u32)sub_080008C8() % 14; - { const u32 *table = table8441C_084EC330; - u32 index = randomIndex << 2; - u32 row = tier * 56; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(randomIndex), "r"(table), "i"(3)); } - goto applyEntry8441C; - case 4: - randomIndex = (u32)sub_080008C8() % 14; - { const u32 *table = table8441C_084EC3D8; - u32 index = randomIndex << 2; - u32 row = tier * 56; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(randomIndex), "r"(table), "i"(4)); } - goto applyEntry8441C; - case 5: - { register u32 index asm("r1") = (u32)sub_080008C8() & 7; - const u32 *table = table8441C_084EC480; - register u32 row asm("r0"); - index <<= 2; - row = tier << 5; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(5)); } - goto applyEntry8441C; - case 6: - { register u32 index asm("r1") = (u32)sub_080008C8() & 7; - const u32 *table = table8441C_084EC4E0; - register u32 row asm("r0"); - index <<= 2; - row = tier << 5; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(6)); } - goto applyEntry8441C; - case 7: - { register u32 index asm("r1") = (u32)sub_080008C8() & 7; - const u32 *table = table8441C_084EC540; - register u32 row asm("r0"); - index <<= 2; - row = tier << 5; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(7)); } - goto applyEntry8441C; - case 8: - { register u32 index asm("r1") = (u32)sub_080008C8() & 7; - const u32 *table = table8441C_084EC5A0; - register u32 row asm("r0"); - index <<= 2; - row = tier << 5; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(8)); } - goto applyEntry8441C; - case 9: - { register u32 index asm("r1") = (u32)sub_080008C8() & 7; - const u32 *table = table8441C_084EC600; - register u32 row asm("r0"); - index <<= 2; - row = tier << 5; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(9)); } - goto applyEntry8441C; - case 10: - { register u32 index asm("r1") = (u32)sub_080008C8() & 7; - const u32 *table = table8441C_084EC660; - register u32 row asm("r0"); - index <<= 2; - row = tier << 5; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(10)); } - goto applyEntry8441C; - case 11: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC6C0; - goto tripleEntry8441C; - case 12: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC6E4; - goto tripleEntry8441C; - case 13: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC708; - goto tripleEntry8441C; - case 14: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC72C; - goto tripleEntry8441C; - case 15: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC750; - goto tripleEntry8441C; - case 16: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC774; - goto tripleEntry8441C; - case 17: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC798; - goto tripleEntry8441C; - case 18: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC7BC; - goto tripleEntry8441C; - case 19: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC7E0; - goto tripleEntry8441C; - case 20: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC804; - goto tripleEntry8441C; - case 21: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC828; - goto tripleEntry8441C; - case 22: - randomIndex = (u32)sub_080008C8() % 3; - tripleTable = table8441C_084EC84C; -tripleEntry8441C: - { const u16 *p = (const u16 *)(((tier * 3 + randomIndex) << 2) + (u32)tripleTable); - result->type = p[0]; result->subtype = p[1]; } - goto finalize8441C; - case 23: - { register u32 index asm("r1") = (u32)sub_080008C8() & 3; - const u32 *table = table8441C_084EC870; - register u32 row asm("r0"); - index <<= 2; - row = (tier + 1) << 4; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(23)); } - goto applyEntry8441C; - case 24: - { register u32 index asm("r1") = (u32)sub_080008C8() & 3; - const u32 *table = table8441C_084EC8B0; - register u32 row asm("r0"); - index <<= 2; - row = (tier + 1) << 4; - entry = (const u16 *)(index + row + (u32)table); - asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(24)); } - goto applyEntry8441C; - default: goto finalize8441C; - } -lowTier8441C: - if (classification == 23) goto low23; - if (classification == 24) goto low24; - goto LAB_0808481c; -low23: - { u32 index = (u32)sub_080008C8() & 3; - const u32 *table; - table = table8441C_084EC870; - entry = (const u16 *)((index << 2) + (u32)table); } - goto applyEntry8441C; -low24: - { u32 index = (u32)sub_080008C8() & 3; - const u32 *table; - table = table8441C_084EC8B0; - entry = (const u16 *)((index << 2) + (u32)table); } -applyEntry8441C: - result->type = entry[0]; - result->subtype = entry[1]; - goto finalize8441C; -LAB_0808481c: - switch (((struct Record8441C *)stack)->type) { - case 9: - { - s32 subtype = ((struct Record8441C *)stack)->subtype; - if (subtype == 3) goto rareFirst8441C; - if (subtype == 4) goto rareSecond8441C; - if (((u32)sub_080008C8() & 1) == 0) goto inventorySecond8441C; - goto inventoryFirst8441C; -rareFirst8441C: - randomIndex = (u32)sub_080008C8(); - randomIndex &= subtype; - { - struct Triple8441C *temporary = (struct Triple8441C *)(stack + 0x4C); - const u32 *table; - const struct Triple8441C *source; - table = table8441C_084EC8F0; - { u32 offset = randomIndex * 12; - struct Triple8441C *destination; - destination = temporary; - source = (const struct Triple8441C *)(offset + (u32)table); - *destination = *source; } - - copy8441C(result, temporary, 16); + do { + if (sub_0800CDF8() != 0 || sub_080021A8() != 0) + goto done; + { s32 v = (s16)slide2; slide2 = v - ((v - 0x77) >> 1); } + sub_08000AF0(0x15, right.pal + 0x1C0, 1); + sub_08065230(&right, (s16)slide2 + 0xB9, 0x88, 0, 0); + sub_080003F0(); + } while ((s16)slide2 != 0x77); + break; + case 0: + { + s32 d; + again: + if (sub_0800CDF8() != 0 || (zr = sub_080021A8()) != 0) + goto done; + { s32 v = (s16)slide0; slide0 = v - ((v - 0x77) >> 1); } + { s32 v = (s16)slide1; slide1 = v - ((v - 0xAE) >> 1); } + { s32 v = (s16)slide2; slide2 = v - ((v - 0x40) >> 1); } + d = (s16)slide0 - 0x77; + if (d < 0) d = -d; + if (d == 1) slide0 = 0x77; + d = (s16)slide1 - 0xAE; + if (d < 0) d = -d; + if (d == 1) slide1 = 0xAE; + d = (s16)slide2 - 0x40; + if (d < 0) d = -d; + if (d == 1) slide2 = 0x40; + sub_08000AF0(0x14, left.pal + 0x1C0, 1); + sub_08000AF0(0x15, middle.pal + 0x1C0, 1); + sub_08000AF0(0x1E, right.pal + 0x1C0, 1); + e2 = (s16)slide2; + sub_08065230(&right, e2 + 0xF0, 0x88, 0, zr); + e1 = (s16)slide1; + sub_08065230(&middle, e1 + 0x82, 0x88, 0, zr); + e0 = (s16)slide0; + sub_08065230(&left, e0 + 0xB9, 0x88, 0, zr); + asm("" : : "r"(e2)); + sub_080003F0(); + if (e0 != 0x77 || e1 != 0xAE || e2 != 0x40) + goto again; + } + break; } + sub_080003F0(); + sub_080003F0(); +done: + *(u32 *)((u8 *)gUnk_03006440 + 0x28) &= ~2; +#else + u32 param_1 = input; + /* Preserve the original 208-byte frame, including its outgoing argument. */ + extern u32 gUnk_084ECC04[]; + extern u16 sub_08057AE8(s32); + extern u16 keys83AE8 asm("gUnk_03001324"); + u8 frameStorage83AE8[204]; + register u8 *stack asm("sp"); + /* Empty constraints retain the original register and stack lifetimes. */ + s32 uVar1; + u16 uVar2; + u8 *puVar3; + int iVar4; + u32 uVar5; + u32 uVar6; + u32 uVar7; + short sVar8; + u32 uVar9; + short sVar10; + u16 uVar11; + u32 uVar12; + u32 unaff_r9; + register u32 unaff_r10 asm("r10"); + u32 in_lr; - goto finalize8441C; -rareSecond8441C: - randomIndex = (u32)sub_080008C8(); - { u32 mask = 3; randomIndex &= mask; } + + if (gUnk_03003170.curLevel == 0) uVar1 = sub_08057AE8(0x15); + else uVar1 = 2; + switch ((s32)uVar1) { + case 1: { - struct Triple8441C *temporary = (struct Triple8441C *)(stack + 0x4C); - const u32 *table; - const struct Triple8441C *source; - table = table8441C_084EC920; - { u32 offset = randomIndex * 12; - struct Triple8441C *destination; - destination = temporary; - source = (const struct Triple8441C *)(offset + (u32)table); - *destination = *source; } - copy8441C(result, temporary, 16); + u8 *panel = stack + 0x38; + + sub_08065158(panel, 0x500CB, 0, -1, 0); + sub_08000AF0(0x15, *(u32 *)(panel + 0xC) + 0x1C0, 1); + unaff_r9 = ({ register u32 value asm("r1") = 0x77; asm("" : "+r"(value)); value; }); + goto setCountdown; } - - goto thirdValue8441C; -inventoryFirst8441C: - do { - randomIndex = (u32)sub_080008C8() % 12; + case 2: + { + u8 *panel = stack + 0x6C; + sub_08065158(panel, 0x500CA, 0, -1, 0); { - u8 *source = (u8 *)(u32)gUnk_030034E0; - u32 byteOffset = randomIndex << 4; - register struct Record8441C *destination asm("r1"); - register u32 baseOffset asm("r5"); - source += byteOffset; - destination = result; - baseOffset = 0x790; - asm("" : "+r"(destination), "+r"(baseOffset)); - source += baseOffset; - *destination = *(struct Record8441C *)source; - asm("" : : "r"(baseOffset), "r"(subtype)); - } - - } while (result->type == 0); - { u32 loaded = sub_08007290(result->subtype | 0xB0000); - *(u32 *)(stack + 0x64) = loaded; - if (*(u16 *)(loaded + 0xBC) != 0) goto finalize8441C; } - if (*(u16 *)((u8 *)result + 6) != 0) goto finalize8441C; - if (*(u16 *)(*(volatile u32 *)(stack + 0x64) + 0xB0) != 0) goto finalize8441C; - goto secondAttribute8441C; -inventorySecond8441C: - { - struct Record8441C *inventoryResult = result; - do { - randomIndex = (u32)sub_080008C8() % 12; + u32 palette = *(u32 *)(panel + 0xC); - { - u8 *source = (u8 *)(u32)gUnk_030034E0; - u32 byteOffset = randomIndex << 4; - register struct Record8441C *destination asm("r1"); - register u32 baseOffset asm("r5"); - source += byteOffset; - destination = inventoryResult; - baseOffset = 0x850; - asm("" : "+r"(destination), "+r"(baseOffset)); - source += baseOffset; - *destination = *(struct Record8441C *)source; - asm("" : : "r"(baseOffset), "r"(inventoryResult)); + sub_08000AF0(0x15, palette + ({ u32 offset = 0x1C0; offset; }), 1); } - - } while (inventoryResult->type == 0); + unaff_r10 = ({ register u32 value asm("r1") = 0x77; asm("" : "+r"(value)); value; }); + } +setCountdown: + *(u32 *)(stack + 0xC4) = ({ register u32 value asm("r2") = 0x77; value; }); + break; + case 0: + { + u8 *middle; + u8 *right; + sub_08065158(frameStorage83AE8, 0x500CC, 0, -1, 0); + middle = stack + 0x38; + + sub_08065158(middle, 0x500CB, 0, -1, 0); + right = stack + 0x6C; + + sub_08065158(right, 0x500CA, 0, -1, 0); + sub_08000AF0(0x14, *(u32 *)(stack + 0x10) + 0x1C0, 1); + sub_08000AF0(0x15, *(u32 *)(middle + 0xC) + 0x1C0, 1); + sub_08000AF0(0x1E, *(u32 *)(right + 0xC) + 0x1C0, 1); + *(u32 *)(stack + 0xC4) = ({ u32 value = 0x77; value; }); + unaff_r9 = ({ register u32 value asm("r1") = 0xAE; asm("" : "+r"(value)); value; }); + unaff_r10 = ({ register u32 value asm("r2") = 0x40; asm("" : "+r"(value)); value; }); + } + break; + } + (*(u8 *)((stack + 4) + 0x2A)) = 4; + (*(u8 *)((stack + 4) + 0x5E)) = 5; + (*(u32 *)((stack + 4) + 0xBC)) = sub_08007290(({ register u32 *table asm("r1") = gUnk_084ECC04; register u32 index asm("r2"); register u32 *entry asm("r0"); index = param_1; asm("" : "+r"(index)); entry = (u32 *)((index << 2) + (u32)table); *entry; }) | 0x140000); + *(u32 *)(*(int *)((u32)&gUnk_03006440) + 0x28) = *(u32 *)(*(int *)((u32)&gUnk_03006440) + 0x28) | 2; + if (({ register u32 raw asm("r1") = *(u32 *)(stack + 0xC4); register s32 scaled asm("r0"); scaled = raw << 16; scaled; }) > 0) { + u8 *middle = stack + 0x38; + u32 paletteOffset = 0x1C0; + s32 shiftedCount; + + do { + s32 zero; + if (sub_0800CDF8() != 0) goto LAB_080841de; + zero = sub_080021A8(); + + if (zero != 0) goto LAB_080841de; + if (({ register u32 raw asm("r1") = *(u32 *)(stack + 0xC4); register s32 scaled asm("r0"); scaled = raw << 16; scaled >> 16; }) == 1) *(u32 *)(stack + 0xC4) = ({ register u32 value asm("r0") = 0; value; }); + { + register u32 raw asm("r1") = *(u32 *)(stack + 0xC4); + s32 scaled; + register s32 signedValue asm("r1"); + + scaled = raw << 16; + signedValue = scaled >> 16; + + signedValue = (u16)(signedValue - (scaled >> 17)); + + *(u32 *)(stack + 0xC4) = signedValue; + } + if (({ register u32 raw asm("r1") = unaff_r9; register s32 scaled asm("r0"); scaled = raw << 16; scaled >> 16; }) == 1) unaff_r9 = ({ register u32 value asm("r0") = 0; value; }); + { + u32 raw = unaff_r9; + s32 scaled; + register s32 signedValue asm("r1"); + + scaled = raw << 16; + signedValue = scaled >> 16; + + signedValue = (u16)(signedValue - (scaled >> 17)); + + unaff_r9 = signedValue; + } + if (({ register u32 raw asm("r1") = unaff_r10; register s32 scaled asm("r0"); scaled = raw << 16; scaled >> 16; }) == 1) unaff_r10 = ({ register u32 value asm("r0") = 0; value; }); + { + register u32 raw asm("r1") = unaff_r10; + s32 scaled; + register s32 signedValue asm("r1"); + + scaled = raw << 16; + signedValue = scaled >> 16; + + signedValue = (u16)(signedValue - (scaled >> 17)); + + unaff_r10 = signedValue; + } + { + register u8 *panel asm("r0"); + register s32 x asm("r1"); + if (uVar1 == 1) goto phase1Middle; + if (uVar1 > 1) goto phase1Greater; + if (uVar1 == 0) goto phase1All; + shiftedCount = ({ register u32 value asm("r2") = *(u32 *)(stack + 0xC4); value; }) << 16; + goto phase1Yield; +phase1Greater: + if (uVar1 == 2) goto phase1Right; + goto phase1SingleEnd; +phase1Middle: + x = ({ register u32 raw asm("r0") = unaff_r9; register s32 x asm("r1"); x = raw << 16; x >>= 16; x + 0xB9; }); + *(u32 *)stack = zero; + + panel = middle; + goto phase1Single; +phase1Right: + x = ({ register u32 raw asm("r0") = unaff_r10; register s32 x asm("r1"); x = raw << 16; x >>= 16; x + 0xB9; }); + *(u32 *)stack = zero; + + panel = stack + 0x6C; +phase1Single: + sub_08065230(panel, x, 0x88, 0, *(u32 *)stack); + { + u32 palette = *(u32 *)(middle + 0xC); + register u32 paletteOffset asm("r2"); + + paletteOffset = 0x1C0; + asm("" : "+r"(paletteOffset)); + sub_08000AF0(0x15, palette + paletteOffset, 1); } - if (result->type == 3) { - *(u32 *)(stack + 0x68) = sub_08007290(result->subtype | 0xC0000); - asm("" : : : "memory"); - if ((*(u32 *)((u8 *)result + 4) & 0xFFFFFF) != 0) goto finalize8441C; - if (*(u16 *)(*(u32 *)(stack + 0x68) + 0xA4) != 0) goto finalize8441C; - } else { - if (result->type == 4) *(u32 *)(stack + 0x6C) = sub_08007290(result->subtype | 0xD0000); - else *(u32 *)(stack + 0x70) = sub_08007290(result->subtype | 0xE0000); - if ((*(u32 *)((u8 *)result + 4) & 0xFFFFFF) != 0) goto finalize8441C; - if (*(u16 *)(*(u32 *)(stack + 0x6C) + 0xA4) != 0) goto finalize8441C; +phase1SingleEnd: + shiftedCount = ({ u32 value = *(u32 *)(stack + 0xC4); value; }) << 16; + goto phase1Yield; +phase1All: + { + u8 *right; + sub_08000AF0(0x14, *(u32 *)(stack + 0x10) + paletteOffset, 1); + sub_08000AF0(0x15, *(u32 *)(middle + 0xC) + paletteOffset, 1); + right = stack + 0x6C; + + sub_08000AF0(0x1E, *(u32 *)(right + 0xC) + paletteOffset, 1); + sub_08065230(right, ({ register u32 raw asm("r2") = unaff_r10; s32 x; asm("" : "+r"(raw)); x = raw << 16; x >>= 16; x + 0xF0; }), 0x88, 0, 0); + sub_08065230(middle, ({ register u32 raw asm("r0") = unaff_r9; s32 x; x = raw << 16; x >>= 16; x + 0x82; }), 0x88, 0, 0); + shiftedCount = ({ register u32 value asm("r1") = *(u32 *)(stack + 0xC4); value; }) << 16; + sub_08065230(frameStorage83AE8, (shiftedCount >> 16) + 0xB9, 0x88, 0, 0); } - goto thirdValue8441C; } - case 2: - { u32 hold2, hold3 asm("r3"); - *result = *(struct Record8441C *)stack; - } - goto secondAttribute8441C; - case 3: case 4: case 5: - { u32 hold5, hold6 asm("r6"); - *result = *(struct Record8441C *)stack; - } - goto thirdValue8441C; - default: break; - } -secondAttribute8441C: - if (((u32)sub_080008C8() & 0xFFFF) <= *(u32 *)((u32)gUnk_030034E0 + 0x6C)) { - register struct Record8441C *attributeRecord asm("r0") = second; - s32 attributeType; - attributeType = attributeRecord->type; - switch (attributeType) { - case 9: +phase1Yield: + sub_080003F0(); + } while (shiftedCount > 0); + } + { + u32 revealIndex; + u32 lastIndex; + u32 blink; + revealIndex = ({ register u32 value asm("r2") = 0; asm("" : "+r"(value)); value; }); + *(u32 *)(stack + 0xCC) = *(u32 *)(stack + 0xC0) + 2; + while (revealIndex <= (u32)sub_0801A638(*(u8 **)(stack + 0xCC))) { + s32 zero; + if (sub_0800CDF8() != 0) goto LAB_080841de; + zero = sub_080021A8(); + + if (zero != 0) goto LAB_080841de; + switch (uVar1) { + case 1: { - s32 subtype = attributeRecord->subtype; - switch (subtype) { - case 0: - randomIndex = (u32)sub_080008C8() % 3; - - unaff_r9 = ({ register u32 value asm("r6") = 1; asm("" : "+r"(value)); value; }); - if (randomIndex == 0) unaff_r9 = ({ register u32 value asm("r0") = 3; asm("" : "+r"(value)); value; }); - break; - case 1: - subtype &= sub_080008C8(); - unaff_r9 = ({ register u32 value asm("r1") = 4; asm("" : "+r"(value)); value; }); - if (subtype == 0) unaff_r9 = ({ register u32 value asm("r2") = 2; asm("" : "+r"(value)); value; }); - break; - case 2: - randomIndex = (u32)sub_080008C8() % 3; - - unaff_r9 = ({ register u32 value asm("r3") = 6; asm("" : "+r"(value)); value; }); - if (randomIndex == 0) unaff_r9 = ({ register u32 value asm("r4") = 5; asm("" : "+r"(value)); value; }); - break; - default: unaff_r9 = ({ u32 value = 0; value; }); break; - } + u8 *middle = stack + 0x38; + + sub_08065230(middle, 0xB9, 0x88, 0, zero); + { u32 palette = *(u32 *)(middle + 0xC); register u32 offset asm("r2"); offset = 0x1C0; asm("" : "+r"(offset)); palette += offset; sub_08000AF0(0x15, palette, 1); } } break; case 2: - unaff_r9 = ({ struct Record8441C *p = second; u32 value; value = p->byte7; value; }); + sub_08065230(stack + 0x6C, 0xB9, 0x88, 0, zero); + { u32 palette = *(u32 *)(stack + 0x44); u32 offset; offset = 0x1C0; palette += offset; sub_08000AF0(0x15, palette, 1); } + break; + case 0: + { + u8 *middle; + u8 *right; + register u32 paletteOffset asm("r4"); + u32 palette = *(u32 *)(stack + 0x10); + + paletteOffset = 0x1C0; + + sub_08000AF0(0x14, palette + paletteOffset, 1); + middle = stack + 0x38; + + sub_08000AF0(0x15, *(u32 *)(middle + 0xC) + paletteOffset, 1); + right = stack + 0x6C; + + sub_08000AF0(0x1E, *(u32 *)(right + 0xC) + paletteOffset, 1); + sub_08065230(right, 0xF0, 0x88, 0, 0); + sub_08065230(middle, 0x82, 0x88, 0, 0); + sub_08065230(frameStorage83AE8, 0xB9, 0x88, 0, 0); + } break; - case 3: case 4: case 5: unaff_r9 = ({ u32 value = 0; value; }); break; - default: break; } - switch (result->type) { - case 3: case 4: case 5: result->byte7 = 0; break; - default: { u32 attribute = unaff_r9; result->byte7 = attribute; } break; + { + u8 *buffer = stack + 0xA0; + register u32 old asm("r2"); + u8 *destination; + u32 offset; + register u8 *source asm("r2"); + register u8 *address asm("r0"); + u32 next; + + old = revealIndex; + asm("" : "+r"(old)); + destination = buffer + old; + + offset = revealIndex + 2; + + source = *(u8 **)(stack + 0xC0); + + address = source + offset; + + *destination = *address; + next = revealIndex + 1; + buffer[next] = 0xFD; + + revealIndex = (u16)next; + sub_0801A3D0(buffer, (u16)(0xF - ((u32)sub_0801A638(*(u8 **)(stack + 0xCC)) >> 1)), 0x12); + sub_080003F0(); } } -thirdValue8441C: { - u32 chance; - u32 tableValue; - register u32 offset asm("r1"); - const u32 *table; + u32 previous = revealIndex - 1; + + lastIndex = (u16)previous; + } + blink = ({ register u32 value asm("r0") = 0; asm("" : "+r"(value)); value; }); + if ((keys83AE8 & 1) == 0) { + u8 *buffer; + u8 *middle; { - u32 random = (u32)sub_080008C8() & 0xFFFF; - u32 limit; - limit = *(u32 *)((u32)gUnk_030034E0 + 0x6C); - chance = 0; - if (random <= limit) chance = 1; - } - switch (result->type) { - case 2: goto resultTwo8441C; - case 3: case 4: case 5: break; - default: goto finalize8441C; - } - { register struct Record8441C *p asm("r2") = third; - switch ((s32)p->type) { - case 2: case 3: case 4: case 5: goto permittedOther8441C; - case 9: goto topRandomTrampoline; - default: goto finalize8441C; - } - } -topRandomTrampoline: - /* Keep the original conditional trampoline; this emits no instructions. */ - asm("" : : "X"(&&topRandomTrampoline)); - goto randomOther8441C; -resultTwo8441C: - { u32 address; - address = sub_08007290(result->subtype | 0xB0000); - *(u32 *)(stack + 0x64) = address; - if (*(u8 *)(address + 0x9B) != 9) goto resultTwoOrdinary8441C; - { register struct Record8441C *p asm("r3") = third; - switch ((s32)p->type) { - case 2: case 3: case 4: case 5: goto permittedFour8441C; - case 9: break; - default: goto finalize8441C; - } - } - } -randomSpecial8441C: - randomIndex = sub_080008C8(); - { u32 mask = 3; randomIndex &= mask; } - if (!chance) goto randomSpecialNo; - table = table8441C_084ECA90; -sharedOffset8441C: - offset = randomIndex << 2; - tableValue = ({ register struct Record8441C *p asm("r4") = third; p->subtype; }); -sharedTable8441C: - tableValue <<= 4; - offset += tableValue; - offset += (u32)table; - tableValue = *(u32 *)offset; - goto setValue8441C; -randomSpecialNo: - table = table8441C_084ECAE0; - offset = randomIndex << 2; - tableValue = ({ register struct Record8441C *p asm("r5") = third; p->subtype; }); - goto sharedTable8441C; -permittedFour8441C: - { u32 value; - value = ({ register struct Record8441C *p asm("r6") = third; p->value; }); - if (value == 0) { result->value = value; goto finalize8441C; } - value = sub_08007290((value - 1) | 0x130000); - { register u8 *duplicate asm("r1") = (u8 *)value; - register u32 flags asm("r1"); - asm("" : : "r"(duplicate)); - value += 0xAC; - flags = *(u16 *)value; - value = 4; value &= flags; - value = (u16)value; - } - if (value == 0) { result->value = value; goto finalize8441C; } - value = ({ register struct Record8441C *p asm("r1") = third; p->value; }); - { result->value = value; goto finalize8441C; } - } -resultTwoOrdinary8441C: - { register struct Record8441C *p asm("r2") = third; - switch ((s32)p->type) { - case 2: case 3: case 4: case 5: goto permittedEight8441C; - case 9: break; - default: goto finalize8441C; - } - } -randomOrdinary8441C: - randomIndex = sub_080008C8(); - { u32 mask = 3; randomIndex &= mask; } - if (!chance) goto randomOrdinary8441Cno; - table = table8441C_084EC950; - offset = randomIndex << 2; - tableValue = ({ register struct Record8441C *p asm("r3") = third; asm("" : "+r"(p)); p->subtype; }); - goto sharedTable8441C; -randomOrdinary8441Cno: - table = table8441C_084EC9A0; - goto sharedOffset8441C; -permittedEight8441C: - { u32 value; - value = ({ register struct Record8441C *p asm("r5") = third; p->value; }); - if (value == 0) { result->value = value; goto finalize8441C; } - value = sub_08007290((value - 1) | 0x130000); - { register u8 *duplicate asm("r1") = (u8 *)value; - register u32 flags asm("r1"); - asm("" : : "r"(duplicate)); - value += 0xAC; - flags = *(u16 *)value; - value = 8; value &= flags; - value = (u16)value; - } - if (value == 0) { result->value = value; goto finalize8441C; } - value = ({ register struct Record8441C *p asm("r6") = third; p->value; }); - { result->value = value; goto finalize8441C; } + register u8 *base asm("r1") = stack + 0xA0; + + buffer = base; } -randomOther8441C: - randomIndex = sub_080008C8(); - { u32 mask = 3; randomIndex &= mask; } - if (!chance) goto randomOther8441Cno; - table = table8441C_084EC9F0; - offset = randomIndex << 2; - tableValue = ({ register struct Record8441C *p asm("r3") = third; p->subtype; }); - goto sharedTable8441C; -randomOther8441Cno: - table = table8441C_084ECA40; - goto sharedOffset8441C; -permittedOther8441C: - { struct Record8441C *valueRecord = third; - u8 *properties; - u32 initial, type, flags, allowed; - initial = valueRecord->value; - if (initial == 0) { result->value = initial; goto finalize8441C; } - { u32 argument = initial; - u32 tag = 0x130000; - asm("" : "+r"(argument), "+r"(tag)); - properties = (u8 *)sub_08007290(argument | tag); } - type = (u16)(result->type - 3); - if (type > 1) goto permittedOne8441C; - { u8 *address = properties; - u32 bits; - u32 mask; - address += 0xAC; - bits = *(u16 *)address; - mask = 2; mask &= bits; - allowed = (u16)mask; - if (allowed == 0) { result->value = allowed; goto finalize8441C; } + middle = stack + 0x38; + + do { + if (sub_0800CDF8() != 0) goto LAB_080841de; + if (({ s32 status = sub_080021A8(); status; }) != 0) goto LAB_080841de; + { + register u32 previous asm("r1") = blink; + u32 next = previous + 1; + + blink = (u16)next; + if (previous <= 0x1D) *(u32 *)(stack + 0xC8) = ({ register u32 value asm("r2") = 1; value; }); + else if (({ u32 value = blink; value; }) > 0x1D) *(u32 *)(stack + 0xC8) = ({ register u32 value asm("r1") = 0; value; }); } - result->value = valueRecord->value; - goto finalize8441C; -permittedOne8441C: - { u8 *address = properties; - u32 mask; - address += 0xAC; - flags = *(u16 *)address; - mask = 1; mask &= flags; - if (mask == 0) { result->value = mask; goto finalize8441C; } + if (({ register u32 value asm("r2") = blink; asm("" : "+r"(value)); value; }) > 0x28) blink = ({ register u32 value asm("r0") = 0; asm("" : "+r"(value)); value; }); + if (({ register u32 value asm("r1") = *(u32 *)(stack + 0xC8); value; })) { + buffer[lastIndex] = 0xA0; + { + u32 next = lastIndex + 1; + register u8 *end asm("r0"); + u32 terminator; + + end = buffer + next; + + terminator = 0xFD; + + *end = terminator; + } + } else buffer[lastIndex] = 0xFD; + { + register u8 *drawBuffer asm("r6") = frameStorage83AE8 + 0x9C; + + switch (uVar1) { + case 1: + sub_08065230(middle, 0xB9, 0x88, 0, 0); + { u32 palette = *(u32 *)(middle + 0xC); register u32 offset asm("r2"); offset = 0x1C0; asm("" : "+r"(offset)); palette += offset; sub_08000AF0(0x15, palette, 1); } + break; + case 2: + sub_08065230(frameStorage83AE8 + 0x68, 0xB9, 0x88, 0, 0); + { u32 palette = *(u32 *)(middle + 0xC); u32 offset; offset = 0x1C0; palette += offset; sub_08000AF0(0x15, palette, 1); } + break; + case 0: + { + u8 *right; + { u32 palette = *(u32 *)(stack + 0x10); register u32 offset asm("r2"); offset = 0x1C0; asm("" : "+r"(offset)); palette += offset; sub_08000AF0(0x14, palette, 1); } + { u32 palette = *(u32 *)(middle + 0xC); u32 offset; offset = 0x1C0; asm("" : "+r"(offset)); palette += offset; sub_08000AF0(0x15, palette, 1); } + right = stack + 0x6C; + + { u32 palette = *(u32 *)(right + 0xC); register u32 offset asm("r2"); offset = 0x1C0; asm("" : "+r"(offset)); palette += offset; sub_08000AF0(0x1E, palette, 1); } + sub_08065230(right, 0xF0, 0x88, 0, 0); + sub_08065230(middle, 0x82, 0x88, 0, 0); + sub_08065230(frameStorage83AE8, 0xB9, 0x88, 0, 0); + } + break; + } + sub_0801A3D0(drawBuffer, (u16)(0xF - ((u32)sub_0801A638(*(u8 **)(stack + 0xCC)) >> 1)), 0x12); + sub_080003F0(); } - { register struct Record8441C *last asm("r5") = third; - result->value = last->value; } - goto finalize8441C; - } -setValue8441C: - result->value = tableValue; + } while ((keys83AE8 & 1) == 0); } - -finalize8441C: + } + { + register u32 zero asm("r0") = 0; + + *(u32 *)(stack + 0xC4) = zero; + unaff_r9 = zero; + unaff_r10 = zero; + } + sub_0805865C(0xF); + switch (uVar1) { + case 1: { - u32 *stateAddress; - u32 *weight; - struct Record8441C *input; - stateAddress = ({ register u32 *p asm("r6") = (u32 *)&gUnk_030034E0; asm("" : "+r"(p)); p; }); - weight = *(u32 *volatile *)(stack + 0x78); - input = *(struct Record8441C *volatile *)(stack + 0x5C); + u8 *panel = stack + 0x38; + s32 amount; + do { - u32 normalized; - switch ((s32)input->type) { - case 2: case 3: case 4: case 5: goto weightByte8441C; - case 9: break; - default: goto weightZero8441C; - } - switch (((struct Record8441C *)stack)->subtype) { - case 0: - normalized = input->value; - *weight = normalized; - normalized /= (u32)20; - - goto weightStore8441C; - case 1: - normalized = input->value; - *weight = normalized; - normalized = (normalized << 3) / 100; + s32 zero; + if (sub_0800CDF8() != 0) goto LAB_080841de; + zero = sub_080021A8(); + + if (zero != 0) goto LAB_080841de; + { + u32 raw = unaff_r9; + register s32 value asm("r0"); + s32 delta; - goto weightStore8441C; - case 2: - normalized = input->value; - *weight = normalized; - normalized /= (u32)10; + value = raw << 16; + value >>= 16; - goto weightStore8441C; - default: - normalized = input->value; - *weight = normalized; - normalized /= (u32)100; - asm("" : "+r"(normalized) : "i"(100)); - goto weightStore8441C; + delta = value - 0x77; + delta >>= 1; + + value = (u16)(value - delta); + + unaff_r9 = value; } -weightByte8441C: - normalized = input->byte6; - goto weightStore8441C; -weightZero8441C: - normalized = 0; -weightStore8441C: - *weight = normalized; - asm("" : "+r"(weight)); - weight++; - input++; - } while (weight <= *(u32 *volatile *)(stack + 0x78) + 2); + + { + u32 palette = *(u32 *)(panel + 0xC); + register u32 paletteOffset asm("r2"); + + paletteOffset = 0x1C0; + asm("" : "+r"(paletteOffset)); + sub_08000AF0(0x15, palette + paletteOffset, 1); + } + { + register u32 raw asm("r0") = unaff_r9; + + amount = raw << 16; + + amount >>= 16; + } + sub_08065230(panel, amount + 0xB9, 0x88, 0, zero); + sub_080003F0(); + } while (amount != 0x77); + } + break; + case 2: + { + u8 *panel = stack + 0x6C; + s32 amount; + + do { + s32 zero; + if (sub_0800CDF8() != 0) goto LAB_080841de; + zero = sub_080021A8(); + + if (zero != 0) goto LAB_080841de; + { + register u32 raw asm("r1") = unaff_r10; + register s32 value asm("r0"); + s32 delta; + + value = raw << 16; + value >>= 16; + + delta = value - 0x77; + delta >>= 1; + + value = (u16)(value - delta); + + unaff_r10 = value; + } + + { + u32 palette = *(u32 *)(panel + 0xC); + register u32 paletteOffset asm("r2"); + + paletteOffset = 0x1C0; + asm("" : "+r"(paletteOffset)); + sub_08000AF0(0x15, palette + paletteOffset, 1); + } + { + register u32 raw asm("r0") = unaff_r10; + + amount = raw << 16; + + amount >>= 16; + } + sub_08065230(panel, amount + 0xB9, 0x88, 0, zero); + sub_080003F0(); + } while (amount != 0x77); + } + break; + case 0: + for (;;) { + register s32 zero asm("r8"); + s32 shiftedCount; + s32 firstCount; + s32 secondCount; + s32 thirdCount; + u8 *middle; + u8 *right; + if (sub_0800CDF8() != 0) goto LAB_080841de; { - register u32 factor asm("r6") = *(u32 *)(*(volatile u32 *)(stack + 0x5C) + 0x34); - u32 score; - u32 sum; - u32 *values; - u32 multiplier; - u32 *global; + s32 status = sub_080021A8(); + zero = status; - factor = factor / 10000 + 1; + if (status != 0) goto LAB_080841de; + } + { + register u32 raw asm("r1") = *(u32 *)(stack + 0xC4); + s32 delta; - sum = *(u32 *)(stack + 0x40); + shiftedCount = raw << 16; + shiftedCount >>= 16; - values = *(u32 *volatile *)(stack + 0x78); + delta = shiftedCount - 0x77; + delta >>= 1; - sum += values[1]; - sum += values[2]; - sum += factor; - global = stateAddress; + shiftedCount -= delta; - multiplier = *(u32 *)(*global + 0x6C); - asm("" : : "r"(values)); - sum *= multiplier; - score = (sum >> 18) + 3; - if (score > 19) score = 20; + shiftedCount <<= 16; + + } { - u32 random = sub_080008C8(); - const u32 *weights; - u32 range; - register u32 roll asm("r6"); - register u32 index asm("r4"); - u32 value; - const u32 *base; + u32 raw = unaff_r9; + register s32 value asm("r0"); + s32 delta; - weights = ({ const u32 *p = table8441C_084ECB30; p; }); - range = score << 2; - range += (u32)weights; - range = *(u32 *)range + 1; - roll = random % range; - index = 0; + value = raw << 16; + value >>= 16; - if (index >= score) goto afterWeight8441C; - if (index > roll) goto scanWeight8441C; - base = weights; - value = *base; - goto compareWeight8441C; -scanWeight8441C: - base = table8441C_084ECB30; - value = *(u32 *)((index << 2) + (u32)base); - index++; - if (index >= score) goto afterWeight8441C; - if (value > roll) goto scanWeight8441C; - value = *(u32 *)((index << 2) + (u32)base); -compareWeight8441C: - if (roll >= value) goto scanWeight8441C; - result->byte6 = index; -afterWeight8441C: - { register u32 *metadata asm("r2") = *(u32 *volatile *)(stack + 0x5C); - roll = metadata[13]; } - roll += (u32)sub_080008C8() % 200000; - index = 0; + delta = value - 0xAE; + delta >>= 1; - if (index > roll) goto scanBonus8441C; - value = table8441C_084ECB84[0]; - if (roll < value) goto afterBonus8441C; -scanBonus8441C: - base = table8441C_084ECB84; - value = *(u32 *)((index << 2) + (u32)base); - index++; - if (index > 4) goto afterBonus8441C; - if (value > roll) goto scanBonus8441C; - value = *(u32 *)((index << 2) + (u32)base); - if (roll >= value) goto scanBonus8441C; - result->byte6 += index; -afterBonus8441C: - ; + value = (u16)(value - delta); + + unaff_r9 = value; + } + { + register u32 raw asm("r1") = unaff_r10; + register s32 value asm("r0"); + s32 delta; + asm("" : "+r"(raw)); + value = raw << 16; + value >>= 16; + + delta = value - 0x40; + delta >>= 1; + + value = (u16)(value - delta); + + unaff_r10 = value; } + *(u32 *)(stack + 0xC4) = (u32)shiftedCount >> 16; + shiftedCount >>= 16; + { + register s32 delta asm("r0") = shiftedCount - 0x77; + if (delta < 0) delta = -delta; + if (delta == 1) *(u32 *)(stack + 0xC4) = ({ register u32 value asm("r1") = 0x77; value; }); } - } - if (result->type == 2) { - *(u32 *)(stack + 0x64) = sub_08007290(result->subtype | 0xB0000); - if (*(u8 *)(*(u32 *)(stack + 0x64) + 0x9B) == 9) result->byte6 = 0; - } - if (result->byte6 > 19) result->byte6 = 20; - switch (result->type) { - case 2: - randomIndex = 0; - if (*(u16 *)(*(u32 *)(stack + 0x64) + 0xB0) != 0) goto clearByIndex8441C; -scanProperty2: - randomIndex++; - if (randomIndex > 2) goto copyOutput8441C; - if (({ register u32 offset asm("r0") = randomIndex << 2; register u8 *properties asm("r3"); properties = *(u8 **)(stack + 0x64); *(u16 *)(properties + offset + 0xB0); }) == 0) goto scanProperty2; - goto clearByZero8441C; - case 3: - randomIndex = 0; - if (*(u16 *)(*(u32 *)(stack + 0x68) + 0xA4) != 0) goto clearByIndex8441C; -scanProperty3: - randomIndex++; - if (randomIndex > 2) goto copyOutput8441C; - if (({ register u32 offset asm("r0") = randomIndex << 2; register u8 *properties asm("r4"); properties = *(u8 **)(stack + 0x68); *(u16 *)(properties + offset + 0xA4); }) == 0) goto scanProperty3; - goto clearByZero8441C; - case 4: - randomIndex = 0; - if (*(u16 *)(*(u32 *)(stack + 0x6C) + 0xA4) != 0) goto clearByIndex8441C; -scanProperty4: - randomIndex++; - if (randomIndex > 2) goto copyOutput8441C; - if (({ register u32 offset asm("r0") = randomIndex << 2; register u8 *properties asm("r6"); properties = *(u8 **)(stack + 0x6C); *(u16 *)(properties + offset + 0xA4); }) == 0) goto scanProperty4; - goto clearByZero8441C; - case 5: - randomIndex = 0; - if (*(u16 *)(*(u32 *)(stack + 0x70) + 0xA4) == 0) goto scanProperty5; -clearByIndex8441C: - result->value = randomIndex; - goto copyOutput8441C; - -scanProperty5: - randomIndex++; - if (randomIndex > 2) goto copyOutput8441C; - if (({ register u32 offset asm("r0") = randomIndex << 2; register u8 *properties asm("r1"); properties = *(u8 **)(stack + 0x70); *(u16 *)(properties + offset + 0xA4); }) == 0) goto scanProperty5; - goto clearByZero8441C; -clearByZero8441C: - result->value = 0; - goto copyOutput8441C; - - default: goto copyOutput8441C; - } -copyOutput8441C: - { - register struct Record8441C *output asm("r1") = *(struct Record8441C **)(stack + 0x60); - struct Record8441C *source; - u32 hold5, hold6 asm("r6"); - asm("" : "+r"(output)); - source = result; - asm("" : "+r"(source), "=r"(hold5), "=r"(hold6)); - *output = *source; - - } - { - register u32 firstPrice asm("r4") = sub_0805AE94(*(void **)(stack + 0x5C)); - u32 secondPrice; - u32 thirdPrice; - u32 outputPrice; - u32 *globalAddress; - u8 *state; - - secondPrice = sub_0805AE94(*(void **)(stack + 0x7C)); - asm("" : "+r"(secondPrice)); - thirdPrice = sub_0805AE94(*(void **)(stack + 0x74)); - asm("" : "+r"(thirdPrice)); - outputPrice = sub_0805AE94(*(void **)(stack + 0x60)); - - { register u32 *p asm("r0") = (u32 *)&gUnk_030034E0; + { + register u32 raw asm("r2") = unaff_r9; + register s32 delta asm("r0"); + asm("" : "+r"(raw)); + delta = raw << 16; + delta >>= 16; - globalAddress = p; + delta -= 0xAE; + if (delta < 0) delta = -delta; + if (delta == 1) unaff_r9 = ({ u32 value = 0xAE; value; }); + } + { + register u32 raw asm("r1") = unaff_r10; + register s32 delta asm("r0"); - state = (u8 *)*p; } - firstPrice += secondPrice; - firstPrice += thirdPrice; - { register u32 *input asm("r1") = *(u32 *volatile *)(stack + 0x5C); + delta = raw << 16; + delta >>= 16; - firstPrice += input[13]; } - firstPrice = *(u32 *)(state + 0x6C) + firstPrice / 10; - firstPrice -= outputPrice / 10; - *(u32 *)(state + 0x6C) = firstPrice; - if ((s32)firstPrice < 0) *(u32 *)(state + 0x6C) = 0; + delta -= 0x40; + if (delta < 0) delta = -delta; + if (delta == 1) unaff_r10 = ({ register u32 value asm("r2") = 0x40; asm("" : "+r"(value)); value; }); + } { - register u32 *address asm("r2") = globalAddress; - u8 *current; - s32 value; - register u32 maximum asm("r2"); - asm("" : "+r"(address)); - current = (u8 *)*address; - value = *(s32 *)(current + 0x6C); - maximum = 0xFFFF; + register u32 paletteOffset asm("r4"); + u32 palette = *(u32 *)(stack + 0x10); + + paletteOffset = 0x1C0; + + sub_08000AF0(0x14, palette + paletteOffset, 1); + middle = stack + 0x38; + + sub_08000AF0(0x15, *(u32 *)(middle + 0xC) + paletteOffset, 1); + right = stack + 0x6C; + + sub_08000AF0(0x1E, *(u32 *)(right + 0xC) + paletteOffset, 1); + } + { + register u32 raw asm("r1") = unaff_r10; + register s32 scaled asm("r0"); + + scaled = raw << 16; + + thirdCount = scaled >> 16; + } + { + s32 x = thirdCount + 0xF0; + register u32 stackZero asm("r2"); - if (value > (s32)maximum) *(u32 *)(current + 0x6C) = maximum; + stackZero = zero; + asm("" : "+r"(stackZero)); + sub_08065230(right, x, 0x88, 0, stackZero); + } + { + register u32 raw asm("r1") = unaff_r9; + register s32 scaled asm("r0"); + + scaled = raw << 16; + + secondCount = scaled >> 16; + } + { + s32 x = secondCount + 0x82; + register u32 stackZero asm("r2"); + + stackZero = zero; + asm("" : "+r"(stackZero)); + sub_08065230(middle, x, 0x88, 0, stackZero); + } + { + register u32 raw asm("r0") = *(u32 *)(stack + 0xC4); + + firstCount = raw << 16; + firstCount >>= 16; + + } + { + s32 x = firstCount + 0xB9; + register u32 stackZero asm("r2"); + + stackZero = zero; + asm("" : "+r"(stackZero)); + sub_08065230(frameStorage83AE8, x, 0x88, 0, stackZero); } + sub_080003F0(); + if (firstCount == 0x77 && secondCount == 0xAE && thirdCount == 0x40) break; } + break; + } + sub_080003F0(); + sub_080003F0(); +LAB_080841de: + *(u32 *)(*(int *)((u32)&gUnk_03006440) + 0x28) = *(u32 *)(*(int *)((u32)&gUnk_03006440) + 0x28) & 0xfffffffd; + return; +#endif } - -/* [StartCharacterStatAndSkillMenuTask] No arguments or meaningful return. Retries exact allocation - * of0x624=1572 bytes for shared manager0x03006440, yielding after failures, initializes first word0. Then - * retries1024-byte task stack on fixed task0x03006450, sets top+1020, priority100, finalizer0x08085484 and - * callback0x0807A5D4, scheduler argument0. No active-task or existing-manager protection; starts request and - * does not wait for menu closure. Complete pinned matching source body and complete original configured range - * inspected, including long-range continuations. Original range equals copied verified-main ELF; no local - * build or runtime test. */ -void sub_08084EAC(void) +/* [ClassifyThreeItemSubtypePattern] r0 points to three16-byte item records. Requires unsigned kind halfwords + * at+0/+16/+32 all9 or returns0. Reads subtype halfwords+2/+18/+34 and returns a pure ordered-pattern + * code:000=>1,222=>2,111=>3, + * all-distinct0..2=>4;020/101/010/121/212/202=>5..10;002/110/001/112/221/220/200/011/100/211/122/022=>11..22;333=>23,444=>24. + * Everything else returns0, including mixed3/4. No side effects, RNG or validation of pointed storage. Does + * not guess material names for kind9 or subtype values. Complete original configured body audited against ROM; + * copied verified-main ELF static equality, no local build or runtime test. */ +u32 sub_08084200(const u8 *arg0) { - while ((gUnk_03006440 = sub_08001494(0x624)) == 0) - sub_080003F0(); - *(u32 *)gUnk_03006440 = 0; - while ((task84eac[8] = sub_08001494(0x400)) == 0) - sub_080003F0(); - task84eac[4] = task84eac[8] + 0x3FC; - task84eac[2] = 0x64; - task84eac[9] = (u32)sub_08085484; - task84eac[3] = (u32)sub_0807A5D4; - sub_08000274((M2C_UNK *)task84eac, 0); + u16 b; + u16 c; + + if (*(const u16 *)(arg0 + 0x00) != 9 || + *(const u16 *)(arg0 + 0x10) != 9 || + *(const u16 *)(arg0 + 0x20) != 9) + return 0; + + + if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 0 && *(const u16 *)(arg0 + 0x22) == 0) return 1; + if (*(const u16 *)(arg0 + 0x02) == 2 && *(const u16 *)(arg0 + 0x12) == 2 && *(const u16 *)(arg0 + 0x22) == 2) return 2; + if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 1) return 3; + if ((u32)*(const u16 *)(arg0 + 0x02) <= 2 && (u32)(b = *(const u16 *)(arg0 + 0x12)) <= 2 && (u32)(c = *(const u16 *)(arg0 + 0x22)) <= 2 && *(const u16 *)(arg0 + 0x02) != b && *(const u16 *)(arg0 + 0x02) != c && b != c) return 4; + if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 2 && *(const u16 *)(arg0 + 0x22) == 0) return 5; + if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 0 && *(const u16 *)(arg0 + 0x22) == 1) return 6; + if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 0) return 7; + if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 2 && *(const u16 *)(arg0 + 0x22) == 1) return 8; + { + /* Keep the original halfword extensions across the shared tests. */ + u32 d; + register u32 raw asm("r0"); + if (*(const u16 *)(arg0 + 0x02) == 2 && + ({ + raw = *(const u16 *)(arg0 + 0x12); + asm("" : "+r"(raw)); + d = raw; + + d; + }) == 1 && *(const u16 *)(arg0 + 0x22) == 2) return 9; + if (*(const u16 *)(arg0 + 0x02) == 2 && + ({ + raw = d << 16; + + raw; + }) == 0 && *(const u16 *)(arg0 + 0x22) == 2) return 10; + } + if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 0 && *(const u16 *)(arg0 + 0x22) == 2) return 11; + if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 0) return 12; + if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 0 && *(const u16 *)(arg0 + 0x22) == 1) return 13; + if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 2) return 14; + { + /* Keep the original halfword extensions across the shared tests. */ + u32 d; + register u32 raw asm("r0"); + if (*(const u16 *)(arg0 + 0x02) == 2 && + ({ + raw = *(const u16 *)(arg0 + 0x12); + asm("" : "+r"(raw)); + d = raw; + + d; + }) == 2 && *(const u16 *)(arg0 + 0x22) == 1) return 15; + if (*(const u16 *)(arg0 + 0x02) == 2 && + ({ + raw = (u16)d; + asm("" : "+r"(raw), "+r"(d)); + raw; + }) == 2 && *(const u16 *)(arg0 + 0x22) == 0) return 16; + if (*(const u16 *)(arg0 + 0x02) == 2 && + ({ + raw = d << 16; + + raw; + }) == 0 && *(const u16 *)(arg0 + 0x22) == 0) return 17; + } + if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 1) return 18; + if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 0 && *(const u16 *)(arg0 + 0x22) == 0) return 19; + if (*(const u16 *)(arg0 + 0x02) == 2 && *(const u16 *)(arg0 + 0x12) == 1 && *(const u16 *)(arg0 + 0x22) == 1) return 20; + if (*(const u16 *)(arg0 + 0x02) == 1 && *(const u16 *)(arg0 + 0x12) == 2 && *(const u16 *)(arg0 + 0x22) == 2) return 21; + if (*(const u16 *)(arg0 + 0x02) == 0 && *(const u16 *)(arg0 + 0x12) == 2 && *(const u16 *)(arg0 + 0x22) == 2) return 22; + if (*(const u16 *)(arg0 + 0x02) == 3 && *(const u16 *)(arg0 + 0x12) == 3 && *(const u16 *)(arg0 + 0x22) == 3) return 23; + if (*(const u16 *)(arg0 + 0x02) == 4 && *(const u16 *)(arg0 + 0x12) == 4 && *(const u16 *)(arg0 + 0x22) == 4) return 24; + return 0; } -/* [StartInventoryMenuTask] Retries allocation of a 0x624-byte item-menu manager through global 03006440, - * clears only its first word, then retries a 0x900-byte stack allocation. Initializes the existing - * task-control record with stack top allocation +0x8FC, flags/state word +8 equal 0x64, finalizer 854A0 and - * callback 7B7B4, then registers it through 00274 with argument zero. Failed allocations wait on scheduler - * signal 1. It does not initialize every manager field, impose a retry bound or establish priority from the - * task flag word. */ -void sub_08084F24(void) +/* [SynthesizeRandomItemFromThreeInputs] r0 points to at least three16-byte item records PLUS metadata word + * at+0x34; r1 points to16-byte output. Randomly permutes three inputs via rejection sampling. Classifies + * original ordered triple through0x08084200; nonzero class and RNG low16<=saved-state word+0x6C can select + * class/tier recipe tables, tier from summed unsigned values with boundaries100/300/500. Fallback uses first + * randomized equipment record or random nonempty saved stock entries for kind9; empty stock can loop + * indefinitely. Further randomized property/value inheritance uses other two records and compatibility flags, + * with an inherited r9 path for unsupported kinds. */ +void sub_0808441C(u16 *param_1, u32 *param_2) { - while ((gUnk_03006440 = sub_08001494(0x624)) == 0) - sub_080003F0(); - *(u32 *)gUnk_03006440 = 0; - while ((task84f24[8] = sub_08001494(0x900)) == 0) - sub_080003F0(); - task84f24[4] = task84f24[8] + 0x8FC; - task84f24[2] = 0x64; - task84f24[9] = (u32)sub_080854A0; - task84f24[3] = (u32)sub_0807B7B4; - sub_08000274((M2C_UNK *)task84f24, 0); -} -/* [StartItemCollectionInteractionMenuTask] Full-word r0 interaction variant forwarded unchanged. - * Retries1572-byte manager allocation into0x03006440 and zeros its first word; retries2560-byte stack on fixed - * task0x03006450. Sets stack top+2556, priority100, callback0x08082BB0 and finalizer0x08085518, then starts - * task with variant argument. No existing-manager/task activity guard and no wait for menu completion; - * allocation failures yield. Complete pinned matching source body and original configured range preserved for - * independent static audit; original equals copied verified-main ELF, no local build or runtime test. */ -void sub_08084F9C(u32 arg) -{ - while ((gUnk_03006440 = sub_08001494(0x624)) == 0) - sub_080003F0(); - *(u32 *)gUnk_03006440 = 0; - while ((task84f9c[8] = sub_08001494(0xA00)) == 0) - sub_080003F0(); - task84f9c[4] = task84f9c[8] + 0x9FC; - task84f9c[2] = 0x64; - task84f9c[9] = (u32)sub_08085518; - task84f9c[3] = (u32)sub_08082BB0; - sub_08000274((M2C_UNK *)task84f9c, arg); -} -/* [DrawSkillProgressTileRun] r0 is an unbounded row index, r1 an unsigned count clamped to seven, and r2 a - * tile variant. Writes count halfwords of ((u16)(variant+0x16B)|0xE000) at text-map +0x2C+(index+5)*64; queues - * row index+5 only when count is nonzero. Does not clear remaining tiles. Original caller 0x0807B53E supplies - * skill level+1 and variant 3; 0x0807B54E supplies progress and variant 0. No row validation. Complete - * original configured body and literal use audited against EU ROM; copied verified-main ELF equality is static - * corroboration, not a new build or runtime test. */ -void sub_08085014(u32 index, u32 count, u32 value) -{ - u32 i; - u16 encoded; - u16 *dst; - if (count > 7) count = 7; - encoded = value + 0x16B; - for (i=0; itype = b; + init->subtype = b; + init->byte6 = zb; + init->byte7 = zb; + init->value = b; + a = 0; + out = init; + } + rec1 = &rec[1]; + rec2 = &rec[2]; + do { u8 *bytes = (u8 *)&rec[3].value; u32 zero = 0; bytes[a] = zero; a++; } while (a <= 0xB); + a = (u32)sub_080008C8() % 3; + rec[0] = ((struct Record8441C *)param_1)[a]; + do { b = (u32)sub_080008C8() % 3; asm("" : : "r"(a), "r"(a), "r"(a), "r"(a), "r"(a), "r"(a), "r"(a), "r"(a), "r"(a), "r"(a)); asm("" : : "r"(b), "r"(b), "r"(b), "r"(b), "r"(b), "r"(b), "r"(b), "r"(b)); asm("" : : "r"(b), "r"(b), "r"(b), "r"(b), "r"(b), "r"(b), "r"(b), "r"(b)); asm("" : : "r"(b), "r"(b), "r"(b), "r"(b), "r"(b), "r"(b), "r"(b), "r"(b)); } while (a == b); + (*rec1) = ((struct Record8441C *)param_1)[b]; + do { n = (u32)sub_080008C8() % 3; } while (a == n || b == n); + (*rec2) = ((struct Record8441C *)param_1)[n]; + b = sub_08084200((u8 *)param_1); + if (b == 0) goto ordinary; + if (((u32)sub_080008C8() & 0xFFFF) > *(u32 *)((u32)gUnk_030034E0 + SAVE_FIELD(0x6C))) goto ordinary; + n = ((struct Record8441C *)param_1)[0].value + ((struct Record8441C *)param_1)[1].value + ((struct Record8441C *)param_1)[2].value; + if (n <= 99) goto low; + if (n - 100 <= 199) n = 0; + else if (n - 300 <= 199) n = 1; + else n = 2; + switch (b) { + case 1: + a = (u32)sub_080008C8() % 14; + out->type = table8441C_084EC1E0[n][a].type; + out->subtype = table8441C_084EC1E0[n][a].subtype; + goto finalize; + case 2: + a = (u32)sub_080008C8() % 14; + out->type = table8441C_084EC288[n][a].type; + out->subtype = table8441C_084EC288[n][a].subtype; + goto finalize; + case 3: + a = (u32)sub_080008C8() % 14; + out->type = table8441C_084EC330[n][a].type; + out->subtype = table8441C_084EC330[n][a].subtype; + goto finalize; + case 4: + a = (u32)sub_080008C8() % 14; + out->type = table8441C_084EC3D8[n][a].type; + out->subtype = table8441C_084EC3D8[n][a].subtype; + goto finalize; + case 5: + a = (u32)sub_080008C8() & 7; + out->type = table8441C_084EC480[n][a].type; + out->subtype = table8441C_084EC480[n][a].subtype; + goto finalize; + case 6: + a = (u32)sub_080008C8() & 7; + out->type = table8441C_084EC4E0[n][a].type; + out->subtype = table8441C_084EC4E0[n][a].subtype; + goto finalize; + case 7: + a = (u32)sub_080008C8() & 7; + out->type = table8441C_084EC540[n][a].type; + out->subtype = table8441C_084EC540[n][a].subtype; + goto finalize; + case 8: + a = (u32)sub_080008C8() & 7; + out->type = table8441C_084EC5A0[n][a].type; + out->subtype = table8441C_084EC5A0[n][a].subtype; + goto finalize; + case 9: + a = (u32)sub_080008C8() & 7; + out->type = table8441C_084EC600[n][a].type; + out->subtype = table8441C_084EC600[n][a].subtype; + goto finalize; + case 10: + a = (u32)sub_080008C8() & 7; + out->type = table8441C_084EC660[n][a].type; + out->subtype = table8441C_084EC660[n][a].subtype; + goto finalize; + case 11: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC6C0[n * 3 + a].type; + out->subtype = table8441C_084EC6C0[n * 3 + a].subtype; + goto finalize; + case 12: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC6E4[n * 3 + a].type; + out->subtype = table8441C_084EC6E4[n * 3 + a].subtype; + goto finalize; + case 13: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC708[n * 3 + a].type; + out->subtype = table8441C_084EC708[n * 3 + a].subtype; + goto finalize; + case 14: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC72C[n * 3 + a].type; + out->subtype = table8441C_084EC72C[n * 3 + a].subtype; + goto finalize; + case 15: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC750[n * 3 + a].type; + out->subtype = table8441C_084EC750[n * 3 + a].subtype; + goto finalize; + case 16: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC774[n * 3 + a].type; + out->subtype = table8441C_084EC774[n * 3 + a].subtype; + goto finalize; + case 17: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC798[n * 3 + a].type; + out->subtype = table8441C_084EC798[n * 3 + a].subtype; + goto finalize; + case 18: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC7BC[n * 3 + a].type; + out->subtype = table8441C_084EC7BC[n * 3 + a].subtype; + goto finalize; + case 19: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC7E0[n * 3 + a].type; + out->subtype = table8441C_084EC7E0[n * 3 + a].subtype; + goto finalize; + case 20: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC804[n * 3 + a].type; + out->subtype = table8441C_084EC804[n * 3 + a].subtype; + goto finalize; + case 21: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC828[n * 3 + a].type; + out->subtype = table8441C_084EC828[n * 3 + a].subtype; + goto finalize; + case 22: + a = (u32)sub_080008C8() % 3; + out->type = table8441C_084EC84C[n * 3 + a].type; + out->subtype = table8441C_084EC84C[n * 3 + a].subtype; + goto finalize; + case 23: + a = (u32)sub_080008C8() & 3; + out->type = table8441C_084EC870[n + 1][a].type; + out->subtype = table8441C_084EC870[n + 1][a].subtype; + goto finalize; + case 24: + a = (u32)sub_080008C8() & 3; + out->type = table8441C_084EC8B0[n + 1][a].type; + out->subtype = table8441C_084EC8B0[n + 1][a].subtype; + goto finalize; + } + goto finalize; +low: + switch (b) { + case 23: + a = (u32)sub_080008C8() & 3; + out->type = table8441C_084EC870[0][a].type; + out->subtype = table8441C_084EC870[0][a].subtype; + goto finalize; + case 24: + a = (u32)sub_080008C8() & 3; + out->type = table8441C_084EC8B0[0][a].type; + out->subtype = table8441C_084EC8B0[0][a].subtype; + goto finalize; } -} -extern u32 digits850C0[] asm("gUnk_084EBD5C"); -/* [ExpandEncodedTextUnsignedNumberToken] r0 source, low 16 bits of r1 number, r2 destination. Skips two source - * bytes; copies byte stream until 0xFD, replacing every 0xF7 with decimal digits encoded 0x41+digit. Reads six - * 32-bit divisors 100000,10000,1000,100,10,1 at 0x084EBD5C and suppresses leading zero digits but retains - * final zero. Output length wraps u16; appends 0xFD and returns dst+length-1, including dst-1 for empty text. - * No destination-capacity check or bounded search for a missing source terminator; no claim of ASCII output. - * Complete original configured body and literal use audited against EU ROM; copied verified-main ELF equality - * is static corroboration, not a new build or runtime test. */ -u8 *sub_080850C0(u8 *src, u16 value, u8 *dst) -{ - u16 n; - u8 c; - u8 *next; - src += 2; - n = 0; - while ((c = *src) != 0xFD) { - if (c == 0xF7) { - s32 number = value; - u32 *divisor = digits850C0; - u8 *out = dst + n; - u32 started = 0; - u16 i = 0; - next = src + 1; +ordinary: + switch (rec[0].type) { + case 9: + switch (rec[0].subtype) { + case 3: + a = (u32)sub_080008C8() & 3; + *(struct Triple8441C *)tmp = table8441C_084EC8F0[a]; + copy8441C(out, tmp, 16); + goto finalize; + case 4: + a = (u32)sub_080008C8() & 3; + *(struct Triple8441C *)tmp = table8441C_084EC920[a]; + copy8441C(out, tmp, 16); + goto third; + default: + if ((u32)sub_080008C8() & 1) { do { - u32 ch = sub_08000498(&number, *divisor) + 0x41; - *out = ch; - if (started != 0 || (u8)ch != 0x41 || i == 5) { - out++; - started = 1; - n++; - } - i++; - divisor++; - } while (i <= 5); - + a = (u32)sub_080008C8() % 12; + *out = ((struct SA *)gUnk_030034E0)->r[a]; + } while (out->type == 0); + recA = (u8 *)sub_08007290(out->subtype | 0xB0000); + if (*(u16 *)(recA + 0x194) != 0) goto finalize; + if (*(u16 *)((u8 *)out + 6) != 0) goto finalize; + if (*(u16 *)(recA + 0x188) != 0) goto finalize; + goto second; } else { - dst[n++] = c; - next = src + 1; + struct Record8441C *q = out; + do { + a = (u32)sub_080008C8() % 12; + *q = ((struct SB *)gUnk_030034E0)->r[a]; + } while (q->type == 0); + if (out->type == 3) { + recB = (u8 *)sub_08007290(out->subtype | 0xC0000); + if ((*(u32 *)((u8 *)out + 4) & 0xFFFFFF) != 0) goto finalize; + if (*(u16 *)(recB + 0x180) != 0) goto finalize; + } else if (out->type == 4) { + recC = (u8 *)sub_08007290(out->subtype | 0xD0000); + if ((*(u32 *)((u8 *)out + 4) & 0xFFFFFF) != 0) goto finalize; + if (*(u16 *)(recC + 0x180) != 0) goto finalize; + } else { + recD = (u8 *)sub_08007290(out->subtype | 0xE0000); + if ((*(u32 *)((u8 *)out + 4) & 0xFFFFFF) != 0) goto finalize; + if (*(u16 *)(recC + 0x180) != 0) goto finalize; + } } - src = next; - } - dst[n] = 0xFD; - return dst + (n - 1); -} -/* [AllocateSkillMenuEffectTaskPool] No input or meaningful return. Repeatedly allocates 200 bytes, storing - * pointer at item-menu manager +0x620 and yielding after failures. Initializes only word +8 in five 40-byte - * task controls to zero; other bytes are not initialized. Caller 0x0807A832 performs menu setup; 0x08085218 - * consumes this exact pool for skill-increase effects. Complete original configured body and literal use - * audited against EU ROM; copied verified-main ELF equality is static corroboration, not a new build or - * runtime test. */ -void sub_0808516C(void) -{ - u32 i; - while ((*(u32 *)(gUnk_03006440 + 0x620) = sub_08001494(0xC8)) == 0) - sub_080003F0(); - for (i = 0; i <= 4; i++) - *(u32 *)(*(u32 *)(gUnk_03006440 + 0x620) + i * 0x28 + 8) = 0; -} -/* [WaitForSkillMenuEffectsAndFreeTaskPool] Captures the initial pool pointer at manager+0x620 and sequentially - * polls activity for its five 40-byte controls, yielding while each is active. After waiting it reloads the - * manager through global03006440, frees the current +0x620 field, reloads the manager again and stores the - * final zero activity-query result there. The captured waited-on pool and later freed current pointer are not - * assumed identical across yields. Does not request cancellation, free per-task stacks directly, or validate - * manager/pool. Original menu task calls at 0x0807B740 on teardown. */ -void sub_080851B8(void) -{ - u8 *entries = *(u8 **)(gUnk_03006440 + 0x620); - u32 i; - u32 result; - for (i = 0; i <= 4; i++) { - while ((result = sub_08000470((u32)(entries + i * 0x28))) != 0) - sub_080003F0(); - } - sub_08001538(*(s32 *)(gUnk_03006440 + 0x620)); - *(u32 *)(gUnk_03006440 + 0x620) = result; -} -/* [StartSkillIncreaseIndicatorTask] r0/r1 are full-word x/y forwarded as scheduler arguments. Scans five pool - * controls, skipping active entries and any nonzero word +8. First eligible entry gets word+8=60 before - * attempting a 1024-byte stack allocation. Allocation failure returns without restoring word+8; full pool also - * returns. Success installs callback 0x08085534, stack top allocation+1020 and null finalizer then starts - * task. Original caller 0x0807AE14 follows skill-level increment and point deduction, not arbitrary completion - * signalling. Complete original configured body and literal use audited against EU ROM; copied verified-main - * ELF equality is static corroboration, not a new build or runtime test. */ -void sub_08085218(u32 arg0, u32 arg1) -{ - u8 *entry = *(u8 **)(gUnk_03006440 + 0x620); - u32 i = 0; - u32 memory; - goto check; - do { -next: - i++; - entry += 0x28; -check: - if (i > 4) return; - if (sub_08000470((u32)entry) != 0 || *(u32 *)(entry + 8) != 0) - goto next; - *(u32 *)(entry + 8) = 0x3C; - memory = sub_08001494(0x400); - *(u32 *)(entry + 0x20) = memory; - } while (0); - if (memory == 0) return; - *(u32 *)(entry + 0xC) = (u32)sub_08085534; - *(u32 *)(entry + 0x10) = memory + 0x3FC; - *(u32 *)(entry + 0x24) = 0; - sub_08000274_(entry,arg0,arg1); -} -/* [VCountApplyBg0FourPixelVerticalOffset] Writes halfword 4 directly to BG0VOFS hardware register 04000012, - * sets the next VCount compare line to 159 and replaces the VCount callback with sibling 852AC. Does not - * modify BG0 scroll shadow, enable the VCount interrupt, preserve an arbitrary prior scroll value or stop the - * alternating callback chain. */ -void sub_0808528C(void) { - *(s16 *)0x04000012 = 4; - sub_08001108(0x9F); - sub_0800115C((s32) &sub_080852AC); -} -/* [VCountResetBg0VerticalOffset] Writes halfword zero directly to BG0VOFS hardware register 04000012, sets - * next VCount compare line to 136 and installs sibling 8528C. It resets this hardware offset rather than - * restoring an arbitrary saved value. The callback chain continues; this is not a function to disable the band - * or the VCount interrupt. */ -void sub_080852AC(void) -{ - *(u16 *)0x04000012 = 0; - sub_08001108(0x88); - sub_0800115C((s32)sub_0808528C); -} -/* [CopyItemMenuCollectionRecords] r0 source; manager pointer is read from 0x03006440. Copies complete 16-byte - * records as four words into manager+0x104: 75 records when manager word zero equals 4, otherwise 12. Returns - * void; no source-size, overlap or manager validation. Consumers include currency summation at 0x08085330 and - * item menu initialization caller 0x08083182/0x080831C8. Does not infer shop versus stash from mode alone. - * Complete original configured body and literal use audited against EU ROM; copied verified-main ELF equality - * is static corroboration, not a new build or runtime test. */ -void sub_080852CC(struct Entry852CC *src) -{ - u32 i; - if (collection852CC->kind != 4) { - for (i=0; i<=11; src++) { - collection852CC->entries[i] = *src; - i++; } - } else { - for (i=0; i<=0x4A; src++) { - collection852CC->entries[i] = *src; - i++; + goto third; + case 2: + *out = rec[0]; + break; + case 3: case 4: case 5: + *out = rec[0]; + goto third; + } +second: + if (((u32)sub_080008C8() & 0xFFFF) <= *(u32 *)((u32)gUnk_030034E0 + SAVE_FIELD(0x6C))) { + struct Record8441C *r1p = rec1; + asm("" : "+r"(r1p)); + switch (r1p->type) { + case 9: + switch (r1p->subtype) { + case 0: + a = (u32)sub_080008C8() % 3; + attr = 1; + if (a == 0) attr = 3; + break; + case 1: + a = (u32)sub_080008C8() & 1; + attr = 4; + if (a == 0) attr = 2; + break; + case 2: + a = (u32)sub_080008C8() % 3; + attr = 6; + if (a == 0) attr = 5; + break; + default: + attr = 0; + break; + } + break; + case 2: + attr = (*rec1).byte7; + break; + case 3: case 4: case 5: + attr = 0; + break; + } + switch (out->type) { + case 3: case 4: case 5: out->byte7 = 0; break; + default: out->byte7 = attr; break; } } -} -/* [SumItemMenuStashOrStockCurrency] In item-menu mode 4, sums word +4 for kind-10 entries among exactly 75 - * records at manager +0x104, stride 16. Otherwise returns 5D404, the stash sum at character/inventory base - * +0x2E0 through pointer global 030034E0. These are distinct from the menu manager through global 03006440. - * This helper never adds the bag total; the separate 8543C query adds bag currency only in mode 4. Original - * arithmetic returns the low 32-bit sum without saturation or capacity checks. */ -u32 sub_08085330(void) -{ - u32 total = 0; - u8 *base = (u8 *)gUnk_03006440; - if (*(u32 *)base == 4) { - u8 *entry; - u32 i; - i = 0; entry = base + 0x104; - for (; i <= 0x4A; i++) { - if (*(u16 *)entry == 0xA) - total += *(u32 *)(entry + 4); - entry += 0x10; +third: + { + u32 limit; + u32 r = (u32)sub_080008C8() & 0xFFFF; + limit = *(u32 *)((u32)gUnk_030034E0 + SAVE_FIELD(0x6C)); + b = 0; + if (r <= limit) b = 1; + } + { + register u32 off asm("r1"); + register u32 fl asm("r1"); + register u32 mk asm("r0"); + register u32 tv asm("r0"); + register u16 tvh asm("r0"); + register const u32 *table asm("r2"); + switch (out->type) { + case 2: + recA = (u8 *)sub_08007290(out->subtype | 0xB0000); + if (ITEM_KIND(recA) == 9) { + switch (rec2->type) { + case 9: + a = (u32)sub_080008C8() & 3; + if (b) { + table = table8441C_084ECA90[0]; + off = a * 4; + tv = rec2->subtype; + sharedTbl: + tv = tv * 16; + off += tv; + off += (u32)table; + tv = *(u32 *)off; + goto setv; + } + table = table8441C_084ECAE0[0]; + off = a * 4; + tv = rec2->subtype; + asm("" : : "i"(0)); + goto sharedTbl; + case 2: case 3: case 4: case 5: + { + u32 v = rec2->value; + if (v == 0) { out->value = v; goto finalize; } + q = (u8 *)sub_08007290((v - 1) | 0x130000); + v = (u16)(*(u16 *)(q + 0x184) & 4); + if (v == 0) { out->value = v; goto finalize; } + out->value = rec2->value; + goto finalize; + } + } + } else { + switch (rec2->type) { + case 9: + a = (u32)sub_080008C8() & 3; + if (b) { + table = table8441C_084EC950[0]; + off = a * 4; + tv = rec2->subtype; + goto sharedTbl; + } + table = table8441C_084EC9A0[0]; + off = a * 4; + tv = rec2->subtype; + goto sharedTbl; + case 2: case 3: case 4: case 5: + { + u32 v = rec2->value; + if (v == 0) { out->value = v; goto finalize; } + q = (u8 *)sub_08007290((v - 1) | 0x130000); + v = (u16)(*(u16 *)(q + 0x184) & 8); + if (v == 0) { out->value = v; goto finalize; } + out->value = rec2->value; + goto finalize; + } + } + } + goto finalize; + case 3: case 4: case 5: + switch (rec2->type) { + case 9: + a = (u32)sub_080008C8() & 3; + if (b) { + table = table8441C_084EC9F0[0]; + off = a * 4; + tv = rec2->subtype; + goto sharedTbl; + } + table = table8441C_084ECA40[0]; + off = a * 4; + tvh = rec2->subtype; + goto sharedTbl; + case 2: case 3: case 4: case 5: + { + register struct Record8441C *p2 asm("r4") = rec2; + u32 v; + { + u32 v0 = p2->value; + if (v0 == 0) { out->value = v0; goto finalize; } + q = (u8 *)sub_08007290(({ register u32 tag asm("r1") = 0x130000; v0 | tag; })); + } + if ((u16)(out->type - 3) <= 1) { + u32 v2 = (u16)(*(u16 *)(q + 0x184) & 2); + if (v2 == 0) { out->value = v2; goto finalize; } + out->value = p2->value; + goto finalize; + } + v = *(u16 *)(q + 0x184) & 1; + if (v == 0) { out->value = v; goto finalize; } + out->value = rec2->value; + goto finalize; + } } - } else { - total = sub_0805D404(); } - return total; -} -/* [AllocateItemMenuSubtaskControl] Retries a 0x28-byte allocation until nonnull, storing every attempt in the - * word at item-menu manager +0x620 through pointer global 03006440. Each failed attempt waits for scheduler - * signal 1 through 003F0. It allocates the child task-control record only: it does not clear the record, - * allocate its execution stack, select a callback or register the task. There is no bounded retry count or - * proved manager lifetime. */ -void sub_0808536C(void) -{ - while ((M2C_FIELD(gUnk_03006440, s32 *, 0x620) = sub_08001494(0x28)) == 0) - sub_080003F0(); -} -/* [WaitForItemMenuSubtaskAndFreeControl] Captures the task-control pointer at item-menu manager +0x620 and - * polls 00470 until it is absent from the scheduled-task list, yielding on scheduler signal 1 between nonzero - * results. Then reloads the global manager and frees its current +0x620 pointer through 01538; reloads the - * manager again and stores the zero query result at +0x620. The polled captured pointer and later freed - * current field are not assumed identical across yields. It does not explicitly free the execution-stack field - * or impose a timeout. */ -void sub_08085398(void) -{ - u32 value = *(u32 *)(gUnk_03006440 + 0x620); - u32 result; - while ((result = sub_08000470(value)) != 0) - sub_080003F0(); - sub_08001538(*(u32 *)(gUnk_03006440 + 0x620)); - *(u32 *)(gUnk_03006440 + 0x620) = result; -} -/* [StartItemMenuSubtask] Captures the task-control pointer at item-menu manager +0x620, retries allocation of - * a 0x400-byte stack with signal-1 waits, and writes each attempt to that captured control +0x20. Sets task +8 - * to 0x50, callback +0xC to 83AE8 only when the complete argument equals 1 and otherwise to 8381C, stack top - * +0x10 to allocation +0x3FC, and finalizer +0x24 to zero. Registers the control through 00274, forwarding the - * complete argument. The flag word is not identified as priority, and non-1 arguments are not restricted to - * zero. */ -void sub_080853DC(u32 arg) -{ - u8 *base = *(u8 **)0x03006440; - u8 *task = *(u8 **)(base + 0x620); - u32 memory; - memory = sub_08001494(0x400); - *(u32 *)(task + 0x20) = memory; - while (memory == 0) { - sub_080003F0(); - memory = sub_08001494(0x400); - *(u32 *)(task + 0x20) = memory; + goto finalize; + setv: + out->value = tv; } - *(u32 *)(task + 8) = 0x50; - if (arg == 1) *(u32 *)(task + 0xC) = (u32)sub_08083AE8; - else *(u32 *)(task + 0xC) = (u32)sub_0808381C; - *(u32 *)(task + 0x10) = *(u32 *)(task + 0x20) + 0x3FC; - *(u32 *)(task + 0x24) = 0; - sub_08000274((M2C_UNK *)task, (s32)arg); -} -/* [ReadItemMenuCurrencyTotal] Reads the current item-menu manager word at +0. In mode 4, sums word +4 for - * kind-10 records among exactly 75 entries at manager +0x104, stride 16, then adds the bag-currency result - * from 5D3D4. In every other mode, returns 5D404 directly, which sums the 75-entry stash at base *(u8 - * **)0x030034E0 + 0x2E0. This is a mode-dependent currency total, not an unconditional bag-plus-stash sum. The - * original performs low-32-bit word additions without saturation or capacity checks. */ -u32 sub_0808543C(void) -{ - u8 *base = (u8 *)gUnk_03006440; - u32 total; - if (*(u32 *)base == 4) { - u8 *entry; - u32 i; - u32 subtotal = 0; - i = 0; - entry = base + 0x104; - for (; i <= 0x4A; i++) { - if (*(u16 *)entry == 0xA) - subtotal += *(u32 *)(entry + 4); - entry += 0x10; +finalize: + { + for (b = 0; b <= 2; b++) { + switch (((struct Record8441C *)param_1)[b].type) { + case 9: + switch (rec[0].subtype) { + case 0: weights[b] = ((struct Record8441C *)param_1)[b].value; weights[b] = weights[b] / 20; break; + case 1: weights[b] = ((struct Record8441C *)param_1)[b].value; weights[b] = weights[b] * 8 / 100; break; + case 2: weights[b] = ((struct Record8441C *)param_1)[b].value; weights[b] = weights[b] / 10; break; + default: weights[b] = ((struct Record8441C *)param_1)[b].value; weights[b] = weights[b] / 100; break; + } + break; + case 2: case 3: case 4: case 5: + weights[b] = ((struct Record8441C *)param_1)[b].byte6; + break; + default: + weights[b] = 0; + break; + } } - total = subtotal; - total += sub_0805D3D4(); - } else { - total = sub_0805D404(); } - return total; -} -/* [ClearAndFreeItemMenuManager] Unconditionally loads pointer global0x03006440, writes word0 at pointee+0, - * frees pointee with0x08001538 and clears pointer global. Original instructions have no null check despite - * empty conditional in source. Registered finalizer by0x08084EAC for shared manager menu task0x0807A5D4. No - * pool wait, task cancellation or other field cleanup here. Complete original configured body and literals - * audited against ROM; copied verified-main ELF static equality, no local build or runtime test. */ -void sub_08085484(void) -{ - s32 p = gUnk_03006440; - if (p) - { - } - *((s32 *) p) = 0; - sub_08001538(p); - gUnk_03006440 = 0; -} -/* [FreeInventoryMenuManager] Loads pointer global0x03006440, calls heap free0x08001538, then clears global - * pointer. Does not write pointee first or test null. Original0x08084F24 registers it as finalizer of - * confirmed TaskInventoryMenu0x0807B7B4. Does not itself cancel tasks or free pool. Complete original - * configured body and literals audited against ROM; copied verified-main ELF static equality, no local build - * or runtime test. */ -void sub_080854A0(void) { - sub_08001538(gUnk_03006440); - gUnk_03006440 = 0; -} -/* [ClearHeldItemMenuRecord] Fills the 16-byte held-item record at menu manager +0xF4 with zero using CpuSet - * control 0x05000004, then reloads global 03006440 and writes word 22 at manager +0x1C and word zero at +0x20. - * Matched inventory movement/sale helpers and original 7C29C item-validation paths identify these as the held - * record and its source/index fields. It does not restore or transfer the item to another location, free the - * manager or clear the separate +0x18 interaction state. No direct caller or runtime reachability is - * established by this row. */ -void sub_080854B8(void) -{ - u32 zero = 0; - u8 *p; - CpuSet(&zero, (void *)(gUnk_03006440 + 0xF4), 0x05000004); - p = (u8 *)gUnk_03006440; - *(u32 *)(p + 0x1C) = 0x16; - *(u32 *)(p + 0x20) = 0; -} -/* [CountDecimalDigitsCappedAtSix] Unsigned full-word r0 value. Starts result6 and compares - * thresholds100000,10000,1000,100,10,1 from word table0x084EBD4C offsets16..36. Decrements while - * threshold>value, returning0 for zero,1..5 for1..99999, and6 for every value>=100000 including values with - * more than six decimal digits. No mutation or division. This is a capped display-width helper, not a true - * unbounded digit count. Complete original configured body and literals audited against ROM; copied - * verified-main ELF static equality, no local build or runtime test. */ -s32 sub_080854E8(u32 value) -{ - s32 result = 6; - const u32 *p; - u32 i = 4; - if (gUnk_084EBD4C[4] > value) { - p = &gUnk_084EBD4C[4]; - do { - p++; - i++; - result--; - } while (i <= 9 && *p > value); + m = *(u32 *)((u8 *)param_1 + 0x34); + m = m / 10000 + 1; + a = ((weights[0] + weights[1] + weights[2] + m) * *(u32 *)((u32)gUnk_030034E0 + SAVE_FIELD(0x6C)) >> 18) + 3; + if (a > 19) a = 20; + m = (u32)sub_080008C8() % (table8441C_084ECB30[a] + 1); + { + u32 prev = 0; + for (b = 0; b < a; ) { + if (prev <= m && m < table8441C_084ECB30[b]) { + out->byte6 = b; + break; + } + prev = table8441C_084ECB30[b]; + b++; + } } - return result; -} -/* [ClearAndFreeFullScreenItemMenuManager] Unconditionally loads shared item-menu pointer global0x03006440, - * writes word0 at pointee+0, calls heap free0x08001538, then clears pointer global. No null check or - * nested-pool cleanup. Original0x08084F9C registers as finalizer of full-screen item-menu callback0x08082BB0, - * which selects manager modes3/4/5/6 from its incoming mode. Same operation sequence as0x08085484 but distinct - * canonical entry and registration; raw bytes differ because the relative call to heap free has a different - * displacement. No collection-only domain is established. Complete original configured body and literals - * audited against ROM; copied verified-main ELF static equality, no local build or runtime test. */ -void sub_08085518(void) -{ - s32 p = gUnk_03006440; - { - *((s32 *) p) = 0; - } - sub_08001538(p); - gUnk_03006440 = 0; -} -extern u16 flags85534 asm("gUnk_03001308"); -void sub_08065230(void *, s32, s32, u16, s32); -/* [TaskAnimateSkillIncreaseIndicator] Task receives full-word x/y in r0/r1, gets shared sprite context, starts - * song 0x25, then performs exactly 30 iterations. Each clears halfword global 0x03001308 bits 0x30, decrements - * y when global tick word &3 is zero, advances descriptor 14 with two u16 local animation counters, draws - * descriptor 14 at x/y using first counter, and yields. Finally clears current task control word+8. - * Coordinates and input-mask side effects are explicit; no claim of resource freeing or runtime visual - * confirmation. Complete original configured body and literal use audited against EU ROM; copied verified-main - * ELF equality is static corroboration, not a new build or runtime test. */ -void sub_08085534(s32 arg0, s32 arg1) -{ - u16 a; - u16 b; - void *ctx; - u16 i; - ctx = sub_080653CC(); - sub_0805865C(0x25); - a = 0; - b = 0; - i = 0x1D; - do { - flags85534 &= 0xFFCF; - if ((gUnk_03002344 & 3) == 0) arg1--; - sub_08065370(ctx, 0xE, (s32)&a, (s32)&b, 1); - sub_08065230(ctx, arg0, arg1, 0xE, a); - sub_080003F0(); - i--; - } while (i != 0xFFFF); - *(u32 *)(sub_0800048C() + 8) = 0; -} -struct Shop6478 { - u32 running; - s32 cat; - s32 cursor; - s32 shown; - s32 index; - u32 grid; - u32 mode; - u32 unk1C; - u32 unk20; - s16 x; - s16 y; - s16 tx; - s16 ty; - u8 sprite[0x34]; -}; -struct Save855D4 { - u8 pad0[0x150]; - struct { u16 type; u16 id; u8 pad[0xC]; } slots[25]; - u8 pad2E0[0xC10 - 0x2E0]; - u8 counts[1]; -}; -struct Item855D4 { - s16 unk0, unk2, unk4, unk6, unk8; - u8 padA[6]; + m = *(u32 *)((u8 *)param_1 + 0x34); + m += (u32)sub_080008C8() % 200000; + { + u32 prev = 0; + for (b = 0; b <= 4; ) { + if (prev <= m && m < table8441C_084ECB84[b]) { + out->byte6 += b; + break; + } + prev = table8441C_084ECB84[b]; + b++; + } + } + if (out->type == 2) { + recA = (u8 *)sub_08007290(out->subtype | 0xB0000); + if (ITEM_KIND(recA) == 9) out->byte6 = 0; + } + if (out->byte6 > 19) out->byte6 = 20; + switch (out->type) { + case 2: + a = 0; + if (*(u16 *)(recA + 0x188) != 0) goto clearIdx; + scan2: + a++; + if (a > 2) goto copy; + if (({ u32 o4 = a * 4; u8 *pp = recA; asm("" : "+r"(o4)); *(u16 *)(pp + o4 + 0x188); }) == 0) goto scan2; + goto clearZero; + case 3: + a = 0; + if (*(u16 *)(recB + 0x180) != 0) goto clearIdx; + scan3: + a++; + if (a > 2) goto copy; + if (({ u32 o4 = a * 4; u8 *pp = recB; asm("" : "+r"(o4)); *(u16 *)(pp + o4 + 0x180); }) == 0) goto scan3; + goto clearZero; + case 4: + a = 0; + if (*(u16 *)(recC + 0x180) != 0) goto clearIdx; + scan4: + a++; + if (a > 2) goto copy; + if (({ u32 o4 = a * 4; u8 *pp = recC; asm("" : "+r"(o4)); *(u16 *)(pp + o4 + 0x180); }) == 0) goto scan4; + goto clearZero; + case 5: + a = 0; + if (*(u16 *)(recD + 0x184) == 0) goto scan5; + clearIdx: + out->value = a; + goto copy; + scan5: + a++; + if (a > 2) goto copy; + if (({ u32 o4 = a * 4; u8 *pp = recD; asm("" : "+r"(o4)); *(u16 *)(pp + o4 + 0x184); }) == 0) goto scan5; + clearZero: + out->value = 0; + } +copy: + *(struct Record8441C *)param_2 = *out; + { + u32 p1, p2, p3, p4; + s32 d; + u8 *st; + p1 = sub_0805AE94(&((struct Record8441C *)param_1)[0]); + p2 = sub_0805AE94(&((struct Record8441C *)param_1)[1]); + p3 = sub_0805AE94(&((struct Record8441C *)param_1)[2]); + p4 = sub_0805AE94(param_2); + st = (u8 *)gUnk_030034E0; + p1 += p2; + p1 += p3; + p1 += *(u32 *)((u8 *)param_1 + 0x34); + d = *(u32 *)(st + SAVE_FIELD(0x6C)) + p1 / 10; + d -= p4 / 10; + *(u32 *)(st + SAVE_FIELD(0x6C)) = d; + if (d < 0) *(u32 *)(st + SAVE_FIELD(0x6C)) = 0; + if (*(s32 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x6C)) > 0xFFFF) *(s32 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x6C)) = 0xFFFF; + } +#else + /* Combine three randomized records and update the shared success value. */ + extern const u32 table8441C_084EC1E0[] asm("gUnk_084EC1E0"); + extern const u32 table8441C_084EC288[] asm("gUnk_084EC288"); + extern const u32 table8441C_084EC330[] asm("gUnk_084EC330"); + extern const u32 table8441C_084EC3D8[] asm("gUnk_084EC3D8"); + extern const u32 table8441C_084EC480[] asm("gUnk_084EC480"); + extern const u32 table8441C_084EC4E0[] asm("gUnk_084EC4E0"); + extern const u32 table8441C_084EC540[] asm("gUnk_084EC540"); + extern const u32 table8441C_084EC5A0[] asm("gUnk_084EC5A0"); + extern const u32 table8441C_084EC600[] asm("gUnk_084EC600"); + extern const u32 table8441C_084EC660[] asm("gUnk_084EC660"); + extern const u32 table8441C_084EC6C0[] asm("gUnk_084EC6C0"); + extern const u32 table8441C_084EC6E4[] asm("gUnk_084EC6E4"); + extern const u32 table8441C_084EC708[] asm("gUnk_084EC708"); + extern const u32 table8441C_084EC72C[] asm("gUnk_084EC72C"); + extern const u32 table8441C_084EC750[] asm("gUnk_084EC750"); + extern const u32 table8441C_084EC774[] asm("gUnk_084EC774"); + extern const u32 table8441C_084EC798[] asm("gUnk_084EC798"); + extern const u32 table8441C_084EC7BC[] asm("gUnk_084EC7BC"); + extern const u32 table8441C_084EC7E0[] asm("gUnk_084EC7E0"); + extern const u32 table8441C_084EC804[] asm("gUnk_084EC804"); + extern const u32 table8441C_084EC828[] asm("gUnk_084EC828"); + extern const u32 table8441C_084EC84C[] asm("gUnk_084EC84C"); + extern const u32 table8441C_084EC870[] asm("gUnk_084EC870"); + extern const u32 table8441C_084EC8B0[] asm("gUnk_084EC8B0"); + extern const u32 table8441C_084EC8F0[] asm("gUnk_084EC8F0"); + extern const u32 table8441C_084EC920[] asm("gUnk_084EC920"); + extern const u32 table8441C_084EC950[] asm("gUnk_084EC950"); + extern const u32 table8441C_084EC9A0[] asm("gUnk_084EC9A0"); + extern const u32 table8441C_084EC9F0[] asm("gUnk_084EC9F0"); + extern const u32 table8441C_084ECA40[] asm("gUnk_084ECA40"); + extern const u32 table8441C_084ECA90[] asm("gUnk_084ECA90"); + extern const u32 table8441C_084ECAE0[] asm("gUnk_084ECAE0"); + extern const u32 table8441C_084ECB30[] asm("gUnk_084ECB30"); + extern const u32 table8441C_084ECB84[] asm("gUnk_084ECB84"); + extern u32 sub_0805AE94(const void *); + extern void *copy8441C(void *, const void *, u32) asm("memcpy"); + extern u32 sub_08084200(const u8 *); + struct Triple8441C { u32 a, b, c; }; + struct Record8441C { u16 type, subtype, value; u8 byte6, byte7; u32 word8, wordC; }; + /* Preserve the original frame, including partially initialized records. */ + u8 frameStorage8441C[128]; + register u8 *stack asm("sp"); + register struct Record8441C *result; + struct Record8441C *second; + register struct Record8441C *third asm("r8"); + u32 firstIndex; + u32 secondIndex; + register u32 thirdIndex asm("r6"); + register u32 tier asm("r6"); + u32 randomIndex; + const u16 *entry; + const u32 *tripleTable; + s32 classification; + u32 unaff_r9; + + *(u16 **)(stack + 0x5C) = param_1; + *(u32 **)(stack + 0x60) = param_2; + { + register u32 zeroHalf asm("r4") = 0; + struct Record8441C *initial = (struct Record8441C *)(stack + 0x30); + u32 zeroByte = 0; + + initial->type = zeroHalf; + initial->subtype = zeroHalf; + initial->byte6 = zeroByte; + initial->byte7 = zeroByte; + initial->value = zeroHalf; + firstIndex = 0; + result = initial; + } + second = ({ struct Record8441C *p = (struct Record8441C *)(stack + 0x10); p; }); + third = ({ register struct Record8441C *p asm("r1") = (struct Record8441C *)(stack + 0x20); p; }); + { + register u8 *temporary asm("r2") = stack; + asm("" : "+r"(temporary)); + temporary += 0x40; + *(u8 **)(stack + 0x78) = temporary; + } + { + u8 *bytes = stack + 0x34; + register u32 zero asm("r2") = 0; + + do { bytes[firstIndex] = zero; firstIndex++; } while (firstIndex <= 0xB); + } + firstIndex = (u32)sub_080008C8() % 3; + { + u32 offset = firstIndex << 4; + register struct Record8441C *destination asm("r1"); + register struct Record8441C *input asm("r3"); + struct Record8441C *source; + + destination = (struct Record8441C *)stack; + asm("" : "+r"(destination)); + input = *(struct Record8441C **)(stack + 0x5C); + + source = (struct Record8441C *)(offset + (u32)input); + + *destination = *source; + input++; + *(struct Record8441C **)(stack + 0x7C) = input; + } + { + register u8 *next asm("r3") = *(u8 **)(stack + 0x5C); + + next += 0x20; + *(u8 **)(stack + 0x74) = next; + } + do { secondIndex = (u32)sub_080008C8() % 3; } while (firstIndex == secondIndex); + { + u32 offset = secondIndex << 4; + register struct Record8441C *destination asm("r1"); + register struct Record8441C *input asm("r6"); + struct Record8441C *source; + + destination = second; + asm("" : "+r"(destination)); + input = *(struct Record8441C **)(stack + 0x5C); + + source = (struct Record8441C *)(offset + (u32)input); + + *destination = *source; + + } + do { thirdIndex = (u32)sub_080008C8() % 3; } while (firstIndex == thirdIndex || secondIndex == thirdIndex); + { + u32 offset = thirdIndex << 4; + register struct Record8441C *destination asm("r1"); + struct Record8441C *input; + register struct Record8441C *source asm("r0"); + + destination = third; + asm("" : "+r"(destination)); + input = *(struct Record8441C **)(stack + 0x5C); + + source = (struct Record8441C *)(offset + (u32)input); + asm("" : "+r"(source)); + *destination = *source; + asm("" : : "r"(input)); + } + classification = sub_08084200(*(u8 **)(stack + 0x5C)); + if (classification == 0) goto LAB_0808481c; + if (((u32)sub_080008C8() & 0xFFFF) > *(u32 *)((u32)gUnk_030034E0 + SAVE_FIELD(0x6C))) goto LAB_0808481c; + { + register struct Record8441C *input asm("r6") = *(struct Record8441C **)(stack + 0x5C); + + tier = (u32)input[0].value + (u32)input[1].value + (u32)input[2].value; + } + if (tier <= 99) goto lowTier8441C; + if (tier - 100 <= 199) tier = 0; + else { + u32 range = tier - 300; + tier = 2; + if (range <= 199) tier = 1; + } + switch (classification) { + case 1: + randomIndex = (u32)sub_080008C8() % 14; + { const u32 *table = table8441C_084EC1E0; + u32 index = randomIndex << 2; + u32 row = tier * 56; + entry = (const u16 *)(index + row + (u32)table); + } + goto applyEntry8441C; + case 2: + randomIndex = (u32)sub_080008C8() % 14; + { const u32 *table = table8441C_084EC288; + u32 index = randomIndex << 2; + u32 row = tier * 56; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(randomIndex), "r"(table), "i"(2)); } + goto applyEntry8441C; + case 3: + randomIndex = (u32)sub_080008C8() % 14; + { const u32 *table = table8441C_084EC330; + u32 index = randomIndex << 2; + u32 row = tier * 56; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(randomIndex), "r"(table), "i"(3)); } + goto applyEntry8441C; + case 4: + randomIndex = (u32)sub_080008C8() % 14; + { const u32 *table = table8441C_084EC3D8; + u32 index = randomIndex << 2; + u32 row = tier * 56; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(randomIndex), "r"(table), "i"(4)); } + goto applyEntry8441C; + case 5: + { register u32 index asm("r1") = (u32)sub_080008C8() & 7; + const u32 *table = table8441C_084EC480; + register u32 row asm("r0"); + index <<= 2; + row = tier << 5; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(5)); } + goto applyEntry8441C; + case 6: + { register u32 index asm("r1") = (u32)sub_080008C8() & 7; + const u32 *table = table8441C_084EC4E0; + register u32 row asm("r0"); + index <<= 2; + row = tier << 5; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(6)); } + goto applyEntry8441C; + case 7: + { register u32 index asm("r1") = (u32)sub_080008C8() & 7; + const u32 *table = table8441C_084EC540; + register u32 row asm("r0"); + index <<= 2; + row = tier << 5; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(7)); } + goto applyEntry8441C; + case 8: + { register u32 index asm("r1") = (u32)sub_080008C8() & 7; + const u32 *table = table8441C_084EC5A0; + register u32 row asm("r0"); + index <<= 2; + row = tier << 5; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(8)); } + goto applyEntry8441C; + case 9: + { register u32 index asm("r1") = (u32)sub_080008C8() & 7; + const u32 *table = table8441C_084EC600; + register u32 row asm("r0"); + index <<= 2; + row = tier << 5; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(9)); } + goto applyEntry8441C; + case 10: + { register u32 index asm("r1") = (u32)sub_080008C8() & 7; + const u32 *table = table8441C_084EC660; + register u32 row asm("r0"); + index <<= 2; + row = tier << 5; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(10)); } + goto applyEntry8441C; + case 11: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC6C0; + goto tripleEntry8441C; + case 12: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC6E4; + goto tripleEntry8441C; + case 13: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC708; + goto tripleEntry8441C; + case 14: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC72C; + goto tripleEntry8441C; + case 15: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC750; + goto tripleEntry8441C; + case 16: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC774; + goto tripleEntry8441C; + case 17: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC798; + goto tripleEntry8441C; + case 18: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC7BC; + goto tripleEntry8441C; + case 19: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC7E0; + goto tripleEntry8441C; + case 20: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC804; + goto tripleEntry8441C; + case 21: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC828; + goto tripleEntry8441C; + case 22: + randomIndex = (u32)sub_080008C8() % 3; + tripleTable = table8441C_084EC84C; +tripleEntry8441C: + { const u16 *p = (const u16 *)(((tier * 3 + randomIndex) << 2) + (u32)tripleTable); + result->type = p[0]; result->subtype = p[1]; } + goto finalize8441C; + case 23: + { register u32 index asm("r1") = (u32)sub_080008C8() & 3; + const u32 *table = table8441C_084EC870; + register u32 row asm("r0"); + index <<= 2; + row = (tier + 1) << 4; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(23)); } + goto applyEntry8441C; + case 24: + { register u32 index asm("r1") = (u32)sub_080008C8() & 3; + const u32 *table = table8441C_084EC8B0; + register u32 row asm("r0"); + index <<= 2; + row = (tier + 1) << 4; + entry = (const u16 *)(index + row + (u32)table); + asm("" : "+r"(entry) : "r"(row), "r"(table), "i"(24)); } + goto applyEntry8441C; + default: goto finalize8441C; + } +lowTier8441C: + if (classification == 23) goto low23; + if (classification == 24) goto low24; + goto LAB_0808481c; +low23: + { u32 index = (u32)sub_080008C8() & 3; + const u32 *table; + table = table8441C_084EC870; + entry = (const u16 *)((index << 2) + (u32)table); } + goto applyEntry8441C; +low24: + { u32 index = (u32)sub_080008C8() & 3; + const u32 *table; + table = table8441C_084EC8B0; + entry = (const u16 *)((index << 2) + (u32)table); } +applyEntry8441C: + result->type = entry[0]; + result->subtype = entry[1]; + goto finalize8441C; +LAB_0808481c: + switch (((struct Record8441C *)stack)->type) { + case 9: + { + s32 subtype = ((struct Record8441C *)stack)->subtype; + if (subtype == 3) goto rareFirst8441C; + if (subtype == 4) goto rareSecond8441C; + if (((u32)sub_080008C8() & 1) == 0) goto inventorySecond8441C; + goto inventoryFirst8441C; +rareFirst8441C: + randomIndex = (u32)sub_080008C8(); + randomIndex &= subtype; + { + struct Triple8441C *temporary = (struct Triple8441C *)(stack + 0x4C); + const u32 *table; + const struct Triple8441C *source; + table = table8441C_084EC8F0; + { u32 offset = randomIndex * 12; + struct Triple8441C *destination; + destination = temporary; + source = (const struct Triple8441C *)(offset + (u32)table); + *destination = *source; } + + copy8441C(result, temporary, 16); + } + + goto finalize8441C; +rareSecond8441C: + randomIndex = (u32)sub_080008C8(); + { u32 mask = 3; randomIndex &= mask; } + { + struct Triple8441C *temporary = (struct Triple8441C *)(stack + 0x4C); + const u32 *table; + const struct Triple8441C *source; + table = table8441C_084EC920; + { u32 offset = randomIndex * 12; + struct Triple8441C *destination; + destination = temporary; + source = (const struct Triple8441C *)(offset + (u32)table); + *destination = *source; } + copy8441C(result, temporary, 16); + } + + goto thirdValue8441C; +inventoryFirst8441C: + do { + randomIndex = (u32)sub_080008C8() % 12; + + { + u8 *source = (u8 *)(u32)gUnk_030034E0; + u32 byteOffset = randomIndex << 4; + register struct Record8441C *destination asm("r1"); + register u32 baseOffset asm("r5"); + source += byteOffset; + destination = result; + baseOffset = SAVE_FIELD(0x790); + asm("" : "+r"(destination), "+r"(baseOffset)); + source += baseOffset; + *destination = *(struct Record8441C *)source; + asm("" : : "r"(baseOffset), "r"(subtype)); + } + + } while (result->type == 0); + { u32 loaded = sub_08007290(result->subtype | 0xB0000); + *(u32 *)(stack + 0x64) = loaded; + if (*(u16 *)(loaded + ITEM_FIELD(0xBC)) != 0) goto finalize8441C; } + if (*(u16 *)((u8 *)result + 6) != 0) goto finalize8441C; + if (*(u16 *)(*(volatile u32 *)(stack + 0x64) + ITEM_FIELD(0xB0)) != 0) goto finalize8441C; + goto secondAttribute8441C; +inventorySecond8441C: + { + struct Record8441C *inventoryResult = result; + do { + randomIndex = (u32)sub_080008C8() % 12; + + { + u8 *source = (u8 *)(u32)gUnk_030034E0; + u32 byteOffset = randomIndex << 4; + register struct Record8441C *destination asm("r1"); + register u32 baseOffset asm("r5"); + source += byteOffset; + destination = inventoryResult; + baseOffset = SAVE_FIELD(0x850); + asm("" : "+r"(destination), "+r"(baseOffset)); + source += baseOffset; + *destination = *(struct Record8441C *)source; + asm("" : : "r"(baseOffset), "r"(inventoryResult)); + } + + } while (inventoryResult->type == 0); + } + if (result->type == 3) { + *(u32 *)(stack + 0x68) = sub_08007290(result->subtype | 0xC0000); + asm("" : : : "memory"); + if ((*(u32 *)((u8 *)result + 4) & 0xFFFFFF) != 0) goto finalize8441C; + if (*(u16 *)(*(u32 *)(stack + 0x68) + EQUIP_FIELD(0xA4)) != 0) goto finalize8441C; + } else { +#ifdef REGION_USA + if (result->type == 4) { + *(u32 *)(stack + 0x6C) = sub_08007290(result->subtype | 0xD0000); + if ((*(u32 *)((u8 *)result + 4) & 0xFFFFFF) != 0) goto finalize8441C; + if (*(u16 *)(*(u32 *)(stack + 0x6C) + EQUIP_FIELD(0xA4)) != 0) goto finalize8441C; + } else { + *(u32 *)(stack + 0x70) = sub_08007290(result->subtype | 0xE0000); + if ((*(u32 *)((u8 *)result + 4) & 0xFFFFFF) != 0) goto finalize8441C; + if (*(u16 *)(*(u32 *)(stack + 0x6C) + EQUIP_FIELD(0xA4)) != 0) goto finalize8441C; + } +#else + if (result->type == 4) *(u32 *)(stack + 0x6C) = sub_08007290(result->subtype | 0xD0000); + else *(u32 *)(stack + 0x70) = sub_08007290(result->subtype | 0xE0000); + if ((*(u32 *)((u8 *)result + 4) & 0xFFFFFF) != 0) goto finalize8441C; + if (*(u16 *)(*(u32 *)(stack + 0x6C) + EQUIP_FIELD(0xA4)) != 0) goto finalize8441C; +#endif + } + goto thirdValue8441C; + } + case 2: + { u32 hold2, hold3 asm("r3"); + *result = *(struct Record8441C *)stack; + } + goto secondAttribute8441C; + case 3: case 4: case 5: + { u32 hold5, hold6 asm("r6"); + *result = *(struct Record8441C *)stack; + } + goto thirdValue8441C; + default: break; + } +secondAttribute8441C: + if (((u32)sub_080008C8() & 0xFFFF) <= *(u32 *)((u32)gUnk_030034E0 + SAVE_FIELD(0x6C))) { + register struct Record8441C *attributeRecord asm("r0") = second; + s32 attributeType; + attributeType = attributeRecord->type; + switch (attributeType) { + case 9: + { + s32 subtype = attributeRecord->subtype; + switch (subtype) { + case 0: + randomIndex = (u32)sub_080008C8() % 3; + + unaff_r9 = ({ register u32 value asm("r6") = 1; asm("" : "+r"(value)); value; }); + if (randomIndex == 0) unaff_r9 = ({ register u32 value asm("r0") = 3; asm("" : "+r"(value)); value; }); + break; + case 1: + subtype &= sub_080008C8(); + unaff_r9 = ({ register u32 value asm("r1") = 4; asm("" : "+r"(value)); value; }); + if (subtype == 0) unaff_r9 = ({ register u32 value asm("r2") = 2; asm("" : "+r"(value)); value; }); + break; + case 2: + randomIndex = (u32)sub_080008C8() % 3; + + unaff_r9 = ({ register u32 value asm("r3") = 6; asm("" : "+r"(value)); value; }); + if (randomIndex == 0) unaff_r9 = ({ register u32 value asm("r4") = 5; asm("" : "+r"(value)); value; }); + break; + default: unaff_r9 = ({ u32 value = 0; value; }); break; + } + } + break; + case 2: + unaff_r9 = ({ struct Record8441C *p = second; u32 value; value = p->byte7; value; }); + break; + case 3: case 4: case 5: unaff_r9 = ({ u32 value = 0; value; }); break; + default: break; + } + switch (result->type) { + case 3: case 4: case 5: result->byte7 = 0; break; + default: { u32 attribute = unaff_r9; result->byte7 = attribute; } break; + } + } +thirdValue8441C: + { + u32 chance; + u32 tableValue; + register u32 offset asm("r1"); + const u32 *table; + { + u32 random = (u32)sub_080008C8() & 0xFFFF; + u32 limit; + limit = *(u32 *)((u32)gUnk_030034E0 + SAVE_FIELD(0x6C)); + chance = 0; + if (random <= limit) chance = 1; + } + switch (result->type) { + case 2: goto resultTwo8441C; + case 3: case 4: case 5: break; + default: goto finalize8441C; + } + { register struct Record8441C *p asm("r2") = third; + switch ((s32)p->type) { + case 2: case 3: case 4: case 5: goto permittedOther8441C; + case 9: goto topRandomTrampoline; + default: goto finalize8441C; + } + } +topRandomTrampoline: + /* Keep the original conditional trampoline; this emits no instructions. */ + asm("" : : "X"(&&topRandomTrampoline)); + goto randomOther8441C; +resultTwo8441C: + { u32 address; + address = sub_08007290(result->subtype | 0xB0000); + *(u32 *)(stack + 0x64) = address; + if (ITEM_KIND(address) != 9) goto resultTwoOrdinary8441C; + { register struct Record8441C *p asm("r3") = third; + switch ((s32)p->type) { + case 2: case 3: case 4: case 5: goto permittedFour8441C; + case 9: break; + default: goto finalize8441C; + } + } + } +randomSpecial8441C: + randomIndex = sub_080008C8(); + { u32 mask = 3; randomIndex &= mask; } + if (!chance) goto randomSpecialNo; + table = table8441C_084ECA90; +sharedOffset8441C: + offset = randomIndex << 2; + tableValue = ({ register struct Record8441C *p asm("r4") = third; p->subtype; }); +sharedTable8441C: + tableValue <<= 4; + offset += tableValue; + offset += (u32)table; + tableValue = *(u32 *)offset; + goto setValue8441C; +randomSpecialNo: + table = table8441C_084ECAE0; + offset = randomIndex << 2; + tableValue = ({ register struct Record8441C *p asm("r5") = third; p->subtype; }); + goto sharedTable8441C; +permittedFour8441C: + { u32 value; + value = ({ register struct Record8441C *p asm("r6") = third; p->value; }); + if (value == 0) { result->value = value; goto finalize8441C; } + value = sub_08007290((value - 1) | 0x130000); + { register u8 *duplicate asm("r1") = (u8 *)value; + register u32 flags asm("r1"); + asm("" : : "r"(duplicate)); + value += 0xAC; + flags = *(u16 *)value; + value = 4; value &= flags; + value = (u16)value; + } + if (value == 0) { result->value = value; goto finalize8441C; } + value = ({ register struct Record8441C *p asm("r1") = third; p->value; }); + { result->value = value; goto finalize8441C; } + } +resultTwoOrdinary8441C: + { register struct Record8441C *p asm("r2") = third; + switch ((s32)p->type) { + case 2: case 3: case 4: case 5: goto permittedEight8441C; + case 9: break; + default: goto finalize8441C; + } + } +randomOrdinary8441C: + randomIndex = sub_080008C8(); + { u32 mask = 3; randomIndex &= mask; } + if (!chance) goto randomOrdinary8441Cno; + table = table8441C_084EC950; + offset = randomIndex << 2; + tableValue = ({ register struct Record8441C *p asm("r3") = third; asm("" : "+r"(p)); p->subtype; }); + goto sharedTable8441C; +randomOrdinary8441Cno: + table = table8441C_084EC9A0; + goto sharedOffset8441C; +permittedEight8441C: + { u32 value; + value = ({ register struct Record8441C *p asm("r5") = third; p->value; }); + if (value == 0) { result->value = value; goto finalize8441C; } + value = sub_08007290((value - 1) | 0x130000); + { register u8 *duplicate asm("r1") = (u8 *)value; + register u32 flags asm("r1"); + asm("" : : "r"(duplicate)); + value += 0xAC; + flags = *(u16 *)value; + value = 8; value &= flags; + value = (u16)value; + } + if (value == 0) { result->value = value; goto finalize8441C; } + value = ({ register struct Record8441C *p asm("r6") = third; p->value; }); + { result->value = value; goto finalize8441C; } + } +randomOther8441C: + randomIndex = sub_080008C8(); + { u32 mask = 3; randomIndex &= mask; } + if (!chance) goto randomOther8441Cno; + table = table8441C_084EC9F0; + offset = randomIndex << 2; + tableValue = ({ register struct Record8441C *p asm("r3") = third; p->subtype; }); + goto sharedTable8441C; +randomOther8441Cno: + table = table8441C_084ECA40; + goto sharedOffset8441C; +permittedOther8441C: + { struct Record8441C *valueRecord = third; + u8 *properties; + u32 initial, type, flags, allowed; + initial = valueRecord->value; + if (initial == 0) { result->value = initial; goto finalize8441C; } + { u32 argument = initial; + u32 tag = 0x130000; + asm("" : "+r"(argument), "+r"(tag)); + properties = (u8 *)sub_08007290(argument | tag); } + type = (u16)(result->type - 3); + if (type > 1) goto permittedOne8441C; + { u8 *address = properties; + u32 bits; + u32 mask; + address += 0xAC; + bits = *(u16 *)address; + mask = 2; mask &= bits; + allowed = (u16)mask; + if (allowed == 0) { result->value = allowed; goto finalize8441C; } + } + result->value = valueRecord->value; + goto finalize8441C; +permittedOne8441C: + { u8 *address = properties; + u32 mask; + address += 0xAC; + flags = *(u16 *)address; + mask = 1; mask &= flags; + if (mask == 0) { result->value = mask; goto finalize8441C; } + } + { register struct Record8441C *last asm("r5") = third; + result->value = last->value; } + goto finalize8441C; + } +setValue8441C: + result->value = tableValue; + } + +finalize8441C: + { + u32 *stateAddress; + u32 *weight; + struct Record8441C *input; + stateAddress = ({ register u32 *p asm("r6") = (u32 *)&gUnk_030034E0; asm("" : "+r"(p)); p; }); + weight = *(u32 *volatile *)(stack + 0x78); + input = *(struct Record8441C *volatile *)(stack + 0x5C); + do { + u32 normalized; + switch ((s32)input->type) { + case 2: case 3: case 4: case 5: goto weightByte8441C; + case 9: break; + default: goto weightZero8441C; + } + switch (((struct Record8441C *)stack)->subtype) { + case 0: + normalized = input->value; + *weight = normalized; + normalized /= (u32)20; + + goto weightStore8441C; + case 1: + normalized = input->value; + *weight = normalized; + normalized = (normalized << 3) / 100; + + goto weightStore8441C; + case 2: + normalized = input->value; + *weight = normalized; + normalized /= (u32)10; + + goto weightStore8441C; + default: + normalized = input->value; + *weight = normalized; + normalized /= (u32)100; + asm("" : "+r"(normalized) : "i"(100)); + goto weightStore8441C; + } +weightByte8441C: + normalized = input->byte6; + goto weightStore8441C; +weightZero8441C: + normalized = 0; +weightStore8441C: + *weight = normalized; + asm("" : "+r"(weight)); + weight++; + input++; + } while (weight <= *(u32 *volatile *)(stack + 0x78) + 2); + { + register u32 factor asm("r6") = *(u32 *)(*(volatile u32 *)(stack + 0x5C) + 0x34); + u32 score; + u32 sum; + u32 *values; + u32 multiplier; + u32 *global; + + factor = factor / 10000 + 1; + + sum = *(u32 *)(stack + 0x40); + + values = *(u32 *volatile *)(stack + 0x78); + + sum += values[1]; + sum += values[2]; + sum += factor; + global = stateAddress; + + multiplier = *(u32 *)(*global + SAVE_FIELD(0x6C)); + asm("" : : "r"(values)); + sum *= multiplier; + score = (sum >> 18) + 3; + if (score > 19) score = 20; + { + u32 random = sub_080008C8(); + const u32 *weights; + u32 range; + register u32 roll asm("r6"); + register u32 index asm("r4"); + u32 value; + const u32 *base; + + weights = ({ const u32 *p = table8441C_084ECB30; p; }); + range = score << 2; + range += (u32)weights; + range = *(u32 *)range + 1; + roll = random % range; + index = 0; + + if (index >= score) goto afterWeight8441C; + if (index > roll) goto scanWeight8441C; + base = weights; + value = *base; + goto compareWeight8441C; +scanWeight8441C: + base = table8441C_084ECB30; + value = *(u32 *)((index << 2) + (u32)base); + index++; + if (index >= score) goto afterWeight8441C; + if (value > roll) goto scanWeight8441C; + value = *(u32 *)((index << 2) + (u32)base); +compareWeight8441C: + if (roll >= value) goto scanWeight8441C; + result->byte6 = index; +afterWeight8441C: + { register u32 *metadata asm("r2") = *(u32 *volatile *)(stack + 0x5C); + roll = metadata[13]; } + roll += (u32)sub_080008C8() % 200000; + index = 0; + + if (index > roll) goto scanBonus8441C; + value = table8441C_084ECB84[0]; + if (roll < value) goto afterBonus8441C; +scanBonus8441C: + base = table8441C_084ECB84; + value = *(u32 *)((index << 2) + (u32)base); + index++; + if (index > 4) goto afterBonus8441C; + if (value > roll) goto scanBonus8441C; + value = *(u32 *)((index << 2) + (u32)base); + if (roll >= value) goto scanBonus8441C; + result->byte6 += index; +afterBonus8441C: + ; + } + } + } + if (result->type == 2) { + *(u32 *)(stack + 0x64) = sub_08007290(result->subtype | 0xB0000); + if (ITEM_KIND(*(u32 *)(stack + 0x64)) == 9) result->byte6 = 0; + } + if (result->byte6 > 19) result->byte6 = 20; + switch (result->type) { + case 2: + randomIndex = 0; + if (*(u16 *)(*(u32 *)(stack + 0x64) + ITEM_FIELD(0xB0)) != 0) goto clearByIndex8441C; +scanProperty2: + randomIndex++; + if (randomIndex > 2) goto copyOutput8441C; + if (({ register u32 offset asm("r0") = randomIndex << 2; register u8 *properties asm("r3"); properties = *(u8 **)(stack + 0x64); *(u16 *)(properties + offset + ITEM_FIELD(0xB0)); }) == 0) goto scanProperty2; + goto clearByZero8441C; + case 3: + randomIndex = 0; + if (*(u16 *)(*(u32 *)(stack + 0x68) + EQUIP_FIELD(0xA4)) != 0) goto clearByIndex8441C; +scanProperty3: + randomIndex++; + if (randomIndex > 2) goto copyOutput8441C; + if (({ register u32 offset asm("r0") = randomIndex << 2; register u8 *properties asm("r4"); properties = *(u8 **)(stack + 0x68); *(u16 *)(properties + offset + EQUIP_FIELD(0xA4)); }) == 0) goto scanProperty3; + goto clearByZero8441C; + case 4: + randomIndex = 0; + if (*(u16 *)(*(u32 *)(stack + 0x6C) + EQUIP_FIELD(0xA4)) != 0) goto clearByIndex8441C; +scanProperty4: + randomIndex++; + if (randomIndex > 2) goto copyOutput8441C; + if (({ register u32 offset asm("r0") = randomIndex << 2; register u8 *properties asm("r6"); properties = *(u8 **)(stack + 0x6C); *(u16 *)(properties + offset + EQUIP_FIELD(0xA4)); }) == 0) goto scanProperty4; + goto clearByZero8441C; + case 5: + randomIndex = 0; + if (*(u16 *)(*(u32 *)(stack + 0x70) + 0xA4) == 0) goto scanProperty5; +clearByIndex8441C: + result->value = randomIndex; + goto copyOutput8441C; + +scanProperty5: + randomIndex++; + if (randomIndex > 2) goto copyOutput8441C; + if (({ register u32 offset asm("r0") = randomIndex << 2; register u8 *properties asm("r1"); properties = *(u8 **)(stack + 0x70); *(u16 *)(properties + offset + EQUIP_FIELD(0xA4)); }) == 0) goto scanProperty5; + goto clearByZero8441C; +clearByZero8441C: + result->value = 0; + goto copyOutput8441C; + + default: goto copyOutput8441C; + } +copyOutput8441C: + { + register struct Record8441C *output asm("r1") = *(struct Record8441C **)(stack + 0x60); + struct Record8441C *source; + u32 hold5, hold6 asm("r6"); + asm("" : "+r"(output)); + source = result; + asm("" : "+r"(source), "=r"(hold5), "=r"(hold6)); + *output = *source; + + } + { + register u32 firstPrice asm("r4") = sub_0805AE94(*(void **)(stack + 0x5C)); + u32 secondPrice; + u32 thirdPrice; + u32 outputPrice; + u32 *globalAddress; + u8 *state; + + secondPrice = sub_0805AE94(*(void **)(stack + 0x7C)); + asm("" : "+r"(secondPrice)); + thirdPrice = sub_0805AE94(*(void **)(stack + 0x74)); + asm("" : "+r"(thirdPrice)); + outputPrice = sub_0805AE94(*(void **)(stack + 0x60)); + + { register u32 *p asm("r0") = (u32 *)&gUnk_030034E0; + + globalAddress = p; + + state = (u8 *)*p; } + firstPrice += secondPrice; + firstPrice += thirdPrice; + { register u32 *input asm("r1") = *(u32 *volatile *)(stack + 0x5C); + + firstPrice += input[13]; } + firstPrice = *(u32 *)(state + SAVE_FIELD(0x6C)) + firstPrice / 10; + firstPrice -= outputPrice / 10; + *(u32 *)(state + SAVE_FIELD(0x6C)) = firstPrice; + if ((s32)firstPrice < 0) *(u32 *)(state + SAVE_FIELD(0x6C)) = 0; + { + register u32 *address asm("r2") = globalAddress; + u8 *current; + s32 value; + register u32 maximum asm("r2"); + asm("" : "+r"(address)); + current = (u8 *)*address; + value = *(s32 *)(current + SAVE_FIELD(0x6C)); + maximum = 0xFFFF; + + if (value > (s32)maximum) *(u32 *)(current + SAVE_FIELD(0x6C)) = maximum; + } + } +#endif +} + +/* [StartCharacterStatAndSkillMenuTask] No arguments or meaningful return. Retries exact allocation + * of0x624=1572 bytes for shared manager0x03006440, yielding after failures, initializes first word0. Then + * retries1024-byte task stack on fixed task0x03006450, sets top+1020, priority100, finalizer0x08085484 and + * callback0x0807A5D4, scheduler argument0. No active-task or existing-manager protection; starts request and + * does not wait for menu closure. Complete pinned matching source body and complete original configured range + * inspected, including long-range continuations. Original range equals copied verified-main ELF; no local + * build or runtime test. */ +void sub_08084EAC(void) +{ + while ((gUnk_03006440 = sub_08001494(0x624)) == 0) + sub_080003F0(); + *(u32 *)gUnk_03006440 = 0; + while ((task84eac[8] = sub_08001494(0x400)) == 0) + sub_080003F0(); + task84eac[4] = task84eac[8] + 0x3FC; + task84eac[2] = 0x64; + task84eac[9] = (u32)sub_08085484; + task84eac[3] = (u32)sub_0807A5D4; + sub_08000274((M2C_UNK *)task84eac, 0); +} +/* [StartInventoryMenuTask] Retries allocation of a 0x624-byte item-menu manager through global 03006440, + * clears only its first word, then retries a 0x900-byte stack allocation. Initializes the existing + * task-control record with stack top allocation +0x8FC, flags/state word +8 equal 0x64, finalizer 854A0 and + * callback 7B7B4, then registers it through 00274 with argument zero. Failed allocations wait on scheduler + * signal 1. It does not initialize every manager field, impose a retry bound or establish priority from the + * task flag word. */ +void sub_08084F24(void) +{ + while ((gUnk_03006440 = sub_08001494(0x624)) == 0) + sub_080003F0(); + *(u32 *)gUnk_03006440 = 0; + while ((task84f24[8] = sub_08001494(0x900)) == 0) + sub_080003F0(); + task84f24[4] = task84f24[8] + 0x8FC; + task84f24[2] = 0x64; + task84f24[9] = (u32)sub_080854A0; + task84f24[3] = (u32)sub_0807B7B4; + sub_08000274((M2C_UNK *)task84f24, 0); +} +/* [StartItemCollectionInteractionMenuTask] Full-word r0 interaction variant forwarded unchanged. + * Retries1572-byte manager allocation into0x03006440 and zeros its first word; retries2560-byte stack on fixed + * task0x03006450. Sets stack top+2556, priority100, callback0x08082BB0 and finalizer0x08085518, then starts + * task with variant argument. No existing-manager/task activity guard and no wait for menu completion; + * allocation failures yield. Complete pinned matching source body and original configured range preserved for + * independent static audit; original equals copied verified-main ELF, no local build or runtime test. */ +void sub_08084F9C(u32 arg) +{ + while ((gUnk_03006440 = sub_08001494(0x624)) == 0) + sub_080003F0(); + *(u32 *)gUnk_03006440 = 0; + while ((task84f9c[8] = sub_08001494(0xA00)) == 0) + sub_080003F0(); + task84f9c[4] = task84f9c[8] + 0x9FC; + task84f9c[2] = 0x64; + task84f9c[9] = (u32)sub_08085518; + task84f9c[3] = (u32)sub_08082BB0; + sub_08000274((M2C_UNK *)task84f9c, arg); +} +/* [DrawSkillProgressTileRun] r0 is an unbounded row index, r1 an unsigned count clamped to seven, and r2 a + * tile variant. Writes count halfwords of ((u16)(variant+0x16B)|0xE000) at text-map +0x2C+(index+5)*64; queues + * row index+5 only when count is nonzero. Does not clear remaining tiles. Original caller 0x0807B53E supplies + * skill level+1 and variant 3; 0x0807B54E supplies progress and variant 0. No row validation. Complete + * original configured body and literal use audited against EU ROM; copied verified-main ELF equality is static + * corroboration, not a new build or runtime test. */ +void sub_08085014(u32 index, u32 count, u32 value) +{ + u32 i; + u16 encoded; + u16 *dst; + if (count > 7) count = 7; + encoded = value + 0x16B; + for (i=0; i 4) return; + if (sub_08000470((u32)entry) != 0 || *(u32 *)(entry + 8) != 0) + goto next; + *(u32 *)(entry + 8) = 0x3C; + memory = sub_08001494(0x400); + *(u32 *)(entry + 0x20) = memory; + } while (0); + if (memory == 0) return; + *(u32 *)(entry + 0xC) = (u32)sub_08085534; + *(u32 *)(entry + 0x10) = memory + 0x3FC; + *(u32 *)(entry + 0x24) = 0; + sub_08000274_(entry,arg0,arg1); +} +/* [VCountApplyBg0FourPixelVerticalOffset] Writes halfword 4 directly to BG0VOFS hardware register 04000012, + * sets the next VCount compare line to 159 and replaces the VCount callback with sibling 852AC. Does not + * modify BG0 scroll shadow, enable the VCount interrupt, preserve an arbitrary prior scroll value or stop the + * alternating callback chain. */ +void sub_0808528C(void) { + *(s16 *)0x04000012 = 4; + sub_08001108(0x9F); + sub_0800115C((s32) &sub_080852AC); +} +/* [VCountResetBg0VerticalOffset] Writes halfword zero directly to BG0VOFS hardware register 04000012, sets + * next VCount compare line to 136 and installs sibling 8528C. It resets this hardware offset rather than + * restoring an arbitrary saved value. The callback chain continues; this is not a function to disable the band + * or the VCount interrupt. */ +void sub_080852AC(void) +{ + *(u16 *)0x04000012 = 0; + sub_08001108(0x88); + sub_0800115C((s32)sub_0808528C); +} +/* [CopyItemMenuCollectionRecords] r0 source; manager pointer is read from 0x03006440. Copies complete 16-byte + * records as four words into manager+0x104: 75 records when manager word zero equals 4, otherwise 12. Returns + * void; no source-size, overlap or manager validation. Consumers include currency summation at 0x08085330 and + * item menu initialization caller 0x08083182/0x080831C8. Does not infer shop versus stash from mode alone. + * Complete original configured body and literal use audited against EU ROM; copied verified-main ELF equality + * is static corroboration, not a new build or runtime test. */ +void sub_080852CC(struct Entry852CC *src) +{ + u32 i; + if (collection852CC->kind != 4) { + for (i=0; i<=11; src++) { + collection852CC->entries[i] = *src; + i++; + } + } else { + for (i=0; i<=0x4A; src++) { + collection852CC->entries[i] = *src; + i++; + } + } +} +/* [SumItemMenuStashOrStockCurrency] In item-menu mode 4, sums word +4 for kind-10 entries among exactly 75 + * records at manager +0x104, stride 16. Otherwise returns 5D404, the stash sum at character/inventory base + * +0x2E0 through pointer global 030034E0. These are distinct from the menu manager through global 03006440. + * This helper never adds the bag total; the separate 8543C query adds bag currency only in mode 4. Original + * arithmetic returns the low 32-bit sum without saturation or capacity checks. */ +u32 sub_08085330(void) +{ + u32 total = 0; + u8 *base = (u8 *)gUnk_03006440; + if (*(u32 *)base == 4) { + u8 *entry; + u32 i; + i = 0; entry = base + 0x104; + for (; i <= 0x4A; i++) { + if (*(u16 *)entry == 0xA) + total += *(u32 *)(entry + 4); + entry += 0x10; + } + } else { + total = sub_0805D404(); + } + return total; +} +/* [AllocateItemMenuSubtaskControl] Retries a 0x28-byte allocation until nonnull, storing every attempt in the + * word at item-menu manager +0x620 through pointer global 03006440. Each failed attempt waits for scheduler + * signal 1 through 003F0. It allocates the child task-control record only: it does not clear the record, + * allocate its execution stack, select a callback or register the task. There is no bounded retry count or + * proved manager lifetime. */ +void sub_0808536C(void) +{ + while ((M2C_FIELD(gUnk_03006440, s32 *, 0x620) = sub_08001494(0x28)) == 0) + sub_080003F0(); +} +/* [WaitForItemMenuSubtaskAndFreeControl] Captures the task-control pointer at item-menu manager +0x620 and + * polls 00470 until it is absent from the scheduled-task list, yielding on scheduler signal 1 between nonzero + * results. Then reloads the global manager and frees its current +0x620 pointer through 01538; reloads the + * manager again and stores the zero query result at +0x620. The polled captured pointer and later freed + * current field are not assumed identical across yields. It does not explicitly free the execution-stack field + * or impose a timeout. */ +void sub_08085398(void) +{ + u32 value = *(u32 *)(gUnk_03006440 + 0x620); + u32 result; + while ((result = sub_08000470(value)) != 0) + sub_080003F0(); + sub_08001538(*(u32 *)(gUnk_03006440 + 0x620)); + *(u32 *)(gUnk_03006440 + 0x620) = result; +} +/* [StartItemMenuSubtask] Captures the task-control pointer at item-menu manager +0x620, retries allocation of + * a 0x400-byte stack with signal-1 waits, and writes each attempt to that captured control +0x20. Sets task +8 + * to 0x50, callback +0xC to 83AE8 only when the complete argument equals 1 and otherwise to 8381C, stack top + * +0x10 to allocation +0x3FC, and finalizer +0x24 to zero. Registers the control through 00274, forwarding the + * complete argument. The flag word is not identified as priority, and non-1 arguments are not restricted to + * zero. */ +void sub_080853DC(u32 arg) +{ + u8 *base = *(u8 **)&gUnk_03006440; + u8 *task = *(u8 **)(base + 0x620); + u32 memory; + memory = sub_08001494(0x400); + *(u32 *)(task + 0x20) = memory; + while (memory == 0) { + sub_080003F0(); + memory = sub_08001494(0x400); + *(u32 *)(task + 0x20) = memory; + } + *(u32 *)(task + 8) = 0x50; + if (arg == 1) *(u32 *)(task + 0xC) = (u32)sub_08083AE8; + else *(u32 *)(task + 0xC) = (u32)sub_0808381C; + *(u32 *)(task + 0x10) = *(u32 *)(task + 0x20) + 0x3FC; + *(u32 *)(task + 0x24) = 0; + sub_08000274((M2C_UNK *)task, (s32)arg); +} +/* [ReadItemMenuCurrencyTotal] Reads the current item-menu manager word at +0. In mode 4, sums word +4 for + * kind-10 records among exactly 75 entries at manager +0x104, stride 16, then adds the bag-currency result + * from 5D3D4. In every other mode, returns 5D404 directly, which sums the 75-entry stash at base *(u8 + * **)0x030034E0 + 0x2E0. This is a mode-dependent currency total, not an unconditional bag-plus-stash sum. The + * original performs low-32-bit word additions without saturation or capacity checks. */ +u32 sub_0808543C(void) +{ + u8 *base = (u8 *)gUnk_03006440; + u32 total; + if (*(u32 *)base == 4) { + u8 *entry; + u32 i; + u32 subtotal = 0; + i = 0; + entry = base + 0x104; + for (; i <= 0x4A; i++) { + if (*(u16 *)entry == 0xA) + subtotal += *(u32 *)(entry + 4); + entry += 0x10; + } + total = subtotal; + total += sub_0805D3D4(); + } else { + total = sub_0805D404(); + } + return total; +} +/* [ClearAndFreeItemMenuManager] Unconditionally loads pointer global0x03006440, writes word0 at pointee+0, + * frees pointee with0x08001538 and clears pointer global. Original instructions have no null check despite + * empty conditional in source. Registered finalizer by0x08084EAC for shared manager menu task0x0807A5D4. No + * pool wait, task cancellation or other field cleanup here. Complete original configured body and literals + * audited against ROM; copied verified-main ELF static equality, no local build or runtime test. */ +void sub_08085484(void) +{ + s32 p = gUnk_03006440; + if (p) + { + } + *((s32 *) p) = 0; + sub_08001538(p); + gUnk_03006440 = 0; +} +/* [FreeInventoryMenuManager] Loads pointer global0x03006440, calls heap free0x08001538, then clears global + * pointer. Does not write pointee first or test null. Original0x08084F24 registers it as finalizer of + * confirmed TaskInventoryMenu0x0807B7B4. Does not itself cancel tasks or free pool. Complete original + * configured body and literals audited against ROM; copied verified-main ELF static equality, no local build + * or runtime test. */ +void sub_080854A0(void) { + sub_08001538(gUnk_03006440); + gUnk_03006440 = 0; +} +/* [ClearHeldItemMenuRecord] Fills the 16-byte held-item record at menu manager +0xF4 with zero using CpuSet + * control 0x05000004, then reloads global 03006440 and writes word 22 at manager +0x1C and word zero at +0x20. + * Matched inventory movement/sale helpers and original 7C29C item-validation paths identify these as the held + * record and its source/index fields. It does not restore or transfer the item to another location, free the + * manager or clear the separate +0x18 interaction state. No direct caller or runtime reachability is + * established by this row. */ +void sub_080854B8(void) +{ + u32 zero = 0; + u8 *p; + CpuSet(&zero, (void *)(gUnk_03006440 + 0xF4), 0x05000004); + p = (u8 *)gUnk_03006440; + *(u32 *)(p + 0x1C) = 0x16; + *(u32 *)(p + 0x20) = 0; +} +/* [CountDecimalDigitsCappedAtSix] Unsigned full-word r0 value. Starts result6 and compares + * thresholds100000,10000,1000,100,10,1 from word table0x084EBD4C offsets16..36. Decrements while + * threshold>value, returning0 for zero,1..5 for1..99999, and6 for every value>=100000 including values with + * more than six decimal digits. No mutation or division. This is a capped display-width helper, not a true + * unbounded digit count. Complete original configured body and literals audited against ROM; copied + * verified-main ELF static equality, no local build or runtime test. */ +s32 sub_080854E8(u32 value) +{ + s32 result = 6; + const u32 *p; + u32 i = 4; + if (gUnk_084EBD4C[4] > value) { + p = &gUnk_084EBD4C[4]; + do { + p++; + i++; + result--; + } while (i <= 9 && *p > value); + } + return result; +} +/* [ClearAndFreeFullScreenItemMenuManager] Unconditionally loads shared item-menu pointer global0x03006440, + * writes word0 at pointee+0, calls heap free0x08001538, then clears pointer global. No null check or + * nested-pool cleanup. Original0x08084F9C registers as finalizer of full-screen item-menu callback0x08082BB0, + * which selects manager modes3/4/5/6 from its incoming mode. Same operation sequence as0x08085484 but distinct + * canonical entry and registration; raw bytes differ because the relative call to heap free has a different + * displacement. No collection-only domain is established. Complete original configured body and literals + * audited against ROM; copied verified-main ELF static equality, no local build or runtime test. */ +void sub_08085518(void) +{ + s32 p = gUnk_03006440; + { + *((s32 *) p) = 0; + } + sub_08001538(p); + gUnk_03006440 = 0; +} +extern u16 flags85534 asm("gUnk_03001308"); +void sub_08065230(void *, s32, s32, u16, s32); +/* [TaskAnimateSkillIncreaseIndicator] Task receives full-word x/y in r0/r1, gets shared sprite context, starts + * song 0x25, then performs exactly 30 iterations. Each clears halfword global 0x03001308 bits 0x30, decrements + * y when global tick word &3 is zero, advances descriptor 14 with two u16 local animation counters, draws + * descriptor 14 at x/y using first counter, and yields. Finally clears current task control word+8. + * Coordinates and input-mask side effects are explicit; no claim of resource freeing or runtime visual + * confirmation. Complete original configured body and literal use audited against EU ROM; copied verified-main + * ELF equality is static corroboration, not a new build or runtime test. */ +void sub_08085534(s32 arg0, s32 arg1) +{ + u16 a; + u16 b; + void *ctx; + u16 i; + ctx = sub_080653CC(); + sub_0805865C(0x25); + a = 0; + b = 0; + i = 0x1D; + do { + flags85534 &= 0xFFCF; + if ((gUnk_03002344 & 3) == 0) arg1--; + sub_08065370(ctx, 0xE, (s32)&a, (s32)&b, 1); + sub_08065230(ctx, arg0, arg1, 0xE, a); + sub_080003F0(); + i--; + } while (i != 0xFFFF); + *(u32 *)(sub_0800048C() + 8) = 0; +} +struct Shop6478 { + u32 running; + s32 cat; + s32 cursor; + s32 shown; + s32 index; + u32 grid; + u32 mode; + u32 unk1C; + u32 unk20; + s16 x; + s16 y; + s16 tx; + s16 ty; + u8 sprite[0x34]; +}; +struct Save855D4 { + u8 pad0[SAVE_FIELD(0x150)]; + struct { u16 type; u16 id; u8 pad[0xC]; } slots[25]; + u8 pad2E0[0xC10 - 0x2E0]; + u8 counts[1]; +}; +struct Item855D4 { +#ifdef REGION_USA + u16 names[6][31]; +#endif + s16 unk0, unk2, unk4, unk6, unk8; + u8 padA[6]; s32 unk10; s16 unk14, unk16, unk18, unk1A, unk1C, unk1E; u8 pad20[2]; @@ -8045,7 +10282,7 @@ struct Win855D4 { s16 atk; s16 def; u8 pad1D0[0x204 - 0x1D0]; - u8 item[0xD8]; + u8 item[sizeof(struct Item855D4)]; u8 pad2DC[4]; }; struct Sprite855D4 { u8 pad0[0xC]; u32 unkC; u8 pad10[0xC]; u8 unk1C; u8 pad1D[0x34 - 0x1D]; }; @@ -8067,56 +10304,568 @@ extern const struct Item855D4 gItemsB855D4[] asm("gUnk_0848529C"); extern const u32 gAnim855D4[][0x16] asm("gUnk_08479140"); extern const u16 gGridText855D4[] asm("gUnk_084ECE74"); -extern void f855_009F8(s32, s32, s32) asm("sub_080009F8"); -extern void f855_009C0(s32, s32, s32) asm("sub_080009C0"); -extern void f855_00AA8(u16, u32 *) asm("sub_08000AA8"); -extern void f855_0B650(s32, s32, s32, u16, u16) asm("sub_0800B650"); -extern void f855_0B7DC(s32, s32, s32, u16, u16) asm("sub_0800B7DC"); -extern void f855_0CF90(void) asm("sub_0800CF90"); -extern s32 f855_1A664(s32, s32) asm("sub_0801A664"); -extern s32 f855_003F0(void) asm("sub_080003F0"); -extern s32 f855_65158(void *, u32, s32, s32, s32) asm("sub_08065158"); -extern u32 f855_008C8(void) asm("sub_080008C8"); -extern void f855_1AA34(s32) asm("sub_0801AA34"); -extern void f855_1AA8C(s32) asm("sub_0801AA8C"); -extern s32 f855_1AAE0(void) asm("sub_0801AAE0"); -extern s32 f855_0CDF8(void) asm("sub_0800CDF8"); -extern void f855_0CCB8(void) asm("sub_0800CCB8"); -extern void f855_0CE54(void) asm("sub_0800CE54"); -extern void f855_659F4(s32 *, s32, s32, s32) asm("sub_080659F4"); -extern void f855_65230(void *, s32, s32, u16, s32) asm("sub_08065230"); -extern void f855_5865C(s32) asm("sub_0805865C"); -extern s32 f855_020F4(void) asm("sub_080020F4"); -extern u8 *f855_07290(s32) asm("sub_08007290"); -extern void f855_00AF0(u32, const void *, u32) asm("sub_08000AF0"); -extern void f855_CpuSet(const void *, void *, u32) asm("CpuSet"); -extern void f855_00C08(s16, s16) asm("sub_08000C08"); -extern s32 f855_58DB0(void) asm("sub_08058DB0"); -extern s32 f855_021A8(void) asm("sub_080021A8"); -extern s32 f855_5AB20(void *) asm("sub_0805AB20"); -extern s32 f855_0CE30(void) asm("sub_0800CE30"); -extern void f855_1A3D0(const u8 *, u16, u16) asm("sub_0801A3D0"); -extern void *f855_memcpy(void *, const void *, u32) asm("memcpy"); -extern void f855_1C8F0(struct Win855D4 *) asm("sub_0801C8F0"); -extern void f855_5FB7C(s32, s32, s32, s32) asm("sub_0805FB7C"); -extern u32 f855_1A638(u8 *) asm("sub_0801A638"); -extern void f855_659BC(void *, s32, s32, u16, s32, s32) asm("sub_080659BC"); -extern void f855_1ABE8(s32) asm("sub_0801ABE8"); -extern void f855_57624(u16) asm("sub_08057624"); -extern s32 f855_0CFA4(void) asm("sub_0800CFA4"); -extern void f855_00420(s32) asm("sub_08000420"); +extern void f855_009F8(s32, s32, s32) asm("sub_080009F8"); +extern void f855_009C0(s32, s32, s32) asm("sub_080009C0"); +extern void f855_00AA8(u16, u32 *) asm("sub_08000AA8"); +extern void f855_0B650(s32, s32, s32, u16, u16) asm("sub_0800B650"); +extern void f855_0B7DC(s32, s32, s32, u16, u16) asm("sub_0800B7DC"); +extern void f855_0CF90(void) asm("sub_0800CF90"); +extern s32 f855_1A664(s32, s32) asm("sub_0801A664"); +extern s32 f855_003F0(void) asm("sub_080003F0"); +extern s32 f855_65158(void *, u32, s32, s32, s32) asm("sub_08065158"); +extern u32 f855_008C8(void) asm("sub_080008C8"); +extern void f855_1AA34(s32) asm("sub_0801AA34"); +extern void f855_1AA8C(s32) asm("sub_0801AA8C"); +extern s32 f855_1AAE0(void) asm("sub_0801AAE0"); +extern s32 f855_0CDF8(void) asm("sub_0800CDF8"); +extern void f855_0CCB8(void) asm("sub_0800CCB8"); +extern void f855_0CE54(void) asm("sub_0800CE54"); +extern void f855_659F4(s32 *, s32, s32, s32) asm("sub_080659F4"); +extern void f855_65230(void *, s32, s32, u16, s32) asm("sub_08065230"); +extern void f855_5865C(s32) asm("sub_0805865C"); +extern s32 f855_020F4(void) asm("sub_080020F4"); +extern u8 *f855_07290(s32) asm("sub_08007290"); +extern void f855_00AF0(u32, const void *, u32) asm("sub_08000AF0"); +extern void f855_CpuSet(const void *, void *, u32) asm("CpuSet"); +extern void f855_00C08(s16, s16) asm("sub_08000C08"); +extern s32 f855_58DB0(void) asm("sub_08058DB0"); +extern s32 f855_021A8(void) asm("sub_080021A8"); +extern s32 f855_5AB20(void *) asm("sub_0805AB20"); +extern s32 f855_0CE30(void) asm("sub_0800CE30"); +extern void f855_1A3D0(const u8 *, u16, u16) asm("sub_0801A3D0"); +extern void *f855_memcpy(void *, const void *, u32) asm("memcpy"); +extern void f855_1C8F0(struct Win855D4 *) asm("sub_0801C8F0"); +extern void f855_5FB7C(s32, s32, s32, s32) asm("sub_0805FB7C"); +extern u32 f855_1A638(u8 *) asm("sub_0801A638"); +extern void f855_659BC(void *, s32, s32, u16, s32, s32) asm("sub_080659BC"); +extern void f855_1ABE8(s32) asm("sub_0801ABE8"); +extern void f855_57624(u16) asm("sub_08057624"); +extern s32 f855_0CFA4(void) asm("sub_0800CFA4"); +extern void f855_00420(s32) asm("sub_08000420"); + +void sub_080855D4_v(void) asm("sub_080855D4"); + +/* [TaskMonsterCardCatalogAndBagTransfer] No meaningful arguments or return. Before menu, scans25 bag records + * at saved-character+0x150 and deposits kind8 records into byte counts at+0xC10 by item-id when existing + * count<=98, increments to at most99, clears only kind/id halfwords of deposited bag records. Deposits occur + * before cancellation and are not rolled back. Animates deposited records, then browses category + * table0x084ECC2C with end-category100, localized resource0x120000 names/details and per-id owned counts. + * Modes0 category list,1 detail,3 detail-field grid; grid13 A constructs kind8/id record and attempts + * TryAddItemToBag, decrements collection count only on success. No spending currency or purchase logic. */ +void sub_080855D4_v(void) +{ +#ifdef REGION_USA + TextChar name[0x20]; + TextChar desc[3][0x20]; + u8 pad_c8[0x28]; + struct Win855D4 winBuf; + struct Sprite855D4 spriteB; + u8 spriteA[0x34]; + struct { u16 type; u16 id; u8 pad[0xC]; } use; + struct { s32 x; s32 y; } pts[25]; + s32 speed[25]; + s32 pos[25]; + u8 state[25]; + u16 zero; + union { struct { u32 cnt:16; u32 spare:16; } bits; u16 half; u32 word; } bg; + s32 ox; + s32 oy; + u32 count; + u32 last; + u8 *text; + const TextChar *s; + u8 *data; + u8 *pal; + u32 n; + u32 i; + u32 j; + TextChar c; + TextChar c2; + + f855_009F8(0x200, 0, 1); + f855_009C0(0x1D00, 0, 1); + bg.bits.cnt = 0x1E00; + f855_00AA8(3, &bg.word); + gBgOfs855D4[1] = 0; + gBgOfs855D4[0] = 0; + gBgOfs855D4[3] = 0; + gBgOfs855D4[2] = 0; + gBgOfs855D4[5] = 0; + gBgOfs855D4[4] = 0; + gBgOfs855D4[7] = 0; + gBgOfs855D4[6] = 0; + f855_0B650(0x47, 0x1E, 0x06000000, 0, 0xF); + f855_0CF90(); + f855_1A664(0, 0x14); + f855_003F0(); + f855_003F0(); + f855_1A664(0, 0x14); + f855_003F0(); + + n = 0; + for (i = 0; i <= 0x18; i++) { + if (gSave855D4->slots[i].type == 8) { + if (gSave855D4->counts[gSave855D4->slots[i].id] <= 0x62) { + gSave855D4->counts[gSave855D4->slots[i].id]++; + gSave855D4->slots[i].type = 0; + gSave855D4->slots[i].id = 0; + n++; + } + } + } + f855_65158(spriteA, RES_ID(0x500AF), 1, -1, 0); + for (i = 0; i < n; i++) { + j = f855_008C8() & 0xFF; + pts[i].x = gSin855D4[j + 0x40] * 0xF0 + 0x78; + pts[i].y = gSin855D4[j] * 0xF0 + 0x50; + pos[i] = 0; + speed[i] = (f855_008C8() & 0xF) + 8; + state[i] = 0; + } + f855_1AA34(0x1E); + while (f855_1AAE0() == 0) { + if (f855_0CDF8() != 0) + { + f855_0CCB8(); + f855_0CE54(); + return; + } + f855_003F0(); + } + while (!(gKeys855D4 & 1)) { + if (f855_0CDF8() != 0) + { + f855_0CCB8(); + f855_0CE54(); + return; + } + for (i = 0; i < n; i++) { + f855_659F4(&ox, pts[i].x, 0x7800, pos[i]); + f855_659F4(&oy, pts[i].y, 0x5000, pos[i]); + if (state[i] != 2) + f855_65230(spriteA, ox >> 8, oy >> 8, 0, 0x1D); + pos[i] += speed[i]; + if (pos[i] > 0x200 && state[i] == 0) { + f855_5865C(0x60); + state[i] = 1; + } + if (pos[i] > 0x3FF) { + pos[i] = 0x400; + speed[i] = 0; + state[i] = 2; + } + } + f855_003F0(); + if (gKeys855D4 & 2) + goto exit; + } + f855_5865C(0x177); + f855_1AA8C(0x3C); + /* item is scoped to the shop loops: its later pseudo number puts the GCSE + temps for item+0xD4/+0xD6 before the winBuf.def address (ROM slot order). */ + { + const struct Item855D4 *item; + + while (f855_1AAE0() == 0) { + for (i = 0; i < n; i++) { + f855_659F4(&ox, pts[i].x, 0x7800, pos[i]); + f855_659F4(&oy, pts[i].y, 0x5000, pos[i]); + if (state[i] == 0) + f855_65230(spriteA, ox >> 8, oy >> 8, 0, 0x1D); + pos[i] += speed[i]; + if (pos[i] > 0x3FF) { + pos[i] = 0x400; + if (state[i] == 0) { + f855_5865C(0x60); + state[i] = 1; + speed[i] = 0; + } + } + } + f855_003F0(); + } + f855_020F4(); + f855_0B7DC(0x2E, 0x1A, 0x06000000, 0, 1); + f855_0B650(0x30, 0x1B, 0x06000000, 0, 1); + f855_0B650(0x2F, 0x1E, 0x06000000, 0, 1); + f855_0B650(0x31, 0x1F, 0x06000000, 0, 2); + f855_0B650(0x49, 0x1D, 0x06000000, 0, 0xF); + pal = f855_07290(0x7000B); + f855_00AF0(0xF, pal + 0x1E0, 1); + f855_65158(gShop855D4->sprite, 0x50006, 0, -1, 0); + f855_009F8(0x200, 0, 1); + f855_009C0(0x1F00, 0, 1); + bg.bits.cnt = 0x5A01; + f855_00AA8(1, &bg.word); + bg.bits.cnt = 0x5E01; + f855_00AA8(2, &bg.word); + bg.bits.cnt = 0x1D03; + f855_00AA8(3, &bg.word); + gShop855D4->mode = 0; + gShop855D4->cat = 0; + gShop855D4->cursor = 0; + gShop855D4->index = 0; + gShop855D4->running = 1; + gShop855D4->grid = 0; + for (j = 0; j <= 7; j++) { + winBuf.slots[j].id = 0xFFFF; + zero = 0; + f855_CpuSet(&zero, winBuf.slots[j].data, 0x01000018); + } + for (count = 0; gTab855D4[count][1] != 0x64; count++) + last = gTab855D4[count][1]; + f855_003F0(); + f855_1A664(0, 0x13); + f855_003F0(); + f855_00C08(0xC, 2); + f855_1AA34(0x14); -void sub_080855D4_v(void) asm("sub_080855D4"); + while (gShop855D4->running != 0) { + s32 r = f855_0CDF8(); + if (r != 0) + { + f855_0CCB8(); + f855_0CE54(); + return; + } + if (f855_1AAE0() == 0 || f855_58DB0() != 0) { + gKeys855D4 = r; + gRep855D4 = r; + gKey130C855D4 = r; + } + if (f855_021A8() != 0) + return; + switch (gShop855D4->mode) { + case 0: + if (gRep855D4 & 0x80) { + if (gTab855D4[gShop855D4->index + gShop855D4->cursor + 1][1] == gShop855D4->cat) { + gShop855D4->cursor++; + f855_5865C(0xE); + } + } else if (gRep855D4 & 0x40) { + if (gShop855D4->cursor != 0) { + gShop855D4->cursor--; + f855_5865C(0xE); + } + } else if (gKeys855D4 & 0x100) { + f855_5865C(0x177); + if (++gShop855D4->cat > last) + gShop855D4->cat = 0; + for (i = 0; gTab855D4[i][1] != gShop855D4->cat; i++) + ; + gShop855D4->index = i; + f855_1A664(0, 0x13); + gShop855D4->cursor = 0; + } else if (gKeys855D4 & 0x200) { + f855_5865C(0x177); + if (--gShop855D4->cat < 0) + gShop855D4->cat = last; + for (i = 0; gTab855D4[i][1] != gShop855D4->cat; i++) + ; + gShop855D4->index = i; + f855_1A664(0, 0x13); + gShop855D4->cursor = 0; + } else if (gKeys855D4 & 1) { + f855_5865C(0xF); + gShop855D4->index += gShop855D4->cursor; + gShop855D4->shown = gShop855D4->index + 1; + gShop855D4->mode = 1; + f855_1A664(0, 0x13); + } else if (gKeys855D4 & 2) { + f855_5865C(0x10); + gShop855D4->running = 0; + } + break; + case 1: + if (gKeys855D4 & 1) { + gShop855D4->mode = 3; + f855_5865C(0xF); + } else if (gKeys855D4 & 2) { + for (i = 0; gTab855D4[i][1] != gShop855D4->cat; i++) + ; + gShop855D4->index = i; + gShop855D4->mode = 0; + f855_1A664(0, 0x13); + f855_5865C(0x10); + } else if (gRep855D4 & 0x20) { + if (--gShop855D4->index < 0) + gShop855D4->index = 0; + f855_5865C(0x177); + } else if (gRep855D4 & 0x10) { + if (++gShop855D4->index >= count) + gShop855D4->index = count - 1; + f855_5865C(0x177); + } else if (gKeys855D4 & 0x177) { + gShop855D4->index += 10; + if (gShop855D4->index >= count) + gShop855D4->index = count - 1; + f855_5865C(0x177); + } else if (gKeys855D4 & 0x200) { + gShop855D4->index -= 10; + if (gShop855D4->index < 0) + gShop855D4->index = 0; + f855_5865C(0x177); + } + break; + case 3: + if (gKeys855D4 & 1) { + if (gShop855D4->grid == 0xD + && gSave855D4->counts[gTab855D4[gShop855D4->index][0]] != 0) { + use.type = 8; + use.id = gTab855D4[gShop855D4->index][0]; + if (f855_5AB20(&use) != 0) { + s32 k; + gSave855D4->counts[gTab855D4[gShop855D4->index][0]]--; + k = gShop855D4->index; + gShop855D4->shown = k + 1; + if (gSave855D4->counts[gTab855D4[k][0]] == 0) + gShop855D4->mode = 1; + f855_5865C(0x26); + } else { + f855_5865C(0x61); + } + } + } else if (gKeys855D4 & 2) { + gShop855D4->shown = gShop855D4->index + 1; + gShop855D4->mode = 1; + f855_5865C(0xE); + } else if (gRep855D4 & 0x20) { + gShop855D4->grid &= ~1; + f855_5865C(0xE); + } else if (gRep855D4 & 0x10) { + gShop855D4->grid |= 1; + f855_5865C(0xE); + } else if (gRep855D4 & 0x40) { + if (gShop855D4->grid > 1) { + gShop855D4->grid -= 2; + f855_5865C(0xE); + } + } else if (gRep855D4 & 0x80) { + if (gShop855D4->grid <= 0xB) { + gShop855D4->grid += 2; + f855_5865C(0xE); + } + } + break; + } -/* [TaskMonsterCardCatalogAndBagTransfer] No meaningful arguments or return. Before menu, scans25 bag records - * at saved-character+0x150 and deposits kind8 records into byte counts at+0xC10 by item-id when existing - * count<=98, increments to at most99, clears only kind/id halfwords of deposited bag records. Deposits occur - * before cancellation and are not rolled back. Animates deposited records, then browses category - * table0x084ECC2C with end-category100, localized resource0x120000 names/details and per-id owned counts. - * Modes0 category list,1 detail,3 detail-field grid; grid13 A constructs kind8/id record and attempts - * TryAddItemToBag, decrements collection count only on success. No spending currency or purchase logic. */ -void sub_080855D4_v(void) -{ + switch (gShop855D4->mode) { + case 0: + gBgOfs855D4[2] = 0; + gBgOfs855D4[3] = 0; + gBgOfs855D4[4] = 0; + gBgOfs855D4[5] = 0; + for (i = 0; gTab855D4[gShop855D4->index + i][1] == gShop855D4->cat; i++) { + if (gSave855D4->counts[gTab855D4[gShop855D4->index + i][0]] != 0) { + data = f855_07290(gTab855D4[gShop855D4->index + i][0] | 0x120000); + if (f855_0CE30() != 0) + s = gItemsB855D4[*(u16 *)(data + 0x176)].names[gLang855D4]; + else + s = gItemsA855D4[*(u16 *)(data + 0x176)].names[gLang855D4]; + } else { + s = gNoItem855D4.names[gLang855D4]; + } + j = 0; + c = *s; + while (c != 0) { + name[j] = c; + j++; + s++; + c = *s; + } + name[j] = TEXT_CTRL(0xFD); + f855_1A3D0((u8 *)name, 5, i * 2 + 2); + } + gShop855D4->tx = 0x20; + gShop855D4->ty = gShop855D4->cursor * 16 + 0x18; + f855_65230(gShop855D4->sprite, gShop855D4->x, gShop855D4->y, 0x15, 0); + gShop855D4->shown = 0x64; + { + s32 t = gShop855D4->cursor + 1; + f855_5FB7C(0xE, 0x13, gShop855D4->index + t, 0); + } + f855_5FB7C(0x12, 0x13, count, 0); + break; + case 3: + { + u32 g = gShop855D4->grid; + gShop855D4->tx = (g & 1) * 0x48 + 0x74; + gShop855D4->ty = (g >> 1) * 8 + 0x24; + } + case 1: + gBgOfs855D4[4] = 0x100; + gBgOfs855D4[5] = 0; + gBgOfs855D4[2] = 0x100; + gBgOfs855D4[3] = 0; + if (gShop855D4->shown != gShop855D4->index) { + if (gSave855D4->counts[gTab855D4[gShop855D4->index][0]] != 0) { + data = f855_07290(gTab855D4[gShop855D4->index][0] | 0x120000); + if (f855_0CE30() != 0) + item = &gItemsB855D4[*(u16 *)(data + 0x176)]; + else + item = &gItemsA855D4[*(u16 *)(data + 0x176)]; + } else { + item = &gNoItem855D4; + } + f855_memcpy(winBuf.item, item, sizeof(struct Item855D4)); + s = item->names[gLang855D4]; + j = 0; + c2 = *s; + while (c2 != 0) { + name[j] = c2; + j++; + s++; + c2 = *s; + } + name[j] = TEXT_CTRL(0xFD); + data = f855_07290(gTab855D4[gShop855D4->index][0] | 0x120000); + text = f855_07290(*(u16 *)(data + 0x17A) | 0x140000); + s = (TextChar *)(text + TEXT_HEADER); + i = 0; + j = 0; + while (*s != TEXT_CTRL(0xFD)) { + if (*s == TEXT_CTRL(0xFF)) { + desc[i][j] = TEXT_CTRL(0xFD); + i++; + j = 0; + } else { + desc[i][j] = *s; + j++; + } + s++; + } + desc[i][j] = TEXT_CTRL(0xFD); + f855_1C8F0(&winBuf); + f855_5FB7C(0x14, 4, winBuf.atk, 0); + f855_5FB7C(0x14, 5, winBuf.def, 0); + f855_5FB7C(0x14, 6, item->unk8, 0); + f855_5FB7C(0x14, 7, item->unk0, 0); + f855_5FB7C(0x14, 8, item->unk2, 0); + f855_5FB7C(0x14, 9, item->unk4, 0); + f855_5FB7C(0x14, 0xA, item->unk6, 0); + f855_5FB7C(0x1B, 4, item->unk14, 0); + f855_5FB7C(0x1B, 5, item->unk16, 0); + f855_5FB7C(0x1B, 6, item->unk18, 0); + f855_5FB7C(0x1B, 7, item->unk1A, 0); + f855_5FB7C(0x1B, 8, item->unk1C, 0); + f855_5FB7C(0x1B, 9, item->unk1E, 0); + gShop855D4->shown = gShop855D4->index; + f855_65158(&spriteB, gAnim855D4[item->unkD4 + 0xA][0], 4, -1, 0); + spriteB.unk1C = 4; + f855_00AF0(0x14, (void *)(spriteB.unkC + (item->unkD6 << 5)), 1); + f855_5FB7C(0xE, 0x13, gShop855D4->index + 1, 0); + f855_5FB7C(0x12, 0x13, count, 0); + f855_5FB7C(0x1B, 0xB, gSave855D4->counts[gTab855D4[gShop855D4->index][0]], 0); + } + f855_5FB7C(0x11, 0xC, item->unk6 * 3, 0); + f855_5FB7C(0x11, 0xD, item->unk4 * 2, 0); + f855_5FB7C(9, 0xD, item->unk10, 0); + if (item->unk22 != 0) { + switch (item->unk22) { + case 1: + text = f855_07290(0x140541); + break; + case 2: + text = f855_07290(0x140540); + break; + } + s = (TextChar *)(text + TEXT_HEADER); + if (gSave855D4->counts[gTab855D4[gShop855D4->index][0]] != 0) + f855_1A3D0((u8 *)s, 0x12, 0xC); + } + f855_1A3D0((u8 *)name, 0x10 - (f855_1A638((u8 *)name) >> 1), 1); + f855_659BC(gShop855D4->sprite, 0xBC, 0x55, 0x25, 0, 1); + if (gShop855D4->mode == 3) { + if (gShop855D4->grid == 0xD) + f855_65230(gShop855D4->sprite, gShop855D4->x, gShop855D4->y + 8, 0xB, 0); + else + f855_65230(gShop855D4->sprite, gShop855D4->x, gShop855D4->y, 0xB, 0); + if (gShop855D4->grid <= 0xC) { + f855_1A664(0xF, 4); + text = f855_07290(gGridText855D4[gShop855D4->grid] | 0x140000); + f855_1A3D0(text + TEXT_HEADER, 2, 0xF); + } else { + f855_1A664(0xF, 4); + text = f855_07290(0x140542); + s = (TextChar *)(text + TEXT_HEADER); + i = 0; + j = 0; + while (*s != TEXT_CTRL(0xFD)) { + if (*s == TEXT_CTRL(0xFF)) { + desc[i][j] = TEXT_CTRL(0xFD); + i++; + j = 0; + } else { + desc[i][j] = *s; + j++; + } + s++; + } + desc[i][j] = TEXT_CTRL(0xFD); + f855_1A3D0((u8 *)desc[0], 2, 0xF); + f855_1A3D0((u8 *)desc[1], 2, 0x11); + } + } else if (gSave855D4->counts[gTab855D4[gShop855D4->index][0]] != 0) { + f855_1A3D0((u8 *)desc[0], 2, 0xF); + f855_1A3D0((u8 *)desc[1], 2, 0x11); + } else { + f855_1A664(0xF, 4); + } + { + if (gSave855D4->counts[gTab855D4[gShop855D4->index][0]] != 0) { + switch (gTab855D4[gShop855D4->index][0]) { + case 0x75: + case 0x76: + case 0x77: + f855_659BC(&spriteB, 0x34, 0x48, 0, 0, 3); + break; + case 0x66: + case 0x67: + case 0x68: + f855_659BC(&spriteB, 0x34, 0x5C, 0, 0, 3); + break; + case 0x90: + f855_659BC(&spriteB, 0x34, 0x59, 0, 0, 3); + break; + case 0x84: + case 0x85: + case 0x86: + f855_659BC(&spriteB, 0x34, 0x56, 0, 0, 3); + break; + default: + switch (item->unk45) { + case 0: + f855_659BC(&spriteB, 0x34, 0x50, 0, 0, 3); + break; + case 1: + f855_659BC(&spriteB, 0x34, 0x56, 0, 0, 3); + break; + case 2: + f855_659BC(&spriteB, 0x34, 0x5C, 0, 0, 3); + break; + } + break; + } + } + } + break; + } + gShop855D4->x += (gShop855D4->tx - gShop855D4->x) / 2; + gShop855D4->y += (gShop855D4->ty - gShop855D4->y) / 2; + f855_003F0(); + } + } +exit: + f855_1ABE8(6); + while (f855_1AAE0() == 0) + f855_003F0(); + f855_57624(0x1E); + pal = f855_07290(0x70003); + f855_00AF0(0xF, pal + 0x1E0, 1); + f855_1A664(0, 0x14); + f855_0CFA4(); + f855_00420(0x11201100); +#else u8 name[0x20]; u8 desc[5][0x20]; u8 pad_c8[8]; @@ -8644,6 +11393,7 @@ void sub_080855D4_v(void) f855_1A664(0, 0x14); f855_0CFA4(); f855_00420(0x11201100); +#endif } /* [FreeMonsterCardCatalogManager] No arguments or meaningful return. Frees current pointer global0x03006478 * then clears it; no null check, pointee-zeroing, nested cleanup or task cancellation.0x080867F8 registers it @@ -8743,7 +11493,7 @@ void sub_08086860(void) sub_08057624(5); sub_08001538((s32)buf); gUnk_03001250[7] = 200; - obj86860(obj, 0x5011F, 0, 2, 0); + obj86860(obj, RES_ID(0x5011F), 0, 2, 0); sub_0805865C(0x172); sub_0805865C(0x171); sub_0805865C(0x178); @@ -9007,7 +11757,7 @@ void sub_08086860(void) sub_0805865C(0x177); sub_0801AA8C(0x1E); sub_08057624(0x3C); - obj86860(obj, 0x5011E, 0, 2, 0); + obj86860(obj, RES_ID(0x5011E), 0, 2, 0); sub_0800B650(0x45, 0x1E, 0x06000000, 0, 0xF); sub_0801AA34(0x1E); i = 1; @@ -9516,6 +12266,117 @@ extern void fade087A5C(u32, u32, u32, u16, u16, u32) asm("sub_0800903C"); * rows12,14,16,18; mode1 first2 on16,18; mode2 all8 on2..16. Other modes draw no text. */ void sub_08087A5C(u32 msg, u32 arg1) { +#ifdef REGION_USA + TextChar lines[8][32]; + u32 mode; + s16 a; + s16 b; + u32 hi; + u32 row, col; + TextChar *s; + TextChar *d; + u8 *base; + u8 *name; + u8 *name0; + u32 ff, fd; + u32 c; + u32 t; + u32 code; + + row = 0; + hi = arg1 >> 16; + for (; row <= 7; row++) + for (col = 0; col <= 0x1F; col++) + lines[row][col] = TEXT_CTRL(0xFD); + s = (TextChar *)((u8 *)sub_08007290(msg | 0x140000) + TEXT_HEADER); + row = 0; + col = 0; + if (*s != TEXT_CTRL(0xFD)) { + ff = 0xFFFF; asm("" : "+r"(ff)); + fd = 0xFFFD; + base = (u8 *)gUnk_03003CE0; + name0 = base + 2; asm("" : "+r"(name0)); + do { + c = *s; + code = c;asm("" : "+r"(code)); + if (code == ff) { + lines[row][col] = fd; + row++; + col = 0; + } else if (code == TEXT_CTRL(0xFE)) { + lines[row][col] = fd; + row++; + col = 0; + s += 2; + } else if (code == TEXT_CTRL(0xF6)) { + d = (TextChar *)((u8 *)lines + (col * 2 + row * 64)); + if ((t = (*d = *(TextChar *)(col * 2 + (u32)(name0)))) != 0 && t != fd) { + col++; + s--; + } + } else if (code == TEXT_CTRL(0xF4)) { + d = (TextChar *)((u8 *)lines + (col * 2 + row * 64)); + name = base + 0x15a; + if ((t = (*d = *(TextChar *)(col * 2 + (u32)name))) != 0 && t != fd) { + col++; + s--; + } + } else if (code == TEXT_CTRL(0xF3)) { + d = (TextChar *)((u8 *)lines + (col * 2 + row * 64)); + name = base + 0x2b2; + if ((t = (*d = *(TextChar *)(col * 2 + (u32)name))) != 0 && t != fd) { + col++; + s--; + } + } else if (code == TEXT_CTRL(0xF2)) { + d = (TextChar *)((u8 *)lines + (col * 2 + row * 64)); + name = base + 0x40a; + if ((t = (*d = *(TextChar *)(col * 2 + (u32)name))) != 0 && t != fd) { + col++; + s--; + } + } else { + lines[row][col] = c; + col++; + } + s++; + } while (*s != fd); + } + lines[row][col] = TEXT_CTRL(0xFD); + mode = hi; + arg1 &= 0xFFFF; + a = 0; + b = 16; + while (--arg1 != -1) { + fade087A5C(1, 0x3F, 1, a, b, 0); + if (gUnk_03002344 & 0xF) { + if ((s16)++a > 15) + a = 16; + if ((s16)--b <= 0) + b = 0; + } + switch (mode) { + case 0: + text087A5C((u8 *)lines[0], (u16)(15 - ((u32)sub_0801A638((u8 *)lines[0]) >> 1)), 12); + text087A5C((u8 *)lines[1], (u16)(15 - ((u32)sub_0801A638((u8 *)lines[1]) >> 1)), 14); + text087A5C((u8 *)lines[2], (u16)(15 - ((u32)sub_0801A638((u8 *)lines[2]) >> 1)), 16); + text087A5C((u8 *)lines[3], (u16)(15 - ((u32)sub_0801A638((u8 *)lines[3]) >> 1)), 18); + break; + case 1: + text087A5C((u8 *)lines[0], (u16)(15 - ((u32)sub_0801A638((u8 *)lines[0]) >> 1)), 16); + text087A5C((u8 *)lines[1], (u16)(15 - ((u32)sub_0801A638((u8 *)lines[1]) >> 1)), 18); + break; + case 2: + for (row = 0; row <= 7; row++) + text087A5C((u8 *)lines[row], (u16)(15 - ((u32)sub_0801A638((u8 *)lines[row]) >> 1)), (u16)(row * 2 + 2)); + break; + } + if (sub_080021A8() != 0 || sub_0801AAF8() != 0) + break; + sub_080003F0(); + } + close087A5C(0, 0x14); +#else u8 lines[8][32]; s16 a; s16 b; @@ -9620,4 +12481,5 @@ void sub_08087A5C(u32 msg, u32 arg1) sub_080003F0(); } close087A5C(0, 0x14); +#endif } diff --git a/src/code_08087CC0.c b/src/code_08087CC0.c index 8b1bf79d..24098d49 100644 --- a/src/code_08087CC0.c +++ b/src/code_08087CC0.c @@ -543,10 +543,10 @@ u32 sub_08088B6C(u8 *tbl, u32 arg1) u16 zero; for (i = 1, zero = 0; i <= 3; i++) { e = (u16 *)(tbl + (*(u16 *)((u8 *)gUnk_03005CF4 + 0x36) * 36 + 4) + i * 8); - d = (*(s32 *)(p + 0x8C) >> 11) - e[0]; + d = (*(s32 *)(p + PLAYER_FIELD(0x8C)) >> 11) - e[0]; if (d < 0) d = -d; - if (d <= 1 && (*(s32 *)(p + 0x90) >> 11) == e[1]) { + if (d <= 1 && (*(s32 *)(p + PLAYER_FIELD(0x90)) >> 11) == e[1]) { sub_08015ED4(); sub_0801ABE8(3); sub_0800BB40(); @@ -566,19 +566,19 @@ u32 sub_08088B6C(u8 *tbl, u32 arg1) } struct Pos090 { s32 x, y; }; struct Player090 { - u8 pad0[0x1C]; + u8 pad0[PLAYER_FIELD(0x1C)]; u16 w1C; /* 0x1C */ u16 pad1E; u16 state; /* 0x20 */ u16 w22; /* 0x22 */ - u8 pad24[0xC]; + u8 pad24[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x24)]; u32 flags; /* 0x30 */ - u8 pad34[0x34]; + u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 b68; /* 0x68 */ - u8 pad69[0x23]; + u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; struct Pos090 pos8C; /* 0x8C */ struct Pos090 pos94; /* 0x94 */ - u8 pad9C[0x14C - 0x9C]; + u8 pad9C[PLAYER_SIZE - PLAYER_FIELD(0x9C)]; }; extern struct Player090 players090[] asm("gUnk_03003CE0"); struct Warp090 { u16 x, y; }; @@ -636,7 +636,7 @@ s32 sub_08088C24(u8 *arg0) { while (sub_0800BA6C() == 0) sub_080003F0(); { - u8 *q = (0x14C * idx) + playerCoord88C24; + u8 *q = (PLAYER_SIZE * idx) + playerCoord88C24; sub_0800AD04(q, q + 4, sub_0800CCCC()); } { @@ -644,7 +644,7 @@ s32 sub_08088C24(u8 *arg0) { *(u16 *)(gs + 0x10) = 1; *(u16 *)(gs + 0x1C) = 1; } - *(u32 *)((0x14C * idx) + (playerCoord88C24 - 0x5C)) &= 0x2000; + *(u32 *)((PLAYER_SIZE * idx) + (playerCoord88C24 - 0x5C)) &= 0x2000; sub_08067D74(); sub_08057624(0xA); sub_08057328(0, callback2B8A4_090); @@ -747,7 +747,7 @@ s32 sub_08088F30(u8 *arg0) { while (sub_0800BA6C() == 0) sub_080003F0(); { - u8 *q = (0x14C * i) + playerCoord88F30; + u8 *q = (PLAYER_SIZE * i) + playerCoord88F30; sub_0800AD04(q, q + 4, sub_0800CCCC()); } { @@ -877,7 +877,7 @@ s32 sub_08089204(u8 *arg0) { sub_080003F0(); gUnk_03003170.pad76 = 0x20; { - u8 *q = (0x14C * idx) + playerCoord89204; + u8 *q = (PLAYER_SIZE * idx) + playerCoord89204; sub_0800AD04(q, q + 4, sub_0800CCCC()); } { @@ -939,7 +939,7 @@ s32 sub_08089384(u8 *arg0) { while (sub_0800BA6C() == 0) sub_080003F0(); { - u8 *q = (0x14C * idx) + playerCoord89384; + u8 *q = (PLAYER_SIZE * idx) + playerCoord89384; sub_0800AD04(q, q + 4, sub_0800CCCC()); } sub_08057328(0, callback2C674_090); @@ -1033,7 +1033,7 @@ s32 sub_08089500(u8 *arg0) { p->state = 0; players090[idx].flags = (players090[idx].flags & 0xFFFFDFDB) | 2; sub_0802996C(); - spriteInit090(sprite, 0x5008C, 8, -1, 0); + spriteInit090(sprite, RES_ID(0x5008C), 8, -1, 0); sub_08000AF0(0x17, (void *)sprite[3], 2); p->b68 = 1; sub_0806617C(); @@ -1047,7 +1047,7 @@ s32 sub_08089500(u8 *arg0) { while (sub_0800BA6C() == 0) sub_080003F0(); { - u8 *q = (0x14C * idx) + playerCoord89500; + u8 *q = (PLAYER_SIZE * idx) + playerCoord89500; sub_0800AD04(q, q + 4, sub_0800CCCC()); } if (sub_0800CF10() != 0) { @@ -1098,15 +1098,19 @@ s32 sub_08089784(u8 *table) {u32 delta=state978491->row*0x24;delta+=4;position=(u16 *)(table+delta);} sub_0800CCDC(); {u8 *base; register u8 *px asm("r1"); - offset=sub_080020F4();base=players978491;offset*=0x14C;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); +#ifdef REGION_USA + offset=sub_080020F4();base=players978491;offset*=PLAYER_SIZE;{register u8 *xf asm("r3");u8 *yf;xf=base+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)offset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=base+PLAYER_FIELD(0x90);yf=(u8 *)((u32)offset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=base;dst+=PLAYER_FIELD(0x94);offset+=(u32)dst;}*(struct Pos978491 *)offset=*(struct Pos978491 *)xf;}} +#else + offset=sub_080020F4();base=players978491;offset*=PLAYER_SIZE;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); *(u32 *)px=(u32)position[0]<<8; px=base+0x90;px=(u8 *)((u32)offset+(u32)px);*(u32 *)px=(u32)position[1]<<8; offset+=(u32)base;player=(u8 *)offset;*(struct Pos978491 *)(player+0x94)=*(struct Pos978491 *)(player+0x8C);} +#endif sub_08009930(0, 5); while (sub_0800BA6C() == 0) sub_080003F0(); {u8 *p=profile978491; u32 v; p+=0x76;v=0x20;*(u16 *)p=v;} - coordinates = (s32 *)(coords978491 + myId * 0x14C); + coordinates = (s32 *)(coords978491 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callback978491); sub_08015EF8(); @@ -1114,7 +1118,7 @@ s32 sub_08089784(u8 *table) state978491->active = 1; sub_08015C38(); } - {s32 idx=sub_080020F4(); u8 *p=players978491; u32 stride=0x14c; idx*=stride;p+=0x90; + {s32 idx=sub_080020F4(); u8 *p=players978491; u32 stride=PLAYER_SIZE; idx*=stride;p+=PLAYER_FIELD(0x90); idx+=(u32)p; if ((*(s32 *)idx >> 11) > 0x1E) { sub_08015ED4(); sub_0801ABE8(3); @@ -1161,14 +1165,18 @@ s32 sub_080898D4(u8 *input) {u32 delta=state98D491->row*0x24;delta+=4;position=(u16 *)(table+delta);} sub_0800CCDC(); {u8 *base; register u8 *px asm("r1"); - offset=sub_080020F4();base=players98D491;offset*=0x14C;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); +#ifdef REGION_USA + offset=sub_080020F4();base=players98D491;{register u8 *xf asm("r3");register u8 *yf asm("r1");register u8 *b12 asm("ip")=base;offset*=PLAYER_SIZE;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)offset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12;yf+=PLAYER_FIELD(0x90);yf=(u8 *)((u32)offset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);offset+=(u32)dst;}*(struct Pos98D491 *)offset=*(struct Pos98D491 *)xf;}} +#else + offset=sub_080020F4();base=players98D491;offset*=PLAYER_SIZE;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); *(u32 *)px=(u32)position[0]<<8; px=base+0x90;px=(u8 *)((u32)offset+(u32)px);*(u32 *)px=(u32)position[1]<<8; {u8 *p;offset+=(u32)base;p=(u8 *)offset;*(struct Pos98D491 *)(p+0x94)=*(struct Pos98D491 *)(p+0x8C);}} +#endif sub_08009930(0, 0xC); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coords98D491 + myId * 0x14C); + coordinates = (s32 *)(coords98D491 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); state98D491->step = 1; state98D491->active = 1; @@ -1176,13 +1184,13 @@ s32 sub_080898D4(u8 *input) sub_08057328(0, (u32)callback98D491); sub_08015EF8(); } else { - player = players98D491 + sub_080020F4() * 0x14C; + player = players98D491 + sub_080020F4() * PLAYER_SIZE; for (exitIndex = 1; exitIndex <= 3; exitIndex++) { {register u32 row asm("r0")=state98D491->row*0x24;register u32 col asm("r1");row+=4;row=(u32)table+row;col=exitIndex*8;exit=(const struct Exit98D491 *)(row+col);} - difference = (*(s32 *)(player + 0x8C) >> 11) - exit->x; + difference = (*(s32 *)(player + PLAYER_FIELD(0x8C)) >> 11) - exit->x; if (difference < 0) difference = -difference; - if (difference <= 1 && (*(s32 *)(player + 0x90) >> 11) == exit->y) { + if (difference <= 1 && (*(s32 *)(player + PLAYER_FIELD(0x90)) >> 11) == exit->y) { sub_08015ED4(); sub_0801ABE8(3); sub_0800BB40(); @@ -1203,7 +1211,7 @@ s32 sub_080898D4(u8 *input) } } } - {s32 idx=sub_080020F4(); u8 *p=players98D491; u32 stride=0x14c; idx*=stride;p+=0x90; + {s32 idx=sub_080020F4(); u8 *p=players98D491; u32 stride=PLAYER_SIZE; idx*=stride;p+=PLAYER_FIELD(0x90); idx+=(u32)p; if ((*(s32 *)idx >> 11) > 0x11) { sub_08015ED4(); sub_0801ABE8(3); @@ -1231,7 +1239,11 @@ s32 sub_08089AE4(u8 *table) const u16 *position; u8 *player; s32 *coordinates; +#ifdef REGION_USA + register const struct Exit9AE491 *exit asm("r5"); +#else register const struct Exit9AE491 *exit asm("r6"); +#endif u32 exitIndex; u32 zero; s32 difference; @@ -1250,18 +1262,30 @@ s32 sub_08089AE4(u8 *table) myId = sub_080020F4(); {register u32 delta asm("r0")=state9AE491->row*0x24;delta+=4;position=(u16 *)(table+delta);} sub_0800CCDC(); +#ifdef REGION_USA + {u8 *base; register u8 *px asm("r1"); register u32 stride asm("r4"); +#else {u8 *base; register u8 *px asm("r1"); register u32 stride asm("r5"); - offset=sub_080020F4();base=players9AE491;stride=0x14c;offset*=stride;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); +#endif +#ifdef REGION_USA + offset=sub_080020F4();base=players9AE491;stride=PLAYER_SIZE;{register u8 *xf asm("r3");register u8 *yf asm("r1");u8 *b12=base;offset*=stride;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)offset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)offset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);offset+=(u32)dst;}*(struct Pos9AE491 *)offset=*(struct Pos9AE491 *)xf;} +#else + offset=sub_080020F4();base=players9AE491;stride=PLAYER_SIZE;offset*=stride;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); *(u32 *)px=(u32)position[0]<<8; px=base+0x90;px=(u8 *)((u32)offset+(u32)px);*(u32 *)px=(u32)position[1]<<8; {u8 *p;offset+=(u32)base;p=(u8 *)offset;*(struct Pos9AE491 *)(p+0x94)=*(struct Pos9AE491 *)(p+0x8C);} +#endif sub_0800CCDC(); - {u32 *flags;s32 index=myId;index*=stride;base+=0x30;index+=(u32)base;flags=(u32 *)index;*flags &= 0x2000;}} +#ifdef REGION_USA + {u32 *flags;s32 index=myId;index*=stride;{u8 *fb=base;fb+=PLAYER_FIELD(0x30);index+=(u32)fb;}flags=(u32 *)index;*flags &= 0x2000;}} +#else + {u32 *flags;s32 index=myId;index*=stride;base+=PLAYER_FIELD(0x30);index+=(u32)base;flags=(u32 *)index;*flags &= 0x2000;}} +#endif sub_08067D74(); sub_08009930(0, 6); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coords9AE491 + myId * 0x14C); + coordinates = (s32 *)(coords9AE491 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callback9AE491); sub_08015EF8(); @@ -1270,14 +1294,18 @@ s32 sub_08089AE4(u8 *table) sub_08015C38(); return 0; } - player = players9AE491 + sub_080020F4() * 0x14C; + player = players9AE491 + sub_080020F4() * PLAYER_SIZE; +#ifdef REGION_USA + exitIndex=1; +#else exitIndex=1;zero=0; +#endif for (; exitIndex <= 3; exitIndex++) { {register u32 row asm("r0")=state9AE491->row*0x24;register u32 col asm("r1");row+=4;row=(u32)table+row;col=exitIndex*8;exit=(const struct Exit9AE491 *)(row+col);} - difference = (*(s32 *)(player + 0x8C) >> 11) - exit->x; + difference = (*(s32 *)(player + PLAYER_FIELD(0x8C)) >> 11) - exit->x; if (difference < 0) difference = -difference; - if (difference <= 1 && (*(s32 *)(player + 0x90) >> 11) == exit->y) { + if (difference <= 1 && (*(s32 *)(player + PLAYER_FIELD(0x90)) >> 11) == exit->y) { sub_08015ED4(); sub_0801ABE8(3); sub_0800BB40(); @@ -1289,7 +1317,11 @@ s32 sub_08089AE4(u8 *table) else if (exitIndex == 2) state9AE491->row = exitIndex; {struct State9AE491 *p=state9AE491; +#ifdef REGION_USA + p->destination=exit->destination;p->script=scripts9AE491[exit->destination];p->step=0;p->active=0;} +#else p->destination=exit->destination;p->script=scripts9AE491[exit->destination];p->step=zero;p->active=zero;} +#endif return 1; } } @@ -1302,18 +1334,33 @@ s32 sub_08089CA0(u8 *table) struct Pos9CA091 { u32 x, y; }; struct Exit9CA091 { u16 x, y, destination, unused; }; const u16 *position; +#ifndef REGION_USA u8 *player; +#endif s32 *coordinates; +#ifdef REGION_USA + register const struct Exit9CA091 *exit asm("r5"); +#else register const struct Exit9CA091 *exit asm("r4"); +#endif u32 exitIndex; +#ifdef REGION_USA + u8 *player; +#else register u32 zero asm("r8"); +#endif s32 difference; extern struct State9CA091 *state9CA091 asm("gUnk_03005CF4"); extern u8 players9CA091[] asm("gUnk_03003CE0"); extern u8 coords9CA091[] asm("gUnk_03003D6C"); +#ifndef REGION_USA extern u32 scripts9CA091[] asm("gUnk_084F0AC0"); +#endif extern void callback9CA091(void) asm("sub_0802D568"); extern s32 sub_08009930(u32, u32); +#ifdef REGION_USA + extern u32 scripts9CA091[] asm("gUnk_084F0AC0"); +#endif extern s32 sub_0800AD04(s32 *, s32 *, s32); s32 myId; register s32 offset asm("r2"); @@ -1323,17 +1370,29 @@ s32 sub_08089CA0(u8 *table) myId = sub_080020F4(); {register u32 delta asm("r0")=state9CA091->row*0x24;delta+=4;position=(u16 *)(table+delta);} sub_0800CCDC(); +#ifdef REGION_USA + {u8 *base; register u8 *px asm("r1"); register u32 stride asm("r4"); +#else {u8 *base; register u8 *px asm("r1"); u32 stride; - offset=sub_080020F4();base=players9CA091;stride=0x14c;offset*=stride;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); +#endif +#ifdef REGION_USA + offset=sub_080020F4();base=players9CA091;stride=PLAYER_SIZE;{u8 *xf;u8 *yf;u8 *b12 asm("ip")=base;offset*=stride;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)offset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)offset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{u8 *dst=b12;dst+=PLAYER_FIELD(0x94);offset+=(u32)dst;}*(struct Pos9CA091 *)offset=*(struct Pos9CA091 *)xf;} +#else + offset=sub_080020F4();base=players9CA091;stride=PLAYER_SIZE;offset*=stride;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); *(u32 *)px=(u32)position[0]<<8; px=base+0x90;px=(u8 *)((u32)offset+(u32)px);*(u32 *)px=(u32)position[1]<<8; {u8 *p;struct Pos9CA091 *dest;offset+=(u32)base;p=(u8 *)offset;dest=(struct Pos9CA091 *)(p+0x94);*dest=*(struct Pos9CA091 *)(p+0x8C);} - {u32 *flags;s32 index=myId;index*=stride;base+=0x30;index+=(u32)base;flags=(u32 *)index;*flags &= 0x2000;}} +#endif +#ifdef REGION_USA + {u32 *flags;s32 index=myId;u8 *t;index*=stride;t=base+PLAYER_FIELD(0x30);index+=(u32)t;flags=(u32 *)index;*flags &= 0x2000;}} +#else + {u32 *flags;s32 index=myId;index*=stride;base+=PLAYER_FIELD(0x30);index+=(u32)base;flags=(u32 *)index;*flags &= 0x2000;}} +#endif sub_08067D74(); sub_08009930(0, 0xD); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coords9CA091 + myId * 0x14C); + coordinates = (s32 *)(coords9CA091 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08015EF8(); sub_08057328(0, (u32)callback9CA091); @@ -1341,14 +1400,18 @@ s32 sub_08089CA0(u8 *table) state9CA091->active = 1; sub_08015C38(); } else { - player = players9CA091 + sub_080020F4() * 0x14C; + player = players9CA091 + sub_080020F4() * PLAYER_SIZE; +#ifdef REGION_USA + exitIndex=1; +#else exitIndex=1;{register struct State9CA091 **p asm("r6")=&state9CA091;asm("" : "=r"(zero) : "r"(p), "0"(0));} +#endif for (; exitIndex <= 3; exitIndex++) { {register u32 row asm("r0")=state9CA091->row*0x24;register u32 col asm("r1");row+=4;row=(u32)table+row;col=exitIndex*8;exit=(const struct Exit9CA091 *)(row+col);} - difference = (*(s32 *)(player + 0x8C) >> 11) - exit->x; + difference = (*(s32 *)(player + PLAYER_FIELD(0x8C)) >> 11) - exit->x; if (difference < 0) difference = -difference; - if (difference <= 1 && (*(s32 *)(player + 0x90) >> 11) == exit->y) { + if (difference <= 1 && (*(s32 *)(player + PLAYER_FIELD(0x90)) >> 11) == exit->y) { sub_08015ED4(); sub_0801ABE8(3); sub_0800BB40(); @@ -1359,13 +1422,18 @@ s32 sub_08089CA0(u8 *table) state9CA091->row = exitIndex; else if (exitIndex == 2) state9CA091->row = 1; +#ifdef REGION_USA + else state9CA091->row=0; + {struct State9CA091 *p=state9CA091;p->destination=exit->destination;p->script=scripts9CA091[exit->destination];p->step=0;p->active=0;} +#else else {struct State9CA091 *p=state9CA091;u32 z=zero;p->row=z;} {register struct State9CA091 *p asm("r1")=state9CA091;p->destination=exit->destination;p->script=scripts9CA091[exit->destination];p->step=zero;p->active=zero;} +#endif return 1; } } } - {s32 idx=sub_080020F4(); u8 *p=players9CA091; u32 stride=0x14c; idx*=stride;p+=0x90; + {s32 idx=sub_080020F4(); u8 *p=players9CA091; u32 stride=PLAYER_SIZE; idx*=stride;p+=PLAYER_FIELD(0x90); idx+=(u32)p; if ((*(s32 *)idx >> 11) > 0x11) { sub_08015ED4(); sub_0801ABE8(3); @@ -1407,14 +1475,18 @@ s32 sub_08089EC4(u8 *table) {u32 delta=state9EC491->row*0x24;delta+=4;position=(u16 *)(table+delta);} sub_0800CCDC(); {u8 *base; register u8 *px asm("r1"); - offset=sub_080020F4();base=players9EC491;offset*=0x14C;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); +#ifdef REGION_USA + offset=sub_080020F4();base=players9EC491;offset*=PLAYER_SIZE;{register u8 *xf asm("r3");u8 *yf;xf=base+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)offset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=base+PLAYER_FIELD(0x90);yf=(u8 *)((u32)offset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=base;dst+=PLAYER_FIELD(0x94);offset+=(u32)dst;}*(struct Pos9EC491 *)offset=*(struct Pos9EC491 *)xf;}} +#else + offset=sub_080020F4();base=players9EC491;offset*=PLAYER_SIZE;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); *(u32 *)px=(u32)position[0]<<8; px=base+0x90;px=(u8 *)((u32)offset+(u32)px);*(u32 *)px=(u32)position[1]<<8; offset+=(u32)base;player=(u8 *)offset;*(struct Pos9EC491 *)(player+0x94)=*(struct Pos9EC491 *)(player+0x8C);} +#endif sub_08009930(0, 0x10); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coords9EC491 + myId * 0x14C); + coordinates = (s32 *)(coords9EC491 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callback9EC491); sub_08015EF8(); @@ -1422,7 +1494,7 @@ s32 sub_08089EC4(u8 *table) state9EC491->active = 1; sub_08015C38(); } - { s32 idx=sub_080020F4(); u8 *p=players9EC491; u32 stride=0x14c; idx*=stride;p+=0x90; + { s32 idx=sub_080020F4(); u8 *p=players9EC491; u32 stride=PLAYER_SIZE; idx*=stride;p+=PLAYER_FIELD(0x90); idx+=(u32)p; if ((*(s32 *)idx >> 11) > 0x25) { sub_08015ED4(); sub_0801ABE8(3); @@ -1471,14 +1543,18 @@ s32 sub_0808A008(u8 *input) {u32 delta=stateA00891->row*0x24;delta+=4;position=(u16 *)(table+delta);} sub_0800CCDC(); {u8 *base; register u8 *px asm("r1"); - offset=sub_080020F4();base=playersA00891;offset*=0x14C;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); +#ifdef REGION_USA + offset=sub_080020F4();base=playersA00891;{register u8 *xf asm("r3");register u8 *yf asm("r1");register u8 *b12 asm("ip")=base;offset*=PLAYER_SIZE;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)offset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)offset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);offset+=(u32)dst;}*(struct PosA00891 *)offset=*(struct PosA00891 *)xf;}} +#else + offset=sub_080020F4();base=playersA00891;offset*=PLAYER_SIZE;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); *(u32 *)px=(u32)position[0]<<8; px=base+0x90;px=(u8 *)((u32)offset+(u32)px);*(u32 *)px=(u32)position[1]<<8; {u8 *p;offset+=(u32)base;p=(u8 *)offset;*(struct PosA00891 *)(p+0x94)=*(struct PosA00891 *)(p+0x8C);}} +#endif sub_08009930(0, 8); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coordsA00891 + myId * 0x14C); + coordinates = (s32 *)(coordsA00891 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); stateA00891->step = 1; stateA00891->active = 1; @@ -1489,13 +1565,13 @@ s32 sub_0808A008(u8 *input) sub_08015EF8(); sub_08015C38(); } else { - player = playersA00891 + sub_080020F4() * 0x14C; + player = playersA00891 + sub_080020F4() * PLAYER_SIZE; for (exitIndex = 1; exitIndex <= 3; exitIndex++) { {register u32 row asm("r0")=stateA00891->row*0x24;register u32 col asm("r1");row+=4;row=(u32)table+row;col=exitIndex*8;exit=(const struct ExitA00891 *)(row+col);} - difference = (*(s32 *)(player + 0x8C) >> 11) - exit->x; + difference = (*(s32 *)(player + PLAYER_FIELD(0x8C)) >> 11) - exit->x; if (difference < 0) difference = -difference; - if (difference <= 1 && (*(s32 *)(player + 0x90) >> 11) == exit->y) { + if (difference <= 1 && (*(s32 *)(player + PLAYER_FIELD(0x90)) >> 11) == exit->y) { sub_08015ED4(); sub_0801ABE8(3); sub_0800BB40(); @@ -1516,7 +1592,7 @@ s32 sub_0808A008(u8 *input) } } } - {s32 idx=sub_080020F4(); u8 *p; laterBase=playersA00891;laterStride=0x14c;idx*=laterStride;p=laterBase+0x8C; + {s32 idx=sub_080020F4(); u8 *p; laterBase=playersA00891;laterStride=PLAYER_SIZE;idx*=laterStride;p=laterBase+PLAYER_FIELD(0x8C); idx+=(u32)p; if ((*(s32 *)idx >> 11) > 0x1B) { sub_08015ED4(); sub_0801ABE8(3); @@ -1531,7 +1607,7 @@ s32 sub_0808A008(u8 *input) stateA00891->active = 0; return 1; } - {s32 idx=sub_080020F4(); u8 *p; idx*=laterStride;p=laterBase+0x90; + {s32 idx=sub_080020F4(); u8 *p; idx*=laterStride;p=laterBase+PLAYER_FIELD(0x90); idx+=(u32)p; if ((*(s32 *)idx >> 11) > 0x24) { sub_08015ED4(); sub_0801ABE8(3); @@ -1578,7 +1654,10 @@ s32 sub_0808A294(u8 *table) sub_0800CCDC(); playerOffset = sub_080020F4(); playerBase = playersA29491; - playerOffset *= 0x14C; +#ifdef REGION_USA + {register u8 *xf asm("r3");register u8 *yf asm("r1");u8 *b12=playerBase;playerOffset *= PLAYER_SIZE;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)playerOffset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)playerOffset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);playerOffset+=(u32)dst;}*(struct PosA29491 *)playerOffset=*(struct PosA29491 *)xf;} +#else + playerOffset *= PLAYER_SIZE; field = playerBase; field += 0x8C; field = (u8 *)(playerOffset + (u32)field); @@ -1589,10 +1668,11 @@ s32 sub_0808A294(u8 *table) *(u32 *)field = (u32)position[1] << 8; player = (u8 *)(playerOffset + (u32)playerBase); *(struct PosA29491 *)(player + 0x94) = *(struct PosA29491 *)(player + 0x8C); +#endif sub_08009930(0, 0xE); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coordsA29491 + myId * 0x14C); + coordinates = (s32 *)(coordsA29491 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callbackA29491); sub_08015EF8(); @@ -1635,7 +1715,10 @@ s32 sub_0808A380(u8 *table) sub_0800CCDC(); playerOffset = sub_080020F4(); playerBase = playersA38091; - playerOffset *= 0x14C; +#ifdef REGION_USA + {register u8 *xf asm("r3");register u8 *yf asm("r1");u8 *b12=playerBase;playerOffset *= PLAYER_SIZE;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)playerOffset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)playerOffset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);playerOffset+=(u32)dst;}*(struct PosA38091 *)playerOffset=*(struct PosA38091 *)xf;} +#else + playerOffset *= PLAYER_SIZE; field = playerBase; field += 0x8C; field = (u8 *)(playerOffset + (u32)field); @@ -1646,10 +1729,11 @@ s32 sub_0808A380(u8 *table) *(u32 *)field = (u32)position[1] << 8; player = (u8 *)(playerOffset + (u32)playerBase); *(struct PosA38091 *)(player + 0x94) = *(struct PosA38091 *)(player + 0x8C); +#endif sub_08009930(0, 0xB); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coordsA38091 + myId * 0x14C); + coordinates = (s32 *)(coordsA38091 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callbackA38091); sub_08015EF8(); @@ -1661,9 +1745,9 @@ s32 sub_0808A380(u8 *table) } checkOffset = sub_080020F4(); checkBase = playersA38091; - checkStride = 0x14C; + checkStride = PLAYER_SIZE; checkOffset *= checkStride; - checkBase += 0x90; + checkBase += PLAYER_FIELD(0x90); if ((*(s32 *)(checkOffset + (u32)checkBase) >> 11) > 0x25) { sub_08015ED4(); sub_0801ABE8(3); @@ -1711,14 +1795,18 @@ s32 sub_0808A4D4(u8 *input) {u32 delta=stateA4D491->row*0x24;delta+=4;position=(u16 *)(table+delta);} sub_0800CCDC(); {u8 *base; register u8 *px asm("r1"); - offset=sub_080020F4();base=playersA4D491;offset*=0x14C;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); +#ifdef REGION_USA + offset=sub_080020F4();base=playersA4D491;{register u8 *xf asm("r3");register u8 *yf asm("r1");register u8 *b12 asm("ip")=base;offset*=PLAYER_SIZE;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)offset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)offset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);offset+=(u32)dst;}*(struct PosA4D491 *)offset=*(struct PosA4D491 *)xf;}} +#else + offset=sub_080020F4();base=playersA4D491;offset*=PLAYER_SIZE;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); *(u32 *)px=(u32)position[0]<<8; px=base+0x90;px=(u8 *)((u32)offset+(u32)px);*(u32 *)px=(u32)position[1]<<8; {u8 *p;offset+=(u32)base;p=(u8 *)offset;*(struct PosA4D491 *)(p+0x94)=*(struct PosA4D491 *)(p+0x8C);}} +#endif sub_08009930(0, 7); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coordsA4D491 + myId * 0x14C); + coordinates = (s32 *)(coordsA4D491 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); stateA4D491->step = 1; stateA4D491->active = 1; @@ -1726,13 +1814,13 @@ s32 sub_0808A4D4(u8 *input) sub_08057328(0, (u32)callbackA4D491); sub_08015EF8(); } else { - player = playersA4D491 + sub_080020F4() * 0x14C; + player = playersA4D491 + sub_080020F4() * PLAYER_SIZE; for (exitIndex = 1; exitIndex <= 3; exitIndex++) { {register u32 row asm("r0")=stateA4D491->row*0x24;register u32 col asm("r1");row+=4;row=(u32)table+row;col=exitIndex*8;exit=(const struct ExitA4D491 *)(row+col);} - difference = (*(s32 *)(player + 0x8C) >> 11) - exit->x; + difference = (*(s32 *)(player + PLAYER_FIELD(0x8C)) >> 11) - exit->x; if (difference < 0) difference = -difference; - if (difference <= 1 && (*(s32 *)(player + 0x90) >> 11) == exit->y) { + if (difference <= 1 && (*(s32 *)(player + PLAYER_FIELD(0x90)) >> 11) == exit->y) { sub_08015ED4(); sub_0801ABE8(3); sub_0800BB40(); @@ -1753,7 +1841,7 @@ s32 sub_0808A4D4(u8 *input) } } } - {s32 idx=sub_080020F4(); u8 *p; laterBase=playersA4D491;laterStride=0x14c;idx*=laterStride;p=laterBase+0x8C; + {s32 idx=sub_080020F4(); u8 *p; laterBase=playersA4D491;laterStride=PLAYER_SIZE;idx*=laterStride;p=laterBase+PLAYER_FIELD(0x8C); idx+=(u32)p; if ((*(s32 *)idx >> 11) <= 1) { sub_08015ED4(); sub_0801ABE8(3); @@ -1768,7 +1856,7 @@ s32 sub_0808A4D4(u8 *input) stateA4D491->active = 0; return 1; } - {s32 idx=sub_080020F4(); u8 *p; idx*=laterStride;p=laterBase+0x90; + {s32 idx=sub_080020F4(); u8 *p; idx*=laterStride;p=laterBase+PLAYER_FIELD(0x90); idx+=(u32)p; if ((*(s32 *)idx >> 11) > 0x24) { sub_08015ED4(); sub_0801ABE8(3); @@ -1818,7 +1906,10 @@ s32 sub_0808A744(u8 *table) sub_0800CCDC(); playerOffset = sub_080020F4(); playerBase = playersA74491; - playerOffset *= 0x14C; +#ifdef REGION_USA + {register u8 *xf asm("r3");register u8 *yf asm("r1");u8 *b12=playerBase;playerOffset *= PLAYER_SIZE;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)playerOffset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)playerOffset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);playerOffset+=(u32)dst;}*(struct PosA74491 *)playerOffset=*(struct PosA74491 *)xf;} +#else + playerOffset *= PLAYER_SIZE; field = playerBase; field += 0x8C; field = (u8 *)(playerOffset + (u32)field); @@ -1829,10 +1920,11 @@ s32 sub_0808A744(u8 *table) *(u32 *)field = (u32)position[1] << 8; player = (u8 *)(playerOffset + (u32)playerBase); *(struct PosA74491 *)(player + 0x94) = *(struct PosA74491 *)(player + 0x8C); +#endif sub_08009930(0, 0xA); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coordsA74491 + myId * 0x14C); + coordinates = (s32 *)(coordsA74491 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callbackA74491); sub_08015EF8(); @@ -1876,7 +1968,10 @@ s32 sub_0808A830(u8 *table) sub_0800CCDC(); playerOffset = sub_080020F4(); playerBase = playersA83091; - playerOffset *= 0x14C; +#ifdef REGION_USA + {register u8 *xf asm("r3");register u8 *yf asm("r1");u8 *b12=playerBase;playerOffset *= PLAYER_SIZE;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)playerOffset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)playerOffset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);playerOffset+=(u32)dst;}*(struct PosA83091 *)playerOffset=*(struct PosA83091 *)xf;} +#else + playerOffset *= PLAYER_SIZE; field = playerBase; field += 0x8C; field = (u8 *)(playerOffset + (u32)field); @@ -1887,10 +1982,11 @@ s32 sub_0808A830(u8 *table) *(u32 *)field = (u32)position[1] << 8; player = (u8 *)(playerOffset + (u32)playerBase); *(struct PosA83091 *)(player + 0x94) = *(struct PosA83091 *)(player + 0x8C); +#endif sub_08009930(0, 9); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coordsA83091 + myId * 0x14C); + coordinates = (s32 *)(coordsA83091 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callbackA83091); sub_08015EF8(); @@ -1902,9 +1998,9 @@ s32 sub_0808A830(u8 *table) } checkOffset = sub_080020F4(); checkBase = playersA83091; - checkStride = 0x14C; + checkStride = PLAYER_SIZE; checkOffset *= checkStride; - checkBase += 0x90; + checkBase += PLAYER_FIELD(0x90); if ((*(s32 *)(checkOffset + (u32)checkBase) >> 11) > 0x25) { sub_08015EF8(); sub_0801ABE8(3); @@ -1953,7 +2049,10 @@ s32 sub_0808A984(u8 *table) sub_0800CCDC(); playerOffset = sub_080020F4(); playerBase = playersA98491; - playerOffset *= 0x14C; +#ifdef REGION_USA + {register u8 *xf asm("r3");register u8 *yf asm("r1");u8 *b12=playerBase;playerOffset *= PLAYER_SIZE;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)playerOffset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)playerOffset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);playerOffset+=(u32)dst;}*(struct PosA98491 *)playerOffset=*(struct PosA98491 *)xf;} +#else + playerOffset *= PLAYER_SIZE; field = playerBase; field += 0x8C; field = (u8 *)(playerOffset + (u32)field); @@ -1964,10 +2063,11 @@ s32 sub_0808A984(u8 *table) *(u32 *)field = (u32)position[1] << 8; player = (u8 *)(playerOffset + (u32)playerBase); *(struct PosA98491 *)(player + 0x94) = *(struct PosA98491 *)(player + 0x8C); +#endif sub_08009930(0, 0xF); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coordsA98491 + myId * 0x14C); + coordinates = (s32 *)(coordsA98491 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callbackA98491); sub_08015EF8(); @@ -2008,14 +2108,18 @@ s32 sub_0808AA70(u8 *table) {register u32 delta asm("r0")=stateAA7091->row*0x24;delta+=4;position=(u16 *)(table+delta);} sub_0800CCDC(); {u8 *base; register u8 *px asm("r1"); - offset=sub_080020F4();base=playersAA7091;offset*=0x14C;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); +#ifdef REGION_USA + offset=sub_080020F4();base=playersAA7091;{register u8 *xf asm("r3");register u8 *yf asm("r1");register u8 *b12 asm("ip")=base;offset*=PLAYER_SIZE;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)offset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)offset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);offset+=(u32)dst;}*(struct PosAA7091 *)offset=*(struct PosAA7091 *)xf;}} +#else + offset=sub_080020F4();base=playersAA7091;offset*=PLAYER_SIZE;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); *(u32 *)px=(u32)position[0]<<8; px=base+0x90;px=(u8 *)((u32)offset+(u32)px);*(u32 *)px=(u32)position[1]<<8; {u8 *p;offset+=(u32)base;p=(u8 *)offset;*(struct PosAA7091 *)(p+0x94)=*(struct PosAA7091 *)(p+0x8C);}} +#endif sub_08009930(0, 0x11); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coordsAA7091 + myId * 0x14C); + coordinates = (s32 *)(coordsAA7091 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callbackAA7091); sub_08015EF8(); @@ -2023,14 +2127,14 @@ s32 sub_0808AA70(u8 *table) stateAA7091->active = 1; return 0; } - player = playersAA7091 + sub_080020F4() * 0x14C; + player = playersAA7091 + sub_080020F4() * PLAYER_SIZE; exitIndex=1;{register struct StateAA7091 **p asm("r6")=&stateAA7091;asm("" : "=r"(zero) : "r"(p), "0"(0));} for (; exitIndex <= 3; exitIndex++) { {register u32 row asm("r0")=stateAA7091->row*0x24;register u32 col asm("r1");row+=4;row=(u32)table+row;col=exitIndex*8;exit=(const struct ExitAA7091 *)(row+col);} - difference = (*(s32 *)(player + 0x8C) >> 11) - exit->x; + difference = (*(s32 *)(player + PLAYER_FIELD(0x8C)) >> 11) - exit->x; if (difference < 0) difference = -difference; - if (difference <= 1 && (*(s32 *)(player + 0x90) >> 11) == exit->y) { + if (difference <= 1 && (*(s32 *)(player + PLAYER_FIELD(0x90)) >> 11) == exit->y) { sub_08015ED4(); sub_0801ABE8(3); sub_0800BB40(); @@ -2082,14 +2186,18 @@ s32 sub_0808AC08(u8 *input) {register u32 delta asm("r0")=stateAC0891->row*0x24;delta+=4;position=(u16 *)(table+delta);} sub_0800CCDC(); {u8 *base; register u8 *px asm("r1"); - offset=sub_080020F4();base=playersAC0891;offset*=0x14C;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); +#ifdef REGION_USA + offset=sub_080020F4();base=playersAC0891;{register u8 *xf asm("r3");register u8 *yf asm("r1");register u8 *b12 asm("ip")=base;offset*=PLAYER_SIZE;xf=b12+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)offset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=b12+PLAYER_FIELD(0x90);yf=(u8 *)((u32)offset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=b12;dst+=PLAYER_FIELD(0x94);offset+=(u32)dst;}*(struct PosAC0891 *)offset=*(struct PosAC0891 *)xf;}} +#else + offset=sub_080020F4();base=playersAC0891;offset*=PLAYER_SIZE;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); *(u32 *)px=(u32)position[0]<<8; px=base+0x90;px=(u8 *)((u32)offset+(u32)px);*(u32 *)px=(u32)position[1]<<8; {u8 *p;offset+=(u32)base;p=(u8 *)offset;*(struct PosAC0891 *)(p+0x94)=*(struct PosAC0891 *)(p+0x8C);}} +#endif sub_08009930(0, 0x12); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coordsAC0891 + myId * 0x14C); + coordinates = (s32 *)(coordsAC0891 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callbackAC0891); sub_08015EF8(); @@ -2098,13 +2206,13 @@ s32 sub_0808AC08(u8 *input) stateAC0891->active = 1; return 0; } - player = playersAC0891 + sub_080020F4() * 0x14C; + player = playersAC0891 + sub_080020F4() * PLAYER_SIZE; for (exitIndex = 1; exitIndex <= 3; exitIndex++) { {register u32 row asm("r0")=stateAC0891->row*0x24;u32 col;row+=4;row=(u32)table+row;col=exitIndex*8;exit=(const struct ExitAC0891 *)(row+col);} - difference = (*(s32 *)(player + 0x8C) >> 11) - exit->x; + difference = (*(s32 *)(player + PLAYER_FIELD(0x8C)) >> 11) - exit->x; if (difference < 0) difference = -difference; - if (difference <= 1 && (*(s32 *)(player + 0x90) >> 11) == exit->y) { + if (difference <= 1 && (*(s32 *)(player + PLAYER_FIELD(0x90)) >> 11) == exit->y) { sub_08015ED4(); sub_0801ABE8(3); sub_0800BB40(); @@ -2154,14 +2262,18 @@ s32 sub_0808AD90(u8 *input) {register u32 delta asm("r0")=stateAD9091->row*0x24;delta+=4;position=(u16 *)(table+delta);} sub_0800CCDC(); {u8 *base; register u8 *px asm("r1"); - offset=sub_080020F4();base=playersAD9091;offset*=0x14C;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); +#ifdef REGION_USA + offset=sub_080020F4();base=playersAD9091;offset*=PLAYER_SIZE;{register u8 *xf asm("r3");u8 *yf;xf=base+PLAYER_FIELD(0x8C);xf=(u8 *)((u32)offset+(u32)xf);*(u32 *)xf=(u32)position[0]<<8;yf=base+PLAYER_FIELD(0x90);yf=(u8 *)((u32)offset+(u32)yf);*(u32 *)yf=(u32)position[1]<<8;{register u8 *dst asm("r0")=base;dst+=PLAYER_FIELD(0x94);offset+=(u32)dst;}*(struct PosAD9091 *)offset=*(struct PosAD9091 *)xf;}} +#else + offset=sub_080020F4();base=playersAD9091;offset*=PLAYER_SIZE;px=base+0x8C;px=(u8 *)((u32)offset+(u32)px); *(u32 *)px=(u32)position[0]<<8; px=base+0x90;px=(u8 *)((u32)offset+(u32)px);*(u32 *)px=(u32)position[1]<<8; {u8 *p;offset+=(u32)base;p=(u8 *)offset;*(struct PosAD9091 *)(p+0x94)=*(struct PosAD9091 *)(p+0x8C);}} +#endif sub_08009930(0, 0x13); while (sub_0800BA6C() == 0) sub_080003F0(); - coordinates = (s32 *)(coordsAD9091 + myId * 0x14C); + coordinates = (s32 *)(coordsAD9091 + myId * PLAYER_SIZE); sub_0800AD04(coordinates, coordinates + 1, sub_0800CCCC()); sub_08057328(0, (u32)callbackAD9091); sub_08015EF8(); @@ -2170,14 +2282,14 @@ s32 sub_0808AD90(u8 *input) stateAD9091->step = 1; stateAD9091->active = 1; } else { - player = playersAD9091 + sub_080020F4() * 0x14C; + player = playersAD9091 + sub_080020F4() * PLAYER_SIZE; exitIndex=1;zero=0; do { {register u32 row asm("r0")=stateAD9091->row*0x24;register u32 col asm("r1");row+=4;row=(u32)table+row;col=exitIndex*8;exit=(const struct ExitAD9091 *)(row+col);} - difference = (*(s32 *)(player + 0x8C) >> 11) - exit->x; + difference = (*(s32 *)(player + PLAYER_FIELD(0x8C)) >> 11) - exit->x; if (difference < 0) difference = -difference; - if (difference <= 1 && (*(s32 *)(player + 0x90) >> 11) == exit->y) { + if (difference <= 1 && (*(s32 *)(player + PLAYER_FIELD(0x90)) >> 11) == exit->y) { sub_08015ED4(); sub_0801ABE8(3); sub_0800BB40(); @@ -2199,8 +2311,8 @@ s32 sub_0808AD90(u8 *input) sub_08056E78(); {struct StateAD9091 **st;struct StateAD9091 **r=&stateAD9091;struct StateAD9091 *p; u32 one;u8 *base;u32 stride;st=r;p=*r;one=1;p->row=one; - {register s32 idx asm("r2")=sub_080020F4();u8 *p;base=playersAD9091;stride=0x14c;idx*=stride;p=base+0x30;idx+=(u32)p;*(u32 *)idx &= ~2;} - {s32 idx=sub_080020F4();idx*=stride;idx+=(u32)base;*(u16 *)(idx+0x20)=result;} + {register s32 idx asm("r2")=sub_080020F4();u8 *p;base=playersAD9091;stride=PLAYER_SIZE;idx*=stride;p=base+PLAYER_FIELD(0x30);idx+=(u32)p;*(u32 *)idx &= ~2;} + {s32 idx=sub_080020F4();idx*=stride;idx+=(u32)base;*(u16 *)(idx+PLAYER_FIELD(0x20))=result;} {struct StateAD9091 **r=st;struct StateAD9091 *p=*r;*(u16 *)((u8 *)p+0x30)=one;*(u16 *)((u8 *)p+0x24)=one;}} return 1; } @@ -2221,7 +2333,26 @@ void sub_0808AFA4(const u16 *pos) u8 *state; offset = sub_080020F4(); base = (u8 *)gUnk_03003CE0; - offset *= 0x14C; + offset *= PLAYER_SIZE; +#ifdef REGION_USA + { + register u8 *state asm("r3"); + state = base; + state += PLAYER_FIELD(0x8C); + state = (u8 *)(offset + (u32)state); + *(u32 *)state = (u32)pos[0] << 8; + field = base; + field += PLAYER_FIELD(0x90); + field = (u8 *)(offset + (u32)field); + *(u32 *)field = (u32)pos[1] << 8; + { + register u8 *dst asm("r0") = base; + dst += PLAYER_FIELD(0x94); + offset += (u32)dst; + } + *(struct PositionPairAFA4 *)offset = *(struct PositionPairAFA4 *)state; + } +#else field = base; field += 0x8C; field = (u8 *)(offset + (u32)field); @@ -2232,13 +2363,14 @@ void sub_0808AFA4(const u16 *pos) *(u32 *)field = (u32)pos[1] << 8; state = (u8 *)(offset + (u32)base); *(struct PositionPairAFA4 *)(state + 0x94) = *(struct PositionPairAFA4 *)(state + 0x8C); +#endif } struct SprAF91 { u8 p0[0xC]; u8 *data; u8 p10[0xC]; u8 flags; u8 p1D[0x17]; }; struct RecAF91 { u16 type; u16 val; u32 time; u8 b8; u8 b9; u8 pad[6]; }; struct TypeAF91 { u16 a; u16 b; }; -struct EntryAF91 { u8 pad[0xD4]; u16 obj; u16 pal; }; +struct EntryAF91 { u8 pad[ENEMY_DATA_FIELD(0xD4)]; u16 obj; u16 pal; }; struct ObjAF91 { u32 gfx[22]; }; -struct PlayerAF91 { u8 p0[0x10]; u16 h10; u8 p12[0x52]; u16 h64; u8 b66; u8 p67[0xE5]; }; +struct PlayerAF91 { u8 p0[PLAYER_FIELD(0x10)]; u16 h10; u8 p12[PLAYER_FIELD(0x64) - PLAYER_FIELD(0x12)]; u16 h64; u8 b66; u8 p67[PLAYER_SIZE - PLAYER_FIELD(0x67)]; }; struct StateAF91 { u8 p0[0x36]; u16 h36; u8 p38[8]; u32 w40; u8 p44[0x18]; struct RecAF91 rec; }; extern u16 heldAF91 asm("gUnk_03001308"); @@ -2328,7 +2460,7 @@ void sub_0808AFE8_v(void) struct StageStateViewAF91 { u8 prefix[0x14A]; u16 stage; }; ((struct StageSaveViewAF91 *)saveAF91)->stage = stagesAF91[((struct StageStateViewAF91 *)stateAF91)->stage]; } - sub_08065158(&anim, 0x50067, 9, -1, 0); + sub_08065158(&anim, RES_ID(0x50067), 9, -1, 0); sprite = (void *)sub_080653CC(); sub_080009F8(0x200, 0, 1); sub_080009C0(0x1D00, 0, 1); @@ -2489,7 +2621,7 @@ void sub_0808AFE8_v(void) detailRow = (struct RecAF91 *)((u8 *)records + ((sel + selectionStride) << 4)); sub_0805FFBC(0xF, 0x12, &detailRow[col], 0x80000000); } else { - text = (u8 *)sub_08007290((sel + 0x49F) | 0x140000) + 2; + text = (u8 *)sub_08007290((sel + 0x49F) | 0x140000) + TEXT_HEADER; sub_0801A3D0(text, 0xF - ((u32)sub_0801A638(text) >> 1), 0x12); } switch (sel) { @@ -2543,7 +2675,7 @@ void sub_0808AFE8_v(void) sub_0805FB7C(2, 8, sub_08058900(sel) / 3600, 0); sub_0805FB7C(5, 8, sub_08058900(sel) % 3600 / 60, 0); sub_0805FB7C(8, 8, sub_08058934(sel), 0); - text = (u8 *)sub_08007290((sel + 0x49F) | 0x140000) + 2; + text = (u8 *)sub_08007290((sel + 0x49F) | 0x140000) + TEXT_HEADER; sub_0801A3D0(text, 0xF - ((u32)sub_0801A638(text) >> 1), 0x12); switch (sel) { case 0: tbl = data084AA9E8AF91; break; @@ -2640,6 +2772,9 @@ void sub_0808B978(void) { asm("" : "=r"(var_r9), "=r"(entry_r7), "=r"(saved_reg_r8)); var_r7 = entry_r7; +#ifdef REGION_USA + sub_08065158(&sp4, 0x50006, 0, -1, 0); /* single language */ +#else switch (gUnk_03003470) { /* switch 1 */ case 0: /* switch 1 */ var_r1 = 0x50006; @@ -2659,6 +2794,7 @@ void sub_0808B978(void) { sub_08065158(&sp4, 0x5000A, 0, -1, 0); break; } +#endif sub_0800CF58(); sub_08057934(); sub_08028AAC(0, 0x79, 0x1BE, 0); @@ -2673,7 +2809,11 @@ void sub_0808B978(void) { var_r6 = times[temp_r2]; } +#ifdef REGION_USA + { register u32 zero asm("r0") = 0; asm("" : "+r"(zero)); sp38 = zero; } +#else sp38 = 0; +#endif switch (temp_r2) { /* switch 2 */ case 0: /* switch 2 */ var_r1_2 = &gUnk_084AA9E0; @@ -2981,7 +3121,7 @@ goto test_83; sub_08057624(1U); test_83: { - u32 offset = sub_080020F4() * 0x14C; + u32 offset = sub_080020F4() * PLAYER_SIZE; register s32 *base asm("r2"); base = B978PlayerTime; @@ -3117,7 +3257,7 @@ void sub_0808C020_v(void) } sub_08057624(1); test: - sub_0801A3D0(text + 2, 9, 0x12); + sub_0801A3D0(text + TEXT_HEADER, 9, 0x12); flag = gFlagC020; if (flag == 0) goto loop; sub_08015C5C(sub_08058240(), 0x16C); @@ -3128,7 +3268,7 @@ void sub_0808C020_v(void) } struct C0Anim { s32 res; s32 f4; s32 f8; u8 pad[0x10]; u8 id; u8 pad2[0x17]; }; struct C0Item {u16 unk0;u8 unk2;u8 unk3;}; -struct C0Player {u8 p0[16];u16 unk10;u8 p12[10];s16 unk1C;u8 p1e[2];u16 state;u8 p22[14];u32 flags;u8 p34[48];u16 unk64;u8 p66[2];u8 unk68;u8 p69[35];s32 unk8C;s32 unk90;u8 p94[180];struct C0Item *unk148;}; +struct C0Player {u8 p0[PLAYER_FIELD(0x10)];u16 unk10;u8 p12[PLAYER_FIELD(0x1C) - PLAYER_FIELD(0x12)];s16 unk1C;u8 p1e[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x1E)];u16 state;u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 p34[PLAYER_FIELD(0x64) - PLAYER_FIELD(0x34)];u16 unk64;u8 p66[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x66)];u8 unk68;u8 p69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)];s32 unk8C;s32 unk90;u8 p94[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x94)];struct C0Item *unk148;}; extern struct C0Player gPlayersC0[] asm("gUnk_03003CE0"); extern u16 gKeysC0[] asm("gUnk_03001250"); @@ -3138,13 +3278,13 @@ extern u8 *gStateC0 asm("gUnk_03005CF4"); extern u8 gPortraitC0[] asm("gUnk_08479140"); extern u8 gCoordsC0[] asm("gUnk_084F0C30"); extern u8 gCoordsThirdC0[] asm("gUnk_084F0C34"); -struct C0Slot { struct C0Item *item; u8 pad[0x148]; }; +struct C0Slot { struct C0Item *item; u8 pad[PLAYER_SIZE - 4]; }; extern struct C0Slot gSlotsC0[] asm("gUnk_03003E28"); /* Seat coordinates: [category][seat in category][x, y, z]. */ extern u16 gSeatPosC0[][3][3] asm("gUnk_084F0C30"); extern s32 C0Draw(u32, u32, u32, u32, u32, void *, s32, s32) asm("sub_08007870"); extern u8 C0Vc(u32) asm("sub_08001108"); -#define C0_CENTER_TEXT(id) do { temp_r4_15 = sub_08007290(id) + 2; sub_0801A3D0(temp_r4_15, (u16)(0xF - ((u32)sub_0801A638(temp_r4_15) >> 1)), 0x12); } while (0) +#define C0_CENTER_TEXT(id) do { temp_r4_15 = sub_08007290(id) + TEXT_HEADER; sub_0801A3D0(temp_r4_15, (u16)(0xF - ((u32)sub_0801A638(temp_r4_15) >> 1)), 0x12); } while (0) /* Clear the per-category counters, then draw every free portrait at its seat. */ #define C0_DRAW_ALL() \ for (loopCounterC0 = 0; loopCounterC0 < 5; loopCounterC0++) \ @@ -3236,7 +3376,7 @@ void sub_0808C0C4_v(void) { gKeysC0[0xC / 2] = 0; sub_0800B974(0x38U, 0x1EU); sub_0800B650(0x35, 0x1F, 0x06000000, 0U, 0xF); - sub_08065158(&sp18, 0x50067, 9, -1, 0); + sub_08065158(&sp18, RES_ID(0x50067), 9, -1, 0); sub_080653CC(); sub_080009F8(0x200, 0, 1); sub_080009C0(0x1D00, 0, 1); @@ -3254,10 +3394,15 @@ void sub_0808C0C4_v(void) { sub_08000AA8(3U, bgHalfC0); for (loopCounterC0 = 0; loopCounterC0 < sub_08002164(); loopCounterC0++) { portraitBaseC0 = ((u8 *)portraitsC0); +#ifdef REGION_USA + temp_r4 = portraitBaseC0 + (0x34 * loopCounterC0); +#endif portraitTableC0 = gPortraitC0; playerTableC0 = gPlayersC0; +#ifndef REGION_USA temp_r4 = portraitBaseC0 + (0x34 * loopCounterC0); - temp_r0 = (struct C0Player *)(loopCounterC0 * 0x14C + (u32)playerTableC0); +#endif + temp_r0 = (struct C0Player *)(loopCounterC0 * PLAYER_SIZE + (u32)playerTableC0); portraitLookupC0 = temp_r0->unk10 * 4; portraitRowC0 = temp_r0->unk64 * 0x58; portraitLookupC0 += portraitRowC0; @@ -3266,6 +3411,9 @@ void sub_0808C0C4_v(void) { sub_08065158(temp_r4, portraitLookupC0, 0, -1, 0); temp_r4[0x1C] = (s8) loopCounterC0; } +#ifdef REGION_USA + sub_08065158(&sp4C, 0x50002, 0, -1, 0); +#else switch (gUnk_03003470) { case 0: sub_08065158(&sp4C, 0x50002, 0, 0x80000000, 0); @@ -3286,6 +3434,7 @@ void sub_0808C0C4_v(void) { sub_08065158(&sp4C, 0x5015E, 0, 0x80000000, 0); break; } +#endif sp160 = 0; sub_080003F0(); sub_080003F0(); @@ -3312,8 +3461,8 @@ void sub_0808C0C4_v(void) { } /* Main menu loop: invariants (player table, stride) are hoisted out of it. */ for (;;) { - playerStrideC0 = 0x14C; - selPlayerC0 = (struct C0Player *)(sub_08007290(0x1401F6) + 2); + playerStrideC0 = PLAYER_SIZE; + selPlayerC0 = (struct C0Player *)(sub_08007290(0x1401F6) + TEXT_HEADER); sub_0801A3D0((u8 *)selPlayerC0, (u16) (0xF - ((u32) sub_0801A638((u8 *)selPlayerC0) >> 1)), 0x12); for (loopCounterC0 = 0; loopCounterC0 < 5; loopCounterC0++) sp150[loopCounterC0] = 0; @@ -3325,7 +3474,7 @@ void sub_0808C0C4_v(void) { loop_24BodyC0: playerBaseC0 = (u8 *)gPlayersC0; { - u8 *b148 = playerBaseC0 + 0x148; + u8 *b148 = playerBaseC0 + PLAYER_FIELD(0x148); temp_r0_2 = (struct C0Item **)(b148 + var_r9); } temp_r1 = *temp_r0_2; @@ -3348,7 +3497,7 @@ void sub_0808C0C4_v(void) { *temp_r0_3 += 1; } } - var_r9 += 0x14C; + var_r9 += PLAYER_SIZE; loopCounterC0 += 1; loop_24CheckC0: if (loopCounterC0 < sub_08002164()) @@ -3442,7 +3591,7 @@ void sub_0808C0C4_v(void) { do { u32 k; u16 *cn; - temp_r4_10 = sub_08007290(0x1401F6) + 2; + temp_r4_10 = sub_08007290(0x1401F6) + TEXT_HEADER; sub_0801A3D0(temp_r4_10, (u16) (0xF - ((u32) sub_0801A638(temp_r4_10) >> 1)), 0x12); for (var_r5_2 = 0, k = loopCounterC0 + 1; var_r5_2 < 5; var_r5_2++) sp150[var_r5_2] = 0; @@ -3463,9 +3612,9 @@ void sub_0808C0C4_v(void) { { u32 off; u16 *cnt; - for (var_r5_2 = 0, cnt = sp150, off = 0; var_r5_2 < sub_08002164(); off += 0x14C, var_r5_2++) { + for (var_r5_2 = 0, cnt = sp150, off = 0; var_r5_2 < sub_08002164(); off += PLAYER_SIZE, var_r5_2++) { u8 *base = (u8 *)gPlayersC0; - u8 *b148 = base + 0x148; + u8 *b148 = base + PLAYER_FIELD(0x148); struct C0Item **pit = (struct C0Item **)(b148 + off); if (((*pit)->unk0 >> 4) == 0) { if (var_r5_2 == sub_080020F4()) { @@ -3522,6 +3671,13 @@ void sub_0808C0C4_v(void) { goto block_94; } confirmFlagsC0 = temp_r0_7; +#ifdef REGION_USA + if (confirmFlagsC0 == 1) { + if (sp160 == 0) { + sub_0805865C(0xF); + goto loop_113CheckC0; + } +#else switch (confirmFlagsC0) { case 1: if (sp160 != 0) @@ -3529,12 +3685,21 @@ void sub_0808C0C4_v(void) { sub_0805865C(0xF); goto loop_113CheckC0; case 2: +#endif goto block_10; +#ifdef REGION_USA + } + if (confirmFlagsC0 == 2) { +block_10: + sub_0805865C(0x10); + goto loop_15; +#else default: goto block_94; +#endif } block_94: - temp_r4_15 = sub_08007290(0x1401F7) + 2; + temp_r4_15 = sub_08007290(0x1401F7) + TEXT_HEADER; sub_0801A3D0(temp_r4_15, (u16) (0xF - ((u32) sub_0801A638(temp_r4_15) >> 1)), 0x12); sub_08065370(&sp4C, 4U, (s32)&sp10[1], (s32)&sp14[1], 1); sub_08065370(&sp4C, 5U, (s32) &sp10, (s32) &sp14, 1); @@ -3637,6 +3802,9 @@ void sub_0808CB58(void) { register s32 *countBase asm("r8"); +#ifdef REGION_USA + sub_08065158(anim, 0x50006, 0, -1, 0); /* single language */ +#else switch ((u32)gUnk_03003470) { case 0: sub_08065158(anim, 0x50006, 0, -1, 0); break; case 1: sub_08065158(anim, 0x50007, 0, -1, 0); break; @@ -3644,6 +3812,7 @@ void sub_0808CB58(void) { case 3: sub_08065158(anim, 0x50009, 0, -1, 0); break; case 4: sub_08065158(anim, 0x5000A, 0, -1, 0); break; } +#endif sub_0800CF58(); sub_08028AAC(0, 0x79, 0x1BE, 0); sub_080290E4(0, 4); @@ -3655,24 +3824,24 @@ void sub_0808CB58(void) { var_r6 = 0; var_r4 = 0; players = (u8 *)gUnk_03003CE0; - stride = 0x14C; - var_r5 = players + 0x68; + stride = PLAYER_SIZE; + var_r5 = players + PLAYER_FIELD(0x68); while ((var_r4 < sub_08002164()) && (sub_080020F4() != var_r4)) { { u32 off = stride * sub_080020F4(); asm("" : "+r"(off)); - if (*((u8 *)(off + (u32)players) + 0x68) == *var_r5) { + if (*((u8 *)(off + (u32)players) + PLAYER_FIELD(0x68)) == *var_r5) { var_r6 += 1; } } - var_r5 += 0x14C; + var_r5 += PLAYER_SIZE; var_r4 += 1; } players2 = (u8 *)gUnk_03003CE0; - if (*((players2 + 0x14C * sub_080020F4()) + 0x68) != 0) { + if (*((players2 + PLAYER_SIZE * sub_080020F4()) + PLAYER_FIELD(0x68)) != 0) { table = gUnk_084F0C8A; { - register s32 idx asm("r1") = *((players2 + 0x14C * sub_080020F4()) + 0x68); + register s32 idx asm("r1") = *((players2 + PLAYER_SIZE * sub_080020F4()) + PLAYER_FIELD(0x68)); tableIndex = idx - 3; } @@ -3685,7 +3854,7 @@ void sub_0808CB58(void) { temp_r5 = *(u16 *)addr; } { - s32 idx = *((players2 + 0x14C * sub_080020F4()) + 0x68); + s32 idx = *((players2 + PLAYER_SIZE * sub_080020F4()) + PLAYER_FIELD(0x68)); idx -= 3; @@ -3703,7 +3872,7 @@ void sub_0808CB58(void) { } sub_08028AAC(0, temp_r5, tableY, 0); { - register s32 idx asm("r1") = *((players2 + 0x14C * sub_080020F4()) + 0x68); + register s32 idx asm("r1") = *((players2 + PLAYER_SIZE * sub_080020F4()) + PLAYER_FIELD(0x68)); tableIndex = idx - 3; } @@ -3728,12 +3897,12 @@ void sub_0808CB58(void) { u8 *base = (u8 *)gUnk_03003CE0; var_r6_2 = sp5C; - var_r5_2 = base + 0x68; + var_r5_2 = base + PLAYER_FIELD(0x68); } while (var_r4 < sub_08002164()) { *var_r6_2 = (s32) *var_r5_2; var_r6_2 += 1; - var_r5_2 += 0x14C; + var_r5_2 += PLAYER_SIZE; var_r4 += 1; } sub_08057328(0, &sub_0802F208); @@ -3777,14 +3946,14 @@ void sub_0808CB58(void) { u32 offset; register u8 *ptr asm("r0"); - offset = 0x14C * var_r4; + offset = PLAYER_SIZE * var_r4; - ptr = base + 0x148; + ptr = base + PLAYER_FIELD(0x148); ptr = (u8 *)(offset + (u32)ptr); if (((u32) (**(u8 **)ptr << 0x1C) >> 0x1C) != 0xB) { - ptr = base + 0x30; + ptr = base + PLAYER_FIELD(0x30); ptr = (u8 *)(offset + (u32)ptr); @@ -3795,7 +3964,7 @@ void sub_0808CB58(void) { asm("" : "+r"(address)); team = (u8 *)address; - team += 0x68; + team += PLAYER_FIELD(0x68); temp_r0 = *team; } if (temp_r0 != 0) { @@ -3868,18 +4037,18 @@ void sub_0808CB58(void) { u32 offset; register u8 *ptr asm("r0"); - offset = 0x14C * var_r4; + offset = PLAYER_SIZE * var_r4; ptr = base; - ptr += 0x30; + ptr += PLAYER_FIELD(0x30); ptr = (u8 *)(offset + (u32)ptr); if (*(u32 *)ptr & 0x2000) goto next_player; ptr = (u8 *)(offset + (u32)base); - ptr += 0x68; + ptr += PLAYER_FIELD(0x68); if (*ptr == 0) goto next_player; } found_player: @@ -3904,7 +4073,7 @@ void sub_0808CB58(void) { base = (u8 *)gUnk_03003CE0; - *(base + index * 0x14C + 0x68) = 0; + *(base + index * PLAYER_SIZE + PLAYER_FIELD(0x68)) = 0; } sub_0806617C(); while (sub_0805EEFC((void *)var_sl) == 0) sub_080003F0(); @@ -3933,9 +4102,9 @@ void sub_0808CB58(void) { base = (u8 *)gUnk_03003CE0; - offset = index * 0x14C; + offset = index * PLAYER_SIZE; - base += 0x30; + base += PLAYER_FIELD(0x30); target = (s32 *)(offset + (u32)base); @@ -4020,11 +4189,11 @@ void sub_0808D0B0(void) { * equality, no local build or runtime test. */ void sub_0808D0C4(void) { - u8 *state = (u8 *)gUnk_03003CE0 + sub_080020F4() * 0x14C; - if ((*(u32 *)(state + 0x30) & 0x4000) == 0) { + u8 *state = (u8 *)gUnk_03003CE0 + sub_080020F4() * PLAYER_SIZE; + if ((*(u32 *)(state + PLAYER_FIELD(0x30)) & 0x4000) == 0) { do { sub_08057624(1); - } while ((*(u32 *)(state + 0x30) & 0x4000) == 0); + } while ((*(u32 *)(state + PLAYER_FIELD(0x30)) & 0x4000) == 0); } sub_08057DD0(0x78, 0x14A, 0x78, 0x50, (u32)sub_0808C020, 0); } diff --git a/src/code_0808D4A8.c b/src/code_0808D4A8.c index b9233afa..fca3d0ae 100644 --- a/src/code_0808D4A8.c +++ b/src/code_0808D4A8.c @@ -190,18 +190,47 @@ void sub_0808D654(u8 *arg0) { register u32 temp_r9 asm("r9"); u8 *temp_r4; u16 *palette; +#ifdef REGION_USA + register u32 zero asm("r4"); +#else register u32 zero asm("r5"); +#endif u16 *paletteInit; sub_0801623C(arg0, gUnk_084A1910, 3); +#ifdef REGION_USA + temp_r0 = (u16)((*(u16 *)(arg0 + 0x2)) + (*(u16 *)(arg0 + 0x0))); +#else temp_r0 = (*(u16 *)(arg0 + 0x0)) + (*(u16 *)(arg0 + 0x2)); +#endif zero = 0; (*(u16 *)(arg0 + 0x2)) = temp_r0; +#ifdef REGION_USA + temp_r4 = arg0 + 0x204; +#else { register u32 off asm("r2") = 0x204; asm("" : "+r"(off)); temp_r4 = arg0 + off; } +#endif +#ifdef REGION_USA + sub_08019F60(temp_r4); + *(u16 *)(arg0 + 0x6C) = zero; + paletteInit = (u16 *)(arg0 + 0x6A); + *paletteInit = zero; + *(u16 *)(arg0 + 0x68) = zero; + temp_r0 = *(s16 *)(temp_r4 + ENEMY_DATA_FIELD(6)) * 3; + (*(s16 *)(arg0 + 0x1D6)) = temp_r0; + (*(s16 *)(arg0 + 0x5C)) = temp_r0; + temp_r0_2 = *(s16 *)(temp_r4 + ENEMY_DATA_FIELD(4)); + scaledStat = temp_r0_2 * 2; + temp_r0_2 *= 8; + temp_r0_2 += scaledStat; + temp_r0_2 *= 2; + (*(s16 *)(arg0 + 0x1D4)) = temp_r0_2; + (*(s16 *)(arg0 + 0x5E)) = temp_r0_2; +#else sub_08019F60(temp_r4); (*(u16 *)(arg0 + 0x6C)) = zero; paletteInit = (u16 *)(arg0 + 0x6A); @@ -210,19 +239,20 @@ void sub_0808D654(u8 *arg0) { u8 *hold = arg0 + 0x68; s32 val; *(u16 *)hold = zero; - val = *(s16 *)(temp_r4 + 6); + val = *(s16 *)(temp_r4 + ENEMY_DATA_FIELD(6)); asm volatile("" : : "r"(hold) : "memory"); temp_r0 = val * 3; } (*(s16 *)(arg0 + 0x1D6)) = temp_r0; (*(s16 *)(arg0 + 0x5C)) = temp_r0; - temp_r0_2 = *(s16 *)(temp_r4 + 4); + temp_r0_2 = *(s16 *)(temp_r4 + ENEMY_DATA_FIELD(4)); scaledStat = temp_r0_2 * 2; temp_r0_2 *= 8; temp_r0_2 += scaledStat; temp_r0_2 *= 2; (*(s16 *)(arg0 + 0x1D4)) = temp_r0_2; (*(s16 *)(arg0 + 0x5E)) = temp_r0_2; +#endif (*(u16 *)(arg0 + 0xC)) = zero; var_sl = zero; flashing = 0; @@ -237,7 +267,7 @@ void sub_0808D654(u8 *arg0) { temp_r4_2 = (*(u16 *)(arg0 + 0xC)); switch (temp_r4_2) { /* irregular */ case 0: - d654InitAnimation(anim, 0x5005D, 5, -1, temp_r4_2); + d654InitAnimation(anim, RES_ID(0x5005D), 5, -1, temp_r4_2); (*(u16 *)(arg0 + 0x68)) = temp_r4_2; break; case 10: @@ -510,7 +540,7 @@ void sub_0808DB38(u32 arg) u32 pr; s32 *sprite; - sub_08065158(anim, 0x50122, 0, -1, 0); + sub_08065158(anim, RES_ID(0x50122), 0, -1, 0); sub_08000AF0(0x15, (void *)anim[3], 1); *(u8 *)&anim[7] = 5; switch (arg) { @@ -552,7 +582,7 @@ void sub_0808DB38(u32 arg) if (sub_0800CCCC() == 0) sub_0805865C(0x2E); sound = 0; } - if (hit && (height >> 8) <= 7 && sub_08021FE0(pos, (u8 *)player + 0x8C, &size, &box)) { + if (hit && (height >> 8) <= 7 && sub_08021FE0(pos, (u8 *)player + PLAYER_FIELD(0x8C), &size, &box)) { hit = 0; sub_08029A7C(0, 0x10, 1); } @@ -568,7 +598,7 @@ void sub_0808DB38(u32 arg) sub_080003F0(); } if (!sub_0800CCCC()) sub_0805865C(0x29); - sub_08065158(anim, 0x50053, 0, -1, 0); + sub_08065158(anim, RES_ID(0x50053), 0, -1, 0); a1 = 0; a0 = 0; while (!sub_08065370(anim, 6, (s32)&a0, (s32)&a1, 0)) { @@ -1073,7 +1103,7 @@ void sub_0808E530_v(u32 arg) s32 vis; if (sub_0800CCCC() == 0) { - initE530(sprite, 0x500F1, 0, -1, 0); + initE530(sprite, RES_ID(0x500F1), 0, -1, 0); switch ((arg >> 16) & 0xFF) { case 0: frame = 14; @@ -1842,7 +1872,7 @@ u32 sub_0808F15C(u32 arg) return 0; } struct AnimF1E4 { s32 w0, w4, w8; u8 *graphics; u8 p10[12]; u8 data[24]; }; -struct DataF1E4 { u8 p0[4]; s16 f4, f6; }; +struct DataF1E4 { u8 p0[ENEMY_DATA_FIELD(4)]; s16 f4, f6; }; struct EntF1E4 { u16 f0; u8 p2[0xA]; u16 fC; u8 pE[6]; s32 x, y; u8 p1C[0x30]; s32 f4C; u8 p50[0xC]; s16 f5C, f5E; u8 p60[8]; u16 f68, f6A, f6C; u8 p6E[0x166]; @@ -1894,7 +1924,7 @@ void sub_0808F1E4_v(struct EntF1E4 *e) data = &e->data; resetF1E4(); limit = 0xFFFF; - while ((slot = allocF1E4(0x5012F, 0)) == limit) { + while ((slot = allocF1E4(RES_ID(0x5012F), 0)) == limit) { e->fC = 11; if (sub_0800CB78() != 0 || sub_08056E90() != 0) { activeF1E4 &= ~(1 << e->f0); @@ -1924,7 +1954,7 @@ void sub_0808F1E4_v(struct EntF1E4 *e) thinkF1E4(e); switch (e->fC) { case 0: - initF1E4(&anim, 0x5012F, slot, -1, 0); + initF1E4(&anim, RES_ID(0x5012F), slot, -1, 0); e->f68 = 0; break; case 10: @@ -2057,22 +2087,22 @@ void sub_0808F6A8(void) /* Player (0x14C bytes) view with the fields used by the map warp handlers below */ struct F9E0Vec { s32 x, y; }; struct F9E0P { - u8 pad0[0x1C]; + u8 pad0[PLAYER_FIELD(0x1C)]; u16 w1C; u16 pad1E; u16 state; - u8 pad22[0xE]; + u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; - u8 pad34[0x2C]; + u8 pad34[PLAYER_FIELD(0x60) - PLAYER_FIELD(0x34)]; u16 a60[2]; - u8 pad64[4]; + u8 pad64[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x64)]; u8 b68; - u8 pad69[0x23]; + u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; struct F9E0Vec pos; struct F9E0Vec pos2; - u8 pad9C[0x26]; + u8 pad9C[PLAYER_FIELD(0xC2) - PLAYER_FIELD(0x9C)]; u16 aC2[2]; - u8 padC6[0x14C - 0xC6]; + u8 padC6[PLAYER_SIZE - PLAYER_FIELD(0xC6)]; }; extern struct F9E0P F9E0pl[] asm("gUnk_03003CE0"); extern u8 F9E0pos[] asm("gUnk_03003D6C"); @@ -2123,7 +2153,7 @@ u32 sub_0808F700(u16 *arg) sub_080003F0(); sub_0805D518(); gUnk_03003170.pad76 = 0x20; - { struct F9E0Vec *q = (struct F9E0Vec *)(F9E0pos + idx * 0x14C); F700_AD04(&q->x, &q->y, sub_0800CCCC()); } + { struct F9E0Vec *q = (struct F9E0Vec *)(F9E0pos + idx * PLAYER_SIZE); F700_AD04(&q->x, &q->y, sub_0800CCCC()); } *(u16 *)(*(u8 **)&gUnk_03005CF4 + 0x10) = 1; sub_0805A66C(); i = 0; @@ -2219,7 +2249,7 @@ u32 sub_0808F9E0(u16 *arg) while (sub_0800BA6C() == 0) sub_080003F0(); gUnk_03003170.pad76 = 0x20; - { struct F9E0Vec *q = (struct F9E0Vec *)(F9E0pos + idx * 0x14C); F9E0_AD04(&q->x, &q->y, sub_0800CCCC()); } + { struct F9E0Vec *q = (struct F9E0Vec *)(F9E0pos + idx * PLAYER_SIZE); F9E0_AD04(&q->x, &q->y, sub_0800CCCC()); } *(u16 *)(*(u8 **)&gUnk_03005CF4 + 0x10) = 1; sub_08056E38(); if (*(u16 *)(*(u8 **)&gUnk_03005CF4 + 0x36) & 0x8000) diff --git a/src/code_0808FB5C.c b/src/code_0808FB5C.c index 11ad45dd..0228156f 100644 --- a/src/code_0808FB5C.c +++ b/src/code_0808FB5C.c @@ -105,7 +105,7 @@ u32 sub_0808FBDC(u32 arg0) return 0; } struct State8FC5095 {u8 p0[0x10];u16 mode;u8 p12[0x12];u16 w24;u8 p26[0xA];u16 w30;u8 p32[4];u16 w36;}; -struct Player8FC5095 {u8 p0[0x20];u16 state;u8 p22[0xE];u32 flags;u8 rest[0x118];}; +struct Player8FC5095 {u8 p0[PLAYER_FIELD(0x20)];u16 state;u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 rest[PLAYER_SIZE - PLAYER_FIELD(0x34)];}; struct Display8FC5095 {u8 pad[0x8C];u16 x;}; extern struct State8FC5095 *state8FC5095 asm("gUnk_03005CF4"); extern struct Player8FC5095 players8FC5095[] asm("gUnk_03003CE0"); @@ -201,9 +201,9 @@ s32 sub_0808FE04(s32 arg) sub_08056FB8(0,0); p=(u8 *)sub_080020F4(); base=playersFE0495; - stride=0x14C; + stride=PLAYER_SIZE; p=(u8 *)((u32)p*stride+(u32)base); - p+=0x68; + p+=PLAYER_FIELD(0x68); zero=0; one=1; *p=one; @@ -212,13 +212,13 @@ s32 sub_0808FE04(s32 arg) state->f36=zero; index=sub_080020F4(); index*=stride; - p=base+0x30; + p=base+PLAYER_FIELD(0x30); flags=(u32 *)(index+(u32)p); *flags&=~2; p=(u8 *)((u32)sub_080020F4()*stride+(u32)base); - *(u16 *)(p+0x20)=zero; + *(u16 *)(p+PLAYER_FIELD(0x20))=zero; p=(u8 *)((u32)sub_080020F4()*stride+(u32)base); - *(u16 *)(p+0x1C)=4; + *(u16 *)(p+PLAYER_FIELD(0x1C))=4; state=*pp; state->f30=one; state->f24=one; @@ -347,7 +347,7 @@ u32 sub_0809007C(u32 arg) return 0; } struct State9011C95 { u8 p0[0x10];u16 mode;u8 p12[0x12];u16 w24;u8 p26[0xA];u16 w30;u8 p32[4];u16 w36;u8 p38[0x3C];u32 flags; }; -struct Player9011C95 {u8 p0[0x20];u16 state;u8 p22[0xE];u32 flags;u8 rest[0x118];}; +struct Player9011C95 {u8 p0[PLAYER_FIELD(0x20)];u16 state;u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 rest[PLAYER_SIZE - PLAYER_FIELD(0x34)];}; extern struct State9011C95 *state9011C95 asm("gUnk_03005CF4"); extern struct Player9011C95 players9011C95[] asm("gUnk_03003CE0"); /* [UpdateSceneExitDestination] Calls common initialization when scene +0x10 is zero; otherwise tests the @@ -421,7 +421,7 @@ u32 sub_0809021C(u32 arg0) return 0; } struct State9029095 { u8 p0[0x10];u16 mode;u8 p12[0x12];u16 w24;u8 p26[0xA];u16 w30;u8 p32[4];u16 w36; }; -struct Player9029095 {u8 p0[0x1C];u16 action;u8 p1E[2];u16 state;u8 p22[0xE];u32 flags;u8 p34[0x34];u8 active;u8 rest[0xE3];}; +struct Player9029095 {u8 p0[PLAYER_FIELD(0x1C)];u16 action;u8 p1E[PLAYER_FIELD(0x20) - PLAYER_FIELD(0x1E)];u16 state;u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)];u8 active;u8 rest[PLAYER_SIZE - PLAYER_FIELD(0x69)];}; extern struct State9029095 *state9029095 asm("gUnk_03005CF4"); extern struct Player9029095 players9029095[] asm("gUnk_03003CE0"); /* [UpdateMapZeroExitReset] Initialization branch calls common scene initializer. */ @@ -435,11 +435,11 @@ u32 sub_08090290(u32 arg) sub_080570DC(1); sub_08056FB8(0,0); firstIndex=sub_080020F4(); base=players9029095; - { struct Player9029095 *player=(struct Player9029095 *)(firstIndex*0x14C+(u32)base); + { struct Player9029095 *player=(struct Player9029095 *)(firstIndex*PLAYER_SIZE+(u32)base); u8 *active=&player->active; zero=0;one=1;*active=one; } sub_08056E78(); (*holder)->w36=zero; - { register u32 offset asm("r2"); u8 *flagsBase; offset=sub_080020F4()*0x14C; flagsBase=(u8 *)base+0x30; offset+=(u32)flagsBase; *(u32 *)offset&=~2; } + { register u32 offset asm("r2"); u8 *flagsBase; offset=sub_080020F4()*PLAYER_SIZE; flagsBase=(u8 *)base+PLAYER_FIELD(0x30); offset+=(u32)flagsBase; *(u32 *)offset&=~2; } base[sub_080020F4()].state=zero; base[sub_080020F4()].action=4; { struct State9029095 *finalState=*holder; finalState->w30=one; finalState->w24=one; } @@ -553,6 +553,225 @@ extern void palette90495(u32,u32,u32) asm("sub_08000AF0"); * index when the debounce counter is zero, A starts the selected ID and B stops audio in selection mode or * exits the idle mode. These are input-update/task-loop semantics, not fixed elapsed-frame guarantees. */ void sub_080904A4(void) { +#ifdef REGION_USA + /* USA: each table entry carries its own name; the mode strings sit before the empty one. */ + struct Song90495 { u16 id; u8 name[26]; }; + extern struct Song90495 songsU90495[] asm("gUnk_085181C0"); + extern struct Song90495 soundsU90495[] asm("gUnk_0851820A"); + struct Sprite90495 sprite; + u16 frames[6],ticks[6],next[6],flags[6],results[6]; + u8 text[52]; + struct { u32 value:16, unused:16; } control; + struct { u16 x, y; } pos; + u16 soundCur; + u16 soundSel; + u16 songCur; + u16 songSel; + s32 mode; + u16 playing; + s32 toggle; + u8 counter; + s32 running; + s32 done; + + sub_0801A6D4(1); + sub_08000A34_90495(1, 0, 0, 0, 0); + sub_080009F8(0xF00, 0, 0); + sub_08000990(0, 0); + sub_080009C0(0x1100, 0, 0); + control.value = 0x1801; + sub_08000AA8(0, &control); + sub_080921E4_90495(0, 0x18); + sub_08065158_90495(&sprite, 0x50021, 8, -1, 1); + sprite.payload[0] = 8; + frames[3] = 1; + flags[3] = 1; + ticks[3] = next[3] = results[3] = 0; + frames[0] = 2; + flags[0] = 0; + ticks[0] = next[0] = results[0] = 0; + frames[2] = 6; + flags[2] = 0; + ticks[2] = next[2] = results[2] = 0; + frames[1] = 7; + flags[1] = 0; + ticks[1] = next[1] = results[1] = 0; + frames[4] = 8; + flags[4] = 0; + ticks[4] = next[4] = results[4] = 0; + sub_08092124(); + sub_08000940(); + sub_0801AB50(6); + soundSel = 0; + soundCur = 0; + counter = 0; + songSel = 0; + songCur = 0; + playing = 0; + toggle = 0; + mode = 0; + running = 1; + do { + if (repeat90495 & 1) { + palette90495(0x18, sprite.fC, 1); + results[1] = sub_08065370_90495(&sprite, frames[1], &ticks[1], &next[1], flags[1]); + sub_08007870_90495(0xD3, 0x83, frames[1], ticks[1], 0, sprite.payload, sprite.f8, sprite.f0); + } + if (repeat90495 & 2) { + palette90495(0x18, sprite.fC, 1); + results[2] = sub_08065370_90495(&sprite, frames[2], &ticks[2], &next[2], flags[2]); + sub_08007870_90495(0xC1, 0x83, frames[2], ticks[2], 0, sprite.payload, sprite.f8, sprite.f0); + } + if (repeat90495 & 0xF0) { + if (repeat90495 & 0x40) + frames[0] = 2; + else if (repeat90495 & 0x80) + frames[0] = 3; + else if (repeat90495 & 0x10) + frames[0] = 4; + else + frames[0] = 5; + palette90495(0x18, sprite.fC, 1); + results[0] = sub_08065370_90495(&sprite, frames[0], &ticks[0], &next[0], flags[0]); + sub_08007870_90495(0x30, 0x7D, frames[0], ticks[0], 0, sprite.payload, sprite.f8, sprite.f0); + } + if (mode == 0) { + palette90495(0x18, sprite.fC, 1); + results[3] = sub_08065370_90495(&sprite, frames[3], &ticks[3], &next[3], flags[3]); + sub_08007870_90495(0x7B, 0x7E, frames[3], ticks[3], mode, sprite.payload, sprite.f8, sprite.f0); + } + palette90495(0x18, sprite.fC, 1); + results[4] = sub_08065370_90495(&sprite, frames[4], &ticks[4], &next[4], flags[4]); + sub_08007870_90495(0xC7, 0x74, frames[4], ticks[4], 0, sprite.payload, sprite.f8, sprite.f0); + if (results[4] != 0 && frames[4] == 9) { + frames[4] = 11; + flags[4] = 1; + results[4] = 0; + next[4] = 0; + ticks[4] = 0; + } + if (playing == 1 && heap90495 == 0) + sub_08092190(); + if (pressed90495 & 8) { + if (playing != 0) { + } else if (mode != 0) { + mode = 0; + counter = 0; + frames[4] = 8; + flags[4] = counter; + results[4] = counter; + next[4] = counter; + ticks[4] = counter; + frames[3] = 1; + flags[3] = 1; + results[3] = counter; + next[3] = counter; + ticks[3] = counter; + } else { + mode = 1; + counter = 60; + frames[4] = 9; + flags[4] = playing; + results[4] = playing; + next[4] = playing; + ticks[4] = playing; + } + } else if ((held90495 & 0x30) && mode != 0) { + toggle ^= 1; + counter = 60; + } else if ((held90495 & 0x40) && mode != 0 && counter == 0) { + if (toggle == 0) + songSel = songSel != 0 ? songSel - 1 : 36; + else + soundSel = soundSel != 0 ? soundSel - 1 : 289; + } else if ((held90495 & 0x80) && mode != 0 && counter == 0) { + if (toggle == 0) + songSel = songSel != 36 ? songSel + 1 : 0; + else + soundSel = soundSel != 289 ? soundSel + 1 : 0; + } else if ((pressed90495 & 1) && mode != 0 && counter == 0) { + if (toggle == 0) { + if (playing == 1) { + m4aSongNumStop(songsU90495[songCur].id); + } else { + frames[4] = 10; + flags[4] = 1; + results[4] = toggle; + next[4] = toggle; + ticks[4] = toggle; + } + playing = 1; + songCur = songSel; + m4aSongNumStart(songsU90495[songSel].id); + } else { + m4aSongNumStop(soundsU90495[soundCur].id); + soundCur = soundSel; + m4aSongNumStart(soundsU90495[soundSel].id); + } + } else if (pressed90495 & 2) { + counter = 0; + if (mode != 0) { + if (playing == 1) { + m4aSongNumStop(songsU90495[songCur].id); + playing = 0; + frames[4] = 11; + flags[4] = 1; + results[4] = counter; + next[4] = counter; + ticks[4] = counter; + } + m4aSongNumStop(soundsU90495[soundCur].id); + } else if (playing == 0) { + running = 0; + } + } + /* Macro-style block: its loop note raises the weight of pos so it keeps r7. */ + do { + pos.x = 0x4C; + pos.y = 0x74; + } while (0); + if (mode != 0) { + if (counter != 0) { + u8 old = counter; + counter--; + if (old & 3) { + if (toggle == 0) + sub_08091F9C_90495(empty90495 - 0x20, text); + else + sub_08091F9C_90495(empty90495 - 0x10, text); + sub_0801A764_90495(text, pos.x, pos.y); + } else { + sub_08091F9C_90495(empty90495, text); + sub_0801A764_90495(text, pos.x, pos.y); + } + } else { + if (toggle == 0) + sub_08091F9C_90495(songsU90495[songSel].name, text); + else + sub_08091F9C_90495(soundsU90495[soundSel].name, text); + } + sub_0801A764_90495(text, pos.x, pos.y); + } + sub_080003F0(); + } while (running != 0); + sub_0801AA8C(0x3C); + while ((done = sub_0801AAE0_90495()) == 0) { + palette90495(0x18, sprite.fC, 1); + sub_08065370_90495(&sprite, frames[3], &ticks[3], &next[3], flags[3]); + sub_08007870_90495(0x7B, 0x7E, frames[3], ticks[3], done, sprite.payload, sprite.f8, sprite.f0); + palette90495(0x18, sprite.fC, 1); + sub_08065370_90495(&sprite, frames[4], &ticks[4], &next[4], flags[4]); + sub_08007870_90495(0xC7, 0x74, frames[4], ticks[4], done, sprite.payload, sprite.f8, sprite.f0); + sub_080003F0(); + } + if (heap90495 != 0) { + sub_08001538(heap90495); + heap90495 = 0; + } + sub_0801A6D4(0); + sub_08000968(); + sub_08000420(0x14); +#else struct Sprite90495 sprite; u16 frames[6],ticks[6],next[6],flags[6],results[6]; u8 text[12]; @@ -775,6 +994,7 @@ void sub_080904A4(void) { sub_0801A6D4(0); sub_08000968(); sub_08000420(0x14); +#endif } struct Anim095_08090B84 {u32 f0,f4,f8,fC;u8 pad10[12];u8 payload[24];s32 x,y;u16 frame,tick,next,pad42;}; @@ -797,14 +1017,14 @@ void sub_08090B84(void) { p[0] = a; b = a + 1; p[1] = b; - init095_08090B84(a, 0x5008A, 0, -1, 0); + init095_08090B84(a, RES_ID(0x5008A), 0, -1, 0); a->payload[0] = 0; a->frame = 10; a->next = 0; a->tick = 0; a->x = 0x10000; a->y = 0x5800; - init095_08090B84(b, 0x500BE, 1, -1, 0); + init095_08090B84(b, RES_ID(0x500BE), 1, -1, 0); b->payload[0] = 1; b->frame = 14; a[1].next = 0; @@ -925,13 +1145,13 @@ void sub_08090E38(void) { variant = r < 0 ? -r : r; switch (variant) { case 0: - init095_08090E38(a, 0x50012, 0, -1, 0); + init095_08090E38(a, RES_ID(0x50012), 0, -1, 0); break; case 1: - init095_08090E38(a, 0x50013, 0, -1, 0); + init095_08090E38(a, RES_ID(0x50013), 0, -1, 0); break; case 2: - init095_08090E38(a, 0x50014, 0, -1, 0); + init095_08090E38(a, RES_ID(0x50014), 0, -1, 0); break; } a->payload[0] = 0; @@ -954,13 +1174,13 @@ void sub_08090E38(void) { if (a->x <= 0x8000) { switch (variant) { case 0: - init095_08090E38(a, 0x50015, 0, -1, 0); + init095_08090E38(a, RES_ID(0x50015), 0, -1, 0); break; case 1: - init095_08090E38(a, 0x50016, 0, -1, 0); + init095_08090E38(a, RES_ID(0x50016), 0, -1, 0); break; case 2: - init095_08090E38(a, 0x50017, 0, -1, 0); + init095_08090E38(a, RES_ID(0x50017), 0, -1, 0); break; } done = 0; @@ -976,13 +1196,13 @@ void sub_08090E38(void) { if (done != 0) { switch (variant) { case 0: - init095_08090E38(a, 0x50012, 0, -1, 0); + init095_08090E38(a, RES_ID(0x50012), 0, -1, 0); break; case 1: - init095_08090E38(a, 0x50013, 0, -1, 0); + init095_08090E38(a, RES_ID(0x50013), 0, -1, 0); break; case 2: - init095_08090E38(a, 0x50014, 0, -1, 0); + init095_08090E38(a, RES_ID(0x50014), 0, -1, 0); break; } flag = 1; @@ -1041,10 +1261,10 @@ void sub_080910A8(void) { variant = r < 0 ? -r : r; switch (variant) { case 0: - init095_080910A8(a, 0x50022, 0, -1, 0); + init095_080910A8(a, RES_ID(0x50022), 0, -1, 0); break; case 1: - init095_080910A8(a, 0x50023, 0, -1, 0); + init095_080910A8(a, RES_ID(0x50023), 0, -1, 0); break; } a->payload[0] = 0; @@ -1067,10 +1287,10 @@ void sub_080910A8(void) { if (a->x <= 0x8000) { switch (variant) { case 0: - init095_080910A8(a, 0x50024, 0, -1, 0); + init095_080910A8(a, RES_ID(0x50024), 0, -1, 0); break; case 1: - init095_080910A8(a, 0x50025, 0, -1, 0); + init095_080910A8(a, RES_ID(0x50025), 0, -1, 0); break; } done = 0; @@ -1086,10 +1306,10 @@ void sub_080910A8(void) { if (done != 0) { switch (variant) { case 0: - init095_080910A8(a, 0x50022, 0, -1, 0); + init095_080910A8(a, RES_ID(0x50022), 0, -1, 0); break; case 1: - init095_080910A8(a, 0x50023, 0, -1, 0); + init095_080910A8(a, RES_ID(0x50023), 0, -1, 0); break; } flag = 1; @@ -1148,10 +1368,10 @@ void sub_080912CC(void) { variant = r < 0 ? -r : r; switch (variant) { case 0: - init095_080912CC(a, 0x5001D, 0, -1, 0); + init095_080912CC(a, RES_ID(0x5001D), 0, -1, 0); break; case 1: - init095_080912CC(a, 0x5001F, 0, -1, 0); + init095_080912CC(a, RES_ID(0x5001F), 0, -1, 0); break; } a->payload[0] = 0; @@ -1174,10 +1394,10 @@ void sub_080912CC(void) { if (a->x <= 0x8000) { switch (variant) { case 0: - init095_080912CC(a, 0x5001E, 0, -1, 0); + init095_080912CC(a, RES_ID(0x5001E), 0, -1, 0); break; case 1: - init095_080912CC(a, 0x50021, 0, -1, 0); + init095_080912CC(a, RES_ID(0x50021), 0, -1, 0); break; } done = 0; @@ -1193,10 +1413,10 @@ void sub_080912CC(void) { if (done != 0) { switch (variant) { case 0: - init095_080912CC(a, 0x5001D, 0, -1, 0); + init095_080912CC(a, RES_ID(0x5001D), 0, -1, 0); break; case 1: - init095_080912CC(a, 0x5001F, 0, -1, 0); + init095_080912CC(a, RES_ID(0x5001F), 0, -1, 0); break; } flag = 1; @@ -1255,10 +1475,10 @@ void sub_080914F0(void) { variant = r < 0 ? -r : r; switch (variant) { case 0: - init096_080914F0(a, 0x5002B, 0, -1, 0); + init096_080914F0(a, RES_ID(0x5002B), 0, -1, 0); break; case 1: - init096_080914F0(a, 0x5002A, 0, -1, 0); + init096_080914F0(a, RES_ID(0x5002A), 0, -1, 0); break; } a->payload[0] = 0; @@ -1281,10 +1501,10 @@ void sub_080914F0(void) { if (a->x <= 0x8000) { switch (variant) { case 0: - init096_080914F0(a, 0x5002C, 0, -1, 0); + init096_080914F0(a, RES_ID(0x5002C), 0, -1, 0); break; case 1: - init096_080914F0(a, 0x5002D, 0, -1, 0); + init096_080914F0(a, RES_ID(0x5002D), 0, -1, 0); break; } done = 0; @@ -1300,10 +1520,10 @@ void sub_080914F0(void) { if (done != 0) { switch (variant) { case 0: - init096_080914F0(a, 0x5002B, 0, -1, 0); + init096_080914F0(a, RES_ID(0x5002B), 0, -1, 0); break; case 1: - init096_080914F0(a, 0x5002A, 0, -1, 0); + init096_080914F0(a, RES_ID(0x5002A), 0, -1, 0); break; } flag = 1; @@ -1360,10 +1580,10 @@ void sub_08091714(void) { variant = r < 0 ? -r : r; switch (variant) { case 0: - init096_08091714(a, 0x50030, 0, -1, 0); + init096_08091714(a, RES_ID(0x50030), 0, -1, 0); break; case 1: - init096_08091714(a, 0x50031, 0, -1, 0); + init096_08091714(a, RES_ID(0x50031), 0, -1, 0); break; } a->payload[0] = 0; @@ -1386,10 +1606,10 @@ void sub_08091714(void) { if (a->x <= 0x8000) { switch (variant) { case 0: - init096_08091714(a, 0x50033, 0, -1, 0); + init096_08091714(a, RES_ID(0x50033), 0, -1, 0); break; case 1: - init096_08091714(a, 0x50032, 0, -1, 0); + init096_08091714(a, RES_ID(0x50032), 0, -1, 0); break; } done = 0; @@ -1405,10 +1625,10 @@ void sub_08091714(void) { if (done != 0) { switch (variant) { case 0: - init096_08091714(a, 0x50030, 0, -1, 0); + init096_08091714(a, RES_ID(0x50030), 0, -1, 0); break; case 1: - init096_08091714(a, 0x50031, 0, -1, 0); + init096_08091714(a, RES_ID(0x50031), 0, -1, 0); break; } flag = 1; @@ -1465,10 +1685,10 @@ void sub_08091938(void) { variant = r < 0 ? -r : r; switch (variant) { case 0: - init096_08091938(a, 0x50035, 0, -1, 0); + init096_08091938(a, RES_ID(0x50035), 0, -1, 0); break; case 1: - init096_08091938(a, 0x50037, 0, -1, 0); + init096_08091938(a, RES_ID(0x50037), 0, -1, 0); break; } a->payload[0] = 0; @@ -1491,10 +1711,10 @@ void sub_08091938(void) { if (a->x <= 0x8000) { switch (variant) { case 0: - init096_08091938(a, 0x50036, 0, -1, 0); + init096_08091938(a, RES_ID(0x50036), 0, -1, 0); break; case 1: - init096_08091938(a, 0x50038, 0, -1, 0); + init096_08091938(a, RES_ID(0x50038), 0, -1, 0); break; } done = 0; @@ -1510,10 +1730,10 @@ void sub_08091938(void) { if (done != 0) { switch (variant) { case 0: - init096_08091938(a, 0x50035, 0, -1, 0); + init096_08091938(a, RES_ID(0x50035), 0, -1, 0); break; case 1: - init096_08091938(a, 0x50037, 0, -1, 0); + init096_08091938(a, RES_ID(0x50037), 0, -1, 0); break; } flag = 1; @@ -1567,7 +1787,7 @@ void sub_08091B5C(void) { a = (struct Anim096_08091B5C *)(heap096_08091B5C = (u32)sub_08001494(0x44)); random096(); variant = 0; - init096_08091B5C(a, 0x50027, 0, -1, variant); + init096_08091B5C(a, RES_ID(0x50027), 0, -1, variant); a->payload[0] = variant; a->frame = 10; a->next = variant; @@ -1587,7 +1807,7 @@ void sub_08091B5C(void) { a->x -= 0x100; if (a->x <= 0x8000) { if (variant == 0) - init096_08091B5C(a, 0x50028, 0, -1, 0); + init096_08091B5C(a, RES_ID(0x50028), 0, -1, 0); flag = 0; a->payload[0] = 0; a->frame = 10; @@ -1599,7 +1819,7 @@ void sub_08091B5C(void) { case 1: if (done != 0) { if (variant == 0) - init096_08091B5C(a, 0x50027, 0, -1, 0); + init096_08091B5C(a, RES_ID(0x50027), 0, -1, 0); flag = 1; a->frame = 10; *next = 0; @@ -1651,7 +1871,7 @@ void sub_08091CF8(void) { a = (struct Anim096_08091CF8 *)(heap096_08091CF8 = (u32)sub_08001494(0x44)); random096(); variant = 0; - init096_08091CF8(a, 0x50019, 0, -1, variant); + init096_08091CF8(a, RES_ID(0x50019), 0, -1, variant); a->payload[0] = variant; a->frame = 10; a->next = variant; @@ -1671,7 +1891,7 @@ void sub_08091CF8(void) { a->x -= 0x100; if (a->x <= 0x8000) { if (variant == 0) - init096_08091CF8(a, 0x5001A, 0, -1, 0); + init096_08091CF8(a, RES_ID(0x5001A), 0, -1, 0); flag = 0; a->payload[0] = 0; a->frame = 10; @@ -1683,7 +1903,7 @@ void sub_08091CF8(void) { case 1: if (done != 0) { if (variant == 0) - init096_08091CF8(a, 0x50019, 0, -1, 0); + init096_08091CF8(a, RES_ID(0x50019), 0, -1, 0); flag = 1; a->frame = 10; *next = 0; @@ -1797,6 +2017,28 @@ extern u32 language096F asm("gUnk_03003470"); * until zero/0xFD. Each branch copies at most 255 bytes. On ordinary termination writes 0xFD; hitting that * copy limit returns without appending a terminator. This is not a Unicode decoder or a universal * interpretation of the mode global. */ +#ifdef REGION_USA +/* USA: a single ASCII-to-TextChar path (no language mode); digits map to +0x11. */ +s32 sub_08091F9C(u8 *input,u8 *out) +{ + s8 *source=(s8 *)input; + TextChar *output=(TextChar *)out; + u8 count=0; + while(*source!=0){ + u32 c=*(u8 *)source; + if(*source==0x20) *output=0x51; + else if((u8)(c-0x41)<=0x19) *output=*source-0x40; + else if((u8)(c-0x61)<=0x19) *output=*source-0x40; + else if((u8)(c-0x30)<=9) *output=*source+0x11; + else break; + source++;output++;count++; + if(count>0xFE) goto done; + } + *output=TEXT_CTRL(0xFD); +done: + return (u8)(count-1); +} +#else s32 sub_08091F9C(u8 *source,u8 *output) { u32 mode; @@ -1857,6 +2099,7 @@ s32 sub_08091F9C(u8 *source,u8 *output) return (u8)(count-1); } +#endif diff --git a/src/code_08095B04.c b/src/code_08095B04.c index 6a187455..2900b861 100644 --- a/src/code_08095B04.c +++ b/src/code_08095B04.c @@ -183,7 +183,7 @@ s32 sub_08095E70(struct Motion95 *p, s16 x, s16 y) return (u8)p->unk8; } struct TargetF10 { u16 x, y; }; -struct PlayerF10 { u8 pad[0x148]; struct TargetF10 *target; }; +struct PlayerF10 { u8 pad[PLAYER_FIELD(0x148)]; struct TargetF10 *target; }; extern struct PlayerF10 playersF10[] asm("gUnk_03003CE0"); extern s32 angleF10(s16, s16) asm("ArcTan2"); /* [SetActorFacingTowardPlayerPacket] Uses the same octant/facing conversion as sub_08095E70, with target @@ -365,7 +365,7 @@ s8 motionStart99(struct MotionStart99 *arg0, u32 arg1, u32 arg2, u32 arg3) { } struct NearEntity99 { u8 pad[0x14]; s32 x, y; }; -struct NearPlayer99 { u8 pad[0x30]; u32 flags; u8 pad34[0x114]; u16 *target; }; +struct NearPlayer99 { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 pad34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; u16 *target; }; extern struct NearPlayer99 nearPlayers99[] asm("gUnk_03003CE0"); /* [SelectPlayerByAscendingDistanceWithinLimit] Builds player distance/index pairs from packet coordinates * relative to actor +0x14/+0x18, sorts squared distances ascending and compares the first Sqrt result, @@ -662,7 +662,7 @@ s32 sub_08096394(s32 inputX, s32 inputY) flags = player->flags; if (flags & 0x2000) goto skip; if (flags & 0x40002) goto skip; - temp7 = 0x148; + temp7 = PLAYER_FIELD(0x148); asm("" : "+r"(temp7)); temp0 = (u32)player + temp7; @@ -681,7 +681,7 @@ s32 sub_08096394(s32 inputX, s32 inputY) skip: distance += 2; i++; - temp7 = 0x14C; + temp7 = PLAYER_SIZE; player = (void *)((u32)player + temp7); } while (i < count); @@ -788,7 +788,7 @@ s32 sub_08096494(s32 inputX, s32 inputY) flags = player->flags; if (flags & 0x2000) goto skip; if (flags & 0x40002) goto skip; - temp7 = 0x148; + temp7 = PLAYER_FIELD(0x148); asm("" : "+r"(temp7)); temp0 = (u32)player + temp7; @@ -807,7 +807,7 @@ s32 sub_08096494(s32 inputX, s32 inputY) skip: distance += 2; i++; - temp7 = 0x14C; + temp7 = PLAYER_SIZE; player = (void *)((u32)player + temp7); } while (i < count); @@ -859,7 +859,7 @@ s32 sub_08096494(s32 inputX, s32 inputY) } return entries[1]; } -struct SelectPlayer99 { u8 pad[0x30]; u32 flags; u8 pad34[0x114]; u8 *target; }; +struct SelectPlayer99 { u8 pad[PLAYER_FIELD(0x30)]; u32 flags; u8 pad34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; u8 *target; }; extern struct SelectPlayer99 selectPlayers99[] asm("gUnk_03003CE0"); /* [SelectPlayerInAlternatingOrder] Uses the low bit of counter array 0x03000290 at the supplied byte index to * choose one of two player visitation orders. Rejects flags 0x2000/0x40002 and packet state nibble 11 while @@ -899,7 +899,7 @@ s32 sub_08096594(u8 arg0) case 3: selected = 2; break; } } - offset = selected * 0x14C; + offset = selected * PLAYER_SIZE; player = (void *)(offset + (u32)base); flags = player->flags; if (flags & 0x2000) goto next; @@ -912,7 +912,7 @@ s32 sub_08096594(u8 arg0) done: return selected; } -struct Body99640 {u16 index;u8 pad2[10];u16 state;u8 padE[6];s32 x,y;u8 pad1C[0x212];u8 radiusX,radiusY;u8 tail[0xB0];}; +struct Body99640 {u16 index;u8 pad2[10];u16 state;u8 padE[6];s32 x,y;u8 pad1C[ENEMY_FIELD(0x22E) - 0x1C];u8 radiusX,radiusY;u8 tail[ENEMY_SIZE - ENEMY_FIELD(0x230)];}; extern struct Body99640 *bodies99640 asm("gUnk_030056F4"); extern u32 active99640 asm("gUnk_030056FC"); extern s16 sine99640[] asm("gUnk_080B9704"); @@ -979,7 +979,7 @@ void sub_08096640(struct Body99640 *arg0) } } extern u16 shakeScale99 asm("gUnk_0300029C"); -struct ShakeView99 { u8 pad[0x18]; u16 vertical; }; +struct ShakeView99 { u8 pad[SAVE_FIELD(0x18)]; u16 vertical; }; extern struct ShakeView99 *shakeView99 asm("gUnk_030034E0"); extern struct Task *shakeTask99 asm("gUnk_03000298"); extern void shakeOffset99(u32, s32) asm("sub_0800BB80"); @@ -2008,7 +2008,7 @@ s32 sub_08097A74(void *arg0, void *arg1, s32 arg2, s16 arg3) { s8 temp_r5; void *temp_r0; - temp_r0 = M2C_FIELD(arg1, void **, 0x148); + temp_r0 = M2C_FIELD(arg1, void **, PLAYER_FIELD(0x148)); temp_r5 = sub_08096060(arg0, (u16) M2C_FIELD(temp_r0, u16 *, 0) >> 4, (u32) (M2C_FIELD(temp_r0, u16 *, 2) << 0x14) >> 0x14, arg3); if (temp_r5 != 0) { M2C_FIELD(arg0, u16 *, 8) = sub_08013E90(arg2, arg0 + 0x14, M2C_FIELD(arg0, u16 *, 8), 0, 0); @@ -2134,7 +2134,7 @@ void sub_08097C6C(void) if (obj != 0) { if (obj[2] != 0) { u32 *dst = (u32 *)gUnk_030034E0; - *(u16 *)((u8 *)dst + 0x18) = ss2ScaleSave; + *(u16 *)((u8 *)dst + SAVE_FIELD(0x18)) = ss2ScaleSave; sub_080003A8((u32)obj); } sub_08001538((u32)gUnk_03000298); @@ -2164,7 +2164,7 @@ void sub_08097CA8(u16 value) *(u32 *)(task + 0x24) = 0; *(u32 *)(task + 8) = 0x4C; sub_08000274_(task, (u32)(s32)(s16)value, 0); - ss2ScaleSave = *(u16 *)((u8 *)gUnk_030034E0 + 0x18); + ss2ScaleSave = *(u16 *)((u8 *)gUnk_030034E0 + SAVE_FIELD(0x18)); } /* [SetBg2EffectTransformPosition] Stores the low 16 bits of two inputs at transform 0x030002A0 +4/+6. BG2 * affine consumers add these position fields to the separate offset fields. */ diff --git a/src/code_08097E28.c b/src/code_08097E28.c index 61ffb88c..1a9c3a78 100644 --- a/src/code_08097E28.c +++ b/src/code_08097E28.c @@ -239,14 +239,14 @@ extern void sub_0809975C(void); extern void sub_080997C0(u16,u16); #endif struct Sprite108 {u32 base,p4,data,palette,p10,p14,p18;u8 payload[24];}; -struct Player108 {u8 p0[0x30];u32 flags;u8 p34[0x118];}; -struct Spr108 {u8 *sprite;u8 p4[0x148];}; +struct Player108 {u8 p0[PLAYER_FIELD(0x30)];u32 flags;u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)];}; +struct Spr108 {u8 *sprite;u8 p4[PLAYER_SIZE - 0x4];}; struct Actor108 { u16 f0; u16 f2; u8 p4[4]; u16 f8; u8 pA[2]; u16 state; u8 pE[6]; s32 x; s32 y; u8 p1C[0x30]; s32 damage; s32 f50; u8 p54[6]; u16 f5A; u16 f5C; u16 f5E; u8 p60[8]; u16 anim; u16 frame; u16 tick; u16 f6E; u8 p70[0x164]; u16 f1D4; u16 f1D6; u8 p1D8[0x24]; u8 lo:4; u8 hi:4; u8 phase; u8 next; u8 p1FF; u8 f200; u8 p201; u16 f202; - u8 res[0xD4]; u16 f2D8; u16 f2DA; + u8 res[ENEMY_FIELD(0x2D8) - 0x204]; u16 f2D8; u16 f2DA; }; #define S108(p,o) (*(s16 *)((u8 *)(p)+(o))) #define I108(p,o) (*(s32 *)((u8 *)(p)+(o))) @@ -295,7 +295,7 @@ extern u32 screenS108(s16,s16,s16 *,s16 *,s32,s32) asm("sub_0800BC08"); if (sub_0800CCCC() == 0 && sub_0800CC98() == 0) { \ zero = sub_0800CD34(); \ if (zero == 0) { \ - sub_08000AF0(palette108 + 0x10, (u8 *)sprite->palette + (*P108(resource, 0xD6) << 5), 1); \ + sub_08000AF0(palette108 + 0x10, (u8 *)sprite->palette + (*P108(resource, ENEMY_DATA_FIELD(0xD6)) << 5), 1); \ priority = sub_0800BC44(actor108->x >> 8, actor108->y >> 8, 0); \ actor108->f6E = anim108(sprite, actor108->anim, &actor108->frame, &actor108->tick, 1); \ screenS108((actor108->x << 8) >> 16, (actor108->y << 8) >> 16, &sx, &sy, zero, zero); \ @@ -368,8 +368,8 @@ void sub_08098108(void *input) actor->tick = 0; actor->frame = 0; actor->anim = 0; - actor->f5C = actor->f1D6 = S108(resource, 6) * 3; - value = S108(resource, 4) * 2; + actor->f5C = actor->f1D6 = S108(resource, ENEMY_DATA_FIELD(6)) * 3; + value = S108(resource, ENEMY_DATA_FIELD(4)) * 2; actor->f5E = actor->f1D4 = (value * 4 + value) * 2; actor->state = 0; mode = 0; @@ -387,7 +387,7 @@ void sub_08098108(void *input) do { entry = 0; do { - *(u32 *)((u8 *)seen108 + entry * 4 + player * 0x14C) = 0; + *(u32 *)((u8 *)seen108 + entry * 4 + player * PLAYER_SIZE) = 0; entry++; } while (entry <= 4); player++; @@ -609,7 +609,7 @@ void sub_08098108(void *input) actor108->frame = 0; } sprite->payload[0] = palette108; - sub_08000AF0(palette108 + 0x10, (u8 *)sprite->palette + (*P108(resource, 0xD6) << 5), 1); + sub_08000AF0(palette108 + 0x10, (u8 *)sprite->palette + (*P108(resource, ENEMY_DATA_FIELD(0xD6)) << 5), 1); if (sub_08098004() & 1) priority = sub_08097FF8(); else @@ -664,7 +664,7 @@ void sub_08098108(void *input) if (sub_0800CCCC() == 0 && sub_0800CC98() == 0) { zero = sub_0800CD34(); if (zero == 0) { - sub_08000AF0(palette108 + 0x10, (u8 *)sprite->palette + (*P108(resource, 0xD6) << 5), 1); + sub_08000AF0(palette108 + 0x10, (u8 *)sprite->palette + (*P108(resource, ENEMY_DATA_FIELD(0xD6)) << 5), 1); priority = sub_0800BC44(actor108->x >> 8, actor108->y >> 8, 0); actor108->f6E = anim108(sprite, actor108->anim, &actor108->frame, &actor108->tick, 1); screen108((actor108->x << 8) >> 16, (actor108->y << 8) >> 16, &sx, &sy, zero, zero); @@ -692,7 +692,7 @@ void sub_08098108(void *input) RENDER_108(); players108[sub_080020F4()].flags &= ~1; sound108(0xD); - transition108(actor108, sprite, *P108(resource, 0xD6), palette108); + transition108(actor108, sprite, *P108(resource, ENEMY_DATA_FIELD(0xD6)), palette108); if (!(players108[sub_080020F4()].flags & 0x2000) && actor108->f5A != 0) { reward = reward108(inventory108, resource); floatingOffset = 0x1D; @@ -720,7 +720,7 @@ void sub_08098108(void *input) #undef S108 #undef I108 #undef P108 -struct Player98F {u8 p0[0x20];u16 state;u8 p22[14];u32 flags;u8 p34[0x34];u8 active;u8 p69[0x1F];u16 angle;u16 p8A;s32 x,y;u8 p94[0x1C];u16 motion;u8 pB2[0x16];u16 timer;s16 direction;u16 speed;u8 pCE[0x16];u32 seen[26];}; +struct Player98F {u8 p0[PLAYER_FIELD(0x20)];u16 state;u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)];u8 active;u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)];u16 angle;u16 p8A;s32 x,y;u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)];u16 motion;u8 pB2[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0xB2)];u16 timer;s16 direction;u16 speed;u8 pCE[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xCE)];u32 seen[26];}; struct Entity98F {u16 index;u8 p2[10];u16 state;u8 pE[6];s32 x,y;u8 p1C[0x34];u32 counter;}; extern struct Player98F players98F[] asm("gUnk_03003CE0"); extern struct Entity98F *entity98F asm("gUnk_030002D0"); @@ -772,7 +772,7 @@ u8 sub_08098F2C(void) if (players98F[sub_080020F4()].timer == 0) entity98F->counter++; } -struct Player99468 {u8 p0[0x20];u16 state;u8 p22[14];u32 flags;u8 p34[0x34];u8 active;u8 p69[0x1F];u16 angle;u16 p8A;s32 x,y;u8 p94[0x1C];u16 motion;u8 pB2[0x16];u16 timer;s16 direction;u16 speed;u8 pCE[0x16];u32 seen[26];}; +struct Player99468 {u8 p0[PLAYER_FIELD(0x20)];u16 state;u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)];u8 active;u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)];u16 angle;u16 p8A;s32 x,y;u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)];u16 motion;u8 pB2[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0xB2)];u16 timer;s16 direction;u16 speed;u8 pCE[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xCE)];u32 seen[26];}; struct Entity99468 {u16 index;u8 p2[10];u16 state;u8 pE[6];s32 x,y;u8 p1C[0x34];u32 counter;}; extern struct Player99468 players99468[] asm("gUnk_03003CE0"); extern struct Entity99468 *entity99468 asm("gUnk_030002D0"); @@ -873,7 +873,7 @@ void sub_08099468(u32 unused, s32 dir) vx = gUnk_080B9704[gUnk_085186DC[dir] + 0x40] * 0x180 / 256; x = entity99468->x; y = entity99468->y; - t071Init(&sprite, 0x50130, 5, -1, 0); + t071Init(&sprite, RES_ID(0x50130), 5, -1, 0); sub_08000AF0(0x15, (void *)(sprite.fC + 0x20), 1); sprite.f1D = 5; count = 0x10D; @@ -981,14 +981,14 @@ void sub_080997C0(u16 a, u16 b) sub_08000274_3((u32)t, a, b); } struct Sprite99 {u32 base,p4,data,palette,p10,p14,p18;u8 payload[24];}; -struct Player99 {u8 p0[0x30];u32 flags;u8 p34[0x118];}; +struct Player99 {u8 p0[PLAYER_FIELD(0x30)];u32 flags;u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)];}; struct Spr99 {u8 *sprite;u8 p4[0x148];}; struct Actor99 { u16 f0; u16 f2; u8 p4[4]; u16 f8; u8 pA[2]; u16 state; u8 pE[6]; s32 x; s32 y; u8 p1C[0x30]; s32 damage; s32 f50; u8 p54[6]; u16 f5A; u16 f5C; u16 f5E; u8 p60[8]; u16 anim; u16 frame; u16 tick; u16 f6E; u8 p70[0x164]; u16 f1D4; u16 f1D6; u8 p1D8[0x24]; u8 lo:4; u8 hi:4; u8 phase; u8 next; u8 p1FF; u8 f200; u8 p201; u16 f202; - u8 res[0xD4]; u16 f2D8; u16 f2DA; + u8 res[ENEMY_FIELD(0x2D8) - 0x204]; u16 f2D8; u16 f2DA; }; #define S99(p,o) (*(s16 *)((u8 *)(p)+(o))) #define I99(p,o) (*(s32 *)((u8 *)(p)+(o))) @@ -1035,7 +1035,7 @@ extern void quake99(u32) asm("sub_08097CA8"); extern void spawn99(u32) asm("sub_0809AE88"); extern void start99(void) asm("sub_0809AE24"); extern void end99(void) asm("sub_0809AE50"); -#define PAL99 (*P99(resource, 0xD6)) +#define PAL99 (*P99(resource, ENEMY_DATA_FIELD(0xD6))) #define RENDER_99() { s32 zero; players99[sub_080020F4()].flags |= 1; if (sub_0800CCCC() == 0 && sub_0800CC98() == 0) { zero = sub_0800CD34(); if (zero == 0) { sub_08000AF0(palette99 + 0x10, (u8 *)sprite->palette + (PAL99 << 5), 1); priority = sub_0800BC44(actor99->x >> 8, actor99->y >> 8, 0); actor99->f6E = anim99(sprite, 0, &actor99->frame, &actor99->tick, 1); screen99((actor99->x << 8) >> 16, (actor99->y << 8) >> 16, &sx, &sy, zero, zero); draw99(sx, sy, actor99->anim, actor99->frame, priority, sprite->payload, sprite->data, sprite->base); if (blink99 & 1) draw99(sx, sy - 1, 0x18, 0, priority, sprite->payload, sprite->data, sprite->base); } } sub_080003F0(); } @@ -1100,8 +1100,8 @@ void sub_08099838(void *input) actor->tick = 0; actor->frame = 0; actor->anim = 0; - actor->f5C = actor->f1D6 = S99(resource, 6) * 3; - value = S99(resource, 4) * 2; + actor->f5C = actor->f1D6 = S99(resource, ENEMY_DATA_FIELD(6)) * 3; + value = S99(resource, ENEMY_DATA_FIELD(4)) * 2; actor->f5E = actor->f1D4 = (value * 4 + value) * 2; actor->state = 0; mode = 0; @@ -1119,7 +1119,7 @@ void sub_08099838(void *input) do { entry = 0; do { - *(u32 *)((u8 *)seen99 + entry * 4 + player * 0x14C) = 0; + *(u32 *)((u8 *)seen99 + entry * 4 + player * PLAYER_SIZE) = 0; entry++; } while (entry <= 4); player++; @@ -1375,7 +1375,7 @@ void sub_08099838(void *input) #undef I99 #undef P99 extern s32 x102A5[] asm("gUnk_03003D6C"); -struct Player102A5 {u8 p0[0x20];u16 state;u8 p22[14];u32 flags;u8 p34[0x34];u8 active;u8 p69[0x1F];u16 angle;u16 p8A;s32 x,y;u8 p94[0x1C];u16 motion;u8 pB2[0x16];u16 timer;s16 direction;u16 speed;u8 pCE[0x16];u32 seen[26];}; +struct Player102A5 {u8 p0[PLAYER_FIELD(0x20)];u16 state;u8 p22[PLAYER_FIELD(0x30)-PLAYER_FIELD(0x22)];u32 flags;u8 p34[0x34];u8 active;u8 p69[0x1F];u16 angle;u16 p8A;s32 x,y;u8 p94[0x1C];u16 motion;u8 pB2[0x16];u16 timer;s16 direction;u16 speed;u8 pCE[0x16];u32 seen[26];}; struct Entity102A5 {u16 index;u8 p2[10];u16 state;u8 pE[6];s32 x,y;u8 p1C[0x34];u32 counter;}; extern struct Player102A5 players102A5[] asm("gUnk_03003CE0"); extern struct Entity102A5 *entity102A5 asm("gUnk_030002DC"); @@ -1391,7 +1391,7 @@ u8 sub_0809A5E0(void) u16 a, lo; s32 id; - { s32 k; struct Entity102A5 *e; k=sub_080020F4(); e=entity102A5; asm("" : : "r"(players102A5)); dx=(e->x-x102A5[k*83])>>8; } + { s32 k; struct Entity102A5 *e; k=sub_080020F4(); e=entity102A5; asm("" : : "r"(players102A5)); dx=(e->x-x102A5[k*(PLAYER_SIZE / 4)])>>8; } dy = (entity102A5->y - players102A5[sub_080020F4()].y) >> 8; if (Sqrt(dx * dx + dy * dy) <= 0x2F && sub_0800CDF8() == 0 && sub_0800CCCC() == 0 && sub_0800CD8C() == 0 && entity102A5->state != 0xB && !(players102A5[sub_080020F4()].flags & 0x2000) @@ -1402,8 +1402,8 @@ u8 sub_0809A5E0(void) players102A5[sub_080020F4()].motion = 0xFFFE; id = sub_080020F4(); players102A5[id].angle += delta102A5(entity102A5, &players102A5[sub_080020F4()]); - { s32 i; u32 index; u32 *dest; u32 n; struct Entity102A5 *e; i=sub_080020F4(); e=entity102A5; index=e->index; index<<=2; index+=i*0x14c; dest=(u32 *)((u8 *)players102A5+0xe4+index); n=e->counter; *dest=n; e->counter=n+1; } - dx = (x102A5[sub_080020F4()*83] - entity102A5->x) >> 8; + { s32 i; u32 index; u32 *dest; u32 n; struct Entity102A5 *e; i=sub_080020F4(); e=entity102A5; index=e->index; index<<=2; index+=i*PLAYER_SIZE; dest=(u32 *)((u8 *)players102A5+PLAYER_FIELD(0xe4)+index); n=e->counter; *dest=n; e->counter=n+1; } + dx = (x102A5[sub_080020F4()*(PLAYER_SIZE / 4)] - entity102A5->x) >> 8; dy = (players102A5[sub_080020F4()].y - entity102A5->y) >> 8; a = ArcTan2(dx, dy); lo = a << 3; @@ -1428,7 +1428,7 @@ u8 sub_0809A5E0(void) } return result; } -struct Player834 {u8 p0[0x20];u16 state;u8 p22[14];u32 flags;u8 p34[0x34];u8 active;u8 p69[0x23];s32 x,y;u8 p94[0x1C];u16 motion;u8 pB2[0x32];u32 seen[25];u16 *home;}; +struct Player834 {u8 p0[PLAYER_FIELD(0x20)];u16 state;u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)];u8 active;u8 p69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)];s32 x,y;u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)];u16 motion;u8 pB2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)];u32 seen[25];u16 *home;}; struct Entity834 {u16 index;u8 p2[10];u16 state;u8 pE[6];s32 x,y;u8 p1C[0x34];u32 counter;}; struct Sprite834 {u32 f0,f4,f8;u8 *fC;u8 pad10[12];u8 f1C[13];u8 f29;u8 pad2A[10];}; struct Obj834 {u32 f0,f4,f8;s32 fC;}; @@ -1685,10 +1685,10 @@ void sub_0809AE88(u16 arg) do { t->f10 = t->f20 + 0x3FC; t->fC = (u32) sub_0809A834; t->f24 = z; t->f8 = 0x46; sub_08000274_2(t, arg); } while (0); } struct SpriteAEE8 {u32 base,p4,data,palette,p10,p14,p18;u8 payload[24];}; -struct PlayerAEE8 {u8 p0[0x30];u32 flags;u8 p34[0x118];}; +struct PlayerAEE8 {u8 p0[PLAYER_FIELD(0x30)];u32 flags;u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)];}; struct PosAEE8 {s32 x,y;}; struct OrbitAEE8 {s32 x,y;u8 angle;u8 pad[3];}; -struct ResAEE8 {u8 p0[4];s16 f4;s16 f6;u8 p8[0x22];u8 f2A;u8 f2B;u8 p2C[0xA8];u16 fD4;u16 fD6;}; +struct ResAEE8 {u8 p0[ENEMY_FIELD(0x208) - 0x204];s16 f4;s16 f6;u8 p8[0x22];u8 f2A;u8 f2B;u8 p2C[0xA8];u16 fD4;u16 fD6;}; struct ActorAEE8 { u16 f0; u16 f2; u8 p4[4]; u16 f8; u8 pA[2]; u16 state; u8 pE[2]; u16 f10; u8 p12[2]; s32 x; s32 y; u8 p1C[0x2C]; u16 f48; u16 f4A; s32 damage; s32 f50; s32 f54; u8 p58[2]; u16 f5A; u16 f5C; u16 f5E; @@ -1857,7 +1857,7 @@ void sub_0809AEE8(void *input) do { j = 0; do { - *(u32 *)((u8 *)seenAEE8 + j * 4 + i * 0x14C) = 0; + *(u32 *)((u8 *)seenAEE8 + j * 4 + i * PLAYER_SIZE) = 0; j++; } while (j <= 4); i++; @@ -1954,7 +1954,7 @@ void sub_0809AEE8(void *input) shake = 0; orbitDone = 0; for (i = 0; i <= 1; i++) { - allies[i] = (struct ActorAEE8 *)(poolAEE8 + (i * 0x2E0 + 0x8A0)); + allies[i] = (struct ActorAEE8 *)(poolAEE8 + (i * ENEMY_SIZE + 3 * ENEMY_SIZE)); activeAEE8 |= 1 << (i + 3); sub_0801A0A4(allies[i]); { struct ActorAEE8 *a = allies[i]; @@ -2244,7 +2244,7 @@ void sub_0809AEE8(void *input) } #undef RENDER_AEE8 struct SprC1B4 { u32 f0, f4, f8, fC; u8 pad10[0xC]; u8 f1C[7]; u8 f23; u8 f24; u8 pad25[0xF]; }; -struct PlayerC1B4 { u8 p0[0x20]; u16 state; u8 p22[0xe]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x23]; s32 x, y; u8 p94[0x1c]; u16 fb0; u8 pb2[0x32]; u32 fe4[26]; }; +struct PlayerC1B4 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 f68; u8 p69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x, y; u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 fb0; u8 pb2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; u32 fe4[26]; }; struct ObjC1B4 { u16 f0; u8 p2[6]; s16 f8; u16 fa, fc; u8 pe[6]; s32 x, y; u8 p1c[0x34]; s32 f50; }; extern struct PlayerC1B4 playersC1B4[] asm("gUnk_03003CE0"); extern struct ObjC1B4 *objC1B4 asm("gUnk_030002EC"); @@ -2339,7 +2339,7 @@ void sub_0809C1B4(u16 arg0) taskC1B4()->f8 = 0; } struct PosC4E8 { u16 x, y; }; -struct PlayerC4E8 { u8 p0[0x20]; u16 state; u8 p22[0xe]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x23]; s32 x, y; u8 p94[0x1c]; u16 fb0; u8 pb2[0x32]; u32 fe4[25]; struct PosC4E8 *pos; }; +struct PlayerC4E8 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 f68; u8 p69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x, y; u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 fb0; u8 pb2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; u32 fe4[25]; struct PosC4E8 *pos; }; extern struct PlayerC4E8 playersC4E8[] asm("gUnk_03003CE0"); extern struct ObjC1B4 *objC4E8 asm("gUnk_030002EC"); struct XYC4E8 { s32 x, y; }; @@ -2541,7 +2541,7 @@ void sub_0809C4E8(u16 which) u32 playerOffset = sub_080020F4(); s32 effectY = (pos.y >> 8) + 12; register s32 *playerYBase asm("r3"); - playerOffset *= 0x14C; + playerOffset *= PLAYER_SIZE; playerYBase = (s32 *)playersYC4E8; @@ -2578,7 +2578,7 @@ void sub_0809C4E8(u16 which) currentTask->f8 = 0; } } -struct PlayerC8F4 { u8 p0[0x20]; u16 state; u8 p22[0xe]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x1f]; u16 f88; u8 p8a[2]; s32 x, y; u8 p94[0x1c]; u16 fb0; u8 pb2[0x16]; u16 fc8, fca, fcc; u8 pce[0x16]; u32 fe4[26]; }; +struct PlayerC8F4 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 f68; u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; u16 f88; u8 p8a[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x8A)]; s32 x, y; u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 fb0; u8 pb2[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0xB2)]; u16 fc8, fca, fcc; u8 pce[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xCE)]; u32 fe4[26]; }; extern struct PlayerC8F4 playersC8F4[] asm("gUnk_03003CE0"); extern u16 atanC8F4(s16, s16) asm("ArcTan2"); extern u16 hitC8F4(void *, void *) asm("sub_0801ED8C"); @@ -2652,8 +2652,8 @@ void sub_0809C8F4_(struct ObjC1B4 *o) struct SprCC2C { u32 f0, f4, f8, fC; u8 pad10[0xC]; u8 f1C[7]; u8 f23; u8 f24; u8 pad25[0xF]; }; struct PosCC2C { u16 x, y; }; struct XYCC2C { u32 x, y; }; -struct PlayerCC2C { u8 p0[0x30]; u32 flags; u8 p34[0x114]; struct PosCC2C *pos; }; -struct SubCC2C { u8 p0[4]; s16 f4, f6; u8 p8[0xce]; u16 fd6; }; +struct PlayerCC2C { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; struct PosCC2C *pos; }; +struct SubCC2C { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0xce]; u16 fd6; }; struct EntCC2C { u16 f0, f2; u8 p4[4]; u16 f8; u8 pa[2]; u16 fc; u8 pe[6]; s32 x, y; u8 p1c[0x2c]; u16 f48; u8 p4a[2]; s32 f4c; s32 f50, f54; @@ -2736,7 +2736,7 @@ void sub_0809CC2C_(u8 idx) palNo = 6; - ent = (struct EntCC2C *)(entsCC2C + (idx * 0x2e0 + 0x2e0)); + ent = (struct EntCC2C *)(entsCC2C + (idx * ENEMY_SIZE + ENEMY_SIZE)); sub_0801A0A4(ent); maskCC2C |= 1 << (idx + 1); tblCC2C[idx] = ent; @@ -2757,8 +2757,8 @@ void sub_0809CC2C_(u8 idx) ent->f202 = ent->f2; ent->f200 = 0xFF; ent->f1fd = 2; - initCC2C(&spr1, 0x5004C, 6, -1, 0); - initCC2C(&spr2, 0x5004B, 6, -1, 0); + initCC2C(&spr1, RES_ID(0x5004C), 6, -1, 0); + initCC2C(&spr2, RES_ID(0x5004B), 6, -1, 0); ent->f5c = ent->f1d6 = sub->f6 * 3; ent->f5e = ent->f1d4 = (sub->f4 << 1) * 10; ent->f6c = 0; @@ -2777,7 +2777,9 @@ void sub_0809CC2C_(u8 idx) p6c = &ent->f6c; p6a = &ent->f6a; p68 = &ent->f68; +#ifndef REGION_USA do { +#endif if (r == 1) { limit = 90; speed = 0x100; @@ -2948,10 +2950,12 @@ void sub_0809CC2C_(u8 idx) } } } +#ifndef REGION_USA } while (0); +#endif } struct PosD374 { u16 x, y; }; -struct PlayerD374 { u8 p0[0x20]; u16 state; u8 p22[0xe]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x1f]; u16 f88; u8 p8a[0x26]; u16 fb0; u8 pb2[0x32]; u32 fe4[25]; struct PosD374 *pos; }; +struct PlayerD374 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 f68; u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; u16 f88; u8 p8a[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x8A)]; u16 fb0; u8 pb2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; u32 fe4[25]; struct PosD374 *pos; }; struct ObjectD374 { u16 f0; u8 p2[6]; s16 f8; u16 fa, fc; u8 pe[6]; s32 x,y; u8 p1c[0x34]; s32 f50; }; extern struct PlayerD374 playersD374[] asm("gUnk_03003CE0"); extern u16 sqrtD374(s32) asm("Sqrt"); @@ -2973,11 +2977,11 @@ s32 sub_0809D374(struct ObjectD374 *o) { u32 angle, direction, rem; indexD374 = sub_080020F4(); - scaledIndexD374 = indexD374 * 0x14C; + scaledIndexD374 = indexD374 * PLAYER_SIZE; /* Share the position-slot base across both player lookups. */ - positionBaseD374 += 0x148; + positionBaseD374 += PLAYER_FIELD(0x148); px = (*(struct PosD374 **)(positionBaseD374 + scaledIndexD374))->x >> 4; - py = (u32)(*(struct PosD374 **)(positionBaseD374 + sub_080020F4() * 0x14C))->y << 20; + py = (u32)(*(struct PosD374 **)(positionBaseD374 + sub_080020F4() * PLAYER_SIZE))->y << 20; px -= (s16)x; py = (py >> 20) - (s16)y; dx = px; diff --git a/src/code_0809D878.c b/src/code_0809D878.c index e90b658b..27d91ab1 100644 --- a/src/code_0809D878.c +++ b/src/code_0809D878.c @@ -18,22 +18,27 @@ extern s32 gUnk_03000324; #define SD878(p,o) (*(s16 *)((u8 *)(p)+(o))) #define ID878(p,o) (*(s32 *)((u8 *)(p)+(o))) #define PD878(p,o) ((u16 *)((u8 *)(p)+(o))) +#ifdef REGION_USA +#define PAL_D878 (*PD878(resource, ENEMY_DATA_FIELD(0xD6))) +#else +#define PAL_D878 (*pal) +#endif struct SpriteD878 {u32 base,p4,data,palette,p10,p14,p18;u8 payload[24];}; -struct PlayerD878 {u8 p0[0x30];u32 flags;u8 p34[0x118];}; +struct PlayerD878 {u8 p0[PLAYER_FIELD(0x30)];u32 flags;u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)];}; struct PosD878 {s32 x,y;}; struct ObjD878 {u32 f0,f4,f8;s32 fC;}; -struct ResD878 {u8 p0[4];s16 f4;s16 f6;u8 p8[0xCE];u16 fD6;}; +struct ResD878 {u8 p0[ENEMY_FIELD(0x208) - 0x204];s16 f4;s16 f6;u8 p8[0xCE];u16 fD6;}; struct ActorD878 { u16 f0; u16 f2; u8 p4[4]; u16 f8; u8 pA[2]; u16 state; u8 pE[6]; s32 x; s32 y; u8 p1C[0x30]; s32 damage; s32 f50; u8 p54[6]; u16 f5A; u16 f5C; u16 f5E; u8 p60[8]; u16 anim; u16 frame; u16 tick; u16 f6E; u8 p70[0x164]; u16 f1D4; u16 f1D6; u8 p1D8[0x24]; u8 lo:4; u8 hi:4; u8 phase; u8 next; u8 p1FF; u8 f200; u8 p201; u16 f202; - u8 res[0xD4]; u16 f2D8; u16 f2DA; + u8 res[ENEMY_FIELD(0x2D8) - 0x204]; u16 f2D8; u16 f2DA; }; extern struct ActorD878 *actorD878 asm("gUnk_03000310"); extern u16 paletteD878 asm("gUnk_03000314"); extern u32 activeD878 asm("gUnk_030056FC"); -extern u32 seenD878[][83] asm("gUnk_03003DC4"); +extern u32 seenD878[][PLAYER_SIZE / 4] asm("gUnk_03003DC4"); extern struct PlayerD878 playersD878[] asm("gUnk_03003CE0"); extern void *inventoryD878 asm("gUnk_030034E0"); extern u8 *stateD878 asm("gUnk_03005CF4"); @@ -72,7 +77,7 @@ extern void sub_0809FA64(u16); if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0) { \ zero = sub_0800CD34(); \ if (zero == 0) { \ - sub_08000AF0(paletteD878 + 0x10, (u8 *)sprite.palette + (*pal << 5), 1); \ + sub_08000AF0(paletteD878 + 0x10, (u8 *)sprite.palette + (PAL_D878 << 5), 1); \ priority = sub_0800BC44(actorD878->x >> 8, actorD878->y >> 8, 0); \ sprite.payload[0] = paletteD878; \ animD878(&sprite, actorD878->anim, &actorD878->frame, &actorD878->tick, zero); \ @@ -108,7 +113,9 @@ void sub_0809D878(void *input) s32 finished; u16 *frame; u16 *tick; +#ifndef REGION_USA u16 *pal; +#endif struct ActorD878 *actor; u16 *animation; s32 mode; @@ -142,8 +149,8 @@ void sub_0809D878(void *input) } initD878(&sprite, 0x50007, paletteD878, -1, 1); sprite.payload[0] = paletteD878; - actor->f5C = actor->f1D6 = SD878(resource, 6) * 3; - value = SD878(resource, 4) * 2; + actor->f5C = actor->f1D6 = SD878(resource, ENEMY_DATA_FIELD(6)) * 3; + value = SD878(resource, ENEMY_DATA_FIELD(4)) * 2; actor->f5E = actor->f1D4 = (value * 4 + value) * 2; actor->phase = 2; actor->next = 2; @@ -172,11 +179,13 @@ void sub_0809D878(void *input) tick = &actor->tick; frame = &actor->frame; animation = &actor->anim; - pal = PD878(resource, 0xD6); +#ifndef REGION_USA + pal = PD878(resource, ENEMY_DATA_FIELD(0xD6)); +#endif do { entry = 0; do { - *(u32 *)((u8 *)seenD878 + entry * 4 + player * 0x14C) = 0; + *(u32 *)((u8 *)seenD878 + entry * 4 + player * PLAYER_SIZE) = 0; entry++; } while (entry <= 4); player++; @@ -310,7 +319,7 @@ void sub_0809D878(void *input) actorD878->tick = 0; actorD878->frame = 0; } - sub_08000AF0(paletteD878 + 0x10, (u8 *)sprite.palette + (*pal << 5), 1); + sub_08000AF0(paletteD878 + 0x10, (u8 *)sprite.palette + (PAL_D878 << 5), 1); if (sub_08098004() & 1) priority = sub_08097FF8(); else @@ -364,7 +373,7 @@ void sub_0809D878(void *input) if (sub_0800CCCC() == 0 && sub_0800CC98() == 0) { zero = sub_0800CD34(); if (zero == 0) { - sub_08000AF0(paletteD878 + 0x10, (u8 *)sprite.palette + (*pal << 5), 1); + sub_08000AF0(paletteD878 + 0x10, (u8 *)sprite.palette + (PAL_D878 << 5), 1); priority = sub_0800BC44(actorD878->x >> 8, actorD878->y >> 8, 0); sprite.payload[0] = paletteD878; animD878(&sprite, actorD878->anim, &actorD878->frame, &actorD878->tick, zero); @@ -392,7 +401,7 @@ void sub_0809D878(void *input) RENDER_D878(); playersD878[sub_080020F4()].flags &= ~1; soundD878(0xD); - transitionD878(actorD878, &sprite, *pal, paletteD878); + transitionD878(actorD878, &sprite, PAL_D878, paletteD878); if (!(playersD878[sub_080020F4()].flags & 0x2000) && actorD878->f5A != 0) { reward = rewardD878(inventoryD878, resource); floatingOffset = 0x1D; @@ -426,7 +435,7 @@ void sub_0809D878(void *input) #undef ID878 #undef PD878 union BgE468 { struct { u32 cnt:16; u32 spare:16; } bits; u16 half; }; -struct PlayerE468 {u8 p0[0xC8];u16 timer;s16 direction;u16 speed;u8 pCE[0x7E];}; +struct PlayerE468 {u8 p0[PLAYER_FIELD(0xC8)];u16 timer;s16 direction;u16 speed;u8 pCE[PLAYER_SIZE - PLAYER_FIELD(0xCE)];}; extern struct PlayerE468 playersE468[] asm("gUnk_03003CE0"); extern volatile u16 g31EE468 asm("gUnk_0300031E"); extern u8 g31CE468 asm("gUnk_0300031C"); @@ -866,13 +875,13 @@ s32 sub_0809EF84(void) struct Packed9F018 { u16 x,y; }; union Tail9F018 { u32 seen[26]; struct {u32 pad[25]; struct Packed9F018 *visual;} remote; }; struct Player9F018 { - u8 p0[0x20]; u16 state; u8 p22[14]; u32 flags; - u8 p34[0x34]; u8 active; u8 p69[0x1F]; u16 health,p8A; - s32 x,y; u8 p94[0x1C]; u16 motion; u8 pB2[0x32]; union Tail9F018 tail; + u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; + u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; u16 health,p8A; + s32 x,y; u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 motion; u8 pB2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; union Tail9F018 tail; }; struct Actor9F018 { u16 id; u8 p2[10]; u16 state; u8 pE[6]; s32 x,y; - u8 p1C[0x34]; u32 serial; u8 p54[0x286]; u16 paletteOffset; + u8 p1C[0x34]; u32 serial; u8 p54[ENEMY_FIELD(0x2DA) - 0x54]; u16 paletteOffset; }; struct Sprite9F018 {u32 base,p4,data,palette,p10,p14,p18;u8 payload[24];}; struct Draw9F018 {u32 p0[3];s32 y;}; @@ -1108,7 +1117,7 @@ void sub_0809F018(u16 kind) u32 playerOffset = sub_080020F4(); s32 effectY = (pos.y >> 8) + 12; register s32 *playerYBase asm("r3"); - playerOffset *= 0x14C; + playerOffset *= PLAYER_SIZE; playerYBase = (s32 *)playersY9F018; @@ -1141,8 +1150,8 @@ void sub_0809F018(u16 kind) pl[sub_080020F4()].motion=0xFFFE; player=sub_080020F4();actor=actor9F018; { - u32 offset = actor->id * 4 + player * 0x14C; - u8 *base = (u8 *)pl + 0xE4; + u32 offset = actor->id * 4 + player * PLAYER_SIZE; + u8 *base = (u8 *)pl + PLAYER_FIELD(0xE4); *(u32 *)(offset + (u32)base) = actor->serial++; } @@ -1162,13 +1171,13 @@ void sub_0809F018(u16 kind) struct Actor9F4A8 { u16 id; u8 pad2[10]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x34]; u32 serial; - u8 pad54[0x286]; u16 paletteOffset; + u8 pad54[ENEMY_FIELD(0x2DA) - 0x54]; u16 paletteOffset; }; struct Player9F4A8 { - u8 pad0[0x20]; u16 state; u8 pad22[14]; u32 flags; - u8 pad34[0x34]; u8 active; u8 pad69[0x1F]; - u16 health, pad8A; s32 x,y; u8 pad94[0x1C]; - u16 motion; u8 padB2[0x32]; u32 seen[26]; + u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; + u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 pad69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; + u16 health, pad8A; s32 x,y; u8 pad94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; + u16 motion; u8 padB2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; u32 seen[26]; }; struct Sprite9F4A8 { u32 base,pad4,data,palette,pad10,pad14,pad18; u8 payload[24]; }; struct DrawObj9F4A8 { u32 pad0[3]; s32 y; }; @@ -1495,15 +1504,15 @@ struct EntFB6 { u8 p70[0x164]; u16 f1D4, f1D6; u8 p1D8[0x24]; u8 lo:4; u8 hi:4; u8 f1FD, f1FE, p1FF; u8 f200; u8 p201; u16 f202; - u8 res[0xd4]; u16 f2D8, f2DA; + u8 res[ENEMY_FIELD(0x2D8) - 0x204]; u16 f2D8, f2DA; }; -struct AuxFB6 { u8 p0[4]; s16 f4, f6; u8 p8[0xce]; u16 fD6; }; +struct AuxFB6 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0xce]; u16 fD6; }; extern struct EntFB6 *actor9FB6C asm("gUnk_0300032C"); -struct PlayerFB6 { u8 p0[0x30]; u32 flags; u8 p34[0x118]; }; +struct PlayerFB6 { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; extern struct PlayerFB6 playersFB6[] asm("gUnk_03003CE0"); extern u16 palette9FB6C asm("gUnk_03000330"); extern u32 active9FB6C asm("gUnk_030056FC"); -extern u32 seen9FB6C[][83] asm("gUnk_03003DC4"); +extern u32 seen9FB6C[][PLAYER_SIZE / 4] asm("gUnk_03003DC4"); extern u8 players9FB6C[] asm("gUnk_03003CE0"); extern void *inventory9FB6C asm("gUnk_030034E0"); extern u8 config9FB6C[] asm("gUnk_084A3EB0"); @@ -1535,7 +1544,7 @@ extern s32 sound9FB6C(s32) asm("sub_08058688"); #define END_RENDER9FB6C() { \ actor9FB6C->f6E=anim9FB6C(&sprite,actor9FB6C->f68,&actor9FB6C->f6A,&actor9FB6C->f6C,1); \ screen9FB6C((s32)(actor9FB6C->x<<8)>>16,(s32)(actor9FB6C->y<<8)>>16,&sx,&sy,zero,zero); \ - sub_08000AF0(palette9FB6C+16,sprite.palette+(H9FB6C(resource,0xD6)<<5),1); \ + sub_08000AF0(palette9FB6C+16,sprite.palette+(H9FB6C(resource, ENEMY_DATA_FIELD(0xD6))<<5),1); \ draw9FB6C(sx,sy,actor9FB6C->f68,actor9FB6C->f6A,2,sprite.payload,sprite.data,sprite.base); \ } @@ -1585,8 +1594,8 @@ void sub_0809FB6C(void *input) } init9FB6C(&sprite,0x50009,palette9FB6C,-1,1); sprite.payload[0]=palette9FB6C; - actor->f5C=actor->f1D6=S9FB6C(resource,6)*3; - actor->f5E=actor->f1D4=(S9FB6C(resource,4)<<1)*10; + actor->f5C=actor->f1D6=S9FB6C(resource, ENEMY_DATA_FIELD(6))*3; + actor->f5E=actor->f1D4=(S9FB6C(resource, ENEMY_DATA_FIELD(4))<<1)*10; actor->fC=0; floatingTimer=0;flash=0; actor->f6C=0; actor->f6A=0; actor->f68=0; @@ -1599,7 +1608,7 @@ void sub_0809FB6C(void *input) do { entry=0; do { - *(u32 *)((u8 *)seen9FB6C + entry * 4 + player * 0x14C) = 0; + *(u32 *)((u8 *)seen9FB6C + entry * 4 + player * PLAYER_SIZE) = 0; entry++; } while(entry<=4); player++; @@ -1696,11 +1705,11 @@ void sub_0809FB6C(void *input) u32 old=flash; flash=old-1; if((old&1) && sub_0800CCCC()==0 && sub_0800CC98()==0 && sub_0800CD34()==0) { - sub_08000AF0(palette9FB6C+16,sprite.palette+(H9FB6C(resource,0xD6)<<5),1); + sub_08000AF0(palette9FB6C+16,sprite.palette+(H9FB6C(resource, ENEMY_DATA_FIELD(0xD6))<<5),1); draw9FB6C(sx,sy,*animation,*frame,priority,sprite.payload,sprite.data,sprite.base); } } else if(sub_0800CCCC()==0 && sub_0800CC98()==0 && sub_0800CD34()==0) { - sub_08000AF0(palette9FB6C+16,sprite.palette+(H9FB6C(resource,0xD6)<<5),1); + sub_08000AF0(palette9FB6C+16,sprite.palette+(H9FB6C(resource, ENEMY_DATA_FIELD(0xD6))<<5),1); draw9FB6C(sx,sy,*animation,*frame,priority,sprite.payload,sprite.data,sprite.base); } value=actor->f4C; @@ -1753,7 +1762,7 @@ void sub_0809FB6C(void *input) soundStop9FB6C(0);sub_080A10AC(); if(sub_0800CCCC()==0 && sub_0800CC98()==0 && sub_0800CD8C()==0 && sub_0800CD34()==0) { sound9FB6C(13); - transition9FB6C(actor9FB6C,&sprite,H9FB6C(resource,0xD6),palette9FB6C,2); + transition9FB6C(actor9FB6C,&sprite,H9FB6C(resource, ENEMY_DATA_FIELD(0xD6)),palette9FB6C,2); } if(!(playersFB6[sub_080020F4()].flags&0x2000) && actor9FB6C->f5A!=0) { reward=reward9FB6C(inventory9FB6C,resource); @@ -1785,8 +1794,8 @@ void sub_0809FB6C(void *input) #undef I9FB6C #undef P9FB6C struct Sprite105 {u32 base,pad4,data,palette,pad10,pad14,pad18;u8 payload[24];}; -struct Actor105 {u16 index;u8 pad2[10];u16 state;u8 padE[0x42];u32 serial;u8 pad54[0x286];u16 paletteOffset;}; -struct Player105 {u8 p0[0x20];u16 state;u8 p22[14];u32 flags;u8 p34[0x34];u8 active;u8 p69[0x1F];u16 health;u16 p8A;s32 x,y;u8 p94[0x1C];u16 motion;u8 pB2[0x32];u32 seen[26];}; +struct Actor105 {u16 index;u8 pad2[10];u16 state;u8 padE[0x42];u32 serial;u8 pad54[ENEMY_FIELD(0x2DA) - 0x54];u16 paletteOffset;}; +struct Player105 {u8 p0[PLAYER_FIELD(0x20)];u16 state;u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)];u8 active;u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)];u16 health;u16 p8A;s32 x,y;u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)];u16 motion;u8 pB2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)];u32 seen[26];}; struct Obj105 {u32 p0,p4,p8;s32 y;}; extern struct Actor105 *actor105 asm("gUnk_0300032C"); extern u16 variant105 asm("gUnk_03000330"); @@ -1897,7 +1906,7 @@ void sub_080A05B4(u32 kind,void *done) *(u32 *)((u8 *)sub_0800048C() + 8) = timer; } struct EntryA099C { u8 pad[8]; u16 unk8, unkA; u8 rest[20]; }; -struct PlayerA099C { u8 pad[0x8C]; u32 x, y, xx, yy; u8 rest[0xB0]; }; +struct PlayerA099C { u8 pad[PLAYER_FIELD(0x8C)]; u32 x, y, xx, yy; u8 rest[PLAYER_SIZE - PLAYER_FIELD(0x9C)]; }; extern struct PlayerA099C gPlayersA099C[] asm("gUnk_03003CE0"); extern u8 gFlagA099C asm("gUnk_03000338"); extern u8 gFlag2A099C asm("gUnk_03000339"); @@ -1977,7 +1986,7 @@ void sub_080A099C(void) sub_080003F0(); } } -struct SubA0B44 { u8 pad0[0xD6]; u16 paletteOffset; }; +struct SubA0B44 { u8 pad0[ENEMY_DATA_FIELD(0xD6)]; u16 paletteOffset; }; struct ActorA0B44 { u16 id; u8 pad2[10]; u16 state; u8 padE[6]; s32 x, y; u8 pad1C[0x34]; u32 serial; @@ -1986,10 +1995,10 @@ struct ActorA0B44 { struct PosA0B44 { u16 x, y; }; typedef struct { s32 x, y; } VecA0B44; struct PlayerA0B44 { - u8 pad0[0x20]; u16 state; u8 pad22[14]; u32 flags; - u8 pad34[0x34]; u8 active; u8 pad69[0x23]; - s32 x, y; u8 pad94[0x1C]; - u16 motion; u8 padB2[0x32]; u32 seen[25]; struct PosA0B44 *pos; + u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; + u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; + s32 x, y; u8 pad94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; + u16 motion; u8 padB2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; u32 seen[25]; struct PosA0B44 *pos; }; struct SpriteA0B44 { u32 base, pad4, data, palette, pad10, pad14, pad18; u8 payload[24]; }; struct DrawA0B44 { u32 pad0[3]; s32 y; }; @@ -2015,7 +2024,9 @@ void sub_080A0B44(void) u16 frame1, tick1, frame2, tick2; s16 screenX, screenY; s32 velocity[2]; +#ifndef REGION_USA register struct ActorA0B44 **ref asm("sl"); +#endif struct SubA0B44 *sub; struct PlayerA0B44 *target; VecA0B44 pos; @@ -2036,8 +2047,12 @@ void sub_080A0B44(void) s32 distance; u32 serial; +#ifdef REGION_USA + sub = &actorA0B44->sub; +#else ref = &actorA0B44; sub = &(*ref)->sub; +#endif initA0B44(&sprite1, 0x5000A, variantA0B44, -1, 1); initA0B44(&sprite2, 0x5000A, variantA0B44, -1, 1); sprite1.payload[0] = variantA0B44; @@ -2099,12 +2114,22 @@ void sub_080A0B44(void) animA0B44(&sprite2, anim, &frame2, &tick2, animArg); if (sub_0800CCCC() == 0 && sub_0800CD8C() == 0 && sub_0800CD34() == 0 && (zero = sub_0800CC98()) == 0) { +#ifndef REGION_USA palette = &sub->paletteOffset; +#endif if (state == 0 || state == 1) { +#ifdef REGION_USA + sub_08000AF0(variantA0B44 + 16, sprite1.palette + (sub->paletteOffset << 5), 1); +#else sub_08000AF0(variantA0B44 + 16, sprite1.palette + (*palette << 5), 1); +#endif { +#ifdef REGION_USA + struct ActorA0B44 *a = actorA0B44; +#else register struct ActorA0B44 **r asm("r2") = ref; struct ActorA0B44 *a = *r; +#endif screenA0B44((s32)((u32)a->x << 8) >> 16, (s32)((u32)a->y << 8) >> 16, &screenX, &screenY, zero, zero); } @@ -2122,12 +2147,20 @@ void sub_080A0B44(void) } object->y = screenY; { +#ifdef REGION_USA + struct ActorA0B44 *a = actorA0B44; +#else struct ActorA0B44 *a = *ref; +#endif pos.x = a->x + 0x1000; pos.y = a->y - 0x3000; } } +#ifdef REGION_USA + sub_08000AF0(variantA0B44 + 16, sprite2.palette + (sub->paletteOffset << 5), 1); +#else sub_08000AF0(variantA0B44 + 16, sprite2.palette + (*palette << 5), 1); +#endif screenA0B44((s32)((u32)pos.x << 8) >> 16, (s32)((u32)pos.y << 8) >> 16, &screenX, &screenY, zero, zero); object = drawA0B44(screenX, 0x9F, anim, frame2, 1, sprite2.payload, sprite2.data, @@ -2171,18 +2204,26 @@ void sub_080A0B44(void) u32 seenByteOffset; ((struct PlayerA0B44 *)playerBase)[motionPlayer].motion = 0xFFFE; player = sub_080020F4(); +#ifdef REGION_USA + actor = actorA0B44; +#else actor = *ref; +#endif seenByteOffset = actor->id << 2; - seenByteOffset += player * 0x14C; + seenByteOffset += player * PLAYER_SIZE; - playerBase += 0xE4; + playerBase += PLAYER_FIELD(0xE4); *(u32 *)(seenByteOffset + (u32)playerBase) = actor->serial++; } +#ifdef REGION_USA + hit = 1; +#else { register u32 hitOne asm("r2") = 1; asm("" : "+r"(hitOne)); hit = hitOne; } +#endif next: sub_080003F0(); lastRunning = running; @@ -2387,6 +2428,11 @@ void sub_080A11B4(void) #define SA12(p,o) (*(s16 *)((u8 *)(p)+(o))) #define IA12(p,o) (*(s32 *)((u8 *)(p)+(o))) #define PA12(p,o) ((u16 *)((u8 *)(p)+(o))) +#ifdef REGION_USA +#define PAL_A12 (*PA12(resource, ENEMY_DATA_FIELD(0xD6))) +#else +#define PAL_A12 (*pal) +#endif extern struct ActorD878 *actorA12 asm("gUnk_03000348"); extern u16 paletteA12 asm("gUnk_0300034C"); extern u8 configA12[] asm("gUnk_084A5CA8"); @@ -2401,7 +2447,7 @@ extern void sub_080A2720(u8 mode, u16 arg); if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0) { \ zero = sub_0800CD34(); \ if (zero == 0) { \ - sub_08000AF0(paletteA12 + 0x10, (u8 *)sprite->palette + (*pal << 5), 1); \ + sub_08000AF0(paletteA12 + 0x10, (u8 *)sprite->palette + (PAL_A12 << 5), 1); \ priority = sub_0800BC44(actorA12->x >> 8, actorA12->y >> 8, 0); \ actorA12->f6E = animD878(sprite, actorA12->anim, &actorA12->frame, &actorA12->tick, 1); \ screenD878((actorA12->x << 8) >> 16, (actorA12->y << 8) >> 16, &sx, &sy, zero, zero); \ @@ -2432,7 +2478,9 @@ void sub_080A1208(void *input) u16 chase; u16 elapsed; s16 floatingOffset; +#ifndef REGION_USA u16 *pal; +#endif u16 *frame; u16 *tick; s32 finished; @@ -2471,8 +2519,8 @@ void sub_080A1208(void *input) actor->tick = 0; actor->frame = 0; actor->anim = 0; - actor->f5C = actor->f1D6 = SA12(resource, 6) * 3; - value = SA12(resource, 4) * 2; + actor->f5C = actor->f1D6 = SA12(resource, ENEMY_DATA_FIELD(6)) * 3; + value = SA12(resource, ENEMY_DATA_FIELD(4)) * 2; actor->f5E = actor->f1D4 = (value * 4 + value) * 2; actor->state = 0; mode = 0; @@ -2486,11 +2534,13 @@ void sub_080A1208(void *input) tick = &actor->tick; frame = &actor->frame; animation = &actor->anim; - pal = PA12(resource, 0xD6); +#ifndef REGION_USA + pal = PA12(resource, ENEMY_DATA_FIELD(0xD6)); +#endif do { entry = 0; do { - *(u32 *)((u8 *)seenD878 + entry * 4 + player * 0x14C) = 0; + *(u32 *)((u8 *)seenD878 + entry * 4 + player * PLAYER_SIZE) = 0; entry++; } while (entry <= 4); player++; @@ -2605,7 +2655,7 @@ void sub_080A1208(void *input) actorA12->frame = 0; } sprite->payload[0] = paletteA12; - sub_08000AF0(paletteA12 + 0x10, (u8 *)sprite->palette + (*pal << 5), 1); + sub_08000AF0(paletteA12 + 0x10, (u8 *)sprite->palette + (PAL_A12 << 5), 1); if (sub_08098004() & 1) priority = sub_08097FF8(); else @@ -2659,7 +2709,7 @@ void sub_080A1208(void *input) if (sub_0800CCCC() == 0 && sub_0800CC98() == 0) { zero = sub_0800CD34(); if (zero == 0) { - sub_08000AF0(paletteA12 + 0x10, (u8 *)sprite->palette + (*pal << 5), 1); + sub_08000AF0(paletteA12 + 0x10, (u8 *)sprite->palette + (PAL_A12 << 5), 1); priority = sub_0800BC44(actorA12->x >> 8, actorA12->y >> 8, 0); actorA12->f6E = animD878(sprite, actorA12->anim, &actorA12->frame, &actorA12->tick, 1); screenD878((actorA12->x << 8) >> 16, (actorA12->y << 8) >> 16, &sx, &sy, zero, zero); @@ -2687,7 +2737,7 @@ void sub_080A1208(void *input) RENDER_A12(); playersD878[sub_080020F4()].flags &= ~1; soundD878(0xD); - transitionD878(actorA12, sprite, *pal, paletteA12); + transitionD878(actorA12, sprite, PAL_A12, paletteA12); if (!(playersD878[sub_080020F4()].flags & 0x2000) && actorA12->f5A != 0) { reward = rewardD878(inventoryD878, resource); floatingOffset = 0x1D; @@ -2717,7 +2767,7 @@ void sub_080A1208(void *input) #undef PA12 struct ActorA1DA8 { u16 f0; u8 p2[6]; s16 f8; u16 fA, fC; u8 pE[6]; s32 f14, f18; u8 p1C[0x34]; s32 f50; }; extern struct ActorA1DA8 *gActorA1DA8 asm("gUnk_03000348"); -struct PlayerA1DA8 { u8 p0[0x20]; u16 state; u8 p22[14]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x1F]; u16 f88; u8 p8A[0x26]; u16 fB0; u8 pB2[0x32]; u32 fE4[25]; u16 *f148; }; +struct PlayerA1DA8 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 f68; u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; u16 f88; u8 p8A[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x8A)]; u16 fB0; u8 pB2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; u32 fE4[25]; u16 *f148; }; extern struct PlayerA1DA8 gPlayersA1DA8[] asm("gUnk_03003CE0"); extern s16 atanA1DA8(s16,s16) asm("ArcTan2"); extern s16 sub_0801ED8C(void *, void *); @@ -2742,10 +2792,10 @@ void sub_080A1DA8(void) x = (u32)(gActorA1DA8->f14 << 8) >> 16; y = (u32)(gActorA1DA8->f18 << 8) >> 16; positions = (void *)gPlayersA1DA8; - offset = 0x14C * sub_080020F4(); - positions += 0x148; + offset = PLAYER_SIZE * sub_080020F4(); + positions += PLAYER_FIELD(0x148); px = **(u16 **)(positions + offset) >> 4; - py = (u32)((*(u16 **)(positions + 0x14C * sub_080020F4()))[1] << 20); + py = (u32)((*(u16 **)(positions + PLAYER_SIZE * sub_080020F4()))[1] << 20); deltaX = px - (s16)x; deltaY = (py >> 20) - (s16)y; dx = deltaX; @@ -2813,10 +2863,10 @@ struct ActorA1FF4 { u16 id; u8 p2[6]; s16 facing; u16 pA, state; u8 pE[6]; s32 x extern struct ActorA1FF4 *gActorA1FF4 asm("gUnk_03000348"); struct AnimA1FF4 { u32 f0, f4, f8, fC; u8 p10[12]; u8 attr[24]; }; struct PlayerA1FF4 { - u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; - u8 p34[0x34]; u8 active; u8 p69[0x23]; s32 x, y; - u8 p94[0x1C]; u16 effect; u8 pB2[0x32]; - u32 serial[25]; u8 pad[0x14C-0xE4-100]; + u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; + u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 p69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x, y; + u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 effect; u8 pB2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; + u32 serial[25]; u8 pad[PLAYER_SIZE - PLAYER_FIELD(0x148)]; }; extern struct PlayerA1FF4 gPlayersA1FF4[] asm("gUnk_03003CE0"); extern s32 sub_08065158(void *, u32, u16, s32, s32); @@ -2875,18 +2925,18 @@ void sub_080A1FF4(void *unused, u16 direction) gPlayersA1FF4[sub_080020F4()].state != 14 && gPlayersA1FF4[sub_080020F4()].state != 11 && gPlayersA1FF4[sub_080020F4()].state != 12 && - *(u32 *)((u8 *)&gPlayersA1FF4[sub_080020F4()] + 0xE4 + gActorA1FF4->id * 4) != gActorA1FF4->serial) { + *(u32 *)((u8 *)&gPlayersA1FF4[sub_080020F4()] + PLAYER_FIELD(0xE4) + gActorA1FF4->id * 4) != gActorA1FF4->serial) { if (sub_0800CE30() == 1) sub_08029CEC(0, 60, 2); else sub_08029CEC(0, 30, 2); gPlayersA1FF4[sub_080020F4()].effect = 0xFFFE; - *(u32 *)((u8 *)&gPlayersA1FF4[sub_080020F4()] + 0xE4 + gActorA1FF4->id * 4) = gActorA1FF4->serial++; + *(u32 *)((u8 *)&gPlayersA1FF4[sub_080020F4()] + PLAYER_FIELD(0xE4) + gActorA1FF4->id * 4) = gActorA1FF4->serial++; hit = 1; } } if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0) { s32 zero = sub_0800CD34(); if (zero == 0) { - sub_08000AF0(gUnk_0300034C + 0x10, anim.fC + (*(u16 *)(aux + 0xD6) << 5), 1); + sub_08000AF0(gUnk_0300034C + 0x10, anim.fC + (*(u16 *)(aux + ENEMY_DATA_FIELD(0xD6)) << 5), 1); sub_0800BC08((x << 8) >> 16, (y << 8) >> 16, &screenX, &screenY, zero, zero); sub_08065370(&anim, 8, (s32)&tile, (s32)&extra, 1); sub_08007870(screenX, screenY, 8, tile, zero, anim.attr, anim.f8, anim.f0); @@ -2909,9 +2959,9 @@ struct TargetXYT107 { s32 x, y; }; extern void t107VelocityPair(struct TargetXYT107,struct TargetXYT107,s32 *) asm("sub_08097978"); struct Nib107 { u8 lo:4, hi:4; }; struct PlayerT107C { - u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; - u8 p34[0x34]; u8 active; u8 p69[0x23]; s32 x, y; - u8 p94[0x1C]; u16 effect; u8 pB2[0x32]; + u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; + u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 p69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x, y; + u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 effect; u8 pB2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; u32 serial[25]; u16 *data; }; extern struct PlayerT107C t107PlayersC[] asm("gUnk_03003CE0"); @@ -2994,7 +3044,7 @@ void sub_080A230C(void *unused, u16 delay) zero = sub_0800CC98(); if (zero == 0) { sub_08065370(&anim, 8, (s32)&tile, (s32)&extra, 1); - sub_08000AF0(gUnk_0300034C + 0x10, anim.fC + (*(u16 *)(aux + 0xD6) << 5), 1); + sub_08000AF0(gUnk_0300034C + 0x10, anim.fC + (*(u16 *)(aux + ENEMY_DATA_FIELD(0xD6)) << 5), 1); anim.attr[0] = gUnk_0300034C; t107CCall0800BC08((pos.x << 8) >> 16, (pos.y << 8) >> 16, &screenX, &screenY, zero, zero); t107CCall08007870(screenX, screenY, 8, tile, zero, anim.attr, anim.f8, anim.f0); @@ -3078,11 +3128,11 @@ struct EntA27 { u8 p70[0x164]; s16 f1D4, f1D6; u8 p1D8[0x24]; u8 lo:4; u8 hi:4; u8 f1FD, f1FE, p1FF; u8 f200; u8 p201; u16 f202; - u8 p204[0x2a]; s8 f22E, f22F; u8 p230[0xa8]; u16 f2D8, f2DA; + u8 p204[ENEMY_FIELD(0x22E) - 0x204]; s8 f22E, f22F; u8 p230[ENEMY_FIELD(0x2D8) - ENEMY_FIELD(0x230)]; u16 f2D8, f2DA; }; -struct AuxA27 { u8 p0[4]; s16 f4, f6; u8 p8[0xce]; u16 fD6; }; +struct AuxA27 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0xce]; u16 fD6; }; struct AnimA27 { u32 f0, f4, f8, fC; u8 pad10[12]; u8 attr[24]; }; -struct PlayerA27 { u8 p0[0x30]; u32 flags; u8 p34[0x118]; }; +struct PlayerA27 { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; struct GlobA27 { u8 p0[0x720]; s32 f720; }; extern struct EntA27 *selfA27 asm("gUnk_03000364"); extern struct EntA27 *otherA27 asm("gUnk_03000368"); @@ -3137,7 +3187,12 @@ extern s32 s1E46CA27(void *, void *) asm("sub_0801E46C"); extern s32 s1E4CCA27(void *, s32) asm("sub_0801E4CC"); extern void s6171CA27(void *, s32) asm("sub_0806171C"); -#define TAIL_A27() { s32 z; playersA27[sub_080020F4()].flags |= 1; if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0 && (z = sub_0800CD34()) == 0) { sub_08000AF0(tileA27 + 0x10, (void *)(animsA27[0].fC + *pD6 * 32), 1); pal = sub_0800BC44(selfA27->x >> 8, selfA27->y >> 8, 0); selfA27->f6E = animA27(&animsA27[0], selfA27->f68, &selfA27->f6A, &selfA27->f6C, 1); coordsA27((s16)(selfA27->x >> 8), (s16)(selfA27->y >> 8), &sx, &sy, z, z); drawA27(sx, sy, selfA27->f68, selfA27->f6A, pal, animsA27[0].attr, animsA27[0].f8, animsA27[0].f0); } yieldA27(); } +#ifdef REGION_USA +#define D6_A27 (aux->fD6) +#else +#define D6_A27 (*pD6) +#endif +#define TAIL_A27() { s32 z; playersA27[sub_080020F4()].flags |= 1; if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0 && (z = sub_0800CD34()) == 0) { sub_08000AF0(tileA27 + 0x10, (void *)(animsA27[0].fC + D6_A27 * 32), 1); pal = sub_0800BC44(selfA27->x >> 8, selfA27->y >> 8, 0); selfA27->f6E = animA27(&animsA27[0], selfA27->f68, &selfA27->f6A, &selfA27->f6C, 1); coordsA27((s16)(selfA27->x >> 8), (s16)(selfA27->y >> 8), &sx, &sy, z, z); drawA27(sx, sy, selfA27->f68, selfA27->f6A, pal, animsA27[0].attr, animsA27[0].f8, animsA27[0].f0); } yieldA27(); } /* [RunPatternedAttachmentEncounter] Places main actor at fixed position, restores field+0x5C to999 on hits, * and alternates timed pursuit/contact with event-selected15-byte configurations for one primary attachment @@ -3153,7 +3208,9 @@ void sub_080A27B8(struct EntA27 *self) u16 flash; u16 wait8; u16 wait4; +#ifndef REGION_USA u16 *pD6; +#endif s16 shake; u8 pal; u16 t; @@ -3214,7 +3271,9 @@ void sub_080A27B8(struct EntA27 *self) selfA27->f202 = selfA27->f2; selfA27->f200 = 0xFF; s67C18A27(); +#ifndef REGION_USA pD6 = &aux->fD6; +#endif while (s67C08A27() == 0) yieldA27(); s6849CA27(s67BF8A27()); @@ -3347,7 +3406,7 @@ void sub_080A27B8(struct EntA27 *self) } } animsA27[modeA27].attr[0] = tileA27; - sub_08000AF0(tileA27 + 0x10, (void *)(animsA27[modeA27].fC + *pD6 * 32), 1); + sub_08000AF0(tileA27 + 0x10, (void *)(animsA27[modeA27].fC + D6_A27 * 32), 1); if (sub_0800CD8C() == 0) selfA27->f6E = animA27(&animsA27[modeA27], 0, &selfA27->f6A, &selfA27->f6C, 1); if (sub_08098004() & 1) @@ -3363,7 +3422,7 @@ void sub_080A27B8(struct EntA27 *self) } if (modeA27 != 0 && sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD34() == 0) { animsA27[1].attr[0] = tileA27; - sub_08000AF0(tileA27 + 0x10, (void *)(animsA27[1].fC + *pD6 * 32), 1); + sub_08000AF0(tileA27 + 0x10, (void *)(animsA27[1].fC + D6_A27 * 32), 1); p = drawA27(sx, sy - 1, 0x11, 0, pal, animsA27[1].attr, animsA27[1].f8, animsA27[1].f0); p[3] = sy; } @@ -3406,7 +3465,7 @@ void sub_080A27B8(struct EntA27 *self) sub_080A4B10(); sub_080A4A54(); s58688A27(0xD); - s970CCA27(selfA27, animsA27, *pD6, tileA27); + s970CCA27(selfA27, animsA27, D6_A27, tileA27); if (!(playersA27[sub_080020F4()].flags & 0x2000) && otherA27->f5A != 0) { h = s1E46CA27(heapA27, aux); shake = 0x1D; @@ -3434,9 +3493,9 @@ struct EntA35 { u8 p70[0x164]; s16 f1D4, f1D6; u8 p1D8[0x24]; u8 lo:4; u8 hi:4; u8 f1FD, f1FE, p1FF; u8 f200; u8 p201; u16 f202; - u8 p204[0x2a]; s8 f22E, f22F; + u8 p204[ENEMY_FIELD(0x22E) - 0x204]; s8 f22E, f22F; }; -struct AuxA35 { u8 p0[4]; s16 f4, f6; u8 p8[0xce]; u16 fD6; }; +struct AuxA35 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0xce]; u16 fD6; }; struct AnimA35 { u32 f0, f4, f8, fC; u8 pad10[12]; u8 attr[24]; }; struct TileA35 { u8 p[0x90]; u16 f90; }; extern struct EntA35 *mainA35 asm("gUnk_03000364"); @@ -3486,7 +3545,7 @@ void t107MainD(void) s32 *p; maskA35 |= 2; - entA35 = (struct EntA35 *)(poolA35 + 0x2E0); + entA35 = (struct EntA35 *)(poolA35 + ENEMY_SIZE); sub_0801A0A4(entA35); setupA35(entA35, srcA35, 1); aux = (struct AuxA35 *)((u8 *)entA35 + 0x204); diff --git a/src/code_080A3D2C.c b/src/code_080A3D2C.c index 5927c7f8..3dfeef43 100644 --- a/src/code_080A3D2C.c +++ b/src/code_080A3D2C.c @@ -27,7 +27,7 @@ extern s32 gUnk_03000408; void sub_080A68B0(void); extern s32 gUnk_0300040C; -struct Res3D2C { u8 p0[4]; s16 f4, f6; u8 p8[0x22]; u8 f2A, f2B; u8 p2C[0xAA]; u16 fD6; }; +struct Res3D2C { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0x22]; u8 f2A, f2B; u8 p2C[0xAA]; u16 fD6; }; struct Act3D2C { u16 f0, f2; u8 p4[8]; @@ -55,8 +55,8 @@ struct Act3D2C { }; struct Spr3D2C { u32 f0, f4, f8; u8 *palette; u8 pad10[12]; u8 style, paletteId; u8 pad1E[22]; }; struct Oam3D2C { u32 f0, f4; s32 x, y; }; -struct E2E0_3D2C { u8 b[0x2E0]; }; -struct Pl3D2C { u8 p0[0x30]; u32 flags; u8 p34[0x118]; }; +struct E2E0_3D2C { u8 b[ENEMY_SIZE]; }; +struct Pl3D2C { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; struct G3170_3D2C { u8 p0[0x90]; u16 f90; }; extern struct Act3D2C *gObj3D2C asm("gUnk_03000364"); extern struct Act3D2C *gActs3D2C[] asm("gUnk_03000370"); @@ -269,7 +269,7 @@ void sub_080A3D2C_v(u16 idx) dropEnd3D2C(gData3D2C, h); } } -struct Player1084520 {u8 pad0[0x20];u16 state;u8 pad22[14];u32 flags;u8 pad34[52];u8 active;u8 pad69[31];u16 timer;u8 pad8A[2];s32 x,y;u8 pad94[28];u16 fB0;u8 padB2[22];u16 fC8,fCA,fCC;u8 padCE[22];u32 history[5];u8 padF8[84];}; +struct Player1084520 {u8 pad0[PLAYER_FIELD(0x20)];u16 state;u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)];u32 flags;u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)];u8 active;u8 pad69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)];u16 timer;u8 pad8A[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x8A)];s32 x,y;u8 pad94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)];u16 fB0;u8 padB2[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0xB2)];u16 fC8,fCA,fCC;u8 padCE[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xCE)];u32 history[5];u8 padF8[PLAYER_SIZE - PLAYER_FIELD(0xF8)];}; extern struct Player1084520 players1084520[] asm("gUnk_03003CE0"); extern u8 x1084520[] asm("gUnk_03003D6C"); extern u8 *object1084520 asm("gUnk_03000364"); @@ -297,7 +297,7 @@ void sub_080A4520(void) { u32 i = sub_080020F4(); s32 x = (s32)(*(s32 *)((u8 *)(object1084520) + (0x14))) >> 8; asm("" : "+r"(x) : "r"(players1084520)); - temp_r4 = x - ((s32)(*(s32 *)((u8 *)(x1084520 + 0x14C * i) + (0))) >> 8); + temp_r4 = x - ((s32)(*(s32 *)((u8 *)(x1084520 + PLAYER_SIZE * i) + (0))) >> 8); } temp_r4_2 = (s16) temp_r4; temp_r1 = ((s32) (*(s32 *)((u8 *)(object1084520) + (0x18))) >> 8) - ((s32) players1084520[sub_080020F4()].y >> 8); @@ -334,17 +334,17 @@ void sub_080A4520(void) { register u8 *base asm("r7") = (u8 *)players1084520; u32 t; - i *= 0x14c; + i *= PLAYER_SIZE; i += (u32)base; - i += 0x88; + i += PLAYER_FIELD(0x88); t = *(u16 *)i; *(u16 *)i = d + t; } players1084520[sub_080020F4()].history[(*(u16 *)((u8 *)(object1084520) + (0)))] = (*(u32 *)((u8 *)(object1084520) + (0x50))); - temp_r4_4 = ((s32) (*(s32 *)((u8 *)(x1084520+0x14C*sub_080020F4()) + (0))) >> 8) - ((s32) (*(s32 *)((u8 *)(object1084520) + (0x14))) >> 8); + temp_r4_4 = ((s32) (*(s32 *)((u8 *)(x1084520+PLAYER_SIZE*sub_080020F4()) + (0))) >> 8) - ((s32) (*(s32 *)((u8 *)(object1084520) + (0x14))) >> 8); new_var = (((s32) players1084520[sub_080020F4()].y >> 8) - ((s32) (*(s32 *)((u8 *)(object1084520) + (0x18))) >> 8)); temp_r0 = (u32)angle1084520((s16) temp_r4_4, (s16) new_var) << 0x10; { @@ -366,13 +366,13 @@ void sub_080A4520(void) { register u8 *base asm("r2") = (u8 *)players1084520; u8 *p; - i *= 0x14C; + i *= PLAYER_SIZE; i += (u32)base; p = (u8 *)i; dir = var_r4 - 2; - var_r0 = (s16 *)(p + 0xCA); + var_r0 = (s16 *)(p + PLAYER_FIELD(0xCA)); } goto store; zero: @@ -381,12 +381,12 @@ void sub_080A4520(void) { register u8 *base asm("r2") = (u8 *)players1084520; u8 *p; - i *= 0x14C; + i *= PLAYER_SIZE; i += (u32)base; p = (u8 *)i; - var_r0 = (s16 *)(p + 0xCA); + var_r0 = (s16 *)(p + PLAYER_FIELD(0xCA)); } dir = 6; goto store; @@ -396,12 +396,12 @@ void sub_080A4520(void) { register u8 *base asm("r2") = (u8 *)players1084520; u8 *p; - i *= 0x14C; + i *= PLAYER_SIZE; i += (u32)base; p = (u8 *)i; - var_r0 = (s16 *)(p + 0xCA); + var_r0 = (s16 *)(p + PLAYER_FIELD(0xCA)); } dir = 7; store: @@ -451,29 +451,16 @@ void sub_080A47A0_v(void) rot = 0; tile = 0; for (;;) { - wait: - if ((f = gFrame47A0) == 0) { - sub_080003F0(); - goto wait; - } - if (gSide47A0 == 1) - animation = f + 5; - else { - register vu8 *frame asm("r0") = &gFrame47A0; - animation = *frame; - } + if (gFrame47A0 == 0) { sub_080003F0(); continue; } + if (gSide47A0 == 1) animation = gFrame47A0 + 5; else animation = gFrame47A0; pos.x = *(s32 *)(gObj47A0 + 0x14); pos.y = *(s32 *)(gObj47A0 + 0x18); { - s32 k = gDir47A0 * 4; - u32 ox = (u32)gOffX47A0; - pos.x += *(s16 *)(k + ox); - /* Keep the table address live until the x-offset load completes. */ - asm("" : : "r"(ox)); - pos.y += *(s16 *)((u8 *)gOffY47A0 + k); +extern s16 off2[][2] asm("gUnk_08518754"); pos.x += off2[gDir47A0][0]; + pos.y += off2[gDir47A0][1]; } gSpr47A0[gSide47A0].style = gPal47A0; - sub_08000AF0(gPal47A0 + 0x10, gSpr47A0[gSide47A0].palette + (*(u16 *)(res + 0xD6) << 5), 1); + sub_08000AF0(gPal47A0 + 0x10, gSpr47A0[gSide47A0].palette + (*(u16 *)(res + ENEMY_DATA_FIELD(0xD6)) << 5), 1); { s32 t = sub_0800CD8C(); if (t == 0) @@ -696,7 +683,7 @@ void sub_080A4CFC(s8 arg0) { gUnk_030003F0 = arg0; } struct Sprite1084D {u32 f0,f4,f8;u8 *palette;u8 pad10[12];u8 f1C,f1D;u8 pad1E[22];}; -struct Res4D08 { u8 p0[4]; s16 f4, f6; u8 p8[0xCC]; u16 fD4, fD6; }; +struct Res4D08 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0xCC]; u16 fD4, fD6; }; struct Act4D08 { u16 f0, f2; u8 p4[4]; @@ -728,7 +715,7 @@ extern u16 palette1084D asm("gUnk_03000404"); extern u8 select1084D asm("gUnk_03000406"); extern u8 selectSecond1084D asm("gUnk_03000407"); extern u8 *game1084D asm("gUnk_03005CF4"); -struct Pl4D08 { u8 p0[0x30]; u32 f30; u8 p34[0x58]; s32 x, y, x2, y2; u8 p9C[0x14]; u16 fB0; u8 pB2[0x9A]; }; +struct Pl4D08 { u8 p0[PLAYER_FIELD(0x30)]; u32 f30; u8 p34[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x34)]; s32 x, y, x2, y2; u8 p9C[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x9C)]; u16 fB0; u8 pB2[PLAYER_SIZE - PLAYER_FIELD(0xB2)]; }; extern struct Pl4D08 players1084D[] asm("gUnk_03003CE0"); extern u8 history1084D[] asm("gUnk_03003DC4"); extern u8 config1084D[] asm("gUnk_084A8088"); @@ -768,6 +755,11 @@ extern u32 h1084D05DF38(u32,u32,u32,u32,u32,u32) asm("sub_0805DF38"); * scaled stats, link barriers and mode-dependent state machine: entrance, timed waits, horizontal passes, * captured-player relocation/contact damage, eight falling shots, two turning volleys and optional * twelve-target attack. Renders shadow/hit flash/damage, checks death, or scene-exit enters same ending path. */ +#ifdef REGION_USA +#define D6_4D08 (res->fD6) +#else +#define D6_4D08 (*palIndex) +#endif void sub_080A4D08(struct Act4D08 *arg0) { struct Sprite1084D sprite; s8 hitFlag; @@ -789,7 +781,9 @@ void sub_080A4D08(struct Act4D08 *arg0) { s32 shadow; s32 healed; s32 dead; +#ifndef REGION_USA u16 *palIndex; +#endif s16 i, j; u16 timer; u16 state; @@ -848,10 +842,12 @@ void sub_080A4D08(struct Act4D08 *arg0) { healed = 0; shadow = 1; arg0->f50 = animLoop; +#ifndef REGION_USA palIndex = &res->fD6; +#endif for (i = 0; i <= 3; i++) for (j = 0; j <= 4; j++) - F_1084D(history1084D+j*4+i*0x14C,u32,0) = 0; + F_1084D(history1084D+j*4+i*PLAYER_SIZE,u32,0) = 0; select1084D = 0xFF; selectSecond1084D = 0xFF; sub_08097FE4(); @@ -1265,7 +1261,7 @@ void sub_080A4D08(struct Act4D08 *arg0) { mode = sub_08097FF8(); else mode = sub_0800BC44(arg0->f14 >> 8, arg0->f18 >> 8, 0); - sub_08000AF0(palette1084D + 0x10, sprite.palette + (*palIndex << 5), 1); + sub_08000AF0(palette1084D + 0x10, sprite.palette + (D6_4D08 << 5), 1); h1084D00BC08((s16)(arg0->f14 >> 8), (s16)(arg0->f18 >> 8), &sx, &sy, 0, 0); psx = &sx; if (flash != 0) { @@ -1326,7 +1322,7 @@ void sub_080A4D08(struct Act4D08 *arg0) { players1084D[sub_080020F4()].f30 |= 1; if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && (zero = sub_0800CD34()) == 0) { arg0->f6E = h1084D065370(&sprite, arg0->f68, &arg0->f6A, &arg0->f6C, animLoop); - sub_08000AF0(palette1084D + 0x10, sprite.palette + (*palIndex << 5), 1); + sub_08000AF0(palette1084D + 0x10, sprite.palette + (D6_4D08 << 5), 1); mode = sub_0800BC44(object1084D->f14 >> 8, object1084D->f18 >> 8, 0); h1084D00BC08((s16)(object1084D->f14 >> 8), (s16)(object1084D->f18 >> 8), &sx, &sy, zero, (void *)zero); h1084D007870(sx, sy, object1084D->f68, object1084D->f6A, mode, &sprite.f1C, sprite.f8, sprite.f0); @@ -1344,7 +1340,7 @@ void sub_080A4D08(struct Act4D08 *arg0) { players1084D[sub_080020F4()].f30 |= 1; if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0 && (zero2 = sub_0800CD34()) == 0) { arg0->f6E = h1084D065370(&sprite, arg0->f68, &arg0->f6A, &arg0->f6C, animLoop); - sub_08000AF0(palette1084D + 0x10, sprite.palette + (*palIndex << 5), 1); + sub_08000AF0(palette1084D + 0x10, sprite.palette + (D6_4D08 << 5), 1); mode = sub_0800BC44(object1084D->f14 >> 8, object1084D->f18 >> 8, 0); h1084D00BC08((s16)(object1084D->f14 >> 8), (s16)(object1084D->f18 >> 8), &sx, &sy, zero2, (void *)zero2); h1084D007870(sx, sy, object1084D->f68, object1084D->f6A, mode, &sprite.f1C, sprite.f8, sprite.f0); @@ -1356,7 +1352,7 @@ void sub_080A4D08(struct Act4D08 *arg0) { players1084D[sub_080020F4()].f30 |= 1; if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0 && (zero2 = sub_0800CD34()) == 0) { arg0->f6E = h1084D065370(&sprite, arg0->f68, &arg0->f6A, &arg0->f6C, animLoop); - sub_08000AF0(palette1084D + 0x10, sprite.palette + (*palIndex << 5), 1); + sub_08000AF0(palette1084D + 0x10, sprite.palette + (D6_4D08 << 5), 1); mode = sub_0800BC44(object1084D->f14 >> 8, object1084D->f18 >> 8, 0); h1084D00BC08((s16)(object1084D->f14 >> 8), (s16)(object1084D->f18 >> 8), &sx, &sy, zero2, (void *)zero2); h1084D007870(sx, sy, object1084D->f68, object1084D->f6A, mode, &sprite.f1C, sprite.f8, sprite.f0); @@ -1370,7 +1366,7 @@ void sub_080A4D08(struct Act4D08 *arg0) { players1084D[sub_080020F4()].f30 |= 1; if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0 && (zero2 = sub_0800CD34()) == 0) { arg0->f6E = h1084D065370(&sprite, arg0->f68, &arg0->f6A, &arg0->f6C, animLoop); - sub_08000AF0(palette1084D + 0x10, sprite.palette + (*palIndex << 5), 1); + sub_08000AF0(palette1084D + 0x10, sprite.palette + (D6_4D08 << 5), 1); mode = sub_0800BC44(object1084D->f14 >> 8, object1084D->f18 >> 8, 0); h1084D00BC08((s16)(object1084D->f14 >> 8), (s16)(object1084D->f18 >> 8), &sx, &sy, zero2, (void *)zero2); h1084D007870(sx, sy, object1084D->f68, object1084D->f6A, mode, &sprite.f1C, sprite.f8, sprite.f0); @@ -1380,7 +1376,7 @@ void sub_080A4D08(struct Act4D08 *arg0) { players1084D[sub_080020F4()].f30 &= ~1; sub_0805867C(0x1A1); h1084D058688(0xD); - h1084D0970CC(object1084D, &sprite, *palIndex, palette1084D); + h1084D0970CC(object1084D, &sprite, D6_4D08, palette1084D); if (!(players1084D[sub_080020F4()].f30 & 0x2000) && object1084D->f5A != 0) { dropFx = sub_0801E46C((void *) gUnk_030034E0, res); shake = 0x1D; @@ -1405,7 +1401,7 @@ void sub_080A4D08(struct Act4D08 *arg0) { sub_080A80D8(); } #undef SET_PLAYER_XY_4D08 -struct T109P6258 { u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x1F]; u16 f88; u8 p8A[2]; s32 x, y; u8 p94[0x1C]; u16 fB0; u8 pB2[0x12]; s16 fC4; u8 pC6[2]; u16 fC8, fCA, fCC; u8 pCE[0x16]; u32 fE4[26]; }; +struct T109P6258 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x1F]; u16 f88; u8 p8A[2]; s32 x, y; u8 p94[0x1C]; u16 fB0; u8 pB2[0x12]; s16 fC4; u8 pC6[2]; u16 fC8, fCA, fCC; u8 pCE[0x16]; u32 fE4[26]; }; struct T109Obj6258 { u16 id; u8 p2[10]; u16 fC; u8 pE[6]; s32 x,y; u8 p1C[0x34]; u32 serial; }; extern struct T109P6258 t109P6258[] asm("gUnk_03003CE0"); extern struct T109Obj6258 *t109O6258 asm("gUnk_03000400"); @@ -1433,7 +1429,7 @@ s32 sub_080A6258(u8 arg0) { first = sub_080020F4(); objx = t109O6258->x >> 8; base = t109P6258; - dx = objx - (t109X6258[first*0x53] >> 8); + dx = objx - (t109X6258[first*(PLAYER_SIZE / 4)] >> 8); second = sub_080020F4(); yy = (t109O6258->y >> 8) + 12; y = yy - (t109P6258[second].y >> 8); @@ -1457,7 +1453,7 @@ s32 sub_080A6258(u8 arg0) { value88 = t109P6258[i].f88; t109P6258[i].f88 = amount + value88; t109P6258[sub_080020F4()].fE4[t109O6258->id] = t109O6258->serial++; - dx = (t109X6258[sub_080020F4()*0x53] >> 8) - (t109O6258->x >> 8); + dx = (t109X6258[sub_080020F4()*(PLAYER_SIZE / 4)] >> 8) - (t109O6258->x >> 8); x = dx; y = (t109P6258[sub_080020F4()].y >> 8) - (t109O6258->y >> 8); angle = (u16)t109Angle6258(x,y); @@ -1492,7 +1488,7 @@ s32 sub_080A6258(u8 arg0) { end: return result; } -struct T109P6510 { u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x1F]; u16 f88; u8 p8A[2]; s32 x; s32 y; u8 p94[0x1C]; u16 fB0; u8 pB2[0x12]; s16 fC4; u8 pC6[0x1E]; u32 fE4[26]; }; +struct T109P6510 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 f68; u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; u16 f88; u8 p8A[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x8A)]; s32 x; s32 y; u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 fB0; u8 pB2[PLAYER_FIELD(0xC4) - PLAYER_FIELD(0xB2)]; s16 fC4; u8 pC6[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xC6)]; u32 fE4[26]; }; struct T109Obj6510 { u16 id; u8 p2[10]; u16 fC; u8 pE[6]; s32 x; s32 y; u8 p1C[0x34]; u32 serial; }; extern struct T109P6510 t109P6510[] asm("gUnk_03003CE0"); extern struct T109Obj6510 *t109O6510 asm("gUnk_03000400"); @@ -1590,7 +1586,7 @@ s32 sub_080A6510(void) return result; } -struct T109Player { u8 pad0[0x1C]; s16 f1C; u8 pad1E[0x6E]; s32 x, y, x2, y2; u8 pad9C[0x14]; u16 fB0; u8 padB2[0x9A]; }; +struct T109Player { u8 pad0[PLAYER_FIELD(0x1C)]; s16 f1C; u8 pad1E[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x1E)]; s32 x, y, x2, y2; u8 pad9C[0x14]; u16 fB0; u8 padB2[PLAYER_SIZE - PLAYER_FIELD(0xB2)]; }; extern struct T109Player t109Players[] asm("gUnk_03003CE0"); extern s32 t109X[] asm("gUnk_03003D6C"); extern s32 t109Origin[2] asm("gUnk_085187B4"); @@ -1627,11 +1623,11 @@ s32 sub_080A66E0(u8 *arg0) { i2 = sub_080020F4(); j = sub_080020F4(); base = t109Players; - t109X[i2 * 0x53] += (t109Targets[mode][j][0] - t109Origin[0]) / 20; + t109X[i2 * (PLAYER_SIZE / 4)] += (t109Targets[mode][j][0] - t109Origin[0]) / 20; i3 = sub_080020F4(); t109Players[i3].y += (t109Targets[mode][sub_080020F4()][1] - t109Origin[1]) / 20; i4 = sub_080020F4(); - t109Players[i4].x2 = t109X[sub_080020F4() * 0x53]; + t109Players[i4].x2 = t109X[sub_080020F4() * (PLAYER_SIZE / 4)]; i5 = sub_080020F4(); t109Players[i5].y2 = t109Players[sub_080020F4()].y; base[sub_080020F4()].f1C = 5; @@ -1649,7 +1645,7 @@ s32 sub_080A66E0(u8 *arg0) { } return result; } -struct T109P68B0 { u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x1F]; u16 f88; u8 p8A[2]; s32 x; s32 y; u8 p94[0x1C]; u16 fB0; u8 pB2[0x12]; s16 fC4; u8 pC6[0x1E]; u32 fE4[26]; }; +struct T109P68B0 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 f68; u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; u16 f88; u8 p8A[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x8A)]; s32 x; s32 y; u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 fB0; u8 pB2[PLAYER_FIELD(0xC4) - PLAYER_FIELD(0xB2)]; s16 fC4; u8 pC6[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xC6)]; u32 fE4[26]; }; struct T109Obj68B0 { u16 id; u8 p2[10]; u16 fC; u8 pE[6]; s32 x; s32 y; u8 p1C[0x34]; u32 serial; }; extern struct T109P68B0 t109P68B0[] asm("gUnk_03003CE0"); extern struct T109Obj68B0 *t109O68B0 asm("gUnk_03000400"); @@ -1659,7 +1655,7 @@ extern s32 t109Init68B0(void *,s32,u16,s32,s32) asm("sub_08065158"); extern u32 t109Screen68B0(s32,s32,s16 *,s16 *,s32,s32) asm("sub_0800BC08"); extern s32 t109Draw68B0(s16,s16,s32,u16,s32,void *,s32,s32) asm("sub_08007870"); extern s32 t109Anim68B0(void *,s32,u16 *,u16 *,s32) asm("sub_08065370"); -extern u32 t109Serial68B0[][83] asm("gUnk_03003DC4"); +extern u32 t109Serial68B0[][PLAYER_SIZE / 4] asm("gUnk_03003DC4"); extern void t109Run68B0(u16) asm("sub_080A68B0"); /* [RunAcceleratingFallingProjectile] Uses a halfword argument to delay launch by argument times 17 with a byte * wait counter; after launch optionally drifts x by 0xC0, increases y velocity by 18, conditionally draws and @@ -1732,7 +1728,7 @@ void t109Run68B0(u16 arg0) { zero = sub_0800CD34(); if (zero == 0) { t109Screen68B0((s32)(pos[0]<<8)>>16,(s32)(pos[1]<<8)>>16,&outX,&outY,zero,zero); - sub_08000AF0(t109Index68B0+16,*(u8 **)(sprite+0xC)+(*(u16 *)(resource+0xD6)<<5),1); + sub_08000AF0(t109Index68B0+16,*(u8 **)(sprite+0xC)+(*(u16 *)(resource+ENEMY_DATA_FIELD(0xD6))<<5),1); t109Anim68B0(sprite,2,&frame,&tick,1); t109Draw68B0(outX,outY,2,frame,zero,sprite+0x1C,*(s32 *)(sprite+8),*(s32 *)sprite); } @@ -1751,7 +1747,7 @@ void t109Run68B0(u16 arg0) { task = (s32 *)sub_0800048C(); task[2] = zero; } -struct Pl6BE8 { u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x1F]; u16 f88; u8 p8A[2]; s32 x, y; u8 p94[0x1C]; u16 fB0; u8 pB2[0x32]; u32 hitIds[26]; }; +struct Pl6BE8 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x1F]; u16 f88; u8 p8A[2]; s32 x, y; u8 p94[0x1C]; u16 fB0; u8 pB2[0x32]; u32 hitIds[26]; }; struct Obj6BE8 { u16 id; u8 p2[10]; u16 fC; u8 pE[6]; s32 x, y; u8 p1C[0x34]; u32 serial; }; struct Anim6BE8 { u32 f0, f4, f8; u8 *fC; u8 p10[12]; u8 f1C; u8 p1d[0x17]; }; struct Part6BE8 { s32 x, y, speed; u16 frame, tick; u8 dir, timer, hit, delay; }; @@ -1831,8 +1827,12 @@ void sub_080A6BE8_v(u16 cw) { s32 t = p[i].speed + 0x20; p[i].speed = t - i; } } if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0 && (z = sub_0800CD34()) == 0) { - loadPal6BE8(gTile6BE8 + 0x10, anim.fC + *(u16 *)(res + 0xD6) * 32, 1); + loadPal6BE8(gTile6BE8 + 0x10, anim.fC + *(u16 *)(res + (ENEMY_FIELD(0x2DA) - 0x204)) * 32, 1); +#ifdef REGION_USA + { s32 *zAddr; proj6BE8((s16)(p[i].x >> 8), (s16)(p[i].y >> 8), &sx, &sy, z, *(zAddr = &z)); } +#else proj6BE8((s16)(p[i].x >> 8), (s16)(p[i].y >> 8), &sx, &sy, z, z); +#endif anim6BE8(&anim, p[i].dir + 5, &p[i].frame, &p[i].tick, 1); draw6BE8(sx, sy, p[i].dir + 5, p[i].frame, z, &anim.f1C, anim.f8, anim.f0); } @@ -1863,7 +1863,7 @@ void sub_080A6BE8_v(u16 cw) } while (--n != 0xFFFF); *(u32 *)((u8 *)sub_0800048C() + 8) = 0; } -struct Pl705C { u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; u8 p34[0x34]; u8 f68; u8 p69[0x1F]; u16 f88; u8 p8A[2]; s32 x, y; u8 p94[0x1C]; u16 fB0; u8 pB2[0x12]; s16 fC4; u8 pC6[0x1E]; u32 hitIds[25]; u16 *f148; }; +struct Pl705C { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 f68; u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; u16 f88; u8 p8A[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x8A)]; s32 x, y; u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 fB0; u8 pB2[PLAYER_FIELD(0xC4) - PLAYER_FIELD(0xB2)]; s16 fC4; u8 pC6[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xC6)]; u32 hitIds[25]; u16 *f148; }; struct Obj705C { u16 id; u8 p2[10]; u16 fC; u8 pE[6]; s32 x, y; u8 p1C[0x34]; u32 serial; }; struct Anim705C { u32 f0, f4, f8; u8 *fC; u8 p10[12]; u8 f1C; u8 p1d[0x17]; }; struct Part705C { s32 x, y, timer; u16 frame, tick; u8 dir, active, p12[2]; }; @@ -1968,7 +1968,7 @@ void sub_080A705C_v(void) } } if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0 && (z = sub_0800CD34()) == 0) { - loadPal705C(gTile705C + 0x10, anim.fC + *(u16 *)(res + 0xD6) * 32, 1); + loadPal705C(gTile705C + 0x10, anim.fC + *(u16 *)(res + (ENEMY_FIELD(0x2DA) - 0x204)) * 32, 1); proj705C((s16)(p[i].x >> 8), (s16)(p[i].y >> 8), &sx, &sy, z, z); anim705C(&anim, p[i].dir + 5, &p[i].frame, &p[i].tick, 1); draw705C(sx, sy, p[i].dir + 5, p[i].frame, z, &anim.f1C, anim.f8, anim.f0); @@ -2019,7 +2019,7 @@ void sub_080A74E8(void) struct Anim756C { u32 f0, f4, f8; u8 *fC; u8 p10[12]; u8 f1C; u8 p1d[0x17]; }; struct XY756C { s32 x, y; }; struct Pos756C { u16 x; u16 y : 12; u16 r : 4; u8 z : 6; u8 r2 : 2; }; -struct Pl756C { u8 p0[0x30]; u32 flags; u8 p34[0x58]; s32 x, y; u8 p94[4]; s32 f98; u8 p9C[0xAC]; struct Pos756C *f148; }; +struct Pl756C { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x34)]; s32 x, y; u8 p94[PLAYER_FIELD(0x98) - PLAYER_FIELD(0x94)]; s32 f98; u8 p9C[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x9C)]; struct Pos756C *f148; }; struct Draw756C { u8 p0[0xC]; s32 fC; }; struct G3170_756C { u8 p0[0x90]; u16 f90; }; extern struct Pl756C gPl756C[] asm("gUnk_03003CE0"); @@ -2085,7 +2085,7 @@ void sub_080A756C_v(void) animInit756C(&anim0, 0x5000F, 0, -1, 1); anim0.f1C = gTile756C; loadPal756C(gTile756C + 0x10, anim0.fC, 1); - animInit756C(&anim1, 0x50010, 0, -1, 0); + animInit756C(&anim1, RES_ID(0x50010), 0, -1, 0); fx = 0; tick1 = fx; frame1 = fx; @@ -2530,7 +2530,7 @@ void sub_080A8114(void) *(u32 *)(entry + 0x24) = 0; sub_08000274_(entry, 0, 0); } -struct Res8164 { u8 p0[4]; s16 f4, f6; u8 p8[0x22]; u8 f2A, f2B; u8 p2C[0xA8]; u16 fD4, fD6; }; +struct Res8164 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0x22]; u8 f2A, f2B; u8 p2C[0xA8]; u16 fD4, fD6; }; struct Act8164 { u16 f0, f2; u8 p4[4]; @@ -2558,7 +2558,7 @@ struct Act8164 { }; struct Anim8164 { u32 f0, f4, f8; u8 *fC; u8 p10[12]; u8 f1C; u8 p1d[0x17]; }; struct XY8164 { s32 x, y; }; -struct Pl8164 { u8 p0[0x30]; u32 flags; u8 p34[0x118]; }; +struct Pl8164 { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; struct Draw8164 { u8 p0[8]; s32 f8, fC; }; extern struct Act8164 *gCur8164 asm("gUnk_0300041C"); extern u16 gTile8164 asm("gUnk_03000420"); @@ -2681,7 +2681,7 @@ void sub_080A8164_v(struct Act8164 *a) a->f50 = 1; for (i = 0; i <= 3; i++) for (j = 0; j <= 4; j++) - *(s32 *)(gHist8164 + j * 4 + i * 0x14C) = 0; + *(s32 *)(gHist8164 + j * 4 + i * PLAYER_SIZE) = 0; sub_08097FE4(); sub_08097A4C(); sub_080A9818(); @@ -3029,7 +3029,7 @@ void sub_080A8164_v(struct Act8164 *a) sub_08067BF8(); sub_08056E24(); } -struct PlayerHit111 { u8 pad0[0x20]; u16 state; u8 pad22[0xE]; u32 flags; u8 pad34[0x34]; u8 active; u8 pad69[0x23]; s32 x,y; u8 pad94[0x34]; u16 lock, direction, power; u8 padCE[0x16]; s32 previous[0x1A]; }; +struct PlayerHit111 { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x,y; u8 pad94[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0x94)]; u16 lock, direction, power; u8 padCE[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xCE)]; s32 previous[0x1A]; }; extern struct PlayerHit111 hitPlayers111[] asm("gUnk_03003CE0"); extern u8 *hitObject111 asm("gUnk_0300041C"); /* [PushPlayerFromObjectHorizontally] Within distance 19, after object/player lifecycle, timer, pause and @@ -3049,12 +3049,12 @@ void sub_080A8F90(void) ix = sub_080020F4(); objX = hitObject111; base = hitPlayers111; - ix *= 0x14C; + ix *= PLAYER_SIZE; px = &base->x; dx = (u32)((*(s32 *)(objX + 0x14) - *(s32 *)((u8 *)px + ix)) << 8) >> 16; iy = sub_080020F4(); objY = hitObject111; - iy *= 0x14C; + iy *= PLAYER_SIZE; py = &base->y; dy = (*(s32 *)(objY + 0x18) - *(s32 *)((u8 *)py + iy)) << 8; if (Sqrt((s16)dx * (s16)dx + (dy >> 16) * (dy >> 16)) > 19) return; @@ -3064,7 +3064,7 @@ void sub_080A8F90(void) if (sub_0800CD8C() != 0) return; if (sub_0800CCCC() != 0) return; if (*(u16 *)(hitObject111 + 0xC) == 11) return; - iflags = 0x14C * sub_080020F4(); + iflags = PLAYER_SIZE * sub_080020F4(); flags = &base->flags; if (*(u32 *)((u8 *)flags + iflags) & 0x2000) return; if (base[sub_080020F4()].active == 0) return; @@ -3074,11 +3074,11 @@ void sub_080A8F90(void) itable = sub_080020F4(); objTable = hitObject111; offset = *(u16 *)objTable * 4; - itable *= 0x14C; + itable *= PLAYER_SIZE; offset += itable; table = base->previous; if (*(s32 *)((u8 *)table + offset) == *(s32 *)(objTable + 0x50)) return; - icmp = 0x14C * sub_080020F4(); + icmp = PLAYER_SIZE * sub_080020F4(); if (*(s32 *)((u8 *)px + icmp) <= *(s32 *)(hitObject111 + 0x14)) { target = (s16 *)&base[sub_080020F4()].direction; direction = 1; @@ -3090,7 +3090,7 @@ void sub_080A8F90(void) hitPlayers111[sub_080020F4()].power = 0x400; hitPlayers111[sub_080020F4()].lock = 8; } -struct PlayerHit2111 { u8 pad0[0x20]; u16 state; u8 pad22[0xE]; u32 flags; u8 pad34[0x34]; u8 active; u8 pad69[0x23]; s32 x,y; u8 pad94[0x1C]; u16 hit; u8 padB2[0x16]; u16 lock, direction, power; u8 padCE[0x16]; s32 previous[0x1A]; }; +struct PlayerHit2111 { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x,y; u8 pad94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 hit; u8 padB2[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0xB2)]; u16 lock, direction, power; u8 padCE[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xCE)]; s32 previous[0x1A]; }; extern struct PlayerHit2111 hitPlayers2111[] asm("gUnk_03003CE0"); extern u8 *hitObject2111 asm("gUnk_0300041C"); extern s16 hitOffsets111[] asm("gUnk_080B9704"); @@ -3118,10 +3118,10 @@ void sub_080A9100(void) y += hitOffsets111[0x70] << 5; ix = sub_080020F4(); base = hitPlayers2111; - ix *= 0x14C; + ix *= PLAYER_SIZE; px = &base->x; dx = (u32)((x - *(s32 *)((u8 *)px + ix)) << 8) >> 16; - iy = 0x14C * sub_080020F4(); + iy = PLAYER_SIZE * sub_080020F4(); py = &base->y; dy = (y - *(s32 *)((u8 *)py + iy)) << 8; if (Sqrt((s16)dx * (s16)dx + (dy >> 16) * (dy >> 16)) > 19) return; @@ -3130,7 +3130,7 @@ void sub_080A9100(void) if (sub_0800CD8C() != 0) return; if (sub_0800CCCC() != 0) return; if (*(u16 *)(hitObject2111 + 0xC) == 11) return; - iflags = 0x14C * sub_080020F4(); + iflags = PLAYER_SIZE * sub_080020F4(); flags = &base->flags; if (*(u32 *)((u8 *)flags + iflags) & 0x2000) return; if (base[sub_080020F4()].active == 0) return; @@ -3140,7 +3140,7 @@ void sub_080A9100(void) itable = sub_080020F4(); objTable = hitObject2111; offset = *(u16 *)objTable * 4; - itable *= 0x14C; + itable *= PLAYER_SIZE; offset += itable; table = base->previous; if (*(s32 *)((u8 *)table + offset) == *(s32 *)(objTable + 0x50)) return; @@ -3152,7 +3152,7 @@ void sub_080A9100(void) saveIndex = sub_080020F4(); saveObj = hitObject2111; saveOffset = *(u16 *)saveObj * 4; - saveIndex *= 0x14C; + saveIndex *= PLAYER_SIZE; saveOffset += saveIndex; saveTable = hitPlayers2111->previous; saveDst = (s32 *)((u8 *)saveTable + saveOffset); @@ -3163,7 +3163,7 @@ void sub_080A9100(void) hitPlayers2111[sub_080020F4()].power = 0x400; hitPlayers2111[sub_080020F4()].lock = 0x50; } -struct PlayerEffect111 { u8 pad0[0x20]; u16 state; u8 pad22[0xE]; u32 flags; u8 pad34[0x34]; u8 active; u8 pad69[0x23]; s32 x,y; u8 pad94[0x1C]; u16 hit; u8 padB2[0x16]; u16 lock, direction, power; u8 padCE[0x16]; s32 previous[0x1A]; }; +struct PlayerEffect111 { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x,y; u8 pad94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 hit; u8 padB2[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0xB2)]; u16 lock, direction, power; u8 padCE[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xCE)]; s32 previous[0x1A]; }; extern struct PlayerEffect111 effectPlayers111[] asm("gUnk_03003CE0"); extern u8 *effectObject111 asm("gUnk_0300041C"); struct SpriteEffect111 { s32 f0, f4, f8, fC, f10, f14, f18; u8 bytes[0x18]; }; @@ -3231,21 +3231,21 @@ void sub_080A92C0_(u32 argument) if (testEffect111(pos, area, 0x18) != 0) break; ix = sub_080020F4(); base = effectPlayers111; - ix *= 0x14C; + ix *= PLAYER_SIZE; px = &base->x; dx = (u32)((pos.x - *(s32 *)((u8 *)px + ix)) << 8) >> 16; - iy = 0x14C * sub_080020F4(); + iy = PLAYER_SIZE * sub_080020F4(); py = &base->y; dy = (pos.y - *(s32 *)((u8 *)py + iy)) << 8; distance = Sqrt((s16)dx * (s16)dx + (dy >> 16) * (dy >> 16)); if (hit == 0 && distance <= 11 && sub_0800CDF8() == 0 && sub_0800CD8C() == 0 && sub_0800CCCC() == 0 && *(u16 *)(effectObject111 + 0xC) != 11) { - iflags = 0x14C * sub_080020F4(); + iflags = PLAYER_SIZE * sub_080020F4(); flags = &base->flags; if ((*(u32 *)((u8 *)flags + iflags) & 0x2000) == 0 && base[sub_080020F4()].active != 0 && base[sub_080020F4()].state != 14 && base[sub_080020F4()].state != 11 && base[sub_080020F4()].state != 12) { itable = sub_080020F4(); objTable = effectObject111; offset = *(u16 *)objTable * 4; - itable *= 0x14C; + itable *= PLAYER_SIZE; offset += itable; table = base->previous; if (*(s32 *)((u8 *)table + offset) != *(s32 *)(objTable + 0x50)) { @@ -3255,7 +3255,7 @@ void sub_080A92C0_(u32 argument) saveIndex = sub_080020F4(); saveObj = effectObject111; saveOffset = *(u16 *)saveObj * 4; - saveIndex *= 0x14C; + saveIndex *= PLAYER_SIZE; saveOffset += saveIndex; saveTable = effectPlayers111->previous; saveDst = (s32 *)((u8 *)saveTable + saveOffset); @@ -3268,7 +3268,7 @@ void sub_080A92C0_(u32 argument) } if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0 && (zero = sub_0800CD34()) == 0) { screenEffect111((pos.x << 8) >> 16, (pos.y << 8) >> 16, &screenX, &screenY, zero, zero); - sub_08000AF0(gUnk_03000420 + 0x10, (u8 *)sprite.fC + (*(u16 *)(effectObject111 + 0x2DA) << 5), 1); + sub_08000AF0(gUnk_03000420 + 0x10, (u8 *)sprite.fC + (*(u16 *)(effectObject111 + ENEMY_FIELD(0x2DA)) << 5), 1); animateEffect111(&sprite, 3, &frame, &tick, zero); layer = (u8)sub_0800BC44(*(s32 *)(effectObject111 + 0x14) >> 8, *(s32 *)(effectObject111 + 0x18) >> 8, 0); if (kind != 0) diff --git a/src/code_080A9680.c b/src/code_080A9680.c index 6d7a7cbb..4bc2edf2 100644 --- a/src/code_080A9680.c +++ b/src/code_080A9680.c @@ -22,7 +22,7 @@ struct TaskP { u32 f0, f4, f8, fC, f10, f14, f18, f1C, f20, f24; }; extern u32 gMask030056FC asm("gUnk_030056FC"); extern u16 gArr03000798[] asm("gUnk_03000798"); extern u8 *gPtr030007A8 asm("gUnk_030007A8"); -struct E2E0 { u8 b[0x2E0]; }; +struct E2E0 { u8 b[ENEMY_SIZE]; }; void sub_080B2058(); void sub_080AE420(void); @@ -40,7 +40,7 @@ extern s32 *gUnk_03000448[]; extern s32 *gUnk_030004D0; extern s32 gUnk_030056FC; -struct Player111 { u8 pad0[0x20]; u16 state; u8 pad22[0xE]; u32 flags; u8 pad34[0x34]; u8 active; u8 pad69[0x23]; s32 x, y, oldX, oldY; u8 pad9C[0x2C]; u16 lock; u8 padCA[0x82]; }; +struct Player111 { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x, y, oldX, oldY; u8 pad9C[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0x9C)]; u16 lock; u8 padCA[PLAYER_SIZE - PLAYER_FIELD(0xCA)]; }; extern struct Player111 players111[] asm("gUnk_03003CE0"); extern s32 *object111 asm("gUnk_0300041C"); /* [RestorePlayerOnObjectIntersection] Rejects locked/inactive or excluded-state players, constructs player and @@ -60,21 +60,21 @@ s32 sub_080A9680(void) s32 *dx, *dy; s32 *sx, *sy; if (base[sub_080020F4()].lock != 0) goto fail; - idxF = 0x14C * sub_080020F4(); + idxF = PLAYER_SIZE * sub_080020F4(); pf = &base->flags; if (*(u32 *)((u8 *)pf + idxF) & 0x2000) goto fail; if (base[sub_080020F4()].active == 0) goto fail; if (base[sub_080020F4()].state == 14) goto fail; if (base[sub_080020F4()].state == 11) goto fail; if (base[sub_080020F4()].state == 12) goto fail; - idxX = 0x14C * sub_080020F4(); + idxX = PLAYER_SIZE * sub_080020F4(); px = &base->x; playerLine[0] = *(s32 *)((u8 *)px + idxX) >> 8; - idxY = 0x14C * sub_080020F4(); + idxY = PLAYER_SIZE * sub_080020F4(); py = &base->y; playerLine[1] = *(s32 *)((u8 *)py + idxY) >> 8; - playerLine[2] = (px[0x53 * sub_080020F4()] + 0xC00) >> 8; - playerLine[3] = (py[0x53 * sub_080020F4()] - 0x800) >> 8; + playerLine[2] = (px[(PLAYER_SIZE / 4) * sub_080020F4()] + 0xC00) >> 8; + playerLine[3] = (py[(PLAYER_SIZE / 4) * sub_080020F4()] - 0x800) >> 8; objectLine[0] = (object111[5] - 0x4000) >> 8; objectLine[1] = (object111[6] - 0x2000) >> 8; objectLine[2] = (object111[5] + 0x4000) >> 8; @@ -82,14 +82,14 @@ s32 sub_080A9680(void) if (sub_080A98E0(objectLine, objectLine + 2, playerLine, playerLine + 2) != 0) { ix = sub_080020F4(); jx = sub_080020F4(); - dx = (s32 *)((u8 *)px + 0x14C * ix); - srcIndexX = 0x14C * jx; + dx = (s32 *)((u8 *)px + PLAYER_SIZE * ix); + srcIndexX = PLAYER_SIZE * jx; sx = &base->oldX; *dx = *(s32 *)((u8 *)sx + srcIndexX); iy = sub_080020F4(); jy = sub_080020F4(); - dy = (s32 *)((u8 *)py + 0x14C * iy); - srcIndexY = 0x14C * jy; + dy = (s32 *)((u8 *)py + PLAYER_SIZE * iy); + srcIndexY = PLAYER_SIZE * jy; sy = &base->oldY; *dy = *(s32 *)((u8 *)sy + srcIndexY); return 1; @@ -201,7 +201,7 @@ s32 sub_080A9910(struct V *a, struct V *b, struct V *c) v2.y = c->y - a->y; r = v1.x * v2.y - v1.y * v2.x; res = 1; if (r <= 0) { res = 0; if (r < 0) res--; } return res; } -struct Res9950 { u8 p0[4]; s16 f4, f6; u8 p8[0x1F]; u8 f27; u8 p28[0xAE]; u16 fD6; }; +struct Res9950 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0x1F]; u8 f27; u8 p28[0xAE]; u16 fD6; }; struct Act9950 { u16 f0, f2; u8 p4[4]; @@ -226,11 +226,11 @@ struct Act9950 { u8 f1FD, f1FE, p1ff; u8 f200, p201; u16 f202; - u8 res[0xD4]; + u8 res[ENEMY_FIELD(0x2D8) - 0x204]; u16 f2D8, f2DA; }; struct Anim9950 { u32 f0, f4, f8; u8 *fC; u8 p10[12]; u8 f1C; u8 p1d[0x17]; }; -struct Pl9950 { u8 p0[0x30]; u32 flags; u8 p34[0x114]; u16 *f148; }; +struct Pl9950 { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; u16 *f148; }; struct Pose9950 { u8 animA, dirA, animB, dirB, flag; }; struct Map9950 { u8 p0[0x90]; u16 f90; }; struct XY9950 { s32 x, y; }; @@ -334,9 +334,9 @@ void sub_080A9950_v(struct Act9950 *a) gB9950 = a; gMask9950 |= 2; - gA9950 = (struct Act9950 *)((base = gBase9950) + 0x2E0); + gA9950 = (struct Act9950 *)((base = gBase9950) + ENEMY_SIZE); res = (struct Res9950 *)a->res; - resA = (struct Res9950 *)(base + 0x4E4); + resA = (struct Res9950 *)(base + ENEMY_SIZE + 0x204); setup9950(a, gImg9950, 0); setup9950(gA9950, gImg9950, 1); initRes9950(resA); @@ -346,7 +346,7 @@ void sub_080A9950_v(struct Act9950 *a) { struct Act9950 *g; u16 one; - base[0x50B] = one = 1; + base[ENEMY_SIZE + ENEMY_FIELD(0x22B)] = one = 1; g = gA9950; g->f0 = one; g->f2 = 5; @@ -386,7 +386,7 @@ void sub_080A9950_v(struct Act9950 *a) gB9950->f50 = 1; for (i = 0; i <= 3; i++) for (j = 0; j <= 4; j++) - *(s32 *)(gHist9950 + j * 4 + i * 0x14C) = 0; + *(s32 *)(gHist9950 + j * 4 + i * PLAYER_SIZE) = 0; proj = 0; alt = 0; sfxFlag = 0; @@ -905,7 +905,7 @@ void sub_080A9950_v(struct Act9950 *a) sub_08067BF8(); sub_08056E24(); } -struct P112A { u8 p0[0x20]; u16 state; u8 p22[14]; u32 flags; u8 p34[0x34]; u8 unk68; u8 p69[0x1f]; u16 unk88; u8 p8a[6]; s32 unk90; u8 p94[0x1c]; u16 unkB0; u8 pb2[0x16]; u16 unkC8,unkCA,unkCC; u8 pce[0x16]; u32 unkE4[0x1a]; }; +struct P112A { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[0x34]; u8 unk68; u8 p69[0x1f]; u16 unk88; u8 p8a[6]; s32 unk90; u8 p94[0x1c]; u16 unkB0; u8 pb2[0x16]; u16 unkC8,unkCA,unkCC; u8 pce[0x16]; u32 unkE4[0x1a]; }; struct O112A { u16 unk0; u8 p2[10]; u16 unkC; u8 pe[6]; s32 unk14,unk18; u8 p1c[0x34]; s32 unk50; }; extern struct P112A players112A[] asm("gUnk_03003CE0"); extern s32 x112A asm("gUnk_03003D6C"); @@ -964,7 +964,7 @@ s32 sub_080AB054(struct O112A *arg0, s32 arg1, s32 arg2, u32 arg3) { asm("" : "+r"(word2)); base = (struct P112A *)word2; - word1 = 0x14C; + word1 = PLAYER_SIZE; stride = word1; @@ -1070,24 +1070,24 @@ s32 sub_080AB054(struct O112A *arg0, s32 arg1, s32 arg2, u32 arg3) { idx = sub_080020F4(); tail = players112A; - word1 = 0x14C; + word1 = PLAYER_SIZE; idx *= word1; idx += (u32)tail; var_r1 = var_r4 - 2; - var_r0 = (s16 *)(idx + 0xCA); + var_r0 = (s16 *)(idx + PLAYER_FIELD(0xCA)); goto storeDirection; direction0: idx = sub_080020F4(); tail = players112A; - word1 = 0x14C; + word1 = PLAYER_SIZE; idx *= word1; idx += (u32)tail; - var_r0 = (s16 *)(idx + 0xCA); + var_r0 = (s16 *)(idx + PLAYER_FIELD(0xCA)); var_r1 = 6; goto storeDirection; @@ -1095,11 +1095,11 @@ s32 sub_080AB054(struct O112A *arg0, s32 arg1, s32 arg2, u32 arg3) { idx = sub_080020F4(); tail = players112A; - word1 = 0x14C; + word1 = PLAYER_SIZE; idx *= word1; idx += (u32)tail; - var_r0 = (s16 *)(idx + 0xCA); + var_r0 = (s16 *)(idx + PLAYER_FIELD(0xCA)); var_r1 = 7; storeDirection: @@ -1107,7 +1107,7 @@ s32 sub_080AB054(struct O112A *arg0, s32 arg1, s32 arg2, u32 arg3) { idx = sub_080020F4(); tailbase = players112A; - tailstride = 0x14C; + tailstride = PLAYER_SIZE; ((struct P112A *)(idx * tailstride + (u32)tailbase))->unkCC = 0x400; ((struct P112A *)(sub_080020F4() * tailstride + (u32)tailbase))->unkC8 = 0x10; @@ -1122,7 +1122,7 @@ void sub_080AB2D8(void) { gUnk_030056FC = 0; sub_08016ECC(gUnk_03000430); } -struct ResB2F8 { u8 p0[4]; s16 f4, f6; u8 p8[0xCE]; u16 fD6; }; +struct ResB2F8 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0xCE]; u16 fD6; }; struct ActB2F8 { u16 f0, f2; u8 p4[4]; @@ -1145,11 +1145,11 @@ struct ActB2F8 { u8 f1FC_hi : 4; u8 f1FD, f1FE, p1ff; u8 p200[4]; - u8 res[0xD4]; + u8 res[ENEMY_FIELD(0x2D8) - 0x204]; u16 f2D8, f2DA; }; struct AnimB2F8 { u32 f0, f4, f8; u8 *fC; u8 p10[12]; u8 f1C; u8 p1d[0x17]; }; -struct PlB2F8 { u8 p0[0x30]; u32 flags; u8 p34[0x114]; u16 *f148; }; +struct PlB2F8 { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; u16 *f148; }; extern struct ActB2F8 *gActB2F8 asm("gUnk_03000434"); extern u16 gTileB2F8 asm("gUnk_03000438"); @@ -1282,7 +1282,7 @@ void sub_080AB2F8_v(struct ActB2F8 *a) gActB2F8->f50 = 1; for (i = 0; i <= 3; i++) for (j = 0; j <= 4; j++) - *(s32 *)((u8 *)gHistB2F8 + j * 4 + i * 0x14C) = 0; + *(s32 *)((u8 *)gHistB2F8 + j * 4 + i * PLAYER_SIZE) = 0; sub_08097FE4(); sub_08097A4C(); done = 0; @@ -1560,7 +1560,11 @@ void sub_080AB2F8_v(struct ActB2F8 *a) gPlB2F8[sub_080020F4()].flags |= 1; gActB2F8->f6E = animB2F8(sl, 0, &gActB2F8->f6A, &gActB2F8->f6C, 1); if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD34() == 0) { +#ifdef REGION_USA + loadPalB2F8(gTileB2F8 + 0x10, sl->fC - -(res->fD6 * 32), 1); +#else loadPalB2F8(gTileB2F8 + 0x10, sl->fC + res->fD6 * 32, 1); +#endif prio = prioB2F8(gActB2F8->f14 >> 8, gActB2F8->f18 >> 8, 0); projB2F8((s16)(gActB2F8->f14 >> 8), (s16)(gActB2F8->f18 >> 8), &sx, &sy, 0, 0); drawB2F8(sx, sy, 0, gActB2F8->f6A, prio, &sl->f1C, sl->f8, sl->f0); @@ -1617,7 +1621,7 @@ void sub_080AB2F8_v(struct ActB2F8 *a) } sub_08056E24(); } -struct P113214 { u8 pad0[0x20]; u16 state; u8 pad22[14]; u32 flags; u8 pad34[0x34]; u8 active; u8 pad69[0x23]; s32 x,y; u8 pad94[0x34]; u16 c8,ca,cc; u8 padce[0x7e]; }; +struct P113214 { u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x,y; u8 pad94[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0x94)]; u16 c8,ca,cc; u8 padce[PLAYER_SIZE - PLAYER_FIELD(0xCE)]; }; extern struct P113214 p113214[] asm("gUnk_03003CE0"); extern s32 *obj113214 asm("gUnk_03000434"); extern u8 angle113214(s32,s32,s32,s32) asm("sub_08095FC8"); @@ -1636,15 +1640,15 @@ void sub_080AC214(s32 arg0) if (base[sub_080020F4()].state == 11) return; if (base[sub_080020F4()].state == 14) return; if (base[sub_080020F4()].state == 12) return; - offset = 0x14C * sub_080020F4(); + offset = PLAYER_SIZE * sub_080020F4(); flags = &base->flags; if (*(u32 *)(offset + (u32)flags) & 0x2000) return; if (base[sub_080020F4()].active == 0) return; i = sub_080020F4(); - offset = 0x14C * sub_080020F4(); + offset = PLAYER_SIZE * sub_080020F4(); coord = &base->x; x = *(s32 *)(offset + (u32)coord) >> 8; - offset = 0x14C * sub_080020F4(); + offset = PLAYER_SIZE * sub_080020F4(); coord = &base->y; base[i].ca = angle113214(x, *(s32 *)(offset + (u32)coord) >> 8, obj113214[5] >> 8, obj113214[6] >> 8); base[sub_080020F4()].cc = 0x200; @@ -1657,7 +1661,7 @@ void sub_080AC214(s32 arg0) -struct P1132 { u8 pad0[0x20]; u16 unk20; u8 pad22[14]; u32 flags; u8 pad34[0x34]; u8 unk68; u8 pad69[0x1f]; u16 unk88; u8 pad8a[2]; s32 unk8C,unk90; u8 pad94[0x1c]; u16 unkB0; u8 padb2[0x16]; u16 unkC8,unkCA,unkCC; u8 padce[0x16]; u32 unkE4[0x1a]; }; +struct P1132 { u8 pad0[PLAYER_FIELD(0x20)]; u16 unk20; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[0x34]; u8 unk68; u8 pad69[0x1f]; u16 unk88; u8 pad8a[2]; s32 unk8C,unk90; u8 pad94[0x1c]; u16 unkB0; u8 padb2[0x16]; u16 unkC8,unkCA,unkCC; u8 padce[0x16]; u32 unkE4[0x1a]; }; struct O1132 { u16 unk0; u8 pad2[10]; u16 unkC; u8 pade[6]; s32 unk14,unk18; u8 pad1c[0x34]; s32 unk50; }; extern struct P1132 players1132[] asm("gUnk_03003CE0"); extern struct O1132 *obj1132 asm("gUnk_03000434"); @@ -1724,9 +1728,9 @@ s32 sub_080AC2E8(u8 arg0) { initialObj = &obj1132; firstSource = *initialObj; initialBase = players1132; - initialStride = 0x14C; + initialStride = PLAYER_SIZE; indexWord = idx * initialStride; - angle = (u32)initialBase + 0x8C; + angle = (u32)initialBase + PLAYER_FIELD(0x8C); indexWord += angle; @@ -1765,7 +1769,7 @@ s32 sub_080AC2E8(u8 arg0) { } else if ((obj = &obj1132, (*obj)->unkC) == 0xB) { - } else if ((off = sub_080020F4(), base = players1132, stride = 0x14C, off *= stride, fp = &base->flags, *(u32 *)(off + (u32)fp) & 0x2000)) { + } else if ((off = sub_080020F4(), base = players1132, stride = PLAYER_SIZE, off *= stride, fp = &base->flags, *(u32 *)(off + (u32)fp) & 0x2000)) { } else if ((*(struct P1132 *)(sub_080020F4() * stride + (u32)base)).unk68 == 0) { @@ -1836,20 +1840,20 @@ s32 sub_080AC2E8(u8 arg0) { idx = sub_080020F4(); tail = players1132; - var_r0 = (s16 *)(idx * 0x14C + (u32)tail); + var_r0 = (s16 *)(idx * PLAYER_SIZE + (u32)tail); var_r1 = var_r4 - 2; - var_r0 = (s16 *)((u8 *)var_r0 + 0xCA); + var_r0 = (s16 *)((u8 *)var_r0 + PLAYER_FIELD(0xCA)); } goto storeDirection; } direction0: idx = sub_080020F4(); tail = players1132; - var_r0 = (s16 *)(idx * 0x14C + (u32)tail); var_r0 = (s16 *)((u8 *)var_r0 + 0xCA); var_r1 = 6; + var_r0 = (s16 *)(idx * PLAYER_SIZE + (u32)tail); var_r0 = (s16 *)((u8 *)var_r0 + PLAYER_FIELD(0xCA)); var_r1 = 6; goto storeDirection; direction1: idx = sub_080020F4(); tail = players1132; - var_r0 = (s16 *)(idx * 0x14C + (u32)tail); var_r0 = (s16 *)((u8 *)var_r0 + 0xCA); var_r1 = 7; + var_r0 = (s16 *)(idx * PLAYER_SIZE + (u32)tail); var_r0 = (s16 *)((u8 *)var_r0 + PLAYER_FIELD(0xCA)); var_r1 = 7; storeDirection: *var_r0 = var_r1; @@ -1867,7 +1871,7 @@ s32 sub_080AC2E8(u8 arg0) { -struct P1135 { u8 pad0[0x20]; u16 unk20; u8 pad22[14]; u32 flags; u8 pad34[0x34]; u8 unk68; u8 pad69[0x1f]; u16 unk88; u8 pad8a[2]; s32 unk8C; u8 pad90[0x20]; u16 unkB0; u8 padb2[0x16]; u16 unkC8,unkCA,unkCC; u8 padce[0x16]; u32 unkE4[0x1a]; }; +struct P1135 { u8 pad0[PLAYER_FIELD(0x20)]; u16 unk20; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 pad34[0x34]; u8 unk68; u8 pad69[0x1f]; u16 unk88; u8 pad8a[2]; s32 unk8C; u8 pad90[0x20]; u16 unkB0; u8 padb2[0x16]; u16 unkC8,unkCA,unkCC; u8 padce[0x16]; u32 unkE4[0x1a]; }; struct O1135 { u16 unk0; u8 pad2[10]; u16 unkC; u8 pade[6]; s32 unk14,unk18; u8 pad1c[0x34]; s32 unk50; }; extern struct P1135 players1135[] asm("gUnk_03003CE0"); extern struct O1135 *obj1135 asm("gUnk_03000434"); @@ -1916,7 +1920,7 @@ s32 sub_080AC5B4(void) { obj = &obj1135; initial = *obj; base = players1135; - stride = 0x14C; + stride = PLAYER_SIZE; idx *= stride; xp = &base->unk8C; @@ -2001,20 +2005,20 @@ s32 sub_080AC5B4(void) { idx = sub_080020F4(); tail = players1135; - var_r0 = (s16 *)(idx * 0x14C + (u32)tail); + var_r0 = (s16 *)(idx * PLAYER_SIZE + (u32)tail); var_r1 = var_r4 - 2; - var_r0 = (s16 *)((u8 *)var_r0 + 0xCA); + var_r0 = (s16 *)((u8 *)var_r0 + PLAYER_FIELD(0xCA)); } goto storeDirection; } direction0: idx = sub_080020F4(); tail = players1135; - var_r0 = (s16 *)(idx * 0x14C + (u32)tail); var_r0 = (s16 *)((u8 *)var_r0 + 0xCA); var_r1 = 6; + var_r0 = (s16 *)(idx * PLAYER_SIZE + (u32)tail); var_r0 = (s16 *)((u8 *)var_r0 + PLAYER_FIELD(0xCA)); var_r1 = 6; goto storeDirection; direction1: idx = sub_080020F4(); tail = players1135; - var_r0 = (s16 *)(idx * 0x14C + (u32)tail); var_r0 = (s16 *)((u8 *)var_r0 + 0xCA); var_r1 = 7; + var_r0 = (s16 *)(idx * PLAYER_SIZE + (u32)tail); var_r0 = (s16 *)((u8 *)var_r0 + PLAYER_FIELD(0xCA)); var_r1 = 7; storeDirection: *var_r0 = var_r1; @@ -2037,7 +2041,7 @@ void sub_080AC81C(void) gUnk_030056FC = 0; sub_08016ECC(gUnk_03000438); } -struct ResC844 { u8 p0[4]; s16 f4, f6; u8 p8[0xCE]; u16 fD6; }; +struct ResC844 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0xCE]; u16 fD6; }; struct ActC844 { u16 f0, f2; u8 p4[4]; @@ -2061,12 +2065,12 @@ struct ActC844 { u8 f1FD, f1FE, p1ff; u8 f200, p201; u16 f202; - u8 res[0xD4]; + u8 res[ENEMY_FIELD(0x2D8) - 0x204]; u16 f2D8, f2DA; }; struct SprC844 { u32 f0, f4, f8; u8 *fC; u8 p10[12]; u8 f1C; }; struct PosC844 { s32 x, y; }; -struct PlC844 { u8 p0[0x30]; u32 flags; u8 p34[0x118]; }; +struct PlC844 { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; extern struct ActC844 *gCurC844 asm("gUnk_03000440"); extern struct ActC844 *gActsC844[] asm("gUnk_03000448"); @@ -2163,7 +2167,7 @@ void sub_080AC844_v(struct ActC844 *a) a->f50 = 1; for (i = 0; i <= 3; i++) for (j = 0; j <= 4; j++) - *(s32 *)(gHistC844 + j * 4 + i * 0x14C) = 0; + *(s32 *)(gHistC844 + j * 4 + i * PLAYER_SIZE) = 0; gPosC844[0].x = a->f14 >> 8; gPosC844[0].y = (a->f18 >> 8) + 0x10; gDirC844[0] = 0; @@ -2457,7 +2461,7 @@ void sub_080AC844_v(struct ActC844 *a) } sub_08056E24(); } -struct ResAD534 { u8 p0[4]; s16 f4, f6; }; +struct ResAD534 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; }; struct ActorAD534 { u16 f0, f2; u8 p4[4]; @@ -2486,8 +2490,8 @@ struct ActorAD534 { }; struct SpriteAD534 { u32 f0, f4, f8; u16 *fC; u8 p10[12]; u8 f1C; }; struct PosAD534 { s32 x, y; }; -struct E2E0AD534 { u8 b[0x2E0]; }; -struct PlayerAD534 { u8 p0[0x30]; u32 flags; u8 p34[0x118]; }; +struct E2E0AD534 { u8 b[ENEMY_SIZE]; }; +struct PlayerAD534 { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; extern struct ActorAD534 *actorsAD534[] asm("gUnk_03000448"); extern struct SpriteAD534 spriteAD534 asm("gUnk_03000458"); @@ -2752,7 +2756,7 @@ void sub_080AD534_v(u32 idx) sub_0801E4CC(dataAD534, h); } } -struct Player114DE {u8 p0[0x20];u16 state;u8 p22[14];u32 flags;u8 p34[0x34];u8 active;u8 p69[0x1F];u16 angle;u16 p8A;s32 x,y;u8 p94[0x1C];u16 motion;u8 pB2[0x16];u16 timer;s16 direction;u16 speed;u8 pCE[0x16];u32 seen[26];}; +struct Player114DE {u8 p0[PLAYER_FIELD(0x20)];u16 state;u8 p22[PLAYER_FIELD(0x30)-PLAYER_FIELD(0x22)];u32 flags;u8 p34[0x34];u8 active;u8 p69[0x1F];u16 angle;u16 p8A;s32 x,y;u8 p94[0x1C];u16 motion;u8 pB2[0x16];u16 timer;s16 direction;u16 speed;u8 pCE[0x16];u32 seen[26];}; struct Entity114DE {u16 index;u8 p2[10];u16 state;u8 pE[6];s32 x,y;u8 p1C[0x34];u32 counter;}; extern s32 x114DE[] asm("gUnk_03003D6C"); extern struct Player114DE players114DE[] asm("gUnk_03003CE0"); @@ -2768,7 +2772,7 @@ s32 sub_080ADE30(struct Entity114DE *entity102A5) u16 a, lo; s32 id; - dx = (entity102A5->x - x114DE[({ s32 i=sub_080020F4(); asm("" : : "r"(players114DE)); i; })*83]) >> 8; + dx = (entity102A5->x - x114DE[({ s32 i=sub_080020F4(); asm("" : : "r"(players114DE)); i; })*(PLAYER_SIZE / 4)]) >> 8; dy = (entity102A5->y - players114DE[sub_080020F4()].y) >> 8; if (Sqrt(dx * dx + dy * dy) <= 0x0F && sub_0800CDF8() == 0 && sub_0800CCCC() == 0 && sub_0800CD8C() == 0 && entity102A5->state != 0xE && entity102A5->state != 0xB && entity102A5->state != 0xA @@ -2780,8 +2784,8 @@ s32 sub_080ADE30(struct Entity114DE *entity102A5) players114DE[sub_080020F4()].motion = 0xFFFE; id = sub_080020F4(); players114DE[id].angle += delta114DE(entity102A5, &players114DE[sub_080020F4()]); - { s32 i; u32 index; u32 *dest; u32 n; i=sub_080020F4(); index=entity102A5->index; index <<= 2; index += i*0x14c; dest=(u32 *)((u8 *)players114DE+0xe4+index); n=entity102A5->counter; *dest=n; entity102A5->counter=n+1; } - dx = (x114DE[sub_080020F4()*83] - entity102A5->x) >> 8; + { s32 i; u32 index; u32 *dest; u32 n; i=sub_080020F4(); index=entity102A5->index; index <<= 2; index += i*PLAYER_SIZE; dest=(u32 *)((u8 *)players114DE+PLAYER_FIELD(0xe4)+index); n=entity102A5->counter; *dest=n; entity102A5->counter=n+1; } + dx = (x114DE[sub_080020F4()*(PLAYER_SIZE / 4)] - entity102A5->x) >> 8; dy = (players114DE[sub_080020F4()].y - entity102A5->y) >> 8; a = ArcTan2(dx, dy); lo = a << 3; @@ -2884,7 +2888,7 @@ void sub_080AE184(void) } struct Entry114E {u8 *actor; u8 pad[0xA8];}; extern struct Entry114E entries114E[] asm("gUnk_030004D0"); -extern u32 history114E[][83] asm("gUnk_03003DC4"); +extern u32 history114E[][PLAYER_SIZE / 4] asm("gUnk_03003DC4"); extern u8 count114E asm("gUnk_03000780"); extern void sub_080AF2BC(void); extern void sub_080AF350(u8); @@ -2899,7 +2903,7 @@ void sub_080AE1B4(void) s16 count; s32 allocation[4]; u8 *actor; - { register u32 zero asm("r4"); register u32 stride asm("ip"); register u8 *cnt asm("r7"); register u32 *hist asm("r6"); i=0; cnt=&count114E; stride=0x14c; hist=(u32 *)history114E; asm("" : : "r"(hist)); zero=0; do { for (j=0;j<=4;j++) *(u32 *)((u8 *)history114E+i*stride+j*4)=zero; i++; } while(i<=3); } + { register u32 zero asm("r4"); register u32 stride asm("ip"); register u8 *cnt asm("r7"); register u32 *hist asm("r6"); i=0; cnt=&count114E; stride=PLAYER_SIZE; hist=(u32 *)history114E; asm("" : : "r"(hist)); zero=0; do { for (j=0;j<=4;j++) *(u32 *)((u8 *)history114E+i*stride+j*4)=zero; i++; } while(i<=3); } count114E=sub_08002164(); sub_080AF2BC(); for (i=0;ifE; cpuSetAE420(p->f58, a->f1CC, 0x18); - cpuSetAE420(p->f38, res, 0x10); + cpuSetAE420(p->f38, (u8 *)res + ENEMY_DATA_FIELD(0), 0x10); a0A4AE420(a); a->f1DC = 4; a->f5E = a->f1D4; @@ -3208,7 +3212,7 @@ void sub_080AE420_v(u32 idx) gEntAE420[idx].fAA = 0x1E; break; } - x34 = objAE420(res->f28 | 0xB0000)->f9B; + x34 = ITEM_KIND(objAE420(res->f28 | 0xB0000)); animInitAE420(&gEntAE420[idx].anim[0], gTblAE420[kind].a[x34], gEntAE420[idx].fA6, -1, 0); animInitAE420(&gEntAE420[idx].anim[1], gTblAE420[kind].b[x34], gEntAE420[idx].fA6, -1, 0); gEntAE420[idx].anim[0].f1C = gEntAE420[idx].fA6; @@ -3607,7 +3611,7 @@ void sub_080AF3C4(void) *m &= ~(1 << (*new_var)); } } -struct ResF3F4 { u8 p0[4]; s16 f4, f6; u8 p8[0x1C]; u16 f24; u8 p26[2]; u16 f28; }; +struct ResF3F4 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0x1C]; u16 f24; u8 p26[2]; u16 f28; }; struct ActF3F4 { u16 f0, f2; u8 p4[4]; @@ -3634,7 +3638,7 @@ struct ActF3F4 { struct ResF3F4 res; }; struct AnimF3F4 { u32 f0, f4, f8; u8 *fC; u8 p10[12]; u8 f1C; u8 p1d[0x17]; }; -struct PlF3F4 { u8 p0[0xC]; u16 fC; u8 pe[0x22]; u32 flags; u8 p34[0x118]; }; +struct PlF3F4 { u8 p0[PLAYER_FIELD(0xC)]; u16 fC; u8 pe[PLAYER_FIELD(0x30) - PLAYER_FIELD(0xE)]; u32 flags; u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; struct HistF3F4 { s32 h[5]; u8 rest[0x138]; }; extern struct ActF3F4 *gCurF3F4 asm("gUnk_03000788"); @@ -3696,7 +3700,7 @@ void sub_080AF3F4_v(struct ActF3F4 *a) s16 sx, sy; struct ResF3F4 *res; s32 lastHit; - u8 sfx; + ItemKind sfx; s32 animState; u16 lastAnim; s32 flag; @@ -3720,9 +3724,9 @@ void sub_080AF3F4_v(struct ActF3F4 *a) setupF3F4(a, gImgF3F4, 0); initResF3F4(res); a0A4F3F4(a); - animInitF3F4(&anim[0], 0x50089, 5, -1, 0); - animInitF3F4(&anim[1], 0x50087, 5, -1, 0); - animInitF3F4(&anim[2], 0x50088, 5, -1, 0); + animInitF3F4(&anim[0], RES_ID(0x50089), 5, -1, 0); + animInitF3F4(&anim[1], RES_ID(0x50087), 5, -1, 0); + animInitF3F4(&anim[2], RES_ID(0x50088), 5, -1, 0); a->f5C = a->f1D6 = res->f6 * 3; { s32 t = res->f4 * 2; a->f5E = a->f1D4 = ((res->f4 << 3) + t) * 2; } a->fC = 0; @@ -3732,15 +3736,19 @@ void sub_080AF3F4_v(struct ActF3F4 *a) hitTimer = 0; a->f1FD = 2; a->f1FE = 2; +#ifdef REGION_USA + { u16 *f = &res->f28; id = 0xB3; *f = id; } +#else id = 0xB3; res->f28 = id; - sfx = objF3F4(0xB0000 | id)[0x9B]; +#endif + sfx = ITEM_KIND(objF3F4(0xB0000 | id)); res->f24 = 2; - ((u8 *)a)[0x22B] = 0; + ((u8 *)a)[ENEMY_FIELD(0x22B)] = 0; a->f50 = 1; for (i = 0; i <= 3; i++) for (j = 0; j <= 4; j++) - *(s32 *)((u8 *)gHistF3F4 + j * 4 + i * 0x14C) = 0; + *(s32 *)((u8 *)gHistF3F4 + j * 4 + i * PLAYER_SIZE) = 0; a->f6C = 0; a->f6A = 0; a->f68 = 0; @@ -4077,7 +4085,7 @@ void sub_080AF3F4_v(struct ActF3F4 *a) } sub_08056E24(); } -struct Res0288 { u8 p0[4]; s16 f4, f6; u8 p8[0x1C]; u16 f24; u8 p26[2]; u16 f28; }; +struct Res0288 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0x1C]; u16 f24; u8 p26[2]; u16 f28; }; struct Act0288 { u16 f0, f2; u8 p4[4]; @@ -4104,7 +4112,7 @@ struct Act0288 { struct Res0288 res; }; struct Anim0288 { u32 f0, f4, f8; u8 *fC; u8 p10[12]; u8 f1C; u8 p1d[0x17]; }; -struct Pl0288 { u8 p0[0xC]; u16 fC; u8 pe[0x22]; u32 flags; u8 p34[0x118]; }; +struct Pl0288 { u8 p0[PLAYER_FIELD(0xC)]; u16 fC; u8 pe[PLAYER_FIELD(0x30) - PLAYER_FIELD(0xE)]; u32 flags; u8 p34[PLAYER_SIZE - PLAYER_FIELD(0x34)]; }; struct Hist0288 { s32 h[5]; u8 rest[0x138]; }; extern struct Act0288 *gCur0288 asm("gUnk_03000788"); @@ -4165,7 +4173,7 @@ void sub_080B0288_v(struct Act0288 *a) s16 sx, sy; struct Res0288 *res; s32 lastHit; - u8 sfx; + ItemKind sfx; s32 animState; u16 lastAnim; s32 flag; @@ -4187,9 +4195,9 @@ void sub_080B0288_v(struct Act0288 *a) setup0288(a, gImg0288, 0); initRes0288(res); a0A40288(a); - animInit0288(&anim[0], 0x50089, 5, -1, 0); - animInit0288(&anim[1], 0x50087, 5, -1, 0); - animInit0288(&anim[2], 0x50088, 5, -1, 0); + animInit0288(&anim[0], RES_ID(0x50089), 5, -1, 0); + animInit0288(&anim[1], RES_ID(0x50087), 5, -1, 0); + animInit0288(&anim[2], RES_ID(0x50088), 5, -1, 0); a->f5C = a->f1D6 = res->f6 * 3; { s32 t = res->f4 * 2; a->f5E = a->f1D4 = ((res->f4 << 3) + t) * 2; } a->fC = 0; @@ -4199,15 +4207,20 @@ void sub_080B0288_v(struct Act0288 *a) hitTimer = 0; a->f1FD = 2; a->f1FE = 2; +#ifdef REGION_USA + { u16 *f = &res->f28; id = 0xB3; *f = id; } + sfx = ITEM_KIND(obj0288(0xB0000 | id)); +#else id = 0xB3; res->f28 = id; - sfx = obj0288(0xB0000 | id)[0x9B]; + sfx = ITEM_KIND(obj0288(0xB0000 | id)); +#endif res->f24 = 2; - ((u8 *)a)[0x22B] = 0; + ((u8 *)a)[ENEMY_FIELD(0x22B)] = 0; a->f50 = 1; for (i = 0; i <= 3; i++) for (j = 0; j <= 4; j++) - *(s32 *)((u8 *)gHist0288 + j * 4 + i * 0x14C) = 0; + *(s32 *)((u8 *)gHist0288 + j * 4 + i * PLAYER_SIZE) = 0; a->f6C = 0; a->f6A = 0; a->f68 = 0; @@ -4535,7 +4548,7 @@ void sub_080B0FC4_v(struct Act0288 *a) struct Anim0288 *sl; struct Res0288 *res; s32 lastHit; - u8 sfx; + ItemKind sfx; s32 animState; u16 lastAnim; s32 flag; @@ -4560,7 +4573,7 @@ void sub_080B0FC4_v(struct Act0288 *a) setup0288(a, gImgB0FC4, 0); initRes0288(res); a0A40288(a); - { u16 *t = &gTileB0FC4; *t = allocB0FC4(*(u16 *)((u8 *)a + 0x2D8), 0); } + { u16 *t = &gTileB0FC4; *t = allocB0FC4(*(u16 *)((u8 *)a + ENEMY_FIELD(0x2D8)), 0); } while (gTileB0FC4 == 0xFFFF) { a->fC = 11; if (sub_0800CB78() || sub_08056E90()) { @@ -4569,9 +4582,9 @@ void sub_080B0FC4_v(struct Act0288 *a) } sub_080003F0(); } - animInit0288(&anim[0], 0x50089, gTileB0FC4, -1, 0); - animInit0288(&anim[1], 0x50087, gTileB0FC4, -1, 0); - animInit0288(&anim[2], 0x50088, gTileB0FC4, -1, 0); + animInit0288(&anim[0], RES_ID(0x50089), gTileB0FC4, -1, 0); + animInit0288(&anim[1], RES_ID(0x50087), gTileB0FC4, -1, 0); + animInit0288(&anim[2], RES_ID(0x50088), gTileB0FC4, -1, 0); a->f5C = a->f1D6 = res->f6 * 3; { s32 t = res->f4 * 2; a->f5E = a->f1D4 = ((res->f4 << 3) + t) * 2; } a->fC = 0; @@ -4581,15 +4594,19 @@ void sub_080B0FC4_v(struct Act0288 *a) hitTimer = 0; a->f1FD = 3; a->f1FE = 3; +#ifdef REGION_USA + { u16 *f = &res->f28; id = 0xB3; *f = id; } +#else id = 0xB3; res->f28 = id; - sfx = obj0288(0xB0000 | id)[0x9B]; +#endif + sfx = ITEM_KIND(obj0288(0xB0000 | id)); res->f24 = 2; - *((u8 *)res + 0x27) = 0; + *((u8 *)res + (ENEMY_FIELD(0x22B) - 0x204)) = 0; a->f50 = 1; for (i = 0; i <= 3; i++) for (j = 0; j <= 4; j++) - *(s32 *)((u8 *)gHist0288 + j * 4 + i * 0x14C) = 0; + *(s32 *)((u8 *)gHist0288 + j * 4 + i * PLAYER_SIZE) = 0; a->f6C = 0; a->f6A = 0; a->f68 = 0; @@ -5101,7 +5118,7 @@ s32 sub_080B2200(void) s32 r; u8 k; u32 sz; - sub_08065158_5(&s, 0x50089, gHalf030007A4, -1, 0); + sub_08065158_5(&s, RES_ID(0x50089), gHalf030007A4, -1, 0); s.b1C[0] = gHalf030007A4; sz = 0x18; a46 = 0; @@ -5171,7 +5188,7 @@ void sub_080B236C(u32 a, u32 b) second = b; sub_08000274_4(taskArg, first, second, z); } -struct Ene0B23C8 { u8 pad0[0x7A]; u16 flags; u8 pad7C[0x264]; }; +struct Ene0B23C8 { u8 pad0[0x7A]; u16 flags; u8 pad7C[ENEMY_SIZE - 0x7C]; }; extern struct Ene0B23C8 *enemies0B23C8 asm("gUnk_030056F4"); /* [SetEnemySlots1To4Flag0] Other enemy consumers test this bit together with scene-exit predicate to gate * action; exact mask name avoids claiming universal removal or forced stop. */ @@ -5223,9 +5240,9 @@ void sub_080B2454(void) sub_08000274_3((u32)gTaskP030007AC, 0, 0); } struct Task0B24B8 { u32 f0, f4, f8, fC, f10, f14, f18, f1C, f20, f24; }; -struct Actor0B24B8 { u16 f0; u8 pad2[0xA]; u16 fC; u8 padE[0x2CA]; u16 f2D8, f2DA; }; +struct Actor0B24B8 { u16 f0; u8 pad2[0xA]; u16 fC; u8 padE[ENEMY_FIELD(0x2D8) - 0xE]; u16 f2D8, f2DA; }; struct Pos0B24B8 { u16 x; u16 y; }; -struct Player0B24B8 { u8 pad0[0x148]; struct Pos0B24B8 *pos; }; +struct Player0B24B8 { u8 pad0[PLAYER_FIELD(0x148)]; struct Pos0B24B8 *pos; }; struct Point0B24B8 { s32 x, y; }; extern struct Task0B24B8 *taskA0B24B8 asm("gUnk_030007B0"); extern struct Task0B24B8 *taskB0B24B8 asm("gUnk_030007B4"); @@ -5236,7 +5253,7 @@ extern u16 slot0B24B8 asm("gUnk_030007C8"); extern u8 dir0B24B8 asm("gUnk_030007CA"); extern u8 tracking0B24B8 asm("gUnk_030007CB"); extern u8 pointing0B24B8 asm("gUnk_030007CC"); -extern u32 history0B24B8[4][83] asm("gUnk_03003DC4"); +extern u32 history0B24B8[4][PLAYER_SIZE / 4] asm("gUnk_03003DC4"); extern struct Player0B24B8 players0B24B8[] asm("gUnk_03003CE0"); extern u16 alloc0B24B8(u16, u16) asm("sub_08016E04"); extern s32 who0B24B8(s32) asm("sub_08096594"); @@ -5287,7 +5304,7 @@ void sub_080B24B8(struct Actor0B24B8 *actor) } for (i = 0; i <= 3; i++) for (j = 0; j <= 4; j++) - *(u32 *)(i * 0x14C + j * 4 + (u32)history0B24B8) = 0; + *(u32 *)(i * PLAYER_SIZE + j * 4 + (u32)history0B24B8) = 0; sub_08097FE4(); sub_08097A4C(); sub_08097C4C(); @@ -5358,7 +5375,7 @@ void sub_080B2780(void) { gUnk_030056FC = 0; sub_08016ECC(gUnk_030007C8); } -struct Res280C { u8 p0[4]; s16 f4, f6; u8 p8[0xCE]; u16 fD6; }; +struct Res280C { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0xCE]; u16 fD6; }; struct Actor280C { u16 f0, f2; u8 p4[4]; @@ -5387,7 +5404,7 @@ struct Actor280C { struct Spr280C { s32 f0, f4, f8, fC; u8 p10[12]; u8 f1C; u8 p1d[0x17]; }; struct Pos280C { s32 x, y; }; struct Tile280C { u16 pad : 4; u16 x : 12; u16 y : 12; u16 pad2 : 4; }; -struct Player280C { u8 p0[0x30]; u32 flags; u8 p34[0x114]; struct Tile280C *f148; }; +struct Player280C { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; struct Tile280C *f148; }; extern struct Actor280C *actor280C asm("gUnk_030007B8"); extern struct Actor280C *other280C asm("gUnk_030007BC"); @@ -5803,9 +5820,13 @@ void sub_080B280C(void) break; } mask280C &= ~(1 << actor280C->f0); +#ifdef REGION_USA + { u32 z; ((u8 *)actor280C)[ENEMY_FIELD(0x22E)] = z = 0; ((u8 *)actor280C)[ENEMY_FIELD(0x22F)] = z; sel = z; } +#else ((u8 *)actor280C)[0x22E] = 0; ((u8 *)actor280C)[0x22F] = 0; sel = 0; +#endif a4 = actor280C; a4->f68 = dir; a4->f6C = 0; diff --git a/src/code_080B3648.c b/src/code_080B3648.c index 5ab94dcf..f010b523 100644 --- a/src/code_080B3648.c +++ b/src/code_080B3648.c @@ -10,7 +10,7 @@ struct TaskP { u32 f0, f4, f8, fC, f10, f14, f18, f1C, f20, f24; }; void sub_080B5F94(void); void sub_080B6178(void); -struct ResB3648 { u8 p0[4]; s16 f4, f6; u8 p8[0x22]; u8 f2A, f2B; u8 p2C[0xAA]; u16 fD6; }; +struct ResB3648 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0x22]; u8 f2A, f2B; u8 p2C[0xAA]; u16 fD6; }; struct ActB3648 { u16 f0, f2; u8 p4[4]; @@ -38,10 +38,10 @@ struct ActB3648 { u16 f202; struct ResB3648 res; }; -struct E2E0B3648 { u8 b[0x2E0]; }; +struct E2E0B3648 { u8 b[ENEMY_SIZE]; }; struct AnimB3648 { u32 f0, f4, f8; u8 *fC; u8 p10[12]; u8 f1C; u8 p1d[0x17]; }; struct XYB3648 { s32 x, y; }; -struct PlB3648 { u8 p0[0x30]; u32 flags; u8 p34[0x114]; u16 *f148; }; +struct PlB3648 { u8 p0[PLAYER_FIELD(0x30)]; u32 flags; u8 p34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; u16 *f148; }; struct DrawB3648 { u8 p0[0xC]; s32 fC; }; struct G3170B3648 { u8 p0[0x90]; u16 f90; }; @@ -107,6 +107,9 @@ void sub_080B3648(void) struct { s16 x, y; } pos; struct XYB3648 tgt; struct XYB3648 off; +#ifdef REGION_USA + struct ResB3648 *res; +#endif s32 lastHit; s32 yoff; u16 tile; @@ -125,7 +128,9 @@ void sub_080B3648(void) u8 hitflag; s32 once; s32 active; +#ifndef REGION_USA struct ResB3648 *res; +#endif struct ActB3648 *a; u8 b; u8 c; @@ -585,7 +590,7 @@ void sub_080B3648(void) } } struct Boss0B44F0 { u16 index; u8 p2[0xA]; u16 state; u8 pE[6]; s32 x, y; u8 p1C[0x34]; u32 hitId; }; -struct Player0B44F0 { u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; u8 p34[0x34]; u8 alive; u8 p69[0x1F]; u16 hp; u8 p8A[2]; s32 x, y; u8 p94[0x1C]; u16 fB0; u8 pB2[0x32]; u32 hitIds[0x1A]; }; +struct Player0B44F0 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 alive; u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; u16 hp; u8 p8A[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x8A)]; s32 x, y; u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 fB0; u8 pB2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; u32 hitIds[0x1A]; }; extern struct Player0B44F0 players0B44F0[] asm("gUnk_03003CE0"); extern u16 hit0B44F0(void *, void *) asm("sub_0801ED8C"); s32 sub_080B44F0_v(struct Boss0B44F0 *b, s32 ox, s32 oy, u16 range) asm("sub_080B44F0"); @@ -628,7 +633,7 @@ s32 sub_080B44F0_v(struct Boss0B44F0 *b, s32 ox, s32 oy, u16 range) return hit; } struct Boss0B4690 { u16 index; u8 p2[6]; s16 f8; u8 pA[2]; u16 state; u8 pE[6]; s32 x, y; u8 p1C[0x34]; u32 hitId; }; -struct Player0B4690 { u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; u8 p34[0x34]; u8 alive; u8 p69[0x1F]; u16 hp; u8 p8A[2]; s32 x, y; u8 p94[0x1C]; u16 fB0; u8 pB2[0x32]; u32 hitIds[0x19]; u16 *f148; }; +struct Player0B4690 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 alive; u8 p69[PLAYER_FIELD(0x88) - PLAYER_FIELD(0x69)]; u16 hp; u8 p8A[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x8A)]; s32 x, y; u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 fB0; u8 pB2[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xB2)]; u32 hitIds[0x19]; u16 *f148; }; struct Anim0B4690 { s32 w0, w4, w8; u8 *graphics; u8 p10[12]; u8 data[0x18]; }; struct Vec0B4690 { s32 x, y; }; struct Task0B4690 { u32 f0, f4, f8; u8 pC[0x1C]; }; @@ -672,7 +677,7 @@ void sub_080B4690(u32 a0, u32 a1) idx = a1; for (i = 0; i < idx * 48; i++) sub_080003F0(); - init0B4690(&anim, 0x50130, 6, -1, 0); + init0B4690(&anim, RES_ID(0x50130), 6, -1, 0); sub_08000AF0(0x16, anim.graphics + 0x20, 1); anim.data[1] = 6; rotation = 0; @@ -755,11 +760,11 @@ void sub_080B4690(u32 a0, u32 a1) tasks0B4690[idx].f8 = 0; } struct B4A7CPlayer { - u8 pad0[0x20]; u16 state; u8 pad22[0x30 - 0x22]; - u32 flags; u8 pad34[0x68 - 0x34]; u8 active; - u8 pad69[0x8C - 0x69]; s32 x, y; - u8 pad94[0xC8 - 0x94]; u16 time, result, delay; - u8 tail[0x14C - 0xCE]; + u8 pad0[PLAYER_FIELD(0x20)]; u16 state; u8 pad22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; + u32 flags; u8 pad34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 active; + u8 pad69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x, y; + u8 pad94[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0x94)]; u16 time, result, delay; + u8 tail[PLAYER_SIZE - PLAYER_FIELD(0xCE)]; }; extern struct B4A7CPlayer playersB4A7C[] asm("gUnk_03003CE0"); extern u8 sub_08095FC8(s32, s32, s32, s32); @@ -788,20 +793,20 @@ void sub_080B4A7C(struct B4A7CTarget target) if (player->state == 0xC) return; index = sub_080020F4(); player = &players[index]; - field = (u8 *)players + 0x30; - if (*(u32 *)(field + index * 0x14C) & 0x2000) return; + field = (u8 *)players + PLAYER_FIELD(0x30); + if (*(u32 *)(field + index * PLAYER_SIZE) & 0x2000) return; index = sub_080020F4(); player = &players[index]; if (!player->active) return; targetIndex = sub_080020F4(); index = sub_080020F4(); player = &players[index]; - field = (u8 *)players + 0x8C; - x = *(s32 *)(field + index * 0x14C) >> 8; + field = (u8 *)players + PLAYER_FIELD(0x8C); + x = *(s32 *)(field + index * PLAYER_SIZE) >> 8; index = sub_080020F4(); player = &players[index]; - field = (u8 *)players + 0x90; - y = *(s32 *)(field + index * 0x14C) >> 8; + field = (u8 *)players + PLAYER_FIELD(0x90); + y = *(s32 *)(field + index * PLAYER_SIZE) >> 8; players[targetIndex].result = sub_08095FC8(x, y, target.x >> 8, target.y >> 8); index = sub_080020F4(); player = &players[index]; @@ -886,7 +891,7 @@ void sub_080B4BB8(u8 a, u16 arg) } do { t->f10 = t->f20 + 0x3FC; t->fC = (u32) sub_080B4690; t->f24 = z; t->f8 = arg + 0x40; sub_08000274_3((u32)t, a, arg); } while (0); } -struct Res4C34 { u8 p0[4]; s16 f4, f6; u8 p8[0x1F]; u8 f27; u8 p28[2]; u8 f2A, f2B; u8 p2C[0xA8]; u16 fD4, fD6; }; +struct Res4C34 { u8 p0[ENEMY_FIELD(0x208) - 0x204]; s16 f4, f6; u8 p8[0x1F]; u8 f27; u8 p28[2]; u8 f2A, f2B; u8 p2C[0xA8]; u16 fD4, fD6; }; struct Act4C34 { u16 f0, f2; u8 p4[4]; @@ -912,7 +917,7 @@ struct Act4C34 { u16 f202; struct Res4C34 res; }; -struct Pl4C34 { u8 p0[0xC]; u16 fC; u8 pe[0x22]; u32 flags; u8 p34[0x114]; u16 *f148; }; +struct Pl4C34 { u8 p0[PLAYER_FIELD(0xC)]; u16 fC; u8 pe[PLAYER_FIELD(0x30) - PLAYER_FIELD(0xE)]; u32 flags; u8 p34[PLAYER_FIELD(0x148) - PLAYER_FIELD(0x34)]; u16 *f148; }; struct XY4C34 { s32 x, y; }; struct G5CF4_4C34 { u8 p0[0x720]; u32 f720; }; @@ -950,7 +955,7 @@ static inline s32 ABS4C34(s32 x) { if (x < 0) x = -x; return x; } s32 z; \ gPl4C34[sub_080020F4()].flags |= 1; \ if (sub_0800CCCC() == 0 && sub_0800CC98() == 0 && sub_0800CD8C() == 0 && (z = sub_0800CD34()) == 0) { \ - loadPalB3648(gTile4C34 + 0x10, anim.fC + *pres * 32, 1); \ + loadPalB3648(gTile4C34 + 0x10, anim.fC + D6_4C34 * 32, 1); \ b = prioB3648(gAct4C34->f14 >> 8, gAct4C34->f18 >> 8, 0); \ gAct4C34->f6E = animB3648(&anim, gAct4C34->f68, &gAct4C34->f6A, &gAct4C34->f6C, 1); \ projB3648((s16)(gAct4C34->f14 >> 8), (s16)(gAct4C34->f18 >> 8), &sx, &sy, z, z); \ @@ -967,6 +972,11 @@ static inline s32 ABS4C34(s32 x) { if (x < 0) x = -x; return x; } * animation/damage feedback. On death/session/area exit clears its active bit, stops the auxiliary task, * dispatches remote full-HP damage, synchronizes the completion token, shows resource0x1400A7 and runs * transition/reward feedback when eligible; finally synchronizes and marks the encounter finished. */ +#ifdef REGION_USA +#define D6_4C34 (res->fD6) +#else +#define D6_4C34 (*pres) +#endif void sub_080B4C34(struct Act4C34 *a) { struct AnimB3648 anim; @@ -988,7 +998,9 @@ void sub_080B4C34(struct Act4C34 *a) u8 cooldown; u8 cycle; u8 cycle2; +#ifndef REGION_USA u16 *pres; +#endif s16 i, j; s16 cnt; u8 b; @@ -1029,10 +1041,12 @@ void sub_080B4C34(struct Act4C34 *a) save22E = gAct4C34->res.f2A; save22F = gAct4C34->res.f2B; gAct4C34->f50 = 1; +#ifndef REGION_USA pres = &res->fD6; +#endif for (i = 0; i <= 3; i++) for (j = 0; j <= 4; j++) - *(u32 *)(i * 0x14C + j * 4 + (u32)gHist4C34) = 0; + *(u32 *)(i * PLAYER_SIZE + j * 4 + (u32)gHist4C34) = 0; gAct4C34->f1FD = 3; gAct4C34->f1FE = 3; gAct4C34->f1FC_lo = gAct4C34->f0; @@ -1278,7 +1292,7 @@ void sub_080B4C34(struct Act4C34 *a) cooldown = 0; } } - loadPalB3648(gTile4C34 + 0x10, anim.fC + *pres * 32, 1); + loadPalB3648(gTile4C34 + 0x10, anim.fC + D6_4C34 * 32, 1); if (bgFlagB3648() & 1) b = bgPrioB3648(); else @@ -1336,7 +1350,7 @@ void sub_080B4C34(struct Act4C34 *a) gGame4C34->f720 = msg4C34(1, 14, 0x19, 2, 0x3C, 0x1400A7); while (msgDone4C34(gGame4C34->f720) == 0) REDRAW4C34(); - dropB3648(gAct4C34, &anim, *pres, gTile4C34); + dropB3648(gAct4C34, &anim, D6_4C34, gTile4C34); if (!(gPl4C34[sub_080020F4()].flags & 0x2000) && gAct4C34->f5A != 0) { h = dropFxB3648(gDataB3648, res); for (shake = 0x1D; shake != -1; shake--) { @@ -1352,7 +1366,7 @@ void sub_080B4C34(struct Act4C34 *a) sub_08067BF8(); sub_08056E24(); } -struct Player0B5B90 { u8 p0[0x20]; u16 state; u8 p22[0xE]; u32 flags; u8 p34[0x34]; u8 b68; u8 p69[0x23]; s32 x, y; u8 p94[0x1C]; u16 wB0; u8 pB2[0x16]; u16 knock, dir, speed; u8 pCE[0x16]; u32 hits[4]; u8 pF4[0x14C - 0xF4]; }; +struct Player0B5B90 { u8 p0[PLAYER_FIELD(0x20)]; u16 state; u8 p22[PLAYER_FIELD(0x30) - PLAYER_FIELD(0x22)]; u32 flags; u8 p34[PLAYER_FIELD(0x68) - PLAYER_FIELD(0x34)]; u8 b68; u8 p69[PLAYER_FIELD(0x8C) - PLAYER_FIELD(0x69)]; s32 x, y; u8 p94[PLAYER_FIELD(0xB0) - PLAYER_FIELD(0x94)]; u16 wB0; u8 pB2[PLAYER_FIELD(0xC8) - PLAYER_FIELD(0xB2)]; u16 knock, dir, speed; u8 pCE[PLAYER_FIELD(0xE4) - PLAYER_FIELD(0xCE)]; u32 hits[4]; u8 pF4[PLAYER_SIZE - PLAYER_FIELD(0xF4)]; }; struct Boss0B5B90 { u16 slot; u8 p2[0xA]; u16 state; u8 pE[6]; s32 x, y; u8 p1C[0x34]; u32 hitId; u8 p54[8]; s16 active; }; extern struct Player0B5B90 players0B5B90[] asm("gUnk_03003CE0"); extern struct Boss0B5B90 *boss0B5B90 asm("gUnk_030007DC"); @@ -1452,7 +1466,7 @@ u32 sub_080B5B90(u8 kind) out: return ret; } -struct Enemy0B5E64 { u8 p0[0xC]; u16 state; u8 pE[6]; s32 x, y; u8 p1C[0x2E]; u16 hp; u8 p4C[8]; u32 hitId; u8 p58[0x24]; u16 knock, dir, speed; u8 p82[0x25E]; }; +struct Enemy0B5E64 { u8 p0[0xC]; u16 state; u8 pE[6]; s32 x, y; u8 p1C[0x2E]; u16 hp; u8 p4C[8]; u32 hitId; u8 p58[0x24]; u16 knock, dir, speed; u8 p82[ENEMY_SIZE - 0x82]; }; struct Boss0B5E64 { u8 p0[0xC]; u16 state; u8 pE[6]; s32 x, y; u8 p1C[0x34]; u32 hitId; u8 p54[8]; s16 active; }; extern struct Enemy0B5E64 *enemies0B5E64 asm("gUnk_030056F4"); extern u32 activeMask0B5E64 asm("gUnk_030056FC"); @@ -1631,7 +1645,7 @@ void clearTask60F4(void) i = 1; do { if (gMask60F4 & (1 << i)) - *(u16 *)(gIcons60F4 + i * 0x2E0 + 0x7A) |= 1; + *(u16 *)(gIcons60F4 + i * ENEMY_SIZE + 0x7A) |= 1; i++; } while (i <= 4); i = 0; @@ -1819,6 +1833,18 @@ void sub_080B6448(u32 a, u32 b) } /* [FlagFourActorEntries] ORs bit 0 into halfword +0x7A of actor-array entries 1 through 4 at stride 0x2E0; * does not test the connected-entry mask. */ +#ifdef REGION_USA +void sub_080B64A4(void) +{ + register void *volatile *base asm("r5"); + u8 i; + asm("" : : : "r4", "r6"); + i = 1; + base = &gUnk_030056F4; + for (i = 1; i <= 4; i++) + *(u16 *)((u8 *)*base + i * ENEMY_SIZE + 0x7A) |= 1; +} +#else void sub_080B64A4(void) { register void *volatile *base asm("r4"); @@ -1827,5 +1853,6 @@ void sub_080B64A4(void) i = 1; base = &gUnk_030056F4; for (i = 1; i <= 4; i++) - *(u16 *)((u8 *)*base + i * 0x2E0 + 0x7A) |= 1; + *(u16 *)((u8 *)*base + i * ENEMY_SIZE + 0x7A) |= 1; } +#endif diff --git a/src/libgcc2.c b/src/libgcc2.c index 7110ccc5..ed91fa7f 100644 --- a/src/libgcc2.c +++ b/src/libgcc2.c @@ -354,7 +354,7 @@ __udiv_w_sdiv (USItype *rp __attribute__ ((__unused__)), #endif #ifdef L_udivmoddi4 -static const UQItype __clz_tab[] = +const UQItype __clz_tab[] = { 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, diff --git a/src/regions/usa/usa_only.c b/src/regions/usa/usa_only.c index 7a91ff7e..b8095265 100644 --- a/src/regions/usa/usa_only.c +++ b/src/regions/usa/usa_only.c @@ -17,25 +17,11 @@ extern u32 usaDialogueRowIndex asm("usa_gUnk_03003590"); extern u32 usaLinkQueueCount asm("usa_gUnk_03006488"); extern u8 *usaLinkQueue asm("usa_gUnk_03006450"); extern u8 *usaEnemies asm("usa_gUnk_03005844"); -extern u32 usaDigitDivisors[] asm("usa_gUnk_08540B8C"); extern u32 usaStartTextWindowTask(u32, u32, u32, u32) asm("usa_sub_0805D6E8"); extern void usaInitSpriteResourceDescriptor(void *, u32, u32, u32, u32) asm("usa_sub_08064FC0"); extern u32 usaResolveMainResourceById(u32) asm("usa_sub_08006E34"); extern void usaTaskDialogueScriptWindow(void) asm("usa_sub_0805E1DC"); -extern u32 sub_08000498(s32 *, u32); - -/* [CountRenderableScriptGlyphs16] USA 16-bit-text form of EU CountRenderableScriptGlyphs (sub_0801A638): - * counts halfwords until the 0xFFFD terminator or any control halfword with bit 15 set. */ -u32 usa_sub_0801A1C8(u16 *text) -{ - u32 n = 0; - while (*text != 0xFFFD && !(*text & 0x8000)) { - n++; - text++; - } - return n; -} /* [StartDialogueTaskAtLayout] Unreferenced in the USA ROM. Like EU StartFixedLayoutDialogueTask, but the * window position and size are arguments (height scaled by 13/8) and the stack is 0x1000 bytes without a retry @@ -141,50 +127,3 @@ u32 usa_sub_08067CA4(u32 index) usaLinkQueueCount++; return 1; } - -/* [ExpandEncodedTextUnsignedNumberToken16] USA 16-bit-text form of EU ExpandEncodedTextUnsignedNumberToken - * (sub_080850C0): skips the two-halfword header, copies until 0xFFFD and replaces each 0xFFF7 token with the - * decimal digits of value (leading zeros dropped, glyph = digit + 0x41). Returns the last written halfword. */ -u16 *usa_sub_080813D8(u16 *src, u16 value, u16 *dst) -{ - u16 n; - u16 c; - u16 *next; - src += 2; - n = 0; - while ((c = *src) != 0xFFFD) { - register u32 token asm("r1") = 0xFFF7; - if (c == token) { - s32 number; - u32 *divisor; - u16 *out; - u32 started; - u16 i; - register s32 copy asm("r0") = value; - asm("" : "+r"(copy)); - number = copy; - divisor = usaDigitDivisors; - out = dst + n; - started = 0; - i = 0; - next = src + 1; - do { - u32 ch = sub_08000498(&number, *divisor) + 0x41; - *out = ch; - if (started != 0 || (u16)ch != 0x41 || i == 5) { - out++; - started = 1; - n++; - } - i++; - divisor++; - } while (i <= 5); - } else { - dst[n++] = c; - next = src + 1; - } - src = next; - } - dst[n] = 0xFFFD; - return dst + (n - 1); -} diff --git a/tools/config/region_symbols_jp.json b/tools/config/region_symbols_jp.json index ffb3d258..c4c5d6c3 100644 --- a/tools/config/region_symbols_jp.json +++ b/tools/config/region_symbols_jp.json @@ -8,6 +8,7 @@ "0x08000760": "0x08000760", "0x0800086C": "0x0800086C", "0x080008C8": "0x080008C8", + "0x0800093C": "0x0800093C", "0x08000940": "0x08000940", "0x08000968": "0x08000968", "0x08000990": "0x08000990", @@ -39,6 +40,7 @@ "0x08001404": "0x08001404", "0x08001494": "0x08001494", "0x08001538": "0x08001538", + "0x08001634": "0x08001634", "0x08001638": "0x08001638", "0x080016C8": "0x080016C8", "0x080016EC": "0x080016EC", @@ -290,6 +292,7 @@ "0x0801A298": "0x08019DF8", "0x0801A2F0": "0x08019E50", "0x0801A328": "0x08019E88", + "0x0801A500": "0x0801A0BC", "0x0801A508": "0x0801A0C4", "0x0801A558": "0x0801A114", "0x0801A5A8": "0x0801A164", @@ -506,6 +509,7 @@ "0x0805782C": "0x08058CF0", "0x080578BC": "0x08058D80", "0x080579AC": "0x08058E78", + "0x080579D8": "0x08058EA8", "0x08057A20": "0x08058EF0", "0x08057A5C": "0x08058F2C", "0x08057AA4": "0x08058F74", @@ -534,6 +538,8 @@ "0x080583EC": "0x08059814", "0x08058404": "0x0805982C", "0x08058420": "0x08059848", + "0x080584FC": "0x0805992C", + "0x08058510": "0x08059940", "0x08058524": "0x08059954", "0x0805853C": "0x0805996C", "0x08058574": "0x080599A4", @@ -577,6 +583,7 @@ "0x08058CC4": "0x0805A0F8", "0x08058D8C": "0x0805A1C0", "0x08058D98": "0x0805A1CC", + "0x08058E14": "0x0805A24C", "0x08058E28": "0x0805A260", "0x08058E3C": "0x0805A274", "0x0805921C": "0x0805A2E8", @@ -660,6 +667,7 @@ "0x0805EF84": "0x0805F8A8", "0x0805EF90": "0x0805F8B4", "0x0805EFBC": "0x0805F8E0", + "0x0805F0C4": "0x0805F9D4", "0x0805F0F0": "0x0805FA00", "0x0805F134": "0x0805FA44", "0x0805F158": "0x0805FA68", @@ -667,6 +675,7 @@ "0x0805FAC0": "0x080601A4", "0x0805FB7C": "0x08060260", "0x0805FC0C": "0x080602F0", + "0x08061688": "0x08061E08", "0x0806171C": "0x08061E9C", "0x08061910": "0x08062090", "0x08061B88": "0x08062308", @@ -786,6 +795,7 @@ "0x080760E8": "0x080768A8", "0x08077444": "0x08077C6C", "0x080793BC": "0x08079C34", + "0x08079CC4": "0x0807A548", "0x08079ED0": "0x0807A754", "0x0807A028": "0x0807A8B0", "0x0807A040": "0x0807A8C8", @@ -831,6 +841,9 @@ "0x0808D05C": "0x0808D324", "0x0808D0B0": "0x0808D378", "0x0808D118": "0x0808D3E4", + "0x0808D11C": "0x0808D3E8", + "0x0808D190": "0x0808D45C", + "0x0808D204": "0x0808D4D0", "0x0808DE08": "0x0808E104", "0x0808DE94": "0x0808E190", "0x0808DF14": "0x0808E210", @@ -858,6 +871,10 @@ "0x0808FB5C": "0x0808FEE0", "0x0808FBDC": "0x0808FF60", "0x0808FD88": "0x08090114", + "0x0808FEB8": "0x08090250", + "0x0808FF28": "0x080902C0", + "0x0808FF98": "0x08090330", + "0x08090008": "0x080903A0", "0x0809007C": "0x08090414", "0x080901A8": "0x08090540", "0x0809021C": "0x080905B4", @@ -982,6 +999,7 @@ "0x08098060": "0x08098374", "0x08098088": "0x0809839C", "0x080980F0": "0x08098404", + "0x08099720": "0x08099B64", "0x0809975C": "0x08099BA0", "0x08099788": "0x08099BCC", "0x080997C0": "0x08099C04", @@ -989,6 +1007,7 @@ "0x0809AE24": "0x0809B394", "0x0809AE50": "0x0809B3C0", "0x0809AE88": "0x0809B3F8", + "0x0809D558": "0x0809DCB4", "0x0809D564": "0x0809DCC0", "0x0809D574": "0x0809DCD0", "0x0809D5B8": "0x0809DD14", @@ -1003,6 +1022,9 @@ "0x0809D848": "0x0809DFA4", "0x0809EDFC": "0x0809F5B8", "0x0809EF84": "0x0809F740", + "0x0809F8C8": "0x080A0118", + "0x0809F90C": "0x080A015C", + "0x0809F918": "0x080A0168", "0x0809F934": "0x080A0184", "0x0809F998": "0x080A01E8", "0x0809F9F8": "0x080A0248", @@ -1268,6 +1290,8 @@ "0x030002BD": "0x03000355", "0x030002C0": "0x03000358", "0x030002C8": "0x03000360", + "0x030002D0": "0x03000368", + "0x030002D4": "0x0300036C", "0x030002D8": "0x03000370", "0x030002DC": "0x03000374", "0x030002E0": "0x03000378", @@ -1281,7 +1305,10 @@ "0x03000308": "0x030003A0", "0x0300030C": "0x030003A4", "0x0300030E": "0x030003A6", + "0x03000310": "0x030003A8", + "0x03000314": "0x030003AC", "0x03000318": "0x030003B0", + "0x0300031C": "0x030003B4", "0x0300031E": "0x030003B6", "0x03000320": "0x030003B8", "0x03000324": "0x030003BC", @@ -1473,6 +1500,7 @@ "0x03006040": "0x03006100", "0x03006110": "0x030061D0", "0x03006160": "0x03006220", + "0x03006180": "0x03006240", "0x030061B0": "0x03006270", "0x030061E0": "0x030062A0", "0x03006208": "0x030062C8", @@ -1953,6 +1981,7 @@ "0x0805F1B1": "0x0805FAC1", "0x0805FB7D": "0x08060261", "0x0805FC81": "0x08060365", + "0x08060E45": "0x080615C1", "0x08061911": "0x08062091", "0x08061E45": "0x080625C5", "0x080624D9": "0x08062CB5", @@ -1970,6 +1999,7 @@ "0x080653B9": "0x080659E5", "0x080653CD": "0x080659F9", "0x08065425": "0x08065A51", + "0x080656ED": "0x08065D19", "0x080658A1": "0x08065ECD", "0x080658CD": "0x08065EF9", "0x080659F5": "0x08066021", @@ -2016,6 +2046,7 @@ "0x08075779": "0x08075F1D", "0x08076BA1": "0x08077375", "0x08078BCD": "0x08079429", + "0x08079949": "0x0807A1C5", "0x08079D85": "0x0807A609", "0x0807A121": "0x0807A9A9", "0x0807A125": "0x0807A9AD", @@ -2139,6 +2170,7 @@ "0x08098061": "0x08098375", "0x0809919D": "0x08099591", "0x08099469": "0x08099871", + "0x08099789": "0x08099BCD", "0x0809A835": "0x0809AD59", "0x0809AE51": "0x0809B3C1", "0x0809C1B5": "0x0809C791", @@ -2152,6 +2184,9 @@ "0x0809E469": "0x0809EC35", "0x0809F019": "0x0809F7D5", "0x0809F4A9": "0x0809FCB5", + "0x0809F935": "0x080A0185", + "0x0809FA29": "0x080A0279", + "0x0809FAED": "0x080A033D", "0x080A05B5": "0x080A0E3D", "0x080A099D": "0x080A1285", "0x080A0B45": "0x080A1459", diff --git a/tools/config/region_symbols_usa.json b/tools/config/region_symbols_usa.json index a5616193..05b01e1f 100644 --- a/tools/config/region_symbols_usa.json +++ b/tools/config/region_symbols_usa.json @@ -8,6 +8,7 @@ "0x08000760": "0x08000760", "0x0800086C": "0x0800086C", "0x080008C8": "0x080008C8", + "0x0800093C": "0x0800093C", "0x08000940": "0x08000940", "0x08000968": "0x08000968", "0x08000990": "0x08000990", @@ -39,6 +40,7 @@ "0x08001404": "0x08001404", "0x08001494": "0x08001494", "0x08001538": "0x08001538", + "0x08001634": "0x08001634", "0x08001638": "0x08001638", "0x080016C8": "0x080016C8", "0x080016EC": "0x080016EC", @@ -52,6 +54,7 @@ "0x08001B04": "0x08001B04", "0x08001B14": "0x08001B14", "0x08001B54": "0x08001B54", + "0x08001B78": "0x08001B78", "0x08001BE4": "0x08001BE4", "0x08001DF0": "0x08001DF0", "0x0800207C": "0x0800207C", @@ -72,11 +75,17 @@ "0x080022A4": "0x080022A4", "0x080022F4": "0x080022F4", "0x08002304": "0x08002304", + "0x0800232C": "0x0800232C", "0x08002658": "0x080024CC", + "0x08002694": "0x08002508", "0x08002A54": "0x0800285C", "0x08002A8C": "0x08002894", "0x08002AA0": "0x080028A8", + "0x08002B70": "0x08002978", + "0x08003984": "0x08003728", "0x08005A24": "0x08005638", + "0x08005B88": "0x0800579C", + "0x0800608C": "0x08005C58", "0x08006544": "0x080060C0", "0x08006550": "0x080060CC", "0x080065B0": "0x0800612C", @@ -121,6 +130,7 @@ "0x08006E64": "0x080069E0", "0x08006E84": "0x08006A00", "0x08006EC8": "0x08006A44", + "0x08006EE0": "0x08006A5C", "0x08007164": "0x08006D08", "0x08007280": "0x08006E24", "0x08007290": "0x08006E34", @@ -149,6 +159,7 @@ "0x0800907C": "0x08008C20", "0x08009088": "0x08008C2C", "0x080090B0": "0x08008C54", + "0x08009138": "0x08008CDC", "0x080092C8": "0x08008E64", "0x080093E4": "0x08008F80", "0x080094CC": "0x08009068", @@ -158,6 +169,7 @@ "0x0800A03C": "0x08009BD8", "0x0800A298": "0x08009E34", "0x0800A34C": "0x08009EE8", + "0x0800A998": "0x0800A534", "0x0800AD04": "0x0800A8A0", "0x0800AE50": "0x0800A9EC", "0x0800AEF4": "0x0800AA90", @@ -183,6 +195,7 @@ "0x0800BD1C": "0x0800B700", "0x0800BD48": "0x0800B72C", "0x0800BD5C": "0x0800B740", + "0x0800BEC0": "0x0800B8A4", "0x0800C9F4": "0x0800C3D8", "0x0800CB30": "0x0800C514", "0x0800CB3C": "0x0800C520", @@ -264,42 +277,119 @@ "0x0800D140": "0x0800CB24", "0x0800D154": "0x0800CB38", "0x0800D164": "0x0800CB48", + "0x0800D1B0": "0x0800CB94", + "0x0800D2F4": "0x0800CCD8", + "0x0800D368": "0x0800CD4C", + "0x080135C4": "0x08013024", + "0x080137A0": "0x08013204", + "0x08013850": "0x080132B4", + "0x08013BC0": "0x08013630", + "0x08013C3C": "0x080136AC", + "0x08013CEC": "0x0801375C", "0x08013E90": "0x08013900", + "0x080140AC": "0x08013B1C", + "0x08014170": "0x08013BE0", + "0x08014B28": "0x08014594", + "0x08014C04": "0x08014670", + "0x08014C8C": "0x080146F8", + "0x08014D60": "0x080147CC", + "0x08014E68": "0x080148D4", "0x0801500C": "0x08014A78", + "0x08015090": "0x08014AFC", + "0x08015150": "0x08014BBC", + "0x080151E0": "0x08014C4C", + "0x080152CC": "0x08014D38", + "0x080153A4": "0x08014E10", + "0x08015464": "0x08014ED0", + "0x0801551C": "0x08014F88", + "0x08015620": "0x0801508C", + "0x080156FC": "0x08015168", + "0x08015820": "0x0801528C", + "0x08015914": "0x08015380", + "0x08015A48": "0x080154B4", + "0x08015B20": "0x0801558C", + "0x08015C14": "0x08015680", + "0x08015C38": "0x080156A4", + "0x08015C5C": "0x080156C8", + "0x08015C8C": "0x080156F8", + "0x08015CB4": "0x08015720", + "0x08015CE0": "0x0801574C", + "0x08015D04": "0x08015770", + "0x08015D2C": "0x08015798", + "0x08015D50": "0x080157BC", + "0x08015D74": "0x080157E0", + "0x08015D98": "0x08015804", "0x08015DC0": "0x0801582C", "0x08015DE0": "0x0801584C", "0x08015E00": "0x0801586C", + "0x08015E3C": "0x080158A8", + "0x08015E84": "0x080158F0", + "0x08015ED4": "0x08015940", + "0x08015EF8": "0x08015964", + "0x08015F20": "0x0801598C", "0x08015F44": "0x080159B0", "0x0801602C": "0x08015A98", + "0x08016114": "0x08015B80", "0x080161A4": "0x08015C14", + "0x0801623C": "0x08015CAC", + "0x0801641C": "0x08015E90", + "0x0801674C": "0x080161C8", "0x0801681C": "0x08016294", "0x080168FC": "0x08016374", + "0x080169C8": "0x08016440", + "0x08016A7C": "0x080164F4", + "0x08016B30": "0x080165A8", "0x08016C88": "0x08016700", + "0x08016D40": "0x080167B8", "0x08016E04": "0x08016878", "0x08016ECC": "0x08016940", + "0x08016F28": "0x0801699C", + "0x08017C6C": "0x080176E4", + "0x08017E34": "0x080178B4", + "0x08017EC8": "0x08017948", + "0x08017F7C": "0x080179FC", + "0x0801801C": "0x08017A9C", + "0x08019BF8": "0x08019744", + "0x08019C3C": "0x08019788", "0x08019C8C": "0x080197DC", "0x08019CDC": "0x0801982C", "0x08019CE8": "0x08019838", + "0x08019D34": "0x08019884", "0x08019D7C": "0x080198D0", + "0x08019DE0": "0x08019934", "0x08019E20": "0x08019978", + "0x08019E30": "0x08019988", "0x08019E74": "0x080199D0", + "0x08019EB8": "0x08019A14", + "0x08019F04": "0x08019A60", + "0x08019F60": "0x08019ABC", "0x08019FA8": "0x08019B20", "0x08019FD8": "0x08019B50", "0x0801A040": "0x08019BB8", + "0x0801A050": "0x08019BC8", "0x0801A0A4": "0x08019C1C", "0x0801A0B0": "0x08019C28", + "0x0801A0BC": "0x08019C34", "0x0801A120": "0x08019C9C", + "0x0801A1C8": "0x08019D44", "0x0801A270": "0x08019DE4", "0x0801A298": "0x08019E0C", "0x0801A2F0": "0x08019E64", "0x0801A328": "0x08019E9C", + "0x0801A388": "0x08019EFC", + "0x0801A3D0": "0x08019F44", + "0x0801A500": "0x0801A090", "0x0801A508": "0x0801A098", "0x0801A558": "0x0801A0E8", "0x0801A5A8": "0x0801A138", "0x0801A628": "0x0801A1B8", "0x0801A62C": "0x0801A1BC", + "0x0801A638": "0x0801A1C8", "0x0801A650": "0x0801A1FC", "0x0801A664": "0x0801A210", + "0x0801A6D4": "0x0801A280", + "0x0801A70C": "0x0801A2B8", + "0x0801A764": "0x0801A310", "0x0801A7AC": "0x0801A37C", "0x0801A9BC": "0x0801A58C", "0x0801AA34": "0x0801A604", @@ -312,27 +402,88 @@ "0x0801ABE8": "0x0801A7B8", "0x0801AC24": "0x0801A7F4", "0x0801AC78": "0x0801A848", + "0x0801ACB8": "0x0801A888", "0x0801B264": "0x0801AE34", + "0x0801B58C": "0x0801B15C", "0x0801B6F4": "0x0801B2D4", "0x0801B720": "0x0801B300", + "0x0801B74C": "0x0801B32C", + "0x0801B8A8": "0x0801B488", + "0x0801BA74": "0x0801B660", + "0x0801C8F0": "0x0801C52C", + "0x0801CC10": "0x0801C868", + "0x0801CCC8": "0x0801C920", + "0x0801D028": "0x0801CC9C", + "0x0801D34C": "0x0801CFE0", + "0x0801D7AC": "0x0801D4A0", + "0x0801DB94": "0x0801D888", + "0x0801DD9C": "0x0801DA8C", + "0x0801DDB8": "0x0801DAA8", + "0x0801DDD4": "0x0801DAC4", + "0x0801DDF0": "0x0801DAE0", + "0x0801DE18": "0x0801DB08", + "0x0801DE3C": "0x0801DB2C", + "0x0801DE60": "0x0801DB50", + "0x0801DE78": "0x0801DB68", + "0x0801DE98": "0x0801DB88", + "0x0801DEB8": "0x0801DBA8", + "0x0801DF08": "0x0801DBFC", + "0x0801DF4C": "0x0801DC40", "0x0801DF80": "0x0801DC78", + "0x0801DF8C": "0x0801DC84", "0x0801DFE8": "0x0801DCE0", + "0x0801E024": "0x0801DD1C", + "0x0801E0A0": "0x0801DD98", "0x0801E0AC": "0x0801DDA4", "0x0801E0BC": "0x0801DDB4", "0x0801E0D0": "0x0801DDC8", "0x0801E104": "0x0801DDFC", "0x0801E12C": "0x0801DE24", + "0x0801E164": "0x0801DE5C", + "0x0801E1A4": "0x0801DE9C", + "0x0801E1D8": "0x0801DED0", "0x0801E20C": "0x0801DF04", "0x0801E244": "0x0801DF3C", + "0x0801E278": "0x0801DF70", "0x0801E2CC": "0x0801DFC4", + "0x0801E324": "0x0801E01C", "0x0801E378": "0x0801E070", "0x0801E3D8": "0x0801E0D0", "0x0801E438": "0x0801E130", + "0x0801E46C": "0x0801E164", + "0x0801E4B0": "0x0801E1B0", + "0x0801E4CC": "0x0801E1CC", "0x0801E538": "0x0801E238", + "0x0801E550": "0x0801E250", "0x0801E594": "0x0801E294", + "0x0801E5B0": "0x0801E2B0", + "0x0801E988": "0x0801E694", + "0x0801ED8C": "0x0801EAA4", + "0x0801EF14": "0x0801EC2C", + "0x0801F024": "0x0801ED40", + "0x0801F1C4": "0x0801EEF4", "0x0801F2CC": "0x0801EFFC", + "0x0801F320": "0x0801F050", + "0x0801F374": "0x0801F0A4", + "0x0801F79C": "0x0801F4D4", + "0x0801F99C": "0x0801F6DC", + "0x0801FB14": "0x0801F868", + "0x0801FC34": "0x0801F9A4", + "0x0801FD64": "0x0801FAF0", + "0x0801FDD0": "0x0801FB5C", + "0x08020680": "0x080204B4", "0x08020D40": "0x08020B8C", + "0x08020E08": "0x08020C54", + "0x08020F74": "0x08020DC0", + "0x080210A8": "0x08020EF4", + "0x08021214": "0x08021060", + "0x0802133C": "0x08021188", + "0x08021490": "0x080212DC", "0x080215E4": "0x08021430", + "0x080216BC": "0x08021508", + "0x080217D8": "0x08021624", + "0x08021960": "0x080217A8", + "0x08021AD8": "0x0802191C", "0x08021C6C": "0x08021AB0", "0x08021C70": "0x08021AB4", "0x08021C74": "0x08021AB8", @@ -345,6 +496,7 @@ "0x08021EC8": "0x08021D0C", "0x08021F58": "0x08021D9C", "0x08021FE0": "0x08021E24", + "0x08022028": "0x08021E6C", "0x08022078": "0x08021EBC", "0x08022100": "0x08021F44", "0x08022180": "0x08021FC4", @@ -357,28 +509,64 @@ "0x08022504": "0x08022348", "0x0802258C": "0x080223D0", "0x08022630": "0x08022474", + "0x080226A4": "0x080224E8", "0x08022E60": "0x08022CA4", "0x08023274": "0x080230B8", "0x08023684": "0x080234C8", "0x080239E0": "0x08023824", + "0x08023A3C": "0x08023880", "0x08023ED8": "0x08023D1C", "0x08023F98": "0x08023DDC", + "0x0802413C": "0x08023F80", + "0x08024538": "0x0802437C", + "0x080245CC": "0x08024410", "0x080257D4": "0x08025618", + "0x08025890": "0x080256D4", "0x08026338": "0x0802617C", + "0x080263B4": "0x080261F8", "0x080267DC": "0x08026620", + "0x08026858": "0x0802669C", "0x08026C54": "0x08026A98", "0x08026CD0": "0x08026B14", + "0x0802704C": "0x08026E90", + "0x080277E0": "0x0802762C", + "0x08027B50": "0x0802799C", + "0x08027C1C": "0x08027A68", "0x08028368": "0x08028224", "0x080283C4": "0x08028280", "0x08028498": "0x08028354", + "0x080284F4": "0x080283B0", + "0x08028830": "0x080286EC", "0x08028918": "0x080287D4", "0x080289C0": "0x0802887C", + "0x08028AAC": "0x08028968", + "0x08028D98": "0x08028C54", + "0x080290E4": "0x08028FA0", + "0x08029174": "0x08029030", + "0x0802926C": "0x08029128", + "0x0802939C": "0x08029258", + "0x0802949C": "0x08029358", + "0x08029788": "0x08029644", + "0x0802996C": "0x08029828", + "0x08029A7C": "0x08029938", + "0x08029B98": "0x08029A54", + "0x08029CEC": "0x08029BAC", + "0x08029E0C": "0x08029CCC", + "0x08029F54": "0x08029E10", + "0x0802A01C": "0x08029ED8", + "0x0802A080": "0x08029F3C", "0x0802A104": "0x08029FC0", "0x0802A19C": "0x0802A058", "0x0802A228": "0x0802A0E4", "0x0802A590": "0x0802A44C", + "0x0802A644": "0x0802A500", + "0x0802A7DC": "0x0802A6C0", + "0x0802A9B0": "0x0802A894", "0x0802AA28": "0x0802A928", + "0x0802B8A4": "0x0802B7A4", + "0x0802C144": "0x0802C044", "0x0802C2A0": "0x0802C1A0", + "0x0802C674": "0x0802C574", "0x0802CF84": "0x0802CE84", "0x0802D050": "0x0802CF50", "0x0802D200": "0x0802D100", @@ -393,55 +581,208 @@ "0x0802E444": "0x0802E344", "0x0802E6E0": "0x0802E5E0", "0x0802E7AC": "0x0802E6AC", + "0x0802EA50": "0x0802E950", + "0x0802F208": "0x0802F108", "0x0802F424": "0x0802F324", "0x0802F4B0": "0x0802F3B0", + "0x0802F578": "0x0802F478", + "0x0802FA80": "0x0802F980", + "0x0802FEA0": "0x0802FDA0", + "0x08030480": "0x08030380", + "0x080308B4": "0x080307B4", + "0x08030B28": "0x08030A28", + "0x08030F54": "0x08030E54", + "0x0803145C": "0x0803135C", + "0x08031580": "0x08031480", + "0x080316A4": "0x080315A4", + "0x0803188C": "0x0803178C", + "0x080319F0": "0x080318F0", + "0x08031B54": "0x08031A54", + "0x08031CB8": "0x08031BB8", + "0x08031D88": "0x08031C88", + "0x08031E58": "0x08031D58", + "0x08031F28": "0x08031E28", + "0x08031FF8": "0x08031EF8", "0x08032598": "0x08032498", + "0x0803294C": "0x0803284C", + "0x08032DE4": "0x08032CE4", + "0x08033198": "0x08033098", + "0x08033520": "0x08033420", + "0x08033650": "0x08033550", + "0x08033B3C": "0x08033A3C", + "0x08033C40": "0x08033B40", "0x08034488": "0x08034388", + "0x08034900": "0x08034800", + "0x08034A5C": "0x0803495C", + "0x08034F64": "0x08034E64", + "0x0803540C": "0x0803530C", "0x08035914": "0x08035814", "0x080359E8": "0x080358E8", "0x08035A88": "0x08035988", + "0x08035B18": "0x08035A18", + "0x080368F4": "0x080367F4", + "0x080376CC": "0x080375CC", + "0x08037B04": "0x08037A00", + "0x08037DFC": "0x08037CF8", + "0x080384D4": "0x080383D4", + "0x0803898C": "0x0803888C", + "0x08038D18": "0x08038C18", + "0x080392B4": "0x080391B0", + "0x080399E4": "0x080398E0", + "0x08039F00": "0x08039DFC", + "0x0803A460": "0x0803A35C", + "0x0803A8F0": "0x0803A7EC", + "0x0803AD74": "0x0803AC70", + "0x0803AE6C": "0x0803AD68", + "0x0803B194": "0x0803B090", "0x0803B69C": "0x0803B598", + "0x0803B720": "0x0803B61C", + "0x0803BC3C": "0x0803BB38", + "0x0803C008": "0x0803BF00", + "0x0803C3C8": "0x0803C2C0", + "0x0803C4C0": "0x0803C3B8", + "0x0803C698": "0x0803C590", + "0x0803CC50": "0x0803CB48", + "0x0803D1F8": "0x0803D0F0", + "0x0803D36C": "0x0803D264", + "0x0803D454": "0x0803D34C", + "0x0803D99C": "0x0803D894", + "0x0803DE84": "0x0803DD7C", + "0x0803E510": "0x0803E40C", "0x0803E5D8": "0x0803E4D4", + "0x0803E638": "0x0803E534", + "0x0803EE88": "0x0803ED84", + "0x0803F18C": "0x0803F088", "0x0803F210": "0x0803F10C", "0x0803F348": "0x0803F244", + "0x0803F454": "0x0803F350", "0x0803FE34": "0x0803FD30", + "0x080400D4": "0x0803FFD0", + "0x080402F4": "0x080401F0", + "0x08040530": "0x0804042C", + "0x0804076C": "0x08040668", + "0x08041030": "0x08040F2C", + "0x08041B7C": "0x08041A78", + "0x08041E8C": "0x08041D88", + "0x080420C8": "0x08041FC4", + "0x08042390": "0x0804228C", + "0x080425CC": "0x080424C8", + "0x08042938": "0x08042834", + "0x08042BB0": "0x08042AAC", + "0x080435C4": "0x080434C0", + "0x08043664": "0x08043560", + "0x08043850": "0x0804374C", + "0x08043A4C": "0x08043948", + "0x08043B20": "0x08043A1C", + "0x08043BF4": "0x08043AF0", + "0x08043CC8": "0x08043BC4", + "0x08043D9C": "0x08043C98", + "0x08043E70": "0x08043D6C", + "0x08043F44": "0x08043E40", + "0x08044018": "0x08043F14", + "0x080440EC": "0x08043FE8", + "0x080441C0": "0x080440BC", + "0x08044318": "0x08044214", + "0x080443EC": "0x080442E8", "0x080444C0": "0x080443BC", + "0x080445E8": "0x080444E4", "0x08044D1C": "0x08044C18", "0x08044E34": "0x08044D30", + "0x08044EB4": "0x08044DB0", + "0x0804534C": "0x08045248", "0x080455F0": "0x080454EC", "0x08045660": "0x0804555C", "0x08045764": "0x08045660", "0x08045AFC": "0x080459F8", + "0x08045B68": "0x08045A64", "0x08045E38": "0x08045D34", + "0x08045F44": "0x08045E40", + "0x08046490": "0x0804638C", + "0x080469DC": "0x080468D8", + "0x08046F28": "0x08046E24", + "0x08047474": "0x08047370", + "0x0804778C": "0x08047684", + "0x08047970": "0x08047868", + "0x08047B2C": "0x08047A24", "0x080480E8": "0x08047FE4", + "0x0804819C": "0x08048098", + "0x08048570": "0x0804846C", + "0x08048A74": "0x08048974", + "0x08049DC4": "0x08049CD4", + "0x08049EBC": "0x08049DCC", + "0x0804A188": "0x0804A098", + "0x0804A478": "0x0804A38C", + "0x0804A89C": "0x0804A7B0", "0x0804AE48": "0x0804AD5C", "0x0804AF80": "0x0804AE94", "0x0804B054": "0x0804AF68", + "0x0804B100": "0x0804B014", + "0x0804B32C": "0x0804B230", + "0x0804B61C": "0x0804B520", "0x0804B8EC": "0x0804B7F0", "0x0804B984": "0x0804B888", + "0x0804BC38": "0x0804BB3C", + "0x0804BEF8": "0x0804BDFC", + "0x0804C150": "0x0804C054", "0x0804C408": "0x0804C30C", "0x0804C4E8": "0x0804C3EC", "0x0804C5A8": "0x0804C4AC", + "0x0804C67C": "0x0804C580", "0x0804C948": "0x0804C84C", + "0x0804CBBC": "0x0804CAC0", + "0x0804D020": "0x0804CF28", + "0x0804D330": "0x0804D238", "0x0804DA44": "0x0804D950", "0x0804DB48": "0x0804DA54", + "0x0804DDBC": "0x0804DCC8", + "0x0804E360": "0x0804E26C", + "0x0804E628": "0x0804E534", + "0x0804E7B8": "0x0804E6C4", + "0x0804EABC": "0x0804E9C8", "0x0804ED18": "0x0804EC30", "0x0804EE20": "0x0804ED38", + "0x0804EEA8": "0x0804EDC0", + "0x0804F128": "0x0804F040", "0x0804F390": "0x0804F2A8", "0x0804F998": "0x0804F8B0", "0x0804FA68": "0x0804F980", + "0x0804FB0C": "0x0804FA24", + "0x0804FC3C": "0x0804FB54", + "0x0804FF04": "0x0804FE1C", + "0x080502DC": "0x080501FC", "0x08050454": "0x08050374", "0x08050524": "0x08050444", + "0x080505C8": "0x080504E8", + "0x08050688": "0x080505AC", + "0x080509A8": "0x080508CC", + "0x08050E48": "0x08050D70", + "0x08051A78": "0x080519A0", + "0x08051BFC": "0x08051B24", + "0x08051CE4": "0x08051C10", "0x08051DF0": "0x08051D1C", + "0x08051E98": "0x08051DC4", "0x08052060": "0x08051F8C", "0x080523D8": "0x08052304", "0x0805247C": "0x080523A8", + "0x080526B4": "0x080525E0", + "0x080529E0": "0x0805290C", + "0x08052D0C": "0x08052C38", "0x08052FE8": "0x08052F14", "0x08053060": "0x08052F8C", "0x08053120": "0x0805304C", + "0x080531C4": "0x080530F0", + "0x08053510": "0x0805343C", + "0x080537DC": "0x08053708", + "0x08053A80": "0x080539AC", "0x08053B24": "0x08053A50", + "0x08053C5C": "0x08053B88", + "0x08053CF4": "0x08053C20", + "0x08053D98": "0x08053CC4", + "0x08053E3C": "0x08053D68", + "0x080542C4": "0x080541EC", "0x0805442C": "0x08054354", "0x08054514": "0x0805443C", + "0x080545A0": "0x080544C8", "0x08054644": "0x0805456C", "0x08054748": "0x08054670", "0x08054904": "0x0805482C", @@ -450,14 +791,22 @@ "0x08055174": "0x0805509C", "0x08055558": "0x08055480", "0x080557CC": "0x080556F4", + "0x080558D0": "0x080557F8", "0x08055974": "0x0805589C", "0x08055A60": "0x08055988", "0x08055BA4": "0x08055ACC", "0x08055C58": "0x08055B80", + "0x08055D1C": "0x08055C44", "0x08055E74": "0x08055D9C", "0x080560D0": "0x08055FF8", + "0x080563F0": "0x08056318", + "0x08056494": "0x080563BC", + "0x08056538": "0x08056460", + "0x0805664C": "0x08056574", + "0x080567D4": "0x080566FC", "0x08056CB4": "0x08056BDC", "0x08056D2C": "0x08056C54", + "0x08056D80": "0x08056CA8", "0x08056E24": "0x08056D4C", "0x08056E38": "0x08056D60", "0x08056E50": "0x08056D78", @@ -508,7 +857,12 @@ "0x08057780": "0x080576A8", "0x0805782C": "0x08057754", "0x080578BC": "0x080577E4", + "0x0805790C": "0x08057834", + "0x08057934": "0x0805785C", + "0x0805795C": "0x08057884", + "0x08057984": "0x080578AC", "0x080579AC": "0x080578D4", + "0x080579BC": "0x080578E4", "0x080579D8": "0x08057900", "0x08057A20": "0x08057948", "0x08057A5C": "0x08057984", @@ -529,15 +883,26 @@ "0x08057DD0": "0x08057CF8", "0x08057E74": "0x08057D9C", "0x08057F18": "0x08057E40", + "0x08057FBC": "0x08057EE4", "0x08058048": "0x08057F70", + "0x08058094": "0x08057FBC", "0x080580EC": "0x08058014", + "0x080580F8": "0x08058020", + "0x0805813C": "0x08058064", "0x0805817C": "0x080580A4", + "0x080581E4": "0x0805810C", + "0x08058240": "0x08058168", + "0x08058260": "0x08058188", + "0x08058280": "0x080581A8", "0x080582C0": "0x080581EC", "0x080582D4": "0x08058200", "0x08058318": "0x08058244", + "0x08058334": "0x08058260", "0x080583EC": "0x08058318", "0x08058404": "0x08058330", "0x08058420": "0x0805834C", + "0x08058444": "0x08058370", + "0x08058498": "0x080583C4", "0x080584FC": "0x08058428", "0x08058510": "0x0805843C", "0x08058524": "0x08058450", @@ -552,6 +917,7 @@ "0x08058688": "0x080585B4", "0x080586B4": "0x080585E0", "0x080586D0": "0x080585FC", + "0x080586EC": "0x08058618", "0x0805874C": "0x08058678", "0x08058758": "0x08058684", "0x08058768": "0x08058694", @@ -566,6 +932,7 @@ "0x08058818": "0x08058744", "0x08058824": "0x08058750", "0x08058830": "0x0805875C", + "0x08058844": "0x08058770", "0x08058878": "0x080587A8", "0x080588C0": "0x080587F0", "0x08058900": "0x08058830", @@ -576,18 +943,39 @@ "0x08058A18": "0x08058948", "0x08058A4C": "0x0805897C", "0x08058A80": "0x080589B0", + "0x08058AD0": "0x08058A00", "0x08058B08": "0x08058A38", "0x08058B74": "0x08058AA4", "0x08058C08": "0x08058B38", + "0x08058C74": "0x08058BA4", "0x08058C8C": "0x08058BBC", "0x08058CC4": "0x08058BF4", + "0x08058D4C": "0x08058C7C", "0x08058D8C": "0x08058CBC", "0x08058D98": "0x08058CC8", + "0x08058DB0": "0x08058CE0", + "0x08058E08": "0x08058D38", "0x08058E14": "0x08058D44", "0x08058E28": "0x08058D58", "0x08058E3C": "0x08058D6C", + "0x08058E54": "0x08058D84", + "0x08058EF8": "0x08058E28", + "0x08058F4C": "0x08058E7C", + "0x08059000": "0x08058F30", + "0x080590B4": "0x08058FE4", + "0x08059168": "0x08059098", "0x0805921C": "0x0805914C", + "0x08059250": "0x08059180", + "0x080592FC": "0x0805922C", "0x08059340": "0x08059270", + "0x08059374": "0x080592A4", + "0x08059418": "0x08059348", + "0x08059488": "0x080593B8", + "0x08059534": "0x08059464", + "0x080595E0": "0x08059510", + "0x0805968C": "0x080595BC", + "0x08059738": "0x08059668", + "0x080597E4": "0x08059714", "0x08059890": "0x080597C0", "0x0805990C": "0x0805983C", "0x08059954": "0x08059884", @@ -595,16 +983,28 @@ "0x080599B0": "0x080598E0", "0x080599C4": "0x080598F4", "0x080599D8": "0x08059908", + "0x08059A40": "0x08059970", "0x08059A94": "0x080599C4", + "0x08059AD0": "0x08059A00", + "0x08059B84": "0x08059AB4", + "0x08059C38": "0x08059B68", + "0x08059CEC": "0x08059C1C", + "0x08059DA0": "0x08059CD0", + "0x08059E54": "0x08059D84", + "0x08059F08": "0x08059E38", "0x08059FBC": "0x08059EEC", "0x0805A004": "0x08059F34", "0x0805A040": "0x08059F70", "0x0805A054": "0x08059F84", + "0x0805A088": "0x08059FB8", + "0x0805A0EC": "0x0805A01C", "0x0805A138": "0x0805A068", "0x0805A194": "0x0805A0C4", + "0x0805A1B4": "0x0805A0E4", "0x0805A258": "0x0805A188", "0x0805A2B8": "0x0805A1E8", "0x0805A2E4": "0x0805A214", + "0x0805A318": "0x0805A248", "0x0805A350": "0x0805A280", "0x0805A384": "0x0805A2B4", "0x0805A3B0": "0x0805A2E0", @@ -633,31 +1033,70 @@ "0x0805A71C": "0x0805A64C", "0x0805A780": "0x0805A6B0", "0x0805A7C4": "0x0805A6F4", + "0x0805A874": "0x0805A7A4", "0x0805A8F8": "0x0805A828", + "0x0805A960": "0x0805A890", + "0x0805A994": "0x0805A8C4", "0x0805A9F4": "0x0805A924", "0x0805AA68": "0x0805A998", "0x0805AAB8": "0x0805A9E8", + "0x0805AB20": "0x0805AA50", + "0x0805AC08": "0x0805AB38", + "0x0805AD18": "0x0805AC48", + "0x0805AD78": "0x0805ACAC", + "0x0805AE34": "0x0805AD6C", + "0x0805AE94": "0x0805ADD4", + "0x0805B068": "0x0805AFC8", + "0x0805B0F0": "0x0805B04C", "0x0805B140": "0x0805B09C", "0x0805B21C": "0x0805B178", "0x0805B2C4": "0x0805B220", "0x0805B4CC": "0x0805B428", "0x0805B618": "0x0805B574", + "0x0805B688": "0x0805B5E4", + "0x0805BD5C": "0x0805BCC8", + "0x0805C208": "0x0805C190", "0x0805C4FC": "0x0805C4B0", + "0x0805C620": "0x0805C5D4", + "0x0805C7B8": "0x0805C768", "0x0805CB04": "0x0805CAC0", "0x0805CB8C": "0x0805CB48", "0x0805CDF8": "0x0805CDB4", + "0x0805CFA0": "0x0805CF5C", + "0x0805CFCC": "0x0805CF88", + "0x0805CFF8": "0x0805CFB4", + "0x0805D028": "0x0805CFE4", + "0x0805D064": "0x0805D020", + "0x0805D094": "0x0805D050", + "0x0805D0E8": "0x0805D0A4", + "0x0805D13C": "0x0805D0F8", + "0x0805D190": "0x0805D14C", + "0x0805D1E0": "0x0805D19C", + "0x0805D210": "0x0805D1CC", + "0x0805D278": "0x0805D238", + "0x0805D2E0": "0x0805D2A4", + "0x0805D348": "0x0805D310", "0x0805D37C": "0x0805D344", + "0x0805D3D4": "0x0805D39C", + "0x0805D404": "0x0805D3CC", "0x0805D434": "0x0805D3FC", "0x0805D460": "0x0805D428", "0x0805D498": "0x0805D460", "0x0805D4C4": "0x0805D48C", "0x0805D4F4": "0x0805D4BC", "0x0805D518": "0x0805D4E0", + "0x0805D548": "0x0805D510", + "0x0805D580": "0x0805D548", + "0x0805D5A0": "0x0805D568", + "0x0805D5F4": "0x0805D5BC", + "0x0805D650": "0x0805D618", "0x0805D6B8": "0x0805D680", "0x0805D720": "0x0805D6E8", "0x0805D854": "0x0805D81C", "0x0805DC1C": "0x0805DBE4", "0x0805DE98": "0x0805DE60", + "0x0805DF38": "0x0805DF00", + "0x0805E0C4": "0x0805E1DC", "0x0805EE6C": "0x0805F084", "0x0805EEDC": "0x0805F0F4", "0x0805EEEC": "0x0805F104", @@ -667,16 +1106,35 @@ "0x0805EF84": "0x0805F19C", "0x0805EF90": "0x0805F1A8", "0x0805EFBC": "0x0805F1D4", + "0x0805F020": "0x0805F238", + "0x0805F07C": "0x0805F28C", + "0x0805F0C4": "0x0805F2C8", "0x0805F0F0": "0x0805F2F4", "0x0805F134": "0x0805F338", "0x0805F158": "0x0805F35C", "0x0805F184": "0x0805F388", + "0x0805F1B0": "0x0805F3B4", "0x0805FAC0": "0x0805FA98", "0x0805FB7C": "0x0805FB54", "0x0805FC0C": "0x0805FBE4", + "0x0805FC80": "0x0805FC58", + "0x0805FFBC": "0x0805FFC0", + "0x080605D0": "0x08060658", + "0x08060DB0": "0x08060E38", + "0x08060E44": "0x08060ECC", + "0x08061688": "0x08061710", "0x0806171C": "0x080617A4", + "0x08061830": "0x080618B8", "0x08061910": "0x08061998", "0x08061B88": "0x08061C10", + "0x08061E44": "0x08061ECC", + "0x080624D8": "0x08062564", + "0x0806335C": "0x080631C0", + "0x080634D8": "0x0806333C", + "0x080636B0": "0x08063514", + "0x08063B80": "0x080639E4", + "0x08063E30": "0x08063C94", + "0x0806441C": "0x08064280", "0x08064E14": "0x08064C7C", "0x0806514C": "0x08064FB4", "0x08065158": "0x08064FC0", @@ -693,6 +1151,7 @@ "0x080653FC": "0x08065264", "0x08065424": "0x0806528C", "0x08065504": "0x0806536C", + "0x080655CC": "0x08065434", "0x08065654": "0x080654BC", "0x0806569C": "0x08065504", "0x080656B8": "0x08065520", @@ -703,19 +1162,29 @@ "0x080658A0": "0x08065708", "0x080658CC": "0x08065734", "0x08065918": "0x08065780", + "0x08065974": "0x080657DC", "0x080659B0": "0x08065818", "0x080659BC": "0x08065824", "0x080659F4": "0x0806585C", + "0x08065A1C": "0x08065884", "0x08065A90": "0x080658F8", "0x08065AE8": "0x08065950", + "0x08065AFC": "0x08065964", "0x08065B58": "0x080659C0", "0x08065B84": "0x080659EC", + "0x08065BD0": "0x08065A38", "0x08065C50": "0x08065AB8", "0x08065CA8": "0x08065B10", + "0x08065D50": "0x08065BB8", + "0x08065DAC": "0x08065C0C", "0x08065E38": "0x08065C98", "0x08065F08": "0x08065D68", + "0x08065FE8": "0x08065E48", "0x0806603C": "0x08065E9C", "0x080660EC": "0x08065F4C", + "0x0806617C": "0x08065FDC", + "0x08066220": "0x08066080", + "0x080662C4": "0x08066124", "0x08066404": "0x08066200", "0x08066490": "0x0806628C", "0x08066520": "0x0806631C", @@ -723,6 +1192,7 @@ "0x08066624": "0x08066420", "0x08066720": "0x0806651C", "0x08066898": "0x08066694", + "0x0806690C": "0x08066708", "0x08067A68": "0x08067844", "0x08067AC0": "0x0806789C", "0x08067AC4": "0x080678A0", @@ -741,12 +1211,17 @@ "0x08067AF8": "0x080678D4", "0x08067AFC": "0x080678D8", "0x08067B4C": "0x08067928", + "0x08067B50": "0x0806792C", "0x08067B9C": "0x08067978", "0x08067BF8": "0x080679D4", "0x08067C08": "0x080679E4", "0x08067C18": "0x080679F4", + "0x08067C28": "0x08067A04", "0x08067C68": "0x08067A44", "0x08067CA8": "0x08067A84", + "0x08067CE8": "0x08067AC4", + "0x08067D28": "0x08067B04", + "0x08067D74": "0x08067B50", "0x08067DC8": "0x08067BA4", "0x08067E08": "0x08067BE4", "0x08067E48": "0x08067C24", @@ -756,6 +1231,13 @@ "0x08067F4C": "0x08067D84", "0x08067F94": "0x08067DCC", "0x08067FE0": "0x08067E18", + "0x08068030": "0x08067E68", + "0x08068070": "0x08067EA8", + "0x080680B4": "0x08067EEC", + "0x080680F8": "0x08067F30", + "0x08068144": "0x08067F7C", + "0x0806818C": "0x08067FC4", + "0x080681F4": "0x0806802C", "0x0806823C": "0x08068074", "0x080682A4": "0x080680DC", "0x080682B8": "0x080680F0", @@ -763,10 +1245,13 @@ "0x08068384": "0x080681BC", "0x080683CC": "0x08068204", "0x080683DC": "0x08068214", + "0x08068450": "0x08068288", "0x08068490": "0x080682C8", "0x0806849C": "0x080682D4", + "0x080684A8": "0x080682E0", "0x080684E8": "0x08068320", "0x080684F4": "0x0806832C", + "0x08068500": "0x08068338", "0x08068540": "0x08068378", "0x0806854C": "0x08068384", "0x08068558": "0x08068390", @@ -774,8 +1259,12 @@ "0x080685F0": "0x08068428", "0x08068600": "0x08068438", "0x08068670": "0x080684A8", + "0x080686A4": "0x080684DC", "0x080686F4": "0x0806852C", + "0x08068758": "0x08068590", + "0x080687A8": "0x080685E0", "0x080687E8": "0x08068620", + "0x08068820": "0x08068658", "0x08068868": "0x080686A0", "0x0806886C": "0x080686A4", "0x08068870": "0x080686A8", @@ -784,28 +1273,106 @@ "0x08068894": "0x080686CC", "0x080688F4": "0x0806872C", "0x080688F8": "0x08068730", + "0x0806898C": "0x080687C4", + "0x08068A00": "0x08068838", + "0x08068F9C": "0x08068D84", + "0x08069080": "0x08068E68", "0x08069224": "0x0806900C", + "0x08069388": "0x08069170", + "0x080694AC": "0x08069290", + "0x080698D4": "0x080696B4", "0x08069A30": "0x08069810", "0x08069AEC": "0x080698CC", "0x08069BBC": "0x0806999C", + "0x08069C44": "0x08069A24", + "0x0806A19C": "0x08069F84", + "0x0806A88C": "0x0806A674", + "0x0806ABC0": "0x0806A9A8", + "0x0806B3C4": "0x0806B1AC", + "0x0806BE24": "0x0806BC0C", + "0x0806C568": "0x0806C350", + "0x0806CDF0": "0x0806CBD4", + "0x0806D4A4": "0x0806D294", + "0x0806D7EC": "0x0806D5DC", + "0x0806DB1C": "0x0806D90C", + "0x0806DE94": "0x0806DC84", + "0x0806E7D4": "0x0806E5C0", + "0x0806F0CC": "0x0806EEB0", + "0x0806FE1C": "0x0806FBFC", + "0x0806FF1C": "0x0806FCFC", + "0x080710DC": "0x08070EC8", + "0x08072390": "0x08072188", + "0x08072D5C": "0x08072B54", + "0x0807356C": "0x080733A0", + "0x0807386C": "0x080736A0", + "0x08073CF4": "0x08073B28", "0x08073E2C": "0x08073C60", + "0x08073EE8": "0x08073D1C", + "0x0807414C": "0x08073F78", + "0x08074398": "0x080741C0", + "0x08074530": "0x08074354", + "0x080746A4": "0x080744C8", + "0x08074818": "0x0807463C", + "0x0807498C": "0x080747B0", + "0x08074B00": "0x08074924", + "0x08074C74": "0x08074A98", "0x08074DE8": "0x08074C0C", + "0x08075088": "0x08074EAC", "0x08075494": "0x080752B8", + "0x08075520": "0x08075344", "0x080756EC": "0x08075510", + "0x08075778": "0x0807559C", "0x080760E8": "0x08075F1C", + "0x080761A4": "0x08075FD8", + "0x08076A88": "0x08076908", + "0x08076BA0": "0x08076A20", "0x08077444": "0x0807730C", + "0x08077508": "0x080773D0", + "0x08077D04": "0x08077BDC", + "0x08077DAC": "0x08077C84", + "0x0807854C": "0x08078428", + "0x080785F4": "0x080784D0", + "0x08078B24": "0x08078A00", + "0x08078BCC": "0x08078AA8", "0x080793BC": "0x080792A0", + "0x08079458": "0x0807933C", "0x08079888": "0x0807976C", + "0x08079948": "0x0807982C", "0x08079CC4": "0x08079BAC", + "0x08079D84": "0x08079C6C", "0x08079ED0": "0x08079DB8", + "0x08079FD0": "0x08079EB8", "0x0807A028": "0x08079F10", "0x0807A040": "0x08079F28", "0x0807A064": "0x08079F4C", + "0x0807A0E0": "0x08079FC8", "0x0807A120": "0x0807A008", + "0x0807A124": "0x0807A00C", + "0x0807A20C": "0x0807A0F4", + "0x0807A2E0": "0x0807A1C8", + "0x0807A378": "0x0807A25C", + "0x0807A4B4": "0x0807A39C", "0x0807A544": "0x0807A430", + "0x0807A56C": "0x0807A458", + "0x0807A5D4": "0x0807A4C0", + "0x0807B7B4": "0x0807B5FC", + "0x0807BD78": "0x0807BB20", + "0x0807BEA0": "0x0807BC48", + "0x0807C014": "0x0807BDBC", "0x0807C114": "0x0807BEBC", "0x0807C1D8": "0x0807BF80", + "0x0807C29C": "0x0807C044", + "0x08080A78": "0x08080828", + "0x080811E0": "0x08080F90", + "0x08081518": "0x080812D8", + "0x080850C0": "0x080813D8", + "0x080815F4": "0x08081498", + "0x08082960": "0x08082214", + "0x08082BB0": "0x08082468", + "0x0808381C": "0x08082FC4", + "0x08083AE8": "0x080832C4", "0x08084200": "0x080839EC", + "0x0808441C": "0x08083C08", "0x08084EAC": "0x080846EC", "0x08084F24": "0x08084764", "0x08084F9C": "0x080847DC", @@ -820,6 +1387,7 @@ "0x08085330": "0x08084AC4", "0x0808536C": "0x08084B00", "0x08085398": "0x08084B2C", + "0x080853DC": "0x08084B70", "0x0808543C": "0x08084BD0", "0x08085484": "0x08084C18", "0x080854A0": "0x08084C34", @@ -827,10 +1395,13 @@ "0x080854E8": "0x08084C7C", "0x08085518": "0x08084CAC", "0x08085534": "0x08084CC8", + "0x080855D4": "0x08084D68", "0x080867E0": "0x08085FDC", "0x080867F8": "0x08085FF4", + "0x08086860": "0x0808605C", "0x08087788": "0x08086F84", "0x080878AC": "0x080870A8", + "0x08087A5C": "0x08087258", "0x08087CC0": "0x08087538", "0x080887D4": "0x0808804C", "0x08088914": "0x0808818C", @@ -841,53 +1412,106 @@ "0x08088A60": "0x080882D8", "0x08088AA8": "0x08088320", "0x08088B24": "0x0808839C", + "0x08088B6C": "0x080883E4", + "0x08088C24": "0x0808849C", + "0x08088F30": "0x080887A8", + "0x08089204": "0x08088A7C", + "0x08089384": "0x08088BFC", + "0x08089500": "0x08088D7C", + "0x08089784": "0x08089004", + "0x080898D4": "0x08089150", + "0x08089AE4": "0x08089360", + "0x08089CA0": "0x0808951C", + "0x08089EC4": "0x08089740", + "0x0808A008": "0x08089880", + "0x0808A294": "0x08089B0C", + "0x0808A380": "0x08089BF4", + "0x0808A4D4": "0x08089D44", + "0x0808A744": "0x08089FB4", + "0x0808A830": "0x0808A09C", + "0x0808A984": "0x0808A1EC", + "0x0808AA70": "0x0808A2D4", + "0x0808AC08": "0x0808A46C", + "0x0808AD90": "0x0808A5F4", + "0x0808AFA4": "0x0808A804", + "0x0808AFE8": "0x0808A848", + "0x0808B978": "0x0808B1E8", + "0x0808C020": "0x0808B82C", + "0x0808C0C4": "0x0808B8D0", + "0x0808CB58": "0x0808C2F0", "0x0808D05C": "0x0808C794", "0x0808D0B0": "0x0808C7E8", + "0x0808D0C4": "0x0808C7FC", "0x0808D118": "0x0808C850", "0x0808D11C": "0x0808C854", "0x0808D190": "0x0808C8C8", "0x0808D204": "0x0808C93C", + "0x0808D278": "0x0808C9B0", "0x0808D31C": "0x0808CA54", "0x0808D390": "0x0808CAC8", + "0x0808D404": "0x0808CB3C", "0x0808D4A8": "0x0808CBE0", "0x0808D4AC": "0x0808CBE4", "0x0808D520": "0x0808CC58", + "0x0808D594": "0x0808CCCC", + "0x0808D654": "0x0808CD8C", + "0x0808D9AC": "0x0808D0F0", + "0x0808DA20": "0x0808D164", + "0x0808DA94": "0x0808D1D8", + "0x0808DB38": "0x0808D27C", "0x0808DE08": "0x0808D54C", "0x0808DE94": "0x0808D5D8", "0x0808DF14": "0x0808D658", "0x0808E000": "0x0808D744", + "0x0808E090": "0x0808D7D4", "0x0808E130": "0x0808D874", "0x0808E184": "0x0808D8C8", "0x0808E1F8": "0x0808D93C", "0x0808E26C": "0x0808D9B0", + "0x0808E2FC": "0x0808DA40", "0x0808E3A0": "0x0808DAE4", "0x0808E414": "0x0808DB58", + "0x0808E488": "0x0808DBCC", + "0x0808E530": "0x0808DC74", "0x0808E66C": "0x0808DDB0", "0x0808E774": "0x0808DEB8", "0x0808E7FC": "0x0808DF40", + "0x0808E88C": "0x0808DFD0", "0x0808E94C": "0x0808E090", "0x0808E970": "0x0808E0B4", "0x0808E9B8": "0x0808E0FC", "0x0808E9FC": "0x0808E140", "0x0808EAD8": "0x0808E21C", "0x0808EB68": "0x0808E2AC", + "0x0808EBF4": "0x0808E338", "0x0808ECA0": "0x0808E3E4", "0x0808ECD0": "0x0808E414", "0x0808ECFC": "0x0808E440", "0x0808ED7C": "0x0808E4C0", "0x0808EDF0": "0x0808E534", + "0x0808EE98": "0x0808E5DC", + "0x0808EF54": "0x0808E698", + "0x0808EFEC": "0x0808E730", + "0x0808F088": "0x0808E7CC", "0x0808F15C": "0x0808E8A0", + "0x0808F1E4": "0x0808E928", "0x0808F6A8": "0x0808EDF4", + "0x0808F700": "0x0808EE4C", + "0x0808F9E0": "0x0808F130", "0x0808FB5C": "0x0808F2AC", "0x0808FBDC": "0x0808F32C", + "0x0808FC50": "0x0808F3A0", "0x0808FD88": "0x0808F4D8", + "0x0808FE04": "0x0808F554", "0x0808FEB8": "0x0808F608", "0x0808FF28": "0x0808F678", "0x0808FF98": "0x0808F6E8", "0x08090008": "0x0808F758", "0x0809007C": "0x0808F7CC", + "0x0809011C": "0x0808F86C", "0x080901A8": "0x0808F8F8", "0x0809021C": "0x0808F96C", + "0x08090290": "0x0808F9E0", "0x08090330": "0x0808FA80", "0x080903C4": "0x0808FB14", "0x08090434": "0x0808FB84", @@ -895,7 +1519,18 @@ "0x0809044C": "0x0808FB9C", "0x08090470": "0x0808FBC0", "0x08090494": "0x0808FBE4", + "0x080904A4": "0x0808FBF4", + "0x08090B84": "0x0809031C", + "0x08090E38": "0x080905D0", + "0x080910A8": "0x08090840", + "0x080912CC": "0x08090A64", + "0x080914F0": "0x08090C88", + "0x08091714": "0x08090EAC", + "0x08091938": "0x080910D0", + "0x08091B5C": "0x080912F4", + "0x08091CF8": "0x08091490", "0x08091E94": "0x0809162C", + "0x08091F9C": "0x080916B8", "0x08092080": "0x08091738", "0x08092094": "0x0809174C", "0x080920A0": "0x08091758", @@ -961,8 +1596,16 @@ "0x08095B04": "0x080951BC", "0x08095D1C": "0x080953D4", "0x08095E70": "0x08095528", + "0x08095F10": "0x080955C8", "0x08095FC8": "0x08095680", "0x08096060": "0x08095718", + "0x08096154": "0x0809580C", + "0x08096274": "0x0809592C", + "0x08096394": "0x08095A4C", + "0x08096494": "0x08095B4C", + "0x08096594": "0x08095C4C", + "0x08096640": "0x08095CF8", + "0x080967D0": "0x08095E88", "0x0809689C": "0x08095F54", "0x080968C0": "0x08095F78", "0x080969CC": "0x08096084", @@ -981,11 +1624,14 @@ "0x08097A38": "0x080970F0", "0x08097A4C": "0x08097104", "0x08097A60": "0x08097118", + "0x08097A74": "0x0809712C", "0x08097AC0": "0x08097178", "0x08097B24": "0x080971DC", "0x08097B6C": "0x08097224", "0x08097BA4": "0x0809725C", "0x08097C4C": "0x08097304", + "0x08097C6C": "0x08097324", + "0x08097CA8": "0x08097360", "0x08097D0C": "0x080973C4", "0x08097D18": "0x080973D0", "0x08097D24": "0x080973DC", @@ -1009,13 +1655,28 @@ "0x08098060": "0x08097718", "0x08098088": "0x08097740", "0x080980F0": "0x080977A8", + "0x08098108": "0x080977C0", + "0x08098F2C": "0x0809861C", + "0x0809919C": "0x0809888C", + "0x08099468": "0x08098B58", + "0x08099720": "0x08098E10", "0x0809975C": "0x08098E4C", "0x08099788": "0x08098E78", "0x080997C0": "0x08098EB0", + "0x08099838": "0x08098F28", + "0x0809A5E0": "0x08099D18", + "0x0809A834": "0x08099F6C", "0x0809ADE8": "0x0809A524", "0x0809AE24": "0x0809A560", "0x0809AE50": "0x0809A58C", "0x0809AE88": "0x0809A5C4", + "0x0809AEE8": "0x0809A624", + "0x0809C1B4": "0x0809B93C", + "0x0809C4E8": "0x0809BC70", + "0x0809C8F4": "0x0809C07C", + "0x0809CC2C": "0x0809C3B4", + "0x0809D374": "0x0809CB10", + "0x0809D558": "0x0809CCF4", "0x0809D564": "0x0809CD00", "0x0809D574": "0x0809CD10", "0x0809D5B8": "0x0809CD54", @@ -1028,8 +1689,12 @@ "0x0809D7E4": "0x0809CF80", "0x0809D810": "0x0809CFAC", "0x0809D848": "0x0809CFE4", + "0x0809D878": "0x0809D014", + "0x0809E468": "0x0809DC5C", "0x0809EDFC": "0x0809E5F0", "0x0809EF84": "0x0809E778", + "0x0809F018": "0x0809E80C", + "0x0809F4A8": "0x0809EC9C", "0x0809F8C8": "0x0809F0BC", "0x0809F90C": "0x0809F100", "0x0809F918": "0x0809F10C", @@ -1041,6 +1706,10 @@ "0x0809FACC": "0x0809F2C0", "0x0809FAEC": "0x0809F2E0", "0x0809FB18": "0x0809F30C", + "0x0809FB6C": "0x0809F360", + "0x080A05B4": "0x0809FDDC", + "0x080A099C": "0x080A01C4", + "0x080A0B44": "0x080A036C", "0x080A0F64": "0x080A07A4", "0x080A0FA8": "0x080A07E8", "0x080A0FC4": "0x080A0804", @@ -1058,10 +1727,19 @@ "0x080A1170": "0x080A09B0", "0x080A118C": "0x080A09CC", "0x080A11B4": "0x080A09F4", + "0x080A1208": "0x080A0A48", + "0x080A1DA8": "0x080A1618", "0x080A1F88": "0x080A17F8", + "0x080A1FF4": "0x080A1864", + "0x080A230C": "0x080A1B80", "0x080A2698": "0x080A1F14", "0x080A26D0": "0x080A1F4C", "0x080A2720": "0x080A1F9C", + "0x080A27B8": "0x080A2034", + "0x080A35D0": "0x080A2E78", + "0x080A3D2C": "0x080A35EC", + "0x080A4520": "0x080A3E04", + "0x080A47A0": "0x080A4084", "0x080A49A8": "0x080A4298", "0x080A49EC": "0x080A42DC", "0x080A4A54": "0x080A4344", @@ -1079,8 +1757,17 @@ "0x080A4CDC": "0x080A45CC", "0x080A4CF0": "0x080A45E0", "0x080A4CFC": "0x080A45EC", + "0x080A4D08": "0x080A45F8", + "0x080A6258": "0x080A5BB0", + "0x080A6510": "0x080A5E68", + "0x080A66E0": "0x080A6038", + "0x080A68B0": "0x080A6208", + "0x080A6BE8": "0x080A6544", + "0x080A705C": "0x080A69BC", "0x080A74E8": "0x080A6E50", + "0x080A756C": "0x080A6ED4", "0x080A7DEC": "0x080A7754", + "0x080A7E38": "0x080A77A0", "0x080A7E68": "0x080A77D0", "0x080A7E94": "0x080A77FC", "0x080A7ECC": "0x080A7834", @@ -1094,39 +1781,71 @@ "0x080A80BC": "0x080A7A24", "0x080A80D8": "0x080A7A40", "0x080A8114": "0x080A7A7C", + "0x080A8164": "0x080A7ACC", + "0x080A8F90": "0x080A8924", + "0x080A9100": "0x080A8A94", + "0x080A92C0": "0x080A8C54", + "0x080A9680": "0x080A9014", "0x080A97E0": "0x080A9174", "0x080A9818": "0x080A91AC", "0x080A9844": "0x080A91D8", "0x080A987C": "0x080A9210", "0x080A98E0": "0x080A9274", "0x080A9910": "0x080A92A4", + "0x080A9950": "0x080A92E4", + "0x080AB054": "0x080AAA28", "0x080AB2D8": "0x080AACAC", + "0x080AB2F8": "0x080AACCC", + "0x080AC214": "0x080ABC1C", + "0x080AC2E8": "0x080ABCF0", + "0x080AC5B4": "0x080ABFBC", "0x080AC81C": "0x080AC224", + "0x080AC844": "0x080AC24C", + "0x080AD534": "0x080ACF20", + "0x080ADE30": "0x080AD820", "0x080AE080": "0x080ADA70", "0x080AE0B8": "0x080ADAA8", "0x080AE0E4": "0x080ADAD4", "0x080AE11C": "0x080ADB0C", "0x080AE184": "0x080ADB74", + "0x080AE1B4": "0x080ADBA4", + "0x080AE420": "0x080ADE10", "0x080AF2AC": "0x080AED68", "0x080AF2BC": "0x080AED78", "0x080AF304": "0x080AEDC0", "0x080AF350": "0x080AEE0C", "0x080AF3C4": "0x080AEE80", + "0x080AF3F4": "0x080AEEB0", + "0x080B0288": "0x080AFD58", "0x080B0F70": "0x080B0A58", "0x080B0F9C": "0x080B0A84", + "0x080B0FC4": "0x080B0AAC", + "0x080B1FD4": "0x080B1AE0", "0x080B2058": "0x080B1B64", + "0x080B2200": "0x080B1D0C", "0x080B22E8": "0x080B1DF4", "0x080B2330": "0x080B1E3C", "0x080B236C": "0x080B1E78", + "0x080B23C8": "0x080B1ED4", "0x080B23FC": "0x080B1F08", "0x080B2424": "0x080B1F30", "0x080B2454": "0x080B1F60", + "0x080B24B8": "0x080B1FC4", "0x080B2780": "0x080B228C", + "0x080B280C": "0x080B2318", + "0x080B3648": "0x080B30BC", + "0x080B44F0": "0x080B3F18", + "0x080B4690": "0x080B40B8", + "0x080B4A7C": "0x080B44A4", "0x080B4B48": "0x080B4570", "0x080B4B7C": "0x080B45A4", "0x080B4BB8": "0x080B45E0", + "0x080B4C34": "0x080B465C", + "0x080B5B90": "0x080B55F8", + "0x080B5E64": "0x080B58CC", "0x080B5F94": "0x080B5A04", "0x080B6068": "0x080B5AD8", + "0x080B60F4": "0x080B5B64", "0x080B6178": "0x080B5BE8", "0x080B6324": "0x080B5D94", "0x080B6360": "0x080B5DD0", @@ -1134,13 +1853,20 @@ "0x080B63BC": "0x080B5E2C", "0x080B640C": "0x080B5E7C", "0x080B6448": "0x080B5EB8", + "0x080B64A4": "0x080B5F14", + "0x080B64E8": "0x080B5F58", "0x080B6910": "0x080B6380", "0x080B6928": "0x080B6398", "0x080B6948": "0x080B63B8", + "0x080B6978": "0x080B63E8", "0x080B6990": "0x080B6400", + "0x080B6992": "0x080B6402", "0x080B69AC": "0x080B641C", + "0x080B69AE": "0x080B641E", "0x080B69B8": "0x080B6428", + "0x080B69D8": "0x080B6448", "0x080B69F4": "0x080B6464", + "0x080B6A08": "0x080B6478", "0x080B6A38": "0x080B64A8", "0x080B6A44": "0x080B64B4", "0x080B6A58": "0x080B64C8", @@ -1153,6 +1879,7 @@ "0x080B6AF8": "0x080B6568", "0x080B6B10": "0x080B6580", "0x080B6B24": "0x080B6594", + "0x080B6B3C": "0x080B65AC", "0x080B6DD0": "0x080B6840", "0x080B6DE0": "0x080B6850", "0x080B6E24": "0x080B6894", @@ -1240,7 +1967,8 @@ "0x080B8D18": "0x080B8788", "0x080B8E3C": "0x080B88AC", "0x080B8E60": "0x080B88D0", - "0x080B8E78": "0x080B88E8" + "0x080B8E78": "0x080B88E8", + "0x080B8F60": "0x080B89D0" }, "symbols": { "0x00000004": "0x00000004", @@ -1257,7 +1985,9 @@ "0x03000026": "0x03000026", "0x03000028": "0x03000028", "0x03000030": "0x03000030", + "0x03000060": "0x03000060", "0x03000124": "0x030001FC", + "0x03000128": "0x03000200", "0x03000168": "0x03000280", "0x0300016C": "0x03000284", "0x03000170": "0x03000288", @@ -1288,6 +2018,7 @@ "0x03000280": "0x03000398", "0x03000290": "0x030003A8", "0x03000298": "0x030003B0", + "0x0300029C": "0x030003B4", "0x030002A0": "0x030003B8", "0x030002B0": "0x030003C8", "0x030002B4": "0x030003CC", @@ -1298,6 +2029,8 @@ "0x030002BD": "0x030003D5", "0x030002C0": "0x030003D8", "0x030002C8": "0x030003E0", + "0x030002D0": "0x030003E8", + "0x030002D4": "0x030003EC", "0x030002D8": "0x030003F0", "0x030002DC": "0x030003F4", "0x030002E0": "0x030003F8", @@ -1317,6 +2050,7 @@ "0x0300031C": "0x03000434", "0x0300031E": "0x03000436", "0x03000320": "0x03000438", + "0x03000321": "0x03000439", "0x03000324": "0x0300043C", "0x03000328": "0x03000440", "0x0300032C": "0x03000444", @@ -1336,8 +2070,10 @@ "0x03000358": "0x03000470", "0x0300035C": "0x03000474", "0x03000360": "0x03000478", + "0x03000364": "0x0300047C", "0x03000368": "0x03000480", "0x03000370": "0x03000488", + "0x03000380": "0x03000498", "0x030003E8": "0x03000500", "0x030003EA": "0x03000502", "0x030003EC": "0x03000504", @@ -1351,6 +2087,8 @@ "0x030003FC": "0x03000514", "0x03000400": "0x03000518", "0x03000404": "0x0300051C", + "0x03000406": "0x0300051E", + "0x03000407": "0x0300051F", "0x03000408": "0x03000520", "0x0300040C": "0x03000524", "0x03000410": "0x03000528", @@ -1359,11 +2097,20 @@ "0x0300041C": "0x03000534", "0x03000420": "0x03000538", "0x03000424": "0x0300053C", + "0x03000428": "0x03000540", + "0x0300042C": "0x03000544", "0x03000430": "0x03000548", + "0x03000434": "0x0300054C", "0x03000438": "0x03000550", "0x03000440": "0x03000558", "0x03000448": "0x03000560", + "0x03000458": "0x03000570", + "0x03000490": "0x030005A8", + "0x030004B8": "0x030005D0", "0x030004BE": "0x030005D6", + "0x030004C0": "0x030005D8", + "0x030004C1": "0x030005D9", + "0x030004C4": "0x030005DC", "0x030004C8": "0x030005E0", "0x030004D0": "0x030005E8", "0x03000780": "0x03000898", @@ -1373,13 +2120,18 @@ "0x0300079C": "0x030008B4", "0x030007A0": "0x030008B8", "0x030007A4": "0x030008BC", + "0x030007A6": "0x030008BE", "0x030007A8": "0x030008C0", "0x030007AC": "0x030008C4", "0x030007B0": "0x030008C8", "0x030007B4": "0x030008CC", "0x030007B8": "0x030008D0", "0x030007BC": "0x030008D4", + "0x030007C0": "0x030008D8", "0x030007C8": "0x030008E0", + "0x030007CA": "0x030008E2", + "0x030007CB": "0x030008E3", + "0x030007CC": "0x030008E4", "0x030007D0": "0x030008E8", "0x030007D4": "0x030008EC", "0x030007D8": "0x030008F0", @@ -1453,10 +2205,13 @@ "0x030031EC": "0x0300330C", "0x030031EE": "0x0300330E", "0x030031F2": "0x03003312", + "0x030031FC": "0x0300331C", + "0x030031FE": "0x0300331E", "0x03003200": "0x03003320", "0x0300342C": "0x0300354C", "0x03003430": "0x03003550", "0x03003460": "0x03003580", + "0x03003470": "0x03003590", "0x03003474": "0x03003594", "0x03003478": "0x03003598", "0x03003480": "0x030035A0", @@ -1465,11 +2220,29 @@ "0x030034D8": "0x030035F8", "0x030034E0": "0x03003600", "0x030034F0": "0x03003610", + "0x03003590": "0x030036B0", "0x03003C10": "0x03003D30", "0x03003C40": "0x03003D60", + "0x03003CE0": "0x03003E00", + "0x03003CE2": "0x03003E02", + "0x03003D10": "0x03003E3C", + "0x03003D14": "0x03003E40", + "0x03003D18": "0x03003E44", + "0x03003D38": "0x03003E64", + "0x03003D6C": "0x03003E98", + "0x03003D70": "0x03003E9C", + "0x03003DC4": "0x03003EF0", + "0x03003E28": "0x03003F54", + "0x03003EBC": "0x03003FF4", + "0x03003F74": "0x030040AC", + "0x03004008": "0x0300414C", + "0x030040C0": "0x03004204", + "0x03004154": "0x030042A4", + "0x0300420C": "0x0300435C", "0x03004210": "0x03004360", "0x03004220": "0x03004370", "0x030042E8": "0x03004438", + "0x030046EC": "0x0300483C", "0x030056F0": "0x03005840", "0x030056F4": "0x03005844", "0x030056F8": "0x03005848", @@ -1480,8 +2253,10 @@ "0x03005740": "0x03005890", "0x03005C40": "0x03005D90", "0x03005C54": "0x03005DA4", + "0x03005C60": "0x03005DB0", "0x03005C94": "0x03005DE4", "0x03005C98": "0x03005DE8", + "0x03005CA0": "0x03005DF0", "0x03005CE0": "0x03005E30", "0x03005CE4": "0x03005E34", "0x03005CF0": "0x03005E40", @@ -1498,13 +2273,30 @@ "0x03005D6C": "0x03005EBC", "0x03005D70": "0x03005EC0", "0x03005D80": "0x03005ED0", + "0x03005DC0": "0x03005F10", + "0x03005DDC": "0x03005F2C", + "0x03005DF4": "0x03005F44", + "0x03005E28": "0x03005F78", + "0x03005E5C": "0x03005FAC", + "0x03005E90": "0x03005FE0", + "0x03005EC4": "0x03006014", + "0x03005EF8": "0x03006048", + "0x03005F2C": "0x0300607C", + "0x03005F60": "0x030060B0", + "0x03005F94": "0x030060E4", + "0x03005FC8": "0x03006118", "0x03006000": "0x03006150", "0x03006028": "0x03006178", "0x0300602C": "0x0300617C", "0x03006030": "0x03006180", "0x03006040": "0x03006190", + "0x03006074": "0x030061C4", + "0x030060A8": "0x030061F8", + "0x030060DC": "0x0300622C", "0x03006110": "0x03006260", + "0x03006130": "0x03006280", "0x03006160": "0x030062B0", + "0x03006180": "0x030062D0", "0x030061B0": "0x03006300", "0x030061E0": "0x03006330", "0x03006208": "0x03006358", @@ -1558,6 +2350,7 @@ "0x080003F1": "0x080003F1", "0x080003F5": "0x080003F5", "0x08000421": "0x08000421", + "0x08000441": "0x08000441", "0x08000465": "0x08000465", "0x08000471": "0x08000471", "0x0800048D": "0x0800048D", @@ -1581,6 +2374,7 @@ "0x08000BC9": "0x08000BC9", "0x08000C09": "0x08000C09", "0x08000C1D": "0x08000C1D", + "0x08000D8D": "0x08000D8D", "0x08000E49": "0x08000E49", "0x08000EC9": "0x08000EC9", "0x08000EF5": "0x08000EF5", @@ -1597,6 +2391,7 @@ "0x080012F9": "0x080012F9", "0x08001349": "0x08001349", "0x08001395": "0x08001395", + "0x080013F9": "0x080013F9", "0x08001405": "0x08001405", "0x08001495": "0x08001495", "0x08001539": "0x08001539", @@ -1607,8 +2402,14 @@ "0x08001991": "0x08001991", "0x08001A51": "0x08001A51", "0x08001A65": "0x08001A65", + "0x08001AA5": "0x08001AA5", + "0x08001B05": "0x08001B05", + "0x08001B15": "0x08001B15", + "0x08001B55": "0x08001B55", "0x08001B79": "0x08001B79", "0x08001BE5": "0x08001BE5", + "0x0800207D": "0x0800207D", + "0x0800208D": "0x0800208D", "0x080020E1": "0x080020E1", "0x080020F5": "0x080020F5", "0x08002119": "0x08002119", @@ -1625,25 +2426,38 @@ "0x080022F5": "0x080022F5", "0x08002305": "0x08002305", "0x0800232D": "0x0800232D", + "0x08002659": "0x080024CD", "0x08002695": "0x08002509", + "0x08002A55": "0x0800285D", + "0x08002AA1": "0x080028A9", "0x08002B71": "0x08002979", "0x08003985": "0x08003729", "0x08005A25": "0x08005639", "0x08005B89": "0x0800579D", "0x0800608D": "0x08005C59", + "0x08006545": "0x080060C1", + "0x08006551": "0x080060CD", + "0x080065B1": "0x0800612D", + "0x08006695": "0x08006211", + "0x080066A9": "0x08006225", "0x080066BD": "0x08006239", + "0x08006B2D": "0x080066A9", + "0x08006B71": "0x080066ED", "0x08006BC1": "0x0800673D", "0x08006BE9": "0x08006765", "0x08006BF9": "0x08006775", "0x08006C15": "0x08006791", "0x08006C31": "0x080067AD", + "0x08006C71": "0x080067ED", "0x08006CB5": "0x08006831", "0x08006CD1": "0x0800684D", "0x08006D09": "0x08006885", "0x08006D5D": "0x080068D9", "0x08006DAD": "0x08006929", "0x08006E65": "0x080069E1", + "0x08006E85": "0x08006A01", "0x08006EE1": "0x08006A5D", + "0x08007165": "0x08006D09", "0x08007281": "0x08006E25", "0x08007291": "0x08006E35", "0x08007871": "0x08007415", @@ -1655,20 +2469,31 @@ "0x08008C1D": "0x080087C1", "0x08008CC5": "0x08008869", "0x08008D39": "0x080088DD", + "0x08008E75": "0x08008A19", "0x08009015": "0x08008BB9", "0x0800903D": "0x08008BE1", "0x08009089": "0x08008C2D", "0x080090B1": "0x08008C55", "0x08009139": "0x08008CDD", + "0x080092C9": "0x08008E65", "0x080093E5": "0x08008F81", "0x080094CD": "0x08009069", + "0x08009595": "0x08009131", + "0x08009931": "0x080094CD", + "0x08009B85": "0x08009721", + "0x0800A03D": "0x08009BD9", "0x0800A34D": "0x08009EE9", "0x0800A999": "0x0800A535", "0x0800AD05": "0x0800A8A1", "0x0800AE51": "0x0800A9ED", + "0x0800AEF5": "0x0800AA91", "0x0800B119": "0x0800ACB5", "0x0800B651": "0x0800B1ED", + "0x0800B7DD": "0x0800B1ED", + "0x0800B975": "0x0800B379", "0x0800B9F1": "0x0800B3F5", + "0x0800BA6D": "0x0800B471", + "0x0800BAC5": "0x0800B4C9", "0x0800BB41": "0x0800B545", "0x0800BB55": "0x0800B559", "0x0800BB81": "0x0800B585", @@ -1677,18 +2502,25 @@ "0x0800BBD9": "0x0800B5DD", "0x0800BC09": "0x0800B60D", "0x0800BC45": "0x0800B649", + "0x0800BCA1": "0x0800B6A5", "0x0800BCDD": "0x0800B6E1", "0x0800BD49": "0x0800B72D", "0x0800BD5D": "0x0800B741", "0x0800BEC1": "0x0800B8A5", + "0x0800CB31": "0x0800C515", "0x0800CB3D": "0x0800C521", "0x0800CB79": "0x0800C55D", "0x0800CB9D": "0x0800C581", "0x0800CBAD": "0x0800C591", + "0x0800CBBD": "0x0800C5A1", + "0x0800CBCD": "0x0800C5B1", + "0x0800CBED": "0x0800C5D1", "0x0800CBF9": "0x0800C5DD", "0x0800CC19": "0x0800C5FD", + "0x0800CC39": "0x0800C61D", "0x0800CC49": "0x0800C62D", "0x0800CC69": "0x0800C64D", + "0x0800CC89": "0x0800C66D", "0x0800CC99": "0x0800C67D", "0x0800CCA9": "0x0800C68D", "0x0800CCB9": "0x0800C69D", @@ -1697,6 +2529,8 @@ "0x0800CCED": "0x0800C6D1", "0x0800CD01": "0x0800C6E5", "0x0800CD35": "0x0800C719", + "0x0800CD69": "0x0800C74D", + "0x0800CD79": "0x0800C75D", "0x0800CD8D": "0x0800C771", "0x0800CD9D": "0x0800C781", "0x0800CDAD": "0x0800C791", @@ -1709,42 +2543,133 @@ "0x0800CE31": "0x0800C815", "0x0800CE41": "0x0800C825", "0x0800CE55": "0x0800C839", + "0x0800CE69": "0x0800C84D", + "0x0800CED9": "0x0800C8BD", + "0x0800CEE9": "0x0800C8CD", + "0x0800CEFD": "0x0800C8E1", "0x0800CF11": "0x0800C8F5", + "0x0800CF21": "0x0800C905", + "0x0800CF35": "0x0800C919", "0x0800CF49": "0x0800C92D", + "0x0800CF59": "0x0800C93D", + "0x0800CF6D": "0x0800C951", "0x0800CF81": "0x0800C965", "0x0800CF91": "0x0800C975", "0x0800CFA5": "0x0800C989", + "0x0800CFB9": "0x0800C99D", + "0x0800CFC9": "0x0800C9AD", + "0x0800CFDD": "0x0800C9C1", "0x0800CFF1": "0x0800C9D5", + "0x0800D001": "0x0800C9E5", + "0x0800D015": "0x0800C9F9", "0x0800D029": "0x0800CA0D", + "0x0800D039": "0x0800CA1D", + "0x0800D04D": "0x0800CA31", + "0x0800D061": "0x0800CA45", + "0x0800D071": "0x0800CA55", + "0x0800D085": "0x0800CA69", + "0x0800D099": "0x0800CA7D", + "0x0800D0A9": "0x0800CA8D", + "0x0800D0F5": "0x0800CAD9", "0x0800D109": "0x0800CAED", + "0x0800D11D": "0x0800CB01", + "0x0800D12D": "0x0800CB11", + "0x0800D141": "0x0800CB25", + "0x0800D155": "0x0800CB39", + "0x0800D165": "0x0800CB49", + "0x0800D1B1": "0x0800CB95", + "0x0800D2F5": "0x0800CCD9", + "0x0800D369": "0x0800CD4D", "0x080135C5": "0x08013025", + "0x080137A1": "0x08013205", + "0x08013851": "0x080132B5", + "0x08013BC1": "0x08013631", + "0x08013C3D": "0x080136AD", + "0x08013CED": "0x0801375D", "0x08013E91": "0x08013901", + "0x080140AD": "0x08013B1D", "0x08014171": "0x08013BE1", + "0x08014B29": "0x08014595", + "0x08014C05": "0x08014671", + "0x08014C8D": "0x080146F9", + "0x08014D61": "0x080147CD", "0x08014E69": "0x080148D5", + "0x0801500D": "0x08014A79", + "0x08015091": "0x08014AFD", + "0x08015151": "0x08014BBD", + "0x080151E1": "0x08014C4D", + "0x080152CD": "0x08014D39", + "0x080153A5": "0x08014E11", + "0x08015465": "0x08014ED1", + "0x0801551D": "0x08014F89", + "0x08015621": "0x0801508D", + "0x080156FD": "0x08015169", + "0x08015821": "0x0801528D", + "0x08015915": "0x08015381", + "0x08015A49": "0x080154B5", + "0x08015B21": "0x0801558D", "0x08015C15": "0x08015681", + "0x08015C39": "0x080156A5", + "0x08015C5D": "0x080156C9", + "0x08015C8D": "0x080156F9", + "0x08015CB5": "0x08015721", + "0x08015CE1": "0x0801574D", + "0x08015D05": "0x08015771", + "0x08015D2D": "0x08015799", + "0x08015D51": "0x080157BD", "0x08015D75": "0x080157E1", "0x08015D99": "0x08015805", + "0x08015DC1": "0x0801582D", + "0x08015DE1": "0x0801584D", + "0x08015E01": "0x0801586D", "0x08015ED5": "0x08015941", + "0x08015EF9": "0x08015965", + "0x08015F21": "0x0801598D", "0x08016115": "0x08015B81", "0x080161A5": "0x08015C15", + "0x0801623D": "0x08015CAD", "0x0801641D": "0x08015E91", "0x0801674D": "0x080161C9", "0x0801681D": "0x08016295", + "0x080168FD": "0x08016375", "0x080169C9": "0x08016441", + "0x08016A7D": "0x080164F5", + "0x08016B31": "0x080165A9", "0x08016C89": "0x08016701", + "0x08016D41": "0x080167B9", + "0x08016E05": "0x08016879", "0x08016ECD": "0x08016941", + "0x08016F29": "0x0801699D", + "0x08017C6D": "0x080176E5", + "0x08017EC9": "0x08017949", "0x08017F7D": "0x080179FD", + "0x0801801D": "0x08017A9D", + "0x08019BF9": "0x08019745", "0x08019C3D": "0x08019789", + "0x08019CE9": "0x08019839", "0x08019D35": "0x08019885", + "0x08019D7D": "0x080198D1", + "0x08019EB9": "0x08019A15", + "0x08019F05": "0x08019A61", + "0x08019F61": "0x08019ABD", + "0x08019FA9": "0x08019B21", "0x08019FD9": "0x08019B51", "0x0801A041": "0x08019BB9", "0x0801A0A5": "0x08019C1D", "0x0801A0B1": "0x08019C29", "0x0801A0BD": "0x08019C35", + "0x0801A121": "0x08019C9D", "0x0801A389": "0x08019EFD", + "0x0801A3D1": "0x08019F45", + "0x0801A509": "0x0801A099", "0x0801A559": "0x0801A0E9", + "0x0801A639": "0x0801A1C9", "0x0801A665": "0x0801A211", + "0x0801A6D5": "0x0801A281", + "0x0801A70D": "0x0801A2B9", + "0x0801A765": "0x0801A311", "0x0801A7AD": "0x0801A37D", + "0x0801A9BD": "0x0801A58D", "0x0801AA35": "0x0801A605", "0x0801AA8D": "0x0801A65D", "0x0801AAE1": "0x0801A6B1", @@ -1753,11 +2678,58 @@ "0x0801AB51": "0x0801A721", "0x0801AB91": "0x0801A761", "0x0801ABE9": "0x0801A7B9", + "0x0801AC25": "0x0801A7F5", "0x0801AC79": "0x0801A849", + "0x0801ACB9": "0x0801A889", + "0x0801B265": "0x0801AE35", + "0x0801B58D": "0x0801B15D", + "0x0801B6F5": "0x0801B2D5", + "0x0801B74D": "0x0801B32D", + "0x0801B8A9": "0x0801B489", + "0x0801BA75": "0x0801B661", + "0x0801C8F1": "0x0801C52D", "0x0801CCC9": "0x0801C921", + "0x0801D029": "0x0801CC9D", + "0x0801D34D": "0x0801CFE1", + "0x0801D7AD": "0x0801D4A1", "0x0801DB95": "0x0801D889", + "0x0801DD9D": "0x0801DA8D", "0x0801DE61": "0x0801DB51", + "0x0801DEB9": "0x0801DBA9", + "0x0801DF8D": "0x0801DC85", + "0x0801E025": "0x0801DD1D", "0x0801E0AD": "0x0801DDA5", + "0x0801E0BD": "0x0801DDB5", + "0x0801E105": "0x0801DDFD", + "0x0801E165": "0x0801DE5D", + "0x0801E1A5": "0x0801DE9D", + "0x0801E1D9": "0x0801DED1", + "0x0801E20D": "0x0801DF05", + "0x0801E245": "0x0801DF3D", + "0x0801E279": "0x0801DF71", + "0x0801E2CD": "0x0801DFC5", + "0x0801E379": "0x0801E071", + "0x0801E3D9": "0x0801E0D1", + "0x0801E46D": "0x0801E165", + "0x0801E4B1": "0x0801E1B1", + "0x0801E4CD": "0x0801E1CD", + "0x0801E539": "0x0801E239", + "0x0801E5B1": "0x0801E2B1", + "0x0801E989": "0x0801E695", + "0x0801ED8D": "0x0801EAA5", + "0x0801EF15": "0x0801EC2D", + "0x0801F025": "0x0801ED41", + "0x0801F1C5": "0x0801EEF5", + "0x0801F2CD": "0x0801EFFD", + "0x0801F321": "0x0801F051", + "0x0801F375": "0x0801F0A5", + "0x0801F79D": "0x0801F4D5", + "0x0801F99D": "0x0801F6DD", + "0x0801FB15": "0x0801F869", + "0x0801FC35": "0x0801F9A5", + "0x0801FD65": "0x0801FAF1", + "0x0801FDD1": "0x0801FB5D", + "0x08020681": "0x080204B5", "0x08020D41": "0x08020B8D", "0x08020E09": "0x08020C55", "0x08020F75": "0x08020DC1", @@ -1772,27 +2744,50 @@ "0x08021AD9": "0x0802191D", "0x08021C6D": "0x08021AB1", "0x08021C71": "0x08021AB5", + "0x08021C75": "0x08021AB9", + "0x08021D01": "0x08021B45", "0x08021D89": "0x08021BCD", "0x08021DAD": "0x08021BF1", + "0x08021DC5": "0x08021C09", + "0x08021E45": "0x08021C89", "0x08021EC9": "0x08021D0D", "0x08021FE1": "0x08021E25", + "0x08022029": "0x08021E6D", + "0x08022079": "0x08021EBD", + "0x08022101": "0x08021F45", + "0x08022181": "0x08021FC5", "0x08022201": "0x08022045", + "0x08022285": "0x080220C9", "0x0802230D": "0x08022151", + "0x080223A5": "0x080221E9", + "0x080223F5": "0x08022239", + "0x0802247D": "0x080222C1", + "0x08022505": "0x08022349", "0x0802258D": "0x080223D1", "0x08022631": "0x08022475", "0x080226A5": "0x080224E9", + "0x08022E61": "0x08022CA5", + "0x08023275": "0x080230B9", + "0x08023685": "0x080234C9", "0x08023A3D": "0x08023881", "0x08023ED9": "0x08023D1D", "0x08023F99": "0x08023DDD", "0x0802413D": "0x08023F81", + "0x08024539": "0x0802437D", "0x080245CD": "0x08024411", + "0x080257D5": "0x08025619", "0x08025891": "0x080256D5", + "0x08026339": "0x0802617D", "0x080263B5": "0x080261F9", + "0x080267DD": "0x08026621", "0x08026859": "0x0802669D", + "0x08026C55": "0x08026A99", "0x08026CD1": "0x08026B15", "0x0802704D": "0x08026E91", "0x080277E1": "0x0802762D", "0x08027C1D": "0x08027A69", + "0x08028369": "0x08028225", + "0x080283C5": "0x08028281", "0x08028499": "0x08028355", "0x080284F5": "0x080283B1", "0x08028831": "0x080286ED", @@ -1804,10 +2799,44 @@ "0x08029175": "0x08029031", "0x0802926D": "0x08029129", "0x0802939D": "0x08029259", + "0x0802949D": "0x08029359", + "0x08029789": "0x08029645", "0x0802996D": "0x08029829", + "0x08029A7D": "0x08029939", + "0x08029B99": "0x08029A55", + "0x08029CED": "0x08029BAD", + "0x08029E0D": "0x08029CCD", + "0x0802A01D": "0x08029ED9", + "0x0802A081": "0x08029F3D", "0x0802A105": "0x08029FC1", + "0x0802A19D": "0x0802A059", "0x0802A229": "0x0802A0E5", "0x0802A591": "0x0802A44D", + "0x0802A645": "0x0802A501", + "0x0802A7DD": "0x0802A6C1", + "0x0802A9B1": "0x0802A895", + "0x0802AA29": "0x0802A929", + "0x0802B8A5": "0x0802B7A5", + "0x0802C145": "0x0802C045", + "0x0802C2A1": "0x0802C1A1", + "0x0802C675": "0x0802C575", + "0x0802CF85": "0x0802CE85", + "0x0802D051": "0x0802CF51", + "0x0802D201": "0x0802D101", + "0x0802D2C9": "0x0802D1C9", + "0x0802D569": "0x0802D469", + "0x0802D73D": "0x0802D63D", + "0x0802D801": "0x0802D701", + "0x0802D8C5": "0x0802D7C5", + "0x0802DAF1": "0x0802D9F1", + "0x0802DE0D": "0x0802DD0D", + "0x0802E111": "0x0802E011", + "0x0802E445": "0x0802E345", + "0x0802E6E1": "0x0802E5E1", + "0x0802E7AD": "0x0802E6AD", + "0x0802EA51": "0x0802E951", + "0x0802F209": "0x0802F109", + "0x0802F425": "0x0802F325", "0x0802F579": "0x0802F479", "0x0802FA81": "0x0802F981", "0x0802FEA1": "0x0802FDA1", @@ -1824,11 +2853,25 @@ "0x08031CB9": "0x08031BB9", "0x08031D89": "0x08031C89", "0x08031E59": "0x08031D59", + "0x08031F29": "0x08031E29", + "0x08031FF9": "0x08031EF9", "0x08032599": "0x08032499", + "0x0803294D": "0x0803284D", + "0x08032DE5": "0x08032CE5", "0x08033199": "0x08033099", "0x08033651": "0x08033551", + "0x08033B3D": "0x08033A3D", "0x08033C41": "0x08033B41", + "0x08034489": "0x08034389", + "0x08034901": "0x08034801", + "0x08034A5D": "0x0803495D", "0x08034F65": "0x08034E65", + "0x0803540D": "0x0803530D", + "0x08035915": "0x08035815", + "0x080359E9": "0x080358E9", + "0x08035A89": "0x08035989", + "0x08035B19": "0x08035A19", + "0x080368F5": "0x080367F5", "0x080376CD": "0x080375CD", "0x08037B05": "0x08037A01", "0x08037DFD": "0x08037CF9", @@ -1846,9 +2889,17 @@ "0x0803B69D": "0x0803B599", "0x0803B721": "0x0803B61D", "0x0803BC3D": "0x0803BB39", + "0x0803C009": "0x0803BF01", "0x0803C3C9": "0x0803C2C1", + "0x0803C4C1": "0x0803C3B9", "0x0803C699": "0x0803C591", + "0x0803D99D": "0x0803D895", + "0x0803E511": "0x0803E40D", "0x0803E5D9": "0x0803E4D5", + "0x0803F18D": "0x0803F089", + "0x0803F211": "0x0803F10D", + "0x0803F349": "0x0803F245", + "0x0803F455": "0x0803F351", "0x080400D5": "0x0803FFD1", "0x080402F5": "0x080401F1", "0x08040531": "0x0804042D", @@ -1861,40 +2912,100 @@ "0x080425CD": "0x080424C9", "0x08042939": "0x08042835", "0x08042BB1": "0x08042AAD", + "0x080435C5": "0x080434C1", + "0x08043665": "0x08043561", + "0x08043851": "0x0804374D", + "0x08043A4D": "0x08043949", + "0x08043B21": "0x08043A1D", + "0x08043BF5": "0x08043AF1", + "0x08043CC9": "0x08043BC5", + "0x08043D9D": "0x08043C99", + "0x08043E71": "0x08043D6D", + "0x08043F45": "0x08043E41", + "0x08044019": "0x08043F15", + "0x080440ED": "0x08043FE9", + "0x080441C1": "0x080440BD", + "0x08044319": "0x08044215", + "0x080443ED": "0x080442E9", + "0x080444C1": "0x080443BD", + "0x080445E9": "0x080444E5", + "0x08044D1D": "0x08044C19", "0x08044E35": "0x08044D31", "0x08044EB5": "0x08044DB1", + "0x0804534D": "0x08045249", "0x080455F1": "0x080454ED", + "0x08045661": "0x0804555D", + "0x08045765": "0x08045661", "0x08045B69": "0x08045A65", "0x08045E39": "0x08045D35", "0x08045F45": "0x08045E41", "0x08046491": "0x0804638D", "0x080469DD": "0x080468D9", "0x08046F29": "0x08046E25", + "0x08047971": "0x08047869", + "0x08047B2D": "0x08047A25", + "0x08048571": "0x0804846D", + "0x08048A75": "0x08048975", + "0x0804A479": "0x0804A38D", + "0x0804A89D": "0x0804A7B1", "0x0804B055": "0x0804AF69", + "0x0804B32D": "0x0804B231", + "0x0804BC39": "0x0804BB3D", "0x0804BEF9": "0x0804BDFD", + "0x0804C151": "0x0804C055", "0x0804C4E9": "0x0804C3ED", + "0x0804D021": "0x0804CF29", + "0x0804D331": "0x0804D239", + "0x0804E629": "0x0804E535", + "0x0804E7B9": "0x0804E6C5", + "0x0804ED19": "0x0804EC31", "0x0804EE21": "0x0804ED39", + "0x0804F391": "0x0804F2A9", "0x0804FA69": "0x0804F981", + "0x080502DD": "0x080501FD", "0x08050525": "0x08050445", + "0x08050E49": "0x08050D71", + "0x08051A79": "0x080519A1", "0x08051DF1": "0x08051D1D", "0x080523D9": "0x08052305", "0x08053121": "0x0805304D", "0x08053C5D": "0x08053B89", + "0x080542C5": "0x080541ED", + "0x0805442D": "0x08054355", "0x08054515": "0x0805443D", "0x08055A61": "0x08055989", "0x08055BA5": "0x08055ACD", "0x08055D1D": "0x08055C45", "0x080560D1": "0x08055FF9", + "0x08056539": "0x08056461", "0x0805664D": "0x08056575", "0x080567D5": "0x080566FD", + "0x08056CB5": "0x08056BDD", + "0x08056E25": "0x08056D4D", + "0x08056E39": "0x08056D61", "0x08056E51": "0x08056D79", + "0x08056E65": "0x08056D8D", + "0x08056E79": "0x08056DA1", "0x08056E91": "0x08056DB9", + "0x08056EA5": "0x08056DCD", + "0x08056F79": "0x08056EA1", + "0x08056F8D": "0x08056EB5", + "0x08056FB9": "0x08056EE1", + "0x08056FCD": "0x08056EF5", + "0x08056FE1": "0x08056F09", + "0x08056FF9": "0x08056F21", "0x0805700D": "0x08056F35", + "0x08057069": "0x08056F91", "0x080570DD": "0x08057005", + "0x08057171": "0x08057099", "0x080571A5": "0x080570CD", + "0x080572A5": "0x080571CD", "0x08057315": "0x0805723D", "0x08057329": "0x08057251", + "0x08057391": "0x080572B9", "0x080573A1": "0x080572C9", + "0x08057425": "0x0805734D", + "0x08057431": "0x08057359", "0x08057625": "0x0805754D", "0x0805768D": "0x080575B5", "0x080576A9": "0x080575D1", @@ -1902,9 +3013,31 @@ "0x08057935": "0x0805785D", "0x0805795D": "0x08057885", "0x08057985": "0x080578AD", + "0x080579D9": "0x08057901", + "0x08057A21": "0x08057949", "0x08057A5D": "0x08057985", + "0x08057AA5": "0x080579CD", "0x08057AE9": "0x08057A11", + "0x08057B2D": "0x08057A55", + "0x08057B65": "0x08057A8D", + "0x08057B99": "0x08057AC1", + "0x08057BD1": "0x08057AF9", + "0x08057C0D": "0x08057B35", + "0x08057C35": "0x08057B5D", + "0x08057C6D": "0x08057B95", + "0x08057CAD": "0x08057BD5", + "0x08057CED": "0x08057C15", + "0x08057DD1": "0x08057CF9", + "0x0805813D": "0x08058065", + "0x08058241": "0x08058169", + "0x08058261": "0x08058189", + "0x080583ED": "0x08058319", + "0x08058405": "0x08058331", + "0x08058421": "0x0805834D", "0x08058525": "0x08058451", + "0x0805853D": "0x08058469", + "0x08058609": "0x08058535", + "0x08058621": "0x0805854D", "0x0805865D": "0x08058589", "0x0805867D": "0x080585A9", "0x08058689": "0x080585B5", @@ -1913,9 +3046,26 @@ "0x08058769": "0x08058695", "0x08058791": "0x080586BD", "0x080587E5": "0x08058711", + "0x080587F1": "0x0805871D", + "0x08058879": "0x080587A9", + "0x080588C1": "0x080587F1", + "0x08058901": "0x08058831", + "0x08058935": "0x08058865", + "0x0805896D": "0x0805889D", + "0x080589A1": "0x080588D1", + "0x080589D9": "0x08058909", + "0x08058A19": "0x08058949", + "0x08058B09": "0x08058A39", + "0x08058B75": "0x08058AA5", + "0x08058CC5": "0x08058BF5", "0x08058DB1": "0x08058CE1", "0x08058EF9": "0x08058E29", + "0x08058F4D": "0x08058E7D", + "0x08059169": "0x08059099", + "0x0805921D": "0x0805914D", + "0x08059251": "0x08059181", "0x080592FD": "0x0805922D", + "0x08059341": "0x08059271", "0x08059375": "0x080592A5", "0x08059419": "0x08059349", "0x08059489": "0x080593B9", @@ -1924,7 +3074,13 @@ "0x0805968D": "0x080595BD", "0x08059739": "0x08059669", "0x080597E5": "0x08059715", + "0x08059891": "0x080597C1", "0x0805990D": "0x0805983D", + "0x08059955": "0x08059885", + "0x08059969": "0x08059899", + "0x080599B1": "0x080598E1", + "0x08059A41": "0x08059971", + "0x08059A95": "0x080599C5", "0x08059AD1": "0x08059A01", "0x08059B85": "0x08059AB5", "0x08059C39": "0x08059B69", @@ -1932,15 +3088,36 @@ "0x08059DA1": "0x08059CD1", "0x08059E55": "0x08059D85", "0x08059F09": "0x08059E39", + "0x08059FBD": "0x08059EED", + "0x0805A005": "0x08059F35", + "0x0805A041": "0x08059F71", + "0x0805A055": "0x08059F85", "0x0805A089": "0x08059FB9", + "0x0805A0ED": "0x0805A01D", "0x0805A139": "0x0805A069", + "0x0805A195": "0x0805A0C5", + "0x0805A1B5": "0x0805A0E5", "0x0805A2E5": "0x0805A215", + "0x0805A319": "0x0805A249", "0x0805A351": "0x0805A281", "0x0805A385": "0x0805A2B5", "0x0805A3B1": "0x0805A2E1", "0x0805A3F1": "0x0805A321", "0x0805A405": "0x0805A335", "0x0805A43D": "0x0805A36D", + "0x0805A475": "0x0805A3A5", + "0x0805A4A1": "0x0805A3D1", + "0x0805A4BD": "0x0805A3ED", + "0x0805A58D": "0x0805A4BD", + "0x0805A60D": "0x0805A53D", + "0x0805A619": "0x0805A549", + "0x0805A625": "0x0805A555", + "0x0805A631": "0x0805A561", + "0x0805A63D": "0x0805A56D", + "0x0805A649": "0x0805A579", + "0x0805A655": "0x0805A585", + "0x0805A661": "0x0805A591", + "0x0805A66D": "0x0805A59D", "0x0805A6A1": "0x0805A5D1", "0x0805A6B9": "0x0805A5E9", "0x0805A705": "0x0805A635", @@ -1950,86 +3127,223 @@ "0x0805AA69": "0x0805A999", "0x0805AAB9": "0x0805A9E9", "0x0805AB21": "0x0805AA51", + "0x0805AD19": "0x0805AC49", + "0x0805AD79": "0x0805ACAD", + "0x0805AE35": "0x0805AD6D", "0x0805AE95": "0x0805ADD5", + "0x0805B069": "0x0805AFC9", + "0x0805B0F1": "0x0805B04D", "0x0805B141": "0x0805B09D", "0x0805B21D": "0x0805B179", + "0x0805B2C5": "0x0805B221", "0x0805B4CD": "0x0805B429", + "0x0805B619": "0x0805B575", "0x0805B689": "0x0805B5E5", + "0x0805BD5D": "0x0805BCC9", "0x0805C209": "0x0805C191", "0x0805C4FD": "0x0805C4B1", + "0x0805C621": "0x0805C5D5", "0x0805C7B9": "0x0805C769", + "0x0805CB05": "0x0805CAC1", + "0x0805CB8D": "0x0805CB49", "0x0805CDF9": "0x0805CDB5", "0x0805CFA1": "0x0805CF5D", + "0x0805CFF9": "0x0805CFB5", + "0x0805D029": "0x0805CFE5", + "0x0805D065": "0x0805D021", + "0x0805D095": "0x0805D051", + "0x0805D0E9": "0x0805D0A5", + "0x0805D13D": "0x0805D0F9", + "0x0805D191": "0x0805D14D", + "0x0805D1E1": "0x0805D19D", + "0x0805D211": "0x0805D1CD", + "0x0805D279": "0x0805D239", + "0x0805D2E1": "0x0805D2A5", "0x0805D349": "0x0805D311", "0x0805D37D": "0x0805D345", "0x0805D3D5": "0x0805D39D", "0x0805D405": "0x0805D3CD", + "0x0805D461": "0x0805D429", + "0x0805D499": "0x0805D461", + "0x0805D4C5": "0x0805D48D", + "0x0805D4F5": "0x0805D4BD", + "0x0805D519": "0x0805D4E1", + "0x0805D549": "0x0805D511", + "0x0805D581": "0x0805D549", + "0x0805D5A1": "0x0805D569", + "0x0805D6B9": "0x0805D681", + "0x0805D721": "0x0805D6E9", "0x0805D855": "0x0805D81D", + "0x0805DC1D": "0x0805DBE5", "0x0805DE99": "0x0805DE61", "0x0805DF39": "0x0805DF01", + "0x0805E0C5": "0x0805E1DD", "0x0805EE6D": "0x0805F085", + "0x0805EEDD": "0x0805F0F5", + "0x0805EEED": "0x0805F105", "0x0805EEFD": "0x0805F115", "0x0805EF15": "0x0805F12D", "0x0805EF2D": "0x0805F145", + "0x0805EF85": "0x0805F19D", "0x0805EF91": "0x0805F1A9", "0x0805EFBD": "0x0805F1D5", + "0x0805F021": "0x0805F239", "0x0805F07D": "0x0805F28D", + "0x0805F0F1": "0x0805F2F5", + "0x0805F135": "0x0805F339", "0x0805F185": "0x0805F389", "0x0805F1B1": "0x0805F3B5", + "0x0805FAC1": "0x0805FA99", "0x0805FB7D": "0x0805FB55", "0x0805FC81": "0x0805FC59", + "0x0805FFBD": "0x0805FFC1", + "0x080605D1": "0x08060659", + "0x08060DB1": "0x08060E39", + "0x08060E45": "0x08060ECD", + "0x08061689": "0x08061711", + "0x0806171D": "0x080617A5", + "0x08061831": "0x080618B9", "0x08061911": "0x08061999", "0x08061E45": "0x08061ECD", "0x080624D9": "0x08062565", + "0x0806335D": "0x080631C1", "0x080634D9": "0x0806333D", "0x080636B1": "0x08063515", "0x08063B81": "0x080639E5", + "0x08063E31": "0x08063C95", "0x0806441D": "0x08064281", "0x08064E15": "0x08064C7D", + "0x0806514D": "0x08064FB5", "0x08065159": "0x08064FC1", + "0x08065205": "0x0806506D", "0x08065231": "0x08065099", "0x08065265": "0x080650CD", + "0x080652E1": "0x08065149", "0x08065371": "0x080651D9", "0x08065395": "0x080651FD", "0x080653B9": "0x08065221", "0x080653CD": "0x08065235", + "0x080653D5": "0x0806523D", + "0x080653FD": "0x08065265", "0x08065425": "0x0806528D", + "0x08065505": "0x0806536D", + "0x08065655": "0x080654BD", + "0x0806569D": "0x08065505", + "0x080656B9": "0x08065521", + "0x080656ED": "0x08065555", + "0x08065749": "0x080655B1", + "0x080657C5": "0x0806562D", + "0x08065839": "0x080656A1", "0x080658A1": "0x08065709", "0x080658CD": "0x08065735", + "0x08065919": "0x08065781", + "0x08065975": "0x080657DD", + "0x080659BD": "0x08065825", "0x080659F5": "0x0806585D", "0x08065A1D": "0x08065885", + "0x08065A91": "0x080658F9", + "0x08065AE9": "0x08065951", "0x08065B59": "0x080659C1", "0x08065B85": "0x080659ED", "0x08065BD1": "0x08065A39", + "0x08065C51": "0x08065AB9", "0x08065CA9": "0x08065B11", + "0x08065D51": "0x08065BB9", + "0x08065DAD": "0x08065C0D", "0x08065E39": "0x08065C99", "0x08065F09": "0x08065D69", "0x08065FE9": "0x08065E49", "0x0806603D": "0x08065E9D", + "0x080660ED": "0x08065F4D", + "0x0806617D": "0x08065FDD", + "0x08066221": "0x08066081", + "0x080662C5": "0x08066125", + "0x080663A5": "0x08067CA5", + "0x08066405": "0x08066201", "0x08066491": "0x0806628D", + "0x08066521": "0x0806631D", + "0x080665B1": "0x080663AD", + "0x08066625": "0x08066421", "0x08066721": "0x0806651D", "0x08066899": "0x08066695", "0x0806690D": "0x08066709", "0x08067A69": "0x08067845", "0x08067AFD": "0x080678D9", + "0x08067B51": "0x0806792D", "0x08067B9D": "0x08067979", "0x08067BF9": "0x080679D5", "0x08067C09": "0x080679E5", "0x08067C19": "0x080679F5", + "0x08067C29": "0x08067A05", + "0x08067CA9": "0x08067A85", + "0x08067D29": "0x08067B05", + "0x08067D75": "0x08067B51", "0x08067DC9": "0x08067BA5", + "0x08067E61": "0x08067C3D", + "0x08067EC9": "0x08067D01", + "0x08067F05": "0x08067D3D", + "0x08067F4D": "0x08067D85", + "0x08067F95": "0x08067DCD", + "0x08067FE1": "0x08067E19", + "0x08068031": "0x08067E69", "0x08068071": "0x08067EA9", + "0x080680B5": "0x08067EED", + "0x080680F9": "0x08067F31", + "0x08068145": "0x08067F7D", + "0x0806818D": "0x08067FC5", + "0x080681F5": "0x0806802D", + "0x0806823D": "0x08068075", + "0x080682A5": "0x080680DD", "0x080682B9": "0x080680F1", "0x08068331": "0x08068169", "0x08068385": "0x080681BD", + "0x080683CD": "0x08068205", + "0x08068451": "0x08068289", + "0x08068491": "0x080682C9", + "0x0806849D": "0x080682D5", + "0x080684F5": "0x0806832D", + "0x08068559": "0x08068391", "0x08068671": "0x080684A9", + "0x080686F5": "0x0806852D", "0x080687A9": "0x080685E1", + "0x080687E9": "0x08068621", "0x08068821": "0x08068659", "0x080688F9": "0x08068731", + "0x0806898D": "0x080687C5", + "0x08068A01": "0x08068839", + "0x08068F9D": "0x08068D85", + "0x08069081": "0x08068E69", + "0x08069225": "0x0806900D", + "0x08069389": "0x08069171", + "0x080694AD": "0x08069291", "0x080698D5": "0x080696B5", + "0x08069A31": "0x08069811", "0x08069AED": "0x080698CD", + "0x08069C45": "0x08069A25", + "0x0806A19D": "0x08069F85", + "0x0806A88D": "0x0806A675", + "0x0806ABC1": "0x0806A9A9", + "0x0806B3C5": "0x0806B1AD", + "0x0806BE25": "0x0806BC0D", + "0x0806C569": "0x0806C351", + "0x0806CDF1": "0x0806CBD5", + "0x0806D4A5": "0x0806D295", + "0x0806D7ED": "0x0806D5DD", + "0x0806DB1D": "0x0806D90D", + "0x0806DE95": "0x0806DC85", + "0x0806E7D5": "0x0806E5C1", + "0x0806F0CD": "0x0806EEB1", + "0x0806FE1D": "0x0806FBFD", + "0x0806FF1D": "0x0806FCFD", + "0x080710DD": "0x08070EC9", + "0x08072391": "0x08072189", + "0x08072D5D": "0x08072B55", + "0x0807356D": "0x080733A1", + "0x0807386D": "0x080736A1", "0x08073CF5": "0x08073B29", "0x08073E2D": "0x08073C61", "0x08073EE9": "0x08073D1D", + "0x0807414D": "0x08073F79", "0x08074399": "0x080741C1", "0x08074531": "0x08074355", "0x080746A5": "0x080744C9", @@ -2037,25 +3351,76 @@ "0x0807498D": "0x080747B1", "0x08074B01": "0x08074925", "0x08074C75": "0x08074A99", + "0x08074DE9": "0x08074C0D", "0x08075089": "0x08074EAD", + "0x08075495": "0x080752B9", "0x08075521": "0x08075345", + "0x080756ED": "0x08075511", "0x08075779": "0x0807559D", + "0x080760E9": "0x08075F1D", + "0x080761A5": "0x08075FD9", + "0x08076A89": "0x08076909", "0x08076BA1": "0x08076A21", + "0x08077445": "0x0807730D", + "0x08077509": "0x080773D1", + "0x08077D05": "0x08077BDD", + "0x08077DAD": "0x08077C85", + "0x0807854D": "0x08078429", + "0x080785F5": "0x080784D1", + "0x08078B25": "0x08078A01", "0x08078BCD": "0x08078AA9", + "0x080793BD": "0x080792A1", "0x08079459": "0x0807933D", + "0x08079889": "0x0807976D", "0x08079949": "0x0807982D", + "0x08079CC5": "0x08079BAD", "0x08079D85": "0x08079C6D", + "0x08079ED1": "0x08079DB9", + "0x08079FD1": "0x08079EB9", + "0x0807A029": "0x08079F11", + "0x0807A041": "0x08079F29", + "0x0807A065": "0x08079F4D", "0x0807A121": "0x0807A009", "0x0807A125": "0x0807A00D", + "0x0807A20D": "0x0807A0F5", + "0x0807A2E1": "0x0807A1C9", + "0x0807A379": "0x0807A25D", + "0x0807A4B5": "0x0807A39D", "0x0807A5D5": "0x0807A4C1", "0x0807B7B5": "0x0807B5FD", "0x0807BD79": "0x0807BB21", "0x0807BEA1": "0x0807BC49", "0x0807C015": "0x0807BDBD", + "0x0807C115": "0x0807BEBD", + "0x0807C1D9": "0x0807BF81", + "0x0807C29D": "0x0807C045", + "0x08080A79": "0x08080829", + "0x080811E1": "0x08080F91", + "0x08081519": "0x080812D9", + "0x080815F5": "0x08081499", + "0x08082961": "0x08082215", "0x08082BB1": "0x08082469", + "0x0808381D": "0x08082FC5", + "0x08083AE9": "0x080832C5", + "0x08084201": "0x080839ED", + "0x0808441D": "0x08083C09", + "0x08084EAD": "0x080846ED", + "0x08084F25": "0x08084765", "0x08084F9D": "0x080847DD", + "0x08085015": "0x08084855", + "0x08085065": "0x080848A5", + "0x080850C1": "0x080813D9", + "0x0808516D": "0x08084901", + "0x080851B9": "0x0808494D", + "0x08085219": "0x080849AD", "0x0808528D": "0x08084A21", "0x080852AD": "0x08084A41", + "0x080852CD": "0x08084A61", + "0x08085331": "0x08084AC5", + "0x0808536D": "0x08084B01", + "0x08085399": "0x08084B2D", + "0x080853DD": "0x08084B71", + "0x0808543D": "0x08084BD1", "0x08085485": "0x08084C19", "0x080854A1": "0x08084C35", "0x08085519": "0x08084CAD", @@ -2070,11 +3435,21 @@ "0x08087CC1": "0x08087539", "0x080887D5": "0x0808804D", "0x08088915": "0x0808818D", + "0x0808899D": "0x08088215", "0x080889D5": "0x0808824D", + "0x08088A19": "0x08088291", + "0x08088A61": "0x080882D9", "0x08088AA9": "0x08088321", + "0x08088B6D": "0x080883E5", "0x0808AFE9": "0x0808A849", + "0x0808B979": "0x0808B1E9", + "0x0808C021": "0x0808B82D", "0x0808C0C5": "0x0808B8D1", + "0x0808CB59": "0x0808C2F1", + "0x0808D05D": "0x0808C795", + "0x0808D0B1": "0x0808C7E9", "0x0808D119": "0x0808C851", + "0x0808D655": "0x0808CD8D", "0x0808DB39": "0x0808D27D", "0x0808E131": "0x0808D875", "0x0808E531": "0x0808DC75", @@ -2096,9 +3471,18 @@ "0x08091939": "0x080910D1", "0x08091B5D": "0x080912F5", "0x08091CF9": "0x08091491", + "0x08091F9D": "0x080916B9", + "0x08092081": "0x08091739", + "0x08092095": "0x0809174D", + "0x080920A1": "0x08091759", + "0x080920E5": "0x0809179D", + "0x08092125": "0x080917DD", + "0x08092191": "0x08091849", "0x080921E5": "0x0809189D", "0x080922B5": "0x0809196D", "0x08092345": "0x080919FD", + "0x08092349": "0x08091A01", + "0x080923B1": "0x08091A69", "0x080923B5": "0x08091A6D", "0x080923FD": "0x08091AB5", "0x08092CB9": "0x08092371", @@ -2150,109 +3534,279 @@ "0x0809561D": "0x08094CD5", "0x08095A61": "0x08095119", "0x08095AD9": "0x08095191", + "0x08095B05": "0x080951BD", "0x08095D1D": "0x080953D5", + "0x08095F11": "0x080955C9", + "0x08095FC9": "0x08095681", "0x08096061": "0x08095719", + "0x08096595": "0x08095C4D", + "0x08096641": "0x08095CF9", + "0x080967D1": "0x08095E89", + "0x0809689D": "0x08095F55", + "0x080968C1": "0x08095F79", + "0x08096AF5": "0x080961AD", "0x08096BA9": "0x08096261", "0x08096D41": "0x080963F9", "0x08096E21": "0x080964D9", "0x08096EFD": "0x080965B5", "0x08096FA1": "0x08096659", + "0x080970CD": "0x08096785", + "0x080972B9": "0x08096971", + "0x08097659": "0x08096D11", + "0x08097979": "0x08097031", "0x080979D9": "0x08097091", + "0x08097A39": "0x080970F1", + "0x08097A4D": "0x08097105", + "0x08097A75": "0x0809712D", + "0x08097AC1": "0x08097179", + "0x08097B25": "0x080971DD", "0x08097B6D": "0x08097225", "0x08097BA5": "0x0809725D", + "0x08097C4D": "0x08097305", "0x08097C6D": "0x08097325", + "0x08097CA9": "0x08097361", + "0x08097D0D": "0x080973C5", "0x08097D19": "0x080973D1", + "0x08097D3D": "0x080973F5", + "0x08097D65": "0x0809741D", + "0x08097D71": "0x08097429", + "0x08097D7D": "0x08097435", + "0x08097E29": "0x080974E1", "0x08097EB1": "0x08097569", "0x08097EF1": "0x080975A9", "0x08097F71": "0x08097629", + "0x08097FE5": "0x0809769D", + "0x08097FF9": "0x080976B1", + "0x08098005": "0x080976BD", "0x08098011": "0x080976C9", "0x08098029": "0x080976E1", + "0x08098045": "0x080976FD", "0x08098061": "0x08097719", + "0x08098089": "0x08097741", + "0x080980F1": "0x080977A9", + "0x08098109": "0x080977C1", + "0x08098F2D": "0x0809861D", "0x0809919D": "0x0809888D", "0x08099469": "0x08098B59", + "0x08099721": "0x08098E11", + "0x0809975D": "0x08098E4D", + "0x08099789": "0x08098E79", + "0x080997C1": "0x08098EB1", + "0x08099839": "0x08098F29", + "0x0809A5E1": "0x08099D19", "0x0809A835": "0x08099F6D", + "0x0809ADE9": "0x0809A525", + "0x0809AE25": "0x0809A561", "0x0809AE51": "0x0809A58D", + "0x0809AE89": "0x0809A5C5", + "0x0809AEE9": "0x0809A625", "0x0809C1B5": "0x0809B93D", "0x0809C4E9": "0x0809BC71", "0x0809C8F5": "0x0809C07D", "0x0809CC2D": "0x0809C3B5", + "0x0809D375": "0x0809CB11", + "0x0809D559": "0x0809CCF5", + "0x0809D575": "0x0809CD11", + "0x0809D5B9": "0x0809CD55", "0x0809D5E5": "0x0809CD81", + "0x0809D621": "0x0809CDBD", + "0x0809D6A9": "0x0809CE45", "0x0809D6D9": "0x0809CE75", + "0x0809D711": "0x0809CEAD", + "0x0809D77D": "0x0809CF19", + "0x0809D7E5": "0x0809CF81", "0x0809D811": "0x0809CFAD", "0x0809D849": "0x0809CFE5", + "0x0809D879": "0x0809D015", "0x0809E469": "0x0809DC5D", + "0x0809EDFD": "0x0809E5F1", + "0x0809EF85": "0x0809E779", "0x0809F019": "0x0809E80D", "0x0809F4A9": "0x0809EC9D", + "0x0809F8C9": "0x0809F0BD", + "0x0809F90D": "0x0809F101", + "0x0809F919": "0x0809F10D", "0x0809F935": "0x0809F129", + "0x0809F999": "0x0809F18D", + "0x0809F9F9": "0x0809F1ED", "0x0809FA29": "0x0809F21D", + "0x0809FA65": "0x0809F259", + "0x0809FACD": "0x0809F2C1", "0x0809FAED": "0x0809F2E1", + "0x0809FB19": "0x0809F30D", + "0x0809FB6D": "0x0809F361", "0x080A05B5": "0x0809FDDD", "0x080A099D": "0x080A01C5", "0x080A0B45": "0x080A036D", + "0x080A0F65": "0x080A07A5", + "0x080A0FA9": "0x080A07E9", "0x080A0FC5": "0x080A0805", + "0x080A0FED": "0x080A082D", + "0x080A104D": "0x080A088D", + "0x080A1059": "0x080A0899", + "0x080A1071": "0x080A08B1", + "0x080A107D": "0x080A08BD", + "0x080A1089": "0x080A08C9", + "0x080A1095": "0x080A08D5", + "0x080A10AD": "0x080A08ED", + "0x080A10B9": "0x080A08F9", "0x080A10D5": "0x080A0915", + "0x080A10FD": "0x080A093D", + "0x080A1171": "0x080A09B1", "0x080A118D": "0x080A09CD", + "0x080A11B5": "0x080A09F5", + "0x080A1209": "0x080A0A49", + "0x080A1DA9": "0x080A1619", "0x080A1F89": "0x080A17F9", "0x080A1FF5": "0x080A1865", "0x080A230D": "0x080A1B81", + "0x080A2699": "0x080A1F15", + "0x080A26D1": "0x080A1F4D", + "0x080A2721": "0x080A1F9D", + "0x080A27B9": "0x080A2035", "0x080A35D1": "0x080A2E79", "0x080A3D2D": "0x080A35ED", + "0x080A4521": "0x080A3E05", "0x080A47A1": "0x080A4085", + "0x080A49A9": "0x080A4299", + "0x080A49ED": "0x080A42DD", "0x080A4A55": "0x080A4345", + "0x080A4A7D": "0x080A436D", "0x080A4AD1": "0x080A43C1", + "0x080A4AE5": "0x080A43D5", "0x080A4B11": "0x080A4401", + "0x080A4B49": "0x080A4439", "0x080A4BB1": "0x080A44A1", + "0x080A4BE1": "0x080A44D1", "0x080A4BFD": "0x080A44ED", + "0x080A4C25": "0x080A4515", + "0x080A4C75": "0x080A4565", + "0x080A4CA9": "0x080A4599", + "0x080A4CDD": "0x080A45CD", + "0x080A4CF1": "0x080A45E1", + "0x080A4CFD": "0x080A45ED", + "0x080A4D09": "0x080A45F9", + "0x080A6259": "0x080A5BB1", + "0x080A6511": "0x080A5E69", + "0x080A66E1": "0x080A6039", "0x080A68B1": "0x080A6209", "0x080A6BE9": "0x080A6545", "0x080A705D": "0x080A69BD", "0x080A74E9": "0x080A6E51", "0x080A756D": "0x080A6ED5", + "0x080A7DED": "0x080A7755", + "0x080A7E69": "0x080A77D1", "0x080A7E95": "0x080A77FD", + "0x080A7ECD": "0x080A7835", + "0x080A7F31": "0x080A7899", "0x080A7F5D": "0x080A78C5", + "0x080A7F95": "0x080A78FD", + "0x080A7FF9": "0x080A7961", "0x080A8015": "0x080A797D", + "0x080A803D": "0x080A79A5", + "0x080A8091": "0x080A79F9", + "0x080A80BD": "0x080A7A25", "0x080A80D9": "0x080A7A41", + "0x080A8115": "0x080A7A7D", + "0x080A8165": "0x080A7ACD", + "0x080A8F91": "0x080A8925", + "0x080A9101": "0x080A8A95", "0x080A92C1": "0x080A8C55", + "0x080A9681": "0x080A9015", + "0x080A97E1": "0x080A9175", + "0x080A9819": "0x080A91AD", "0x080A9845": "0x080A91D9", + "0x080A987D": "0x080A9211", + "0x080A98E1": "0x080A9275", "0x080A9911": "0x080A92A5", + "0x080A9951": "0x080A92E5", + "0x080AB055": "0x080AAA29", + "0x080AB2D9": "0x080AACAD", "0x080AB2F9": "0x080AACCD", + "0x080AC215": "0x080ABC1D", + "0x080AC2E9": "0x080ABCF1", + "0x080AC5B5": "0x080ABFBD", "0x080AC81D": "0x080AC225", "0x080AC845": "0x080AC24D", "0x080AD535": "0x080ACF21", + "0x080ADE31": "0x080AD821", "0x080AE081": "0x080ADA71", + "0x080AE0B9": "0x080ADAA9", "0x080AE0E5": "0x080ADAD5", + "0x080AE11D": "0x080ADB0D", "0x080AE185": "0x080ADB75", "0x080AE1B5": "0x080ADBA5", "0x080AE421": "0x080ADE11", "0x080AF2AD": "0x080AED69", + "0x080AF2BD": "0x080AED79", "0x080AF305": "0x080AEDC1", + "0x080AF351": "0x080AEE0D", "0x080AF3C5": "0x080AEE81", "0x080AF3F5": "0x080AEEB1", "0x080B0289": "0x080AFD59", "0x080B0F71": "0x080B0A59", "0x080B0F9D": "0x080B0A85", + "0x080B0FC5": "0x080B0AAD", "0x080B1FD5": "0x080B1AE1", "0x080B2059": "0x080B1B65", "0x080B2201": "0x080B1D0D", + "0x080B22E9": "0x080B1DF5", + "0x080B2331": "0x080B1E3D", + "0x080B236D": "0x080B1E79", + "0x080B23C9": "0x080B1ED5", + "0x080B23FD": "0x080B1F09", + "0x080B2425": "0x080B1F31", + "0x080B2455": "0x080B1F61", + "0x080B24B9": "0x080B1FC5", + "0x080B2781": "0x080B228D", + "0x080B280D": "0x080B2319", + "0x080B3649": "0x080B30BD", + "0x080B44F1": "0x080B3F19", "0x080B4691": "0x080B40B9", + "0x080B4A7D": "0x080B44A5", + "0x080B4B49": "0x080B4571", "0x080B4B7D": "0x080B45A5", + "0x080B4BB9": "0x080B45E1", + "0x080B4C35": "0x080B465D", + "0x080B5B91": "0x080B55F9", + "0x080B5E65": "0x080B58CD", "0x080B5F95": "0x080B5A05", "0x080B6069": "0x080B5AD9", "0x080B60F5": "0x080B5B65", "0x080B6179": "0x080B5BE9", + "0x080B6325": "0x080B5D95", "0x080B6361": "0x080B5DD1", + "0x080B63A1": "0x080B5E11", + "0x080B63BD": "0x080B5E2D", + "0x080B640D": "0x080B5E7D", + "0x080B6449": "0x080B5EB9", + "0x080B64A5": "0x080B5F15", "0x080B64D9": "0x080B5F49", "0x080B64E9": "0x080B5F59", + "0x080B6554": "0x080B5FC4", + "0x080B6558": "0x080B5FC8", + "0x080B655C": "0x080B5FCC", + "0x080B6560": "0x080B5FD0", + "0x080B6564": "0x080B5FD4", + "0x080B6568": "0x080B5FD8", "0x080B656D": "0x080B5FDD", + "0x080B690A": "0x080B637B", "0x080B6929": "0x080B6399", + "0x080B6949": "0x080B63B9", "0x080B6979": "0x080B63E9", "0x080B6991": "0x080B6401", "0x080B6993": "0x080B6403", + "0x080B69A8": "0x080B6418", "0x080B69AD": "0x080B641D", "0x080B69AF": "0x080B641F", + "0x080B69B9": "0x080B6429", "0x080B6B3D": "0x080B65AD", + "0x080B6B6C": "0x080B65DC", + "0x080B6B70": "0x080B65E0", "0x080B6B75": "0x080B65E5", "0x080B6DD1": "0x080B6841", + "0x080B6DD8": "0x080B6848", + "0x080B6DDC": "0x080B684C", "0x080B6DE1": "0x080B6851", "0x080B6E25": "0x080B6895", "0x080B703D": "0x080B6AAD", @@ -2332,6 +3886,7 @@ "0x080B8F29": "0x080B8999", "0x080B8F2D": "0x080B899D", "0x080B8F31": "0x080B89A1", + "0x080B8F35": "0x080B89A5", "0x080B8F39": "0x080B89A9", "0x080B8F61": "0x080B89D1", "0x080B9395": "0x080B8E05", @@ -2343,10 +3898,12 @@ "0x080B9704": "0x080B9174", "0x080B9984": "0x080B93F4", "0x080B99C8": "0x080B9438", + "0x080B99D4": "0x080B9444", "0x080B99D8": "0x080B9448", "0x080B9AD0": "0x080B9540", "0x080BB6D0": "0x080BB140", "0x080BB6E4": "0x080BB154", + "0x080BB7E4": "0x080BB274", "0x080BB878": "0x080BB308", "0x080BB92C": "0x080BB3BC", "0x080BB95C": "0x080BB3EC", @@ -2359,6 +3916,37 @@ "0x080BC5DC": "0x080BC06C", "0x080BC60C": "0x080BC09C", "0x08366A60": "0x083664F0", + "0x08366BC0": "0x08366650", + "0x08366DCC": "0x08366850", + "0x08366DD0": "0x08366854", + "0x08366E0C": "0x08366890", + "0x08366E34": "0x083668B8", + "0x08366EFC": "0x08366980", + "0x08366FC4": "0x08366A48", + "0x0838AFF0": "0x0838F7C0", + "0x083B0B4C": "0x083DAC64", + "0x083D8AEC": "0x083DC470", + "0x084009A4": "0x083D8D18", + "0x08428C38": "0x083DBC6C", + "0x0842A38C": "0x083DC47C", + "0x0842A6D4": "0x083DCBFC", + "0x084303B8": "0x083EA338", + "0x08434738": "0x083F37B8", + "0x0843B8C8": "0x08403110", + "0x08442498": "0x08411DC8", + "0x0844A820": "0x08424170", + "0x0844EB50": "0x0842D900", + "0x084506D0": "0x08431640", + "0x084742BC": "0x0847C874", + "0x08477F3C": "0x08484F34", + "0x08478044": "0x0848503C", + "0x08478158": "0x08485150", + "0x08478220": "0x08485218", + "0x084782F4": "0x084852EC", + "0x08478310": "0x08485308", + "0x08478338": "0x08485330", + "0x08478378": "0x08485370", + "0x0847838C": "0x08485384", "0x0847842C": "0x084854FC", "0x0847843C": "0x0848550C", "0x0847844C": "0x0848551C", @@ -2366,11 +3954,153 @@ "0x0847846C": "0x0848553C", "0x08478470": "0x08485540", "0x08478F4C": "0x0848601C", + "0x08478F9A": "0x0848606A", + "0x08479044": "0x08486114", + "0x08479054": "0x08486124", + "0x084790B4": "0x08486184", + "0x084790C4": "0x08486194", + "0x08479140": "0x08486210", + "0x0847AC64": "0x08487BC0", + "0x0847ACE8": "0x08487DB8", + "0x0847ACF8": "0x08487DC8", "0x0847AD0A": "0x08487DDA", + "0x0847AD1C": "0x08487DEC", + "0x0847AD3C": "0x08487E0C", + "0x0848529C": "0x084A403C", + "0x0848FA0C": "0x084DC2B0", "0x0848FA48": "0x084DC2EC", + "0x0848FB68": "0x084DC40C", + "0x0848FB7C": "0x084DC420", + "0x0848FB84": "0x084DC428", + "0x0848FB90": "0x084DC434", + "0x0848FB9C": "0x084DC440", + "0x0848FBA8": "0x084DC44C", + "0x0848FBB4": "0x084DC458", + "0x0848FBC0": "0x084DC464", + "0x0848FBCC": "0x084DC470", + "0x0848FBD8": "0x084DC47C", + "0x0848FBE4": "0x084DC488", + "0x0848FBF0": "0x084DC494", + "0x0848FBFC": "0x084DC4A0", + "0x0848FC08": "0x084DC4AC", + "0x0848FC14": "0x084DC4B8", + "0x0848FC20": "0x084DC4C4", + "0x0848FC2C": "0x084DC4D0", + "0x0848FC38": "0x084DC4DC", + "0x0848FC44": "0x084DC4E8", + "0x0848FC50": "0x084DC4F4", + "0x0848FC5C": "0x084DC500", + "0x0848FC68": "0x084DC50C", + "0x0848FC74": "0x084DC518", + "0x0848FC80": "0x084DC524", + "0x0848FC8C": "0x084DC530", + "0x0848FC98": "0x084DC53C", + "0x0848FCA4": "0x084DC548", + "0x0848FCB0": "0x084DC554", + "0x0848FCBC": "0x084DC560", + "0x0848FCC8": "0x084DC56C", + "0x0848FCD4": "0x084DC578", + "0x0848FCE0": "0x084DC584", + "0x0848FCEC": "0x084DC590", + "0x0848FCF8": "0x084DC59C", + "0x0848FD04": "0x084DC5A8", + "0x0848FD10": "0x084DC5B4", + "0x0848FD1C": "0x084DC5C0", + "0x0848FD28": "0x084DC5CC", + "0x0848FD34": "0x084DC5D8", + "0x0848FD40": "0x084DC5E4", + "0x0848FD4C": "0x084DC5F0", + "0x0848FD58": "0x084DC5FC", + "0x0848FD64": "0x084DC608", + "0x0848FD70": "0x084DC614", + "0x0848FD7C": "0x084DC620", + "0x0848FD88": "0x084DC62C", + "0x0848FD94": "0x084DC638", + "0x0848FDA0": "0x084DC644", + "0x0848FDAC": "0x084DC650", + "0x0848FDB8": "0x084DC65C", + "0x0848FDC4": "0x084DC668", + "0x0848FDD0": "0x084DC674", + "0x0848FDDC": "0x084DC680", + "0x0848FDE8": "0x084DC68C", + "0x0848FDF4": "0x084DC698", + "0x0848FE00": "0x084DC6A4", + "0x0848FE0C": "0x084DC6B0", + "0x0848FE18": "0x084DC6BC", + "0x0848FE24": "0x084DC6C8", + "0x0848FE30": "0x084DC6D4", + "0x0848FE3C": "0x084DC6E0", + "0x0848FE48": "0x084DC6EC", + "0x0848FE54": "0x084DC6F8", + "0x0848FE60": "0x084DC704", + "0x0848FE6C": "0x084DC710", + "0x0848FE78": "0x084DC71C", + "0x0848FE84": "0x084DC728", + "0x0848FEA8": "0x084DC74C", + "0x0848FEB4": "0x084DC758", + "0x0848FEC0": "0x084DC764", + "0x0848FECC": "0x084DC770", + "0x0848FED8": "0x084DC77C", + "0x0848FEE4": "0x084DC788", + "0x0848FEE8": "0x084DC78C", + "0x0848FEEC": "0x084DC790", + "0x0848FEF0": "0x084DC794", + "0x0848FF30": "0x084DC7D4", + "0x0848FF34": "0x084DC7D8", + "0x0848FF38": "0x084DC7DC", + "0x0848FF3C": "0x084DC7E0", + "0x0848FF40": "0x084DC7E4", + "0x0848FF44": "0x084DC7E8", + "0x0848FF48": "0x084DC7EC", + "0x0848FF4C": "0x084DC7F0", + "0x0848FF50": "0x084DC7F4", + "0x0848FF54": "0x084DC7F8", + "0x08490120": "0x084DC988", "0x0849E580": "0x084ED6B0", + "0x0849E730": "0x084ED860", + "0x0849E740": "0x084ED870", + "0x0849E760": "0x084ED890", + "0x0849E770": "0x084ED8A0", + "0x0849F878": "0x084F46A8", + "0x084A06B0": "0x084F54E0", + "0x084A1910": "0x084F6740", + "0x084A2748": "0x084F7578", + "0x084A3E40": "0x084F8C70", + "0x084A3EB0": "0x084F8CE0", + "0x084A4C40": "0x084F9A70", + "0x084A5CA8": "0x084FAAD8", + "0x084A6DB8": "0x084FBBE8", + "0x084A7CD0": "0x084FCB00", + "0x084A8088": "0x084FCEB8", + "0x084A84B0": "0x084FD2E0", + "0x084A8B40": "0x084FD970", + "0x084A8EC0": "0x084FDCF0", "0x084AA580": "0x084FF3B0", + "0x084AA740": "0x084FF570", + "0x084AA7B0": "0x084FF5E0", + "0x084AA970": "0x084FF7A0", + "0x084AA9E0": "0x084FF810", + "0x084AA9E8": "0x084FF818", + "0x084AAB30": "0x084FF960", + "0x084AAB38": "0x084FF968", + "0x084AAC80": "0x084FFAB0", + "0x084AAC88": "0x084FFAB8", + "0x084AADD0": "0x084FFC00", + "0x084AADD8": "0x084FFC08", + "0x084AAF20": "0x084FFD50", + "0x084AAF28": "0x084FFD58", + "0x084AB070": "0x084FFEA0", + "0x084AB078": "0x084FFEA8", + "0x084AB1C0": "0x084FFFF0", + "0x084AB1C8": "0x084FFFF8", + "0x084AB310": "0x08500140", + "0x084AB318": "0x08500148", + "0x084AB460": "0x08500290", + "0x084AB468": "0x08500298", + "0x084AB5B0": "0x085003E0", + "0x084AB5B8": "0x085003E8", "0x084ABA10": "0x08500840", + "0x084B0AA0": "0x085058D0", "0x084B139C": "0x085061CC", "0x084B13BC": "0x085061EC", "0x084B13E4": "0x08506214", @@ -2394,14 +4124,95 @@ "0x084B16A0": "0x085064D0", "0x084B16B4": "0x085064E4", "0x084B16CC": "0x085064FC", + "0x084B16E0": "0x08506510", + "0x084B1860": "0x08506690", + "0x084B19F0": "0x08506820", + "0x084B1C50": "0x08506A80", + "0x084B1D40": "0x08506B70", + "0x084B1D78": "0x08506BA8", + "0x084B23A8": "0x085071D8", + "0x084B24B0": "0x085072E0", + "0x084B2504": "0x08507334", "0x084E6DD8": "0x0853BC08", + "0x084E7BE8": "0x0853CA18", + "0x084E99E8": "0x0853E818", "0x084EB7E8": "0x08540618", "0x084EB8D8": "0x08540708", "0x084EBCE8": "0x08540B18", "0x084EBD28": "0x08540B58", "0x084EBD38": "0x08540B68", + "0x084EBD48": "0x08540B78", "0x084EBD4C": "0x08540B7C", + "0x084EBD5C": "0x08540B8C", "0x084EBD74": "0x08540BA4", + "0x084EBD7C": "0x08540BAC", + "0x084EBDBC": "0x08540BEC", + "0x084EBDBE": "0x08540BEE", + "0x084EBDC8": "0x08540BF8", + "0x084EBE08": "0x08540C38", + "0x084EBE0A": "0x08540C3A", + "0x084EBE14": "0x08540C44", + "0x084EBE34": "0x08540C64", + "0x084EBE38": "0x08540C68", + "0x084EBE54": "0x08540C84", + "0x084EBE84": "0x08540CB4", + "0x084EBE86": "0x08540CB6", + "0x084EBEBC": "0x08540CEC", + "0x084EBF1C": "0x08540D4C", + "0x084EBF7E": "0x08540DAE", + "0x084EC12C": "0x08540F5C", + "0x084EC14C": "0x08540F7C", + "0x084EC15C": "0x08540F8C", + "0x084EC16C": "0x08540F9C", + "0x084EC17C": "0x08540FAC", + "0x084EC18E": "0x08540FBE", + "0x084EC1A0": "0x08540FD0", + "0x084EC1C0": "0x08540FF0", + "0x084EC1D0": "0x08541000", + "0x084EC1E0": "0x08541010", + "0x084EC288": "0x085410B8", + "0x084EC330": "0x08541160", + "0x084EC3D8": "0x08541208", + "0x084EC480": "0x085412B0", + "0x084EC4E0": "0x08541310", + "0x084EC540": "0x08541370", + "0x084EC5A0": "0x085413D0", + "0x084EC600": "0x08541430", + "0x084EC660": "0x08541490", + "0x084EC6C0": "0x085414F0", + "0x084EC6E4": "0x08541514", + "0x084EC708": "0x08541538", + "0x084EC72C": "0x0854155C", + "0x084EC750": "0x08541580", + "0x084EC774": "0x085415A4", + "0x084EC798": "0x085415C8", + "0x084EC7BC": "0x085415EC", + "0x084EC7E0": "0x08541610", + "0x084EC804": "0x08541634", + "0x084EC828": "0x08541658", + "0x084EC84C": "0x0854167C", + "0x084EC870": "0x085416A0", + "0x084EC8B0": "0x085416E0", + "0x084EC8F0": "0x08541720", + "0x084EC920": "0x08541750", + "0x084EC950": "0x08541780", + "0x084EC9A0": "0x085417D0", + "0x084EC9F0": "0x08541820", + "0x084ECA40": "0x08541870", + "0x084ECA90": "0x085418C0", + "0x084ECAE0": "0x08541910", + "0x084ECB30": "0x08541960", + "0x084ECB84": "0x085419B4", + "0x084ECB98": "0x085419C8", + "0x084ECBB0": "0x085419E0", + "0x084ECBB2": "0x085419E2", + "0x084ECBBC": "0x085419EC", + "0x084ECBC8": "0x085419F8", + "0x084ECBDC": "0x08541A0C", + "0x084ECC04": "0x08541A34", + "0x084ECC2C": "0x08541A5C", + "0x084ECE74": "0x08541CA4", + "0x084ECEB0": "0x08541CC0", "0x084ECF88": "0x08541F0C", "0x084ECFE8": "0x08541F6C", "0x084ED048": "0x08541FCC", @@ -2429,6 +4240,12 @@ "0x084EDC18": "0x08542B9C", "0x084EDCA8": "0x08542C2C", "0x084F0AC0": "0x08545A44", + "0x084F0B10": "0x08545A94", + "0x084F0C00": "0x08545B84", + "0x084F0C28": "0x08545BAC", + "0x084F0C30": "0x08545BB4", + "0x084F0C34": "0x08545BB8", + "0x084F0C8A": "0x08545C0E", "0x084F26E4": "0x08547668", "0x084F4818": "0x0854979C", "0x084F794C": "0x0854C8D0", @@ -2439,7 +4256,9 @@ "0x085060D4": "0x0855B058", "0x08508B54": "0x0855DAD8", "0x0850C6E8": "0x0856166C", + "0x0850CAA8": "0x08561A2C", "0x0850D4EC": "0x08562470", + "0x0850D500": "0x08562484", "0x0850DE28": "0x08562DAC", "0x0850EAC4": "0x08563A48", "0x0850ED20": "0x08563CA4", @@ -2452,6 +4271,8 @@ "0x08515FCC": "0x0856AF50", "0x08517220": "0x0856C1A4", "0x0851810C": "0x0856D090", + "0x085181C0": "0x0856D0A4", + "0x0851820A": "0x0856D4B0", "0x0851844E": "0x0856F468", "0x0851845C": "0x0856F478", "0x0851848C": "0x0856F4A8", @@ -2464,6 +4285,17 @@ "0x085185FC": "0x0856F618", "0x0851863C": "0x0856F658", "0x085186DC": "0x0856F6F8", + "0x085186EC": "0x0856F708", + "0x085186FC": "0x0856F718", + "0x08518724": "0x0856F740", + "0x08518754": "0x0856F770", + "0x08518768": "0x0856F784", + "0x085187B4": "0x0856F7D0", + "0x085187BC": "0x0856F7D8", + "0x0851883C": "0x0856F858", + "0x08518898": "0x0856F8B4", + "0x085188E8": "0x0856F904", + "0x085188F0": "0x0856F90C", "0x08518938": "0x0856F954", "0x08E3FB54": "0x08E1AB98" } diff --git a/tools/scripts/region_autofix.py b/tools/scripts/region_autofix.py new file mode 100644 index 00000000..eb9d541c --- /dev/null +++ b/tools/scripts/region_autofix.py @@ -0,0 +1,375 @@ +#!/usr/bin/env python3 +"""Search the regional layout macros (include/region.h) for shared EU functions. + +For each EU C function that the regional symbol table does not place yet, wraps integer literals +of its source in PLAYER_FIELD / SAVE_FIELD (and 0x14C in PLAYER_SIZE), recompiles the +-DREGION_ object of its module and keeps a rewrite only when the function then equals the +regional ROM outside relocations. The macros are the identity in the EU build, so EU output is +unchanged by construction; still run make compare, region_symbols.py and +make REGION= compare afterwards. + + python3 tools/scripts/region_autofix.py --max-diff 8 # all near candidates + python3 tools/scripts/region_autofix.py sub_0801DE60 sub_0801E0A0 # selected functions + python3 tools/scripts/region_autofix.py --dry-run ... # report only +""" +import argparse +import re +import subprocess +from pathlib import Path + +from elftools.elf.elffile import ELFFile +from rom_regions import ROOT, load_profiles +import region_build +import region_diff +import region_symbols + +LITERAL = re.compile(r'(? 1: + pending.append((text[span[0]:span[1]], level - 1)) + return spans + + +def is_resource(value): + return value >> 16 in (5, 6, 8) and (value & 0xFFFF) >= 4 + + +def code_literals(body): + text = True # text pointers go by many names; exactness decides + """[(start, end, value)] of integer literals outside comments/strings, not yet wrapped.""" + result, index = [], 0 + masked = re.sub(r'/\*.*?\*/|//[^\n]*|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'', + lambda m: ' ' * len(m[0]), body, flags=re.S) + for match in LITERAL.finditer(masked): + value = int(match[1], 0) + if WRAPPED.search(masked[:match.start()].rstrip()[-20:]): + continue + if 0x0A <= value <= SAVE_LIMIT or value in SIZES or is_resource(value) or (text and value == 2): + result.append((match.start(), match.end(), value)) + return result + + +def rewrite(body, literals, choice): + """choice: {literal index: macro name}""" + out, cursor = [], 0 + for index, (start, end, value) in enumerate(literals): + macro = choice.get(index) + if macro is None: + continue + out.append(body[cursor:start]) + out.append(macro if macro in WHOLE else '%s(%s)' % (macro, body[start:end])) + cursor = end + out.append(body[cursor:]) + return ''.join(out) + + +class Checker: + def __init__(self, region): + self.region = region + self.work = 'build/regions/%s/variant' % region + self.target = (ROOT / load_profiles()[region]['filename']).read_bytes() + + def compile(self, module): + obj = '%s/src/%s.o' % (self.work, module) + result = subprocess.run(['make', 'REGION=eu', 'BUILD=' + self.work, 'NAME=%s/shiningsoul2' % self.work, + 'NM_FLAGS=', 'REGION_CPPFLAGS=-DREGION_%s' % self.region.upper(), obj], + cwd=ROOT, capture_output=True, text=True) + return ROOT / obj if result.returncode == 0 else None + + def score(self, module, name, address): + """Differing halfwords of name in the module object against the regional ROM (None: no build).""" + obj = self.compile(module) + if obj is None: + return None + with obj.open('rb') as stream: + elf = ELFFile(stream) + text = elf.get_section_by_name('.text') + symbol = elf.get_section_by_name('.symtab').get_symbol_by_name(name) + if not symbol: + return None + start, size = int(symbol[0]['st_value']) & ~1, int(symbol[0]['st_size']) + data = text.data()[start:start + size] + relocs = region_symbols.object_relocations([obj]).get(name, []) + segments = region_symbols.masked_segments(size, relocs) + + def at(start): + target = self.target[start:][:size] + if len(target) != size: + return None + return sum(1 for a, b in segments for offset in range(a, b, 2) + if target[offset:offset + 2] != data[offset:offset + 2]) + best = at(address - region_build.ROM_BASE) + if best and segments: + # The guessed address can be off when literal pools or stride code changed size; + # accept an exact match of the rewritten function nearby. + first, end = max(segments, key=lambda seg: seg[1] - seg[0]) + if end - first >= 8: + base = address - region_build.ROM_BASE + low, high = max(0, base - SEARCH + first), base + SEARCH + end + position = self.target.find(data[first:end], low, high) + while position >= 0: + start = position - first + if not start & 1 and start != base and at(start) == 0: + return 0 + position = self.target.find(data[first:end], position + 1, high) + return best + + +def search(checker, module, name, address, log, apply_best=False): + path = ROOT / 'src' / (module + '.c') + original = path.read_text(encoding='utf-8') + span = function_span(original, name) + if span is None: + log('%s: definition not found in %s' % (name, path.name)) + return False + function_body = original[span[0]:span[1]] + spans = [span] + [item for item in helper_spans(original, function_body) + if item[1] <= span[0] or item[0] >= span[1]] + head, body, tail = '', original, '' + literals = [item for item in code_literals(original) + if any(start <= item[0] and item[1] <= end for start, end in spans)] + + applied = False + + def evaluate(choice): + path.write_text(head + rewrite(body, literals, choice) + tail, encoding='utf-8') + return checker.score(module, name, address) + + try: + best_choice = {} + best = evaluate(best_choice) + if best is None or best == 0: + log('%s: %s before rewriting, skipped' % (name, 'no build' if best is None else 'equal')) + return False + start = best + save_first = 'gUnk_030034E0' in function_body + item = re.search(r'0[xX][bB]0000|ITEM_KIND', function_body) is not None # item data records + enemy = True # enemy records often arrive as plain pointers; exactness decides + options = {} + for index, (_, _, value) in enumerate(literals): + if value in SIZES: + options.setdefault((SIZES[value], value), []).append(index) + if value == 2: + options.setdefault(('TEXT_HEADER', value), []).append(index) + continue + if is_resource(value): + options.setdefault(('RES_ID', value), []).append(index) + if item and 0x9C <= value < 0x100: + options.setdefault(('ITEM_FIELD', value), []).append(index) + if enemy and 0x206 <= value < ENEMY_STRIDE: + options.setdefault(('ENEMY_FIELD', value), []).append(index) + if value <= SAVE_LIMIT: + for macro in (('SAVE_FIELD', 'PLAYER_FIELD') if save_first else MACROS): + if macro == 'PLAYER_FIELD' and value >= PLAYER_STRIDE: + continue + options.setdefault((macro, value), []).append(index) + # Greedy over whole values first, then over single occurrences. + for granularity in ('value', 'single'): + # Whole-macro moves first (every candidate literal of one macro at once): offsets of + # one record often only match together. + whole = {} + for (macro, _), indices in options.items(): + whole.setdefault((macro, None), []).extend(indices) + # Offset-like literals only (after '+' or '['): stored values stay as they are. + offsets = [index for index in indices + if re.search(r'[+\[]\s*$', body[max(0, literals[index][0] - 8):literals[index][0]])] + if offsets: + whole.setdefault((macro, 'offsets'), []).extend(offsets) + moves = list(whole.items()) + list(options.items()) if granularity == 'value' else \ + [((macro, value), [index]) for (macro, value), indices in options.items() for index in indices] + improved = True + while improved and best: + improved = False + for (macro, _), indices in moves: + for remove in (False, True): + trial = dict(best_choice) + for index in indices: + if remove: + if trial.get(index) == macro: + del trial[index] + else: + trial[index] = macro + if trial == best_choice: + continue + score = evaluate(trial) + if score is not None and score < best: + best, best_choice, improved = score, trial, True + if not best: + break + if not best: + break + # Pairs of whole-value moves for near misses that need two macros at once + # (e.g. PLAYER_SIZE stride plus PLAYER_FIELD base, each worse alone). + values = list(options.items()) + if best and best <= PAIR_LIMIT and len(values) <= PAIR_OPTIONS: + for first in range(len(values)): + for second in range(first + 1, len(values)): + trial = dict(best_choice) + for (macro, _), indices in (values[first], values[second]): + for index in indices: + trial[index] = macro + if trial == best_choice: + continue + score = evaluate(trial) + if score is not None and score < best: + best, best_choice = score, trial + if not best: + break + if not best: + break + if best == 0: + path.write_text(head + rewrite(body, literals, best_choice) + tail, encoding='utf-8') + applied = True + log('%s: fixed (%d -> 0) with %s' % (name, start, ', '.join(sorted( + {'%s(0x%X)' % (best_choice[i], literals[i][2]) if not best_choice[i] in WHOLE + else best_choice[i] for i in best_choice})))) + return True + if apply_best and best is not None and best < start: + path.write_text(head + rewrite(body, literals, best_choice) + tail, encoding='utf-8') + applied = True + log('%s: best %d (from %d), %s%s' % (name, best, start, 'applied' if applied else 'not applied', ''.join( + ' with %s at line %d' % (best_choice[i] if best_choice[i] in WHOLE else '%s(0x%X)' % (best_choice[i], literals[i][2]), + original.count('\n', 0, literals[i][0]) + 1) for i in sorted(best_choice)))) + return False + finally: + if not applied: + path.write_text(original, encoding='utf-8') + checker.compile(module) + + +# Rewrites that match a regional twin elsewhere and displace correctly placed neighbours. +SKIP = {'sub_080663A4'} # USA usa_sub_08067CA4 keeps the EU stride far from this function + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('--region', choices=('usa', 'jp'), default='usa') + parser.add_argument('--max-diff', type=int, default=8) + parser.add_argument('--max-size', type=int, default=4096) + parser.add_argument('--dry-run', action='store_true') + parser.add_argument('--apply-best', action='store_true', help='also keep the best non-exact rewrite') + parser.add_argument('--addresses', help='file of "NAME 0xADDR" lines overriding the guessed regional address') + parser.add_argument('funcs', nargs='*') + args = parser.parse_args(argv) + known = {} + if args.addresses: + for line in open(args.addresses): + words = line.split() + names = [word for word in words if word.startswith('sub_')] + values = [word for word in words if word.startswith('0x')] + if names and values: + known[names[0]] = int(values[-1], 16) + if args.region != 'usa': + parser.exit(1, 'Only the USA layout is described in include/region.h\n') + target_rom = (ROOT / load_profiles()[args.region]['filename']).read_bytes() + symbols, fragments, eu_address, relocations, placed, keys = region_diff.candidates(args.region) + done = {eu for eu, _ in placed} + checker = Checker(args.region) + rows = [] + for fragment in fragments: + eu = eu_address.get(fragment.name) + if eu is None or eu in done or fragment.name not in relocations: + continue + if args.funcs and fragment.name not in args.funcs: + continue + if fragment.name in SKIP and fragment.name not in args.funcs: + continue + if len(fragment.data) > args.max_size: + continue + if eu == fragment.address and target_rom[eu - region_build.ROM_BASE:][:len(fragment.data)] == fragment.data: + continue + relocs = relocations[fragment.name] + guesses = region_diff.guesses(fragment, eu, placed, keys, relocs, target_rom) + if fragment.name in known: + guesses = [known[fragment.name]] + address = min(guesses, key=lambda item: region_diff.difference(fragment, relocs, target_rom, item)) + diff = region_diff.difference(fragment, relocs, target_rom, address) + if diff and (args.funcs or diff <= args.max_diff): + rows.append((diff, fragment.name, fragment.module, address)) + rows.sort() + fixed = 0 + for diff, name, module, address in rows: + if args.dry_run: + print('%4d %-40s %-16s 0x%08X' % (diff, name, module, address)) + continue + fixed += search(checker, module, name, address, print, args.apply_best) + if not args.dry_run: + print('%d of %d functions rewritten' % (fixed, len(rows))) + + +if __name__ == '__main__': + main() diff --git a/tools/scripts/region_build.py b/tools/scripts/region_build.py index dc5c16c4..8b54dbaf 100644 --- a/tools/scripts/region_build.py +++ b/tools/scripts/region_build.py @@ -4,6 +4,7 @@ from dataclasses import dataclass import hashlib import json +import os from pathlib import Path import re import shutil @@ -184,6 +185,22 @@ def linked_symbols_and_fragments(elf_path, assembly_dir): return symbols, fragments +def variant_build(region): + """Build the EU sources once more with -DREGION_USA / -DREGION_JP, in the EU link order. + + Shared C can describe a regional layout difference under #ifdef REGION_ (for example + the 0x158-byte USA player record). Relocated functions are taken from this build; without such + blocks it is byte-identical to EU. Returns (elf, assembly dir, linked symbols, fragments). + """ + work = 'build/regions/%s/variant' % region + run(['make', 'REGION=eu', 'BUILD=' + work, 'NAME=%s/shiningsoul2' % work, 'NM_FLAGS=', + 'REGION_CPPFLAGS=-DREGION_%s' % region.upper(), '-j%d' % (os.cpu_count() or 1), 'all'], + ROOT / ('build/regions/%s/variant.log' % region)) + elf, assembly = ROOT / work / 'shiningsoul2.elf', ROOT / work / 'src' + symbols, fragments = linked_symbols_and_fragments(elf, assembly) + return elf, assembly, symbols, fragments + + REGION_SYMBOL = re.compile(r'(?Pusa|jp)_(?Psub|gUnk)_(?P
[0-9A-F]{8})') GAME_CC1 = ['tools/agbcc/bin/agbcc', '-mthumb-interwork', '-Wimplicit', '-Wparentheses', '-O2', '-fhex-asm', '-fprologue-bugfix'] @@ -245,14 +262,15 @@ def region_only_fragments(region, target_rom, out, prefix='arm-none-eabi-'): return fragments, symbols, references & called -def relocated_fragments(region, fragments, selected, target_rom, eu_symbols): +def relocated_fragments(region, fragments, selected, target_rom, eu_symbols, variant=()): """EU C functions that a regional ROM keeps with identical code at another address. tools/config/region_symbols_.json (written by region_symbols.py) maps the EU address of each such function to its regional address, and the EU value of every symbol it references to the regional value. The EU compiler assembly is reused unchanged except that those references (and the function's own label) are renamed into a ___ namespace, so the EU values stay - available to same-address fragments. Returns (fragments, symbols, called names). + available to same-address fragments. The assembly comes from the -DREGION_ build + (variant_build) when one is given. Returns (fragments, symbols, called names). """ path = ROOT / 'tools/config' / ('region_symbols_%s.json' % region) if not path.exists(): @@ -263,6 +281,7 @@ def relocated_fragments(region, fragments, selected, target_rom, eu_symbols): functions = {int(eu, 16): int(value, 16) for eu, value in table['functions'].items()} values = {int(eu, 16): int(value, 16) for eu, value in table['symbols'].items()} by_address = {fragment.address: fragment for fragment in fragments} + regional_form = {fragment.name: fragment for fragment in variant} taken = {fragment.name for fragment in selected} prefix = '__%s_' % region result, symbols, called = [], {}, set() @@ -272,6 +291,7 @@ def relocated_fragments(region, fragments, selected, target_rom, eu_symbols): raise RegionError('%s places 0x%08X, which is not an EU C function' % (path.name, eu)) if fragment.name in taken: continue + fragment = regional_form.get(fragment.name, fragment) tokens = set(re.findall(r'(?__bl alias. + data_refs = set(re.findall(r'^\s*\.word\s+(' + IDENTIFIER + r')\s*$', layout, re.M)) + for name in sorted(calls & data_refs): + layout = re.sub(r'(?m)^(\s*bl\s+)%s(\s*)$' % re.escape(name), r'\g<1>%s__bl\g<2>' % name, layout) + symbols[name + '__bl'] = symbols[name] + calls = {name + '__bl' if name in data_refs else name for name in calls} + thumb_targets = thumb_call_targets(calls, symbols) layout += thumb_targets set_names = set(re.findall(r'^\.thumb_set (\S+),', thumb_targets, re.M)) assembly_path, script_path = out / 'layout.s', out / 'layout.ld' diff --git a/tools/scripts/region_diff.py b/tools/scripts/region_diff.py new file mode 100644 index 00000000..00e949c4 --- /dev/null +++ b/tools/scripts/region_diff.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python3 +"""Show how far EU C functions are from their regional form (aid for #ifdef REGION_ work). + +Without FUNC: lists the EU C functions the regional symbol table does not place yet, with the +address guessed from the shift of the placed functions around them and the number of differing +halfwords outside relocations (fewest first). With FUNC: prints a disassembly diff of the +-DREGION_ build of FUNC against the regional ROM. + +Uses the existing build/regions//variant build; run region_symbols.py (or +make REGION= compare) first to refresh it. +""" +import argparse +import bisect +import difflib +import json +import struct +import subprocess +import tempfile +from pathlib import Path + +from rom_regions import ROOT, load_profiles +import region_build +import region_symbols + + +def candidates(region): + work = ROOT / 'build/regions' / region / 'variant' + elf = work / 'shiningsoul2.elf' + if not elf.exists(): + raise SystemExit('Missing %s; run region_symbols.py --region %s first' % (elf, region)) + symbols, fragments = region_build.linked_symbols_and_fragments(elf, work / 'src') + _, eu_fragments = region_build.linked_symbols_and_fragments(ROOT / 'shiningsoul2_eu.elf', ROOT / 'build/src') + eu_address = {fragment.name: fragment.address for fragment in eu_fragments} + relocations = region_symbols.object_relocations(sorted((work / 'src').glob('*.o'))) + table = json.loads(region_symbols.table_path(region).read_text(encoding='utf-8')) + placed = sorted((int(eu, 16), int(address, 16)) for eu, address in table['functions'].items()) + keys = [eu for eu, _ in placed] + return symbols, fragments, eu_address, relocations, placed, keys + + +def guesses(fragment, eu, placed, keys, relocs=None, target_rom=None, radius=0x100): + """Regional addresses to try for fragment: the shift of the placed neighbours and, given the + regional ROM, every nearby address where the function's leading bytes recur (literal pools + of the functions in between may have changed size).""" + index = bisect.bisect_left(keys, eu) + result = [] + for item in (index - 1, index): + if 0 <= item < len(placed): + address = fragment.address + placed[item][1] - placed[item][0] + if address not in result: + result.append(address) + result = result or [fragment.address] + if target_rom is None: + return result + segments = region_symbols.masked_segments(len(fragment.data), relocs or []) + if not segments: + return result + first, end = segments[0] + needle = fragment.data[first:min(end, first + 6)] + if len(needle) < 4: + return result + extra = [] + for base in result: + low = max(0, base - radius - region_build.ROM_BASE + first) + high = base + radius - region_build.ROM_BASE + first + len(needle) + position = target_rom.find(needle, low, high) + while position >= 0: + address = position - first + region_build.ROM_BASE + if not address & 1 and address not in result and address not in extra: + extra.append(address) + position = target_rom.find(needle, position + 2, high) + # Neighbours may be shifted differently (a regional block moved): also try every place in the + # whole ROM where one of the longest unrelocated runs recurs. + for start, end in sorted(segments, key=lambda seg: seg[0] - seg[1])[:3]: + needle = fragment.data[start:min(end, start + 16)] + if len(needle) < 8: + continue + position, count = target_rom.find(needle), 0 + while position >= 0 and count < 20: + address = position - start + region_build.ROM_BASE + if not address & 1 and address not in result and address not in extra: + extra.append(address) + position, count = target_rom.find(needle, position + 2), count + 1 + return result + extra + + +def difference(fragment, relocs, target_rom, address): + data = target_rom[address - region_build.ROM_BASE:][:len(fragment.data)] + return sum(1 for start, end in region_symbols.masked_segments(len(fragment.data), relocs) + for offset in range(start, end, 2) if data[offset:offset + 2] != fragment.data[offset:offset + 2]) + + +def disassemble(data, address, prefix): + with tempfile.NamedTemporaryFile(suffix='.bin') as stream: + stream.write(data) + stream.flush() + text = subprocess.run([prefix + 'objdump', '-D', '-b', 'binary', '-marmv4t', '-Mforce-thumb', + '--adjust-vma=0x%x' % address, stream.name], + capture_output=True, text=True, check=True).stdout + lines = [] + for line in text.splitlines(): + parts = line.split('\t') + if len(parts) >= 3 and parts[0].strip().endswith(':'): + lines.append('%s %s' % (parts[1].strip(), ' '.join(parts[2:]))) + return lines + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('--region', choices=('usa', 'jp'), default='usa') + parser.add_argument('func', nargs='?') + parser.add_argument('--address', type=lambda text: int(text, 16), help='regional address of FUNC') + parser.add_argument('--limit', type=int, default=60) + parser.add_argument('--prefix', default='arm-none-eabi-') + args = parser.parse_args(argv) + target_rom = (ROOT / load_profiles()[args.region]['filename']).read_bytes() + symbols, fragments, eu_address, relocations, placed, keys = candidates(args.region) + done = {eu for eu, _ in placed} + if args.func: + fragment = next((item for item in fragments if item.name == args.func), None) + if fragment is None: + raise SystemExit('%s is not a C function' % args.func) + relocs = relocations.get(fragment.name, []) + options = [args.address] if args.address else guesses(fragment, eu_address[fragment.name], placed, keys, + relocs, target_rom) + address = min(options, key=lambda item: difference(fragment, relocs, target_rom, item)) + data = target_rom[address - region_build.ROM_BASE:][:len(fragment.data)] + print('%s: EU 0x%08X, %s 0x%08X, %d bytes, %d differing halfwords outside relocations%s' + % (fragment.name, eu_address[fragment.name], args.region, address, len(fragment.data), + difference(fragment, relocs, target_rom, address), + ' (placed)' if eu_address[fragment.name] in done else '')) + counted = ['+0x%X: %s -> %s' % (offset, fragment.data[offset:offset + 2][::-1].hex(), + data[offset:offset + 2][::-1].hex()) + for start, end in region_symbols.masked_segments(len(fragment.data), relocs) + for offset in range(start, end, 2) if data[offset:offset + 2] != fragment.data[offset:offset + 2]] + if counted: + print('counted: ' + ', '.join(counted)) + mine = disassemble(fragment.data, address, args.prefix) + theirs = disassemble(data, address, args.prefix) + for line in difflib.unified_diff(mine, theirs, 'variant', args.region, n=2, lineterm=''): + print(line) + return + rows = [] + for fragment in fragments: + eu = eu_address.get(fragment.name) + if eu is None or eu in done or fragment.name not in relocations: + continue + if eu == fragment.address and target_rom[eu - region_build.ROM_BASE:][:len(fragment.data)] == fragment.data: + continue # same address and bytes: taken unchanged + relocs = relocations[fragment.name] + best = min(guesses(fragment, eu, placed, keys, relocs, target_rom), + key=lambda item: difference(fragment, relocs, target_rom, item)) + rows.append((difference(fragment, relocs, target_rom, best), len(fragment.data), fragment.name, + fragment.module, best)) + rows.sort() + for diff, size, name, module, address in rows[:args.limit]: + print('%4d %5d %-40s %-16s 0x%08X' % (diff, size, name, module, address)) + print('%d unplaced EU C functions, %d bytes' % (len(rows), sum(row[1] for row in rows))) + + +if __name__ == '__main__': + main() diff --git a/tools/scripts/region_permute.py b/tools/scripts/region_permute.py new file mode 100644 index 00000000..f764e9bf --- /dev/null +++ b/tools/scripts/region_permute.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +"""Run decomp-permuter on a shared EU function against its regional ROM bytes. + + python3 tools/scripts/region_permute.py FUNC REGIONAL_ADDR [--region usa] [--time S] [--jobs N] [--dir D] + +For register/stack-slot near misses of the -DREGION_ build (region_diff.py reports the +difference). The source is preprocessed with -DREGION_; target.o is the control object of +that source with the function bytes replaced by the regional ROM bytes everywhere except relocation +sites, so relocations (bl targets, literal pool symbols) compare equal. This only works when the +compiled function and the regional function have the same size. Stack differences are scored +(--stack-diffs). The best result is printed as a permuter output directory; transfer the change into +an #ifdef REGION_ block by hand and verify with region_symbols.py / make REGION= compare. +""" +import argparse +import glob +import json +import os +import re +import subprocess +import sys +import tempfile +import time + +ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) +ap.add_argument("func") +ap.add_argument("addr") +ap.add_argument("--region", default="usa") +ap.add_argument("--time", type=int, default=600, help="seconds; 0 only builds the directory") +ap.add_argument("--jobs", type=int, default=4) +ap.add_argument("--dir") +args = ap.parse_args() + +os.environ["DECOMP_CPPFLAGS"] = (os.environ.get("DECOMP_CPPFLAGS", "") + " -DREGION_%s" % args.region.upper()).strip() +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import decomp # noqa: E402 +import permute # noqa: E402 +from process_tree import run_in_process_tree # noqa: E402 +from rom_regions import ROOT, load_profiles # noqa: E402 +from elftools.elf.elffile import ELFFile # noqa: E402 +from elftools.elf.relocation import RelocationSection # noqa: E402 + +func, addr = args.func, int(args.addr, 16) +mod = decomp.module_of_addr(decomp.func_address(func)) +cfile = os.path.join(str(ROOT), "src", mod + ".c") +d = args.dir or tempfile.mkdtemp(prefix="rperm_%s_" % func) +permute.setup(func, cfile, d) + +sys.path.insert(0, permute.PERMUTER) +from src.candidate import Candidate # noqa: E402 +from src.helpers import get_default_randomization_weights # noqa: E402 +from src.perm.parse import perm_parse # noqa: E402 +from src.perm.perm import EvalState # noqa: E402 + +settings = json.load(open(os.path.join(d, "control-settings.json"))) +perm = perm_parse(open(os.path.join(d, "base.c")).read()) +state = EvalState() +candidate = Candidate.from_source(perm.evaluate(0, state), state, settings["c_name"], + get_default_randomization_weights("gcc"), 0) +open(os.path.join(d, "control.c"), "w").write(candidate.get_source()) +control = os.path.join(d, "control.o") +result = subprocess.run(["sh", os.path.join(d, "compile.sh"), os.path.join(d, "control.c"), "-o", control], + capture_output=True, text=True) +if result.returncode: + sys.exit("control compile failed\n" + result.stdout + result.stderr) + +rom = (ROOT / load_profiles()[args.region]["filename"]).read_bytes() +data = bytearray(open(control, "rb").read()) +with open(control, "rb") as handle: + elf = ELFFile(handle) + text = elf.get_section_by_name(".text") + symtab = elf.get_section_by_name(".symtab") + symbol = [s for s in symtab.iter_symbols() + if s.name in (settings["c_name"], func) and s["st_info"]["type"] == "STT_FUNC"][0] + start = symbol["st_value"] & ~1 + later = sorted(s["st_value"] & ~1 for s in symtab.iter_symbols() + if s["st_info"]["type"] == "STT_FUNC" and (s["st_value"] & ~1) > start) + end = later[0] if later else text["sh_size"] + masked = set() + for section in elf.iter_sections(): + if isinstance(section, RelocationSection) and section.name in (".rel.text", ".rela.text"): + for relocation in section.iter_relocations(): + masked.update(range(relocation["r_offset"], relocation["r_offset"] + 4)) + offset = text["sh_offset"] +regional = rom[addr - 0x08000000:addr - 0x08000000 + end - start] +changed = 0 +for i in range(end - start): + if start + i not in masked and data[offset + start + i] != regional[i]: + data[offset + start + i] = regional[i] + changed += 1 +target = os.path.join(d, "target.o") +open(target, "wb").write(bytes(data)) +if symbol.name != settings["c_name"]: + # The permuter looks functions up by their C name. + subprocess.run(["arm-none-eabi-objcopy", "--redefine-sym", "%s=%s" % (symbol.name, settings["c_name"]), target], + check=True) + with open(os.path.join(d, "compile.sh"), "a") as script: + script.write('arm-none-eabi-objcopy --redefine-sym %s=%s "$3"\n' % (symbol.name, settings["c_name"])) +print("%s: %d differing bytes over %d (target %s)" % (func, changed, end - start, d)) +if args.time <= 0: + sys.exit(0) +deadline = time.time() + args.time +while time.time() < deadline - 30 and not glob.glob(os.path.join(d, "output-0-*")): + try: # the permuter occasionally dies on an AST assertion; restart it until the deadline + run_in_process_tree([sys.executable, "-u", os.path.join(permute.PERMUTER, "permuter.py"), d, "-j", str(args.jobs), + "--stop-on-zero", "--best-only", "--quiet", "--stack-diffs"], + timeout=deadline - time.time()) + except subprocess.TimeoutExpired: + break +outputs = sorted(glob.glob(os.path.join(d, "output-*")), + key=lambda p: int(p.split("-")[-2]) if p.split("-")[-2].isdigit() else 10 ** 9) +print("best:", outputs[0] if outputs else "none") diff --git a/tools/scripts/region_structs.py b/tools/scripts/region_structs.py new file mode 100644 index 00000000..ccd29bb9 --- /dev/null +++ b/tools/scripts/region_structs.py @@ -0,0 +1,349 @@ +#!/usr/bin/env python3 +"""Give player-record struct views their regional layout (include/region.h). + +Sources describe the 0x14C-byte player record with many local views such as + struct RemovePlayer019 { u8 pad[0x34]; struct RemoveEntry019 *entries; u8 tail[0x114]; }; +This tool computes the EU layout of each struct of exactly 0x14C bytes, keeps every named member +and rewrites only the dimensions of its pad arrays (names pad*/unk*/gap*/tail*/fill*/rest* or p) so +that member o lands at PLAYER_FIELD(o) and the struct is PLAYER_SIZE bytes: + struct RemovePlayer019 { u8 pad[PLAYER_FIELD(0x34)]; ...; u8 tail[PLAYER_SIZE - PLAYER_FIELD(0x38)]; }; +In the EU build the expressions keep their values. A rewrite is kept only if, in the +-DREGION_ object of the module, no exact function is lost and the module's total difference +from the regional ROM bytes decreases (follow with region_autofix.py for the remaining literals). Run make compare, region_symbols.py and make REGION= compare afterwards. + + python3 tools/scripts/region_structs.py [--dry-run] [MODULE ...] +""" +import argparse +import re +from pathlib import Path + +from elftools.elf.elffile import ELFFile +from rom_regions import ROOT, load_profiles +import region_build +import region_diff +import region_symbols +from region_autofix import Checker + +EU_SIZE, USA_SIZE = 0x14C, 0x158 + + +class Record: + def __init__(self, eu_size, usa_size, field, size, mapping): + self.eu_size, self.usa_size, self.field, self.size, self.map = eu_size, usa_size, field, size, mapping + + +def enemy_field(offset): + return offset if offset < 0x206 else offset + 0x174 + + +# Record kinds by EU size: player record and enemy actor record (include/region.h). +RECORDS = {0x14C: None, 0x2E0: None} +PAD = re.compile(r'^(pad|unk|gap|tail|fill|rest|_|p[0-9A-Fa-f]+$|u[0-9A-Fa-f]+$|x[0-9A-Fa-f]+$)', re.I) +BASE = {'u8': 1, 's8': 1, 'char': 1, 'bool8': 1, 'vu8': 1, 'vs8': 1, + 'u16': 2, 's16': 2, 'short': 2, 'vu16': 2, 'vs16': 2, 'bool16': 2, + 'u32': 4, 's32': 4, 'int': 4, 'long': 4, 'unsigned': 4, 'signed': 4, 'float': 4, + 'vu32': 4, 'vs32': 4, 'bool32': 4, 'fixed': 4, 'size_t': 4} + + +def usa_field(offset): + return offset if offset < 0x0C else offset + 10 if offset < 0x2A else offset + 12 + + +RECORDS[0x14C] = Record(0x14C, 0x158, 'PLAYER_FIELD', 'PLAYER_SIZE', usa_field) +RECORDS[0x2E0] = Record(0x2E0, 0x454, 'ENEMY_FIELD', 'ENEMY_SIZE', enemy_field) + + +def strip_comments(text): + return re.sub(r'/\*.*?\*/|//[^\n]*', lambda m: ' ' * len(m[0]), text, flags=re.S) + + +def evaluate(expr): + expr = expr.strip() + if not re.fullmatch(r'[0-9a-fA-FxX+\-*/() ]+', expr): + return None + try: + return int(eval(re.sub(r'(?', kind.eu_size, 0, 1, None, 1, False)]: + if is_pad: + continue + target = kind.usa_size if name == '' else kind.map(offset) + if target % align: + return None + # Pads between the previous real member (or start) and this one take up the difference. + between = [item for item in pads if (previous[0] + previous[1] if previous else 0) <= item[1] < offset] + if name == '' and not between and getattr(kind, 'partial', False): + break # a prefix view: the compiler sizes the tail + eu_gap = sum(item[2] for item in between) + usa_gap = target - usa_offset + if between: + if usa_gap < 0 or usa_gap == eu_gap and target == offset: + usa_offset = target + size + previous = (offset, size) + continue + if len(between) != 1 or usa_gap % between[0][5]: + return None + pad = between[0] + if previous is None: + start = '0' + else: + end = previous[0] + previous[1] + field = kind.field if kind.map(end) != end or kind.map(previous[0]) != previous[0] else None + if field is None: + start = '0x%X' % end + else: + start = '%s(0x%X)' % (field, end) if kind.map(end) == kind.map(previous[0]) + previous[1] \ + else '(%s(0x%X) + 0x%X)' % (field, previous[0], previous[1]) + stop = kind.size if name == '' else ('%s(0x%X)' % (kind.field, offset) + if kind.map(offset) != offset else '0x%X' % offset) + expr = stop if start == '0' else '%s - %s' % (stop, start) + if pad[5] != 1: + expr = '(%s) / %d' % (expr, pad[5]) + new[pad[4]] = expr + elif usa_gap != 0: + return None + usa_offset = target + size + previous = (offset, size) + return new or None + + +def save_field(offset): + return offset if offset < 0x0A else offset + 10 if offset < 0x10 else offset + 12 + + +PARTIAL = (('PLAYER_FIELD', usa_field, 0x14C), ('SAVE_FIELD', save_field, 0x1000), + ('ENEMY_FIELD', enemy_field, 0x2E0)) + + +_HEADER_SIZES = None + + +def header_sizes(): + """Sizes of the structs defined in include/*.h (members of module structs may use them).""" + global _HEADER_SIZES + if _HEADER_SIZES is None: + _HEADER_SIZES = {} + for path in sorted((ROOT / 'include').glob('*.h')): + text = path.read_text(encoding='utf-8', errors='replace') + for name, start, end in struct_definitions(text): + try: + _HEADER_SIZES[name] = members(text[start:end], _HEADER_SIZES)[1] + except Exception: + continue + return _HEADER_SIZES + + +def player_views(text, partial=False): + """[(view key, {dim span: expression}, partial)] for rewritable record structs of text: structs of + exactly a record size, and with partial=True also smaller structs read as a prefix view of a + player, save or enemy record (their end maps through the field macro).""" + sizes, views = dict(header_sizes()), [] + for name, start, end in struct_definitions(text): + try: + layout, size = members(text[start:end], sizes) + except Layout: + continue + sizes[name] = size + kinds = [] + if size[0] in RECORDS: + kinds.append((name, RECORDS[size[0]], False)) + elif partial: + for field, mapping, limit in PARTIAL: + if size[0] <= limit and mapping(size[0]) != size[0]: + kind = Record(size[0], mapping(size[0]), field, '%s(0x%X)' % (field, size[0]), mapping) + kind.partial = True + kinds.append(('%s as %s' % (name, field), kind, True)) + for key, kind, is_partial in kinds: + dims = regional_dims(layout, kind) + if dims: + views.append((key, {(start + a, start + b): expr for (a, b), expr in dims.items()}, is_partial)) + return views + + +def module_scores(checker, module, table): + obj = checker.compile(module) + if obj is None: + return None + relocs = region_symbols.object_relocations([obj]) + scores = {} + with obj.open('rb') as stream: + elf = ELFFile(stream) + text = elf.get_section_by_name('.text').data() + for symbol in elf.get_section_by_name('.symtab').iter_symbols(): + if symbol['st_info']['type'] != 'STT_FUNC' or symbol.name not in table: + continue + start, size = int(symbol['st_value']) & ~1, int(symbol['st_size']) + data = text[start:start + size] + best = None + for address in table[symbol.name]: + target = checker.target[address - region_build.ROM_BASE:][:size] + if len(target) != size: + continue + diff = sum(1 for a, b in region_symbols.masked_segments(size, relocs.get(symbol.name, [])) + for offset in range(a, b, 2) if target[offset:offset + 2] != data[offset:offset + 2]) + best = diff if best is None else min(best, diff) + if best is not None: + scores[symbol.name] = best + return scores + + +def addresses(region): + target_rom = (ROOT / load_profiles()[region]['filename']).read_bytes() + symbols, fragments, eu_address, relocations, placed, keys = region_diff.candidates(region) + known = dict(placed) + table = {} + for fragment in fragments: + eu = eu_address.get(fragment.name) + if eu is None: + continue + table[fragment.name] = [known[eu]] if eu in known else region_diff.guesses( + fragment, eu, placed, keys, relocations.get(fragment.name), target_rom) + return table + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('--region', choices=('usa',), default='usa') + parser.add_argument('--dry-run', action='store_true') + parser.add_argument('--partial', action='store_true', + help='also try smaller structs as prefix views (kept only with an exact gain)') + parser.add_argument('modules', nargs='*') + args = parser.parse_args(argv) + checker = Checker(args.region) + table = addresses(args.region) + paths = [ROOT / 'src' / (m + '.c') for m in args.modules] if args.modules else sorted((ROOT / 'src').glob('*.c')) + total = 0 + for path in paths: + module = path.stem + tried, baseline = set(), None + while True: + text = path.read_text(encoding='utf-8') + candidate = next((item for item in player_views(text, args.partial) if item[0] not in tried), None) + if candidate is None: + break + name, dims, is_partial = candidate + tried.add(name) + if args.dry_run: + print('%s: struct %s: %s' % (module, name, '; '.join(dims.values()))) + continue + if baseline is None: + baseline = module_scores(checker, module, table) + if baseline is None: + print('%s: no build' % module) + break + updated = text + for (a, b), expr in sorted(dims.items(), reverse=True): + updated = updated[:a] + expr + updated[b:] + path.write_text(updated, encoding='utf-8') + scores = module_scores(checker, module, table) + # No exact function is lost and the module as a whole moves closer to the regional bytes. + lost = scores is None or any(baseline[f] == 0 and scores.get(f) != 0 for f in baseline) or \ + sum(scores.values()) >= sum(baseline.values()) + closer = 0 if scores is None else sum(1 for f in scores if scores[f] < baseline.get(f, 1 << 30)) + gained = 0 if scores is None else sum(1 for f in scores if scores[f] == 0 and baseline.get(f) != 0) + if lost or not closer or (is_partial and not gained): + path.write_text(text, encoding='utf-8') + print('%s: struct %s: %s' % (module, name, 'no build' if scores is None else + 'loses functions' if lost else 'no gain')) + continue + baseline = scores + total += gained + print('%s: struct %s: %d functions closer, +%d exact' % (module, name, closer, gained)) + checker.compile(module) + print('%d functions gained' % total) + + +if __name__ == '__main__': + main() diff --git a/tools/scripts/region_symbols.py b/tools/scripts/region_symbols.py index ef0e6769..6886eacd 100644 --- a/tools/scripts/region_symbols.py +++ b/tools/scripts/region_symbols.py @@ -22,6 +22,7 @@ hash to match, so a wrong entry cannot be admitted silently. Run after a normal EU `make compare`. """ import argparse +import bisect from collections import defaultdict import json from pathlib import Path @@ -32,7 +33,7 @@ from rom_regions import ROOT, RegionError, load_profiles, verify_rom import region_build -ABS32, THM_CALL, THM_PC22 = 2, 10, 30 +ABS32, THM_CALL, THM_PC22, THM_JUMP11, THM_JUMP8 = 2, 10, 30, 102, 103 WINDOW = 0x4000 MIN_SIZE = 8 @@ -83,6 +84,20 @@ def bl_target(rom, address): return address + 4 + offset +def branch_target(rom, address, kind): + """Target of a Thumb B (JUMP11) or conditional B (JUMP8) at address, or None.""" + (half,) = struct.unpack_from(' build of the EU sources (region_build.variant_build) with the + regional ROM; keys are translated to EU addresses by name.""" target_rom = Path(rom).read_bytes() rom_end = region_build.ROM_BASE + len(target_rom) - symbols, fragments = region_build.linked_symbols_and_fragments(ROOT / 'shiningsoul2_eu.elf', - ROOT / 'build/src') - relocations = object_relocations(sorted((ROOT / 'build/src').glob('*.o'))) + eu_symbols, eu_fragments = region_build.linked_symbols_and_fragments(ROOT / 'shiningsoul2_eu.elf', + ROOT / 'build/src') + elf, assembly, symbols, fragments = region_build.variant_build(region) + eu_rom = elf.with_suffix('.gba').read_bytes() + relocations = object_relocations(sorted(assembly.glob('*.o'))) + eu_addresses = {fragment.name: fragment.address for fragment in eu_fragments} + # EU functions the regional build already takes unchanged at their EU address. + shared = {fragment.name for fragment in eu_fragments if len(fragment.data) >= 8 and target_rom[ + fragment.address - region_build.ROM_BASE:][:len(fragment.data)] == fragment.data} + + def same(fragment, address): + return fragment.name in shared and address == eu_addresses[fragment.name] placed, needs = {}, {} delta = 0 placed_end = region_build.ROM_BASE for fragment in sorted(fragments, key=lambda item: item.address): relocs = relocations.get(fragment.name) - if relocs is None or not self_contained(fragment, relocs, symbols): + if relocs is None: continue expected = fragment.address + delta found = resolve(fragment, relocs, symbols, eu_rom, target_rom, expected) @@ -174,9 +213,7 @@ def derive(rom): delta = address - fragment.address if found is None: continue - same = address == fragment.address and \ - target_rom[address - region_build.ROM_BASE:][:len(fragment.data)] == fragment.data - if same: + if same(fragment, address): continue placed[fragment.name] = address needs[fragment.name] = found @@ -188,22 +225,78 @@ def derive(rom): called[symbol] |= value for fragment in fragments: relocs = relocations.get(fragment.name) - if fragment.name in placed or relocs is None or not self_contained(fragment, relocs, symbols) or len(called.get(fragment.name, ())) != 1: + if fragment.name in placed or relocs is None or len(called.get(fragment.name, ())) != 1: continue address = next(iter(called[fragment.name])) & ~1 found = resolve(fragment, relocs, symbols, eu_rom, target_rom, address) - if found is not None and not (address == fragment.address and target_rom[ - address - region_build.ROM_BASE:][:len(fragment.data)] == fragment.data): + if found is not None and not same(fragment, address): placed[fragment.name] = address needs[fragment.name] = found + # The running delta misses functions after a run of regional differences; retry each remaining + # function with the shift of the placed functions on either side of it. + sizes = {fragment.name: len(fragment.data) for fragment in fragments} + by_name = {fragment.name: fragment for fragment in fragments} + ordered = sorted(placed, key=lambda name: by_name[name].address) + for fragment in fragments: + relocs = relocations.get(fragment.name) + if fragment.name in placed or relocs is None: + continue + eu_order = [by_name[name].address for name in ordered] + index = bisect.bisect_left(eu_order, fragment.address) + neighbours = [ordered[item] for item in (index - 1, index) if 0 <= item < len(ordered)] + candidates = [] + for name in neighbours: + address = fragment.address + placed[name] - by_name[name].address + low = placed[neighbours[0]] + sizes[neighbours[0]] if index > 0 else region_build.ROM_BASE + high = placed[neighbours[-1]] if index < len(ordered) else rom_end + if address in candidates or not low <= address or address + len(fragment.data) > high: + continue + if same(fragment, address): + continue + found = resolve(fragment, relocs, symbols, eu_rom, target_rom, address) + if found is not None: + candidates.append(address) + result = found + if not candidates and len(fragment.data) >= MIN_SIZE: + # Twins elsewhere in the ROM defeat the window search; scan the gap between the placed + # neighbours and keep the match whose shift is closest to theirs (the whole-ROM hash + # check still rejects a wrong choice). + low = placed[neighbours[0]] + sizes[neighbours[0]] if index > 0 else region_build.ROM_BASE + high = placed[neighbours[-1]] if index < len(ordered) else rom_end + shifts = [placed[name] - by_name[name].address for name in neighbours] + segments = masked_segments(len(fragment.data), relocs) + hits = [] + if segments and shifts: + first, end = max(segments, key=lambda seg: seg[1] - seg[0]) + needle = fragment.data[first:end] + position = target_rom.find(needle, low - region_build.ROM_BASE + first, + high - region_build.ROM_BASE) + while position >= 0: + address = position - first + region_build.ROM_BASE + if not address & 1 and address + len(fragment.data) <= high and not same(fragment, address): + found = resolve(fragment, relocs, symbols, eu_rom, target_rom, address) + if found is not None: + distance = min(abs(address - fragment.address - shift) for shift in shifts) + hits.append((distance, address, found)) + position = target_rom.find(needle, position + 1, high - region_build.ROM_BASE) + hits.sort(key=lambda hit: hit[0]) + if hits and (len(hits) == 1 or hits[0][0] < hits[1][0]): + candidates.append(hits[0][1]) + result = hits[0][2] + if len(candidates) == 1: + placed[fragment.name] = candidates[0] + needs[fragment.name] = result + ordered.insert(index, fragment.name) # Resolve every symbol; drop conflicting symbols, overlapping placements and the functions that # need them. - sizes = {fragment.name: len(fragment.data) for fragment in fragments} while True: ordered = sorted(placed, key=placed.get) - for first, second in zip(ordered, ordered[1:]): - if placed[second] < placed[first] + sizes[first]: - raise RegionError('Overlapping placements: %s and %s' % (first, second)) + overlapping = {name for first, second in zip(ordered, ordered[1:]) + if placed[second] < placed[first] + sizes[first] for name in (first, second)} + if overlapping: # ambiguous: neither placement can be trusted + for name in overlapping: + del placed[name] + continue # Keyed by EU value, so aliases of one EU symbol must agree too. values = defaultdict(set) for name, address in placed.items(): @@ -217,10 +310,16 @@ def derive(rom): break for name in dropped: del placed[name] - referenced = {symbols[item] for name in placed for item in needs[name]} - eu_addresses = {name: fragment.address for fragment in fragments for name in (fragment.name,)} + table = {} + for name in placed: + for item in needs[name]: + if item not in eu_symbols: + raise RegionError('%s: %s is not an EU symbol' % (name, item)) + value = next(iter(values[symbols[item]])) + if table.setdefault(eu_symbols[item], value) != value: + raise RegionError('EU symbol 0x%08X has two regional values' % eu_symbols[item]) return ({eu_addresses[name]: placed[name] for name in sorted(placed, key=placed.get)}, - {value: next(iter(values[value])) for value in sorted(referenced)}) + dict(sorted(table.items()))) def main(argv=None): @@ -233,7 +332,7 @@ def main(argv=None): try: identity = verify_rom(rom, args.region) verify_rom(ROOT / 'baserom.gba', 'eu') - placed, symbols = derive(rom) + placed, symbols = derive(rom, args.region) except (RegionError, OSError) as exc: parser.exit(1, '%s\n' % exc) table = { diff --git a/tools/tests/test_region_build.py b/tools/tests/test_region_build.py index 350c9d6f..7cb29940 100644 --- a/tools/tests/test_region_build.py +++ b/tools/tests/test_region_build.py @@ -237,12 +237,18 @@ def test_section_relative_words_must_move_with_the_function(self): relocs = [(10, region_symbols.ABS32, None)] self.assertIsNone(region_symbols.resolve(fragment, relocs, {}, eu, region, self.REGION_BASE)) - def test_references_resolved_inside_the_eu_object_cannot_move(self): + def test_references_resolved_inside_the_eu_object_move_with_the_function(self): fragment = region_build.Fragment('f', 0x08000100, b'', 'f:\n ldr r0, _080B6554\n bl g\n', 'm') symbols = {'f': 0x08000101, 'g': 0x08000201, '_080B6554': 0x080B6554} - self.assertFalse(region_symbols.self_contained(fragment, [(2, 10, 'g')], symbols)) - fragment = region_build.Fragment('f', 0x08000100, b'', 'f:\n bl g\n', 'm') - self.assertTrue(region_symbols.self_contained(fragment, [(2, 10, 'g')], symbols)) + self.assertEqual(region_symbols.internal_references(fragment, [(2, 10, 'g')], symbols), + {'_080B6554'}) + eu, region, moved, relocs = self.roms() + moved = region_build.Fragment(moved.name, moved.address, moved.data, + 'moved:\n ldr r0, _pool\n', moved.module) + symbols = {'moved': 0x08000101, 'callee': 0x08000301, 'gUnk_03000010': 0x03000010, + '_pool': 0x0800010C} + needs = region_symbols.resolve(moved, relocs, symbols, eu, region, self.REGION_BASE) + self.assertEqual(needs['_pool'], {0x0800010C + self.REGION_BASE - self.EU_BASE}) def test_symbol_tables_are_keyed_by_eu_address(self): for region in ('usa', 'jp'):