# ===========================================================================
# SLICE pmfb2 -- run link100, lane PMFB2
# ===========================================================================
#
# Matched translation units this lane took OFF a host copy. Every row was
# re-derived at its own ROM address for this lane; nothing here is carried
# over from a prose file. The CMake gate block is R10a in port/CMakeLists.txt.
#
# ---- BATCH 1: dScMgSound_c's two LEVEL-1 pointer-to-member dispatchers -----
#
# THE WALL, and what took it down. Both TUs open-code the mwcc member pointer
# as two plain ints and do the decode themselves:
#     int adj = e->b;  char *obj = c + (adj >> 1);
#     fn = (adj & 1) ? *(int *)(*(int *)obj + e->a) : e->a;
#     ((void (*)(void *, int))fn)(obj, i);
# so neither a link error nor a `::*` source sweep ever saw them (lane PMFC2's
# third shape). Nothing about the SOURCE was ever the problem. The problem was
# the DATA: the code word held a DS address, because
# __sinit_ov006_02132970 copies the ov006 image's own pairs into the
# destination storage. port/unmatched/MgSound_StateDispatch.cpp stood in with
# a call-time address switch, which cannot retire, because retiring the host
# copy takes the switch with it. port_mg_sound_states_seat, added to that same
# file in this commit and called once from hal/scene_mg.cpp right after the
# ov006 constructors run, installs the eighteen host addresses at boot instead.
#
# THE STRIDE, re-derived out of extracted/overlays/overlay_0006.bin at ov006's
# own base for this lane (runs/link100/out/PMFB2/rom_pairs.txt):
#     func_ov006_0211b954  0x0211b96c  add r3, r4, r0, lsl #3   -> 8 bytes
#     func_ov006_0211b5e0  0x0211b60c  add r3, r4, r0, lsl #3   -> 8 bytes
# and the emitted stride, read off a /FAsc listing of each TU under the port's
# own flags (runs/link100/out/PMFB2/listings/):
#     _data_ov006_02142df8[ebx*8]  and  _data_ov006_02142e20[ebx*8]
# so ROM 8 == emitted 8 on both. THE /Zp4 IN THE GATE BLOCK IS A NO-OP HERE
# AND IS ON THE SET ANYWAY: the two listings are byte-identical with and
# without it (only the TITLE line differs), because these records are two
# plain ints and not the twenty-byte struct-containing-a-pointer-to-member
# that forced lane PMFB1 to pack. It is carried so a later header change
# cannot move the stride silently, which is exactly the defect PMFB1 found.
#
# THE EIGHTEEN ADJUST WORDS ALL READ ZERO in the image, at the eighteen source
# addresses the matched sinit assigns from, so `this` is unadjusted and the
# ROM takes the ldreq arm. NO FACE IS NEEDED: MSVC emits the dispatch as
# `push esi / push edx / call eax / add esp,8`, a plain cdecl call with the
# receiver PUSHED, which is the signature the eighteen host bodies already
# have. (The family-C CALL SHAPE rows are the opposite case and do need one.)
#
# NOT TAKEN HERE: the thirteen level-2 tables the sub-dispatchers read. Their
# code words are still DS addresses and their host copies still route through
# port_mg_sound_call1. Installing them is the same shape one level down and is
# the next lane's work.
src/actors/dScMgSound_c.cpp
#
# ---- BATCH 2: Bird::Render and Flag::Render (lane FACEF's two proposals) ---
#
# FACEF closed with these two NOT TAKEN and a stated precondition: "retiring it
# needs a ROM-ordered ModelAnim table, which is the opposite of what every MSVC
# caller of the same object needs". Lane SLOT5F built that table. The fill in
# hal/cxxname_bridge.cpp is now
#     _ZTV9ModelAnim[5] = ma2_render   _ZTV9ModelAnim[6] = ma2_virtual18
# with slots 0 and 1 carrying the ROM's D1/D0 pair separately instead of MSVC's
# fold, which is the numbering include/ModelAnim.h annotates on the ROM table.
# So the precondition is met, and nothing had to be dual-filled to meet it.
#
# THE ROM, re-read at both addresses for this lane out of
# extracted/overlays/overlay_0009.bin at ov009 base 0x021111a0
# (runs/link100/out/PMFB2/rom_renders.txt). Ten instructions, identical in both:
#     02111870  _ZN4Bird6RenderEv  kind:function(arm,size=0x28)
#     0211211c  _ZN10daMcFlag_c6RenderEv  kind:function(arm,size=0x28)
#         ldr r2,[r0,#0xd4]!    pre-indexed WITH WRITEBACK: the receiver at the
#                               blx is the ModelAnim sub-object, not the actor
#         mov r1,#0             the one argument
#         ldr r2,[r2,#0x14]     vtable slot 5
#         blx r2  /  mov r0,#1  the return value the caller discards
# include/Bird.h:25 and include/Flag.h:17 both put mModelAnim at 0x0d4, which is
# the offset the ROM writes back.
#
# THE FACE, in port/hal/except_faces.cpp (this lane's own section). Both matched
# TUs recovered as real C++ methods, so they define ?Render@Bird@@QAEHXZ while
# hal/actor_classes.cpp:1334 and :1506 call _ZN4Bird6RenderEv and
# _ZN10daMcFlag_c6RenderEv at C linkage. One cdecl line each; no fill site changes.
#
# CONVENTION: MSVC compiles the matched TU's `b->m(0)` as a __thiscall indirect
# call (receiver in ecx, the 0 pushed, callee cleans four) and the host slot
# holds ma2_render, declared __fastcall(void *self, void *unused, const void *s).
# Same receiver register, same stack argument, same cleanup -- the rule lane
# EXCEPT measured and lane FACEF re-measured.
src/_ZN4Bird6RenderEv.cpp
src/game/actors/d_a_mc_flag.cpp
#
# ---- BATCH 3: family-C CALL SHAPE rows over a table that already has an ----
# ---- installing seat                                                    ----
#
# Lane PMFC2 measured 120 CALL SHAPE rows in family C and found that only
# ELEVEN of them read a table that already has a seat writing host addresses
# into it. That set was RE-DERIVED on this tree for this lane
# (runs/link100/out/PMFB2/seatcover2.py, because lanes FACEF and PMFB1 landed
# after PMFC2 measured) and came back as the same eleven. Five of them are
# below; the other six are named at the end of this section with the reason.
#
# WHY THESE ROWS WERE HOSTED, and it is one thing, not eleven. Each matched TU
# dispatches a real pointer-to-member, and MSVC emits that as
#
#     mov ecx, <table>[i*8+4]      the adjust word
#     mov eax, <table>[i*8]        the code word
#     add ecx, <this>
#     call eax
#
# -- `call <reg>` with the receiver in ECX and NOTHING pushed. The state bodies
# the seats install are plain cdecl and read the receiver off the STACK, so the
# code word could not hold one of them and the dispatcher had to be host-copied
# instead. The repair is a __fastcall face per state body, written into the code
# word by the seat that owns the table: __fastcall takes its first argument in
# ecx, ignores edx, and cleans the same stack the __thiscall dispatch cleans.
# NO ROM DATA CHANGES SHAPE and no fill site moves.
#
# EVERY ROW'S STRIDE WAS RE-DERIVED BOTH WAYS, because lane PMFB1 found that
# PMFC2's width_ev column records the operand SCALE and not the product with
# the LEA that feeds it, and that MSVC gives any struct CONTAINING a
# pointer-to-member eight-byte alignment. ROM strides come from the overlay
# image at each row's own address; emitted strides come from a /FAsc listing of
# the matched TU under the port's own flags
# (runs/link100/out/PMFB2/listings/, emit_familyc.py):
#
#   row                            ROM stride                     emitted
#   _ZN16dPathLiftActor_c12BaseBehaviorEv   20  mla r0,r1,#0x14 @020efab4  lea [eax+eax*4] then [eax*4+8]  = 20*i+8   /Zp4
#   _ZN7da1up_c8BehaviorEv   8  add r3,r1,r0,lsl#3 @020b0138  [eax*8]                       = 8*i
#   _ZN4Coin8BehaviorEv             8  add r3,r1,r0,lsl#3 @020b2410  [eax*8]                       = 8*i
#   _ZN9PowerStar8BehaviorEv        8  add r3,r1,r0,lsl#3 @020eb164  [eax*8]                       = 8*i
#   _ZN7daPkn_c8BehaviorEv    8  add r3,r0,r4,lsl#3 @0212fde0  [esi*8]                       = 8*i
#
# PathLift is the only one of the five whose record is a STRUCT CONTAINING a
# pointer-to-member ({char pad[8]; PLFn fn; char tail[4]}), so it is the only
# one that needs the /Zp4: without it the same listing emits
# lea [eax+eax*2] then [eax*8], which is 24 against the ROM's 20 -- exactly
# PMFB1's defect, and it would have been silent, because every one of these
# machines starts in state 0.
#
# EVERY ROW'S ADJUST WORDS WERE READ OUT OF THE OVERLAY IMAGE at the addresses
# each table's own MATCHED sinit assigns from, not off a seat's runtime
# assertion (runs/link100/out/PMFB2/rom_pairs_familyc.txt and rom_pairs2.txt):
#   0210af2c  6 pairs  0x02109740..0x02109768   all {code, 0}
#   0210dc00 14 pairs  0x02108300..0x02108368   all {code, 0}
#   0210dc70  9 pairs  0x02108730..0x02108770   all {code, 0}
#   021109d8 14 pairs  0x0210a990..0x0210a9f8   all {code, 0}
#   02130e80  9 pairs  0x02130ba4..0x02130be4   all {code, 0}
# so `this` is never adjusted and every ROM dispatch takes its ldreq arm.
#
# ONE ROW OF THIS BATCH DEFINES ITS OWN C NAME and needs no face for its own
# symbol (PathLift; so do the two ov006 rows of batch 1). FOUR recovered as
# real C++ methods and take one cdecl line each in port/hal/except_faces.cpp:
# ?Behavior@Coin@@QAEHXZ, ?Behavior@da1up_c@@QAEHXZ,
# ?Behavior@PowerStar@@QAEHXZ, ?Behavior@daPkn_c@@QAEHXZ.
#
# THREE NEED AN /alternatename, because the matched TU declares its table
# OUTSIDE its extern "C" block and so names it at C++ linkage while the mount
# defines the plain C name. Each directive lives in the seat file that owns
# that table (the hal/bob_enemy_bridges.cpp precedent), and in each the LHS is
# never DEFINED anywhere, which is alternatename_guard's rule:
#   ?data_ov002_0210dc70@@3PAP8C@@AEXXZA    = _data_ov002_0210dc70
#   ?data_ov002_021109d8@@3PAP8C@@AEXXZA    = _data_ov002_021109d8
#   ?data_ov084_02130e80@@3PAP8Cls@@AEXXZA  = _data_ov084_02130e80
# PathLift's and OneUpMushroom's TUs declare theirs INSIDE extern "C" and come
# in as the plain C name, so they need nothing.
#
# ONE ROW ONLY GETS A FACE ON HALF ITS TABLE. data_ov002_0210af2c is read by
# TWO dispatchers: src/func_ov002_020efa54.cpp takes the ENTER pair at
# record+0 and _ZN16dPathLiftActor_c12BaseBehaviorEv takes the TICK pair at record+8.
# PMFB1 seated the first as a FREE row because MSVC compiles it as a TAIL JUMP,
# and a tail jump hands the callee the forwarder's own cdecl frame, so a plain
# cdecl body is correct there. Only the three TICK words change.
#
# THE SIX NOT TAKEN, each with its own reason and not with "no time":
#   _ZN12daSoundObj_c8BehaviorEv (data_ov002_0211110c). The host copy carries a
#     PORT-ONLY out-of-range refusal the matched TU does not have: actor param
#     7 passes InitResources' own `> 7` gate and has no cell in a seven-cell
#     table, and the host copy names it, destroys the emitter and returns
#     rather than dispatching off the end of the mount. Retiring the copy
#     turns that into an out-of-bounds read of ov002's storage. The row is
#     otherwise ready (stride 8 both sides, seven pairs all {code, 0}, the
#     alias spelled) and it wants the guard moved into the seat first.
#   (the Enemy pair moved to batch 4 below once its second listing was read)
#   func_ov002_020f2dd4, func_ov002_020f37a0, func_ov002_020f5990
#     (data_ov002_02110ebc, 02110e4c, 02110e7c). Their host copies are in
#     hal/cutscene_states_link100.cpp while the seat that installs their tables
#     is in hal/intro_kuppa_dispatch.cpp, and their tables are filled FIELD BY
#     FIELD by __sinit_ov002_02107370 (`[i].x =`, `[i].y =`) rather than by the
#     whole-pair copy every other row uses, so the adjust evidence is a
#     different read. They are also NESTED: cell 2 of 02110e4c is
#     func_ov002_020f3310, itself a dispatcher over 02110e24, and cell 3 of
#     02110e7c is func_ov002_020f3d98 over 02110e34. Three tables, two files
#     and a nest is a lane, not a row.
src/_ZN16dPathLiftActor_c12BaseBehaviorEv.cpp
src/actors/da1up_c.cpp
src/_ZN4Coin8BehaviorEv.cpp
src/_ZN9PowerStar8BehaviorEv.cpp
# QUARANTINED at the main->port sync (origin/main 9c7f38a24): main consolidated ov084's
# PiranhaPlant bodies into this one TU, and the TU carries func_ov084_0212f204, whose
# zero-argument _ZN8dActor_c13ClosestPlayerEv() call closestplayer_guard refuses (thiscall
# with no receiver faults on null this + 0x5c). The port already hosts that function in
# port/unmatched/Actor_ClosestPlayer_OverlayReaders.cpp, which the raw TU would now
# duplicate. Restore this row once the host copy covers the whole consolidated TU.
#src/actors/daPkn_c.cpp
#
# ---- BATCH 4: the Enemy death / enter-death pair ---------------------------
#
# The two rows batch 3 deferred, taken once the second listing was read. Both
# dispatches PUSH arguments, so their faces are not the zero-argument shape;
# each face's arity comes from that row's OWN listing and from nowhere else,
# which is the standing wrong-arity trap.
#
#   _ZN12dEnemyBase_c11UpdateDeathER10dBgCh_Actr  table data_ov002_0210dbc0
#       ROM  0x020ae6e0  add r3, r1, r0, lsl #3           stride 8
#       emit ?data_ov002_0210dbc0@@3PAP8Enemy@@AEHAAUWithMeshClsn@@@ZA[eax*8-8]
#            with `push DWORD PTR _clsn$[ebp]` before the call: ONE argument
#       face int __fastcall (void *self, void *dead_edx, void *clsn)
#   func_ov002_020aea30                     table data_ov002_0210db80
#       ROM  0x020aea70  add lr, r3, r0, lsl #3           stride 8
#       emit ?data_ov002_0210db80@@3PAP8C@@AEXHH@ZA[edx*8-8]
#            with `push _b$` and `push _a$` before the call: TWO arguments
#       face void __fastcall (void *self, void *dead_edx, int a, int b)
#
# The -8 / -4 displacements are the ROM's own index-1 folded into the operand.
# Neither record is a struct containing a pointer-to-member, so neither is on
# the /Zp4 list; both emit 8 with and without it.
#
# ALL SIXTEEN SOURCE PAIRS (0x02108140..0x021081b8) read {code, 0} in
# extracted/overlays/overlay_0002.bin, so `this` is never adjusted.
#
# ONE SEAT COVERS BOTH ROWS and writes FOUR places per index: the eight ROM
# statics of each table plus each bss copy. All four take the face, because
# leaving the statics on the raw body would let a second run of the sinit
# reinstate the wrong convention.
#
# ALIASES: the death table's directive already exists in
# hal/bob_enemy_bridges.cpp:66; the enter table's is new and lives in the seat
# file. Both TUs define their own Itanium C name, so neither needs a method
# face.
#
# src/func_ov002_020aea30.cpp is a //cpp-marked .c -- `typedef void (C::*PMF)
# (int, int);` is not C -- and is given LANGUAGE CXX in CMake block R10a, the
# same treatment the tree gives every other //cpp-marked .c it compiles.
src/_ZN12dEnemyBase_c11UpdateDeathER10dBgCh_Actr.cpp
src/func_ov002_020aea30.cpp
