# ===========================================================================
# SLICE pmfb3 -- run link100, lane PMFB3
# ===========================================================================
#
# Matched translation units this lane took OFF a host copy. Every row was
# re-derived at its own ROM address on this tree for this lane; nothing here is
# carried over from a prose file. The CMake gate block is R10b in
# port/CMakeLists.txt.
#
# ---- BATCH 1: dScMgSound_c's THIRTEEN LEVEL-2 SUB-DISPATCHERS -------------
#
# WHAT LANE PMFB2 LEFT. Its gate 1 installed host addresses into the two
# LEVEL-1 tables (data_ov006_02142df8, 5 slots; data_ov006_02142e20, 13 slots)
# and retired the two level-1 dispatchers onto their own matched TUs. It said
# in port/slice_pmfb2.txt: "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." This is that work, and it
# closes the class: NO HOST COPY OF A dScMgSound_c DISPATCHER IS LEFT.
#
# THE THIRTEEN ROM BODIES ARE ONE SHAPE, and that is a measurement, not a
# convenience. Read word for word out of extracted/overlays/overlay_0006.bin at
# ov006 base 0x020bfec0 for this lane (runs/link100/out/PMFB3/
# romstride_pmfb3.txt): 0x0211b590, 0x0211b398, 0x0211b17c, 0x0211af60,
# 0x0211ad44, 0x0211abdc, 0x0211aa44, 0x0211a7ac, 0x0211a648, 0x0211a4b0,
# 0x0211a2c4, 0x0211a0d8 and 0x02119eec are BYTE IDENTICAL over their first
# nineteen words and differ only in the TWENTIETH, the literal-pool word that
# names their table. All thirteen pool words agree with the destination
# __sinit_ov006_02132970 fills (runs/link100/out/PMFB3/pool_words.txt), which
# is what says which table belongs to which body without reading a name:
#     0211b590 word20 @ 0211b5dc = 02142d38     0211a648 word20 @ 0211a694 = 02142d68
#     0211b398 word20 @ 0211b3e4 = 02142d50     0211a4b0 word20 @ 0211a4fc = 02142d98
#     0211b17c word20 @ 0211b1c8 = 02142d80     0211a2c4 word20 @ 0211a310 = 02142cc0
#     0211af60 word20 @ 0211afac = 02142dc8     0211a0d8 word20 @ 0211a124 = 02142d08
#     0211ad44 word20 @ 0211ad90 = 02142de0     02119eec word20 @ 02119f38 = 02142db0
#     0211abdc word20 @ 0211ac28 = 02142cd8
#     0211aa44 word20 @ 0211aa90 = 02142cf0
#     0211a7ac word20 @ 0211a7f8 = 02142d20
#
# THE STRIDE, BOTH SIDES.
#   ROM      `add ip, r3, r2, lsl #3` in every one of the thirteen  -> 8 bytes
#   EMITTED  each matched TU compiled under the port's own flags with a /FAsc
#            listing (runs/link100/out/PMFB3/emit_subdisp.txt and listings/):
#            _data_ov006_XXXXXXXX[eax*8] and [eax*8+4]               -> 8 bytes
# so ROM 8 == emitted 8 on all thirteen.
#
# NO /Zp4 ON ANY OF THE THIRTEEN, and that is measured rather than assumed.
# Lane PMFB1's finding is that MSVC gives any struct CONTAINING a
# pointer-to-member an alignment of eight, which rounds a twenty-byte record up
# to twenty-four and makes every state after state 0 read the wrong record,
# silently. These thirteen records are NOT that shape: each table is an array of
# the BARE pointer to member, which is eight bytes with the option and eight
# without. Every one of the thirteen was compiled both ways for this lane and
# the two listings are IDENTICAL, zero diff lines, not merely equal in the
# operand. Block R10a's own rule for that case is to leave the option off, and
# this block follows it.
#
# THE THIRTY-NINE SOURCE PAIRS ALL READ {code, 0} in the overlay image at the
# addresses src/__sinit_ov006_02132970.c assigns each slot from -- read out of
# the cartridge, not off a seat's runtime assertion. All thirty-nine are
# WHOLE-PAIR copies (`data_ov006_TAB[i] = data_ov006_SRC;`); there is not one
# field-form fill among them, which is the condition that lets the installer
# prove what it writes. The thirty-nine code words are DISTINCT and every one
# lands inside dScMgSound_c's own code block 0x02119904..0x0211cb70, which is
# the check that says these tables are this class's and not the neighbouring
# dScMgTeresa_c's (the trap the head of MgSound_StateDispatch.cpp records).
#
# A FACE IS NEEDED HERE AND WAS NOT NEEDED AT LEVEL 1, and the difference is in
# the SOURCE, not in the data. The two level-1 TUs open-code the mwcc member
# pointer as two plain ints and call `((void(*)(void*,int))fn)(obj,i)`, which
# MSVC emits as `push esi / push edx / call eax / add esp,8` -- a cdecl call
# with the receiver PUSHED, which is what the host bodies already are. The
# thirteen level-2 TUs spell a REAL pointer to member,
# `(((C *)o)->*data_ov006_XXXXXXXX[idx])(i)`, and MSVC emits
#     push  ecx                                  the one argument, i
#     mov   ecx, _data_ov006_XXXXXXXX[eax*8+4]   the adjustment word
#     mov   eax, _data_ov006_XXXXXXXX[eax*8]     the code word
#     add   ecx, edx                             this
#     call  eax
#     pop   ebp / ret 0                      NO add esp,4: the CALLEE cleans
# -- a __thiscall indirect. So the thirty-nine installed words are
# `void __fastcall snd2_func_ov006_XXXXXXXX(void *self, void *dead_edx, int i)`
# faces, in port/unmatched/MgSound_StateDispatch.cpp, the file that owns the
# tables. Three of them forward to a body the ROM gives no argument
# (func_ov006_0211b3e8, _0211ac2c, _0211a698: empty bodies in src, declared and
# called with no argument, which is the shape port/tools/aritycheck.py checks).
#
# ONE /alternatename, in that same seat file. Twelve of the thirteen matched TUs
# declare their table INSIDE their own extern "C" block and come in as the plain
# C name the ov006 mount defines. src/actors/dScMgSound_c.cpp declares
# `extern PMF data_ov006_02142cc0[];` at namespace scope, so MSVC spells the
# reference ?data_ov006_02142cc0@@3PAP8C@@AEXH@ZA -- read off that TU's own
# /FAsc listing, not guessed -- and without the directive the slice does not
# link. hal/pmfc_aliases.cpp's guard argument applies unchanged: the LHS is a
# C++ mangling nothing in the tree defines, so it cannot be silently defeated.
#
# WHAT ELSE THE SEAT CHANGED, both inside this lane's own file:
#   port_mg_sound_call1 and its switch sound_try_1 are DELETED. Nothing calls
#     them once the thirteen host copies are gone, and the fifteen tables now
#     hold host addresses that the installer verified against the ROM's own
#     words before writing. The "unknown code word" counter that switch fed is
#     now structurally zero, which is said out loud in the file: the defect it
#     used to convict at frame time is convicted at boot instead, by an abort.
#   snd1_state1_0211bc8c, a plain cdecl counting wrapper, goes into LEVEL-1
#     slot 1 in place of the bare body. That counter has read zero since lane
#     PMFB2 put func_ov006_0211bc8c straight into the table, while
#     hal/scene_mg_boombox.cpp went on printing it as the witness that a tap
#     produced an execution. Same convention in and out, same two arguments,
#     same body called.
src/actors/dScMgSound_c.cpp
#
# ---- BATCH 2: SoundObject::Behavior ---------------------------------------
#
# THE ROW LANE PMFB2 NAMED AND DID NOT TAKE: "the host copy carries a PORT-ONLY
# out-of-range refusal the matched TU does not have ... 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."
#
# WHERE THE REFUSAL LIVES NOW: port_sound_object_behavior, in the seat file
# port/unmatched/SoundObject_Behavior.cpp, which is the port's slot-6 body. The
# vtable fill in hal/actor_classes_ccm.cpp already went through a __fastcall
# face for every method of this class (sob_init, sob_d1, sob_d0 and sob_behavior
# are all the same shape and always were); the one hunk outside this lane's own
# files is that face's target, `port_sound_object_behavior` in place of
# `_ZN12daSoundObj_c8BehaviorEv`, plus its declaration. The refusal is unchanged
# text: the same param test, the same message, the same MarkForDestruction, the
# same return 1. It is now AHEAD of the matched TU rather than instead of it.
#
# WHY IT MUST STAY SOMEWHERE, and this lane read both sides of the ROM's own
# off-by-one to say why (runs/link100/out/PMFB3/rom_soundobj.txt):
#   InitResources (src/game/actors/d_a_sound_obj.cpp) returns 0 on
#     `param > 7`, so param 7 is ACCEPTED, and it then indexes a 0xc-stride
#     tuning table at data_ov002_0210c080 with it.
#   That tuning table has SEVEN rows. Row 7 at 0x0210c0d4 reads
#     00000000 / 0210c048 / 020f95e0 -- a pointer and a code address, the next
#     thing in the image, not a tuning row.
#   The dispatch table has seven cells, 0x0211110c..0x02111143, and the ov002
#     mount publishes data_ov002_02111144 and data_ov002_02111148 as the next
#     two symbols, so cell 7 is eight bytes of another symbol's storage.
# A param-7 emitter runs off the end of both on the cartridge as well. The
# refusal is the port declining to reproduce a latent ROM defect; it is not a
# fix for anything the port broke, and it is the only port-only behaviour left
# in the class.
#
# NOT PROVEN BY THIS LANE: which level row, if any, spawns actor 359 with param
# 7. The battery's 51 level rows and 36 scene rows all pass with the refusal in
# place and never printed its message, which says the path is not on any of
# them; it does not say no level data anywhere sets the param. Naming the row
# needs a sweep of the level object tables, which is a different lane's read.
#
# THE STRIDE, BOTH SIDES.
#   ROM      0x020f9510  add r3, r1, r0, lsl #3                       -> 8
#            (and the argument is `add r1, r4, #0xdc`, one argument, with
#            `this` in r0 at the blx: the pool word at 0x020f95d0 is 0211110c)
#   EMITTED  ?data_ov002_0211110c@@3PAP8C@@AEHPAX@ZA[eax*8] and [eax*8+4]
#            (runs/link100/out/PMFB3/listings/SoundObject_Behavior_nozp.asm)
# No /Zp4: the table is an array of the bare pointer to member, not a struct
# containing one.
#
# THE SEVEN SOURCE PAIRS all read {code, 0} in extracted/overlays/
# overlay_0002.bin at the addresses __sinit_ov002_02107f88 assigns them from
# (0x0210c010..0x0210c040), all seven are whole-pair copies, and the five
# distinct code words are the five the seat already installs.
#
# THE FACES ARE NEW AND THE SEAT IS NOT. port_sound_object_states_seat has
# rewritten these seven cells since gate 190, but with plain cdecl bodies,
# because the dispatcher reading them was this file's own host copy. The matched
# TU dispatches a real pointer to member -- `push edi / mov ecx, tab[eax*8+4] /
# mov eax, tab[eax*8] / add ecx, esi / call eax` with NO `add esp, 4` after it,
# so receiver in ecx, one argument on the stack, callee cleanup. The seven cells
# now hold five one-argument __fastcall faces (the ROM parks 0x020f9468 in three
# of them).
#
# ONE /alternatename, in the seat file: the matched TU declares its table
# outside its extern "C" block, so it comes in as
# ?data_ov002_0211110c@@3PAP8C@@AEHPAX@ZA while the ov002 mount defines the
# plain C name. Read off the TU's own listing.
#
# THE GUESS MARKER IS NOT A BLOCKER HERE, and it was checked rather than
# assumed. src/game/actors/d_a_sound_obj.cpp carries "recovered from vtable
# slot identity", but port/tools/inferred_stub_adjudicated.txt:2313 already
# rules it REAL_DECOMP against the ROM: addr 0x020f94fc size 0xe4, match.py
# 2004/b56 strict-reloc MATCH, every non-relocated word identical. The guard
# reports the seat, it does not refuse it.
src/game/actors/d_a_sound_obj.cpp
#
# ---- BATCH 3: the dScMgBase framework set, the THREE TABLE-BASED rows ------
#
# LANE PMFC2 CALLED THE NINE-ROW FRAMEWORK SET "the highest-value remaining
# work in the family". This lane measured all nine and took the three that a
# BOOT INSTALLER can reach. The other six are named at the end of this section
# with the measurement that stops them, not with "no time".
#
# THE ONE FACT THAT COVERS ALL NINE, and it is the opposite of batch 1's:
# EVERY ONE OF THE NINE COMPILES ITS DISPATCH TO A TAIL JUMP. Read off each
# TU's own /FAsc listing under the port's own flags
# (runs/link100/out/PMFB3/listings/func_ov004_020add88.asm and its eight
# siblings): `jmp eax` or `jmp edx`, with pop ebp (and pop esi where there is
# one) executed FIRST, so the stack at the jump is the forwarder's own entry
# frame -- return address at [esp], the single argument at [esp+4]. A tail jump
# hands the callee that frame, so the callee finds the receiver exactly where
# its one declared cdecl argument lives and returns straight to the forwarder's
# caller. So a PLAIN CDECL BODY is correct in the code word for every row in
# this batch and NO FACE IS WRITTEN ANYWHERE IN IT. That is lane PMFB1's FREE-row
# rule (slice_pmfb2.txt records it for src/func_ov002_020efa54.cpp), re-measured
# per row here rather than carried.
#
# THE THREE TAKEN.
#
#   func_ov004_020add88  table data_ov004_020beb98, 2 cells
#   func_ov004_020adf2c  table data_ov004_020beb88, 2 cells
#     ROM stride 8: `add r3, r2, r1, lsl #3` at 0x020add98 and 0x020adf3c, on
#       the literal-pool words 0x020addc8 = 020beb98 and 0x020adf6c = 020beb88.
#       The index is a SHORT at +0x1e (`ldrsh r1, [r0, #0x1e]`), which is what
#       both src structs spell.
#     Emitted stride 8: [edx*8] and [edx*8+4] in both listings.
#     Source pairs, out of extracted/overlays/overlay_0004.bin at the addresses
#       src/__sinit_ov004_020b948c.c assigns from, all whole-pair copies
#       (runs/link100/out/PMFB3/rom_framework.txt):
#         020beb88[0] <- 020bbf4c  code=020adeb0  adjust=0
#         020beb88[1] <- 020bbf5c  code=020addcc  adjust=0
#         020beb98[0] <- 020bbf54  code=020adcc8  adjust=0
#         020beb98[1] <- 020bbf64  code=020adc80  adjust=0
#       -- the same four addresses port_mg_call0's own mg_try_ov004_0 arm has
#       always routed, which is the framework half the header of
#       unmatched/MgBase_StateDispatch.cpp calls "paid once for all thirty".
#     Two /alternatename directives, in that same file: both TUs declare their
#       table at namespace scope, so they come in as
#       ?data_ov004_020beb88@@3PAP8C@@AEXXZA and ...beb98..., read off the
#       listings. Neither LHS is defined anywhere in the tree.
#
#   func_ov006_021050bc  table data_ov006_02142860, 5 cells
#     ROM stride 8: `add r3, r2, r1, lsl #3` at 0x021050e4 on the pool word
#       0x02105114 = 02142860; the guard byte is +0x4674 and the index +0x4675,
#       which is what the src spells.
#     Emitted stride 8: [eax*8] and [eax*8+4], and the listing is IDENTICAL
#       with and without /Zp4 even though this record IS a struct containing a
#       pointer to member (`struct Entry { PMF pmf; }`) -- eight either way, so
#       the option is not claimed on it. That is the PMFB1 lever checked and
#       found inert here rather than assumed either way.
#     Source pairs, out of overlay_0006.bin at __sinit_ov006_02131fa4's own
#       addresses, all whole-pair copies:
#         [0] <- 0213dcd4 code=0210508c/0   [3] <- 0213dca4 code=02104ecc/0
#         [1] <- 0213dcc4 code=0210500c/0   [4] <- 0213dcb4 code=02104ec8/0
#         [2] <- 0213dc7c code=02104fb4/0
#     No alias: the TU declares its table INSIDE its extern "C" block.
#     The other five tables in dScMgPanel_c are untouched and still route
#       through port_mg_panel_call0.
#
# TWO NEW SEATS, and one hunk outside this lane's own files. The installers are
# port_mg_framework_states_seat (unmatched/MgBase_StateDispatch.cpp, the file
# that owns port_mg_call0) and port_mg_panel_states_seat
# (unmatched/MgPanel_StateDispatch.cpp, the file that owned the retired host
# copy). Both are the port_pushblock_states_seat shape: compare the cell against
# the ROM's own code word and a zero adjustment, abort loudly on either
# mismatch, then write the host body. The hunk outside is hal/scene_mg.cpp --
# two declarations and two calls beside the port_mg_sound_states_seat() lane
# PMFB2 added, in the one function in the tree that runs the ov004 and ov006
# constructors, and after them.
#
# THE SIX NOT TAKEN, with the measurement that stops each:
#   func_ov004_020b31b4  reads the pair at self+0x08
#   func_ov004_020b321c  reads the pair at self+0x00
#   func_ov004_020b52fc  reads the pair at self+0x00
#   _ZN10dMgState_c6RenderEv  reads the pair at self+0x10
#   _ZN10dMgState_c8BehaviorEv  reads the pair at self+0x08
#   func_ov006_020cf758  reads the pair at self+0x00
# None of the six reads a TABLE. Each reads the eight-byte pair out of an
# OBJECT FIELD, so there is no storage a boot installer can verify and rewrite:
# what has to change is the WRITER. The writers are host copies, and they store
# the ROM's own DS code word today --
# unmatched/MgBase_StateSetter.cpp's _ZN10dMgState_c8SetStateEi does
# `self->pmf0 = g_table[self->index]` out of the twenty data_ov004_020bc9xx pair
# globals and then hands that DS word to port_mg_call0, and func_ov004_020b3278
# fills self+0x08 the same way, with dScMgMemory2_c and dScMgTrampoline_c
# filling their own +0x00 elsewhere. Turning those four writers around means
# each one installs a host address AND stops dispatching through the switch
# itself, per writer, with its own abort-on-mismatch evidence: four writers in
# four files is a lane, not a row, and half-doing it would leave a writer
# handing a host address to a switch that only knows DS ones. Named here so the
# next lane starts from the measurement rather than from the census.
src/func_ov004_020add88.cpp
src/func_ov004_020adf2c.cpp
src/actors/dScMgPanel_c.cpp
