diff --git a/docs/FAKES.md b/docs/FAKES.md index fc8f54eb3..aa8a6baf4 100644 --- a/docs/FAKES.md +++ b/docs/FAKES.md @@ -11,7 +11,6 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | Version | File | Function | Fake | Natural shape tried | | --- | --- | --- | --- | --- | | DEMO_US_1, DEMO_JP | src/mario/mario_motion.c | marioDemoHalf (data: three .rodata doubles) | DEMO_US_1, DEMO_JP: unreferenced static function (deadstripped, emits nothing in the DOL) whose constants 0.5, 3.0 and 0.0 create the three stray doubles of the demo's .rodata pool before mot_talk's literals | a file-scope `static const f64` array (named objects precede the pool: lands at the section start), `#include ` inline constants (same, section start), no stand-in (three doubles missing, .rodata 0x18 short); the original user of the constants is stripped from the demo DOL | -| JP, US, PAL, DEMO_US_2, DEMO_EU | src/party/party_yoshi.c | L_getStick (inlined into yoshi_use case 13) | original bug: both marioGetMoveRate calls pass no direction (the function takes `f32 dir`, so it reads whatever is in f1, here the angle just stored to *angle); called through a `(f32 (*)(void))` cast to keep the call without the argument. The demo passes the angle (natural call) | passing `*angle` or `ang`: emits a register move the target does not have | | all | src/pmario_sound.c | psndBGMOn_f_d | (1) DEMO_US_1, DEMO_JP: the looked-up BGM id is kept in the bgm_name parameter (`bgm_name = (char*)i`, read back as `(s32)bgm_name`): the demo reuses the name's register (r27) for the id (2) all versions: fo/ft/fl copies of the params; flags is reused as a holder for the vol value and fadetime for the PSND_FADE_RESTART test (blocks copy-propagation of ft); a dead guard after the early return (`ft = (ft / (ft + 1)) / ((ft + 1) / ft)`, the same for fo) gives ft/fo a second definition so they keep their own registers; no code | (1) a separate `s32 id` local (any declaration order, u32/int types, `id = i = ...`, id initialised to -1, dead `gz` guards on id, i or bgm_name, psndBGMSearchP or a demo search inline): id coalesces with i or the entry pointer (99.36-99.6) (2) see comment; plain params (no fo/ft/fl copies, no guard), a `nofade` local for flags & 0x10, `vol = bgm->volume = entry->volume`, `i = psndBGMSearch(bgm_name)`: 99.02% (US); the same with psndBGMSearchP: 98.58%; fadetime reused for the 0x10 test: 99.01%; guard bodies `ft = 0; fo = 0;`, `ft = ft / (ft + 1)` or one division per variable: r24/r27 swap | | all | src/driver/animdrv.c | animSetMaterial_Texture | (1) DEMO_US_1, DEMO_JP: (1a) the non-CI path's wrapS else-arm is `(wrapFlags & 1) != 0` (same value): its temp sits beside the late-read wrapFlags and lifts it to r30; (1b) `tex2 = texId` s32 copy after the `continue` (texId loads into r4, then `mr r20,r4`); (1c) the texture-matrix pass is a block in the function, not an inlined helper, with `s32 j[1]` (IRO temp: j r20, texMtx r21, k r22) and a dead `gz = 0; if (gz != 0) { k = 0; }` guard so `k = 0` is not propagated into j (`li r22,0` / `mr r20,r22`); the local declaration order is load-bearing (2) all versions: texCount/texIdRemap/pTexEntries copied into locals (kept as separate webs by the dead guard before loop 2); the incoming param nodes then neighbour the other params and m but not the counter, which with the counter as a ...; s32 copy after the continue: texId loads into r4 for the first TEXGet, then mr r19,r4 as in the target; dead int guard (no code after RA) keeps the three copies from being propagated away; unsigned multiply (i >= 0, same value) shifts loop-2 colouring toward target | (1) four rounds, about 5,000 variants: wrapFlags read at the loop top (wrapFlags r30 but the load is early, 22 rows), after the check/printf, passed as `entry->wrapFlags`, through a two-level TexObj helper, in both paths, inline wrappers, dead guards, self-copies, type-changing copies, `register`, one-element arrays, every declaration order sampled (late read always r20-r22 while the non-CI path used the two-step `wrapS = wrapFlags; wrapS &= 1`); plain `wrapS = wrapFlags & 1` (r30 but a li/bne select); TexMtx as an inline helper with all 7,920 local orders, params, k*3/no-j/no-texMtx forms, nested helpers, GXSetTexCoordGen wrapper (k r21/texMtx r22 every time); block form with named j (li, j/texMtx swapped), j array without the guard (li r20,0) (2) see comment; fakes3: the dead guard before loop 2 alone removed: 110 diff lines; `j = i[0] * 3` (s32 j: 43, int j: 2, u32 j: 2, the loop-2 `addi r21` scheduled one slot later), `texMtx = GX_TEXMTX0 + i[0] * 3` with s32/u32/GXTexMtx texMtx (43), `(u32)i[0] * 3` without j (0, but the same cast); without the (1c) gz guard JP builds the same and both early demos differ (k = 0 is propagated: `li r20,0` instead of `mr r20,r22`) | | all | src/driver/msgdrv.c | msgAnalize | (1) DEMO_US_1, DEMO_JP: a dead `{ s32 gz = 0; if (gz != 0) { y = 0; } }` guard at the top of the parse loop gives y its own web there, so y takes r26 and the other parse state keeps its target registers (2) all versions: nn, fp, fx, ys and yx are one-element arrays (IRO scalarizes them into @ temps). nn is the ruby index copy; int, not s32 (same width/sign; changes colouring); dead int guard (COLOURING W): msg is redefined in the arm while next is still live; called through a u16-parameter cast (target passes clrlwi r5 with no extsh to the s16 parameter); (u32) index casts here and in the second loop stop the IR optimizer from strength-reducing tag[j]/tag[i]; the backend does it instead and its pointer-IV init in the preheader keeps the dead j/i steps alive, as in the target ...; 100% (A22, 10-22): #pragma opt_lifetimes off around msgAnalize keeps total as one web so the rubyW conversion int (total = (u16)total - E) shares the loop-1 accumulator register; the webs the target splits are split by hand (glyphD, wwD, wwR, kR declared first so they take the split temps numbers); write-only one-element int arrays zz/z3/z4 read back as 0 + 1 + 2 - 3 for the kR init leave three pre-RA-only li fillers so li kR schedules after the rubyW clrlwi; a one-trip j loop around animPoseSetGXFunc enables array-to-register, which drops their stores.; also `#pragma opt_lifetimes off`: turns off lifetime splitting so the register allocation matches the target (3) all versions: a second dead guard at the top of the ruby loop (`{ s32 gz = 0; if (gz != 0) { fp[0] = fx[0]; ys[0] = yx[0] + ys[0]; } }`) | (1) y declared in 34 positions, s32/int/short y, a one-element y (or x) array, the same guard at each statement from the parse-state loads to the loop head (only the loop head works) (2) see comment; fakes3: the iconGetWidthHight cast matches fontmgr.c, which declares that function locally with a u16 id; msgdrv.c includes icondrv.h (s16/s32 prototype), so the same local declaration would conflict, and the definition's parameter type cannot change without changing icondrv.c. The other levers were not reworked in this pass (whole-function register and web shaping; see comment) (3) without the ruby-loop guard msgAnalize colours differently throughout and gains an instruction (1343 -> 1344, JP object compared) | @@ -31,7 +30,6 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | all | rels/bom/src/bom_01.c | ext_main | SFX_NAME_WORD (integer round trip) on the literal, see jump(); also `#pragma opt_propagation off` and `opt_lifetimes off` around ext_main (no copy propagation or lifetime splitting) | plain literals, a named `se` local, `(const char*)(u32)` (spill search); fakes3: `const char* fall = "SFX_STG7_BOMB_FALL1"` declared after the Mtx locals (99.75: the named local is an extra `mr` copy of the hoisted address under ext_main's lifetimes-off pragma) or first in the function (99.61); the hoist needs an integer-typed expression, whose only other source would be a changed psndSFXOn_3D prototype for every caller; without both pragmas ext_main is 1464 instructions instead of 1317 (opt_propagation off alone 1468, opt_lifetimes off alone 1313) (JP object compared) | | all | rels/bom/src/bom_01.c | jump | SFX_NAME_WORD (integer round trip) makes the front end hoist the literal address (same pointer value) | see comment; also tried: plain literal and `(char*)` cast: jump itself is identical, but its inlined copy in ext_main changes (frame 544 -> 528); fakes3: plain literal again (jump 100%, ext_main 97.99 / 98.56 for the ext_main site, 97.23 both); see ext_main | | all | rels/eki/src/eki_00.c | ext_moamoa_main | integer cast (SFX_NAME_WORD) hoists the literal as an @ temp; block-local copies of the float args (behaviour-identical) put the f1..f5 arg moves ahead of the ?: as in the target; also `#pragma opt_propagation off` and `opt_lifetimes off` around ext_moamoa_main (no copy propagation or lifetime splitting) | see comment; fakes3: the plain string literal shifts the .data/.text (ext_moamoa_main 99.32%); for the arg copies: plain `moamoa_jump(.., (d < 100.0f) ? moa->state : 0, 1, x, y, z, a2, b)` (the f1..f4 moves land after the ?:), the rand call as the last argument, a `next` local for the ?:, if/else with two calls: all differ. (The two named Vec + static zero templates were replaced by `Vec v = {0.0f, 0.0f, 0.0f}` locals.); without both pragmas ext_moamoa_main is 3601 instructions instead of 3184 (opt_propagation off alone 3601; opt_lifetimes off alone the same length with 663 different) (JP object compared) | -| all | rels/mri/src/mri_16.c | ss_check | the dead condition moves the ssf load ahead of event->args; casts, temps and u32 index variants do not reproduce it | see comment; fakes2: plain `evtSetFloat(event, event->args[0], ssf)`, an args local, an s32 or f32 copy of ssf first, a pointer to ssf: all 14 rows (ssf loaded after args); fakes3: `EvtWord* args` local, `s32 a` first, `*event->args`, `f32 f = ssf` before/after the args read, `s32 v = ssf` in both orders, `(f32)(s32)ssf`, `(int)ssf`, `static int`/`BOOL ssf`, an empty `if (ssf) {}`: all 86.9 (the same schedule: args read into r7 after the conversion) | | all | rels/mri/src/mri_puni.c | evt_puni_all_save | (1) opt_propagation off for evt_puni_all_save (keeps the branch-2 zero argument in its own temp, register colouring) (2) the zero-position branch of evt_puni_all_save inlines its own copy of puni_exit_swset with another local declaration order (register colouring only) | (1) see comment (2) single shared inline (95.9 best of 120 decl orders), idx-form inlines (92.7), block-local open code (86.4), by-value Vec (72), named zero / M-trick for the constant (no change) | | all | rels/mri/src/mri_puni.c | evt_puni_exit | `#pragma opt_dead_assignments off` around the function (removing it changes mri.rel); the exit direction is read into i, so the first loop's counter is a second web of i (register colouring); slot offsets computed by the caller into named locals o1/o2 (puni_exit_swset takes the offset); the dead mode variable reused for this loop's slot offset (register colouring) | the old form with lifetimes off; 24 counter/offset choices for the last loop; ~40 decl single/double moves; notMri00 casts / ternary / pre-set forms | | all | rels/mri/src/mri_puni.c | evt_puni_init | second copy of puniAnimationInit in its natural form (puniAnimCount for both tables); evt_puni_init inlines it and reaches 100%, while the out-of-line puniAnimationInit above only matches with its hand-written second loop. Same ... | see comment; fakes3: rechecked: evt_puni_init calling the out-of-line puniAnimationInit (auto-inlined, 2 instructions long, 62 lines); the natural two-puniAnimCount body for puniAnimationInit matches evt_puni_init but its own out-of-line copy is then off by 14 lines, so one shared function cannot give both | @@ -44,7 +42,6 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | all | rels/rsh/src/rsh_05.c | ext_moamoa_main | named Vec copied into sp2_ instead of a compound literal; integer cast (SFX_NAME_WORD) hoists the literal as an @ temp (same values) { Vec tmp; static const Vec z0 = {0.0f, 0.0f, 0.0f}; tmp = z0; tmp.x = pose->mtx[0][3]; tmp.y = ...; block-local copies of the float args (behaviour-identical) put the f1..f5 arg moves ahead of the ?: as in the target; named Vec + static zero template instead of &(Vec){...} (drops one coalesced copy; same values) (+1 more FAKE comment(s)); also `#pragma opt_propagation off` and `opt_lifetimes off` around ext_moamoa_main (no copy propagation or lifetime splitting) | see comment; fakes3: the two static zero templates are gone (`Vec pos = {0.0f, 0.0f, 0.0f};` then the field stores matches); left: the `tmp`->`sp2_` copy plus SFX_NAME_WORD (`sp2_ = (Vec){...}` with SFX_NAME_WORD only swaps the 0x14/0x20 stack slots; a plain string literal: 99.1), the block-local arg copies (direct args 99.64, `randf` inline in the call 99.68, a named or if/else `next` 99.1-99.6), the zv2 pad (without it the rodata shifts; `mario->floorMove = (Vec){...}` adds a stack temp); without both pragmas ext_moamoa_main is 3663 instructions instead of 3208 (opt_propagation off alone 3663; opt_lifetimes off alone the same length with 739 different) (JP object compared) | | all | rels/rsh/src/rsh_06.c | ext_moamoa_main | keeps the named in-argument holder `aa` of case 15 (dead store otherwise dropped by IRO), so the sum is a low-numbered named vreg as in the target; integer cast (SFX_NAME_WORD) hoists the literal as an @ temp (sfx local removed) (+5 more FAKE comment(s)); also `#pragma opt_propagation off` and `opt_lifetimes off` around the inline mmI and ext_moamoa_main (no copy propagation or lifetime splitting) | see comment; fakes3: both static zero templates replaced by a zero-initialised Vec (`Vec pos = {0.0f, 0.0f, 0.0f};` then the field stores); fakes3: the second hand-inlined randf: 100.0f + randf(0, 5) / randf(0, 5) + 100.0f / a named d (32 lines), randf(100, 105) (9 lines, 5 short), += randf (35); fakes3: the VOICE1 cast: plain literal or a block local (473 lines), a function-top const char* initialised with the literal at two positions (39-41 lines, one extra instruction); without the three pragmas ext_moamoa_main is 3405 instructions instead of 3063 (opt_propagation off alone 3062 with 1645 different, opt_lifetimes off alone 522 different, opt_dead_assignments off alone 13 different) (JP object compared) | | all | rels/muj/src/unit/unit_boss_gundan_zako_group2.c | zakogun_ext_main2 | `se1 = (0, "...")` / `se2 = (0, "...")`: the comma expressions stop constant propagation of the two sound names, so they are loaded into saved registers before the loop as in the game | plain string assignments (zakogun_ext_main2 differs) | -| all | rels/tik/src/tik_00.c | ss_check | the dead condition moves the ssf load ahead of event->args; casts, temps and u32 index variants do not reproduce it | see comment; also tried: `evtSetFloat(event, event->args[0], ssf)`, `(f32)ssf`, f32/s32 value locals, an `args` local: all load args before ssf; fakes3: an `a` local set first, ssf through f32/f64/s32 locals and declared in both orders with an args local, `*event->args`, `ssf ? ssf : 0` / `!ssf ? 0 : ssf` (67.6%), if/else on ssf, an empty `if (ssf) {}`, `ssf * 1.0f`: all 86.91% (args loaded after the conversion, into r7); the mri_16 twin has the same fake | | all | rels/tou/src/tou.c | tou_champion_belt | alias of &eff->userdata; a typed StarStoneWork* local or direct eff->userdata changes codegen | typed `StarStoneWork*` local, direct `eff->userdata` cast: object differs (A2); `((StarStoneWork*)eff->userdata)->` at each site: 99.36% (event/npc swap r30/r31), unchanged by moving eff or npc to any declaration slot or reusing eff for the new entry; `StarStoneWork* wp = eff->userdata`: 88.5%; fakes3: `((StarStoneWork*)eff->userdata)->` at each site with 40 declaration orders of the six locals (no change: 38 diff lines, event+eff r30 / npc r31 instead of r31 / r30), `eff = event->userdatap[0]` moved before pose/positions/idx/angle (60-64), cast on the userdatap read (38), block-scoped eff (38), `event->userdatap[0] = effStarStoneEntry(...)` without entry (83) | | all | rels/tou/src/tou_02.c | ext_fan_main | hand-inlined randf(135.0f, 225.0f) (same rand() call, r*90+135), 6.28 first so its pool address is created before 90/135 as in the target; integer cast (SFX_NAME_WORD) makes the literal a CSE/loop-invariant temp (target addi r30 + mr r29 copy); also `#pragma opt_propagation off` and `opt_lifetimes off` around ext_fan_main (no copy propagation or lifetime splitting) | see comment; fakes2: `6.2831855f * randf(135.0f, 225.0f) / 360.0f`, or randf into angle then the scale: 18 rows (90/135 pool addresses before 6.28, fmadds operands); plain string literal for the SFX: ~770 rows; fakes3: `{ f32 r = rand() / 32767.0f; angle = 6.2831855f * (r * 90.0f + 135.0f) / 360.0f; }` gets the pool order right: 99.99%, one fmadds with its multiplicands swapped (r * 90 / 90 * r / r * (225 - 135), r at block or case scope all canonicalise the same); angle reused as the random value: 2 diff lines; without both pragmas ext_fan_main is 1121 instructions instead of 1011 (opt_propagation off alone 1121; opt_lifetimes off alone the same length with 278 different) (JP object compared) | | all | rels/win/src/window/win_04.c | ss_ch_check | the `u64 out` local reorders the args[1] load | see comment; also tried: direct `args[1]`, `(f32)` cast, f32/s32 value locals, `EvtWord out`, evtGetValue nested in the index: register numbering differs (r4/r0 for r6/r5); `s64 out` matches (same fake); fakes3: `EvtWord`/`s32` out declared first or after index, `f32 val` local, `s32* p = ssf` / `&ssf[index]`, `u32 index`, `*args++` walk, separate declaration and assignment: all 99.33 (same 4 rows, r4/r0 for r6/r5); `event->args[1]` 90.6. The target colouring needs args[1] live in r4 across the int-to-float conversion, which only a non-propagated 64-bit copy gives | @@ -75,20 +72,15 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | all | src/driver/hitdrv.c | _hitEnt | i (dead after the joint search) as the packed counter and j holding the list offset: their later webs become the @ temps that give the target colouring | see comment; fakes3: packed loop on j or i with the offset inline or in a `u8* list` block local: 97.33% in all four forms | | all | src/driver/hitdrv.c | hitCalcVtxPosition | NULL check through stride gives stride an early web (the packed stride becomes a split @ temp, target r19); the dead int guard (COLOURING M) keeps stride as the compared operand so the pointer compare stays cmplwi; dead store, references k before j's first use so the packed k/counter split temps get the target r18/r17; popcount accumulated in m (later reused as the i0 pointer) so stride is a single-def web; loop bound in the dead popcount counter (its later web becomes an @ temp); (s32) keeps the signed compare (+1 more FAKE comment(s)); the two following strip vertices read by byte offset (`(u8*)list + (k + n) * sizeof(MapVtxRec) + offsetof(MapRawDL, vtx)`) for the target strength reduction | variable-reuse forms; lab sweeps; unsigned/pointer compares without the guard fold the stride web (91.2); `list->vtx[k + n].pos`, `(&list->vtx[k + n])->pos`, `(u8*)list->vtx + (k + n) * sizeof`; fakes3: only the `k = 0` dead store removed: 99.80% (k/counter r17/r18 swap) | | all | src/driver/itemdrv.c | itemseq_Bound | itemHitCheckUp written out here (inlining it leaves the Y block below in the wrong stack order); h/r are the inline's result copies. hit* declared in reverse for ascending slots.; no-op u32 cast so the earlier masked status value is not reused (target reloads status here); itemHitCheckY written out here; the result goes through h so the caller's hit is set in each arm (coalesces into r26 like the target). | fakes3: fabs is now the MSL inline (math.h), so peak and the hitDist sums use plain fabs(). Also cos local and the /4.0f note removed (`dz = (f32)cos(..); dz = dt * (speed * -dz)` matches; `/ 4.0f` is plain C). All fabs fakes (peak and both inlines' hitDist) vanish if fabs is an inline function returning __fabs (as in MSL) instead of the math.h macro: with that, `hit = itemHitCheckUp(entry, dy)` matches as written, leaving 3 rows (Y result: li r3,0 + mr r26,r3 at the join instead of r26 in each arm; Y with returns in arms, (entry, vy) signature, if/else forms: same) and 2 rows (status reload: `!= 0`, `0x100000u`, nested first test: CSE kept). itemHitCheckY/Up are not in the target symbol list, so they were inline or written in place | -| all | src/driver/mapdrv.c | _mapLoad | (1) chunk search written out here (was mapLoadFindChunk_) with k declared last, for the target k/w register order; same search (2) calls lightEntry through `LightEntryArgOrderFn` (`s32(const char *, s32, Vec *, Vec *, GXColor *, f32, f32, s32, s32)`), the prototype this file was compiled with, instead of the header prototype `s32 lightEntry(const char* name, s32 type, Vec* position, Vec* rotation, GXColor color, s32 attenType, s32 flags, f32 spotAngle, f32 attenAngle);` | (1) see comment; fakes3: the wo/wo2 aliases are gone (plain wp->entries[group] stores match); k declared first in mapLoadAnim_: 9 rows (2) the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/driver/mapdrv.c | mapSetLight, mapSetMaterialLight | a file-local `lightGetNearObj` macro calls the function through a `s32 (*)(Vec*, LightEntry**, s32, LightEntryFlags)` cast and passes the Vec's address; the definition takes the Vec by value | the header call `lightGetNearObj(pos, ...)` builds a stack copy of the Vec first: mapSetLight 115 -> 127, mapSetMaterialLight 351 -> 363 instructions (JP object compared) | +| all | src/driver/mapdrv.c | _mapLoad | chunk search written out here (was mapLoadFindChunk_) with k declared last, for the target k/w register order; same search | see comment; fakes3: the wo/wo2 aliases are gone (plain wp->entries[group] stores match); k declared first in mapLoadAnim_: 9 rows | | all | src/driver/npcdrv.c | fbatBattleMode | the recovered-item loop as a static inline helper (counter = inline-local @ temp, ptr r30), with the stored zero held in a local z kept alive by a dead int guard (COLOURING M; folded after RA, no code): i = 0 / z = 0 share a ...; dead int-guarded re-definition keeps mario a named web (COLOURING M); the stolen check as a loop with break over a byte offset (int counter): MWCC unrolls it into the if/else chain with every offset folded into cur, and the 8 loads share one vreg (an indexed `stolenItems[k]` loop is ... (+1 more FAKE comment(s)) | see comment; fakes3 (mario guard only removed): mario fetched before/after pouch or after the rotation store, num = 0 kept without the guard: 97.67-98.71 (98-105 rows) | -| all | src/driver/npcdrv.c | fbatEncountCheck | dead int-guarded re-definition inside the loop keeps dir a named web (COLOURING M; no code, no preheader split) | guard between def and loop (block split, li j before lfs: 99.73), dead stores, ternary guard, facing/j guards (Q8); fakes3 (no guard): all 24 orders of dist/dir/a/yaw, dir built in two statements (`dir = marioGetDispDir() - yaw; dir = reviseAngle(dir)` and other splits), no yaw local, `dir <= 180.0f`/`>=` arms, combined | | all | src/driver/npcdrv.c | fbatHitCheck | (1) store through a pointer to res (keeps the two branch stores, no if-conversion); same field. (2) its ~20 struct reads (NpcEntry, MarioWork.currMotionId, GlobalWork.mapEventId, CameraEntry.viewYaw, FieldBattleData.sandersBombTrigger) are written `(*(T*)&((S*)p)->field)` (were raw `FH(p, off, T)`); any plainer form lowers the inline cost and the deferred inliner pulls _npcHitCheckSphere/_npcHitCheckHammerAllMotion in | (2) `p->field`, `((S*)p)->field` (4 offsets alone ok, not combined), `*&`, `(u8*)`/`(void*)` casts, `[0].field`; caller/callee `dont_inline`, `inline_depth(0)`, `auto_inline off`, `inline_max_size(1)`, `inline_max_total_size` push/pop: none stop the deferred inliner; fakes3: with the hammer position code as the shared inlines npcHammerPos/npcKaitenHammerPos, 4 reads are plain (mapEventId, two currMotionId, one reactionFlags), any 5th plain read lets the inliner in (59.76); (1) in isolation (inliner held off): plain if/else, ternary, `>=` form, default-then-if, switch, if/else in an inline returning the kind or storing through a pointer parameter: all if-converted (99.25-99.66); enum-named kinds in if/else or ?: are also if-converted (99.25) | | all | src/driver/shadowdrv.c | shadowDisp | `cam->cameraAt.z = cam->cameraAt.z` inside a never-taken `s32 gz = 0; if (gz != 0)` guard: the read keeps a cam web live from entry into case 5, which gives cfg r27; it never runs, so the unset pointer is never read (before: the same self-assignment unguarded, a load/store through an uninitialised pointer in the C) | unguarded self-assignment removed, `cam = NULL` at the declaration, a guarded `cam = cam`: cfg takes r26; earlier: no self-assignment with cfg at function scope (3 orders), a block-local `CameraEntry* cam` for CAMERA_3D, a separate local for camGetCurPtr, 28 combos of decl order (disp/cam/cfg), branch-1 camGetCurPtr forms and case-5 forms, the follow block as a static inline: all cfg r26 | | all | src/effect/eff_fall.c | effFallEntry | comma temps are coloured in assignment order (ia r30 above sfxName r29) | plain `irand((s32)arg4)`: 300/304 (r29/r30 swapped); every sfxName placement/spelling, named `ia` without comma: 219-300/304 (V); fakes3: `irand(width)` (implicit conversion, no ia) with a plain sfxName local assigned at each of 10 statement positions, declared first or in place: best 99.06% (the name address goes through an extra `mr` copy); literal passed straight to psndSFXOn_3D: 91.60%; a `char*` prototype for psndSFXOn_3D: no change. Only `irand(width)` plus SFX_NAME_WORD on the literal reaches 100%, which is the same integer-cast lever as effFallMain. Reason class: hoisting of a literal address | | all | src/effect/eff_fall.c | effFallMain | the seven sfx names are spelled SFX_NAME_WORD("lit") (an integer round trip) at each call (no locals) so each becomes a hoisted loop-invariant @ temp (UNBLOCK.log lever); plain literals in calls are not hoisted. Same string addresses.; also `#pragma opt_propagation off` and `opt_lifetimes off` around effFallRelease and effFallMain (no copy propagation or lifetime splitting) | named-string casts (no effect), one literal fully cast (moved the pool), declaration orders, koopa1 2-of-3 partial (99.56); fakes3: plain literals at every call 95.80; seven `const char*` locals initialised at declaration in first-use order 97.08, reverse order 96.88. Reason class: hoisting of a literal address (the integer cast is the only form that makes the address a loop-invariant temp); without both pragmas effFallMain is 1477 instructions instead of 1459 (opt_propagation off alone 1477; opt_lifetimes off alone the same length with 36 different; effFallEntry also changes, effFallRelease does not) (JP object compared) | | DEMO_US_1, DEMO_JP | src/effect/eff_funemizu.c | effFunemizuDisp | GXPeekARGB called through an unprototyped `void (*)()` cast with (s32) coordinates and the u8[4] buffer | the SDK call `GXPeekARGB((s32)sx, (s32)sy, (u32*)argb)`: the u16 parameters add two clrlwi narrowings, effFunemizuDisp 591 -> 593 instructions (G8ME01_DEMO_1 object compared) | | all | src/effect/eff_naniga.c | effNanigaDisp | iconGetTexObj called through a `void (*)(GXTexObj*, s32)` cast | the header call: the JP (and demo) prototype takes an s16 id, so the u16 icon_id is narrowed first; effNanigaDisp 325 -> 326 instructions and its registers shift (JP object compared). The US/PAL prototype already takes an s32 | -| all | src/effect/eff_mahojin.c | effMahojinDisp | alias of idx forces z/idx base register order | ~30 tried, none 100: all single decl moves, idx int/u32, z/idx/zp reorders, zp init placement, swap/fill statement reorders, walked idx pointer, named id temp, work+idx[k], per-element pointers; fakes3: `&work[idx[k]]` / `work + idx[k]` with all 120 declaration orders of mtx/z/idx/zp/map (99.75-99.82%: z/idx bases swap r28/r29), swapped ti/tz temps, swap statements reordered (98.48%), ternary pass init (88%), an idx pointer like zp (96.07%), walked `*ip++` (93.29%) | | all | src/effect/eff_nice.c | acrobatMain | integer cast (SFX_NAME_WORD) makes the literal a CSE/loop-invariant @ temp (numbers below the SR temps) | sfx2 at function scope (extra mr, 258-269 rows), inc order, LI off, i<<2 (RE.log) | -| all | src/effect/eff_sleep.c | effSleepDisp | same values as the plain form, written so the code generator sees the target's shapes: - sin argument via `(t = tau * x, t *= 0.015625f)`: a compound assignment skips the front end's commutative swap (CExpr optimizecomm), so the ... | named k/half/one (any decl/statement order: 98.25-98.73 lab), `/ 64.0f` (pool moves), static const one (folded), sleepMul helper (volatile f4-f6 swap, 99.84); fakes3: plain sin/xh/GXPosition3f32 with `1.0f * y`: 85.2; an `f32 h = 1.0f` height local next to `w` used as `h * y` with the plain sin (94.8), with the compound-assignment sin (97.8), `/ 64.0f` (97.8), `0.015625f * (...)` (97.2) | -| all | src/effect/eff_splash.c | effSplashGetCol | GXPeekARGB called through an unprototyped `void (*)()` cast with (s32) coordinates and the u8[4] buffer | the SDK call `GXPeekARGB((s32)sx, (s32)sy, (u32*)argb)`: the u16 parameters add two clrlwi narrowings (JP 73 -> 75 instructions, G8ME01_DEMO_1 126 -> 128) | | all | src/effect/eff_starpoint.c | _cosf (inline, used by effStarPointEntry) | dead guard, no code (COLOURING W); its float temps keep the hoisted 2.0 deferred (f31) | see comment; fakes3: no guard with the eff_damage_star `_sinf`/`_cosf` shape (y temp), all 24 declaration orders of a/b/c/x2 in each inline and the 12 cross combinations (best 99.20), `_sinf(angle) * 2.0f`, a named `speed` (95.5-98.9), dropping either pragma (75-91): the hoisted 2.0 stays coloured last (f22, target f31) | | all | src/effect/eff_ultra_hammer.c | effUltraHammerDisp | register-promoted array (vtx fmt + loop counter); separate scalars differ | see comment; fakes2: a scalar counter (s32/u32/int) declared at the top, after i, in the if block, in its own block, or as do/while, with and without a fmt local: 14-58 rows (best at the top: the counter IV is numbered before the two pointer IVs); fakes3: u32/s32 `j` at the top, after i, after texObj (14-58), while loop (14), a `size` local in the body (14), `* 32` (14), `(u32)` on the size, `sizeof(wakka_dl_0_size_tbl)` bound (54-60), walking `dl`/`sz` pointers (54-62): the counter IV is always numbered below the two pointer IVs (target: counter r29, size r28, dl r27) | | all | src/effect/n64/eff_booboo_n64.c | effBoobooDisp | register-promoted array (anim id + time*30); separate scalars differ | no locals (expressions inline, 124 diff lines), one `phase` scalar (38), `phase` + `anim` scalars (36); fakes3: two scalars (s32/u8/int anim) in all 20 declaration orders: 98.5-99.13%; anim in an inner block or at the loop top: 98.83%; phase inline as `work->time * 30 + i * 20`: 83-85% | @@ -131,7 +123,7 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | all | src/sound.c | SoundEfxMain | opt_strength_reduction off for this function only. With it on, the second loop's chan*sizeof offset becomes an induction temp created before the loop's split temps and gets the highest register; the target has the effect pointer ... | no pragma: 99.52% (also with effect declared first); `int i` declared before effect: 98.88%; loop 2 through its own `SoundEffect* sfx` (first or last declared): 99.64%; `effect = &sound.effects[i]` per iteration in loop 2: 96.35%, in both loops: 95.42%; fakes3: with the voice lookup as the SoundEfxGetVoiceID inline (used by SoundEfxCheckCh) and no pragma: 99.52%; loop 2 header orders (`effect++, i++` 99.57%, `i = 0, effect = ...`, `effect = &sound.effects[0]`, `continue` form), `u32`/`long`/`s16` i (99.33/99.57/96.78), a separate `chan` index for loop 2 (97.73): the offset IV always takes the highest register (r30 instead of r28) | | all | src/sound.c | _sscallback | len2/buffer1/buffer2 are copied from the params into locals of a different type (unsigned int, s16*) so IRO cannot propagate the copies; the params then coalesce into r3/r5/r6 and these statement copies give the target order len1 ...; dst (not a u8* dst8) for the byte copies, so dst's split webs number above i/n; loop 2 reads through its own copy of src8; the copy takes the pre-RA scheduler's cycle-1 slot so `mr dst,buffer2` issues after mulhwu (magic constant and dst then share r3, as in the target); the copy itself colours to a ... US: len1 is also a local copy of its parameter, copied first, so it leaves r4 before the sound base is formed. | see comment; fakes3: not reworked (the copies, cast-lvalue byte stores and the src8 copy each steer one coloured web; see comment) | | US, DEMO_US_2 | src/window/win_main.c | winMain | US: the case-200 `list[11]` (only 7 entries used) gives the 96-byte frame of the target | see comment; fakes3: list[7] / list[8] 99.97% (frame 80), list[9] or more give the 96-byte frame; nothing in the US-only code (case 0 ternaries, the 24-byte language table copy in case 1) uses stack, so the target frame holds at least 5 bytes no code touches | -| JP, US, PAL, DEMO_US_2, DEMO_EU | src/window/win_mario.c | winMarioDisp | (1) JP: dead store; makes y the first float referenced, so its later web (the wazaOpen list label x) is split before x's (register order) (2) US, PAL: every float live range in its own named variable; one-element copies q1/q2 of row0/row1 are kept live across rowC by two dead int guards (gz is 0, no code) | (1) without the dead store 4 rows (f19/f20 swap); `y = y;` also works; statement swaps of x/y loads change load order; fakes3: new block-local names for the f190 label x / cost x / AP x in all 15 subsets and orders (best 99.996: y/x right, AP x f18 instead of f21); function-level new names at every declaration position (declaration order does not matter there); `x =` before `y =` (99.90); the expressions inlined in the loop (99.42) (2) see comment | +| JP | src/window/win_mario.c | winMarioDisp | JP: dead store; makes y the first float referenced, so its later web (the wazaOpen list label x) is split before x's (register order) | without the dead store 4 rows (f19/f20 swap); `y = y;` also works; statement swaps of x/y loads change load order; fakes3: new block-local names for the f190 label x / cost x / AP x in all 15 subsets and orders (best 99.996: y/x right, AP x f18 instead of f21); function-level new names at every declaration position (declaration order does not matter there); `x =` before `y =` (99.90); the expressions inlined in the loop (99.42) | | all | src/party.c | partyHelloMain, partyRideMain | no-op `(PartyEntry*)party` cast on the moveFrames shrink-timer accesses (was raw `*(s32*)((u8*)party + 0x24)`); the plain field reschedules the int->float conversion | `party->moveFrames`, `*&party->moveFrames`, `(&party->moveFrames)[0]`, `*(s32*)&party->moveFrames`, `*(&party->moveFrames + 0)`, stores-only as field: all reschedule; `(*party).moveFrames`, `party[0].moveFrames`: same as the plain field (Hello 96.17%, Ride 99.81%); fakes3 (Hello): plain field with `(s32)` value cast, implicit conversion, `s32 n` temp in both cases, `-x + 16`, `/ 16`: all the same 26 rows, 4 instructions longer (the double constant address is folded into lfd and the Vec template load becomes lwzu instead of the target's addi + lwz 0) | | all | src/motion/mot_roll.c | mot_roll | no-op `(MarioWork*)mario` cast on the directionView/groundRot.x/.z accesses (10 sites, were raw `MF(0x1a0/0x218/0x220)`); the plain field reorders a const load (lis/lfs) | `mario->field` per line, `*&field`, `(&field)[0]`, `(*mario).field`, inlining into angOut: all reorder; fakes3: casts only at the tcA reads, or only at the other reads: both fail (99.82, the lfs of directionView after the 10.0f load at all 3 angOut sites); `angOutT(mario->directionView, ...)`, `angOut(mario->directionView, ...)` and a plain tcA with angOutT: 99.82 | | all | src/window/win_badge.c | winBadgeMain | equip toggle reads the selection as `wt->badge.sel[0]` with `wt = (WindowWork*)((s32*)w + tab)` (base w + 4*tab, 0x3E4 in the displacement) | `w->badge.sel[tab]` (r27/r28 swap; the w + 4*tab CSE temp colours before tab, a named local declared after tab colours after it); `s32* sel = &w->badge.sel[tab]` (addi + lwzx); fakes3: moving every function-scope declaration (no change, 99.84%), idx at function scope (99.71%) | @@ -160,34 +152,17 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | all | src/driver/hitdrv.c | hitStrippedPool | the stand-in (retail, and since the demo work the demo too) for a function the linker stripped now also builds for the demo; codegen runs bottom-up, so its 0.0f and 0.1f open the demo's .sdata2 pool ahead of hitMain's 10.0f (without it they land at the pool's end); it is dead-stripped at link | none: the stripped function is in no build, only its constants survive | | all | src/himo.c | vivihimo | calls spline_maketable through `Spline_maketableLocalFn` (`void(s32, Vec *, f32 *, f32 *)`), the prototype this file was compiled with, instead of the header prototype `void spline_maketable(s32 n, Vec* pts, f32* t, Vec* out);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/himo.c | vivihimoDisp | calls spline_getvalue through `Spline_getvalueArgOrderFn` (`void(Vec *, s32, Vec *, f32 *, f32 *, f32)`), the prototype this file was compiled with, instead of the header prototype `void spline_getvalue(Vec* out, f32 t, s32 n, Vec* pts, f32* ts, Vec* tbl);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/battle_audience_kinopio.c | BattleAudienceCtrlProcessKinopioDamage | calls BattleAudience_GetEscapeChangeOK through `BattleAudience_GetEscapeChangeOKNoProtoFn` (`u8()`), the prototype this file was compiled with, instead of the header prototype `BOOL BattleAudience_GetEscapeChangeOK(s32 index);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/battle_break_slot.c | BattleBreakSlot_Main | calls pouchSetAP through `PouchSetAPS32Fn` (`void(s32)`), the prototype this file was compiled with, instead of the header prototype `void pouchSetAP(s16 points);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/battle_damage.c | BattleSetStatusDamage | (1) calls BtlUnit_GetStatus through `BtlUnit_GetStatusS8Fn` (`void(BattleUnit *, s8, s8 *, s8 *)`), the prototype this file was compiled with, instead of the header prototype `void BtlUnit_GetStatus(BattleUnit* unit, StatusEffectType type, s8* turns, s8* strength);` (2) calls BtlUnit_SetStatus through `BtlUnit_SetStatusS8Fn` (`BOOL(BattleUnit*, s8, s8, s8)`), the prototype this file was compiled with, instead of the header prototype `BOOL BtlUnit_SetStatus(BattleUnit* unit, StatusEffectType type, s8 turns, s8 strength);` | (1) the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) (2) the plain call (no sign extension of the status id) and an explicit `(s8)` cast of the id (the extsb is scheduled before the other argument moves) | | all | src/battle/battle_disp.c | btlUnitItemDisp | calls iconDispGx through `IconDispGxArgOrderFn` (`void(f32, Vec *, s16, u16)`), the prototype this file was compiled with, instead of the header prototype `void iconDispGx(Vec* position, s16 flags, u16 iconId, f32 scale);`; also `#pragma opt_dead_assignments off` (push/pop) around btlUnitItemDisp: keeps the dead assignments the target has | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call); without the pragma btlUnitItemDisp is 59 instructions instead of 63 (JP object compared) | | all | src/battle/battle_disp.c | btlUnitStolenItemDisp | calls iconDispGx through `IconDispGxArgOrderFn` (`void(f32, Vec *, s16, u16)`), the prototype this file was compiled with, instead of the header prototype `void iconDispGx(Vec* position, s16 flags, u16 iconId, f32 scale);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/battle_event_default.c | _anime_load | calls BattlePartyAnimeLoad through `BattlePartyAnimeLoadRetBoolFn` (`BOOL(s32)`), the prototype this file was compiled with, instead of the header prototype `void BattlePartyAnimeLoad(s32 partyId);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/battle_event_default.c | _anime_load_wait | calls BattlePartyAnimeLoad through `BattlePartyAnimeLoadRetBoolFn` (`BOOL(s32)`), the prototype this file was compiled with, instead of the header prototype `void BattlePartyAnimeLoad(s32 partyId);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/battle/battle_menu_disp.c | DrawMainIconHukidasi | calls FontDrawStringCenterMtx through `FontDrawStringCenterMtxLocalFn` (`void(Mtx, const char *)`), the prototype this file was compiled with, instead of the header prototype `void FontDrawStringCenterMtx(Mtx mtx, const s8* msg);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/battle_status_icon.c | _bsi_default_turn | calls BtlUnit_GetStatus through `BtlUnit_GetStatusS8Fn` (`void(BattleUnit *, s8, s8 *, s8 *)`), the prototype this file was compiled with, instead of the header prototype `void BtlUnit_GetStatus(BattleUnit* unit, StatusEffectType type, s8* turns, s8* strength);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/battle_status_icon.c | _bsi_guruguru | calls BtlUnit_GetStatus through `BtlUnit_GetStatusS8Fn` (`void(BattleUnit *, s8, s8 *, s8 *)`), the prototype this file was compiled with, instead of the header prototype `void BtlUnit_GetStatus(BattleUnit* unit, StatusEffectType type, s8* turns, s8* strength);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/battle_status_icon.c | _bsi_allergy | calls BtlUnit_GetStatus through `BtlUnit_GetStatusS8Fn` (`void(BattleUnit *, s8, s8 *, s8 *)`), the prototype this file was compiled with, instead of the header prototype `void BtlUnit_GetStatus(BattleUnit* unit, StatusEffectType type, s8* turns, s8* strength);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/battle_status_icon.c | _bsi_biribiri | calls BtlUnit_GetStatus through `BtlUnit_GetStatusS8Fn` (`void(BattleUnit *, s8, s8 *, s8 *)`), the prototype this file was compiled with, instead of the header prototype `void BtlUnit_GetStatus(BattleUnit* unit, StatusEffectType type, s8* turns, s8* strength);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/battle_status_icon.c | _bsi_regeneration | (1) calls BtlUnit_GetStatus through `BtlUnit_GetStatusS8Fn` (`void(BattleUnit *, s8, s8 *, s8 *)`), the prototype this file was compiled with, instead of the header prototype `void BtlUnit_GetStatus(BattleUnit* unit, StatusEffectType type, s8* turns, s8* strength);` (2) calls BtlUnit_CheckStatus through `BtlUnit_CheckStatusS8Fn` (`BOOL(BattleUnit*, s8)`), the prototype this file was compiled with, instead of the header prototype `BOOL BtlUnit_CheckStatus(BattleUnit* unit, StatusEffectType type);` | (1) the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) (2) the plain call (no sign extension of the status id) and an explicit `(s8)` cast of the id (the extsb is scheduled before the other argument moves) | | all | src/unit/party/unit_party_yoshi.c | _btlYoshiDisp | calls btlDispTexPlane through `BtlDispTexPlaneFloatsFirstFn` (`void(f32, f32, f32, f32, f32, u32, GXColor, s32)`), the floats first; same registers as (id, color, 0, x, y, z, sx, sy), the texture-id load comes last as in the original | the header order loads the texture id before the floats (JP, US, PAL and the US demo all differ; not retried for the Japanese demo) | | all | src/battle/ac/ac_button_down.c | actionCommandDisp | calls iconDispGx through `IconDispGxS32S32Fn` (`void(Vec *, s32, s32, f32)`), the prototype this file was compiled with, instead of the header prototype `void iconDispGx(Vec* position, s16 flags, u16 iconId, f32 scale);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/battle/ac/ac_gauge_timing2.c | actionCommandDisp | calls BattleACGetButtonIcon through `BattleACGetButtonIconRetS32Fn` (`s32(s32, s32)`), the prototype this file was compiled with, instead of the header prototype `u16 BattleACGetButtonIcon(s32 button, s32 pressed);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/ac/ac_monosiri_target.c | actionCommandDisp | calls iconDispGx through `IconDispGxS32S32Fn` (`void(Vec *, s32, s32, f32)`), the prototype this file was compiled with, instead of the header prototype `void iconDispGx(Vec* position, s16 flags, u16 iconId, f32 scale);`; calls BattleACGetButtonIcon through `BattleACGetButtonIconRetS32Fn` (`s32(s32, s32)`), the prototype this file was compiled with, instead of the header prototype `u16 BattleACGetButtonIcon(s32 button, s32 pressed);`; also `#pragma dont_inline on` ... `reset` around actionCommandDisp: keeps it out of line as in the target | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call); dont_inline: without it actionCommandDisp is inlined into battleAcDisp_MonosiriTarget (15 -> 258 instructions) (all five versions compared) | -| all | src/battle/ac/ac_power_gauge.c | actionCommandDisp | calls BattleACGetButtonIcon through `BattleACGetButtonIconRetS32Fn` (`s32(s32, s32)`), the prototype this file was compiled with, instead of the header prototype `u16 BattleACGetButtonIcon(s32 button, s32 pressed);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/ac/ac_power_gauge_lv2.c | actionCommandDisp | calls BattleACGetButtonIcon through `BattleACGetButtonIconRetS32Fn` (`s32(s32, s32)`), the prototype this file was compiled with, instead of the header prototype `u16 BattleACGetButtonIcon(s32 button, s32 pressed);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/ac/ac_repeatedly.c | actionCommandDisp | calls BattleAcDrawGauge through `BattleAcDrawGaugeNoProtoFn` (`void()`), the prototype this file was compiled with, instead of the header prototype `void BattleAcDrawGauge(s32 x, s32 y, s32 width, f32 ratio, s32 level, s32 a, s32 b, s32 c, s32 flags);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/ac/ac_repeatedly_lv.c | actionCommandDisp | calls BattleAcDrawGauge through `BattleAcDrawGaugeArgOrderFn` (`void(f32, s32, s32, u8, s32, s32, s32, s32, s32)`), the prototype this file was compiled with, instead of the header prototype `void BattleAcDrawGauge(s32 x, s32 y, s32 width, f32 ratio, s32 level, s32 a, s32 b, s32 c, s32 flags);`; calls BattleACGetButtonIcon through `BattleACGetButtonIconRetS32Fn` (`s32(s32, s32)`), the prototype this file was compiled with, instead of the header prototype `u16 BattleACGetButtonIcon(s32 button, s32 pressed);`; also `#pragma dont_inline on` from actionCommandDisp to the end of the file (no reset): keeps it out of line as in the target | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call); dont_inline: without it the code differs: 1 function changes length, e.g. battleAcMain_RepeatedlyLv 366 -> 368 instructions (all five versions compared) | | all | src/battle/sac/sac_bakugame.c | bakuGameMain | calls (through the GET_EXIST macro) BattleAudience_GetExist through `BattleAudience_GetExistRetU8Fn` (`u8(s32)`), the prototype this file was compiled with, instead of the header prototype `BOOL BattleAudience_GetExist(s32 index);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/battle/sac/sac_bakugame.c | bakuGameAudienceSurpriseReset | calls (through the GET_EXIST macro) BattleAudience_GetExist through `BattleAudience_GetExistRetU8Fn` (`u8(s32)`), the prototype this file was compiled with, instead of the header prototype `BOOL BattleAudience_GetExist(s32 index);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/battle/sac/sac_genki.c | main_mario | calls weapon_entry through `Weapon_entryLocalFn` (`void(void)`), the prototype this file was compiled with, instead of the header prototype `void weapon_entry(void);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/battle/sac/sac_genki.c | disp_3D | calls iconDispGxCol through `IconDispGxColU16S32Fn` (`void(Mtx, u16, s32, GXColor)`), the prototype this file was compiled with, instead of the header prototype `void iconDispGxCol(Mtx pos, s16 flags, u16 iconId, GXColor color);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/battle/sac/sac_genki.c | main_base, main_mario | object_entry and object_get_num (USER_FUNC definitions that no script uses) are called through `void (*)(void)` and `s32 (*)(void)` casts; the cast call keeps deferred codegen from inlining them | direct calls with the functions declared `static void object_entry(void)` / `static s32 object_get_num(void)`: both are inlined (main_base 333 -> 345 instructions, main_mario 146 -> 157; JP object compared) | | all | src/battle/sac/sac_zubastar.c | zubastar_disp2D | calls iconDispGx through `IconDispGxS32Fn` (`void(Vec *, s16, s32, f32)`), the prototype this file was compiled with, instead of the header prototype `void iconDispGx(Vec* position, s16 flags, u16 iconId, f32 scale);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/driver/extdrv.c | extMakeTexture | calls animPoseDisp_MakeExtTexture through `AnimPoseDisp_MakeExtTextureLocalFn` (`void(const char *, const char *, f32, f32, GXTexObj *, void * * *, s32 *, s32 *, s32 *, s32 *)`), the prototype this file was compiled with, instead of the header prototype `void animPoseDisp_MakeExtTexture(const char* group, const char* anim, f32 frame, f32 scale, GXTexObj* obj, struct smartEntry** image, s32* x0, s32* y0, s32* x1, s32* y1);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/event/evt_batstage.c | evt_batstage_light_set_player_on | unused `u8 en2[4] = {0, 0, 0, 0}` keeps its 4-byte zero initialiser template in the data | removing it drops the template (data diff) | | all | src/event/evt_batstage.c | evt_batstage_set_stg_dark_base | calls BattleStageSetStgDarkBase through `BattleStageSetStgDarkBaseS32Fn` (`void(u8, s32, s32)`), the prototype this file was compiled with, instead of the header prototype `void BattleStageSetStgDarkBase(u8 v, s32 time, u8 mode);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/event/evt_batstage.c | evt_batstage_set_stg_dark | calls BattleStageSetStgDark through `BattleStageSetStgDarkS32Fn` (`void(u8, s32, s32)`), the prototype this file was compiled with, instead of the header prototype `void BattleStageSetStgDark(u8 v, s32 time, u8 mode);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | @@ -196,22 +171,15 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | all | src/event/evt_batstage.c | evt_batstage_return_stg_dark_base | calls BattleStageReturnStgDarkBase through `BattleStageReturnStgDarkBaseS32Fn` (`void(s32, s32)`), the prototype this file was compiled with, instead of the header prototype `void BattleStageReturnStgDarkBase(s32 time, u8 mode);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/event/evt_batstage.c | evt_batstage_return_aud_dark_base | calls BattleStageReturnAudDarkBase through `BattleStageReturnAudDarkBaseS32Fn` (`void(s32, s32)`), the prototype this file was compiled with, instead of the header prototype `void BattleStageReturnAudDarkBase(s32 time, u8 mode);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/event/evt_map.c | evt_mapobj_color | calls mapObjSetColor through `MapObjSetColorGxcolorFn` (`void(const char *, GXColor)`), the prototype this file was compiled with, instead of the header prototype `void mapObjSetColor(const char* name, GXColor* color);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/event/evt_mario.c | evt_mario_mov_pos, evt_mario_mov_pos2 and the party door/bero moves | (1) calls marioSetForceMove through `MarioSetForceMoveArgOrderFn` (`void(s32, f32, f32)`), the prototype this file was compiled with, instead of the header prototype `void marioSetForceMove(f32 dir, s32 time, f32 speed);` (2) partyMoveBehindMario3 declared with a third f32 the definition does not take; the callers compute and pass it | (1) the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) (2) the header prototype cannot take the third argument the target computes and passes | +| all | src/event/evt_mario.c | evt_mario_mov_pos, evt_mario_mov_pos2 | calls marioSetForceMove through `MarioSetForceMoveArgOrderFn` (`void(s32, f32, f32)`), the prototype this file was compiled with, instead of the header prototype `void marioSetForceMove(f32 dir, s32 time, f32 speed);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/event/evt_mario.c | evt_mario_set_motion | marioChgMot called through a `void (*)(s32)` cast | the plain call narrows the value to the 16-bit MarioMotion enum first (`clrlwi r3,r3,16`, 12 -> 13 instructions; JP object compared) | | all | src/event/evt_sub.c | evt_sub_spline_get_value | calls spline_getvalue through `Spline_getvalueLocalFn` (`void(f32 *, f32, s32, Vec *, f32 *, Vec *)`), the prototype this file was compiled with, instead of the header prototype `void spline_getvalue(Vec* out, f32 t, s32 n, Vec* pts, f32* ts, Vec* tbl);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/event/evt_sub.c | evt_sub_spline_get_value_manual | (1) `t = t;` self-assignment (second definition of t) keeps the target float register order (2) calls spline_getvalue through `Spline_getvalueLocalFn` (`void(f32 *, f32, s32, Vec *, f32 *, Vec *)`), the prototype this file was compiled with, instead of the header prototype `void spline_getvalue(Vec* out, f32 t, s32 n, Vec* pts, f32* ts, Vec* tbl);` | (1) without it f1/f2 swap in the divide (2) the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/event/evt_telop.c | telop | `scale = scale;` in the then-branch of the width fit keeps the target branch layout | inverted test: cror instead of bge+b; `!(a < b)`: whole function moves; ternary: extra stack store | | US, PAL, DEMO_US_2, DEMO_EU | src/manager/winmgr.c | winMgrSelectEntry | calls L_pouchEquipBadge through `L_pouchEquipBadgeRetU16Fn` (`u16(s32)`), the prototype this file was compiled with, instead of the header prototype `ItemType L_pouchEquipBadge(s32 id);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/party/party_chuchu.c | search_result | calls effFukidashiEntry through `EffFukidashiEntryRetVoidptrS32Fn` (`void*(s32, s32, s32, f32, f32, f32, f32, f32, s32)`), the prototype this file was compiled with, instead of the header prototype `EffectEntry* effFukidashiEntry(s32 type, s32 number, NpcEntry* npc, f32 x, f32 y, f32 z, f32 size, f32 angle, s32 duration);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/window/win_item.c | winItemMain | (1) all versions: calls pouchSetHP through `PouchSetHPS32Fn` (`void(s32)`), the prototype this file was compiled with, instead of the header prototype `void pouchSetHP(s16 points);` (2) DEMO_US_1, DEMO_JP: calls pouchSetFP through `PouchSetFPS32Fn` (`void(s32)`), the prototype this file was compiled with, instead of the header prototype `void pouchSetFP(s16 points);`; calls pouchSetAP through `PouchSetAPS32Fn` (`void(s32)`), the prototype this file was compiled with, instead of the header prototype `void pouchSetAP(s16 points);` | (1) the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) (2) the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| PAL, DEMO_EU | src/window/win_item.c | itemUseDisp | calls pouchGetMaxHP through `PouchGetMaxHPRetS32Fn` (`s32(void)`), the prototype this file was compiled with, instead of the header prototype `s16 pouchGetMaxHP(void);`; calls pouchGetMaxFP through `PouchGetMaxFPRetS32Fn` (`s32(void)`), the prototype this file was compiled with, instead of the header prototype `s16 pouchGetMaxFP(void);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | src/window/win_main.c | itemUseFunc | calls pouchSetHP through `PouchSetHPS32Fn` (`void(s32)`), the prototype this file was compiled with, instead of the header prototype `void pouchSetHP(s16 points);`; calls pouchSetFP through `PouchSetFPS32Fn` (`void(s32)`), the prototype this file was compiled with, instead of the header prototype `void pouchSetFP(s16 points);`; calls pouchSetAP through `PouchSetAPS32Fn` (`void(s32)`), the prototype this file was compiled with, instead of the header prototype `void pouchSetAP(s16 points);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | rels/eki/src/eki_03.c | test_glare | calls envGlareFilter through `EnvGlareFilterS16Fn` (`void(s32, s16, s16, s16, s16)`), the prototype this file was compiled with, instead of the header prototype `void envGlareFilter(s32 type, s32 y0, s32 x0, s32 y1, s32 x1);` | the plain call through the header prototype and `(s16)` casts on each argument (both load the rectangle in a different order) | -| all | rels/hom/src/hom_00.c | test_glare | calls envGlareFilter through `EnvGlareFilterS16Fn` (`void(s32, s16, s16, s16, s16)`), the prototype this file was compiled with, instead of the header prototype `void envGlareFilter(s32 type, s32 y0, s32 x0, s32 y1, s32 x1);` | the plain call through the header prototype and `(s16)` casts on each argument (both load the rectangle in a different order) | -| all | rels/jin/src/unit/unit_faker_mario.c | _anime_load_wait | calls BattlePartyAnimeLoad through `BattlePartyAnimeLoadRetBoolFn` (`BOOL(s32)`), the prototype this file was compiled with, instead of the header prototype `void BattlePartyAnimeLoad(s32 partyId);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | rels/jin/src/unit/unit_faker_mario.c | _anime_load | calls BattlePartyAnimeLoad through `BattlePartyAnimeLoadRetBoolFn` (`BOOL(s32)`), the prototype this file was compiled with, instead of the header prototype `void BattlePartyAnimeLoad(s32 partyId);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | +| PAL, DEMO_EU | src/window/win_item.c | itemUseDisp | PAL: calls pouchGetMaxHP and pouchGetMaxFP through `PouchGetMaxHPRetS32Fn` / `PouchGetMaxFPRetS32Fn` (`s32(void)`). The header prototypes now return s32 too, so the cast is a no-op kept only until a PAL build confirms the plain call | the US branch of the same code builds the plain calls identically (G8ME01); not checked in PAL (no PAL disc in that check) | | all | rels/kpa/src/kpa.c | kpa_status_disp | calls iconDispGx through `IconDispGxArgOrderFn` (`void(f32, Vec *, s16, u16)`), the prototype this file was compiled with, instead of the header prototype `void iconDispGx(Vec* position, s16 flags, u16 iconId, f32 scale);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | -| all | rels/mri/src/driver/punidrv.c | puniMakeTexture | calls animPoseDisp_MakeExtTexture through `AnimPoseDisp_MakeExtTextureLocalFn` (`void(const char *, const char *, f32, f32, GXTexObj *, void * * *, s32 *, s32 *, s32 *, s32 *)`), the prototype this file was compiled with, instead of the header prototype `void animPoseDisp_MakeExtTexture(const char* group, const char* anim, f32 frame, f32 scale, GXTexObj* obj, struct smartEntry** image, s32* x0, s32* y0, s32* x1, s32* y1);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | rels/tst/src/unit/unit_yoshi.c | _btlYoshiDisp | calls btlDispTexPlane through `BtlDispTexPlaneArgOrderFn` (`void(f32, f32, f32, f32, f32, u32, GXColor, s32)`), the floats first, instead of tst's older prototype `void btlDispTexPlane(u32 id, GXColor color, s32 unk, f32 tX, f32 tY, f32 tZ, f32 sX, f32 sY);` | the plain call through that prototype (tried 10-29: the table load moves ahead of the float arguments, .text differs) | | all | src/battle/battle_seq_command.c | BattleCommandInput | calls BattleCommandDisplay_ChangePartySelectMenuSetup through the function pointer type `MenuSetupFn` (its own prototype) so that MWCC does not inline it; the function is defined after the dont_inline region | the direct call (MWCC inlines the setup into BattleCommandInput) | | all | src/battle/battle_audience.c | BattleAudienceSoundHandBeat | calls psndSFX_vol through `PsndSFX_volS32Fn` (`void(s32, s32)`), the prototype this file was compiled with, instead of the header prototype `void psndSFX_vol(s32 id, u8 vol);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | @@ -227,24 +195,18 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | US, PAL, DEMO_US_2, DEMO_EU | src/party/party_motion.c | party_motion_homing_fly | calls partySearchHead through `PartySearchHeadRetVoidptrFn` (`void*(PartyEntry *, Vec *, f32 *, f32)`), the prototype this file was compiled with, instead of the header prototype `void partySearchHead(PartyEntry *party, Vec *pos, f32 *dist, f32 angle);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/party/party_move.c | partyMoveMain | calls partySearchHead through `PartySearchHeadRetHitentryptrFn` (`HitEntry*(PartyEntry *, Vec *, f32 *, f32)`), the prototype this file was compiled with, instead of the header prototype `void partySearchHead(PartyEntry *party, Vec *pos, f32 *dist, f32 angle);` | the plain call through the header prototype (changes the argument/return conversions or the argument evaluation order at this call) | | all | src/party/party_move.c | partyRecordFootmark (retail and demo versions) | partyClearFootmark2 called through a `void (*)(void)` cast (its own type), so deferred codegen does not inline it | the plain call inlines it: partyRecordFootmark 355 -> 437 instructions (JP), 409 -> 499 (G8ME01_DEMO_1) | -| all | src/mario/mario_kemuri.c | mario_kemuri | `s = s;` in the empty pipe-motion (MARIO_MOTION_DOKAN) branch emits the extra instruction the original has there; also `#pragma dont_inline on`: keeps the following function(s) out of line as in the target | an empty branch (one instruction short) | +| all | src/mario/mario_kemuri.c | mario_kemuri | `#pragma dont_inline on`: keeps the following function(s) out of line as in the target | removing the pragma changes the code | | all | src/manager/winmgr.c | winMgrSelectDelete | sel and its item list go through a chain of copies (`items3 = (sel2 = (sel3 = sel))->items`) so the target's `mr r0,r3; li r3,0; mr r31,r0` order comes out | `__memFree(HEAP_DEFAULT, sel->items); __memFree(HEAP_DEFAULT, sel);`, with a items local, with a select copy, with a heap local: all load the heap id after saving sel | | all | src/manager/cardmgr.c | memcard_probe | `timeout = (u32)timeout;` inside the busy loop (retail inline copy and demo copy) | dropping the line changes cardMain/create_main/read_main/write_main (retail) and memcard_probe (demo) | -| all | src/driver/casedrv.c | caseEntry | `return i & 0xFFFFFFFFFFFFFFFFu;` (a no-op mask) gives i and entry the target's registers | `return i;` swaps r29/r30 | -| all | src/driver/casedrv.c | caseMain | calls evtEntry through `EvtEntryS32PriorityFn` (`EventEntry*(void*, s32, u8)`), the prototype this file was compiled with: the s32 priority is passed without the u8 truncation of the header prototype (replaces a #define rename around the evtmgr.h include) | the plain call through the header prototype adds the truncation to the priority argument | | all | src/manager/fontmgr.c | FontDrawMessageMtx | `scale = scale;` before the icon draw | deleting it changes the register allocation of FontDrawMessageMtx in all five versions | | all | src/manager/fontmgr.c | FontGetMessageWidthLine | `if (code && code) { }`, an empty test before the last charspace subtraction, keeps code live there | removing it, `if (code) { }` and `if (code) { (void)0; }` change the register allocation in all five versions (`if (code && code) { (void)0; }` also matches) | | all | src/driver/shadowdrv.c | shadowBegin (inlined into shadowDisp) | `cfg = (0, &shadowConfig[i])` and the byte-offset `((ShadowConfig*)((u8*)shadowConfig + i * sizeof(ShadowConfig)))->sizeIdx/projType` reads: same addresses, but the expression trees give the inlined copy in shadowDisp the target registers | plain `&shadowConfig[i]` and `shadowConfig[i].field`: shadowDisp's inlined copy takes other registers (r26/r27 swapped, mulli/lwzx form) | -| all | src/driver/mobjdrv.c | mobjHitEntry | `(f32)(0, __fabs((0, max.x - min.x)))` (and z): comma expressions that give the \ | max - min\ | -| all | src/driver/mapdrv.c | mapEntry | `wp = (0, &mapWork[activeGroup])`: the comma expression gives wp r31 | plain `&mapWork[activeGroup]`: wp r30 | -| all | src/driver/mapdrv.c | bmapLoad | `wp = (0, &mapWork[1])`: the comma expression keeps the target register order | plain `&mapWork[1]`: registers differ | | all | src/driver/animdrv.c | animStrippedPool | stand-in for a function the linker stripped; codegen runs bottom-up, so its 0.0f, the degrees-to-radians factor and the int-to-float constant take their target pool slots; dead-stripped at link | none: the stripped function is in no build, only its constants survive | | all | src/driver/mapdrv.c | mapStrippedPool | stand-in for a stripped map.dat version check (its strings: "information", "ver1.01", "ver1.02", "not converted", "animation_table", "curve_table"); keeps the .rodata/.sdata2 constants in their target order; dead-stripped at link | none: the stripped function is in no build, only its constants survive | | all | src/driver/npcdrv.c | npcStrippedAnnouncePool, npcStrippedHitPool, npcStrippedKoopaPool | stand-ins for stripped functions: -600/600 (first-strike banner), 15.0f (retail only), 60/365 and the kpa_03 waterfall strings; they keep those constants in their target pool order; dead-stripped at link | none: the stripped functions are in no build, only their constants survive | | all | rels/hei/src/hei_10.c | chb_sin, chb_cos (inlined into ext_main and ext_init) | no-op `a = a;` statements inside the polynomial sine/cosine | the same polynomials without the self-assignments (hei.rel differs in JP) | | all | rels/hei/src/hei_10.c | ext_main | `sfx = (0, "SFX_STG1_CHORO_ESCAPE1");` comma expression (same value); also `#pragma opt_lifetimes off` and `opt_dead_assignments off` (push/pop) around jump_r, escape_r and ext_main | plain `sfx = "SFX_STG1_CHORO_ESCAPE1";` (hei.rel differs in JP); without both pragmas ext_main is 892 instructions instead of 783 (opt_dead_assignments off alone 892; opt_lifetimes off alone the same length with 202 different); jump_r and escape_r do not change (JP object compared) | | all | rels/gon/src/gon_03.c | senkaron_ext_main | `(0, "SFX_...")` comma expressions for the three sound-name locals (same values) | plain assignments of the literals (gon.rel differs in JP) | -| all | src/mario/mario_motion.c | marioRollChgChk (inlined into the motion-change functions) | calls marioCreviceWallChk through `MarioCreviceWallChkByValueFn` (`BOOL(Vec)`): the by-value Vec travels as a pointer to a stack copy, which is what the real `BOOL marioCreviceWallChk(const Vec*)` receives | `pos = mario->position; marioCreviceWallChk(&pos)` (as mot_slit.c does) and `&mario->position`: both change marioRollChgChk and every function it is inlined into | | JP, US, PAL, DEMO_US_2, DEMO_EU | src/mario/mario.c | marioMoveMain | calls N_dou10_yoko_yari3 through `NDou10YokoYari3ArgFn` with `&wp->frontWallDist`, an argument the function (`HitEntry* N_dou10_yoko_yari3(void)`) does not take: the original loads r3 before the call | the plain call without an argument (one instruction short) | | all | src/party/party_bomhei.c | bomhei_use_main | calls marioSetSplash through `MarioSetSplashByValueFn` (`void(s32, Vec)`): the by-value Vec travels as a pointer to a stack copy, which is what the real `void marioSetSplash(s32, Vec*)` receives; the copy sets the frame | `&party->position`: the frame and the code of this function and its inlined callers change | | all | rels/las/src/las_04.c | firebar_entry | the FirebarWork pointer is reloaded from the event each frame with `*(FirebarWork**)&wp = event->userdatap[0];`: taking the address of `wp` keeps it in a stack slot (0x8(r1)) for the whole function, as the target does | `wp = event->userdatap[0];` (wp moves to a register and the loads/stores of the whole function change) | @@ -276,16 +238,13 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | JP, US, DEMO_US_2 | src/event/evt_mobj.c | mobj_koopa_stone_blk | JP, US and the September US demo (`#if !MOBJ_EXTRA_OBJS`): uncalled stub whose mobjNameToPtr calls keep "MOBJ_BombRock", "OFF_d_bom" and "MOBJ_trap" in .rodata; dead-stripped at link | without it (JP object compared) the three strings are missing from .rodata; the stripped originals are the breaking-rock and trap-floor objects PAL, the European demo and the early demos keep | | JP, US, PAL, DEMO_US_2, DEMO_EU | src/event/evt_sub.c | coin_fmt (data: the orphan "%f%f%f" in .rodata) | the releases and the September demos (`#if VERSION >= VERSION_JP`): `#pragma force_active on` around an unreferenced `static const char[]` keeps the string of a stripped coin-position helper at the start of .rodata | without the pragma the linker strips the string and the JP build fails (DOL and every REL); the original helper is unknown | | all | src/driver/shadowdrv.c | _filter | `f32 t = 20.0f;` dead store under `#pragma opt_dead_assignments off`: its literal takes the target .sdata2 slot; also `#pragma opt_dead_assignments off`: keeps the dead stores that the target has | without it .sdata2 is reordered (DOL hash differs) | -| all | rels/gor/src/gor_01.c | cook_chk, cook_chk2 | `(volatile u32)args[n]` as the script-variable argument of evtSetValue, so args[n] is loaded after the inlined itemNameToID result as in the target (the JP demo's cooking.xml versions of both functions use the same cast, also for the naniga_okorukana_cook result in cook_chk2) | plain `args[n]`, the result in a local first (two instructions swap), a `(u32)` cast of the result, `event->args[n]` | +| DEMO_US_1, DEMO_JP | rels/gor/src/gor_01.c | cook_chk, cook_chk2 (the demos' cooking.xml versions) | `(volatile u32)args[n]` as the script-variable argument of evtSetValue, so args[n] is loaded after the inlined itemNameToID result as in the target (in cook_chk2 also for the naniga_okorukana_cook result) | plain `args[n]`, the result in a local first (two instructions swap), a `(u32)` cast of the result, `event->args[n]`; the retail versions match plainly with the result in an `ItemType id` local (`id = itemNameToID(...); evtSetValue(event, args[n], id);`), a form not checked in the demos (no demo files here) | | all | rels/gor/src/gor_01.c, rels/gor/src/gor_03.c | mario_keyoff_wait | `switch (!marioChkKey())` with `default` = block and `case 0` = yield | `if (marioChkKey()) return YIELD; return BLOCK;`, the negated `if`, and both `?:` forms | | all | rels/gor/src/gor_03.c | fall_rtn (monte counter sounds), goryuugijo_main_slot, kuzi_bomb_bomb_eff | `(0, "SFX_...")` and `(0, evtGetValue(...))` comma expressions (same values) | the plain literal or call, one site at a time: each changes the string-pool order or the register use | | all | rels/yuu/src/yuu_02.c | fall_rtn | `(0, "SFX_EVT_GAME_MONTE_COUNT1")` comma expression puts the string address in its own saved register | the plain literal (the same expression in yuu_00/yuu_01 is plain) | -| all | src/party/party_move.c | partyMoveBehindMario3 | original bug: party_set_behind_dir(party, dir) is called without `dir`, so homeDir gets whatever is in f1; called through a `(void (*)(PartyEntry*))` cast | passing a direction adds the load the target does not have | | all | src/party/party_chuchu.c, src/party/party_nokonoko.c | chuchu_move, nokonoko_move | partyWalkInit(party) is called with a second argument 1 (no effect, the function takes one); called through a `(void (*)(PartyEntry*, s32))` cast | the one-argument call drops the `li r4,1` | -| all | src/battle/battle_disp.c | _GetStatusPoseType | calls BtlUnit_CheckStatus through `BtlUnit_CheckStatusS8Fn` (`BOOL(BattleUnit*, s8)`), the prototype this file was compiled with, instead of the header prototype `BOOL BtlUnit_CheckStatus(BattleUnit* unit, StatusEffectType type);` | the plain call (no sign extension of the status id) and an explicit `(s8)` cast of the id (the extsb is scheduled before the other argument moves) | | all | src/battle/battle_message.c | _disp | calls windowDispGX_Waku_col through `WindowDispWakuColPtrFn` (`void(u16, GXColor*, f32, f32, f32, f32, f32)`), the prototype this file was compiled with, instead of the header prototype `void windowDispGX_Waku_col(u16 gxTexMapID, GXColor color, f32 x, f32 y, f32 width, f32 height, f32 curve);` | the plain call with the colour by value (the struct copy changes the code) | | all | src/battle/battle_seq_command.c | BattleCommandDisplay_WeaponMultiItemCancelCheckDisp | calls windowDispGX_Waku_col through `WindowDispWakuColFloatsFirstFn` (`void(f32, f32, f32, f32, f32, u16, GXColor)`), the prototype this file was compiled with, instead of the header prototype `void windowDispGX_Waku_col(u16 gxTexMapID, GXColor color, f32 x, f32 y, f32 width, f32 height, f32 curve);` | the plain call (the float arguments are then evaluated after the colour) | -| all | src/battle/battle_unit.c | BtlUnit_snd_se | calls BtlUnit_snd_se_pos through `BtlUnit_snd_se_posS32PitchFn` (`s32(BattleUnit*, const char*, s32, s32, Vec*)`), the prototype this file was compiled with, instead of the header prototype `s32 BtlUnit_snd_se_pos(BattleUnit* unit, const char* sfxName, s32 volume, s16 pitch, Vec* pos);` | the plain call (adds an extsh of the pitch); an s32 pitch in the definition changes the callee | | all | src/effect/eff_levelup.c | effLevelupDisp | MWCC lvalue cast `(u8*)w += ofs;` steps the work pointer by the byte offset the loop keeps; it is an MWCC extension, not standard C (clang rejects it) | `w = (EffLevelupWork*)((u8*)w + ofs)`, the same from effect->userdata in one statement, `(void*)` and `(u32)` sums, `&((u8*)w)[ofs]`, `*(u8**)&w += ofs`: each loads userdata into r0 and adds into w (2 instructions differ) | | all | src/battle/battle_event_cmd.c | btlevtcmd_DivePosition | calls intpl_sub through `IntplSubArgOrderFn` (`f32(s32 mode, f32 start, f32 end, s32 cur, s32 steps)`), the argument order this file was compiled with, instead of the header prototype `f32 intpl_sub(s32 mode, s32 cur, s32 steps, f32 start, f32 end);` (same registers) | the plain call in header order (evaluates the arguments in another order and changes the code) | | all | src/battle/battle_event_cmd.c | btlevtcmd_EllipseMovePosition | calls intpl_sub through `IntplSubArgOrderFn` (`f32(s32 mode, f32 start, f32 end, s32 cur, s32 steps)`), the argument order this file was compiled with, instead of the header prototype `f32 intpl_sub(s32 mode, s32 cur, s32 steps, f32 start, f32 end);` (same registers) | the plain call in header order (evaluates the arguments in another order and changes the code) | @@ -301,7 +260,7 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | all | src/driver/mapdrv.c | mapSetMaterialTev | `#pragma opt_lifetimes off`: no lifetime splitting in mapSetMaterialTev, which gives the target register allocation | without it 328 of mapSetMaterialTev's 2,927 instructions use other registers (same length) (JP object compared) | | all | src/driver/msgdrv.c | msgWindow_Main | `#pragma opt_common_subs off`: no common subexpression elimination in msgWindow_Main, so its fields are reloaded as in the target | without it 445 of its 492 instructions differ (same length: reloads and registers) (JP object compared) | | all | src/driver/npcdrv.c | npcDisp_blur | `#pragma optimization_level 2`: npcDisp_blur is compiled at level 2, as the target code is | at the file's level npcDisp_blur is 205 instructions instead of 187 (JP object compared) | -| all | src/driver/npcdrv.c | npcSetTalkPose | `#pragma opt_propagation off`: turns off copy propagation so the temporaries and registers match the target | removing the pragma changes the code (JP object compared) | +| all | src/driver/npcdrv.c | npcCheckHitMarioSide | `#pragma opt_propagation off` and `opt_lifetimes off`: no copy propagation or lifetime splitting, so the temporaries and registers match the target | without them npcCheckHitMarioSide is 78.66% (G8ME01). npcSetTalkPose and npcSetStayPose, which the pragmas used to cover too, match without them | | all | src/driver/shadowdrv.c | cylinder | `#pragma dont_inline on`: keeps the following function(s) out of line as in the target | removing the pragma changes the code (JP object compared) | | all | src/event/evt_badgeshop.c | badgeShop_set | `#pragma dont_inline on`: keeps badgeShop_set out of line as in the target | without it badgeShop_set is inlined into badgeShop_bargainGeneration (433 -> 530 instructions) (JP object compared) | | all | src/event/evt_badgeshop.c | evt_badgeShop_bottakuru_dec | `#pragma opt_common_subs off`: turns off common subexpression elimination so the reloads match the target | removing the pragma changes the code (JP object compared) | @@ -440,22 +399,19 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | all | rels/tou2/src/unit/unit_piders.c | piders_get_target | `#pragma dont_inline on`: keeps piders_get_target a real call | without it piders_renzoku_attack_set_target is 63 instructions instead of 52 (JP object compared) | | JP, US, PAL | rels/yuu/src/event/evt_yuunpc.c | fallcheck | `#pragma dont_inline on` (releases only; the Japanese demo inlines it): keeps fallcheck a real call | without it fallcheck is inlined into yuunpc_pose_minigame4_main (3647 instructions instead of 3564) (JP object compared) | | all | rels/yuu/src/yuu_00.c | yuuminigame1_gamerule | `#pragma dont_inline on`: keeps yuuminigame1_gamerule a real call | without it yuuminigame1_gamerule is inlined into yuuminigame_main_1hikoki (188 instructions instead of 66) (JP object compared) | -| all | src/battle/battle_audience_kinopio.c | BattleAudienceCtrlProcessKinopioWait | `#pragma opt_propagation off` and `opt_lifetimes off` for BattleAudienceCtrlProcessKinopioWait: no copy propagation or lifetime splitting | without both it is 483 instructions instead of 491; without opt_propagation off alone 483; without opt_lifetimes off alone the same length with 3 instructions different (JP object compared) | +| all | src/battle/battle_audience_kinopio.c | BattleAudienceCtrlProcessKinopioWait | `th += (f32)(10.0f * a)`: an (f32) cast of a product that is already f32 (an extra tree node) | without the cast the US object differs (G8ME01 build); the earlier `opt_propagation`/`opt_lifetimes off` pragmas are no longer needed with the natural statement order | | all | src/battle/battle_disp.c | btlDispAnimeSpeed | `#pragma opt_dead_assignments off` (push/pop) around btlDispAnimeSpeed | without it the code is the same in all five builds, but the float constants 1.0, 2.0 and 5.0 in .sdata2 come out in a different order (JP object compared) | -| all | src/battle/battle_seq_command.c | _btlcmd_MakeMultiItemTable | `#pragma opt_propagation off` for _btlcmd_MakeMultiItemTable: no copy propagation, which gives the target temporaries and registers | without it _btlcmd_MakeMultiItemTable is 171 instructions instead of 180 (JP object compared) | | all | src/battle/battle_stage.c | BattleStageLightSetLightColor | `#pragma opt_propagation off` for BattleStageLightSetLightColor: no copy propagation, which gives the target temporaries and registers | without it BattleStageLightSetLightColor is 39 instructions instead of 41 (JP object compared) | | all | src/battle/battle_stage.c | BattleStageLightSetPosition | `#pragma opt_propagation off` for BattleStageLightSetPosition: no copy propagation, which gives the target temporaries and registers | without it BattleStageLightSetPosition is 38 instructions instead of 40 (JP object compared) | | all | src/battle/battle_stage.c | BattleStageLightSetTarget | `#pragma opt_propagation off` for BattleStageLightSetTarget: no copy propagation, which gives the target temporaries and registers; also `#pragma dont_inline on` ... `reset` around BattleStageLightSetTarget: keeps it out of line as in the target | without it BattleStageLightSetTarget is 41 instructions instead of 43 (JP object compared); dont_inline: without it BattleStageLightSetTarget is inlined into BattleStageLightSetTargetByUnit (46 -> 80 instructions) (all five versions compared) | | all | src/battle/battle_stage.c | BattleStageLightSetUpVec | `#pragma opt_propagation off` for BattleStageLightSetUpVec: no copy propagation, which gives the target temporaries and registers | without it BattleStageLightSetUpVec is 38 instructions instead of 40 (JP object compared) | | all | src/battle/battle_stage.c | BattleStageLightSetWidth | `#pragma opt_propagation off` for BattleStageLightSetWidth: no copy propagation, which gives the target temporaries and registers | without it BattleStageLightSetWidth is 28 instructions instead of 30 (JP object compared) | -| all | src/battle/battle_unit.c | BtlUnit_ControlPoseSoundMain | `#pragma opt_propagation off` (push/pop) for BtlUnit_ControlPoseSoundMain: no copy propagation, which gives the target temporaries and registers | without it BtlUnit_ControlPoseSoundMain is 167 instructions instead of 175 (JP object compared) | | all | src/driver/animdrv.c | animPoseDisp_MakeExtTexture | `#pragma opt_lifetimes off` (push/pop) for animPoseDisp_MakeExtTexture: no lifetime splitting, which gives the target register allocation | without it animPoseDisp_MakeExtTexture keeps its length (481) with 13 instructions different (JP object compared) | | all | src/effect/eff_damage_star.c | effDamageStarEntry | `#pragma opt_propagation off` and `opt_lifetimes off` for effDamageStarEntry: no copy propagation or lifetime splitting, which gives the target register allocation and scheduling | without both effDamageStarEntry is 235 instructions instead of 216; without opt_propagation off alone 235; without opt_lifetimes off alone the same length with 118 instructions different (JP object compared) | | all | src/effect/eff_gonbaba_breath.c | init_breath | `#pragma opt_propagation off` and `opt_lifetimes off` for init_breath: no copy propagation or lifetime splitting, which gives the target register allocation and scheduling | without both init_breath is 412 instructions instead of 376; without opt_propagation off alone 412; without opt_lifetimes off alone the same length with 136 instructions different (JP object compared) | | all | src/effect/eff_kemuri.c | effKemuri2Entry | `#pragma opt_propagation off` for effKemuri2Entry: no copy propagation, which gives the target temporaries and registers | without it effKemuri2Entry is 128 instructions instead of 136 (effKemuriEntry also changes) (JP object compared) | | all | src/effect/eff_kemuri.c | effKemuri2Main | `#pragma opt_propagation off` for effKemuri2Main: no copy propagation, which gives the target temporaries and registers | without it effKemuri2Main is 116 instructions instead of 117 (effKemuriEntry, effKemuriMain and effKemuri2Entry also change) (JP object compared) | | all | src/effect/eff_mobj_broken.c | effMObjBrokenMain | `#pragma opt_propagation off` and `opt_lifetimes off` for effMObjBrokenMain: no copy propagation or lifetime splitting, which gives the target register allocation and scheduling | without both effMObjBrokenMain is 285 instructions instead of 278; without opt_propagation off alone 285, without opt_lifetimes off alone 286 (effMObjBrokenEntry also changes) (JP object compared) | -| all | src/effect/eff_sleep.c | sleepPos, effSleepDisp | `#pragma opt_propagation off` (push/pop) around sleepPos and effSleepDisp | without it the code is the same in all five builds, but two of the float constants in .sdata2 (1/64 and 0.5) swap places (JP object compared) | | all | src/effect/eff_starpoint.c | effStarPointEntry | `#pragma opt_propagation off` and `opt_lifetimes off` for effStarPointEntry: no copy propagation or lifetime splitting, which gives the target register allocation and scheduling (see also the _cosf row) | without both effStarPointEntry is 205 instructions instead of 201 (JP object compared) | | all | src/effect/eff_syuryou.c | effSyuryouMain | `#pragma opt_dead_assignments off` (push/pop) around effSyuryouMain: keeps the dead assignments the target has (the site comment also names effSyuryouDisp, which is after the pop) | without it effSyuryouMain keeps its length (139) with 7 instructions different; effSyuryouDisp is unchanged (JP object compared) | | all | src/effect/n64/eff_ice_n64.c | effIceDisp | `#pragma opt_lifetimes off` (set before effIceMain, never reset) also covers effIceDisp | without it effIceDisp keeps its length (194) with 2 instructions different (JP object compared) | @@ -470,7 +426,6 @@ Why a no-op cast or a spare temp can change the output: MWCC builds an expressio | all | src/effect/n64/eff_small_star_n64.c | _cosf, alphaf (inlined into effSmallStarMain), effSmallStarMain | `#pragma opt_propagation off` and `opt_lifetimes off` around the two inline helpers and effSmallStarMain: no copy propagation or lifetime splitting | without both effSmallStarMain is 226 instructions instead of 217 (effSmallStarN64Entry also changes); without opt_propagation off alone the same; without opt_lifetimes off alone 217 with 16 instructions different (JP object compared) | | all | src/effect/n64/eff_stardust2_n64.c | effStardust2Main | `#pragma opt_propagation off` for effStardust2Main: no copy propagation, which gives the target temporaries and registers | without it effStardust2Main is 330 instructions instead of 333 (effStardust2N64Entry also changes) (JP object compared) | | all | src/effect/n64/eff_sweat_n64.c | effSweatDisp | `#pragma opt_loop_invariants off` for effSweatDisp: no loop-invariant code motion, which gives the target loop code | without it effSweatDisp is 219 instructions instead of 218 (effSweatMain and effSweatN64Entry also change) (JP object compared) | -| all | src/sdk/arc.c | entryToPath | `#pragma inline_depth(3)` from entryToPath to the end of the file: limits the inlining depth | without it entryToPath is 169 instructions instead of 136; the ARC functions after it do not change (JP object compared) | | all | src/effect/eff_updown.c | iconGetTexObj (local prototype) | iconGetTexObj takes the icon id as u16 (icondrv.h: s16/s32 by version), as this file was compiled | the header prototype (deleting the local line and including the header): the object changes in every version (trial build 10-29) | | all | src/effect/n64/eff_balloon_n64.c | tri1 (local prototype) | tri1 is declared without parameters (eff_n64.h: (u16, u16, u16, u16)), as this file was compiled | the header prototype (deleting the local line and including the header): the object changes in every version (trial build 10-29) | | all | src/effect/n64/eff_sweat_n64.c | sin (local prototype) | sin takes a float (libc: double), as this file was compiled | the header prototype (deleting the local line and including the header): the object changes in every version (trial build 10-29) | diff --git a/docs/KNOWN_GAME_BUGS.md b/docs/KNOWN_GAME_BUGS.md index eca8546b5..e53161926 100644 --- a/docs/KNOWN_GAME_BUGS.md +++ b/docs/KNOWN_GAME_BUGS.md @@ -36,8 +36,6 @@ Each entry names the file and the function (or script) that holds the bug, with | `rels/tik/src/tik_06.c`, script `evt_kanban2` (`GSW(GSW_JON_STAR_PIECES_FOUND)`) | all | The Pit of 100 Trials sign prints GSW 34 as a Star Piece count out of 100, but nothing in the game writes GSW 34, so the count is always 0. | | `src/driver/msgdrv.c`, `msgAnalize` (the `` / `` ruby tags) | all | The closing ruby tag test compares one character with the two-character constant `'/r'` (the fontmgr bug again), so only `` tags are handled there. | | `src/manager/evtmgr_cmd.c`, `evt_readf_n` (`READ_FLOAT_INDEXED`, `entry->readAddr[offset]`) | all | The indexed float read takes the word through the integer view of the read pointer and converts it, so a float table entry comes out as the integer value of its bits; `READ_FLOAT` to `READ_FLOAT4` read floats correctly. | -| `src/party/party_move.c`, `partyMoveBehindMario3` (the `party_set_behind_dir` call) | all | `party_set_behind_dir` takes a direction, but the call passes none, so the partner's home direction is whatever is left in the first float register. | -| `src/party/party_yoshi.c`, `L_getStick` (inlined into `yoshi_use`, the `marioGetMoveRate` calls) | JP, US and PAL (the demo passes the angle) | `marioGetMoveRate` takes a direction, but both calls pass none, so it reads the angle just stored, which is left in the first float register. | | `rels/las/src/las_05.c`, `_kurokaron_run_away` (`result`) | all | With no candidate position and the current distance not smaller than the next one, `result` is never set and the function returns whatever its register held. | | `rels/rsh/src/rsh.c`, `rsh_window_tev` (`x0`..`y1`) | all | When no parent map object has flag 0x10, the screen rectangle `x0`, `y0`, `x1`, `y1` is never set and is read uninitialised. | | `src/battle/battle_disp.c`, `btlDispMain` (`part->animFlags &= ~PART_ANIM_RESTART` in an `if`) | all | `&=` where `&` was meant: the test clears PART_ANIM_RESTART and checks the flags that are left, so the pose restarts whenever another flag (normally PART_ANIM_MANUAL_POSE) is set. Only Hooktail sets PART_ANIM_RESTART, and gets the restart anyway: no visible effect. | diff --git a/include/battle/battle.h b/include/battle/battle.h index 662927d81..f72890974 100644 --- a/include/battle/battle.h +++ b/include/battle/battle.h @@ -365,4 +365,4 @@ void BattleStatusWindowAPRecoveryOn(void); void BattleStatusWindowEventOff(void); u8 BattleMajinaiCheck(void); BOOL BattleStatusWindowCheck(void); -void BattlePartyAnimeLoad(s32 partyId); +BOOL BattlePartyAnimeLoad(s32 partyId); diff --git a/include/battle/battle_ac.h b/include/battle/battle_ac.h index 83b5632d4..2afccc513 100644 --- a/include/battle/battle_ac.h +++ b/include/battle/battle_ac.h @@ -84,4 +84,4 @@ void BattleAcGaugeSeUpdate(f32 value); void BattleAcGaugeSeDelete(void); s32 BattleActionCommandCheckDefence(BattleUnit* unit, BattleWeapon* weapon); u16 BattleACGetButtonIcon(s32 button, s32 pressed); -void BattleAcDrawGauge(s32 x, s32 y, s32 width, f32 ratio, s32 level, s32 a, s32 b, s32 c, s32 flags); +void BattleAcDrawGauge(s32 x, s32 y, f32 ratio, s32 width, s32 level, s32 a, s32 b, s32 c, s32 flags); diff --git a/include/battle/battle_audience.h b/include/battle/battle_audience.h index 6aebc9133..932460025 100644 --- a/include/battle/battle_audience.h +++ b/include/battle/battle_audience.h @@ -414,4 +414,4 @@ void BattleAudience_Case_FirstAttack_Bad(void); s32 BattleAudienceAddAudienceNum(s32 num); void BattleAudienceSoundSetVol(s32 index, u8 a2, s32 a3); s32 BattleAudienceSoundCheck(s32 index); -BOOL BattleAudience_GetEscapeChangeOK(s32 index); +u8 BattleAudience_GetEscapeChangeOK(s32 index); diff --git a/include/battle/battle_unit.h b/include/battle/battle_unit.h index 4b26b91a4..d8173659e 100644 --- a/include/battle/battle_unit.h +++ b/include/battle/battle_unit.h @@ -1018,11 +1018,12 @@ void BtlUnit_SetMoveSpeed(BattleUnit* unit, f32 moveSpeedXZ); void BtlUnit_SetPartsMoveSpeed(BattleUnitPart* part, f32 moveSpeedXZ); void BtlUnit_SetJumpSpeed(BattleUnit* unit, f32 moveSpeedY); s8 BtlUnit_GetBelong(BattleUnit* unit); -void BtlUnit_GetStatus(BattleUnit* unit, StatusEffectType type, s8* turns, s8* strength); -BOOL BtlUnit_SetStatus(BattleUnit* unit, StatusEffectType type, s8 turns, s8 strength); +// The status functions take the StatusEffectType as s8, so callers sign-extend a variable id. +void BtlUnit_GetStatus(BattleUnit* unit, s8 type, s8* turns, s8* strength); +BOOL BtlUnit_SetStatus(BattleUnit* unit, s8 type, s8 turns, s8 strength); void BtlUnit_ClearStatus(BattleUnit* unit); -BOOL BtlUnit_CheckRecoveryStatus(BattleUnit* unit, StatusEffectType type); -BOOL BtlUnit_CheckStatus(BattleUnit* unit, StatusEffectType type); +BOOL BtlUnit_CheckRecoveryStatus(BattleUnit* unit, s8 type); +BOOL BtlUnit_CheckStatus(BattleUnit* unit, s8 type); s32 BtlUnit_CheckStatusFlag(BattleUnit* unit, s32 flags); void BtlUnit_OnStatusFlag(BattleUnit* unit, s32 flags); void BtlUnit_OffStatusFlag(BattleUnit* unit, s32 flags); @@ -1050,7 +1051,7 @@ BOOL BtlUnit_CheckData(BattleUnit* unit, s32 tag); BOOL BtlUnit_GetEnemyBelong(BattleUnit* unit); void BtlUnit_ReviseHpFp(BattleUnit* unit); void BtlUnit_SetParamFromPouch(BattleUnit* unit); -s32 BtlUnit_snd_se(BattleUnit* unit, const char* sfxName, s32 volume, s32 pan); +s32 BtlUnit_snd_se(BattleUnit* unit, const char* sfxName, s32 volume, s16 pitch); s32 BtlUnit_snd_se_pos(BattleUnit* unit, const char* sfxName, s32 volume, s16 pitch, Vec* pos); BattleUnit* BtlUnit_GetGuardKouraPtr(BattleUnit* unit); diff --git a/include/driver/animdrv.h b/include/driver/animdrv.h index 3d13341ca..536c76363 100644 --- a/include/driver/animdrv.h +++ b/include/driver/animdrv.h @@ -433,4 +433,4 @@ void L_animPoseWorldPositionEvalOff(s32 poseId); void animPoseDrawShape(s32 poseId, s32 shapeId); void animPoseSetDispCallBack(s32 poseId, void* callback, void* userData); void animPoseVivianMain(s32 poseId, Vec* pos); -void animPoseDisp_MakeExtTexture(const char* group, const char* anim, f32 frame, f32 scale, GXTexObj* obj, struct smartEntry** image, s32* x0, s32* y0, s32* x1, s32* y1); +void animPoseDisp_MakeExtTexture(const char* group, const char* anim, f32 frame, f32 scale, GXTexObj* obj, void** image, s32* x0, s32* y0, s32* x1, s32* y1); diff --git a/include/driver/envdrv.h b/include/driver/envdrv.h index 2169dc285..fb37281b1 100644 --- a/include/driver/envdrv.h +++ b/include/driver/envdrv.h @@ -80,7 +80,7 @@ void envBlurOff(void); struct MapTevCallbackInfo; void envSetWater(struct MapTevCallbackInfo* info); -void envGlareFilter(s32 type, s32 y0, s32 x0, s32 y1, s32 x1); +void envGlareFilter(s32 type, s16 y0, s16 x0, s16 y1, s16 x1); void envGlareFilterZ(f32 zscale); void envAddTev(s32 type, MapTevCallbackInfo* info); void envSetYamiView(Mtx view); diff --git a/include/driver/extdrv.h b/include/driver/extdrv.h index 4162e347f..f84ed263d 100644 --- a/include/driver/extdrv.h +++ b/include/driver/extdrv.h @@ -28,7 +28,7 @@ typedef struct ExtdrvPose { } ExtdrvPose; typedef struct ExtdrvTex { - void** image; // 0x0 + void* image; // 0x0 GXTexObj obj; // 0x4 GXTexRegion region; // 0x24 } ExtdrvTex; diff --git a/include/driver/icondrv.h b/include/driver/icondrv.h index 2931d996a..3a85f25d1 100644 --- a/include/driver/icondrv.h +++ b/include/driver/icondrv.h @@ -108,7 +108,7 @@ void iconChange(const char* name, u16 iconId); void iconDispGxAlpha(Vec* position, s16 flags, u16 iconId, u8 alpha, f32 scale); void iconDispGx(Vec* position, s16 flags, u16 iconId, f32 scale); void iconDispGx2(Mtx mtx, s16 flags, u16 iconId); -void iconDispGxCol(Mtx pos, s16 flags, u16 iconId, GXColor color); +void iconDispGxCol(Mtx pos, u16 flags, u16 iconId, GXColor color); #if VERSION >= VERSION_US void iconGetTexObj(GXTexObj* texObj, s32 iconId); #else diff --git a/include/driver/lightdrv.h b/include/driver/lightdrv.h index a5befd742..aad79c95a 100644 --- a/include/driver/lightdrv.h +++ b/include/driver/lightdrv.h @@ -39,13 +39,13 @@ typedef struct LightWork { void lightInit(void); void lightReInit(void); void lightMain(void); -s32 lightEntry(const char* name, s32 type, Vec* position, Vec* rotation, GXColor color, s32 attenType, s32 flags, f32 spotAngle, f32 attenAngle); +s32 lightEntry(const char* name, s32 type, Vec* position, Vec* rotation, GXColor color, f32 spotAngle, f32 attenAngle, s32 attenType, s32 flags); LightEntry* lightNameToPtr(const char* name); LightEntry* lightNumberToPtr(s32 index); LightEntry* lightGetPaperCraft(void); s32 lightGetEntryNum(void); LightEntry* lightGetAmbient(void); -s32 lightGetNearObj(Vec position, LightEntry** out, s32 count, LightEntryFlags flags); +s32 lightGetNearObj(Vec* position, LightEntry** out, s32 count, LightEntryFlags flags); LightEntry* lightGetCharaAmbient(void); s32 lightCheckCharaLight(void); diff --git a/include/manager/evtmgr.h b/include/manager/evtmgr.h index 98852e115..7d1d02421 100644 --- a/include/manager/evtmgr.h +++ b/include/manager/evtmgr.h @@ -272,7 +272,7 @@ typedef struct EventWork { EventWork* evtGetWork(void); void evtmgrInit(void); void evtmgrReInit(void); -EventEntry* evtEntry(void* evtCode, u8 priority, u8 flags); +EventEntry* evtEntry(void* evtCode, s32 priority, u8 flags); EventEntry* evtEntryType(void* evtCode, u8 priority, u8 flags, u8 type); EventEntry* evtChildEntry(EventEntry* parent, void* evtCode, u8 flags); EventEntry* evtBrotherEntry(EventEntry* brother, void* evtCode, u8 flags); diff --git a/include/mario/mario_pouch.h b/include/mario/mario_pouch.h index ef3b3947a..5269bb9bb 100644 --- a/include/mario/mario_pouch.h +++ b/include/mario/mario_pouch.h @@ -471,19 +471,19 @@ s32 pouchGetStarPiece(void); s16 pouchAddStarPiece(s16 count); s16 pouchAddHP(s32 points); s32 pouchGetHP(void); -s16 pouchGetMaxHP(void); -void pouchSetHP(s16 points); +s32 pouchGetMaxHP(void); +void pouchSetHP(s32 points); void pouchSetMaxHP(s16 points); s32 pouchGetPartyHP(PartyId partnerId); void pouchSetPartyHP(s32 partnerId, s32 points); s32 pouchGetFP(void); -s16 pouchGetMaxFP(void); -void pouchSetFP(s16 points); +s32 pouchGetMaxFP(void); +void pouchSetFP(s32 points); void pouchSetMaxFP(s16 points); s32 pouchGetAP(void); void pouchAddAP(s32 points); -void pouchSetAP(s16 points); -s16 pouchGetMaxAP(void); +void pouchSetAP(s32 points); +s32 pouchGetMaxAP(void); f32 pouchGetAudienceNum(void); void pouchSetAudienceNum(f32 num); s32 pouchGetJumpLv(void); diff --git a/include/mot/mot_slit.h b/include/mot/mot_slit.h index e4d93f947..102eaf2a4 100644 --- a/include/mot/mot_slit.h +++ b/include/mot/mot_slit.h @@ -12,7 +12,7 @@ BOOL marioChkSlitEnd(void); BOOL marioChkSlitThrouh(void); BOOL marioGetMotSlitCancel3(void); -BOOL marioCreviceWallChk(const Vec* p); +BOOL marioCreviceWallChk(Vec pos); void marioSlitReenter(void); void N_marioSlitSetAfterLand(void); BOOL marioSlitKeyDisable(void); diff --git a/include/party/party_move.h b/include/party/party_move.h index 591a3fc82..3f9f64cb8 100644 --- a/include/party/party_move.h +++ b/include/party/party_move.h @@ -59,7 +59,7 @@ BOOL partyChkNoStandMobj(struct HitEntry* hit); void partyChgMoveMode(PartyEntry* party, s32 mode); void partySetDir(PartyEntry* party, f32 x, f32 z); void partyMoveBehindMario(PartyEntry* party, s32 arg); -void partyMoveBehindMario3(PartyEntry* party, s32 arg); +void partyMoveBehindMario3(PartyEntry* party, s32 arg, f32 dir); void partyMoveBesideMario(PartyEntry* party, s32 arg); void partyMoveCheckWall(PartyEntry* party); void partyChkWall(PartyEntry* party); diff --git a/rels/eki/src/eki_03.c b/rels/eki/src/eki_03.c index 210be30e1..4662fe20b 100644 --- a/rels/eki/src/eki_03.c +++ b/rels/eki/src/eki_03.c @@ -23,8 +23,6 @@ #include "evt/evt_story.h" static smartEntry* ind_lp; -// FAKE: eki_03.c calls envGlareFilter through this prototype (the types it was compiled with) instead of the one in driver/envdrv.h; same registers, behaviour-identical. -typedef void (*EnvGlareFilterS16Fn)(s32, s16, s16, s16, s16); static USER_FUNC(test_glare); static void sun_tev(MapTevCallbackInfo* info); @@ -565,7 +563,7 @@ static USER_FUNC(test_glare) { } else if (rect[0] == 0 && rect[1] == 0 && rect[2] == 0 && rect[3] == 0) { envGlareFilter(0, 0, 0, 0, 0); } else { - ((EnvGlareFilterS16Fn)envGlareFilter)(1, rect[1] - 50, rect[0] - 50, rect[3] + 50, rect[2] + 50); + envGlareFilter(1, rect[1] - 50, rect[0] - 50, rect[3] + 50, rect[2] + 50); #if VERSION <= VERSION_DEMO_JP envGlareFilterZ(0.998f); #else diff --git a/rels/gor/src/gor_01.c b/rels/gor/src/gor_01.c index 2013a63a4..bea165b55 100644 --- a/rels/gor/src/gor_01.c +++ b/rels/gor/src/gor_01.c @@ -7376,7 +7376,7 @@ static USER_FUNC(cook_chk) { } parsePop(); fileFree(file); - // FAKE: volatile casts, see the retail cook_chk. + // FAKE: the (volatile u32) casts order the args[n] loads after the inlined itemNameToID as in the target. evtSetValue(event, (volatile u32)args[1], itemNameToID(result)); evtSetValue(event, (volatile u32)args[2], itemNameToID(result2)); return EVT_RETURN_DONE; @@ -7401,7 +7401,7 @@ static USER_FUNC(cook_chk2) { if (item1 == 163 || item2 == 163) { item2 = naniga_okorukana_cook(); - // FAKE: volatile cast, see the retail cook_chk. + // FAKE: volatile cast, as in cook_chk above. evtSetValue(event, (volatile u32)args[2], item2); return EVT_RETURN_DONE; } @@ -7433,7 +7433,7 @@ static USER_FUNC(cook_chk2) { } parsePop(); fileFree(file); - // FAKE: volatile cast, see the retail cook_chk. + // FAKE: volatile cast, as in cook_chk above. evtSetValue(event, (volatile u32)args[2], itemNameToID(out)); return EVT_RETURN_DONE; } @@ -7447,21 +7447,23 @@ static USER_FUNC(cook_chk2) { static USER_FUNC(cook_chk) { EvtWord* args = event->args; s32 item = evtGetValue(event, args[0]); + s32 cook; ItemData* data = &itemDataTable[item]; u32 i; + ItemType id; if (item == 163) { - item = naniga_okorukana_cook(); - evtSetValue(event, args[1], item); - evtSetValue(event, args[2], item); + cook = naniga_okorukana_cook(); + evtSetValue(event, args[1], cook); + evtSetValue(event, args[2], cook); return EVT_RETURN_DONE; } for (i = 0; i < 26; i++) { if (strcmp(data->id, R_simple_recipe_table[i].ingredient) == 0) { - // FAKE: the (volatile u32) casts order the args[n] loads after the inlined itemNameToID as in the target - // (tried: a result local, a u32 cast of the result, event->args[n]). - evtSetValue(event, (volatile u32)args[1], itemNameToID(R_simple_recipe_table[i].result)); - evtSetValue(event, (volatile u32)args[2], itemNameToID(R_simple_recipe_table[i].result2)); + id = itemNameToID(R_simple_recipe_table[i].result); + evtSetValue(event, args[1], id); + id = itemNameToID(R_simple_recipe_table[i].result2); + evtSetValue(event, args[2], id); return EVT_RETURN_DONE; } } @@ -7482,12 +7484,13 @@ static USER_FUNC(cook_chk2) { s32 item2 = evtGetValue(event, args[1]); ItemData* data1 = &itemDataTable[item1]; ItemData* data2 = &itemDataTable[item2]; + CookRecipe* recipe; u32 i; + ItemType id; if (item1 == 163 || item2 == 163) { - item2 = naniga_okorukana_cook(); - // FAKE: volatile cast, see cook_chk. - evtSetValue(event, (volatile u32)args[2], item2); + id = naniga_okorukana_cook(); + evtSetValue(event, args[2], id); return EVT_RETURN_DONE; } #if VERSION >= VERSION_US @@ -7495,10 +7498,11 @@ static USER_FUNC(cook_chk2) { #else for (i = 0; i < 289; i++) { #endif - if ((strcmp(data1->id, R_cookbook_recipe_table[i].a) == 0 && strcmp(data2->id, R_cookbook_recipe_table[i].b) == 0) || - (strcmp(data2->id, R_cookbook_recipe_table[i].a) == 0 && strcmp(data1->id, R_cookbook_recipe_table[i].b) == 0)) { - // FAKE: volatile cast, see cook_chk. - evtSetValue(event, (volatile u32)args[2], itemNameToID(R_cookbook_recipe_table[i].out)); + recipe = &R_cookbook_recipe_table[i]; + if ((strcmp(data1->id, recipe->a) == 0 && strcmp(data2->id, recipe->b) == 0) || + (strcmp(data2->id, recipe->a) == 0 && strcmp(data1->id, recipe->b) == 0)) { + id = itemNameToID(R_cookbook_recipe_table[i].out); + evtSetValue(event, args[2], id); return EVT_RETURN_DONE; } } diff --git a/rels/hom/src/hom_00.c b/rels/hom/src/hom_00.c index 63a66aeae..7a8984681 100644 --- a/rels/hom/src/hom_00.c +++ b/rels/hom/src/hom_00.c @@ -35,8 +35,6 @@ #include "version.h" #include "evt/evt_story.h" #include "driver/casedrv.h" -// FAKE: hom_00.c calls envGlareFilter through this prototype (the types it was compiled with) instead of the one in driver/envdrv.h; same registers, behaviour-identical. -typedef void (*EnvGlareFilterS16Fn)(s32, s16, s16, s16, s16); static smartEntry* ind_lp; @@ -989,7 +987,7 @@ static USER_FUNC(test_glare) { envGlareFilter(0, 0, 0, 0, 0); } else { // The glare box is the sun's screen rectangle grown by 50 on each side. - ((EnvGlareFilterS16Fn)envGlareFilter)(1, rect[1] - 50, rect[0] - 50, rect[3] + 50, rect[2] + 50); + envGlareFilter(1, rect[1] - 50, rect[0] - 50, rect[3] + 50, rect[2] + 50); } return EVT_RETURN_BLOCK; } diff --git a/rels/jin/src/unit/unit_faker_mario.c b/rels/jin/src/unit/unit_faker_mario.c index ed5e43630..c8c1bc765 100644 --- a/rels/jin/src/unit/unit_faker_mario.c +++ b/rels/jin/src/unit/unit_faker_mario.c @@ -27,8 +27,6 @@ enum { UW_FAKER_MARIO_HP_50 = 2, // 50% of his max HP: below it he complains (stg4_jin_26_01) UW_FAKER_MARIO_HP_25 = 3, // 25% of his max HP: below it he is nearly beaten (stg4_jin_26_02) }; -// FAKE: unit_faker_mario.c calls BattlePartyAnimeLoad through this prototype (the types it was compiled with) instead of the one in battle/battle.h; same registers, behaviour-identical. -typedef BOOL (*BattlePartyAnimeLoadRetBoolFn)(s32); typedef struct FakerStatus { s16 data[15]; @@ -110,7 +108,7 @@ static USER_FUNC(_anime_load_wait) { anime = UNIT_YOSHI; break; } - if (((BattlePartyAnimeLoadRetBoolFn)BattlePartyAnimeLoad)(anime)) { + if (BattlePartyAnimeLoad(anime)) { return EVT_RETURN_DONE; } return EVT_RETURN_BLOCK; @@ -142,7 +140,7 @@ static USER_FUNC(_anime_load) { anime = UNIT_YOSHI; break; } - ((BattlePartyAnimeLoadRetBoolFn)BattlePartyAnimeLoad)(anime); + BattlePartyAnimeLoad(anime); return EVT_RETURN_DONE; } diff --git a/rels/mri/include/driver/punidrv.h b/rels/mri/include/driver/punidrv.h index 1e98dbea4..17260e64d 100644 --- a/rels/mri/include/driver/punidrv.h +++ b/rels/mri/include/driver/punidrv.h @@ -29,7 +29,7 @@ typedef struct PunidrvPose { } PunidrvPose; typedef struct PunidrvTex { - void** image; // 0x0 + void* image; // 0x0 GXTexObj obj; // 0x4 GXTexRegion region; // 0x24 } PunidrvTex; diff --git a/rels/mri/src/driver/punidrv.c b/rels/mri/src/driver/punidrv.c index ba8240a1b..8df8fa1e7 100644 --- a/rels/mri/src/driver/punidrv.c +++ b/rels/mri/src/driver/punidrv.c @@ -13,8 +13,6 @@ #include "libc_decls.h" static void puniMakeTexture(CameraId camId, void* param); -// FAKE: punidrv.c calls animPoseDisp_MakeExtTexture through this prototype (the types it was compiled with) instead of the one in driver/animdrv.h; same registers, behaviour-identical. -typedef void (*AnimPoseDisp_MakeExtTextureLocalFn)(const char*, const char*, f32, f32, GXTexObj*, void***, s32*, s32*, s32*, s32*); static f32 camGetRy(void); static s32 compare(const void* a, const void* b); @@ -175,7 +173,7 @@ static void puniMakeTexture(CameraId camId, void* param) { anim_ext_tex_size = 0; for (i = 0; i < wp->texNum; i++, info++, tex++) { n = i * 12; - ((AnimPoseDisp_MakeExtTextureLocalFn)animPoseDisp_MakeExtTexture)(info->group, info->anim, info->frame, 5.84f, &tex->obj, &tex->image, &x0, &y0, &x1, &y1); + animPoseDisp_MakeExtTexture(info->group, info->anim, info->frame, 5.84f, &tex->obj, &tex->image, &x0, &y0, &x1, &y1); wp->vtx[n++] = x0 * scale; wp->vtx[n++] = -y0 * scale; wp->vtx[n++] = 0.0f; diff --git a/rels/mri/src/mri_16.c b/rels/mri/src/mri_16.c index 8759480b9..55ede90cd 100644 --- a/rels/mri/src/mri_16.c +++ b/rels/mri/src/mri_16.c @@ -38,18 +38,11 @@ static HitDamageReturn hitDmgRetPoints[5]; /** * Reads the bar-switch state ssf for the script: * returns it as a float in args[0] (0 idle, 1 Mario is riding the bar switch, 2 he left it). - * The odd extra statements only keep the compiled order of the original. */ static USER_FUNC(ss_check) { - s32 dest; - s32 notSet; + EvtWord* args = event->args; + s32 dest = *args++; - // FAKE: the dead condition moves the ssf load ahead of event->args; casts, temps and u32 index variants do not - // reproduce it - dest = event->args[0]; - notSet = !ssf; - if ((notSet && !ssf) != 0) { - } evtSetFloat(event, dest, ssf); return EVT_RETURN_DONE; } diff --git a/rels/tik/src/tik_00.c b/rels/tik/src/tik_00.c index 22422dc0c..2941719aa 100644 --- a/rels/tik/src/tik_00.c +++ b/rels/tik/src/tik_00.c @@ -486,16 +486,10 @@ static USER_FUNC(setmertn) { /** Script helper. Stores the module-level flag ssf (set by ss_set) into the variable args[0]. */ static USER_FUNC(ss_check) { - s32 a; - s32 z; - - // FAKE: the dead condition moves the ssf load ahead of event->args; casts, temps and - // u32 index variants do not reproduce it - a = event->args[0]; - z = !ssf; - if ((z && !ssf) != 0) { - } - evtSetFloat(event, a, ssf); + EvtWord* args = event->args; + s32 dest = *args++; + + evtSetFloat(event, dest, ssf); return EVT_RETURN_DONE; } diff --git a/src/battle/ac/ac_air_gauge.c b/src/battle/ac/ac_air_gauge.c index 671f7a15c..b1fe88343 100644 --- a/src/battle/ac/ac_air_gauge.c +++ b/src/battle/ac/ac_air_gauge.c @@ -437,7 +437,7 @@ static void actionCommandDisp(f32 x, f32 y) { disp->gaugeRatio = ratio; } } - BattleAcDrawGauge((s32)x, (s32)y, 0xB2, disp->gaugeRatio, ac->params[2], ac->params[3], ac->params[4], + BattleAcDrawGauge((s32)x, (s32)y, disp->gaugeRatio, 0xB2, ac->params[2], ac->params[3], ac->params[4], ac->params[5], 0); if (pw->flag) { Vec pos = {0.0f, 0.0f, 0.0f}; diff --git a/src/battle/ac/ac_gauge_timing.c b/src/battle/ac/ac_gauge_timing.c index abf898d45..cb305bfc0 100644 --- a/src/battle/ac/ac_gauge_timing.c +++ b/src/battle/ac/ac_gauge_timing.c @@ -407,9 +407,9 @@ static void actionCommandDisp(f32 x, f32 y) { t = 100.0f; } if (cw->timer > 0) { - BattleAcDrawGauge((s32)x, (s32)y, 0xB2, -1.0f, 100, 100, 100, 100, 0); + BattleAcDrawGauge((s32)x, (s32)y, -1.0f, 0xB2, 100, 100, 100, 100, 0); } else { - BattleAcDrawGauge((s32)x, (s32)y, 0xB2, t, 100, 100, 100, 100, 0); + BattleAcDrawGauge((s32)x, (s32)y, t, 0xB2, 100, 100, 100, 100, 0); } if (cw->gauge >= (f32)g->target) { icon = ICON_095; @@ -425,7 +425,7 @@ static void actionCommandDisp(f32 x, f32 y) { break; } default: { - BattleAcDrawGauge((s32)x, (s32)y, 0xB2, 0.0f, 100, 100, 100, 100, 0); + BattleAcDrawGauge((s32)x, (s32)y, 0.0f, 0xB2, 100, 100, 100, 100, 0); if (cw->timer <= 0) { CameraEntry* cam = camGetPtr(CAMERA_2D); rx = (-200.0f + x - 88.0f) + 173.0f * cw->gauge / 100.0f; diff --git a/src/battle/ac/ac_monosiri_target.c b/src/battle/ac/ac_monosiri_target.c index af25cceb3..d43e05e34 100644 --- a/src/battle/ac/ac_monosiri_target.c +++ b/src/battle/ac/ac_monosiri_target.c @@ -11,10 +11,6 @@ #include #include "version.h" -// FAKE: ac_monosiri_target.c calls iconDispGx through this prototype (the types it was compiled with) instead of the one in driver/icondrv.h; same registers, behaviour-identical. -typedef void (*IconDispGxS32S32Fn)(Vec*, s32, s32, f32); -// FAKE: ac_monosiri_target.c calls BattleACGetButtonIcon through this prototype (the types it was compiled with) instead of the one in battle/battle_ac.h; same registers, behaviour-identical. -typedef s32 (*BattleACGetButtonIconRetS32Fn)(s32, s32); // US battle texture ids are 0x16 higher for these entries. #define BTL_TEX(id) ((id) + VERSION_PICK(0, 0x16)) @@ -177,13 +173,12 @@ void battleAcDelete_MonosiriTarget(BattleWork* work) { */ static void actionCommandDisp(f32 x, f32 y) { BattleWork* work = _battleWorkPointer; - BattleActions* ac = &work->actionCommands; - MonosiriTargetWork* cw = (MonosiriTargetWork*)ac->work; + MonosiriTargetWork* cw = (MonosiriTargetWork*)work->actionCommands.work; f32 alpha = 0.0f; Vec screen; Vec screen2; - s32 icon; - s32 pressedIcon; + u16 iconOn; + u16 iconOff; btlGetScreenPoint(&cw->pos, &screen); btlDispTex4(BTL_TEX(0x42), screen, (Vec){1.0f, 1.0f, 1.0f}, (Vec){0.0f, 0.0f, 0.0f}, (GXColor){255, 255, 255, 255}); @@ -191,14 +186,9 @@ static void actionCommandDisp(f32 x, f32 y) { screen.y -= 4.0f; screen.z -= 2.0f; btlDispTex4(BTL_TEX(0x42), screen, (Vec){1.0f, 1.0f, 1.0f}, (Vec){0.0f, 0.0f, 0.0f}, (GXColor){128, 128, 128, 255}); - - if (cw->inRange) { - s32 t = cw->inRangeCnt % 30; - if (t < 20) { - alpha = 0.01f * intplGetValue(5, 100.0f, 0.0f, t, 20); - } + if (cw->inRange && cw->inRangeCnt % 30 < 20) { + alpha = 0.01f * intplGetValue(5, 100.0f, 0.0f, cw->inRangeCnt % 30, 20); } - btlGetScreenPoint(&cw->targetPos, &screen2); btlDispTex4(BTL_TEX(0x41), screen2, (Vec){1.0f, 1.0f, 1.0f}, (Vec){0.0f, 0.0f, cw->angle}, (GXColor){255, 255, 255, 255}); if (alpha > 0.0f) { @@ -209,12 +199,8 @@ static void actionCommandDisp(f32 x, f32 y) { screen2.z -= 2.0f; btlDispTex4(BTL_TEX(0x41), screen2, (Vec){1.0f, 1.0f, 1.0f}, (Vec){0.0f, 0.0f, cw->angle}, (GXColor){128, 128, 128, 255}); cw->angle += 2.0f; - - pressedIcon = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(PAD_BUTTON_A, 1); - icon = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(PAD_BUTTON_A, 0); - if (__fabs(cw->pos.x - cw->targetPos.x) < 15.0) { - icon = pressedIcon; - } - ((IconDispGxS32S32Fn)iconDispGx)(&(Vec){-200.0f + x, 50.0f + y, 0.0f}, ICON_DISP_2D, icon, 1.0f); + iconOn = BattleACGetButtonIcon(PAD_BUTTON_A, 1); + iconOff = BattleACGetButtonIcon(PAD_BUTTON_A, 0); + iconDispGx(&(Vec){-200.0f + x, 50.0f + y, 0.0f}, ICON_DISP_2D, __fabs(cw->pos.x - cw->targetPos.x) < 15.0 ? iconOn : iconOff, 1.0f); } #pragma dont_inline reset diff --git a/src/battle/ac/ac_power_gauge.c b/src/battle/ac/ac_power_gauge.c index 0ae061c19..6991f096e 100644 --- a/src/battle/ac/ac_power_gauge.c +++ b/src/battle/ac/ac_power_gauge.c @@ -9,8 +9,6 @@ #include "system.h" #include #include "version.h" -// FAKE: ac_power_gauge.c calls BattleACGetButtonIcon through this prototype (the types it was compiled with) instead of the one in battle/battle_ac.h; same registers, behaviour-identical. -typedef s32 (*BattleACGetButtonIconRetS32Fn)(s32, s32); // this unit is size-optimised, as in the original (the object differs without it) #pragma optimize_for_size on @@ -29,7 +27,6 @@ typedef struct PowerGaugeWork { #define PG_WORK(ac) ((PowerGaugeWork*)(ac)->work) -#define ICONGX ((void (*)(Vec*, s32, s32, f32))iconDispGx) static void actionCommandDisp(f32 x, f32 y); /** @@ -291,11 +288,16 @@ void battleAcDelete_PowerGauge(BattleWork* work) { static void actionCommandDisp(f32 x, f32 y) { BattleWork* work = _battleWorkPointer; BattleActions* ac = &work->actionCommands; - PowerGaugeWork* pw; - s32 a, b, c, d; BattleACDispParams* disp = (BattleACDispParams*)&ac->disp; + PowerGaugeWork* pw; f32 ratio; - u32 flags; + f32 px; + f32 py; + u16 icon; + u16 iconOn; + u16 iconOff; + u16 iconOn2; + u16 iconOff2; camGetPtr(CAMERA_2D); pw = PG_WORK(ac); @@ -304,178 +306,102 @@ static void actionCommandDisp(f32 x, f32 y) { ratio = 1.0f; } disp->gaugeRatio = ratio; - if (ac->acFlags & 2) { - BattleAcDrawGauge((s32)x, (s32)y, 0xB2, ratio, 1, 100, 100, 100, 0); + BattleAcDrawGauge(x, y, ratio, 0xB2, 1, 100, 100, 100, 0); } else { - BattleAcDrawGauge((s32)x, (s32)y, 0xB2, ratio, 2, ac->params[4], 100, 100, 0); + BattleAcDrawGauge(x, y, ratio, 0xB2, 2, ac->params[4], 100, 100, 0); } - - flags = ac->acFlags; - if (!(flags & 4)) { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = -288.0f + x + (f32)(ac->params[4] * 0xB0) / 100.0f; - pos.y = 45.0f + y; - ICONGX(&pos, ICON_DISP_2D, ICON_096, 1.0f); + if (!(ac->acFlags & 4)) { + iconDispGx(&(Vec){-288.0f + x + (f32)(ac->params[4] * 0xB0) / 100.0f, 45.0f + y, 0.0f}, ICON_DISP_2D, ICON_096, 1.0f); } else { - s32 icon; - if (pw->gauge >= (f32)ac->params[4] && pw->gauge <= 100.0f) { + if (pw->gauge >= ac->params[4] && pw->gauge <= 100.0f) { icon = ICON_095; } else { icon = ICON_091; } - if (flags & 8) { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = 120.0f + (-200.0f + x) - 12.0f; - pos.y = 18.0f + y; - ICONGX(&pos, ICON_DISP_2D, icon, 1.0f); + if (ac->acFlags & 8) { + iconDispGx(&(Vec){120.0f + (-200.0f + x) - 12.0f, 18.0f + y, 0.0f}, ICON_DISP_2D, icon, 1.0f); } else { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = 120.0f + (-200.0f + x); - pos.y = 18.0f + y; - ICONGX(&pos, ICON_DISP_2D, icon, 1.0f); + iconDispGx(&(Vec){120.0f + (-200.0f + x), 18.0f + y, 0.0f}, ICON_DISP_2D, icon, 1.0f); } } - switch (ac->params[0]) { case 0: - a = ICON_07F; - b = ICON_07E; - c = ICON_081; - d = ICON_080; + iconOn = ICON_07F; + iconOff = ICON_07E; + iconOn2 = ICON_081; + iconOff2 = ICON_080; break; case 1: - a = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(PAD_BUTTON_A, 1); - b = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(PAD_BUTTON_A, 0); - c = 0; - d = 0; + iconOn = BattleACGetButtonIcon(PAD_BUTTON_A, 1); + iconOff = BattleACGetButtonIcon(PAD_BUTTON_A, 0); + iconOn2 = 0; + iconOff2 = 0; break; case 2: - a = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(PAD_BUTTON_A, 1); - b = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(PAD_BUTTON_A, 0); - c = 0; - d = 0; + iconOn = BattleACGetButtonIcon(PAD_BUTTON_A, 1); + iconOff = BattleACGetButtonIcon(PAD_BUTTON_A, 0); + iconOn2 = 0; + iconOff2 = 0; break; case 3: - a = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(PAD_TRIGGER_R, 1); - b = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(PAD_TRIGGER_R, 0); - c = 0; - d = 0; + iconOn = BattleACGetButtonIcon(PAD_TRIGGER_R, 1); + iconOff = BattleACGetButtonIcon(PAD_TRIGGER_R, 0); + iconOn2 = 0; + iconOff2 = 0; break; } - switch (ac->acState) { case 99: case 100: case 1003: case 1004: case 1005: - if ((u16)c) { - Vec pos = {0.0f, 0.0f, 0.0f}; - f32 px = -225.0f + x; - f32 py = 80.0f + y; - pos.x = px; - pos.y = py; - ICONGX(&pos, ICON_DISP_2D, b, 1.0f); - { - Vec pos2 = {0.0f, 0.0f, 0.0f}; - pos2.x = 56.0f + px; - pos2.y = py; - ICONGX(&pos2, ICON_DISP_2D, d, 1.0f); - } + if (iconOn2) { + px = -225.0f + x; + py = 80.0f + y; + iconDispGx(&(Vec){px, py, 0.0f}, ICON_DISP_2D, iconOff, 1.0f); + iconDispGx(&(Vec){56.0f + px, py, 0.0f}, ICON_DISP_2D, iconOff2, 1.0f); } else { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = 28.0f + (-225.0f + x); - pos.y = 80.0f + y; - ICONGX(&pos, ICON_DISP_2D, b, 1.0f); + iconDispGx(&(Vec){28.0f + (-225.0f + x), 80.0f + y, 0.0f}, ICON_DISP_2D, iconOff, 1.0f); } break; case 1000: case 1001: if (pw->mode) { - if (pw->gauge >= (f32)ac->params[4] && pw->gauge <= 100.0f) { - if ((u16)c) { - Vec pos = {0.0f, 0.0f, 0.0f}; - f32 px = -225.0f + x; - f32 py = 80.0f + y; - pos.x = px; - pos.y = py; - ICONGX(&pos, ICON_DISP_2D, a, 1.0f); - { - Vec pos2 = {0.0f, 0.0f, 0.0f}; - pos2.x = 56.0f + px; - pos2.y = py; - ICONGX(&pos2, ICON_DISP_2D, c, 1.0f); - } + if (pw->gauge >= ac->params[4] && pw->gauge <= 100.0f) { + if (iconOn2) { + px = -225.0f + x; + py = 80.0f + y; + iconDispGx(&(Vec){px, py, 0.0f}, ICON_DISP_2D, iconOn, 1.0f); + iconDispGx(&(Vec){56.0f + px, py, 0.0f}, ICON_DISP_2D, iconOn2, 1.0f); } else { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = 28.0f + (-225.0f + x); - pos.y = 80.0f + y; - ICONGX(&pos, ICON_DISP_2D, a, 1.0f); + iconDispGx(&(Vec){28.0f + (-225.0f + x), 80.0f + y, 0.0f}, ICON_DISP_2D, iconOn, 1.0f); } + } else if (iconOn2) { + px = -225.0f + x; + py = 80.0f + y; + iconDispGx(&(Vec){px, py, 0.0f}, ICON_DISP_2D, iconOff, 1.0f); + iconDispGx(&(Vec){56.0f + px, py, 0.0f}, ICON_DISP_2D, iconOff2, 1.0f); } else { - if ((u16)c) { - Vec pos = {0.0f, 0.0f, 0.0f}; - f32 px = -225.0f + x; - f32 py = 80.0f + y; - pos.x = px; - pos.y = py; - ICONGX(&pos, ICON_DISP_2D, b, 1.0f); - { - Vec pos2 = {0.0f, 0.0f, 0.0f}; - pos2.x = 56.0f + px; - pos2.y = py; - ICONGX(&pos2, ICON_DISP_2D, d, 1.0f); - } - } else { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = 28.0f + (-225.0f + x); - pos.y = 80.0f + y; - ICONGX(&pos, ICON_DISP_2D, b, 1.0f); - } + iconDispGx(&(Vec){28.0f + (-225.0f + x), 80.0f + y, 0.0f}, ICON_DISP_2D, iconOff, 1.0f); } - } else { - if ((pw->gauge >= (f32)ac->params[4] && pw->gauge <= 100.0f) || (s32)ac->outputParams[0] == 0) { - if ((u16)c) { - Vec pos = {0.0f, 0.0f, 0.0f}; - f32 px = -225.0f + x; - f32 py = 80.0f + y; - pos.x = px; - pos.y = py; - ICONGX(&pos, ICON_DISP_2D, b, 1.0f); - { - Vec pos2 = {0.0f, 0.0f, 0.0f}; - pos2.x = 56.0f + px; - pos2.y = py; - ICONGX(&pos2, ICON_DISP_2D, d, 1.0f); - } - } else { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = 28.0f + (-225.0f + x); - pos.y = 80.0f + y; - ICONGX(&pos, ICON_DISP_2D, b, 1.0f); - } + } else if ((pw->gauge >= ac->params[4] && pw->gauge <= 100.0f) || ac->outputParams[0] == 0) { + if (iconOn2) { + px = -225.0f + x; + py = 80.0f + y; + iconDispGx(&(Vec){px, py, 0.0f}, ICON_DISP_2D, iconOff, 1.0f); + iconDispGx(&(Vec){56.0f + px, py, 0.0f}, ICON_DISP_2D, iconOff2, 1.0f); } else { - if ((u16)c) { - Vec pos = {0.0f, 0.0f, 0.0f}; - f32 px = -225.0f + x; - f32 py = 80.0f + y; - pos.x = px; - pos.y = py; - ICONGX(&pos, ICON_DISP_2D, a, 1.0f); - { - Vec pos2 = {0.0f, 0.0f, 0.0f}; - pos2.x = 56.0f + px; - pos2.y = py; - ICONGX(&pos2, ICON_DISP_2D, c, 1.0f); - } - } else { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = 28.0f + (-225.0f + x); - pos.y = 80.0f + y; - ICONGX(&pos, ICON_DISP_2D, a, 1.0f); - } + iconDispGx(&(Vec){28.0f + (-225.0f + x), 80.0f + y, 0.0f}, ICON_DISP_2D, iconOff, 1.0f); } + } else if (iconOn2) { + px = -225.0f + x; + py = 80.0f + y; + iconDispGx(&(Vec){px, py, 0.0f}, ICON_DISP_2D, iconOn, 1.0f); + iconDispGx(&(Vec){56.0f + px, py, 0.0f}, ICON_DISP_2D, iconOn2, 1.0f); + } else { + iconDispGx(&(Vec){28.0f + (-225.0f + x), 80.0f + y, 0.0f}, ICON_DISP_2D, iconOn, 1.0f); } break; } diff --git a/src/battle/ac/ac_power_gauge_lv.c b/src/battle/ac/ac_power_gauge_lv.c index 30cb1fed6..8f669469f 100644 --- a/src/battle/ac/ac_power_gauge_lv.c +++ b/src/battle/ac/ac_power_gauge_lv.c @@ -205,7 +205,7 @@ static void actionCommandDisp(f32 x, f32 y) { ratio = 1.0f; } disp->gaugeRatio = ratio; - BattleAcDrawGauge((s32)x, (s32)y, 0xB2, disp->gaugeRatio, work->actionCommands.params[1], work->actionCommands.params[2], + BattleAcDrawGauge((s32)x, (s32)y, disp->gaugeRatio, 0xB2, work->actionCommands.params[1], work->actionCommands.params[2], work->actionCommands.params[3], work->actionCommands.params[4], 0); switch (work->actionCommands.acState) { case 99: diff --git a/src/battle/ac/ac_power_gauge_lv2.c b/src/battle/ac/ac_power_gauge_lv2.c index 9b4614491..0ae55e943 100644 --- a/src/battle/ac/ac_power_gauge_lv2.c +++ b/src/battle/ac/ac_power_gauge_lv2.c @@ -9,8 +9,6 @@ #include "system.h" #include #include "version.h" -// FAKE: ac_power_gauge_lv2.c calls BattleACGetButtonIcon through this prototype (the types it was compiled with) instead of the one in battle/battle_ac.h; same registers, behaviour-identical. -typedef s32 (*BattleACGetButtonIconRetS32Fn)(s32, s32); // this unit is size-optimised, as in the original (the object differs without it) #pragma optimize_for_size on @@ -247,33 +245,24 @@ void battleAcDelete_PowerGaugeLv2(BattleWork* work) { } } -#define ICON ((void (*)(Vec*, s32, s32, f32))iconDispGx) /** * Draws the gauge with level marks from gaugeParams (pulsing red once full), the A icon and a star, * both lit while holding A is safe. */ static void actionCommandDisp(f32 x, f32 y) { - BattleWork* work = _battleWorkPointer; - BattleActions* ac = &work->actionCommands; - f32 ratio; - s32 full; - s32 tmp[4]; - s32 cnt; + BattleActions* ac = &_battleWorkPointer->actionCommands; + s32 levels[4]; + s32 count; s32 i; - s32 pressedIcon; - s32 icon; - f32 px; - f32 py; + s32 flash; + f32 ratio; + u16 iconOn; + u16 iconOff; + u16 icon; + camGetPtr(CAMERA_2D); - px = -200.0f + x; - py = 25.0f + y; - { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = px; - pos.y = py; - ICON(&pos, ICON_DISP_2D, ICON_08C, 1.0f); - } - full = 0; + iconDispGx(&(Vec){-200.0f + x, 25.0f + y, 0.0f}, ICON_DISP_2D, ICON_08C, 1.0f); + flash = 0; ratio = AC_WORK(ac)->gauge / 100.0f; if (ratio > 1.0f) { ratio = 1.0f; @@ -283,7 +272,7 @@ static void actionCommandDisp(f32 x, f32 y) { ac->disp.color.g += ac->disp.colorStep[1]; ac->disp.color.b += ac->disp.colorStep[2]; if (ac->disp.gaugeRatio >= 1.0f) { - full |= 1; + flash |= 1; } if (ac->disp.color.g <= 0x80 && ac->disp.colorStep[1] < 0) { ac->disp.colorStep[1] = ac->disp.colorStep[2] = 0x10; @@ -292,57 +281,38 @@ static void actionCommandDisp(f32 x, f32 y) { ac->disp.colorStep[1] = ac->disp.colorStep[2] = -0x10; } } - cnt = 0; + count = 0; for (i = 0; i < 4; i++) { - tmp[i] = 100; + levels[i] = 100; } - for (i = 0; i < 4; i++, cnt++) { - tmp[i] = ac->gaugeParams[i]; - if (i != 0 && !(tmp[i] - tmp[i - 1] > 0)) { + for (i = 0; i < 4; i++, count++) { + levels[i] = ac->gaugeParams[i]; + if (i != 0 && levels[i] - levels[i - 1] <= 0) { break; } } - BattleAcDrawGauge((s32)x, (s32)y, 0xB2, ac->disp.gaugeRatio, cnt, tmp[0], tmp[1], tmp[2], full); - pressedIcon = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(AC_WORK(ac)->button, 1); - icon = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(AC_WORK(ac)->button, 0); + BattleAcDrawGauge(x, y, ac->disp.gaugeRatio, 0xB2, count, levels[0], levels[1], levels[2], flash); + iconOn = BattleACGetButtonIcon(AC_WORK(ac)->button, 1); + iconOff = BattleACGetButtonIcon(AC_WORK(ac)->button, 0); switch (ac->acState) { case 99: case 100: case 1002: case 1003: - case 1004: { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = px; - pos.y = 70.0f + y; - ICON(&pos, ICON_DISP_2D, icon, 1.0f); + case 1004: + iconDispGx(&(Vec){-200.0f + x, 70.0f + y, 0.0f}, ICON_DISP_2D, iconOff, 1.0f); break; - } case 1000: if (AC_WORK(ac)->inZone) { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = px; - pos.y = 70.0f + y; - ICON(&pos, ICON_DISP_2D, pressedIcon, 1.0f); + iconDispGx(&(Vec){-200.0f + x, 70.0f + y, 0.0f}, ICON_DISP_2D, iconOn, 1.0f); } else { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = px; - pos.y = 70.0f + y; - ICON(&pos, ICON_DISP_2D, icon, 1.0f); + iconDispGx(&(Vec){-200.0f + x, 70.0f + y, 0.0f}, ICON_DISP_2D, iconOff, 1.0f); } break; } - { - s32 id = ICON_091; - Vec pos; - if (AC_WORK(ac)->inZone) { - id = ICON_095; - } - { - Vec zero = {0.0f, 0.0f, 0.0f}; - pos = zero; - } - pos.x = 120.0f + px; - pos.y = py; - ICON(&pos, ICON_DISP_2D, id, 1.0f); + icon = ICON_091; + if (AC_WORK(ac)->inZone) { + icon = ICON_095; } + iconDispGx(&(Vec){120.0f + (-200.0f + x), 25.0f + y, 0.0f}, ICON_DISP_2D, icon, 1.0f); } diff --git a/src/battle/ac/ac_repeatedly.c b/src/battle/ac/ac_repeatedly.c index 306b67a65..bb520d22d 100644 --- a/src/battle/ac/ac_repeatedly.c +++ b/src/battle/ac/ac_repeatedly.c @@ -11,8 +11,6 @@ #include #include "icon_ids.h" #include -// FAKE: ac_repeatedly.c calls BattleAcDrawGauge through this prototype (the types it was compiled with) instead of the one in battle/battle_ac.h; same registers, behaviour-identical. -typedef void (*BattleAcDrawGaugeNoProtoFn)(); typedef struct RepeatDisp { s32 frame; // 0x0 @@ -486,7 +484,7 @@ static void actionCommandDisp(f32 x, f32 y) { if (r->done == -1) { flags |= 2; } - ((BattleAcDrawGaugeNoProtoFn)BattleAcDrawGauge)((s32)x, (s32)y, d->gauge, r->iconParam, 2, (acw->acFlags & 2) ? 100 : (s32)r->pos, 100, 100, flags); + BattleAcDrawGauge((s32)x, (s32)y, d->gauge, r->iconParam, 2, (acw->acFlags & 2) ? 100 : (s32)r->pos, 100, 100, flags); { Vec pos = {0.0f, 0.0f, 0.0f}; pos.x = (-288.0f + x) + (176.0f * r->pos) / 100.0f; diff --git a/src/battle/ac/ac_repeatedly_lv.c b/src/battle/ac/ac_repeatedly_lv.c index 1316bba01..d59e60a92 100644 --- a/src/battle/ac/ac_repeatedly_lv.c +++ b/src/battle/ac/ac_repeatedly_lv.c @@ -9,11 +9,6 @@ #include "system.h" #include -// FAKE: ac_repeatedly_lv.c calls BattleAcDrawGauge through this prototype (the types it was compiled with) instead of the one in battle/battle_ac.h; same registers, behaviour-identical. -typedef void (*BattleAcDrawGaugeArgOrderFn)(f32, s32, s32, u8, s32, s32, s32, s32, s32); -// FAKE: ac_repeatedly_lv.c calls BattleACGetButtonIcon through this prototype (the types it was compiled with) instead of the one in battle/battle_ac.h; same registers, behaviour-identical. -typedef s32 (*BattleACGetButtonIconRetS32Fn)(s32, s32); - // this unit is size-optimised, as in the original (the object differs without it) #pragma optimize_for_size on @@ -49,7 +44,7 @@ typedef struct RepeatedlyLvWork { s32 endTimer; // 0x30 } RepeatedlyLvWork; -#define RL_IconDisp ((void (*)(Vec*, s16, s32, f32))iconDispGx) +#define RL_WORK(ac) ((RepeatedlyLvWork*)(ac)->work) /** * Reads the script parameters: params[0] picks the input (A by default; 2 B, 3 X, 4 Y, 5 R, 6 stick left, @@ -382,153 +377,131 @@ void battleAcDelete_RepeatedlyLv(BattleWork* work) { * and per acFlags the params[6] target marker and the level number. */ static void actionCommandDisp(f32 x, f32 y) { - BattleWork* work = _battleWorkPointer; - BattleActions* ac = &work->actionCommands; - RepeatedlyLvWork* p = (RepeatedlyLvWork*)ac->work; - BattleACDispParams* disp = &ac->disp; - s32 arr[4]; - s32 i, count, flags, phase; + BattleActions* ac = &_battleWorkPointer->actionCommands; + u16 iconOn; + s32 buttons; + u16 iconOff; + u16 iconOn2; + u16 iconOff2; + s32 dx1; + s32 dx2; + s32 blink; + s32 levels[4]; + s32 count; + s32 i; + s32 flash; + s32 number; f32 target; + f32 numberX; + Mtx mtx; + Mtx trans; + Mtx scale; + camGetPtr(CAMERA_2D); - { - s32 numIcons; - s32 pressedA, idleA, pressedB, idleB; - s32 off0, off1; - idleB = 0; - pressedB = 0; - numIcons = 1; - ac->disp.blinkTimer++; - off1 = 0; - off0 = 0; - pressedA = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(p->mask, 1); - idleA = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(p->mask, 0); - switch (ac->params[0]) { - case 15: - off0 = -10; - off1 = 10; - case 11: - case 12: - pressedA = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(p->maskA, 1); - idleA = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(p->maskA, 0); - pressedB = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(p->maskB, 1); - idleB = ((BattleACGetButtonIconRetS32Fn)BattleACGetButtonIcon)(p->maskB, 0); - numIcons = 2; - break; - case 13: - pressedA = ICON_07C; - idleA = ICON_076; - break; - case 14: - pressedA = ICON_078; - idleA = ICON_07A; - break; - } - phase = ac->disp.blinkTimer / 7; - if (numIcons == 1) { - if ((phase & 1) == 1) { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = -200.0f + x; - pos.y = 70.0f + y; - RL_IconDisp(&pos, ICON_DISP_2D, idleA, 1.0f); - } else { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = -200.0f + x; - pos.y = 70.0f + y; - RL_IconDisp(&pos, ICON_DISP_2D, pressedA, 1.0f); - } + ac->disp.blinkTimer++; + iconOff2 = 0; + iconOn2 = 0; + buttons = 1; + dx2 = 0; + dx1 = 0; + iconOn = BattleACGetButtonIcon(RL_WORK(ac)->mask, 1); + iconOff = BattleACGetButtonIcon(RL_WORK(ac)->mask, 0); + switch (ac->params[0]) { + case 15: + dx1 = -10; + dx2 = 10; + case 11: + case 12: + iconOn = BattleACGetButtonIcon(RL_WORK(ac)->maskA, 1); + iconOff = BattleACGetButtonIcon(RL_WORK(ac)->maskA, 0); + iconOn2 = BattleACGetButtonIcon(RL_WORK(ac)->maskB, 1); + iconOff2 = BattleACGetButtonIcon(RL_WORK(ac)->maskB, 0); + buttons = 2; + break; + case 13: + iconOn = ICON_07C; + iconOff = ICON_076; + break; + case 14: + iconOn = ICON_078; + iconOff = ICON_07A; + break; + } + blink = ac->disp.blinkTimer / 7; + if (buttons == 1) { + if ((blink & 1) == 1) { + iconDispGx(&(Vec){-200.0f + x, 70.0f + y, 0.0f}, ICON_DISP_2D, iconOff, 1.0f); } else { - if ((phase & 1) == 1) { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = -225.0f + x + off0; - pos.y = 70.0f + y; - RL_IconDisp(&pos, ICON_DISP_2D, idleA, 1.0f); - { - Vec pos2 = {0.0f, 0.0f, 0.0f}; - pos2.x = -175.0f + x + off1; - pos2.y = 70.0f + y; - RL_IconDisp(&pos2, ICON_DISP_2D, pressedB, 1.0f); - } - } else { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = -225.0f + x + off0; - pos.y = 70.0f + y; - RL_IconDisp(&pos, ICON_DISP_2D, pressedA, 1.0f); - { - Vec pos2 = {0.0f, 0.0f, 0.0f}; - pos2.x = -175.0f + x + off1; - pos2.y = 70.0f + y; - RL_IconDisp(&pos2, ICON_DISP_2D, idleB, 1.0f); - } - } + iconDispGx(&(Vec){-200.0f + x, 70.0f + y, 0.0f}, ICON_DISP_2D, iconOn, 1.0f); } + } else if ((blink & 1) == 1) { + iconDispGx(&(Vec){-225.0f + x + dx1, 70.0f + y, 0.0f}, ICON_DISP_2D, iconOff, 1.0f); + iconDispGx(&(Vec){-175.0f + x + dx2, 70.0f + y, 0.0f}, ICON_DISP_2D, iconOn2, 1.0f); + } else { + iconDispGx(&(Vec){-225.0f + x + dx1, 70.0f + y, 0.0f}, ICON_DISP_2D, iconOn, 1.0f); + iconDispGx(&(Vec){-175.0f + x + dx2, 70.0f + y, 0.0f}, ICON_DISP_2D, iconOff2, 1.0f); } - target = p->gauge / 100.0f; - if (disp->gaugeRatio <= target) { + target = RL_WORK(ac)->gauge / 100.0f; + if (ac->disp.gaugeRatio <= target) { if (ac->acFlags & REPEATEDLY_LV_FAST_GAUGE) { - disp->gaugeRatio += 0.02f; + ac->disp.gaugeRatio += 0.02f; } else { - disp->gaugeRatio += 0.01f; + ac->disp.gaugeRatio += 0.01f; } if (ac->acFlags & REPEATEDLY_LV_INSTANT_GAUGE) { - disp->gaugeRatio = target; + ac->disp.gaugeRatio = target; } - if (disp->gaugeRatio > target) { - disp->gaugeRatio = target; + if (ac->disp.gaugeRatio > target) { + ac->disp.gaugeRatio = target; } } else { if (ac->acFlags & REPEATEDLY_LV_FAST_GAUGE) { - disp->gaugeRatio -= 0.02f; + ac->disp.gaugeRatio -= 0.02f; } else { - disp->gaugeRatio -= 0.01f; + ac->disp.gaugeRatio -= 0.01f; } if (ac->acFlags & REPEATEDLY_LV_INSTANT_GAUGE) { - disp->gaugeRatio = target; + ac->disp.gaugeRatio = target; } - if (disp->gaugeRatio < target) { - disp->gaugeRatio = target; + if (ac->disp.gaugeRatio < target) { + ac->disp.gaugeRatio = target; } } count = 0; - flags = 0; - if (p->state == 1 && disp->gaugeRatio >= 1.0f) { - flags |= 1; - disp->color.g += disp->colorStep[1]; - disp->color.b += disp->colorStep[2]; - if (disp->color.g <= 0x80 && disp->colorStep[1] < 0) { - disp->colorStep[1] = disp->colorStep[2] = 0x10; + flash = 0; + if (RL_WORK(ac)->state == 1 && ac->disp.gaugeRatio >= 1.0f) { + flash |= 1; + ac->disp.color.g += ac->disp.colorStep[1]; + ac->disp.color.b += ac->disp.colorStep[2]; + if (ac->disp.color.g <= 0x80 && ac->disp.colorStep[1] < 0) { + ac->disp.colorStep[1] = ac->disp.colorStep[2] = 0x10; } - if (disp->color.g >= 0xF5 && disp->colorStep[1] > 0) { - disp->colorStep[1] = disp->colorStep[2] = -0x10; + if (ac->disp.color.g >= 0xF5 && ac->disp.colorStep[1] > 0) { + ac->disp.colorStep[1] = ac->disp.colorStep[2] = -0x10; } } - if ((s8)p->state == -1) { - flags |= 2; + if (RL_WORK(ac)->state == -1) { + flash |= 2; } for (i = 0; i < 4; i++) { - arr[i] = 100; + levels[i] = 100; } for (i = 0; i < 4; i++, count++) { - arr[i] = ac->gaugeParams[i]; - if (i != 0 && arr[i] - arr[i - 1] <= 0) { + levels[i] = ac->gaugeParams[i]; + if (i != 0 && levels[i] - levels[i - 1] <= 0) { break; } } - ((BattleAcDrawGaugeArgOrderFn)BattleAcDrawGauge)(disp->gaugeRatio, (s32)x, (s32)y, p->u24, count, arr[0], arr[1], arr[2], flags); + BattleAcDrawGauge(x, y, ac->disp.gaugeRatio, RL_WORK(ac)->u24, count, levels[0], levels[1], levels[2], flash); if (ac->acFlags & REPEATEDLY_LV_SHOW_MARK) { - Vec pos = {0.0f, 0.0f, 0.0f}; - pos.x = -288.0f + x + (f32)(ac->params[6] * 0xB0) / 100.0f; - pos.y = 45.0f + y; - RL_IconDisp(&pos, ICON_DISP_2D, ICON_096, 1.0f); + iconDispGx(&(Vec){-288.0f + x + (f32)(ac->params[6] * 0xB0) / 100.0f, 45.0f + y, 0.0f}, ICON_DISP_2D, ICON_096, 1.0f); } if (ac->acFlags & REPEATEDLY_LV_SHOW_LEVEL) { - Mtx m3, m1, m2; - s32 number = (s32)ac->outputParams[2] + ac->params[7]; - { - f32 w = 108.0f; - PSMTXTrans(m1, -200.0f + x + w, 25.0f + y, 0.0f); - } - PSMTXScale(m2, 1.0f, 1.0f, 1.0f); - PSMTXConcat(m1, m2, m3); - iconNumberDispGx(m3, number, FALSE, (GXColor){255, 255, 255, 255}); + number = ac->outputParams[2] + ac->params[7]; + numberX = 108.0f; + PSMTXTrans(trans, -200.0f + x + numberX, 25.0f + y, 0.0f); + PSMTXScale(scale, 1.0f, 1.0f, 1.0f); + PSMTXConcat(trans, scale, mtx); + iconNumberDispGx(mtx, number, FALSE, (GXColor){255, 255, 255, 255}); } } diff --git a/src/battle/battle.c b/src/battle/battle.c index 60d7cd1bb..fadc5092b 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -477,12 +477,12 @@ BattleUnit* BattleGetPartnerPtr(BattleWork* wp, BattleUnit* unit) { /** * Starts loading a partner's animation data in the background (partyId is the unit kind 0xE0-0xE6) - * so a partner switch is quick. + * so a partner switch is quick; returns TRUE once it has loaded (animEffectAsync's result). */ -void BattlePartyAnimeLoad(s32 partyId) { +BOOL BattlePartyAnimeLoad(s32 partyId) { BattleUnitSetup* setup = &entryunit_party[partyId - UNIT_GOOMBELLA]; - animEffectAsync(setup->unitKindParams->parts->modelName, 1); + return animEffectAsync(setup->unitKindParams->parts->modelName, 1); } /** diff --git a/src/battle/battle_ac.c b/src/battle/battle_ac.c index 27f931026..efc5a285b 100644 --- a/src/battle/battle_ac.c +++ b/src/battle/battle_ac.c @@ -436,7 +436,7 @@ static inline void gaugeQuad(CameraEntry* cam, f32 x0, f32 y0, f32 x1, f32 y1, u * flags 1 tints the fill with the command's display colour, flags 2 draws it red. * Used by the air gauge and timing gauge commands. */ -void BattleAcDrawGauge(s32 x, s32 y, s32 width, f32 ratio, s32 level, s32 a, s32 b, s32 c, s32 flags) { +void BattleAcDrawGauge(s32 x, s32 y, f32 ratio, s32 width, s32 level, s32 a, s32 b, s32 c, s32 flags) { BattleWork* wp = _battleWorkPointer; s32 max = 100; u8* mod = (u8*)&wp->actionCommands.disp.color; diff --git a/src/battle/battle_audience.c b/src/battle/battle_audience.c index c24af839b..6bc01c357 100644 --- a/src/battle/battle_audience.c +++ b/src/battle/battle_audience.c @@ -3327,7 +3327,7 @@ u8 BattleAudience_GetWaiting(s32 index) { * in its shell, fuse lit, in a Boo or Shy Guy event, in a demo-only status or already leaving. * Used when the crowd shrinks, the Punies flee and falling objects or blasts scatter the crowd. */ -BOOL BattleAudience_GetEscapeChangeOK(s32 index) { +u8 BattleAudience_GetEscapeChangeOK(s32 index) { BattleAudience* audience; BattleAudienceMember* member; @@ -3363,7 +3363,10 @@ BOOL BattleAudience_GetEscapeChangeOK(s32 index) { if (member->status == 22) { return FALSE; } - return member->status != 12; + if (member->status == 12) { + return FALSE; + } + return TRUE; } /** @@ -3985,7 +3988,7 @@ s32 BattleAudienceAddAudienceNum(s32 num) { for (i = 0; i > num; i--) { count = 0; for (j = 0; j < 200; j++) { - if (AUD_U8CALL(BattleAudience_GetEscapeChangeOK, j)) { + if (BattleAudience_GetEscapeChangeOK(j)) { list[count++] = j; } } @@ -4015,7 +4018,7 @@ void BattleAudiencePuniAllEscape(void) { count = 0; for (i = 0; i < AUDIENCE_MEMBER_MAX; i++) { member = BattleAudienceGetPtr(i); - if (AUD_U8CALL(BattleAudience_GetEscapeChangeOK, i) && member->type == 7) { + if (BattleAudience_GetEscapeChangeOK(i) && member->type == 7) { BattleAudience_ChangeStatus(i, 12); #if VERSION <= VERSION_DEMO_JP audience->targetAudienceCount -= 1.0f; @@ -5382,7 +5385,7 @@ void BattleAudience_Case_FallObject_Aud(s32 index, u8 type) { } for (i = 0; i < 8; i++) { no = BattleAudience_GetAudienceNoFromOffset(index, near[i][0], near[i][1]); - if (no != -1 && (u8)BattleAudience_GetEscapeChangeOK(no)) { + if (no != -1 && BattleAudience_GetEscapeChangeOK(no)) { BattleAudience_ChangeStatus(no, 12); audience->targetAudienceCount -= 1.0f; } @@ -5394,7 +5397,7 @@ void BattleAudience_Case_FallObject_Aud(s32 index, u8 type) { } for (i = 0; i < 24; i++) { no = BattleAudience_GetAudienceNoFromOffset(index, far[i][0], far[i][1]); - if (no != -1 && (u8)BattleAudience_GetEscapeChangeOK(no)) { + if (no != -1 && BattleAudience_GetEscapeChangeOK(no)) { BattleAudience_ChangeStatus(no, 12); audience->targetAudienceCount -= 1.0f; } @@ -5405,7 +5408,7 @@ void BattleAudience_Case_FallObject_Aud(s32 index, u8 type) { BattleAudience_ChangeStatus(index, 10); } for (i = 0; i < 200; i++) { - if ((u8)BattleAudience_GetEscapeChangeOK(i)) { + if (BattleAudience_GetEscapeChangeOK(i)) { BattleAudience_ChangeStatus(i, 12); audience->targetAudienceCount -= 1.0f; } diff --git a/src/battle/battle_audience_kinopio.c b/src/battle/battle_audience_kinopio.c index fa0e15ecd..1a3dda646 100644 --- a/src/battle/battle_audience_kinopio.c +++ b/src/battle/battle_audience_kinopio.c @@ -19,8 +19,6 @@ #include "version.h" #include "libc_decls.h" #include "battle/battle_break_slot.h" -// FAKE: battle_audience_kinopio.c calls BattleAudience_GetEscapeChangeOK through this prototype (the types it was compiled with) instead of the one in battle/battle_audience.h; same registers, behaviour-identical. -typedef u8 (*BattleAudience_GetEscapeChangeOKNoProtoFn)(); // this unit is size-optimised, as in the original (the object differs without it) #pragma optimize_for_size on @@ -180,28 +178,24 @@ void BattleAudienceCtrlProcessKinopio(s32 index) { } } -// propagation optimisation off for BattleAudienceCtrlProcessKinopioWait: the original register allocation and scheduling need it -#pragma opt_propagation off -// lifetimes optimisation off for BattleAudienceCtrlProcessKinopioWait: the original register allocation and scheduling need it -#pragma opt_lifetimes off /** * Status 0, idle: faces the stage (or away, for back-facing seats) and now and * then starts a fidget (turn around, tilt the head, hop) or a cheer, * more often the fuller the crowd is relative to its expected size. A member hit by Mario switches to status 10. */ static void BattleAudienceCtrlProcessKinopioWait(s32 index, s32 front) { - BattleAudience* base; - BattleAudienceMember* m; + BattleAudience* base = BattleAudienceBaseGetPtr(); + BattleAudienceMember* m = BattleAudienceGetPtr(index); + f32 r; + f32 speed; f32 a; f32 b; f32 scale; - f32 speed; - f32 r; - s32 th; + s32 flags; s32 rnd; + s32 th; s32 n; - base = BattleAudienceBaseGetPtr(); - m = BattleAudienceGetPtr(index); + pouchGetPtr(); if ((u8)front == 1) { BattleAudience_SetAnim(index, 0, FALSE); @@ -210,8 +204,7 @@ static void BattleAudienceCtrlProcessKinopioWait(s32 index, s32 front) { } r = (base->targetAudienceCount + base->addedAudienceCount) / base->audienceDeltaMultiplier; if (r >= 0.75f) { - speed = 1.0f; - scale = speed; + scale = speed = 1.0f; } else if (r >= 0.5f) { speed = 0.5f; scale = 2.0f; @@ -234,7 +227,8 @@ static void BattleAudienceCtrlProcessKinopioWait(s32 index, s32 front) { a = 1.0f; b = 0.0f; } else { - b = a = 0.0f; + a = 0.0f; + b = 0.0f; } switch (m->type) { case 4: @@ -309,56 +303,53 @@ static void BattleAudienceCtrlProcessKinopioWait(s32 index, s32 front) { m->timer++; break; } - if (m->flags & MEMBER_FLAG_ATTACKED) { - m->flags &= ~(MEMBER_FLAG_TARGETED | MEMBER_FLAG_ATTACKED); + flags = m->flags; + if (flags & MEMBER_FLAG_ATTACKED) { + m->flags = flags & ~(MEMBER_FLAG_TARGETED | MEMBER_FLAG_ATTACKED); BattleAudience_ChangeStatus(index, 10); - if (!(BattleAudienceItemGetPtr(0)->itemType >= ITEM_AUDIENCE_CAN && BattleAudienceItemGetPtr(0)->itemType < BADGE_MIN)) { + if (BattleAudienceItemGetPtr(0)->itemType < ITEM_AUDIENCE_CAN || BattleAudienceItemGetPtr(0)->itemType >= BADGE_MIN) { BattleAudienceAddTargetNum(-0.14999999f * BattleAudienceBaseGetPtr()->audienceDeltaMultiplier, 0.0f); } - } else if (!(m->flags & MEMBER_FLAG_TARGETED)) { + } else if (!(flags & MEMBER_FLAG_TARGETED)) { switch (m->itemId) { - case -1: { - rnd = irand(360000); - if (rnd < 10) { - BattleAudience_ChangeStatus(index, 1); - } else { - th = 20; - if (rnd < th) { - BattleAudience_ChangeStatus(index, 2); - } else { - th = (s32)(th + (f32)(10.0f * a)); - if (rnd < th) { - BattleAudience_ChangeStatus(index, 4); - } else if (BattleBreakSlot_GetBreakTurn() >= 1 || base->excited == 1) { - if (rnd < th + 300) { - if (m->type != 11) { - BattleAudience_ChangeStatus(index, 3); - } - } - } else { - th += (s32)(10.0f * b); - if (rnd < th) { - n = BattleAudience_GetAudienceNoFromOffset(index, 0, 1); - if (n != -1) { - BattleAudienceGetPtr(n); - if (m->type != 11) { - if ((u8)BattleAudience_GetExist(n) == 1) { - BattleAudience_ChangeStatus(index, 3); - } - } - } - } - } + case -1: + break; + default: + return; + } + rnd = irand(360000); + if (rnd < 10) { + BattleAudience_ChangeStatus(index, 1); + return; + } + if (rnd < (th = 20)) { + BattleAudience_ChangeStatus(index, 2); + return; + } + th += (f32)(10.0f * a); // FAKE: the (f32) cast of the f32 product is needed (without it kinopio.o differs) + if (rnd < th) { + BattleAudience_ChangeStatus(index, 4); + return; + } + if (BattleBreakSlot_GetBreakTurn() >= 1 || base->excited == 1) { + if (rnd < th + 300 && m->type != 11) { + BattleAudience_ChangeStatus(index, 3); + } + } else { + th += (s32)(10.0f * b); + if (rnd < th) { + n = BattleAudience_GetAudienceNoFromOffset(index, 0, 1); + if (n != -1) { + BattleAudienceGetPtr(n); + if (m->type != 11 && (u8)BattleAudience_GetExist(n) == 1) { + BattleAudience_ChangeStatus(index, 3); } } - break; } } } } -#pragma opt_propagation reset -#pragma opt_lifetimes reset /** Status 1, "furimuki" (looking back): turns 180 degrees over 15 frames, holds, turns back, then idles again. */ static void BattleAudienceCtrlProcessKinopioWaitHurimuki(s32 index, s32 front) { BattleAudienceMember* m = BattleAudienceGetPtr(index); @@ -642,7 +633,7 @@ static void BattleAudienceCtrlProcessKinopioDamage(s32 index) { if (BattleAudience_GetAnimEnd(index) == 1) { m->baseScale.y = 1.0f; m->timer = 0; - if (((BattleAudience_GetEscapeChangeOKNoProtoFn)BattleAudience_GetEscapeChangeOK)(index) == 1) { + if (BattleAudience_GetEscapeChangeOK(index) == 1) { BattleAudience_ChangeStatus(index, 12); psndSFXOn_3D("SFX_AUDIENCE_PANIC_SCREAM2", &m->position); } else { diff --git a/src/battle/battle_break_slot.c b/src/battle/battle_break_slot.c index 7b3495863..6fa24f318 100644 --- a/src/battle/battle_break_slot.c +++ b/src/battle/battle_break_slot.c @@ -28,8 +28,6 @@ #include "battle/battle_message.h" #include "evt/evt_eff.h" #include "libc_decls.h" -// FAKE: battle_break_slot.c calls pouchSetAP through this prototype (the types it was compiled with) instead of the one in mario/mario_pouch.h; same registers, behaviour-identical. -typedef void (*PouchSetAPS32Fn)(s32); typedef struct { s32 v[8]; @@ -537,7 +535,7 @@ void BattleBreakSlot_Main(void) { break; case 4: evtEntry(doku_kinoko_effect, 0, EVENT_START_NOW); - ((PouchSetAPS32Fn)pouchSetAP)(pouchGetAP() / 2); + pouchSetAP(pouchGetAP() / 2); break; } } diff --git a/src/battle/battle_damage.c b/src/battle/battle_damage.c index ff919cf38..13525db01 100644 --- a/src/battle/battle_damage.c +++ b/src/battle/battle_damage.c @@ -29,10 +29,6 @@ #include "battle/battle_status_effect.h" #include "eff/eff_updown.h" #include "battle/battle_actrecord.h" -// FAKE: battle_damage.c calls BtlUnit_GetStatus through this prototype (the types it was compiled with) instead of the one in battle/battle_unit.h; same registers, behaviour-identical. -typedef void (*BtlUnit_GetStatusS8Fn)(BattleUnit*, s8, s8*, s8*); -// FAKE: battle_damage.c calls BtlUnit_SetStatus through this prototype (the types it was compiled with) instead of the one in battle/battle_unit.h; same registers, behaviour-identical. -typedef BOOL (*BtlUnit_SetStatusS8Fn)(BattleUnit*, s8, s8, s8); static void _getSickStatusParam(BattleUnit* unit, BattleWeapon* weapon, u32 type, s8* outTime, s8* outStrength); static s32 BattleSetStatusDamage(u32* result, BattleUnit* unit, BattleUnitPart* part, u32 special, s32 type, s32 rate, s32 levelDiff, s8 time, s8 strength); @@ -1200,7 +1196,7 @@ static s32 BattleSetStatusDamage(u32* result, BattleUnit* unit, BattleUnitPart* if ((u32)type == STATUS_INSTANT_KILL) { *result |= STATUS_RESULT_INSTANT_KILL; } - ok = ((BtlUnit_SetStatusS8Fn)BtlUnit_SetStatus)(unit, type, time, strength); + ok = BtlUnit_SetStatus(unit, type, time, strength); } switch (type) { case 6: @@ -1412,7 +1408,7 @@ static s32 BattleSetStatusDamage(u32* result, BattleUnit* unit, BattleUnitPart* announce = 0; if (ok) { - ((BtlUnit_GetStatusS8Fn)BtlUnit_GetStatus)(unit, type, &curTurns, &curStrength); + BtlUnit_GetStatus(unit, type, &curTurns, &curStrength); switch (type) { case 0x10: if (curStrength > 0) { diff --git a/src/battle/battle_disp.c b/src/battle/battle_disp.c index de488d126..b3df99755 100644 --- a/src/battle/battle_disp.c +++ b/src/battle/battle_disp.c @@ -26,8 +26,6 @@ // FAKE: battle_disp.c calls iconDispGx through this prototype (the types it was compiled with) instead of the one in driver/icondrv.h; same registers, behaviour-identical. typedef void (*IconDispGxArgOrderFn)(f32, Vec*, s16, u16); -// FAKE: battle_disp.c calls BtlUnit_CheckStatus through this prototype (the types it was compiled with) instead of the one in battle/battle_unit.h; same registers, behaviour-identical. -typedef BOOL (*BtlUnit_CheckStatusS8Fn)(BattleUnit*, s8); #define PART_GRAVITY(p) ((p)->gravityTimer) #define PART_FLOAT(p) ((p)->floatTimer) @@ -328,7 +326,7 @@ BattlePoseType _GetStatusPoseType(BattleUnit* unit) { type = *table; if (*table == -1) break; - if (((BtlUnit_CheckStatusS8Fn)BtlUnit_CheckStatus)(unit, type)) { + if (BtlUnit_CheckStatus(unit, type)) { return (BattlePoseType)type; } table++; diff --git a/src/battle/battle_event_default.c b/src/battle/battle_event_default.c index 74575b2f4..39cc208fb 100644 --- a/src/battle/battle_event_default.c +++ b/src/battle/battle_event_default.c @@ -22,8 +22,6 @@ #include "battle/battle_damage.h" #include "version.h" -// FAKE: battle_event_default.c calls BattlePartyAnimeLoad through this prototype (the types it was compiled with) instead of the one in battle/battle.h; same registers, behaviour-identical. -typedef BOOL (*BattlePartyAnimeLoadRetBoolFn)(s32); static USER_FUNC(_anime_load); static USER_FUNC(_anime_load_wait); @@ -1064,13 +1062,13 @@ static USER_FUNC(_backfire) { /** Script: starts loading the animations of the partner chosen in the command menu. */ static USER_FUNC(_anime_load) { - ((BattlePartyAnimeLoadRetBoolFn)BattlePartyAnimeLoad)(_battleWorkPointer->commandMenu.partyKind); + BattlePartyAnimeLoad(_battleWorkPointer->commandMenu.partyKind); return EVT_RETURN_DONE; } /** Script: blocks until the chosen partner's animations are loaded. */ static USER_FUNC(_anime_load_wait) { - return ((BattlePartyAnimeLoadRetBoolFn)BattlePartyAnimeLoad)(_battleWorkPointer->commandMenu.partyKind) ? EVT_RETURN_DONE : EVT_RETURN_BLOCK; + return BattlePartyAnimeLoad(_battleWorkPointer->commandMenu.partyKind) ? EVT_RETURN_DONE : EVT_RETURN_BLOCK; } /** diff --git a/src/battle/battle_seq_command.c b/src/battle/battle_seq_command.c index d8720c1c1..1007d43e0 100644 --- a/src/battle/battle_seq_command.c +++ b/src/battle/battle_seq_command.c @@ -950,32 +950,29 @@ static void _btlcmd_MakeOperationTable(BattleWork* wp) { } } -// propagation optimisation off for _btlcmd_MakeMultiItemTable: the original register allocation and scheduling need it -#pragma opt_propagation off /** * Builds the menu shown before the item list when Double Dip or Triple Dip is equipped: * a single item, then Double Dip and Triple Dip with their FP cost (the P versions' names and icons for a * partner). */ static void _btlcmd_MakeMultiItemTable(BattleWork* wp) { - BattleUnit* unit; - BattleCommand* cmd; + BattleUnit* unit = BattleGetUnitPtr(wp, wp->activeUnitId); + BattleCommand* cmd = &wp->commandMenu; BattleCursor* cursor; s32 num; - unit = BattleGetUnitPtr(wp, wp->activeUnitId); - cmd = &wp->commandMenu; if (cmd == NULL) { return; } _btlcmd_GetCursorPtr(cmd, 3, &cursor); - cmd->multiItem[0].dipCount = 1; - cmd->multiItem[0].enabled = 1; - cmd->multiItem[0].name = msgSearch("btl_cmd_act_item"); - cmd->multiItem[0].icon = ICON_14C; - cmd->multiItem[0].help = NULL; - cmd->multiItem[0].cost = 0; - num = 1; + num = 0; + cmd->multiItem[num].dipCount = 1; + cmd->multiItem[num].enabled = 1; + cmd->multiItem[num].name = msgSearch("btl_cmd_act_item"); + cmd->multiItem[num].icon = ICON_14C; + cmd->multiItem[num].help = NULL; + cmd->multiItem[num].cost = 0; + num++; if (unit->badgesEquipped.DoubleDip) { cmd->multiItem[num].dipCount = 2; if (unit->currentKind == UNIT_MARIO) { @@ -1025,7 +1022,6 @@ static void _btlcmd_MakeMultiItemTable(BattleWork* wp) { cursor->absPos = cursor->count - 1; } } -#pragma opt_propagation reset // FAKE: inlining off (FAKES.md); without it _battleGetPartyIcon is inlined into _btlcmd_MakeOperationTable (274 -> 315 instructions; one other caller grows) #pragma dont_inline on @@ -3223,14 +3219,14 @@ static BOOL BattleCommandAttackAudienceCheck(void) { * or can't pick it now). */ static USER_FUNC(_get_msg) { - s32 index = event->args[0]; BattleWork* wp = _battleWorkPointer; + EvtWord* args = event->args; + s32 index = *args++; const char* msg; switch (wp->commandMenu.disableReason) { case 1: msg = "btl_msg_cmderror_no_fp"; - if (!event->args && !event->args) {} break; case 2: msg = "btl_msg_cmderror_no_ap"; diff --git a/src/battle/battle_seq_end.c b/src/battle/battle_seq_end.c index 4fb5676d1..dade12f22 100644 --- a/src/battle/battle_seq_end.c +++ b/src/battle/battle_seq_end.c @@ -354,15 +354,15 @@ void btlseqEnd(BattleWork* wp) { case 0x7000005: { BattleUnit* mario = BattleGetMarioPtr(wp); BattleUnit* party = BattleGetPartyPtr(wp); - s32 i; + s8 i; if (party && BtlUnit_CheckStatusFlag(party, STATUS_FLAG_FLIPPED)) { party->flippedTurns = 0; BtlUnit_OffStatusFlag(party, STATUS_FLAG_FLIPPED); BtlUnit_GetPartsPtr(party, BtlUnit_GetBodyPartsId(party))->poseTable = pose_table_nokotarou_stay; } BattleConsumeReserveItem(); - for (i = 0; (s8)i < STATUS_INVALID; i++) { - if ((s8)i >= STATUS_INVALID || (s8)i < STATUS_FRIGHT) { + for (i = 0; i < STATUS_INVALID; i++) { + if (i >= STATUS_INVALID || i < STATUS_FRIGHT) { if (party) BtlUnit_SetStatus(party, i, 0, 0); BtlUnit_SetStatus(mario, i, 0, 0); diff --git a/src/battle/battle_status_icon.c b/src/battle/battle_status_icon.c index 785c8c2b9..ff686ba16 100644 --- a/src/battle/battle_status_icon.c +++ b/src/battle/battle_status_icon.c @@ -10,10 +10,6 @@ #include "mario/mariost.h" #endif #include "battle/battle_unit.h" -// FAKE: battle_status_icon.c calls BtlUnit_GetStatus through this prototype (the types it was compiled with) instead of the one in battle/battle_unit.h; same registers, behaviour-identical. -typedef void (*BtlUnit_GetStatusS8Fn)(BattleUnit*, s8, s8*, s8*); -// FAKE: battle_status_icon.c calls BtlUnit_CheckStatus through this prototype (the types it was compiled with) instead of the one in battle/battle_unit.h; same registers, behaviour-identical. -typedef BOOL (*BtlUnit_CheckStatusS8Fn)(BattleUnit*, s8); typedef struct IconDispTableEntry IconDispTableEntry; struct IconDispTableEntry { @@ -326,15 +322,15 @@ static BOOL _bsi_default_turn(BattleUnit* unit, IconDispTableEntry* disp, Battle s8 turns, strength; s32 kind; if (_battleWorkPointer->flags & BATTLE_FLAG_SHOW_ALL_STATUS_ICONS) { - if (type != 1 && !BtlUnit_CheckStatus(unit, (s8)disp->statusType)) + if (type != 1 && !BtlUnit_CheckStatus(unit, type)) return FALSE; kind = (s32)unit->currentKind; if (!((kind >= 1 && kind < 0xd8) || (kind >= 0xde && kind < 0xe0) || (kind >= 0xe0 && kind < 0xe7))) return FALSE; - } else if (!BtlUnit_CheckStatus(unit, (s8)disp->statusType)) { + } else if (!BtlUnit_CheckStatus(unit, type)) { return FALSE; } - ((BtlUnit_GetStatusS8Fn)BtlUnit_GetStatus)(unit, type, &turns, &strength); + BtlUnit_GetStatus(unit, type, &turns, &strength); entry->type = type; entry->turns = turns >= 0 ? turns : -turns; entry->icon = disp->icon; @@ -356,12 +352,12 @@ static BOOL _bsi_guruguru(BattleUnit* unit, IconDispTableEntry* disp, BattleWork int type = disp->statusType; s8 turns, strength; Vec v; - if (!BtlUnit_CheckStatus(unit, (s8)type)) { + if (!BtlUnit_CheckStatus(unit, type)) { unit->statusIconWork.dizzyAngle = 0.0f; return FALSE; } unit->statusIconWork.dizzyAngle += 4.0f; - ((BtlUnit_GetStatusS8Fn)BtlUnit_GetStatus)(unit, type, &turns, &strength); + BtlUnit_GetStatus(unit, type, &turns, &strength); entry->type = type; entry->turns = turns >= 0 ? turns : -turns; entry->icon = disp->icon; @@ -383,11 +379,11 @@ static BOOL _bsi_guruguru(BattleUnit* unit, IconDispTableEntry* disp, BattleWork static BOOL _bsi_allergy(BattleUnit* unit, IconDispTableEntry* disp, BattleWorkStatusIconEntry* entry) { int type = disp->statusType; s8 turns, strength; - if (!BtlUnit_CheckStatus(unit, (s8)type)) { + if (!BtlUnit_CheckStatus(unit, type)) { unit->statusIconWork.allergyBlinkTimer = 0; return FALSE; } - ((BtlUnit_GetStatusS8Fn)BtlUnit_GetStatus)(unit, type, &turns, &strength); + BtlUnit_GetStatus(unit, type, &turns, &strength); entry->type = type; entry->turns = turns >= 0 ? turns : -turns; entry->icon = disp->icon; @@ -411,7 +407,7 @@ static BOOL _bsi_allergy(BattleUnit* unit, IconDispTableEntry* disp, BattleWorkS static BOOL _bsi_biribiri(BattleUnit* unit, IconDispTableEntry* disp, BattleWorkStatusIconEntry* entry) { s32 type = disp->statusType; s8 turns, strength; - if (!BtlUnit_CheckStatus(unit, (s8)disp->statusType)) { + if (!BtlUnit_CheckStatus(unit, type)) { unit->statusIconWork.elecState = 0; unit->statusIconWork.elecTimer = 0; return FALSE; @@ -438,7 +434,7 @@ static BOOL _bsi_biribiri(BattleUnit* unit, IconDispTableEntry* disp, BattleWork } break; } - ((BtlUnit_GetStatusS8Fn)BtlUnit_GetStatus)(unit, type, &turns, &strength); + BtlUnit_GetStatus(unit, type, &turns, &strength); entry->type = type; entry->turns = turns >= 0 ? turns : -turns; entry->icon = disp->icon; @@ -472,7 +468,7 @@ static BOOL _bsi_regeneration(BattleUnit* unit, IconDispTableEntry* disp, Battle } else { return FALSE; } - if (!((BtlUnit_CheckStatusS8Fn)BtlUnit_CheckStatus)(unit, disp->statusType)) { + if (!BtlUnit_CheckStatus(unit, type)) { *ctr = 0; return FALSE; } @@ -480,7 +476,7 @@ static BOOL _bsi_regeneration(BattleUnit* unit, IconDispTableEntry* disp, Battle t = (*ctr * 12) % 720; if (t >= 360) t = 720 - t; - ((BtlUnit_GetStatusS8Fn)BtlUnit_GetStatus)(unit, type, &turns, &strength); + BtlUnit_GetStatus(unit, type, &turns, &strength); entry->type = type; entry->turns = turns >= 0 ? turns : -turns; entry->icon = disp->icon; diff --git a/src/battle/battle_unit.c b/src/battle/battle_unit.c index bd4c60baa..48e65b742 100644 --- a/src/battle/battle_unit.c +++ b/src/battle/battle_unit.c @@ -19,8 +19,6 @@ #include "unit/unit_koura.h" #include "unit/party/unit_party_vivian.h" #include "battle/battle_actrecord.h" -// FAKE: battle_unit.c calls BtlUnit_snd_se_pos through this prototype (the types it was compiled with) instead of the one in battle/battle_unit.h; same registers, behaviour-identical. -typedef s32 (*BtlUnit_snd_se_posS32PitchFn)(BattleUnit*, const char*, s32, s32, Vec*); double pow(double, double); void BtlActRec_AddCount(u8* rec); @@ -1000,11 +998,11 @@ void _CheckMoveCount(BattleUnit* unit) { * for statuses with no strength (sleep, stop, dizzy, ...) both get the turn count. * A size, attack or defense change of the other sign reads as 0. */ -void BtlUnit_GetStatus(BattleUnit* unit, StatusEffectType type, s8* turns, s8* strength) { +void BtlUnit_GetStatus(BattleUnit* unit, s8 type, s8* turns, s8* strength) { s8 status_turns = 0; s8 status_strength = 0; - switch ((s8)type) { + switch (type) { case STATUS_SLEEP: status_strength = unit->sleepTurns; status_turns = status_strength; @@ -1139,8 +1137,8 @@ void BtlUnit_GetStatus(BattleUnit* unit, StatusEffectType type, s8* turns, s8* s * Returns FALSE when nothing was applied; retail versions also return FALSE when Charge drops below 0 * or Allergic or Payback is set to 0 turns, which the demos treat as set. */ -BOOL BtlUnit_SetStatus(BattleUnit* unit, StatusEffectType type, s8 turns, s8 strength) { - switch ((s8)type) { +BOOL BtlUnit_SetStatus(BattleUnit* unit, s8 type, s8 turns, s8 strength) { + switch (type) { case STATUS_SLEEP: unit->sleepTurns = turns; unit->sleepStrength = 0; @@ -1181,7 +1179,7 @@ BOOL BtlUnit_SetStatus(BattleUnit* unit, StatusEffectType type, s8 turns, s8 str case STATUS_HUGE: case STATUS_TINY: if (!strength) { - if ((s8)type == STATUS_HUGE) { + if (type == STATUS_HUGE) { if (unit->sizeChangeStrength >= 0) { unit->sizeChangeTurns = 0; unit->sizeChangeStrength = 0; @@ -1230,7 +1228,7 @@ BOOL BtlUnit_SetStatus(BattleUnit* unit, StatusEffectType type, s8 turns, s8 str unit->defChangeTurns = turns; unit->defChangeStrength = strength; } else if (strength == 0) { - if ((s8)type == STATUS_DEFENSE_DOWN) { + if (type == STATUS_DEFENSE_DOWN) { if (unit->defChangeStrength <= 0) { unit->defChangeTurns = 0; unit->defChangeStrength = 0; @@ -1358,7 +1356,7 @@ void BtlUnit_ClearStatus(BattleUnit* unit) { * attack and defense changes, poison and regen), clearing its strength when the turns run out. * Returns TRUE when the status just wore off; FALSE when it continues, was not active, or the unit is KO'd. */ -BOOL BtlUnit_CheckRecoveryStatus(BattleUnit* unit, StatusEffectType type) { +BOOL BtlUnit_CheckRecoveryStatus(BattleUnit* unit, s8 type) { s8 turns, strength; if (!unit) { @@ -1374,7 +1372,7 @@ BOOL BtlUnit_CheckRecoveryStatus(BattleUnit* unit, StatusEffectType type) { if (!turns) { return FALSE; } - switch ((s8)type) { + switch (type) { case STATUS_SLEEP: if (turns > 1) { turns--; @@ -1477,7 +1475,7 @@ BOOL BtlUnit_CheckRecoveryStatus(BattleUnit* unit, StatusEffectType type) { } /** Returns TRUE while the status effect has turns left; Electric also counts as active when the unit wears Zap Tap. */ -BOOL BtlUnit_CheckStatus(BattleUnit* unit, StatusEffectType type) { +BOOL BtlUnit_CheckStatus(BattleUnit* unit, s8 type) { s8 turns, strength; if (!unit) { @@ -1487,7 +1485,7 @@ BOOL BtlUnit_CheckStatus(BattleUnit* unit, StatusEffectType type) { if (turns) { return TRUE; } - if ((s8)type == STATUS_ELECTRIC && unit->badgesEquipped.ZapTap) { + if (type == STATUS_ELECTRIC && unit->badgesEquipped.ZapTap) { return TRUE; } return FALSE; @@ -2207,9 +2205,6 @@ void BtlUnit_PoseSoundInit(BattleUnitPart* part) { PART_POSE_SOUND(part)->prevTime = 0.0f; } -#pragma push -// propagation optimisation off for BtlUnit_ControlPoseSoundMain, BtlUnit_snd_se, BtlUnit_snd_se_pos and 4 more: the original register allocation and scheduling need it -#pragma opt_propagation off /** * Plays the sound effects tied to a part's current animation: * each frame, entries in the part's pose sound table whose time (in seconds of the animation) was just passed @@ -2219,90 +2214,79 @@ void BtlUnit_PoseSoundInit(BattleUnitPart* part) { void BtlUnit_ControlPoseSoundMain(BattleUnitPart* part) { BattleWork* wp = _battleWorkPointer; BtlPartPoseSound* state; - AnimTableEntry* anim; + const char* anim; BtlPoseSoundData* entry; AnimationPose* pose; f32 time; + u32 loops; s32 id; u8 vol; - f64 dv; - if (!part) { - return; - } - state = PART_POSE_SOUND(part); - entry = state->table; - if (!entry) { - return; - } - if (part->poseId == -1) { - return; - } - pose = animPoseGetAnimPosePtr(part->poseId); - if (!pose) { - return; - } - time = pose->localFrame / 60.0f; - if (state->loopCount > (u32)pose->loopTime) { - state->time = time; - state->prevTime = -1.0f; - state->loopCount = (s32)pose->loopTime; - state->count = 0; - if (BattleGetSeq(wp, SEQ_PHASE) == BATTLE_PHASE_PLAYER || BattleGetSeq(wp, SEQ_PHASE) == BATTLE_PHASE_ENEMY) { - state->flag = 1; - } - } else if (state->loopCount == (u32)pose->loopTime && state->time > time) { - state->time = time; - state->prevTime = -1.0f; - } else if (state->loopCount < (u32)pose->loopTime) { - state->time = time; - state->prevTime = -1.0f; - state->loopCount = (s32)pose->loopTime; - } else { - state->prevTime = state->time; - state->time = time; - } - if (state->time == state->prevTime) { - return; - } - anim = animPoseGetCurrentAnim(part->poseId); - for (; entry->animName; entry++) { - if (strcmp(entry->animName, (const char*)anim)) { - continue; - } - if (entry->time <= state->time && entry->time > state->prevTime) { - if (entry->flags & 1) { - if (entry->callback) { - id = entry->callback(part->owner, entry, state); + if (part) { + state = PART_POSE_SOUND(part); + entry = state->table; + if (entry && part->poseId != -1) { + pose = animPoseGetAnimPosePtr(part->poseId); + if (pose) { + time = pose->localFrame / 60.0f; + loops = pose->loopTime; + if (state->loopCount > loops) { + state->time = time; + state->prevTime = -1.0f; + state->loopCount = (s32)pose->loopTime; + state->count = 0; + if (BattleGetSeq(wp, SEQ_PHASE) == BATTLE_PHASE_PLAYER || BattleGetSeq(wp, SEQ_PHASE) == BATTLE_PHASE_ENEMY) { + state->flag = 1; + } + } else if (state->loopCount == loops && state->time > time) { + state->time = time; + state->prevTime = -1.0f; + } else if (state->loopCount < loops) { + state->time = time; + state->prevTime = -1.0f; + state->loopCount = (s32)pose->loopTime; } else { - id = BtlUnit_snd_se(part->owner, entry->sfxName, -250000000, entry->pitch); + state->prevTime = state->time; + state->time = time; } - psndSFX_vol(id, vol = 0x7F); - state->count++; - if (part->owner->attackPhase != BattleGetSeq(wp, SEQ_PHASE)) { - f64 k; - dv = (f64)(u32)vol; - vol = dv * (k = 0.7); - psndSFX_vol(id, vol); - } - } else { - if (entry->callback) { - entry->callback(part->owner, entry, state); - } else { - BtlUnit_snd_se(part->owner, entry->sfxName, -250000000, entry->pitch); + if (state->time != state->prevTime) { + anim = (const char*)animPoseGetCurrentAnim(part->poseId); + for (; entry->animName; entry++) { + if (!strcmp(entry->animName, anim) && entry->time <= state->time && entry->time > state->prevTime) { + if (entry->flags & 1) { + if (entry->callback) { + id = entry->callback(part->owner, entry, state); + } else { + id = BtlUnit_snd_se(part->owner, entry->sfxName, -250000000, entry->pitch); + } + vol = 0x7F; + psndSFX_vol(id, vol); + state->count++; + if (part->owner->attackPhase != BattleGetSeq(wp, SEQ_PHASE)) { + vol *= 0.7; + psndSFX_vol(id, vol); + } + } else { + if (entry->callback) { + entry->callback(part->owner, entry, state); + } else { + BtlUnit_snd_se(part->owner, entry->sfxName, -250000000, entry->pitch); + } + state->count++; + } + } + } } - state->count++; } } } } -#pragma pop /** Plays a sound effect at the unit's position (BtlUnit_snd_se_pos). */ -s32 BtlUnit_snd_se(BattleUnit* unit, const char* sfxName, s32 volume, s32 pan) { +s32 BtlUnit_snd_se(BattleUnit* unit, const char* sfxName, s32 volume, s16 pitch) { Vec pos; BtlUnit_GetPos(unit, &pos.x, &pos.y, &pos.z); - return ((BtlUnit_snd_se_posS32PitchFn)BtlUnit_snd_se_pos)(unit, sfxName, volume, pan, &pos); + return BtlUnit_snd_se_pos(unit, sfxName, volume, pitch, &pos); } /** diff --git a/src/battle/sac/sac_bakugame.c b/src/battle/sac/sac_bakugame.c index 3cb8fcdee..40cb6b64e 100644 --- a/src/battle/sac/sac_bakugame.c +++ b/src/battle/sac/sac_bakugame.c @@ -1427,7 +1427,7 @@ static void bakuGameDisp2D(CameraId cam, void* param) { disp->colorStep[1] = disp->colorStep[2] = -0x10; } } - BattleAcDrawGauge(w->dc, w->e0, 0xB1, w->rate, 3, 0x21, 0x42, 0x64, full); + BattleAcDrawGauge(w->dc, w->e0, w->rate, 0xB1, 3, 0x21, 0x42, 0x64, full); } #pragma dont_inline reset diff --git a/src/battle/sac/sac_genki.c b/src/battle/sac/sac_genki.c index 7032bc90c..3f0e79659 100644 --- a/src/battle/sac/sac_genki.c +++ b/src/battle/sac/sac_genki.c @@ -39,8 +39,6 @@ static void weapon_entry(void); // FAKE: sac_genki.c calls weapon_entry through this prototype (the types it was compiled with) instead of the one in battle/sac/sac_genki.h; same registers, behaviour-identical. typedef void (*Weapon_entryLocalFn)(void); -// FAKE: sac_genki.c calls iconDispGxCol through this prototype (the types it was compiled with) instead of the one in driver/icondrv.h; same registers, behaviour-identical. -typedef void (*IconDispGxColU16S32Fn)(Mtx, u16, s32, GXColor); // US battle texture ids are 0x16 higher for these entries. #define BTL_TEX(id) ((id) + VERSION_PICK(0, 0x16)) @@ -1027,7 +1025,7 @@ static void disp_3D(CameraId cam, void* param) { BattleUnit* party; u16 flags; s32 i; - s32 icon; + u16 icon; f32 ang; f32 mx, my, mz; f32 px, py, pz; @@ -1200,7 +1198,7 @@ static void disp_3D(CameraId cam, void* param) { } PSMTXScale(m, s, s, 1.0f); PSMTXTransApply(m, m, o->pos.x, o->pos.y - 20.0f * s, o->pos.z); - ((IconDispGxColU16S32Fn)iconDispGxCol)(m, flags, icon, (GXColor){255, 255, 255, 255}); + iconDispGxCol(m, flags, icon, (GXColor){255, 255, 255, 255}); } } diff --git a/src/battle/sac/sac_zubastar.c b/src/battle/sac/sac_zubastar.c index 326aad2b3..f9506c353 100644 --- a/src/battle/sac/sac_zubastar.c +++ b/src/battle/sac/sac_zubastar.c @@ -1017,7 +1017,7 @@ static void zubastar_disp2D(CameraId cam, void* param) { pos.x = w->gaugePos.x - 200.0f; pos.y = 60.0f + w->gaugePos.y; ((IconDispGxS32Fn)iconDispGx)(&pos, ICON_DISP_2D, icon, 1.0f); - BattleAcDrawGauge(w->gaugePos.x, w->gaugePos.y, 0xb1, 0.01f * w->gauge, 4, 0x1a, 0x34, 0x4e, 0); + BattleAcDrawGauge(w->gaugePos.x, w->gaugePos.y, 0.01f * w->gauge, 0xb1, 4, 0x1a, 0x34, 0x4e, 0); } GXSetCullMode(GX_CULL_NONE); GXClearVtxDesc(); diff --git a/src/driver/animdrv.c b/src/driver/animdrv.c index db9896fe4..5f1b0012e 100644 --- a/src/driver/animdrv.c +++ b/src/driver/animdrv.c @@ -6612,7 +6612,7 @@ inline s32 animPoseSearchName(const char* name, s32 type) { * The clamp of the bottom edge tests top instead of bottom, as in the original. */ void animPoseDisp_MakeExtTexture(const char* group, const char* anim, f32 frame, f32 scale, GXTexObj* obj, - smartEntry** image, s32* x0, s32* y0, s32* x1, s32* y1) { + void** image, s32* x0, s32* y0, s32* x1, s32* y1) { AnimationPose* pose; AnimationPose backup; Mtx m; @@ -6688,9 +6688,9 @@ void animPoseDisp_MakeExtTexture(const char* group, const char* anim, f32 frame, GXSetTexCopyDst(w, h, GX_TF_RGB5A3, GX_FALSE); anim_ext_tex_size += GXGetTexBufferSize(w, h, GX_TF_RGB5A3, GX_FALSE, 0); *image = smartAlloc(GXGetTexBufferSize(w, h, GX_TF_RGB5A3, GX_FALSE, 0), 1); - GXCopyTex((*image)->address, GX_TRUE); + GXCopyTex(((smartEntry*)*image)->address, GX_TRUE); GXPixModeSync(); - GXInitTexObj(obj, (*image)->address, w, h, GX_TF_RGB5A3, GX_CLAMP, GX_CLAMP, GX_FALSE); + GXInitTexObj(obj, ((smartEntry*)*image)->address, w, h, GX_TF_RGB5A3, GX_CLAMP, GX_CLAMP, GX_FALSE); *x0 = left - (s32)hw; *y0 = top - (s32)hh; *x1 = right - (s32)hw; diff --git a/src/driver/casedrv.c b/src/driver/casedrv.c index f89407eff..901d40106 100644 --- a/src/driver/casedrv.c +++ b/src/driver/casedrv.c @@ -18,10 +18,6 @@ #include #include -// FAKE: casedrv.c calls evtEntry through the prototype it was compiled with (an s32 priority, passed without -// the u8 truncation) instead of the one in manager/evtmgr.h; same registers -typedef EventEntry* (*EvtEntryS32PriorityFn)(void* evtCode, s32 priority, u8 flags); - typedef struct CaseWork { s32 count; // 0x0 CaseEntry* entries; // 0x4 @@ -56,8 +52,9 @@ void caseReInit(void) { */ s32 caseEntry(CaseSetup* setup) { CaseEntry* entry; - int i = 0; - for (entry = wp->entries; i < wp->count; i++, entry++) { + s32 i; + + for (i = 0, entry = wp->entries; i < wp->count; i++, entry++) { if (!(entry->flags & CASE_ENTRY_FLAG_IN_USE)) { break; // unused entry } @@ -77,7 +74,7 @@ s32 caseEntry(CaseSetup* setup) { entry->priority = setup->priority; entry->evtId = 0; memcpy(entry->lwData, setup->lwData, sizeof(entry->lwData)); - return i & 0xFFFFFFFFFFFFFFFFu; // FAKE: the no-op 64-bit mask swaps the i and entry registers as in the target; see FAKES.md + return i; } /** Releases case entry caseId so it no longer fires. */ @@ -256,7 +253,7 @@ void caseMain(void) { if (!evtCheckID(entry->evtId)) entry->evtId = 0; if (entry->evtId == 0) { - evt = ((EvtEntryS32PriorityFn)evtEntry)(entry->evtCode, entry->priority, 0x20); + evt = evtEntry(entry->evtCode, entry->priority, 0x20); evt->caseId = entry->caseId; entry->evtId = evt->eventId; memcpy(evt->lwData, entry->lwData, sizeof(entry->lwData)); diff --git a/src/driver/envdrv.c b/src/driver/envdrv.c index 2209c26dc..9ea420983 100644 --- a/src/driver/envdrv.c +++ b/src/driver/envdrv.c @@ -856,10 +856,9 @@ static void envGlare(EnvironmentGlare* glare) { * and x0/y0..x1/y1 the screen rectangle it covers (rounded out to even pixels and clamped to the frame); * type 0 turns it off. No caller in this tree. */ -void envGlareFilter(s32 type, s32 y0, s32 x0, s32 y1, s32 x1) { +void envGlareFilter(s32 type, s16 y0, s16 x0, s16 y1, s16 x1) { EnvironmentWork* wp = envGetWork(); EnvironmentGlareFilter* f = &wp->filter; - s16 sx1, sy1, sx0, sy0; if (type == 0) { f->type = 0; @@ -870,27 +869,27 @@ void envGlareFilter(s32 type, s32 y0, s32 x0, s32 y1, s32 x1) { wp->flags &= ~ENV_FLAG_GLARE; return; } - sx0 = x0 - (x0 & 1); - sy0 = y0 - (y0 & 1); - sx1 = x1 + (x1 & 1); - sy1 = y1 + (y1 & 1); - if (sx0 < 0) { - sx0 = 0; + x0 -= x0 & 1; + y0 -= y0 & 1; + x1 += x1 & 1; + y1 += y1 & 1; + if (x0 < 0) { + x0 = 0; } - if (sy0 < 0) { - sy0 = 0; + if (y0 < 0) { + y0 = 0; } - if (sx1 > gp->fbWidth) { - sx1 = gp->fbWidth; + if (x1 > gp->fbWidth) { + x1 = gp->fbWidth; } - if (sy1 > gp->efbHeight) { - sy1 = gp->efbHeight; + if (y1 > gp->efbHeight) { + y1 = gp->efbHeight; } f->type = type; - f->y0 = sy0; - f->x0 = sx0; - f->y1 = sy1; - f->x1 = sx1; + f->y0 = y0; + f->x0 = x0; + f->y1 = y1; + f->x1 = x1; f->zscale = 0.0f; f->flags &= ~ENV_GLARE_FLAG_DEPTH; wp->flags |= ENV_FLAG_GLARE; diff --git a/src/driver/extdrv.c b/src/driver/extdrv.c index c3ebd0e73..15aca12e3 100644 --- a/src/driver/extdrv.c +++ b/src/driver/extdrv.c @@ -15,8 +15,6 @@ #include "eff/eff_n64.h" #include "version.h" #include "libc_decls.h" -// FAKE: extdrv.c calls animPoseDisp_MakeExtTexture through this prototype (the types it was compiled with) instead of the one in driver/animdrv.h; same registers, behaviour-identical. -typedef void (*AnimPoseDisp_MakeExtTextureLocalFn)(const char*, const char*, f32, f32, GXTexObj*, void***, s32*, s32*, s32*, s32*); static ExtdrvWork work[2]; static u8 shadow_dl[32]; @@ -168,7 +166,7 @@ static void extMakeTexture(CameraId camId, void* param) { queen_uv[3] = -1.0f / wp->texNum; for (i = 0; i < wp->texNum; i++, info++, tex++) { n = i * 12; - ((AnimPoseDisp_MakeExtTextureLocalFn)animPoseDisp_MakeExtTexture)(info->group, info->anim, info->frame, 4.0f, &tex->obj, &tex->image, &x0, &y0, &x1, &y1); + animPoseDisp_MakeExtTexture(info->group, info->anim, info->frame, 4.0f, &tex->obj, &tex->image, &x0, &y0, &x1, &y1); wp->vtx[n++] = x0 / 2.0f; wp->vtx[n++] = -y0 / 2.0f; wp->vtx[n++] = 0.0f; diff --git a/src/driver/icondrv.c b/src/driver/icondrv.c index f68cdb60d..22df629c0 100644 --- a/src/driver/icondrv.c +++ b/src/driver/icondrv.c @@ -543,7 +543,7 @@ void iconDispGx2(Mtx mtx, s16 flags, u16 iconId) { * Immediately draws icon iconId with a caller-built matrix, tinted by color; * used for the digit icons of iconNumberDispGx. */ -void iconDispGxCol(Mtx pos, s16 flags, u16 iconId, GXColor color) { +void iconDispGxCol(Mtx pos, u16 flags, u16 iconId, GXColor color) { IconEntry entry; Mtx m; CameraEntry* camera; diff --git a/src/driver/lightdrv.c b/src/driver/lightdrv.c index b31d19821..6ba6297fa 100644 --- a/src/driver/lightdrv.c +++ b/src/driver/lightdrv.c @@ -130,7 +130,7 @@ static const Vec decay_tbl[] = { * attenType picks the distance falloff from decay_tbl, flag 2 marks a character-only light. * A clashing name gets a _0000-style suffix. Returns the slot index. */ -s32 lightEntry(const char* name, s32 type, Vec* position, Vec* rotation, GXColor color, s32 attenType, s32 flags, f32 spotAngle, f32 attenAngle) { +s32 lightEntry(const char* name, s32 type, Vec* position, Vec* rotation, GXColor color, f32 spotAngle, f32 attenAngle, s32 attenType, s32 flags) { LightWork* wp = lightGetWork(); LightEntry* entry; s32 i, j, n; @@ -237,35 +237,27 @@ static s32 _sort(const void* a, const void* b) { * keeping only lights with any of flags (0 = all); NULL-pads the rest and returns how many were found. * mapdrv uses it to light map parts and characters. */ -s32 lightGetNearObj(Vec position, LightEntry** out, s32 count, LightEntryFlags flags) { - s32 found; +s32 lightGetNearObj(Vec* position, LightEntry** out, s32 count, LightEntryFlags flags) { LightWork* wp = lightGetWork(); - NearWork tmp[32]; - LightEntry** op; - NearWork* tp; + NearWork tmp[LIGHT_ENTRY_COUNT]; LightEntry* entry; - s32 i; u32 n; - u32 mask; + s32 i; + s32 j; if (lightGetEntryNum() > 8) { - entry = wp->entries; - tp = tmp; n = 0; - for (i = 0; i < wp->count; i++, entry++) { + for (i = 0, entry = wp->entries; i < wp->count; i++, entry++) { if (entry->flags & LIGHT_ENABLED) { - tp->entry = entry; - tp->dist = VECDistance(&position, &entry->position); - tp++; + tmp[n].entry = entry; + tmp[n].dist = VECDistance(position, &entry->position); n++; } } - qqsort(tmp, n, 8, _sort); + qqsort(tmp, n, sizeof(NearWork), _sort); } else { - entry = wp->entries; - tp = tmp; n = 0; - for (i = 0; i < wp->count; i++, entry++) { + for (j = 0, entry = wp->entries; j < wp->count; j++, entry++) { if (entry->flags & LIGHT_ENABLED) { tmp[n].entry = entry; n++; @@ -273,26 +265,25 @@ s32 lightGetNearObj(Vec position, LightEntry** out, s32 count, LightEntryFlags f } } - op = out; - tp = tmp; - mask = flags; - found = 0; - for (i = 0; i < n; i++, tp++) { - u32 fl; - LightEntry* e = tp->entry; - fl = e->flags; - if (!(fl & LIGHT_AMBIENT) && (!mask || (mask & fl))) { - *op++ = e; - found++; - if (found >= count) { - break; - } + j = 0; + for (i = 0; i < n; i++) { + entry = tmp[i].entry; + if (entry->flags & LIGHT_AMBIENT) { + continue; + } + if (flags && !(flags & entry->flags)) { + continue; + } + out[j] = entry; + j++; + if (j >= count) { + break; } } - for (i = found; i < count; i++) { + for (i = j; i < count; i++) { out[i] = NULL; } - return found; + return j; } /** Returns the first enabled map (non-character) ambient light, or NULL. */ diff --git a/src/driver/mapdrv.c b/src/driver/mapdrv.c index 3bf1e790b..8832a5ece 100644 --- a/src/driver/mapdrv.c +++ b/src/driver/mapdrv.c @@ -21,8 +21,6 @@ #include "gxsub.h" #include #include "driver/hitdrv.h" -// FAKE: mapdrv.c calls lightEntry through this prototype (the types it was compiled with) instead of the one in driver/lightdrv.h; same registers, behaviour-identical. -typedef s32 (*LightEntryArgOrderFn)(const char*, s32, Vec*, Vec*, GXColor*, f32, f32, s32, s32); /** Single-precision sine for this file, routed through the double sin() of math.h. */ static inline f32 sinf(f32 x) { return sin(x); @@ -93,8 +91,6 @@ s32 activeGroup; MapWork* mapWork; // allocates two entries static void mapGetJointsSub(MapFileJoint* joint, s32* numJoints); -// FAKE: calls lightGetNearObj with the Vec address instead of a by-value copy (FAKES.md) -#define lightGetNearObj(pos, out, count, flags) ((s32 (*)(Vec*, LightEntry**, s32, LightEntryFlags))lightGetNearObj)(pos, out, count, flags) // local prototypes static void mapGetJointsSub(MapFileJoint* joint, s32* numJoints); @@ -495,7 +491,7 @@ static MapObject* mapEntrySub(MapFileJoint* joint, MapObject* parent, Mtx mtx, B * and builds the object tree from the root joint with world matrix mtx; returns the root object. */ static MapObject* mapEntry(MapFileJoint* joint, Mtx mtx, s32 index) { - MapWork* wp = (0, &mapWork[activeGroup]); // FAKE: the comma expression gives wp the target register (r31, not r30) + MapWork* wp = mapGetWork(); u32 size; wp->entries[index].numJoints = mapGetJoints(joint); @@ -996,7 +992,6 @@ static void _mapLoad(MapWork* wp, BOOL group, const char* map) { for (i = 0; i < wp->entries[group].lightTable->count; i++) { MapFileLight* light = wp->entries[group].lightTable->lights[i]; Vec pos; - GXColor lcolor; s32 type = 1; s32 lflags = 0; PSVECScale(&light->position, &pos, 10.0f); @@ -1012,8 +1007,7 @@ static void _mapLoad(MapWork* wp, BOOL group, const char* map) { if (light->magic == 0x12D60D8) { lflags = light->lflags; } - lcolor = light->color; - ((LightEntryArgOrderFn)lightEntry)(light->name, type, &pos, &light->rotation, &lcolor, light->spotAngle, light->attenAngle, light->attenType, lflags); + lightEntry(light->name, type, &pos, &light->rotation, light->color, light->spotAngle, light->attenAngle, light->attenType, lflags); } } mapResetPaperAmbColor(); @@ -1452,8 +1446,8 @@ void bmapLoad(const char* map, const char* map2) { } } - wp = (0, &mapWork[1]); // FAKE: the comma expression keeps the target register order for wp activeGroup = 1; + wp = mapGetWork(); memset(wp, 0, sizeof(MapWork)); #if VERSION <= VERSION_DEMO_JP // the demo reads the battle map archives itself diff --git a/src/driver/mobjdrv.c b/src/driver/mobjdrv.c index a03b37995..a7ed10f3a 100644 --- a/src/driver/mobjdrv.c +++ b/src/driver/mobjdrv.c @@ -476,11 +476,9 @@ void mobjHitEntry(MapObjectEntry* entry, s32 type) { PSVECScale(&entry->translation, &entry->translation, 0.5f); PSVECScale(&entry->translation, &entry->translation, 10.0f); entry->translation.y = 0.0f; - // FAKE: the `(0, x)` comma expressions change MWCC's expression tree so the |max - min| loads get the - // target float registers; the values are the same - entry->scale2.x = 10.0f * (entry->scale.x * (f32)(0, __fabs((0, max.x - min.x)))); - entry->scale2.y = 10.0f * (entry->scale.y * (f32)__fabs(max.y)); - entry->scale2.z = 10.0f * (entry->scale.z * (f32)(0, __fabs((0, max.z - min.z)))); + entry->scale2.x = 10.0f * (entry->scale.x * (f32)fabs(max.x - min.x)); + entry->scale2.y = 10.0f * (entry->scale.y * (f32)fabs(max.y)); + entry->scale2.z = 10.0f * (entry->scale.z * (f32)fabs(max.z - min.z)); if (strncmp(pose->fileName, "HOBJ_", strlen("HOBJ_")) == 0) { entry->translation.z = 0.0f; entry->scale2.z = 10.0f * (2.5f * entry->scale.z); diff --git a/src/driver/npcdrv.c b/src/driver/npcdrv.c index 94822c117..b4f1b56d2 100644 --- a/src/driver/npcdrv.c +++ b/src/driver/npcdrv.c @@ -1354,37 +1354,41 @@ void npcSetMarioAutoTalkPose(const char* stayPose, const char* talkPose) { strcpy(MarioTalkPose, talkPose); } -// FAKE: turns off copy propagation so the temporaries and registers match the target; removing it changes the code -#pragma opt_propagation off -#pragma opt_lifetimes off /** * name is non-const as in the original: through a const char* the scheduler moves the first load up into the * register saves (MWCC treats const loads as not aliasing the stores). */ void npcSetTalkPose(char* name) { PartyEntry* party; + NpcWork* wp; NpcEntry* npc; + s32 total; + int i; - if (*(s8*)name == 0) - return; - if (!strcmp(name, "(^x^)party")) - return; - if (!strcmp(name, "party")) { - party = partyGetPtr(marioGetPartyId()); - if (party) { - partyChgPoseId(party, 7); - } - } else if (!strcmp(name, "extparty")) { - party = partyGetPtr(marioGetExtraPartyId()); - if (party) { - partyChgPoseId(party, 7); - } - } else if (!strcmp(name, "mario")) { - marioChgPose(MarioTalkPose); - } else { - npc = npcNameToPtr(name); - if (npc->flags & NPC_FLAG_TALK_ANIM) { - animPoseSetAnim(npc->poseId, npc->talkAnim, TRUE); + if ((s8)name[0] != '\0' && strcmp(name, "(^x^)party")) { + if (!strcmp(name, "party")) { + party = partyGetPtr(marioGetPartyId()); + if (party != NULL) { + partyChgPoseId(party, 7); + } + } else if (!strcmp(name, "extparty")) { + party = partyGetPtr(marioGetExtraPartyId()); + if (party != NULL) { + partyChgPoseId(party, 7); + } + } else if (!strcmp(name, "mario")) { + marioChgPose(MarioTalkPose); + } else { + wp = npcGetWorkPtrInline(); + total = wp->total; + for (i = 0, npc = wp->entries; i < total; i++, npc++) { + if (npc->flags & NPC_FLAG_USED && !strcmp(npc->description, name)) { + break; + } + } + if (npc->flags & NPC_FLAG_TALK_ANIM) { + animPoseSetAnim(npc->poseId, npc->talkAnim, TRUE); + } } } } @@ -1397,32 +1401,42 @@ void npcSetTalkPose(char* name) { */ void npcSetStayPose(char* name) { PartyEntry* party; + NpcWork* wp; NpcEntry* npc; + s32 total; + int i; - if (*(s8*)name == 0) - return; - if (!strcmp(name, "(^x^)party")) - return; - if (!strcmp(name, "party")) { - party = partyGetPtr(marioGetPartyId()); - if (party) { - partyChgPoseId(party, 1); - } - } else if (!strcmp(name, "extparty")) { - party = partyGetPtr(marioGetExtraPartyId()); - if (party) { - partyChgPoseId(party, 1); - } - } else if (!strcmp(name, "mario")) { - marioChgPose(MarioStayPose); - } else { - npc = npcNameToPtr(name); - if (npc->flags & NPC_FLAG_TALK_ANIM) { - animPoseSetAnim(npc->poseId, npc->stayAnim, TRUE); + if ((s8)name[0] != '\0' && strcmp(name, "(^x^)party")) { + if (!strcmp(name, "party")) { + party = partyGetPtr(marioGetPartyId()); + if (party != NULL) { + partyChgPoseId(party, 1); + } + } else if (!strcmp(name, "extparty")) { + party = partyGetPtr(marioGetExtraPartyId()); + if (party != NULL) { + partyChgPoseId(party, 1); + } + } else if (!strcmp(name, "mario")) { + marioChgPose(MarioStayPose); + } else { + wp = npcGetWorkPtrInline(); + total = wp->total; + for (i = 0, npc = wp->entries; i < total; i++, npc++) { + if (npc->flags & NPC_FLAG_USED && !strcmp(npc->description, name)) { + break; + } + } + if (npc->flags & NPC_FLAG_TALK_ANIM) { + animPoseSetAnim(npc->poseId, npc->stayAnim, TRUE); + } } } } +// FAKE: turns off copy propagation so the temporaries and registers match the target; removing it changes the code +#pragma opt_propagation off +#pragma opt_lifetimes off /** * Keeps a friendly NPC from walking through Mario: * if they overlap side-on and vertically, the NPC goes back to its previous X/Z @@ -2070,7 +2084,6 @@ void fbatEncountCheck(void) { f32 dir; f32 a; f32 yaw; - s32 k; pos.x = mario->position.x; pos.z = mario->position.z; pos.y = npc->position.y; @@ -2082,24 +2095,15 @@ void fbatEncountCheck(void) { yaw = camGetPtr(CAMERA_3D)->viewYaw; dir = reviseAngle(marioGetDispDir() - yaw); for (j = 0; j < 3; j++) { - // FAKE: dead int-guarded re-definition inside the loop keeps dir a named web (COLOURING M; no code, no preheader split) - k = 0; - if (k != 0) - dir = 0.0f; switch (j) { case 0: - yaw = camGetPtr(CAMERA_3D)->viewYaw; - a = reviseAngle(angleABf(mario->position.x, mario->position.z, npc->position.x, npc->position.z) - yaw); + a = reviseAngle(angleABf(mario->position.x, mario->position.z, npc->position.x, npc->position.z) - camGetPtr(CAMERA_3D)->viewYaw); break; - case 1: - yaw = camGetPtr(CAMERA_3D)->viewYaw; - a = reviseAngle(angleABf(mario->position.x, mario->position.z, npc->position.x + (0.5f * npc->width), npc->position.z) - yaw); + a = reviseAngle(angleABf(mario->position.x, mario->position.z, npc->position.x + 0.5f * npc->width, npc->position.z) - camGetPtr(CAMERA_3D)->viewYaw); break; - default: - yaw = camGetPtr(CAMERA_3D)->viewYaw; - a = reviseAngle(angleABf(mario->position.x, mario->position.z, npc->position.x - (0.5f * npc->width), npc->position.z) - yaw); + a = reviseAngle(angleABf(mario->position.x, mario->position.z, npc->position.x - 0.5f * npc->width, npc->position.z) - camGetPtr(CAMERA_3D)->viewYaw); break; } diff --git a/src/effect/eff_mahojin.c b/src/effect/eff_mahojin.c index 3a431fa22..42d1d75db 100644 --- a/src/effect/eff_mahojin.c +++ b/src/effect/eff_mahojin.c @@ -11,7 +11,7 @@ #include static void effMahojinMain(EffectEntry* effect); -static void effMahojinDisp(CameraId cameraId, EffectEntry* effect); +static void effMahojinDisp(CameraId cameraId, void* param); s32 mahojin_rate; @@ -277,60 +277,59 @@ static void effMahojinMain(EffectEntry* effect) { break; } } - dispEntry(CAMERA_3D, dispCalcZ(&position), 2, (DispCallback)effMahojinDisp, effect); + dispEntry(CAMERA_3D, dispCalcZ(&position), 2, effMahojinDisp, effect); } /** * Draws the magic circle's front and back animation poses at the effect position, * applying the purple tint callback. */ -static void effMahojinDisp(CameraId cameraId, EffectEntry* effect) { - Mtx mtx; - f32 z[16]; - s32 idx[16]; - f32* zp; - MapWork* map; - s32* idxList; // FAKE: alias of idx forces z/idx base register order - s32 i; +static void effMahojinDisp(CameraId cameraId, void* param) { s32 j; - s32 k; - s32 n; - EffMahojinWork* work = effect->userdata; + EffMahojinWork* work; s32 pass; + MapWork* map; + s32 ti; s32 alpha; + s32 i; + f32 tz; + EffectEntry* effect; u16 flags; + s32 n; + EffMahojinWork* p; + Mtx mtx; + f32 z[16]; + s32 idx[16]; + effect = param; + work = effect->userdata; camGetPtr(cameraId); alpha = work->alpha; map = mapGetWork(); - zp = z; flags = map->entries[0].flags; - for (pass = 0; pass < 2; pass++) { n = 0; if (pass == 0) { - zp[0] = -9999.0f; + z[n] = -9999.0f; idx[n++] = 0; z[n] = -10000.0f; idx[n++] = 1; } else { - zp[0] = -10000.0f; + z[n] = -10000.0f; idx[n++] = 0; z[n] = 10000.0f; idx[n++] = 1; } for (i = 2; i < effect->count; i++) { - f32 d = dispCalcZ(&pos_tbl[i - 2]); - z[n] = d; + z[n] = dispCalcZ(&pos_tbl[i - 2]); idx[n++] = i; } - idxList = idx; // FAKE for (i = 0; i < effect->count - 1; i++) { for (j = i + 1; j < effect->count; j++) { - if (zp[i] > z[j]) { - s32 ti = idx[i]; - f32 tz = zp[i]; - zp[i] = z[j]; + if (z[i] > z[j]) { + tz = z[i]; + ti = idx[i]; + z[i] = z[j]; idx[i] = idx[j]; z[j] = tz; idx[j] = ti; @@ -339,8 +338,8 @@ static void effMahojinDisp(CameraId cameraId, EffectEntry* effect) { } map->entries[0].flags &= ~1; PSMTXTrans(mtx, work->position.x, work->position.y, work->position.z); - for (k = 0; k < effect->count; k++) { - EffMahojinWork* p = &work[idxList[k]]; + for (i = 0; i < effect->count; i++) { + p = &work[idx[i]]; if (pass == 1 && p->arg != NULL) { p->func(cameraId, p->arg); } diff --git a/src/effect/eff_sleep.c b/src/effect/eff_sleep.c index 93a7ce524..b78d9e595 100644 --- a/src/effect/eff_sleep.c +++ b/src/effect/eff_sleep.c @@ -10,12 +10,17 @@ #include "version.h" #include "libc_decls.h" +/** Single-precision sine for this file, routed through the double sin() (as in mapdrv.c). */ +static inline f32 sinf(f32 x) { + return sin(x); +} + static void effSleepMain(EffectEntry* effect); // US effect texture ids are 0x1C lower for these entries. #define EFF_TEX(id) ((id) - VERSION_PICK(0, 0x1C)) // local prototypes -static void effSleepDisp(CameraId camId, EffectEntry* effect); +static void effSleepDisp(CameraId camId, void* param); /** * Spawns the sleep marks at (x, y, z). @@ -98,46 +103,24 @@ static void effSleepMain(EffectEntry* effect) { } } } - dispEntry(CAMERA_3D, dispCalcZ(&position), 2, (DispCallback)effSleepDisp, effect); + dispEntry(CAMERA_3D, dispCalcZ(&position), 2, effSleepDisp, effect); } -// FAKE: match-forcing setting: the same code without it compiles differently (removal tried). -#pragma push -// FAKE: propagation optimisation off for sleepPos, effSleepDisp: the original register allocation and scheduling need it -#pragma opt_propagation off - -// FAKE: same values as the plain form, written so the code generator sees the target's shapes: -// - sin argument via `(t = tau * x, t *= 0.015625f)`: a compound assignment skips the front end's -// commutative swap (CExpr optimizecomm), so the constant stays the right operand; -// - 0.5f / 0.015625f / 1.0f are literals (LICM-hoisted temps in first-use order), xh = x0 * 0.5f is -// computed in the inner loop body, and the y products go through sleepPos so `1.0f * y` is not -// folded away by the front end (CExpr_IsOne). -static inline void sleepPos(f32 x, f32 one, f32 y) { - GXPosition3f32(x, one * y, 0.0f); -} /** * Draws each visible mark as a camera-facing strip of 8 quads whose x offset follows a sine wave, * giving a wavy ribbon texture. */ -static void effSleepDisp(CameraId camId, EffectEntry* effect) { - s32 off; - f32 tau; - f32 x0; - Mtx mtx; - Mtx scale; - s32 base; - Mtx rot; - Mtx res; - GXTexObj texObj; - f32 w; +static void effSleepDisp(CameraId camId, void* param) { + EffectEntry* effect = param; CameraEntry* cam; + s32 base; effSleepData* data; - int i; + s32 i; s32 j; s32 alpha; - f32 xh; - f32 s0, s1; - f32 t; + Mtx mtx, scale, rot, res; + GXTexObj texObj; + f32 w, s0, s1; data = effect->userdata; cam = camGetPtr(camId); @@ -167,9 +150,8 @@ static void effSleepDisp(CameraId camId, EffectEntry* effect) { GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); w = 8.0f; - x0 = -w; - - for (i = 1, data++, base = 50; i < effect->count; base += 50, i++, data++) { + data++; + for (i = 1, base = 50; i < effect->count; base += 50, i++, data++) { if (data->delay == 0) { GXSetChanMatColor(GX_COLOR0A0, (GXColor){0xFF, 0xFF, 0xFF, data->alpha * alpha / 255}); PSMTXTrans(mtx, data->position.x, data->position.y, data->position.z); @@ -178,30 +160,22 @@ static void effSleepDisp(CameraId camId, EffectEntry* effect) { PSMTXConcat(res, mtx, mtx); GXLoadPosMtxImm(mtx, GX_PNMTX0); GXSetCurrentMtx(GX_PNMTX0); - tau = 6.2831855f; - j = 0; - off = 0; - while (j < 8) { - s0 = 0.5f * (f32)sin((t = (tau * (f32)(u32)(gp->retraceCount + base + off)), t *= 0.015625f)); - s1 = 0.5f * (f32)sin((t = (tau * (f32)(u32)(gp->retraceCount + base + (j + 1) * 10)), t *= 0.015625f)); - xh = x0; - xh *= 0.5f; + for (j = 0; j < 8; j++) { + s0 = 0.5f * sinf(6.2831855f * (gp->retraceCount + base + j * 10) / 64); + s1 = 0.5f * sinf(6.2831855f * (gp->retraceCount + base + (j + 1) * 10) / 64); GXBegin(GX_QUADS, GX_VTXFMT0, 4); - sleepPos(xh + s1, 1.0f, j + 1); - GXTexCoord2f32(0.0f, 0.125f * (f32)(7 - j)); - sleepPos(4.0f + s1, 1.0f, j + 1); - GXTexCoord2f32(1.0f, 0.125f * (f32)(7 - j)); - sleepPos(4.0f + s0, 1.0f, j); - GXTexCoord2f32(1.0f, 0.125f * (f32)(8 - j)); - sleepPos(xh + s0, 1.0f, j); - GXTexCoord2f32(0.0f, 0.125f * (f32)(8 - j)); - j++; - off += 10; + GXPosition3f32(-w / 2 + s1, w / 8 * (j + 1), 0.0f); + GXTexCoord2f32(0.0f, 0.125f * (7 - j)); + GXPosition3f32(w / 2 + s1, w / 8 * (j + 1), 0.0f); + GXTexCoord2f32(1.0f, 0.125f * (7 - j)); + GXPosition3f32(w / 2 + s0, w / 8 * j, 0.0f); + GXTexCoord2f32(1.0f, 0.125f * (8 - j)); + GXPosition3f32(-w / 2 + s0, w / 8 * j, 0.0f); + GXTexCoord2f32(0.0f, 0.125f * (8 - j)); + GXEnd(); } } } } -#pragma pop - // target pad words (G5: section sizes must match or later DOL addresses shift) diff --git a/src/effect/eff_splash.c b/src/effect/eff_splash.c index f8287fffa..79c62166d 100644 --- a/src/effect/eff_splash.c +++ b/src/effect/eff_splash.c @@ -339,8 +339,7 @@ static void effSplashGetCol(CameraId cameraId, EffectEntry* effect) { GXProject(work->position.x, work->position.y, work->position.z, cam->view, proj, vp, &sx, &sy, &sz); if (sx > 0.0f && sx < 608.0f && sy > 0.0f && sy < 480.0f) { sysWaitDrawSync(); - // FAKE: unprototyped call: the SDK u16 parameters would add two narrowings (FAKES.md) - ((void (*)())GXPeekARGB)((s32)sx, (s32)sy, argb); + GXPeekARGB(sx, sy, (u32*)argb); work->color.r = argb[1]; work->color.g = argb[2]; work->color.b = argb[3]; diff --git a/src/event/evt_kinopio.c b/src/event/evt_kinopio.c index 82bed30fc..e4c7e3a98 100644 --- a/src/event/evt_kinopio.c +++ b/src/event/evt_kinopio.c @@ -34,8 +34,6 @@ typedef struct KinopioParty { s16 pad8[3]; } KinopioParty; -typedef s32 (*KinopioGetter)(void); - typedef struct KinopioWork { s32 breakfastItem; // 0x0 Vec breakfastPos; // 0x4 @@ -100,7 +98,7 @@ static USER_FUNC(power_chk) { break; } } - if (((KinopioGetter)pouchGetHP)() == ((KinopioGetter)pouchGetMaxHP)() && ((KinopioGetter)pouchGetFP)() == ((KinopioGetter)pouchGetMaxFP)() && ((KinopioGetter)pouchGetAP)() == ((KinopioGetter)pouchGetMaxAP)() && ok) { + if (pouchGetHP() == pouchGetMaxHP() && pouchGetFP() == pouchGetMaxFP() && pouchGetAP() == pouchGetMaxAP() && ok) { evtSetValue(event, args[0], 1); } else { evtSetValue(event, args[0], 0); diff --git a/src/event/evt_mario.c b/src/event/evt_mario.c index b79525ceb..a65e806e9 100644 --- a/src/event/evt_mario.c +++ b/src/event/evt_mario.c @@ -26,6 +26,7 @@ #include "mot/mot_plane.h" #include "mot/mot_slit.h" #include "party/party_motion.h" +#include "party/party_move.h" #include "party/party_yoshi.h" #include "peach.h" #include "version.h" @@ -152,9 +153,6 @@ static inline BOOL marioLandChk(f32 vy) { return FALSE; } -// FAKE: the calls pass a direction that partyMoveBehindMario3 (party_move.c) does not take; -// the extra f32 argument is computed and ignored, so it goes through this wider prototype. -void partyMoveBehindMario3(PartyEntry* party, s32 a, f32 dir); void partySetDispDirToMario(PartyEntry* party); /** diff --git a/src/manager/evtmgr.c b/src/manager/evtmgr.c index 0c48a8edf..131c7c2af 100644 --- a/src/manager/evtmgr.c +++ b/src/manager/evtmgr.c @@ -182,7 +182,7 @@ static void evtEntryRunCheck(EventEntry* entry) { * type 0xEF (stopped by every system level). Its LW/LF variables start at 0. * Started during evtmgrMain with EVENT_START_NOW, it also runs this frame. Does not check that a slot is free. */ -EventEntry* evtEntry(void* evtCode, u8 priority, u8 flags) { +EventEntry* evtEntry(void* evtCode, s32 priority, u8 flags) { EventWork* wp = evtGetWork(); EventEntry* entry; int i, id; diff --git a/src/mario/mario_kemuri.c b/src/mario/mario_kemuri.c index 5141781b2..ae5d04050 100644 --- a/src/mario/mario_kemuri.c +++ b/src/mario/mario_kemuri.c @@ -44,48 +44,46 @@ void mario_kemuri(void) { attr = 0; - if ((u32)marioStGetSystemLevel() == 0) { - if (!(mario->flags & MARIO_FLAG_TUBE_MODE)) { - if (mario->currMotionId == MARIO_MOTION_DOKAN) { - // no dust while going through a pipe - // FAKE: an empty branch is one instruction short; the self-assignment keeps the original's branch layout - s = s; - } else { - if (mario->currMotionId != MARIO_MOTION_JUMP) { - if (mario->hitobjStandOn != NULL) { - attr = hitGetAttr(mario->hitobjStandOn); - } - } else if (mario->hitobjJumpFrom != NULL) { - attr = hitGetAttr(mario->hitobjJumpFrom); - } - { - if (attr & HIT_ATTR_GRASS) { - kemuri_mugi(); - } else if (attr & HIT_ATTR_SHALLOW_WATER) { - mario_kemuri_landon(); - } else if (attr & 0x100000) { - mario = marioGetPtr(); - if (mario->currMotionId != MARIO_MOTION_DASH && mario->currMotionId != MARIO_MOTION_WALK) { - ct = 8; - } else if (ct++ > 8) { - ct = 0; - sincosf(&s, &c, 6.2831855f * reviseAngle(-mario->directionView) / 360.0f); - effKemuri7N64Entry(mario->position.x + 0.2f * (mario->wPlayerCollisionBox.x * s), - 0.5f + mario->position.y, - mario->position.z + 0.2f * (mario->wPlayerCollisionBox.x * c), - -mario->directionView, (f32)left_or_right); - left_or_right = left_or_right == 0; - } - } else if (!(mario->flags & MARIO_FLAG_TUBE_MODE)) { - if (kpaGetBodyStatus() <= 0 && mario->characterId != 1) { - kemuri(); - } - } - } - } + // no dust at a raised system level, in tube mode or while going through a pipe + if ((u32)marioStGetSystemLevel() != 0 || (mario->flags & MARIO_FLAG_TUBE_MODE) || + mario->currMotionId == MARIO_MOTION_DOKAN) { + return; + } + if (mario->currMotionId != MARIO_MOTION_JUMP) { + if (mario->hitobjStandOn != NULL) { + attr = hitGetAttr(mario->hitobjStandOn); } + } else if (mario->hitobjJumpFrom != NULL) { + attr = hitGetAttr(mario->hitobjJumpFrom); + } + if (attr & HIT_ATTR_GRASS) { + kemuri_mugi(); + return; + } + if (attr & HIT_ATTR_SHALLOW_WATER) { + mario_kemuri_landon(); + return; + } + if (attr & 0x100000) { + mario = marioGetPtr(); + if (mario->currMotionId != MARIO_MOTION_DASH && mario->currMotionId != MARIO_MOTION_WALK) { + ct = 8; + return; + } + if (ct++ > 8) { + ct = 0; + sincosf(&s, &c, 6.2831855f * reviseAngle(-mario->directionView) / 360.0f); + effKemuri7N64Entry(mario->position.x + 0.2f * (mario->wPlayerCollisionBox.x * s), + 0.5f + mario->position.y, + mario->position.z + 0.2f * (mario->wPlayerCollisionBox.x * c), + -mario->directionView, (f32)left_or_right); + left_or_right = left_or_right == 0; + } + return; + } + if (!(mario->flags & MARIO_FLAG_TUBE_MODE) && kpaGetBodyStatus() <= 0 && mario->characterId != 1) { + kemuri(); } -out:; } /** diff --git a/src/mario/mario_motion.c b/src/mario/mario_motion.c index 49e70f11f..43d6c72cb 100644 --- a/src/mario/mario_motion.c +++ b/src/mario/mario_motion.c @@ -1131,8 +1131,6 @@ s32 marioChkRub(void) { return 0; } -typedef BOOL (*MarioCreviceWallChkByValueFn)(Vec pos); - /** * From the slit motion: rolls Mario into a tube when R is held, the stick-rub gesture counts 3, * he has the Tube Curse and no wall or crevice is around him. Not in 8-bit mode. @@ -1158,9 +1156,7 @@ s32 marioRollChgChk(void) { if (!PCHK(3)) { return 0; } - // FAKE: the Vec goes by value (the ABI passes a pointer to a copy, which is what the real `const Vec*` - // receives); copying it into a local first changes the code of this function and of its inlined callers - if (marioSlitChkWallAround() || ((MarioCreviceWallChkByValueFn)marioCreviceWallChk)(mario->position)) { + if (marioSlitChkWallAround() || marioCreviceWallChk(mario->position)) { return 0; } if (mario->buttonHold & PAD_TRIGGER_R) { diff --git a/src/mario/mario_pouch.c b/src/mario/mario_pouch.c index 66283e84b..d496fc88c 100644 --- a/src/mario/mario_pouch.c +++ b/src/mario/mario_pouch.c @@ -1117,12 +1117,12 @@ s32 pouchGetHP(void) { } /** Max HP including HP Plus badges. */ -s16 pouchGetMaxHP(void) { +s32 pouchGetMaxHP(void) { return mpp->maximumHP; } /** Sets current HP, clamped to the maximum (not to 0). */ -void pouchSetHP(s16 points) { +void pouchSetHP(s32 points) { mpp->currentHP = points; if (mpp->currentHP > mpp->maximumHP) { mpp->currentHP = mpp->maximumHP; @@ -1157,12 +1157,12 @@ s32 pouchGetFP(void) { } /** Max FP including FP Plus badges. */ -s16 pouchGetMaxFP(void) { +s32 pouchGetMaxFP(void) { return mpp->maximumFP; } /** Sets current FP, clamped to the maximum (not to 0). */ -void pouchSetFP(s16 points) { +void pouchSetFP(s32 points) { mpp->currentFP = points; if (mpp->currentFP > mpp->maximumFP) { mpp->currentFP = mpp->maximumFP; @@ -1192,7 +1192,7 @@ void pouchAddAP(s32 points) { } /** Sets Star Power, clamped to 0..maximumSP. */ -void pouchSetAP(s16 points) { +void pouchSetAP(s32 points) { mpp->currentSP = points; if (mpp->currentSP < 0) { mpp->currentSP = 0; @@ -1203,7 +1203,7 @@ void pouchSetAP(s16 points) { } /** Star Power maximum in hundredths of a gauge unit (100 per Crystal Star). */ -s16 pouchGetMaxAP(void) { +s32 pouchGetMaxAP(void) { return mpp->maximumSP; } diff --git a/src/motion/mot_slit.c b/src/motion/mot_slit.c index 2958ea18f..39805fbe6 100644 --- a/src/motion/mot_slit.c +++ b/src/motion/mot_slit.c @@ -131,117 +131,92 @@ BOOL marioSlitKeyDisable(void) { */ BOOL U_marioSlitContinueChk(void) { MarioWork* mario = marioGetPtr(); - Vec pos; if (marioSlitButton()) { return TRUE; } if (marioSlitChkWallAround()) { return TRUE; } - pos = mario->position; - return marioCreviceWallChk(&pos) != 0; + return marioCreviceWallChk(mario->position) != 0; } #endif /** - * TRUE when position p is inside a narrow crack: + * TRUE when pos is inside a narrow crack: * rays 20 units to both sides (each tried from the centre and from points 10 units ahead and behind) hit walls * whose normals face each other within 10 degrees. */ -BOOL marioCreviceWallChk(const Vec* p) { +BOOL marioCreviceWallChk(Vec pos) { + Vec start; + Vec dir; + Vec outPos; + Vec outNrm; + f32 s; + f32 c; + f32 dist; f32 offX; f32 offZ; + f32 h; f32 angA; f32 angB; HitEntry* hitA; HitEntry* hitB; - f32 s; - f32 c; - f32 dist; - f32 h = 10.0f; - Vec pos; - Vec dir; - Vec outPos; - Vec outNrm; marioGetPtr(); + h = 10.0f; sincosf(&s, &c, toMovedirSimple(270.0f)); - offX = 0.5f * (20.0f * s); - offZ = 0.5f * (20.0f * c); angA = 0.0f; angB = angA; + offX = 0.5f * (20.0f * s); + offZ = 0.5f * (20.0f * c); + sincosf(&s, &c, toMovedirSimple(180.0f)); dist = 20.0f; - pos = *p; - pos.y += 10.0f; - { - Vec t1 = {0, 0, 0}; - t1.x = s; - t1.z = c; - dir = t1; - } - hitA = marioHitCheckVec(&pos, &dir, &outPos, &outNrm, &dist); + start = pos; + start.y += h; + dir = (Vec){s, 0.0f, c}; + hitA = marioHitCheckVec(&start, &dir, &outPos, &outNrm, &dist); if (hitA) { angA = angleABf(0.0f, 0.0f, outNrm.x, outNrm.z); } if (!hitA) { - Vec t2 = {0, 0, 0}; dist = 20.0f; - t2.x = p->x + offX; - t2.y = p->y + h; - t2.z = p->z + offZ; - pos = t2; - hitA = marioHitCheckVec(&pos, &dir, &outPos, &outNrm, &dist); + start = (Vec){pos.x + offX, pos.y + h, pos.z + offZ}; + hitA = marioHitCheckVec(&start, &dir, &outPos, &outNrm, &dist); if (hitA) { angA = angleABf(0.0f, 0.0f, outNrm.x, outNrm.z); } } if (!hitA) { - Vec t3 = {0, 0, 0}; dist = 20.0f; - t3.x = p->x - offX; - t3.y = p->y + h; - t3.z = p->z - offZ; - pos = t3; - hitA = marioHitCheckVec(&pos, &dir, &outPos, &outNrm, &dist); + start = (Vec){pos.x - offX, pos.y + h, pos.z - offZ}; + hitA = marioHitCheckVec(&start, &dir, &outPos, &outNrm, &dist); if (hitA) { angA = angleABf(0.0f, 0.0f, outNrm.x, outNrm.z); } } + sincosf(&s, &c, toMovedirSimple(0.0f)); dist = 20.0f; - pos = *p; - pos.y += 10.0f; - { - Vec u1 = {0, 0, 0}; - u1.x = s; - u1.z = c; - dir = u1; - } - hitB = marioHitCheckVec(&pos, &dir, &outPos, &outNrm, &dist); + start = pos; + start.y += h; + dir = (Vec){s, 0.0f, c}; + hitB = marioHitCheckVec(&start, &dir, &outPos, &outNrm, &dist); if (hitB) { angB = angleABf(0.0f, 0.0f, outNrm.x, outNrm.z); } if (!hitB) { - Vec u2 = {0, 0, 0}; dist = 20.0f; - u2.x = p->x + offX; - u2.y = p->y + h; - u2.z = p->z + offZ; - pos = u2; - hitB = marioHitCheckVec(&pos, &dir, &outPos, &outNrm, &dist); + start = (Vec){pos.x + offX, pos.y + h, pos.z + offZ}; + hitB = marioHitCheckVec(&start, &dir, &outPos, &outNrm, &dist); if (hitB) { angB = angleABf(0.0f, 0.0f, outNrm.x, outNrm.z); } } if (!hitB) { - Vec u3 = {0, 0, 0}; dist = 20.0f; - u3.x = p->x - offX; - u3.y = p->y + h; - u3.z = p->z - offZ; - pos = u3; - hitB = marioHitCheckVec(&pos, &dir, &outPos, &outNrm, &dist); + start = (Vec){pos.x - offX, pos.y + h, pos.z - offZ}; + hitB = marioHitCheckVec(&start, &dir, &outPos, &outNrm, &dist); if (hitB) { angB = angleABf(0.0f, 0.0f, outNrm.x, outNrm.z); } @@ -641,7 +616,6 @@ void marioReInit_slit(void) { */ static inline BOOL slitContinueChk(void) { MarioWork* mario = marioGetPtr(); - Vec pos; #if VERSION <= VERSION_DEMO_JP if (marioSlitButton() == 2) { #else @@ -652,8 +626,7 @@ static inline BOOL slitContinueChk(void) { if (marioSlitChkWallAround()) { return TRUE; } - pos = mario->position; - if (marioCreviceWallChk(&pos)) { + if (marioCreviceWallChk(mario->position)) { return TRUE; } return FALSE; diff --git a/src/party/party_motion.c b/src/party/party_motion.c index 9e0ab6177..14abd676a 100644 --- a/src/party/party_motion.c +++ b/src/party/party_motion.c @@ -3836,7 +3836,7 @@ void party_motion_homing_fly(PartyEntry* party) { /** * Makes the next behind-Mario walk stand at direction dir (degrees, relative to the camera) from Mario instead - * of behind his facing; partyMoveBehindMario3 calls it without passing dir. + * of behind his facing (partyMoveBehindMario3). */ void party_set_behind_dir(PartyEntry* party, f32 dir) { party->homeDir = revise360(dir + camGetPtr((CameraId)4)->viewYaw); diff --git a/src/party/party_move.c b/src/party/party_move.c index 0d7121bcc..b21a80e2a 100644 --- a/src/party/party_move.c +++ b/src/party/party_move.c @@ -1362,17 +1362,15 @@ void partyMoveBehindMario(PartyEntry* party, s32 arg) { /** * partyMoveBehindMario for evt_mario.c's scripted moves: - * also keeps a set homeDir (party_set_behind_dir) and uses the smaller push box around Mario. + * also sets homeDir to dir (party_set_behind_dir) and uses the smaller push box around Mario. */ -void partyMoveBehindMario3(PartyEntry* party, s32 arg) { +void partyMoveBehindMario3(PartyEntry* party, s32 arg, f32 dir) { if (party->currentMemberId == PARTY_MEMBER_YOSHI && party->runMode == 3) { return; } party->trigFlags |= PARTY_TRIG_FLAG_HOME_DIR_SET; party->trigFlags |= PARTY_TRIG_FLAG_SMALL_HOSEI; - // FAKE: BUG: the call passes no direction, so homeDir gets whatever is left in f1; the cast keeps - // the call without the argument. - ((void (*)(PartyEntry*))party_set_behind_dir)(party); + party_set_behind_dir(party, dir); party->moveArg = arg; partyChgMoveMode(party, 2); partyChgMot(party, 1); diff --git a/src/party/party_yoshi.c b/src/party/party_yoshi.c index 90c9e0e3e..ad007c2c0 100644 --- a/src/party/party_yoshi.c +++ b/src/party/party_yoshi.c @@ -1754,14 +1754,12 @@ void L_getStick(PartyEntry* party, f32* angle, f32* speed) { dist = 1.5f * (mario->baseWalkSpeed * marioGetMoveRate(ang)); } #else - *angle = revise360(ang + party->camDir); + *angle = ang = revise360(ang + party->camDir); if (dist > 0.0f) { if (x * x + y * y > 3025) { - // FAKE: BUG: the retail code (JP/US/PAL) calls marioGetMoveRate without the direction (it reads whatever - // is in f1, here the angle just stored); the cast keeps the call without the argument. - dist = 1.5f * (mario->baseDashSpeed * ((f32 (*)(void))marioGetMoveRate)()); + dist = 1.5f * (mario->baseDashSpeed * marioGetMoveRate(ang)); } else { - dist = 1.5f * (mario->baseWalkSpeed * ((f32 (*)(void))marioGetMoveRate)()); // FAKE: as above + dist = 1.5f * (mario->baseWalkSpeed * marioGetMoveRate(ang)); } #endif if (hitGetAttr(mario->hitobjStandOn) & HIT_ATTR_SHALLOW_WATER) { diff --git a/src/sdk/arc.c b/src/sdk/arc.c index c8f27f99c..07ea577be 100644 --- a/src/sdk/arc.c +++ b/src/sdk/arc.c @@ -164,18 +164,18 @@ static u32 myStrncpy(char* dest, char* src, u32 maxlen) { } return maxlen - i; } -// FAKE: inline_depth(3) to the end of the file: without it entryToPath inlines deeper (169 instead of 136 instructions) -#pragma inline_depth(3) /** Builds the path of an entry into path by walking up its parent directories; returns its length. */ static u32 entryToPath(ARCHandle* handle, u32 entry, char* path, u32 maxlen) { char* name; u32 loc; FSTEntry* FstStart = (FSTEntry*)handle->FSTStart; + char* FstStringStart; if (entry == 0) { return 0; } - name = handle->FSTStringStart + stringOff(entry); + FstStringStart = handle->FSTStringStart; + name = FstStringStart + stringOff(entry); loc = entryToPath(handle, parentDir(entry), path, maxlen); if (loc == maxlen) { return loc; diff --git a/src/unit/party/unit_party_yoshi.c b/src/unit/party/unit_party_yoshi.c index f8407fb13..8fb6cbf78 100644 --- a/src/unit/party/unit_party_yoshi.c +++ b/src/unit/party/unit_party_yoshi.c @@ -2312,7 +2312,7 @@ USER_FUNC(btl_yoshi_yoroyoro_jump_move) { * plays the footstep sound at volume UW_YOSHI_SLIDE_SOUND_POWER * UW_YOSHI_SLIDE_SOUND_PERCENT / 100. */ static void _yoshi_slide_move_sound(BattleUnit* unit, PoseSoundTiming* s) { - BtlUnit_snd_se(unit, s->sfxName, -250000000, (s16)(unit->work[UW_YOSHI_SLIDE_SOUND_POWER] * unit->work[UW_YOSHI_SLIDE_SOUND_PERCENT] / 100)); // slide sound volume + BtlUnit_snd_se(unit, s->sfxName, -250000000, unit->work[UW_YOSHI_SLIDE_SOUND_POWER] * unit->work[UW_YOSHI_SLIDE_SOUND_PERCENT] / 100); // slide sound volume } /** diff --git a/src/window/win_item.c b/src/window/win_item.c index dacab43c5..121e860fc 100644 --- a/src/window/win_item.c +++ b/src/window/win_item.c @@ -23,15 +23,9 @@ #include "evt/evt_story.h" #include #include -// FAKE: win_item.c calls pouchSetHP through this prototype (the types it was compiled with) instead of the one in mario/mario_pouch.h; same registers, behaviour-identical. -typedef void (*PouchSetHPS32Fn)(s32); -// FAKE: win_item.c calls pouchSetFP through this prototype (the types it was compiled with) instead of the one in mario/mario_pouch.h; same registers, behaviour-identical. -typedef void (*PouchSetFPS32Fn)(s32); -// FAKE: win_item.c calls pouchSetAP through this prototype (the types it was compiled with) instead of the one in mario/mario_pouch.h; same registers, behaviour-identical. -typedef void (*PouchSetAPS32Fn)(s32); -// FAKE: win_item.c calls pouchGetMaxHP through this prototype (the types it was compiled with) instead of the one in mario/mario_pouch.h; same registers, behaviour-identical. +// FAKE: PAL's itemUseDisp still calls pouchGetMaxHP and pouchGetMaxFP through these s32 prototypes. They are now the +// header's own types, so the plain call should build the same, but it has not been checked against a PAL build. typedef s32 (*PouchGetMaxHPRetS32Fn)(void); -// FAKE: win_item.c calls pouchGetMaxFP through this prototype (the types it was compiled with) instead of the one in mario/mario_pouch.h; same registers, behaviour-identical. typedef s32 (*PouchGetMaxFPRetS32Fn)(void); static void itemUseDisp(WinMgrEntry* entry); @@ -672,17 +666,17 @@ s32 winItemMain(WindowWork* w) { } } if (w->item.useTarget < 1) { - ((PouchSetHPS32Fn)pouchSetHP)(pouchGetHP() + itemDataTable[w->item.useItem].hp_restored); + pouchSetHP(pouchGetHP() + itemDataTable[w->item.useItem].hp_restored); #if VERSION >= VERSION_JP - ((PouchSetFPS32Fn)pouchSetFP)(pouchGetFP() + itemDataTable[w->item.useItem].fp_restored); - ((PouchSetAPS32Fn)pouchSetAP)(pouchGetAP() + itemDataTable[w->item.useItem].sp_restored); + pouchSetFP(pouchGetFP() + itemDataTable[w->item.useItem].fp_restored); + pouchSetAP(pouchGetAP() + itemDataTable[w->item.useItem].sp_restored); #endif } else { party = list[w->item.useTarget - 1]->partyId; pouchSetPartyHP(party, pouchGetPartyHP(party) + itemDataTable[w->item.useItem].hp_restored); #if VERSION >= VERSION_JP - ((PouchSetFPS32Fn)pouchSetFP)(pouchGetFP() + itemDataTable[w->item.useItem].fp_restored); - ((PouchSetAPS32Fn)pouchSetAP)(pouchGetAP() + itemDataTable[w->item.useItem].sp_restored); + pouchSetFP(pouchGetFP() + itemDataTable[w->item.useItem].fp_restored); + pouchSetAP(pouchGetAP() + itemDataTable[w->item.useItem].sp_restored); #endif } w->item.blink = 0; @@ -1009,7 +1003,7 @@ static void itemUseDisp(WinMgrEntry* entry) { #if VERSION >= VERSION_DEMO_EU winFontSetWidth((Vec){entry->x + 310, entry->y - 10 - off, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, black, 30.0f, "%d", ((PouchGetMaxHPRetS32Fn)pouchGetMaxHP)()); #else - winFontSet((Vec){entry->x + 310, entry->y - 10 - off, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, black, "%d", ((PouchGetMaxHPRetS32Fn)pouchGetMaxHP)()); + winFontSet((Vec){entry->x + 310, entry->y - 10 - off, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, black, "%d", pouchGetMaxHP()); #endif #if VERSION >= VERSION_JP if (itemDataTable[w->item.useItem].fp_restored) { @@ -1030,7 +1024,7 @@ static void itemUseDisp(WinMgrEntry* entry) { #if VERSION >= VERSION_DEMO_EU winFontSetWidth((Vec){entry->x + 310, entry->y - 10 - off3, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, black, 30.0f, "%d", ((PouchGetMaxFPRetS32Fn)pouchGetMaxFP)()); #else - winFontSet((Vec){entry->x + 310, entry->y - 10 - off3, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, black, "%d", ((PouchGetMaxFPRetS32Fn)pouchGetMaxFP)()); + winFontSet((Vec){entry->x + 310, entry->y - 10 - off3, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, black, "%d", pouchGetMaxFP()); #endif } else { name = list[i - 1]->partyId != 4 ? msgSearch(list[i - 1]->name) : pouchGetYoshiName(); diff --git a/src/window/win_main.c b/src/window/win_main.c index 387193b4c..00c97cf3a 100644 --- a/src/window/win_main.c +++ b/src/window/win_main.c @@ -41,12 +41,6 @@ #include "mario/mario_pouch.h" #include "mario/mariost.h" #include "win/win_party.h" -// FAKE: win_main.c calls pouchSetHP through this prototype (the types it was compiled with) instead of the one in mario/mario_pouch.h; same registers, behaviour-identical. -typedef void (*PouchSetHPS32Fn)(s32); -// FAKE: win_main.c calls pouchSetFP through this prototype (the types it was compiled with) instead of the one in mario/mario_pouch.h; same registers, behaviour-identical. -typedef void (*PouchSetFPS32Fn)(s32); -// FAKE: win_main.c calls pouchSetAP through this prototype (the types it was compiled with) instead of the one in mario/mario_pouch.h; same registers, behaviour-identical. -typedef void (*PouchSetAPS32Fn)(s32); // FAKE: the 0.5f that winTexSet and friends load is a named .sdata2 constant defined after winLectureCheck // (winConstHalf below); with a plain 0.5f literal the .sdata2 constants come out in a different @@ -936,13 +930,13 @@ static USER_FUNC(itemUseFunc) { case 0: statusWinForceOpen(); if (event->lwData[11] == 0) { - ((PouchSetHPS32Fn)pouchSetHP)(pouchGetHP() + item->hp_restored); - ((PouchSetFPS32Fn)pouchSetFP)(pouchGetFP() + item->fp_restored); - ((PouchSetAPS32Fn)pouchSetAP)(pouchGetAP() + item->sp_restored); + pouchSetHP(pouchGetHP() + item->hp_restored); + pouchSetFP(pouchGetFP() + item->fp_restored); + pouchSetAP(pouchGetAP() + item->sp_restored); } else { pouchSetPartyHP(event->lwData[11], pouchGetPartyHP(event->lwData[11]) + item->hp_restored); - ((PouchSetFPS32Fn)pouchSetFP)(pouchGetFP() + item->fp_restored); - ((PouchSetAPS32Fn)pouchSetAP)(pouchGetAP() + item->sp_restored); + pouchSetFP(pouchGetFP() + item->fp_restored); + pouchSetAP(pouchGetAP() + item->sp_restored); } cnt++; break; diff --git a/src/window/win_mario.c b/src/window/win_mario.c index fc0a3ea9d..de9af90b2 100644 --- a/src/window/win_mario.c +++ b/src/window/win_mario.c @@ -472,68 +472,32 @@ static void fukidashi(WindowWork* w, u32 idx, f32 x, f32 y) { * Draws the Mario window (menu slot idx): name, level and rank, the gear and curse bubbles, HP/FP/BP, * the Star Power gauge, Star Points, coins, Star Pieces, Shine Sprites and play time (capped at 99:59), * Mario's model, and the special-move list when open. - * US: every float live range has its own variable (register order); rowC is the second value of rowB */ void winMarioDisp(s32 camId, void* param, s32 idx) { - f32 rowC; - // FAKE: q1/q2 hold copies of row0/row1 for the dead guards after the f198 block (register order, no code) - f32 q1[1]; - f32 q2[1]; static s32 pri[6] = {3, 2, 8, 10, 7, 9}; - f32 rowL; - f32 y2; - f32 x2; - f32 cx6; - f32 cx5; - f32 cx4; - f32 cx3; - f32 cx2; - f32 nameW3; - f32 rowB; - f32 rowA; - f32 row0; - f32 row1; - f32 row2; - f32 nameW2; - f32 left; - f32 col7; - f32 col6; - f32 col5; - f32 col4; - f32 col3; - f32 col2; - f32 rowA3; - f32 rowA2; - f32 row0b; - f32 rowB3; - f32 rowB2; - f32 row1b; - f32 row2b; - f32 x; - f32 y; - f32 cx; - f32 col; - f32 nameW; - f32 numX; - f32 row3; - f32 rubyW; - WindowWork* w; + WindowWork* w = param; + PouchData* pouch = pouchGetPtr(); + GXColor white2; + GXColor black2; GXColor white; GXColor black; - PouchData* pouch; + f32 cx; + f32 nameW; + char buf[0x100]; s32 i; - s64 secs; - u64 tsecs; + f32 iconX; + f32 apX; + f32 left; + u64 secs; s32 hour; s32 min; AnimData* anim; Mtx mtx; - char buf[0x100]; + f32 x; + f32 y; - w = param; - pouch = pouchGetPtr(); - white = (GXColor){0xFF, 0xFF, 0xFF, 0xFF}; - black = (GXColor){0x00, 0x00, 0x00, 0xFF}; + white2 = white = (GXColor){0xFF, 0xFF, 0xFF, 0xFF}; + black2 = black = (GXColor){0x00, 0x00, 0x00, 0xFF}; x = w->menu[idx].x; y = w->menu[idx].y; winBgGX(w, 0, x, y); @@ -554,12 +518,13 @@ void winMarioDisp(s32 camId, void* param, s32 idx) { nameW = 20.0f; } winFontInit(); - winFontSetEdgeWidth((Vec){(190.0f + (x - 265.0f)) - nameW - 10.0f, 152.0f + y, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white, 20.0f, buf); + winFontSetEdgeWidth((Vec){190.0f + (x - 265.0f) - nameW - 10.0f, 152.0f + y, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white, 20.0f, buf); winTexInit(*w->res->data); winTexSet(0xB0, (Vec){x - 255.0f, 112.0f + y, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, white); winFontInit(); winFontSetWidth((Vec){x - 240.0f, 124.0f + y, 0.0f}, (Vec){0.7f, 0.7f, 0.7f}, black, 140.0f, msgSearch(BattleGetRankNameLabel(pouch->level))); + // the gear and curse bubbles, the one under the cursor drawn last so it sits on top for (i = 0; i < 6; i++) { if (w->marioSel != pri[i]) { fukidashi(w, pri[i], x, y); @@ -567,140 +532,124 @@ void winMarioDisp(s32 camId, void* param, s32 idx) { } fukidashi(w, w->marioSel, x, y); + // the HP/FP/BP rows: a coloured tab with the stat's name and its ruby winKirinukiGX(w, 0, x - 270.0f, y - 10.0f, 264.0f, 110.0f); - col = 50.0f + (x - 270.0f); - for (i = 0; i < 3; i++) { - GXColor cols[3] = {{0xCB, 0x8C, 0xA2, 0xFE}, {0xCB, 0xBE, 0x89, 0xFE}, {0x94, 0xB9, 0xC7, 0xFE}}; - GXColor reds[3] = {{0xA7, 0x3C, 0x3C, 0xFF}, {0x37, 0x69, 0x1E, 0xFF}, {0x0F, 0x21, 0x7A, 0xFF}}; - const char* const N_stat_name_tbl[7][3] = { - {"\x82\x67\x82\x6F", "\x82\x65\x82\x6F", "\x82\x61\x82\x6F"}, - {"HP", "FP", "BP"}, - {"KP", "BP", "OP"}, - {"PC", "PF", "PB"}, - {"PC", "PF", "PM"}, - {"PV", "PF", "PT"}, - {"HP", "FP", "BP"}, - }; - const char* ruby[3] = {"msg_menu_mario_ruby_hp", "msg_menu_mario_ruby_fp", "msg_menu_mario_ruby_bp"}; - - rowL = 50.0f + (x - 270.0f) - 2.0f; - nameW2 = FontGetMessageWidth(N_stat_name_tbl[gp->language][i]); - rubyW = 0.5f * FontGetMessageWidth(msgSearch(ruby[i])); - winTexInit(*w->res->data); - GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0); - GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_A0, GX_CA_TEXA, GX_CA_ZERO); - winTexSet(0xAF, (Vec){rowL, (cx2 = (y - 38.0f) - (f32)(i * 34)) - 4.0f, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, cols[i]); - winFontInit(); - winFontSet((Vec){col - nameW2 / 2.0f, 12.0f + cx2, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, N_stat_name_tbl[gp->language][i]); - winFontSet((Vec){col - rubyW / 2.0f, 21.0f + cx2, 0.0f}, (Vec){0.5f, 0.5f, 0.5f}, reds[i], msgSearch(ruby[i])); + { + f32 nameW2; + f32 rubyW; + + for (i = 0; i < 3; i++) { + GXColor cols[3] = {{0xCB, 0x8C, 0xA2, 0xFE}, {0xCB, 0xBE, 0x89, 0xFE}, {0x94, 0xB9, 0xC7, 0xFE}}; + GXColor reds[3] = {{0xA7, 0x3C, 0x3C, 0xFF}, {0x37, 0x69, 0x1E, 0xFF}, {0x0F, 0x21, 0x7A, 0xFF}}; + const char* N_stat_name_tbl[7][3] = { + {"\x82\x67\x82\x6F", "\x82\x65\x82\x6F", "\x82\x61\x82\x6F"}, + {"HP", "FP", "BP"}, + {"KP", "BP", "OP"}, + {"PC", "PF", "PB"}, + {"PC", "PF", "PM"}, + {"PV", "PF", "PT"}, + {"HP", "FP", "BP"}, + }; + const char* ruby[3] = {"msg_menu_mario_ruby_hp", "msg_menu_mario_ruby_fp", "msg_menu_mario_ruby_bp"}; + + nameW2 = FontGetMessageWidth(N_stat_name_tbl[gp->language][i]); + rubyW = 0.5f * FontGetMessageWidth(msgSearch(ruby[i])); + winTexInit(*w->res->data); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_A0, GX_CA_TEXA, GX_CA_ZERO); + winTexSet(0xAF, (Vec){(50.0f + (x - 270.0f)) - 2.0f, ((y - 38.0f) - i * 34) - 4.0f, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, cols[i]); + winFontInit(); + winFontSet((Vec){(50.0f + (x - 270.0f)) - nameW2 / 2.0f, 12.0f + ((y - 38.0f) - i * 34), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black2, N_stat_name_tbl[gp->language][i]); + winFontSet((Vec){(50.0f + (x - 270.0f)) - rubyW / 2.0f, 21.0f + ((y - 38.0f) - i * 34), 0.0f}, (Vec){0.5f, 0.5f, 0.5f}, reds[i], msgSearch(ruby[i])); + } } + // the stat icons and values (current / maximum for HP and FP, BP alone) winIconInit(); - winIconSet(ICON_19F, (Vec){col2 = 110.0f + (x - 270.0f), row0 = 4.0f + (y - 38.0f), 0.0f}, (Vec){0.82f, 0.82f, 0.82f}, white); - winIconSet(ICON_1A0, (Vec){col2, row1 = 4.0f + (rowB = (y - 38.0f) - 34.0f), 0.0f}, (Vec){0.82f, 0.82f, 0.82f}, white); - winIconSet(ICON_1A1, (Vec){col2, 4.0f + (rowA = (y - 38.0f) - 68.0f), 0.0f}, (Vec){0.82f, 0.82f, 0.82f}, white); + iconX = 110.0f + (x - 270.0f); + winIconSet(ICON_19F, (Vec){iconX, 4.0f + (y - 38.0f), 0.0f}, (Vec){0.82f, 0.82f, 0.82f}, white); + winIconSet(ICON_1A0, (Vec){iconX, 4.0f + ((y - 38.0f) - 34.0f), 0.0f}, (Vec){0.82f, 0.82f, 0.82f}, white); + winIconSet(ICON_1A1, (Vec){iconX, 4.0f + ((y - 38.0f) - 68.0f), 0.0f}, (Vec){0.82f, 0.82f, 0.82f}, white); winFontInit(); - winFontSetR((Vec){col3 = 130.0f + (x - 270.0f), row2 = 4.0f + (12.0f + (y - 38.0f)), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, "%s", winZenkakuStr(pouch->currentHP)); - winFontSetR((Vec){col3, rowC = 4.0f + (12.0f + rowB), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, "%s", winZenkakuStr(pouch->currentFP)); - winFontSetR((Vec){col3, 4.0f + (12.0f + rowA), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, "%s", winZenkakuStr(pouch->maximumBP)); + winFontSetR((Vec){130.0f + (x - 270.0f), 4.0f + (12.0f + (y - 38.0f)), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, "%s", winZenkakuStr(pouch->currentHP)); + winFontSetR((Vec){130.0f + (x - 270.0f), 4.0f + (12.0f + ((y - 38.0f) - 34.0f)), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, "%s", winZenkakuStr(pouch->currentFP)); + winFontSetR((Vec){130.0f + (x - 270.0f), 4.0f + (12.0f + ((y - 38.0f) - 68.0f)), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, "%s", winZenkakuStr(pouch->maximumBP)); winTexInit(*w->res->data); - col4 = 190.0f + (x - 270.0f); - winTexSet(0x10, (Vec){col4, row0, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, white); - // FAKE: copies read only by the dead guards below; they keep two coalesced FPR nodes live across rowC (register order) - q1[0] = row0; - q2[0] = row1; - winTexSet(0x10, (Vec){col4, row1, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, white); + winTexSet(0x10, (Vec){190.0f + (x - 270.0f), 4.0f + (y - 38.0f), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, white); + winTexSet(0x10, (Vec){190.0f + (x - 270.0f), 4.0f + ((y - 38.0f) - 34.0f), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, white); winFontInit(); - winFontSet((Vec){col5 = 200.0f + (x - 270.0f), row2, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, "%s", winZenkakuStr(pouch->maximumHP)); - winFontSet((Vec){col5, rowC, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, "%s", winZenkakuStr(pouch->maximumFP)); + winFontSet((Vec){200.0f + (x - 270.0f), 4.0f + (12.0f + (y - 38.0f)), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, "%s", winZenkakuStr(pouch->maximumHP)); + winFontSet((Vec){200.0f + (x - 270.0f), 4.0f + (12.0f + ((y - 38.0f) - 34.0f)), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, "%s", winZenkakuStr(pouch->maximumFP)); + // the special moves Mario has: a star per move, lit up to the current Star Power if (w->mario.wazaCount > 0) { + f32 spY; + winKirinukiGX(w, 0, 10.0f + x, (20.0f + (130.0f + y)) - 20.0f, 260.0f, 80.0f); winIconInit(); - col6 = 10.0f + (40.0f + x); - nameW3 = 106.0f + y; - winIconSet(ICON_20F, (Vec){col6, nameW3, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white); - cx3 = 70.0f + y; - winIconSet(ICON_197, (Vec){col6, cx3, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white); + iconX = 10.0f + (40.0f + x); + winIconSet(ICON_20F, (Vec){iconX, 106.0f + y, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white); + spY = 70.0f + y; + winIconSet(ICON_197, (Vec){iconX, spY, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white); winFontInit(); - winFontSetWidth((Vec){10.0f + (70.0f + x), 10.0f + cx3, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, 175.0f, msgSearch("msg_menu_mario_special")); + winFontSetWidth((Vec){10.0f + (70.0f + x), 10.0f + spY, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, 175.0f, msgSearch("msg_menu_mario_special")); winIconInit(); - cx4 = 10.0f + (80.0f + x); for (i = 0; i < w->mario.wazaCount; i++) { if (i < pouch->currentSP / 100) { - winIconSet(ICON_1B7 + i, (Vec){cx4 + (f32)(i * 22), nameW3, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white); + winIconSet(ICON_1B7 + i, (Vec){(10.0f + (80.0f + x)) + i * 22, 106.0f + y, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white2); } else { - winIconSet(ICON_1BF, (Vec){cx4 + (f32)(i * 22), nameW3, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white); + winIconSet(ICON_1BF, (Vec){(10.0f + (80.0f + x)) + i * 22, 106.0f + y, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white2); } } } - // FAKE: two dead int guards (gz is 0; folded after register allocation, no code): the first redefines q1/q2 so - // they are not propagated, the second consumes them into y - { - s32 gz = 0; - if (gz != 0) { - q1[0] = -q1[0]; - q2[0] = -q2[0]; - } - } - { - s32 gz = 0; - if (gz != 0) { - y = q1[0] + q2[0]; - } - } + // the collection counters: Star Points, coins, Star Pieces, Shine Sprites, play time left = 10.0f + x; winKirinukiGX(w, 0, left, 10.0f + (20.0f + y), 260.0f, 150.0f); winIconInit(); - rowB2 = 10.0f + (20.0f + x); - winIconSet(ICON_18C, (Vec){rowB2, 10.0f + y, 0.0f}, (Vec){0.62f, 0.62f, 0.62f}, white); - winIconSet(ICON_18B, (Vec){rowB2, 10.0f + (y - 28.0f), 0.0f}, (Vec){0.62f, 0.62f, 0.62f}, white); - winIconSet(ICON_18D, (Vec){rowB2, 10.0f + (y - 56.0f), 0.0f}, (Vec){0.62f, 0.62f, 0.62f}, white); - winIconSet(ICON_102, (Vec){rowB2, 10.0f + (y - 84.0f), 0.0f}, (Vec){0.62f, 0.62f, 0.62f}, white); - winIconSet(ICON_1A2, (Vec){rowB2, 10.0f + (y - 112.0f), 0.0f}, (Vec){0.62f, 0.62f, 0.62f}, white); + iconX = 10.0f + (20.0f + x); + winIconSet(ICON_18C, (Vec){iconX, 10.0f + y, 0.0f}, (Vec){0.62f, 0.62f, 0.62f}, white); + winIconSet(ICON_18B, (Vec){iconX, 10.0f + (y - 28.0f), 0.0f}, (Vec){0.62f, 0.62f, 0.62f}, white); + winIconSet(ICON_18D, (Vec){iconX, 10.0f + (y - 56.0f), 0.0f}, (Vec){0.62f, 0.62f, 0.62f}, white); + winIconSet(ICON_102, (Vec){iconX, 10.0f + (y - 84.0f), 0.0f}, (Vec){0.62f, 0.62f, 0.62f}, white); + winIconSet(ICON_1A2, (Vec){iconX, 10.0f + (y - 112.0f), 0.0f}, (Vec){0.62f, 0.62f, 0.62f}, white); winFontInit(); - col7 = 10.0f + (35.0f + x); - rowA2 = 12.0f + y; - row0b = 10.0f + rowA2; - winFontSetWidth((Vec){col7, row0b, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, 140.0f, msgSearch("msg_menu_mario_num_sp")); - row1b = 10.0f + (rowA2 - 28.0f); - winFontSetWidth((Vec){col7, row1b, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, 140.0f, msgSearch("msg_menu_mario_num_coin")); - row2b = 10.0f + (rowA2 - 56.0f); - winFontSetWidth((Vec){col7, row2b, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, 140.0f, msgSearch("msg_menu_mario_num_hoshi")); - row3 = 10.0f + (rowA2 - 84.0f); - winFontSetWidth((Vec){col7, row3, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, 140.0f, msgSearch("msg_menu_mario_num_super_coin")); - rowA3 = 10.0f + (rowA2 - 112.0f); - winFontSetWidth((Vec){col7, rowA3, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, 125.0f, msgSearch("msg_menu_mario_num_playtime")); - winFontSetR((Vec){numX = 2.0f + (8.0f + (205.0f + x)), row0b, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStr(pouch->starPoints)); - winFontSetR((Vec){numX, row1b, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStr(pouch->coins)); - winFontSetR((Vec){numX, row2b, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStr(pouch->starPieceCount)); - winFontSetR((Vec){numX, row3, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStr(pouch->shineSpriteCount)); - - tsecs = gp->playTime / OS_TIMER_CLOCK; - if (tsecs > 359999) { - hour = 99; - min = 59; - } else { - secs = tsecs; - hour = (u64)secs / 3600; - min = (u64)secs % 3600 / 60; + winFontSetWidth((Vec){10.0f + (35.0f + x), 10.0f + (12.0f + y), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, 140.0f, msgSearch("msg_menu_mario_num_sp")); + winFontSetWidth((Vec){10.0f + (35.0f + x), 10.0f + ((12.0f + y) - 28.0f), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, 140.0f, msgSearch("msg_menu_mario_num_coin")); + winFontSetWidth((Vec){10.0f + (35.0f + x), 10.0f + ((12.0f + y) - 56.0f), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, 140.0f, msgSearch("msg_menu_mario_num_hoshi")); + winFontSetWidth((Vec){10.0f + (35.0f + x), 10.0f + ((12.0f + y) - 84.0f), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, 140.0f, msgSearch("msg_menu_mario_num_super_coin")); + winFontSetWidth((Vec){10.0f + (35.0f + x), 10.0f + ((12.0f + y) - 112.0f), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, 125.0f, msgSearch("msg_menu_mario_num_playtime")); + winFontSetR((Vec){2.0f + (8.0f + (205.0f + x)), 10.0f + (12.0f + y), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStr(pouch->starPoints)); + winFontSetR((Vec){2.0f + (8.0f + (205.0f + x)), 10.0f + ((12.0f + y) - 28.0f), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStr(pouch->coins)); + winFontSetR((Vec){2.0f + (8.0f + (205.0f + x)), 10.0f + ((12.0f + y) - 56.0f), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStr(pouch->starPieceCount)); + winFontSetR((Vec){2.0f + (8.0f + (205.0f + x)), 10.0f + ((12.0f + y) - 84.0f), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStr(pouch->shineSpriteCount)); + { + // capped at 99:59 + u64 tsecs = OSTicksToSeconds(gp->playTime); + if (tsecs > 359999) { + hour = 99; + min = 59; + } else { + secs = tsecs; + hour = tsecs / 3600; + secs %= 3600; + min = secs / 60; + } } - winFontSetR((Vec){2.0f + (2.0f + ((8.0f + (172.0f + x)) - 16.0f)), rowA3, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStrPad(hour, 2)); - winFontSetR((Vec){numX, rowA3, 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStrPad(min, 2)); - + winFontSetR((Vec){2.0f + (2.0f + ((8.0f + (172.0f + x)) - 16.0f)), 10.0f + ((12.0f + y) - 112.0f), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStrPad(hour, 2)); + winFontSetR((Vec){2.0f + (8.0f + (205.0f + x)), 10.0f + ((12.0f + y) - 112.0f), 0.0f}, (Vec){0.9f, 0.9f, 0.9f}, black, "%s", winZenkakuStrPad(min, 2)); winTexInit(*w->res->data); - cx5 = 10.0f + (190.0f + x); for (i = 0; i < 4; i++) { - winTexSet(0x11, (Vec){cx5, 10.0f + (y - (f32)(i * 28)), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, white); + winTexSet(0x11, (Vec){10.0f + (190.0f + x), 10.0f + (y - i * 28), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, white2); } - rowB3 = 220.0f + x; - winTexSet(0x12, (Vec){rowB3, (10.0f + (2.0f + (y - 112.0f))) - 2.0f, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, white); + apX = 220.0f + x; + winTexSet(0x12, (Vec){apX, (10.0f + (2.0f + (y - 112.0f))) - 2.0f, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, white); + // Mario himself animPoseGetAnimPosePtr(w->mario.poseId); anim = animPoseGetAnimDataPtr(w->mario.poseId); if (w->mario.hammerHold == 0) { - animPoseSetLocalTime(w->mario.poseId, (f32)(gp->retraceCount % (s32)anim->loopInfo[2])); + animPoseSetLocalTime(w->mario.poseId, gp->retraceCount % (s32)anim->loopInfo[2]); } animPoseMain(w->mario.poseId); winKageGX(w, (GXColor){0x00, 0x00, 0x00, 0x80}, x - 150.0f, y, 0.0f, 1.0f); @@ -708,22 +657,20 @@ void winMarioDisp(s32 camId, void* param, s32 idx) { winZClear(); animPoseDrawMtx(w->mario.poseId, mtx, 2, 0.0f, 5.0f); + // the special-move list if (w->mario.wazaOpen) { const char* msg = msgSearch("msg_menu_mario_sac_waza"); + char sbuf[0x20]; + winWazaGX(w, 0, x - 270.0f, 160.0f, 270.0f, 254.0f); winFontInit(); - winFontSetEdge((Vec){(x - 270.0f) + (f32)((240 - FontGetMessageWidth(msg)) / 2), 155.0f, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white, msg); - winFontSetEdge((Vec){rowB3 - 270.0f, 155.0f, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white, msgSearch("btl_cost_disp_AP")); - y2 = 10.0f + (left - 270.0f); - x2 = (228.0f + x) - 270.0f; - cx6 = 4.0f + ((17.0f + rowB3) - 270.0f); + winFontSetEdge((Vec){(x - 270.0f) + (240 - FontGetMessageWidth(msg)) / 2, 155.0f, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white, msg); + winFontSetEdge((Vec){apX - 270.0f, 155.0f, 0.0f}, (Vec){0.8f, 0.8f, 0.8f}, white, msgSearch("btl_cost_disp_AP")); for (i = 0; i < w->mario.wazaCount; i++) { - char sbuf[0x20]; - - winFontSetWidth((Vec){y2, (f32)(130 - i * 26), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, 180.0f, msgSearch(superActionTable[i]->name)); + winFontSetWidth((Vec){10.0f + (left - 270.0f), 130 - i * 26, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black2, 180.0f, msgSearch(superActionTable[i]->name)); sprintf(sbuf, "%s", winZenkakuStr(superActionTable[i]->baseSpCost)); - winFontSet((Vec){x2 - (f32)(FontGetMessageWidth(sbuf) / 2), (f32)(130 - i * 26), 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black, sbuf); - winFontSet((Vec){cx6, (f32)(120 - i * 26), 0.0f}, (Vec){0.5f, 0.5f, 0.5f}, black, msgSearch("btl_cost_disp_AP")); + winFontSet((Vec){((228.0f + x) - 270.0f) - FontGetMessageWidth(sbuf) / 2, 130 - i * 26, 0.0f}, (Vec){1.0f, 1.0f, 1.0f}, black2, sbuf); + winFontSet((Vec){4.0f + ((17.0f + apX) - 270.0f), 120 - i * 26, 0.0f}, (Vec){0.5f, 0.5f, 0.5f}, black2, msgSearch("btl_cost_disp_AP")); } } }