﻿cmake_minimum_required(VERSION 3.16)
project(sm64ds-port C CXX)
option(HANDHELD "Controller-first front end with fullscreen startup" OFF)
if(HANDHELD)
    add_compile_definitions(SM64DS_HANDHELD=1)
endif()
# Link the static CRT so shipped exes never depend on the VC++ redist (CMP0091).
# Release 0.1.6 shipped dynamically linked because nothing pinned this and CMake
# defaults to the DLL runtime, so a player without the redist could not start the
# game at all, and that failure produces no crash dump and never reaches intake.
# This must stay GLOBAL and stay above the targets: a per-target property on the
# shipped exe alone would leave the test harnesses on the dynamic default, and a
# harness linked differently from the shipped artifact resolves addresses that do
# not match what players run. The generator expression keeps the debug CRT for
# Debug builds, so heap and iterator assertions still fire while chasing
# allocator bugs; plain "MultiThreaded" would silently link the release CRT there.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MAP")
add_compile_options(/Oy-)

# THE mwcc POINTER-TO-MEMBER WIDTH, run link100 lane PMF.
#
# mwccarm's pointer-to-member-function is always the EIGHT-byte {code,
# this-adjust} pair the ROM's five-instruction dispatch reads (the sequence is
# disassembled verbatim in unmatched/MgBase_StateDispatch.cpp section 1). MSVC's
# default "best case" representation is not, and it is wrong in TWO OPPOSITE
# DIRECTIONS at once, which is why no single narrowing ever fixed it: FOUR bytes
# for a complete single-inheritance class, SIXTEEN for a class that is only ever
# forward-declared.
#
# MEASURED on this box's compiler (cl 19.44.35228 for x86), not inherited:
#
#   representation             none  /vms  /vmm  /vmv  /vmg  /vmg+/vmm   ROM
#   PMF complete single-inh       4     4     4     4    16          8     8
#   PMF complete multiple-inh     8     8     8     8    16          8     8
#   PMF complete + vtable         4     4     4     4    16          8     8
#   PMF forward-declared only    16    16    16    16    16          8     8
#   PMD complete single-inh       4     4     4     4    12          4     4
#   PMD forward-declared only    12    12    12    12    12          4     4
#
# READ THE /vmm COLUMN. ON ITS OWN THE FLAG IS INERT -- every entry under it is
# the default entry. /vms, /vmm and /vmv only choose the worst case that /vmg's
# general representation has to cover, so the PAIR is what lands, and it lands
# every pointer-to-member on the ROM's own width, data members included. /vmg
# alone is worse than nothing: it takes everything to sixteen.
#
# The FIELD ORDER agrees too, checked by dumping a formed pointer: word 0 is the
# code address and word 1 the this-adjust, which is `struct { unsigned fn; int
# delta; }` -- the shape every seat in port/ already hand-declares.
#
# THIS SUPERSEDES R8, R9 AND W6, AND IT REVERSES THE RULING THEY CARRY. Those
# three blocks below set the same pair per source file, twenty-eight files
# between them, each with its own measured before/after, and R9 states the rule
# as "PER-SOURCE, NEVER GLOBAL" on the grounds that "a TU that already agrees
# with MSVC's default would silently change layout under a blanket flag".
#
# The measurement is right and the conclusion inverts once the ROM is the
# reference rather than the host. A TU THAT AGREES WITH MSVC'S DEFAULT DISAGREES
# WITH THE ROM: four bytes where the ROM lays down eight, every field after the
# pointer shifted. R8's own text says as much -- "THE SAME OPTION IS THE FIX FOR
# THE OTHER TWENTY-ONE TUs with this shape" -- and each wave since has spent a
# lane paying for a few more of them one before/after at a time. R9's twelve
# INERT rows are that cost made visible: options set on TUs nothing references
# yet, as traps disarmed ahead of a lane.
#
# AND THE HAZARD R9 NAMES IS THE PER-SOURCE FORM'S OWN, NOT THE GLOBAL FORM'S.
# What breaks is a struct with a member-pointer field crossing a header boundary
# between a TU that has the option and a TU that does not -- which is possible
# only while the setting is per-source. R9 has to argue the set is safe ("none
# of these TUs takes a pointer-to-member across a header boundary"); a global
# setting has nothing to argue, because there is no boundary left to cross.
#
# So it goes on add_compile_options above every target and must never become a
# per-target property either: half a build with it is worse than none. The three
# per-source blocks are left where they are, redundant and harmless, so their
# derivations stay readable and a revert of this line restores their behaviour.
#
# WHAT IT REPAIRS ON A PATH THAT ALREADY LINKS, which is why it is not merely an
# enabler for the host-copy retirements. Twenty-seven in-slice TUs form a member
# pointer without carrying one of the per-source rows below; ov075's pair is the
# one that is provably wrong today, and it is provable WITHOUT the ROM because
# both halves are in the tree and disagree with each other:
#
#   src/__sinit_ov075_0211b5e0.c FILLS the two tables and spells the cell
#     struct P2 { int a, b; };  extern struct P2 data_ov075_0211d56c[10];
#                               extern struct P2 data_ov075_0211d53c[6];
#   -- eight bytes, ten and six cells, which is exactly the 0x50 and 0x30 those
#   two bss symbols span in config/arm9/overlays/ov075/symbols.txt.
#
#   src/func_ov075_02114cd8.cpp READS them and spells the same cell
#     struct C0 {};  typedef void (C0::*PMF)();  struct PmfRow { PMF pmf; };
#     (((C0*)self)->*data_ov075_0211d56c[*(int*)(s + 0x110)].pmf)();
#   -- FOUR bytes on MSVC's default, so the reader indexes a table at half the
#   stride the writer laid down. Both TUs are in the slice and in the map today.
#
# Under this flag PmfRow is eight bytes, the reader and the writer agree, and
# both agree with the span the config publishes.
#
# HOW MUCH THAT IS WORTH, SAID EXACTLY. Nothing seats those two ov075 tables
# with host addresses -- swept, there is no seat -- so the words the reader
# fetches are still the mount's DS addresses and the dispatch would fault if it
# ran. It does not run today: the battery is green. So this is a LATENT repair,
# a wrong stride made right ahead of the lane that seats ov075, not a fault
# fixed in a shipping path. It is here because it is the one case in the
# twenty-seven that is provably wrong rather than merely representationally
# different, and because a stride bug found later, after a seat exists, reads
# as a seat bug.
#
# TWO CLAIMS THAT LOOK LIKE THIS ONE AND ARE NOT, checked and struck rather than
# left standing. src/game/actors/daBrq_c.cpp does stride `c->pp + 1` by four on
# MSVC's default -- but R8 below already sets the option on that exact file, so
# it has been eight bytes since wave 17. And src/_ZN9ActorBase7Process...cpp
# does read three four-byte member pointers from callers that push eight-byte
# pairs -- but tools/hostgen.py rewrites all four of those callers into vtable
# index dispatches (build/port/host-src/src/func_0204335c.c), so nothing in
# the binary makes that call and the mismatch is unreachable.
#
# C2287 IS THE FAILURE MODE TO WATCH FOR -- a class that genuinely needs the
# VIRTUAL inheritance representation cannot be covered by /vmm. There is none in
# src/ or include/, and the system headers this tree includes (the STL subset in
# hal/, windows.h, mmsystem.h, process.h) were compiled both ways and are
# byte-identical. If one ever appears, the error names the class.
#
# CXX ONLY: /vm* is a C++ switch and cl warns on it once per .c file otherwise.
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/vmg>
                    $<$<COMPILE_LANGUAGE:CXX>:/vmm>)

# Test-only fault injection: SM64DS_TEST_QUARANTINE, the hook in
# port/unmatched/func_02043fdc_hostcopy.cpp that force-freezes an actor by
# raising the access violation a real per-actor decline raises. A proof run
# needs it to reproduce a quarantine on demand; a player must never carry a
# way to force a fault on an arbitrary actor id read out of the environment,
# so it is OFF unless a build asks for it by name. build-port.cmd forwards its
# arguments to cmake:
#
#     build-port.cmd -DPORT_TEST_HOOKS=ON
#
# It is a cache variable, so a tree configured for a proof STAYS a proof tree;
# configure a fresh build directory (or pass -DPORT_TEST_HOOKS=OFF) for anything
# that ships. The warning is there so a proof binary is identifiable from the
# build log and not only from the source.
option(PORT_TEST_HOOKS
       "compile the SM64DS_TEST_QUARANTINE fault-injection hook (TEST BUILDS ONLY)"
       OFF)
if(PORT_TEST_HOOKS)
    add_compile_definitions(PORT_TEST_HOOKS=1)
    message(WARNING
        "PORT_TEST_HOOKS=ON: these binaries carry the SM64DS_TEST_QUARANTINE "
        "fault-injection hook and are TEST ONLY. Do not ship them.")
endif()

# ===========================================================================
# THE PORT-SIDE CALL TRACE (run link100, lane TRACEPORT)
# ===========================================================================
#
# Lane ROMTRACE built an instrumented melonDS that writes down every function
# call the REAL cartridge's ARM9 makes and resolves the addresses to this
# repository's own names: 27,571 of 27,571 named on the title screen. This
# option is the other half. With it on, MSVC emits "call _penter" as the FIRST
# instruction of every function it compiles, port/hal/fn_trace.cpp answers that
# call, and port/tools/porttrace.py turns the result into the same named listing
# the cartridge half produces, so port/tools/tracediff.py can line the two up
# and name the first function they disagree about.
#
# WHY IT NEEDS NO OTHER SOURCE EDIT. /Gh is the compiler's own hook. No
# translation unit is rewritten, no call site is wrapped and no header changes,
# so a traced build cannot perturb what it is measuring by construction. The one
# call to ntr_fn_trace_frame in hal/rom_frame.cpp is the only exception and it
# exists for one reason -- both halves must agree where a frame ends. It sits in
# port_rom_frame_phase6 because every path that renders a frame comes through
# there exactly once, which is the property the frame cross-check in that same
# file already depends on, and it compiles to nothing at all unless
# PORT_FN_TRACE is defined.
#
# WHAT IT COSTS, MEASURED ON THIS BOX (cl 19.44 x86, /O2 /Oy-, C:/tmp/ghtest):
# 20,000,000 real non-inlined calls took 0.0204 s untraced and 0.0364 s traced,
# which is 0.8 nanoseconds a hook. The cartridge makes about 1,800 calls a frame
# on the menu page, so the hook is on the order of a millisecond per second of
# game. Inlining is NOT inhibited, so the hook fires once per real call and not
# once per source-level call.
#
# AND WHAT IT DOES NOT COST: TAIL JUMPS SURVIVE. A one-call forwarder still
# compiles to "call _penter / push ebp / mov ebp,esp / pop ebp / jmp target",
# checked on the disassembly before this option was written, so the roughly fifty
# ov007 rows that are correct only because MSVC turns a forwarder into a jmp --
# the ones port/tools/tailjump_guard.py exists to protect -- carry their
# arguments through a traced build exactly as they do in a shipped one. The one
# thing a traced build DOES disturb is that guard's own scan, which reads an E8
# rel32 in a frame's map span: every frame now opens with an E8 to _penter. Run
# the guards on the PLAIN build, which is the one that ships.
#
# OFF BY DEFAULT AND A CACHE VARIABLE, so a tree configured for tracing STAYS a
# tracing tree; configure a fresh build directory, or pass -DPORT_FN_TRACE=OFF,
# for anything that ships. The warning is there so a traced binary is
# identifiable from the build log and not only from the source.
option(PORT_FN_TRACE
       "compile the /Gh function-entry call trace (TRACING BUILDS ONLY)"
       OFF)
set(PORT_FN_TRACE_SRC "")
if(PORT_FN_TRACE)
    add_compile_options(/Gh)
    add_compile_definitions(PORT_FN_TRACE=1)
    set(PORT_FN_TRACE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/hal/fn_trace.cpp")
    message(WARNING
        "PORT_FN_TRACE=ON: every function in these binaries calls _penter on "
        "entry. They are TRACING BUILDS ONLY. Do not ship them, and do not read "
        "tailjump_guard's verdict off them.")
endif()

# THE CONFIGURE-TIME INPUTS, REGISTERED (run link100, lane CMAKEDEPS).
#
# WHY THIS BLOCK EXISTS.  build-port.cmd used to run `cmake -S ... -B ...`
# unconditionally in front of ninja.  On an already-configured tree with nothing
# changed that was measured at 2m23s in this worktree and 4m53s on the
# integration tree: single-threaded, one core out of twelve, before a single
# file compiled.  build.ninja has always carried its own RERUN_CMAKE edge that
# would do that reconfigure on demand, so the explicit call looks like pure
# waste.  It was not.  That edge only knew the inputs CMake knew about, which
# were this file, CMakeCache.txt, the four compiler files, CMake's own modules
# and the generated tierscan_split.cmake -- thirty-two paths, exactly one of
# them in this repository.  THE SLICE LISTS WERE NOT AMONG THEM.  This file
# reads 233 of them and registered none, so dropping the explicit cmake call
# without this block would hand a lane that edits a slice file no reconfigure at
# all: its newly seated sources would silently never compile and the build would
# look clean.  This registration is the thing that makes the build-port.cmd
# change safe, which is why it lands first and on its own.
#
# HOW.  Each list is registered AT THE POINT IT IS READ, by port_read_lines
# below, which is file(STRINGS) plus the registration.  The 229 plain reads in
# this file all go through it, so a gate block copied from any of them inherits
# the registration instead of having to remember a second list somewhere else.
# The four remaining raw file(STRINGS) calls are the REGEX predicate reads at
# SC1, RT1, IR1 and AE1: those regexes end in a literal semicolon, which a macro
# cannot forward through ${ARGN} without CMake splitting it into two arguments,
# so they keep the raw call and carry their own port_configure_input line.  The
# self-check at the bottom of this file counts the raw calls and says so if a
# new one appears.
#
# MEASURED on this CMake (3.31.6) and this ninja, not assumed:
#   - a registered file that is touched re-runs cmake through RERUN_CMAKE;
#   - a registered path that does NOT exist is silently dropped by CMake, so the
#     EXISTS guard below keeps the configure log honest, it does not protect the
#     build;
#   - a registered file that is DELETED does not wedge ninja: the generator
#     emits a "missing CMake input file is not an error" phony for every one of
#     these deps, so the deletion reconfigures instead;
#   - file(GLOB ... CONFIGURE_DEPENDS) was tried and REJECTED.  Its verification
#     step is correct on a real build, but it makes every `ninja -n` dry run
#     report a reconfigure that a real run would not do, because the dry run
#     never updates the verification stamp.  That costs the cheapest check there
#     is of what a build is about to do;
#   - a plain file(GLOB) of slice_*.txt was tried and REJECTED too.  It
#     registers what is on disk rather than what is read.  Three lists here are
#     read by nothing today (slice_gate30.txt, slice_gate181.txt,
#     slice_mga361.txt), so editing one of those would have bought a full
#     reconfigure and no compile; and it assumes every configure input is named
#     slice_*.txt, which tools/tierscan.py and the four predicate sources are
#     not;
#   - registering the port DIRECTORY itself was tried and REJECTED.  It works (a
#     directory's timestamp moves when a file inside it is created or deleted)
#     and it would catch a list APPEARING for the EXISTS-guarded gates 70-74
#     loop.  But port/ is where the lanes keep their notes: a hundred-odd .txt
#     documents sit beside these lists, and the untracked build wrapper is
#     written here too, so every new file would have cost a full reconfigure
#     that changes nothing compiled.  The benefit is empty today -- all five
#     gate 70-74 lists exist and are registered by name -- so the residual hole
#     is stated instead of paid for: a list that is REFERENCED but ABSENT today,
#     appearing later without an edit to this file, is not seen until the next
#     reconfigure.  Adding a gate normally edits this file, which is registered.
function(port_configure_input)
    foreach(_pci_path IN LISTS ARGN)
        if(EXISTS "${_pci_path}")
            set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND
                         PROPERTY CMAKE_CONFIGURE_DEPENDS "${_pci_path}")
        else()
            message(STATUS "CONFIGURE INPUT absent, not registered: ${_pci_path}")
        endif()
    endforeach()
endfunction()

# Read a list AND register it, in that order, so the two cannot drift apart.  A
# macro rather than a function: the caller wants the variable in its own scope,
# which is what all 229 call sites already assume.
# ---- WHOLE-TU HOSTGEN SUBSTITUTION ------------------------------------------
#
# 2026-09-13, main -> port sync, lane SYNC3.  A hostgen substitution names one
# SOURCE FILE, because the decomp's convention was one function per file and the
# port's blocks below spell their targets as `src/<symbol>.c|cpp`.  main has
# been merging those one-function sources into consolidated translation units
# under `src/<area>/`, so a body the port substitutes no longer has a file of
# its own: the whole TU is one file, named by every slice that used to name each
# of its members separately.
#
# Three of those TUs still need what their member's substitution did, and the
# only way to keep it is to substitute the WHOLE TU.  That is the shape the FLW,
# BNT and TTE blocks already use per slice.  Done per slice it does not scale
# here: src/actors/Player.cpp alone is named by SEVENTEEN slice lists feeding
# several targets, and one surviving raw row anywhere brings the duplicate
# symbol back at link time while one missing generated copy drops 301 symbols.
# A miss in either direction is silent at configure and loud in a place that
# does not name the cause.
#
# So the substitution is made ONCE, here, and port_read_lines() applies it to
# every slice list as it is read.  A slice row naming a substituted TU becomes
# the repo-relative path of its generated copy, so every loop below that turns a
# row into `${CMAKE_CURRENT_SOURCE_DIR}/../${line}` picks up the generated file
# without knowing anything about it, on every target that slice feeds.  That is
# what makes the duplicate and the drop impossible rather than merely checked.
#
# The generated copy stays under CMAKE_BINARY_DIR because tierscan's candidate
# split classifies a source inside the build directory as generated and does not
# try to read it on a fresh configure (it normalises with get_filename_component
# ABSOLUTE first, so the `port/..` in the row's spelling collapses away).
#
# THE COUNT IS ASSERTED at the end of this file: a substitution that matches no
# slice row is a substitution that silently did nothing, which is the failure
# this block exists to prevent.
#
# Why each of the three is here, measured rather than assumed:
#   src/actors/Player.cpp                     CALL_STATE_FN, St_NoControl_Init's
#       mwcc member-pointer dispatch of a DS code word (the walljump-crash
#       family), plus the TU's own `extern int func_ov002_020cfbdc(void*);`
#       redeclaration of a body it defines `(char*)` -- two extern "C" spellings
#       of one name in one TU, which is MSVC C2733 and stops the file dead.
#   src/actors/dScMgPanel_c.cpp               THIRTY-ONE MMIO derefs (both
#       engines' DISPCNT/BGxCNT and the blend registers), which compiled raw
#       latch in the mapped I/O window and never reach the PPU, plus the two
#       open-coded state dispatches MG_PMF_CALL routes through the panel seam
#       and the one real mwcc pointer-to-member dispatch that routes the same
#       way.
#   src/game/actors/d_a_propeller_heyho.cpp   FALLS_OFF_RETURN (an int body that
#       ends without one, C4716) and EXTERN_C_DATA (seven SharedFilePtr externs
#       declared above the TU's own `extern "C" {`, so MSVC asks the linker for
#       the C++-mangled spelling of names the port's mount emits with C linkage).
#   src/game/actors/d_a_bg_snwmn.cpp   REG_RIDE_ARG (TextureSequence::Prepare is
#       called with two arguments where the ROM's caller leaves a third riding
#       in a register). Added at the main->port sync, lane SYNC5: lane SEAT6
#       keyed this on the per-function TU main has since folded into this one.
#   port/unmatched/dScMgHanachan_c.cpp   PMF_SEAM on four typed member-pointer
#       dispatches of a FIELD (three per-Wiggler bodies at sub-object +0x10 and
#       the Behavior at scene +0x4660) and MG_PMF_CALL on a fifth that open-codes
#       the same decode in plain ints. Nothing seats those fields, so the code
#       word is a DS address at every one of the five and a raw call jumps into
#       the mounted overlay's data image. Added run link100, lane HOSTGEN2;
#       retires the five host copies in unmatched/MgWiggler_StateDispatch.cpp.
#       THE ROW MOVED OFF src/actors/dScMgHanachan_c.cpp, run link100 wave 10
#       round 4, lane SCENES3: scene 386 died in func_ov006_020eac38 of an
#       ARGUMENT EVALUATION ORDER defect (the matched source assigns t.urot
#       inside the comma expression that is argument two of an OAM::Render call
#       and reads it as argument eight; MSVC pushes a cdecl call right to left
#       and passes uninitialised stack on the first loop iteration). src/ is
#       byte-verified and is not edited, so port/unmatched/dScMgHanachan_c.cpp
#       is the src TU with that one call spelled in the cartridge's own order,
#       and THE COPY KEEPS THE STEM on purpose: tools/hostgen.py keys every
#       patch table on the file stem, so all five rows above go on applying to
#       the copy verbatim, which a copy under a new name would silently drop.
#       port/slice_wig.txt names the copy in the src TU's place. The file's own
#       header carries the ARM disassembly at 0x020eadd8..0x020eae10, the host
#       disassembly at 0x005cbffa..0x005cc05b and the one line that reproduces
#       it from the matched source.
#   src/actors/dScMgRoulette_c.cpp   PMF_SEAM on the wheel object's one member-
#       pointer dispatch, and VIRTUAL_CALL on the same body's other defect -- a
#       local four-virtual shadow calling ROM slot 3 on the host Model at +0x10,
#       which is Model::UpdateVerts. Added run link100, lane HOSTGEN2; retires
#       func_ov006_02107db8 in unmatched/MgRoulette_WheelDispatch.cpp.
#   src/actors/dScMgCup_c.cpp   UNINIT_LOCAL on func_ov006_020def80's `int cup;`,
#       the one of the sixteen PORT_HOST_ABI rulings that is not an ABI question
#       at all: the matched body reaches its epilogue through a goto that never
#       assigns the local, and mwcc's register allocation is what made that
#       harmless. Added run link100, lane HOSTGEN2; retires
#       unmatched/MgCup_UninitEpilogue_020def80.cpp. The class's FACTORY host
#       copy (unmatched/MgCup_Factory.cpp) is NOT retired by this: its row is the
#       vptr address-point question and belongs to the lane that settles it.
#   src/actors/daBmb_c.cpp, src/game/actors/d_a_ey_bm.cpp and
#       src/game/actors/d_a_mc_flag.cpp   ZTV_C_LINKAGE, the first three of lane
#       VPTR's nine DECORATED vtable externs. Each TU sees its table declared as
#       a plain C++ `extern int _ZTV<X>[];` -- from include/daBmb_c.h:158 and
#       include/daEyBm_c.h:83 for two of them, from its own line 66 for the
#       flag -- so MSVC emits ?_ZTV7daBmb_c@@3PAHA while the port's host array
#       and the /alternatename that binds it carry the C name __ZTV7daBmb_c. An
#       /alternatename is a NAME bridge and cannot cross a decoration, so all
#       three sat on the unresolved wall. hostgen puts a C-linkage declaration
#       ahead of the include and the header's own inherits it. The same pass
#       drops each store's +8 address-point bias, so the three rows also leave
#       tools/vptr_addend_baseline.txt. Added run link100, lane HOSTGEN3.
#       DS_SHIFT, run link100, lane LCTEXT1. src/func_0201b100.c composes the
#       level-clear save menu's button captions, and its spill statement shifts
#       a 32-bit word RIGHT BY A REGISTER COUNT that reaches 32 whenever the
#       pen lands on an odd tile boundary (sh == 0 with the fast path above it
#       not taken). The ARM saturates that to zero; x86 masks the count to five
#       bits and returns the word UNSHIFTED, so the glyph's left half was
#       duplicated eight pixels to its right -- the stray mark after the "&"
#       and the merged "IT" of SAVE & QUIT. hostgen routes the two expressions
#       through hal/cstd_div.c's ds_lsr; src/ is untouched and the body stays
#       the ROM's, so linkage does not move.
set(PORT_HOSTGEN_TU
    # run rel042, lane NARROWRET1: THE NARROW-RETURN CURE. Each of these TUs
    # DEFINES a function that returns s8/u8/s16/u16/bool; on the DS the callee
    # extends that into the whole of r0, and under MSVC the upper bytes of EAX
    # are junk, so every caller that declares the function wider read junk on
    # the PC. tools/hostgen.py's NARROW_RETURN table renames each body and
    # binds its ROM name to a wrapper that extends the result as the ARM
    # epilogue does (or, for a member, adds the wrapper the alias rows in
    # hal/cxx_aliases.cpp and hal/actor_classes_ov026.cpp now name). src/ is
    # untouched and every body in the link is still the ROM's. Census:
    # tools/narrowret_census.py. src/actors/Player.cpp is already on this list.
    src/_ZN4cstd5atan2E5Fix12IiES1_.c
    src/GetPlayerFlagByte.c
    src/DecIfAbove0_Byte.c
    src/DecIfAbove0_Short.c
    src/NumStars.c
    src/Vec3_HorzAngle.c
    src/Vec3_VertAngle.c
    src/func_02020168.c
    src/func_02020364.c
    src/func_020201f0.c
    src/GetLevelPart.c
    src/func_0201a96c.c
    src/func_0201a9ec.c
    src/NumVsStarsObtained.c
    src/func_ov007_020c3be0.c
    src/IsAreaShowing.c
    src/IsPlayerWarping.c
    src/GetStarCameraSetting.c
    src/func_02065138.c
    src/func_0205b63c.c
    src/func_02053f30.c
    src/func_02053f58.c
    src/func_02053f80.c
    src/func_02053fa8.c
    src/func_02054004.c
    src/func_02054168.c
    src/func_0205417c.c
    src/func_020456a0.c
    src/CountStarsCollectedInLevelToDisplay.c
    src/_ZN8dActor_c12ReflectAngleE5Fix12IiES1_s.cpp
    src/_ZN8SaveData13GetCoinRecordEj.cpp
    src/_ZN8SaveData26CountStarsCollectedInLevelEj.cpp
    src/_ZN3OAM11GetObjWidthEii.cpp
    src/_ZN3OAM12GetObjHeightEii.cpp
    src/_ZN5dBgCh21ShouldPassThroughImplEPvRK4CLPSRKS_b.cpp
    src/_ZN8dActor_c18HorzAngleToCPlayerEv.cpp
    src/func_0201b100.c
    # run link100 wave 20, lane CAMSWIM3: the camera follow state. The
    # CAM_TERMS table in tools/hostgen.py traces the eye-height terms
    # (inert unless SM64DS_CAM_TERMS is set) and DS_SHIFT_FX carries the
    # host-arithmetic correction the trace found. src/ is untouched, and
    # the body in the link is still the ROM's, so linkage does not move.
    src/func_02009e70.cpp
    src/actors/Player.cpp
    src/actors/daBmb_c.cpp
    src/game/actors/d_a_ey_bm.cpp
    src/game/actors/d_a_mc_flag.cpp
    src/actors/dScMgCup_c.cpp
    src/actors/dScMgPanel_c.cpp
    port/unmatched/dScMgHanachan_c.cpp
    src/actors/dScMgRoulette_c.cpp
    src/game/actors/d_a_bg_snwmn.cpp
    src/game/actors/d_a_propeller_heyho.cpp
    # DATA_C_LINKAGE, run link100, lane HOSTGEN4. The same defect as the three
    # ZTV rows above, one level out: each of these five translation units
    # declares a ROM DATUM with a plain C++ `extern <T> data_<hex>;`, so MSVC
    # asks the linker for the decorated name while the port's mount emits that
    # datum with C linkage and every other consumer spells it that way. Sixteen
    # rows of walk_window's unresolved wall, all sixteen with the C-linkage twin
    # already DEFINED in the same link (ov006_syms.c, ov015_syms.c,
    # ov022_syms.c, hal/actor_vtables.cpp, hal/cxxname_bridge.cpp and
    # hal/auto_bss.cpp). hostgen inserts a file-scope extern "C" declaration
    # after a named anchor and the TU's own declaration inherits the linkage;
    # the DATA_C_LINKAGE block in tools/hostgen.py says why the block-scope half
    # cannot be fixed where it stands (MSVC C2598, measured).
    src/actors/dMgJump3DMario_c.cpp
    src/_ZN9TowerStep13InitResourcesEv.cpp
    src/game/actors/d_a_star_gate.cpp
    src/_ZN10LavaSeesaw16CleanupResourcesEv.cpp
    src/_ZN11ShadowModelD1Ev.cpp
    # DATA_C_LINKAGE again, run link100 lane HOSTGEN4, the dBgW collision
    # callbacks. These thirteen translation units never CALL dBgW's two
    # callback bodies: func_020393d4 is handed the address and the mesh
    # collider calls it later, so each one declares the body as a DATUM under
    # its flat Itanium name -- and they do not agree on the type. `int`,
    # `char`, `void *`, `int[]`, whatever each author happened to write, so
    # MSVC emits FOUR decorated spellings of UpdatePosAndAngs and FOUR of
    # UpdatePosWithTransform against one ROM body, seven of which are on
    # walk_window's wall. Under C linkage they collapse onto the flat name the
    # ROM carries, which port/faces_sync.txt already has as an ordinary face
    # row, so seven wrong spellings of one missing thing become the one right
    # spelling and nothing new arrives. The fourteenth copy of the same
    # declaration is unmatched/Coffin_InitResources.cpp, a host copy, which
    # carries its own extern "C" instead.
    src/func_ov002_020b5e58.cpp
    src/_ZN13TTC_MovingBar13InitResourcesEv.cpp
    src/_ZN16RotatingCogSmall13InitResourcesEv.cpp
    src/func_ov002_020b676c.cpp
    src/_ZN25RotatingUpDownPlatformUtm13InitResourcesEv.cpp
    src/func_ov091_02133254.cpp
    src/_ZN6ToxBox13InitResourcesEv.cpp
    src/_ZN11PyramidLift13InitResourcesEv.cpp
    src/_ZN11PyramidStep13InitResourcesEv.cpp
    src/game/actors/d_a_obj_wc_obj04.cpp
    src/_ZN8CccArena13InitResourcesEv.cpp
    src/_ZN9SeesawBob13InitResourcesEv.cpp
    src/_ZN6ShipUp13InitResourcesEv.cpp
    # VIRTUAL_CALL, run link100 lane HOSTGEN4: the WaterfallMist duplicate, one
    # of the six LNK2005 rows still on walk_window's link. Lane CAPSHOW's host
    # copy exists because daObjMarioCap_c::Behavior calls the cap's own
    # ModelAnim through a local four-virtual shadow at +0x0c, which is
    # UpdateVerts in the ROM's numbering and Virtual10(Matrix4x3 &) in the
    # port's MSVC-numbered table, whose `ret 4` unbalances the frameless
    # caller. slice_gate33's loop skips the src row by name for exactly that
    # reason -- but slice_gate204 and slice_gate51 name the class TU main
    # folded the body into, so the matched body arrives anyway and the two
    # collide. The substitution carries CAPSHOW's one-line correction into the
    # class TU, and unmatched/WaterfallMist_Behavior_HostSites.cpp is retired
    # in the same change.
    src/actors/daObjMarioCap_c.cpp
    # REDECL_CONFLICT and ALTNAME, run link100 lane HOSTGEN4. The Monkey
    # class TU, seated by port/slice_hostgen4.txt and refused by MSVC
    # until now: eighteen block-scope redeclarations that disagree with
    # the TU's own file-scope spelling about a return type (C2556/C2371),
    # six function-local classes used to declare an extern (C2624), and
    # seven ROM data references that reach the linker decorated because
    # they are declared inside C++ members where no linkage-specification
    # is allowed. Worth fourteen flat ROM rows. The slice file carries the
    # whole derivation and what the seat costs.
    src/actors/daMky_c.cpp
    # LEDGER_PARK and the MMIO rewrite, run link100 lane HOSTGEN4.
    # src/actors/dScMgD3DBase_c.cpp is on no slice and answers NINETEEN
    # rows: five flat ROM names and fourteen decorated members that
    # nothing in this link defines. It compiles clean today, which is new;
    # unmatched/MgD3DBase_DeclConflict.cpp exists because it did not (a
    # C2733 between include/decl_common.h:1516 and this TU's definition of
    # OnKicked) and that reason is obsolete. It needs the substitution for
    # two reasons: TWENTY-FOUR MMIO writes, which compiled raw would latch
    # in the mapped I/O window and never reach the PPU, and one member,
    # OnKicked, that port/faces_sync.txt already defines as a reverse face.
    # That member is PARKED in the generated copy rather than duplicated;
    # the ledger row and the host copy retire together and neither is this
    # lane's file. Measured: no other symbol it defines is defined anywhere
    # else in walk_window's 8661 objects, so the three MgD3DBase_* host
    # copies are untouched and stay.
    src/actors/dScMgD3DBase_c.cpp
    # LEDGER_PARK, run link100 lane HOSTGEN4. Two more class TUs that are
    # on no slice and that MSVC compiles clean today. Between them they
    # answer TWENTY-FIVE rows. What kept each out is a handful of members
    # port/faces_sync.txt already defines as REVERSE faces -- five for
    # daSanbo_c, three for daPkn_c -- whose flat forward targets are all
    # defined in this link by their own per-function TUs, so the face is
    # serving the vtable correctly today and a second definition in the
    # class TU would be a duplicate symbol and nothing else. Each is parked
    # in the generated copy, so the seat changes no dispatch at all. One
    # more member is parked in each for a different reason: they are
    # PORT_HOST_ABI host copies (unmatched/Pokey_HostSites.cpp and
    # unmatched/Actor_ClosestPlayer_OverlayReaders.cpp), and parking keeps
    # each ruling exactly where it is rather than re-adjudicating it.
    src/actors/daSanbo_c.cpp
    src/actors/daPkn_c.cpp
    # And the same shape once more, lane HOSTGEN4. daWanwan_c (Chain Chomp)
    # answers twelve ov014 rows and is held by three ledger members plus its
    # factory, which unmatched/ChainChomp_Spawn_hostcopy.cpp supplies under
    # the VPTR ruling. Its four parks are written PER BODY rather than banner
    # to banner, because these members sit at the top of the file and the
    # wider bracket swallowed an include and four file-scope declarations a
    # member further down still needs; the LEDGER_PARK table says so at the
    # row.
    src/game/actors/d_a_wanwan.cpp
    # ZTV_C_LINKAGE plus the vptr address-point rewrite, run link100 lane
    # SEATS3. src/actors/daGmch_c.cpp (MONEYBAG, ov081) is on no slice and
    # closes two rows itself, ??1daGmch_c@@UAE@XZ and daGmch_c_classInit. It
    # is seated for the other half: its object defines twenty-three decorated
    # members that are flat rows on walk_window's wall today, which is the
    # largest single block a face lane can bind after daMip_c, and its three
    # ledger rows retire with it so Moneybag's InitResources stops calling the
    # face that calls it.
    #
    # It goes through the substitution rather than a plain slice row for two
    # reasons, both in one line of the factory:
    #     p[0] = (int)&_ZTV8daGmch_c[2];
    # The `[2]` is the Itanium address point, which compiled raw is a DIR32
    # relocation with 8 applied at the site; the port's tables have no header
    # words for that bias to skip and vptr_addend_guard refuses a nonzero
    # addend that is not in tools/vptr_addend_baseline.txt. And the name is
    # declared in include/daGmch_c.h as a plain C++ extern, so MSVC asks for
    # ?_ZTV8daGmch_c@@3PAHA, which the /alternatename in
    # port/hal/actor_classes_ov081.cpp cannot reach across a decoration. The
    # substitution drops the bias and gives the extern C linkage.
    src/actors/daGmch_c.cpp
    # LEDGER_PARK, same lane. src/minigames/d_s_mg_roulette.cpp holds exactly
    # two bodies: func_ov006_0210a4ac, an empty ROM stub which is the one wall
    # row it closes, and dScMgRoulette_c_classInit, which
    # port/unmatched/MgRoulette_Factory.cpp host-copies to repair a factory
    # that calls _ZN11dScMgBase_cC2Ev with no argument. The park brackets the
    # factory out of the generated copy, so the host copy and its ruling are
    # untouched and the duplicate port/CMakeLists.txt refuses this TU for on
    # slice_rlt.txt does not exist.
    src/minigames/d_s_mg_roulette.cpp
    # REDECL_CONFLICT (lane HOSTGEN4's, already in tools/hostgen.py) plus
    # ZTV_C_LINKAGE and the vptr address-point rewrite, run link100 lane
    # SEATS3. src/actors/daMip_c.cpp (MIPS the rabbit, ov085) was PREPARED AND
    # NOT SEATED by lane HOSTGEN4: the repair for the nine MSVC errors is in
    # the REDECL_CONFLICT table and verified compiling, and the seat was left
    # because one closed row did not justify a build slot at the end of that
    # lane's budget. It is worth more than one row here, because the two
    # members that stopped it -- InitResources and Render -- are the same
    # recursion defect the fold closed eleven of, and their ledger rows retire
    # with this seat. Re-measured on this tree's own generated object: closes
    # daMip_c_classInit, duplicates exactly those two members and nothing else,
    # and its twenty-five decorated ov085 data references are bridged in
    # port/unmatched/Seats3_NameBridges.cpp.
    src/actors/daMip_c.cpp
    # THE MMIO REWRITE, run link100 lane SEATS3, and this row is the reason
    # the mechanism exists. src/_ZN11dScMgBase_c16OnAimedAtWithEggEv.cpp is a
    # one-member translation unit on no live slice row (slice_slice1.txt
    # line 67 has it commented out) and it closes
    # ?OnAimedAtWithEgg@dScMgBase_c@@UAEHXZ, which four class TUs' vtables ask
    # for by LNK2001 today. It is the minigame overlay menu going up: the body
    # stashes POWCNT1's screen-swap bit, clears every layer- and window-enable
    # bit in BOTH DISPCNTs, saves the BG palette and the sub-screen OBJ VRAM
    # into the object and draws the menu over them. SIX of its writes are
    # register writes hostgen rewrites, measured on the generated file rather
    # than counted by eye. Compiled raw they would latch in the mapped I/O
    # window and never reach the PPU, which is what the substitution exists to
    # prevent and the same reason dScMgD3DBase_c is on this list.
    src/_ZN11dScMgBase_c16OnAimedAtWithEggEv.cpp
    # HOST_COPY_PARK, run link100 lane DUPES: the last three of walk_window's
    # five duplicate symbols. Each of these translation units defines a body
    # port/unmatched/ also defines under a standing PORT_HOST_ABI ruling, and
    # every one of those rulings says the HOST COPY is the body that runs
    # (runs/link100/out/ALIAS2/host_abi_conflicts.txt and
    # out/HOSTGEN4/needs_main.md section 3). The substitution brackets the src
    # definition out of the GENERATED copy and does nothing else: the host copy
    # is untouched, the flat name stays defined by the same object that defines
    # it today, and the rest of each class TU goes on compiling. The other two
    # duplicate rows need no entry here, because src/actors/dScMgCup_c.cpp and
    # src/minigames/d_s_mg_trampoline2.cpp are already substituted; their parks
    # are rows in tools/hostgen.py's HOST_COPY_PARK table alone.
    #
    # WHAT ELSE EACH SUBSTITUTION CARRIES. Moving a compile off the raw path
    # brings hostgen's other rewrites with it, so each was measured on the
    # generated object rather than assumed:
    #   src/actors/dScMgSound_c.cpp        SIX MMIO rewrites, which compiled
    #       raw latch in the mapped I/O window and never reach the PPU, and ONE
    #       vtable address-point bias dropped on dScMgSound_c_classInit's store
    #       of _ZTV12dScMgSound_c.
    #   src/actors/daBombking_c.cpp        ONE vtable address-point bias
    #       dropped, on the factory's store of &_ZTV12daBombking_c[2].
    #   src/game/actors/d_a_obj_b_swdoor.cpp   nothing else. main's rewrite of
    #       that TU spells its factory `return new daObjBSwdoor_c();`, so the
    #       object carries no _ZTV14daObjBSwdoor_c relocation at all and the
    #       baseline row for it was already stale before this change.
    # The two live bias drops retire two rows of tools/vptr_addend_baseline.txt,
    # which is what that file's own header asks for: "A row leaves it when its
    # TU joins port/CMakeLists.txt's PORT_HOSTGEN_TU list, where
    # tools/hostgen.py's VPTR_ADDRESS_POINT rewrite drops the bias." Nothing is
    # added to the baseline and vptr_addend_guard goes on refusing any new
    # nonzero addend.
    src/actors/dScMgSound_c.cpp
    src/actors/daBombking_c.cpp
    src/game/actors/d_a_obj_b_swdoor.cpp
    # Run link100 wave 9c, lane LINK21. Two one-function TUs that MSVC cannot
    # take raw, both on port/slice_link21.txt.
    #
    # ArrowSignRight::OnAttacked1 carries a BARE `return;` inside an int body,
    # which is a C2561 and not the C4716 that /wd4716 answers, so the TU has been
    # quarantined since lane SLICE1. hostgen's FALLS_OFF_RETURN table turns the
    # early exit into the absence of the call, which is #2663's own shape for the
    # five siblings of this family and invents no return value; the ROM's early
    # exit leaves r0 holding the receiver, and the table's note carries that
    # disassembly. The generated body then falls off the end like its two seated
    # siblings, so the raw path is on PORT_FALLS_OFF_END_SOURCES below and the
    # loop there puts /wd4716 on the generated path too.
    #
    # IRQ::SetIRQs pokes IME 0x4000208 and IE 0x4000210 through literal casts and
    # needs the MMIO routing, two rewrites.
    src/_ZN14ArrowSignRight11OnAttacked1ER8dActor_c.cpp
    src/_ZN3IRQ7SetIRQsEj.cpp
    # Run link100, lane CRASH6. THE SIX VPTR STORES THAT ARE MEASURABLY WRONG,
    # and the first run-time conviction of the defect tools/vptr_addend_guard.py
    # was written to predict. Its docstring already said what would happen: "the
    # +8 store puts every dispatch two slots high: ROM slot 0, InitResources,
    # the first call on the spawn path, enters slot 2 instead", and "Only a run
    # convicts it, as a wrong function with a wrong arity on the spawn path."
    # That is exactly what killed the level-1 boot tonight, instruction for
    # instruction, measured on the shipped artifact under a debugger:
    #
    #   daObjWaterfall_c_classInit at 004098dd stores 0x9f6738, which is
    #   __ZTV16daObjWaterfall_c + 8. The table starts at 0x9f6730, so
    #   fBase_c::Process, inlined into func_0204335c, read slots 2, 3 and 4
    #   where it meant slots 0, 1 and 2. It called AfterInitResources instead of
    #   InitResources, so the mist was never initialised, and the two faces it
    #   reached have the wrong STACK arity for those call sites: ob2_ainit is
    #   __fastcall(void*, void*, unsigned) and ends `ret 4` where nothing was
    #   pushed, ob2_bclean is __fastcall(void*, void*) and ends `ret 0` where
    #   one word was. Four bytes each in opposite directions, so ESP
    #   re-balanced and the return address survived. The only casualty was the
    #   `pop edi` at 005efdd3, which loaded the leftover pushed argument. The
    #   caller, daObjMcWater_c::InitResources, holds `this` in EDI across that
    #   call and faulted on its second loop iteration reading [1 + 0xcc].
    #
    # WHY THESE SIX AND NOT THE OTHER SIXTEEN. 206 *_classInit functions in this
    # image install a vptr; 184 store table+0 and 22 store table+8. Sixteen of
    # the 22 name tables that live in .dsstate, which CRASH6 read as ROM MOUNTS:
    # a vtable mwcc built really does carry offset-to-top and typeinfo in front
    # of its slots, so +8 looked plausibly like the ROM's own address point
    # there, and moving it needed the ROM layout read first. The six below name
    # .data HOST ARRAYS declared in port/hal (`int _ZTV8daTree_c[31];` and
    # siblings) and filled from `vt[0]`, checked one at a time, so on those +8
    # is two slots past the first virtual and there is nothing in front of it
    # to skip.
    #
    # CORRECTION, run link100 lane VPTR16, read out of the cartridge: THE
    # SIXTEEN ARE THE SAME DEFECT, not a different question, and the .dsstate
    # reading above was wrong in both halves. They are not ROM mounts (they are
    # host arrays declared in port/hal that land in .dsstate only because they
    # sit inside a DSSTATE_BEGIN/END bracket, which exists so the save state
    # captures them), and +8 is not the ROM's address point either (the ROM's
    # Itanium header sits BEFORE the symbol the config names, not after it).
    # The measurement and the sixteen rows are in the VPTR16 block below.
    #
    # Each one was run through tools/hostgen.py standalone first and diffed
    # against its raw source: exactly one bias dropped per TU, zero MMIO
    # rewrites, nothing else changed. Their six rows leave
    # tools/vptr_addend_baseline.txt in the NEXT commit, not this one, which is
    # what that file's own header asks for. The order matters: the guard runs
    # once before configure, against the PREVIOUS build's objects, so retiring
    # the rows in this commit would refuse the very build that earns the
    # retirement.
    src/game/actors/d_a_obj_waterfall.cpp
    src/game/actors/d_a_set_se.cpp
    src/game/actors/d_a_tree.cpp
    src/game/actors/d_a_sound_obj.cpp
    src/game/actors/d_a_obj_rc_dorifu.cpp
    src/actors/Scuttlebug.cpp
    # Run link100, lane VPTR16. THE SIXTEEN CRASH6 LEFT OPEN, SETTLED FROM THE
    # CARTRIDGE, AND THE CARTRIDGE CONDEMNS ALL SIXTEEN. Not one of them was
    # right, and the reason CRASH6 could not tell is that its discriminator does
    # not discriminate.
    #
    # WHAT WAS READ. For each of the sixteen the vtable symbol's DS address
    # comes from config/arm9/overlays/ovNNN/symbols.txt and the bytes come from
    # extracted/overlays/overlay_00NN.bin at the base address in
    # extracted/dsd/arm9_overlays/overlays.yaml -- never the dsd copies, which
    # are shifted, and never arm9_dec.bin, which loads at 0x02004000 rather than
    # the RAM base. Every one of the sixteen reads the same way:
    #
    #     symbol - 8   00000000                          offset-to-top
    #     symbol - 4   -> _ZTI<Class>                     typeinfo pointer
    #     symbol + 0   -> <Class>::InitResources          virtual slot 0
    #     symbol + 4   -> dActor_c::BeforeInitResources   virtual slot 1
    #     symbol + 8   -> dActor_c::AfterInitResources    virtual slot 2
    #
    # THE ITANIUM HEADER IS IN FRONT OF THE SYMBOL, NOT BEHIND IT, so the symbol
    # the config names IS the address point and `&_ZTV<X>[2]` is two slots past
    # it. The front triplet is bit for bit the one CRASH6 measured on
    # daObjWaterfall_c and convicted at run time, and the two faces a shifted
    # read lands on are the same ob2_ainit (@12, `ret 4`) and ob2_bclean (@8,
    # `ret 0`) whose opposite four-byte errors hide the slide.
    #
    # THE BASE IS NOT WRONG, WHICH IS THE ONE WAY THIS MEASUREMENT COULD LIE
    # (tools/evidence_rom.py:66; lane CRASH2 lost time to it, because at a wrong
    # base everything decodes as plausible ARM). 48 EXACT SYMBOL HITS say the
    # base is right: sixteen typeinfo pointers that resolve to
    # _ZTI<that exact class>, sixteen slot-1 words that resolve to
    # dActor_c::BeforeInitResources, sixteen slot-2 words to
    # dActor_c::AfterInitResources. A wrong load address does not produce that.
    #
    # THIRD CHECK, AND IT IS THE ONE THAT TIES THE ROM TO THIS TREE. Counted
    # FROM THE SYMBOL, slot 16 and slot 17 land exactly on <Class>::D1 and
    # <Class>::D0 (checked on seven, 14 exact symbol hits). That is the index
    # port/hal already seats the destructor pair at, and the index lane TAIL's
    # tools/tail_slots.py measurement off config/arm9/overlays/ov002/relocs.txt
    # already assumed when it wrote
    # `0x021091d4 +0x40 -> 0x020b6664 D1  +0x44 -> 0x020b660c D0`
    # into hal/actor_classes_ov036.cpp. Two parts of this tree were already
    # treating the symbol as the address point.
    #
    # THE MSVC DESTRUCTOR FOLD IS RULED OUT FOR THIS SET, not merely unused.
    # memory sm64ds-port-msvc-dtor-slot-shift is the obvious suspect for an
    # eight-byte difference at the head of a table, because mwccarm gives a
    # virtual destructor two entries and MSVC folds them to one. It cannot be
    # the answer here: these are dActor_c-derived classes whose destructor pair
    # is at slots 16 and 17, so nothing at the front of the table can shift.
    #
    # AND THE .dsstate PREMISE ITSELF WAS FALSE. All sixteen tables are HOST
    # ARRAYS declared in port/hal/actor_classes_*.cpp (`void *_ZTV7daBar_c[31];`
    # and siblings, 31/32/33 wide) inside a DSSTATE_BEGIN/END bracket. That
    # bracket is why they land in .dsstate -- the save state has to capture them
    # -- and it is not evidence of a cartridge mount. Not one of the sixteen has
    # a live /alternatename onto a data_ovNNN_ symbol; the single such pragma in
    # the tree, daBar_c -> _data_ov002_02108480, is commented out. Every filler
    # was read: thirteen assign `vt[0]` the class's own init face directly and
    # three (Kaitendai, Kuruma, Kurumajiku) go through a tabs[] loop that also
    # starts at vt[0], and whose own comment already records that "the ROM parks
    # ZERO in slots 0 and 3 on both tables", which is exactly what sits at
    # symbol+0 and symbol+12 for those three.
    #
    # Each TU was run through tools/hostgen.py standalone and diffed against its
    # raw source before this row was written: one bias dropped per TU, zero MMIO
    # rewrites, nothing else changed. daObjLava_c reports two because its file
    # header quotes the spelling in prose and the rewrite reaches the comment as
    # well; the generated comment then reads oddly and the generated code is
    # right. The sixteen baseline rows retire in the NEXT commit, not this one,
    # for the ordering reason CRASH6 wrote down above.
    #
    # WHAT IS LEFT AFTER THIS ROW, TAKEN FROM THE GUARD ITSELF RATHER THAN FROM
    # A SOURCE SWEEP, because a sweep of src/ undercounts what is already
    # substituted and misses a store spelled through a macro. After the build
    # this row earns, vptr_addend_guard reports ELEVEN nonzero relocations over
    # NINE distinct rows, and all nine were settled out of the cartridge the
    # same way and read the same way: dScMgMemory2_c, dScMgBSC_c, dScMgCard_c,
    # dMgCardObj_c, dMgDilarCardObj_c, dScMgMCarlo_c, dScMgMCarlo2_c,
    # dScMgMemory_c, dScMgTrampoline_c. All nine live in ov006 and all nine have
    # the Itanium header in front of the symbol. So the residue is ONE coherent
    # follow-up, the ov006 minigame scene family, and it is outside this lane's
    # brief rather than undecided. There is no surviving case anywhere in this
    # tree where +8 is correct.
    src/game/actors/d_a_bar.cpp
    src/game/actors/d_a_cam_tag.cpp
    src/game/actors/d_a_obj_km1_dorifu.cpp
    src/game/actors/d_a_obj_km2_fall_block.cpp
    src/game/actors/d_a_obj_km2_gura.cpp
    src/game/actors/d_a_obj_km3_dorifu.cpp
    src/game/actors/d_a_obj_km3_kaitendai.cpp
    src/game/actors/d_a_obj_km3_kuruma.cpp
    src/game/actors/d_a_obj_km3_kurumajiku.cpp
    src/game/actors/d_a_obj_rc_carpet.cpp
    src/game/actors/d_a_obj_wc_obj01.cpp
    src/game/actors/d_a_obj_wc_obj06.cpp
    src/game/actors/d_a_obj_wc_obj07.cpp
    src/game/actors/d_a_s_cre.cpp
    src/game/actors/d_a_warpkun.cpp
    src/actors/daObjLava_c.cpp
    # Run link100 wave 10 round 2, lanes SCENES1 and SCENES2. THE OV006
    # MINIGAME SCENE FAMILY, which is the residue the VPTR16 block above named
    # and left ("the 11 remaining relocations are 9 distinct rows ... all nine
    # live in ov006 ... one coherent follow-up"). It is now convicted at run
    # time, the same way CRASH6's six were, and it costs SEVEN SCENE BOOTS:
    #
    #   362 MEMORY1   363 MEMORY2   379 CARD   381 MCARLO
    #   382 MCARLO2   384 TRAMPOLINE           388 LUCKYSTARS
    #
    # All seven died at ONE instruction, CopyUpLargeMov+0xa, the CRT's memcpy
    # writing to address 0. Measured with cdb on the 940023bca build, scene 362,
    # breakpoint on ?AfterInitResources@dScMgBase_c@@UAEXI@Z:
    #
    #   [AINIT] obj=307facc0 vptr=0183581c slot0=006a9680 slot1=004161e0
    #           slot2=004ff680 beb60=00000000
    #
    # __ZTV13dScMgMemory_c is at 0x01835814 in that build's map, so the object
    # holds table + 8 and vptr[0] is the table's slot 2. fBase_c::Process
    # dispatches its InitResources pointer-to-member at virtual index 0 and
    # lands on AfterInitResources, so dScMgBase_c::BeforeInitResources (vtable
    # slot 1, the ONLY writer of data_ov004_020beb60) never runs. Then
    # AfterInitResources calls LoadFont(2), LoadFont's data_0209d698 == 2 arm
    # calls LoadFileAt(0x980e, func_ov004_020adc4c()), that veneer returns the
    # still-zero data_ov004_020beb60, and func_02018270 memcpys 0x4000 bytes to
    # address 0. Crash record: c0000005 WRITE to 0x00000000, ecx = edx = 0x4000,
    # edi = 0.
    #
    # THE CONTROL IS ALREADY IN THE TREE AND IT IS EXACT. dScMgCup_c,
    # dScMgPanel_c, dScMgHanachan_c and dScMgRoulette_c are on this list
    # already, carry no baseline row, and their scenes get past this point:
    # the same breakpoint on scene 361 reads beb60=3011a57c and hits the port's
    # own __ZN11dScMgBase_c19BeforeInitResourcesEv once, where scene 362 never
    # hits it at all.
    #
    # Each of the seven was run through tools/hostgen.py standalone and diffed
    # against its raw source before this row was written. THIRTEEN address-point
    # biases dropped (d_s_mg_card.cpp has seven sites of its own: two element
    # classes seated in four places plus the scene) and TWENTY-SEVEN MMIO
    # rewrites, which are the second half of what the substitution is for and
    # are counted here rather than by eye: 3 in d_s_mg_card.cpp, 4 in
    # d_s_mg_m_carlo.cpp, 4 in d_s_mg_m_carlo2.cpp, 16 in d_s_mg_trampoline.cpp
    # (both DISPCNTs, DISP3DCNT and the master brightness registers, which
    # compiled raw latch in the mapped I/O window and never reach the PPU), and
    # none at all in d_s_mg_memory.cpp, dScMgMemory2_c.cpp or d_s_mg_bsc.cpp.
    # Nothing else changed in any of the seven.
    #
    # Their nine rows leave tools/vptr_addend_baseline.txt in the NEXT commit,
    # not this one, for the ordering reason the CRASH6 block above wrote down:
    # the guard runs once before configure against the PREVIOUS build's
    # objects, so retiring the rows here would refuse the very build that earns
    # the retirement.
    src/minigames/d_s_mg_memory.cpp
    src/actors/dScMgMemory2_c.cpp
    src/minigames/d_s_mg_card.cpp
    src/minigames/d_s_mg_m_carlo.cpp
    src/minigames/d_s_mg_m_carlo2.cpp
    src/minigames/d_s_mg_trampoline.cpp
    src/minigames/d_s_mg_bsc.cpp
    # run linkfull wave 23, lane HGFRONT1 (LINK15 batch W23-6). The cutscene
    # object's command slot 2 adds 0x8e to a loaded void*, the GNU byte
    # arithmetic mwcc accepts and MSVC refuses (C2036), in the one spelling
    # tools/hostgen.py's VOIDPP_ARITH did not reach: an operand with a
    # parenthesis of its own, `*(void **)(p + (idx << 2)) + 0x8e`. The rewrite
    # now reaches it (the table's own comment has the measurement), so the
    # matched TU replaces unmatched/Ov002_CutsceneCmd_020f7780.c.
    # port/slice_w23_hostgen.txt names the row.
    src/func_ov002_020f7780.c
    # run link100 wave 12, fixer FILESEL (card out/FILESEL1/card_filesel.md). The ov007
    # vector normalise the FILE SELECT runs twice a frame: matched on main by 7dba86b5d
    # (PR #2361), newly on slice_ov007.txt, and every one of its 24 register accesses is a
    # literal-cast store or load to the DS divider, square root or IME. Plain, those latch in
    # mapped memory and the units are never told, so the row is substituted by the hostgen
    # copy, which routes all 24 through the NTR_MMIO proxy ntr/io.cpp emulates. No geometry
    # command port is involved, which is why this is here and not in TITEX_GX_SYMS.
    src/func_ov007_020c368c.c)

# ---- run link100 lane SAMECLASS: THE SAME DROPPED-STORE DEFECT, ELEVEN MORE -
#
# THE CLASS lane mg15 TITLETEX named and fixed for twelve ov007 translation
# units, and lane MODESEL fixed for a thirteenth (the title menu's cell
# submitter, the TITLEQUAD block far below), arriving on ELEVEN MORE. Same
# shape every time: a ROM translation unit writes a DS geometry command port
# with a PLAIN literal store while being built plain, ntr maps real memory
# across 0x04000000, the word latches and the geometry engine is never told.
# Nothing in the build can see it -- the TU byte-matches, the linker is happy
# and linkage.py counts the row -- and the instruction is thrown away every
# frame.
#
# THE SET IS THE MEASURED ONE AND IT WAS MEASURED TWICE. MODESEL rescanned
# TITLETEX's stale set on its own tree and found these eleven; this lane
# repeated the scan independently on its own configured build.ninja
# (out/SAMECLASS/gxscan.py: every source on walk_window's own compile lines
# that is not already a host-src copy, comments stripped) and got the same
# eleven files with the same register lists to the digit. The sixteen other
# hits are the host's own files -- gx.cpp, io.cpp, runtime.cpp,
# walk_window.cpp, player_bridges.cpp and the smoke_*.cpp harnesses -- which
# reach the engine through NTR_MMIO by construction and are excluded by
# reading them, not by a name rule.
#
#   func_ov007_020c19cc   444 448 470 48c 494 500 504
#       MTX_PUSH, MTX_POP, MTX_TRANS, VTX_16, VTX_XY, BEGIN_VTXS, END_VTXS.
#       ov007's ribbon/stroke submitter: it brackets each segment of a stroke
#       with a push and a pop, translates to the point, rotates by the bisector
#       of the two segment angles through func_0205532c (which IS routed), and
#       emits the two edge vertices. EVERY store in it is dropped, so the whole
#       routine draws nothing at all -- not a misplaced ribbon, no ribbon.
#       This is the one MODESEL called the cheapest next one, and the only one
#       of the eleven on a path the port reaches today.
#
#   func_ov075_0211a948   4a4 4a8 4ac 4c0 4c4
#   func_ov075_0211afb0   440 444 448 46c 484 488 48c 4c8 4cc 500 504
#       dScEntry_c's material setup and its VS/wireless entry-menu grid mesh.
#       The first pushes the object's cached DIF_AMB, SPE_EMI, TEXIMAGE_PARAM
#       and TEXPLTT_BASE and then a fixed POLYGON_ATTR; the second concatenates
#       the object matrix with the pooled camera matrix and emits the grid's
#       triangle strips. Both drop everything.
#
#   func_ov080_02125460   4a4 4a8 4ac 4c0 4c4
#   func_ov080_02125fd0   440 444 448 46c 484 488 48c 4c8 4cc 500 504
#   func_ov080_0212677c   440 444 448 46c 484 488 48c 4c8 4cc 500 504
#       The same two routines again in ov080, plus a second mesh submitter.
#       The register lists are identical to the ov075 pair's, which is what a
#       routine duplicated into a second overlay looks like.
#
#   _ZN11dScMiniGm_c13InitResourcesEv   4cc
#       LIGHT_COLOR. The minigame scene's resource init sets its light colours
#       once and none of them arrives.
#
#   Initialise3dGraphics  44c 540 580   (and DISP3DCNT at 0x4000060)
#   func_0205583c         4a4 4a8 4ac 504
#   func_020556d0         440 448 454   (and GXSTAT at 0x4000600)
#   func_020554bc         4d0
#       THE BOOT 3D SETUP, one call chain: Initialise3dGraphics calls
#       func_0205583c, which calls func_020556d0 and func_020554bc, and then
#       Initialise3dGraphics calls both of them again itself. Between them they
#       are the whole reset: GXSTAT and DISP3DCNT, the matrix-stack unwind
#       (MTX_MODE / MTX_POP / MTX_IDENTITY for all three stacks), the 32-entry
#       SHININESS table, the default POLYGON_ATTR, TEXIMAGE_PARAM and
#       TEXPLTT_BASE, MTX_STORE into slot 0 and SWAP_BUFFERS. Not one of those
#       stores arrives. MODESEL recorded that the VIEWPORT word here is
#       bfff0000, the whole screen, which is also ntr::gx_reset's own fallback
#       rectangle, so THAT register costs nothing today; MTX_STORE and the
#       matrix-stack unwind are not free, for the reason the TITLETEX block
#       above already wrote down about MTX_STORE's slot.
#       func_020556d0's sibling func_02055624 -- GXSTAT, MTX_MODE, MTX_POP,
#       MTX_IDENTITY, the identical shape -- has been on the TIDEP_RESET_SYMS
#       list since run mg15, which is the precedent for routing this one.
#
# THE TREATMENT IS THE ONE THE PORT ALREADY USES FOR THIS CLASS and it costs
# nothing in the ledger: tools/hostgen.py rewrites the literal derefs to
# NTR_MMIO so each store dispatches through ntr::io_write, src/ is not edited,
# and every one of these translation units stays byte-matched. Each was run
# through hostgen standalone first and the output read: 20, 1, 9, 23, 5, 19, 5,
# 14, 19, 9 and 34 rewrites respectively, every one a register the routine's
# own literal pool already named.
#
# THEY GO ON PORT_HOSTGEN_TU RATHER THAN INTO ELEVEN BLOCKS OF THEIR OWN.
# port_read_lines substitutes a listed TU in every slice row that names it, as
# the row is read, so no slice can miss one and none can take the raw TU as
# well. That matters here beyond tidiness: src/Initialise3dGraphics.cpp is on
# THREE lists (slice_gate36.txt, slice_s4_slot0.txt and slice_w1l2.txt) and a
# hand-written cut against one of them would have left the other two adding the
# plain copy beside the generated one. The other ten are on one list each
# (slice_ov007, slice_vs twice, slice_gate50 three times, slice_mgm, and
# slice_w1l2 for the remaining three boot TUs). None of the eleven is named by
# a raw path anywhere in this file, so the per-source-property guard below has
# nothing to complain about.
#
# WHAT EACH ONE IS WORTH TODAY, measured on this lane's own baseline binary
# rather than assumed. The port reaches exactly ONE of the five registered
# scene classes: every capture reports "37 scene classes registered (ov003,
# ov005, ov006, ov007, ov075)" and then only ov007 takes slot hits, and every
# run ends "frames of scene 1 (SCENE_TITLE)". So func_ov007_020c19cc is on a
# live path and can show a picture; the ov075 pair, the ov080 trio and
# dScMiniGm_c::InitResources are on scenes nothing reaches yet, and routing
# them is right for the day those scenes run while changing nothing visible
# now. The four boot-setup TUs run on every scene including level 1, which is
# why they are switched separately from the other seven.
#
# ---- run link100 lane SAMECLASS2: THE SET RE-MEASURED, AND THREE CORRECTIONS
#
# The eleven rows above were banked without a verdict. This lane re-derived the
# set from the commit's own diff, re-ran every count, and A/B'd the two arms on
# three builds (build/port, build/port-plain with both switches ON, and two
# tracing builds). THE ROUTING IS RIGHT IN ALL ELEVEN CASES and none of it is
# backed out. Three of the claims above are wrong and are corrected here rather
# than edited away, because the wrong claim is the useful record.
#
# 1. THE REWRITE COUNTS RE-MEASURE EXACTLY. 20, 5, 19, 5, 14, 19, 34, 9, 23, 9
#    and 1 in this block's own order, the same multiset the paragraph above
#    lists. Every generated copy was lined up against its byte-matched source
#    and differs by NOTHING but an MMIO rewrite of the same width at the same
#    address, with no plain deref left behind. The two documented leftovers
#    (an unused pointer bind in func_ov075_0211a948's shape) are the binding
#    statements hostgen deliberately keeps.
#
# 2. func_ov007_020c19cc IS NOT ON A LIVE PATH TODAY. The paragraph above calls
#    it "the only one of the eleven on a path the port reaches today" and says
#    it can show a picture. It cannot, and that is why the banking lane saw no
#    pixel change and could not make the ribbon appear. It is THE DOODLE: its
#    three callers all come from the draw hub func_ov007_020b91b4, which the
#    render dispatcher func_ov007_020bcf90 reaches only in outer states 1..4,
#    the draw screen. MEASURED with the /Gh function-entry trace (lane
#    TRACEPORT's tools, frames 60..70 and 150..158 of scene 1, with and without
#    a 200-frame scripted stylus drag over the whole bottom screen):
#    func_ov007_020bcf90 is entered 20 times and the stylus driver
#    func_ov007_020c1db0 twice, while func_ov007_020b0358, func_ov007_020b91b4,
#    func_ov007_020b8fd4 and func_ov007_020c19cc itself are entered ZERO times.
#    The headless title never leaves the attract screen, so the draw screen is
#    not reachable from here. Routing it is still right; it is INERT today.
#
# 3. ov080 IS NOT dScEntry_c DUPLICATED AND IT IS NOT ON A SCENE. The paragraph
#    above reads the ov080 trio as "the same two routines again in ov080".
#    The register lists match because the Nitro G3 material-setup shape is the
#    same, but ov080 is an ACTOR overlay (port/ov080_syms.txt: the castle
#    interior's PAINTING, daPicGate_c actor 307, plus MontyMole, MontyMoleRock
#    and CrazedCrate). func_ov080_02125fd0 and func_ov080_0212677c are two of
#    the PAINTING's twelve state slots, seated in hal/actor_overlays.cpp's
#    g_painting_states, and func_ov080_02125460 is the material setter both of
#    them call. So they are on a live ACTOR's render path on level 2, not on an
#    unreachable scene -- which makes routing them worth more than the note
#    above claims, not less. They are inert today only because level 2 faults
#    during boot (c0000005 after the six "[paint] init" lines), IDENTICALLY on
#    both arms and equally on level 5, so it is a pre-existing level fault and
#    nothing to do with this change. Level 1 boots clean and its framebuffer is
#    byte-identical between the arms at 200 and 420 frames.
#
# WHAT THE FOUR BOOT TUs ARE ACTUALLY WORTH, which the block above left as a
# prediction. They are LIVE and the census proves it. SM64DS_PPU_AUDIT over 300
# frames of scene 1, this arm against SAMECLASS_GX_PLAIN=ON + SAMECLASS_BOOT_
# PLAIN=ON, differs on the boot frame and only there: PORT_WRITES 404 -> 617,
# MTX_MODE 29 -> 44, MTX_IDENTITY 8 -> 23, MTX_POP 8 -> 13, MTX_STORE 7 -> 9,
# SWAP_BUFFERS 2 -> 4, VIEWPORT 4 -> 6, and POLYGON_ATTR / TEXIMAGE_PARAM /
# PLTT_BASE / END_VTXS each +3. Every command in that list is a register one of
# the four boot TUs writes and none of the other seven writes any of them, and
# the trace says none of the seven is entered at all, so the whole delta is the
# boot group's. It costs nothing visible: VIEWPORT_X/Y/W/H, POLYGONS,
# SWAP_PARAM, PROJ_FP, PROJ_IDENTITY and POS_IDENTITY are identical on both
# arms, the title's last frame is byte-identical, and so is level 1's. The
# ROM's own GX reset now reaches the engine and lands on the state
# ntr::gx_reset had already produced.
#
# NOTHING ELSE OF THIS SHAPE IS LEFT. All 71 sources in the tree that name a
# geometry command port were cross-referenced against the configured
# build.ninja: 65 compile through hostgen, 4 are not compiled by any target at
# all (func_01ffde98, func_0200f4b4, func_0201a054, func_ov007_020caeac -- two
# of which DO store to command ports and will need routing the day a slice
# takes them), and the remaining 2 are src/func_02055464.c and
# src/func_02055490.c, which only READ GXSTAT's stack-level field and store
# nothing. Those two are already served correctly: ntr::gxstat_publish keeps
# the mapped window live for exactly those readers, by name, in ntr/gx.cpp.
# tools/gxport_guard.py now asks this question on every build so the next one
# refuses at configure time instead of waiting for somebody to read a literal
# pool.
#
# TWO KILL SWITCHES, not one, because the two groups carry different risk and a
# lane that has to back one out should not lose the other. Both print on every
# configure in both directions, for the reason run mg15's SQRT lane wrote down:
# a CMake option() CACHES, and an A/B switch that only announces one arm
# silently keeps the wrong one. Lane SAMECLASS2 used both, together, to build
# the pre-fix arm every measurement above is against, and gxport_guard.py reads
# them out of CMakeCache.txt and stands down by name when either is on.
option(SAMECLASS_GX_PLAIN
       "run link100 SAMECLASS: build the seven scene-local geometry-port TUs PLAIN (pre-fix arm)"
       OFF)
option(SAMECLASS_BOOT_PLAIN
       "run link100 SAMECLASS: build the four boot 3D-setup TUs PLAIN (pre-fix arm)"
       OFF)
set(SAMECLASS_GX_TU
    src/func_ov007_020c19cc.c
    src/func_ov075_0211a948.c
    src/func_ov075_0211afb0.c
    src/func_ov080_02125460.c
    src/func_ov080_02125fd0.c
    src/func_ov080_0212677c.c
    src/_ZN11dScMiniGm_c13InitResourcesEv.cpp)
set(SAMECLASS_BOOT_TU
    src/Initialise3dGraphics.cpp
    src/func_0205583c.c
    src/func_020556d0.c
    src/func_020554bc.c)
if(SAMECLASS_GX_PLAIN)
    message(STATUS "SAMECLASS: SAMECLASS_GX_PLAIN=ON -- the seven scene-local "
                   "geometry-port TUs build PLAIN. This is the PRE-FIX arm: "
                   "their stores latch in mapped memory and the geometry "
                   "engine is never told.")
else()
    message(STATUS "SAMECLASS: SAMECLASS_GX_PLAIN=OFF -- the seven scene-local "
                   "geometry-port TUs route through hostgen (shipped arm).")
    list(APPEND PORT_HOSTGEN_TU ${SAMECLASS_GX_TU})
endif()
if(SAMECLASS_BOOT_PLAIN)
    message(STATUS "SAMECLASS: SAMECLASS_BOOT_PLAIN=ON -- the four boot 3D "
                   "setup TUs build PLAIN. This is the PRE-FIX arm: the GX "
                   "reset, the matrix-stack unwind, the shininess table and "
                   "MTX_STORE never reach the engine.")
else()
    message(STATUS "SAMECLASS: SAMECLASS_BOOT_PLAIN=OFF -- the four boot 3D "
                   "setup TUs route through hostgen (shipped arm).")
    list(APPEND PORT_HOSTGEN_TU ${SAMECLASS_BOOT_TU})
endif()
get_filename_component(PORT_HOSTGEN_TU_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE)
set(PORT_HOSTGEN_TU_GEN "")
foreach(_hgt_rel IN LISTS PORT_HOSTGEN_TU)
    if(NOT EXISTS "${PORT_HOSTGEN_TU_ROOT}/${_hgt_rel}")
        message(FATAL_ERROR "whole-TU hostgen source ${_hgt_rel} does not exist; "
                "the substitution would be silently dropped and the defects it "
                "carries would go back into the link")
    endif()
    string(REGEX REPLACE "[.](c|cpp)$" ".cpp" _hgt_out_rel "${_hgt_rel}")
    set(_hgt_out "${CMAKE_BINARY_DIR}/host-src/${_hgt_out_rel}")
    add_custom_command(OUTPUT "${_hgt_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${_hgt_rel}
        DEPENDS "${PORT_HOSTGEN_TU_ROOT}/${_hgt_rel}"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${_hgt_rel}")
    file(RELATIVE_PATH _hgt_row "${PORT_HOSTGEN_TU_ROOT}" "${_hgt_out}")
    set("PORT_HOSTGEN_TU_ROW_${_hgt_rel}" "${_hgt_row}")
    # The row is matched as a REGEX by port_read_lines, so the dot in the
    # extension has to stop being "any character".
    string(REPLACE "." "\\." _hgt_re "${_hgt_rel}")
    set("PORT_HOSTGEN_TU_RE_${_hgt_rel}" "${_hgt_re}")
    set("PORT_HOSTGEN_TU_HITS_${_hgt_rel}" 0)
    list(APPEND PORT_HOSTGEN_TU_GEN "${_hgt_out}")
endforeach()

# ---- A PER-SOURCE PROPERTY DOES NOT FOLLOW THE SUBSTITUTION ----------------
#
# The substitution rewrites SLICE LISTS. It does not rewrite the paths spelled
# literally in this file, and a set_source_files_properties() call that names
# only the raw TU goes on setting a property for a source nothing compiles any
# more. The property is not reported missing: the generated TU simply builds
# without it.
#
# It has bitten once already and cost a build each time. Putting
# src/actors/dScMgCup_c.cpp on the list above moved its compile to the generated
# path, the /wd4716 row in PORT_FALLS_OFF_END_SOURCES stayed on the raw one, and
# the TU came back as `error C4716: 'dScMgCup_c::Virtual50': must return a
# value` -- a fall-off-the-end body this tree adjudicated long ago, reported as
# if it were new. That loop now sets the option on both paths.
#
# The other live instance is the one lane FACES2 had to leave alone.
# src/actors/daBombking_c.cpp carries `-D_ZN13MontyMoleRockD0Ev=
# func_ov078_02123804` at the block near line 10,360, which is what makes King
# Bob-omb's two throw states call his own throw body rather than the Monty Mole
# rock's destructor. Substituting that TU without moving the definition would
# not fail to build; it would build a King Bob-omb who calls a destructor when
# he throws. That is the only reason its PORT_HOST_ABI duplicate row is still
# open.
#
# So this refuses at configure rather than leaving the next lane to find it.
# Counted on this file's own text: a listed TU whose raw path is spelled here
# more often than its generated path is a property going missing. The check is
# plain string arithmetic on purpose -- a regex over 19,000 lines of paths that
# contain dots and brackets is a second thing to get right.
set(PORT_HOSTGEN_TU_RAW_OK
    # PROPERTIES LANGUAGE CXX, in the block near line 1,280, on a file that is
    # already .cpp and whose generated twin is .cpp as well: there is nothing
    # for the property to carry. Every other exemption needs the same sentence.
    src/actors/Player.cpp
    # The ov006 minigame scene family, run link100 wave 10 round 2, lane
    # SCENES2. Each of these two is named once by a PROPERTIES LANGUAGE CXX
    # call (line 2,106 for the card scene, line 9,546 for the trampoline),
    # and both files are ALREADY .cpp, as is the generated twin, so there is
    # nothing for the property to carry. The two calls date from when each
    # was a .c file with a //cpp marker; the sync renamed them and left the
    # rows behind. Nothing else in this file names either raw path.
    src/minigames/d_s_mg_card.cpp
    src/minigames/d_s_mg_trampoline.cpp)
file(READ "${CMAKE_CURRENT_LIST_FILE}" _hgp_self)
string(LENGTH "${_hgp_self}" _hgp_self_len)
foreach(_hgp_rel IN LISTS PORT_HOSTGEN_TU)
    list(FIND PORT_HOSTGEN_TU_RAW_OK "${_hgp_rel}" _hgp_exempt)
    if(NOT _hgp_exempt EQUAL -1)
        continue()
    endif()
    set(_hgp_raw "/../${_hgp_rel}\"")
    string(LENGTH "${_hgp_raw}" _hgp_raw_len)
    string(REPLACE "${_hgp_raw}" "" _hgp_cut "${_hgp_self}")
    string(LENGTH "${_hgp_cut}" _hgp_cut_len)
    math(EXPR _hgp_raw_n "(${_hgp_self_len} - ${_hgp_cut_len}) / ${_hgp_raw_len}")
    if(_hgp_raw_n GREATER 0)
        string(REGEX REPLACE "[.](c|cpp)$" ".cpp" _hgp_out "${_hgp_rel}")
        set(_hgp_gen "host-src/${_hgp_out}\"")
        string(LENGTH "${_hgp_gen}" _hgp_gen_len)
        string(REPLACE "${_hgp_gen}" "" _hgp_cut2 "${_hgp_self}")
        string(LENGTH "${_hgp_cut2}" _hgp_cut2_len)
        math(EXPR _hgp_gen_n
             "(${_hgp_self_len} - ${_hgp_cut2_len}) / ${_hgp_gen_len}")
        if(_hgp_gen_n LESS _hgp_raw_n)
            message(FATAL_ERROR
                "${_hgp_rel} is on PORT_HOSTGEN_TU, so the build compiles "
                "build/port/host-src/${_hgp_out} instead of it -- but this "
                "file names the raw path ${_hgp_raw_n} time(s) and the "
                "generated path ${_hgp_gen_n}. Whatever those calls set is "
                "being set for a source nothing compiles. Name BOTH paths in "
                "each of them (the dScMgPanel_c and d_a_propeller_heyho blocks "
                "are the shape), or add the row to PORT_HOSTGEN_TU_RAW_OK "
                "above with the sentence that says why the property does not "
                "matter.")
        endif()
    endif()
endforeach()

# ---- THE SYNC FACES ---------------------------------------------------------
#
# 2026-09-13, main -> port sync, lane FACES1.  The sync's last link wall is the
# flat ROM names whose bodies the synced tree now defines as __thiscall C++
# MEMBERS.  The reference is an extern "C" declaration, so the call is __cdecl
# with the receiver as the first stack argument; the definition takes it in ECX.
# An /alternatename is a NAME bridge and never an ABI bridge, so those rows
# cannot be closed with one -- the alias would link, the receiver would be
# garbage, and nothing would say so (hal/method_faces.cpp failure class 3, and
# hal/lk4_solidheap_seat.cpp's measured fault).  What closes them is a FACE: a
# one-line extern "C" forwarder whose body is the qualified call
# ((Cls *)self)->Cls::meth(args).
#
# The rows are CHECKED IN, at port/faces_sync.txt, one line per face naming the
# decorated definition it binds to and the ROM address that proves the binding.
# tools/facegen.py --sync re-derives every row from that ledger and REFUSES any
# row whose binding no longer holds; a refused row fails the build rather than
# quietly leaving the link, because a face that disappears is a receiver that
# goes back to garbage.  The tool generates nothing that is not in the ledger.
#
# A BUILD-TIME custom command, not an execute_process at configure, for the
# reason the hostgen blocks above use one: the derivation runs undname over
# every row and there is no reason to pay for it on a configure that changed
# nothing.  DEPENDS names the ledger and the tool, which are the two inputs
# that change the OUTPUT.  config/**/symbols.txt is an input to the CHECK and
# not to the code -- the emitted face binds by name, and the address is the
# proof the ledger carries -- so a config rename shows up the next time the
# ledger is regenerated rather than silently changing a binary.
set(PORT_FACES_SYNC_LEDGER "${CMAKE_CURRENT_SOURCE_DIR}/faces_sync.txt")
set(PORT_FACES_SYNC_GEN "${CMAKE_BINARY_DIR}/host-src/faces_sync_gen.cpp")
port_configure_input("${PORT_FACES_SYNC_LEDGER}")
add_custom_command(OUTPUT "${PORT_FACES_SYNC_GEN}"
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/facegen.py"
            --sync "${PORT_FACES_SYNC_LEDGER}"
            --root "${CMAKE_CURRENT_SOURCE_DIR}/.."
            --out "${PORT_FACES_SYNC_GEN}"
    DEPENDS "${PORT_FACES_SYNC_LEDGER}"
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/facegen.py"
    COMMENT "facegen --sync faces_sync.txt")

macro(port_read_lines _prl_path _prl_var)
    port_configure_input("${_prl_path}")
    # Apply the whole-TU hostgen substitution declared above to every row as it
    # is read, so no slice list and no target can miss it or take the raw TU as
    # well.
    #
    # THE SUBSTITUTION IS DONE ON THE TEXT, BEFORE file(STRINGS), AND NOT ON THE
    # LIST AFTERWARDS. Every list() sub-command in CMake flattens an element
    # that contains a semicolon: file(STRINGS) escapes those correctly, and
    # list(TRANSFORM) or a foreach/list(APPEND) rebuild hands back TWO elements
    # where there was one. Dozens of slice COMMENTS in this tree contain a
    # semicolon ("... _02106168; review found the count low ..." in
    # slice_ppp.txt is one), so the tail of each became a fresh element that no
    # longer began with `#` and every loop below read it as a source path.
    # Measured, not guessed: cmake -P on a three-line fixture turns a 3-element
    # list into a 4-element one across one list(TRANSFORM). Rewriting the file's
    # TEXT and letting file(STRINGS) do the escaping once cannot do that.
    set(_prl_read "${_prl_path}")
    if(PORT_HOSTGEN_TU)
        file(READ "${_prl_path}" _prl_text)
        set(_prl_text "\n${_prl_text}\n")
        set(_prl_hit FALSE)
        foreach(_prl_tu IN LISTS PORT_HOSTGEN_TU)
            # Whole-line matches only, in both line endings the slice lists use
            # (24 of the 264 are CRLF).
            string(REPLACE "\n${_prl_tu}\n"
                           "\n${PORT_HOSTGEN_TU_ROW_${_prl_tu}}\n"
                           _prl_new "${_prl_text}")
            string(REPLACE "\n${_prl_tu}\r\n"
                           "\n${PORT_HOSTGEN_TU_ROW_${_prl_tu}}\r\n"
                           _prl_new "${_prl_new}")
            if(NOT _prl_new STREQUAL _prl_text)
                set(_prl_text "${_prl_new}")
                set(_prl_hit TRUE)
                math(EXPR "PORT_HOSTGEN_TU_HITS_${_prl_tu}"
                     "${PORT_HOSTGEN_TU_HITS_${_prl_tu}} + 1")
            endif()
        endforeach()
        if(_prl_hit)
            get_filename_component(_prl_name "${_prl_path}" NAME)
            set(_prl_read "${CMAKE_BINARY_DIR}/slice-subst/${_prl_name}")
            file(WRITE "${_prl_read}" "${_prl_text}")
        endif()
    endif()
    file(STRINGS "${_prl_read}" ${_prl_var})
endmacro()

# tools/tierscan.py, which execute_process() runs at configure time to split the
# shared and the per-target compile tiers.  Its OUTPUT, tierscan_split.cmake, is
# include()d and CMake has always tracked that; the script that writes it was
# tracked by nothing at all, so a fix to the tier rule did not reach a
# configured tree.
port_configure_input("${CMAKE_CURRENT_SOURCE_DIR}/tools/tierscan.py")

# WHAT IS STILL NOT REGISTERED, stated rather than left to be discovered:
#   - the ~10600 sources tierscan.py READS to decide which TU is tier-shared and
#     which is per-target.  Registering them would reconfigure on every source
#     edit, which is every build, and would give back the whole saving.  The
#     residual is narrow and named: a source that references NONE of the four
#     divergent defines today (SM64DS_STAGE_SLOT6_ROM, SM64DS_STAGE_SLOT9_ROM,
#     NTR_WIDE_RT, NTR_HIRES) and starts referencing one, with no other
#     configure input moving, keeps its old shared classification until the next
#     reconfigure.  Five files in the whole tree mention any of the four today
#     (port/hal/stage_bridges.cpp, port/ntr/include/ntr/ppu.h, port/ntr/ppu.cpp,
#     port/ntr/ppu_sub.cpp, port/tests/walk_window.cpp), and introducing a NEW
#     divergent define means editing this file, which IS registered.
#   - the git tip embedded in port_gittip.c by the file(WRITE) below.  It now
#     reflects the commit at the last CONFIGURE rather than the last build.  It
#     is a diagnostic string in fault dumps, and registering .git would
#     reconfigure on every commit, which the house laws ask lanes to do often.
#     Touch this file, or pass any argument to build-port.cmd, to refresh it.

# Gate 1: compile the manifest slice out of ../src plus the HAL, link the
# smoke runner. 32-bit host only -- platform.h enforces it at compile time.

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Resource-pack scripts are part of the shipped port, so Lua is built from the
# pinned vendored source instead of depending on a user's machine-wide install.
file(GLOB LUA_RESOURCE_PACK_SOURCES
    "${CMAKE_CURRENT_SOURCE_DIR}/vendor/lua/src/*.c")
list(FILTER LUA_RESOURCE_PACK_SOURCES EXCLUDE REGEX "/lua\.c$")
list(FILTER LUA_RESOURCE_PACK_SOURCES EXCLUDE REGEX "/luac\.c$")
list(FILTER LUA_RESOURCE_PACK_SOURCES EXCLUDE REGEX "/ltests\.c$")
list(FILTER LUA_RESOURCE_PACK_SOURCES EXCLUDE REGEX "/onelua\.c$")
add_library(lua_resource_pack STATIC ${LUA_RESOURCE_PACK_SOURCES})
target_include_directories(lua_resource_pack PUBLIC
    "${CMAKE_CURRENT_SOURCE_DIR}/vendor/lua/src")
if(MSVC)
    target_compile_options(lua_resource_pack PRIVATE /wd4244 /wd4267 /wd4996)
endif()

add_executable(resource_pack_probe
    tests/resource_pack_probe.cpp
    hal/resource_pack.cpp)
target_include_directories(resource_pack_probe PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}/hal")
target_link_libraries(resource_pack_probe PRIVATE lua_resource_pack)

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate1.txt" SLICE_LINES)
set(SLICE_SOURCES "")
foreach(line IN LISTS SLICE_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

add_executable(smoke
    tests/smoke.cpp
    hal/cstd_div.c
    hal/os_time.cpp
    hal/shims.cpp
    ${SLICE_SOURCES})

target_include_directories(smoke PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")

target_compile_definitions(smoke PRIVATE SM64DS_PLATFORM_PC)
if(MSVC)
    # The decomp C uses guest idioms MSVC warns about; keep the build quiet
    # enough that a NEW warning is visible. /W3 stays on.
    target_compile_options(smoke PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Gate 2: the allocator family + torture smoke, its own binary so gate 1
# stays a stable baseline.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate2.txt" SLICE2_LINES)
set(SLICE2_SOURCES "")
foreach(line IN LISTS SLICE2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

add_executable(smoke_heap tests/smoke_heap.cpp hal/heap_globals.cpp ${SLICE2_SOURCES})
target_include_directories(smoke_heap PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_compile_definitions(smoke_heap PRIVATE SM64DS_PLATFORM_PC)
if(MSVC)
    target_compile_options(smoke_heap PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# LANE SMOKELINK2 (run link100 wave 10 round 2): THE GATE-2 SMOKE'S HALF OF THE
# SYNC.  smoke_heap.exe stopped linking at the 09-14 sync with twelve
# unresolved externals, every one of them a flat Itanium name whose body this
# target already compiles under an MSVC decoration.  The twelve close three
# different ways and the split is measured, not chosen:
#
#   4  ordinary non-static members and constructors (AllocateForwards,
#      AllocateBackwards, ExpandingHeapAllocator::ExpandingHeapAllocator,
#      NestedHeapIterator::NestedHeapIterator).  Receiver in ECX, so per
#      port/faces_sync.txt's header an /alternatename would link and hand the
#      callee garbage.  They get FACES, generated by the same
#      port/tools/facegen.py --sync from port/faces_sync_smoke_heap.txt, whose
#      four rows are copied verbatim out of port/faces_sync.txt and re-derived
#      against their ROM addresses on every build.
#   5  static members and data (CreateNode, LinkNode, UnlinkNode,
#      data_020a4d34, data_020a4d38).  Both sides __cdecl or plain storage, so
#      a name bridge IS an ABI bridge: port/hal/smoke_aliases_heap.cpp carries
#      the five /alternatename rows, copied verbatim from hal/cxx_aliases.cpp.
#   3  the harness's own calls.  port/tests/smoke_heap.cpp is host test code,
#      so it now includes Heap.h and ExpandingHeapAllocator.h and calls the
#      members as C++.
#
# The generated file is SEPARATE from ${PORT_FACES_SYNC_GEN} on purpose.  That
# one is 1925 rows, every row a call into a C++ member, and this target links
# 26 objects: it would trade twelve unresolved names for hundreds.  There is no
# /Gy in this build, so there is no function-level COMDAT for /OPT:REF to drop
# either.  A four-row ledger costs four faces.
set(PORT_FACES_SYNC_SMOKE_HEAP_LEDGER
    "${CMAKE_CURRENT_SOURCE_DIR}/faces_sync_smoke_heap.txt")
set(PORT_FACES_SYNC_SMOKE_HEAP_GEN
    "${CMAKE_BINARY_DIR}/host-src/faces_sync_smoke_heap_gen.cpp")
port_configure_input("${PORT_FACES_SYNC_SMOKE_HEAP_LEDGER}")
add_custom_command(OUTPUT "${PORT_FACES_SYNC_SMOKE_HEAP_GEN}"
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/facegen.py"
            --sync "${PORT_FACES_SYNC_SMOKE_HEAP_LEDGER}"
            --root "${CMAKE_CURRENT_SOURCE_DIR}/.."
            --out "${PORT_FACES_SYNC_SMOKE_HEAP_GEN}"
    DEPENDS "${PORT_FACES_SYNC_SMOKE_HEAP_LEDGER}"
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/facegen.py"
    COMMENT "facegen --sync faces_sync_smoke_heap.txt")
target_sources(smoke_heap PRIVATE
    hal/smoke_aliases_heap.cpp "${PORT_FACES_SYNC_SMOKE_HEAP_GEN}")

# LANE SMOKELINK3 (run link100 wave 10 round 2): THE SAME THREE MECHANISMS, ONCE.
#
# SMOKELINK2 wrote the block above by hand for smoke_heap and proved the lever.
# Fourteen targets stopped linking at the 09-14 sync and the remaining twelve of
# them close the same three ways, so the wiring is a function rather than twelve
# copies of twenty lines.  The function adds nothing a target does not name:
#
#   faces_sync_smoke_<name>.txt   a SUBSET LEDGER, every row copied verbatim out
#                                 of port/faces_sync.txt and re-derived against
#                                 its ROM address by the SAME tools/facegen.py
#                                 --sync on every build.  This is what closes a
#                                 non-static member or a constructor: the
#                                 receiver is in ECX and port/faces_sync.txt's
#                                 header says an /alternatename is a NAME bridge
#                                 and never an ABI bridge.
#   hal/smoke_aliases_<name>.cpp  /alternatename rows, copied verbatim out of
#                                 hal/cxx_aliases.cpp, for the names whose two
#                                 sides already agree about the ABI (statics,
#                                 data, and same-class thiscall spellings).  A
#                                 file of nothing but linker directives compiles
#                                 to an object with no code, no data and no
#                                 external reference.
#   SRC <files...>                translation units that already exist in this
#                                 tree, that walk_window already compiles, and
#                                 that this target simply did not list.  Never a
#                                 new definition.
#
# Either file may be absent: a target with no ledger rows gets no generated
# face, a target with no alias rows gets no directive object.  The ledger is
# deliberately NOT ${PORT_FACES_SYNC_GEN}: that one is 1925 rows and every row
# CALLS a C++ member, so putting it on a 54-object harness would trade a dozen
# unresolved names for hundreds, and there is no /Gy in this build for /OPT:REF
# to drop the difference.
function(port_smoke_relink _psr_target)
    cmake_parse_arguments(PSR "" "" "SRC" ${ARGN})
    set(_psr_ledger "${CMAKE_CURRENT_SOURCE_DIR}/faces_sync_smoke_${_psr_target}.txt")
    set(_psr_alias  "${CMAKE_CURRENT_SOURCE_DIR}/hal/smoke_aliases_${_psr_target}.cpp")
    set(_psr_add "")
    if(EXISTS "${_psr_ledger}")
        set(_psr_gen "${CMAKE_BINARY_DIR}/host-src/faces_sync_smoke_${_psr_target}_gen.cpp")
        port_configure_input("${_psr_ledger}")
        add_custom_command(OUTPUT "${_psr_gen}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/facegen.py"
                    --sync "${_psr_ledger}"
                    --root "${CMAKE_CURRENT_SOURCE_DIR}/.."
                    --out "${_psr_gen}"
            DEPENDS "${_psr_ledger}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/facegen.py"
            COMMENT "facegen --sync faces_sync_smoke_${_psr_target}.txt")
        list(APPEND _psr_add "${_psr_gen}")
    endif()
    if(EXISTS "${_psr_alias}")
        list(APPEND _psr_add "${_psr_alias}")
    endif()
    foreach(_psr_src IN LISTS PSR_SRC)
        list(APPEND _psr_add "${CMAKE_CURRENT_SOURCE_DIR}/../${_psr_src}")
    endforeach()
    target_sources(smoke_${_psr_target} PRIVATE ${_psr_add})
endfunction()

# Gate 3a: root heap + Memory:: layer over the gate-2 allocator.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate3a.txt" SLICE3A_LINES)
set(SLICE3A_SOURCES "")
foreach(line IN LISTS SLICE3A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE3A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

add_executable(smoke_roots tests/smoke_roots.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES})
target_include_directories(smoke_roots PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_compile_definitions(smoke_roots PRIVATE SM64DS_PLATFORM_PC)
if(MSVC)
    target_compile_options(smoke_roots PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# The ntr platform layer: imported host DS hardware (see ntr/README.md).
# Compiled as its own lib so every gate binary can link the pieces it needs.
add_library(ntr STATIC
    ntr/io.cpp ntr/gx.cpp ntr/texture.cpp ntr/ppu.cpp ntr/ppu_sub.cpp ntr/ppu_audit.cpp ntr/lz77.cpp
    ntr/rt.cpp ntr/runtime.cpp ntr/fs.cpp ntr/bmd.cpp ntr/ipc.cpp
    ntr/hdtex.cpp ntr/smooth.cpp)
target_include_directories(ntr PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/ntr/include")
# ntr/runtime.cpp hosts two DS DMA globals (data_020a60c4/data_020a6460) that
# are real save state, so it needs hal/dsstate_seg.h. PRIVATE: only this
# library reads it, consumers keep their own include set.
target_include_directories(ntr PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
if(MSVC)
    target_compile_options(ntr PRIVATE /wd4311 /wd4312)
endif()

# ntr_2x, THE FIXED 512x384 TIER, IS GONE. It existed for exactly one consumer,
# walk_window, and walk_window links ntr_wide_rt below instead: same 512x384
# picture when the Aspect key is 0 (its default), and a wider one when it is not.
# Nothing else ever linked it, so leaving it here would have been a second copy
# of eleven translation units built every configure to be thrown away. The
# NTR_HIRES2 tier itself still exists in ntr/ppu.h -- ntr_wide_rt's 4:3 default
# IS that tier's extent -- there is just no library compiled at it.

# THE RUNTIME-SELECTABLE 16:9 LAYER, and the one walk_window now links. Its
# framebuffer is the wide maximum (1024x576) but the ACTIVE render size is chosen
# at boot from the Aspect settings key (ntr::configure_aspect): 512x384
# 4:3 -- byte-for-byte the old 2x window -- when the key is off, the full
# 1024x576 when it is on. That is what makes one exe present either aspect
# without a second build. NTR_WIDE_RT is PUBLIC so it reaches walk_window's own
# sources (ppu.h's dims, the runtime widescreen branches) exactly as the tier
# defines above reach their targets.
add_library(ntr_wide_rt STATIC
    ntr/io.cpp ntr/gx.cpp ntr/texture.cpp ntr/ppu.cpp ntr/ppu_sub.cpp ntr/ppu_audit.cpp ntr/lz77.cpp
    ntr/rt.cpp ntr/runtime.cpp ntr/fs.cpp ntr/bmd.cpp ntr/ipc.cpp
    ntr/hdtex.cpp ntr/smooth.cpp)
target_include_directories(ntr_wide_rt PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/ntr/include")
target_include_directories(ntr_wide_rt PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_compile_definitions(ntr_wide_rt PUBLIC NTR_WIDE_RT)
if(MSVC)
    target_compile_options(ntr_wide_rt PRIVATE /wd4311 /wd4312)
endif()

# The same layer at 1024x768 for the interactive window; the smokes keep
# the DS-native lib (their reference pixel counts depend on 256x192).
add_library(ntr_hires STATIC
    ntr/io.cpp ntr/gx.cpp ntr/texture.cpp ntr/ppu.cpp ntr/ppu_sub.cpp ntr/ppu_audit.cpp ntr/lz77.cpp
    ntr/rt.cpp ntr/runtime.cpp ntr/fs.cpp ntr/bmd.cpp ntr/ipc.cpp
    ntr/hdtex.cpp ntr/smooth.cpp)
target_include_directories(ntr_hires PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/ntr/include")
# ntr/runtime.cpp hosts two DS DMA globals (data_020a60c4/data_020a6460) that
# are real save state, so it needs hal/dsstate_seg.h. PRIVATE: only this
# library reads it, consumers keep their own include set.
target_include_directories(ntr_hires PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_compile_definitions(ntr_hires PUBLIC NTR_HIRES)
if(MSVC)
    target_compile_options(ntr_hires PRIVATE /wd4311 /wd4312)
endif()

# _penter's definition, when PORT_FN_TRACE is on. It goes in the three ntr
# libraries rather than in each executable because every executable in this
# build links exactly one of them, and every object in a traced build refers to
# _penter, so the archive member is always pulled in. Empty otherwise: a normal
# build does not compile this file.
if(PORT_FN_TRACE)
    foreach(_fnt_lib ntr ntr_wide_rt ntr_hires)
        target_sources(${_fnt_lib} PRIVATE "${PORT_FN_TRACE_SRC}")
    endforeach()
endif()

# Gate 3b: SharedFilePtr over the host card seam; assets come from the
# repo's extracted/ tree + asset catalog, root baked in (env-overridable).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate3b.txt" SLICE3B_LINES)
set(SLICE3B_SOURCES "")
foreach(line IN LISTS SLICE3B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE3B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

get_filename_component(PORT_REPO_ROOT_ABS "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE)
# What the binary EMBEDS, distinct from what the build USES. A ROM-clean build
# compiles out the only reader of this path (hal/asset_root_refuse.cpp), so the
# shipped exe must not carry the build machine's directory in its strings.
set(PORT_REPO_ROOT_EMBED "${PORT_REPO_ROOT_ABS}")
if(PORT_ROM_CLEAN)
    set(PORT_REPO_ROOT_EMBED "")
endif()

# PORT_REPO_ROOT IS SCOPED TO ITS TEN READERS, NOT PUT ON EVERY COMMAND LINE.
#
# It used to be a target-level define, which put the BUILD MACHINE'S ABSOLUTE
# PATH on all 32,716 compile command lines while exactly ten source files in
# the tree read it. Two costs came out of that. The command line is part of
# every compiler cache's key, so two worktrees of the same commit -- ten lanes
# build on one box tonight -- produced different keys for identical objects and
# could never share a cached compile. And the path went into targets that never
# needed it, which is noise in every log and every /showIncludes trace.
#
# The ten readers are listed here and get it as a SOURCE property, so the
# define reaches exactly them and no other command line carries the path.
# PORT_REPO_ROOT_DEF below is the empty variable that the target-level uses
# were replaced with; leaving it defined (rather than deleting the arguments)
# keeps every target_compile_definitions call's shape intact, so an appended
# block that still spells the PORT_REPO_ROOT define out itself keeps
# working -- it just puts the path back on that one target's command lines.
#
# ADDING AN ELEVENTH READER MEANS ADDING IT HERE. Seven of the ten carry
# `#ifndef PORT_REPO_ROOT / #define PORT_REPO_ROOT "."`, so a missing entry
# does not fail the compile -- it makes that file look for the asset tree in
# the current directory at run time. The three tests (smoke_gx, smoke_soak,
# smoke_soak_anim) have no fallback and fail the build loudly.
set(PORT_REPO_ROOT_DEF "")
set(PORT_REPO_ROOT_READERS
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/fs.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/fs_mods.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/fs_names.cpp"
    # The eleventh reader (run link100, lane LOADOV). hal/nitrofs_boot.cpp
    # reads build/assets/nitrofs.tsv for the cartridge header's overlay-table
    # words (+0x50..+0x5c) the way hal/fs_names.cpp reads it for the FNT and
    # FAT words, and it carries the same #ifndef PORT_REPO_ROOT / "." fallback,
    # so a build that forgets this line looks in the working directory and says
    # so at run time rather than failing to compile.
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/nitrofs_boot.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/stage_geom.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/romdata_loader.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/asset_root_refuse.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/sdat/sdat.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/tests/smoke_gx.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/tests/smoke_soak.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/tests/smoke_soak_anim.cpp")
foreach(_rr IN LISTS PORT_REPO_ROOT_READERS)
    set_property(SOURCE "${_rr}" APPEND PROPERTY COMPILE_DEFINITIONS
                 "PORT_REPO_ROOT=\"${PORT_REPO_ROOT_EMBED}\"")
endforeach()


# Build-time git tip embed (fault_probe.h's rich dump reports which build
# crashed). Resolved at configure time via `git rev-parse`; a re-configure on a
# new commit refreshes it. Emitted as a tiny .c so any target that wants the tip
# just links it. Falls back to "unknown" outside a git checkout, which matches
# fault_probe.h's weak default.
find_program(GIT_EXECUTABLE git)
set(PORT_GIT_TIP "unknown")
if(GIT_EXECUTABLE)
    execute_process(
        COMMAND "${GIT_EXECUTABLE}" -C "${PORT_REPO_ROOT_ABS}" rev-parse --short HEAD
        OUTPUT_VARIABLE PORT_GIT_TIP_OUT
        OUTPUT_STRIP_TRAILING_WHITESPACE
        ERROR_QUIET RESULT_VARIABLE PORT_GIT_RC)
    if(PORT_GIT_RC EQUAL 0 AND PORT_GIT_TIP_OUT)
        set(PORT_GIT_TIP "${PORT_GIT_TIP_OUT}")
    endif()
endif()
set(PORT_GITTIP_C "${CMAKE_BINARY_DIR}/host-src/port_gittip.c")
file(WRITE "${PORT_GITTIP_C}"
    "/* generated by CMake -- the git tip this build was cut from */\n"
    "const char port_build_gittip[] = \"${PORT_GIT_TIP}\";\n")

# Gate 4a: the game's display-list submission machinery over the ntr GX.
# These src/ files touch MMIO textually, so they build from hostgen-emitted
# copies under the build tree -- src/ itself is never edited.
set(GATE4A_SYMS
    func_0205532c func_02055388 func_020553a4 func_02055780
    func_0205a358 func_0205a290 func_0205a21c func_02056e98 func_02059fa8)
set(GATE4A_GEN "")
foreach(sym IN LISTS GATE4A_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE4A_GEN "${sym_out}")
endforeach()

# THE GRAPHICS-CARD OPAQUE PASS'S OWN RULES (run hd2, lane GPU2). Small on
# purpose: it links the renderer, the shared device and the settings reader
# and nothing else, drives the geometry ports by hand and grades RELATIONS
# BETWEEN PIXELS rather than a picture. It asks for WARP, the software
# Direct3D device Windows ships, so the answers are the API's and not one
# vendor's; the in-process A/B covers real hardware on real scenes.
if(WIN32)
    add_executable(smoke_gpu_raster
        tests/smoke_gpu_raster.cpp
        hal/gpu_raster.cpp
        hal/gpu_device.cpp
        hal/host_settings.cpp
        hal/os_arena.cpp)
    target_include_directories(smoke_gpu_raster PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}"
        "${CMAKE_CURRENT_SOURCE_DIR}/../include")
    target_link_libraries(smoke_gpu_raster PRIVATE ntr)
    target_compile_definitions(smoke_gpu_raster PRIVATE SM64DS_PLATFORM_PC
        ${PORT_REPO_ROOT_DEF})
endif()

add_executable(smoke_gx tests/smoke_gx.cpp ${GATE4A_GEN})
target_include_directories(smoke_gx PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_gx PRIVATE ntr)
target_compile_definitions(smoke_gx PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_gx PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Gate 4b: the whole Model pipeline. Adds the material-bind and matrix
# feeders to the hostgen set and the Model/render slice on top of everything.
set(GATE4B_SYMS func_02044b30 Geometry_MatrixMultiply3x3 func_02055998
    func_02044534 func_0204488c NormalizeVec3)
set(GATE4B_GEN "")
foreach(sym IN LISTS GATE4B_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE4B_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate4b.txt" SLICE4B_LINES)
set(SLICE4B_SOURCES "")
foreach(line IN LISTS SLICE4B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE4B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Lane TEX2: ONE ROW OF slice_gate4b IS SERVED FROM host-src, for three targets only.
#
# src/_ZN5Model8LoadFileER13SharedFilePtr.cpp ends its numRefs==1 branch in
# ptr.ReallocateModelFile(), the ROM's heap shrink-to-fit (func_02017060 ->
# Heap::Reallocate), which hands the texel payload Model::LoadTexAndPal has just
# uploaded back to the allocator. The port declines that shrink on its OTHER
# model path already -- port_model_shrink_enabled in hal/level_boot.cpp, applied
# to src/func_02016ff4.cpp by hostgen's VIRTUAL_CALL table -- and has to decline
# it here for the same reason, one level deeper: a level change runs the ROM's
# CleanCommonModelDataArr but does not release the model files, so the next
# Model::SetFile -> Model::DoSetFile re-enters AddToCommonModelDataArr on a file
# the emptied array no longer knows, and LoadTexAndPal uploads the freed block's
# heap header instead of texels. Stars, coins, Yoshi's egg and the completed
# Bob-omb painting come out black with scattered pixels after a level change and
# are correct on a direct boot; measured in out/TEX2/card_texshrink.md.
#
# WHY THE GATE IS AT THE CALL AND NOT AT THE NAME. A host body under
# ?ReallocateModelFile@SharedFilePtr@@QAEXXZ would stop the matched TU being
# referenced and cost a linked TU, which is the shadow SHADOWS2 retired in
# a731fbdc7. Gating the CALL through hostgen keeps the ROM body referenced and
# linked, and linkage stays at 7953.
#
# WHY A FILTERED LIST. slice_gate4b.txt is taken by FOURTEEN targets and only
# three of them (smoke_player, walk_window, walk_window_hires) take GATE35_GEN,
# so commenting the row out of the slice -- the way slice_gate16.txt does for
# func_02016ff4 -- would pull the TU out of the eleven smoke targets as well.
# This is the same shape SLICE10_CAM_SOURCES already uses for HitDeathPlane,
# func_0203d974, CollectStar and func_02049018: a filtered copy of the list,
# consumed only by the targets that also take the generated row.
set(SLICE4B_HOSTGEN_SOURCES "")
foreach(src IN LISTS SLICE4B_SOURCES)
    if(src MATCHES "/_ZN5Model8LoadFileER13SharedFilePtr\\.cpp$")
        continue()
    endif()
    list(APPEND SLICE4B_HOSTGEN_SOURCES "${src}")
endforeach()

# ROM constants (sine table, default matrices): generated locally from the
# extracted arm9 image so Nintendo bytes never enter the repo.
# ROM-CLEAN (2026-08-10): when ON, romdata.py / ovdata.py emit ZEROED arrays and
# a sidecar blob part; the ROMBLOB command below consolidates every part into
# build/assets/romdata.bin (+ manifest + dispatch) and hal/romdata_loader.cpp
# loads it at boot, so the shipped exe embeds no ROM bytes. Default OFF: every
# other target keeps baking the bytes in exactly as before -- see
# out/rom-clean/DESIGN.md and port/tools/romblob_common.py.
option(PORT_ROM_CLEAN "Move baked ROM tables out of the exe into a runtime blob" OFF)
if(PORT_ROM_CLEAN)
    set(ROMCLEAN_FLAG --rom-clean)
else()
    set(ROMCLEAN_FLAG "")
endif()

# LINK-ONLY (2026-09-06): build the REFERENCE GRAPH with no cartridge present.
# When ON, romdata.py / ovdata.py stand a config-length SYNTHETIC image in for
# the extracted images -- the real address in every reloc site, zero everywhere
# else -- so a machine that has never seen the ROM can still link walk_window
# and answer tools/linkage.py. Measured on this tree: the image word at a
# kind:load reloc site equals the reloc's stated target for 40,469 of 40,469
# file-backed sites across all 103 overlays, so every word the reference graph
# is built out of comes back exactly, and the emitters' own desync refusals
# pass because they are true rather than because they were bypassed.
#
# The resulting exe is DEAD ON PURPOSE: every table is zero, the 13 archive
# mounts carry the string LINK-ONLY-BUILD-NOT-A-GAME instead of their narc
# paths (so it cannot open one file), and build/port/LINK_ONLY.stamp sits
# beside it. Default OFF, and OFF is byte-identical to before -- the flag below
# is the empty string and no emitter command line changes.
#
# TWO GATES. This option supplies the argv flag; SM64DS_LINK_ONLY=1 must ALSO
# be in the environment at build time or every emitter refuses. A stray
# argument cannot reach the mode and neither can a stray shell export. See
# port/tools/link_only.py.
option(PORT_LINK_ONLY "Emit ROM mounts from config alone (no cartridge; DEAD exe)" OFF)
if(PORT_LINK_ONLY)
    set(LINKONLY_FLAG --link-only)
    message(WARNING
        "PORT_LINK_ONLY=ON: every ROM table will be ZERO and the executable "
        "will not run. This build measures link coverage only.")
else()
    set(LINKONLY_FLAG "")
endif()

# Every emitter that ships ROM bytes appends its .blobmap here; ROMBLOB reads them.
set(ROMCLEAN_PARTS "")

set(ROMDATA_C "${CMAKE_BINARY_DIR}/host-src/romdata.c")
add_custom_command(OUTPUT "${ROMDATA_C}"
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/romdata.py" "${ROMDATA_C}"
            ${ROMCLEAN_FLAG} ${LINKONLY_FLAG}
    DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/romdata.py"
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob_common.py"
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/link_only.py"
    COMMENT "romdata from extracted/arm9_dec.bin")
if(PORT_ROM_CLEAN)
    list(APPEND ROMCLEAN_PARTS "${ROMDATA_C}.blobmap")
endif()

add_executable(smoke_model tests/smoke_model.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${GATE4A_GEN} ${GATE4B_GEN} "${ROMDATA_C}")
target_include_directories(smoke_model PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_model PRIVATE ntr)
target_compile_definitions(smoke_model PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_model PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Gate 5: the fiber frame loop -- game-shaped frames, host-rastered.
add_executable(smoke_frames tests/smoke_frames.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${GATE4A_GEN} ${GATE4B_GEN} "${ROMDATA_C}")
target_include_directories(smoke_frames PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_frames PRIVATE ntr)
target_compile_definitions(smoke_frames PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_frames PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Gate 4d: the catalog soak -- every model through the game pipeline.
add_executable(smoke_soak tests/smoke_soak.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${GATE4A_GEN} ${GATE4B_GEN} "${ROMDATA_C}")
target_include_directories(smoke_soak PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_soak PRIVATE ntr)
target_compile_definitions(smoke_soak PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_soak PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Gate 8: collision -- the octree walk over real KCL data. cstd::sqrt
# drives the hardware sqrt unit through literal MMIO -> hostgen.
set(GATE8_SYMS _ZN4cstd4sqrtEy _ZN4cstd11fdiv_resultEv _ZN4cstd16reciprocal_asyncE5Fix12IiE
    Matrix4x3_ApplyInPlaceToScale)
set(GATE8_GEN "")
foreach(sym IN LISTS GATE8_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE8_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate8.txt" SLICE8_LINES)
set(SLICE8_SOURCES "")
foreach(line IN LISTS SLICE8_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE8_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Three files the SPHERE pass needs that later gates already carry: gate 10 has
# func_02039794 and func_02037e58, gate 13 has DotVec3. The binaries that stop
# at gate 8/9 (smoke_clsn, smoke_actor) get them here; smoke_player and
# walk_window get them from their own slices, and adding them in both places
# would be a duplicate source in one target.
set(GATE8_EXTRA_SOURCES
    "${PORT_REPO_ROOT_ABS}/src/func_02039794.c"
    "${PORT_REPO_ROOT_ABS}/src/func_02037e58.c"
    "${PORT_REPO_ROOT_ABS}/src/DotVec3.c")

add_executable(smoke_clsn tests/smoke_clsn.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp hal/cstd_div.c
    hal/clsn_vtable.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${SLICE8_SOURCES} ${GATE8_EXTRA_SOURCES}
    ${GATE4A_GEN} ${GATE4B_GEN} ${GATE8_GEN} "${ROMDATA_C}")
target_include_directories(smoke_clsn PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_clsn PRIVATE ntr)
target_compile_definitions(smoke_clsn PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_clsn PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Gate 7: ModelAnim -- the game owns frame progression.
#
# Animation::Advance goes through hostgen (lane shadow-A): its looping arm is
# `% len` with len 0 on a ModelAnim that carries a model and no animation (the
# VS cap), which the ROM's ITCM divider answers with 0 and x86 idiv faults on.
# hostgen's DS_DIV table reroutes that one modulus through ds_imod; the src
# line is skipped in the gate-7 and gate-10 loops below and the generated file
# is appended to both. Retires port/unmatched/Animation_AdvanceDivGuard.cpp.
set(ANIM_ADVANCE_SYM _ZN9Animation7AdvanceEv)
set(ANIM_ADVANCE_GEN "${CMAKE_BINARY_DIR}/host-src/src/${ANIM_ADVANCE_SYM}.cpp")
add_custom_command(OUTPUT "${ANIM_ADVANCE_GEN}"
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            --out "${CMAKE_BINARY_DIR}/host-src" ${ANIM_ADVANCE_SYM}
    DEPENDS "${PORT_REPO_ROOT_ABS}/src/${ANIM_ADVANCE_SYM}.cpp"
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
    COMMENT "hostgen ${ANIM_ADVANCE_SYM}")
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate7.txt" SLICE7_LINES)
set(SLICE7_SOURCES "")
foreach(line IN LISTS SLICE7_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # Animation::Advance comes from hostgen (ANIM_ADVANCE_GEN above); the
    # manifest line is skipped HERE so slice_gate7.txt stays another lane's
    # file, the VS_PathDivGuard shape.
    if(line STREQUAL "src/_ZN9Animation7AdvanceEv.cpp")
        continue()
    endif()
    list(APPEND SLICE7_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE7_SOURCES "${ANIM_ADVANCE_GEN}")

# Gate 24: BlendModelAnim -- the cross-fading ModelAnim. Rides on gate 7's
# stack and is proven by the same smoke; see slice_gate24.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate24.txt" SLICE24_LINES)
set(SLICE24_SOURCES "")
foreach(line IN LISTS SLICE24_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE24_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

add_executable(smoke_modelanim tests/smoke_modelanim.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp hal/anim_bridge.cpp
    hal/blend_vtable.cpp hal/cstd_div.c
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${SLICE7_SOURCES} ${SLICE24_SOURCES} ${GATE4A_GEN} ${GATE4B_GEN}
    # BlendModelAnim::D0 calls func_0203cbc0, whose src form is an ARM r0
    # ride-through. The host copy that replaces it defines func_02073244
    # beside it and otherwise only reaches targets through gate 31.
    "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/func_02073244_hostcopy.c"
    "${ROMDATA_C}")
target_include_directories(smoke_modelanim PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_modelanim PRIVATE ntr)
target_compile_definitions(smoke_modelanim PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_modelanim PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Gate 6: the 2D sprite engine's software side. OAM::Load reads POWCNT
# textually -> hostgen; the rest of the slice is plain.
set(GATE6_SYMS _ZN3OAM4LoadEv)
set(GATE6_GEN "")
foreach(sym IN LISTS GATE6_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE6_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate6.txt" SLICE6_LINES)
set(SLICE6_SOURCES "")
foreach(line IN LISTS SLICE6_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(line MATCHES "_ZN3OAM4LoadEv")
        continue()
    endif()
    list(APPEND SLICE6_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

add_executable(smoke_oam tests/smoke_oam.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${SLICE6_SOURCES} ${GATE4A_GEN} ${GATE4B_GEN} ${GATE6_GEN} "${ROMDATA_C}")
target_include_directories(smoke_oam PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_oam PRIVATE ntr)
target_compile_definitions(smoke_oam PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_oam PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# The OBJ window's bit contract. No game code and no ROM data: it programs
# engine B's registers, VRAM and OAM by hand and reads ppu_scanout_sub back, so
# it links ntr alone and cannot be perturbed by a slice change.
add_executable(smoke_objwin tests/smoke_objwin.cpp)
target_include_directories(smoke_objwin PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(smoke_objwin PRIVATE ntr)
target_compile_definitions(smoke_objwin PRIVATE SM64DS_PLATFORM_PC)

# Gate 5b: the animation soak -- every compatible model+BCA pair.
add_executable(smoke_soak_anim tests/smoke_soak_anim.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${GATE4A_GEN} ${GATE4B_GEN} "${ROMDATA_C}")
target_include_directories(smoke_soak_anim PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_soak_anim PRIVATE ntr)
target_compile_definitions(smoke_soak_anim PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_soak_anim PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Gate 4c: animation -- same slice (the 4c files live in slice_gate4b.txt),
# different driver: the piano posed by its BCA through the game's walk.
add_executable(smoke_anim tests/smoke_anim.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${GATE4A_GEN} ${GATE4B_GEN} "${ROMDATA_C}")
target_include_directories(smoke_anim PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_anim PRIVATE ntr)
target_compile_definitions(smoke_anim PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_anim PRIVATE /wd4311 /wd4312 /wd4068)
endif()

add_executable(smoke_fs tests/smoke_fs.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} "${ROMDATA_C}")
target_include_directories(smoke_fs PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_compile_definitions(smoke_fs PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_fs PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Gate 9: the actor framework -- ArrowSignRight's full lifecycle.
# One .c file carries C++ syntax (mwccarm accepted it); hostgen's
# emit-as-cpp with extern "C" wrap makes it legal.
#
# --extern-data is load-bearing here and was missing until w6-c. The file
# spells its three engine globals by ROLE (gGlobalA / gGlobalB /
# Memory::gameHeapPtr) rather than as data_<hex>, so without the flag hostgen
# emitted them as private file-scope objects: this TU compiled, linked and
# unlinked dead actors from a one-byte char while the real scene tree in
# hal/actor_vtables.cpp kept them. Every target below ran that body. See
# hostgen's ROLE_DATA map for the address of each name.
set(GATE9_SYMS _ZN7fBase_c21AfterCleanupResourcesEj)
set(GATE9_GEN "")
foreach(sym IN LISTS GATE9_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" --extern-data ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE9_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate9.txt" SLICE9_LINES)
set(SLICE9_SOURCES "")
foreach(line IN LISTS SLICE9_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE9_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# THE GAME HEAP for the three actor-world smokes below.
#
# tests/walk_window.cpp and tests/smoke_player.cpp call
# Heap::InitializeGameHeap(0x3b000, 0), the carve func_0201a054 performs at
# arm9 0x0201a108 (re-derived here from extracted/arm9_dec.bin: the prelude
# reads e3a00a3b / e3a01000 / eb00884f, so r0 = 0x3b000, r1 = 0, and the BL
# lands on 0x0203c24c). smoke_actor, smoke_savestate and smoke_persist were
# instead hand-seeding `data_020a0eac_c = data_020a0ea0` -- the game-heap word
# aliased straight onto the root heap, so the ROM's heap object never existed
# and the smokes disagreed with the boot spine about how the heap comes up.
# Lane w3-c measured the link failure that blocked the conversion and left the
# reason at each seat; this is the CMake half it named.
#
# The TU is listed in slice_w1l3.txt, but SLICE_W1L3_SOURCES is built further
# down this file, after these three targets, so the one file is named directly
# rather than hoisting that block over three gates. One line is all it takes:
# Heap::CreateExpandingHeap, the body it calls, has been compiled into these
# targets since gate 3a and was being discarded by /OPT:REF because nothing
# reached it.
set(HEAP_INITGAME_SRC
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN4Heap18InitializeGameHeapEjPS_.cpp")

# THE HEAP DESTROY CHAIN for the same three actor smokes, and it is here for
# the same reason HEAP_INITGAME_SRC is: two src lines that live in a slice these
# targets do not carry.
#
# hal/actor_vtables.cpp hosts Heap_Destroy, the role-named spelling of arm9
# 0x0203c74c that src/_ZN7fBase_c21AfterCleanupResourcesEj.cpp calls when a
# dying actor owns a heap. It used to abort. Run link60 lane LK5 made the ROM's
# own veneer carry a receiver, so it can now forward instead, and the forward
# needs the veneer TU and the method behind it:
#
#   src/_ZN4Heap8_DestroyEv.cpp   the ROM's tail-call veneer, byte matched
#   src/_ZN4Heap7DestroyEv.cpp    Heap::Destroy, the method it tail-calls
#
# Both are in slice_gate16.txt, which rides smoke_player, walk_window and
# walk_window_hires only. actor_vtables.cpp rides those three AND smoke_actor,
# smoke_savestate and smoke_persist, and GATE9_GEN puts the calling teardown TU
# in all six, so without these two lines the three smokes link-fail on
# __ZN4Heap8_DestroyEv. Measured, not predicted: all three reported that exact
# LNK2019 before this was added. The C face _ZN4Heap7DestroyEv sits in
# hal/heap_vtable.cpp, which all six already compile.
#
# No target gets a duplicate: the three big targets take these two TUs from
# slice_gate16 and are not listed here.
set(HEAP_DESTROY_CHAIN_SRC
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN4Heap8_DestroyEv.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN4Heap7DestroyEv.cpp")

# SMOKELINK6 (run link100, wave 10 round 6, 2026-09-17): EXCLUDE_FROM_ALL.
# This target does not link -- one name outstanding, __ZN5Sound4PlayEjjRK7Vector3
# (SMOKELINK5's finding, out/SMOKELINK5/bugs.md and status/SMOKELINK5.md step 1),
# whose every route drags in hal/boot2_ipc.cpp's ARM7 IPC simulation, which this
# harness has never hosted -- a scope question, not a missing row, per the
# coordinator's ruling. Excluded from the default `all`/`ninja` build so
# port/build-port.cmd (no -k) completes and the battery runs again; still
# buildable by name (`ninja smoke_actor`) once the scope question is settled.
add_executable(smoke_actor EXCLUDE_FROM_ALL tests/smoke_actor.cpp "${HEAP_INITGAME_SRC}"
    ${HEAP_DESTROY_CHAIN_SRC}
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp hal/cstd_div.c
    hal/clsn_vtable.cpp hal/actor_vtables.cpp hal/anim_bridge.cpp
    # auto_bss.cpp owns data_020a4ba8, the cleanup list. Gate 9's matched TU
    # reads it from the HAL now (--extern-data + ROLE_DATA) instead of from a
    # private one-byte object of its own, so this smoke has to link the file
    # that actually holds it -- the sibling smokes at the same gate already do.
    hal/cxxname_bridge.cpp hal/megachar_stub.cpp hal/auto_bss.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${SLICE7_SOURCES} ${SLICE8_SOURCES} ${SLICE9_SOURCES} ${GATE8_EXTRA_SOURCES}
    ${GATE4A_GEN} ${GATE4B_GEN} ${GATE8_GEN} ${GATE9_GEN} "${ROMDATA_C}")
target_include_directories(smoke_actor PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_actor PRIVATE ntr)
target_compile_definitions(smoke_actor PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_actor PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Save-state verification (lane lk6): the same actor world as smoke_actor, plus
# hal/lk6_savestate.cpp, driving save -> diverge -> load -> byte-exact compare.
# SMOKELINK6 (run link100, wave 10 round 6, 2026-09-17): EXCLUDE_FROM_ALL.
# Same scope question as smoke_actor above: __ZN5Sound4PlayEjjRK7Vector3's every
# route drags in hal/boot2_ipc.cpp's ARM7 IPC simulation, never hosted here.
# Excluded from the default build so port/build-port.cmd (no -k) completes;
# still buildable by name (`ninja smoke_savestate`).
add_executable(smoke_savestate EXCLUDE_FROM_ALL tests/smoke_savestate.cpp "${HEAP_INITGAME_SRC}"
    ${HEAP_DESTROY_CHAIN_SRC}
    hal/lk6_savestate.cpp hal/dsstate_seg.cpp hal/auto_bss.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp hal/cstd_div.c
    hal/clsn_vtable.cpp hal/actor_vtables.cpp hal/anim_bridge.cpp
    hal/cxxname_bridge.cpp hal/megachar_stub.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${SLICE7_SOURCES} ${SLICE8_SOURCES} ${SLICE9_SOURCES} ${GATE8_EXTRA_SOURCES}
    ${GATE4A_GEN} ${GATE4B_GEN} ${GATE8_GEN} ${GATE9_GEN} "${ROMDATA_C}")
target_include_directories(smoke_savestate PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_savestate PRIVATE ntr)
target_compile_definitions(smoke_savestate PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_savestate PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# Disk-persistence verification (lane lk7): the same actor world, plus
# hal/lk7_persist.cpp. The parent saves and mirrors to savestate.bin, then
# spawns a SECOND PROCESS of itself which loads the disk state and must land on
# the identical arena hash -- the save surviving the process ending is the
# whole point, so the test crosses a real process boundary. Six header cases
# then run in the parent, each doctoring ONE field of an otherwise valid file:
# corrupted magic, stale gittip, DIFFERENT GAME DATA (an asset folder that
# outlived the build that filled it), the same file loaded anyway under
# SM64DS_SAVESTATE_NO_GUARD=1, a legacy format-2 file, and a truncated one --
# and finally a clean valid file, which must refuse nothing at all, so a green
# run cannot be one where every read happens to fail.
# SMOKELINK6 (run link100, wave 10 round 6, 2026-09-17): EXCLUDE_FROM_ALL.
# Same scope question as smoke_actor above: __ZN5Sound4PlayEjjRK7Vector3's every
# route drags in hal/boot2_ipc.cpp's ARM7 IPC simulation, never hosted here.
# Excluded from the default build so port/build-port.cmd (no -k) completes;
# still buildable by name (`ninja smoke_persist`).
add_executable(smoke_persist EXCLUDE_FROM_ALL tests/smoke_persist.cpp "${HEAP_INITGAME_SRC}"
    ${HEAP_DESTROY_CHAIN_SRC}
    hal/lk6_savestate.cpp hal/lk7_persist.cpp hal/dsstate_seg.cpp
    hal/auto_bss.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/gx_upload_bridge.cpp hal/cstd_div.c
    hal/clsn_vtable.cpp hal/actor_vtables.cpp hal/anim_bridge.cpp
    hal/cxxname_bridge.cpp hal/megachar_stub.cpp
    "${PORT_GITTIP_C}"
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_SOURCES}
    ${SLICE7_SOURCES} ${SLICE8_SOURCES} ${SLICE9_SOURCES} ${GATE8_EXTRA_SOURCES}
    ${GATE4A_GEN} ${GATE4B_GEN} ${GATE8_GEN} ${GATE9_GEN} "${ROMDATA_C}")
target_include_directories(smoke_persist PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_persist PRIVATE ntr)
target_compile_definitions(smoke_persist PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_persist PRIVATE /wd4311 /wd4312 /wd4068)
    # A disk state stores absolute pointers into the exe image (every actor's
    # vtable), so the image must load at the same base every run. See the
    # matching flag on walk_window, which is the base the shipped states use.
    target_link_options(smoke_persist PRIVATE /DYNAMICBASE:NO)
endif()

# LANE SMOKELINK3: THE SMOKE HARNESSES' HALF OF THE 09-14 SYNC, ONE CALL EACH.
#
# Every target below stopped linking at the sync with a block of flat Itanium
# names whose bodies it already compiles under an MSVC decoration.  The counts
# beside each call are measured, not chosen: they come from a full
# `ninja -j10 -k 0` over all targets at f7d4b3c3a, classified per name in
# out/SMOKELINK3 (and, for the classification itself, out/SMOKELINK2/route.md).
# Read port_smoke_relink's own block above for what the three mechanisms are
# and why one name may not be closed with another's.
#
# The calls live here, after every one of these targets is defined, rather than
# beside each add_executable: the wiring is identical for all of them, the
# evidence for all of them is one measurement, and a reader comparing two rows
# should not have to page through nine hundred lines to do it.

# THE HEAP-TEARDOWN SOURCE ROWS, once, because every target from smoke_roots
# on hosts the same root-heap layer and was missing the same fifteen bodies.
# All fifteen already exist in this tree and are on walk_window through
# port/slice_gate16.txt; not one of them is a new definition.
#
# The first eight are what the link asked for directly: ExpandingHeap's and
# Heap's destructors and four of ExpandingHeap's virtuals, reached from
# src/_ZN13ExpandingHeapC1EPvjP4HeapP22ExpandingHeapAllocator.cpp's and
# src/_ZN4HeapC2EPvjPS_.cpp's scalar deleting destructors and from the class's
# own vtable, plus the ROM's operator_delete2 veneer at 0x0203cbcc and the
# global operator delete it tail-calls.  The next five are what those eight
# then asked for, and the last two what those asked for.  Only D1 of each
# class is listed: MSVC folds the ROM's D1 and D0 into one symbol, so listing
# both per-function destructor TUs of one class in one link is the LNK2005
# port/slice_seat2.txt:57 states the rule for.
set(PORT_SMOKE_HEAP_TEARDOWN_SRC
    src/_ZN13ExpandingHeapD1Ev.cpp
    src/_ZN4HeapD1Ev.cpp
    src/_ZN13ExpandingHeap14VDeallocateAllEv.cpp
    src/_ZN13ExpandingHeap8VDestroyEv.cpp
    src/_ZN13ExpandingHeap19VMaxAllocatableSizeEv.cpp
    src/_ZN13ExpandingHeap22VMaxAllocationUnitSizeEv.cpp
    src/_ZN6Memory16operator_delete2EPv.cpp
    src/_ZdlPv.cpp
    src/_ZN22ExpandingHeapAllocator13DeallocateAllEPFvPvPS_jEj.cpp
    src/_ZN22ExpandingHeapAllocator16InvokeDeallocateEPvPS_j.cpp
    src/_ZN22ExpandingHeapAllocator18MaxAllocatableSizeEi.cpp
    src/_ZN13HeapAllocator7DestroyEv.cpp
    src/_ZN4Heap11_DeallocateEPv.cpp
    src/_ZN13HeapAllocator6RemoveEv.cpp
    src/_ZN4cstd3absEi.cpp)

# smoke_roots: 30 unresolved -> 0.  8 ledger faces (7 copied verbatim from
# port/faces_sync.txt, 1 derived by address), 19 alias rows (15 copied verbatim
# from hal/cxx_aliases.cpp, 4 for the heap-teardown seam), the 15 source rows
# above, 1 harness call ported to Heap::SetupRootHeap().
port_smoke_relink(roots SRC ${PORT_SMOKE_HEAP_TEARDOWN_SRC})

# smoke_fs: 32 unresolved -> 0.  Gate 3a plus the NitroFS layer, so it is
# smoke_roots's block plus two SharedFilePtr faces, and every other row is the
# same row for the same reason.  10 ledger faces, 19 alias rows, the 15 source
# rows above, 1 harness call ported.
port_smoke_relink(fs SRC ${PORT_SMOKE_HEAP_TEARDOWN_SRC})

# smoke_model: 42 unresolved -> 0.  Gate 4b, so the heap-teardown block again
# plus the model family's own rows.  hal/int4_rows.cpp is what DEFINES
# ?Destructor1@Model@@UAEXXZ and its three siblings: include/ModelBase.h:110
# explains that those two names are ordinary host virtuals holding the two
# vtable slots the ROM's D1 and D0 occupy, so src/_ZN5ModelC1Ev.cpp's vftable
# asks the linker for them, and that file is where the twelve faces live.
port_smoke_relink(model SRC ${PORT_SMOKE_HEAP_TEARDOWN_SRC}
    src/_ZN5Model11UpdateVertsEv.cpp
    src/_ZN5Model9Virtual10ER9Matrix4x3.cpp
    port/hal/smoke_dtor_slots_model.cpp
    port/unmatched/ModelBaseModel_Dtors_HostCopy.c
    # What those six bodies then call: ModelBase's Deallocate (0x02018144) and
    # func_0203cbc0, the ROM veneer onto _ZdlPv whose src form is an ARM r0
    # ride-through.  The host copy that replaces it is the same file and the
    # same reason smoke_modelanim's block already names, twelve targets up.
    src/Deallocate.c
    port/unmatched/func_02073244_hostcopy.c)

# THE MODEL-FAMILY SOURCE ROWS, once, for the same reason the heap-teardown
# list exists: every gate-4b and gate-5 smoke below hosts Model and ModelBase
# and was missing exactly these six.  The two subset files are explained in
# smoke_model's block above and in their own headers.
set(PORT_SMOKE_MODEL_SRC
    src/_ZN5Model11UpdateVertsEv.cpp
    src/_ZN5Model9Virtual10ER9Matrix4x3.cpp
    port/hal/smoke_dtor_slots_model.cpp
    port/unmatched/ModelBaseModel_Dtors_HostCopy.c
    src/Deallocate.c
    port/unmatched/func_02073244_hostcopy.c)

# smoke_soak    43 unresolved -> 0.  Gate 4b soak: smoke_model's block exactly.
# smoke_frames  44 -> 0.  Gate 5, the fiber frame loop, same block.
# smoke_oam     44 -> 0.  Same block; this one has no harness row of its own.
# smoke_anim    44 -> 0.  Gate 7 animation, same block.
# smoke_soak_anim 45 -> 0.  Same block.
port_smoke_relink(soak      SRC ${PORT_SMOKE_HEAP_TEARDOWN_SRC} ${PORT_SMOKE_MODEL_SRC})
port_smoke_relink(frames    SRC ${PORT_SMOKE_HEAP_TEARDOWN_SRC} ${PORT_SMOKE_MODEL_SRC})
port_smoke_relink(oam       SRC ${PORT_SMOKE_HEAP_TEARDOWN_SRC} ${PORT_SMOKE_MODEL_SRC})
port_smoke_relink(anim      SRC ${PORT_SMOKE_HEAP_TEARDOWN_SRC} ${PORT_SMOKE_MODEL_SRC})
port_smoke_relink(soak_anim SRC ${PORT_SMOKE_HEAP_TEARDOWN_SRC} ${PORT_SMOKE_MODEL_SRC})

# smoke_modelanim: 50 unresolved -> 0.  The BlendModelAnim gate, so it does NOT
# read PORT_SMOKE_MODEL_SRC: it needs a THREE-class slot file (ModelBase, Model,
# BlendModelAnim) and the WHOLE parent host copy rather than the two-class
# subsets, because this target does host the anim half of the family and the
# parent's Animation and ModelAnim calls resolve here.  Its own block already
# carries unmatched/func_02073244_hostcopy.c, so that row is not repeated.
# hal/blend_vtable.cpp, already on this target, defines Heap::_Deallocate, so
# the one heap-teardown row that would be a duplicate here is dropped by name
# rather than by leaving the list alone.
set(PORT_SMOKE_MODELANIM_HEAP_SRC ${PORT_SMOKE_HEAP_TEARDOWN_SRC})
list(REMOVE_ITEM PORT_SMOKE_MODELANIM_HEAP_SRC src/_ZN4Heap11_DeallocateEPv.cpp)
port_smoke_relink(modelanim SRC ${PORT_SMOKE_MODELANIM_HEAP_SRC}
    src/_ZN5Model11UpdateVertsEv.cpp
    port/hal/smoke_dtor_slots_modelanim.cpp
    port/hal/smoke_dtor_fwd_modelanim.cpp
    port/unmatched/ModelBaseModelBlend_Dtors_HostCopy.c
    src/Deallocate.c
    src/_ZN9AnimationD1Ev.cpp
    src/_ZN9ModelBaseD1Ev.cpp
    src/_ZN5ModelD1Ev.cpp
    src/_ZN9ModelAnimD1Ev.cpp)

# smoke_clsn: 57 unresolved -> 0.  Gate 8 collision: the heap-teardown and
# model blocks plus eleven dBgW bodies this target reaches from
# hal/clsn_vtable.cpp's slot thunks and from dBgW's own vtable, all of them
# ordinary src/ translation units walk_window already compiles.
port_smoke_relink(clsn SRC ${PORT_SMOKE_HEAP_TEARDOWN_SRC} ${PORT_SMOKE_MODEL_SRC}
    src/_ZN4dBgWD1Ev.cpp
    src/_ZN7dBgW_KcD1Ev.cpp
    src/_ZN4dBgW10BeforeClsnER5dBgPiP8dActor_cR7Vector3P10Vector3_16S7_.cpp
    src/_ZN4dBgW10DetectClsnER9dBgCh_Gnd.cpp
    src/_ZN4dBgW10DetectClsnER9dBgCh_Lin.cpp
    src/_ZN4dBgW10DetectClsnER12dBgCh_SphCrr.cpp
    src/_ZN4dBgW14GetAngularVelYEv.cpp
    src/_ZN4dBgW11GetVelocityER7Vector3.cpp
    src/_ZN4dBgW12TransformPosERK7Vector3RS0_.cpp
    src/_ZN4dBgW9Virtual08Ev.cpp
    # Second order: dBgW_Kc's destructor destroys its CLPS_BlockRef member.
    src/_ZN13CLPS_BlockRefD1Ev.cpp)

# LANE SMOKELINK4B: THE THREE GATE-9 ACTOR HARNESSES, ONE BLOCK.
#
# smoke_actor, smoke_savestate and smoke_persist each had 133 unresolved
# externals after the 09-14 sync, and it is the SAME 133 on all three: the
# targets host the same actor world (the same slices, the same hal files above),
# so the sync moved the same names out from under each of them.  The three name
# lists diff empty, which is out/SMOKELINK4B/actor_batch_names_identical.log,
# and that is why this is one block, one measurement and one commit rather than
# three of each.  Per target: 21 ledger faces, 28 alias rows, the source rows
# below, 2 harness calls ported, 0 new derivations.
#
# NOT PORT_SMOKE_HEAP_TEARDOWN_SRC.  These three targets already compile
# hal/cxxname_bridge.cpp and the gate-8 and gate-9 slices, so nine of that
# list's fifteen rows are already defined here and listing them would be nine
# LNK2005s instead of a fix.  The six that ARE missing are named below, in the
# heap group, which is what the measurement asked for.
set(PORT_SMOKE_ACTOR_SRC
    # THE HEAP LAYER, the six rows of the teardown set these targets actually
    # lack: ExpandingHeap's and Heap's destructors and four of ExpandingHeap's
    # virtuals, reached from the scalar deleting destructors and from the
    # class's own vtable.  Only D1 of each class is listed, for the LNK2005
    # reason port/slice_seat2.txt:57 states.
    src/_ZN13ExpandingHeap14VDeallocateAllEv.cpp
    src/_ZN13ExpandingHeap19VMaxAllocatableSizeEv.cpp
    src/_ZN13ExpandingHeap22VMaxAllocationUnitSizeEv.cpp
    src/_ZN13ExpandingHeap8VDestroyEv.cpp
    src/_ZN13ExpandingHeapD1Ev.cpp
    src/_ZN4HeapD1Ev.cpp
    # fBase_c's OWN VIRTUALS, the ones the actor world dispatches through
    # hal/actor_vtables.cpp and the fBase_c vtable fills.  InitResources is not
    # here: it is the one forward face in port/faces_sync_smoke_actor.txt.
    src/_ZN7fBase_c16CleanupResourcesEv.cpp
    src/_ZN7fBase_c18MarkForDestructionEv.cpp
    src/_ZN7fBase_c6RenderEv.cpp
    src/_ZN7fBase_c8BehaviorEv.cpp
    # dActor_c's SURFACE.  Thirty rows, and they are one class's virtuals plus
    # two of its non-virtual helpers: every Before/After hook the processing
    # lists call, every On* damage and interaction hook the vtable holds, its
    # constructor and its destructor.  All ordinary src/ translation units
    # walk_window already compiles.
    src/_ZN8dActor_c10EarthquakeERK7Vector35Fix12IiE.cpp
    src/_ZN8dActor_c10PoofDustAtERK7Vector3.cpp
    src/_ZN8dActor_c11AfterRenderEj.cpp
    src/_ZN8dActor_c11OnAttacked1ERS_.cpp
    src/_ZN8dActor_c11OnAttacked2ERS_.cpp
    src/_ZN8dActor_c12BeforeRenderEv.cpp
    src/_ZN8dActor_c13AfterBehaviorEj.cpp
    src/_ZN8dActor_c13OnTurnIntoEggER6Player.cpp
    src/_ZN8dActor_c13OnYoshiTryEatEv.cpp
    src/_ZN8dActor_c14BeforeBehaviorEv.cpp
    src/_ZN8dActor_c15OnGroundPoundedERS_.cpp
    src/_ZN8dActor_c15OnHitByMegaCharER6Player.cpp
    src/_ZN8dActor_c16OnAimedAtWithEggEv.cpp
    src/_ZN8dActor_c18AfterInitResourcesEj.cpp
    src/_ZN8dActor_c19BeforeInitResourcesEv.cpp
    src/_ZN8dActor_c19OnHitFromUnderneathERS_.cpp
    src/_ZN8dActor_c21AfterCleanupResourcesEj.cpp
    src/_ZN8dActor_c22BeforeCleanupResourcesEv.cpp
    src/_ZN8dActor_c24OnHitByCannonBlastedCharERS_.cpp
    src/_ZN8dActor_c8OnKickedERS_.cpp
    src/_ZN8dActor_c8OnPushedERS_.cpp
    src/_ZN8dActor_c9UpdatePosEP5dCc_c.cpp
    src/_ZN8dActor_c9Virtual50Ev.cpp
    src/_ZN8dActor_cC1Ev.cpp
    src/_ZN8dActor_cD1Ev.cpp
    # THE MODEL FAMILY, the rows this gate reaches that are not already on the
    # target: Model's and the animation pair's destructors, and the two
    # ShadowModel bodies an actor's shadow needs.
    src/_ZN11ShadowModel10InitCuboidEv.cpp
    src/_ZN11ShadowModel9DoSetFileEPcii.cpp
    src/_ZN5ModelD1Ev.cpp
    src/_ZN9AnimationD1Ev.cpp
    src/_ZN9ModelAnimD1Ev.cpp
    # THE COLLISION LAYER.  dBgW and dBgW_KcMbg's virtuals and destructors, and
    # dBgCh_Lin's four bodies, reached from hal/clsn_vtable.cpp's slot thunks
    # and from each class's own vtable.  smoke_clsn's block names ten of the
    # dBgW rows for the same reason; this gate adds dBgW_KcMbg, which is the
    # collider an actor actually owns.
    src/_ZN10dBgW_KcMbg10DetectClsnER12dBgCh_SphCrr.cpp
    src/_ZN10dBgW_KcMbg10DetectClsnER9dBgCh_Gnd.cpp
    src/_ZN10dBgW_KcMbg10DetectClsnER9dBgCh_Lin.cpp
    src/_ZN10dBgW_KcMbg11GetVelocityER7Vector3.cpp
    src/_ZN10dBgW_KcMbg12TransformPosERK7Vector3RS0_.cpp
    src/_ZN10dBgW_KcMbg14GetAngularVelYEv.cpp
    src/_ZN10dBgW_KcMbg17GetTriangleOriginEsR7Vector3.cpp
    src/_ZN10dBgW_KcMbg9GetNormalEsR7Vector3.cpp
    src/_ZN10dBgW_KcMbg9Virtual08Ev.cpp
    src/_ZN10dBgW_KcMbgD1Ev.cpp
    src/_ZN4dBgW10BeforeClsnER5dBgPiP8dActor_cR7Vector3P10Vector3_16S7_.cpp
    src/_ZN4dBgW10DetectClsnER12dBgCh_SphCrr.cpp
    src/_ZN4dBgW10DetectClsnER9dBgCh_Gnd.cpp
    src/_ZN4dBgW10DetectClsnER9dBgCh_Lin.cpp
    src/_ZN4dBgW11GetVelocityER7Vector3.cpp
    src/_ZN4dBgW12TransformPosERK7Vector3RS0_.cpp
    src/_ZN4dBgW14GetAngularVelYEv.cpp
    src/_ZN4dBgW9Virtual08Ev.cpp
    src/_ZN4dBgWD1Ev.cpp
    src/_ZN7dBgW_KcD1Ev.cpp
    src/_ZN9dBgCh_Lin10DetectClsnEv.cpp
    src/_ZN9dBgCh_Lin13SetObjAndLineERK7Vector3S2_P8dActor_c.cpp
    src/_ZN9dBgCh_LinC1Ev.cpp
    src/_ZN9dBgCh_LinD1Ev.cpp
    # WHAT THOSE THEN CALL: the fixed-point and vector helpers, the particle
    # spawn and the positional sound.  Every one is a one-function src/ TU
    # walk_window compiles, and out/SMOKELINK3/next_targets.md predicted seven
    # of them (route.md had called them NEW derivations).
    src/DecIfAbove0_Byte.c
    src/Matrix4x3_ApplyInPlaceToRotationZXYExt.c
    src/Matrix4x3_ApplyInPlaceToTranslation.c
    src/Matrix4x3_FromTranslation.c
    src/Vec3_Add.c
    src/Vec3_Asr.c
    src/Vec3_HorzAngle.c
    src/_ZN5Sound9PlayBank3EjRK7Vector3.cpp
    src/_ZN8Particle6System9NewSimpleEj5Fix12IiES2_S2_.c
    # ---- SECOND ORDER.  Everything above was named by the link at 454383169;
    # everything below was named by the NEXT link, once those rows were on the
    # target.  out/SMOKELINK3/next_targets.md says to expect this ("a SRC row is
    # rarely first-order") and the rounds are in out/SMOKELINK4B/.
    #
    # The heap allocator's four bodies, which ExpandingHeap::VDestroy and
    # Heap::~Heap above reach.  These ARE four of PORT_SMOKE_HEAP_TEARDOWN_SRC's
    # rows: the other eleven of that list are already defined on these targets,
    # which is why the list is not used whole here.
    src/_ZN13HeapAllocator7DestroyEv.cpp
    src/_ZN22ExpandingHeapAllocator13DeallocateAllEPFvPvPS_jEj.cpp
    src/_ZN22ExpandingHeapAllocator16InvokeDeallocateEPvPS_j.cpp
    src/_ZN22ExpandingHeapAllocator18MaxAllocatableSizeEi.cpp
    # dBgCh, dBgPi, dM3dG* and CLPS_BlockRef: the collision primitives
    # dBgCh_Lin and dBgW_KcMbg above are built out of.
    src/_ZN12dBgCh_SphCrr14SetFloorResultERK5dBgPi.cpp
    src/_ZN12dBgCh_SphCrr15SetObjAndSphereERK7Vector35Fix12IiEP8dActor_c.cpp
    src/_ZN12dBgCh_SphCrrC1Ev.cpp
    src/_ZN12dBgCh_SphCrrD1Ev.cpp
    src/_ZN13CLPS_BlockRefD1Ev.cpp
    src/_ZN5dBgChC2Ev.cpp
    src/_ZN5dBgChD1Ev.cpp
    src/_ZN5dBgPiC1Ev.cpp
    src/_ZN5dBgPiD1Ev.cpp
    src/_ZN5dBgPiaSERKS_.cpp
    src/_ZN8dM3dGLin3SetERK7Vector3S2_.cpp
    src/_ZN8dM3dGLinD2Ev.cpp
    src/_ZN8dM3dGSphC1Ev.cpp
    src/_ZN8dM3dGSphD1Ev.cpp
    # fBase_c's and dActor_c's own remaining bodies, plus the two fBase_c
    # virtuals whose non-virtual spelling the alias rows point at
    # (hal/cxx_aliases.cpp:2988-2989 join U to Q; Q is defined by these two).
    src/_ZN7fBase_c13InitResourcesEv.cpp
    src/_ZN7fBase_c9Virtual34Ejj.cpp
    src/_ZN7fBase_c9Virtual38Ejj.cpp
    src/_ZN7fBase_cD1Ev.cpp
    src/_ZN8dActor_c18GetBitInDeathTableEv.cpp
    src/_ZN8dActor_c22UpdatePosWithOnlySpeedEP5dCc_c.cpp
    src/_ZN8dActor_c24KillAndTrackInDeathTableEv.cpp
    src/_ZN8dActor_c28UpdatePosWithHorzSpeedAndAngEv.cpp
    src/_ZN9fLiNdBa_cD1Ev.cpp
    src/actors/ActorDerived.cpp
    # The twenty-one ROM helpers the collision and background-actor bodies call,
    # each a one-function src/ TU walk_window compiles.
    src/func_0200d8c8.c
    src/func_02016e70.c
    src/func_02035354.c
    src/func_02035394.c
    src/func_020353b0.c
    src/func_020374b8.c
    src/func_02037608.c
    src/func_0203782c.c
    src/func_02037888.c
    src/func_02037940.c
    src/func_02037a04.c
    src/func_02037fec.c
    src/func_0203938c.c
    src/func_0203939c.c
    src/func_020393ac.c
    src/func_020393b4.c
    src/func_02039db8.c
    src/func_02039e30.c
    src/func_02039e48.c
    src/func_0203abd4.c
    # And what the rest call: the two rotation matrices, the area-visibility
    # read, atan2, the clipper's point test.
    src/IsAreaShowing.c
    src/Matrix4x3_FromRotationX.c
    src/Matrix4x3_FromRotationZ.c
    src/_ZN4cstd5atan2E5Fix12IiES1_.c
    src/_ZN7Clipper13Func_020150E8ER7Vector35Fix12IiEPh.cpp
    src/_ZN9ModelBaseD1Ev.cpp
    # THE ROM VENEER'S HOST COPY, the same row smoke_model's and
    # smoke_modelanim's blocks already carry for the same symbol: func_0203cbc0
    # is an ARM r0 ride-through onto _ZdlPv, so the host cannot compile the
    # matched form.
    port/unmatched/func_02073244_hostcopy.c
    # ---- THIRD ORDER, measured in round 2 the same way round 2 was measured
    # in round 1.  Twenty-one more one-function src/ translation units, every
    # one of them already compiled by walk_window: what the collision bodies,
    # dActor_c's death-table pair, fBase_c's two heap virtuals and the particle
    # spawn then call.  src/_ZdlPv.cpp, src/Deallocate.c and
    # src/_ZN13HeapAllocator6RemoveEv.cpp are three of
    # PORT_SMOKE_HEAP_TEARDOWN_SRC's rows arriving here at last, which is why
    # the heap group above has six of that list and not nine.
    src/AddVec3.c
    src/Deallocate.c
    src/DeathTable_GetBit.c
    src/_ZN11fLiNdBaPr_cD1Ev.cpp
    src/_ZN13HeapAllocator6RemoveEv.cpp
    src/_ZN4Heap20RestoreFromTemporaryEv.cpp
    src/_ZN4Heap21MaxAllocationUnitSizeEv.cpp
    src/_ZN4Heap28InitializeSolidHeapAsDefaultEjPS_i.cpp
    src/_ZN6Memory8AllocateEjiP4Heap.cpp
    src/_ZN8Particle7Manager9AddSystemEiR7Vector3.cpp
    src/_ZN8dActor_c17TrackInDeathTableEv.cpp
    src/_ZdlPv.cpp
    src/func_02010da4.c
    src/func_02037b5c.c
    src/func_02037f5c.c
    src/func_020380c0.c
    src/func_0203abcc.c
    src/func_0203ac00.c
    src/func_02042fe4.c
    src/func_ov002_020fea4c.c
    src/func_ov002_020fea68.c
    # ---- FOURTH ORDER, and the last round this lane measured.  Ten more
    # one-function src/ TUs: the solid-heap pair fBase_c's two heap virtuals
    # call, the nested-iterator lookup HeapAllocator::Remove calls, the death
    # table's setter, and five ROM helpers.
    src/DeathTable_SetBit.c
    src/GetLevelPart.c
    src/_ZN18NestedHeapIterator10FindNestedEPv.cpp
    src/_ZN4Heap10SetDefaultEv.cpp
    src/_ZN4Heap23SetupSolidHeapAsDefaultEjPS_i.cpp
    src/func_02037b1c.c
    src/func_02043098.c
    src/func_0204ae2c.c
    src/func_0204d958.c
    src/func_0204d9a0.c
    # ONE HOST FILE WHOLE, and it is the only one of five that measured free.
    # port/hal/actorport_dtor_bridge.cpp closes the six
    # ?Destructor1/0@dActor_c|dBase_c|dBgActor_c@@UAEXXZ rows the actor
    # vftables ask for, and it closes them the way that file closes them for
    # the window targets: Destructor1 is /alternatename'd onto the class's own
    # complete-object destructor (ABI-exact, same __thiscall receiver, no stack
    # args on either side) and Destructor0 onto the shared
    # actorport_dtor_slot_trap, whose body is in the same file.  Measured on
    # smoke_actor: it added NOTHING to the wall -- zero names -- because every
    # right hand side its other 248 rows name is either already defined here or
    # never referenced here, and an /alternatename for an unreferenced symbol is
    # inert.  The four files below it were measured the same way and REFUSED,
    # each one costing more than it closed (round 2, out/SMOKELINK4B):
    #   port/hal/int4_rows.cpp              closes 7, costs 17
    #   port/hal/actorport_dtor_faces.cpp   closes 0, costs 37 (its rows are the
    #                                       bridge's aliases, not this file's)
    #   port/hal/link21_rows.cpp            closes 1, costs 20
    #   port/hal/sdat/sound_abi.cpp         closes 1, costs 22 (the whole sdat
    #                                       consumer, mixer and sequencer layer)
    # Each of those four therefore wants a verbatim subset in the shape
    # port/hal/smoke_dtor_slots_model.cpp established, which is written up in
    # out/SMOKELINK4B/remaining.md and applied below by lane SMOKELINK5
    # (run link100 wave 10 round 5): every one of the batch's 37 names placed.
    port/hal/actorport_dtor_bridge.cpp
    # SMOKELINK5 section A: the three-class destructor-slot subset and its
    # host copy (int4_rows.cpp lines 71-74/81-82/194-207, measured whole at 17
    # against seven closed).
    port/hal/smoke_dtor_slots_actor.cpp
    port/unmatched/ModelBaseModelShadow_Dtors_HostCopy.c
    src/_ZN8dActor_c25OnAimedAtWithEggReturnVecEv.cpp
    # SMOKELINK5 section B: fBase_c's non-polymorphic shadow constructor
    # (link21_rows.cpp lines 169-172, measured whole at 20 against one closed).
    port/hal/smoke_fbase_ctor_actor.cpp
    # SMOKELINK5 section C: the odr-use face for dBgActor_c's inline complete
    # object destructor (actorport_dtor_bridge.cpp:532's alias target).
    port/hal/smoke_dtor_face_actor.cpp
    # SMOKELINK5 section D: the heap and fBase_c seam. Two faces and five
    # alias pairs in port/hal/smoke_heap_seam_actor.cpp, backed by three SRC
    # rows that were not on this batch before (a fourth,
    # _ZN4Heap21MaxAllocationUnitSizeEv.cpp, already was).
    port/hal/smoke_heap_seam_actor.cpp
    src/_ZN4Heap15CreateSolidHeapEjPS_i.cpp
    src/_ZN4Heap11_DeallocateEPv.cpp
    src/_ZN4Heap11ResizeToFitEv.cpp
    # SECOND ORDER on section D, measured the same way SMOKELINK3/4B measured
    # theirs: what CreateSolidHeap's and ResizeToFit's own bodies call and
    # walk_window already compiles. CreateSolidHeap's chain is
    # CreateSolidHeapAllocator -> SolidHeapAllocator's constructor ->
    # func_0204df54 -> NestedHeapIterator's constructor and AddLast (which
    # itself calls Init) -- none a new definition, all matched TUs this batch
    # did not carry yet. SolidHeap's own constructor and Heap's base
    # constructor are the other half of CreateSolidHeap's body. ResizeToFit's
    # is just Heap::Rescue (the decorated member ResizeToFit calls directly;
    # Crash() is already on this batch via hal/heap_vtable.cpp).
    src/_ZN4Heap24CreateSolidHeapAllocatorEPvjj.cpp
    src/_ZN18SolidHeapAllocatorC1EPvj.cpp
    src/func_0204df54.cpp
    src/_ZN18NestedHeapIteratorC1Ej.cpp
    src/_ZN18NestedHeapIterator7AddLastEP13HeapAllocator.cpp
    src/_ZN18NestedHeapIterator4InitEP13HeapAllocator.cpp
    src/_ZN9SolidHeapC1EPvjP4HeapP18SolidHeapAllocator.cpp
    # SolidHeap is a real polymorphic class (include/SolidHeap.h), and its
    # constructor's placement-new needs a complete vtable: all eleven virtual
    # overrides plus the destructor family, or MSVC cannot emit
    # ?_ZN9SolidHeapC1EPvjP4HeapP18SolidHeapAllocator@@... at all. All twelve
    # exist as matched src/ TUs; only the destructor's D1 file is added (D0 is
    # the identical `SolidHeap::~SolidHeap() {}' text -- mwcc emits D0, D1 and
    # D2 from the one definition -- so both files would be LNK2005).
    src/_ZN9SolidHeapD1Ev.cpp
    src/_ZN9SolidHeap8VDestroyEv.cpp
    src/_ZN9SolidHeap9VAllocateEji.cpp
    src/_ZN9SolidHeap11VDeallocateEPv.cpp
    src/_ZN9SolidHeap14VDeallocateAllEv.cpp
    src/_ZN9SolidHeap7VIntactEv.cpp
    src/_ZN9SolidHeap7VRescueEv.cpp
    src/_ZN9SolidHeap11VReallocateEPvj.cpp
    src/_ZN9SolidHeap7VSizeofEPv.cpp
    src/_ZN9SolidHeap22VMaxAllocationUnitSizeEv.cpp
    src/_ZN9SolidHeap19VMaxAllocatableSizeEv.cpp
    src/_ZN9SolidHeap11VMemoryLeftEv.cpp
    src/_ZN9SolidHeap10VSetNodeIDEj.cpp
    src/_ZN9SolidHeap10VGetNodeIDEv.cpp
    src/_ZN9SolidHeap12VResizeToFitEv.cpp
    # THIRD ORDER: SolidHeapAllocator's own five methods the eleven virtuals
    # above call, and Heap::Reallocate (VResizeToFit's fallback path).
    src/_ZN18SolidHeapAllocator8AllocateEji.cpp
    src/_ZN18SolidHeapAllocator5ResetEj.cpp
    src/_ZN18SolidHeapAllocator10ReallocateEPvj.cpp
    src/_ZN18SolidHeapAllocator10MemoryLeftEi.cpp
    src/_ZN18SolidHeapAllocator14TryResizeToFitEv.cpp
    src/_ZN18SolidHeapAllocator16AllocateForwardsEPvjj.cpp
    src/_ZN18SolidHeapAllocator17AllocateBackwardsEPvjj.cpp
    src/_ZN18SolidHeapAllocator10ResetStartEv.cpp
    src/_ZN18SolidHeapAllocator8ResetEndEv.cpp
    src/_ZN4Heap10ReallocateEPvj.cpp
    src/func_0204ebb8.c
    src/_ZN18NestedHeapIterator6RemoveEP13HeapAllocator.cpp
    src/_ZN4HeapC2EPvjPS_.cpp
    src/_ZN4Heap6RescueEv.cpp
    # SMOKELINK5 section E: the host globals and ROM helpers. Eleven of
    # fifteen are here or in the ov001 mount below; four are the plain SRC
    # rows immediately following. data_020a4b58's own triplet is second order
    # (func_02043060.c asks for it, and hal/player_bridges.cpp -- not on this
    # batch, and far too wide to take whole -- is where the window build
    # hosts it), pulled as the same kind of verbatim subset in
    # port/hal/smoke_host_globals_actor.cpp.
    port/hal/smoke_host_globals_actor.cpp
    src/func_02042ffc.c
    src/func_02043060.c
    src/func_02043180.c
    src/func_020433b8.c
    src/func_0204335c.c
    src/_ZN7fBase_c7ProcessEMS_FivEMS_FbvEMS_FvjE.cpp
    # SMOKELINK5 section F: __ZN5Sound4PlayEjjRK7Vector3 is NOT placed. See
    # out/SMOKELINK5/bugs.md -- the coordinator's ruling measured the matched
    # TU's cost against its own six one-function dependencies only. Traced
    # fully, two of those six (func_02048908 and func_02048d80, via
    # func_0204f7cc) and the matched TU's own direct call to
    # Player_PlaySoundEffect both reach func_0205b070's IPCSend, which is
    # hal/boot2_ipc.cpp (713 lines, the host ARM7 simulation, on the two
    # window targets and smoke_player only). The row stays on the wall.
    )

port_smoke_relink(actor     SRC ${PORT_SMOKE_ACTOR_SRC})
port_smoke_relink(savestate SRC ${PORT_SMOKE_ACTOR_SRC})
port_smoke_relink(persist   SRC ${PORT_SMOKE_ACTOR_SRC})

# SMOKELINK5 section E, the last of the fifteen host globals and ROM helpers:
# _data_020ad524, the cuboid shadow's template BMD. hal/cxxname_bridge.cpp:240
# (already on these three targets) aliases it onto _data_ov001_020ad524, so
# the alias's left hand side was present and its right hand side was not: the
# ov001 mount itself, which the build already generates unconditionally (ov001
# is in PORT_ACTOR_OVERLAYS) and which smoke_actor, smoke_savestate and
# smoke_persist did not list.
foreach(_tov001 smoke_actor smoke_savestate smoke_persist)
    target_sources(${_tov001} PRIVATE "${CMAKE_BINARY_DIR}/host-src/ov001_syms.c")
endforeach()

# Gate 10: Player spawns and stands (the walking campaign).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate10.txt" SLICE10_LINES)
set(SLICE10_SOURCES "")
foreach(line IN LISTS SLICE10_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # same substitution as the slice_gate7 loop above -- Animation::Advance
    # comes from hostgen (ANIM_ADVANCE_GEN).
    if(line STREQUAL "src/_ZN9Animation7AdvanceEv.cpp")
        continue()
    endif()
    list(APPEND SLICE10_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE10_SOURCES "${ANIM_ADVANCE_GEN}")
# fix round: func_ov002_020e5948's HOST COPY (the TexSeq Prepare SHORT-1
# caller behind the L11 ONE_UP_MUSHROOM quarantine; Brain A's handoff,
# re-verified against the byte-locked src -- exactly the Prepare arity
# edits, nothing else). Replaces src/func_ov002_020e5948.c, commented out
# of slice_gate10.txt.
list(APPEND SLICE10_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/TexSeq_Caller_ov002_020e5948.cpp")
# Slot 28 has two dispatch sites and the two matched transcriptions disagree
# on calling convention; see unmatched/Player_HeadBonk.cpp. This copy is
# src/actors/Player.cpp with the dispatch remodelled as a C++ virtual
# so both sites are thiscall, which is what lets slot 28 hold a real body.
list(APPEND SLICE10_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Player_HeadBonk.cpp")
# Slots 23 and 24 have exactly one dispatch site each, and both model the vtable
# as plain cdecl function pointers while every seated slot-23/24 body is
# thiscall; see unmatched/Actor_OnAttacked2Dispatch.cpp and
# unmatched/Actor_OnKickedDispatch.cpp. These copies are
# src/func_ov002_020ef070.cpp and src/func_ov002_020eeeb8.cpp with the dispatch
# remodelled as a C++ virtual so each site is thiscall, which is what lets slots
# 23/24 hold real bodies (and stops the base ac_atk2/ac_kicked seats over-popping
# on every dispatch). Both src lines are commented out of slice_gate10.txt.
list(APPEND SLICE10_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Actor_OnAttacked2Dispatch.cpp")
list(APPEND SLICE10_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Actor_OnKickedDispatch.cpp")
# Luigi Infection host-copies the VS player-on-player hit resolver
# func_ov002_020d869c: a verbatim transcription of the src body plus the team
# branch (Luigi victim immune, survivor struck by a Luigi tagged). src line
# commented out of slice_gate10.txt; inert with SM64DS_VS_LUIGI_INFECTION off,
# so survivor-vs-survivor combat is exactly ROM-normal.
list(APPEND SLICE10_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/LuigiInfection_Hit.cpp")

# Two Actor entry points are C++ inside a .c, but a different shape from the
# hostgen cases below: each is a real METHOD against Actor.h, so hostgen's
# wrap is wrong for them -- it would put the whole file, Actor.h include and
# all, inside extern "C". They compile as C++ instead, and
# hal/method_faces.cpp carries the C-linkage faces their callers spell. Both
# were plain C free functions until main rewrote them as methods.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN8dActor_c13SpawnSoundObjEj.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN8dActor_c24KillAndTrackInDeathTableEv.cpp"
    # gate 176: a //cpp-marked state body (local method shadows over extern "C"
    # bodies), the same shape -- compiles as C++, no face needed (its own
    # symbol is extern "C" inside the file).
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/Scuttlebug.cpp"
    # and the generated copy, lane CRASH6: this TU is on PORT_HOSTGEN_TU now,
    # so the raw path alone would set the property on a source nothing
    # compiles. Both paths are already .cpp so LANGUAGE CXX carries nothing
    # either way, but the configure check counts spellings over this whole
    # file, not per call, and a silently-dropped property is the failure this
    # block exists to prevent.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/Scuttlebug.cpp"
    # gate 177: two //cpp-marked .c bodies plus one unmarked C++-ism (an empty
    # struct Callback {}), same treatment.
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN5Bully8BehaviorEv.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daOts_c.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daOts_c.cpp"
    # gate 22 backfill: CanEnterDoor matched 2026-08-07 (PR #1223); //cpp-marked
    # .c whose Door dummy-virtual struct needs C++, own symbol extern "C".
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/Player.cpp"
    # gate 194: a //cpp-marked .c (a top-level `extern "C" {` block, invalid C),
    # HootTheOwl's own state-transition helper.
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov094_02136024.cpp"
    # run linkw wave 7, lane w7b: MrI's InitResources, the one body of the Mr. I
    # closure that is NONMATCHING-but-decompiled. //cpp-marked .c with extern "C"
    # blocks and SharedFilePtr& reference params -- invalid C, same treatment as
    # the gate-176 entry above.
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN3MrI13InitResourcesEv.cpp"
    # run linkw wave 12, lane w12: the one .c in ov073's closure that is really
    # C++ -- a top-level `extern "C" {` block, invalid C. ChiefChilly's
    # jumped-on / hurt-the-player state helper. Same treatment as the entries
    # above; it is the only one of slice_w12.txt's 67 TUs that needs it.
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov073_0211f61c.cpp"
    # run link60 lane L2: the ONE .c in ov007's 619-TU closure that is really
    # C++ -- a top-level `extern "C" {` block, invalid C. The whole slice was
    # swept for the //cpp marker rather than this one being found by a compile
    # error and the rest left to luck.
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov007_020bfd70.cpp"
    # run mg5 lane CCN: the ONE .c in dScMgCoin_c's 61-TU closure that is
    # really C++ -- a //cpp marker, a top-level `extern "C"` block and a
    # thirty-six-virtual dummy struct it dispatches a slot through. The whole
    # slice was swept for the marker and for `extern "C"`, `virtual` and
    # `class`, rather than this one being found by a compile error and the rest
    # left to luck; it is the only hit.
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020dd880.cpp"
    # run mg9 lane S371: THREE .c files in dScMgAmida_c's 29-TU slice are
    # really C++ -- a //cpp marker, top-level `extern "C"` blocks and, in all
    # three, a dummy virtual struct they dispatch a slot through. That struct
    # is THIRTY-SEVEN virtuals wide in these, not thirty-six, because this
    # class is the one true width-37 class of the minigame family and the slot
    # they reach is its 37th (port/slice_s371.txt section 3). The whole slice
    # was swept for the marker AND for `extern "C"`, `virtual` and `class`, the
    # way lane CCN's entry above prescribes, rather than these being found one
    # at a time by compile errors; these three are the only hits.
    # func_ov006_020d3ba0.c IS THE THIRD HIT AND IT IS NOT HERE. It needs C++
    # for the same reason as the two above -- a 37-virtual dummy struct and a
    # namespace -- but its extern "C" block also writes a bare
    # `int data_0209d4b8;`, which C++ makes a strong definition of an arm9
    # global hal/scene_mg_faces.cpp already owns inside DSSTATE. It is
    # host-copied in unmatched/MgAmida_Slot3ba0.cpp instead, one token changed,
    # and that file's header carries the ruling and the sed line that
    # reproduces it.
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020d122c.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN12dScMgAmida_c8BehaviorEv.cpp"
    # run mg11 lane PKR: the ONE .c in dScMgCard_c's 38-TU slice that is really
    # C++ -- a //cpp marker, a top-level `extern "C" {` block and a two-virtual
    # dummy struct it dispatches ELEMENT vtable slot 1 through, ten times a
    # frame. It is the class's whole state machine (a 14-arm ARM jump table).
    # The slice was swept for the marker AND for `extern "C"`, `virtual` and
    # `class`, the way lane CCN's entry above prescribes, rather than this being
    # found by a compile error and the rest left to luck. Three other files hit
    # the `class` filter and all three are the words "Class_Method" and "RTTI
    # class fields" inside recovered-name COMMENTS, which is the false positive
    # that sweep has to tolerate to stay cheap; this is the only real hit.
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/minigames/d_s_mg_card.cpp"
    PROPERTIES LANGUAGE CXX)

# Wave-5 close surgery (w5b_review.md R1/R2): two /alternatename routes died
# when w5-b sliced the real bodies under the aliases' LHS names -- a defined
# LHS defeats /alternatename silently. The affected caller TUs get per-source
# renames instead; the dead pragmas are deleted from hal/cxx_aliases.cpp and
# hal/actor_classes_koopa_chuckya.cpp (the alternatename guard enforces the
# class from here on).
# R1: PeachPainting::InitResources spells ov010's SharedFilePtr BSS as
# daGrock_c_classInit (dsd shared-base misname, gate 42); the real
# daGrock_c_classInit (ov021, id 221's factory) links since wave 5.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13PeachPainting13InitResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS "daGrock_c_classInit=data_ov010_02112d64")
# R2: three ov062 caller TUs spell a shared-base address by its ov065 name,
# and that name is now Swoop's genuinely different real body (sliced in
# wave 5) -- rename the reference back to the ov062 body they always called.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov062_02118058.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov062_021180d4.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov062_02118a00.cpp"
    PROPERTIES COMPILE_DEFINITIONS "func_ov065_02117994=func_ov062_02117994")
# R2b, run rel0215 (lane cast-ov077): THE SAME DISEASE, from the ov077 side,
# and this one was LIVE ON EVERY LEVEL THAT PLACES A LAKITU rather than latent.
# src/func_ov077_0212390c.cpp is LAKITU's per-frame chase body. Its last
# statement is written `_ZN9Spindrift8BehaviorEv(c, c + 0x204)` -- two
# arguments, which Spindrift::Behavior does not take. The ROM's own relocation
# at 0x02123a04 reads `to:0x02123c6c module:overlay(77)`, and 0x02123c6c is
# func_ov077_02123c6c (size 0xd4), ov077's own WithMeshClsn update, whose
# signature IS (actor, WithMeshClsn*). ov081 has _ZN9Spindrift8BehaviorEv
# (size 0x264) at the SAME address because ov077 and ov081 are alternates in
# the window at 0x02123740, and dsd raced the name.
#
# THE COFFIN/SPINDRIFT SHAPE, and the reason this lane's brief calls the alias
# race its defining hazard: nothing about it is visible to the byte gate (the
# ROM bytes are untouched) or to the linkage count (both names are defined, so
# it links clean). What it does at run time is call ov081's Spindrift body with
# a Lakitu `this` every frame. It faulted c0000005 in
# WithMeshClsn::UpdateContinuous on level 43 at frame ~250 and NOT within 300
# frames on levels 24, 28 or 44 -- which is the point: three of the four levels
# were running the wrong body and reading green.
#
# A per-source rename rather than an /alternatename ON PURPOSE, the R1/R2/R3/R4
# rule: _ZN9Spindrift8BehaviorEv is DEFINED in this link (ov081 is mounted and
# hal/actor_classes_ov081.cpp faces it), and an /alternatename onto a defined
# LHS is defeated silently. Found by sweeping every overlay(77) relocation in
# all 91 ov077 TUs against what each source spells; this is the only one.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov077_0212390c.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZN9Spindrift8BehaviorEv=func_ov077_02123c6c")
# R5, run frontfix (lane FRONTFIX): THE SAME SHAPE at 0x020c5dec, where TWO
# bodies alternate at one address and one /alternatename cannot route both.
# hal/cxx_aliases.cpp keeps /alternatename:_func_ov007_020c5dec=_func_ov002_020c5dec
# for the two PLAYER TUs (St_HurtWater_Main, St_WaitQuicksand_Main) that spell
# the ov007 name for what is really ov002's body at that address -- they pass
# two arguments, the ov002 signature, and they still want ov002's body. But
# ov007's own caller src/func_ov007_020ba2e0.c passes one argument and wants
# ov007's body at the same address, and the global alias was handing it ov002's
# body instead: wrong overlay in the ov007 direction. src/func_ov007_020c5dec.cpp
# is now listed in slice_ov007.txt, so compiling it plainly would DEFINE the
# alias LHS -- which alternatename_guard refuses and which would hand the two
# Player TUs the ov007 body too. The Spindrift/ov062 rule fixes it per source:
# rename the symbol in the ov007 body TU and its ov007 caller to a private name,
# so the ov007 body links as func_ov007_020c5dec_own and the ov007 caller reaches
# it, while func_ov007_020c5dec stays undefined for the alias to route the two
# Player TUs to ov002. Per-context routing with no /alternatename ambiguity.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov007_020c5dec.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov007_020ba2e0.c"
    PROPERTIES COMPILE_DEFINITIONS "func_ov007_020c5dec=func_ov007_020c5dec_own")
# PORT_HOST_ABI, run link100 lane WARP1: ov100's fish release pass, the same
# per-context routing one more time. src/_ZN4Fish16CleanupResourcesEv.cpp calls
# func_ov100_02146280 with no argument, which is correct ARM (dActor_c::FindWithID
# has just left the actor in r0 and the helper reads [r0, #0x158]) and faults on
# this ABI, where MSVC pushes nothing. Renaming the symbol FOR THAT ONE TU sends
# its call to hal/cxx_aliases.cpp's thunk, which pushes the value eax still holds
# and calls the ROM's own body; every other reference to func_ov100_02146280 --
# there is no other caller in the ROM, reloc 0x02146ae4 is the only edge -- is
# untouched, and the body itself still links under its own name.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN4Fish16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS "func_ov100_02146280=hal_ov100_02146280_ridethrough")
# PORT_HOST_ABI, run link100 wave 20 (lane CAMTICK_FIX): the camera-rotate
# effect's stop fade. src/func_02009e70.cpp declares Sound_PlayIfNotActive
# with three parameters and calls it with three (:102 and :551); the ROM's
# definition (src/Sound_PlayIfNotActive.c) takes four and stores the fourth
# as the effect's stop fade. At 0x0200ae44 the cartridge materialises r3 = 0
# for the data_0209b000 = 0 store and the call at 0x0200ae64 reuses it, so
# the rotate effect is always registered with fade 0 on the ROM; on this ABI
# the callee read an unwritten stack slot instead. Renaming the symbol FOR
# THAT ONE TU sends its call to the ride-through in port/hal/sdat/sound_abi.cpp,
# which supplies the fourth argument as 0; the definition and every other
# caller are untouched.
# The TU is on PORT_HOSTGEN_TU (lane CAMSWIM3), so the compiled source is
# the generated twin; the property has to name both paths or the
# ride-through would silently leave the build. See the refusal above.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_02009e70.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/func_02009e70.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "Sound_PlayIfNotActive=hal_Sound_PlayIfNotActive_ridethrough")
# R3, run linkw wave 12 (lane w12): THE SAME DISEASE, a fourth time, and this
# one arrived from the OTHER side -- not a newly sliced body under an alias's
# LHS but a newly MOUNTED datum under it. src/actors/Scuttlebug.cpp (Scuttlebug's
# anim load) spells ov071's SharedFilePtr `data_ov073_02122f88` -- a dsd
# shared-window misname; the load site's reloc at 0x0211fc5c targets 0x02122f88
# module:overlay(71). hal/actor_classes_scuttlebug.cpp routed that misspelling
# with /alternatename:_data_ov073_02122f88=_data_ov071_02122f88, and mounting
# ov073 DEFINES the LHS (0x02122f88 is ChiefChilly's tenth state record), which
# defeats the alias silently: the reference would have bound to the state record
# and handed Animation::LoadFile a code address. tools/alternatename_guard.py
# caught it at the first link with ov073 mounted. The dead pragma is deleted
# from that file and the routing lands here, the R1/R2 remedy exactly.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/Scuttlebug.cpp"
    # and the generated copy, lane CRASH6: this TU is on PORT_HOSTGEN_TU now.
    # This one is genuinely load-bearing, not a formality: without it the
    # reference goes back to _data_ov073_02122f88, which mounting ov073 DEFINES
    # as ChiefChilly's tenth state record, and Animation::LoadFile is handed a
    # code address with nothing to say so.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/Scuttlebug.cpp"
    PROPERTIES COMPILE_DEFINITIONS "data_ov073_02122f88=data_ov071_02122f88")
# R4, run linkw wave 12 (lane w12): src/game/actors/d_a_obj_emm_log.cpp (id 174's
# CleanupResources) spells ov052's OWN file table `data_ov056_021124d4` -- ov052
# and ov056 link at overlapping bases and dsd raced the name. Its sibling
# src/game/actors/d_a_obj_emm_log.cpp spells the same address `data_ov052_021124d4`, which
# is what port/ov052_syms.txt mounts, and the load site's relocs at
# 0x02111260/0x02111268 say module:overlay(52). A per-source rename rather than
# an /alternatename ON PURPOSE: ov056 is a live target (id 173, nine instances
# on level 48) and an alias with an ov056 LHS would be defeated the day ov056 is
# mounted, which is the R3 failure this same lane already hit on ov071/ov073.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_emm_log.cpp"
    PROPERTIES COMPILE_DEFINITIONS "data_ov056_021124d4=data_ov052_021124d4")
# R-w3d, run rel0215 (lane w3-d): ov072's two newly seated classes each have
# their vtable spelled TWO ways by their own matched src. daBgSnmBdy_c_classInit.c
# stores `_ZTV11SnowmanBody`, which is what hal/actor_classes_ov072.cpp
# defines as the host array; _ZN12daBgSnmBdy_cD0Ev.c stores the SAME ADDRESS
# (0x021227c0) under dsd's other name for it, `_ZTV12daBgSnmBdy_c`.
# config/arm9/overlays/ov072/symbols.txt carries both names on that one
# address, and the pair repeats for SnowmanHead at 0x021228bc
# (_ZTV11SnowmanHead / _ZTV12daBgSnmHed_c). Left alone the D0s are two
# LNK2019s.
#
# A per-source rename rather than an /alternatename, and NOT because the LHS
# would be defeated -- neither daBgSnm* name is defined anywhere in this link,
# so an alias would in fact hold. It is a -D because this is one TU per name
# reaching for its own class's own table, which is exactly what a per-source
# rename is for, and because it needs no append to the shared
# tools/alternatename_baseline.txt. The R3 defeat mode does not apply here and
# is not being claimed.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daBgSnmBdy_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZTV12daBgSnmBdy_c=_ZTV11SnowmanBody")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11SnowmanHeadD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZTV12daBgSnmHed_c=_ZTV11SnowmanHead")
# Same shape once more, ov070's FlyGuy (lane w3-d): daPropeller_Heyho_c_classInit.c and
# _ZN19daPropeller_Heyho_cD1Ev.c both store `_ZTV6FlyGuy`, which is what
# hal/actor_classes_ov070.cpp defines, while _ZN19daPropeller_Heyho_cD0Ev.c stores the SAME
# ADDRESS (0x02123168) as `_ZTV19daPropeller_Heyho_c` -- symbols.txt carries
# both names on it. One TU, one name, so a per-source rename rather than an
# append to the shared alternatename baseline. As with the two ov072 D0s, the
# LHS is undefined everywhere in this link, so this is not the R3 defeat case.
# BOTH PATHS, 2026-09-13 (lane SYNC3): see the dScMgPanel_c note above. This
# TU is substituted whole as well, and without the generated path the vtable
# name rename would stop applying and the link would ask for a symbol no config
# defines.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_propeller_heyho.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_propeller_heyho.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZTV19daPropeller_Heyho_c=_ZTV6FlyGuy")

# R5, run linkw wave 15 (lane w15): THREE ov025 TUs spell ov025's OWN vtable
# 0x021139d4 (_ZTV11PyramidLift) as `data_ov027_021139d4` -- ov025, ov027,
# ov032 and ov036 all link at 0x021111a0 and dsd raced the name. The three load
# sites (0x0211213c in the D1, 0x021121b0 in the D0, 0x02112648 in the Spawn)
# all say module:overlay(25). Routed with a PER-SOURCE RENAME rather than an
# /alternatename on purpose: ov027 HAS a real data_ov027_021139d4 of its own in
# its config, and an alias with that LHS would be defeated the day ov027 is
# mounted per symbol -- the ov071/ov073 R3 failure. A -D cannot be defeated.
# The target is the HOST ARRAY, since 0x021139d4 is excluded from the mount.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11PyramidLiftD0Ev.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11PyramidLiftD1Ev.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_dp_lift.cpp"
    PROPERTIES COMPILE_DEFINITIONS "data_ov027_021139d4=_ZTV11PyramidLift")
# R6, the same shape one address over: src/__sinit_ov025_02112a44.c spells
# ov025's own destructor-chain node 0x02113acc as `data_ov032_02113acc`. The
# load site 0x02112a9c says module:overlay(25), and ov032 has a real
# data_ov032_02113acc with four readers already in src, so the same argument
# applies and this is a -D too.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/__sinit_ov025_02112a44.c"
    PROPERTIES COMPILE_DEFINITIONS "data_ov032_02113acc=data_ov025_02113acc")
# R7, intro-cutscene landing: the intro's cutscene sprite body
# src/func_ov002_020f2340.cpp calls OAM::RenderSub(attr,int,int) by its MSVC
# spelling, and the intro lane's alternatename routed that to the ii ROM body
# it was verified against. The VS lane's width bridge (vs_aliases.inc, the
# WHF3 class) targets the SAME spelling and won by DEFINITION: the iiii TU's
# object exports the HH name, so the alias died at the first merged link
# (alternatename_guard caught it). Rename the intro reference; the alias for
# the renamed spelling lives in hal/actor_classes_intro.cpp. A -D cannot be
# defeated -- the R4/R5 argument. The four ov075 HH callers stay on their
# bridge, each side bound to the body it was proven against.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov002_020f2340.cpp"
    PROPERTIES COMPILE_DEFINITIONS "RenderSub=RenderSub_ii")

# run linkw wave 6, lane w6-D: THE SAME DISEASE A THIRD TIME, and this one
# would have linked SILENTLY on two of its three references.
# src/game/actors/daObjPathLift_c.cpp (PATH_LIFT's CleanupResources) releases its three
# SharedFilePtrs through the shared-header ROLE-NAME placeholders G0/G1/G2 --
# and G0/G1 are SINGLE GLOBAL NAMES hal/cxx_aliases.cpp has already bound to
# other objects (_G0 -> _data_020a0eac, the GAME HEAP pointer; _G1 ->
# _data_ov002_0210e05c, SignPost's KCL). Only G2 came back as a link error;
# the other two would have resolved quietly and released the wrong storage --
# exactly the CannonHatch/MetalNet failure cxx_aliases.cpp:1313 describes,
# which was fixed there at the SOURCE. The byte-verified tree is not editable
# from here, so the caller gets the per-source rename instead (the R1/R2
# remedy above).
# The three targets are the ROM's own, read off this body's literal pool in
# release order (0x02147098/9c/a0, each feeding the next
# SharedFilePtr::Release at 0x02147078/80/88):
#   G0 = data_ov002_0210d9f0   G1 = data_ov100_02148a54   G2 = data_ov100_02148a5c
# The rename cannot go straight to the mount names: G1/G2 arrive from
# include/decl_common.h:396-397 as `extern int G1[];` while the same header
# already declares data_ov100_02148a54/5c as scalars at 1280-1281, and MSVC
# rejects the redeclaration (C2040, measured). So the three go to private
# names this lane owns, and hal/actor_classes_ov100pl.cpp binds each onto the
# mounted object with a C-name /alternatename -- one indirection, no header
# edit, and each LHS is undefined everywhere so the alias cannot be defeated.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/daObjPathLift_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_pathlift_file0;G1=port_pathlift_file1;G2=port_pathlift_file2")

# RUN LINKW WAVE C: the same remedy for the three OTHER linked TUs that
# collide on G0/G1/VT. port/tools/alias_audit.py found them; each target below
# is the address that TU's own ROM body loads, read out of
# extracted/overlays/overlay_NNNN.bin, and the derivation with the disassembly
# is in hal/cxx_aliases.cpp beside the five /alternatename rows these point at.
# All three are LIVE wrong-object bugs in the shipping binary, none of which
# fails at link -- the CannonHatch/MetalNet shape.
#
# Coffin's two targets are ov071's bss cells and NOT the identically-addressed
# ov070 ones the config names first: the two overlays share base 0x0211f000
# and the port mounts both as separate host objects, so the wrong pick here is
# the ov043/ov047 mistake rather than a harmless synonym.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN6Coffin16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_coffin_file0;G1=port_coffin_file1")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN15BookShotSpawner13InitResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_bookshotspawner_file0;G1=port_bookshotspawner_file1")
# The spawner's deleting destructor stores its OWN table, which in this port is
# the host array hal/actor_classes_ov063.cpp declares. HEAP is left alone: its
# binding to the game heap pointer 0x020a0eac is what this body means.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN15BookShotSpawnerD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT=port_bookshotspawner_vt")
# Lane DTOR-PAIRS-C: the brick-block tag's deleting destructor is the same
# shape -- `t[0] = (int)VT;` then Actor's D2 then Deallocate(HEAP) -- and its
# ROM store relocates to its OWN table (ov002 from:0x020b41b0 -> 0x02108c18,
# _ZTV10BrickBlock, the host array hal/actor_classes_bob_world.cpp fills).
# decl_common.h already declares _ZTV10BrickBlock as `extern int []`, the
# same type the VT placeholder carries, so the rename is a plain substitution.
# HEAP stays bound to the game heap (the pool's second word is 020A0EAC).
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10BrickBlockD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT=_ZTV10BrickBlock")
# Lane DTOR-PAIRS-C: the cutscene object's deleting destructor, the same VT/HEAP
# shape; its store relocates to its own table (ov002 from:0x020f1fc4 ->
# 0x0210bd60, _ZTV14CutsceneObject, the host array hal/actor_classes_intro.cpp
# fills; decl_common.h already declares it `extern int []`).
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN14CutsceneObjectD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT=_ZTV14CutsceneObject")
# Lane DTOR-PAIRS-C: the four bully destructors spell VT1 for their second vptr
# store, and the ROM relocates all four stores to ov064 0x0211b768 -- the
# bullies' base table, data_ov064_0211b768, hosted in hal/actor_classes_ov027.cpp
# (which rides the same three targets as slice_gate177). Per source, so bare VT1
# (auto_bss's dummy) keeps serving whatever else still spells it. G0 is the game
# heap by the standing alias, the pool's last word (020A0EAC) in both D0s.
foreach(bully_dtor _ZN5BullyD1Ev _ZN5BullyD0Ev _ZN8BigBullyD1Ev _ZN8BigBullyD0Ev)
    set_source_files_properties(
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/${bully_dtor}.c"
        PROPERTIES COMPILE_DEFINITIONS
        "VT1=data_ov064_0211b768")
endforeach()
# Lane DTOR-PAIRS-C: the castle water's deleting destructor spells VT0 and VT1
# (the SphereClsn placeholder pair). The ROM relocates its two stores to ov009
# 0x02113a18 (_ZTV14daObjMcWater_c, hosted in hal/actor_classes.cpp) and ov002
# 0x0210ae38 (the Platform base table, hosted as _ZTV10dBgActor_c), the Mecha03
# treatment below; G0 is the game heap by the standing alias (020A0EAC).
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_mc_water.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV14daObjMcWater_c;VT1=_ZTV10dBgActor_c")

# RUN LINK60 lane A2: SPINDRIFT'S KILL-BY-INVINCIBLE EDGE, misrouted since the
# ov081 seat. One ROM address, 0x020ada40, resolved two ways in one binary.
#
# The port defines both occupants: _func_ov002_020ada40 out of
# src/_ZN12dEnemyBase_c20KillByInvincibleCharERK10Vector3_16R6Player5Fix12IiE.cpp (the real 0x100-byte body, 0x020ada40..0x020adb40
# in ov002's delinks) and _func_ov004_020ada40
# out of the ov004 TU. dsd tagged every level-overlay call into that address
# module:overlays(2,4) because it cannot tell the occupants apart, and ov004
# loads only alongside ov006 for a minigame scene while ov081 is a level actor
# overlay co-resident with ov002. TWELVE other TUs in src/ spell the target
# `func_020ada40` -- ov062 x2, ov063, ov064, ov065 x2, ov081's own
# func_ov081_021243cc, ov084, ov090, ov100, ov102 and BobOmb::Behavior -- and
# land on hal/bob_enemy_bridges.cpp's
# /alternatename:_func_020ada40=_func_ov002_020ada40. NINE of those twelve are
# in this link; func_ov081_021243cc, func_ov090_021310b4 and
# func_ov102_0214cbec are not. Nine is the number that matters, because it is
# the count of live callers the routing this rename joins already carries.
# src/func_ov081_02123910.cpp
# is the single outlier: it takes the name from include/decl_Enemy.h:24 and so
# binds to the ov004 body, whose first statement is a null guard on
# data_ov004_020beb68 -- the permanently-zero host global in
# hal/actor_classes_ov081.cpp that nothing in this build ever writes. The kill
# path returned doing nothing, every frame, and neither the byte gate nor the
# linkage count could see it.
#
# The rename spells this one TU's reference the way those twelve already spell
# it, so the existing alias does the routing and no new symbol is added.
# A -D and not an alias of its own: the mangled Enemy name is DEFINED in this
# binary by the ov004 TU, so an /alternatename with it on the left would be
# defeated silently -- the R3 ov071/ov073 failure, already realised here.
#
# Arity, measured rather than assumed. The ROM body reads r0/r1/r2 and never
# reads r3 on entry (it recomputes the slot-0x74 result itself at 0x020adaf0),
# so 0x020ada40 takes THREE parameters, which is what src/func_ov081_021243cc.cpp
# declares and what src/_ZN12dEnemyBase_c20KillByInvincibleCharERK10Vector3_16R6Player5Fix12IiE.cpp defines. The ROM's own call at
# 0x02123988 still loads r3 from the vcall it just made, and the recovered
# .cpp mirrors that, so the caller passes a fourth argument the callee ignores.
# Both sides are cdecl, so the caller cleans it up and the extra argument is
# inert. hal/bob_enemy_bridges.cpp:34 declares four and is a declaration only.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov081_02123910.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_ov004_020ada40=func_020ada40")

# func_ov002_020d708c is C++ inside a .c (a `virtual` vtable shadow), which
# MSVC will not compile as C. hostgen.py already emits .cpp with the symbols
# wrapped back to C linkage, so route it through hostgen rather than editing
# the byte-verified tree.
# engine/fader/StartExitFaderWipe.c is the same case: a `virtual` class in a
# .c, this time the FaderWipe the death path calls SetToStart on. hostgen
# resolves a path as well as a bare name, so the fader subdirectory works.
# func_ov002_020c897c does void-pointer arithmetic (the NoControl body's
# `*(void**)(c + id * 4 + 0xdc) + 0x50` anim probe), which MSVC C rejects
# with C2036; hostgen's VOIDPP_ARITH rewrite retypes the deref to char*.
# func_ov002_020cfbdc and func_ov002_020d6c60 are a third shape: decl_common.h
# declares each with a different pointer parameter type than its own TU defines
# it with (void* vs char*, and (char*,void*) vs (char*,char*)). Two separate
# symbols while the decl_*.h headers were C++-mangled, one extern "C" overload
# since main gave them C linkage -- error C2733. hostgen's HEADER_SHADOW hides
# the header's declaration of just those names, so neither src/ nor include/
# has to move.
# THREE ENTRIES LEFT THIS LIST 2026-09-13 (main -> port sync, lane SYNC3).
# main folded func_ov002_020c897c, func_ov002_020cfbdc and
# _ZN6Player17St_NoControl_InitEv into src/actors/Player.cpp. The first two no
# longer need anything of their own: 020c897c's void-pointer arithmetic is gone
# from main's spelling of the body (the only VOIDPP_ARITH match left anywhere in
# that TU is inside a comment), and 020cfbdc's C2733 is no longer a header
# collision, so HEADER_SHADOW cannot answer it -- the TU redeclares the name
# itself, inside the body it defines. St_NoControl_Init's CALL_STATE_FN dispatch
# and that redeclaration are both answered by the WHOLE-TU substitution of
# src/actors/Player.cpp at the top of this file.
set(GATE10_SYMS func_ov002_020dec70 func_ov002_020d708c
    engine/fader/StartExitFaderWipe
    engine/fader/StartEntranceFaderWipe
    func_ov002_020d6c60
    # Three Player state functions whose mwcc member-pointer dispatch calls a DS
    # code word raw (St_WallJump_Main's was the walljump crash): hostgen's
    # CALL_STATE_FN table routes each through hal_call_state_fn, retiring the
    # Player_St_*.cpp host copies these three used to be.
    _ZN6Player12St_Jump_MainEv _ZN6Player16St_WallJump_MainEv
    # func_ov002_020e444c is an ARITY disagreement between two matched TUs, the
    # ARG_WIDTH shape one register wider: include/decl_common.h:1461 declares
    # func_ov002_020e3f90 `(void)` and this body calls it with no argument,
    # while src/func_ov002_020e3f90.c defines it `(char*)` and dereferences
    # that pointer on its first line. The ROM says they agree -- 0x020e4454
    # `mov r4,r0` then 0x020e4458 `bl 0x020e3f90`, so r0 is still the incoming
    # Player and mwccarm had nothing to move. Under x86 cdecl the callee would
    # read its receiver off a stack slot the caller never wrote. hostgen's
    # HEADER_SHADOW hides the `(void)` declaration for this TU alone and its
    # REG_RIDE_ARG table spells the argument, which retires
    # port/unmatched/func_ov002_020e444c_hostcopy.c -- the whole hundred-line
    # body transcribed to change that one call. It is the body that seats the
    # player's head-model world matrix (`*(Matrix4x3*)(head+0x1c)`).
    func_ov002_020e444c)
set(GATE10_GEN "")
foreach(sym IN LISTS GATE10_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE10_GEN "${sym_out}")
endforeach()

# Every ovdata mount also writes a <out>.c.map sidecar, and OV_DATA_MAPS
# collects them for the --cross pass at the end of this block. See the module
# docstring in tools/ovdata.py: one invocation cannot see another's symbols, so
# a pointer from one mounted overlay into another needs a pass that has all of
# them in hand. tools/ovsweep.py reads the same sidecars to check the result.
set(OV_DATA_MAPS "")

set(OV002DATA_C "${CMAKE_BINARY_DIR}/host-src/ov002_data.c")
add_custom_command(OUTPUT "${OV002DATA_C}" "${OV002DATA_C}.map"
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/ovdata.py" ov002
            "${OV002DATA_C}" --from-list "${CMAKE_CURRENT_SOURCE_DIR}/ov002_syms.txt"
            ${ROMCLEAN_FLAG} ${LINKONLY_FLAG}
    DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/ovdata.py"
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob_common.py"
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/link_only.py"
            "${CMAKE_CURRENT_SOURCE_DIR}/ov002_syms.txt"
    COMMENT "ovdata ov002")
list(APPEND OV_DATA_MAPS "${OV002DATA_C}.map")
if(PORT_ROM_CLEAN)
    list(APPEND ROMCLEAN_PARTS "${OV002DATA_C}.blobmap")
endif()

# Gate 30: the LEVEL overlays, one whole-image mount each.
#
# A level overlay cannot be mounted symbol by symbol: its LVL_Overlay hangs
# nine object tables off one base and the loaders walk them by count, straight
# across whatever symbol boundaries dsd happened to name. --whole emits the
# entire image as one array and rebases its internal pointers from the reloc
# table.
#
# Every level overlay is linked at the SAME DS base (0x021111a0) because the
# DS only ever has one loaded. On the host they are separate arrays and
# port_ovNNN_at() is per-overlay, so hosting several at once is just several
# mounts; hal/level_boot.cpp's table picks which one the boot walks.
#
#   ov009 = level 1, castle grounds  (data/stage/main_castle), course 29
#   ov014 = level 6, Bob-omb Battlefield  (data/stage/bombhei_map), course 0
#   ov010 = level 2, a castle interior floor, course 29 (interior-shaped)
#   ov015 = level 7, Whomp's Fortress, course 1 (open course)
#   ov011 = level 3, the castle garden  (data/stage/main_garden), course 29
#   ov016 = level 8, Jolly Roger Bay  (data/stage/kaizoku_irie), course 2
#
# Both facts come from the ROM, not from the overlay numbering: the arm9's
# level-to-overlay table data_020758c8 maps level -> overlay (it is level+8),
# and each overlay's LVL_Overlay names its own kcl/bmd/icg/icl OV0 HANDLES,
# resolved through build/assets/handles.tsv rather than by arithmetic. See the
# evidence note at the top of hal/level_boot.cpp, including what a derived
# handle constant got wrong; and the course numbers are the arm9
# SUBLEVEL_LEVEL_TABLE (0x02075298) which picks levels of two shapes here.
#
# ADDING A LEVEL IS MECHANICAL, and this list plus a row in hal/level_boot.cpp's
# port_level_table[] is the whole of it. The mount recipe lives in the header
# docstring of tools/ovdata.py; the level-boot recipe beside port_level_table[].
set(PORT_LEVEL_OVERLAYS ov009 ov014 ov010 ov015)
# gate 95: ov011 is level 3's own overlay (data/stage/main_garden, the castle
# garden, course 29). Mounted whole like the four above; the level->overlay map
# data_020758c8[3] = 11, the LVL_Overlay table data_02092208[3] = 0x021113ac,
# and the four handles at LVL_Overlay+8 resolve through build/assets/handles.tsv
# to main_garden's kcl/bmd/icg/icl. Its actor-overlay roster (ov063 ov085 ov089
# ov098 ov100 ov102) is all already mounted except ov063, so its shared cast
# spawns for free and only ov063-owned classes are skipped by name at the gate.
list(APPEND PORT_LEVEL_OVERLAYS ov011)
# gate 128: ov017 is level 9's own overlay (data/stage/kaizoku_ship, the sunken
# pirate ship, course 2 -- Jolly Roger Bay's ship sublevel). Mounted whole like
# the five above; the level->overlay map data_020758c8[9] = 17 (level+8, a read
# not an assumption), the LVL_Overlay table data_02092208[9] = 0x02111a78, and
# the four handles at LVL_Overlay+8 (bmd 1894 / kcl 1892 / icg 1895 / icl 1896)
# resolve through build/assets/handles.tsv to kaizoku_ship's bmd/kcl/icg/icl.
# SUBLEVEL_LEVEL_TABLE[9] (0x02075298) is 0x02 = course 2. Its actor-overlay
# roster (ov064 plus the always-loaded ov098/ov102) has ov098 and ov102 already
# mounted; ov064-owned classes are skipped by name at the gate. own_sinits 0.
list(APPEND PORT_LEVEL_OVERLAYS ov017)
# gate 121: ov016 is level 8's own overlay, the first MAIN COURSE the port
# mounts (data/stage/kaizoku_irie, Jolly Roger Bay, course 2). Read from the
# ROM like the rest: data_020758c8[8] = 16, LVL_Overlay data_02092208[8] =
# 0x02113b90, handles at +8 (bmd 0x0761, kcl 0x075f, icg 0x0762, icl 0x0763)
# resolve through build/assets/handles.tsv to kaizoku_irie's all.bmd/kcl/icg/icl.
# SUBLEVEL_LEVEL_TABLE[8] = 2 = course 2, a big open course (384 load relocs, a
# 25609-byte KCL). Mounted --whole like the rest; own_sinits stays 0.
list(APPEND PORT_LEVEL_OVERLAYS ov016)
# gate 114: ov012 is level 4's own overlay (data/stage/castle_b1, a castle
# basement floor, course 29). Mounted whole like the five above; read from the
# ROM: the level->overlay map data_020758c8[4] = 12, the LVL_Overlay table
# data_02092208[4] = 0x02111c54, and the four OV0 handles at LVL_Overlay+8
# (raw 0x0615/0x061b/0x061c/0x061d) resolve through build/assets/handles.tsv --
# the overlay's handle base is a constant +232 above the tsv index, confirmed
# across all five known-good levels -- to castle_b1's kcl/bmd/icg/icl.
# SUBLEVEL_LEVEL_TABLE[4] (0x02075298) is 0x1d = course 29, the castle family,
# interior-shaped like level 2. own_sinits stays 0.
list(APPEND PORT_LEVEL_OVERLAYS ov012)
# gate 117: ov013 is level 5's own overlay (data/stage/castle_2f, the castle
# second floor, course 29). Same evidence path: data_020758c8[5] = 13, the
# LVL_Overlay table data_02092208[5] = 0x02111844, and the four handles at
# LVL_Overlay+8 (raw 0x060b/0x0612/0x0613/0x0614, +232) resolve to castle_2f's
# kcl/bmd/icg/icl. SUBLEVEL_LEVEL_TABLE[5] = 0x1d = course 29. own_sinits 0.
list(APPEND PORT_LEVEL_OVERLAYS ov013)
# gate 135: ov018 is level 10's own overlay (data/stage/snow_mt, Cool Cool
# Mountain, course 3 -- the mountain main course). Mounted whole like the eight
# above; read from the ROM: the level->overlay map data_020758c8[10] = 18 (it is
# level+8, a read not an assumption), the LVL_Overlay table data_02092208[10] =
# 0x02112f2c, and the four OV0 handles at LVL_Overlay+8 (raw 0x06d7/0x06d5/
# 0x06d8/0x06d9) resolve through build/assets/handles.tsv -- the overlay's handle
# base is a constant +232 above the tsv index, confirmed across all nine
# known-good levels -- to snow_mt's all.bmd/kcl/icg/icl (a 46876-byte KCL, a big
# main course). SUBLEVEL_LEVEL_TABLE[10] (0x02075298) is 0x03 = course 3.
# Mounted --whole like the rest; own_sinits stays 0.
list(APPEND PORT_LEVEL_OVERLAYS ov018)
# gate 142: ov019 is level 11's own overlay (data/stage/snow_slider, Cool Cool
# Mountain's slide sublevel, course 3). Mounted whole like the seven above; read
# from the ROM: the level->overlay map data_020758c8[11] = 19 (level+8, a read
# not an assumption), the LVL_Overlay table data_02092208[11] = 0x02112c68, and
# the four OV0 handles at LVL_Overlay+8 (raw bmd 0x07c4 / kcl 0x07c2 / icg 0x07c5
# / icl 0x07c6) resolve through build/assets/handles.tsv -- looked up directly in
# the handle column, the same delta-0 mapping the known-good levels 8 and 9 use
# -- to snow_slider's all.bmd/kcl/icg.bin/icl.bin. SUBLEVEL_LEVEL_TABLE[11]
# (0x02075298) is 3 = course 3, an outdoor slide with subCount = 1 (43 Standard
# and Simple entries) and a 57805-byte KCL, the largest mounted so far.
# own_sinits stays 0.
list(APPEND PORT_LEVEL_OVERLAYS ov019)
# gate 149: ov020 = level 12, Big Boo's Haunt (data/stage/teresa_house), course 4.
# data_020758c8[12] = 20, LVL_Overlay data_02092208[12] = 0x021138fc, OV0 handles
# at +8 (bmd 0x07d2/kcl 0x07cc/icg 0x07d3/icl 0x07d4) resolve directly through
# handles.tsv to teresa_house's all.bmd/kcl/icg/icl; SUBLEVEL_LEVEL_TABLE[12] = 4.
# Mounted --whole; own_sinits 0.
list(APPEND PORT_LEVEL_OVERLAYS ov020)
# gate 163: ov022 = level 14, Lethal Lava Land (data/stage/fire_land), course 6.
# Read from the ROM, not the overlay numbering: the level->overlay map
# data_020758c8[14] = 22 (level+8, a read not an assumption), the LVL_Overlay
# table data_02092208[14] = 0x02113228, and the four OV0 handles at LVL_Overlay+8
# (bmd 0x0742 / kcl 0x0740 / icg 0x0743 / icl 0x0744) resolve DIRECTLY through
# build/assets/handles.tsv -- the ov0 handle in the overlay IS the tsv handle, no
# arithmetic, the delta-0 mapping the known-good levels use -- to fire_land's
# all.bmd (26833) / kcl (22144) / icg.bin (21732) / icl.bin (512). Handles read
# from the RAW ndspy overlay image (extracted/overlays/overlay_0022.bin), the
# same image ovdata.py mounts; the dsd export is stale against config
# re-addressings. SUBLEVEL_LEVEL_TABLE[14] (0x02075298) is 0x06 = course 6, a
# main course with subCount 1. Mounted --whole like the rest; own_sinits stays 0.
list(APPEND PORT_LEVEL_OVERLAYS ov022)
# gate 170: ov023 = level 15, Lethal Lava Land (data/stage/fire_mt), course 6 --
# a sublevel of the fire main course (level 14 is the same course 6, ov022, the
# main stage; 15 is its second area). Read from the ROM like the rest, all three
# facts measured out of the arm9 tables in extracted/arm9_dec.bin at base
# 0x02004000, verified against all twelve known-good levels first: the
# level->overlay map data_020758c8[15] = 23 (level+8, a read not an assumption),
# the LVL_Overlay table data_02092208[15] = 0x02111b88, and the four OV0 handles
# at LVL_Overlay+8 (bmd 0x0748 / kcl 0x0745 / icg 0x0749 / icl 0x074a) resolve
# DIRECTLY through build/assets/handles.tsv -- the ov0 handle in the overlay IS
# the tsv handle, delta 0, the same mapping the known-good levels 8..12 use --
# to fire_mt's fire_mt_all.bmd / fire_mt.kcl / fire_mt_icg.bin / fire_mt_icl.bin.
# The handles must be read out of extracted/overlays/overlay_0023.bin (the
# unpack.py output ovdata itself reads), NOT extracted/dsd/arm9_overlays/ov023.bin
# -- the dsd export is stale and drifts these handle halfwords by a constant,
# which is what the +232 the castle-level comments mention actually was.
# SUBLEVEL_LEVEL_TABLE[15] (0x02075298) is 0x06 = course 6, subCount 1, a
# 38002-byte KCL. Mounted --whole like the rest; own_sinits stays 0. This block
# is append-only and self-contained (distinct overlay name); a reviewer folds it
# into the sibling level streams at merge.
list(APPEND PORT_LEVEL_OVERLAYS ov023)
# gate 156: ov021 = level 13, Hazy Maze Cave (data/stage/cave), course 5.
# data_020758c8[13] = 21 (level+8, a read not an assumption), LVL_Overlay
# data_02092208[13] = 0x021138c4, OV0 handles at +8 (bmd 0x0709/kcl 0x0706/
# icg 0x070a/icl 0x070b) resolve directly through handles.tsv to cave's
# cave_all.bmd/cave.kcl/cave_icg.bin/cave_icl.bin; SUBLEVEL_LEVEL_TABLE[13] = 5,
# subCount 8, a 61224-byte KCL. Mounted --whole; own_sinits 0.
list(APPEND PORT_LEVEL_OVERLAYS ov021)
# gate 204: ov045 = level 37, Bowser in the Fire Sea (data/stage/koopa2_map),
# course 16 -- the first level the port mounts outside the 1..15 block, and the
# platform overlay the collision family's ExtendingMeshCollider has been waiting
# on (port/slice_w1l4.txt records why the class could not be seated without it).
# Read from the ROM like the rest, and calibrated against all fifteen mounted
# rows before anything about ov045 was believed:
#   data_020758c8[37] = 45, LVL_Overlay data_02092208[37] = 0x021124d4, OV0
#   handles at LVL_Overlay+8 (bmd 0x0782 / kcl 0x077a / icg 0x0783 / icl 0x0784)
#   resolve DIRECTLY through build/assets/handles.tsv -- delta 0, the mapping
#   levels 8..15 use -- to koopa2_map's koopa2_map_all.bmd (30726) /
#   koopa2_map.kcl (33715) / koopa2_map_icg.bin (34352) / koopa2_map_icl.bin.
#   SUBLEVEL_LEVEL_TABLE[37] (0x02075298) is 0x10 = course 16, subCount 1.
# koopa2 is the ROM's own name for the second Bowser stage: levels 35/36 are
# course 15 (koopa1, Dark World), 37/38 course 16, 39 course 17.
#
# A CORRECTION TO THE COMMENTS ABOVE, since a later level had to re-derive it:
# data_020758c8 is a WORD table, stride 4, not the byte table "data_020758c8[N]"
# reads as. Byte-stride gets every one of the fifteen known levels wrong (level
# 4 comes back as ov9); word-stride reproduces all fifteen exactly. Same for
# data_02092208. hal/level_change.cpp's port_level_overlay_id already reads it
# with the *4, so only the prose was loose.
#
# The handles must come from extracted/overlays/overlay_0045.bin -- ov045 is
# compressed:true in overlays.yaml, so extracted/dsd/arm9_overlays/ov045.bin is
# the COMPRESSED image and reading handle halfwords out of it is reading noise,
# the trap the ov023 block above describes from the other direction.
#
# THE SHARED-WINDOW QUESTION, asked before the mount rather than after: ov045's
# footprint is 0x021111a0..0x02113280 (code 8160 + bss 256), and ovdata.py
# --cross drops a target that lands in MORE THAN ONE mounted window. Every
# address in ov045's window already sits inside both ov009's (..0x02113ee0) and
# ov016's (..0x02114ea0), so it is already contested by two mounts and this
# mount cannot flip a single target from resolved to raw. Measured, not
# reasoned: before the mount 127 rebased / 4115 raw / 704 contested; after,
# 133 / 4327 / 705 -- the six new rebased pointers are all ov045's own and
# ZERO pre-existing pointers changed or were lost (patch-body diff, w3-d
# review). The raw total grows because ov045's image adds addresses; do not
# read 4327 as a regression when calibrating the next mount.
list(APPEND PORT_LEVEL_OVERLAYS ov045)
# w5-e: ov046 = level 38, the Bowser in the Fire Sea BATTLE ARENA
# (data/stage/koopa2_boss), course 16 -- the first boss arena the port mounts.
# Read from the ROM like the rest and re-validated against all sixteen mounted
# rows first: data_020758c8[38] = 46 (word table), LVL_Overlay data_02092208[38]
# = 0x02111560, OV0 handles at +8 (bmd 0x0777 / kcl 0x0775 / icg 0x0778 /
# icl 0x0779) resolve DIRECTLY through build/assets/handles.tsv (delta 0) to
# koopa2_boss_all.bmd (4908) / koopa2_boss.kcl (2561) / koopa2_boss_icg.bin
# (17580) / koopa2_boss_icl.bin (512); handles read from
# extracted/overlays/overlay_0046.bin, never the dsd export.
# SUBLEVEL_LEVEL_TABLE[38] = 0x10 = course 16, subCount 1, flags 0. The arena's
# object-overlay set is ov060 + ov089: LoadOrUnloadObjectOverlays
# short-circuits idx 0x24/0x26/0x28 (the three koopaN_boss arenas) to ov060
# with an early return, skipping even the ov098/ov102 tail -- but the
# selector loop runs first, and its row also loads ov089 (KEY 282 /
# LAST_STAR 283, the boss-reward spawns; the KEY-drop wave's hook).
# Mounted --whole; own_sinits 0.
# Shared-window note (the ov045 calibration above): ov046's footprint is
# 0x021111a0..0x021116e0 (code 1344, bss 0, overlays.yaml; compressed:true like
# ov045) and sits entirely inside windows already contested by the sixteen
# prior level mounts, so this mount cannot flip a resolved target raw; the
# cross-pass counts are re-measured in this lane's report.
list(APPEND PORT_LEVEL_OVERLAYS ov046)
# run linkw wave 7 (lane w7-c): the other two koopaN_boss arenas, so all three
# boss arenas are mounted. Every number below was re-derived on this lane from
# extracted/arm9_dec.bin (base 0x02004000) and the raw overlay images, and the
# whole pipeline was re-validated first: all 52 words of data_02092208 dumped
# and checked against the seventeen already-mounted rows, 17/17 exact.
#
# ov044 = LEVEL 36, Bowser in the Dark World arena (data/stage/koopa1_boss),
# course 15. data_020758c8[36] (word at 0x02075958) = 0x2c = 44 -- level+8, and
# the +8 is a READ: all 52 words are contiguous 8..59. LVL_Overlay
# data_02092208[36] (word at 0x02092298) = 0x021113b0. OV0 handles at +8 read
# out of extracted/overlays/overlay_0044.bin (offset 0x210; ov044 is
# compressed:true, so the dsd export is the compressed image and its halfwords
# are noise): bmd 0x076b / kcl 0x0769 / icg 0x076c / icl 0x076d, resolved
# DIRECTLY through build/assets/handles.tsv (delta 0) to koopa1_boss_all.bmd
# (1899, 4411 bytes) / koopa1_boss.kcl (1897, 1624) / koopa1_boss_icg.bin
# (1900, 13728) / koopa1_boss_icl.bin (1901, 512). SUBLEVEL_LEVEL_TABLE[36]
# (byte at 0x020752bc) = 0x0f = course 15; subCount 1, flags 0.
list(APPEND PORT_LEVEL_OVERLAYS ov044)
# ov048 = LEVEL 40, Bowser in the Sky arena (data/stage/koopa3_boss), course 17.
# data_020758c8[40] (word at 0x02075968) = 0x30 = 48. LVL_Overlay
# data_02092208[40] (word at 0x020922a8) = 0x02111624. OV0 handles at +8 out of
# extracted/overlays/overlay_0048.bin (offset 0x484; compressed:true as well):
# bmd 0x0787 / kcl 0x0785 / icg 0x0788 / icl 0x0789 -> koopa3_boss_all.bmd
# (1927, 7228) / koopa3_boss.kcl (1925, 1889) / koopa3_boss_icg.bin (1928,
# 15028) / koopa3_boss_icl.bin (1929, 512). SUBLEVEL_LEVEL_TABLE[40] (byte at
# 0x020752c0) = 0x11 = course 17; subCount 1, flags 0.
#
# Shared-window note (the ov045 calibration two blocks up, asked before the
# mount rather than after): ov044 is 0x021111a0..0x021116a0 (code 1248 + bss 32)
# and ov048 is 0x021111a0..0x02111900 (code 1888, bss 0). Both are strictly
# inside windows the seventeen prior level mounts already contest -- ov009 runs
# to 0x02113ee0 and ov016 to 0x02114ea0 -- so neither mount can flip a target
# from resolved to raw. The cross-pass counts are re-measured in this lane's
# report; the raw total grows because two more images add addresses, which is
# not a regression.
list(APPEND PORT_LEVEL_OVERLAYS ov048)
# run linkw wave 8, lane w8-mounts: every remaining data/stage level the ROM
# has a row for was derived; the sixteen that BOOT are mounted --whole here.
# The full
# derivation -- which read produced which field, the nine already-mounted rows
# the reader reproduced first, the ten level ids that are NOT stages, and each
# level's object-overlay roster out of LoadOrUnloadObjectOverlays -- lives in
# one block beside these overlays' extern declarations in hal/level_boot.cpp.
# Only the two things a CMake reader needs are repeated here.
#
# THE SHARED-WINDOW QUESTION, measured before the mount the way the ov045 and
# ov046 notes above ask for. All sixteen load at 0x021111a0, the same base as
# every level overlay already mounted, and ovdata.py --cross drops a target
# landing
# in more than one mounted window -- so a new mount CAN flip an already-resolved
# pointer to raw and regress a level that already works. Ran the cross pass
# over the old maps and then over old + new: 156 rebased / 4620 raw / 888
# contested across 54 mounts becomes 202 / 5875 / 917 across 70. Every one of
# the 46 new patches belongs to a new overlay, and the set difference the other
# way is EMPTY -- no baseline patch was lost. The raw and contested totals grow
# because the new images add addresses; per the ov045 note, that is not a
# regression to calibrate against.
#
# THAT BASELINE IS THE PRE-ov044 TREE, not this one. The counts above were
# measured against the seventeen-row tree this lane branched from, before the
# ov044/ov048 block directly above landed; the ov044/ov048 lane bounded its own
# two by footprint rather than by these counts. Neither lane measured the
# merged tree, so it was measured on the integration lane instead: 208 rebased
# / 5944 raw / 940 contested across 74 mounts, the +6 over this lane's 202
# being ov022's, with the two koopaN_boss arenas adding no rebased pointer of
# their own. What both lanes established, and what the question is actually
# asking, is that no mount on either side dropped a baseline patch.
#
# ov030 is the one that needed asking: at 19168 bytes it is the LARGEST level
# overlay the port mounts and it extends the shared window to 0x02115ce0, past
# every prior mount's end. That extension is what the measurement above covers,
# and it cost nothing.
#
# Seven more level ids were derived the same way and are NOT here: 16, 21, 25,
# 27, 28, 31 and 33. Each mounts correctly and prints a census; each is blocked
# past the mount by a class this build already registers (FLAME_CHOMP, AMP,
# SNUFIT) or, for 31, by the player's own render path. The level_boot.cpp block
# names each blocker and the SM64DS_SKIP_CLASS run that isolates it, so adding
# their overlays back here is the only CMake work they need.
#
# Levels 36 and 40 (ov044, ov048) are the two koopaN_boss arenas appended just
# above by lane w7-c. This lane derived them independently, agreed, and held
# them for that lane; the two lists union-merged here as intended.
list(APPEND PORT_LEVEL_OVERLAYS
     ov025 ov026 ov027 ov028 ov030 ov031 ov032 ov034 ov043 ov047 ov052 ov053
     ov055 ov056 ov057 ov058)
# run linkw wave 17, lane w17: ov035 is level 27's own overlay
# (data/stage/clock_tower, Tick Tock Clock, course 13) -- the thirty-sixth level
# mount and the first of the seven the wave-8 block marked NOT LANDED to land.
# Read from the ROM like the rest and cross-checked against three EXISTING rows
# (17, 22, 26) before it was written: data_020758c8[27] = 35,
# data_02092208[27] = 0x021120bc, SUBLEVEL_LEVEL_TABLE[27] (0x02075298) = 0x0d
# = course 13, the four handles at LVL_Overlay+8 are bmd 0x070e / kcl 0x070c /
# icg 0x070f / icl 0x0710, subCount 1 and flags 0x00. A small overlay: 0x1ac0
# of code and 0x80 of bss. Mounted --whole; own_sinits stays 0. Its object
# roster is ov065 ov070 ov077 ov084 ov091 ov098 ov102 and only ov077 is
# unmounted, so ov077's classes alone are skipped by name at the gate.
# VS wiring lane: the four VS battle maps the ROM's own list at
# data_ov075_0211c6ec names (levels 51/43/29/42; port/slice_vs.txt section 4).
list(APPEND PORT_LEVEL_OVERLAYS ov059 ov051 ov037 ov050)
list(APPEND PORT_LEVEL_OVERLAYS ov035)
# run linkw wave 21, lane w21: the SIX ids the wave-8 block derived, proved
# mountable and then held back as "NOT LANDED" -- everything that was left of
# the fifty-two after the ten non-stages. Level 27 (ov035, just above) was the
# first of the seven to land; these are the other six.
#
# Every field re-derived from the ROM by this lane rather than copied off that
# block, and the reader proved before it was trusted: it reproduces the
# lvl_overlay of ALL THIRTY-SIX already-mounted rows exactly, and rows 8, 9,
# 17, 22, 26 and 27 field for field -- overlay id, LVL_Overlay address, course,
# subCount, flags and all four handles. The object-overlay reader reproduces
# level 3's documented roster (ov063 ov085 ov089 ov098 ov100 ov102) and the
# ov060+ov089 pair for levels 36/38/40, which is the short-circuit trap.
#
#   lvl  ov     LVL_Overlay   crs sub flg  stage           bmd /kcl /icg /icl
#    16  ov024  0x021129b4   7  1  0x00  desert_land      0713/0711/0714/0715
#    21  ov029  0x02112fd0  10  2  0x00  water_city       07f0/07ed/07f1/07f2
#    25  ov033  0x02111be0  12  1  0x00  tibi_deka_t      07ea/07e8/07eb/07ec
#    28  ov036  0x02112a6c  14  1  0x01  rainbow_cruise   07ab/07a9/07ac/07ad
#    31  ov039  0x02111438  23  1  0x00  habatake         074d/074b/074e/074f
#    33  ov041  0x0211192c  25  1  0x00  metal_switch     07a1/079f/07a2/07a3
#
# All four handles of all six resolve through build/assets/handles.tsv at
# DELTA 0 to one data/stage directory each -- all.bmd, .kcl, _icg.bin, _icl.bin
# -- which is the test the ten non-stage ids fail.
#
# What was blocking them was never the mount. The wave-8 block measured each
# one faulting past a correct mount inside a class this build ALREADY
# registers: FLAME_CHOMP (270) on 16/21/25/28, AMP (266) on 28, SNUFIT (236) on
# 33. Those classes were fixed on the tip between that wave and this one (the
# pointer-to-member width sweep and the ModelAnim slot-5 collision), which is
# what freed these six -- no mount field changed.
#
# Object rosters, with the packs this build does not mount called out; those
# are the worklist the cast lanes take from here:
#    16 ov062 ov070 ov080 ov084 ov092 ov096 ov098 ov102  [unmounted ov092 ov096]
#    21 ov062 ov070 ov077 ov084 ov090 ov098 ov102        [unmounted ov077 ov090]
#    25 ov062 ov070 ov084 ov094 ov098 ov100 ov102        [all mounted]
#    28 ov062 ov070 ov077 ov084 ov091 ov095 ov098 ov102  [unmounted ov077]
#    31 ov084 ov098 ov102                                [all mounted]
#    33 ov065 ov084 ov098 ov102                          [all mounted]
#
# ov030 (19168 bytes) is still the largest level overlay and still sets the
# shared window's end; the largest here is ov029 at 12416, well inside it, so
# none of these six extends the window that ovdata.py --cross contests over.
# Mounted --whole like the rest; own_sinits stays 0 for all six.
list(APPEND PORT_LEVEL_OVERLAYS ov024 ov029 ov033 ov036 ov039 ov041)
# run linkw wave C, lane cat-levels: FIVE MORE, out of the ten ids the wave-8
# block declined as "not stages". They are stages. See the block in
# hal/level_boot.cpp for the measurement that says so and for what the wave-8
# reading actually caught; the short form is that only handle 0 reads as MG/
# minigame art, and only one declined id has a handle equal to 0.
#
#   lvl  ov     LVL_Overlay   crs sub flg  stage           bmd /kcl /icg /icl
#     0  ov008  0x02111210  255  1  0x01  test_map         07d7/07d5/07d8/07d9
#    30  ov038  0x02111218   22  1  0x00  suisou           07c9/07c7/07ca/07cb
#    32  ov040  0x02111228   24  1  0x01  horisoko         075c/075a/075d/075e
#    34  ov042  0x02111218   26  1  0x00  rainbow_mario    07b0/07ae/07b1/07b2
#    46  ov054  0x021112b0   19  5  0x00  ex_l_map         0729/0723/072a/072b
#
# Every handle resolves through build/assets/handles.tsv at DELTA 0 to one
# data/stage directory holding the full four-file set -- <name>_all.bmd,
# <name>.kcl, <name>_icg.bin, <name>_icl.bin -- with real sizes, which is the
# same test the mounted rows pass and the test the five genuinely declined ids
# (29, 41, 42, 43, 51) fail.
#
# THE SHARED WINDOW COSTS NOTHING HERE, by the footprint argument the ov044 and
# ov048 notes use rather than by a re-run of the cross pass. All five load at
# the shared 0x021111a0 level-overlay base and the largest is ov054 at 3008
# bytes, so every one of them is strictly inside the window ov030 (19168 bytes,
# level 22, already mounted) already contests. An overlay that adds no new
# ground cannot take a resolved target away from another mount.
#
# Mounted --whole like the rest; own_sinits stays 0 for all five.
list(APPEND PORT_LEVEL_OVERLAYS ov008 ov038 ov040 ov042 ov054)
set(LEVEL_OV_DATA "")
foreach(ovn IN LISTS PORT_LEVEL_OVERLAYS)
    set(ovn_out "${CMAKE_BINARY_DIR}/host-src/${ovn}_data.c")
    add_custom_command(OUTPUT "${ovn_out}" "${ovn_out}.map"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/ovdata.py" ${ovn}
                "${ovn_out}" --whole ${ROMCLEAN_FLAG} ${LINKONLY_FLAG}
        DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/ovdata.py"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob_common.py"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/link_only.py"
        COMMENT "ovdata ${ovn} (whole image)")
    list(APPEND LEVEL_OV_DATA "${ovn_out}")
    list(APPEND OV_DATA_MAPS "${ovn_out}.map")
    if(PORT_ROM_CLEAN)
        list(APPEND ROMCLEAN_PARTS "${ovn_out}.blobmap")
    endif()
endforeach()

# Gate 17: the level overlay's own actors. ov009 is mounted WHOLE for the
# loaders; its actor code reaches its SharedFilePtrs, CLPS blocks and spawn
# tables BY NAME, so those symbols are mounted a second time per symbol.
# --pack keeps the runs that are really one array contiguous -- ov009's water
# spawn points are three seven-element Vector3 arrays that dsd split into
# twenty-one symbols and func_ov009_02111b1c walks by index.
set(OV009SYMS_C "${CMAKE_BINARY_DIR}/host-src/ov009_syms.c")
add_custom_command(OUTPUT "${OV009SYMS_C}" "${OV009SYMS_C}.map"
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/ovdata.py" ov009
            "${OV009SYMS_C}" --from-list
            "${CMAKE_CURRENT_SOURCE_DIR}/ov009_syms.txt" --pack ${ROMCLEAN_FLAG}
            ${LINKONLY_FLAG}
    DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/ovdata.py"
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob_common.py"
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/link_only.py"
            "${CMAKE_CURRENT_SOURCE_DIR}/ov009_syms.txt"
    COMMENT "ovdata ov009 (per symbol, packed)")
list(APPEND OV_DATA_MAPS "${OV009SYMS_C}.map")
if(PORT_ROM_CLEAN)
    list(APPEND ROMCLEAN_PARTS "${OV009SYMS_C}.blobmap")
endif()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate17.txt" SLICE17_LINES)
set(SLICE17_SOURCES "")
foreach(line IN LISTS SLICE17_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE17_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 18 and up: the ACTOR overlays. Neither the engine overlay nor the
# level's own -- ov085/ov098/ov100/ov102 each carry a handful of classes that
# several levels pull in, and the castle grounds names some of each. They are
# mounted PER SYMBOL like ov002 (nothing walks a table across their symbol
# boundaries the way a level overlay's loaders do), --pack so the runs that
# are really one array stay contiguous, and each list is the overlay's WHOLE
# data span rather than a hand-picked subset -- see the header of any
# ovNNN_syms.txt for why.
# ov001 joins the per-symbol mounts for the HUD's sprite templates (gate 27):
# it is not an actor overlay, but it wants exactly the same treatment --
# packed run, relocations applied, interior pointers rebased to host.
# ov003 joins them for gate 31: not an actor overlay either, mounted for
# exactly one table -- the debug level select's row list. See ov003_syms.txt.
set(PORT_ACTOR_OVERLAYS ov085 ov098 ov100 ov089 ov102 ov001 ov003 ov084
    ov014 ov062 ov091 ov078)
# gate 41-42: ov010 is level 2's own overlay, already mounted whole in
# PORT_LEVEL_OVERLAYS; it joins the per-symbol mounts here so TRAP, LIGHT_BEAM
# and PEACH_PAINTING reach their SpawnInfo records by name -- the gate-17 shape
# of ov009/ov014 applied to the castle interior. See port/ov010_syms.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov010)
# gate 50: ov080 is an ordinary actor overlay carrying the castle interior's
# PAINTING (daPicGate_c, 307) among three other classes; mounted per symbol so
# the actor reaches its SpawnInfo record, tuning tables and twelve state
# statics by name. See port/ov080_syms.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov080)
# gate 59: ov015 is level 7's own overlay (Whomp's Fortress mechanical
# platforms), already mounted whole in PORT_LEVEL_OVERLAYS; it joins the
# per-symbol mounts here so the eight platform classes reach their SpawnInfo
# records and construction-data statics by name -- the gate-17 shape of
# ov010/ov014 applied to a third level overlay. Its seven vtables are host
# arrays the registry fills (two are unnamed data symbols dsd left as plain
# data). See port/ov015_syms.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov015)
# gates 64-69: ov079 is an ENEMY overlay (the ov078/ov079/ov080 set, all linked
# at base 0x02123740 because the DS loads one at a time) carrying six of Whomp's
# Fortress' living cast -- WHOMP (164), WHOMP_KING (165), BULLET_BILL (222),
# BILL_BLASTER (43), FORTRESS_WALL (47) and FORTRESS_WALL_BREAKABLE (48).
# Mounted per symbol so each class reaches its SpawnInfo record, its
# SharedFilePtr construction statics and its two pointer-to-member state tables
# by name -- the gate-32 shape of ov084/ov078. Its four vtables are host arrays
# the registry fills (BillBlaster's is a plain data symbol dsd left unnamed).
# See port/ov079_syms.txt and hal/actor_classes_wf_enemy.cpp.
list(APPEND PORT_ACTOR_OVERLAYS ov079)
# gate 83: ov095 is Bob-omb Battlefield's SEESAW BRIDGE overlay (its own base
# 0x02135700, one of the seven actor overlays level 6 loads). Mounted per symbol
# so SEESAW_BOB (39) reaches its SpawnInfo, its three parallel file-pointer
# tables and the SharedFilePtr statics the two ov095 sinits construct -- the
# ov085/ov080/ov079 shape. Its three vtables (_ZTV9SeesawBob and the UpDownLift/
# Flamethrower ones) are host arrays the registry fills. See port/ov095_syms.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov095)
# gate 176: ov071 is SCUTTLEBUG's overlay (daSpd_c, 255), first mount. Per
# symbol so the actor reaches its SpawnInfo, its model/anim SharedFilePtrs, the
# eighteen state SOURCE PMFs and the bss state array by name. Its vtable is a
# host array the registry fills. See port/ov071_syms.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov071)
# gate 177: ov064 is Lethal Lava Land's actor overlay, first mount -- BULLY,
# BIG_BULLY and ROTATING_FIREBAR ride it; the seat classes (LavaBubble, the
# BowserPuzzle pair) follow in their own gates. See port/ov064_syms.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov064)
# gate 143: ov019 is level 11's own overlay (Cool Cool Mountain's slide),
# already mounted whole in PORT_LEVEL_OVERLAYS; it joins the per-symbol mounts
# here so IceSlideManager (356) reaches its SpawnInfo record and the two
# construction-data statics its InitResources reads by name -- the gate-17 shape
# of ov009/ov010/ov015 applied to an eighth level overlay. Its one vtable
# (_ZTV10daSldMng_c) is a host array the registry fills. Only this class's
# own sinit (__sinit_ov019_02112b14) runs; RacingPenguin's (259, not spawned by
# level 11) is left off. See port/ov019_syms.txt and hal/actor_classes_ccm.cpp.
list(APPEND PORT_ACTOR_OVERLAYS ov019)
# gate 149: ov020 joins the per-symbol mounts so Big Boo's Haunt's furniture
# classes (HAUNTED_CHAIR 326, plus the deferred bookend/bookshot cast) reach
# their SpawnInfo and construction statics by name; its vtables are host arrays
# the registry fills. See ov020_syms.txt and hal/actor_classes_bbh.cpp.
list(APPEND PORT_ACTOR_OVERLAYS ov020)
# gate 188: ov016 is level 8's own overlay (Jolly Roger Bay), already mounted
# whole in PORT_LEVEL_OVERLAYS; it joins the per-symbol mounts here so its six
# MOVER classes (SHIP_DOWN 56, SHIP_UP 57, ROCK_PILLAR 58,
# FLOAT_ON_WATER_PLATFORM_JRB 60, UNAGI 242, SLIDING_BOX 313) reach their
# SpawnInfo records, file-pointer tables, CLPS blocks and -- for UNAGI -- the
# five PMF-dispatch cells, all by name. Its four vtables (_ZTV5Unagi, _ZTV6ShipUp,
# the RockPillar table _ZTV10RockPillar, and the FloatOnWater/SlidingBox
# _ZTV23FloatOnWaterPlatformJrb) are host arrays the registry fills. See
# port/ov016_syms.txt and hal/actor_classes_jrb.cpp.
list(APPEND PORT_ACTOR_OVERLAYS ov016)
# gate 190: ov018 is level 10's own overlay (Cool Cool Mountain, snow_mt),
# already mounted whole in PORT_LEVEL_OVERLAYS; it joins the per-symbol mounts
# here so ICE_SHEET (295) reaches its SpawnInfo and its bss SharedFilePtr
# window, and POWER_STAR_CREATE (355) reaches its SpawnInfo, both by name --
# the gate-59/gate-188 shape of ov015/ov016 applied to a fourth level overlay.
# Its two vtables (_ZTV15daObjIceBoard_c and PowerStarCreate's unnamed table
# _ZTV8daSCre_c) are host arrays the registry fills.
# GATE 191 extends this same mount: SKI_LIFT (63, own vtable
# _ZTV7SkiLift) and MOTHER_PENGUIN (257, own vtable _ZTV7SkiLift ==
# _ZTV10daPgMthr_c -- a dsd-era class-identity mislabel, see
# port/slice_gate191.txt). All four classes' sinits now run
# (__sinit_ov018_02112e00/02112c14/02112c80; PowerStarCreate has none of its
# own). See port/ov018_syms.txt and hal/actor_classes_ccm.cpp.
list(APPEND PORT_ACTOR_OVERLAYS ov018)
# gate 192: ov081 is a 100% matched ACTOR overlay, first mount -- ICE_BLOCK
# (18), MR_BLIZZARD (223) and SPINDRIFT (312) reach their SpawnInfo records,
# SharedFilePtr construction statics and (MrBlizzard) its ten-cell PMF
# dispatch table by name, the ov079/ov080 shape. Its three vtables
# (_ZTV9Spindrift, _ZTV10MrBlizzard, _ZTV8IceBlock == _ZTV15daObjIceBlock_c)
# are host arrays hal/actor_classes_ov081.cpp fills. SNOWBALL and MONEYBAG
# (also in this overlay) stay unregistered -- their own sinits do not run.
# See port/ov081_syms.txt and port/slice_gate192.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov081)
# gate 193: ov072, the ov079/ov080/ov081 shape applied a third time --
# BABY_PENGUIN (256) and the ACTUAL SNOWMAN (272, the unnamed daBgSnwmn_c
# block -- NOT SnowmanBody or SnowmanHead, a dsd class-identity gap; see
# port/ov072_syms.txt's own header) reach their SpawnInfo records,
# SharedFilePtr construction statics and (BabyPenguin) its six-cell PMF
# state-dispatch table by name. Their two vtables (_ZTV11BabyPenguin ==
# _ZTV9daPgBby_c, and daBgSnwmn_c's own unnamed _ZTV11daBgSnwmn_c) are
# host arrays hal/actor_classes_ov072.cpp fills.
#
# LANE w3-d EXTENDED THIS GATE TO THE WHOLE OVERLAY. SnowmanHead (273) and
# SnowmanBody (274) used to stay unregistered with their sinits off; both are
# hosted now, so ALL FOUR of ov072's vtables are host arrays and all four of
# its class sinits run. The two new classes are plain 31-slot Actors whose
# shared slots are byte-identical to the two above, so ov72_fill_shared serves
# all four. Their four pointer-to-member dispatchers are host copies
# (unmatched/Snowman_StateDispatch.cpp) for the pointer-to-member width reason
# port/slice_w18a.txt states -- BabyPenguin's own enter dispatcher, which this
# line used to name as the exemplar, is back on that slice now that /vmg /vmm
# is global and its host copy is deleted; Snowman's four are a different shape
# and have not been re-measured.
# Their state cells are seated with host addresses. One method face
# (unmatched/Ov072_MethodFaces.cpp) closes Player::StartTalk, which two of
# the new state handlers call as a C++ method and no linked TU spells that
# way -- the Coffin closure addendum's shape.
# See port/ov072_syms.txt and port/slice_gate193.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov072)
# gate 194: ov094, HOOT_THE_OWL's (234) own overlay. Fresh per-symbol mount.
# Its own SpawnInfo record, SharedFilePtr construction statics and its
# five-cell (ten-record) state-dispatch table reach it by name. Its vtable
# (_ZTV10HootTheOwl == _ZTV7daOwl_c) is a host array
# hal/actor_classes_ov094.cpp fills. The ov006/ov094 dual spawn-table
# citation is a dual-dump artifact (ov094 is address-nested inside ov006's
# much larger span), NOT co-residency -- no ov006 mount. See
# port/ov094_syms.txt and port/slice_gate194.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov094)
# gate 199: ov012 (level 4's own overlay, already whole-mounted per gate 114)
# joins the per-symbol mounts too -- SWITCH_PILLAR (34) and BASEMENT_WATER
# (35) reach their SpawnInfo records and tuning/CLPS/BTA/BMD data by name,
# the ov009/ov014/ov010 shape. Their two vtables (_ZTV16daObjC0_Switch_c for
# SwitchPillar, _ZTV12SwitchPillar == _ZTV14daObjC0Water_c for BasementWater
# -- a dsd class-identity swap, see port/ov012_syms.txt's own header) are
# host arrays hal/actor_classes_ov012.cpp fills. See port/ov012_syms.txt and
# port/slice_gate199.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov012)
# gate 202: ov013 (level 5's own overlay, already whole-mounted per gate 117)
# joins the per-symbol mounts too -- CLOCK_HAND_SHORT (292), CLOCK_HAND_LONG
# (293) and CLOCK_PENDULUM (294) reach their SpawnInfo records, their
# SharedFilePtrs and the hand-step table by name, the ov012/gate-199 shape.
# Their two vtables (_ZTV18daObjClockHuriko_c for the pendulum, unnamed and
# five-way split by dsd; _ZTV22ClockPaintingHandShort == _ZTV12daObjClock_c
# shared by BOTH hands) are host arrays hal/actor_classes_ov013.cpp fills.
# See port/ov013_syms.txt and port/slice_gate202.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov013)
# run linkw wave 4 (lane w4-b): ov045 (level 37's own overlay, already
# whole-mounted per gate 204) joins the per-symbol mounts too, so Bowser in the
# Fire Sea's six-class platform cast -- FALL_BLOCK_BFS (139), FIRE_SEA_ELEVATOR
# (140), TILTING_PLATFORM_BFS (141), POLE_LIFT (142), FLOATING_FLOOR_BFS (145)
# and EXTENDING_PLATFORM (148) -- reaches its SpawnInfo records, SharedFilePtrs,
# CLPS blocks and file tables by name. Same dual-mount shape as ov012/ov013.
# Its six vtables are host arrays hal/actor_classes_ov045.cpp fills. This mount
# runs port_ov045_pack_check/port_ov045_syms_patch and the five linkable ov045
# sinits from the registry fill rather than from hal/actor_overlays.cpp; see the
# LANE OWNERSHIP block in hal/actor_classes_ov045.cpp for why and for the
# actor_overlays.cpp block that should replace it. See port/ov045_syms.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov045)
# run linkw wave 5 (lane w5-e): ov060, the Bowser-fight actor pack -- the
# overlay all three koopaN_boss arenas load (alongside ov089, which the
# selector row loads BEFORE LoadOrUnloadObjectOverlays' idx-0x24/0x26/0x28
# early return: KEY 282 / LAST_STAR 283, the boss-reward spawns). First
# mount, per symbol; the full seven-class cast map, the one dsd label shift
# and the width pins are in port/ov060_syms.txt. Wave 5 registered ONE
# class (BOWSER_FIRE_SEA_ARENA 166, level 38's floor) and left the pack's 105
# TUs and six sinits in the link but /OPT:REF-stripped; wave 6 (lane w6-A)
# added the other five rows -- SpikeBomb 284, Bowser 279, BowserTail 278,
# BowserFire 280, BowserSkyPlatform 167 -- plus the seat of the six state
# tables they dispatch. port/slice_w5e.txt + port/slice_w6a.txt. See
# hal/actor_classes_ov060.cpp.
list(APPEND PORT_ACTOR_OVERLAYS ov060)
# w5-e: ov046 (level 38's own overlay, whole-mounted this same lane) joins
# the per-symbol mounts with ONE symbol -- the arena platform's private CLPS
# block, which BowserFireSeaArena::InitResources reaches by name under a
# shared-window spelling. See port/ov046_syms.txt's header.
list(APPEND PORT_ACTOR_OVERLAYS ov046)
# run linkw wave 7 (lane w7-c): ov044 (level 36's own overlay, whole-mounted
# this same lane) joins the per-symbol mounts too, because the arena's ONE
# non-ov060 class -- ORANGE_BALL_BILLBOARD / daObjKb1Billboard_c (301), the
# sixteen orange balls ringing the arena -- lives in the LEVEL overlay and
# reaches its SpawnInfo and its two bss cells by name. Same dual-mount shape as
# ov012/ov013/ov021/ov045/ov046. Its one vtable (0x02111604, 31 slots, pinned by
# both the reloc run and the .data/.bss boundary) is a host array
# hal/actor_classes_ov044.cpp fills; the mount bring-up and the single sinit run
# from the registry fill (the ov045/ov060 lane-ownership pattern -- no lane owns
# hal/actor_overlays.cpp this wave). See port/ov044_syms.txt and
# port/slice_w7c.txt. ov048 (level 40) gets NO per-symbol half: its whole cast
# is ov060's and nothing in ov048 is reached by name.
list(APPEND PORT_ACTOR_OVERLAYS ov044)
# run linkw wave 5 (lane w5-c): ov070, the Amp/FlameChomp/FlameChompFire pack
# (level 37's roaming enemies; FlyGuy rides the mount unregistered). Fresh
# per-symbol mount, ids re-read from the raw overlay image; the four vtables
# are host arrays hal/actor_classes_ov070.cpp fills, and the state PMF source
# records are seated with host bodies before the sinits copy them (the
# Scuttlebug treatment; see port/ov070_syms.txt). The bring-up runs from the
# first registry fill (ov70_bringup) -- the same actor_overlays.cpp handoff
# hal/actor_classes_ov045.cpp records.
list(APPEND PORT_ACTOR_OVERLAYS ov070)
# run linkw wave 5 (lane w5-B): ov065, first mount -- Hazy Maze Cave's enemy
# overlay (Snufit 236, Swoop 237, Dorrie 168, DorrieCap 169; the ten Ttc*
# classes ride the mount as data but stay unregistered, the parked subset).
# Its four HMC vtables are host arrays hal/actor_classes_ov065.cpp fills; the
# five Ttc vtables are excluded and hosted nowhere (the ov045 id-141
# precedent). Bring-up rides the registry fill (ov65_bringup), the w4-b
# pattern -- no lane owns hal/actor_overlays.cpp this wave. See
# port/ov065_syms.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov065)
# run linkw wave 18 (lane w18): ov035 is level 27's own overlay (Tick Tock
# Clock, data/stage/clock_tower), already whole-mounted in PORT_LEVEL_OVERLAYS
# since wave 17 landed the level-27 row. It joins the per-symbol mounts here so
# the ov065 Ttc cluster's TWELVE cross-overlay reads -- ten CLPS collision
# blocks and two animation descriptors -- resolve onto host storage instead of
# staying DS addresses. Without this, ovdata.py's cross pass has nothing to
# rebase into (a whole-image mount deliberately provides the cross pass
# nothing), and wave 17 MEASURED what that costs: ids 108 and 114 ticked 300
# frames without faulting on a garbage CLPS, silently, and id 112 divided by
# zero on an animation descriptor that read zero frames. The quiet pair is why
# that seat came back out. The gate-17 dual-mount shape of ov009/ov010/ov012/
# ov013/ov014/ov015/ov016/ov018/ov019/ov020/ov021/ov022/ov031/ov045 applied to a
# fifteenth overlay and a sixth level overlay; ov022 is the worked example.
# Nothing here is excluded -- ov035 contributes no vtables to this mount, all 21
# blocks are plain data. See port/ov035_syms.txt for the twelve seeds (wave 17's
# note names five of them), the closure, and the three width routes of which two
# lie.
list(APPEND PORT_ACTOR_OVERLAYS ov035)
# ...and ov021 (level 13's own overlay, already whole-mounted per gate 156)
# joins the per-symbol mounts too, so WORK_ELEVATOR (68), ROLLING_ROCK (221)
# and SHUTTER_HMC (67) reach their SpawnInfo records, CLPS blocks, tuning
# tables and sinit-built SharedFilePtrs by name -- the ov010/ov019/ov045
# dual-mount shape. Its three vtables are host arrays the same file fills.
# See port/ov021_syms.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov021)
# run linkw wave 5 (lane w5-A): ov063, Big Boo's Haunt's ACTOR overlay, first
# mount -- Boo/BigBoo/BigBooIcon/BooCage, the four daTrsTrap_c furniture ids,
# FallBlockBbh and MadPiano reach their SpawnInfo records, tuning tables and
# SharedFilePtr statics by name (the ov079/ov080/ov081 shape; ov063 is not a
# level overlay, so there is no whole-image half). Its six vtables are host
# arrays hal/actor_classes_ov063.cpp fills; the mount bring-up and the four
# sinits run from the registry fill (the ov045 lane-ownership pattern). See
# port/ov063_syms.txt and port/slice_w5a.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov063)
# run linkw wave 8 (lane w8-packs): ov022 is level 14's own overlay (Lethal
# Lava Land, data/stage/fire_land), already mounted whole in
# PORT_LEVEL_OVERLAYS since gate 163; it joins the per-symbol mounts here so
# its platform cast reaches its SpawnInfo records, its SharedFilePtr statics
# and the three-word file/CLPS tables its InitResources bodies index -- the
# gate-17 shape of ov009/ov010/ov015/ov016/ov018/ov019/ov020/ov021/ov045
# applied to a thirteenth overlay and a fifth level overlay. Its ten vtables
# are excluded from the mount; the four this wave seats are host arrays
# hal/actor_classes_ov022.cpp fills, and the mount bring-up plus four of the
# ten ov022 sinits run from the registry fill (the ov045 lane-ownership
# pattern). See port/ov022_syms.txt and port/slice_w8packs.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov022)
# run linkw wave 10 (lane w10-shared): ov031 (level 23, Tall Tall Mountain's
# slide, already whole-mounted per the w8-mounts sweep) joins the per-symbol
# mounts, so the SLIDE DECORATION QUAD reaches its four SpawnInfo records, its
# four-entry SharedFilePtr table and that table's bss by name. Same dual-mount
# shape as ov010/ov012/ov013/ov015/ov016/ov018/ov019/ov020/ov044/ov045/ov046.
# ONE vtable is excluded from the mount and hosted as an array
# hal/actor_classes_ov031_w10.cpp fills; that file also runs the mount bring-up
# and the overlay's single sinit from the registry fill (the ov045 lane-
# ownership pattern). See port/ov031_syms.txt and port/slice_w10a.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov031)
# run linkw wave 12 (lane w12): ov073, level 49's OBJECT overlay -- the first
# mount of this overlay, per symbol. Level 49 (ex_wario, "Wario's key arena")
# was mounted and booting with four actors placed and eighteen skipped: every
# actor the level places is ov073's, and hal/level_boot.cpp's row for 49 carried
# the note "[unmounted ov073]". CCC_ARENA (170), CCC_BIG_ICE (171) and
# CCC_SMALL_ICE (172) are ONE class under three ids sharing table 0x021231e8;
# CHIEF_CHILLY (218) is the boss on 0x02123090. Both vtables are excluded from
# the mount and hosted as arrays hal/actor_classes_ov073.cpp fills; that file
# also runs the mount bring-up, the forty state records' seat and BOTH sinits
# from the registry fill (the ov045 lane-ownership pattern), in that order,
# because the sinits COPY the records the seat rewrites. The ov052-shaped width
# trap this overlay carries -- ChiefChilly's reloc run reading one word past a
# 31-slot table into CccArena's own state table -- is derived in
# port/ov073_syms.txt. See also port/slice_w12.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov073)
# run linkw wave 12 (lane w12): ov052, LEVEL 44's own overlay ("Mario's key
# course", ex_m_map) -- already whole-mounted since level 44 landed, joining the
# per-symbol mounts too so its two platform classes reach their SpawnInfo
# records, their file tables and their sinit-built SharedFilePtrs by name. Same
# dual-mount shape as ov012/ov013/ov045. BOBBING_LOG_EMM (174) and
# SQUARE_PATH_LIFT (175) are sixteen of level 44's seventeen skipped instances.
# Both vtables are excluded from the mount and hosted as arrays
# hal/actor_classes_ov052.cpp fills; that file also runs the mount bring-up and
# both sinits from the registry fill (the ov045 lane-ownership pattern). The
# width trap this overlay carries -- id 174's reloc run reading SIX words past a
# 32-slot table, straight through id 175's own file table and typeinfo -- is
# derived in port/ov052_syms.txt. See also port/slice_w12b.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov052)
# run linkw wave 15 (lane w15): ov056, LEVEL 48's own overlay ("Wario's key
# course", ex_w_map, course 20) -- already whole-mounted since lane w8-mounts,
# joining the per-symbol mounts too so BIG_MOVING_ICE_BLOCK (173) reaches its
# SpawnInfo record, its file table and its sinit-built SharedFilePtrs by name.
# Same dual-mount shape as ov012/ov013/ov045/ov052. Nine of level 48's fourteen
# skipped instances are this class; the other five are MR_BLIZZARD, refused on
# purpose. Its vtable is excluded from the mount and hosted as an array
# hal/actor_classes_ov056.cpp fills; that file also runs the mount bring-up,
# hal_fill_platform_vtable and the overlay's single sinit from the registry
# fill (the ov045 lane-ownership pattern). The width trap this overlay carries
# -- a dsd split at slot 16 making the next-symbol landing read a 32-slot table
# as SIXTEEN -- is derived in port/ov056_syms.txt. See also port/slice_w15.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov056)
# run linkw wave 15 (lane w15): ov025, LEVEL 17's own overlay -- already
# whole-mounted since lane w8-mounts, joining the per-symbol mounts too so
# PYRAMID_STEP (87) and PYRAMID_LIFT (88) reach their SpawnInfo records, their
# CLPS blocks and their sinit-built SharedFilePtrs by name. Five of level 17's
# eleven skipped instances. Both vtables are excluded from the mount and hosted
# as arrays hal/actor_classes_ov025.cpp fills; that file also runs the mount
# bring-up, hal_fill_platform_vtable and the TWO of the overlay's four sinits
# these classes own (the other two belong to classes with no reach and stay
# unrun, the ov019 rule). TWO width traps are derived in port/ov025_syms.txt:
# dsd split BOTH 32-slot tables at slot 8, and it also split a SharedFilePtr in
# half so an unpinned mount would have sized it FOUR bytes. See also
# port/slice_w15c.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov025)
# run link60 lane A2, gate 206: ov043 (level 35's own overlay, Bowser in the
# Dark World, already whole-mounted in PORT_LEVEL_OVERLAYS) joins the
# per-symbol mounts so DIAMOND_LIFT (135, daObjKm1_Ukishima_c, six instances)
# reaches its SpawnInfo, its two bss SharedFilePtrs and its CLPS block by name.
# Same dual-mount shape as ov012/ov013/ov021/ov044/ov045/ov046. 105 symbols;
# all four vtable spans are excluded and id 135's is the host array
# hal/actor_classes_ov043.cpp fills. Ids 134 and 137 stay skipped on purpose --
# 137's factory hides its real table behind a placeholder AND spells an
# invented class name that means another overlay's base table, and both need
# ov002 base bodies this slice does not pull in. The cast map, the four widths
# and the naming shift are derived in port/ov043_syms.txt; this gate's reading
# and the four re-verified traps are in port/slice_gate206.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov043)

# run link60 lane s2-m7: ov007, the TITLE SCREEN and FILE SELECT scene
# (dScDSMT_c). Not an actor overlay and not reachable today -- it is the fourth
# occupant of the scene slot at 0x020ad660, walk_window runs the ov002 occupant,
# and nothing in a level walk spawns actor id 1. It joins the per-symbol mounts
# for the same reason ov001 and ov003 did: the treatment is right for it and the
# storage has to exist before anything can be wired to read it.
#
# THIS ADDS NO LINKAGE and is not meant to. Mounted bytes are not matched TUs,
# none of ov007's 527 source TUs is compiled in, and nothing calls
# port_ov007_syms_patch(). What lands is 716 symbols, the overlay's whole
# .rodata + .data + .bss contiguous from 0x020ccb54 to 0x02104c40, including the
# TITLE_SCREEN spawninfo record at 0x02103264 that the S1 spine lane's registry
# row will read. ov007 has no sinits to run: its static-init table is one NULL
# word. See port/ov007_syms.txt for the list and the eight ROM width pins.
#
# It is the first mount of a scene-slot occupant, so it is the first real test
# of the residency model merged at 11242964f -- an address-only contest test
# would have taken three of the build's resolved cross pointers back to raw DS
# addresses. It takes none: 228 rebased rows before, the identical 228 after,
# contested unmoved at 105. The measurement is port/ov007_binding_diff.txt,
# including the three findings it turned up and which of them are fixed.
#
# It also grows .dsstate by 229612 bytes, which MOVES THE SELFTEST BMP BASE.
# That is the landed span: 229604 is the sum of the 716 symbol sizes and the
# other 8 are the pack gap at 0x020d7db8. The three water pixels track the
# section base, so the BMP is comparable only at an equal base and must not be
# byte-compared across this commit.
list(APPEND PORT_ACTOR_OVERLAYS ov007)
# run link60 lane s2-m46: ov004 AND ov006, the MINIGAME SCENE PAIR, mounted
# together because the loader loads them together. func_0201a798 loads ov004
# first and then ov006, func_0201a754 unloads both, so ov004 is live exactly
# when ov006 is -- the PASSENGER RULE, and the only pair anywhere in the game
# for which the residency model answers coresident() = True between two scene
# slot occupants. ov006 is the twenty-three Rec Room minigames (1839 matched
# TUs, the largest family left); ov004 is dScMgBase_c, the framework class they
# derive from, and it is never loaded on its own.
#
# THIS ADDS NO LINKAGE and is not meant to. Mounted bytes are not matched TUs,
# none of the 1839 + 276 matched source TUs is compiled in, and nothing calls
# either patch function. No level can reach a minigame either: func_0201a694
# unloads the scene overlay the level is running out of before it loads ov006,
# which is a proof from the load code, so reach needs the scene-switch spine and
# that is not wired here. What lands is storage.
#
# 3524 symbols. ov004 is 597, contiguous 0x020b944c..0x020bfec0; ov006 is 2927,
# contiguous 0x0212b890..0x021430a0. Each carries ONE pack gap, over its own
# .init and .ctor, and unlike ov007's eight zero bytes those gaps cover ROM code
# that is not zero -- the same class as 220 of the 245 pack gaps already here,
# and the largest members of it. Twenty sizes are pinned to their ROM widths.
# The 35 .ctor words are left out (dsd's `.p` names are not C identifiers) and
# the 35 sinits behind them are inventoried in the two list headers, not run.
#
# THE PAIR IS THE PERMISSIVE DIRECTION'S FIRST EXERCISE and it comes out the
# way the model says. 229 rebased rows before, 284 after: nothing lost, nothing
# changed, and 55 rows APPEARED, every one of them a pointer between the two
# overlays that only resolves because they are co-resident. Contested does not
# move at all, 105 either side, because the two footprints abut at 0x020bfec0
# and never overlap. Under the address-only test the residency model replaced,
# these two windows would have taken 195 of the 229 back to raw DS addresses.
# The measurement, with every appeared row adjudicated, is
# port/ov004_ov006_binding_diff.txt.
#
# FOUR HAND-HOSTED STAND-INS RETIRE WITH IT, and they have to go in this same
# commit or the link has two definitions of each: data_ov004_020beb60 out of
# hal/oam2d_ov004_bss.cpp (the file existed for that one word and is deleted),
# data_ov004_020beb68 out of hal/actor_classes_ov081.cpp, and
# data_ov006_02140330 / data_ov006_02140338 out of hal/cxx_aliases.cpp. All four
# are .bss, all four are the ROM span the mount gives them (4, 4, 8 and 8
# bytes), and all four are zero on both sides, so the swap is byte-identical and
# St_LevelEnter_Main's Release still reads numRefs 0. The ov006 scout predicted
# "ZERO duplicates, no host stand-ins to retire" for this territory; there were
# four, and the correction is recorded in port/ov004_ov006_binding_diff.txt.
#
# It grows .dsstate by 123492 bytes, MEASURED, which MOVES THE SELFTEST BMP
# BASE: dsstate_guard reports 810684 bytes captured before and 934176 after, and
# the base moves 0xae2000 to 0xafa000. It reconciles as the landed span of the
# two mounts less what the retired stand-ins give back less what section
# alignment reclaims: 27252 + 96272 - 24 - 8 = 123492. The symbol sums, 24832
# and 79572, are not the number that moves the section. The three water pixels track the section
# base, so the BMP is comparable only at an equal base and must not be
# byte-compared across this commit.
list(APPEND PORT_ACTOR_OVERLAYS ov004 ov006)
# run mg15 lane MENU: ov005, the MINIGAME SELECTION MENU's data. The scene the
# pair above is reached FROM -- dScMiniGm_c, actor id 5 -- and the SECOND
# occupant of the 0x020bfec0 scene slot to be mounted, ov006 being the first.
#
# THE TWO CAN NEVER BE LOADED TOGETHER ON THE DS and the residency model
# already knows it without anything being asserted here: both footprints start
# at 0x020bfec0, so rule 1 (overlap, pure arithmetic) makes them exclusive, and
# rule 2 independently puts both in the scene-occupant set because
# src/GetSceneOverlayID.c returns overlay_5 and overlay_6 from its own arms.
# That is what stops the cross pass resolving an ov005 target into ov006's
# window: the two contest, and a contested target stays raw rather than being
# guessed at. Nothing in the mount below crosses into ov006 anyway.
#
# 51 symbols, the overlay's whole .rodata + .data contiguous from 0x020c2250 to
# 0x020c3020. .bss is start:0x020c3020 end:0x020c3020 -- empty -- so there is
# nothing to mount there, and .ctor is zero length, so there are no sinits to
# run (the ov003 and ov007 shape, not the ov004/ov006 one). No size is pinned:
# every delta between consecutive symbols is >= 4, so ovdata's default IS the
# ROM width in all 51 cases.
#
# UNLIKE ov003/ov004/ov006/ov007 THIS MOUNT IS WIRED THE SAME COMMIT IT LANDS.
# hal/scene_mg_menu.cpp fills data_ov005_020c2490 (the class vtable, 18 words)
# and hal/scene_boot.cpp's registry row reads g_profile_MINIGAME (the
# SpawnInfo), so the storage and its readers arrive together rather than the
# mount sitting ahead of a wiring lane.
#
# THE MOUNT'S OWN CROSS-CHECK, which is why this is not a claim on trust: the
# 36-row launch table at data_ov005_020c24d8 (36 x 0x34 = 1872 bytes) that this
# mount emits is BYTE-IDENTICAL to the verbatim transcription
# hal/scene_mg_sound.cpp has carried since run mg8. Two independent readings of
# the same ROM bytes at the same address agree exactly, which is a stronger
# statement about the mount's addressing than any run-time probe.
#
# IT GROWS .dsstate BY 3544 BYTES, MEASURED, and the symbol count by exactly
# 54 with NOTHING LOST: dsstate_guard reports 959440 bytes captured before and
# 962984 after, and the base moves 0xc8e000 to 0xc92000. The 54 reconcile
# completely -- the mount's 51 symbols, the one pack gap pk005_gap_020c2430
# (the 16 bytes between .rodata's end at 0x020c2430 and .data's start at
# 0x020c2440, which are in the ROM image too), and the two arm9 .bss words
# hal/auto_bss.cpp gained for this scene. A map diff of the two captured spans
# lists those 54 as NEW and zero as GONE.
#
# The three water pixels track the section base, so the selftest BMP is
# comparable only at an equal base and must not be byte-compared across this
# commit.
list(APPEND PORT_ACTOR_OVERLAYS ov005)
# ov075 joins for the VS wiring lane (dScEntry_c, scene 6); the slice block
# and the derivation pointer live beside SLICE_VS_SOURCES further down.
list(APPEND PORT_ACTOR_OVERLAYS ov075)
# run rel0215 wave 1 (lane cast-ov026): ov026 (level 18's own overlay, Dire
# Dire Docks, already whole-mounted in PORT_LEVEL_OVERLAYS) joins the
# per-symbol mounts too, so the level's WHOLE five-class cast --
# daObjWlPolelift_c (89), Submarine (90), BowserShutter (91), Whirlpool (246)
# and WaterSuction (247) -- reaches its SpawnInfo records, SharedFilePtr
# construction statics, CLPS/BTA/BMD blocks and its two pointer-to-member state
# tables by name. The gate-17 dual-mount shape of ov009/ov012/ov013/ov021/
# ov035/ov045 applied to a further level overlay; --whole emits
# port_ov026_image/_patch/_at and nothing by name, --from-list --pack emits the
# named arrays plus port_ov026_syms_patch.
# All five vtables are excluded from the mount and are host arrays
# hal/actor_classes_ov026.cpp fills: _ZTV17daObjWlPolelift_c (31),
# _ZTV21daObjWlKoopaShutter_c (32), _ZTV18daObjWlSubmarine_c (32),
# _ZTV18daWater_Tatumaki_c (31) and _ZTV12WaterSuction (31). Two of those five
# widths are OVER-READ by the typeinfo-terminator route because a
# pointer-to-member source table is packed behind the vtable; those pairs
# belong to the NEXT class in each case, and both the widths and that
# correction are ROM-byte verified in port/ov026_syms.txt.
# DSD CLASS-IDENTITY SWAP: every `_ZN9Submarine*` TU in this overlay is the
# WHIRLPOOL's, not the Submarine's -- config/arm9/overlays/ov026/symbols.txt:201
# puts _ZTV9Submarine on 0x02113d54, whose own typeinfo name string reads
# 18daWater_Tatumaki_c. See port/ov026_syms.txt and port/slice_ov026cast.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov026)
# run rel0215 wave 1 (lane cast-sweep1): ov058 (level 50's own overlay, the Rec
# Room, already whole-mounted in PORT_LEVEL_OVERLAYS) joins the per-symbol
# mounts for ONE SYMBOL -- REC_ROOM_CUPBOARD's (182) SpawnInfo record. It is
# the smallest per-symbol mount in the port and it is one line because ov058
# has no .rodata, no .init, no .ctor and no .bss: zero static initialisers, and
# the class loads no file of its own. It is also the WHOLE of level 50's skip
# list, so this seat takes that level to zero skipped. Its vtable is excluded
# from the mount and hosted as an array hal/actor_classes_ov058.cpp fills, and
# it is a 31-slot ACTOR table, not a 32-slot Platform one -- the ov024
# PYRAMID_TAG shape; dsd's landing on it reads TWO. That file also runs the
# mount bring-up from the registry fill (the ov025/ov045 lane-ownership
# pattern), with no sinit and no hal_fill_platform_vtable to run.
# See port/ov058_syms.txt and port/slice_sweep1_ov058.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov058)
# run rel0215 wave 1 (lane cast-sweep1): ov017 (level 9's own overlay, Jolly
# Roger Bay's sunken ship, already whole-mounted in PORT_LEVEL_OVERLAYS) joins
# the per-symbol mounts so SHIP_WATER (62) reaches its SpawnInfo record, its
# BTA file descriptor, its CLPS block and both sinit-built SharedFilePtrs by
# name. This is the mount hal/level_boot.cpp's own level-9 block asked for by
# name and deferred: "hosting it needs a per-symbol ov017 mount
# (g_profile_KS_MIZU, _ZTV9ShipWater, data_ov017_02111c88) PLUS an
# alias-by-address that resolves the ov055/ov056 spellings onto ov017's host
# bytes". Its vtable is excluded from the mount and hosted as an array
# hal/actor_classes_ov017.cpp fills; that file also runs the mount bring-up,
# hal_fill_platform_vtable and the overlay's single sinit from the registry
# fill (the ov025/ov045 lane-ownership pattern). The block named two raced
# spellings; there are three, and the third is LIVE on this tip. See
# port/ov017_syms.txt and port/slice_sweep1_ov017.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov017)
# run rel0215 wave 1 (lane cast-sweep1): ov023 (level 15's own overlay, Lethal
# Lava Land's volcano interior, already whole-mounted in PORT_LEVEL_OVERLAYS)
# joins the per-symbol mounts so SQUASHER (84) reaches its SpawnInfo record and
# both sinit-built SharedFilePtrs by name. It is the WHOLE of level 15's skip
# list -- one instance, one class -- so this seat takes that level to zero
# skipped. Its vtable is excluded from the mount and hosted as an array
# hal/actor_classes_ov023.cpp fills; dsd's landing on it OVER-reads by seven
# slots (39 against a real 32), the opposite error to ov024's and ov033's.
# That file also runs the mount bring-up, hal_fill_platform_vtable and the
# overlay's single sinit from the registry fill (the ov025/ov045 pattern).
# The three alias races its InitResources and destructors carry, all pinned to
# ROM relocations, are in port/ov023_syms.txt. See port/slice_sweep1_ov023.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov023)
# run rel0215 wave 1 (lane cast-sweep1): ov033 (level 25's own overlay, Tiny-
# Huge Island's small side, already whole-mounted in PORT_LEVEL_OVERLAYS) joins
# the per-symbol mounts so TINY_COVER (104) and TINY_WATER (105) reach their
# SpawnInfo records, their two CLPS blocks, id 105's BTA file descriptor and
# all four sinit-built SharedFilePtrs by name. Two of level 25's three skipped
# instances. Both vtables are excluded from the mount and hosted as arrays
# hal/actor_classes_ov033.cpp fills -- and dsd's ONE vtable name here is on the
# WRONG table (_ZTV9TinyWater is the WATER class's; the cover's is unnamed),
# proven three ways in port/ov033_syms.txt. That file also runs the mount
# bring-up, hal_fill_platform_vtable and both sinits from the registry fill
# (the ov025/ov045 lane-ownership pattern). See port/slice_sweep1_ov033.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov033)
# run rel0215 wave 1 (lane cast-sweep1): ov024 (level 16's own overlay,
# Shifting Sand Land, already whole-mounted in PORT_LEVEL_OVERLAYS) joins the
# per-symbol mounts so PYRAMID_TOP (85) and PYRAMID_TAG (86) reach their
# SpawnInfo records, id 85's CLPS block and both sinit-built SharedFilePtrs by
# name. Same dual-mount shape as ov012/ov013/ov025/ov035/ov045/ov052/ov056.
# Five of level 16's nineteen skipped instances. Both vtables are excluded from
# the mount and hosted as arrays hal/actor_classes_ov024.cpp fills -- and they
# are DIFFERENT LENGTHS, 31 for the Actor-derived tag and 32 for the
# Platform-derived top, which is the width finding this overlay carries. That
# file also runs the mount bring-up, hal_fill_platform_vtable and the overlay's
# single sinit from the registry fill (the ov025/ov045 lane-ownership pattern).
# See port/ov024_syms.txt and port/slice_sweep1_ov024.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov024)
# ov084 joins for gate 32: the first ENEMY overlay, GOOMBA and BOB_OMB_BUDDY.
# ...and ov014, ov062 and ov091 with them. ov014 is a LEVEL overlay (Bob-omb
# Battlefield's own) and is mounted a second time here, per symbol, because
# CHAIN_CHOMP and CHAIN_CHOMP_FENCE reach their tables by name -- the gate-17
# treatment of ov009 applied to the second level. ov062 is KOOPA_THE_QUICK's.
# ov091 is the one the chomp drags in: its InitResources spawns actor 27, the
# post it is chained to, and a null back from that spawn is a fault. ov078 is
# KING_BOB_OMB's, and level 6 is the only level of the fifty-two that loads it.
# run rel0215 wave 1 (lane cast-ov077): ov077, THE SHARED ENEMY PACK -- HEAVE_HO
# (238, daPopoi_c), SPINY (260, daTgz_c) and LAKITU (265, daJgm_c). Fresh
# per-symbol mount, the ov079/ov080/ov081/ov072/ov094 shape; ov077 is not a
# level overlay so there is no whole-image half. All three classes reach their
# SpawnInfo records, their SharedFilePtr construction statics and their
# pointer-to-member state tables by name. Their three vtables (_ZTV6Lakitu ==
# _ZTV7daJgm_c, _ZTV5Spiny == _ZTV7daTgz_c, _ZTV7HeaveHo == _ZTV9daPopoi_c --
# three RTTI-spelling pairs, each confirmed by reading that table's OWN
# vtable[-1] typeinfo record through to its name string) are host arrays
# hal/actor_classes_ov077.cpp fills, and all three of the overlay's sinits run.
#
# THE FOURTH OCCUPANT of the 0x02123740 window, joining ov079, ov080 and ov081.
# It adds NO new ground -- ov077 ends 0x02127d40, inside ov081's 0x02129000 --
# but three of its symbols are contested by a mounted sibling and dsd marks all
# three `ambiguous`. Each is settled from the raw overlay bytes in
# port/ov077_syms.txt, including one that ov080's mount ALREADY HOSTS today
# (0x02127848: ov077's bytes there are Lakitu's SpawnInfo, ov080's are a
# repeating tuning tuple) and two that are ov079's Whomp SpawnInfos, whose
# addresses split one 0x60-byte ov077 bss array into three -- pinned, and the
# two phantom splits left out of the list. See port/ov077_syms.txt and
# port/slice_ov077.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov077)
# run rel0215 wave 1 (lane cast-ov030): ov030, TALL TALL MOUNTAIN's own cast.
# ROLLING_LOG_TTM (102), UKIKI_CAGE (103), UKIKI_THIEF (267) and UKIKI_STAR
# (268) reach their SpawnInfo records, their fifteen SharedFilePtr construction
# statics, their four Fix12 tuning records and the Ukiki's ELEVEN-cell PMF
# state-dispatch storage by name -- the ov072/ov079/ov080/ov081 shape. ov030 is
# already whole-mounted in PORT_LEVEL_OVERLAYS (line 1346); this is the SECOND,
# per-symbol mount, the ov009/ov012/ov013/ov014 dual-mount shape.
# FOUR IDS, THREE CLASSES: 267 and 268 are one class (7daMky_c) under two spawn
# entry points -- both factories store the same table 0x02115bfc. Its three
# vtables (_ZTV13daObjHmBskt_c, _ZTV15daObjHmMaruta_c and _ZTV13RollingLogTtm ==
# _ZTV7daMky_c) are host arrays hal/actor_classes_ov030.cpp fills. NO class in
# this overlay stays unregistered, so all three of its sinits run.
# THE CONFIG'S _ZTV LABELS AND MANGLED METHOD NAMES ARE SHIFTED ONE CLASS here
# -- the ov012/ov072 dsd class-identity shape, third instance -- and everything
# is seated BY ADDRESS. See port/ov030_syms.txt's own header for the ROM
# evidence and port/slice_ov030cast.txt for the four displaced TUs.
list(APPEND PORT_ACTOR_OVERLAYS ov030)
# run rel0215 wave 1 (lane cast-ov036): ov036 (level 28's own overlay, already
# whole-mounted in PORT_LEVEL_OVERLAYS) joins the per-symbol mounts too, so
# Rainbow Cruise's whole seven-class platform cast -- SWINGING_PLATFORM (127),
# ROTATING_PLATFORM_RR (129), SHIP_WING (125), DONUT_BLOCK (126),
# ARMED_ROTATING_PLATFORM (132), TRICKY_TRIANGLES (123) and FLYING_CARPET (130)
# -- reaches its SpawnInfo records, SharedFilePtrs, CLPS blocks and per-class
# file records by name. Same dual-mount shape as ov012/ov013/ov045.
# THE CONFIG'S C++ METHOD AND _ZTV NAMES ARE ATTACHED ONE CLASS EARLY in this
# overlay (the ov045 off-by-one, measured here rather than inherited), so the
# seven host vtable arrays hal/actor_classes_ov036.cpp fills are paired to ids
# BY ADDRESS: _ZTV18RotatingPlatformRr is SHIP_WING's table, _ZTV8ShipWing is
# DONUT_BLOCK's, _ZTV18daObjRc_Guruguru_c is ARMED_ROTATING_PLATFORM's and
# _ZTV16daObjRc_Dorifu_c is TRICKY_TRIANGLES'. The derivation, both
# attribution routes, all seven widths and the four size pins are in
# port/ov036_syms.txt. See also port/slice_ov036cast.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov036)
# run rel0215 wave 2 (lane cast-ov090): ov090, THE WATER ENEMY PACK -- SKEETER
# (230, 9daMenbo_c), MANTA_RAY (226, 9daManta_c), CHEEP_CHEEP (227,
# 12daPukupuku_c) and SHARK (225, 9daShark_c). Fresh per-symbol mount, the
# ov077/ov079/ov080/ov081/ov072/ov094 shape; ov090 is not a level overlay so
# there is no whole-image half. All four classes reach their SpawnInfo records,
# their ten SharedFilePtr construction statics and their sixteen
# pointer-to-member state records by name. Their four vtables (_ZTV7Skeeter ==
# _ZTV9daMenbo_c, _ZTV10CheepCheep == _ZTV12daPukupuku_c, _ZTV5Shark ==
# _ZTV9daShark_c -- three RTTI-spelling pairs, each confirmed by reading that
# table's OWN vtable[-1] typeinfo record through to its name string; MantaRay
# has only one spelling) are host arrays hal/actor_classes_ov090.cpp fills, and
# all four of the overlay's sinits run.
#
# THE WINDOW (T6): base 0x02130f00 with ov091 mounted and ov092 not. ov090 ends
# 0x021345e0, STRICTLY INSIDE ov091's 0x021356e0, so it adds no new ground and
# cannot take a resolved target away from another mount. ov006's much larger
# span (0x020bfec0..0x021430a0) also contains all of it, which is why dsd marks
# all four SpawnInfos `ambiguous` and the arm9 spawn-table relocations read
# `module:overlays(6,90)`. That is a dual-dump artifact, not a contest: ov006's
# own raw bytes at all four addresses are minigame tuning tuples with no
# plausible function pointer, while ov090's are real SpawnInfos whose word[0]
# is an e92d4010 prologue in ov090's own .text and whose word[1] low halfword
# is the id that reached them. IDS 225/226/227/230 ARE ALL ov090's -- the
# derivation, both routes and ov006's own bytes are in port/ov090_syms.txt.
#
# NO SIZE PIN IS NEEDED in this overlay, which is measured rather than assumed:
# every mounted symbol's next-symbol delta was checked against what the four
# sinits and the bodies actually write through it. See port/ov090_syms.txt and
# port/slice_ov090.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov090)
# run rel0215 wave 2 (lane cast-ov066): ov066, the EYEROK pack -- EYEROK (176,
# 10daIwante_c), the SSL pyramid boss, wanted by level 17 alone. Fresh
# per-symbol mount, the ov077/ov079/ov080/ov081 shape; ov066 is not a level
# overlay, so this is its only mount. Its 112 data and bss symbols -- one
# SpawnInfo, one typeinfo record, THIRTY-EIGHT pointer-to-member source pairs,
# twenty-two SharedFilePtrs, twenty-two destructor list nodes and NINETEEN
# 16-byte state records -- reach the class by name. Its ONE vtable
# (_ZTV6Eyerok == _ZTV12daIwante_c, 32 slots because Eyerok is Platform-derived,
# confirmed three ways) is a host array hal/actor_classes_ov066.cpp fills, and
# its one sinit runs.
# ONE CLASS, NOT THREE: the two hands and the head are STATES, which is why
# .data carries a 38-entry PMF table instead of three class blocks. See
# port/ov066_syms.txt for the derivation and port/slice_ov066.txt for the four
# host-copied TUs and the SIX /alternatename directives this mount defeats.
list(APPEND PORT_ACTOR_OVERLAYS ov066)
# run rel0215 wave 2 (lane cast-ov027): ov027 (level 19's own overlay, already
# whole-mounted in PORT_LEVEL_OVERLAYS) joins the per-symbol mounts too, so
# Snowman's Land's whole cast -- SLIDING_ICE_SPAWNER (92), SLIDING_ICE (93),
# CHILL_BULLY (217), DA_PG_DFDR (258) and SNOWMAN_BREATH (275) -- reaches its
# SpawnInfo records, SharedFilePtrs, CLPS blocks and per-class file records by
# name. Same dual-mount shape as ov012/ov013/ov036/ov045.
# FIVE IDS, NOT THE FOUR THE TASK SHEET NAMED: route 2 found id 258, whose
# SpawnInfo and factory config leaves unnamed (g_profile_PENGUIN_DEFENDER /
# daPgDfdr_c_classInit) and which owns sixteen of the overlay's 53 functions.
# dsd's names ARE correct by address on this overlay -- no ov036/ov045
# off-by-one -- but ids 92 and 93 SHARE ONE VTABLE and one fill. The
# derivation, both attribution routes, all four widths (including the 37-slot
# ChillBully table whose tail is a pointer-to-member source table, not more
# vtable) and the four size pins are in port/ov027_syms.txt. See also
# port/slice_ov027cast.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov027)
# run rel0215 wave 2 (lane cast-lvl16pair, sub-job 1 of 2): ov092, THE TOX_BOX
# PACK -- TOX_BOX (309, 8daOnms_c), level 16's crushing block, x3 placed there
# and on no other level of the fifty-two. Fresh per-symbol mount, the
# ov017/ov077/ov079/ov080/ov081/ov072/ov094 shape; ov092 is not a level overlay
# so there is no whole-image half. The class reaches its SpawnInfo record, its
# two SharedFilePtr construction statics, its CLPS block, its three path blocks
# and its nine-entry pointer-to-member state table by name. Its one vtable
# (_ZTV6ToxBox, 32 slots, a PLATFORM close rather than the plain Actor close --
# slot 31 is 0x020ee55c _ZN10dBgActor_c4KillEv) is a host array
# hal/actor_classes_ov092.cpp fills, and the overlay's single sinit runs.
#
# THE FOOTPRINT ARGUMENT, and it is short. ov092's span is
# 0x02130f00..0x021325c0 and ov091's, already mounted, is
# 0x02130f00..0x021356e0 -- both re-derived from each overlay's own
# delinks.txt, not quoted. ov092 is STRICTLY INSIDE its mounted sibling, so it
# adds no new ground and cannot take a resolved --cross target from anyone
# (the ov044/ov045/wave-C argument). dsd marks ZERO ov092 symbols `ambiguous`
# and the arm9 spawn-table relocation for id 309 reads `module:overlay(92)`,
# singular -- this overlay has no contested id and needed no adjudication.
# ov006 also covers this window (0x020bfec0..0x021430a0) and is mounted, but
# the two mounts emit different C names at different host storage and the
# registry reaches its record by C name, never by DS address; the one ov006
# reloc that lands inside a symbol this mount hosts points at ov006 CODE. See
# port/ov092_syms.txt and port/slice_ov092.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov092)
# run rel0215 wave 2 (lane cast-lvl16pair, sub-job 2 of 2): ov096, THE POKEY
# PACK -- POKEY (240, daSanbo_c), POKEY_SEGMENT (241, THE SAME CLASS under a
# second spawn entry point) and TORNADO (308, daTor_c). Level 16 places POKEY
# x4 and TORNADO x3; POKEY_SEGMENT is placed on no level and is spawned by
# POKEY. Fresh per-symbol mount, the ov017/ov077/ov079/ov080/ov081/ov072/ov094
# shape; ov096 is not a level overlay so there is no whole-image half. The
# classes reach their three SpawnInfo records, their four SharedFilePtr
# construction statics and POKEY's twelve-record pointer-to-member state table
# by name. The two vtables (_ZTV5Pokey == _ZTV9daSanbo_c, _ZTV7Tornado ==
# _ZTV7daTor_c -- two RTTI-spelling pairs, each confirmed by reading that
# table's OWN vtable[-1] typeinfo record through to its name string) are host
# arrays hal/actor_classes_ov096.cpp fills, and both of the overlay's sinits
# run in the ROM's own .ctor order.
#
# THIS IS THE CAMPAIGN'S ONE WINDOW-EXTENDING MOUNT, and the plan's T6 table is
# right about the arithmetic and incomplete about the consequence. Extents
# re-derived from each overlay's own delinks.txt rather than quoted:
#   ov094  0x02135700..0x02136b80  MOUNTED
#   ov095  0x02135700..0x02137940  MOUNTED, the widest before this
#   ov096  0x02135700..0x02137be0  = +0x2a0 PAST ov095
# and 0x02137be0 is exactly ov098's base, so the extension is ADJACENT, not
# overlapping. But ov006 ALSO covers this window -- its span is
# 0x020bfec0..0x021430a0, it is mounted, and port/ov006_syms.txt already hosts
# 338 symbols inside ov096's range -- so every byte ov096 "adds" is already
# inside a mounted window and the extension cannot flip a --cross target from
# resolved to raw for anyone. The census was re-run both ways regardless,
# because that is what the plan asked of this lane; the numbers are in the
# lane's report and the CONTESTED count does not move.
#
# THREE CONTESTED IDS, ALL THREE LIVE, ALL THREE ADJUDICATED. dsd marks all
# three of this overlay's SpawnInfo rows `ambiguous`, every arm9 spawn-table
# relocation reads `module:overlays(6,96)`, and ov006's mount already hosts all
# three addresses today. Each was settled from the RAW BYTES of both claimants:
# ov096 has a real e92d4010 prologue in word[0] and the reaching table index in
# word[1]'s low halfword at every one, ov006 has NITRO GX command data with no
# plausible function pointer at any. No bridge is needed -- the two mounts emit
# different C names at different host storage and the registry reaches its
# record by C name, never by DS address. See port/ov096_syms.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov096)
# run rel0215 wave 2 (lane w2-ov074): ov074, THE GOOMBOSS PACK -- GOOMBOSS
# (198) and EXPLOSION_GOOMBA (199), both 12daKuriKing_c. Fresh per-symbol
# mount, the ov077/ov079/ov080/ov081/ov072/ov094 shape; ov074 is not a level
# overlay so there is no whole-image half. Level 45 (Mario's key arena,
# ex_mario, ov053) is the only level of the fifty-two that names it, and its
# skip list is exactly one row.
# TWO IDS, ONE CLASS: src/d_a_kuri_king_kuriking.cpp and src/d_a_kuri_king_kuriking_vanish.cpp
# are the same 0xd4 body twice and both store the SAME table, so the overlay
# has ONE vtable (_ZTV8Goomboss, 31 slots, host array
# hal/actor_classes_ov074.cpp fills) and ONE typeinfo record, whose own
# vtable[-1] reads through to "12daKuriKing_c" -- no label shift here.
#
# THE FOURTH OCCUPANT of the 0x0211f000 window, joining ov070, ov071 and
# ov073. It adds NO new ground -- ov074 ends 0x021231a0, inside ov073's
# 0x021234e0 -- but eight of its symbols are marked `ambiguous` by dsd and
# fifteen arm9 spawn-table slots relocate into its span. Both attribution
# routes were run on every one: exactly TWO are ov074's (198, 199) and the
# other thirteen belong to a mounted sibling, including one (id 264 ->
# 0x02122dc4) whose word[0] IS a real ov074 function and which only route 2
# rejects. FIVE of the eight ambiguous rows are PHANTOM SPLITS inside ov074
# objects -- one splits a 0x30 pointer run, one a 0xc destructor list node,
# and THREE split the 0x90 nine-cell state table dsd sizes 0x4c. All three
# heads are pinned and all five phantoms left out of the list. See
# port/ov074_syms.txt and port/slice_ov074.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov074)
# ============================================================================
# RUN REL0215 WAVE 2, LANE CAST-SWEEP2 -- four level overlays, one per commit.
# This region grows by one list(APPEND) per overlay; the source-list region far
# below grows by one block per overlay and feeds ONE ${SWEEP2_SOURCES} into the
# three target lists, so a second overlay costs the coordinator nothing outside
# those two regions. Every overlay here is already whole-mounted in
# PORT_LEVEL_OVERLAYS, so each per-symbol mount is the SECOND mount of the same
# overlay -- the ov012/ov013/ov024/ov025/ov033/ov045 dual shape. --whole emits
# port_ovNNN_image/_patch/_at and nothing by name; --from-list --pack emits the
# named arrays plus port_ovNNN_syms_patch. Every mount bring-up runs from the
# lane's own hal/actor_classes_ovNNN.cpp behind a DSSTATE-bracketed done-guard
# (the ov025/ov033/ov045/ov052/ov056/ov073 lane-ownership pattern), so this lane
# appends NOTHING to hal/actor_overlays.cpp.
#
# 1/4: ov032 (level 24, Tiny-Huge Island's BIG side) joins the per-symbol
# mounts so HUGE_COVER (106), HUGE_WATER (107) and BUBBA (228) reach their three
# SpawnInfo records, their two CLPS blocks, id 107's BTA file descriptor, the
# seven sinit-built SharedFilePtrs, the seven destructor chain nodes and BUBBA's
# ten PMF source pairs and five state cells by name. Four of level 24's seven
# skipped instances. THE CAMPAIGN PLAN LISTS TWO CLASSES HERE AND THE ROM HAS
# THREE: id 228, RTTI 12daBakubaku_c, is the big fish (tools/actor_names.py
# reads it as BUBBA) and carries twenty-four of the overlay's forty-one TUs.
# All three vtables are excluded from the mount and hosted as arrays
# hal/actor_classes_ov032.cpp fills -- and dsd's ONE vtable address here carries
# TWO names, both on the WATER class (_ZTV9HugeCover and _ZTV14daObjTdWater_c at
# 0x021139a4), while the cover's own table and BUBBA's are unnamed. Proven three
# ways in port/ov032_syms.txt. See port/slice_sweep2_ov032.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov032)
# 2/4: ov034 (level 26, Tiny-Huge Island's CAVE) joins the per-symbol mounts so
# WIGGLER (248) reaches its SpawnInfo record, its seven five-element animation
# handle rows, its thirty-five sinit-built SharedFilePtrs, its thirty-five
# destructor chain nodes, its twenty-two PMF source pairs and -- the important
# one -- its ELEVEN-ENTRY, twenty-byte-per-entry state table at
# data_ov034_02114538, whose dsd landing reads ONE ENTRY OF ELEVEN. That is
# level 26's whole skip list, so this mount takes the level to zero skipped.
# Unlike ov032 and ov033 there is NO class-identity shift here: _ZTV7Wiggler is
# on the right class (RTTI "12daHanachan_c") and dsd's inferred 31-slot width is
# right. The table is excluded from the mount and hosted as an array
# hal/actor_classes_ov034.cpp fills. Derivation in port/ov034_syms.txt, slice in
# port/slice_sweep2_ov034.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov034)
# 3/4: ov047 (level 39, Bowser in the Sky) joins the per-symbol mounts so
# RICKSHAW_PLATFORM_BS (151), RICKSHAW_BS (152), STAIRS_BS (153) and
# ROTATING_PLATFORM_BS (156) reach their four SpawnInfo records, their seven
# CLPS collision blocks, their four resource arguments and their thirty-two
# sinit-built SharedFilePtrs and destructor chain nodes by name. Seven of level
# 39's nine skipped instances. THE CAMPAIGN PLAN LISTS THREE CLASSES HERE AND
# THE ROM HAS FOUR: id 156 (RTTI 20daObjKm3_Kaitendai_c, the rotating stand;
# tools/actor_names.py reads it as ROTATING_PLATFORM_BS). All four vtables are
# excluded from the mount and hosted as arrays hal/actor_classes_ov047.cpp
# fills -- and dsd's two vtable names are each attached ONE TABLE LATE, so
# _ZTV20daObjKm3_Kaitendai_c is id 156's and _ZTV17daObjKm3_Dorifu_c is id 153's. Proven
# three ways in port/ov047_syms.txt. See port/slice_sweep2_ov047.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov047)
# 4/4: ov055 (level 47, Luigi's key arena) joins the per-symbol mounts so
# MIRROR_LUIGI (195) reaches its SpawnInfo record, its four state words, its two
# PMF source pairs and -- the important one -- the SIXTEEN-BYTE state cell at
# data_ov055_02111b70, whose dsd landing reads ONE WORD OF FOUR. That is level
# 47's whole skip list, so this mount takes the level to zero skipped. No
# identity shift: _ZTV11MirrorLuigi is on the right class (RTTI "9daLuigi_c",
# base typeinfo Actor's), the table is 31 slots because a MirrorLuigi is a plain
# Actor and not a Platform, and no ov055 TU spells a resolver placeholder. This
# mount DEFINES data_ov055_02111a94, which src/game/actors/d_a_obj_ks_water.cpp
# (ov017, LINKED) spells for OV017's object at the same shared-window address --
# already routed by the wave-1 cast-sweep1 lane's per-source -D, which foresaw
# this mount and is not defeated by a definition the way an /alternatename would
# be. Derivation in port/ov055_syms.txt, slice in port/slice_sweep2_ov055.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov055)
# ov029 is level 21's own overlay (data/stage/water_city, the Dire Dire Docks
# city sublevel, course 10), already mounted --whole in hal/level_boot.cpp's
# level-21 row. This per-symbol mount lands its eight actors -- ids 94..101,
# every one placed by the level-21 boot census -- so RotatingPlatformWdw (94),
# FloatOnWaterPlatformWdwSquare (95), ArrowLift (96), WaterDiamond (97),
# SwitchActivatedPlank (98), CageLift (99), FloatOnWaterPlatformWdwRectangle
# (100) and WDW_Water (101) reach their SpawnInfo records, resource tables and
# the eight __sinit_ov029_* SharedFilePtr windows by name. WaterDiamond borrows
# ArrowLift's vtable and WDW_Water borrows RotatingPlatformWdw's; CageLift uses
# the unnamed Platform table _ZTV15daObjWc_Obj05_c. The four own tables stay OUT
# of the mount (host arrays hal/actor_classes_ov029.cpp fills). Derivation in
# port/ov029_syms.txt, slice in port/slice_ov029.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov029)
# ---- link100 OV ----
# ov039 is level 31's own overlay (data/stage/habatake, Tiny-Huge Island's
# sky, course 23), already mounted --whole in PORT_LEVEL_OVERLAYS above.
# That mount is one array and names nothing, so this per-symbol mount is
# what lets its one actor class -- CLOUD (314, RTTI 11daObjKumo_c, and
# level 31 places seventeen) -- reach the SpawnInfo record the registry
# rewrites in place and the two bss cells __sinit_ov039_021113b4 builds.
# The class's vtable stays OUT of the mount: it is host storage
# hal/actor_classes_ov_link100.cpp fills. Derivation in
# port/ov039_syms.txt, slice in port/slice_gate217.txt.
list(APPEND PORT_ACTOR_OVERLAYS ov039)
# ---- linkfull S4OV0 ----
# ov000 is no actor overlay: it is loaded once, by the boot worker, for its
# entry, which builds the game's ov0 handle table out of 2058 path strings in
# its own data (port/ov000_syms.txt; the entry and the reader are on
# port/slice_w31_s4ov0.txt, enrolled at the end of this file). But its data is
# the same per-symbol packed mount, and THIS LIST is how every consumer of a
# mount finds it: this loop (the three game targets' ACTOR_OV_SYMS and the
# ROM-CLEAN part list, both read before the end of this file), and the two
# tools that re-run the emitters against a cartridge, port/tools/romblob_verify.py
# (the kit build's self-check) and port/tools/romextract.py (a player's
# romdata.bin), both of which read this list out of this file. Its one
# exception, the cross pass, is taken just below the loop.
list(APPEND PORT_ACTOR_OVERLAYS ov000)
set(ACTOR_OV_SYMS "")
foreach(ovn IN LISTS PORT_ACTOR_OVERLAYS)
    set(ovn_out "${CMAKE_BINARY_DIR}/host-src/${ovn}_syms.c")
    add_custom_command(OUTPUT "${ovn_out}" "${ovn_out}.map"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/ovdata.py" ${ovn}
                "${ovn_out}" --from-list
                "${CMAKE_CURRENT_SOURCE_DIR}/${ovn}_syms.txt" --pack ${ROMCLEAN_FLAG}
                ${LINKONLY_FLAG}
        DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/ovdata.py"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob_common.py"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/link_only.py"
                "${CMAKE_CURRENT_SOURCE_DIR}/${ovn}_syms.txt"
        COMMENT "ovdata ${ovn} (per symbol, packed)")
    list(APPEND ACTOR_OV_SYMS "${ovn_out}")
    list(APPEND OV_DATA_MAPS "${ovn_out}.map")
    if(PORT_ROM_CLEAN)
        list(APPEND ROMCLEAN_PARTS "${ovn_out}.blobmap")
    endif()
endforeach()

# ---- linkfull S4OV0: ov000 stays OUT of the cross pass ----
# It has nothing to offer it (0 cross-mount candidates: all 2058 of its
# relocations land in its own .data) and nothing resident points into it (ov001
# replaces it at the same base before any scene), while the residency model
# calls every pair that does not overlap co-resident, so its window would become
# a second candidate for every level overlay's pointer into ov001's HUD tables.
# Leaving OV_DATA_MAPS also hides it from the XREL1 block at the end of this
# file, so its three config files are named here the way that block names them.
list(REMOVE_ITEM OV_DATA_MAPS "${CMAKE_BINARY_DIR}/host-src/ov000_syms.c.map")
set(_s4ov0_cfg "${PORT_REPO_ROOT_ABS}/config/arm9/overlays/ov000")
add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/host-src/ov000_syms.c" APPEND
    DEPENDS "${_s4ov0_cfg}/relocs.txt" "${_s4ov0_cfg}/delinks.txt"
            "${_s4ov0_cfg}/symbols.txt")

# THE CROSS-MOUNT POINTER PASS, last because it needs every map.
#
# A pointer from one mounted overlay into another was left holding its DS
# address by the per-mount passes above, which can only see their own symbols.
# That is not a loud failure: ntr/io.cpp reserves DS main RAM at 0x02000000 as
# zeroed pages, so the read succeeds and hands the game an OamAttr list with no
# 0xffff terminator, and the walk in OAM::Render is unbounded the moment the
# sprite goes off screen. This pass reads every mount's <out>.c.map and emits
# one patch function, port_cross_patch(), for the words that cross.
#
# It reproduces the OAM::MM_PLAYER_ICONS table (ov002 -> ov001, sixteen entries)
# that hal/sub_actors.cpp used to keep by hand, entry for entry, and finds the
# genuinely-crossing pointers a new level's whole-image mount carries (Whomp's
# Fortress -> ov098's cannon data). What it CANNOT resolve is a target in a DS
# window two mounted overlays share -- ov084/ov085 and ov089/ov091 are alternate
# actor overlays linked at one base, and the target address alone cannot say
# which. Those stay hand-resolved from relocs.txt's module: field in
# hal/actor_overlays.cpp (the ov089 key models). tools/ovsweep.py checks that
# nothing crossing was left raw with no patch.
set(OVCROSS_C "${CMAKE_BINARY_DIR}/host-src/ov_cross.c")
# The residency model reads its rules OUT OF the matched loader sources, so
# those five TUs are real inputs of the cross step: without these edges a
# semantic change to a loader body leaves ov_cross.c carrying bindings from
# the superseded model, silently (the stale-artifact shape). A rename still
# fails the next configure loudly, which is the intended trade.
set(OVCROSS_LOADER_SRC
    "${PORT_REPO_ROOT_ABS}/src/GetSceneOverlayID.c"
    "${PORT_REPO_ROOT_ABS}/src/func_0201a694.c"
    "${PORT_REPO_ROOT_ABS}/src/func_0201a798.c"
    "${PORT_REPO_ROOT_ABS}/src/func_0201a754.c"
    "${PORT_REPO_ROOT_ABS}/src/func_0201a614.c")
add_custom_command(OUTPUT "${OVCROSS_C}"
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/ovdata.py" --cross
            "${OVCROSS_C}" ${OV_DATA_MAPS} ${LINKONLY_FLAG}
    DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/ovdata.py" ${OV_DATA_MAPS}
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/link_only.py"
            ${OVCROSS_LOADER_SRC}
    COMMENT "ovdata --cross (pointers between mounted overlays)")

# ROM-CLEAN consolidation, last because it needs every emitter's part. It
# concatenates the .blobpart files into build/assets/romdata.bin, writes the
# manifest the loader checks, and generates romdata_dispatch.c
# (port_romdata_load_all). walk_window links the dispatch + hal/romdata_loader.
# The list is walk_window's exact emitter set; a target with a different set
# would need its own blob, but only the shipped window is ROM-clean today.
# The blob lands in the REPO-ROOT build/assets/ (beside files.tsv/handles.tsv):
# the loader resolves <asset_root>/build/assets/romdata.bin -- the same seam
# fs.cpp uses for the catalogs -- and asset_root defaults to PORT_REPO_ROOT,
# which is the repo root, NOT ${CMAKE_BINARY_DIR} (= build/port).
set(ROMDATA_BIN "${PORT_REPO_ROOT_ABS}/build/assets/romdata.bin")
set(ROMDATA_MANIFEST "${PORT_REPO_ROOT_ABS}/build/assets/romdata.manifest")
set(ROMDATA_DISPATCH_C "${CMAKE_BINARY_DIR}/host-src/romdata_dispatch.c")
if(PORT_ROM_CLEAN)
    # The .blobpart/.blobmap sidecars are written by the SAME emitter commands
    # that write the .c files, so depend on the .c OUTPUTs (which CMake knows how
    # to build) and mark the parts GENERATED. Depending on the parts directly
    # would be "no rule to make target" -- they are side-effects, not OUTPUTs.
    set(ROMCLEAN_C_OUTPUTS "${ROMDATA_C}" "${OV002DATA_C}" ${LEVEL_OV_DATA}
        "${OV009SYMS_C}" ${ACTOR_OV_SYMS})
    set_source_files_properties(${ROMCLEAN_PARTS} PROPERTIES GENERATED TRUE)
    add_custom_command(
        OUTPUT "${ROMDATA_BIN}" "${ROMDATA_MANIFEST}" "${ROMDATA_DISPATCH_C}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob.py"
                "${ROMDATA_BIN}" "${ROMDATA_MANIFEST}" "${ROMDATA_DISPATCH_C}"
                ${ROMCLEAN_PARTS}
        DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob.py"
                ${ROMCLEAN_C_OUTPUTS}
        COMMENT "romblob: consolidate ROM tables -> build/assets/romdata.bin")
    # A build-time self-check: the blob slices must byte-match the arrays the
    # emitters would bake. Guards against a drift between the two code paths.
    add_custom_command(
        OUTPUT "${CMAKE_BINARY_DIR}/assets/romblob_verified.stamp"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob_verify.py"
                "${PORT_REPO_ROOT_ABS}" "${CMAKE_BINARY_DIR}"
                "${ROMDATA_MANIFEST}" "${ROMDATA_BIN}"
        COMMAND ${CMAKE_COMMAND} -E touch
                "${CMAKE_BINARY_DIR}/assets/romblob_verified.stamp"
        DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob_verify.py"
                "${ROMDATA_BIN}" "${ROMDATA_MANIFEST}"
        COMMENT "romblob self-check: blob bytes == baked bytes")
    # The portable kit rebuilds romdata.bin on the player's machine from their
    # own dump; the recipe is the shippable how (offsets and hashes, zero ROM
    # bytes). Generated here, self-verified against the local extracted images,
    # so it can never drift from the manifest it names.
    set(ROMDATA_RECIPE "${PORT_REPO_ROOT_ABS}/build/assets/romdata.recipe.tsv")
    add_custom_command(
        OUTPUT "${ROMDATA_RECIPE}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob_recipe.py"
                "${ROMDATA_MANIFEST}" "${ROMDATA_RECIPE}"
        DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/romblob_recipe.py"
                "${ROMDATA_MANIFEST}"
        COMMENT "romblob recipe: manifest -> kit extraction recipe")
endif()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate18.txt" SLICE18_LINES)
set(SLICE18_SOURCES "")
foreach(line IN LISTS SLICE18_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE18_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# argfix: LakituBro::InitResources calls TextureSequence::Prepare with two
# arguments; the host wrapper reshapes them into a 3-param thiscall and derefs an
# unwritten third slot.
# RETIRED by run link100 lane SHADOWS: the third argument is the WRAPPER's, not
# the ROM's, so it moved into a forwarder (port_texseq_prepare_r1,
# hal/method_faces.cpp) and the ROM's own body took the seat on
# port/slice_shadows.txt. unmatched/TexSeq_Caller_LakituBro.cpp is deleted and
# this append goes with it; the src line stays commented out in gate 18's own
# file, which is not this lane's.
# rabbit-key: func_ov085_0212d268 (the RABBIT_KEY seat-and-enter) WAS a host
# copy here for the gate-16 reason -- MSVC's pointer-to-member over an
# incomplete class. R9c below (run link100 lane PMF3) puts the matched TU back
# instead, so unmatched/RabbitKey_StateSeat.cpp is deleted and this append goes
# with it. The src line stays commented out in slice_gate18.txt, which is gate
# 18's file; port/slice_pmf3.txt owns the row now.
# r0-passthrough: _ZN7daMip_c13StateIdleMainEv (the RABBIT's state Main, daMip_c) calls
# Actor::ClosestPlayer() with no argument, relying on `this` riding ARM r0. Host
# copy passes `c`; src line commented out in slice_gate18.txt. (the actor-187
# RABBIT null-this +0x5c crash, reachable once slot 19 made the rabbit swallowable)
list(APPEND SLICE18_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Ov085_Rabbit_b8dc.cpp")
# RETIRED by run link100 wave 15 lane SEAT15B (LINK15 BATCH 1). The four LakituBro
# (daC_Jugem_c) state bodies func_ov085_0212d9b8/dd10/e310/e4a4 were host-copied
# because their matched sources called Actor::ClosestPlayer() with no argument and
# relied on `this` riding ARM r0. All four sources PASS the receiver today (re-read
# at 8ddff3187: `(c)` in d9b8/dd10/e310, `((void *)self)` in e4a4), so the copies
# had nothing left to work around. unmatched/Ov085_LakituBro_ClosestPlayer.cpp is
# deleted and the four src rows are uncommented in slice_gate18.txt.

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate19.txt" SLICE19_LINES)
set(SLICE19_SOURCES "")
foreach(line IN LISTS SLICE19_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE19_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate20.txt" SLICE20_LINES)
set(SLICE20_SOURCES "")
foreach(line IN LISTS SLICE20_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE20_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Linkage-campaign lane slices (run linkw): five files, one OWNER each, so
# five parallel seat lanes add matched TUs without ever editing this file or
# each other's lists. Same reader shape as the gate slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w1l1.txt" SLICE_W1L1_LINES)
set(SLICE_W1L1_SOURCES "")
foreach(line IN LISTS SLICE_W1L1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W1L1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# EXPERIMENT (LIGHTS lane): route Scene::Initialise3dGraphics through hostgen.
set(SCN3D_HOSTGEN_SKIP "src/_ZN8dScene_c20Initialise3dGraphicsEv.cpp")
set(SCN3D_HOSTGEN_GEN
    "${CMAKE_BINARY_DIR}/host-src/src/_ZN8dScene_c20Initialise3dGraphicsEv.cpp")
add_custom_command(OUTPUT "${SCN3D_HOSTGEN_GEN}"
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            --out "${CMAKE_BINARY_DIR}/host-src" _ZN8dScene_c20Initialise3dGraphicsEv
    DEPENDS "${PORT_REPO_ROOT_ABS}/src/_ZN8dScene_c20Initialise3dGraphicsEv.cpp"
            "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
    COMMENT "hostgen _ZN8dScene_c20Initialise3dGraphicsEv")

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w1l2.txt" SLICE_W1L2_LINES)
set(SLICE_W1L2_SOURCES ${SCN3D_HOSTGEN_GEN})
foreach(line IN LISTS SLICE_W1L2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(line IN_LIST SCN3D_HOSTGEN_SKIP)
        continue()
    endif()
    list(APPEND SLICE_W1L2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w1l3.txt" SLICE_W1L3_LINES)
set(SLICE_W1L3_SOURCES "")
foreach(line IN LISTS SLICE_W1L3_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W1L3_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w1l4.txt" SLICE_W1L4_LINES)
set(SLICE_W1L4_SOURCES "")
foreach(line IN LISTS SLICE_W1L4_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W1L4_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# run linkw wave 5 (lane w5-c): the ov070 enemy pack + the level-37 census
# closers. Two hostgen groups ride with the slice:
#   SQRTUNIT -- the hardware square-root unit's four drivers. func_02053008 /
#   func_020531a4 write the unit through bound pointers, func_02052fdc reads
#   it through literal derefs, and func_02053130 reaches it through role-named
#   externs (hostgen's MMIO_EXTERN table). All four route through run_sqrt via
#   ntr/io.cpp's widened SQRT_PARAM trigger; the numeric proof is in the
#   commit that landed the mechanism. Quaternion_Normalize (slice_w1l4's
#   restored id-141 chain) and Quaternion_FromVector3 are the callers.
#   Folded from lane w5-B (the level-13 reach evidence): the same unit is
#   pulled in by WORK_ELEVATOR's rider-push callback (func_ov021_02112024
#   -> Quaternion_Normalize), closing the id-141 sqrt gap
#   hal/actor_classes_ov045.cpp names from the HMC cast as well.
#   OV70GEN -- func_ov070_0211f0a4, the census's measured compile fail (C4716;
#   hostgen's FALLS_OFF_RETURN table documents the returned value); and
#   _ZN19daPropeller_Heyho_c13InitResourcesEv, whose src declares its data_ov070 externs above
#   its own extern "C" block (C++ linkage, LNK2019 against the C-linkage mount).
#   hostgen's EXTERN_C_DATA table moves the extern "C" opener up, retiring the
#   old host mirror.
set(SQRTUNIT_SYMS func_02053008 func_02053130 func_020531a4 func_02052fdc)
set(SQRTUNIT_GEN "")
foreach(sym IN LISTS SQRTUNIT_SYMS)
    set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND SQRTUNIT_GEN "${sym_out}")
endforeach()
# EMPTIED 2026-09-13 (lane SYNC3). main folded both bodies into
# src/game/actors/d_a_propeller_heyho.cpp, so neither has a file of its own to
# substitute for. Both fixes are kept by substituting the WHOLE TU: see
# PORT_HOSTGEN_TU at the top of this file, and the FALLS_OFF_RETURN and
# EXTERN_C_DATA entries in tools/hostgen.py, which are re-keyed onto the TU's
# stem with their strings re-derived against main's own spelling of the bodies.
set(OV70GEN_SYMS)
set(OV70GEN "")
foreach(sym IN LISTS OV70GEN_SYMS)
    set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND OV70GEN "${sym_out}")
endforeach()
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w5c.txt" SLICE_W5C_LINES)
set(SLICE_W5C_SOURCES "")
foreach(line IN LISTS SLICE_W5C_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W5C_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w1l5.txt" SLICE_W1L5_LINES)
set(SLICE_W1L5_SOURCES "")
foreach(line IN LISTS SLICE_W1L5_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W1L5_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# Wave-5 lane slice (run linkw), same one-owner contract as the five above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w5d.txt" SLICE_W5D_LINES)
set(SLICE_W5D_SOURCES "")
foreach(line IN LISTS SLICE_W5D_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W5D_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# run linkw wave 5, lane w5-e: the Bowser arena pack (ov060 + the arena class)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w5e.txt" SLICE_W5E_LINES)
set(SLICE_W5E_SOURCES "")
foreach(line IN LISTS SLICE_W5E_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W5E_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# run linkw wave 6, lane w6-A: THE FIGHT -- the five remaining ov060 classes
# (SpikeBomb 284, Bowser 279, BowserTail 278, BowserFire 280, BowserSkyPlatform
# 167) and ov089's boss reward (Key 282, LastStar 283). Same one-owner
# contract; the coupling between 279/278/280/282 is measured, see that file's
# header and hal/actor_classes.inc's wave-6 row block.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w6a.txt" SLICE_W6A_LINES)
set(SLICE_W6A_SOURCES "")
foreach(line IN LISTS SLICE_W6A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W6A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# run linkw wave 5, lane w5-B (Hazy Maze Cave's cast); same reader shape,
# one owner.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w5b.txt" SLICE_W5B_LINES)
set(SLICE_W5B_SOURCES "")
foreach(line IN LISTS SLICE_W5B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W5B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run rel0215 wave 3, lane w3-a2: ov065's TICK TOCK CLOCK cluster -- eleven
# ids, seven classes, seven 32-slot Platform tables, seven static initialisers.
# Same reader shape, one owner. The cast map is in port/ov065_syms.txt's wave-3
# section and the fills in hal/actor_classes_ov065.cpp.
# ONE TU OF THIS SLICE GOES THROUGH hostgen, AND THE REST DO NOT.
#
# src/_ZN15TtcRotatingCube13InitResourcesEv.cpp re-declares _ZN15TtcRotatingCube10UpdateClsnEv
# and _ZN15TtcRotatingCube11UpdateModelEv `(void*)` inside its own extern "C" block, while
# include/decl_common.h:2777-2778 already declares both `(char*)` inside its.
# One register on the ROM; to MSVC it is two C2733s and then two C2664s at the
# call sites, which bind to the header's spelling. Neither src/ nor include/ may
# be edited for the port, so tools/hostgen.py's HEADER_SHADOW hides the HEADER's
# two declarations across its own include and leaves every definition alone --
# the _ZN5Whomp13InitResourcesEv entry's shape exactly. The emitted file keeps
# the symbol name, so the TU still counts as LINKED.
#
# The two colliding names are themselves on this slice and BOTH define
# themselves `(void*)`, which is the other half of why the header is the odd one
# out here rather than the TU.
set(SLICE_W3A_HOSTGEN_SYMS _ZN15TtcRotatingCube13InitResourcesEv)
set(SLICE_W3A_HOSTGEN_GEN "")
foreach(sym IN LISTS SLICE_W3A_HOSTGEN_SYMS)
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND SLICE_W3A_HOSTGEN_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w3a.txt" SLICE_W3A_LINES)
set(SLICE_W3A_SOURCES "")
foreach(line IN LISTS SLICE_W3A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # the one TU hostgen emits: take the generated copy, never the src/ one,
    # or MSVC gets the unshadowed header and the four errors come back
    if(line STREQUAL "src/_ZN15TtcRotatingCube13InitResourcesEv.cpp")
        continue()
    endif()
    list(APPEND SLICE_W3A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_W3A_SOURCES ${SLICE_W3A_HOSTGEN_GEN})

# ---- THE SIX PER-SOURCE PLACEHOLDER BINDINGS, AND WHY THEY ARE NOT OPTIONAL
#
# VT0/VT1/G0/G1 are the resolver's shared-header placeholders. They are NOT
# undefined symbols that would fail a link: hal/actor_vtables.cpp DEFINES
# `int VT0[20]` and hal/cxx_aliases.cpp alternatename's bare _G0 onto
# data_020a0eac (the game heap) and bare _G1 onto data_ov002_0210e05c
# (SignPost's collision file). So a Ttc TU that spells VT0 and gets no -D LINKS
# CLEAN and writes hal/actor_vtables.cpp's dummy array as its object's vptr,
# and nothing in the build says a word. That is the failure mode these six
# lines exist to remove, and it was found by disassembling the four bodies
# rather than by a link error.
#
# Every target below was read out of the body's OWN literal pool in
# extracted/overlays/overlay_0065.bin, and each is confirmed from the other
# side by the sinit that BUILDS the pair (c76c writes 0211d88c.., c890 writes
# d904.., c9b8 writes d97c.., ca74 writes d9cc..).
#
# THE RENAMES ARE LANE-OWNED NAMES, not the mount names directly, which is the
# ov035 remedy for a C2372: include/decl_common.h already declares
# data_ov065_0211d904 / _0211d90c as `extern char` scalars and _0211d97c /
# _0211d98c as `extern char []`, so `-DG0=data_ov065_0211d904` would rewrite
# that header's own line into a redefinition at a different type. The lane-owned
# names are declared nowhere and are bound by /alternatename in
# hal/actor_classes_ov065.cpp. Nothing is host-copied and all four TUs stay
# matched.
#
# TWO OF THESE FILES ARE THE SAME SOURCE TEXT NEEDING DIFFERENT ANSWERS.
# src/actors/daObjCtMecha03_c.cpp and src/game/actors/daObjCtMecha05_c.cpp are character for
# character identical and their literal pools hold different pairs
# (0211d88c/894 against 0211d904/90c). One shared define would silently break
# one of the two, which is why this is per source.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names daObjCtMecha03_c.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   VT0=_ZTV16daObjCtMecha03_c  --  dead, the TU does not spell VT0
#   VT1=_ZTV10dBgActor_c  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names daObjCtMecha05_c.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   VT0=_ZTV16daObjCtMecha05_c  --  dead, the TU does not spell VT0
#   VT1=_ZTV10dBgActor_c  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daObjCtMecha03_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_ov065_m03_file0;G1=port_ov065_m03_file1")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/daObjCtMecha05_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_ov065_m05_file0;G1=port_ov065_m05_file1")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN15TtcRotatingGear16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_ov065_m08_file0;G1=port_ov065_m08_file1")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN14TTC_MovingBeam16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_ov065_m09_file0;G1=port_ov065_m09_file1")

# run linkw wave 5, lane w5-A: Big Boo's Haunt's cast (ov063 + host copies).
# See the header of port/slice_w5a.txt for the six exclusions and the four
# byte-verified host copies.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w5a.txt" SLICE_W5A_LINES)
set(SLICE_W5A_SOURCES "")
foreach(line IN LISTS SLICE_W5A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W5A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# run linkw wave 6, lane w6-f: FLAMETHROWER (318, ov095). The four matched
# methods plus the four particle emitters the Behavior fires; the Behavior
# itself is the host copy unmatched/Flamethrower_Behavior.c, listed on the
# targets beside the fill. Same one-owner contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w6f.txt" SLICE_W6F_LINES)
set(SLICE_W6F_SOURCES "")
foreach(line IN LISTS SLICE_W6F_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W6F_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 7, lane w7-c: ORANGE_BALL_BILLBOARD (301, ov044) -- level 36's
# only cast item that was not already registered, plus the fill/registry host
# file. Level 40 needs no slice: its three ids are all ov060, all landed in
# wave 6. One TU is held out (the shadow-class MSVC destructor); the header of
# port/slice_w7c.txt carries the reason and the closure walk. Same one-owner
# contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w7c.txt" SLICE_W7C_LINES)
set(SLICE_W7C_SOURCES "")
foreach(line IN LISTS SLICE_W7C_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W7C_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 8, lane w8-faces: THE FACE QUEUE. This lane audits the two
# forwarder-face files against the emitted bytes; the slice carries the one
# matched TU that audit turned from a host stand-in into real decomp code
# (TextureTransformer::Prepare -- the header of port/slice_w8faces.txt has the
# reading, including the parked note it refutes). Same one-owner contract as
# the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w8faces.txt" SLICE_W8FACES_LINES)
set(SLICE_W8FACES_SOURCES "")
foreach(line IN LISTS SLICE_W8FACES_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W8FACES_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 9, lane w9-harvest: THE STALE-FORK HARVEST. This branch forked
# from main at 7b2f913fe (2026-08-04) and is 626 commits behind it, so every TU
# the decomp has matched since is invisible from here -- including ones the port
# hand-hosts under a banner saying no matched TU exists. The slice carries the
# matched TUs that audit recovered; port/slice_w9harvest.txt's header has the
# measured pool (543 main-only TUs: 496 rename-duplicates, 7 host retirements,
# 40 unreferenced) and the per-file evidence. Same one-owner contract as the
# lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w9harvest.txt" SLICE_W9HARVEST_LINES)
set(SLICE_W9HARVEST_SOURCES "")
foreach(line IN LISTS SLICE_W9HARVEST_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W9HARVEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run link100 wave 15, lane SEAT15B -- LINK15 BATCH 1, the ClosestPlayer receiver
# family. Matched TUs whose host copy existed only because the source dropped the
# ClosestPlayer receiver that rides ARM r0, and whose source passes it today. The
# per-row evidence, and the sibling rows deliberately NOT here, are in the header
# of port/slice_l15cp.txt. Same one-owner contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_l15cp.txt" SLICE_L15CP_LINES)
set(SLICE_L15CP_SOURCES "")
foreach(line IN LISTS SLICE_L15CP_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_L15CP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run link100 wave 15, lane SEAT15E (LINK15 BATCH 4): the ov007 / ov002 / ov096
# singles. Every row is a port/unmatched/ host copy whose banner named a defect
# in the matched source and worked around it; the source has since been fixed
# and nothing re-read the banner. port/slice_l15ov7.txt quotes, per row, the
# sentence that was re-tested against src/ at 8ddff3187 and what it reads now,
# and carries the one row of the batch whose refusal STILL holds
# (LoadEntranceObjects) as a written refusal rather than a deletion. Same
# one-owner reader shape as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_l15ov7.txt" SLICE_L15OV7_LINES)
set(SLICE_L15OV7_SOURCES "")
foreach(line IN LISTS SLICE_L15OV7_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_L15OV7_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 6, lane w6-D: PATH_LIFT (31) and the PathLift base branch --
# ov100's daObjPathLift_c over ov002's PathLiftActor_c over Platform, the
# first three-level hierarchy this port hosts that is split across overlays.
# Same reader shape, one owner. The header of port/slice_w6d.txt carries the
# reloc-derived closure, the two PMF host copies and the ov006 naming trap;
# the hierarchy map and both 33-slot widths are in
# hal/actor_classes_ov100pl.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w6d.txt" SLICE_W6D_LINES)
set(SLICE_W6D_SOURCES "")
foreach(line IN LISTS SLICE_W6D_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # VS wiring lane: the PathLift path-follow body's two `x / dv` sites need
    # the ARM divider's x/0 = 0, and a short-or-slow path segment makes dv 0
    # (measured: c0000094 in the VS castle grounds, reproduced with plain
    # SM64DS_LEVEL=51). RETIRED to the matched TU through hostgen's DS_DIV table,
    # which routes both sites through ds_idiv. The plain manifest line is
    # replaced HERE by the hostgen output so slice_w6d.txt itself stays another
    # lane's file (the TTE hostgen-skip shape); this retires the old
    # port/unmatched/VS_PathDivGuard.cpp host copy.
    if(line STREQUAL "src/func_ov002_020ef670.c")
        # SYNC4: hostgen emits .cpp for this TU now -- main's spelling of the
        # body is C++, so the generated copy follows the extension.
        set(_pathdiv_out "${CMAKE_BINARY_DIR}/host-src/src/func_ov002_020ef670.cpp")
        add_custom_command(OUTPUT "${_pathdiv_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" func_ov002_020ef670
            DEPENDS "${PORT_REPO_ROOT_ABS}/src/func_ov002_020ef670.c"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen func_ov002_020ef670")
        list(APPEND SLICE_W6D_SOURCES "${_pathdiv_out}")
        continue()
    endif()
    list(APPEND SLICE_W6D_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 8, lane w8-packs: ov022's Lethal Lava Land platform cast --
# VOLCANO_RING (71), FLOAT_ON_LAVA_PLATFORM (74), FLOATING_FLOOR_LLL_BIG (75)
# and _SMALL (76), LAVA_PLANK (82), plus the four ov022 static initialisers
# those four tables need. Same reader shape, one owner. The cast map (three
# independent routes), the two shifted name blocks, both width routes and the
# four classes held back on the inferred-stub ratchet are in
# hal/actor_classes_ov022.cpp; the mount is port/ov022_syms.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w8packs.txt" SLICE_W8PACKS_LINES)
set(SLICE_W8PACKS_SOURCES "")
foreach(line IN LISTS SLICE_W8PACKS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W8PACKS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run link100 wave 14, lane SEAT14B (BATCH 5): the one ov022 row wave 8 held
# out of slice_w8packs.txt, _ZN9LavaPlank16CleanupResourcesEv. Its G0/G1
# refusal is stale -- the TU now spells its two SharedFilePtrs by the names
# config/arm9/overlays/ov022/symbols.txt gives 0x02114620 and 0x02114618, so
# it needs no per-source -D, only the two /alternatename lines in
# hal/actor_classes_ov022.cpp. port/slice_lava.txt carries the derivation.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_lava.txt" SLICE_LAVA_LINES)
set(SLICE_LAVA_SOURCES "")
foreach(line IN LISTS SLICE_LAVA_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_LAVA_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run link100 wave 14, lane SEAT14B (BATCH 7): small-overlay singles. One row,
# src/BookSwitch_Spawn.c -- the dsd-misnamed ov016 body at 0x021115a4 that is
# really Unagi's d7c state ENTER, retiring the hand transcription in
# unmatched/Unagi_StateDispatch.cpp. port/slice_small7.txt carries the
# instruction-level verification and the three refusals this batch also names.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_small7.txt" SLICE_SMALL7_LINES)
set(SLICE_SMALL7_SOURCES "")
foreach(line IN LISTS SLICE_SMALL7_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SMALL7_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 10, lane w10-shared: ov031's SLIDE DECORATION QUAD -- FOUR
# spawn-table ids (302/303/304/305) onto ONE ROM class and ONE table
# (0x02111984), x3 each on level 23, whose entire baseline skip set was those
# twelve instances. The class reads its variant out of its own actor id, so one
# fill and one closure of bodies serve all four rows. One TU is held out (the
# shadow-class MSVC destructor, slot 16, spelled inline in the fill instead);
# the header of port/slice_w10a.txt carries the reason, both attribution routes
# for each id, the width derivation and the Render slot-5 ruling. Same one-owner
# contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w10a.txt" SLICE_W10A_LINES)
set(SLICE_W10A_SOURCES "")
foreach(line IN LISTS SLICE_W10A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W10A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 10, lane w10-shared, slice B: MEGA_MUSHROOM (277, ov002) x1 on
# level 22 -- ONE TU. Its factory stores _ZTV13OneUpMushroom, the same ROM table
# the already-registered ONE_UP_MUSHROOM (276) installs, so it needs no fill, no
# vtable and no new mount: one record in port/ov002_syms.txt and this one line.
# The header of port/slice_w10b.txt carries both attribution routes, the width
# agreement and the record pin. Same one-owner contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w10b.txt" SLICE_W10B_LINES)
set(SLICE_W10B_SOURCES "")
foreach(line IN LISTS SLICE_W10B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W10B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 11, lane w11: NINETEEN ids whose vtable is already a FILLED
# host array and whose overlay is already mounted -- the tier the census-built
# worklist could not see, found by widening the shared-table sweep from ~70
# classes to all 512 spawn-table ids. One factory TU each and nothing else: no
# mount, no vtable, no fill, no wrapper. Six records were added to
# port/ov095_syms.txt and port/ov002_syms.txt; the other thirteen were mounted
# already. The header of port/slice_w11.txt carries both attribution routes for
# all nineteen, the ten shared tables with the registered sibling that fills
# each, and the done-guard evidence for every fill reused. Same one-owner
# contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w11.txt" SLICE_W11_LINES)
set(SLICE_W11_SOURCES "")
foreach(line IN LISTS SLICE_W11_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W11_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 12, lane w12: ov073, the WHOLE CAST OF LEVEL 49 (ex_wario,
# "Wario's key arena"). The level was mounted and booting with four actors
# placed and EIGHTEEN skipped, because every actor it places is ov073's and
# ov073 had no mount -- hal/level_boot.cpp's own row said "[unmounted ov073]".
# Sixty-seven TUs, the reloc closure of both vtables' ov073 slots, both
# ChangeState veneers, the four Spawns, both sinits and the forty {code, adj}
# state records the sinits copy (those forty are reachable only through the
# state tables, so a reloc-only closure misses all of them). Five TUs are held
# out and host-copied -- one ARM r0 ride-through factory, two MSVC
# pointer-to-member dispatchers, one inline copy of the same, and one
# BlendModelAnim slot-5 collision -- with the derivation for each in the header
# of port/slice_w12.txt. Same one-owner contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w12.txt" SLICE_W12_LINES)
set(SLICE_W12_SOURCES "")
foreach(line IN LISTS SLICE_W12_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W12_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 12, lane w12: ov052's two platform classes (level 44). Sixteen
# TUs, the whole of that overlay's actor code, and the reloc closure leaves
# ov052 for nothing that was not already linked. The header of
# port/slice_w12b.txt carries both attribution routes, the 38-reads-as-32 width
# derivation and the shared-window misspelling this lane renames per source.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w12b.txt" SLICE_W12B_LINES)
set(SLICE_W12B_SOURCES "")
foreach(line IN LISTS SLICE_W12B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W12B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 12, lane w12: CLAM (315), ov064 -- nine instances on a table
# nothing had filled, in an overlay already mounted whole and per symbol. Seven
# TUs; two more bodies of its closure are held out and host-copied (a ModelAnim
# slot-5 Render and a real MSVC destructor with no C name). The header of
# port/slice_w12c.txt carries both, and the measured reason its sibling
# TREASURE_CHEST (13) is not here.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w12c.txt" SLICE_W12C_LINES)
set(SLICE_W12C_SOURCES "")
foreach(line IN LISTS SLICE_W12C_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W12C_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 15, lane w15: BIG_MOVING_ICE_BLOCK (173), ov056 -- nine
# instances on level 48, on a table nothing had filled, in an overlay mounted
# whole but not yet per symbol. EIGHT TUs, the whole of ov056's actor code
# (six vtable slots, the factory and the overlay's single sinit), and the reloc
# closure leaves ov056 for nothing that was not already linked. None of the
# eight carries the inferred-stub guess marker. The header of
# port/slice_w15.txt carries both attribution routes, the Render slot-5 ruling
# and the two destructors' placeholder-store reading; the width derivation is
# in port/ov056_syms.txt. Same one-owner contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w15.txt" SLICE_W15_LINES)
set(SLICE_W15_SOURCES "")
foreach(line IN LISTS SLICE_W15_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W15_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 15, lane w15: the MEGA MUSHROOM TAG pair (319 + 320, ov002) --
# ONE ROM class under two spawn-table ids on one table (0x02108cf4), one
# instance of each on levels 22 and 24. ov002 has been mounted since gate 14,
# so this is two records in port/ov002_syms.txt, one host array with one fill,
# two registry rows and EIGHT TUs, with no new mount and no new sinit. The
# class branches on its own actor id, so one closure serves both rows. Slot 16
# is held out and transcribed in the fill (the SlideDecorationSilverStar
# shadow-class MSVC destructor shape); the ROM disassembly it was transcribed
# from is in hal/actor_classes_ov002_w15.cpp. None of the eight carries the
# inferred-stub guess marker. Same one-owner contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w15b.txt" SLICE_W15B_LINES)
set(SLICE_W15B_SOURCES "")
foreach(line IN LISTS SLICE_W15B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W15B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 15, lane w15: ov025's PYRAMID_STEP (87) and PYRAMID_LIFT (88)
# -- five of level 17's eleven skipped instances. NINETEEN TUs: twelve vtable
# bodies, two factories, four helpers and the two sinits these classes own. One
# more body is held out and host-thunked (PyramidStep::CleanupResources, whose
# src spells its two SharedFilePtrs G0/G1 in C++ and would Release SignPost's
# live ones -- the ov022 FloatingFloorLllBig failure); the ROM disassembly it
# was transcribed from is in hal/actor_classes_ov025.cpp. None of the nineteen
# carries the inferred-stub guess marker. Same one-owner contract as the lane
# slices above.
# run linkw wave 16, lane w16-unblock: FALL_BLOCK_LLL (id 83, ov022) -- nine
# instances on level 14, the sixth of Lethal Lava Land's eleven ids. NO NEW
# MOUNT: lane w8-packs already mounted g_profile_FL_KUZURE and the file
# table data_ov022_0211427c by name and already excluded the vtable 0x021142c4
# so it can be host storage. What held this id back was inferred_stub_guard.py
# -- three of its five bodies carry the "recovered from vtable slot identity"
# marker. All three were disassembled out of the shipped overlay image and
# ruled REAL DECOMP (port/slice_w16a.txt for the derivation, the rulings are
# recorded against their symbols in port/tools/inferred_stub_debt.txt). The
# class is FallBlockBfs' twin: slots 6/9/27/31 are the same four ov098 bodies
# ov045 and ov015 already seat, so the new code is a host array, two
# destructors and one sinit. Width is 32, pinned three ways -- the reloc run
# over-reads to 38 through two typeinfo records, the next-symbol landing
# under-reads to 30 because dsd split the table at slot 30, and slot 31 is a
# real 32nd virtual (_ZN16daObjFallBlock_c4KillEv, NOT Platform::Kill). Same one-owner
# contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w16a.txt" SLICE_W16A_LINES)
set(SLICE_W16A_SOURCES "")
foreach(line IN LISTS SLICE_W16A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W16A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 17, lane w17: SEAWEED (id 296, ov002), RTTI 13daObjWakame_c --
# x8 on level 18 and x4 on level 8. Lane w16 ruled its five marker-carrying
# bodies REAL DECOMP and left it blocked on one mount line; that line is
# g_profile_WAKAME:0x1c in port/ov002_syms.txt, NOT the 0x24 the dsd
# next-symbol delta reads (the two extra words are the vtable's own Itanium
# prologue, the wave-15 MEGA_MUSHROOM shape). The vtable 0x02109bb8 is excluded
# from the mount and hosted as an array; its identity is the RTTI record at
# vtable[-1], since dsd's _ZTV7Seaweed is one class further on and is really
# HealingHeart's (RTTI 12daObjHeart_c). Slot 9 is the ModelAnim slot-5
# collision and is a host copy in hal/actor_classes_ov002_w17.cpp, so
# src/game/actors/d_a_obj_wakame.cpp is deliberately NOT in this slice. Same one-owner
# contract as the lane slices above.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w17a.txt" SLICE_W17A_LINES)
set(SLICE_W17A_SOURCES "")
foreach(line IN LISTS SLICE_W17A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W17A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# R7, run linkw wave 17 (lane w17): src/game/actors/d_a_obj_wakame.cpp (SEAWEED's
# deleting destructor) restores its vtable through the shared-header
# placeholder `VT0` -- and VT0 is DEFINED in this link, as `int VT0[20]` in
# hal/actor_vtables.cpp, whose own comment warns that "two classes can spell
# DIFFERENT vtables VT0 and both resolve here. A slot that is actually
# dispatched must never come through one of them." Slot 17 IS dispatched, so
# this would have linked silently and installed a 20-word dummy as the vptr
# ahead of ModelAnim::D1 and Actor::D2. A -D and not an /alternatename for the
# R4/R5 reason squared: the LHS is already defined, so an alias would be
# defeated on the spot. The target is the HOST ARRAY, since 0x02109bb8 is
# excluded from the mount.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wakame.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT0=_ZTV13daObjWakame_c")

# R8, run linkw wave 17 (lane w17): the mwcc POINTER-TO-MEMBER width bug, and
# the reason level 27 could be mounted green. src/game/actors/daBrq_c.cpp and
# src/game/actors/d_a_krpa.cpp are `PMF *p = c->pp + 1; (c->**p)();` over an
# INCOMPLETE class -- mwcc's PMF there is the Itanium 8-byte {fn, adj} record,
# MSVC's is the 4-byte single-inheritance form, so `+ 1` strides four and lands
# on the adj word, which every seated record holds as 0. Measured as `call 0`
# on frame 0 of level 27 for AMP (0x10a) and FLAME_CHOMP (0x10e) -- the fault
# wave 8 filed as "DATA-dependent". The stride is pinned by the setters
# _ZN7daBrq_c8SetStateEi / func_ov070_02121880, which both index the state table
# by `state << 4`, i.e. two 8-byte PMFs per State. Routed at the two CALLERS
# rather than by editing another lane's slice: the matched TUs stay in src/ and
# on slice_w5c.txt and are now dead. Full reading in
# port/unmatched/Ov070_PmfDispatch.cpp, including the twenty-one OTHER TUs in
# src/ that carry the identical shape and are a lane of their own.
# The remedy is a COMPILE OPTION on the two dispatchers themselves, not a
# rename of their callers: MSVC's /vmg /vmm pair says "for a pointer-to-member
# declared before its class, use the MULTIPLE-INHERITANCE representation",
# which is {void *fn; int delta;} -- eight bytes, the ROM's own record, with a
# call that adds delta to `this` and calls fn. So `c->pp + 1` strides eight and
# the dispatch is the ROM's even-adj branch exactly. The ROM stores adj and
# shifts it right by one where MSVC stores delta directly; every record in
# ov070 carries adj 0, so the two agree word for word here.
# Nothing is renamed, nothing goes dead, and the two matched TUs keep doing
# their own job. THE SAME OPTION IS THE FIX FOR THE OTHER TWENTY-ONE TUs with
# this shape (port/unmatched/Ov070_PmfDispatch.cpp lists them); only these two
# are turned on here, because only these two are on level 27's critical path
# and each one wants its own measured before/after.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/daBrq_c.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_krpa.cpp"
    PROPERTIES COMPILE_OPTIONS "/vmg;/vmm")

# R9, run linkw wave 18 (lane w18): THE REST OF THE POINTER-TO-MEMBER WIDTH
# SWEEP. R8 above fixed the two ov070 dispatchers that stood between level 27
# and a green battery and left the rest of the class for a lane with a measured
# before/after per TU. This is that lane.
#
# The predicate that finds them is NOT "the TU mentions a pointer-to-member" --
# 302 TUs in src/ do. It is the conjunction of a pointer-to-member of an
# INCOMPLETE class AND a NONZERO offset applied to it. At index 0 the wrong
# stride cannot bite: MSVC's 4-byte PMF at offset 0 IS the fn word, and every
# seated record in this game carries adj 0, so the pp[0] siblings are correct
# BY LUCK and are deliberately NOT listed here. Scanning src/ for that
# conjunction returns exactly TWENTY-ONE TUs, the three above included.
#
# THE STRIDE IS THE ROM'S, READ OFF THE ROM, TWENTY-ONE FOR TWENTY-ONE. Each
# body was disassembled at its own address out of extracted/overlays/ and the
# instruction that forms `pp + 1` read directly: `add r3, r1, #8`, every time,
# feeding the Itanium odd-adj branch. Three of them (KingBobOmb, MrBlizzard,
# ChiefChilly) prove it a second way without leaving src/: each guards the
# dispatch with `*(void **)((char *)pp + 8) != 0` -- a BYTE offset of 8 on the
# same word `pp + 1` then dereferences, so sizeof(PMF) is 8 by the source's own
# arithmetic.
#
# MSVC'S SIDE IS MEASURED TOO, and it settles a disagreement in this tree.
# unmatched/KingBobOmb_States.cpp and unmatched/Bbh_PmfDispatch.c both say MSVC
# "widens PMF to its four-word general representation"/"the 16-byte general
# form"; unmatched/Scuttlebug_StateDispatch.cpp says MSVC's is 4 bytes. The
# objs say 4. Same build, same shape, one flag apart:
#
#   func_ov070_02121fd0 (no option)   mov eax,[ecx+31Ch]   <- pp
#                                     mov eax,[eax+4]      <- ADJ of record 0 = 0
#                                     jmp eax              <- jmp 0
#   _ZN7daBrq_c11UpdateStateEv (/vmg /vmm)   mov edx,[eax+41Ch]   <- pp
#                                     mov ecx,[edx+0Ch]    <- delta of record 1
#                                     add ecx,eax          <- this += delta
#                                     mov eax,[edx+8]      <- FN of record 1
#                                     jmp eax
#
# `[eax+4]` versus `[edx+8]`: the fix moves the call target from the adj word,
# which is zero on every seated record, onto the record's function word. A
# 16-byte representation would have produced a wrong-but-nonzero target, not
# the EIP=0 wave 17 measured.
#
# PER-SOURCE, NEVER GLOBAL. /vmg /vmm changes the representation of every
# pointer-to-member declared in a TU, so a TU that already agrees with MSVC's
# default would silently change layout under a blanket flag. It is safe here
# because none of these TUs takes a pointer-to-member across a header boundary:
# the 4-line dispatchers include nothing at all, and KingBobOmb.h /
# MrBlizzard.h / ChiefChilly.h / decl_common.h / types.h declare no `::*`
# between them. `pp` itself is a POINTER and stays four bytes either way, so no
# `struct C` in this set changes size.
#
# WHICH OF THESE ARE LIVE. Four states, and only two of them are measurable:
#
#   MATCHED+LINKED (3, all ov070): func_ov070_02121fd0 is the one that matters.
#       It is on slice_w5c.txt, it is in walk_window.map today, and it is a
#       live `jmp 0` in the shipping binary -- the same latent crash wave 17
#       fixed on its two siblings and did not fix here. Its class is not on a
#       mounted level yet, which is the only reason no battery caught it.
#   HOSTCOPY->RECLAIMED (4): on slice_w18a.txt, replacing four host bodies.
#   HOSTCOPY->RANKED (2): KingBobOmb::Behavior and ChiefChilly::Behavior are
#       real linkage but their host files also carry setters and table seats.
#   ABSENT (12): not linked, and nothing in the port references them, so
#       /OPT:REF strips them the moment they are sliced. The option is set
#       anyway and is INERT today -- it is not a fix that has been measured,
#       it is a trap disarmed ahead of the lane that mounts the class.
set_source_files_properties(
    # --- live: matched, linked, and a `jmp 0` in the binary until this line ---
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_kp_fr.cpp"
    # --- reclaimed from host copies by slice_w18a.txt (see that file) ---
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov072_02121cdc.cpp"  # BabyPenguin tick, ov072 +0x35c
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/Scuttlebug.cpp"  # Scuttlebug main, ov071 +0x380
    # and the generated copy, lane CRASH6: this TU is on PORT_HOSTGEN_TU now,
    # so the raw path alone would set the option on a source nothing compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/Scuttlebug.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov071_021215c0.cpp"  # MrI main,        ov071 +0x1e4
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov080_021250c8.cpp"  # Bbh tick,        ov080 +0x36c
    # --- inert today: no host copy, no reference, /OPT:REF strips them ---
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daBombking_c.cpp"   # KingBobOmb, ov078 +0x420
    # and the generated copy, lane DUPES: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set the property on a source
    # nothing compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/daBombking_c.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10MrBlizzard8BehaviorEv.cpp"   # MrBlizzard, ov081 +0x3f8
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11ChiefChilly8BehaviorEv.cpp"  # ChiefChilly, ov073 +0x37c
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_pg_mthr.cpp"  # ov018 +0x370
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov019_02112268.cpp"  # ov019 +0x370
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daPgDfdr_c.cpp"  # ov027 +0x3cc
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daMky_c.cpp"  # ov030 +0x3a4
    # and the generated copy, lane HOSTGEN4: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set the option on a source nothing
    # compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/daMky_c.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daBgSnmBdy_c.cpp"  # ov072 +0x38c
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11SnowmanHead17CallStateBehaviorEv.cpp"  # ov072 +0x328
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov077_02124718.cpp"  # ov077 +0x3f0
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov077_02125e20.cpp"  # ov077 +0x3d0
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daGmch_c.cpp"  # ov081 +0x3dc
    # and the generated copy, lane SEATS3: this TU is on PORT_HOSTGEN_TU now,
    # so the raw path alone would set the option on a source nothing compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/daGmch_c.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13PrincessPeach17CallStateBehaviorEv.cpp"  # ov085 +0x350
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daSanbo_c.cpp"  # ov096 +0x384
    # and the generated copy, lane HOSTGEN4: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set the option on a source nothing
    # compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/daSanbo_c.cpp"
    PROPERTIES COMPILE_OPTIONS "/vmg;/vmm")

# run linkw wave 18 (lane w18): the four matched dispatchers reclaimed from
# host copies by the R9 sweep above. Their four host bodies are deleted in the
# same commit -- BabyPenguin_StateTick.cpp entirely (the whole file was that
# one body), and one function each out of Scuttlebug_StateDispatch.cpp,
# MrI_StateDispatch.cpp and Bbh_PmfDispatch.c, whose remaining bodies and table
# seats are untouched and still needed. Same one-owner contract as the lane
# slices above: a symbol is defined by the matched TU or by a host copy, never
# both.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w18a.txt" SLICE_W18A_LINES)
set(SLICE_W18A_SOURCES "")
foreach(line IN LISTS SLICE_W18A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W18A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# R9b, run link100 lane PMF2: THE REST OF THE FREE POINTER-TO-MEMBER SET.
# R8 above turned /vmg /vmm on for the whole target, which makes MSVC's
# pointer-to-member the ROM's own 8-byte {function, delta} pair. Wave 18 and
# lane PMF took six TUs off the back of that; this slice takes the twenty-eight
# more whose object form was MEASURED under the port's own flags and whose
# {function, delta} tables are proven delta-zero on every boot by the seat
# that fills them. The reading, the listings and the per-row evidence are in
# port/slice_pmf2.txt; the twenty-eight host bodies they replace come out in
# the same commit, eight of them as whole files.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pmf2.txt" SLICE_PMF2_LINES)
set(SLICE_PMF2_SOURCES "")
foreach(line IN LISTS SLICE_PMF2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PMF2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# R9c, run link100 lane PMF3: THE LEFTOVERS R9b NAMED.
# PMF2 left three families behind. This slice takes the rows whose adjustment
# word is now proven TWICE -- by the seat that fills the table aborting on any
# nonzero delta (or, for the crate, writing the word to zero as it seats), and
# by a fresh static re-read of the ROM's own {code, adjust} pairs out of the
# raw overlay images with their relocations, eighty-two pairs and every adjust
# word zero. The reading, the refusals and the per-row evidence are in
# port/slice_pmf3.txt; the listing is runs/link100/out/PMF3/deltas_static.txt.
# The host bodies these replace come out in the same commit, two as whole
# files (unmatched/Ov085_PrincessPeach_States.cpp and
# unmatched/RabbitKey_StateSeat.cpp).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pmf3.txt" SLICE_PMF3_LINES)
set(SLICE_PMF3_SOURCES "")
foreach(line IN LISTS SLICE_PMF3_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PMF3_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# R9d, run link100 lane PMFB1: THE THIRTEEN FREE ROWS OF THE POINTER-TO-MEMBER
# FAMILY, AND THE RECORD-STRIDE DEFECT THAT HAD TO BE FIXED FIRST.
# Lane PMFC2 measured all 153 rows of the family and named these thirteen FREE:
# each is a tail jump, each reads a table whose adjustment words are proven zero
# and whose function words a seat rewrites with HOST addresses before the class
# can spawn. That reading is right. What it did not read is the record STRIDE.
# Its width pass recorded the SCALE of the indexed operand and never the LEA
# that feeds it, so it reported "index stride 8" for an object that strides
#     lea eax, DWORD PTR [eax+eax*2]   /   ...@@3PAUEntry@@A[eax*8]
# which is 24 bytes per entry. All thirteen ROM bodies were disassembled at
# their own addresses out of extracted/overlays/ for this lane: ELEVEN of them
# stride TWENTY (mov r1, #0x14 / mla r3, r2, r1, r3) and only the two ov063 rows
# stride sixteen. Index 0 is right either way and every other state would have
# read the wrong record -- quietly, because every one of these state machines
# starts in state 0.
# WHY MSVC SIZES A 20-BYTE RECORD AT 24, probed under the port own flags:
# sizeof(PMF) is 8 and __alignof(PMF) is 4 -- the ROM {function, delta} pair,
# which is what /vmg /vmm bought in block R8 -- but MSVC gives any CLASS THAT
# CONTAINS a pointer-to-member an alignment of EIGHT, and that rounds the
# 20-byte record up to 24. The ROM record is 20 and is not 8-aligned at all.
# THE FIX IS A COMPILE OPTION ON THE THIRTEEN AND NOTHING ELSE. /Zp4 caps the
# default structure packing at four, which is the alignment every field in
# these records actually has. It is the same lever block R8 already uses on
# this exact family, one step further: no source edit, no ROM data touched, no
# reference the ROM does not make. Measured before and after on all thirteen
# (runs/link100/out/PMFB1/zp4_stride_table.txt): every emitted stride becomes
# exactly the stride the ROM uses, every row stays a TAIL JUMP, every mangled
# EXTRN is unchanged and the receiver still gets this + delta. Each TU holds
# only the record and struct C { char pad[N]; int idx; }, whose fields are all
# four-byte, so /Zp4 touches nothing else; the two ov063 rows are 16 either way
# and are kept on the option so the set reads as one.
# The reading, the per-row evidence and the retire plan are in
# port/slice_pmfc.txt; the seven table-name aliases the slice needs to link at
# all are port/hal/pmfc_aliases.cpp. The thirteen host bodies they replace come
# out in the same commit, three of them as whole files
# (unmatched/Ov085_Toad_StateSeat.cpp, unmatched/Wiggler_StateEnter.cpp and
# unmatched/Wiggler_StateTick.cpp).
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov002_020b9704.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov002_020b9750.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov002_020efa54.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_wanwan.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_wanwan.cpp"
    # and the generated copy TWICE, lane HOSTGEN4: this TU is on
    # PORT_HOSTGEN_TU now, the raw rows above are a pre-existing duplicate,
    # and the configure-time check counts spellings rather than sources.
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_wanwan.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_wanwan.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov034_021125b8.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov034_02112604.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/unnamed/ov063/func_ov063_0211ddac.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/unnamed/ov063/func_ov063_0211ddf4.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov071_021223c8.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov071_02122414.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN4Toad8SetStateEi.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN4Toad8RunStateEv.cpp"
    PROPERTIES COMPILE_OPTIONS "/Zp4")
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pmfc.txt" SLICE_PMFC_LINES)
set(SLICE_PMFC_SOURCES "")
foreach(line IN LISTS SLICE_PMFC_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PMFC_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w15c.txt" SLICE_W15C_LINES)
set(SLICE_W15C_SOURCES "")
foreach(line IN LISTS SLICE_W15C_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W15C_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate21.txt" SLICE21_LINES)
set(SLICE21_SOURCES "")
foreach(line IN LISTS SLICE21_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE21_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate22.txt" SLICE22_LINES)
set(SLICE22_SOURCES "")
foreach(line IN LISTS SLICE22_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE22_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate23.txt" SLICE23_LINES)
set(SLICE23_SOURCES "")
foreach(line IN LISTS SLICE23_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE23_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 25: the bottom screen. The OAM lifecycle, Stage::LoadGraphics2D's
# closure and Stage::CheckCameraInput; see slice_gate25.txt. OAM::Load is not
# here -- it reads POWCNT textually and comes from GATE6_GEN, which this
# target picks up alongside the slice. (Renumbered from 24 at merge: the
# animation stream took 24 for BlendModelAnim the same night.)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate25.txt" SLICE25_LINES)
set(SLICE25_SOURCES "")
foreach(line IN LISTS SLICE25_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE25_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 26: the boot spine -- the real Stage actor. See the header of
# slice_gate26.txt; the HAL seam is hal/stage_bridges.cpp. (Renumbered from
# 24 at merge: three streams picked 24 the same night.)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate26.txt" SLICE26_LINES)
set(SLICE26_SOURCES "")
foreach(line IN LISTS SLICE26_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE26_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 27: the HUD actor (id 334). Its methods are all matched; what it needed
# was gate 25's sub-OAM path, a registry row, and the ov001 sprite templates.
# InitResources is the matched TU through hostgen (GATE27_GEN below) -- see the
# head of slice_gate27.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate27.txt" SLICE27_LINES)
set(SLICE27_SOURCES "")
foreach(line IN LISTS SLICE27_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE27_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# Lane HUD-INITRES: HUD::InitResources is src/_ZN3HUD13InitResourcesEv.cpp,
# retiring port/unmatched/HUD_InitResources.cpp (the matched body with
# `extern` on its globals and its loader calls hand-rerouted). --extern-data
# turns the TU's ten file-scope engine globals into declarations (seven
# collide with storage the port owns, the save block hal/level_boot.cpp holds
# as a grouped-section run among them); hostgen's CALLEE_SEAM routes
# LoadFile / DecompressLZ16 / LoadOBJPltt to hal/hud_load.cpp, the raw loader
# (the ROM's still-compressed contract, so DecompressLZ16 decodes once) with
# the null path for the handles this extraction does not carry. The
# `u8 GetHealth()` shadow declaration is bridged by name in the same file.
# See status/HUDINITRES.md.
set(GATE27_SYMS _ZN3HUD13InitResourcesEv)
set(GATE27_GEN "")
foreach(sym IN LISTS GATE27_SYMS)
    set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" --extern-data ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE27_GEN "${sym_out}")
endforeach()
list(APPEND SLICE27_SOURCES ${GATE27_GEN}
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/hud_load.cpp")

# Gate 28: the MINIMAP actor (id 335). Same shape as the HUD -- eighteen-slot
# vtable, constructor as factory -- plus the BG3-sub tilemap and the extended
# palette. See the head of slice_gate28.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate28.txt" SLICE28_LINES)
set(SLICE28_SOURCES "")
foreach(line IN LISTS SLICE28_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE28_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# Minimap::Behavior and Minimap::Render are host-copied for the sixteen-player
# minimap: the ROM's four-entry per-player tables are indexed by player number,
# which a console on slot 8..15 walks off the end (a c0000005 in Render). src/
# is byte-frozen; the two host copies keep the storage sixteen wide (see
# port/unmatched/Minimap_wide.h) and are linked in place of the excluded src
# TUs (commented out in slice_gate28.txt). Every target that hosts SLICE28
# picks them up here, so no add_executable line changes.
list(APPEND SLICE28_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Minimap_Behavior.cpp")
list(APPEND SLICE28_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Minimap_Render.cpp")

# Gate 29: the particle subsystem -- the last subsystem the boot reported as
# stubbed. 101 matched files (the other 18 in its closure already ride on
# gates 10/13/16) plus hal/particle_vtable.cpp for the thirteen Callback
# vtables the tracker's constructor installed when this gate was written. See
# the head of slice_gate29.txt for what the dispatch turned out to be, and for
# why those tables are dead now that the callback classes are real C++ classes
# whose matched constructors install MSVC's own.
#
# THIS GATE GOES THROUGH HOSTGEN, unlike most slices, and it has to. Ten of
# its files reach the geometry engine through raw 0x04xxxxxx literals -- the
# particle render family (func_0204af3c, b028, b244, b460, b81c, bbd8, be40,
# c194, c24c) and func_02049ee8, which is what Particle::RenderAll calls.
# Compiled raw, every one of those writes would latch into dead mapped memory
# and the geometry engine would never see a particle: the same failure
# hostgen.py's own header describes for MTX_SCALE. hostgen also carries the
# HEADER_SHADOW entry the tracker's Initialise needs -- decl_Particle.h
# declares it (void*) with C++ linkage and the TU defines it extern "C" over
# a struct, which MSVC rejects as an overload on C linkage (C2733).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate29.txt" SLICE29_LINES)
set(GATE29_GEN "")
foreach(line IN LISTS SLICE29_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    get_filename_component(sym "${line}" NAME_WE)
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../${line}"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE29_GEN "${sym_out}")
endforeach()

# Gate 33: Bob-omb Battlefield's mechanisms, terrain objects and pickups --
# the classes of level 6 (ov014) that are not living creatures. The roster and
# the evidence behind every actor id are in the head of slice_gate33.txt; the
# vtable fills and the debug spawn hook are hal/actor_classes_bob_world.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate33.txt" SLICE33_LINES)
set(SLICE33_SOURCES "")
foreach(line IN LISTS SLICE33_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # Lane CAPSHOW: WaterfallMist::Behavior is substituted by
    # port/unmatched/WaterfallMist_Behavior_HostSites.cpp -- its shadow
    # `v03()` on the cap's ModelAnim is the ROM's +0x0c UpdateVerts, and the
    # port's MSVC-numbered _ZTV9ModelAnim puts Virtual10(Matrix4x3 &) there,
    # whose `ret 4` unbalances the frameless caller (measured: c0000005 on
    # the frame after a VS cap is collected). Skipped HERE so
    # slice_gate33.txt stays another lane's file, the VS_PathDivGuard shape.
    #
    # INERT SINCE run link100 lane HOSTGEN4, and left standing as the record.
    # The TU is on PORT_HOSTGEN_TU now, so port_read_lines has already
    # rewritten this row to the generated copy by the time the compare runs
    # and the skip cannot fire. That is the intended end state: the generated
    # copy carries CAPSHOW's correction, so there is nothing left to skip,
    # and the host copy it used to make room for is retired. The skip stays
    # because the substitution can be retired and this row would be needed
    # again the same day.
    if(line STREQUAL "src/actors/daObjMarioCap_c.cpp")
        continue()
    endif()
    list(APPEND SLICE33_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE33_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/WaterfallMist_Behavior_HostSites.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Coin_Behavior.cpp")
# unmatched/Coin_CollectDispatch.cpp and unmatched/StarMarker_SpawnDispatch.cpp
# RETIRED (run linkfull, lane RS4PORT): main #3106 passes the found player and
# the found StarMarker their ROM registers carried, so src/func_ov002_020b19dc.c
# and src/func_ov002_020b10a0.c (main's blobs) are back on slice_gate33.txt.

# Gate 32: Bob-omb Battlefield's living cast -- the first ENEMY-family actor
# classes the port hosts, and the first vtables past twenty slots. See the head
# of slice_gate32.txt; the HAL seam is hal/actor_classes_bob_enemy.cpp and the
# direct-spawn probe that brings them up before their own level exists is
# hal/actor_spawn_probe_bob.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate32.txt" SLICE32_LINES)
set(SLICE32_SOURCES "")
foreach(line IN LISTS SLICE32_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE32_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# argfix: func_ov078_02123f1c (King Bob-omb) calls Player::GetHealth() with no
# argument and relies on the held Player (c->field_494) riding ARM r0. Host copy
# passes it. Src line commented out in slice_gate32.txt.
list(APPEND SLICE32_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/KingBobOmb_HeldHealthCheck.cpp")

# Gate 31: the level HANDOFF. Small on purpose -- almost all of it was already
# linked by gate 10 (see the head of slice_gate31.txt); what is here is
# StartFile's own closure, the Player's destroy slots and the collider
# registry reset. The driver is hal/level_change.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate31.txt" SLICE31_LINES)
set(SLICE31_SOURCES "")
foreach(line IN LISTS SLICE31_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE31_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE31_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Player_CleanupResources.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/func_02073244_hostcopy.c")
# unmatched/SetNumPlayers_hostcopy.c RETIRED (run linkfull, lane RS2PORT):
# src/SetNumPlayers.c passes func_020308d0 the count (main 59013376ce) and is
# back on port/slice_gate31.txt.
# unmatched/Door_CleanupResources.cpp RETIRED (run link100, lane UNMATCH):
# its `obj->v1()` workaround was the MSVC destructor fold, and
# hal/model_dtor_seat.cpp seats the ROM's deleting half at slot 1 of all
# three model-family tables now. src/_ZN4Door16CleanupResourcesEv.cpp carries it,
# in port/slice_unmatch.txt.

# ---- the NEW-FILE OPENING (run lvled, lane intro-cutscene) ------------------
# Everything the ROM's own intro gate reaches once it is allowed to fire. All of
# it was already MATCHED and simply never offered, because with the intro bit
# force-set in hal/level_boot.cpp none of it was reachable. See slice_intro.txt
# for what each group is and the fault that named it.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_intro.txt" SLICEINTRO_LINES)
set(SLICEINTRO_SOURCES "")
foreach(line IN LISTS SLICEINTRO_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICEINTRO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# The kuppa command dispatcher is a HOST COPY (the gate-16 pointer-to-member
# case; its src line is commented out in slice_gate10.txt), and CUTSCENE_OBJECT
# gets its own class file rather than an append to actor_classes.cpp.
list(APPEND SLICEINTRO_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/intro_kuppa_dispatch.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_intro.cpp")
# unmatched/Ov085_LakituBro_IntroEnd.cpp RETIRED (run linkfull, lane RS4PORT):
# src/func_ov085_0212d5dc.cpp passes func_ov002_020c3e8c the player (main
# #3106's hunk) and is back on slice_gate18.txt.
# void* arithmetic: func_ov002_020f7780 (cutscene-object command slot 2) adds
# 0x8e to a void*, which mwcc takes as the GNU extension and MSVC C refuses with
# C2036. One cast, same address; src line commented out in slice_intro.txt.
list(APPEND SLICEINTRO_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Ov002_CutsceneCmd_020f7780.c")
# The opening's 55 script ARGUMENT RECORDS, hosted with real host pointers the
# way ptr_tables.cpp table 2 hosts the 39 camera-script records. They are NOT in
# romdata.py's byte-copy list on purpose: each carries a relocated word at +4,
# and a byte-copied pointer is the data_020876e4 crash.
list(APPEND SLICEINTRO_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/intro_script_records.cpp")
# data_02089dcc is hosted rather than byte-copied because port/tools/ptr_audit.py
# flagged it and was right: its single relocation points at CODE
# (func_ov007_020c020c, unhosted, and ov007 is outside this lane's grant). The
# blob is carried with that one word seated to a loud trap; the opening never
# reaches it. Removed from romdata.py's list in the same change.
list(APPEND SLICEINTRO_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/intro_dcc_blob.cpp")
# The ov002 mount's POINTER WORDS, seated with host addresses. The mount
# byte-copies, so the pointer arrays this lane added to port/ov002_syms.txt
# carried DS addresses -- one of them handed SharedFilePtr::Load 0x02130744.
# Generated and individually checked against relocs.txt; see the file header.
list(APPEND SLICEINTRO_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/intro_ov002_seat.cpp")
# unmatched/Ov002_CutsceneLoad_020f6618.cpp RETIRED (run linkfull, lane
# RS4PORT): the matched cast LOAD SPINE is back on slice_intro.txt; the flat
# ModelBase::SetFile bridge returns the int it tests (hal/cxxname_bridge.cpp).
# Its per-object LoadFile trace (SM64DS_INTRO_WATCH) goes with it.
# unmatched/CutsceneObject_Render.cpp RETIRED (run link100, lane UNMATCH).
# It existed because CutsceneObject::Render dispatches its model through a
# LOCAL SHADOW counted in ROM numbering, and the folded host table put
# ModelAnim::Virtual18 on the slot the source means for Render. Lane SLOT5F's
# unfold ROM-numbers the table and gave this file's shadow its sixth virtual,
# which left it a line-for-line copy of the matched source plus a render trace.
# src/_ZN14CutsceneObject6RenderEv.cpp carries it now, in port/slice_unmatch.txt;
# co_render's port_actor_render_probe call is the trace that stays.
# unmatched/CutsceneObject_CleanupResources.cpp RETIRED (run link100, lane
# UNMATCH), the same one-slot shift one file over. Its `m04` is ROM index 1,
# the DELETING destructor, and with the fold gone that is what index 1 on both
# cutscene model tables holds. src/_ZN14CutsceneObject16CleanupResourcesEv.cpp
# carries it now, in port/slice_unmatch.txt.
# And the third instance, one layer down: the cutscene ModelAnim's own deleting
# destructor destroys its TextureSequence through a hand-indexed vtable word at
# ROM slot 1. MSVC folds D1/D0, so hal/model_dtor_seat.cpp seats that body at
# index 0 and leaves index 1 NULL -- measured as a call through a null pointer
# (+ffc00000 is address 0 against this image's 0x00400000 base). The calling
# convention moves with the index: what is seated there is __fastcall.
# unmatched/Ov002_ModelAnimD0_020f6778.cpp RETIRED (run link100, lane EXCEPT).
# Index 1 is not null any more: hal/model_dtor_seat.cpp seats the ROM's own
# word for that slot, _ZN15TextureSequenceD0Ev, behind a CDECL thunk -- which
# is the convention the readers of that word actually use, `typedef void
# (*VFN)(void*)`. Nothing MSVC generates ever indexes 1 (the class has one
# virtual destructor, so MSVC's own table has one slot), so index 0 keeps its
# __fastcall thunk untouched. src/_ZN8daDemo_c10anmModel_cD0Ev.cpp carries the body now,
# on port/slice_except.txt.
# Cutscene-object command 4, the character voice. The matched TU declares its
# callee inside `namespace Sound`, which MSVC mangles YA as
# ?PlayCharVoice@Sound@@YAXIIABUVector3@@@Z while the one real definition carries
# the Itanium C name (Sound::PlayCharVoice is in this binary already,
# slice_gate10.txt:1225). WIRED as a faithful seam: hal/cxx_aliases.cpp now
# carries the /alternatename for that mangling, so the matched TU links behind
# it; the Ov002_KuppaCmd_020bd480.cpp host copy is retired.
list(APPEND SLICEINTRO_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov002_020bd480.cpp")
# And command 9, the knockback. The matched TU reaches Player::Hurt through a
# local shadow CLASS, so MSVC mangles it thiscall (?Hurt@Player@@QAEX..., `this`
# in ecx) while the real body carries the Itanium C name with self on the stack.
# WIRED as a faithful seam: hal/reverse_bridges.cpp now carries the Player::Hurt
# receiver face (Particle::System::NewSimple's static mangle already had its
# alias in cxx_aliases.cpp), so the matched TU links behind it; the
# Ov002_KuppaCmd_020bd250.cpp host copy is retired.
list(APPEND SLICEINTRO_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov002_020bd250.cpp")

# ---- link100 TAIL2 ----
# GATE 219: CUTSCENE_OBJECT's ten pointer-to-member STATE tables (49 body
# TUs). port/slice_gate219.txt carries the list and the derivation of each;
# hal/cutscene_states_link100.cpp is the ten address switches, generated from
# the ROM by port/tools/tail2_gen_states.py and NOT hand-edited.
#
# The three trap-filled arm9 FADER tables this gate originally also seated
# (data_0208eacc/eb2c/eafc, six matched TUs) came back OUT during finisher
# review: seating them exposed a caller/callee calling-convention hazard
# fdr_arm9_fader_seat.cpp already documents by name (the "GARBAGE-RECEIVER
# HAZARD," ~line 220 there) for the three cdecl-shape sites that reach
# data_0208ea6c. That hazard was proven benign there ONLY because MSVC happens
# to leave the receiver in ECX at those three specific call sites -- "a
# property of what MSVC happened to emit... not a guarantee" (same file). No
# equivalent audit exists for the sites that reach an installed fader through
# eacc/eb2c/eafc once func_02017278 or Scene::SetFaders install one (the
# pointers are data_0209f5bc / data_0209d4ac): src/func_ov002_020f23f0.c's
# `((int(**)(void*))*(void**)o)[5](o)` (CutsceneObject::Behavior's kind-0x2f
# branch calls it directly) is one such site and is NOT one of the three
# audited for data_0208ea6c; fdr_arm9_fader_seat.cpp's own comment names a
# second, "Minimap::Behavior's vt->f[5]" -- Minimap is spawned in every level,
# so that site alone would explain reaching the hazard with CUTSCENE_OBJECT's
# class skipped, which is what SM64DS_SKIP_CLASS=CUTSCENE_OBJECT measured (the
# crash persisted). Neither site's callee register allocation happens to
# leave the receiver in ECX the way the three audited data_0208ea6c sites do.
# Seating a real __fastcall body onto data_0208eacc/eb2c's slot 5 turns either
# into a garbage-receiver call, and
# FaderBrightness::IsAtStart()'s `currInterp == 0` read faults on the garbage
# pointer -- reproduced with SM64DS_TEST_LOCK's opening-cutscene proof
# (SKIP_MENU, new-file, 4000 frames): clean on this tree with the three tables
# left trapped, c0000005 inside func_ov002_020f23f0 with them seated, every
# time. Bisected by reverting exactly this fill (nothing else in the gate) and
# rerunning the same proof. Re-seating these three tables needs the same kind
# of dispatch-site audit port/fader_boot_map.txt section 9c did for
# data_0208ea6c, extended to data_0209f5bc / data_0209d4ac's OTHER readers --
# out of scope for this finisher pass. hal/scene_boot.cpp is back to its
# pre-TAIL2 state (full trap on all three tables); config/arm9/relocs.txt's
# six words were real and still are, they are just not seated.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate219.txt" SLICE219_LINES)
set(SLICE219_SOURCES "")
foreach(line IN LISTS SLICE219_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE219_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE219_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/cutscene_states_link100.cpp")

# THE SCENE BOOT: the star select, the one non-level scene the port can enter.
# ov003 carries three scene classes -- dScTitle_c (id 2), dScStarSel_c (id 4)
# and dScGameOver_c (id 8) -- and ONLY id 4 is seated; the other two are
# derived to the same depth and blocked, which slice_scene1.txt spells out. It
# is reached through the ROM's own Scene::SetSceneToSpawn ->
# Scene::SpawnIfNecessary -> func_02043098 spawn spine. hal/scene_boot.cpp
# seats that one ACTOR_SPAWN_TABLE record and fills its vtable; port_scene_run
# drives the frame. SM64DS_SCENE=<id> in walk_window takes the run, and an
# unhosted id is refused by name. Eighteen of the sixty src TUs this slice
# lists are /OPT:REF-dropped on purpose; see slice_scene1.txt for why every TU
# here links off the ROM's own edges rather than a link root, and
# scene_boot_map.txt section 8 for which eighteen do not link at all.
# Run link100, lane CARDFS: the card mount. The ROM's own LoadArchive, on the
# ROM's own mount table, answering for the honest reason.
#
# hal/scene_boot.cpp carried a face for LoadArchive from run link60 until now,
# under a banner that called the alternative "a fake, not a fix". The banner's
# own middle paragraph is what retired it: the ROM's call asks whether archive
# N is resident, and on the host every archive is, because hal/fs.cpp reads
# each NARC whole on first use and never releases it (1,035,956 bytes for all
# thirteen, measured). hal/card_mount.cpp hosts data_0208ecf4 at its ROM span
# inside .dsstate, hal/fs.cpp publishes the image it is already holding into
# each entry, and the matched TU reads the word.
#
# WHY THESE FOUR AND ONLY THESE FOUR. src/LoadArchive.c is reached by nine
# live callers (LoadTextNarcs, Stage::InitResources, func_02034fbc,
# _ZN12dScStarSel_c13InitResourcesEv, _ZN11dScMiniGm_c13InitResourcesEv, _ZN9dScDSMT_c8BehaviorEv and three
# ov075 minigame bodies), all of which called the face yesterday. It calls
# func_02018934, which calls func_02018d98 and Heap::_Allocate's tail-call
# veneer. Four more matched TUs -- func_0204ee40, func_0204ef9c, func_0205cbe4
# and func_0205d518 -- are already on slice_scene1.txt and were /OPT:REF-
# dropped because nothing on the link line called them; func_02018934 does, so
# they stop being dropped without being listed twice.
#
# WHAT IS NOT HERE. LoadFile and func_0201818c are the other half of the seam
# GATES measured and they are NOT takeable from this lane: hal/level_boot.cpp
# defines LoadFile as a PORT_HOST_ABI face and that file belongs to another
# lane. func_020185c0, func_020186c0, func_02018598, func_0204eda4 and
# func_0204ede8 hang off func_0201818c and would be dropped again if listed,
# so they are not. The mount table they read is already the right shape for
# them (hal/card_mount.cpp publishes the +0x50/+0x54/+0x58 words
# src/func_0204ee40.c writes), which is the whole of what this lane can do for
# that half.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_cardfs.txt" SLICE_CARDFS_LINES)
set(SLICE_CARDFS_SOURCES "")
foreach(line IN LISTS SLICE_CARDFS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_CARDFS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_CARDFS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/hal/card_mount.cpp")

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_scene1.txt" SLICE_SCENE1_LINES)
set(SLICE_SCENE1_SOURCES "")
foreach(line IN LISTS SLICE_SCENE1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SCENE1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run link60 lane L2: THE SECOND SCENE, and the biggest single linkage move the
# port has made. dScDSMT_c is ov007's one scene class -- the TITLE SCREEN and
# FILE SELECT, actor id 1 -- and it rides the identical spine: the ROM's
# ACTOR_SPAWN_TABLE record at 0x02103264 (hosted by the ov007 mount), the
# eighteen-slot _ZTV8dScene_c shape at 0x021032e8 filled in place, and
# Scene::SetSceneToSpawn -> Scene::SpawnIfNecessary. SM64DS_SCENE=1 takes it.
#
# 619 src TUs, which is not a slice of ov007 but very nearly the whole overlay:
# a relocation BFS from the class's eight entry points reaches all 548 of its
# functions, so the title screen is what ov007 is for. See slice_ov007.txt for
# the derivation and the one exclusion, and port/ov007_seat.txt for the vtable
# table, the two spine-caveat audits and what actually links.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov007.txt" SLICE_OV007_LINES)
set(SLICE_OV007_SOURCES "")
# TWO FLAGS AND NOT ONE, because the review caught them being conflated. A
# single "displaced" flag answers "did the cut run", and the marker block below
# needs "is the matched body in this binary", which is NOT the same question:
# both a cut line and a MISSING line leave the TU out of the build, and only
# one of those is a healthy tree. Read separately, every message below can be
# scoped to the state it actually names.
set(RT1_BE980_IN_SLICE FALSE)      # the slice file lists the line
set(RT1_BE980_DISPLACED FALSE)     # and this block cut it, so a host copy runs
set(RT1_ADD3C_IN_SLICE FALSE)
set(AE1_ADD3C_DISPLACED FALSE)     # run link60 lane AE1, the same pair one
                                   # frame deeper: listed, and cut
set(AE1_BBFF0_COMPILED FALSE)      # and the NEXT blocker's caller: compiled,
                                   # set where the append happens, not where
                                   # the line is read
set(TS1_B6EB4_IN_SLICE FALSE)      # run link60 Stage 5 lane TS1, the third
set(TS1_B6EB4_DISPLACED FALSE)     # displacement: listed, and cut
set(IR1_C2B9C_IN_SLICE TRUE)       # mg16 arc 4: the matched TU is back in the
                                   # slice as itself, so the VOID_DEF guard far
                                   # below can still fire if anyone reintroduces
                                   # the `void` spelling. Left TRUE deliberately:
                                   # with it FALSE the guard is silently dead.      # run mg15 lane IMPLICITR, the fourth
set(IR1_C2B9C_DISPLACED FALSE)     # displacement and the first on the RETURN
                                   # side: listed, and cut
set(TIDEP_B4B5C_DISPLACED FALSE)   # run mg15 lane TITLEDEPTH, the fourth
# DECLARED HERE AND NOT BESIDE ITS SIBLING SWITCH, because the loop below reads
# it and CMake evaluates this file top to bottom. Declared further down it would
# still work from the command line -- -D writes the cache before this file runs
# -- and its DEFAULT would be an empty variable up here, which is the shape of a
# switch that is right for the wrong reason.
option(TIDEP_ARITY_PLAIN
       "run mg15 TITLEDEPTH: keep src/func_ov007_020b4b5c.c in the port slice, \
so the title's cell sizer is called without its camera (pre-fix arm)"
       OFF)
foreach(line IN LISTS SLICE_OV007_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # run link60 lane RT1: THE ONE DISPLACEMENT IN THIS SLICE.
    #
    # func_ov007_020be980 is MATCHED and stays matched. It is cut from the port
    # only, because it is the frame where scene 1's ARM register ride-through
    # destroys information: its caller sets r1 and r2, its callee reads them,
    # and this body -- correctly, on ARM -- names neither. On MSVC that is two
    # stack slots nobody wrote. The seat's shape was ruled by the PC2 review
    # before it was taken; the derivation, the caller sweep that fixes the
    # signature, and why the other two frames are the wrong ones to displace
    # are all in port/unmatched/Ov007_RideThrough_020be980.cpp's header and
    # port/ov007_seat.txt sections 5b and 5c.
    #
    # THE FLAGS ARE NOT BOOKKEEPING. The PC2 marker block below reads them, so
    # the cut and the marker's retirement are the same fact and cannot drift:
    # delete this if-block to put the TU back and the marker re-arms in that
    # configure, unasked, because the same edit that restores the body clears
    # the flag that retires the marker.
    # RETIRED, run link100 wave 15, lane SEAT15E. THE DISPLACEMENT IS GONE AND
    # THE MATCHED TU IS BACK: src/func_ov007_020be980.c today is
    #     void func_ov007_020be980(char *r0, int i, int a2)
    #     { func_ov007_020bc3dc(*(void**)(r0+4), i, a2); ... }
    # -- three parameters declared, three passed, into a callee
    # src/func_ov007_020bc3dc.c defines as (void *, int, int). Nothing rides r1
    # or r2 through a frame that does not name them any more, so the reason this
    # block cut the line is measurably gone. The four arm_call rows landing on
    # 0x020be980 in config/arm9/overlays/ov007/relocs.txt all pass three
    # arguments, so the arity the source now spells is the ROM's own.
    #
    # THE FLAG STAYS AND THE `continue()` GOES, which is the whole edit. The PC2
    # marker block below reads RT1_BE980_IN_SLICE and RT1_BE980_DISPLACED as a
    # pair, and its three-way message only tells the truth while the "is the
    # line in the slice" half keeps saying yes. Dropping the flag with the cut
    # would print "not in the slice at all ... the link fails before scene 1 can
    # be judged" over a tree where the seam is seated and scene 1 runs.
    if(line MATCHES "^src/func_ov007_020be980\\.c$")
        set(RT1_BE980_IN_SLICE TRUE)
    endif()
    # run link60 lane AE1: THE SECOND DISPLACEMENT IN THIS SLICE, and the
    # OPPOSITE FRAME from the one above.
    #
    # func_ov007_020add3c is MATCHED and stays matched. It is cut from the port
    # only, because it is the frame where scene 1's implicit r0 argument is
    # destroyed: the value is add3c's OWN incoming argument, its callee
    # func_ov007_020ae558 reads r0 directly, and on ARM the caller's
    # `mov r4, r0` leaves r0 holding it at the branch so there is nothing to
    # emit. On MSVC the caller pushes zero arguments and the callee reads its
    # saved esi. The seat's shape was ruled by the RT1 and SC1N reviews before
    # it was taken; the derivation, the one-call-site sweep and why the callee
    # is the wrong frame to displace are in
    # port/unmatched/Ov007_ImplicitR0_020add3c.cpp's header and
    # port/ov007_seat.txt sections 5c, 5d and 5e.
    #
    # THE FLAG IS NOT BOOKKEEPING, same as the be980 block above: the RT1
    # marker block below reads it, so the cut and the marker's retirement are
    # the same fact and cannot drift.
    #
    # WHAT THE COMMENT THAT STOOD HERE ASKED FOR WAS ONE FLAG SHORT, and it is
    # worth recording rather than quietly fixing. It said a lane seating this
    # seam "adds a `continue()` here and the marker retires in the same
    # configure". A bare `continue()` leaves RT1_ADD3C_IN_SLICE set TRUE, so
    # the predicate below would have gone on arming a marker for a blocker that
    # no longer shipped -- the exact failure RT1 caught in PC2's predicate,
    # arriving a third time. The cut therefore sets its own DISPLACED flag and
    # the predicate reads both, which is the shape the be980 block already had.
    # RETIRED, run link100 wave 15, lane SEAT15E. THE DISPLACEMENT IS GONE AND
    # THE MATCHED TU IS BACK: src/func_ov007_020add3c.c opens
    #     extern int func_ov007_020ae558(char *self);
    # and calls it `int r = func_ov007_020ae558(c);` on its own incoming
    # argument, and src/func_ov007_020ae558.c defines
    # `int func_ov007_020ae558(char *self)` with that one parameter. The value
    # this frame used to destroy is passed now, so there is nothing left for a
    # stack ABI to lose and nothing for the host copy to spell out. The rest of
    # the host body was the same source's statement list line for line.
    #
    # THE FLAG STAYS AND THE `continue()` GOES, for the reason the be980 block
    # above gives: the RT1 marker block below reads RT1_ADD3C_IN_SLICE and
    # AE1_ADD3C_DISPLACED as a pair, and only the pair tells "the seam is
    # seated" apart from "the TU vanished and the link is about to fail". The
    # marker retires by its own predicate in the same configure, because the
    # `(void)` declaration of func_ov007_020ae558 it greps for is gone.
    #
    # port/tools/tailjump_guard.py's Class A row 1 comes back off RETIRED in
    # this build, because its `tu` (src/func_ov007_020add3c.c) is now what the
    # build really compiles. The row requires this frame to emit a REAL CALL
    # and forbids a tail jump; the seated body is twenty statements, so the
    # required form is what MSVC has to emit.
    if(line MATCHES "^src/func_ov007_020add3c\\.c$")
        set(RT1_ADD3C_IN_SLICE TRUE)
    endif()
    # run link60 Stage 5 lane TS1: THE THIRD DISPLACEMENT IN THIS SLICE, and
    # the same frame shape as the two above.
    #
    # func_ov007_020b6eb4 is MATCHED and stays matched. It is cut from the port
    # only, because it is the frame where the title screen's PENDING GRAPHICS
    # MODE is destroyed: the body's own guard loads *(int *)(g + 0x1c) to test
    # it, the ROM leaves that word in r0 across the branch, and
    # func_ov007_020bd648 -- which is the only writer of DISPCNT bits 8-12 in
    # the whole overlay -- reads it as its `mode`. The declaration in the
    # matched TU says `(void)` and MSVC pushes nothing.
    #
    # port/ov007_seat.txt section 5d screened this row and named THIS frame as
    # the one to displace ("displacing bd648 would be displacing the blameless
    # end", because src/func_ov007_020b7138.c's own call passes the argument
    # correctly). Section 5h is the measurement that turned the candidate into
    # a defect and the frame-0 register readings either side of the fix.
    #
    # RETIRED (run linkfull, lane RS4PORT): main #3107 passes
    # func_ov007_020bd648 the pending mode the guard just loaded, so the
    # matched TU is in SLICE_OV007_SOURCES as itself, the cut is gone, and
    # unmatched/Ov007_BdPending_020b6eb4.cpp is no longer appended (the block
    # that appended it, below, is retired with it). The two TS1_B6EB4 flags
    # above are no longer set.
    # run mg15 lane IMPLICITR: THE FOURTH DISPLACEMENT IN THIS SLICE, and the
    # FIRST ONE ON THE RETURN SIDE.
    #
    # func_ov007_020c2b9c is MATCHED and stays matched. It is cut from the port
    # only, because it is the frame where the title's IMPLICIT RETURN VALUE is
    # destroyed: its own call to func_ov007_020c2c68 leaves the new object in
    # r0, nothing between that branch and the single `bx lr` writes r0, so the
    # ROM's callee hands the object back by falling out and the matched body is
    # correct to declare `void`. Both matched callers -- func_ov007_020c2acc
    # and func_ov007_020c2b38, the byte-array and int-array twins -- already
    # declare it `void *` and take it out of r0 with `mov r5, r0`. On MSVC the
    # callee never writes EAX and both callers read whatever was left there;
    # 020c2acc then faults at +0x3f on `mov dword ptr [eax+esi*4], ecx` with
    # eax = 0x62.
    #
    # THE CALLEE IS THE ONLY FRAME THAT CAN BE DISPLACED, which is the
    # difference from the three seams above. The value is allocated inside
    # func_ov007_020c2c68 and lives in the callee's own local; no caller frame
    # holds it to forward. One cut therefore answers BOTH call sites and
    # neither caller is touched. Derivation, the ROM disassembly of every path,
    # the two-row reloc sweep and the measured src/ alternative are in
    # port/unmatched/Ov007_ImplicitReturn_020c2b9c.cpp's header.
    #
    # THE FLAGS ARE NOT BOOKKEEPING, same as the three blocks above: the
    # IMPLICITR predicate near the marker blocks reads them, so the cut and
    # what the predicate says about it cannot drift.
    # RETIRED, run mg16 arc 4: src/func_ov007_020c2b9c.c now SPELLS its return
    # (void*, `return r;`) and still byte-matches at 2004/b56, so the matched TU
    # is built as itself and the host copy is gone. The VOID_DEF regex guard
    # below is what makes that safe to assert rather than hope: it stops matching
    # the moment the definition is no longer spelled `void`.
    # run mg15 lane TITLEDEPTH: THE FOURTH DISPLACEMENT IN THIS SLICE, and the
    # same frame shape as add3c above -- one register over.
    #
    # func_ov007_020b4b5c is MATCHED and stays matched. It is cut from the port
    # only, because it is the frame where the title screen's CAMERA is
    # destroyed: it declares func_ov007_020c43bc with one parameter and calls it
    # with one, and the ROM leaves the camera in r1 across the branch (it saves
    # its own second argument into r5 at 0x020b4b78 and never writes r1 before
    # the bl at 0x020b4b80). On MSVC the callee reads a stack slot nobody
    # filled.
    #
    # THE ROW WAS ALREADY KNOWN AND ALREADY ACCEPTED: port/ov007_seat.txt
    # section 5d lists it among the sixteen faulting-direction rows, and
    # port/tools/aritycheck_plainfunc_baseline.txt line 159 carries it. What
    # this lane adds is the SYMPTOM. func_ov007_020c43bc computes the cell
    # system's world quad size as texels * depth * tan(halfFov) / 96, reading
    # the field of view from the camera's +0xd4; with the garbage pointer it
    # read an index of 256 (22.5 degrees) where the title's camera carries 6.77,
    # so every cell was cot(6.77)/cot(22.5) = 3.4877 times too large. The
    # arithmetic reproduces the observed record to the unit -- a 16-texel cell
    # came out 583 and should be 167 -- and the title's backdrop, sized through
    # the OTHER caller (func_ov007_020c41dc, which passes the camera), measures
    # exactly 1.000 DS pixels per texel in the same frame. The derivation is in
    # port/unmatched/Ov007_ImplicitR1_020b4b5c.cpp's header.
    #
    # THE FLAG IS NOT BOOKKEEPING, same as the three blocks above: the branch
    # below reads it, so the cut and the host copy's membership are one fact.
    #
    # KILL SWITCH -DTIDEP_ARITY_PLAIN=ON puts the matched TU back and drops the
    # host copy, which is the PRE-FIX arm and is a real control rather than a
    # reconstruction: that arm's binary contains exactly the translation unit
    # the base tree compiled. It is a REBUILD and not one binary, so the two
    # arms' .dsstate bases have to be read before their selftest BMPs are
    # compared -- notes/port-selftest-bmp-gate.md. The arm is printed on every
    # configure in BOTH directions, because run mg15's SQRT lane proved a CMake
    # option() caches and a switch that only announces one arm silently keeps
    # the wrong one.
    # RETIRED, run mg16 arc 4: src/func_ov007_020b4b5c.c now FORWARDS the camera
    # -- its own second argument, which the ROM leaves in r1 across the branch --
    # and still byte-matches at 2004/b56, so the matched TU is back as itself.
    # run link60 lane AE1: THE NEXT BLOCKER'S CALLER, and this flag is placed
    # where it is on purpose.
    #
    # Every cut in this loop is a `continue()` ABOVE this line, so a flag set
    # HERE, on the same statement run that appends the source, cannot say
    # "compiled" about a TU that was cut. That is the property the add3c note
    # above did not have: it recorded "listed", the cut recorded nothing, and a
    # lane following its instructions to the letter would have left the marker
    # armed. Membership flags for this loop belong here from now on.
    if(line MATCHES "^src/func_ov007_020bbff0\\.c$")
        set(AE1_BBFF0_COMPILED TRUE)
    endif()
    list(APPEND SLICE_OV007_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# run mg12 lane TITLE seated THE TWO COMMS SLOT-INDEX FRAMES here as host
# copies. RUN MG15 LANE MP1 RETIRED THEM: the defect was never the frames, it
# was include/decl_common.h declaring func_0203dabc and func_0203dae4 as (void)
# when both matched definitions take the comms slot index -- which the ROM
# leaves in r0 from the func_0203da9c() call immediately before, so ARM is
# correct and a stack ABI reads an unwritten slot.
#
# The header now declares both with the parameter, and the one linked ROM
# caller passes it: src/_ZN9dScDSMT_c8BehaviorEv.cpp does
#     func_0203dabc(func_0203da9c())
# which is the same two bl's on ARM. STILL A MATCH at 2004/b56 with strict
# relocs after the change; that gate is the whole reason the header could be
# fixed instead of worked around. The two matched TUs are therefore back in
# the link as themselves, and port/unmatched/Comms_SlotIndex_*.cpp are gone.
#
# WHY IT MATTERED NOW: mg15's MP1 lane links src/func_0203bb60.c and
# src/func_0203bc7c.c, the ROM's four-player fan-out, and those are precisely
# the two callers that pass a REAL index rather than riding slot 0 through r0.
# A face that ignores its argument would have served all four players slot 0's
# record and the four-slot path would have looked like it worked.
# RETIRED, run mg16 arc 4. src/func_ov007_020b4b5c.c now forwards the camera --
# its own second argument, the one the ROM leaves in r1 across the branch at
# 0x020b4b80 -- and it STILL byte-matches at 2004/b56 (30 words, 0 MISMATCH,
# verified against func_ov007_020b63e4 as the alignment control). So the matched
# TU is in the build as itself, unmatched/Ov007_ImplicitR1_020b4b5c.cpp is
# deleted, and TIDEP_ARITY_PLAIN is gone with it: the pre-fix arm it selected
# cannot be reconstructed from a source that no longer contains the defect.
#
# THE DISPLACEMENT WAS NEVER WRONG -- it was correct for a tree where the fix
# could not be spelled in the matched source. What changed is that it can:
# three implicit-argument defects in a row (020c78b0, 020cc600, the
# 02013edc/02042fe4 veneer pair) recovered with the byte match intact, which is
# what made this worth re-attempting rather than assuming settled.
# RETIRED, run link100 wave 15, lane SEAT15E: the implicit-r0 host copy is no
# longer appended, because the cut above no longer happens and the matched TU is
# in SLICE_OV007_SOURCES as itself.
# port/unmatched/Ov007_ImplicitR0_020add3c.cpp keeps its derivation -- the
# 54-instruction capstone reading, the eight-arm jump table, and the measured
# save-versus-argument listing at 0042A310 that settled the class -- and carries
# no body, so it can never become a second definition of 0x020add3c.
# RETIRED, run mg16 arc 4. src/func_ov007_020c2b9c.c now SPELLS the return its two
# matched callers already declare -- `void*` and `return r;` -- and STILL
# byte-matches at 2004/b56 (23 words, 0 MISMATCH). The matched TU is in the build
# as itself and unmatched/Ov007_ImplicitReturn_020c2b9c.cpp is deleted.
#
# The VOID_DEF regex guard further down is deliberately LEFT IN PLACE: it greps
# the source for a `void func_ov007_020c2b9c(` definition, so it stops matching
# now and starts matching again the moment anyone reintroduces the void spelling.
# That is the check that makes this retirement safe to assert rather than hope.
# RETIRED (run linkfull, lane RS4PORT): the pending-mode host copy
# unmatched/Ov007_BdPending_020b6eb4.cpp is no longer appended; the cut in the
# slice loop above is gone and src/func_ov007_020b6eb4.c (main #3107's blob) is
# in SLICE_OV007_SOURCES as itself.
# RETIRED, run link100 wave 15, lane SEAT15E: the ride-through host copy is no
# longer appended, because the cut above no longer happens and the matched TU is
# in SLICE_OV007_SOURCES as itself. port/unmatched/Ov007_RideThrough_020be980.cpp
# keeps its derivation -- the capstone reading at the config-aligned base, the
# four-call-site arity sweep, the r1/r2 liveness correction -- and carries no
# body, so it can never become a second definition of 0x020be980.

# run link60 Stage 5 lane T2: THE HARDWARE DIVIDER'S LAST RAW CALLER.
#
# THE TITLE SCREEN'S 3D LAYER RASTERISED NOTHING BECAUSE ITS PROJECTION MATRIX
# HAD A ZERO X SCALE, and the zero comes from here rather than from anything
# graphical. The chain, measured rather than argued (port/ov007_seat.txt 5i):
#
#   src/func_ov007_020c0128.cpp   the title camera's init writes its ASPECT
#                                 field as `_ZN4cstd4ldivEii(0x4000, 0x3000)`,
#                                 4/3 through the DS hardware divider
#   src/func_ov007_020c0078.c     reads it back, `>> 0x14`, and hands it to
#                                 G3i::PerspectiveW_ as the aspect
#   PerspectiveW_                 divides the cotangent by it for mtx[0]
#
# and cstd::ldiv returned a dead word, so the aspect arrived 0, so mtx[0]
# arrived 0, so every vertex projected to clip x = 0 -- the framebuffer's
# vertical centre line, which is exactly where the audit found all 96
# triangles.
#
# WHY IT RETURNED A DEAD WORD. src/_ZN4cstd10fdiv_asyncE5Fix12IiE5Fix12IiE.c
# reaches DIVCNT, DIV_NUMER and DIV_DENOM through plain literal-address stores,
# and src/_ZN4cstd4ldivEii.cpp reads DIV_RESULT the same way. ntr maps real
# memory across the DS I/O window, so those stores latch and ntr::run_divide
# is never entered -- the identical failure shape hostgen.py's own header
# records for MTX_SCALE. hostgen rewrites the derefs to NTR_MMIO, which is the
# door into ntr::io_write, and the unit runs.
#
# THE BLAST RADIUS IS ONE CALLER AND IT WAS SWEPT, not assumed. cstd::fdiv --
# the divider's other client and the one every level uses -- is a HOST FACE in
# hal/cstd_div.c (pure C, no register), so src/_ZN4cstd4fdivEii.cpp is not in the
# link at all; the map has __ZN4cstd4fdivEii coming from cstd_div.c.obj.
# cstd::ldiv's only caller anywhere in src/ is func_ov007_020c0128, and
# fdiv_async's only callers are cstd::fdiv and cstd::ldiv. So the only live
# path this changes is the title screen's camera init.
#
# BOTH TUs AND NOT JUST THE WRITE SIDE. run_divide publishes its result with
# raw_write into the same mapped window, so a raw READ of DIV_RESULT would
# have worked once the writes were proxied, and hostgen'ing ldiv is not what
# makes the frame change. It is here so the busy-spin, the result read and the
# stores all go through one door: the day ntr models DIV_BUSY, or serves
# DIV_RESULT from anywhere but the window, a half-routed caller would desync
# silently and this is the caller that already cost one lane a frame.
# The measurement is in 5i: fdiv_async alone is load-bearing today.
set(T2_DIV_SYMS _ZN4cstd10fdiv_asyncE5Fix12IiE5Fix12IiE _ZN4cstd4ldivEii)
set(T2_DIV_GEN "")
foreach(sym IN LISTS T2_DIV_SYMS)
    # DEPENDS follows the extension the file actually has. Both of these were
    # .c when the block was written and main promoted them to .cpp, which made
    # ninja depend on a path that does not exist and stopped the build before
    # anything compiled. (2026-09-12, lane SYNC2.)
    set(sym_dep "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    if(NOT EXISTS "${sym_dep}")
        set(sym_dep "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_dep}"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND T2_DIV_GEN "${sym_out}")
endforeach()

# The plain entries have to go, or the hostgen copy is a duplicate symbol. Each
# of the two is listed in exactly ONE slice file (checked at the tip, and the
# count below is the guard: if a third listing appears the message fires and
# the link is the thing that tells you, not a silent double body).
set(T2_DIV_CUT 0)
set(SLICE_OV007_SRC_T2 "")
foreach(src IN LISTS SLICE_OV007_SOURCES)
    if(src MATCHES "/_ZN4cstd4ldivEii\\.(c|cpp)$")
        math(EXPR T2_DIV_CUT "${T2_DIV_CUT}+1")
        continue()
    endif()
    list(APPEND SLICE_OV007_SRC_T2 "${src}")
endforeach()
set(SLICE_OV007_SOURCES ${SLICE_OV007_SRC_T2})
set(SLICE10_SRC_T2 "")
foreach(src IN LISTS SLICE10_SOURCES)
    if(src MATCHES "/_ZN4cstd10fdiv_asyncE5Fix12IiE5Fix12IiE\\.(c|cpp)$")
        math(EXPR T2_DIV_CUT "${T2_DIV_CUT}+1")
        continue()
    endif()
    list(APPEND SLICE10_SRC_T2 "${src}")
endforeach()
set(SLICE10_SOURCES ${SLICE10_SRC_T2})
if(NOT T2_DIV_CUT EQUAL 2)
    message(STATUS "T2: expected to cut 2 plain divider entries and cut "
                   "${T2_DIV_CUT}. If a slice file stopped listing one of "
                   "src/_ZN4cstd4ldivEii.cpp or "
                   "src/_ZN4cstd10fdiv_asyncE5Fix12IiE5Fix12IiE.c the hostgen "
                   "copy is still added and the link will say so; if a THIRD "
                   "slice started listing one, this cut missed it and the link "
                   "will say that too")
endif()

# run mg14 lane TITLE2: THE DIVIDER'S ACTUAL LAST RAW CALLER, cstd::mod.
#
# The T2 block above says "THE HARDWARE DIVIDER'S LAST RAW CALLER" and it was
# wrong by one. Its blast-radius sweep bounded itself to cstd::ldiv and
# fdiv_async and to cstd::fdiv (which is a host face and not in the link at
# all). It never asked about src/_ZN4cstd3modEii.cpp, which reaches DIVCNT,
# DIV_NUMER and DIV_DENOM through the same plain literal-address stores and
# reads DIV_REM (0x040002a8) back the same way, and which slice_ov007.txt
# listed as a plain entry. Same failure, same fix, one caller later.
#
# WHAT IT ACTUALLY DID, measured on this tree's own binary rather than argued.
# ntr maps real memory across the DS I/O window, so a plain TU's stores latch
# and ntr::run_divide is never entered; the read of DIV_REM then returns
# whatever the last HOSTGEN-ROUTED divide left in the window. cstd::mod was
# therefore a function that returns the PREVIOUS divide's remainder. The probe
# in hal/scene_boot.cpp prints the demonstration on one line:
#
#     div1000_7=142 mod419_40=6(want19)
#
# 1000/7 is 142 remainder 6, and cstd::mod(419, 40) answered 6. cstd::div is
# correct because slice_gate29.txt routes its whole gate through hostgen; this
# is the asymmetry that hid it, because the two live one line apart in src/.
#
# WHAT IT COST, and this is why a title-screen lane is editing a divider.
# func_ov007_020b0da0 is the title's attract callback (MATCH at 2004/b56). It
# computes var_r4 from cstd::mod(counter, 0x28) and ends the attract with
#
#     if ((st4 & 2) && (var_r4 == 0 || var_r4 == 0x800)) scene->f_100->f_18 = 0;
#
# With a stale mod, var_r4 was never 0 and never 0x800 (measured 614), so the
# callback pointer was never dropped, so func_ov007_020b0a20's
# `if (scene->f_100->f_18 == 0)` re-arm never fired, so func_ov007_020be980
# never restarted the logo animation, so it stayed PAUSED at frame 0 of 157 --
# f0 == 1 being the one value func_ov007_020c9110 refuses to step -- and
# scene 1 sat in state 11 forever. The touch was being HEARD the whole time:
# the same body's stylus hotspot sets st4 |= 2 on the press frame.
#
# BLAST RADIUS, SWEPT NOT ASSUMED. `grep -rl _ZN4cstd3modEii src/` is 15 files:
# the definition and fourteen callers, ALL of them ov007 --
# 020ae2d0 020aefb4 020af260 020b0da0 020b1cf0 020b2e64 020b9ca8 020ba368
# 020baa10 020bad8c 020bb4b0 020bed60 020c49bc 020c9d90. So nothing outside the
# title screen and file select changes behaviour here, and inside it every one
# of those fourteen was reading a stale remainder. src/ is NOT edited: this is
# a build-time routing exactly like T2's, so the byte gate cannot move.
#
# ONE SLICE LISTS IT (port/slice_ov007.txt), and the cut below is guarded on
# that count the way T2's is: if a second slice ever lists it the hostgen copy
# becomes a duplicate symbol and the link says so, and if this cut ever misses
# the plain entry the link says that too.
# THE A/B THIS ROUTING GETS AND T2's DID NOT. -DTI2_MOD_PLAIN=ON puts the plain
# entry back and drops the hostgen copy, so the before/after is two builds off
# ONE tree with ONE difference, which is what a regression on a build-time
# change can honestly be. It is a REBUILD and not one binary, so the two arms'
# .dsstate bases have to be read before their BMPs are compared -- see
# notes/port-selftest-bmp-gate.md, whose rule this switch exists to satisfy
# rather than to dodge. Default OFF: the routing is the shipped behaviour.
option(TI2_MOD_PLAIN "run mg14 TITLE2: build cstd::mod PLAIN (pre-fix arm)" OFF)
set(TI2_MOD_SYMS _ZN4cstd3modEii)
if(TI2_MOD_PLAIN)
    set(TI2_MOD_SYMS "")
    message(STATUS "TI2: TI2_MOD_PLAIN=ON -- cstd::mod builds PLAIN. This is "
                   "the PRE-FIX arm: the DS divider is never entered and "
                   "cstd::mod returns the previous proxied divide's remainder.")
endif()
set(TI2_MOD_GEN "")
foreach(sym IN LISTS TI2_MOD_SYMS)
    # DEPENDS follows the extension the file actually has. Both of these were
    # .c when the block was written and main promoted them to .cpp, which made
    # ninja depend on a path that does not exist and stopped the build before
    # anything compiled. (2026-09-12, lane SYNC2.)
    set(sym_dep "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    if(NOT EXISTS "${sym_dep}")
        set(sym_dep "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_dep}"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND TI2_MOD_GEN "${sym_out}")
endforeach()

set(TI2_MOD_CUT 0)
set(SLICE_OV007_SRC_TI2 "")
foreach(src IN LISTS SLICE_OV007_SOURCES)
    if(src MATCHES "/_ZN4cstd3modEii\\.(c|cpp)$" AND NOT TI2_MOD_PLAIN)
        math(EXPR TI2_MOD_CUT "${TI2_MOD_CUT}+1")
        continue()
    endif()
    list(APPEND SLICE_OV007_SRC_TI2 "${src}")
endforeach()
set(SLICE_OV007_SOURCES ${SLICE_OV007_SRC_TI2})
if(TI2_MOD_PLAIN)
    # The A arm cuts nothing on purpose, so satisfy the guard rather than
    # letting it print a scary line about a cut that was never meant to happen.
    set(TI2_MOD_CUT 1)
endif()
if(NOT TI2_MOD_CUT EQUAL 1)
    message(STATUS "TI2: expected to cut 1 plain cstd::mod entry and cut "
                   "${TI2_MOD_CUT}. If slice_ov007.txt stopped listing "
                   "src/_ZN4cstd3modEii.cpp the hostgen copy is still added and "
                   "the link will say so; if a SECOND slice started listing "
                   "it, this cut missed it and the link will say that too")
endif()

# run mg15 lane SQRT: THE SQUARE-ROOT UNIT'S FIFTH CLIENT, func_02053274.
#
# SQRTUNIT_SYMS above routes the unit's four DRIVERS (func_02053008,
# func_02053130, func_020531a4, func_02052fdc). It does not route the unit's
# fifth client, and that one is not a driver at all: src/func_02053274.c is the
# 3D DISTANCE function. It squares the three axis deltas, shifts the sum left by
# 2, drives the unit with that as a 64-bit operand and returns
# (SQRT_RESULT + 1) >> 1, the rounded distance. slice_gate10.txt listed it plain.
#
# WHY IT SURVIVED FOUR ROUNDS OF THIS. Every sweep for raw MMIO before mg14
# looked for a CAST-DEREF of a literal. This body reaches SQRTCNT (0x40002b0)
# and BOTH HALVES of SQRT_PARAM (0x40002b8, 0x40002bc) through a POINTER BOUND
# TO A LITERAL --
#
#     volatile unsigned int *param = (volatile unsigned int *)0x40002b8;
#     param[0] = (unsigned int)sq;  param[1] = (unsigned int)(sq >> 32);
#
# -- and reaches only SQRT_RESULT by a cast-deref. So a deref-only scan sees one
# harmless RESULT READ and files the body as safe, while the two stores that
# actually start the unit are invisible to it. hostgen's MMIO_BIND transform is
# exactly the thing that sees them; it emits NINE rewrites on this body, and
# port/tools/hostgen.py's own audit of source-touches-versus-NTR_MMIO-sites is
# the check that says none was missed (9 touches, 9 sites, same address
# multiset, nothing left plain, and param[1] scaled to 0x40002bc).
#
# WHAT IT DID. ntr maps real memory across the DS I/O window, so a plain TU's
# stores latch and ntr::run_sqrt is never entered; the read of SQRT_RESULT then
# returns whatever the last HOSTGEN-ROUTED sqrt left there. func_02053274 was a
# distance function that answers the PREVIOUS square root. The self-test in
# hal/scene_boot.cpp (SM64DS_SQRT_SELFTEST=1) asks it two roots it cannot get
# wrong, each seeded by the routed func_020531a4 so the broken answer is
# PREDICTED and not merely wrong.
#
# AND IT CORRECTS A COMMENT THAT SAID THIS WAS ALREADY FIXED. ntr/io.cpp's
# sqrt-trigger block claimed the widening "silently fixed a SECOND split-half
# SQRT_PARAM writer already in the build: func_02053274". It cannot have:
# widening io_write's dispatch only helps a store that REACHES io_write, and a
# plain TU's stores never do. That comment is corrected in the same commit as
# this routing, because it is the reason nobody looked here for a year.
#
# BLAST RADIUS, SWEPT NOT ASSUMED. Three direct callers, eight TUs to depth 3,
# and every one of the eight is in a slice list, so every one is in the link:
#
#   in-level engine (slice_gate10)
#     Player::St_NoControl_Main -> func_ov002_020c8a4c     dist < 0xa000 gate
#     Player::St_YoshiPower_Main -> func_ov002_020d6998
#                                -> func_ov002_020d6dac    raycast hit distance
#                                                          -> self+0x654, then a
#                                                          Particle::System::New
#   title / ov007 (slice_ov007)
#     func_ov007_020c65bc -> func_ov007_020c25fc
#                         -> func_ov007_020c2e90            (d<<12) > r range test
#
# Nothing reaches it indirectly: the address 0x02053274 appears in no pointer
# table in the tree. src/ is NOT edited -- this is a build-time routing, so the
# byte gate cannot move.
#
# WHAT THE BREAKAGE COST, in the callers' own terms. func_ov002_020c8a4c is
# sub-state 15 of Player::St_NoControl_Main: it faces the player at a target
# point (self+0x744), and the whole body turns on
#
#     if (func_02053274(self+0x5c, self+0x744) < 0xa000)   /* 0xa000 = 10.0 */
#
# which is an ARRIVAL test -- "am I close enough to the target yet". With a
# stale sqrt that test compares a number that never changes against a constant,
# so it is either permanently true or permanently false for the whole scripted
# move, and which one it is depends on what the last routed sqrt happened to
# leave in the register. func_ov002_020d6dac stores the raycast hit distance
# straight into self+0x654 and then spawns a particle at the hit point, so its
# stale value is a wrong distance written into player state. func_ov007_020c2e90
# is a two-sided range test, (d<<12) > r and r <= (e<<12).
#
# AND WHAT THE REGRESSION COULD AND COULD NOT SEE, measured rather than
# inferred. Five paired captures (scenes 1, 4, 374 and level 1 at two frame
# counts each) came back BYTE-IDENTICAL across the two arms. That is only
# reassuring once you know whether the body ran in those frames at all, so
# ntr::sqrt_runs() was added to count entries to run_sqrt -- a plain build never
# enters it, so the arms' difference IS the call count the routing added:
#
#     scene 1  @300   4734 vs  4734     delta 0
#     scene 4  @300   1200 vs  1200     delta 0
#     scene 374@300      0 vs     0     delta 0
#     level 1  @300  56404 vs 56404     delta 0
#     level 1  @450  82988 vs 82988     delta 0
#
# The counter is demonstrably live (level 1 runs the unit 56,404 times in 300
# frames); func_02053274 is simply not on any of those paths. Both Player
# callers are sub-states a W-held walk never enters, and the ov007 chain hangs
# off func_ov007_020c65bc, which nothing in src/ calls by name. So the identical
# pixels are a measured NOT-REACHED, not a fix that does nothing -- and no run
# in the standard regression set can confirm the repair in pixels. The self-test
# is the confirmation, and it is why this change has one.
#
# ONE SLICE LISTS IT (port/slice_gate10.txt) and the cut below is guarded on
# that count the way TI2's and T2's are: if a second slice ever lists it the
# hostgen copy becomes a duplicate symbol and the link says so, and if this cut
# ever misses the plain entry the link says that too.
#
# THE A/B. -DSQ_DIST_PLAIN=ON puts the plain entry back and drops the hostgen
# copy, so the before/after is two builds off ONE tree with ONE difference. It
# is a REBUILD and not one binary, so the two arms' .dsstate bases have to be
# read before their BMPs are compared -- see notes/port-selftest-bmp-gate.md.
# Default OFF: the routing is the shipped behaviour.
# AND IT SAYS WHICH ARM IT IS ON EVERY CONFIGURE, not only when the switch is
# on. `option()` writes to CMakeCache.txt, so a build dir that was once
# configured with -DSQ_DIST_PLAIN=ON STAYS on the pre-fix arm when the next
# configure omits the flag entirely. That cost this lane two builds: both were
# labelled fix-on, both were actually pre-fix, and the only reason it did not
# reach the write-up is that the self-test printed BROKEN out of a binary that
# was supposed to be fixed. A guard that only speaks when the switch is set
# cannot catch its own stale cache, so this one always speaks. Pass the flag
# explicitly on BOTH arms (-DSQ_DIST_PLAIN=OFF and =ON) and read this line back
# out of the build log before trusting either binary.
option(SQ_DIST_PLAIN "run mg15 SQRT: build func_02053274 PLAIN (pre-fix arm)" OFF)
set(SQ_DIST_SYMS func_02053274)
if(SQ_DIST_PLAIN)
    set(SQ_DIST_SYMS "")
    message(STATUS "SQRT ARM: SQ_DIST_PLAIN=ON -- func_02053274 builds PLAIN. "
                   "This is the PRE-FIX arm: the DS square-root unit is never "
                   "entered and the 3D distance function returns the previous "
                   "routed sqrt's result.")
else()
    message(STATUS "SQRT ARM: SQ_DIST_PLAIN=OFF -- func_02053274 is ROUTED "
                   "through hostgen. This is the SHIPPED arm.")
endif()
set(SQ_DIST_GEN "")
foreach(sym IN LISTS SQ_DIST_SYMS)
    # DEPENDS follows the extension the file actually has. Both of these were
    # .c when the block was written and main promoted them to .cpp, which made
    # ninja depend on a path that does not exist and stopped the build before
    # anything compiled. (2026-09-12, lane SYNC2.)
    set(sym_dep "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    if(NOT EXISTS "${sym_dep}")
        set(sym_dep "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_dep}"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND SQ_DIST_GEN "${sym_out}")
endforeach()

set(SQ_DIST_CUT 0)
set(SLICE10_SRC_SQ "")
foreach(src IN LISTS SLICE10_SOURCES)
    if(src MATCHES "/func_02053274\\.c$" AND NOT SQ_DIST_PLAIN)
        math(EXPR SQ_DIST_CUT "${SQ_DIST_CUT}+1")
        continue()
    endif()
    list(APPEND SLICE10_SRC_SQ "${src}")
endforeach()
set(SLICE10_SOURCES ${SLICE10_SRC_SQ})
if(SQ_DIST_PLAIN)
    # The pre-fix arm cuts nothing on purpose, so satisfy the guard rather than
    # letting it print a scary line about a cut that was never meant to happen.
    set(SQ_DIST_CUT 1)
endif()
if(NOT SQ_DIST_CUT EQUAL 1)
    message(STATUS "SQRT: expected to cut 1 plain func_02053274 entry and cut "
                   "${SQ_DIST_CUT}. If slice_gate10.txt stopped listing "
                   "src/func_02053274.c the hostgen copy is still added and the "
                   "link will say so; if a SECOND slice started listing it, this "
                   "cut missed it and the link will say that too")
endif()
# ---- run mg15 lane TITLETEX: ov007's GEOMETRY COMMAND PORTS ----------------
#
# THE SAME DEFECT AS TI2 ABOVE, one register block over, and this is the one
# the owner has been looking at since his first title-screen test: "any other
# graphics than those have jumbled glitchy textures", and on the fresh f300 /
# f450 captures, "its just a big glitched yellow texture".
#
# WHAT WAS MEASURED, before anything was changed. SM64DS_MTX_BALANCE=1 (added
# to port/ntr/gx.cpp by this lane) prints, per command port, the commands the
# geometry engine EXECUTED next to the word sitting in the mapped I/O window at
# that same port. On SM64DS_SCENE=1, 300 frames, off the unmodified tree:
#
#     MTX_PUSH   04000444  exec        0  latch 00000000
#     MTX_POP    04000448  exec        0  latch 00000001   <-- STORED, NEVER EXECUTED
#     MTX_MULT_4x3 04000464 exec    17951
#     MTX_SCALE  0400046c  exec    11051
#     VIEWPORT   04000580  exec        0  latch bfff0000   <-- STORED, NEVER EXECUTED
#     SWAP_BUFFERS 04000540 exec       0  latch 00000002   <-- STORED, NEVER EXECUTED
#     pos_sp = 0 on every one of the 300 frames, and 0 at exit
#
# ZERO MATRIX PUSHES AND ZERO POPS IN A WHOLE RUN, against 17,951 matrix
# multiplies. The position stack level never leaves 0 -- read per frame, not at
# one endpoint, because an endpoint cannot tell a bracket that balanced from
# one that never ran. The title screen brackets each of the ~27 objects it
# places per frame with MTX_PUSH ... MTX_POP, and not one of those brackets
# reaches the engine: src/func_ov007_020c421c.c, _020ca5f0.c and _020b413c.c
# write the push and the pop as PLAIN literal stores, and ntr maps real memory
# across 0x04000000, so each one latches a word and the geometry engine is
# never told. Everything the bracket was meant to contain -- the MTX_MULT_4x3
# that src/func_ov007_020c42f8.c submits through func_0205532c, which IS routed
# and DOES arrive -- stays applied to the live matrix for the rest of the
# frame, and the model drawn after it is transformed by an accumulated product
# nothing in the ROM ever computes. The audit's geometry census is the picture
# of that: bounding box x -227.094 .. 1025.594, y -480.132 .. 811.985 on a
# 512x384 panel, 0 degenerate, projection correct. The frame is one surface
# stretched past every edge, which is the yellow.
#
# THE SAME THREE FILES DROP THEIR MTX_SCALE the same way, so every object also
# loses the scale it was placed at, and src/func_ov007_020c0078.c -- the
# title's own perspective setup -- drops MTX_STORE and VIEWPORT. The viewport
# word it stores is bfff0000, which decodes to (0,0)-(255,191), the whole DS
# screen; ntr::gx_reset's fallback rectangle is the same rectangle at the
# host's 2x tier, so THAT one costs nothing today and is routed for
# faithfulness rather than for a symptom. MTX_STORE is not free: its slot is
# what func_ov007_020c0078's own MTX_RESTORE readers come back to.
#
# THE TREATMENT IS THE ONE THE PORT ALREADY USES FOR THIS CLASS and it costs
# nothing in the ledger: port/tools/hostgen.py rewrites the literal derefs to
# NTR_MMIO so the store dispatches through ntr::io_write, src/ is not edited,
# and every one of these translation units stays byte-matched. It is the same
# block shape as T2's divider, TI2's cstd::mod above and the SQRTUNIT group.
#
# THE SET IS THE MEASURED ONE, not a guess. port/tools/hostgen.py's own MMIO
# patterns were run over every source in walk_window's build.ninja that is
# compiled straight out of the tree, with comments stripped so a banner
# quoting a register does not count as a writer. Twelve ov007 translation
# units reach a geometry command port that way; they are all here. THE THREE
# ov007 DIVIDER TUs THAT THE SAME SCAN FOUND (func_ov007_020c30ac,
# _020c31e0, _020c7d60) ARE DELIBERATELY NOT IN THIS SET: they are the
# DIV/SQRT unit, run mg15's SQRT lane owns that register block in the same
# wave, and two lanes routing the same class in one run is how a duplicate
# symbol arrives. They are recorded in this lane's results for the next wave.
#
# THE KILL SWITCH IS -DTITEX_GX_PLAIN=ON and it gives the plain arm back on the
# same tree, which is what a build-time routing can honestly offer. It is a
# REBUILD and not one binary, so the two arms' .dsstate bases have to be read
# before their BMPs are compared -- notes/port-selftest-bmp-gate.md. THE ARM IS
# PRINTED ON EVERY CONFIGURE, in both directions, because run mg15's SQRT lane
# proved that a CMake option() CACHES and an A/B switch that only announces one
# arm silently keeps the wrong one.
option(TITEX_GX_PLAIN
       "run mg15 TITLETEX: build ov007's geometry-port TUs PLAIN (pre-fix arm)"
       OFF)
set(TITEX_GX_SYMS
    func_ov007_020b413c    # MTX_PUSH  MTX_POP
    func_ov007_020b6c54    # SWAP_BUFFERS
    func_ov007_020c0078    # MTX_STORE  VIEWPORT
    func_ov007_020c1404    # PLTT_BASE
    func_ov007_020c1448    # TEXIMAGE_PARAM
    func_ov007_020c232c    # LIGHT_VECTOR  LIGHT_COLOR
    func_ov007_020c421c    # MTX_PUSH  MTX_POP  MTX_SCALE
    func_ov007_020c42f8    # MTX_SCALE
    func_ov007_020c49bc    # TEXCOORD VTX_16 VTX_XZ VTX_YZ BEGIN_VTXS END_VTXS
    func_ov007_020c4fcc    # COLOR  POLYGON_ATTR  TEXIMAGE_PARAM
    func_ov007_020ca5f0    # MTX_PUSH MTX_POP MTX_SCALE MTX_TRANS POLYGON_ATTR
                           # DIF_AMB SPE_EMI
    func_ov007_020ca86c    # NORMAL  VTX_16  BEGIN_VTXS  END_VTXS
    func_ov007_020caeac)   # TEXCOORD  NORMAL  VTX_16  BEGIN_VTXS  END_VTXS
list(LENGTH TITEX_GX_SYMS TITEX_GX_WANT)
if(TITEX_GX_PLAIN)
    message(STATUS "TITEX: TITEX_GX_PLAIN=ON -- ov007's ${TITEX_GX_WANT} "
                   "geometry-port TUs build PLAIN. This is the PRE-FIX arm: "
                   "MTX_PUSH/MTX_POP/MTX_SCALE/VIEWPORT latch in mapped memory "
                   "and the geometry engine is never told.")
else()
    message(STATUS "TITEX: TITEX_GX_PLAIN=OFF -- ov007's ${TITEX_GX_WANT} "
                   "geometry-port TUs route through hostgen (shipped arm).")
endif()
set(TITEX_GX_GEN "")
if(NOT TITEX_GX_PLAIN)
    foreach(sym IN LISTS TITEX_GX_SYMS)
        # The tree spells these .c except func_ov007_020c4fcc, which is .cpp;
        # hostgen emits .cpp either way, so only the DEPENDS has to know.
        set(sym_in "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        if(NOT EXISTS "${sym_in}")
            set(sym_in "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
        endif()
        set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
        add_custom_command(OUTPUT "${sym_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
            DEPENDS "${sym_in}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${sym}")
        list(APPEND TITEX_GX_GEN "${sym_out}")
    endforeach()
endif()
# Cut the plain slice entries in the SAME block that adds the generated ones,
# so the cut cannot drift from the branch that adds the copy. The real net is
# the LINKER either way: a slice that stopped listing one of these answers with
# an undefined symbol, and one that started listing a second copy answers with
# a duplicate. The count guard below is a signpost for a reader looking at that
# failed link, which is what the T2 block's own comment says of its own.
set(TITEX_GX_CUT 0)
set(SLICE_OV007_SRC_TITEX "")
foreach(src IN LISTS SLICE_OV007_SOURCES)
    set(_cut OFF)
    if(NOT TITEX_GX_PLAIN)
        foreach(sym IN LISTS TITEX_GX_SYMS)
            if(src MATCHES "/${sym}\\.(c|cpp)$")
                set(_cut ON)
            endif()
        endforeach()
    endif()
    if(_cut)
        math(EXPR TITEX_GX_CUT "${TITEX_GX_CUT}+1")
    else()
        list(APPEND SLICE_OV007_SRC_TITEX "${src}")
    endif()
endforeach()
set(SLICE_OV007_SOURCES ${SLICE_OV007_SRC_TITEX})
if(TITEX_GX_PLAIN)
    # The pre-fix arm cuts nothing on purpose; satisfy the guard rather than
    # print a scary line about a cut that was never meant to happen.
    set(TITEX_GX_CUT ${TITEX_GX_WANT})
endif()
if(NOT TITEX_GX_CUT EQUAL TITEX_GX_WANT)
    message(STATUS "TITEX: expected to cut ${TITEX_GX_WANT} plain ov007 "
                   "geometry-port entries and cut ${TITEX_GX_CUT}. If "
                   "slice_ov007.txt stopped listing one of them the hostgen "
                   "copy is still added and the link will say so; if a SECOND "
                   "slice started listing one, this cut missed it and the link "
                   "will say that too")
endif()

# ---- run mg15 lane TITLEDEPTH: THE PER-FRAME GEOMETRY RESET ----------------
#
# One row past the TITLETEX block above, and the same defect: two arm9 helpers
# that slice_ov007.txt lists and no other slice does, every store in them
# PLAIN, so none of it reaches the geometry engine.
#
# WHAT THEY ARE, read off extracted/arm9_dec.bin at 0x02004000 rather than
# taken on the source's word. Alignment proven first on the two MATCHED
# neighbours func_02055464 and func_02055490, whose disassembly reproduces
# their src TUs instruction for instruction (the 0x2000>>13 and 0x1f00>>8
# field extractions, the GXSTAT pool word 0x04000600 at each tail):
#
#   func_020557b4  GXSTAT bit-27 busy wait; GXSTAT |= 0x8000 (clear the
#                  matrix-stack error flag); DISP3DCNT |= 0x2000 and |= 0x1000
#                  (the two 3D error acknowledges); call func_02055624; then
#                  POLYGON_ATTR = 0x1f0080, TEXIMAGE_PARAM = 0, PLTT_BASE = 0
#                  -- the DEFAULT MATERIAL every frame starts from.
#   func_02055624  read the position/vector stack level into a and the
#                  projection stack level into b (through the two matched
#                  helpers above, which read GXSTAT); then
#                  MTX_MODE 3 + MTX_IDENTITY   -- the TEXTURE matrix
#                  MTX_MODE 0 + MTX_POP b      -- unwind the projection stack
#                  MTX_MODE 2 + MTX_POP a + MTX_IDENTITY
#                                              -- unwind the position stack and
#                                                 start the frame from identity
#
# IT IS THE PER-FRAME RESET, from the ROM's own call graph and not from the
# name: src/func_ov007_020bcf90.c is the title screen's Render, and it opens
# with func_020557b4(); func_02055624(); func_02055574(...) before it draws
# anything. func_020557b4's only other caller is func_0200f4b4.
#
# WHY IT COULD NOT BE ROUTED UNTIL NOW. func_02055624 POPS BY A NUMBER IT
# READS OUT OF GXSTAT. Until the commit before this one those bits were a
# snapshot refreshed only when something touched the register through the MMIO
# proxy -- measured 1620 disagreements in 2743 samples on 60 frames of scene 1
# -- so routing this while they were dead would have popped by a stale number,
# which is worse than not popping at all. The geometry engine publishes the
# level at push and pop time now, so the two reads are true.
#
# ONE MODELLING DIVERGENCE, NAMED. On hardware DISP3DCNT bits 12 and 13 are
# status bits and writing 1 ACKNOWLEDGES them; against the host's mapped window
# the same store SETS them. Nothing in the port reads DISP3DCNT -- the only
# reader in the tree is ntr/ppu_audit.cpp's census row -- so this costs
# nothing today, and it is written down rather than left for someone to find.
#
# KILL SWITCH -DTIDEP_RESET_PLAIN=ON, printed on EVERY configure in BOTH
# directions (run mg15's SQRT lane proved a CMake option() caches and a switch
# that only announces one arm silently keeps the wrong one). It is a rebuild
# rather than one binary, so the two arms' .dsstate bases have to be read
# before their BMPs are compared -- notes/port-selftest-bmp-gate.md.
option(TIDEP_RESET_PLAIN
       "run mg15 TITLEDEPTH: build the per-frame geometry reset PLAIN (pre-fix arm)"
       OFF)
set(TIDEP_RESET_SYMS
    func_020557b4          # GXSTAT  DISP3DCNT  POLYGON_ATTR  TEXIMAGE_PARAM
                           # PLTT_BASE
    func_02055624)         # GXSTAT  MTX_MODE  MTX_POP  MTX_IDENTITY
list(LENGTH TIDEP_RESET_SYMS TIDEP_RESET_WANT)
if(TIDEP_RESET_PLAIN)
    message(STATUS "TIDEP: TIDEP_RESET_PLAIN=ON -- the ${TIDEP_RESET_WANT} "
                   "per-frame geometry reset TUs build PLAIN. This is the "
                   "PRE-FIX arm: the position and texture matrices are never "
                   "made identity, the stacks are never unwound and the "
                   "default material is never set.")
else()
    message(STATUS "TIDEP: TIDEP_RESET_PLAIN=OFF -- the ${TIDEP_RESET_WANT} "
                   "per-frame geometry reset TUs route through hostgen "
                   "(shipped arm).")
endif()
set(TIDEP_RESET_GEN "")
if(NOT TIDEP_RESET_PLAIN)
    foreach(sym IN LISTS TIDEP_RESET_SYMS)
        set(sym_in "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        if(NOT EXISTS "${sym_in}")
            set(sym_in "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
        endif()
        set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
        add_custom_command(OUTPUT "${sym_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
            DEPENDS "${sym_in}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${sym}")
        list(APPEND TIDEP_RESET_GEN "${sym_out}")
    endforeach()
endif()
# Cut the plain slice entries in the SAME block that adds the generated ones,
# for the TITEX block's reason: the real net is the LINKER either way, and the
# count guard below is only a signpost for a reader looking at a failed link.
set(TIDEP_RESET_CUT 0)
set(SLICE_OV007_SRC_TIDEP "")
foreach(src IN LISTS SLICE_OV007_SOURCES)
    set(_cut OFF)
    if(NOT TIDEP_RESET_PLAIN)
        foreach(sym IN LISTS TIDEP_RESET_SYMS)
            if(src MATCHES "/${sym}\\.(c|cpp)$")
                set(_cut ON)
            endif()
        endforeach()
    endif()
    if(_cut)
        math(EXPR TIDEP_RESET_CUT "${TIDEP_RESET_CUT}+1")
    else()
        list(APPEND SLICE_OV007_SRC_TIDEP "${src}")
    endif()
endforeach()
set(SLICE_OV007_SOURCES ${SLICE_OV007_SRC_TIDEP})
if(TIDEP_RESET_PLAIN)
    set(TIDEP_RESET_CUT ${TIDEP_RESET_WANT})
endif()
if(NOT TIDEP_RESET_CUT EQUAL TIDEP_RESET_WANT)
    message(STATUS "TIDEP: expected to cut ${TIDEP_RESET_WANT} plain "
                   "geometry-reset entries and cut ${TIDEP_RESET_CUT}. If "
                   "slice_ov007.txt stopped listing one of them the hostgen "
                   "copy is still added and the link will say so; if a SECOND "
                   "slice started listing one, this cut missed it and the link "
                   "will say that too")
endif()

# ---- run link100 boot plan rung R3b, step BSWAP: THE ROM'S OWN FRAME SWAP ---
#
# src/func_020190b8.c is the ROM's end-of-frame SWAP_BUFFERS, called once per
# frame by func_020197b8 at phase 6 (func_020197b8.c:52). slice_scene1.txt has
# listed it since scene 1 came up, so it has been LINKED all along -- and built
# PLAIN, which means its one store
#
#     *(volatile int *)0x4000540 = 3;
#
# landed in the mapped I/O window and the geometry engine was never told. Lane
# R3CFIX2 measured exactly that on a 300-frame level run:
# "SWAP_BUFFERS 04000540 exec 0 latch 00000003 <-- STORED, NEVER EXECUTED"
# (status/R3CFIX2.md, 18:22), while func_020190b8 itself was called 301 times.
# port/ntr/io.cpp states the rule this is an instance of: a store only reaches
# ntr::io_write if its TU was rewritten by tools/hostgen.py, and only the
# TITEX/TIDEP blocks above do that -- which is why the ov007 SWAP_BUFFERS
# (func_ov007_020b6c54, the VS menu) DOES arrive and this one did not.
#
# Same shape as those two blocks, one symbol, and the same kill switch
# discipline: the arm is PRINTED ON EVERY CONFIGURE in both directions, because
# a CMake option() caches and a switch that announces only one arm silently
# keeps the wrong one.
option(R3B_SWAP_PLAIN
       "run link100 R3b/BSWAP: build the ROM's frame swap PLAIN (pre-fix arm)"
       OFF)
set(R3B_SWAP_SYMS
    func_020190b8)         # SWAP_BUFFERS
list(LENGTH R3B_SWAP_SYMS R3B_SWAP_WANT)
if(R3B_SWAP_PLAIN)
    message(STATUS "R3B: R3B_SWAP_PLAIN=ON -- the ROM's frame swap builds "
                   "PLAIN. This is the PRE-FIX arm: SWAP_BUFFERS latches in "
                   "mapped memory and the geometry engine is never told.")
else()
    message(STATUS "R3B: R3B_SWAP_PLAIN=OFF -- the ROM's frame swap routes "
                   "through hostgen (shipped arm).")
endif()
set(R3B_SWAP_GEN "")
if(NOT R3B_SWAP_PLAIN)
    foreach(sym IN LISTS R3B_SWAP_SYMS)
        set(sym_in "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        if(NOT EXISTS "${sym_in}")
            set(sym_in "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
        endif()
        set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
        add_custom_command(OUTPUT "${sym_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
            DEPENDS "${sym_in}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${sym}")
        list(APPEND R3B_SWAP_GEN "${sym_out}")
    endforeach()
endif()
# Cut the plain slice entry in the SAME block that adds the generated one. This
# one comes out of slice_scene1, not slice_ov007.
set(R3B_SWAP_CUT 0)
set(SLICE_SCENE1_SRC_R3B "")
foreach(src IN LISTS SLICE_SCENE1_SOURCES)
    set(_cut OFF)
    if(NOT R3B_SWAP_PLAIN)
        foreach(sym IN LISTS R3B_SWAP_SYMS)
            if(src MATCHES "/${sym}\\.(c|cpp)$")
                set(_cut ON)
            endif()
        endforeach()
    endif()
    if(_cut)
        math(EXPR R3B_SWAP_CUT "${R3B_SWAP_CUT}+1")
    else()
        list(APPEND SLICE_SCENE1_SRC_R3B "${src}")
    endif()
endforeach()
set(SLICE_SCENE1_SOURCES ${SLICE_SCENE1_SRC_R3B})
if(R3B_SWAP_PLAIN)
    set(R3B_SWAP_CUT ${R3B_SWAP_WANT})
endif()
if(NOT R3B_SWAP_CUT EQUAL R3B_SWAP_WANT)
    message(STATUS "R3B: expected to cut ${R3B_SWAP_WANT} plain frame-swap "
                   "entries and cut ${R3B_SWAP_CUT}. If slice_scene1.txt "
                   "stopped listing it the hostgen copy is still added and the "
                   "link will say so; if a SECOND slice started listing it, "
                   "this cut missed it and the link will say that too")
endif()

# run link60 lane SC1: THE SCENE 1 INTERIM, AND ITS OWN RETIREMENT SWITCH.
#
# func_ov007_020c9688 is scene 1's blocker and it is a hole in the DECOMP:
# config/arm9/overlays/ov007/delinks.txt runs one block to end:0x020c9688 and
# starts the next at 0x020c9988, so nothing covers the 768 bytes between them
# and no src TU exists. hal/scene_boot.cpp stood a trap there, the trap returned
# 0 six times and func_ov007_020ade58 dereferenced one of them.
#
# port/unmatched/Ov007_OamCellBank_020c9688.cpp is a host transcription of the
# ROM's instructions at that address. Read its banner for the derivation; read
# this block for why it cannot outstay its welcome.
#
# THE GUARD IS THE POINT. An interim that has to be remembered is an interim
# that gets forgotten, and the failure mode is not a link error, it is a host
# body quietly winning over a matched one and the port silently ceasing to be
# the decomp. So the list is EMPTY the moment src/ has the match, whichever
# extension the decomp lands it under, and the matched TU arrives on its own
# through slice_ov007.txt. Configure is where that gets noticed, and the STATUS
# line below says which state this tree is in every time it runs.
set(SC1_INTERIM_SOURCES "")
if(EXISTS "${PORT_REPO_ROOT_ABS}/src/func_ov007_020c9688.c"
   OR EXISTS "${PORT_REPO_ROOT_ABS}/src/func_ov007_020c9688.c")
    message(STATUS "SC1: src/func_ov007_020c9688 EXISTS, the scene 1 interim is "
                   "RETIRED and port/unmatched/Ov007_OamCellBank_020c9688.cpp "
                   "is deletable")
else()
    message(STATUS "SC1: func_ov007_020c9688 still unmatched, scene 1 running "
                   "on the host transcription interim")
    list(APPEND SC1_INTERIM_SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Ov007_OamCellBank_020c9688.cpp")
endif()

# run mg15 lane TITLETEX: THE SECOND SCENE 1 INTERIM, ON SC1's OWN TERMS.
#
# func_ov007_020c4684 is the routine the title screen DRAWS THROUGH -- its
# literal pool is twelve geometry command ports and nothing else -- and
# hal/scene_boot.cpp stood an L2_UNMATCHED trap there that a 300-frame scene-1
# run entered 16,200 times, 54 a frame, returning 0 every time. Nothing the
# title places came out of it. port/unmatched/Ov007_CellQuad_020c4684.cpp is a
# host transcription read off extracted/overlays/overlay_0007.bin at the
# config-aligned base, with all four of its relocations resolved and its
# alignment proven first on its own byte-matched caller.
#
# THE GUARD IS SC1's GUARD, for SC1's reason: an interim that has to be
# remembered is an interim that gets forgotten, and the failure mode is a host
# body quietly winning over a matched one. The list is EMPTY the moment src/
# has the match, whichever extension it lands under, and the matched TU then
# arrives on its own through slice_ov007.txt.
if(EXISTS "${PORT_REPO_ROOT_ABS}/src/func_ov007_020c4684.c"
   OR EXISTS "${PORT_REPO_ROOT_ABS}/src/func_ov007_020c4684.c")
    message(STATUS "TITEX: src/func_ov007_020c4684 EXISTS, the title's "
                   "polygon-submitter interim is RETIRED and "
                   "port/unmatched/Ov007_CellQuad_020c4684.cpp is deletable")
else()
    message(STATUS "TITEX: func_ov007_020c4684 still unmatched, the title "
                   "screen draws through the host transcription interim")
    list(APPEND SC1_INTERIM_SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Ov007_CellQuad_020c4684.cpp")
endif()

# run push0829 lane TITLE-DOODLE: THE DOODLE CANVAS INTERIM, ON SC1's OWN TERMS.
#
# func_ov007_020b8fd4 is the title-screen DOODLE CANVAS/PAPER renderer -- its one
# caller src/func_ov007_020bcf90.c calls it in outer states 1..4 (the draw
# screen) right before the seated stroke hub func_ov007_020b91b4. hal/scene_boot.
# cpp stood an L2_UNMATCHED trap there. Measured on this tree, scene 1 driven into
# the doodle screen (a tap chain that reaches title element state 2 with screen
# mode data_ov007_0210342c+0x20 == 1): the trap was entered 402 times over 1200
# frames and returned 0 every time, so the paper was never sized and the two
# billboards were never positioned. port/unmatched/Ov007_DoodleCanvas_020b8fd4.cpp
# is read off the fanout-opus near-miss draft, re-verified against
# extracted/overlays/overlay_0007.bin at the config-aligned base: EVERY store and
# EVERY call target matches the ROM byte for byte (of 36 residual diffs, 0 are a
# str/stm/bl/b), so only the register coloring is unmatched and the observable
# behaviour is the ROM's exactly.
#
# THE GUARD IS SC1's GUARD, for SC1's reason: the list is EMPTY the moment src/
# has the byte-match, whichever extension it lands under, and the matched TU then
# arrives on its own through slice_ov007.txt. The trap line
# L2_UNMATCHED(func_ov007_020b8fd4) in hal/scene_boot.cpp is removed in the same
# change; leaving it would be an LNK2005 against this body.
if(EXISTS "${PORT_REPO_ROOT_ABS}/src/func_ov007_020b8fd4.c"
   OR EXISTS "${PORT_REPO_ROOT_ABS}/src/func_ov007_020b8fd4.c")
    message(STATUS "DOODLE: src/func_ov007_020b8fd4 EXISTS, the doodle canvas "
                   "interim is RETIRED and "
                   "port/unmatched/Ov007_DoodleCanvas_020b8fd4.cpp is deletable")
else()
    message(STATUS "DOODLE: func_ov007_020b8fd4 still unmatched, the title "
                   "doodle canvas draws through the host transcription interim")
    list(APPEND SC1_INTERIM_SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Ov007_DoodleCanvas_020b8fd4.cpp")
endif()

# run link60 lane PC2: SCENE 1'S NEXT BLOCKER, AND THE PREDICATE THAT NAMES IT.
#
# src/func_ov007_020b2998.c landed and the +0xF4 field is written, so the run
# walks past the old stop and dies one call chain further on, inside a pair of
# matched TUs. It is NOT a missing body this time. It is an ARM REGISTER
# RIDE-THROUGH the host ABI cannot carry:
#
#   src/func_ov007_020b0a20.c    calls func_ov007_020be980(scene->f_100, 1, 0)
#   src/func_ov007_020be980.c    DEFINES it as (int r0) and declares its own
#                                callee `extern int func_ov007_020bc3dc(int)`
#   src/func_ov007_020bc3dc.c    DEFINES it as (void *c, int i, int a2)
#
# On ARM all three are byte-faithful and the middle frame never touches r1 or
# r2, so the 1 and the 0 ride through it into the callee. On MSVC every
# argument is a stack slot, the middle frame pushes one, and the callee reads
# two slots nobody wrote.
#
# WHY A PREDICATE AND NOT A STRING SOMEBODY GREPS FOR. port/tools/battery.py's
# scene-1 row keys on a marker, and a marker that always prints would let ANY
# InitResources fault read as this one. This asks the source fact that IS the
# blocker: the middle TU's one-parameter declaration of its own callee. Change
# that line, or host-copy the seam the way port/CMakeLists.txt answers the
# other ARM ride-throughs, and the marker leaves the build in the configure
# that notices -- the same shape as SC1's interim switch above.
#
# THE ONE THING THIS PREDICATE DOES NOT DO, said plainly: it is armed at scene
# entry, not at the seam, because every frame between ti_init and the fault is
# a matched TU and the port owns none of them. So a DIFFERENT fault inside
# InitResources would still carry the marker. It is tighter than nothing and
# looser than the trap print it replaces, and the row says so too.
#
# run link60 lane RT1 AMENDS THE PREDICATE, and the amendment is the half the
# block above promised and did not implement. PC2 wrote "change that line, OR
# host-copy the seam", but only the first branch was detectable: the regex asks
# the source file, and the source file is untouched by a displacement. Taken
# literally after the seat, it would have kept asserting a blocker that no
# longer ships.
#
# So the predicate now asks the question it always meant: IS THE ONE-PARAMETER
# BODY IN THIS BINARY. That is two facts, and both are read rather than
# remembered -- the declaration still in src/ (unchanged, because the byte gate
# owns that file) AND the TU still in the port's ov007 slice
# (RT1_BE980_DISPLACED, set by the cut itself a few hundred lines up). Either
# one alone is a half-truth. Together they re-arm the marker by themselves if a
# later lane puts the TU back without fixing the seam, which is the property
# that makes this a guard and not a comment.
set(PC2_RIDETHROUGH_DEFS "")
port_configure_input("${PORT_REPO_ROOT_ABS}/src/func_ov007_020be980.c")
file(STRINGS "${PORT_REPO_ROOT_ABS}/src/func_ov007_020be980.c"
     PC2_RIDETHROUGH_DECL
     REGEX "^[ \t]*extern[ \t]+int[ \t]+func_ov007_020bc3dc[ \t]*\\([ \t]*int[ \t]*\\)[ \t]*;")
if(PC2_RIDETHROUGH_DECL AND RT1_BE980_IN_SLICE AND NOT RT1_BE980_DISPLACED)
    message(STATUS "PC2: func_ov007_020be980 still declares its callee with one "
                   "parameter and its TU is still built, so scene 1's "
                   "ride-through blocker STANDS and the battery marker is armed")
    list(APPEND PC2_RIDETHROUGH_DEFS "PORT_OV007_RIDETHROUGH_UNSEATED=1")
elseif(RT1_BE980_DISPLACED)
    message(STATUS "RT1: func_ov007_020be980 is DISPLACED to "
                   "unmatched/Ov007_RideThrough_020be980.cpp, so the "
                   "one-parameter body is not in this binary and scene 1's "
                   "ride-through marker is RETIRED")
elseif(NOT RT1_BE980_IN_SLICE)
    # Retired for the wrong reason, and the block above has already said so.
    # Kept as its own branch rather than folded into the declaration case
    # because "the marker is off because the seam is fixed" and "the marker is
    # off because the TU vanished and the link is about to fail" are opposite
    # states, and one message covering both is how a broken tree reads healthy.
    message(STATUS "RT1: func_ov007_020be980 is not in the slice at all, so the "
                   "ride-through marker is RETIRED but NOT because the seam was "
                   "seated -- see the RT1 slice warning above, the link fails "
                   "before scene 1 can be judged")
else()
    message(STATUS "PC2: func_ov007_020be980's one-parameter callee declaration "
                   "is GONE, scene 1's ride-through marker is RETIRED -- if the "
                   "scene now runs, delete its SCENE_BLOCKED row")
endif()

# run link60 lane RT1: SCENE 1'S NEXT BLOCKER, AND IT IS THE SAME DEFECT CLASS
# ONE FRAME DEEPER. The seam above is seated and the scene now walks past it,
# reaching twenty-four calls into func_ov007_020ae834 that no earlier run
# reached, and dies on another ARM register that no host frame carries:
#
#   src/func_ov007_020add3c.c   extern int func_ov007_020ae558(void);
#                               func_ov007_020ae558();          <- passes none
#   src/func_ov007_020ae558.c   int func_ov007_020ae558(char *self)
#
# On ARM that is exact. The ROM's func_ov007_020add3c does `push {r4, lr} /
# mov r4, r0 / bl func_ov007_020ae558` and never writes r0 in between, so its
# OWN incoming argument is still sitting in r0 when the callee reads it. Both
# TUs are matched and both are right. On MSVC the caller pushes nothing and the
# callee reads [ebp+8], which is the caller's saved esi.
#
# THE DIFFERENCE FROM THE SEAM ABOVE, and it is the reason this gets its own
# marker rather than a reworded one: that seam lost values a MIDDLE frame was
# handed, and the frame to displace was the middle one. This one loses a value
# the CALLER already owns and simply does not pass, so the frame where
# information is destroyed is func_ov007_020add3c, not the callee. The seat is
# derived in port/ov007_seat.txt section 5c and deliberately NOT taken here:
# displacing a matched TU picks which of two matched bodies stops being the
# decomp, and this file's own precedent is that a review rules that and a lane
# executes it. This lane's brief was the seam above and this row.
#
# SAME PREDICATE SHAPE, for the same reason: the source fact that IS the
# blocker, plus whether the TU carrying it is actually in this binary.
set(RT1_AE558_DEFS "")
port_configure_input("${PORT_REPO_ROOT_ABS}/src/func_ov007_020add3c.c")
file(STRINGS "${PORT_REPO_ROOT_ABS}/src/func_ov007_020add3c.c"
     RT1_AE558_DECL
     REGEX "^[ \t]*extern[ \t]+int[ \t]+func_ov007_020ae558[ \t]*\\([ \t]*void[ \t]*\\)[ \t]*;")
if(RT1_AE558_DECL AND RT1_ADD3C_IN_SLICE AND NOT AE1_ADD3C_DISPLACED)
    message(STATUS "RT1: func_ov007_020add3c still calls func_ov007_020ae558 "
                   "with no arguments and its TU is still in the slice, so "
                   "scene 1's implicit-r0 blocker STANDS and the battery "
                   "marker is armed")
    list(APPEND RT1_AE558_DEFS "PORT_OV007_AE558_UNSEATED=1")
elseif(AE1_ADD3C_DISPLACED)
    message(STATUS "AE1: func_ov007_020add3c is DISPLACED to "
                   "unmatched/Ov007_ImplicitR0_020add3c.cpp, which forwards "
                   "its own argument, so the no-argument call is not in this "
                   "binary and scene 1's implicit-r0 marker is RETIRED")
elseif(NOT RT1_ADD3C_IN_SLICE)
    # Retired for the wrong reason, and the AE1 slice warning above has
    # already said so. Kept as its own branch for the reason the be980 block
    # gives: "the marker is off because the seam is fixed" and "the marker is
    # off because the TU vanished and the link is about to fail" are opposite
    # states, and one message covering both is how a broken tree reads healthy.
    message(STATUS "AE1: func_ov007_020add3c is not in the slice at all, so "
                   "the implicit-r0 marker is RETIRED but NOT because the seam "
                   "was seated -- see the AE1 slice warning above, the link "
                   "fails before scene 1 can be judged")
else()
    message(STATUS "RT1: func_ov007_020add3c's no-argument call to "
                   "func_ov007_020ae558 is GONE from this binary, scene 1's "
                   "implicit-r0 marker is RETIRED -- if the scene now runs, "
                   "delete its SCENE_BLOCKED row")
endif()

# run mg15 lane IMPLICITR: THE SEAM BEHIND THE TOUCH-TO-START HANDOFF, and the
# predicate exists to answer ONE question a later lane will make stale.
#
# The displacement above is the fix. The thing that can rot is the reason for
# it: src/func_ov007_020c2b9c.c defines the body `void`, and this lane MEASURED
# that spelling the return there (`void *` + `return r;`) still matches, 0 of 23
# words at 2004/b56 with strict relocs. That is the MP1 shape -- run mg15 lane
# MP1 retired two host copies the moment include/decl_common.h could carry the
# fix -- and if a later lane takes it, this host copy becomes dead weight that
# nothing in the build would complain about.
#
# So the predicate reads the SOURCE FACT that makes the displacement necessary
# (the `void` definition still in src/, which the byte gate owns) against
# whether the cut ran. It is a STATUS line and not a battery define on purpose:
# there is no SCENE_BLOCKED row for this seam to retire, and a define nothing
# consumes is a marker that cannot fire.
port_configure_input("${PORT_REPO_ROOT_ABS}/src/func_ov007_020c2b9c.c")
file(STRINGS "${PORT_REPO_ROOT_ABS}/src/func_ov007_020c2b9c.c"
     IR1_C2B9C_VOID_DEF
     REGEX "^[ \t]*void[ \t]+func_ov007_020c2b9c[ \t]*\\(")
if(IR1_C2B9C_VOID_DEF AND IR1_C2B9C_DISPLACED)
    message(STATUS "IR1: func_ov007_020c2b9c is DISPLACED to "
                   "unmatched/Ov007_ImplicitReturn_020c2b9c.cpp, which spells "
                   "the return its two matched callers already declare, so the "
                   "title's post-handoff fault at func_ov007_020c2acc+0x3f is "
                   "not in this binary")
elseif(IR1_C2B9C_VOID_DEF AND IR1_C2B9C_IN_SLICE)
    message(WARNING "IR1: func_ov007_020c2b9c still DEFINES itself void and its "
                    "TU is back in the build, so both matched callers read an "
                    "EAX nobody set and the title faults after touch-to-start. "
                    "Restore the cut in the slice loop above")
elseif(NOT IR1_C2B9C_VOID_DEF)
    # The good ending, and it is a DIFFERENT tree from the one above rather
    # than the same one worded differently: the decomp itself now returns the
    # object, so the host copy has nothing left to add and its CMake block plus
    # port/unmatched/Ov007_ImplicitReturn_020c2b9c.cpp should go, the way MP1
    # deleted Comms_SlotIndex_*.cpp.
    message(STATUS "IR1: src/func_ov007_020c2b9c.c no longer defines itself "
                   "void, so the implicit-return seam is fixed in the DECOMP "
                   "and this displacement is REDUNDANT -- retire it (delete the "
                   "cut in the slice loop and the host copy)")
endif()

# run link100 lane FILESEL2: THE FILE SELECT'S OWN IMPLICIT r0, FIXED IN THE
# DECOMP AND HELD THERE BY THIS GUARD.
#
# src/func_ov007_020c798c.c allocates a 0x14-byte record and hands it to
# func_ov007_020c78b0 to be zeroed. The ROM's branch at 0x020c79b0 passes
# nothing, because the allocation is still in r0 from func_ov007_020c3df4's
# return and the callee reads it there, so the matched TU used to declare the
# callee `(void)` and call it with no argument. On MSVC that reads an unwritten
# stack slot: it read zero, MultiStore_Int wrote twenty bytes over address 0,
# the quarantine net froze the title scene on the frame the file select comes
# up, and both screens went flat for the rest of the run. Under
# SM64DS_FAULTS_FATAL=1 the same build died with 0xC0000005 instead.
#
# THE FIX IS IN src/, not in a displacement. Spelling the argument costs no
# instruction on ARM and func_ov007_020c798c still byte-matches at 2004/b56
# with strict relocs, which is the MP1/mg16 shape -- the same reason the two
# retirements above could happen. What this guard protects is that spelling.
#
# IT REFUSES rather than warning. A warning is right for a displacement that
# has become redundant; this one is right for a defect that kills the process
# on a screen every player reaches, and the regex is over the ONE call site
# there is (checked by scanning ov007 for every branch to 0x020c78b0, not by
# reading a comment). Break the spelling and the build stops at configure with
# the reason, instead of a fortnight later on somebody's file select.
port_configure_input("${PORT_REPO_ROOT_ABS}/src/func_ov007_020c798c.c")
file(STRINGS "${PORT_REPO_ROOT_ABS}/src/func_ov007_020c798c.c"
     FS2_C798C_VOID_CALL
     REGEX "func_ov007_020c78b0[ \t]*\\([ \t]*(void)?[ \t]*\\)[ \t]*;")
if(FS2_C798C_VOID_CALL)
    message(FATAL_ERROR
            "FILESEL2: src/func_ov007_020c798c.c declares or calls "
            "func_ov007_020c78b0 with no argument again. On ARM the ROM leaves "
            "the allocation in r0 across that branch; on this host the callee "
            "reads an unwritten stack slot and MultiStore_Int writes 0x14 bytes "
            "over whatever it finds -- address 0 in every run measured, which "
            "faults inside the actor walk and freezes the title scene on the "
            "frame the file select appears. Pass the record: "
            "`extern void func_ov007_020c78b0(void *block);` and "
            "`func_ov007_020c78b0(t);`. That spelling still byte-matches at "
            "2004/b56 with strict relocs, so there is nothing to trade.")
endif()

# run link60 lane AE1: SCENE 1'S NEXT BLOCKER, AND IT IS A NEW DEFECT CLASS.
#
# The implicit-r0 seam above is seated, InitResources FINISHES, and Behavior
# runs 299 clean ticks. What is left is entirely inside the scene's own Render
# slot, and it is not an arity disagreement at all. It is a CALLING CONVENTION:
#
#   src/func_ov007_020bbff0.c   declares the FLAT Itanium name
#                               _ZN15ModelComponents6RenderEP9Matrix4x3P7Vector3
#                               as (void *, void *, void *) and calls it with
#                               three cdecl pushes
#   the definition             port/unmatched/ModelComponents_Render.cpp's
#                               `void ModelComponents::Render(Matrix4x3*,
#                               Vector3*)`, a real C++ member, which MSVC emits
#                               as __thiscall: `this` arrives in ECX
#
# and the flat name reaches the mangled one through an /alternatename in
# hal/scene_boot.cpp. AN ALIAS CANNOT CHANGE A CALLING CONVENTION -- that
# sentence is already in that file's own banner, next to the Scene::SetFaders
# FACE that exists for exactly this reason -- so the caller's three pushes land
# one slot off and `this` is whatever ECX happened to hold.
#
# WHY THE PREDICATE IS NOT THE ONE ABOVE, and this is the part worth reading.
# The two seams before this were fixed by DISPLACING a caller, so "is the
# caller's TU in the build" was a fact the fix changed. This seam's expected
# fix is a FACE, which leaves the caller's TU and its declaration exactly where
# they are. A declaration-plus-membership predicate would therefore survive its
# own fix and go on asserting a retired blocker -- the identical trap RT1
# caught in PC2's predicate and this lane caught in RT1's, arriving a third
# time from a third direction. So this reads the two facts that the two
# available fixes actually change:
#
#   the ALIAS, still pointing the flat name at a QAE (__thiscall) target.
#     A face stands a real cdecl definition and retires the directive.
#   the CALLER, still compiled into the ov007 slice.
#     A displacement cuts it, exactly like the two above.
#
# Either fix clears this in the configure that notices, and neither can be
# taken without clearing it.
#
# run link60 Stage 5 lane MR1: THE ALIAS FACT IS NOW ANCHORED, and this is the
# hole the AE1 review demonstrated being closed rather than inherited.
#
# file(STRINGS ... REGEX) is a line scanner with no idea what a comment is, so
# the spelling that shipped here matched the directive's TEXT anywhere on a
# line. Section 8 recorded that as "a known hole shipping on purpose" because
# the only fix that would write such a comment had not been taken yet.
#
# THIS COMMIT TAKES IT, so the hole stopped being hypothetical in the same
# change that closes it. The face in hal/scene_boot.cpp records the directive
# it replaces, verbatim, in its evidence header, the way every other retired
# directive in that file is recorded. Under the old spelling that comment kept
# the marker ARMED after a correct fix: a battery row asserting a blocker that
# no longer exists, which is the exact failure the row's own derivation warns
# about.
#
# The anchor is the pragma itself. A directive reaches link.exe only through
# #pragma comment(linker, ...) in a compiled TU (port/tools/alternatename_guard.py
# mechanism (a), and its audit re-derives every run that the port has no
# mechanism (b)), so requiring the line to BE that pragma is not a heuristic
# about comments, it is the same test the linker applies. Leading whitespace is
# allowed because the preprocessor allows it; a `//` or ` * ` in front is not a
# pragma and no longer counts.
#
# WHAT IT STILL DOES NOT COVER, stated rather than left to be discovered: a
# whole pragma sitting inside a /* */ block comment reads as anchored here and
# is not a linker input. That is the same COMMENT GAP alternatename_guard.py
# names in its own docstring and carries one live instance of, so the two tools
# now have the same blind spot instead of two different ones. Closing it needs
# a C tokenizer and neither tool has one.
set(AE1_MCRENDER_DEFS "")
port_configure_input("${CMAKE_CURRENT_SOURCE_DIR}/hal/scene_boot.cpp")
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/hal/scene_boot.cpp"
     AE1_MCRENDER_ALIAS
     REGEX "^[ \t]*#[ \t]*pragma[ \t]+comment[ \t]*\\([ \t]*linker[ \t]*,[ \t]*\"/alternatename:__ZN15ModelComponents6RenderEP9Matrix4x3P7Vector3=\\?Render@ModelComponents@@QAE")
if(AE1_MCRENDER_ALIAS AND AE1_BBFF0_COMPILED)
    message(STATUS "AE1: the flat _ZN15ModelComponents6RenderE... name is still "
                   "aliased onto a __thiscall member and src/func_ov007_020bbff0.c "
                   "still calls it cdecl, so scene 1's Render-slot blocker "
                   "STANDS and the battery marker is armed")
    list(APPEND AE1_MCRENDER_DEFS "PORT_OV007_MCRENDER_UNSEATED=1")
elseif(NOT AE1_MCRENDER_ALIAS)
    message(STATUS "AE1: the flat _ZN15ModelComponents6RenderE... alias onto a "
                   "__thiscall member is GONE, so scene 1's Render-slot marker "
                   "is RETIRED -- if the scene now runs, delete its "
                   "SCENE_BLOCKED row")
else()
    message(STATUS "AE1: src/func_ov007_020bbff0.c is not compiled into the "
                   "ov007 slice, so its cdecl call is not in this binary and "
                   "scene 1's Render-slot marker is RETIRED")
endif()

# Appended, not string-joined: an empty PC2 list concatenated with a non-empty
# RT1 one produces a leading semicolon, and CMake reads that as an empty define
# to pass to the compiler. Every list goes empty the day every seam is seated.
set(SCENE_BOOT_MARKER_DEFS ${PC2_RIDETHROUGH_DEFS} ${RT1_AE558_DEFS}
    ${AE1_MCRENDER_DEFS})
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/scene_boot.cpp"
    PROPERTIES COMPILE_DEFINITIONS "${SCENE_BOOT_MARKER_DEFS}")

# run link60 lane MG2: THE FIRST MINIGAME, WIRED.
#
# dScMgCurling_c is ov006's curling minigame, actor id 0x176 (its spawn symbol
# is dScMgCurling_c_classInit; Shuffle Shell is the localised name of the same
# game). Lane MG1 derived the seat and left it out of every target because the
# link did not close; this lane closes it. The wall MG1 named was the mwcc
# POINTER-TO-MEMBER ABI, and it is answered the way the port has answered it
# twice before: the six dispatching TUs are EXCLUDED from the slice and
# host-copied against an address switch (unmatched/MgBase_StateDispatch.cpp and
# unmatched/MgCurling_StateDispatch.cpp), the way
# unmatched/Player_ChangeState.cpp answers Player::ChangeState.
#
# 281 src TUs: MG1's 276 plus the sixth wave this lane measured. The
# mechanical half of the wall -- the /alternatename rows -- is generated by
# port/tools/facegen.py into hal/scene_mg_faces_gen.cpp and verified by that
# tool rather than hand-written; the rows facegen REFUSED are in
# hal/scene_mg_faces.cpp with the refusal quoted in the banner.
#
# port/mg_fanout_costs.txt is the derivation and the cost model for the other
# twenty-nine; its section 4 carries this lane's measured wall accounting.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_mg1.txt" SLICE_MG1_LINES)
set(SLICE_MG1_SOURCES "")
foreach(line IN LISTS SLICE_MG1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_MG1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ONE .c IN THIS SLICE IS REALLY C++, run mg10 lane F371. Lane CCN's rule was
# followed rather than waited on: the whole slice was swept for the //cpp
# marker and for extern "C", virtual, class and namespace before the first
# build, and src/func_ov004_020ae5c4.cpp is the only hit. It needs C++ for real
# -- the tree's only slot-34 dispatch is spelled through a dummy 35-virtual
# struct, which is how src/func_ov006_020d3ba0.cpp spells its slot-36 dispatch in
# the same class. Same repair as the psy and smartball blocks below.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov004_020ae5c4.cpp"
    PROPERTIES LANGUAGE CXX)

# Gate mg7 (run link100 wave 14, lane SEAT14E, BATCH 4): the ov006 minigame
# table roots. Nine of the batch's ten rows measured as refusals and
# port/slice_mg7.txt carries the reason for each one; six of them are the same
# reason, which is that the ROM's body is already in the binary under the
# consolidated class TU the sync folded it into and the per-function file is
# LNK2005 beside it. The one row that is real is func_ov006_020e1854,
# dScMgCurling_c's pen-drag state, matched by PR #2352 with a delink block at
# 0x020e1854..0x020e1b54 and verified against the cartridge's own pair word at
# 0x0213c2bc. It replaces lane CT1's hand transcription, retired just below.
# The slice rides SCENE_MG_SOURCES so it lands on exactly the three targets the
# transcription rode and no target line changes.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_mg7.txt" SLICE_MG7_LINES)
set(SLICE_MG7_SOURCES "")
foreach(line IN LISTS SLICE_MG7_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_MG7_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# The seat's own files, on the same three targets the scene-1 and ov007 seats
# ride. They are not optional on any of the three: hal/scene_boot.cpp's
# port_scene_classes table now carries the curling row, so every target that
# compiles scene_boot.cpp references port_mg_curling_spawn and
# port_scene_fill_curling by name.
set(SCENE_MG_SOURCES
    hal/scene_mg.cpp hal/scene_mg_faces.cpp hal/scene_mg_faces_gen.cpp
    ${SLICE_MG7_SOURCES}
    # Lane MUS1: the minigame sound record (re-hosted 0x34) and the verbatim
    # ov005 row seeder that gives a direct SM64DS_SCENE minigame boot its music.
    # Rides these same three targets because scene_boot.cpp calls
    # port_scene_mg_seat_sound by name and it defines data_0209b308.
    hal/scene_mg_sound.cpp
    unmatched/MgBase_Slot1.cpp
    unmatched/MgBase_Slot7.cpp unmatched/MgBase_StateDispatch.cpp
    unmatched/MgCurling_StateDispatch.cpp
    # unmatched/MgBase_LangTable.cpp RETIRED (run linkfull, lane RS4PORT): its
    # reason (a fabricated 29-entry initializer) predates main #1557, which
    # made the src table the ROM's template; the port's src is that blob and
    # is back on slice_mg1.txt.
    # Run mg5, lane BASESET. The framework's STATE SETTER, which was the last
    # named trap in the minigame stack and was a FREEZE in a player's hands:
    # _ZN10dMgState_c8SetStateEi set no state, so a class that asked to advance never
    # did. Not optional on any of the three targets and for a stronger reason
    # than the files above it, which is that its symbol is no longer defined
    # anywhere else: hal/scene_mg_faces.cpp's trap is DELETED, and
    # unmatched/MgBase_StateDispatch.cpp calls port_mg_try_base_state by name
    # from port_mg_call0, so a target that compiles the dispatch and not this
    # fails the link twice over.
    #
    # It no longer defines func_ov004_020b7460, the slot 12 tail-jump veneer:
    # the src TU takes the pointer its two callers pass (main #3166) and is back
    # on port/slice_mg1.txt (run linkfull, lane ASMCPORT).
    unmatched/MgBase_StateSetter.cpp
    # unmatched/MgBase_Slot5.cpp RETIRED (run linkfull, lane RS2PORT). It was
    # dScMgBase_c slot 5's host copy (run mg5, lane BASESET): the src TU called
    # func_0203cbc0 with no argument where the ROM frees data_ov004_020beb60
    # through r0. src/minigames/d_s_mg_base.cpp passes it now (main
    # 59013376ce's one call, taken into the port's text of the TU), and the
    # flat slot-5 name hal/scene_mg.cpp calls is a reverse face in
    # port/faces_sync.txt.
    # Lane CT1's dScMgCurling_c twenty-fifth state, unmatched/MgCurling_State_020e1854.cpp,
    # WAS HERE AND IS RETIRED (run link100 wave 14, lane SEAT14E). "The one with
    # no src TU" is what its line said and it is no longer true: PR #2352
    # (86a6e696d) matched 0x020e1854 and this tree has the delink block, so
    # src/func_ov006_020e1854.c is on port/slice_mg7.txt above instead. The
    # reason the line gave for riding these three targets still holds and is
    # still satisfied -- the dispatch reaches the state only through its switch,
    # and hal/scene_mg_faces.cpp, which is already on all three, now defines
    # port_mg_curling_st_020e1854 as the bridge into the matched body.
    # Lane CUR2: dScMgCurling_c's two shell-against-shell collision bodies,
    # the other two ov006 addresses with no src TU. Same three targets and the
    # same reason as the state above: hal/scene_mg_faces.cpp now calls
    # port_mg_curling_collide_020e1dc8 and _020e20bc by name from the faces
    # the matched physics TUs link against, so a target that compiles the
    # faces and not these fails the link on both symbols.
    unmatched/MgCurling_Collide_020e1dc8.cpp
    unmatched/MgCurling_Collide_020e20bc.cpp
    # Run mg5, lane PCH: dScMgPachinko_c (id 0x170, scene 368). Same three
    # targets and the same reason as every file above -- hal/scene_boot.cpp's
    # port_scene_classes[] now carries the 368 row, so every target that
    # compiles scene_boot.cpp references port_mg_pachinko_spawn and
    # port_scene_fill_pachinko by name, and hal/scene_mg.cpp section 8
    # references port_mg_pachinko_d0, the state counters and the traps.
    #
    # THE STATE DISPATCH IS NOT OPTIONAL EITHER, and for the reason the CT1
    # comment above gives about MgCurling_State_020e1854: this class's five
    # dispatching TUs are EXCLUDED from slice_pch.txt and defined only in
    # MgPachinko_StateDispatch.cpp, so a target that takes the slice and not
    # the dispatch fails the link on all five func_ov006_* names.
    unmatched/MgPachinko_StateDispatch.cpp
    unmatched/MgPachinko_Dtor.cpp
    unmatched/MgPachinko_Traps.cpp
    unmatched/MgPachinko_Faces.cpp
    # RETIRED run link100 wave 15, lane SEAT15D. src/func_ov006_020fa7b8.cpp
    # now spells `extern void* data_ov006_0213ac24;`, which is the one token
    # this host copy existed to change, so the matched TU is taken instead --
    # see port/slice_l15mg.txt. Put this line back only together with the
    # slice line, or the link gets two definitions of func_ov006_020fa7b8.
    # unmatched/MgPachinko_OamRender.cpp
    # Run mg5, lane HISCORE: the class's scoring tick, and the one argument
    # ride-through it owes. func_ov006_020fb7e0 calls the award routine
    # func_ov006_020fbb2c with two arguments where the definition takes three,
    # because the ROM carries the points in r2 out of the ldrh that makes the
    # != 0 test. Same shape and same ruling as unmatched/MgFlower_InitScore.cpp.
    # REPLACES its src TU -- src/func_ov006_020fb7e0.c is out of slice_pch.txt
    # -- so it is not optional on any target that takes the slice, exactly like
    # the state dispatch above.
    unmatched/MgPachinko_Award.cpp
    # unmatched/MgHud_HighScore.cpp RETIRED (run linkfull, lane RS4PORT): main
    # #3107 passes the HIGH SCORE drawer the full 32-bit word (lane HSDISP's
    # 999999 fix, now in the matched source), so src/func_ov006_020fba48.c is
    # back on slice_pch.txt.
    # Run mg5, lane WTIMER: the minigame HUD's SCALED NUMBER drawer, the third
    # of the three ov004 addresses with no delink block and no src TU, and the
    # reason the "Wanted!" countdown never appeared. Same three targets and the
    # same reason as the two curling collision copies above: the faces in
    # hal/scene_mg_faces.cpp now call port_mg_hud_scaled_number_020b2220 by
    # name, so a target that compiles the faces and not this file fails the
    # link on that symbol. Replaces no src TU, because there is none.
    unmatched/MgHud_ScaledNumber.cpp
    # Run mg6, lane LKT: dScMgPachinko2_c (id 0x171, scene 369). Same three
    # targets and the same reason as every file above -- hal/scene_boot.cpp's
    # port_scene_classes[] now carries the 369 row, so every target that
    # compiles scene_boot.cpp references port_mg_pachinko2_spawn and
    # port_scene_fill_pachinko2 by name, and hal/scene_mg.cpp's LKT banner
    # references port_mg_pachinko2_d0, the state counters and the trap.
    #
    # THE STATE DISPATCH IS NOT OPTIONAL EITHER, for the reason the CT1 and PCH
    # comments above give: this class's THREE dispatching TUs are EXCLUDED from
    # slice_lkt.txt and defined only in MgPachinko2_StateDispatch.cpp, so a
    # target that takes the slice and not the dispatch fails the link on
    # func_ov006_020fff84, _0210246c and _02102e8c.
    #
    # THE TRAP FILE IS GONE, run mg7 lane L369. unmatched/MgPachinko2_Traps.cpp
    # existed for exactly one symbol -- func_ov006_0210076c, the per-entry
    # follow-up the fifteen-state dispatcher calls after every dispatch it
    # makes -- and that address is decompiled now and rides slice_lkt.txt as an
    # ordinary src TU. A trap standing beside a real definition is a duplicate
    # symbol rather than a safety net, so the file is deleted, not emptied.
    unmatched/MgPachinko2_StateDispatch.cpp
    unmatched/MgPachinko2_Dtor.cpp
    # The class-vtable name face. src/d_s_mg_pachinko2.c writes
    # _ZTV16dScMgPachinko2_c, which no config defines, so the slice does not
    # link without this file's one /alternatename row.
    unmatched/MgPachinko2_Faces.cpp)

# Lane LINKMG: dScMgBase_c slots 29 and 30 come back as their MATCHED TUs.
# unmatched/MgBase_DeclConflict.cpp carried src/_ZN11dScMgBase_c25OnAimedAtWithEggReturnVecEv.cpp and
# src/_ZN11dScMgBase_c16OnAimedAtWithEggEv.cpp with one token changed each, because both include
# decl_common.h, which declares them (void*) while the TUs define them (char*)
# and (Obj*) -- error C2733 under MSVC. That is exactly the shape hostgen's
# HEADER_SHADOW already answers for func_ov002_020cfbdc, func_ov102_0214b248
# and _ZN8daEyBm_c10HurtPlayerEv: the header's declaration of the TU's OWN name is
# hidden across the include, the definition keeps its src spelling, and every
# caller still sees the header's (void*). Same C linkage, same 4-byte argument,
# so nothing at the call site moves. The 18 MMIO derefs in the two bodies come
# out as NTR_MMIO proxies, which for DISPCNT/POWCNT1 land on the same mapped
# register page the raw writes did (ntr/io.cpp models no side effect for either).
# src/ is untouched; the host-copy file is deleted rather than left inert.
#
# SIX MORE, the OPEN-CODED dispatchers (lane LINKMG, review F1). Their src TUs
# spell the mwcc pair as two plain ints and decode it by hand, so MSVC compiles
# them as they stand; the only wall is the call through the decoded DS code
# address, and tools/hostgen.py's MG_PMF_CALL table swaps exactly that one
# line for the class's own seam (port_mg_pachinko_call1,
# port_mg_bomroom_opencoded_call0, port_mg_panel_call0/1). Their host copies
# are deleted from the three Mg*_StateDispatch.cpp files; the address switches
# those files keep are what the seam dispatches through. func_ov006_02106ca4
# is the one .c of the six, hence the EXISTS test.
# _ZN11dScMgBase_c16OnAimedAtWithEggEv LEFT THIS LIST at the main -> port sync
# (lane SYNC5). Its src TU is quarantined for C2561 -- main's body takes a bare
# `return;` out of an int function, which is a mwccarm extension and ill-formed
# C++ -- and a generated copy of a quarantined TU is a compile of a body no
# target wants: the generation failed on the same C2561, because hostgen
# rewrites declarations, not statements. decomp_side.md item 9 is the ask.
set(SCENE_MG_HOSTGEN_SYMS _ZN11dScMgBase_c25OnAimedAtWithEggReturnVecEv
    func_ov006_020fc7d0 func_ov006_020fe248 func_ov006_020fda7c
    func_ov006_020d8f98)
# TWO PANEL ENTRIES LEFT THIS LIST 2026-09-13 (lane SYNC3).
# _ZN12dScMgPanel_c8BehaviorEv and func_ov006_02106ca4 are both inside
# src/actors/dScMgPanel_c.cpp on main, which is substituted WHOLE at the top of
# this file -- it also carries THIRTY-ONE MMIO derefs (both engines' DISPCNT and
# BGxCNT, and the blend registers) that would otherwise latch in the mapped I/O
# window, and a third dispatch site, func_ov006_02106bc0's, that the port never
# had a file for. The port branch's own src/func_ov006_02106ca4.c, which this
# list used to name, is a SECOND definition of a symbol main's TU also defines,
# so it leaves the build with the entry: one body, out of the decomp's own TU.
foreach(sym IN LISTS SCENE_MG_HOSTGEN_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND SCENE_MG_SOURCES "${sym_out}")
endforeach()

# THE DELETING DESTRUCTOR SPELLS ITS OWN TABLE AS THE SHARED PLACEHOLDER `VT`.
# src/_ZN14dScMgCurling_cD0Ev.cpp is dScMgCurling_c's slot 17 and its body is
# `t[0] = (int)VT;`, but hal/cxx_aliases.cpp binds bare VT to
# _data_ov002_021081e4 -- the ENEMY base table, a whole class wrong for a
# minigame scene object. unmatched/MgPachinko_Dtor.cpp found this on curling's
# seat while repairing the identical defect on pachinko's slot 17 and reported
# it rather than touching another lane's file ("THE SAME DEFECT IS LIVE ON
# CURLING'S SEAT TODAY and this lane did not fix it"). Run mg6, lane VTF, is
# that repair, and it takes the same rename dScMgLuigi_c's slot 17 takes below.
#
# THE ADDRESS IS THE BODY'S OWN LITERAL POOL, disassembled out of
# extracted/overlays/overlay_0006.bin at that overlay's 0x020bfec0 base rather
# than read off a name. The two-word pool sits at the end of the 0x38 body:
#   0x020e0660  E59F1024  ldr r1,[pc,#0x24] -> 0x020e068c
#   0x020e0668  E5841000  str r1,[r4]          the vptr store
#   0x020e068c  0213C304  <- THIS, dScMgCurling_c's own table
#   0x020e0690  020A0EAC  <- the game heap word, loaded BY VALUE at 0x020e0678
# config/arm9/overlays/ov006/relocs.txt agrees on both words
# (from:0x020e068c kind:load to:0x0213c304, from:0x020e0690 to:0x020a0eac), and
# the unmarked D2 sibling _ZN14dScMgCurling_cD1Ev pools the same 0213C304 at
# 0x020e0658, which confirms the table without going through this body at all.
#
# HEAP IS DELIBERATELY NOT RENAMED. The second pool word is 020A0EAC, exactly
# what cxx_aliases.cpp already binds _HEAP to, so that half is right as it
# stands and only VT was wrong.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN14dScMgCurling_cD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=data_ov006_0213c304")

# Run mg5, lane PCH. dScMgPachinko_c's own closure, the second minigame class.
# 65 src TUs in wave 1: 59 ov006 and 6 ov004. The arm9 half is deliberately not
# listed -- port/mg_fanout_costs.txt section 5's /OPT:REF argument -- and the
# waves the linker asks for are appended to slice_pch.txt with the wave they
# arrived in named, which is section 10's method.
#
# port/slice_pch.txt is the derivation: the two-root closure walk, the three
# width checks that keep this table at 36 slots, the `::*` sweep that found
# exactly two pointer-to-member TUs in the class's 623-TU closure, and the
# eight ov006 addresses with no source at all.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pch.txt" SLICE_PCH_LINES)
set(SLICE_PCH_SOURCES "")
foreach(line IN LISTS SLICE_PCH_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PCH_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Run mg6, lane LKT. dScMgPachinko2_c's own closure, the SIBLING of the class
# above in both name and ROM data adjacency. 64 src TUs: 63 ov006 (62 in wave 1
# plus the one delinks join miss, src/func_ov006_02103ac0.c) and 1 ov004.
# The arm9 half is deliberately not listed -- port/mg_fanout_costs.txt
# section 5's /OPT:REF argument -- and the waves the linker asks for are
# appended to slice_lkt.txt with the wave they arrived in named, which is
# section 10's method.
#
# port/slice_lkt.txt is the derivation: the five-root closure walk, the FOUR
# width checks that keep this table at 36 slots (the fourth being the ROM's own
# relocation count inside the span), the ::* sweep that found exactly three
# pointer-to-member TUs in this class's closure and seven more that the
# framework already owns, and the five ov006 addresses with no source at all.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_lkt.txt" SLICE_LKT_LINES)
set(SLICE_LKT_SOURCES "")
foreach(line IN LISTS SLICE_LKT_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_LKT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Run mg5, lane LUI: dScMgLuigi_c, actor id 0x16e = scene 366, "Wanted!".
#
# ONE VARIABLE FOR THE SLICE AND THE HOST COPY, for the reason the fader and
# NFS seats below give: the two are not separable. Six of the slice's TUs are
# host-copied in unmatched/MgLuigi_StateDispatch.cpp because they dispatch an
# mwcc member pointer, twenty of the slice's TUs are reachable ONLY through
# that file's address switch, and hal/scene_boot.cpp's port_scene_classes row
# names port_mg_luigi_spawn and port_scene_fill_luigi, so every target that
# compiles scene_boot.cpp needs the whole set or the link fails.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_lui.txt" SLICE_LUI_LINES)
set(SLICE_LUI_SOURCES unmatched/MgLuigi_StateDispatch.cpp
                      unmatched/MgLuigi_Faces.cpp)
foreach(line IN LISTS SLICE_LUI_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_LUI_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# THE DELETING DESTRUCTOR SPELLS ITS OWN TABLE AS THE SHARED PLACEHOLDER `VT`.
# src/actors/dScMgLuigi_c.cpp is `t[0] = (int)VT;` and hal/cxx_aliases.cpp binds
# bare VT to _data_ov002_021081e4, the ENEMY base table, with a comment saying
# a second VT-spelling TU cannot join a target that links its one reader. This
# is such a TU, so it is renamed onto its own table the way the four D0 bodies
# further down this file are. The address is the body's OWN literal pool, read
# out of extracted/overlays/overlay_0006.bin: 0x020efc60 holds 0213CF10.
# HEAP is deliberately NOT renamed -- the second pool word at 0x020efc64 is
# 020A0EAC, the game heap cxx_aliases.cpp already binds it to.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/dScMgLuigi_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=data_ov006_0213cf10")

# Gate SMB: dScMgSmartball_c, actor id 0x178 (scene 376), the SECOND minigame
# class. Run mg5, lane SMB. Spawn symbol dScMgSmartball_c_classInit, after the
# two menu games one class serves; the ROM's RTTI at 0x0213ec7c reads
# "16dScMgSmartball_c" and every file it loads is /MG/d_2d_mg_smart_ball_*.
#
# 74 src TUs and 41 of them are new. The whole ov004 half and the one ov001
# line are already in slice_mg1.txt and CMake dedupes identical absolute paths,
# so the marginal compile cost is the 41 ov006 lines. That ratio is the
# fan-out's own headline: the framework is paid and a class costs its own
# closure.
#
# THIS CLASS HAS NO POINTER-TO-MEMBER STATE MACHINE, so nothing here needs the
# address-switch treatment MgBase_StateDispatch.cpp and
# MgCurling_StateDispatch.cpp give curling. The three measurements behind that
# claim are in port/slice_smb.txt; the one that matters here is that a
# member-pointer sweep of all 76 TUs the closure reaches hits exactly one file,
# src/_ZN10dMgState_c8SetStateEi.cpp, which is the FRAMEWORK's state setter. It stays
# excluded from every slice; run mg5 lane BASESET replaced the MG1 block's trap
# with the host copy unmatched/MgBase_StateSetter.cpp, which this slice
# inherits along with the rest of the framework.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_smb.txt" SLICE_SMB_LINES)
set(SLICE_SMB_SOURCES "")
foreach(line IN LISTS SLICE_SMB_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SMB_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# The seat's own two files, on the same three targets every scene seat rides.
# Not optional on any of them: hal/scene_boot.cpp's port_scene_classes table
# carries the 376 row, so every target that compiles scene_boot.cpp references
# port_mg_smartball_spawn and port_scene_fill_smartball by name, and
# hal/scene_mg.cpp's face array references all three trap symbols and the slot
# 18 host copy.
#
# MgSmartball_Slot18.cpp REPLACES src/_ZN16dScMgSmartball_c13OnYoshiTryEatEi.cpp, which is off the
# slice for that reason. The matched TU declares func_ov006_02115b0c with no
# parameters and calls it with none while src/func_ov006_02115b0c.c:113 defines
# it taking the object; ARM rides r0 through and the host does not, and the
# callee's first act is seven destructor loops off that pointer. Both TUs are
# matched and read-only, so the fix is the PORT_HOST_ABI shape
# port/mg_fanout_costs.txt section 6 names.
# MgSmartball_Faces.cpp carries three hand-ruled /alternatename rows that
# port/tools/facegen.py refused, with each refusal quoted beside the ruling
# that answers it: one namespace-scope Memory::Deallocate mangle, and two ov004
# DATA words that include/decl_common.h spells with func_ names.
set(SCENE_SMB_SOURCES
    unmatched/MgSmartball_Traps.cpp
    unmatched/MgSmartball_Slot18.cpp
    unmatched/MgSmartball_Faces.cpp)

# Run mg5 lane SMBSEAT: TWO SOURCE PROPERTIES THE SUB-OBJECT SEAT NEEDS.
#
# 1. src/_ZN16dScMgSmartball_c6RenderEv.cpp is main's matched __thiscall member
#    and it is force-fed port/unmatched/MgSmartball_HostAbi.h. That header
#    shadows two include/ headers by pre-defining their own guard macros, which
#    is why the src file itself needs no edit: DispObj's two virtuals are
#    redeclared __cdecl so `p->f1()` pushes its receiver like the twelve
#    `(**(VFunc**)o)(o)` calls in src/_ZN16dScMgSmartball_c8BehaviorEv.cpp that share the same
#    vtables, and dScMgSmartball_c is redeclared without the `sizeof == 0x629c`
#    assert MSVC cannot meet (it neither reuses the base's tail padding nor
#    skips a vfptr for a base that declares no virtual of its own; measured
#    0x47d0 against the ROM's 0x47c8 for the same prefix). /FI is a FLAG rather
#    than an include-path entry on purpose -- CMake emits <INCLUDES> before
#    <FLAGS>, so a /I here would lose to include/ and the shadow would silently
#    not happen.
#
# 2. src/_ZN20cMgSmartball_dokan_c12SaveSnapshotEv.cpp is the ONE .c among the thirty-seven TUs this
#    lane adds that is really C++ -- a //cpp marker and a top-level
#    `extern "C" {` block, invalid C. All thirty-seven were swept for the
#    marker and for `extern "C"`, `virtual`, `class` and `namespace` rather
#    than this one being found by a compile error and the rest left to luck; it
#    is the only hit among the .c files.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN16dScMgSmartball_c6RenderEv.cpp"
    PROPERTIES COMPILE_OPTIONS
    "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/MgSmartball_HostAbi.h")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN20cMgSmartball_dokan_c12SaveSnapshotEv.cpp"
    PROPERTIES LANGUAGE CXX)

# Run link100 lane CRASH2: THE FADER SLOT SHIFT, FIXED AT THE ONE CALL SITE
# WHERE IT CORRUPTS A FRAME. Same /FI mechanism as the block above, and for the
# same kind of reason. include/Fader.h declares its destructor first; mwccarm
# gives that destructor two vtable slots and MSVC gives it one, so a host build
# of dScene_c::SetFaders dispatches IsAtStart, IsAtEnd, SetToEnd and SetToStart
# at slots 4, 5, 7 and 8 while every fader table the port seats is ROM-shaped
# and keeps them at 5, 6, 8 and 9. Landing one slot low on a NO-ARGUMENT slot is
# only a wrong answer; landing on SetForwardTime, which takes two ints and ends
# `ret 8`, pops eight bytes of the caller's frame. Measured in the shipped
# artifact: SetFaders returns into st_binit's tail instead of to its caller,
# dScene_c::ResetFadersAndSound never reaches its `mov al, 1`, Stage's vtable
# slot 1 answers 0, the init dispatcher skips slot 0 which is the level boot,
# and port_stage_a_boot hands port/tests/walk_window.cpp:8335 a null on frame
# one. unmatched/Fader_HostAbi.h carries the whole reading.
#
# /FI is a FLAG rather than an include-path entry for the reason the block above
# gives: CMake emits <INCLUDES> before <FLAGS>, so a /I here would lose to
# include/ and the shadow would silently not happen.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN8dScene_c9SetFadersEP15FaderBrightness.cpp"
    PROPERTIES COMPILE_OPTIONS
    "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Fader_HostAbi.h")

# Run link100 lane CRASH4: THE SPAWN RIDE-THROUGH, PUT BACK. Same /FI mechanism
# as the two blocks above.
#
# dBase_c::Spawn and func_02042ffc each name two of the four arguments they are
# handed, because on ARM the other two sit in r2/r3 and ride through untouched
# into func_02043098. Under MSVC a body that names two forwards two, so
# func_02043098 reads its third and fourth arguments off the caller's frame.
# Measured in the shipped artifact: it is entered with param1 = 0x001af0ac,
# dBase_c::Spawn's own saved ebp, and flags = 0x004bb957, dActor_c::Spawn's
# return address. Every actor the level boot spawns is then built with a stack
# address in fBase_c::mParam at +8; Player::InitResources unpacks it as
# n8 = (0x001af0ac >> 8) & 0xff = 240, func_ov002_020c7dd0 reads
# data_ov002_020ff240[240] past the end of a 20-byte table, mStateStep becomes
# 0x70, and Player::St_LevelEnter_Init indexes a 20-word animation table with
# 112 and hands Player::SetAnim a pointer where an id belongs.
#
# unmatched/ActorDerived_Spawn.cpp has carried the four-argument host copies
# since gate 14, and the gate-14 filter further down excludes the one-function
# decomp file so that they own the symbol. Commit 5116945a1 DELETED that file
# into src/actors/ActorDerived.cpp, a real C++ TU, whose definition carries the
# MSVC-decorated name every C++ caller binds to, while the host copy kept only
# the Itanium spelling that the C-spelled callers reach. Nothing unresolved,
# nothing duplicated, and the fix silently stopped applying: the fold-defect
# shape in5/PORTW9C_COMMON.md names. The header renames the static member for
# this one TU so the four-argument definition in unmatched/ActorDerived_Spawn.cpp
# can own the decorated name. The filter's own line is left as it is rather than
# repointed, because the file it names is gone and the exclusion has nothing
# left to say.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/ActorDerived.cpp"
    PROPERTIES COMPILE_OPTIONS
    "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/dBase_c_SpawnHostAbi.h")

# Run link100 lane CRASH8: QUESTIONBLOCK'S OWN FIELDS, PUT BACK ON THE ROM'S
# OFFSETS. Same /FI mechanism as the three blocks above.
#
# MSVC does not let a derived class reuse its base's TAIL PADDING and the
# Itanium ABI mwccarm implements does. dBgActor_c has a data size of 0x31e and
# a sizeof of 0x320, so mwccarm starts QuestionBlock's own fields at 0x31e,
# include/QuestionBlock.h's `u8 pad_31e[0x2]` fills 0x31e..0x31f, and
# ModelAnim mModelAnim lands on the ROM's 0x320. MSVC starts them at 0x320, the
# same pad fills 0x320..0x321, and mModelAnim is pushed to 0x324. Every field
# of the class from there down is four bytes high and sizeof becomes 0x3fc
# against the 0x3f8 the ROM's own factory asks fBase_c::operator new for.
#
# Measured in the shipped artifact rather than inferred. The class's factory is
# a C translation unit using the ROM's literals and the members are used from
# C++ translation units using MSVC's offsets, so the two disagree in the bytes:
#   _daObjHatenaBlock_c_classInit_HATENA_BLOCK 00521c00
#     00521c1a  lea ecx, [esi + 0x320]  -> __ZN9ModelAnimC1Ev
#   ?InitResources@QuestionBlock@@UAEHXZ 00530240
#     0053026b  lea esi, [edi + 0x324]  -> ModelBase::SetFile
# The ModelAnim is constructed at 0x320 and used at 0x324, so word 0 of the
# used address is still the allocator's zero, and ModelBase::SetFile opens with
# `mov eax,[ecx] / jmp dword ptr [eax+8]`. That is the fault at 004b7986 with
# eax = 0 on the first question block the level loader spawns, which is where
# the boot died after lane CRASH6 cleared the waterfall.
#
# The ROM's own code sits on the 0x320 side, which is what makes the C++
# translation units the outlier and not the factory: _func_ov102_02149da8 at
# 0052c620, matched from ROM bytes, writes mState with
# `mov dword ptr [eax + 0x3e8], edx` where these TUs read it at 0x3ec.
#
# TEN TRANSLATION UNITS, and they are the measured set, not a guess: every
# QuestionBlock symbol in walk_window.map was disassembled with
# tmp/crash8/qbscan.py and these are the ones that compute a displacement at or
# past the 0x320 boundary. src/_ZN13QuestionBlockD0Ev.cpp is not in the link
# (faces_sync_gen.cpp owns that symbol) so it is not listed; add it here if it
# is ever compiled. unmatched/QuestionBlock_HostAbi.h carries the whole reading
# and the full offset table.
#
# /FI is a FLAG rather than an include-path entry for the reason the blocks
# above give: CMake emits <INCLUDES> before <FLAGS>, so a /I here would lose to
# include/ and the shadow would silently not happen.
#
# APPEND, NEVER SET, the rule the DSSTATE FORCE-INCLUDE block at the end of
# this file already states: COMPILE_OPTIONS is one property and
# set_source_files_properties REPLACES it. Two of these ten,
# QuestionBlock::OnAttacked1 and QuestionBlock::OnHitFromUnderneath, are rows in
# PORT_FALLS_OFF_END_SOURCES and take /wd4716 from the loop at the end of this
# file. Measured the hard way: with a plain SET here the first build came back
# with the shadow on eight of the ten, green, and those two TUs still carrying
# the wrong member offsets. The loop at the end now preserves what it finds as
# well, so the two blocks no longer depend on each other's order.
set(PORT_QUESTIONBLOCK_HOSTABI_SOURCES
    src/_ZN13QuestionBlock13InitResourcesEv.cpp
    src/_ZN13QuestionBlock8BehaviorEv.cpp
    src/_ZN13QuestionBlock16CleanupResourcesEv.cpp
    src/_ZN13QuestionBlock6RenderEv.cpp
    src/_ZN13QuestionBlockD1Ev.cpp
    src/_ZN13QuestionBlock11OnAttacked1ER8dActor_c.cpp
    src/_ZN13QuestionBlock15OnGroundPoundedER8dActor_c.cpp
    src/_ZN13QuestionBlock15OnHitByMegaCharER6Player.cpp
    src/_ZN13QuestionBlock19OnHitFromUnderneathER8dActor_c.cpp
    src/_ZN13QuestionBlock8OnKickedER8dActor_c.cpp
    )
foreach(_qb_rel IN LISTS PORT_QUESTIONBLOCK_HOSTABI_SOURCES)
    if(NOT EXISTS "${PORT_REPO_ROOT_ABS}/${_qb_rel}")
        message(FATAL_ERROR "QuestionBlock host-ABI row names a source that "
                "does not exist: ${_qb_rel}")
    endif()
    set_property(SOURCE "${PORT_REPO_ROOT_ABS}/${_qb_rel}"
        APPEND PROPERTY COMPILE_OPTIONS
        "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/QuestionBlock_HostAbi.h")
endforeach()

# ===========================================================================
# Run link100 lane CRASH9: THE dBgW VTABLE IS THE ROM'S SHAPE, NOT MSVC'S.
# ===========================================================================
#
# Same /FI mechanism as the four blocks above, but this one fixes a vtable
# SHAPE rather than a field offset. It moves no field: a virtual adds no data
# member and the vptr is already there, so sizeof(dBgW) stays 0x20.
#
# THE CARTRIDGE'S TABLE HAS THIRTEEN SLOTS. Read out of extracted/arm9_dec.bin
# at base 0x02004000 (NOT 0x02000000 -- at 0x02000000 those words disassemble
# as ARM instructions and a tool that assumes it silently reads the wrong
# function), _ZTV7dBgW_Kc at arm9 0x020993dc, every slot resolving to a named
# ROM symbol out of config/arm9/symbols.txt:
#
#     0 _ZN7dBgW_KcD1Ev        1 _ZN7dBgW_KcD0Ev      2 _ZN7dBgW_Kc9Virtual08Ev
#     3 GetSurfaceInfo [itcm]  4 GetNormal [itcm]     5 GetTriangleOrigin [itcm]
#     6 +0x18 _ZN7dBgW_Kc10DetectClsnER9dBgCh_Gnd
#     7 +0x1c _ZN7dBgW_Kc10DetectClsnER9dBgCh_Lin
#     8 +0x20 _ZN7dBgW_Kc10DetectClsnER12dBgCh_SphCrr
#     9 BeforeClsn  10 TransformPos  11 GetAngularVelY  12 GetVelocity
#
# _ZTV4dBgW, _ZTV10dBgW_KcMbg and _ZTV14dBgW_KcMbgSclY are the same shape.
# include/dBgW.h records exactly this map and says "vtable, in ROM order. Do
# not reorder."
#
# MSVC BUILT TWELVE SLOTS AND PUT Lin AT +0x18, for two independent reasons
# that hal/clsn_vtable.cpp already records in writing:
#   - it spends ONE slot on the destructor where the ROM's Itanium layout
#     spends two (D1 then D0), so everything below shifts up one;
#   - it emits a run of ADJACENT same-name overloads in REVERSE declaration
#     order, so Gnd/Lin/SphCrr came out SphCrr/Lin/Gnd.
# Measured in the shipped artifact, ??_7dBgW_Kc@@6B@ at 0072b7c0:
#     slot 5 +0x14 ?DetectClsn@dBgW_Kc@@UAEHAAUdBgCh_SphCrr@@@Z
#     slot 6 +0x18 ?DetectClsn@dBgW_Kc@@UAEHAAUdBgCh_Lin@@@Z
#     slot 7 +0x1c ?DetectClsn@dBgW_Kc@@UAEHAAUdBgCh_Gnd@@@Z
# and independently by cl /d1reportSingleClassLayoutdBgW_Kc.
#
# TWELVE CALL SITES IN THE LINK DISPATCH THESE BY ROM INDEX, through
# hand-written opaque stand-ins rather than through the real class -- e.g.
# src/_ZN9dBgCh_Gnd10DetectClsnEv.cpp's
#     struct ClsnActor { virtual int v0(); ... virtual int v6(void *); };
#     if (obj->v6(this) != 0)                            /* vtable + 0x18 */
# with five siblings at +0x18/+0x1c/+0x20 (func_02038ea4, func_0203842c,
# func_0203859c, func_02038824, func_02038a38) and one at +0x24 for BeforeClsn
# (func_02038324). So a GROUND raycast was reaching DetectClsn(dBgCh_Lin &).
# That body reads the object as a dBgCh_Lin, 0x68 bytes against dBgCh_Gnd's
# 0x50, and _func_020375ec copies a Vector3 into it at +0x54/+0x58/+0x5c.
# SignPost::InitResources keeps its dBgCh_Gnd at ebp-0x6c and its stack cookie
# at ebp-0x10, which IS ray+0x5c, so the third store landed on the cookie and
# Windows killed the process with STATUS_STACK_BUFFER_OVERRUN (0xc0000409)
# before castle grounds finished spawning its objects. Caught with a hardware
# write watchpoint on the cookie, not inferred: out/CRASH9/probe1_watch_cookie.log.
#
# THE OTHER DIRECTION COSTS NOTHING. The only three REAL C++ virtual calls into
# a dBgW slot anywhere in src/ or port/ are GetSurfaceInfo, GetNormal and
# GetVelocity, and they are recompiled against this same declaration, so they
# move to slots 3, 4 and 12 -- exactly where the cartridge carries them. Every
# consumer lands right and none is traded against another. There are no real
# C++ virtual DetectClsn calls at all.
#
# PROVED IN AN OBJECT BEFORE A BUILD SLOT WAS SPENT, by dumping the emitted
# vftable COMDAT's relocations from src/_ZN7dBgW_KcC1Ev.cpp compiled both ways
# (tmp/crash9/vtprove.cmd; MSVC puts ??_R4 at offset 0, so slot N is at
# offset 4 + 4N):
#     WITHOUT  13 entries, slot 5 SphCrr, slot 6 Lin,  slot 7 Gnd
#     WITH     14 entries, slot 6 Gnd,    slot 7 Lin,  slot 8 SphCrr
# which is the cartridge's table slot for slot.
#
# THE ROW SET is every translation unit that can EMIT one of these four
# vftables plus every one that DISPATCHES a dBgW virtual. MSVC emits the
# vftable COMDAT where the vptr is stored, which is the constructor and
# destructor translation units, so all seventeen of those are listed even
# though today's map shows only the four C1/C2 objects defining a table: a row
# that never emits one is inert, and a missing row would let a stale twelve-slot
# COMDAT win the link silently. The last three are the real-virtual-call sites.
#
# APPEND, NEVER SET -- the rule the block above and the DSSTATE FORCE-INCLUDE
# block at the end of this file both state. COMPILE_OPTIONS is one property and
# set_source_files_properties REPLACES it.
set(PORT_DBGW_HOSTABI_SOURCES
    src/_ZN4dBgWC2Ev.cpp
    src/_ZN4dBgWD0Ev.cpp
    src/_ZN4dBgWD1Ev.cpp
    src/_ZN4dBgWD2Ev.cpp
    src/_ZN7dBgW_KcC1Ev.cpp
    src/_ZN7dBgW_KcC2Ev.cpp
    src/_ZN7dBgW_KcD0Ev.cpp
    src/_ZN7dBgW_KcD1Ev.cpp
    src/_ZN7dBgW_KcD2Ev.cpp
    src/_ZN10dBgW_KcMbgC1Ev.cpp
    src/_ZN10dBgW_KcMbgC2Ev.cpp
    src/_ZN10dBgW_KcMbgD0Ev.cpp
    src/_ZN10dBgW_KcMbgD1Ev.cpp
    src/_ZN10dBgW_KcMbgD2Ev.cpp
    src/_ZN14dBgW_KcMbgSclYC1Ev.cpp
    src/_ZN14dBgW_KcMbgSclYD0Ev.cpp
    src/_ZN14dBgW_KcMbgSclYD1Ev.cpp
    src/_ZN7dBgW_Kc10DetectClsnER9dBgCh_Gnd.cpp
    src/_ZN7dBgW_Kc14GetSurfaceInfoEsR11SurfaceInfo.cpp
    src/_ZN10dBgW_KcMbg9TransformERK9Matrix4x3s.cpp
    # Run link100 lane LEVELS4B: THE FOUR CARRY CALLBACKS, added 2026-09-17.
    # These four are the stock BeforeClsn callbacks a moving platform installs
    # through func_020393d4 to walk its rider along, and every one of them
    # dispatches a LATE dBgW slot on the collider it is handed:
    #
    #   UpdatePosWithTransform      clsn.TransformPos(local, pos)
    #   UpdateAngsWithAngularVelY   clsn.GetAngularVelY()
    #   UpdatePosWithVelocity       clsn.GetVelocity(local)
    #   UpdatePosAndAngs            calls the first two
    #
    # Off this list they compiled against the TWELVE-slot include/dBgW.h while
    # every live collider vtable in the link is THIRTEEN slots, because the
    # tables are emitted by the ctor TUs above, which ARE on this list. Read out
    # of build/port/walk_window.exe (??_7dBgW_KcMbg@@6B@ at 0x00731350): slot 9
    # BeforeClsn, 10 TransformPos, 11 GetAngularVelY, 12 GetVelocity. The three
    # callbacks emitted call [eax+0x24], [eax+0x28] and [eax+0x2c], i.e. indices
    # 9, 10 and 11 -- each one slot low, so TransformPos landed on BeforeClsn. A
    # rider on a moving platform therefore re-entered BeforeClsn from inside its
    # own callback and recursed: the shim reads five stack arguments where that
    # dispatch pushes two, so `pos` came off the caller's own frame (its local
    # Vector3 copy) and the third round dereferenced the rider's x coordinate as
    # an address. That is the whole UPDATEPOS cluster -- levels 21 DDD city, 38
    # BFS arena, 46 Luigi key course and 49 Wario key arena all faulted at
    # dBgW::UpdatePosWithTransform+0xd reading [pos] with pos = 0, 0xffffd000,
    # 0x000c8710 and 0, with UpdatePosWithTransform+0x27 / BeforeClsn+0x18 /
    # UpdatePosAndAngs+0x1a repeating up the stack and func_02038324+0x6e (the
    # ROM's own Obj::m9 entry) underneath.
    #
    # hal/mmc_vtable.cpp measured the same three indices and worked around them
    # by reseating its own hal array; that array is not what the live objects
    # carry, so the shadow header is where the correction belongs.
    src/_ZN4dBgW16UpdatePosAndAngsERS_P8dActor_cR5dBgPiR7Vector3P10Vector3_16S8_.cpp
    src/_ZN4dBgW21UpdatePosWithVelocityERS_P8dActor_cR5dBgPiR7Vector3P10Vector3_16S8_.cpp
    src/_ZN4dBgW22UpdatePosWithTransformERS_P8dActor_cR5dBgPiR7Vector3P10Vector3_16S8_.cpp
    src/_ZN4dBgW25UpdateAngsWithAngularVelYERS_P8dActor_cR5dBgPiR7Vector3P10Vector3_16S8_.cpp
    )
foreach(_dbgw_rel IN LISTS PORT_DBGW_HOSTABI_SOURCES)
    if(NOT EXISTS "${PORT_REPO_ROOT_ABS}/${_dbgw_rel}")
        message(FATAL_ERROR "dBgW host-ABI row names a source that "
                "does not exist: ${_dbgw_rel}")
    endif()
    set_property(SOURCE "${PORT_REPO_ROOT_ABS}/${_dbgw_rel}"
        APPEND PROPERTY COMPILE_OPTIONS
        "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/dBgW_HostAbi.h")
endforeach()

# Run link100 lane DTORCALL: THE ACTOR TEARDOWN DISPATCH, PUT BACK. Same /FI
# mechanism as the five blocks above, and for a defect that reported nothing.
#
# The cartridge dispatches every actor's own complete-object destructor through
# ROM vtable slot 16, in one place:
#
#   _ZN7fBase_c21AfterCleanupResourcesEj, arm9 0x02043b2c
#       02043b78  mov r0, r4           ; this
#       02043b7c  ldr r1, [r0]         ; the object's vtable
#       02043b80  ldr r1, [r1, #0x40]  ; SLOT 16
#       02043b84  blx r1               ; DISPATCH
#       02043b94  bl  #0x203c1e8       ; then Memory::Deallocate
#
# and include/fBase_c.h's own banner says so out loud: "vtable+0x40 (which
# AfterCleanupResources dispatches through) is that D1 destructor". dActor_c
# and dScene_c override AfterCleanupResources only to delegate straight back to
# it, and `this->~fBase_c()` on line 37 of that file is the only explicit
# destructor dispatch in the whole of src/. It is the actor hierarchy's one
# teardown path.
#
# Commit 9cbd99048 gave 341 headers the two-arm destructor spelling that keeps
# MSVC's slot numbering equal to the ROM's, which is what closed lane VTABLE's
# forty measured wrong-slot dispatch sites. It also, as a side effect nobody
# booked, spelled ~fBase_c() NON-VIRTUAL on the host, so that one call stopped
# being a dispatch and became a direct call to fBase_c's own destructor body:
#
#       005ef7d7  mov  ecx, esi
#       005ef7d9  call 0x4f38b0        ; ??1fBase_c@@QAE@XZ, the BASE body
#
# Every actor's own cleanup was skipped from then on. Two independent
# instruments measured ZERO slot-16 dispatch sites in the whole shipped image
# (out/INTWALK/d16scan.py, a byte-encoding scan; out/DTORCALL/slot16scan.py, a
# per-function disassembly of all 24721 map-named functions), against 23 sites
# at slot 15 and 43 at slot 18 either side of it. Nothing reported it, and the
# boot got FURTHER, because the call that used to fault was no longer made.
#
# THE FIX IS PORT-SIDE AND TOUCHES NO DECOMP FILE. unmatched/
# FBase_DtorDispatch_HostAbi.h shadows fBase_c for this one translation unit
# with a VIRTUAL destructor after the sixteen ROM virtuals, so MSVC puts it at
# slot 16 and compiles the call as a dispatch through vtable+0x40. The two-arm
# spelling every other translation unit sees is untouched, so ACTORPORT's forty
# sites cannot move, and this translation unit dispatches no slot above 16.
#
# MSVC routes an explicit destructor call through its scalar deleting
# destructor slot, which is __thiscall with one callee-popped stack argument,
# the delete flag; the cartridge pushes nothing. That difference is already
# ruled on and already paid for by hal/port_d16.h, whose PORT_D16 wrapper takes
# the flag and pops it, and which tools/slot16_guard.py enforces on every
# slot-16 store in the tree. This block is the dispatcher those wrappers were
# built for; without it they are never entered.
#
# /FI is a FLAG rather than an include-path entry for the reason the blocks
# above give: CMake emits <INCLUDES> before <FLAGS>, so a /I here would lose to
# include/ and the shadow would silently not happen. APPEND, so a row that ever
# gains a second force-include keeps both.
# THE ROW GOES ON THE GENERATED FILE, NOT ON src/. This translation unit is
# NOT compiled from src/: it is a GATE9 hostgen symbol (the set() near the top
# of this file), so tools/hostgen.py rewrites it into
# build/port/host-src/src/_ZN7fBase_c21AfterCleanupResourcesEj.cpp and THAT is
# the file every target compiles. A row written against the src/ path, which is
# what the five blocks above legitimately use for their own non-generated
# sources, attaches to a file nothing compiles and does NOTHING AT ALL, with no
# error and no warning. The list(FIND) below is the guard against exactly that:
# if this symbol ever stops being a hostgen symbol, the configure fails loudly
# instead of the force-include silently evaporating.
set(PORT_DTORCALL_HOSTABI_SYM _ZN7fBase_c21AfterCleanupResourcesEj)
if(NOT EXISTS "${PORT_REPO_ROOT_ABS}/src/${PORT_DTORCALL_HOSTABI_SYM}.cpp")
    message(FATAL_ERROR "actor-teardown host-ABI row names a source that "
            "does not exist: src/${PORT_DTORCALL_HOSTABI_SYM}.cpp")
endif()
list(FIND GATE9_SYMS "${PORT_DTORCALL_HOSTABI_SYM}" _dtorcall_gate9_idx)
if(_dtorcall_gate9_idx LESS 0)
    message(FATAL_ERROR "the actor-teardown host-ABI row expects "
            "${PORT_DTORCALL_HOSTABI_SYM} to be a hostgen (GATE9) symbol, so that "
            "the force-include lands on build/port/host-src/. It is not one any "
            "more, so the row below would attach to a file nothing compiles.")
endif()
set_property(SOURCE
    "${CMAKE_BINARY_DIR}/host-src/src/${PORT_DTORCALL_HOSTABI_SYM}.cpp"
    APPEND PROPERTY COMPILE_OPTIONS
    "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/FBase_DtorDispatch_HostAbi.h")

# Run mg5 lane CCN: THE SECOND SEATED MINIGAME CLASS, dScMgCoin_c
# (Coincentration), actor id 0x17a = scene 378. The ROM's own RTTI at
# 0x0213bf24 reads "11dScMgCoin_c" and its vtable is data_ov006_0213bf50, both
# re-derived from extracted/overlays/overlay_0006.bin rather than inherited.
#
# ONE VARIABLE, and for the reason the fader block below states: the slice's
# ov006 bodies are only reachable through the address switch in
# unmatched/MgCoin_StateDispatch.cpp, and that file cannot link without them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-378 row, so
# every target that compiles scene_boot.cpp references port_mg_coin_spawn and
# port_scene_fill_coin by name -- the same coupling the curling row has.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors and the arm9 waves under
# them; CMake appends both lists to the same target and dedupes identical
# absolute paths, so nothing is compiled twice. port/slice_ccn.txt says what it
# reaches and why, and records the class's two hard floors.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ccn.txt" SLICE_CCN_LINES)
set(SLICE_CCN_SOURCES unmatched/MgCoin_StateDispatch.cpp
                      unmatched/MgCoin_Faces.cpp)
foreach(line IN LISTS SLICE_CCN_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_CCN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# THE THIRD `VT`-SPELLING DELETING DESTRUCTOR, and the last one live in this
# build. src/_ZN11dScMgCoin_cD0Ev.cpp is dScMgCoin_c's slot 17 D0 and its body is
# the same four statements curling's and luigi's are, so bare VT sent it to
# _data_ov002_021081e4, the ov002 Enemy base table, a whole class wrong for a
# minigame scene object.
#
# THE ADDRESS IS THE BODY'S OWN LITERAL POOL, disassembled out of
# extracted/overlays/overlay_0006.bin at that overlay's 0x020bfec0 base:
#   0x020dbe68  E59F1024  ldr r1,[pc,#0x24] -> 0x020dbe94
#   0x020dbe70  E5841000  str r1,[r4]          the vptr store
#   0x020dbe94  0213BF50  <- THIS, dScMgCoin_c's own table
#   0x020dbe98  020A0EAC  <- the game heap word, loaded BY VALUE at 0x020dbe80
# config/arm9/overlays/ov006/relocs.txt agrees on both
# (from:0x020dbe94 kind:load to:0x0213bf50, from:0x020dbe98 to:0x020a0eac); the
# D2 sibling _ZN11dScMgCoin_cD1Ev pools the same 0213BF50 at 0x020dbe60; and
# slice_ccn.txt line 29 already named data_ov006_0213bf50 as this class's table
# when the seat was derived. HEAP is right and is not renamed.
#
# FOUND BY THE COFF CENSUS, not by this lane's reading of the alias comment.
# The census is the closure check and it is described at the VT row in
# hal/cxx_aliases.cpp.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11dScMgCoin_cD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=data_ov006_0213bf50")
# Run mg6 lane SOS: dScMgBomroom_c ("Sort or 'Splode"), actor id 0x172 =
# scene 370. The ROM's own RTTI at 0x0213bb38 reads "14dScMgBomroom_c" and its
# vtable is data_ov006_0213bbb4, both derived from
# extracted/overlays/overlay_0006.bin by that lane rather than inherited from
# the fan-out table.
#
# ONE VARIABLE, for lane CCN's reason: the slice's ov006 bodies are only
# reachable through the address switch in
# unmatched/MgBomroom_StateDispatch.cpp, and that file cannot link without
# them. hal/scene_boot.cpp's port_scene_classes table carries the scene-370
# row, so every target that compiles scene_boot.cpp references
# port_mg_bomroom_spawn and port_scene_fill_bomroom by name -- the same
# coupling every other scene row has, which is why this is not optional on any
# of the three targets.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors and the arm9 waves under
# them; CMake appends both lists to the same target and dedupes identical
# absolute paths, so nothing is compiled twice. port/slice_sos.txt says what it
# reaches, why its ov004 delta is ZERO, and records the class's two former
# floors, both closed by run mg7 lane L370: src/func_ov006_020d7c4c.cpp
# (byte-matched) and src/func_ov006_020d8408.c (NONMATCHING, logic verified).
# unmatched/MgBomroom_Traps.cpp held the trap for the second and is deleted.
#
# SEVEN HOST COPIES AND NO TRAP LEFT, which is the largest pointer-to-member bill
# any seated class has run up: seven tables, seven dispatchers, thirty-three
# states. Six of the seven dispatchers are findable by a link or by a
# member-pointer source sweep and the seventh is findable by neither -- it
# open-codes the ARM Itanium sequence in plain ints. Its host copy is in the
# same file and hal/scene_mg_bomroom.cpp counts its dispatches separately, so a
# run can say the seat is working rather than the absence of a link error
# implying it.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sos.txt" SLICE_SOS_LINES)
set(SLICE_SOS_SOURCES hal/scene_mg_bomroom.cpp
                      unmatched/MgBomroom_StateDispatch.cpp)

# THE DELETING DESTRUCTOR SPELLS ITS OWN TABLE AS THE SHARED PLACEHOLDER `VT`,
# and this is the failure that links cleanly. src/_ZN14dScMgBomroom_cD0Ev.cpp is
# `t[0] = (int)VT;` and hal/cxx_aliases.cpp binds bare VT to
# _data_ov002_021081e4, the ov002 ENEMY base table, so with no rename here
# dScMgBomroom_c's D0 writes an ENEMY vtable into the scene object on the way
# down and every slot dispatched after that point comes out of the wrong table.
# Nothing diagnoses it: the alias resolves, the link is clean, and this class's
# D0 did not fire on either of this lane's proof runs, so a census would have
# read zero and said nothing either.
#
# THE ADDRESS IS THE BODY'S OWN LITERAL POOL, read out of
# extracted/overlays/overlay_0006.bin at base 0x020bfec0 rather than taken from
# the vtable derivation: 0x020d5aa8 holds 0213BBB4. Its unmarked D2 sibling
# _ZN14dScMgBomroom_cD1Ev writes the same word from its own pool at 0x020d5a74 and
# does not need a rename, because it spells the symbol rather than the
# placeholder.
#
# HEAP IS DELIBERATELY NOT RENAMED. The second pool word, at 0x020d5aac, is
# 020A0EAC -- the game heap, which cxx_aliases.cpp already binds bare HEAP to.
#
# Found by the run mg6 coordinator's cross-lane note and confirmed here by the
# check that actually works: a COFF short-name scan for _VT over the built
# objects, which named this TU in all three targets. The same scan names two
# other minigame D0s that are still mis-bound (_ZN11dScMgCoin_cD0Ev and
# _020e065c); they belong to other classes and are not this lane's to rename.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN14dScMgBomroom_cD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=data_ov006_0213bbb4")
foreach(line IN LISTS SLICE_SOS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SOS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# run mg6 lane S75: dScMgCurling2_c, actor id 0x177 (scene 375) -- the ADVANCED
# half of the curling pair whose basic half is scene 374, and the seventh ov006
# minigame class the port seats.
#
# ONE TABLE, TWO DEEP. Scene -> dScMgBase_c (ov004 0x020bc0c0) ->
# dScMgCurling2_c (ov006 0x0213c510), 36 slots, checked three ways before a
# word was written (port/slice_s75.txt). No intermediate table, so unlike the
# flower block below there is one face array and no hostgen substitution.
#
# WHAT IT DOES NEED IS THE WHOLE WALL. Five dispatching TUs, seven pointer-to-
# member tables and twenty-five states, covering every one of the three hiding
# places port/mg_fanout_costs.txt section 4 and lane FLW enumerate. All five are
# host-copied in unmatched/MgCurling2_StateDispatch.cpp and all five are
# therefore OUT of slice_s75.txt -- listing both copies would be a duplicate
# symbol, and listing neither would drop the dispatch silently. The slice file
# names the five in its header so the trade is readable from either end.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_s75.txt" SLICE_S75_LINES)
# unmatched/MgCurling2_Traps.cpp IS GONE, run mg7 lane L375. It stood in for
# func_ov006_020e513c and func_ov006_020e5450 while both were decomp gaps, and
# both now have src bodies that slice_s75.txt lists, so keeping the file would
# be two duplicate symbols. Its counters are replaced by the per-slot census in
# MgCurling2_StateDispatch.cpp, which counts at the DISPATCH SITE rather than
# inside a ROM body.
set(SLICE_S75_SOURCES unmatched/MgCurling2_StateDispatch.cpp)
foreach(line IN LISTS SLICE_S75_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_S75_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# The five host-copied dispatchers must stay out of the slice. A slice line that
# came back (a rename, a hand edit, a merge) would define the same symbol twice
# and the link would say so -- but it would say so as a duplicate-symbol wall
# far from its cause, so the assertion is here instead.
# Run link100, lane HOSTGEN2: the three src/actors/dScMgCurling2_c.cpp entries
# LEAVE this list. They were three separate per-function files when the
# assertion was written and the sync's rename collapsed all three onto the
# consolidated TU, so the list refused the whole class over three bodies. Two of
# those three -- StepXAndY and StepXOnly -- are commented out in the host copy
# now, and the reason the assertion gives for refusing ("taking the src one puts
# the mwcc member-pointer stride back") stopped being true when /vmg /vmm went
# on add_compile_options: the stride is the ROM's eight bytes on both machines
# and all four of this class's tables are seated with __fastcall faces. The two
# genuinely host-copied dispatchers keep their rows.
foreach(dup IN ITEMS src/_ZN15dScMgCurling2_c8BehaviorEv.cpp src/func_ov006_020e6354.cpp)
    if(dup IN_LIST SLICE_S75_LINES)
        message(FATAL_ERROR "slice_s75.txt lists ${dup}, which "
                "unmatched/MgCurling2_StateDispatch.cpp host-copies. Taking "
                "both is a duplicate symbol; taking the src one puts the mwcc "
                "member-pointer stride back")
    endif()
endforeach()

# THE DELETING DESTRUCTOR SPELLS ITS OWN TABLE AS THE SHARED PLACEHOLDER `VT`,
# and this is the third minigame class to need the rename. src/func_ov006_
# 020e3878.c line 9 is `t[0] = (int)VT;` and hal/cxx_aliases.cpp:1231 binds
# bare VT to _data_ov002_021081e4, the ov002 ENEMY base table. Without the line
# below this class's slot-17 D0 writes the ENEMY vtable into the object on
# teardown.
#
# THE ADDRESS IS THIS BODY'S OWN LITERAL POOL, read out of
# extracted/overlays/overlay_0006.bin at base 0x020bfec0: 0x020e38a8 holds
# 0213C510, which is this class's table. Its unmarked D2 sibling
# _ZN15dScMgCurling2_cD1Ev stores the same word from its own pool at 0x020e3874 and
# is spelled with the symbol rather than the placeholder, so the two halves of
# the destructor pair cross-confirm the binding.
#
# HEAP IS DELIBERATELY NOT RENAMED. The second pool word at 0x020e38ac is
# 020A0EAC, which is the game heap cxx_aliases.cpp:1232 already binds bare HEAP
# to, so the global alias is correct for this TU and a rename would be noise.
#
# AND THE LINK IS NOT A DETECTOR FOR THIS. The wrong binding resolves cleanly,
# and so does a run: slot 17 is the deleting destructor, so a scene that boots
# and ticks never enters it. This lane's 60-frame and 1200-frame runs of scene
# 375 both entered slots 0, 6 and 9 only. The check that works is reading the
# TU and the body's own pool, which is what the paragraph above is.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names dScMgCurling2_c.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   VT=data_ov006_0213c510  --  dead, the TU does not spell VT
# Deleted rather than merged. The surviving row is unchanged.

# RUN MG8 lane SGX: THE PADDLE DRAWS FROM ANOTHER OVERLAY'S BYTES.
# Tango's lap-2 report on scene 375 is "I cant see the paddle if im suposed to".
# src/actors/dScMgCurling2_c.cpp is the paddle draw -- slot 9 Render calls it last,
# it is gated on the cue-visible flag at +0x55b9, and it hands ONE OamAttr
# template to func_ov004_020afdd0 at the cue's own (x,y) less (0x20,8), the
# half-size offset of a 64x16 sprite pair. The template it names is
# data_ov098_0213c4f0. THAT IS THE WRONG OVERLAY.
#
# 0x0213c4f0 is one address with two occupants, exactly the ov002/ov004 shape
# lane A2 fixed above. Both name it and both are right about their own image:
#   config/arm9/overlays/ov006/relocs.txt:3577
#     from:0x020e4bd0 kind:load to:0x0213c4f0 module:overlay(6)
#   config/arm9/overlays/ov098/relocs.txt:143
#     from:0x021388b4 kind:load to:0x0213c4f0 module:overlay(98)
# 0x020e4bd0 is func_ov006_020e4b78's OWN literal pool word (the body is
# 0x020e4b78..0x020e4bd4), so the load is INTERNAL to ov006 and dsd tagged it
# overlay(6) with no ambiguity. The src TU spells the ov098 name, ov098 is
# mounted (PORT_ACTOR_OVERLAYS), so the port links ov098's bytes into a
# dScMgCurling2_c frame -- and ov098 is a castle-grounds actor overlay that can
# never be co-resident with ov006.
#
# THE BYTES ARE NOT THE SAME AND ARE NOT COMPATIBLE, read out of
# extracted/overlays/ at each overlay's own OVT base:
#   ov006 (base 0x020bfec0)  80004000 00001008 80204000 0000100c
#     = attr {0x4000,0x8000,0x1008} and {0x4000,0x8020,0x100c}: two 32x16
#       sprites, 16-colour, palette 1, priority 0, tiles 0x008 and 0x00c, at
#       x=0 and x=0x20 -- a 64x16 paddle, which is what the -0x20 in the draw
#       centres. Scene 374's own bumper is the SAME pair (32x16 tiles 8 and 12,
#       palette 1, priority 0) in its engine-B OAM, measured with
#       SM64DS_PPU_AUDIT, so the shape is corroborated from a second scene.
#   ov098 (base 0x02137be0)  00014000 00014000 00014000 0000f000
#     = ov098's cannon data. As OAM attributes it is a 16x8 entry at x=1 on
#       tile 0 followed by garbage.
# A -D and not an /alternatename, for lane A2's reason: data_ov098_0213c4f0 is
# DEFINED in this binary by the ov098 mount, and an alias with a defined symbol
# on the left is defeated silently. This is a port-side binding fix; the src
# TU's own spelling is a decomp naming defect and is ROUTED, not taken here.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/dScMgCurling2_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov098_0213c4f0=data_ov006_0213c4f0")

set(SCENE_MG_CURLING2_SOURCES hal/scene_mg_curling2.cpp)
# Run mg6 lane PPP: THE SEVENTH SEATED MINIGAME CLASS, dScMgPanel_c, actor id
# 0x17c = scene 380 -- the minigame the spawn symbol names
# MgPuzzlePanelPuzzlePanic. The class name is the ROM's and is proved by the
# type_info the word BEFORE the vtable points at: data_ov006_0213e24c[-1] is
# 0x0213dd40, whose name pointer is 0x0213dd84, which reads "12dScMgPanel_c".
#
# ONE VARIABLE, for the reason the CCN block above states: the slice's ov006
# bodies are only reachable through the address switch in
# unmatched/MgPanel_StateDispatch.cpp, and that file cannot link without them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-380 row, so
# every target that compiles scene_boot.cpp references port_mg_panel_spawn and
# port_scene_fill_panel by name -- the same coupling every minigame row has.
#
# ELEVEN DISPATCHER HOST COPIES, NOT FIVE: this class runs a TWO-LEVEL state
# machine, so unmatched/MgPanel_StateDispatch.cpp carries eleven bodies rather
# than curling's five. Ten of them came with lane PPP's seat; the eleventh is
# func_ov006_02106ca4, which run mg7 lane L380 decompiled and which turned out
# to dispatch data_ov006_02142840 as well as being slot 6 of the Behavior's own
# table.
#
# unmatched/MgPanel_Faces.cpp IS NOW ONLY THE VTABLE FACE. It used to carry a
# counting trap for func_ov006_02106168, the layout picker slot 0 and slot 18
# both call; that body is decompiled too and joins the slice as an ordinary
# line, so nothing in this seat stands in for a ROM body any more.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors and the arm9 waves under
# them; this class's ov004 delta is measured ZERO. CMake appends both lists to
# the same target and dedupes identical absolute paths, so nothing is compiled
# twice. port/slice_ppp.txt says what it reaches and records the class's ONE
# remaining hard floor (func_ov006_021053a8) and two stategen join misses.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ppp.txt" SLICE_PPP_LINES)
set(SLICE_PPP_SOURCES unmatched/MgPanel_StateDispatch.cpp
                      unmatched/MgPanel_Faces.cpp)
foreach(line IN LISTS SLICE_PPP_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PPP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# THE DELETING DESTRUCTOR SPELLS ITS OWN TABLE AS THE SHARED PLACEHOLDER `VT`,
# the same defect the LUI block above renames one TU for. src/
# _ZN12dScMgPanel_cD0Ev.c is `t[0] = (int)VT;` and hal/cxx_aliases.cpp binds bare
# VT to _data_ov002_021081e4, the ENEMY base table. The address below is the
# body's OWN literal pool, read out of extracted/overlays/overlay_0006.bin:
# 0x021042e0 holds 0213E24C. HEAP is deliberately NOT renamed -- the second
# pool word at 0x021042e4 is 020A0EAC, the game heap cxx_aliases.cpp already
# binds it to.
# BOTH PATHS, 2026-09-13 (lane SYNC3): this TU is substituted whole by its
# hostgen copy (PORT_HOSTGEN_TU at the top of this file), and the copy is what
# every target actually compiles. A -D that named only the src/ path would stop
# applying without a word and bare VT would collapse back onto the ENEMY base
# table, which is the silent-wrong-object bug the clinkage note calls the
# landmine. The src/ row is kept so the property is still right if the
# substitution is ever retired.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/dScMgPanel_c.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/actors/dScMgPanel_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=data_ov006_0213e24c")

# run mg5 lane FLW: THE SECOND MINIGAME CLASS, and the first with a
# three-deep hierarchy.
#
# dScMgFlower_c, actor id 0x186 (390) -- the "Loves Me...?" petal minigame.
# Scene -> dScMgBase_c (ov004) -> dScMgSingle3DBase_c (ov006 0x0213e448) ->
# dScMgFlower_c (ov006 0x02140140), all three tables 36 slots wide and all
# three checked three ways before a word was written (port/slice_flw.txt).
#
# WHAT IT DOES NOT NEED IS THE INTERESTING PART. This class has NO mwcc
# pointer-to-member state machine: slot 6 is a plain switch, no overlay
# constructor builds a pair table for it, and a `::*` sweep of every TU in the
# slice is clean. So there is no address switch, no dispatcher host copy and no
# stategen output on this lane -- port/mg_fanout_costs.txt section 4's "the
# wall is the same one for all thirty" gains a counterexample.
#
# It rides the SAME three targets as the curling seat and it is not optional on
# any of them: hal/scene_boot.cpp's port_scene_classes table now carries the
# flower row, so every target that compiles scene_boot.cpp references
# port_mg_flower_spawn and port_scene_fill_flower by name.
# ONE TU IN THIS SLICE REACHES A GEOMETRY REGISTER, so it builds from a
# hostgen-emitted copy the way every other MMIO-touching src/ file in this
# tree does -- src/ itself is never edited.
#
# _ZN19dScMgSingle3DBase_c9Virtual84Ev is dScMgSingle3DBase_c slot 33, the once-per-boot 3D
# setup every ov006 3D minigame runs, and its last two statements are
#
#     *(vu32 *)0x40004ccu = 0x7fff;        LIGHT_COLOR, light 0 white
#     *(vu32 *)0x40004ccu = 0x40007fff;    LIGHT_COLOR, light 1 white
#
# Compiled straight from src/ those two stores land in the real memory ntr
# maps across the I/O window and stop there: the geometry engine is never
# told, so light 0 keeps colour (0,0,0) and every lit vertex in the scene
# resolves to emission, which every material in this game writes as 0. That
# is the "Yoshi is a black silhouette" report -- measured, before this line,
# as "LIGHT_COLOR commands executed: 0" beside "I/O LATCH
# LIGHT_COLOR(4cc)=40007fff" (SM64DS_MAT_LOG, run mg5 lane YTEX).
#
# The pattern missed it TWICE: hostgen's MMIO type list had no vu32 and the
# `u` suffix on the literal defeated the word boundary after seven hex
# digits. Both are fixed in tools/hostgen.py, and the fix is proven inert
# over the 159 files already in the hostgen set (regenerating all of them
# with the old and new tool gives byte-identical output).
# THE SUBSTITUTION IS NOW WHOLE-TU, 2026-09-12 (main -> port sync, lane SYNC2).
# main merged ov006's dScMgSingle3DBase_c bodies into one translation unit,
# src/minigames/d_s_mg_single3_d_base.cpp, so slot 33 no longer has a file of
# its own to substitute for -- and the raw TU is reachable from slice_mem as
# well, which would have put the two silent LIGHT_COLOR stores back in the link
# whatever this lane did with slice_flw alone. Substituting the WHOLE TU keeps
# the fix and keeps every other body in it: hostgen rewrites MMIO accesses and
# nothing else, it is proven inert over the 159 files already in the set, and on
# this TU it finds FOURTEEN MMIO writes rather than the two slot 33 carried by
# itself. The raw TU is therefore skipped in slice_flw and commented out of
# slice_mem, and the generated copy rides SLICE_FLW_SOURCES into the same three
# targets both slices already feed.
#
# The list is repo-relative PATHS rather than bare symbol names because a merged
# TU's name is neither symbol and it no longer sits at the root of src/.
set(FLW_HOSTGEN_SRCS src/minigames/d_s_mg_single3_d_base.cpp)
set(FLW_HOSTGEN_GEN "")
set(FLW_HOSTGEN_SKIP "")
foreach(rel IN LISTS FLW_HOSTGEN_SRCS)
    if(NOT EXISTS "${PORT_REPO_ROOT_ABS}/${rel}")
        message(FATAL_ERROR "slice_flw hostgen source ${rel} does not exist; "
                "the MMIO substitution would be silently dropped")
    endif()
    set(sym_src "${PORT_REPO_ROOT_ABS}/${rel}")
    list(APPEND FLW_HOSTGEN_SKIP "${rel}")
    string(REGEX REPLACE "[.](c|cpp)$" ".cpp" rel_out "${rel}")
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/${rel_out}")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${rel}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${rel}")
    list(APPEND FLW_HOSTGEN_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_flw.txt" SLICE_FLW_LINES)
set(SLICE_FLW_SOURCES ${FLW_HOSTGEN_GEN})
foreach(line IN LISTS SLICE_FLW_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # The hostgen'd copy stands in for the src/ one; taking both would be a
    # duplicate symbol, and taking neither would drop the body silently.
    if(line IN_LIST FLW_HOSTGEN_SKIP)
        continue()
    endif()
    list(APPEND SLICE_FLW_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# A slice line that stops matching (a rename, a .c that becomes a .cpp) would
# silently take the src/ copy back and put the defect back with it, so the
# substitution asserts rather than hopes.
list(LENGTH FLW_HOSTGEN_SRCS flw_hg_want)
list(LENGTH FLW_HOSTGEN_GEN flw_hg_have)
if(NOT flw_hg_want EQUAL flw_hg_have)
    message(FATAL_ERROR "slice_flw hostgen substitution incomplete: "
            "${flw_hg_have} of ${flw_hg_want} generated")
endif()
foreach(skip IN LISTS FLW_HOSTGEN_SKIP)
    if(NOT skip IN_LIST SLICE_FLW_LINES)
        message(FATAL_ERROR "slice_flw.txt no longer lists ${skip}; the "
                "hostgen substitution for it is now dead and the geometry "
                "register writes in it would go back to latching silently")
    endif()
endforeach()

set(SCENE_MG_FLOWER_SOURCES
    hal/scene_mg_flower.cpp
    # TWO ARGUMENT RIDE-THROUGHS THIS CLASS OWES, both PORT_HOST_ABI host
    # copies under the coordinator's ruling, both the shape
    # port/mg_fanout_costs.txt section 6 prescribes for its own (b) and (c).
    # _ZN19dScMgSingle3DBase_c18AfterInitResourcesEj drops the framework's second argument because the
    # ROM rides it through in r1; func_ov004_020ad8b8 drops the pointer the
    # ROM rides through r0 into func_ov004_020adc3c. Each REPLACES its src TU
    # rather than joining it -- both are out of slice_flw.txt -- so they are
    # not optional on any target that compiles the slice.
    unmatched/MgFlower_Slot2.cpp
    # unmatched/MgFlower_InitScore.cpp RETIRED run link100 wave 15, lane
    # SEAT15D. The half of the sentence above that applies to
    # func_ov004_020ad8b8 is no longer true: src/func_ov004_020ad8b8.c:3 now
    # declares `extern int func_ov004_020adc3c(int* c);` and :24 passes `c`,
    # and the TU's own header says the argument USED TO BE dropped here. The
    # matched TU is taken instead -- see port/slice_l15mg.txt. Put this line
    # back only together with the slice line. The OTHER half,
    # unmatched/MgFlower_Slot2.cpp above, is untouched and still owed.
    # unmatched/MgFlower_InitScore.cpp
    # And the class's half of the pointer-to-member wall. It exists after all,
    # in a form section 4's two silent shapes do not cover: a dispatcher that
    # open-codes the Itanium sequence in plain ints. Replaces
    # src/func_ov006_020c3d18.cpp, which is out of the slice.
    unmatched/MgFlower_SubDispatch.cpp)
# unmatched/MgFlower_ModelRender_020c3bf4.cpp RETIRED (run link100, lane
# FOLD2). It existed because the ROM's vtable BYTE +0x14 is Render while the
# FOLDED host table put ModelAnim::Virtual18 there, so the matched TU handed
# Virtual18 a null matrix and Model::Virtual10 read address 0. Lane SLOT5F's
# destructor unfold ROM-numbers _ZTV9ModelAnim, so index 5 is Render again.
# src/func_ov006_020c3bf4.cpp carries it now -- through tools/hostgen.py, for
# its one LIGHT_VECTOR store; see the FOLD2 hostgen block near the end of this
# file and port/slice_fold2.txt.

# Run mg6 lane MEM: dScMgMemory2_c (Memory Master), actor id 0x16b = scene 363,
# and the SECOND three-deep hierarchy the port seats.
#
#   Scene -> dScMgBase_c (ov004 0x020bc0c0) -> dScMgSingle3DBase_c
#         (ov006 0x0213e448) -> dScMgMemory2_c (ov006 0x0213d4d4)
#
# all three tables 36 slots wide and both new ones checked three ways before a
# word was written (port/slice_mem.txt). The middle table is the same object
# dScMgFlower_c and dScMgCup_c sit under; hal/scene_mg_memory2.cpp section 3
# measures why two files defining their own face array over it is safe and what
# decides which one claims it.
#
# ONE VARIABLE, for the reason the flower and fader blocks give: the slice's
# ov006 bodies are only reachable through the address switch in
# unmatched/MgMemory2_StateDispatch.cpp, and that file cannot link without them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-363 row, so
# every target that compiles scene_boot.cpp references port_mg_memory2_spawn and
# port_scene_fill_memory2 by name.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors and the arm9 waves under them;
# CMake appends every list to the same targets and dedupes identical absolute
# paths, so nothing is compiled twice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_mem.txt" SLICE_MEM_LINES)
set(SLICE_MEM_SOURCES hal/scene_mg_memory2.cpp
                      unmatched/MgMemory2_StateDispatch.cpp
                      unmatched/MgMemory2_FieldPmf.cpp
                      # The aliases the link asked for and two __thiscall
                      # method faces. Its named trap for _ZN14dScMgMemory2_c9DrawCardsEv
                      # is GONE: run mg7 lane MEMCARDS decompiled that body
                      # (the card draw) into src/func_ov006_020f5b98.c and
                      # slice_mem.txt carries it.
                      unmatched/MgMemory2_Faces.cpp
                      # unmatched/MgMemory2_SubObjCtor.cpp RETIRED (run
                      # linkfull, lane RS4PORT): main #3107 spells the three
                      # file ids 0x205/0x206/0x207, so src/func_ov006_020c0a48.c
                      # is back on slice_mem.txt.
                      )
# unmatched/MgMemory2_ModelRender_020c1804.cpp and
# unmatched/MgMemory2_ShadowSlot_020c06dc.cpp RETIRED (run link100, lane
# FOLD2). Both were the destructor fold and nothing else: the first dispatches
# ROM index 5 (Render) on a BlendModelAnim and a Model, the second ROM index 3
# (UpdateVerts), and lane SLOT5F's unfold puts both words back where the ROM
# holds them. src/func_ov006_020c06dc.cpp is a plain row in
# port/slice_fold2.txt; src/func_ov006_020c1804.cpp goes through
# tools/hostgen.py for its two LIGHT_VECTOR stores (the FOLD2 hostgen block
# near the end of this file).
foreach(line IN LISTS SLICE_MEM_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_MEM_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Run mg9 lane CUP: dScMgCup_c -- the minigame the ROM calls "Tox Box Shuffle"
# -- actor id 0x169 = scene 361, and the THIRD class the port seats under
# dScMgSingle3DBase_c.
#
#   Scene -> dScMgBase_c (ov004 0x020bc0c0) -> dScMgSingle3DBase_c
#         (ov006 0x0213e448) -> dScMgCup_c (ov006 0x0213c154)
#
# all three tables 36 slots wide and both new ones checked three ways before a
# word was written (port/slice_cup.txt section 2). The third check is not a
# formality on THIS class: the word past the end of 0x0213c154 is the mwcc pair
# {0x020e0a24, 0} that src/__sinit_ov006_021304ac.c copies into CURLING's state
# table, so a 37-slot fill would corrupt scene 374. That is the case
# port/mg_fanout_costs.txt section 11 was written from.
#
# The middle table is the same object dScMgFlower_c (390) and dScMgMemory2_c
# (363) sit under. The scene-361 row is APPENDED AFTER BOTH of theirs in
# hal/scene_boot.cpp, so the flower's fill still claims it and both existing
# witnesses are unchanged; hal/scene_mg_cup.cpp section 3 has the measurement
# and the argument for promoting kSingle3DFaces to a seam before a FOURTH class
# under this base is seated.
#
# ONE VARIABLE, for the reason the memory2 and flower blocks give: the slice's
# ov006 bodies are only reachable through the two address switches in
# unmatched/MgCup_StateDispatch.cpp and unmatched/MgShared4f38_SubDispatch.cpp,
# neither file can link without them. hal/scene_boot.cpp's port_scene_classes
# table carries the scene-361 row, so every target that compiles scene_boot.cpp
# references port_mg_cup_spawn and port_scene_fill_cup by name.
#
# THE SLICE IS THE DELTA ONLY, and this one is a smaller delta than its
# predecessor artifact implies: eighteen of port/slice_mga361.txt's sixty-eight
# lines are already compiled in by the flower, memory2 and gate slices.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_cup.txt" SLICE_CUP_LINES)
set(SLICE_CUP_SOURCES hal/scene_mg_cup.cpp
                      # The class's TABLE dispatcher: vtable slot 6 and the
                      # eight states of data_ov006_02141870. REPLACES
                      # src/actors/dScMgCup_c.cpp, which is out of the slice.
                      unmatched/MgCup_StateDispatch.cpp
                      # REPLACES src/actors/dScMgCup_c.cpp, the factory, out
                      # of the slice: it calls the base constructor
                      # _ZN11dScMgBase_cC2Ev with NO argument (correct on ARM,
                      # where r0 already holds the object) and that callee
                      # stores three vtable words through the pointer it never
                      # received. The displacement ruling section 12 grants to
                      # "whichever lane seats 361" is that file's header.
                      unmatched/MgCup_Factory.cpp
                      # REPLACES src/actors/dScMgCup_c.cpp, out of the slice:
                      # a MATCHED body that reads an UNINITIALISED local on two
                      # of its three paths. mwccarm put the variable in r1,
                      # which already holds the parameter the ROM's epilogue
                      # uses, so the src is faithful and byte-exact; MSVC gave
                      # it a register holding the object pointer and the first
                      # frame of scene 361 wrote two zero words four gigabytes
                      # out of range. Invisible to the byte gate, to the link
                      # and to a member-pointer sweep -- only a run convicts it.
                      unmatched/MgCup_UninitEpilogue_020def80.cpp
                      # THREE SHARED BODIES OF THE +0x4f38 SUB-OBJECT, host-
                      # copied ONCE and listed by BOTH this block and the BOX
                      # block below. ov006's relocs.txt carries exactly two
                      # arm_calls into each of them, one from dScMgCup_c and
                      # one from dScMgSound_c, so they belong to neither class.
                      # Run mg9 adjudication; the rulings and the ROM evidence
                      # are in each file's header.
                      #   020c2b8c  the FIELD-held pointer-to-member dispatch,
                      #             SIX routed states (lane CUP found four --
                      #             correct for its own closure; 020c22d8 and
                      #             020c26f4 are installed only from
                      #             dScMgSound_c's block and lane BOX routes
                      #             them). REPLACES src/func_ov006_020c2b8c.cpp.
                      unmatched/MgShared4f38_SubDispatch.cpp
                      #   020c29dc  the local-shadow-class model draw at TWO
                      #             call sites (byte +0x14 of the Itanium table
                      #             is Render; the sixth MSVC word is Virtual18
                      #             on BlendModelAnim and nothing on Model),
                      #             plus four LIGHT_COLOR / LIGHT_VECTOR stores
                      #             that a host copy must route through
                      #             NTR_MMIO. RETIRED (run link100, lane
                      #             FOLD2): the fold is dead and hostgen.py
                      #             DOES see the file now -- it is wired
                      #             through the FOLD2 hostgen block near the
                      #             end of this file, which is what routes the
                      #             four stores. src/func_ov006_020c29dc.cpp
                      #             carries the body.
                      #   020c2924  a RECEIVER DROP at a host C++ virtual: a
                      #             __cdecl-typed raw vtable read against a
                      #             __thiscall body, where the stack balances so
                      #             nothing faults and no ABI checker sees it,
                      #             and the garbage answer gates seven stores.
                      #             Found by lane BOX; scene 361 ran the
                      #             DEFECTIVE src TU until this merge. REPLACES
                      #             src/func_ov006_020c2924.cpp, which leaves
                      #             BOTH slice_cup.txt and slice_box.txt.
                      unmatched/MgShared4f38_ShadowFader_020c2924.cpp)
foreach(line IN LISTS SLICE_CUP_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_CUP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Run mg11 lane PGO: dScMgMCarlo2_c, actor id 0x17e (scene 382) -- "Pair-a-Gone
# And On", the ENDLESS-MODE sequel to scene 381's Pair-a-Gone.
#
# THREE TABLES, NOT TWO. Scene -> dScMgBase_c (ov004 0x020bc0c0) ->
# dScMgSingle3DBase_c (ov006 0x0213e448) -> dScMgMCarlo2_c (ov006 0x0213d7e8),
# all three 36 slots, PLUS the element class dMgMCarlo2CardObj_c at
# 0x0213d728, two slots, which the factory writes into the first word of all
# forty card records. Both element slots are live -- Render dispatches slot 0
# and the pair matcher dispatches slot 1 -- so a seat that filled only the scene
# tables would link, boot and jump to a raw DS address on the first rendered
# frame. port/slice_pgo.txt is the derivation.
#
# THE WIDTH IS 36 BY FIVE CHECKS AND THE THIRD ONE IS FOOLED HERE: index 36 of
# 0x0213d7e8 reads 0x020fb4e0, a real code address, because a 25-entry run of
# mwcc {code, 0} pairs starts immediately after the table. Those pairs belong to
# MgBobOmbSquad (0x170) -- their code words are all past this class's block, the
# five .bss tables __sinit_ov006_02131a38 copies them into are read from five
# dispatchers in 0x170's block, and 0x170's own vtable holds 0x020fa75c in slot
# 16, exactly where this class's code ends. A 37-slot fill would have written a
# host thunk over another minigame's first state.
#
# NO HOSTGEN SUBSTITUTION AND NO STATE DISPATCH. This class has no pointer-to-
# member table (no relocation from ov006's .init reaches its code block at all),
# so there is no stategen output; and its slot 0's two PPU writes (0x04000008,
# 0x0400100a) are plain state registers rather than the write-triggered class
# the NTR_MMIO proxy exists for, so it builds from src the way dScMgFlower_c's
# and dScMgMCarlo_c's slot 0 do. The middle base's slot 2 and slot 33
# substitutions are inherited through slice_mem.txt and FLW_HOSTGEN_GEN.
#
# ONE VARIABLE, for the reason the flower and fader blocks give: the slice and
# the .cpp are not separable. hal/scene_boot.cpp's port_scene_classes table now
# carries the scene-382 row, so every target that compiles scene_boot.cpp
# references port_mg_mcarlo2_spawn and port_scene_fill_mcarlo2 by name.
#
# THE SLICE IS THE DELTA ONLY -- this class's own twenty-five bodies. The ov004
# framework, the thirty-five overlay constructors and the arm9 waves come in
# through slice_mg1.txt; the Single3D sub-object family through slice_mem.txt;
# func_ov006_020c1164 and func_ov006_020c16b4 through slice_s381.txt. CMake
# appends every list to the same targets and dedupes identical absolute paths.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pgo.txt" SLICE_PGO_LINES)
set(SLICE_PGO_SOURCES hal/scene_mg_mcarlo2.cpp)
foreach(line IN LISTS SLICE_PGO_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PGO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Run mg9 lane MMT: dScMgMemory_c (Memory Match), actor id 0x16a = scene 362,
# and the THIRD seated class under dScMgSingle3DBase_c.
#
#   Scene -> dScMgBase_c (ov004 0x020bc0c0) -> dScMgSingle3DBase_c
#         (ov006 0x0213e448) -> dScMgMemory_c (ov006 0x0213d1b8)
#
# both derived tables 36 slots wide, and 0x16a is one of the twelve rows
# port/mg_fanout_costs.txt section 11 corrected from 37 to 36 -- so the width
# was checked FOUR ways before a word was written (port/slice_mmt.txt), and
# check 3 names the victim a 37th slot would have had: the word at index 36 is
# the code half of an mwcc pair whose body is dScMgMemory2_c's round-end state,
# on a tree where scene 363 is seated and green.
#
# ONE VARIABLE, for the reason the flower, memory2 and fader blocks give: the
# slice's ov006 bodies are only reachable through the address switch in
# unmatched/MgMemory1_StateDispatch.cpp, and that file cannot link without them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-362 row, so
# every target that compiles scene_boot.cpp references port_mg_memory1_spawn and
# port_scene_fill_memory1 by name.
#
# THE SLICE IS THE DELTA ONLY and this lane's delta is unusually small: its
# ov004 closure adds NOTHING (all 103 functions are already carried or already
# host-copied) and its ov006 delta is this class's own code block plus nothing,
# because the model sub-object at +0x4f38 is the same one run mg6 lane MEM
# already seated for the sibling. CMake appends every list to the same targets
# and dedupes identical absolute paths, so nothing is compiled twice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_mmt.txt" SLICE_MMT_LINES)
set(SLICE_MMT_SOURCES hal/scene_mg_memory1.cpp
                      unmatched/MgMemory1_StateDispatch.cpp
                      # The aliases the link asked for. Its named trap for
                      # _ZN13dScMgMemory_c9DrawCardsEv is GONE: run mg10 lane F362
                      # decompiled that body (the card draw) into
                      # src/func_ov006_020f3e68.c and slice_mmt.txt carries it.
                      unmatched/MgMemory1_Faces.cpp)
foreach(line IN LISTS SLICE_MMT_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_MMT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Run mg9 lane BOX: THE TWELFTH SEATED MINIGAME CLASS, dScMgSound_c, actor id
# 0x16f = scene 367 -- the minigame the spawn symbol names MgBoomBox. The class
# name is the ROM's own and is proved by the type_info the word BEFORE the
# vtable points at: _ZTV12dScMgSound_c[-1] is 0x0213f6e4, whose name pointer
# is 0x0213f708, which reads "12dScMgSound_c". That record's base pointer is a
# second type_info reading "19dScMgSingle3DBase_c", so this is the FOURTH class
# under that intermediate base and the THIRD one seated under it.
#
# THE hal FILE IS NAMED FOR THE MINIGAME AND NOT FOR THE CLASS, which is the
# one place this seat departs from the flower/memory2 naming:
# hal/scene_mg_sound.cpp already exists and is the FAMILY's ov005
# sound-and-spawn-param seat, so a second file named for dScMgSound_c would
# read as its sibling and is not.
#
# ONE VARIABLE, for the reason the CCN and PPP blocks above state: the slice's
# ov006 bodies are only reachable through the address switch in
# unmatched/MgSound_StateDispatch.cpp, and that file cannot link without them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-367 row, so
# every target that compiles scene_boot.cpp references port_mg_boombox_spawn
# and port_scene_fill_boombox by name -- the same coupling every minigame row
# has.
#
# SIXTEEN DISPATCHER HOST COPIES, NOT FIVE AND NOT ELEVEN. Section 14 raised
# the wall from curling's five to dScMgPanel_c's eleven and said the question
# to ask is "how deep is the machine". This one is two deep over FIFTEEN
# tables: vtable slot 6 is a plain switch that calls TWO open-coded
# dispatchers, one of which drives a thirteen-slot table EVERY ONE OF WHOSE
# STATES IS ITSELF A DISPATCHER. Fifty-seven pairs, every adjustment zero.
# unmatched/MgSound_StateDispatch.cpp carries fifteen of the sixteen; the
# sixteenth is the +0x4f38 sub-object's FIELD member pointer, in the same file.
#
# ALL THREE PMF SHAPES IN ONE CLOSURE, which no earlier seat could state: one
# TU is link-visible, twelve are silent behind extern "C" and found only by the
# `::*` sweep, and two open-code the ARM Itanium sequence in plain ints and are
# invisible to BOTH prescribed detectors. Both sweeps were run over the whole
# closure rather than over an LNK1120.
#
# THREE MORE HOST COPIES ARE NOT WALL WORK, and they are one disease in three
# disguises -- a call that reaches the right code with the wrong ABI. None is
# findable by either prescribed detector, and each was found by a different
# instrument, which is the part worth carrying forward:
#   unmatched/MgSound_ShadowSlot35.cpp replaces src/actors/dScMgSound_c.cpp, a
#     state body that is a delinks join miss AND drops its receiver at a
#     vtable slot 35 call AND approximates the ROM's modulo loop AND writes an
#     int where the ROM writes a byte over a live neighbouring gate AND nests
#     the `n == 0` test where the ROM's is unconditional, so the first of the
#     ten records never gets its flag set. FOUR divergences; its banner claims
#     "Logic verified correct vs ROM" and that file's header is the evidence
#     it is not, and is the ROUTING NOTE that lists all four. Found by READING
#     the body against the ROM; the fourth by the run mg9 reviewer.
#   unmatched/MgShared4f38_ModelRender_020c29dc.cpp -- found by the BATTERY,
#     which renders where this lane's own boots did not.
#   unmatched/MgShared4f38_ShadowFader_020c2924.cpp -- found by a WORD-BY-WORD
#     sweep for `blx Rm` through a register loaded from an object. Nothing
#     else could have: no unresolved symbol, no `::*`, no shadow class in the
#     source to grep for, and every boot clean over it.
# src/ is untouched by all three; the defects are the host's.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors and the arm9 waves under
# them; this class's ov004 delta is TWO lines. CMake appends every list to the
# same targets and dedupes identical absolute paths, so nothing is compiled
# twice. port/slice_box.txt says what it reaches. THE CLASS'S ONE HARD FLOOR IS
# GONE: func_ov006_0211bc8c was a STATE and not a vtable slot, which is why
# section 3's nosrc column read 0 and never saw it, and run mg10 lane F367
# decompiled it -- it is src/func_ov006_0211bc8c.cpp in the slice now.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_box.txt" SLICE_BOX_LINES)
set(SLICE_BOX_SOURCES hal/scene_mg_boombox.cpp
                      unmatched/MgSound_StateDispatch.cpp
                      # REPLACES src/actors/dScMgSound_c.cpp, which is out of the
                      # slice and is a delinks join miss besides.
                      unmatched/MgSound_ShadowSlot35.cpp
                      # The four ordinary /alternatename rows the first link
                      # wave asked for. No trap and no stand-in body.
                      unmatched/MgSound_Faces.cpp
                      # THE SAME THREE SHARED +0x4f38 BODIES THE CUP BLOCK
                      # ABOVE LISTS, host-copied once and named in both blocks
                      # on purpose: CMake dedupes identical source paths within
                      # a target, so each compiles once, and listing them here
                      # keeps this seat's block honest about what its own
                      # closure needs -- a later run that retires the 361 seat
                      # cannot silently delete 367's dependency. Run mg9
                      # adjudication; the evidence is in each file's header.
                      #   020c2b8c  the FIELD-held pointer-to-member dispatch.
                      #             This lane's six routed states are the
                      #             canonical set: 020c22d8 and 020c26f4 are
                      #             installed only from dScMgSound_c's block,
                      #             and 020c26f4 is LIVE in scene 367.
                      #             REPLACES src/func_ov006_020c2b8c.cpp.
                      unmatched/MgShared4f38_SubDispatch.cpp
                      #   020c29dc  the sub-object's model draw, with the same
                      #             PAIR of defects
                      #             MgMemory2_ModelRender_020c1804.cpp and
                      #             MgFlower_ModelRender_020c3bf4.cpp carry -- a
                      #             local shadow class calling ROM vtable byte
                      #             +0x14 at two sites, and four I/O-window
                      #             stores that need the geometry proxy. Found
                      #             by the BATTERY, which renders; this lane's
                      #             own NO_RENDER boots were clean over it.
                      #             RETIRED (run link100, lane FOLD2) -- the
                      #             same row the cup slice above carries, and
                      #             the file was listed by both. The four
                      #             stores are hostgen.py's now.
                      #   020c2924  a RECEIVER DROP at a host C++ virtual -- a
                      #             __cdecl-typed raw vtable read against a
                      #             __thiscall body, where the stack balances so
                      #             nothing faults and no ABI checker can see
                      #             it. Its own sibling one line earlier spells
                      #             the same call correctly and the host copy
                      #             borrows that spelling. Found by a
                      #             WORD-BY-WORD `blx Rm` sweep, not by a link,
                      #             a `::*` sweep, a source grep or a run.
                      #             REPLACES src/func_ov006_020c2924.cpp.
                      unmatched/MgShared4f38_ShadowFader_020c2924.cpp)
foreach(line IN LISTS SLICE_BOX_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_BOX_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# THE STATE RESET SPELLS THE ov004 SINGLETON AS A BARE PLACEHOLDER.
# src/actors/dScMgSound_c.cpp reads `g_020beb68`, which include/decl_common.h
# declares as `extern int *g_020beb68` and which exists in NO config -- the
# same per-TU placeholder defect the LUI and PPP blocks above rename VT and
# HEAP for. THE ADDRESS IS THE BODY'S OWN LITERAL POOL, read out of
# extracted/overlays/overlay_0006.bin: 0x0211c6c0 holds 020BEB68, which is
# data_ov004_020beb68, the live dScMgBase_c the framework keeps. The ROM loads
# the POINTER STORED THERE (`ldr r0,[pc,...]` then `ldr r1,[r0]`), which is
# what the src's `int *` spelling means, so the rename is the whole fix.
# ONE SOURCE, ONE SYMBOL: this is the only TU in the tree that names
# g_020beb68, and the -D is scoped to it rather than made repo-global.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/dScMgSound_c.cpp"
    # and the generated copy, lane DUPES: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set the property on a source
    # nothing compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/dScMgSound_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS "g_020beb68=data_ov004_020beb68")

# run mg9 lane S371: dScMgAmida_c, actor id 0x173 (scene 371) -- THE ONE TRUE
# WIDTH-37 CLASS of the twenty-nine. Slot 35 is this class's own
# _ZN12dScMgAmida_c9Virtual8CEv rather than the family terminator ov004 0x020ad660, and
# slot 36 is a real 37th virtual, _ZN12dScMgAmida_c5Unk36Ev, reached by a load
# relocation and dispatched twenty-five times inside the class's own code.
# port/slice_s371.txt writes out how each of port/mg_fanout_costs.txt section
# 11's three checks answers for a genuine 37.
#
# ONE TABLE, TWO DEEP. Scene -> dScMgBase_c (ov004 0x020bc0c0) -> dScMgAmida_c
# (ov006 0x0213b918). The factory and both destructors each store exactly one
# vtable word, so there is one face array and no hostgen substitution.
#
# NOTHING IS HOST-COPIED FOR THIS CLASS, which is the difference between this
# block and the S75 and PPP blocks above it. The class has no pointer-to-member
# state machine at all -- its overlay constructor builds no pair table, no TU
# declares a member-pointer type, and the only twelve DATA relocations into its
# code block are the SpawnInfo's factory word and the eleven vtable slots. So
# no slice line is excluded and there is no duplicate-symbol assertion to make.
#
# unmatched/MgAmida_Faces.cpp IS NOT A FACE FILE DESPITE THE NAME, and as of
# run mg10 lane WALKER it is not a TRAP file either -- it traps nothing. It held
# the two counting traps for func_ov006_020d27dc (0xe48) and
# func_ov006_020d36a4 (0x4fc); both are decompiled now and both traps are
# deleted, so what is left is the DERIVATION that found the holes. It stays in
# the slice because that derivation -- a delinks join over every callee of every
# override, which is the check that finds a callee-shaped floor when the nosrc
# column reads zero -- is the reusable part, and deleting the file would delete
# it.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_s371.txt" SLICE_S371_LINES)
set(SLICE_S371_SOURCES hal/scene_mg_amida.cpp
                       unmatched/MgAmida_Faces.cpp)
                       # unmatched/MgAmida_Slot3ba0.cpp RETIRED run link100
                       # wave 15, lane SEAT15D. It REPLACED
                       # src/func_ov006_020d3ba0.cpp because that TU's
                       # extern "C" block tentatively defined the arm9 RNG
                       # seed -- one token. src:34 now reads
                       # `extern int data_0209d4b8;`, so the matched TU is
                       # taken instead, through port/slice_l15mg.txt and the
                       # SEAT15D block below. Put this line back only together
                       # with the slice line.
foreach(line IN LISTS SLICE_S371_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_S371_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# NO FLOOR HAS TO STAY OUT OF THIS SLICE ANY MORE, run mg10 lane WALKER, and
# the whole sequencing guard is gone with the last trap it sequenced. It named
# two bodies at run mg9, one after run mg10 lane F371, and none now:
# src/func_ov006_020d27dc.c is a real decompilation in the slice and its trap in
# unmatched/MgAmida_Faces.cpp is deleted, so an assertion naming it would refuse
# the very landing it was written to sequence -- which is exactly the reasoning
# that retired the 020d36a4 rows one wave earlier, applied to the last row.
#
# WHAT THE GUARD WAS FOR is worth keeping in words even though the code is gone,
# because the next class with a trapped callee needs it: a slice line that comes
# back while a trap still defines the same symbol is a duplicate symbol, and the
# link reports that as a wall far from its cause. The rule the two retirements
# share is that the trap and the slice line move IN THE SAME COMMIT.
# And the one host-copied body, for the same reason the S75 block asserts its
# five: a slice line that came back would be a duplicate symbol far from its
# cause, and taking the src one instead would put the arm9 RNG seed's second
# definition back.
if("src/func_ov006_020d3ba0.cpp" IN_LIST SLICE_S371_LINES)
    message(FATAL_ERROR "slice_s371.txt lists src/func_ov006_020d3ba0.cpp, which "
            "port/slice_l15mg.txt now carries (run link100 wave 15, lane "
            "SEAT15D: main respelled line 34 `extern int data_0209d4b8;`, so "
            "unmatched/MgAmida_Slot3ba0.cpp is retired and the matched TU is "
            "taken). Listing it twice is a duplicate symbol reported far from "
            "its cause")
endif()
# ONE .c IN THIS SLICE IS REALLY C++, run mg10 lane F371, and the whole slice
# was swept for the //cpp marker and for extern "C", virtual, class and
# namespace rather than the file being found by a compile error.
# src/func_ov006_020d36a4.cpp is the only hit that is IN the slice: it dispatches
# vtable slot 36 through a dummy 37-virtual struct, which is how
# src/func_ov006_020d3ba0.cpp spells the same dispatch in the same class. That
# file is also //cpp and is host-copied instead, so it is not a second row.
#
# AND IT IS DECLARED extern "C" INSIDE, which is the half hostgen cannot do for
# it: tools/hostgen.py wraps every .c in extern "C" unconditionally, and a
# //cpp file's struct-with-virtuals inside that wrap is not what is wanted. The
# TU spells its own linkage.
#
# AND RUN mg10 LANE WALKER MAKES IT TWO. src/func_ov006_020d27dc.c is //cpp for
# the same reason and spells its own extern "C" for the same reason: it
# dispatches slot 36 three times through the same dummy 37-virtual struct.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020d36a4.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020d27dc.c"
    PROPERTIES LANGUAGE CXX)

# ---- run link100 wave 15, lane SEAT15D: LINK15 BATCH 3 -----------------------
#
# THREE HOST COPIES RETIRED AND THEIR MATCHED SOURCES TAKEN, because each was
# written against a spelling in src/ that main has since fixed. The reading is
# in port/slice_l15mg.txt, one paragraph per row, with the src line numbers as
# they stand at 2ddf31f57; the two rows LINK15 put in the same batch that are
# NOT here are refused there with their measured reasons.
#
#   unmatched/MgAmida_Slot3ba0.cpp      -> src/func_ov006_020d3ba0.cpp
#   unmatched/MgPachinko_OamRender.cpp  -> src/func_ov006_020fa7b8.cpp
#   unmatched/MgFlower_InitScore.cpp    -> src/func_ov004_020ad8b8.c
#
# Each host file keeps its banner and is marked RETIRED at the top; its
# source-list entry above is commented out rather than deleted, so a lane that
# has to put one back can see both halves of the swap. THE HOST LINE AND THE
# SLICE LINE MOVE IN THE SAME COMMIT, which is the rule the S371 block states
# in words a few lines up: taking both is a duplicate symbol reported far from
# its cause.
#
# WHY THE SOURCES RIDE SLICE_S371_SOURCES rather than a variable of their own
# on the three target source lists: those three lines are one line each, every
# wave-15 batch has to edit them, and a list this block appends to is already
# on all three. Nothing about the S371 slice is assumed; the append is the last
# statement of this block and SLICE_S371_SOURCES is not read again before the
# targets.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_l15mg.txt" SLICE_L15MG_LINES)
set(SLICE_L15MG_SOURCES "")
foreach(line IN LISTS SLICE_L15MG_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_L15MG_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# A slice that silently empties would take the bodies out of the link
# with no error until a scene dispatched one, so the count is asserted. Run
# link100 wave 15, lane ESP3D added the fourth row (CleanupResources,
# seated by flipping its port/faces_sync.txt row F -> R instead of a plain
# slice-line swap), so the floor moved from three to four.
list(LENGTH SLICE_L15MG_SOURCES l15mg_have)
if(NOT l15mg_have EQUAL 4)
    message(FATAL_ERROR "slice_l15mg.txt lists ${l15mg_have} sources, expected "
            "the four LINK15 BATCH 3 rows (three from lane SEAT15D plus "
            "CleanupResources from lane ESP3D); the retired host copies in "
            "port/unmatched/ no longer define them")
endif()
list(APPEND SLICE_S371_SOURCES ${SLICE_L15MG_SOURCES})

# Run mg9 lane S381: dScMgMCarlo_c, the "Pair-a-Gone" card minigame, actor id
# 0x17d = scene 381, and the FOURTH class the port seats under
# dScMgSingle3DBase_c.
#
#   Scene -> dScMgBase_c (ov004 0x020bc0c0) -> dScMgSingle3DBase_c
#         (ov006 0x0213e448) -> dScMgMCarlo_c (ov006 0x0213d664)
#
# both new tables 36 slots wide and checked FOUR ways before a word was written
# (port/slice_s381.txt): span, terminal slot, what the word past the end is,
# and the relocation count inside the span. The ROM gives this id no spawn
# symbol at all, so the whole identity -- class name, hierarchy and player
# title -- is derived from the ROM in that file's header.
#
# WHAT IT DOES NOT NEED IS AGAIN THE INTERESTING PART, and this class makes it
# three: like dScMgFlower_c and unlike dScMgMemory2_c, it has NO mwcc
# pointer-to-member state machine. Slot 6 and slot 19 are plain switches on the
# same s16 at +0x60a8, no overlay constructor builds a pair table for it (zero
# relocations leave ov006's .init code for its cluster), and a `::*` sweep over
# every TU in the slice is clean. So there is no address switch, no dispatcher
# host copy and no stategen output on this lane.
#
# NO HOSTGEN SUBSTITUTION EITHER, and that is a decision rather than an
# omission. Two of this class's own bodies dereference a literal in the
# 0x04xxxxxx window -- src/minigames/d_s_mg_m_carlo.cpp writes BG0CNT at 0x04000008
# and the sub engine's 0x0400100a -- and both are ordinary PPU control
# registers the display reads back out of the memory ntr maps there. The
# registers that need tools/hostgen.py's NTR_MMIO proxy are the WRITE-TRIGGERED
# ones (the geometry engine, LIGHT_COLOR at 0x040004cc), which is the defect
# run mg5 lane YTEX measured in _ZN19dScMgSingle3DBase_c9Virtual84Ev -- and that body comes in
# through FLW_HOSTGEN_GEN above, already substituted. dScMgFlower_c's own slot
# 0 writes the same class of PPU register straight from src/ for the same
# reason. This paragraph exists so the next lane does not read the absence as
# an oversight.
#
# ONE VARIABLE, for the reason the flower and fader blocks give: the slice and
# the .cpp are not separable. hal/scene_boot.cpp's port_scene_classes table now
# carries the scene-381 row, so every target that compiles scene_boot.cpp
# references port_mg_mcarlo_spawn and port_scene_fill_mcarlo by name.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors and the arm9 waves under
# them, and slice_mem.txt carries the whole Single3D sub-object family this
# class shares with dScMgMemory2_c -- including the three host copies that
# family owes (MgMemory2_ModelRender_020c1804.cpp among them, which this
# class's Render reaches). CMake appends every list to the same targets and
# dedupes identical absolute paths, so nothing is compiled twice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_s381.txt" SLICE_S381_LINES)
set(SLICE_S381_SOURCES hal/scene_mg_mcarlo.cpp)
foreach(line IN LISTS SLICE_S381_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_S381_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run mg9 lane WIG: dScMgHanachan_c, actor id 0x182 (scene 386) -- the "Which
# Wiggler" minigame.
#
# ONE TABLE, TWO DEEP. Scene -> dScMgBase_c (ov004 0x020bc0c0) ->
# dScMgHanachan_c (ov006 0x0213cab8), 36 slots, checked FIVE ways before a word
# was written (port/slice_wig.txt): the span, the terminal slot, what the word
# past it is, this lane's own addition of the relocation COUNT inside the table
# (exactly 36, with no row at index 36), and run mg9 lane LKY's relocation
# STRIDE (4 for exactly 36 words from 0x0213cab8, then 8 to 0x0213cb4c, the jump
# being the table ending). No intermediate table, so there is one face array and
# no hostgen substitution.
#
# THE WALL IS THE FIELD FORM AND THE LINK IS BLIND TO ALL OF IT. This class has
# NO overlay constructor and NO state table: THIRTY-FIVE {code, 0} pairs sit in
# .data at 0x0213c95c..0x0213ca74, holding fifteen distinct code words, and are
# installed by name into member-pointer FIELDS of two different
# objects. Five TUs dispatch them and not one emits a symbol a link could fail
# on. Four are findable by a `::*` source sweep; the fifth, func_ov006_020eb610,
# open-codes the ARM Itanium sequence in plain ints and is findable by neither
# prescribed detector -- it was found by decoding every word of ov006's text and
# matching `add Rd,Rn,Rm,asr #1` followed by `ands Rm,Rm,#1`. All five are
# host-copied in unmatched/MgWiggler_StateDispatch.cpp and all five are
# therefore OUT of slice_wig.txt: listing both copies would be a duplicate
# symbol, and listing neither would drop the dispatch silently. The assertion
# below is here rather than at the link because a duplicate-symbol wall reports
# far from its cause.
#
# THE SEAT IS NOT OPTIONAL ON ANY OF THE THREE TARGETS. hal/scene_boot.cpp's
# port_scene_classes table carries the scene-386 row, so every target that
# compiles scene_boot.cpp references port_mg_wiggler_spawn and
# port_scene_fill_wiggler by name -- the same coupling every other scene row
# has.
#
# unmatched/MgWiggler_Faces.cpp CARRIES THREE /alternatename ROWS, ONE ARGUMENT
# FACE AND THE TWO NAMED TRAPS, and its own header enumerates all six. The three
# alias rows are the .data pairs src/actors/dScMgHanachan_c.cpp declares outside its
# extern "C" block (0x0213c96c, 0x0213c9bc, 0x0213c9c4), alias-safe because that
# TU spells them as two ints; the face is func_0203adec, which is arm9's
# _Z14ApproachLinearRsss under an address-shaped name. The traps are
# func_ov006_020ea914 -- the sole call SITE of which is inside slot 9 Render, at
# 0x020ed0c8, and it is the only arm_call relocation reaching that body anywhere
# in ov006 -- and func_ov006_020ec4dc, wiggler set-up variant 3 of 4. Both traps
# have a config symbol, no delink block and no src file in any module.
#
# NO VT OR HEAP RENAME IS OWED, which is why this block sets no per-source
# COMPILE_DEFINITIONS the way the SOS and S75 blocks above do: both of this
# class's destructors spell data_ov006_0213cab8 by its config name, and a COFF
# short-name scan for _VT and _HEAP over all 180 of this seat's built objects
# finds nothing.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_wig.txt" SLICE_WIG_LINES)
set(SLICE_WIG_SOURCES hal/scene_mg_wiggler.cpp
                      unmatched/MgWiggler_StateDispatch.cpp
                      unmatched/MgWiggler_Faces.cpp)
foreach(line IN LISTS SLICE_WIG_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_WIG_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# Run link100, lane HOSTGEN2: THE ASSERTION IS RETIRED, not widened. Its five
# entries were five separate per-function files when it was written and the
# sync's rename collapsed all five onto the one consolidated TU, so the list
# refused the whole class five times over. All five of those bodies are commented
# out in unmatched/MgWiggler_StateDispatch.cpp now and the TU is a whole-TU
# hostgen substitution, which is the shape the assertion's own last clause asks
# for: "taking the src one puts the mwcc member-pointer stride back" is answered
# by /vmg /vmm for the stride and by the PMF_SEAM rows for the DS code word.
# What replaces it is hostgen's own residue check, which refuses to emit this TU
# if a dispatch site in it is neither routed nor listed as correct raw -- a check
# on the text rather than on a filename, so a body main moves cannot slip past it.
#
# The assertion's own words are kept here so the derivation stays readable:
#   foreach(dup IN ITEMS src/actors/dScMgHanachan_c.cpp, five times)
#     if(dup IN_LIST SLICE_WIG_LINES) -> FATAL_ERROR "slice_wig.txt lists it,
#     which unmatched/MgWiggler_StateDispatch.cpp host-copies. Taking both is a
#     duplicate symbol; taking the src one puts the mwcc member-pointer stride
#     back"

# Run mg9 lane BOO: dScMgTeresa_c, actor id 0x183 = scene 387, "Hide and Boo
# Seek". The class name is the ROM's own and is proved by the type_info the
# word BEFORE the vtable points at: relocs.txt has from:0x0213fa08 to:
# 0x0213f9b4, and that record's name pointer 0x0213f9c0 reads
# "13dScMgTeresa_c". The spawn symbol MgHideAndBooSeek carries the player
# title and is the weaker witness.
#
# ONE VARIABLE, for the reason the PPP and MEM blocks above state: the slice's
# ov006 bodies are only reachable through the address switches in
# unmatched/MgTeresa_StateDispatch.cpp -- the pair words are mounted DATA
# holding DS addresses, so nothing else in the build names them and /OPT:REF
# would drop all twenty-six -- and that file cannot link without them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-387 row, so
# every target that compiles scene_boot.cpp references port_mg_booseek_spawn
# and port_scene_fill_booseek and needs both halves.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors (including this class's own,
# __sinit_ov006_02132f68) and the arm9 waves under them; this class's ov004
# delta is measured ZERO and so is its arm9 delta. CMake appends both lists to
# the same target and dedupes identical absolute paths, so nothing is compiled
# twice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_boo.txt" SLICE_BOO_LINES)
set(SLICE_BOO_SOURCES hal/scene_mg_booseek.cpp
                      unmatched/MgTeresa_StateDispatch.cpp
                      # unmatched/MgTeresa_InitResources.cpp RETIRED (run
                      # linkfull, lane RS4PORT): main #3107 dropped the
                      # `f2 += 0;` no-op MSVC refused (C2036), so
                      # src/_ZN13dScMgTeresa_c13InitResourcesEv.cpp compiles
                      # and is on slice_boo.txt.
                      # REPLACES src/func_ov004_020b6b40.c and
                      # src/func_ov004_020b6c9c.c, both commented out of
                      # slice_mg1.txt in the same commit. THIS IS THE FAMILY'S
                      # DEFECT AND NOT THIS CLASS'S: both bodies call vtable
                      # slot 19 through a shadow array with a plain C function
                      # pointer, so MSVC cleans eight bytes at the call while
                      # hal/scene_mg.cpp's __fastcall mb_v19 cleans four of
                      # them itself, and the body's own epilogue then returns
                      # to a stack word that is not a return address. It rides
                      # THIS variable rather than slice_mg1's because the two
                      # lists reach the same three targets and this lane
                      # derived it; a later lane may want to move it. Scene
                      # 387 is the first seated scene whose FRAMEWORK state
                      # machine runs at all, which is why nothing had reached
                      # these two before.
                      unmatched/MgBase_ShadowSlot19.cpp)
foreach(line IN LISTS SLICE_BOO_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_BOO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# THE DELETING DESTRUCTOR SPELLS ITS OWN TABLE AS THE SHARED PLACEHOLDER `VT`,
# which is the defect the LUI and PPP blocks above rename one TU each for.
# src/actors/dScMgTeresa_c.cpp is `t[0] = (int)VT;` and hal/cxx_aliases.cpp binds
# bare VT to _data_ov002_021081e4, the ENEMY base table, so without this the
# class's D0 would install another class's vtable on the way down. The address
# below is the body's OWN literal pool, read out of
# extracted/overlays/overlay_0006.bin: 0x0211cc24 holds 0213FA0C.
#
# HEAP IS DELIBERATELY NOT RENAMED. The second pool word at 0x0211cc28 is
# 020A0EAC, which is the game heap hal/cxx_aliases.cpp already binds bare HEAP
# to, so a rename here would be a no-op that later reads as a derivation.
#
# THE SIBLING NEEDS NOTHING. Slot 16, src/actors/dScMgTeresa_c.cpp, spells its
# table as data_ov006_0213fa0c directly rather than as VT, so only one of the
# destructor pair is renamed. A sweep of all 76 slice TUs for bare VT/VT0/VT1/
# VT2/HEAP finds exactly this file plus a COMMENT in
# src/d_s_mg_teresa.c, whose code uses _ZTV13dScMgTeresa_c and is
# served by the alias row in hal/scene_mg_booseek.cpp instead.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/dScMgTeresa_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=data_ov006_0213fa0c")

# TWO OF THE SEVENTY-ONE .c FILES IN THIS SLICE ARE REALLY C++ -- a //cpp
# marker and a top-level `extern "C"` block, which is invalid C. All 71 were
# SWEPT for the marker and for `extern "C"`, `virtual`, `class`, `namespace`,
# `bool` and `new`/`delete` rather than these two being found by a compile
# error and the other sixty-nine left to luck, which is the sweep the SMB block
# above records doing for its thirty-seven. These are the only hits.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_0211ea70.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_0211f9fc.c"
    PROPERTIES LANGUAGE CXX)

# Run mg9 lane PSY: dScMg3DEsp_c ("Psyche Out!"), actor id 0x185 = scene 389,
# and the THIRD class the port seats under dScMgSingle3DBase_c.
#
#   Scene -> dScMgBase_c (ov004 0x020bc0c0) -> dScMgSingle3DBase_c
#         (ov006 0x0213e448) -> dScMg3DEsp_c (ov006 0x0213c8c4)
#
# all three tables 36 slots wide, and the derived one checked FIVE ways before a
# word was written (port/slice_psy.txt): span, terminal slot, what the word past
# the end is, the relocation COUNT -- this lane's addition, because a vtable
# slot is a relocated code pointer and word 36 carries no relocation at all --
# and the relocation STRIDE, run mg9 lane LKY's check, which needs no config
# symbol: 4 bytes for thirty-five consecutive steps and then twelve.
#
# THE CLASS NAME IS THE ROM'S OWN type_info, reached through the word before the
# vtable: _ZTV12dScMg3DEsp_c[-1] is 0x0213c7c8, whose name pointer is
# 0x0213c7d4, which reads "12dScMg3DEsp_c".
#
# ONE VARIABLE, for the reason every minigame block above gives: the slice's
# ov006 bodies are only reachable through the address switches in
# unmatched/Mg3DEsp_StateDispatch.cpp, and that file cannot link without them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-389 row, so
# every target that compiles scene_boot.cpp references port_mg_esp3d_spawn and
# port_scene_fill_esp3d by name.
#
# SEVEN DISPATCHER HOST COPIES, AND THE MACHINE IS THREE LEVELS DEEP. Section
# 14 of port/mg_fanout_costs.txt says the cost question is "how deep is the
# machine"; dScMgPanel_c's answer was two and this class's is three. TWO of the
# seven are the open-coded-int third shape that neither a link nor a `::*` sweep
# can see, and one of those two (func_ov006_020e8830) is reachable only through
# the other, so both prescribed detectors read clean over this class.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors (this class's included) and
# the arm9 waves under them; slice_flw.txt and slice_mem.txt already carry all
# six of the middle base's bodies. CMake appends every list to the same targets
# and dedupes identical absolute paths, so nothing is compiled twice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_psy.txt" SLICE_PSY_LINES)
set(SLICE_PSY_SOURCES hal/scene_mg_psycheout.cpp
                      unmatched/Mg3DEsp_StateDispatch.cpp
                      # unmatched/Mg3DEsp_Cleanup.cpp RETIRED run link100 wave
                      # 15, lane ESP3D. src/_ZN12dScMg3DEsp_c16CleanupResourcesEv.cpp
                      # is a real C++ member and is taken instead, through
                      # port/slice_l15mg.txt; the flat Itanium name its one
                      # caller (hal/scene_mg_psycheout.cpp) spells is now
                      # published by the generated REVERSE face its
                      # port/faces_sync.txt row asks for (F -> R). Put this
                      # line back only together with the slice line, or the
                      # link gets two definitions of the flat name.
                      # unmatched/Mg3DEsp_Cleanup.cpp
                      # REPLACES src/_ZN15dMg3DEspModel_c8BehaviorEv.cpp, out of the slice:
                      # the EIGHTH dispatcher, and the one that reads its member
                      # pointer out of an OBJECT FIELD rather than a table. No
                      # link can name that defect -- the type is local to the TU
                      # so no global is emitted -- and the `::*` sweep over the
                      # wave-2 additions is what found it.
                      unmatched/Mg3DEsp_FieldPmf.cpp
                      # The alias rows the link asked for and the five
                      # shadow-class destructors src's two destructors spell.
                      unmatched/Mg3DEsp_Faces.cpp
                      )
# unmatched/Mg3DEsp_ModelAnimRender_020e7b44.cpp and
# unmatched/Mg3DEsp_ModelAnimRender_020e777c.cpp RETIRED (run link100, lane
# FOLD2). They were the two TUs hal/cxxname_bridge.cpp's ModelAnim2 block
# predicted by name when it wrote that trap-by-Virtual18 would name such a TU
# if one ever appeared -- the folded host table put Virtual18 on ROM slot 5.
# That prediction is retracted in the same file now: _ZTV9ModelAnim[5] is
# ModelAnim::Render again, and src/_ZN15dMg3DEspModel_c6RenderEv.cpp and
# src/_ZN17dMg3DEspAnimSet_c6RenderEv.cpp carry both bodies (port/slice_fold2.txt).
foreach(line IN LISTS SLICE_PSY_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PSY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ONE .c IN THIS SLICE IS REALLY C++, and all twenty-seven were swept for it
# rather than one being found by a compile error and the rest left to luck.
# src/func_ov006_020e8bd0.cpp opens with a //cpp marker and declares both its
# callee and itself inside `extern "C"`, which is invalid C. The sweep was for
# the marker and for extern "C", virtual, class and namespace across every .c
# path in port/slice_psy.txt; it is the only hit. Same repair the ov006 smartball
# block above uses for src/_ZN20cMgSmartball_dokan_c12SaveSnapshotEv.c.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020e8bd0.cpp"
    PROPERTIES LANGUAGE CXX)

# NO PER-SOURCE -D ROW FOR THIS CLASS, AND THE REASON IS REUSABLE.
# src/_ZN12dScMg3DEsp_c16CleanupResourcesEv.cpp (slot 3, CleanupResources) releases two
# SharedFilePtrs spelled as the shared placeholders G0 and G1, and
# hal/cxx_aliases.cpp binds bare G0 to _data_020a0eac (the game heap) and bare
# G1 to _data_ov002_0210e05c -- both wrong for this TU, and neither would fail
# a link. The body's OWN literal pool says what they are, read out of
# extracted/overlays/overlay_0006.bin at 0x020e9d14 and 0x020e9d18: 0x02141e9c
# and 0x02141e74, the two SharedFilePtrs src/__sinit_ov006_02130a08.c
# constructs for file ids 0x1ef and 0x202.
#
# THE STANDING REPAIR IS A PER-SOURCE RENAME AND IT CANNOT BE USED HERE. The
# two rows above this block do it (VT and VT0), and it works when the
# placeholder is declared in the TU and the target is not declared anywhere the
# TU can see. G1 and its target are BOTH in include/decl_common.h -- line 396
# is `extern int G1[];` and line 3041 is `extern void*data_ov006_02141e74;` --
# so `-DG1=data_ov006_02141e74` rewrites line 396 into a redefinition of line
# 3041 with a different type of indirection. Measured: error C2372. Host-copied
# in unmatched/Mg3DEsp_Cleanup.cpp instead, and the src TU is out of the slice.
#
# A scan of every TU in port/slice_psy.txt for VT, VT0, HEAP, G0, G1, G2, R0,
# R1 and R2 returns that ONE file. func_020beb68 in src/_ZN12dScMg3DEsp_c13OnYoshiTryEatEi.cpp
# needs no row: unmatched/MgCoin_Faces.cpp already aliases it onto
# data_ov004_020beb68.

# Lane FDR: the arm9 wipe fader's own static initialiser, and the dWipe_c
# vtable it installs. Rides the SAME three targets as the scene seats above,
# and for a stronger reason than symmetry: hal/fdr_arm9_fader_seat.cpp defines
# data_020926f0 and data_0209f610, and it RUNS src/__sinit_02074f80.c from a
# C++ static initialiser. Leave the file off one of the three and that target's
# data_0209f61c keeps a null vptr while the other two do not, which is the kind
# of split nobody notices until a scene faults on one binary and not the other.
#
# It is one variable rather than two because the .cpp and the slice are not
# separable: the slice's bodies are only reachable through the table the .cpp
# fills, and the .cpp cannot link without them.
# Lane LKY of run mg9: dScMgBSC_c, actor id 0x184, scene 388, "Lucky Stars".
# The twelfth ov006 minigame class and the THIRD under dScMgSingle3DBase_c
# (the flower and Memory Master are the other two), so hal/scene_mg_flower.cpp
# claims the middle table at 0x0213e448 and this seat owns only its own
# derived table at 0x0213fec8. port/slice_lky.txt is the derivation, including
# the four width checks and the reason a 37-slot fill here would write into
# MgSnowballSlalom's live state pair.
#
# ONE VARIABLE, for the reason the flower, memory2 and fader blocks give: the
# slice's ov006 bodies are only reachable through the address switch in
# unmatched/MgBSC_StateDispatch.cpp, and that file cannot link without them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-388 row, so
# every target that compiles scene_boot.cpp references port_mg_luckystars_spawn
# and port_scene_fill_luckystars by name.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors (both of this class's among
# them) and the arm9 waves under them; CMake appends every list to the same
# targets and dedupes identical absolute paths, so nothing is compiled twice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_lky.txt" SLICE_LKY_LINES)
set(SLICE_LKY_SOURCES hal/scene_mg_luckystars.cpp
                      # The one pointer-to-member host copy: vtable SLOT 6.
                      # Its src declares the pair table inside extern "C", so
                      # the link and the compile both read clean while MSVC
                      # strides an eight-byte table by four -- one of the two
                      # SILENT shapes port/mg_fanout_costs.txt section 4 names.
                      # src/minigames/d_s_mg_bsc.cpp is out of the slice.
                      unmatched/MgBSC_StateDispatch.cpp
                      # The one /alternatename row the first link asked for:
                      # the class vtable declared at C++ linkage in the factory.
                      unmatched/MgBSC_Faces.cpp)
foreach(line IN LISTS SLICE_LKY_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_LKY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Run mg11 lane BNP: dScMgJump_c, actor id 0x174, scene 372, "Bounce and
# Pounce". The class name is the ROM's own RTTI, reached through the type_info
# the word BEFORE the vtable points at (0x0213cbe0 -> 0x0213cb98 -> 0x0213cba4
# = "11dScMgJump_c"), and the player title is the ROM's own BMG message 552
# reached through the ov005 launch table's ONE row for this id.
# port/slice_bnp.txt is the derivation: five width checks, the fourteen ROM
# adjudications, the seven state pairs and the one floor.
#
# THIS IS THE FIRST OF FOUR CLASSES UNDER dScMgD3DBase_c (0x174, 0x175, 0x180,
# 0x181), and FOUR of the files below are named for the BASE and are reusable by
# the whole family rather than owned by this lane:
#
#   unmatched/MgD3DBase_Slots.cpp            slots 2, 10, 27, 28   (also BNT's)
#   unmatched/MgD3DBase_DeclConflict.cpp     slot 24, the C2733    (also BNT's)
#   unmatched/MgD3DBase_ModelAnimRender.cpp  the ModelAnim draws   (also BNT's)
#   unmatched/MgD3DBase_ObjStateDispatch.cpp the two shared PMF dispatchers
#                                            -- BNP-ONLY, see below
#
# THREE of the four are files lane BNT wrote as well. BNP and BNT hit those
# three independently, from two different scenes, and converged on the same
# filenames and the same symbol names precisely so the two trees collide in ONE
# visible place each instead of producing three duplicate symbols.
#
# THE FOURTH IS BNP-ONLY and the distinction matters at the merge: BNT's tree has
# no MgD3DBase_ObjStateDispatch.cpp and defines none of its symbols, because its
# closure does not reach those two dispatchers. Nothing collides on it.
#
# AND THE THREE CONVERGED FILES ARE NOT BYTE-IDENTICAL, so the merge gate must
# resolve three ADD/ADD conflicts by PICKING ONE COPY -- it does not get a free
# dedupe. Comment-stripped diffs: BNT's Slots carries a vestigial
# `#include <cstdio>` nothing uses; DeclConflict is CODE-IDENTICAL and differs
# only in prose; ModelAnimRender differs in type spelling (BNT forward-declares
# struct OamAttr / Matrix2x2 unqualified, this copy includes common.h and uses
# the struct keyword) over the same two bodies. What lane TTI carries is in
# port/slice_bnp.txt section 9 and is NOT "all four byte-identical": TTI has TWO
# of the four, DeclConflict byte-identical and Slots prose-only-different, with
# ModelAnimRender and ObjStateDispatch absent. Stated there rather than here,
# and pinned to a commit, because an identity claim written inside one of the
# files being compared falsifies itself the moment it is saved.
#
# The dScMgD3DBase_c half of slice_bnp.txt IS safe to list twice: CMake appends
# every list to the same targets and dedupes identical absolute paths.
#
# ONE VARIABLE, for the reason the flower, memory2, LKY and BOO blocks give:
# the slice's ov006 bodies are only reachable through the address switches in
# unmatched/MgBounceAndPounce_StateDispatch.cpp and
# unmatched/MgD3DBase_ObjStateDispatch.cpp -- the state pairs are mounted DATA
# holding DS addresses, so nothing else in the build names them and /OPT:REF
# would drop them -- and those files cannot link without them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-372 row, so
# every target that compiles scene_boot.cpp references port_mg_jump_spawn and
# port_scene_fill_jump by name.
#
# ONE TU IN THIS SLICE REACHES THE GEOMETRY REGISTERS, so it builds from a
# hostgen-emitted copy the way the flower block's _ZN19dScMgSingle3DBase_c9Virtual84Ev and the
# BNT block's func_ov006_020ef2b8 already do -- src/ itself is never edited.
#
# _ZN11dScMgJump_c6RenderEv is dScMgJump_c::Render, vtable SLOT 9 (the row the slice
# header prints at 020b04ec), so it runs before every drawn frame of scene 372.
# Its second half is this scene's LIGHT SETUP and it is the same six-store
# shape scene 373 carries one class over:
#
#     0x040004c8 = pack(v)            LIGHT_VECTOR, light 0
#     0x040004cc = 0x7fff             LIGHT_COLOR, light 0 white
#     0x040004cc = 0x40007fff         LIGHT_COLOR, light 1 white
#     0x040004c8 = pack(w)|1<<30      LIGHT_VECTOR, light 1
#
# where v and w are both (0,0,-0x0ff8) turned -0x2000 by func_0203cd80, a 45
# degree tilt.  Compiled straight from src/ all four land in the real memory
# ntr maps across the I/O window and stop there: the geometry engine is never
# told.  Both lights keep direction (0,0,0) and colour (0,0,0), and ntr/gx.cpp
# resolves a lit vertex as emission + SUM over the enabled lights of (diffuse *
# lightcol * dot + ambient * lightcol), so a zero light colour kills the
# ambient term too.  The one POLYGON_ATTR this scene submits is 001f8081 --
# light 0 enabled -- and its SPE_EMI is 00000000, so every lit vertex resolves
# to BLACK.
#
# MEASURED in this tree (SM64DS_MAT_LOG=1 SM64DS_SCENE=372), before this line:
#
#     [mat] LIGHT_VECTOR commands executed: 0   LIGHT_COLOR: 0
#     [mat] POLYGON_ATTR 001f8081 lights=1000, SPE_EMI 00000000
#
# Control on the same binary, scene 373, whose light body is already
# substituted: LIGHT_VECTOR 2, LIGHT_COLOR 2.
set(BNP_HOSTGEN_SYMS _ZN11dScMgJump_c6RenderEv)
set(BNP_HOSTGEN_GEN "")
set(BNP_HOSTGEN_SKIP "")
foreach(sym IN LISTS BNP_HOSTGEN_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        list(APPEND BNP_HOSTGEN_SKIP "src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
        list(APPEND BNP_HOSTGEN_SKIP "src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND BNP_HOSTGEN_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_bnp.txt" SLICE_BNP_LINES)
set(SLICE_BNP_SOURCES hal/scene_mg_jump.cpp
                      # This class's own pointer-to-member wall: vtable SLOT 6.
                      # src/_ZN11dScMgJump_c8BehaviorEv.cpp is OUT of slice_bnp.txt.
                      unmatched/MgBounceAndPounce_StateDispatch.cpp
                      # The four SHARED base-class repairs. See the block above
                      # before adding any of these from another family lane.
                      unmatched/MgD3DBase_Slots.cpp
                      unmatched/MgD3DBase_DeclConflict.cpp
                      # unmatched/MgD3DBase_ModelAnimRender.cpp RETIRED
                      # (run link100, lane FACEF): all four bodies were the
                      # mwcc virtual-shadow dispatch onto ModelAnim ROM slot 5,
                      # and lane SLOT5F's respelling of the ROM's D1/D0 pair
                      # put Render back at _ZTV9ModelAnim[5] with Virtual18 at
                      # its own slot 6. src/func_ov006_020c4c54.cpp,
                      # _020c7734.cpp, _020c8e90.cpp and _02122814.cpp are on
                      # port/slice_facef.txt; all four define their C name
                      # themselves and none needs a face.
                      unmatched/MgD3DBase_ObjStateDispatch.cpp
                      ${BNP_HOSTGEN_GEN})
foreach(line IN LISTS SLICE_BNP_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # The hostgen'd copy stands in for the src/ one; taking both would be a
    # duplicate symbol, and taking neither would drop the body silently.
    if(line IN_LIST BNP_HOSTGEN_SKIP)
        continue()
    endif()
    list(APPEND SLICE_BNP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# A slice line that stops matching (a rename, a .c that becomes a .cpp) would
# silently take the src/ copy back and put the defect back with it, so the
# substitution asserts rather than hopes.
list(LENGTH BNP_HOSTGEN_SYMS bnp_hg_want)
list(LENGTH BNP_HOSTGEN_GEN bnp_hg_have)
if(NOT bnp_hg_want EQUAL bnp_hg_have)
    message(FATAL_ERROR "slice_bnp hostgen substitution incomplete: "
            "${bnp_hg_have} of ${bnp_hg_want} generated")
endif()
foreach(skip IN LISTS BNP_HOSTGEN_SKIP)
    if(NOT skip IN_LIST SLICE_BNP_LINES)
        message(FATAL_ERROR "slice_bnp.txt no longer lists ${skip}; the "
                "hostgen substitution for it is now dead and the geometry "
                "register writes in it would go back to latching silently")
    endif()
endforeach()
foreach(dup IN ITEMS src/_ZN11dScMgJump_c8BehaviorEv.cpp
                     src/func_ov006_020c4cd8.cpp
                     src/actors/dMgJump3DMario_c.cpp
                     src/func_ov006_020c4c54.cpp
                     src/actors/dMgJump3DMario_c.cpp
                     src/actors/dScMgD3DBase_c.cpp
                     src/actors/dScMgD3DBase_c.cpp
                     src/actors/dScMgD3DBase_c.cpp
                     src/actors/dScMgD3DBase_c.cpp
                     src/actors/dScMgD3DBase_c.cpp)
    if(dup IN_LIST SLICE_BNP_LINES)
        message(FATAL_ERROR "slice_bnp.txt lists ${dup}, which the BNP seat "
                "replaces with its own definition. Taking both is a duplicate "
                "symbol; taking the src one puts back the mwcc member-pointer "
                "stride, the dropped receiver or the C2733 this block exists "
                "to avoid")
    endif()
endforeach()

# Lane BNT of run mg11: dScMgJump2_c, actor id 0x175, scene 373, "Bounce and
# Trounce".  The twenty-second ov006 minigame class and the FIRST under
# dScMgD3DBase_c (data_ov006_0213c62c, which the config misnames
# _ZTV14dScMgD3DBase_c and which 0x174, 0x180 and 0x181 also derive from).
# port/slice_bnt.txt is the derivation: the identity, the ov005 row, the
# sibling-attribution ruling, the width checks on both tables and the closure.
#
# ONE VARIABLE, for the reason the flower, memory2, lucky-stars and fader
# blocks give: the slice's ov006 bodies are only reachable through the two
# address switches in unmatched/MgJump2_FieldPmf.cpp and
# unmatched/MgD3DBase_ObjStateDispatch.cpp, and those files cannot link without
# them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-373 row, so
# every target that compiles scene_boot.cpp references port_mg_jump2_spawn and
# port_scene_fill_jump2 by name.
#
# THE SLICE IS THE DELTA ONLY.  slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors and the arm9 waves under
# them; CMake appends every list to the same targets and dedupes identical
# absolute paths, so nothing is compiled twice -- which is also what makes the
# seventeen dScMgD3DBase_c bodies safe to list in all four of this wave's
# sibling slices.
#
# ONE TU IN THIS SLICE REACHES THE GEOMETRY REGISTERS, so it builds from a
# hostgen-emitted copy the way every other MMIO-touching src/ file in this tree
# does -- src/ itself is never edited.  It is the SAME defect the flower block
# above records at _ZN19dScMgSingle3DBase_c9Virtual84Ev, on a different body.
#
# func_ov006_020ef2b8 is this scene's LIGHT SETUP.  Its only caller is
# src/minigames/d_s_mg_jump2.cpp, dScMgJump2_c vtable slot 9 (Render), which calls
# it as its third statement -- so it runs on EVERY rendered frame, before any
# model is drawn.  Read straight off extracted/overlays/overlay_0006.bin at
# base 0x020bfec0 (0x020ef2b8..0x020ef3bc, pool at 0x020ef3c0) it is six
# literal stores and nothing else:
#
#     0x040004cc = 0x7fff             LIGHT_COLOR, light 0 white
#     0x040004cc = 0x40007fff         LIGHT_COLOR, light 1 white
#     0x040004c8 = pack(v)            LIGHT_VECTOR, light 0
#     0x04000440 = 2                  MTX_MODE, position
#     0x04000454 = 0                  MTX_IDENTITY
#     0x040004c8 = pack(w)|1<<30      LIGHT_VECTOR, light 1
#
# Compiled straight from src/ all six land in the real memory ntr maps across
# the I/O window and stop there: the geometry engine is never told.  Both
# lights keep direction (0,0,0) and colour (0,0,0), and ntr/gx.cpp resolves a
# lit vertex as emission + SUM over the enabled lights of (diffuse * lightcol *
# dot + ambient * lightcol), so a zero light colour kills the ambient term too.
# Every material this scene submits enables light 0 or light 1 (POLYGON_ATTR
# 001f8081 and 001f8082) and every SPE_EMI word it writes is 00000000, so every
# lit vertex in the scene resolves to BLACK.  Mario's model still draws, at
# emission, over the 3D clear colour -- which is the scene-373 report this line
# answers: "a blank screen with glitch textures, and a shadow of mario".  The
# shadow IS the model.
#
# MEASURED in this tree (SM64DS_MAT_LOG=1 SM64DS_SCENE=373), before this line:
#
#     [mat] LIGHT_VECTOR commands executed: 0   LIGHT_COLOR: 0
#     [mat] I/O LATCH  LIGHT_VECTOR(4c8)=6965a400 LIGHT_COLOR(4cc)=40007fff
#
# 0x6965a400 carries bit 30, which is this body's light-1 store: the body RAN
# and its writes arrived nowhere.  Control on the same binary, scene 382, which
# reaches its lights through a body that is already substituted:
#
#     [mat] LIGHT_VECTOR commands executed: 2   LIGHT_COLOR: 2
#
# THE MATRIX PAIR MATTERS TOO and is not incidental.  MTX_MODE and MTX_IDENTITY
# sit BETWEEN the two light vectors because the geometry engine transforms a
# light vector by the current position matrix as it consumes it.  Latching them
# silently would leave light 1 rotated by whatever matrix the previous draw
# left behind even if the two LIGHT_VECTOR writes were fixed on their own, so
# the substitution has to cover the whole body rather than the two registers
# the symptom names.
# PATH FORM, 2026-09-12 (main -> port sync, lane SYNC2). main merged these
# bodies into consolidated translation units under src/<area>/, so the bare
# "src/<symbol>.c" convention this loop assumed no longer finds them and the
# MMIO substitution would have been silently dropped or failed at hostgen. The
# list is repo-relative PATHS now, the whole TU is substituted, and the raw TU
# is commented out of every slice that named it. hostgen rewrites MMIO accesses
# and nothing else, so widening the substitution from one body to its TU keeps
# every other body in the link unchanged.
set(BNT_HOSTGEN_SRCS src/minigames/d_s_mg_jump2.cpp)
set(BNT_HOSTGEN_GEN "")
set(BNT_HOSTGEN_SKIP "")
foreach(rel IN LISTS BNT_HOSTGEN_SRCS)
    if(NOT EXISTS "${PORT_REPO_ROOT_ABS}/${rel}")
        message(FATAL_ERROR "slice_bnt hostgen source ${rel} does not exist; the "
                "MMIO substitution would be silently dropped")
    endif()
    set(sym_src "${PORT_REPO_ROOT_ABS}/${rel}")
    list(APPEND BNT_HOSTGEN_SKIP "${rel}")
    string(REGEX REPLACE "[.](c|cpp)$" ".cpp" rel_out "${rel}")
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/${rel_out}")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${rel}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${rel}")
    list(APPEND BNT_HOSTGEN_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_bnt.txt" SLICE_BNT_LINES)
set(SLICE_BNT_SOURCES hal/scene_mg_jump2.cpp
                      # The class's own pointer-to-member wall: vtable SLOT 6,
                      # dispatching a member pointer held in an OBJECT FIELD at
                      # this+0x5004.  There is no state table and no __sinit
                      # block behind it -- see slice_bnt.txt section 5.
                      # src/minigames/d_s_mg_jump2.cpp is out of the slice.
                      unmatched/MgJump2_FieldPmf.cpp
                      # The two SUB-OBJECT field dispatchers, fields +0x30 and
                      # +0x3c.  Neither is on a vtable.  src/func_ov006_020c4cd8.cpp
                      # and src/actors/dMgJump3DMario_c.cpp are out of the slice.
                      #
                      # THIS LANE WROTE THEM AS unmatched/MgJump2_SubDispatch.cpp
                      # AND LANE BNP WROTE THE SAME TWO SYMBOLS AS
                      # unmatched/MgD3DBase_ObjStateDispatch.cpp.  Different
                      # filenames, so git saw no add/add and the collision only
                      # surfaced as an LNK2005 at the merge.  The two are UNIFIED
                      # into the base-named file below, which carries both lanes'
                      # census APIs; the claim in this block that the pair was
                      # "not shared with the three sibling classes" is what the
                      # merge disproved.  See that file's section 0.
                      unmatched/MgD3DBase_ObjStateDispatch.cpp
                      # dScMgD3DBase_c slot 24, host-copied for the
                      # decl_common.h C2733 run link60 lane MG1 documented for
                      # four dScMgBase_c slots. DELIBERATELY NOT LANE-NAMED:
                      # all four ids under this base need it and all four hit
                      # the same conflict, so the merge keeps exactly one copy.
                      unmatched/MgD3DBase_DeclConflict.cpp
                      # dScMgD3DBase_c slots 2, 10, 27 and 28: four bodies that
                      # each drop an argument the ROM rides through in a
                      # register. Slot 2's dropped RETURN is what put this
                      # class's actor on the cleanup list instead of the
                      # behaviour list on the first run. ALSO NOT LANE-NAMED --
                      # all four ids under this base need all four repairs.
                      unmatched/MgD3DBase_Slots.cpp
                      # The two ModelAnim shadow-render dispatches. ROM slot 5
                      # is MSVC's Virtual18, so the shadow call reached a
                      # two-argument body with one argument and faulted the
                      # RENDERED battery row. Shared with the sibling lanes for
                      # the same reason the file above is.
                      # unmatched/MgD3DBase_ModelAnimRender.cpp RETIRED
                      # (run link100, lane FACEF): all four bodies were the
                      # mwcc virtual-shadow dispatch onto ModelAnim ROM slot 5,
                      # and lane SLOT5F's respelling of the ROM's D1/D0 pair
                      # put Render back at _ZTV9ModelAnim[5] with Virtual18 at
                      # its own slot 6. src/func_ov006_020c4c54.cpp,
                      # _020c7734.cpp, _020c8e90.cpp and _02122814.cpp are on
                      # port/slice_facef.txt; all four define their C name
                      # themselves and none needs a face.
                      # The link faces the FIRST link of this seat asked for:
                      # 27 C++-linkage spellings of C-named DS data, one bare
                      # func_-prefixed name for an ov004 bss word, and three
                      # C++ method spellings of Itanium-named bodies already in
                      # the build. All named by a link, none predicted.
                      unmatched/MgJump2_Faces.cpp
                      ${BNT_HOSTGEN_GEN})
foreach(line IN LISTS SLICE_BNT_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # The hostgen'd copy stands in for the src/ one; taking both would be a
    # duplicate symbol, and taking neither would drop the body silently.
    if(line IN_LIST BNT_HOSTGEN_SKIP)
        continue()
    endif()
    list(APPEND SLICE_BNT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# A slice line that stops matching (a rename, a .c that becomes a .cpp) would
# silently take the src/ copy back and put the defect back with it, so the
# substitution asserts rather than hopes.
list(LENGTH BNT_HOSTGEN_SRCS bnt_hg_want)
list(LENGTH BNT_HOSTGEN_GEN bnt_hg_have)
if(NOT bnt_hg_want EQUAL bnt_hg_have)
    message(FATAL_ERROR "slice_bnt hostgen substitution incomplete: "
            "${bnt_hg_have} of ${bnt_hg_want} generated")
endif()
foreach(skip IN LISTS BNT_HOSTGEN_SKIP)
    if(NOT skip IN_LIST SLICE_BNT_LINES)
        message(FATAL_ERROR "slice_bnt.txt no longer lists ${skip}; the "
                "hostgen substitution for it is now dead and the geometry "
                "register writes in it would go back to latching silently")
    endif()
endforeach()

# Lane SNW of run mg11: dScMgSnowball_c, actor id 0x179, scene 377, "Snowball
# Slalom".  THE ONE CLASS OF THIRTY WHOSE VTABLE NO TOOL RESOLVED --
# port/mg_fanout_costs.txt section 3 left its row blank because no load
# relocation inside its factory points at any signature table.  The reason is
# one delegated constructor: dScMgSnowball_c_classInit allocates and calls
# func_ov006_021295ac, and THAT body writes _ZTV19dScMgSingle3DBase_c and then
# _ZTV15dScMgSnowball_c.  port/slice_snw.txt carries the derivation, the five
# width checks, the ruling-out of the two alternative tables and the wall.
#
# The FOURTH class under dScMgSingle3DBase_c (the flower, Memory Master and
# Lucky Stars are the other three), so hal/scene_mg_flower.cpp claims the
# middle table at 0x0213e448 and this seat owns only its own derived table at
# 0x0214000c.
#
# ONE VARIABLE, for the reason the flower, memory2, luckystars and fader blocks
# give: the slice's ov006 bodies are only reachable through the address switch
# in unmatched/MgSnowball_StateDispatch.cpp, and that file cannot link without
# them.  hal/scene_boot.cpp's port_scene_classes table carries the scene-377
# row, so every target that compiles scene_boot.cpp references
# port_mg_snowball_spawn and port_scene_fill_snowball by name.
#
# THE HOST COPY IS THREE TUs AND NOT ONE, which is what makes this class
# different from every seat before it.  Its vtable slot 6 -- the slot every
# seat wires by name -- contains no pointer-to-member dispatch at all; it CALLS
# func_ov006_0212a2e0, whose table's slots 1 and 2 are two more dispatchers
# that no arm_call in the overlay reaches.  Reading slot 6 alone prices this
# class's wall at zero.
#
# THE SLICE IS THE DELTA ONLY.  slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors (this class's among them) and
# the arm9 waves under them; CMake appends every list to the same targets and
# dedupes identical absolute paths, so nothing is compiled twice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_snw.txt" SLICE_SNW_LINES)
set(SLICE_SNW_SOURCES hal/scene_mg_snowball.cpp
                      # The pointer-to-member host copies: the first-level
                      # dispatcher slot 6 calls, and the two second-level
                      # dispatchers its table holds.  Two of the three declare
                      # their tables inside extern "C" (the SILENT shape: the
                      # link is satisfied and MSVC strides an eight-byte table
                      # by four); the third declares two at C++ linkage (the
                      # LOUD shape).  src/func_ov006_0212a2e0.cpp,
                      # src/func_ov006_0212a224.cpp and
                      # src/func_ov006_02129d94.cpp are out of the slice.
                      unmatched/MgSnowball_StateDispatch.cpp
                      # The one /alternatename row the first link asked for
                      # (this class's vtable declared at C++ linkage in the
                      # constructor).  It used to carry three trapped closure
                      # floors as well; run mg12 lane SNO decompiled and seated
                      # all three through slice_snw.txt section 17, so this
                      # file is now the alias row and its marker only.
                      unmatched/MgSnowball_Faces.cpp)
                      # Vtable SLOT 9, Render.  Not a pointer-to-member TU --
                      # the Itanium scan finds no site in it -- but it carries
                      # the OTHER shadow-dispatch shape Door_Render.cpp and
                      # MgFlower_ModelRender_020c3bf4.cpp name: a C function
                      # pointer read out of a model's vtable and called with
                      # the C convention, into a __fastcall thunk.  The vtable
                      # read is correct (the _ZTV5Model dual fill serves it);
                      # the convention is not, and the stack came back four
                      # bytes short.  Found by a run, not by a checker.
                      # unmatched/MgSnowball_ModelRender.cpp RETIRED (run
                      # link100, lane EXCEPT): the convention is the whole
                      # divergence and tools/hostgen.py now owns it, one
                      # VIRTUAL_CALL row keeping the ROM's word index and the
                      # ROM's arguments.  src/_ZN15dScMgSnowball_c6RenderEv.cpp builds
                      # through the LANE EXCEPT hostgen block at the very
                      # bottom of this file; port/slice_except.txt carries the
                      # vtable word (_ZTV15dScMgSnowball_c[9] = 02127d10, read
                      # out of overlay_0006.bin at base 0x020bfec0) and the
                      # kind:function record.
foreach(line IN LISTS SLICE_SNW_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SNW_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Lane PKR of run mg11: dScMgCard_c, actor id 0x17b, scene 379, "Picture Poker".
# The FOURTH class under dScMgSingle3DBase_c (the flower, Memory Master and
# Lucky Stars are the other three), so hal/scene_mg_flower.cpp claims the middle
# table at 0x0213e448 and this seat owns its own derived table at 0x0213bdb4 --
# plus TWO ELEMENT VTABLES, which no earlier seat in the family has had.
# port/slice_pkr.txt is the derivation, including the five width checks, the
# attribution ruling that keeps dScMgCoin_c's five state tables where they
# belong, and the reason a 37-slot fill here would write into that SEATED
# class's live state pair.
#
# ONE VARIABLE, for the reason the flower, memory2, luckystars and fader blocks
# give: the slice's ov006 bodies are only reachable through the four tables
# hal/scene_mg_card.cpp fills, and that file cannot link without them.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-379 row, so
# every target that compiles scene_boot.cpp references port_mg_card_spawn and
# port_scene_fill_card by name.
#
# THIS CLASS HAS NO POINTER-TO-MEMBER HOST COPY AND THAT IS A MEASUREMENT.
# Its state machine is a 14-arm ARM jump table, not an mwcc member-pointer
# table; the ARM-Itanium encoding scan returns zero over its 37 bodies while the
# same scan over the neighbouring dScMgCoin_c block returns that class's seven
# known sites.  slice_pkr.txt section 6 is the arithmetic.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors and the arm9 waves under them;
# CMake appends every list to the same targets and dedupes identical absolute
# paths, so nothing is compiled twice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pkr.txt" SLICE_PKR_LINES)
set(SLICE_PKR_SOURCES hal/scene_mg_card.cpp
                      # The two /alternatename rows the first link asked for.
                      # No trap and no stand-in body: both are DATA declared at
                      # C++ linkage in a //cpp src TU against the mount's plain
                      # C name.
                      unmatched/MgCard_Faces.cpp)
# NO TRAP. Run mg11 seated this class with ONE floor, _ZN11dScMgCard_c11ArrangeHandEP12dMgCardObj_c
# (0x2ac, the hand sorter), behind unmatched/MgCard_Traps.cpp -- and it was on
# the CRITICAL PATH: the only caller of src/minigames/d_s_mg_card.cpp, which is the
# only writer of a card's slide target, with state 10 waiting for every card to
# arrive. Run mg12 lane SRT decompiled it (byte-identical at 2004/b56) and the
# trap file is gone; src/func_ov006_020da174.c is an ordinary line in
# slice_pkr.txt and the delink block for 0x020da174..0x020da420 is enrolled.
# slice_pkr.txt section 7 is the retirement record, including why that block is
# NOT marked `complete`.
foreach(line IN LISTS SLICE_PKR_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PKR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Lane TTI of run mg11: dScMgTrampoline_c, actor id 0x180, scene 384,
# "Trampoline Time".  The twenty-second ov006 minigame class and the FIRST
# under dScMgD3DBase_c (data_ov006_0213c62c), a middle base four classes share
# -- 0x174, 0x175, 0x180 and 0x181 -- so this seat claims that table rather
# than finding it already hosted.  port/slice_tti.txt is the derivation,
# including the five width checks, the ELEMENT vtable at data_ov006_0213b2c4
# and the reason a 37-slot fill here would write into dScMgTrampoline2_c's
# live pause flag.
#
# ONE VARIABLE, for the reason the flower, memory2, luckystars and fader blocks
# give: the slice's ov006 bodies are only reachable through the address switch
# in unmatched/MgTrampolineTime_StateDispatch.cpp, and that file cannot link
# without them.  hal/scene_boot.cpp's port_scene_classes table carries the
# scene-384 row, so every target that compiles scene_boot.cpp references
# port_mg_trampoline_spawn and port_scene_fill_trampoline by name.
#
# THE SLICE IS THE DELTA ONLY.  slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors and the arm9 waves under
# them; CMake appends every list to the same targets and dedupes identical
# absolute paths, so nothing is compiled twice.
#
# ================= THE TRAMPOLINE PAIR'S SHARED LIGHT BODY =================
#
# func_ov006_020d09e0 IS LISTED IN BOTH slice_tti.txt AND slice_tte.txt, and it
# is one of the geometry-register bodies both scenes need substituted.  That
# makes it the one shape the per-slice hostgen blocks above cannot express, so
# it gets ONE arrangement here rather than a copy in each block.
#
# WHY A PER-SLICE COPY WOULD NOT WORK, precisely, because the failure is not
# the obvious one.  Both blocks would emit to the SAME output path --
# ${CMAKE_BINARY_DIR}/host-src/src/func_ov006_020d09e0.c is derived from the
# symbol, not from the slice -- so the second add_custom_command(OUTPUT ...)
# is a hard CMake error ("multiple rules generate"), not a duplicate symbol.
# The duplicate-symbol version is the NEXT failure, the one that appears if
# somebody works around the first by giving the two copies different output
# paths: two TUs, one body, one link error.  And a third arrangement --
# hostgen in one slice, plain src/ line in the other -- links fine, takes the
# src/ copy, and puts the defect silently back for whichever scene lost the
# race.  All three are avoided by emitting once and letting BOTH slices point
# at the single output; CMake dedupes the identical absolute path when the two
# lists are appended to the same target.
#
# WHAT THE BODY IS.  func_ov006_020d09e0 is the trampoline family's shared
# light setup, called by scene 385's Render (_ZN18dScMgTrampoline2_c6RenderEv, below) and
# reached in scene 384 through its own slice.  It is
#
#     0x04000440 = 2                  MTX_MODE, position
#     0x040004c8 = pack(s)|1<<30      LIGHT_VECTOR, light 1
#     0x040004cc = 0x40007fff         LIGHT_COLOR, light 1 white
#
# around a func_020553a4 call and the four-element draw walk over
# data_ov006_02140990.  THE MTX_MODE STORE IS PART OF THE BODY and not
# incidental: the geometry engine transforms a light vector by the current
# position matrix as it consumes it, so latching MTX_MODE silently would leave
# light 1 rotated by whatever matrix the previous draw left behind even if the
# LIGHT_VECTOR write alone were fixed.  The substitution covers the whole body
# for the reason the BNT block gives for its MTX_MODE/MTX_IDENTITY pair.
# func_ov006_020cf2fc JOINS IT FOR THE SAME REASON, run mg13 lane TRAMP.  It is
# THE MESH DRAW -- the body 020d09e0's loop calls once per record whose +0x328
# gate the stroke installer set -- and it is listed in BOTH slices too, so the
# emit-once arrangement above is the only one that expresses it.  Thirty-two raw
# MMIO writes: MTX_MODE and MTX_SCALE, TEXIMAGE_PARAM and PLTT_BASE, POLYGON_ATTR,
# DIF_AMB and SPE_EMI, then BEGIN_VTXS / TEXCOORD / NORMAL / VTX_16 / END_VTXS
# through two double loops.  Compiled from src/ every one of them lands in the
# mapped I/O window and stops there, which is a trampoline that is built, gated
# on, walked, and invisible -- exactly the shape Tango reported.
set(TT_SHARED_HOSTGEN_SYMS func_ov006_020d09e0 func_ov006_020cf2fc)
set(TT_SHARED_HOSTGEN_GEN "")
set(TT_SHARED_HOSTGEN_SKIP "")
foreach(sym IN LISTS TT_SHARED_HOSTGEN_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        list(APPEND TT_SHARED_HOSTGEN_SKIP "src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
        list(APPEND TT_SHARED_HOSTGEN_SKIP "src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND TT_SHARED_HOSTGEN_GEN "${sym_out}")
endforeach()

# TTI's own geometry-register body, on top of the shared one above.
#
# func_ov006_020cd270 is scene 384's light setup: two LIGHT_VECTOR stores,
# light 0 from (0,0,-0x0ff8) turned 0x2000 by func_0203cd80 and then 0 by
# func_0203ccd4, light 1 from the same vector turned -0x2000, before the
# data_ov006_02140550 draw walk.  Compiled from src/ both land in the mapped
# I/O window and stop there; the scene's one POLYGON_ATTR is 001f8081 (light 0
# enabled) over SPE_EMI 00000000, so every lit vertex resolves to black.
#
# MEASURED (SM64DS_MAT_LOG=1 SM64DS_SCENE=384), before these lines:
#     [mat] LIGHT_VECTOR commands executed: 0   LIGHT_COLOR: 0
set(TTI_HOSTGEN_SYMS func_ov006_020cd270)
set(TTI_HOSTGEN_GEN "")
set(TTI_HOSTGEN_SKIP "")
foreach(sym IN LISTS TTI_HOSTGEN_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        list(APPEND TTI_HOSTGEN_SKIP "src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
        list(APPEND TTI_HOSTGEN_SKIP "src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND TTI_HOSTGEN_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_tti.txt" SLICE_TTI_LINES)
set(SLICE_TTI_SOURCES hal/scene_mg_trampoline.cpp
                      # The one pointer-to-member host copy: vtable SLOT 6.
                      # This class's member pointer is a FIELD at this+0x5004,
                      # not a table, so src spells it as a local struct with a
                      # PMF member -- no external symbol for a `::*` sweep to
                      # find and nothing for the linker to complain about,
                      # while MSVC's member pointer is four bytes where the
                      # ROM's field is eight.  The third of the three silent
                      # shapes port/mg_fanout_costs.txt section 4 names.
                      # src/minigames/d_s_mg_trampoline.cpp is out of the slice.
                      unmatched/MgTrampolineTime_StateDispatch.cpp
                      # dScMgD3DBase_c's SHARED framework-slot repairs, taken
                      # VERBATIM off mg11-bnp so the family merge dedupes
                      # instead of colliding: slots 2, 10, 27 and 28 in
                      # MgD3DBase_Slots.cpp and the slot-24 decl_common C2733
                      # in MgD3DBase_DeclConflict.cpp. Four classes derive from
                      # that base and three other lanes are seating them in
                      # this run; the four src TUs they replace stay out of
                      # every slice.
                      unmatched/MgD3DBase_Slots.cpp
                      unmatched/MgD3DBase_DeclConflict.cpp
                      # vtable SLOT 34, the brush. src does arithmetic on a
                      # void* -- a GNU/mwcc extension MSVC refuses with C2036
                      # -- so the body is re-spelled with one cast under its
                      # OWN name and src/minigames/d_s_mg_trampoline.cpp is out of the
                      # slice. Not an ABI repair: the behaviour is identical.
                      unmatched/MgTrampolineTime_Brush.cpp
                      # the name-spelling repairs (32 C++-linkage references to
                      # C-named mount symbols, three bare names resolved from
                      # their literal pools) and one hosted arm9 BSS global
                      unmatched/MgTrampolineTime_Faces.cpp
                      # the class's undecompiled bodies, count-and-return. Run
                      # mg12 lane TRM retired the stylus hit test out of this
                      # file and lane INST retired the 0x800 installer the same
                      # way (src/func_ov006_020d0c38.c and
                      # src/func_ov006_020d01e0.cpp are slice lines in BOTH
                      # trampoline slices now); only 020cf2fc is still trapped
                      # here, and both lanes' counter APIs are unchanged -- the
                      # two retired slots report a fixed 0.
                      unmatched/MgTrampolineTime_Floors.cpp
                      # The trampoline RECORD READOUT that replaced the retired
                      # hit-test want count as the stroke evidence. Listed ONCE,
                      # here, and read by BOTH scenes' censuses -- every target
                      # that takes SLICE_TTE_SOURCES takes SLICE_TTI_SOURCES
                      # too, so one definition serves 384 and 385 alike and a
                      # second listing would only risk the duplicate the mg11
                      # merge already paid for.
                      hal/trampoline_records.cpp
                      # the SECOND level of the wall: dMgTrmpln3DMario_c, the
                      # four element records the factory builds at this+0x500c,
                      # has a field-held member pointer of its own at
                      # element+0x64 and one dispatcher over 21 bodies. Its src
                      # open-codes the pair correctly and would still have
                      # jumped to a DS address; MSVC refuses it anyway (C2761).
                      unmatched/MgTrmpln3DMario_StateDispatch.cpp
                      # unmatched/MgTrmpln3DMario_ModuleFix.cpp RETIRED (run
                      # linkfull, lane RS2PORT): the TWO CROSS-MODULE
                      # MISBINDINGS it repaired (src calling the ov007 DATA
                      # symbol at an ov006 FUNCTION's address) are fixed in
                      # src by address (44cb9d5e92, 0fc1499c8b), so both
                      # sources are back on port/slice_tti.txt.
                      # unmatched/MgTrmpln3DMario_ModelRender.cpp RETIRED
                      # (run link100, lane FOLD2): the local-shadow
                      # slot-numbering defect died with the destructor unfold,
                      # and src/func_ov006_020cafb4.cpp carries the draw
                      # (port/slice_fold2.txt).
                      # This slice's own light body plus the one it shares with
                      # slice_tte. The shared path is listed by BOTH slices on
                      # purpose -- CMake dedupes the identical absolute path,
                      # and pointing only one slice at it would leave the other
                      # taking the src/ copy back.
                      ${TTI_HOSTGEN_GEN}
                      ${TT_SHARED_HOSTGEN_GEN})
foreach(line IN LISTS SLICE_TTI_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # The hostgen'd copy stands in for the src/ one; taking both would be a
    # duplicate symbol, and taking neither would drop the body silently. Both
    # sets are consulted because the shared body is a slice_tti line too.
    if(line IN_LIST TTI_HOSTGEN_SKIP OR line IN_LIST TT_SHARED_HOSTGEN_SKIP)
        continue()
    endif()
    list(APPEND SLICE_TTI_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# A slice line that stops matching (a rename, a .c that becomes a .cpp) would
# silently take the src/ copy back and put the defect back with it, so the
# substitution asserts rather than hopes.
list(LENGTH TTI_HOSTGEN_SYMS tti_hg_want)
list(LENGTH TTI_HOSTGEN_GEN tti_hg_have)
if(NOT tti_hg_want EQUAL tti_hg_have)
    message(FATAL_ERROR "slice_tti hostgen substitution incomplete: "
            "${tti_hg_have} of ${tti_hg_want} generated")
endif()
foreach(skip IN LISTS TTI_HOSTGEN_SKIP TT_SHARED_HOSTGEN_SKIP)
    if(NOT skip IN_LIST SLICE_TTI_LINES)
        message(FATAL_ERROR "slice_tti.txt no longer lists ${skip}; the "
                "hostgen substitution for it is now dead and the geometry "
                "register writes in it would go back to latching silently")
    endif()
endforeach()

# FIVE OF THIS SLICE'S 98 .c FILES ARE REALLY C++ -- a //cpp marker and a
# top-level `extern "C"` block, which is invalid C. ALL 98 were SWEPT for the
# marker and for `extern "C"`, `virtual`, `class`, `namespace`, `bool`,
# `new`/`delete` and `::` rather than any one of the five being found by a
# compile error and the rest left to luck, which is the sweep the BOO and SMB
# blocks above record doing for theirs. The slice is 143 lines: 98 .c and
# 45 .cpp.
#
# THE `::` ARM OF THE SWEEP: 12 of the 98 contain `::` somewhere, and 11 of the
# 12 have it only in a recovered-name COMMENT ("dScMgTrampoline_c::Behavior --
# recovered from vtable slot identity"), checked line by line against a
# comment-stripping match. The twelfth, src/func_ov006_020cb1a8.cpp, has it in
# CODE (`Sound::PlayBank2_2D`, `ModelAnim::SetAnim`) and is in the list below.
#
# THIS COMMENT SAID "All 49" AND "Eleven files" UNDER A HEADING SAYING FIVE.
# Both figures were true of the slice as it stood when the block was first
# written, at 49 .c files and one CXX row, and neither was re-measured as four
# closure waves grew the slice to 98. A count in a comment is a measurement
# with no gate under it; the numbers above were re-taken against the committed
# slice.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/minigames/d_s_mg_trampoline.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020c9c8c.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020cb1a8.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020cb528.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020cc198.cpp"
    PROPERTIES LANGUAGE CXX)

# ---- run mg15 lane MENU: dScMiniGm_c, actor id 5, the MINIGAME SELECTION
# ---- MENU (ov005) ---------------------------------------------------------
#
# The scene every minigame row above is reached FROM on the DS, and the one the
# port's harness has always skipped: SM64DS_SCENE=<id> boots an ov006 minigame
# directly, so dScMiniGm_c had never run a frame in this tree.
# port/slice_mgm.txt carries the derivation; hal/scene_mg_menu.cpp is the seat.
#
# THIS SLICE IS THE WHOLE OVERLAY, and that is a statement about how small
# ov005 is rather than an appetite: .text is 0x020bfec0..0x020c2250, 0x2390
# bytes, TWENTY-SIX functions, and all twenty-six have a src/ TU. Twenty-three
# are marked complete in config/arm9/overlays/ov005/delinks.txt. A partial
# slice would save nothing and would leave the class's own vtable bodies split
# across the seam.
#
# THE FIVE arm9 TUs AT THE END OF THE SLICE ARE THE MEASURED GAP, not a guess
# at one. The 26 TUs' entire external closure -- 94 names -- was checked
# against build/port/walk_window.map, the shipped window's own link.
# EIGHTY-FIVE already resolved. Nine did not: these five functions (each with a
# matched src/ TU, all five /OPT:REF-stripped today because nothing referenced
# them), two arm9 .data words that joined port/tools/romdata.py's NAMED list,
# and two arm9 .bss words that joined hal/auto_bss.cpp. Nine names is the
# entire distance between "the port has never touched this scene" and "its code
# links", which is why this is one slice and not the multi-lane wave the ov006
# families needed.
#
# THREE OF THE SLICE'S 27 .c FILES ARE REALLY C++ -- a //cpp marker and a
# top-level `extern "C" {` block, invalid C. ALL 27 were SWEPT for the marker
# and for `extern "C"`, `virtual`, `class`, `namespace`, `bool`, `new`/`delete`
# and `::` over comment-stripped text, the sweep the TTI block above records,
# rather than three being found by a compile error and the rest left to luck.
# The sweep found exactly these three and no `::` in code anywhere. The slice
# is 30 lines: 27 .c and 3 .cpp.
#
# ONE of the nine gap names is NOT a line of this slice: func_020233f4 is
# already in port/slice_gate29.txt, and every target that takes SLICE_MGM
# takes that one too. Listing it twice gave MSVC two object rules for one file
# (gate 29 compiles it as C++) and the link refused with LNK2005.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_mgm.txt" SLICE_MGM_LINES)
set(SLICE_MGM_SOURCES hal/scene_mg_menu.cpp)
foreach(line IN LISTS SLICE_MGM_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_MGM_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov005_020c0140.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov005_020c0378.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov005_020c0878.cpp"
    PROPERTIES LANGUAGE CXX)


# ---- VS wiring lane: dScEntry_c, scene id 6 -- the VS / wireless entry menu
# ---- (ov075) ---------------------------------------------------------------
#
# port/slice_vs.txt is BOTH the derivation record and this manifest: 138 TUs
# (135 delinked + 3 honestly-NONMATCHING), the scene-5 template applied, with
# the differences that overlay demanded -- three static initialisers run by
# the seat's gate, a generated .data code-pointer patch
# (hal/vs_data_patch.inc), and FOUR contested-name renames below.
# hal/scene_vs_menu.cpp is the seat; the ov075 data mount joins
# PORT_ACTOR_OVERLAYS beside ov005's.
#
# THE RENAMES ARE THE SHARED-WINDOW RACE, slice_vs.txt section 6: ov063/065
# and ov075 share a load window, and four ov075 spellings are live in OTHER
# overlays' TUs meaning those overlays' storage
# (hal/actor_classes_ov065.cpp's and actor_classes_bowserpuzzle.cpp's
# alternatenames, which go INERT the moment a real definition appears). So
# the mount excludes the four names, and the two ov075 TUs that carry them
# compile with -D renames onto seat-owned symbols. The src/ files are
# untouched -- the rename exists only in this build's compile of them.
# (the PORT_ACTOR_OVERLAYS append lives beside ov005's, BEFORE the ovdata
# generation loop reads the list)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_vs.txt" SLICE_VS_LINES)
set(SLICE_VS_SOURCES hal/scene_vs_menu.cpp
                     # the three PMF dispatch sites, host copies; their
                     # matched src TUs are out of the slice (see the
                     # manifest's dispatch note and the file's banner)
                     unmatched/VS_EntryDispatch.cpp)
foreach(line IN LISTS SLICE_VS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_VS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# The language sweep found TWO .c files in this slice carrying C++ and this row
# marked both (slice_vs.txt s3). It marks ONE now: run rel0215 lane prop16 took
# main's src/func_ov075_02116128.cpp by address, and a .cpp needs no marking --
# CMake reads the language off the extension. Leaving the dead .c path in the
# list would have been silent (set_source_files_properties on a path no target
# compiles does nothing), which is why it goes rather than stays.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov075_021184b0.cpp"
    PROPERTIES LANGUAGE CXX)
# WorkElevator's TUs spell their vtable func_ov075_0211478c; ov075's own body
# at that window address compiles under a port name and the generated patch
# points the one .data record that dispatches it (0x0211c618) at the rename.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov075_0211478c.c"
    PROPERTIES COMPILE_DEFINITIONS
    "func_ov075_0211478c=port_vs_body_0211478c")
# Snufit's SharedFilePtrs and BowserPuzzleManager's record keep their
# ov065/ov064 bindings; ov075's own registrations land on seat storage.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/__sinit_ov075_0211bb00.c"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov075_0211c800=port_vs_data_0211c800;data_ov075_0211d608=port_vs_bss_0211d608;data_ov075_0211d650=port_vs_bss_0211d650")


# Lane TTE of run mg11: dScMgTrampoline2_c, actor id 0x181, scene 385,
# "Trampoline Terror". The twenty-second ov006 minigame class and the FIRST
# under dScMgD3DBase_c -- the middle base config/arm9/overlays/ov006/symbols.txt
# calls _ZTV14dScMgD3DBase_c (0x174's spawn name) and the ROM's own RTTI at
# 0x0213c5c8 calls dScMgD3DBase_c. Four classes hold that table and run mg11
# seats the other three concurrently, so on this branch this seat's fill claims
# it and after the merge the 0x174 row does; both readings are printed by the
# census rather than assumed. port/slice_tte.txt is the derivation, including
# the five width checks and the reason a 37-slot fill here would write into
# scene 388's first live state pair.
#
# ONE VARIABLE, for the reason the flower, memory2 and luckystars blocks give:
# the slice's ov006 bodies are only reachable through the field switch in
# unmatched/MgTrampolineTerror_StateDispatch.cpp, and that file cannot link
# without them. hal/scene_boot.cpp's port_scene_classes table carries the
# scene-385 row, so every target that compiles scene_boot.cpp references
# port_mg_trampoline2_spawn and port_scene_fill_trampoline2 by name.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt already carries the ov004
# framework, the thirty-five overlay constructors and the arm9 waves under
# them; CMake appends every list to the same targets and dedupes identical
# absolute paths, so nothing is compiled twice.
#
# TWO GEOMETRY-REGISTER BODIES OF ITS OWN, on top of func_ov006_020d09e0 which
# it shares with slice_tti and which is emitted once by the TT_SHARED block
# above -- see the hazard note there for why it is not a copy in each slice.
#
# _ZN18dScMgTrampoline2_c6RenderEv is dScMgTrampoline2_c::Render, so it runs before every
# drawn frame of scene 385, and it is BOTH a light setup and the caller of the
# other two.  Its own stores are LIGHT_VECTOR light 0 from (0,0,-0x0ff8) turned
# -0x4000 by func_0203cd80, then LIGHT_COLOR 0x7fff and 0x40007fff; and when
# the field at +0x7ba8 is zero it goes on to call func_ov006_020caadc and
# func_ov006_020d09e0, which are the other two.  All three have to be
# substituted together: leaving any one on the src/ path leaves the register it
# writes latched, and because they run in sequence over the same two lights the
# surviving raw body would simply be the last writer of a dead word.
#
# func_ov006_020caadc is the second: light 0 from (0,0,-0x0ff8) turned -0x2000
# and then -0x3000, light 1 from the same vector turned -0x2000, then
# LIGHT_COLOR 0x7fff and 0x40007fff, before the data_ov006_02140554 walk.
#
# MEASURED (SM64DS_MAT_LOG=1 SM64DS_SCENE=385), before these lines:
#     [mat] LIGHT_VECTOR commands executed: 0   LIGHT_COLOR: 0
# PATH FORM, 2026-09-12 (main -> port sync, lane SYNC2). main merged these
# bodies into consolidated translation units under src/<area>/, so the bare
# "src/<symbol>.c" convention this loop assumed no longer finds them and the
# MMIO substitution would have been silently dropped or failed at hostgen. The
# list is repo-relative PATHS now, the whole TU is substituted, and the raw TU
# is commented out of every slice that named it. hostgen rewrites MMIO accesses
# and nothing else, so widening the substitution from one body to its TU keeps
# every other body in the link unchanged.
set(TTE_HOSTGEN_SRCS src/func_ov006_020caadc.c src/minigames/d_s_mg_trampoline2.cpp)
set(TTE_HOSTGEN_GEN "")
set(TTE_HOSTGEN_SKIP "")
foreach(rel IN LISTS TTE_HOSTGEN_SRCS)
    if(NOT EXISTS "${PORT_REPO_ROOT_ABS}/${rel}")
        message(FATAL_ERROR "slice_tte hostgen source ${rel} does not exist; the "
                "MMIO substitution would be silently dropped")
    endif()
    set(sym_src "${PORT_REPO_ROOT_ABS}/${rel}")
    list(APPEND TTE_HOSTGEN_SKIP "${rel}")
    string(REGEX REPLACE "[.](c|cpp)$" ".cpp" rel_out "${rel}")
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/${rel_out}")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${rel}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${rel}")
    list(APPEND TTE_HOSTGEN_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_tte.txt" SLICE_TTE_LINES)
set(SLICE_TTE_SOURCES hal/scene_mg_trampoline2.cpp
                      # The one pointer-to-member host copy: vtable SLOT 6.
                      # This class holds its member pointer in a FIELD at
                      # +0x5004 rather than in a table, which is the worse of
                      # the two shapes port/mg_fanout_costs.txt section 4 names.
                      # src/minigames/d_s_mg_trampoline2.cpp is out of the slice.
                      unmatched/MgTrampolineTerror_StateDispatch.cpp
                      # The alias rows the six link waves asked for, the two
                      # method faces an /alternatename cannot do, and the three
                      # bodiless floors this closure traps.
                      unmatched/MgTrampolineTerror_Faces.cpp
                      # The FACTORY, host-copied because the matched-side TU
                      # swaps __cxa_vec_ctor's ctor and dtor arguments at all six
                      # of its call sites -- the ROM's own pool words are in the
                      # file's header. src/minigames/d_s_mg_trampoline2.cpp is out of
                      # the slice.
                      unmatched/MgTrampolineTerror_Factory.cpp
                      # The Trampoline-Mario element records' field-held member
                      # pointer, open-coded in plain ints by its src TU -- the
                      # third shape a link and a `::*` sweep are both blind to,
                      # convicted by a run. src/func_ov006_020c8f20.cpp is out
                      # of the slice.
                      unmatched/MgTrampolineTerror_SubDispatch.cpp
                      # The 3D-Mario records' member pointer at offset 0, the
                      # `::*` shape a sweep does find. Two dispatch sites, one
                      # switch. src/func_ov006_020cea2c.cpp and
                      # src/func_ov006_020cf758.cpp are out of the slice.
                      unmatched/MgTrampolineTerror_MarioDispatch.cpp
                      # dScMgD3DBase_c's slots 10, 27 and 28, whose srcs drop
                      # the receiver an ARM register carried. NOT lane-scoped:
                      # the four ids under that base share the three bodies and
                      # more than one mg11 lane lands this same filename, which
                      # is how the merge dedupes it.
                      unmatched/MgD3DBase_Slots.cpp
                      # dScMgD3DBase_c slot 24: decl_common.h declares it
                      # (void*) and the TU defines it (char*), C2733 to MSVC.
                      # The canonical shared host copy, adopted verbatim from
                      # lane BNP so the merge dedupes.
                      unmatched/MgD3DBase_DeclConflict.cpp
                      # The family's two mwcc virtual-shadow dispatches onto
                      # ModelAnim's ROM slot 5. Same non-lane-scoped naming
                      # rule as the file above.
                      # unmatched/MgD3DBase_ModelAnimRender.cpp RETIRED
                      # (run link100, lane FACEF): all four bodies were the
                      # mwcc virtual-shadow dispatch onto ModelAnim ROM slot 5,
                      # and lane SLOT5F's respelling of the ROM's D1/D0 pair
                      # put Render back at _ZTV9ModelAnim[5] with Virtual18 at
                      # its own slot 6. src/func_ov006_020c4c54.cpp,
                      # _020c7734.cpp, _020c8e90.cpp and _02122814.cpp are on
                      # port/slice_facef.txt; all four define their C name
                      # themselves and none needs a face.
                      # This slice's own two light bodies plus the one it
                      # shares with slice_tti. The shared path is listed by
                      # BOTH slices on purpose -- CMake dedupes the identical
                      # absolute path, and pointing only one slice at it would
                      # leave the other taking the src/ copy back.
                      ${TTE_HOSTGEN_GEN}
                      ${TT_SHARED_HOSTGEN_GEN})
foreach(line IN LISTS SLICE_TTE_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # The hostgen'd copy stands in for the src/ one; taking both would be a
    # duplicate symbol, and taking neither would drop the body silently. Both
    # sets are consulted because the shared body is a slice_tte line too.
    if(line IN_LIST TTE_HOSTGEN_SKIP OR line IN_LIST TT_SHARED_HOSTGEN_SKIP)
        continue()
    endif()
    list(APPEND SLICE_TTE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# A slice line that stops matching (a rename, a .c that becomes a .cpp) would
# silently take the src/ copy back and put the defect back with it, so the
# substitution asserts rather than hopes.
list(LENGTH TTE_HOSTGEN_SRCS tte_hg_want)
list(LENGTH TTE_HOSTGEN_GEN tte_hg_have)
if(NOT tte_hg_want EQUAL tte_hg_have)
    message(FATAL_ERROR "slice_tte hostgen substitution incomplete: "
            "${tte_hg_have} of ${tte_hg_want} generated")
endif()
foreach(skip IN LISTS TTE_HOSTGEN_SKIP TT_SHARED_HOSTGEN_SKIP)
    if(NOT skip IN_LIST SLICE_TTE_LINES)
        message(FATAL_ERROR "slice_tte.txt no longer lists ${skip}; the "
                "hostgen substitution for it is now dead and the geometry "
                "register writes in it would go back to latching silently")
    endif()
endforeach()
# THE SHARED BODY'S OWN GATE, and it is the one this arrangement exists for.
# The two per-slice loops above each assert that their OWN slice still lists
# the shared line, so between them they already cover both files -- but only
# while both blocks keep consulting TT_SHARED_HOSTGEN_SKIP. This asserts the
# sharing itself: the body must be a line in BOTH slices, because that is the
# condition that makes one emitted TU the right answer. If a future slice edit
# drops it from one of the two, the single generated copy is still compiled
# into the target and still correct, but the arrangement is no longer shared
# and the comment above it is no longer true -- and a shared block nobody
# re-reads is how the src/ copy comes back.
foreach(skip IN LISTS TT_SHARED_HOSTGEN_SKIP)
    if(NOT skip IN_LIST SLICE_TTI_LINES OR NOT skip IN_LIST SLICE_TTE_LINES)
        message(FATAL_ERROR "${skip} is the slice_tti/slice_tte SHARED hostgen "
                "body but is no longer listed by both slices; re-read the "
                "TT_SHARED block before changing it")
    endif()
endforeach()

# FOUR .c FILES IN THIS SLICE ARE REALLY C++ -- a //cpp marker and a top-level
# `extern "C" {` block each, two of them also a `virtual`, none of which is
# valid C. Every .c line in the slice
# was SWEPT with comments stripped for the marker and for `extern "C"`,
# `virtual`, `class`, `namespace`, `bool`, `new`, `delete`, `::` and `template`
# rather than this one being found by a compile error and the rest left to
# luck. It is the only hit: the files that match `::` or `class` match them
# only inside the naming pass's own comments, which is why the sweep strips
# comments first. (src/minigames/d_s_mg_trampoline2.cpp was the second hit until the
# factory host copy took its place; it is no longer a slice line.)
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020c9098.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020c9c8c.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020cb528.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020cc198.cpp"
    PROPERTIES LANGUAGE CXX)

# AN AMBIGUOUS-MODULE ADDRESS, and the -D rename run mg9 lane S364 established
# for the same shape. 0x020cd72c is func_ov006_020cd72c, a 0x18-byte FUNCTION
# in ov006's symbol table (line 281) -- and it is ALSO data_ov007_020cd72c,
# kind data, in ov007's (line 839). src/func_ov006_020cd6f4.c declares its
# callee with the ov007 DATA name (`extern void data_ov007_020cd72c(int *c);`)
# and calls it. On the DS that is harmless: ov007 is not resident while ov006
# is, so the address is ov006's code either way. On the port BOTH mounts exist,
# the ov007 data face wins the name, and the call jumps into mounted ROM DATA.
# It faulted exactly there on this lane's second boot of scene 385 --
# FAULT c0000005 at +0x008f05e0 inside func_ov006_020cd6f4, one frame under
# the element constructor the factory runs. The rename points the reference at
# ov006's function; src/ and include/ stay untouched, and
# src/func_ov006_020cd72c.c is a slice line so the real body is linked.
# src/func_ov006_020cd12c.c names the same symbol and is NOT in this slice; a
# lane that pulls it in needs the same row.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020cd6f4.c"
    PROPERTIES COMPILE_DEFINITIONS "data_ov007_020cd72c=func_ov006_020cd72c")

# THE ONE BARE VT EXTERN IN THIS SLICE, and it is the run law's per-source
# rename onto this lane's own pool word. Every one of the slice's 204 TUs was
# swept (comments stripped) for VT / VT0 / VT1 / VT2 / HEAP / G0 / G1 / G2 /
# R0 / R1 / R2; there are four hits and three of them are LOCAL TYPE NAMES
# (`typedef struct { int x, y; } G2;` in src/func_ov006_020cc8c8.c and the two
# `struct G2 { int w[2]; }` in _020cc9fc / _020ccd78), which is the reason the
# sweep is read rather than counted. The real one is
# src/_ZN6Player29TryExitCharacterDoorWithIntroEv.cpp -- the Trampoline-Mario
# element CONSTRUCTOR, misnamed by the naming pass and correctly flagged in its
# own header ("The vptr it stores is the invented symbol VT0, which carries no
# address -- a separate problem, left alone here"). VT0 is DEFINED in this link
# as zeroed storage, so the constructor was writing a pointer-to-zeros into the
# element's word 0 and the first virtual dispatch through it called address 0.
# That is exactly what the fourth boot of scene 385 did:
#   FAULT c0000005 at +0xffc00000 accessing 00000000
#     func_ov006_020c9c8c   (o->slot4() on the element)
#     func_ov006_020ca310 / tte_sub_try / func_ov006_020c8f20
# The real table is data_ov006_0213b2e0 -- the ROM's own `str r1,[r4]` at
# 0x020ca7a0 loads it from the pool at 0x020ca7b4 -- and its five words are
# filled with host thunks by hal/scene_mg_trampoline2.cpp.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN6Player29TryExitCharacterDoorWithIntroEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT0=data_ov006_0213b2e0")


port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_fdr.txt" SLICE_FDR_LINES)
set(FDR_FADER_SOURCES hal/fdr_arm9_fader_seat.cpp)
foreach(line IN LISTS SLICE_FDR_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND FDR_FADER_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Run link60 Stage 4, lane NFS: the NitroSDK open-BY-NAME file system.
#
# hal/fs_names.cpp registers the ROM's "rom" archive by calling the ROM's own
# func_0205cc80, which is what lets func_0205d714 resolve a path at all. It
# carries three host faces (FS_Init, the archive read function and the archive
# command proc -- all three are unmapped memory or the card) and hosts the six
# FS globals FS_Init owns.
#
# ONE VARIABLE, THREE TARGETS, for exactly the reason the fader seat above
# gives: the .cpp and the slice are not separable (the slice's three TUs are
# only reachable through this file, and this file cannot link without them),
# and a target that gets one but not the other has an unregistered archive
# while the others do not.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_nfs.txt" SLICE_NFS_LINES)
set(NFS_NAMES_SOURCES hal/fs_names.cpp hal/nitrofs_boot.cpp)
foreach(line IN LISTS SLICE_NFS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND NFS_NAMES_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---------------------------------------------------------------------------
# Run link100, lane NITROFS: the cartridge-header mirror, and the ROM's own
# FS_Init on top of it.
#
# hal/nitrofs_boot.cpp rides NFS_NAMES_SOURCES above -- all three targets --
# because the mirror seed and the read-back belong wherever hal/fs_names.cpp's
# static initialiser runs. THE SLICE DOES NOT. src/func_0205d96c.c takes the
# address of the matched archive proc src/func_0205da94.c, whose two live
# commands reach the cartridge lock, whose six OS-lock TUs bottom out on four
# primitives hal/boot_hw.cpp transcribes (func_02057198, func_0205a74c,
# func_02059d8c, IRQ::DisableAll / IRQ::RestoreAll). hal/boot_hw.cpp is
# SLICE214_SOURCES: walk_window and walk_window_hires only. So the seat goes to
# those two, and smoke_player keeps the face alone in hal/nitrofs_face.cpp --
# which is not merely an omission but a duplicate-symbol requirement, since a
# target carrying the matched TU cannot also define func_0205d96c by hand.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_nitrofs.txt" SLICE_NITROFS_LINES)
set(SLICE_NITROFS_SOURCES "")
foreach(line IN LISTS SLICE_NITROFS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_NITROFS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---------------------------------------------------------------------------
# Run link100, lane LOADOV: the honest subset of the LoadOverlay /
# UnloadOverlay chains. One entry point, src/func_02017e94.c, and the whole
# chain behind it comes with it -- every TU of that chain is already enrolled
# in slice_gate214.txt and already compiles here; /OPT:REF drops all of it
# today because the only thing that named it was hal/scene_boot.cpp's empty
# face. port/slice_loadov.txt carries the per-row rulings, including the two
# rows this lane REFUSED (LoadOverlay reads uninitialised stack on a lookup
# that fails and its tail would copy an overlay image over host code;
# UnloadOverlay's body is this one's with `return` replaced by `Crash()`, on a
# lookup that always fails here).
#
# SAME TARGET SPLIT AS SLICE_NITROFS_SOURCES ABOVE, and for the same reason:
# the chain bottoms out on hal/boot_hw.cpp's ARM primitives, hal/boot_hw.cpp is
# SLICE214_SOURCES, and smoke_player carries neither. smoke_player keeps a face
# in hal/nitrofs_face.cpp. The two are exclusive -- a target with both would
# have func_02017e94 defined twice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_loadov.txt" SLICE_LOADOV_LINES)
set(SLICE_LOADOV_SOURCES "")
foreach(line IN LISTS SLICE_LOADOV_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_LOADOV_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---------------------------------------------------------------------------
# Run link100, lane SND1, rung R1: the ROM's own sound-init pool identity.
#
# hal/snd_globals.cpp hosts the command pool, its callback table and
# SNDSharedWork in the ROM's own layout, and rides SOUND_HOST_SOURCES so the
# storage is on every target that has the sound stack. The slice goes to the
# same three targets (see the target_sources block near the end of this file):
# hal/sdat/consumer.cpp CALLS these bodies, so a sound target without them
# would not link. The one symbol under the seat that smoke_player lacks is
# func_02059d8c, the ARM busy-wait hal/boot_hw.cpp transcribes for the
# SLICE214_SOURCES targets; hal/sdat/snd_smoke_face.cpp supplies it there and
# is exclusive with hal/boot_hw.cpp for that reason.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_snd1.txt" SLICE_SND1_LINES)
set(SLICE_SND1_SOURCES "")
foreach(line IN LISTS SLICE_SND1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SND1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---------------------------------------------------------------------------
# Run link100, lane SND2: the ROM's own sound BRING-UP, the rest of
# src/func_020133bc.c that lane SND1's rung R1 left behind.
#
# Same three targets and the same reason as the two blocks above:
# hal/sdat/consumer.cpp calls these bodies from sd_sound_init_host, and that
# file is on all three sound targets, so a target with the sound stack and
# without this slice would not link. Nothing under the slice is hosted by this
# lane -- every global it names is already a hosted DS global elsewhere in
# hal/, and every symbol it calls is already in the link.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_snd2.txt" SLICE_SND2_LINES)
set(SLICE_SND2_SOURCES "")
foreach(line IN LISTS SLICE_SND2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SND2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---------------------------------------------------------------------------
# Run link100, lane SND1, rungs R8 + R9 + R10: the ROM's own sound FRAME.
#
# Same three targets and the same reason as the block above: hal/sdat/consumer.cpp
# CALLS func_020132d8 now, so a target with the sound stack and without this
# slice would not link. The storage the slice needs (four bss objects and seven
# /alternatename rows for the MSVC spellings the decomp's C++ TUs ask for) is in
# hal/snd_globals.cpp, which already rides SOUND_HOST_SOURCES, and the five
# underwater-filter words plus the byte-wide dB table come out of the cartridge
# through port/tools/romdata.py's NAMED list.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_snd8.txt" SLICE_SND8_LINES)
set(SLICE_SND8_SOURCES "")
foreach(line IN LISTS SLICE_SND8_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SND8_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ONE PER-SOURCE RENAME LEFT OF THE THREE, the shape lane R2ABC used for
# func_02060890 and lane BOOTR1 for main: an edge that is not ROM code yet,
# named in one place, without a host body under a ROM name (a new SHADOW row
# in port/tools/linkage.py's queue). The evidence is in hal/nitrofs_boot.cpp.
#
#   func_02060890  the card driver bring-up. NOT hardware: ORDERING. FS_Init
#                  runs from hal/fs_names.cpp's static initialiser, before
#                  main; the ROM's own bring-up runs later, in the ROM's order,
#                  as func_02042f68's arm 1 inside main (hal/boot_arms.cpp's
#                  R2c). Called from here it would find the guard word still 0
#                  and create the card thread before the OS thread manager
#                  exists. On the DS FS_Init comes after func_02042f68
#                  (src/func_0201a054.c) and the guard returns; this rename is
#                  that return.
#   func_0205db2c  RETIRED (run linkfull, lane S4CARD). The archive's read
#                  function is the ROM's own: the card driver behind it runs
#                  over ntr/card.cpp (port/slice_w28_card.txt), and
#                  hal/fs_names.cpp's port_nitrofs_read serves smoke_player's
#                  face alone.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0205d96c.c"
    PROPERTIES COMPILE_DEFINITIONS
    "func_02060890=port_nitrofs_card_bringup")

#   func_020570c0  EXMEMCNT |= 0x0800 and &= ~0x0800, the NDS slot's ARM7/ARM9
#   func_020570d8  access-right bit. THE TWO RENAMES THAT STOOD HERE ARE GONE
#                  (run link100 wave 7, lane SEAT1). They faced the two matched
#                  TUs because the decomp spelled the address as the placeholder
#                  `G`, which resolves in this binary to hal/heap_vtable.cpp's
#                  default-heap word -- so linked as written the bodies would OR
#                  and AND bit 11 of a heap pointer four times a boot. src/ now
#                  spells the register the ROM's own literal pools name (pools
#                  0x020570d4 and 0x020570ec, both 0x04000204, neither carrying
#                  a relocation), both TUs still byte-verify with that pool word
#                  compared for real instead of wildcarded as a reloc slot, and
#                  they reach the register through hostgen in the SEAT1_GREG
#                  block beside R3F_GREG. src/func_020570f0.c and
#                  src/func_0205710c.c now call the ROM's own bodies under their
#                  own names and the two faces are out of hal/nitrofs_boot.cpp.
#                  Derivation: port/slice_seat1.txt, rows 2 and 3.

# Gate 35: the course loop -- damage, death, respawn, coins, the star and the
# course's own sound. Small, because almost all of it was already linked; see
# the head of slice_gate35.txt for what was actually missing.
#
# func_02049018 is the 3D sound DISTANCE function and it drives the DS square-
# root unit directly (SQRTCNT/SQRT_PARAM/SQRT_RESULT at 0x40002b0). ntr maps
# that page as plain memory and hooks the write-triggered registers, but only
# through the NTR_MMIO macro hostgen substitutes -- a raw cast-deref writes the
# byte and never runs the unit, so the function returned whatever was last left
# in the result register. Measured before this: a player 95 scene units from
# the listener came back 8192, past every distance limit in the game, and every
# positional sound was culled. It goes through hostgen like every other TU that
# touches hardware; src/func_02049018.c comes out of slice 10.
# Lane shadow-A rides three more through the same plain-hostgen loop:
# CollectStar (ARG_WIDTH), func_02016ff4 and the two ActorBase::Process
# wrappers func_0204335c / func_02043288 (VIRTUAL_CALL). Their src lines stay
# skipped where the slices list them (func_0204335c in the gate-10 camera
# filter below).
# ...and lane TEX2 rides a fifth through the same loop:
# _ZN5Model8LoadFileER13SharedFilePtr (VIRTUAL_CALL, the shrink switch on
# the second model path). Its src row is filtered out of
# SLICE4B_HOSTGEN_SOURCES above rather than commented out of
# slice_gate4b.txt, because eleven smoke targets still take the plain row.
set(GATE35_SYMS func_02049018 CollectStar func_02016ff4 func_0204335c
    func_02043288 _ZN5Model8LoadFileER13SharedFilePtr)
set(GATE35_GEN "")
foreach(sym IN LISTS GATE35_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE35_GEN "${sym_out}")
endforeach()

set(GATE32_HOST_SOURCES
    hal/actor_classes_bob_enemy.cpp
    hal/actor_spawn_probe_bob.cpp
    hal/bob_enemy_bridges.cpp
    hal/bob_enemy_shadow_faces.cpp
    hal/bob_enemy_header_faces.cpp
    # the ModelAnim slot-5 collision, for the fourth gate running
    unmatched/BobEnemy_Renders.cpp
    # the mwcc pointer-to-member dispatch for the eighth time, and the first
    # one that belongs to a BASE class: Enemy's own death-type table
    unmatched/Enemy_UpdateDeath.cpp
    # ...and for the ninth: the bob-omb buddy's three-state machine
    unmatched/BobOmbBuddy_States.cpp
    # ...and for the tenth: the chain chomp's six
    unmatched/ChainChomp_States.cpp
    # the ARM r0 ride-through, in a spawn factory for the first time
    unmatched/ChainChomp_Spawn_hostcopy.cpp
    # ...and for the eleventh, the widest one yet: KING_BOB_OMB keeps the
    # ADDRESS of a two-PMF record rather than an index, so both his setter and
    # his Behavior do pointer arithmetic on a type MSVC doubles
    unmatched/KingBobOmb_States.cpp
    # ...and for KOOPA_SHELL (gate 209): its four {init, main} states, seated
    # over the mounted DS addresses on both sides of __sinit_ov102_0214dfac
    unmatched/KoopaShell_States.cpp
    # r0-passthrough overlay readers: func_ov084_02129cf4 (gate 32),
    # func_ov084_0212f204 (gate 70) and func_ov102_02149078 (gate 203) each call
    # Actor::ClosestPlayer() with no argument (this rode ARM r0). Host copies pass
    # each body's own receiver; src lines commented out in their slice gates.
    # Grouped here because all three ship on the same three targets this GATE32
    # host set is added to.
    # func_ov094_02136024 (gate 194) and func_ov060_02111f08 LEFT this file at run
    # link100 wave 15 lane SEAT15B: their sources pass the receiver now, so the
    # matched TUs took the seats (slice_gate194.txt and port/slice_l15cp.txt).
    unmatched/Actor_ClosestPlayer_OverlayReaders.cpp)

# The header/definition collisions in this gate's closure: decl_common.h
# declares each of these `(void*)` and its own TU defines it `(char*)`, which
# is one register on the ROM and C2733 to MSVC. hostgen's HEADER_SHADOW hides
# the header's declaration across the include; src/ and include/ stay untouched.
# func_ov084_021298d0 is here for a different reason: it is C++ inside a .c
# (the gate-9 case), which mwccarm accepted and MSVC will not compile as C.
# hostgen emits it as .cpp with the symbols wrapped back to C linkage.
# func_ov078_02124cf4 is the first kind again: decl_common.h declares
# func_0200fa8c `(void*, int)` and func_ov078_02125c24 `(char*, int)` while
# that TU declares both `(void*, int)`. One register on the ROM, two C2733s to
# MSVC.
# TWO ENTRIES LEFT THIS LIST 2026-09-13 (lane SYNC3). Both were HEADER_SHADOW
# cases -- decl_common.h declaring the TU's own name with a different pointer
# type, C2733 -- and both collisions are gone in the consolidated TUs main
# folded them into. src/actors/daBmb_c.cpp does not include decl_common.h at all
# and declares func_ov102_0214b248 `(void *)` exactly as it defines it;
# src/actors/daBombking_c.cpp does include it, but now spells
# func_ov078_02125c24 `(char*, int)` and func_0200fa8c `(void*, int)`, which is
# what the header says. Checked against the merged tree, not from memory.
set(GATE32_SYMS func_ov084_021298d0)
set(GATE32_GEN "")
foreach(sym IN LISTS GATE32_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE32_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate35.txt" SLICE35_LINES)
set(SLICE35_SOURCES "")
foreach(line IN LISTS SLICE35_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # (a stray `list(APPEND GATE32_GEN ...)` lived here from the six-stream
    # merge -- lesson 4's split-loop damage, masked because CMake dedupes
    # target sources. Caught by the post-merge cross-loop-append check.)
    list(APPEND SLICE35_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 13: the real Camera actor. Adds its own slice plus the HAL seam, and
# swaps three gate-10 files for host copies that only the camera needs
# (see port/unmatched/): ChangeArea calls HideArea() with no argument and
# relies on the ARM r0 ride-through, and func_0200cae4 / func_0200ca50
# dispatch through mwcc member-function pointers. smoke_player keeps the
# matched files -- it never arms data_0209f318, so nothing there dispatches.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate13.txt" SLICE13_LINES)
set(SLICE13_SOURCES "")
foreach(line IN LISTS SLICE13_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE13_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# THE POINTER SWEEP. port/tools/ptr_audit.py intersects romdata.py's NAMED
# list with config/arm9/relocs.txt and reports every named symbol whose ROM
# bytes contain a relocated word -- a DS address the port would emit raw and
# then call through. Two of its answers are tables that matched code indexes
# and CALLS: data_02086758 (the backup-media command table) and the 39 records
# at 0x02086bc0 (the kuppa script's camera commands). Both are hosted with real
# host function pointers in hal/ptr_tables.cpp, which needs their callees to
# exist as host code -- that is slice_ptrsweep.txt, 65 files of matched src
# that were in no slice at all, because the only thing naming them was a table
# of bytes. unmatched/func_02008550_hostcopy.cpp is the second table's
# consumer, host-copied for the same mwcc-PMF reason func_0200cae4 is.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ptrsweep.txt" SLICE_PTR_LINES)
# func_02008550_hostcopy.cpp RETIRED (lane shadow-A): the matched TU goes
# through hostgen's MG_PMF_CALL table (GATE13_SYMS), the 39 seeding lines
# kept and the one PMF call read back as the host handler it seeded.
set(SLICE_PTR_SOURCES hal/ptr_tables.cpp)
foreach(line IN LISTS SLICE_PTR_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PTR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# unmatched/Camera_ApproachAngleVeneer.cpp RETIRED (run linkfull, lane
# RS2PORT): main 59013376ce passes ApproachAngle its fifth argument (0), so
# src/func_020078c4.c runs, from port/slice_w28_rs2port.txt; the data_02086d88
# pointer table (hal/ptr_tables.cpp) resolves to it by the same name.

# gate 10 minus the two files the camera build replaces (ChangeArea by its
# host copy; func_0200cae4 by hostgen, GATE13_SYMS, lane shadow-A)
set(SLICE10_CAM_SOURCES "")
foreach(src IN LISTS SLICE10_SOURCES)
    if(src MATCHES "/ChangeArea\\.c$" OR src MATCHES "/func_0200cae4\\.cpp$")
        continue()
    endif()
    # the pointer sweep: func_02008550 dispatches the camera script commands
    # through an mwcc pointer-to-member array, which MSVC cannot represent and
    # which was loading DS code addresses out of romdata besides. Tables in
    # hal/ptr_tables.cpp; the TU itself is generated by hostgen (GATE13_SYMS,
    # lane shadow-A), so its plain line stays out here.
    if(src MATCHES "/func_02008550\\.cpp$")
        continue()
    endif()
    # gate 14: three more ARM ride-throughs, dormant until the level boot
    # reaches them (port/unmatched/ActorDerived_Spawn.cpp, PathPtr_FromID.cpp)
    # func_0204335c is generated by hostgen instead (GATE35_SYMS, lane
    # shadow-A), so its plain line still has to stay out.
    if(src MATCHES "/_ZN7dBase_c5SpawnEjP7fBase_cii\\.cpp$"
       OR src MATCHES "/func_02042ffc\\.c$"
       OR src MATCHES "/_ZN7PathPtr6FromIDEj\\.cpp$"
       OR src MATCHES "/func_0204335c\\.c$")
        continue()
    endif()
    # gate 29: _ZN8Particle10SysTracker8Contents5Entry10InitialiseEjjR7Vector3PK11Vector3_16fPN5dPa_c7level_c10callback_cE is the particle spawn's tail, and the ONE place
    # in the subsystem that reaches a Callback vtable through a C++ `virtual`,
    # `newCallback->SpawnParticles(*system)`. It used to carry a hostgen
    # VIRTUAL_CALL row that rewrote that call into an explicit cdecl call
    # through vptr[0], on the reasoning that the tables behind it were
    # hal/particle_vtable.cpp's C tables of cdecl bodies and that every other
    # dispatch of them was cdecl too. THAT ROW IS RETIRED (2026-09-16, run
    # link100 lane NULLCALL2): nothing installs those tables any more, and the
    # callback classes are real C++ classes whose matched constructors install
    # MSVC's own tables of __thiscall bodies, which take the receiver in ECX
    # and end in `ret 4`. The patched site pushed the receiver and the System
    # and then cleaned eight bytes of a stack the callee had already cleaned
    # four of; Initialise's epilogue then returned through the uniqueID
    # Contents::Create had pushed, which is what the "jumped to address 1" and
    # "jumped to address 2" boots were reporting. The call is the matched
    # source's own again. The plain line still stays out of this list, because
    # every file on gate 29 is generated by hostgen and slice_gate29.txt
    # carries this one; same treatment as func_ov002_020d708c above. Only the
    # three targets that take this filtered list exist, and all three carry
    # gate 29.
    if(src MATCHES "/_ZN8Particle10SysTracker8Contents5Entry10InitialiseEjjR7Vector3PK11Vector3_16fPN5dPa_c7level_c10callback_cE\\.cpp$")
        continue()
    endif()
    # Sound: func_0205b5d4, the "read the other core's progress" read that
    # hal/sdat/consumer.cpp has to own so the queue's spin-wait can terminate
    # on a single-threaded host. The five ARM argument ride-throughs that led
    # this list (func_0204f600, func_0204f89c, func_0204f7cc, func_0204f86c,
    # func_0204fa2c) compile from src/ now: each is spelled with the arguments
    # its callers pass (hal/sdat/sound_abi.cpp's header has the history).
    if(src MATCHES "/func_0205b5d4\\.c$"
    # ...and Sound::Player::SetPlayableSeqCount, which writes through
    # data_020a4d6c's record field +0x18 now (include/SoundPlayerRecord.h),
    # so it is not filtered any more: its .cpp compiles from gate 10 and links
    # through its hal/cxx_aliases.cpp row.
    # (Sound::Play's clause went at run linkfull lane RS5A: it named a .c the
    # tree no longer has, and the .cpp links now through hal/sdat/sound_abi.cpp's
    # flat-name bridge.)
    # ...and func_0203d974, "does anything still need loading off the card".
    # Its src reads the DS main-RAM mirror word 0x027ffc40 literally, which is
    # past MAIN_BASE+MAIN_SIZE (ntr/include/ntr/mmio.h) and unmapped -- and the
    # DS-faithful answer would then walk into a null sound heap. Hosted in
    # sound_abi.cpp; the header there has the whole argument. It is listed in
    # slice_gate14.txt as well, where it is commented out rather than filtered:
    # gate 14 is appended unfiltered, so a live line there puts it straight back
    # into the link (same as SetPlayableSeqCount above).
       OR src MATCHES "/func_0203d974\\.c$")
        continue()
    endif()
    # gate 35. HitDeathPlane USED TO BE FILTERED HERE, for calling SetNextLevel
    # with the argument riding in r0 across a call its own declaration spelled
    # `(void)`. Main fixed that: src/HitDeathPlane.c declares
    # `extern void SetNextLevel(int arg);` and passes `arg`, so the filter line
    # and hal/star_flow.cpp's host copy both came out at run link100 wave 15
    # (lane SEAT15F) and the matched TU compiles here again.
    # func_0203d974 stays out (it is listed in both slice 10 and slice
    # 14): its 0x027ffc40 console-type read is in no region ntr maps, and the
    # course sound boot is its first caller.
    # ...and CollectStar, the WRITE half of the s8/int argument-width
    # disagreement (its caller CollectStarInLevel.c declares the course id
    # s8, the body takes int, and cdecl pushes an s8 as one meaningful byte
    # in a four-byte slot). It goes through hostgen's ARG_WIDTH patch, listed
    # in GATE35_SYMS below, which retypes the one parameter; the host copy
    # that used to carry the retype is deleted (lane shadow-A).
    if(src MATCHES "/func_0203d974\\.c$"
       OR src MATCHES "/CollectStar\\.c$"
    # ...and func_02049018, the 3D sound distance function, which drives the
    # DS square-root unit through raw cast-derefs and so has to go through
    # hostgen's MMIO transform (GATE35_SYMS) rather than compile as it stands.
       OR src MATCHES "/func_02049018\\.c$")
        continue()
    endif()
    # run mg15 lane MP1: THE DS SLEEP/WAKE PAIR AND ITS SCHEDULER.
    # src/OS_SleepThread.c's first act is data_020a612c->node, and
    # hal/cxx_aliases.cpp hosts data_020a612c as zero -- so the ROM body is a
    # null dereference on its first call, and port/nfs_names_map.txt:402 has
    # said so since the NitroFS seat. MEASURED by build target
    # mp_sleepwake_rom: 0xC0000005, through the real veneer. It is not
    # theoretical either -- src/func_02018e68.c (slice_mg1) reaches it on the
    # file-read failure path, so today the error report faults before it can
    # print. Past the deref, src/func_02057f54.c reschedules through
    # ARMProcessorMode/ARMSaveContext/ARMRestoreContext, none of which has a
    # host body and none of which has an honest one to write.
    # hal/os_thread.cpp reproduces the queue-word half of the contract exactly
    # and replaces the ARM context switch with a bounded host pump. It is
    # appended through SLICE_COMMS_SOURCES below, which every consumer of
    # SLICE10_CAM_SOURCES also takes -- checked: the three add_executable
    # lines that use this variable are the three that use that one.
    if(src MATCHES "/OS_SleepThread\\.c$"
       OR src MATCHES "/OS_WakeupThread\\.c$"
       OR src MATCHES "/func_02057f54\\.c$")
        continue()
    endif()
    list(APPEND SLICE10_CAM_SOURCES "${src}")
endforeach()

# argfix (under-declared-implicit-arg bug class): three gate-10 callers whose
# matched src drops an argument that rode an ARM register for free. Their src
# lines are commented out in slice_gate10.txt; these host copies pass the missing
# argument explicitly (register-proven per site). See each file's header.
# (func_ov002_020e5948's TexSeq caller fix is Brain B's lane, handed over via
# out/argfix/handoff/ -- not wired here.)
# Player_ReleaseHeldDispatch.cpp RETIRED at SYNC6. It was this one body
# transcribed to pass func_ov002_020d5cec the held object the ROM leaves in r0,
# and src/actors/Player.cpp is back in the build (main #2666) defining
# func_ov002_020bdb50 itself, so the two collided. The argument is supplied by a
# hostgen REG_RIDE_ARG row on the Player TU instead -- the same mechanism, on
# main's own text, with apply_patches hard-erroring if either anchor moves --
# so nothing about the call changes and one host copy leaves the tree.
list(APPEND SLICE10_CAM_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Player_SwimMain.cpp")
# unmatched/InitCrashScreen_ResetVeneer.cpp RETIRED (run linkfull, lane
# RS2PORT): hal/cxx_aliases.cpp's face for the static
# dScene_c::ResetHardwareRegisters takes no argument now, so the matched
# argless call is the ROM's call and src/InitCrashScreen.c is back on
# port/slice_gate10.txt.

# run link100 wave 15, LINK15 BATCH 6 (lane SEAT15F): the arm9 miscellaneous
# singles whose host copies recorded an ARM ride-through that main has since
# fixed in src/. Each line of slice_l15arm9.txt names the row it seats and the
# file whose host body came out for it.
#
# APPENDED TO SLICE10_CAM_SOURCES rather than given a list of its own, for the
# reason the conductor line under SLICE_COMMS_SOURCES states: the three
# add_executable lines that take slice 10 (smoke_player, walk_window,
# walk_window_hires) are exactly the three that link the host files these TUs
# replace, so one variable cannot go out of step with another.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_l15arm9.txt" SLICE_L15ARM9_LINES)
foreach(line IN LISTS SLICE_L15ARM9_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE10_CAM_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run mg15 lane MP1: THE RADIO SEAM AND THE COMMS CLOSURE.
#
# hal/comms_seam.cpp hosts the eight ROM addresses where the game stops being
# a game and starts being a radio (the WM SDK, and under it arm7.bin, which
# this repo does not decompile and a PC port does not want). Everything ABOVE
# those eight stays the ROM's, verbatim -- that is the whole point, and it is
# what keeps the port portable back to hardware. The transport contract a
# launcher mod implements is in hal/comms_seam.h; nothing here is a network.
#
# hal/os_thread.cpp is the DS sleep/wake pair, hosted, replacing the three
# gate-10 rows filtered out above.
#
# slice_comms.txt is the ROM's four-player fan-out, linked but not yet driven.
# run mg16 lane MP2: hal/comms_loopback.cpp is the first REAL transport written
# against the seam's contract -- UDP on 127.0.0.1, two copies of the game on one
# machine as DS parent and child. hal/comms_lockstep.cpp drives the eight faces
# in src/func_0203ea5c.c's own order, because that TU is still in no slice and
# an invented order would prove nothing about the contract. BOTH ARE INERT
# WITHOUT SM64DS_COMMS_ROLE: nothing installs, and the seam answers solo.
set(SLICE_COMMS_SOURCES hal/comms_seam.cpp hal/os_thread.cpp
                        hal/comms_loopback.cpp)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_comms.txt" SLICE_COMMS_LINES)
foreach(line IN LISTS SLICE_COMMS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_COMMS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run mg16 lane MP3: the REAL conductor, src/func_0203ea5c.c, and the dispatcher
# that switches to it. slice_mp3.txt says what is in it and why the seam line did
# not move to accommodate it. hal/comms_conductor.cpp is the host side: the DS
# globals the conductor needs that nothing had hosted, the one WM face that stays
# below the seam, the DS key register the dispatcher reads, and the pump that
# finally makes the contract's `poll` entry true.
#
# APPENDED TO SLICE_COMMS_SOURCES ON PURPOSE rather than given a list of its own:
# every consumer of the comms slice needs the conductor too, and three separate
# target lists each having to remember a new variable is exactly the shape
# FINDING 5 of the TITLE lane got bitten by (take one side of a generator-list
# conflict and a lane's TUs silently leave the link, which links fine and runs
# wrong).
list(APPEND SLICE_COMMS_SOURCES hal/comms_conductor.cpp)
# run mg16 lane MP4: the host-authoritative state-sync layer. Port-side
# only -- nothing in src/ knows it exists -- and OFF unless SM64DS_SYNC=1,
# so linking it changes no behaviour. See runs/mg16/status/MP4-DESIGN.md.
list(APPEND SLICE_COMMS_SOURCES hal/comms_sync.cpp)
# Lane VOICE: proximity voice chat. Port-side only -- nothing in src/ knows it
# exists -- and INERT unless settings.json turns VoiceEnabled on, which is off
# by default, so linking it opens no device and changes no behaviour. It rides
# SLICE_COMMS_SOURCES rather than a list of its own because it needs BOTH the
# carrier (comms_loopback.cpp's voice reader) and the hosted ARM7 mixer
# (SOUND_HOST_SOURCES), and the three targets that take this list are exactly
# the three that take that one -- the FINDING 5 shape again: a fourth variable
# each of them has to remember is how a lane's TUs silently leave a link.
list(APPEND SLICE_COMMS_SOURCES hal/voice_chat.cpp hal/voice_capture_win.cpp)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_mp3.txt" SLICE_MP3_LINES)
foreach(line IN LISTS SLICE_MP3_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_COMMS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# Run vs16, hosted-conductor follow-up: src/func_0203ea5c.c carries the ROM's
# nine `< 4` bounds, which is what stopped slots 4..15 entering world lockstep.
# The TU STAYS IN THE LINK, byte for byte, renamed to the narrow arm; the
# symbol the game calls is hal/comms_conductor_wide.cpp's dispatcher, which
# runs this TU for every session of four or fewer and the sixteen-record host
# copy above four. Same per-source rename mechanism as R1/R2 above. Appended
# to SLICE_COMMS_SOURCES like the conductor itself, so every consumer of the
# comms slice sees one and the same func_0203ea5c (FINDING 5 shape).
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0203ea5c.c"
    PROPERTIES COMPILE_DEFINITIONS "func_0203ea5c=func_0203ea5c_narrow")
list(APPEND SLICE_COMMS_SOURCES hal/comms_conductor_wide.cpp)
# 0.3.2: the same wall one layer down. src/func_0203bb60.c and
# src/func_0203bc7c.c (the ROM's per-frame comms-record -> TouchInfo/PadData
# fan-out, steps 0x16/0x17 of the main loop) loop to four. Same shape as the
# conductor: the ROM TUs stay linked under a rename and hal/comms_fanout_wide.cpp
# owns the two symbols, dispatching on the session's width.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0203bb60.c"
    PROPERTIES COMPILE_DEFINITIONS "func_0203bb60=func_0203bb60_narrow")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0203bc7c.c"
    PROPERTIES COMPILE_DEFINITIONS "func_0203bc7c=func_0203bc7c_narrow")
list(APPEND SLICE_COMMS_SOURCES hal/comms_fanout_wide.cpp)

# ---- gate 2thr: THE DS THREAD SCHEDULER, RUN AS THE ROM WROTE IT -----------
# run link2, lane THR.
#
# hal/os_thread.cpp's two host bodies are gone from every shipped target (they
# survive behind PORT_OS_THREAD_HOST_PAIR for the two console probes at the
# foot of this file, which exist to MEASURE them). What replaces them is not
# another stand-in one layer up but the ROM's own scheduler: src/OS_SleepThread
# .c, src/OS_WakeupThread.c and src/func_02057f54.c now link and run, on top of
# hal/boot2_thread.cpp, which gives the two hand-asm ARM context primitives a
# fiber-backed body -- the generalisation port/ntr/include/ntr/rt.h:11-14 said
# the fiber mechanism was for.
#
# APPENDED TO SLICE_COMMS_SOURCES ON PURPOSE, the same way the conductor is:
# the three targets that take that variable (smoke_player, walk_window,
# walk_window_hires) are exactly the three that used to take hal/os_thread.cpp's
# hosted pair, so the pair and its replacement have the same consumers and no
# target can end up with neither. port/slice_gate2thr.txt says what is in it,
# what is deliberately not, and why.
#
# NOTE the three rows also appear in port/slice_gate10.txt, where the filter
# above (`if(src MATCHES "/OS_SleepThread\\.c$" ...)`) still drops them. That
# filter is left alone deliberately: it is the only thing keeping these three
# from arriving on two lists at once.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate2thr.txt" SLICE2THR_LINES)
set(SLICE2THR_SOURCES "")
foreach(line IN LISTS SLICE2THR_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE2THR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_COMMS_SOURCES hal/boot2_thread.cpp ${SLICE2THR_SOURCES})

# The hosted ARM7: native SDAT player behind the game's own command queue.
set(SOUND_HOST_SOURCES
    hal/sdat/sdat.cpp
    hal/sdat/mixer.cpp
    hal/sdat/sseq.cpp
    hal/sdat/out_win.cpp
    hal/sdat/consumer.cpp
    hal/sdat/sound_abi.cpp
    hal/sdat/sound_bss.cpp
    # Run link100, lane SND1, rung R1: the command pool, its callback table and
    # SNDSharedWork in the ROM's own layout, so src/func_0205b358.c can run.
    # STORAGE ONLY, and it rides this list rather than the slice because
    # hal/sdat/consumer.cpp's queue lives on all three of these targets and the
    # object it walks has to be the same shape on each. hal/player_bridges.cpp
    # no longer defines data_020a6760; this file does, as the head of a
    # three-name run.
    hal/snd_globals.cpp)

# THE MODEL FAMILY'S THIRTEEN DESTRUCTOR BODIES (main -> port sync, lane
# SYNC5). main converted ten .c destructor TUs to .cpp, where each defines
# X::~X() -- a destructor the host headers deliberately do not declare, since
# they spell the ROM's two slots as two plain virtuals under _MSC_VER. MSVC
# answers C2600 and nothing on the host side reaches it, so the thirteen src
# rows are quarantined in their slices and the merge base's own bodies are
# host-copied here. The file's header carries the whole derivation and the
# retirement condition; runs/link100/out/SYNC5/decomp_side.md item 6 is the
# ask. It rides the three main targets next to LEVELBOOT_HOST_SOURCES because
# hal/model_dtor_seat.cpp, the actor-class tables and a dozen host copies all
# name these symbols, and all three targets compile those.
set(MODELFAMILY_HOST_SOURCES
    unmatched/ModelFamily_Dtors_HostCopy.c)

# W23-1 MODEL DTOR ARMS (LINK15 batch W23-1, run linkfull). Six of the
# fourteen bodies above retire here: include/Model.h and its four siblings
# already carry the _MSC_VER Destructor1/Destructor0 pair the header comment
# above asks for, and six src/ TUs already define the ROM's flat name under a
# #ifdef _MSC_VER arm (thiz->~X() through the one host symbol, then the
# class's own operator delete). port/slice_w23_modeldtor.txt names them; they
# ride next to MODELFAMILY_HOST_SOURCES on the same three targets because
# that file's surviving D1/D2 bodies still call into the flat names these TUs
# now provide instead. ShadowModel's D0 and every D1 body stay host-copied
# (D1 is already linked through the class's real ??1, so its flat name is a
# face, not a body; ShadowModel has no _MSC_VER arm yet).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w23_modeldtor.txt" SLICE_W23_MODELDTOR_LINES)
set(SLICE_W23_MODELDTOR_SOURCES "")
foreach(line IN LISTS SLICE_W23_MODELDTOR_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W23_MODELDTOR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

set(LEVELBOOT_HOST_SOURCES
    unmatched/ActorDerived_Spawn.cpp
    unmatched/PathPtr_FromID.cpp
    # func_0204335c_hostcopy.cpp and func_02043288_hostcopy.cpp RETIRED (lane
    # shadow-A): the init and behaviour Process wrappers come from hostgen's
    # VIRTUAL_CALL table now (GATE35_SYMS), the three static {slot, 1} records
    # resolved to the vtable slots they name at the caller.
    unmatched/func_0204322c_hostcopy.cpp
    unmatched/func_02043fdc_hostcopy.cpp
    # unmatched/LoadEntranceObjects.cpp RETIRED (run linkfull, lane RS4PORT):
    # the per-function src passes StartEntranceFaderWipe the wipe type (main
    # #3106's hunk) and is back on slice_gate14.txt.
    # func_02016ff4_hostcopy.cpp RETIRED (lane shadow-A): hostgen VIRTUAL_CALL
    # resolves the shadow-class slot-2 call to DoSetFile's host slot 1 and
    # keeps the shrink switch; see the table's note. GATE35_SYMS.
    # unmatched/ActorBase_AfterCleanupResources.cpp RETIRED -- the matched
    # source hosts itself now, through hostgen's ROLE_DATA map. See
    # HOSTABI_RETIRE_SYMS.
    unmatched/func_ov002_020c6f3c.cpp
    # Enemy::UpdateYoshiEat (ov002 0x020ade78): the eaten actor's swallow-arc
    # state machine, host-transcribed here from the 241/243 near-miss draft (the
    # residual is the 6o ordering floor, not matchable in this lane -- see the
    # file header). Retires the constant-0 stub that hal/actor_vtables.cpp used
    # to carry. It rides this slice, next to the enemy Behaviors that call it.
    # RETIRED (run link100 wave 14, lane SHADOWS3). The 6o ordering floor this
    # file's header called unmatchable was crossed by PR #2369 (adf091af7);
    # src/_ZN12dEnemyBase_c14UpdateYoshiEatER10dBgCh_Actr.cpp is on
    # port/slice_shadows3.txt and the flat Itanium name its callers use is
    # published by the generated reverse face its port/faces_sync.txt row now
    # asks for (that row was a FORWARD row while this host copy owned the flat
    # name; it is an R row now).
    # gate 16: two more mwcc pointer-to-member dispatches, both in actor
    # classes the registry carries. MSVC forms a PMF over an INCOMPLETE class
    # as the four-word general representation, which doubles the stride of the
    # table it indexes; see each file's header.
    unmatched/OneUpMushroom_Behavior.cpp
    # NumStars_hostcopy.cpp and CollectStar_hostcopy.cpp RETIRED (lane
    # shadow-A). src/IsStarCollected.c takes the course id as s8 now, so
    # src/NumStars.c links as it stands (slice_gate10.txt); CollectStar goes
    # through hostgen's ARG_WIDTH patch (GATE35_SYMS).
    unmatched/SignPost_StateDispatch.cpp
    # gate 18: the third, LakituBro's eleven-state machine
    unmatched/LakituBro_Behavior.cpp
    # ...and gate 17's ModelAnim slot-5 case with a body attached
    unmatched/Ov085_Renders.cpp
    # gate 19: unmatched/Cannon_Render.cpp RETIRED (run link100, lane FOLD2)
    # -- "the same slot problem one slot lower, on Model" was the destructor
    # fold, and _ZTV5Model[5] is Model::Render again. Its Behavior stays.
    unmatched/Cannon_Behavior.cpp
    # gate 21: the pointer-to-member dispatch for the fifth time
    unmatched/Fish_Behavior.cpp
    unmatched/UnchainedChomp_Behavior.cpp
    # gate 22: the sixth, plus the Model slot the dual fill cannot serve
    unmatched/Door_Behavior.cpp
    # unmatched/Door_Render.cpp RETIRED (run link100, lane FACEF): its reason
    # was the destructor fold on BOTH model tables at once -- "MSVC's slot 4 on
    # Model is Render, and dispatching there would draw the door's key twice
    # and never place it" -- and lane SLOT5F's respelling of the ROM's D1/D0
    # pair put Virtual10 back at _ZTV5Model[4] and Render at [5]
    # (cxxname_bridge.cpp:521-522). src/_ZN4Door6RenderEv.cpp is on
    # port/slice_facef.txt; it defines the C name itself and needs no face.
    # gate 23: the seventh, and the last on this level
    unmatched/QuestionBlock_States.cpp
    unmatched/QuestionBlock_BounceDispatch.cpp)
# unmatched/Painting_Dispatch.cpp RETIRED (run link100, lane UNMATCH). The
# widened-PMF half of its reason is dead under /vmg /vmm -- MSVC strides the
# ROM's own 0x18 and reads the ROM's own {code, adjust} pairs -- and the half
# that was real is now served by the seat: the twelve Painting state records
# hold a __fastcall face each, because these three dispatchers are the one
# member-pointer family in the port that MSVC compiles as `call eax` rather
# than a tail jump. src/_ZN8Painting13InitResourcesEv.cpp, _02126c60.cpp and
# _02126c20.cpp carry them, in port/slice_unmatch2.txt.
# unmatched/ModelAnim_Renders.cpp RETIRED (run link100, lane UNMATCH). Lane
# SLOT5F's stage B took twenty-three of its bodies; the twenty-fourth,
# SWITCH_PILLAR's own Render, stayed only because its source carries the
# "recovered from vtable slot identity" marker. It is ADJUDICATED REAL_DECOMP
# (inferred_stub_adjudicated.txt:2326, match.py 2004/b56 strict-reloc MATCH),
# so src/game/actors/d_a_obj_c0_switch.cpp carries it in port/slice_unmatch.txt and the
# file is gone.

set(CAMERA_HOST_SOURCES
    # unmatched/ChangeArea_hostcopy.c RETIRED (run linkfull, lane RS2PORT):
    # main 59013376ce passes HideArea the area index the ROM leaves in r0, so
    # src/ChangeArea.c runs, from port/slice_w28_rs2port.txt.
    # func_0200cae4_hostcopy.cpp and func_0200ca50_hostcopy.cpp RETIRED (lane
    # shadow-A): the matched dispatchers go through hostgen's MG_PMF_CALL
    # table (GATE13_SYMS), the one PMF call each routed into
    # hal_call_camera_state_fn.
    # G3i_PerspectiveW.cpp and G3i_LookAt.cpp RETIRED (lane shadow-A): both
    # matched TUs reach the geometry engine through a pointer bound once to a
    # literal register address, which hostgen's MMIO_PTR pass rewrites
    # (GATE13_SYMS); PerspectiveW_'s DIVCNT seam is an MMIO_EXTERN entry.
    hal/camera_states.cpp
    hal/camera_bridges.cpp)

# Camera::Render writes CLEAR_COLOR at a literal address; LenVec3 drives the
# hardware sqrt unit and cstd::ldiv_result reads the divider result -- all
# three only work through the NTR_MMIO proxy.
# func_02009d90 carries a GCC __attribute__((unused)) MSVC will not parse;
# hostgen strips attributes as well as rewriting MMIO.
# _ZN7dBase_c18AfterInitResourcesEj is C++ inside a .c (the gate-9 case
# again): hostgen emits it as .cpp with the C-linkage wrap, which MSVC accepts.
# Lane shadow-A adds the camera's three pointer-to-member dispatchers
# (hostgen CALL_STATE_FN: func_0200cae4 / func_0200ca50 into
# hal_call_camera_state_fn; MG_PMF_CALL: func_02008550 over hal/ptr_tables.cpp's records).
# _ZN7dBase_c18AfterInitResourcesEj LEFT THIS LIST 2026-09-13 (lane SYNC3):
# main folded it into src/actors/ActorDerived.cpp, a .cpp TU, so the C-linkage
# wrap of a .c source -- the only thing hostgen did for it -- is what the TU
# already is. No patch-table entry, no textual rewrite: measured, not assumed.
set(GATE13_SYMS _ZN6Camera6RenderEv LenVec3 _ZN4cstd11ldiv_resultEv
    func_02009d90
    func_02008550 func_0200cae4 func_0200ca50
    _ZN3G3i7LookAt_EPK7Vector3S2_S2_bP9Matrix4x3
    _ZN3G3i13PerspectiveW_E5Fix12IiES1_S1_S1_S1_S1_bP9Matrix4x3)
set(GATE13_GEN "")
foreach(sym IN LISTS GATE13_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE13_GEN "${sym_out}")
endforeach()

# LenVec3 comes from the hostgen copy now, so drop the plain gate-9 entry.
set(SLICE9_CAM_SOURCES "")
foreach(src IN LISTS SLICE9_SOURCES)
    if(src MATCHES "/LenVec3\\.c$")
        continue()
    endif()
    list(APPEND SLICE9_CAM_SOURCES "${src}")
endforeach()

# Gate 14: two more C++-in-a-.c files (the gate-9 case): Actor's
# AfterInitResources, which the spawn spine's init Process dispatches, and
# StartEntranceFaderWipe's sibling already in GATE10_SYMS.
# func_ov002_020c6fe4 LEFT THIS LIST 2026-09-13 (lane SYNC3): main folded it
# into src/actors/Player.cpp, which the whole-TU substitution at the top of this
# file covers. Its own two VOIDPP_ARITH sites are gone from main's spelling.
set(GATE14_SYMS _ZN8dActor_c18AfterInitResourcesEj)
set(GATE14_GEN "")
foreach(sym IN LISTS GATE14_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE14_GEN "${sym_out}")
endforeach()

# Gate 14: the real level boot. Stage::LoadClsnAndObjects over ov009's own
# LVL_Overlay, the fifteen sub-loaders, and the setters they store through.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate14.txt" SLICE14_LINES)
set(SLICE14_SOURCES "")
foreach(line IN LISTS SLICE14_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # gate 35: func_0203d974 reads the console-type halfword at 0x027ffc40,
    # which no ntr region maps. It was harmless while nothing called it; the
    # course sound boot calls it. hal/star_flow.cpp hosts it.
    if(line MATCHES "/func_0203d974\\.c$")
        continue()
    endif()
    list(APPEND SLICE14_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 36: the real Stage::InitResources, to replace port_stage_a_boot.
#
# SLICE36_SOURCES IS INERT. It is parsed here and added to NO target, so these
# 33 lines compile nothing and link nothing. The comment that stood here said
# "Linked but NOT yet called", which was false in its first half: nothing is
# linked. The list is kept because it is the gate's inventory and because the
# measurement below is worth having written down, not because it is wired.
#
# WHY IT STAYS THAT WAY, measured in wave 4 rather than argued. Adding
# ${SLICE36_SOURCES} to walk_window and building fails the link with 43
# distinct unresolved externals and ZERO duplicate definitions -- so the
# blocker is not a clash with the host boot, it is that the slice does not
# close. The 43 sort into three groups and none of them is a line in a file:
#
#   22  storage the port hosts nowhere: data_020755e0/5f0/600/6f0/720/769/76a,
#       data_0208ecf4, data_0208ee00, data_02092130, data_02092778,
#       data_0209d4a8, data_0209f278, data_0209f290, data_0209f300,
#       data_0209f304, data_020758c8, data_020a0f04, data_ov001_020ad620,
#       data_ov001_020ad624, _ZTV9FaderWipe, and LoadOrUnloadObjectOverlays
#   15  matched TUs that exist in src/ and are not on this slice at all:
#       GetControllerMode, LoadOverlay, _ZN10FaderColorD2Ev, the five GX::SetBankFor*
#       setters, func_02018908, func_02018934, func_020190b8, func_02023408,
#       func_0203d81c, func_02053e1c, func_02053e34
#    6  ON THIS SLICE ALREADY and still unresolved: _Z17LoadLevelOverlaysi,
#       ShadowModel::CleanAll, Stage::LoadGraphics2D, Stage::LoadFog,
#       Stage::LoadTextureTransformers, FaderWipe::LoadAndSetFile
#
# That last group is what decides it. Those six .cpp files define the real C++
# METHOD -- src/_ZN5Stage7LoadFogEv.cpp compiles `void Stage::LoadFog()`, which
# MSVC mangles ?LoadFog@Stage@@... -- while Stage::InitResources calls the
# ROM's C name __ZN5Stage7LoadFogEv. Listing the file does not produce the
# symbol its caller wants; a hand-written face does, the way
# hal/method_faces.cpp already carries its own. So the slice head's "all 45
# direct callees are matched, nothing here is written by hand, this slice is
# the wiring" does not survive a build: six faces have to be written, 22
# globals hosted and 15 more callees enrolled before the boot swap it describes
# is reachable at all. Wiring it in today only breaks the build, which is why
# the honest move is to leave it inert and say so.
#
# ShadowModel::CleanAll is the one line here that IS doing work today, and it
# does it from slice_w1l3.txt instead -- see the block in that file.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate36.txt" SLICE36_LINES)
set(SLICE36_SOURCES "")
foreach(line IN LISTS SLICE36_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE36_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Stage 4, lane SD0: gate 36 WIRED, which is what the block above says nobody
# had done. port/slice_s4_slot0.txt is SLICE36_SOURCES minus src/LoadArchive.c
# (the one real LNK2005, against hal/scene_boot.cpp's PORT_HOST_ABI host body),
# minus src/UnloadArchive.c and src/_Z17LoadLevelOverlaysi.cpp (host bodies in
# hal/stage_slot0.cpp instead), plus the three matched callees the closure
# names and no active slice carries.
#
# THE 43 THE BLOCK ABOVE MEASURED IS NOW ZERO, and none of the three groups it
# sorted them into survived as written:
#   the 22 unhosted globals   six are romdata rows (data_020755e0/5f0/600,
#       data_02092778 and the two 0x9a sound columns), one is
#       hal/ptr_tables.cpp table 4 (data_020756f0, twelve ov002 pointers), one
#       is an /alternatename (data_02075720 onto VS_STAR_SPAWN_ORDERS), two are
#       4-byte BSS words in hal/stage_slot0.cpp, and the rest closed on their
#       own as the port grew -- data_0208ecf4 and LoadOrUnloadObjectOverlays
#       through hal/scene_boot.cpp, _ZTV9FaderWipe and the two ov001 words
#       through lane SL0.
#   the 15 unsliced callees   twelve closed as other slices took them; three
#       are on this slice.
#   the 6 already-on-the-slice  five are C-name faces (four in
#       hal/stage_slot0.cpp, FaderWipe::LoadAndSetFile in hal/fader_wipes.cpp),
#       and _Z17LoadLevelOverlaysi is a host body.
# The block above is kept as written because the measurement in it is the
# reason this one could be short.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_s4_slot0.txt" SLICE_S4_SLOT0_LINES)
set(SLICE_S4_SLOT0_SOURCES ${SCN3D_HOSTGEN_GEN})
foreach(line IN LISTS SLICE_S4_SLOT0_LINES)
    if(line IN_LIST SCN3D_HOSTGEN_SKIP)
        continue()
    endif()
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_S4_SLOT0_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gates 40-44: levels 1 and 2 (castle grounds ov009, castle interior ov010),
# the actor classes their object tables name that were still printing as
# skipped. Each gate's evidence is in the head of its slice_gateNN.txt and the
# registry rows are in hal/actor_classes.inc.
#   Gate 40: STAR_DOOR (354, ov100) -- the config's mislabeled _ZN4Door family.
#   Gate 41: TRAP (36) + LIGHT_BEAM (37), ov010, level 2's own overlay.
#   Gate 42: PEACH_PAINTING (38), ov010.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate40.txt" SLICE40_LINES)
set(SLICE40_SOURCES "")
foreach(line IN LISTS SLICE40_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE40_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate41.txt" SLICE41_LINES)
set(SLICE41_SOURCES "")
foreach(line IN LISTS SLICE41_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE41_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# Gate 42: PEACH_PAINTING (38), ov010. The ov052/RollingRock "blocker" was the
# shared-base illusion -- ov010 and ov052 link at the same base, so dsd named
# two of PeachPainting's OWN internal references (_ZN13PeachPainting20UpdateModelTransformEv and the
# ov010 BSS SharedFilePtr data_ov010_02112d64) as ov052/ov021 symbols at the
# shared address. The relocs say module:overlay(10) both times. No overlay is
# mounted for this gate; the two mislabeled names are closed by /alternatename
# in hal/actor_classes.cpp. See the head of slice_gate42.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate42.txt" SLICE42_LINES)
set(SLICE42_SOURCES "")
foreach(line IN LISTS SLICE42_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE42_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 50: ov080's PAINTING (daPicGate_c, 307), the castle interior's portrait
# gate. A different class from PEACH_PAINTING, in a different overlay, with no
# cross-overlay spawn -- its closure is 28 matched ov080 TUs plus three sinits.
# See the head of slice_gate50.txt and hal/actor_classes_painting.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate50.txt" SLICE50_LINES)
set(SLICE50_SOURCES "")
foreach(line IN LISTS SLICE50_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE50_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 51: the CAP (WaterfallMist, 269), ov002. Built at gate 33, registered
# here now that its nine-state PMF table is seated. See slice_gate51.txt and
# unmatched/Cap_StateDispatch.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate51.txt" SLICE51_LINES)
set(SLICE51_SOURCES "")
foreach(line IN LISTS SLICE51_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE51_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 59: ov015's seven static initialisers (Whomp's Fortress platforms), plus
# the platform classes' matched lifecycle closures (gates 60-63 append their own
# TUs here). See slice_gate59.txt and hal/actor_classes_wf.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate59.txt" SLICE59_LINES)
set(SLICE59_SOURCES "")
foreach(line IN LISTS SLICE59_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE59_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gates 70-74: Whomp's Fortress' level-7 enemies and platforms (ov084, ov091).
# Both overlays are already mounted (gate 32); these slices are the matched
# lifecycle closures of the five classes, one file each. The HAL seam is
# hal/actor_classes_l7.cpp and the piranha state seat plus the two enemy Renders
# are unmatched/PiranhaPlant_States.cpp. See each slice_gate7N.txt header.
set(SLICE_L7_SOURCES "")
foreach(gate 70 71 72 73 74)
    set(_gf "${CMAKE_CURRENT_SOURCE_DIR}/slice_gate${gate}.txt")
    if(NOT EXISTS "${_gf}")
        continue()
    endif()
    port_read_lines("${_gf}" _glines)
    foreach(line IN LISTS _glines)
        string(STRIP "${line}" line)
        if(line MATCHES "^#" OR line STREQUAL "")
            continue()
        endif()
        list(APPEND SLICE_L7_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
    endforeach()
endforeach()
# gate 70: func_ov084_0212f460 is C++ inside a .c (the gate-9 case) -- it opens
# an `extern "C"` block MSVC's C front end will not parse -- so it goes through
# hostgen, which re-emits it as .cpp with the symbols wrapped back to C linkage.
# (func_ov084_0212f33c uses a C99 compound literal MSVC warns on as C4576; that
# is suppressed per target below rather than transformed.)
# EMPTIED 2026-09-13 (lane SYNC3). main folded func_ov084_0212f460 into
# src/actors/daPkn_c.cpp, a .cpp TU, so the C-linkage wrap hostgen gave the .c
# source is what the TU already is. That TU is also QUARANTINED out of every
# slice (its func_ov084_0212f204 calls ClosestPlayer with no receiver), so the
# body is out of the link either way and a generated copy would only put the
# receiver-less call back.
set(GATE_L7_SYMS)
set(GATE_L7_GEN "")
foreach(sym IN LISTS GATE_L7_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE_L7_GEN "${sym_out}")
endforeach()

# Gate 78: BLUE_COIN_SWITCH (10), ov002. See slice_gate78.txt and the section in
# hal/actor_classes.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate78.txt" SLICE78_LINES)
set(SLICE78_SOURCES "")
foreach(line IN LISTS SLICE78_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE78_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 79: STAR_MARKER (180), ov002. See slice_gate79.txt and the section in
# hal/actor_classes.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate79.txt" SLICE79_LINES)
set(SLICE79_SOURCES "")
foreach(line IN LISTS SLICE79_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE79_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 82: SHUTTER_BOB (40), Bob-omb Battlefield's own shutter. A Platform
# subclass in the already-mounted ov014 (the chain chomp gate), so this slice
# is HAL-only closure -- the five class methods plus the four ov002 helpers
# they reach. See slice_gate82.txt and the SHUTTER_BOB section in
# hal/actor_classes_bob_world.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate82.txt" SLICE82_LINES)
set(SLICE82_SOURCES "")
foreach(line IN LISTS SLICE82_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE82_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# The one method face InitResources needs that no Actor.h-including TU can emit
# (MeshColliderBase::Enable with a class-tagged Actor); see the file's header.
# ...and the host copy of the spawn factory, which restores the vtable-store
# order the shared-header recovery lost (see the file header).
list(APPEND SLICE82_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/shutter_bob_face.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/ShutterBob_Spawn_hostcopy.cpp")

# Gate 83: SEESAW_BOB (39), Bob-omb Battlefield's seesaw bridge, a Platform
# subclass in a FRESH per-symbol ov095 mount (PORT_ACTOR_OVERLAYS). This slice
# is the six class methods, the five ov095 helpers they reach and the two ov095
# sinits. See slice_gate83.txt and the SEESAW_BOB section in
# hal/actor_classes_bob_world.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate83.txt" SLICE83_LINES)
set(SLICE83_SOURCES "")
foreach(line IN LISTS SLICE83_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE83_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 102: FORTRESS_TOWER (49), Whomp's Fortress (ov102). The vtable
# _ZTV13FortressTower, all five methods and the SpawnInfo are already in the
# link (WARP_PIPE, id 298, is registered at gate 33 and installs the same
# table); this slice is the one new symbol, the factory daObjSimpleBg_c_classInit_BK_TOWER.
# The registry row reuses hal_fill_warp_pipe_vtable (fill 0). See
# slice_gate102.txt and the WARP_PIPE section in hal/actor_classes_bob_world.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate102.txt" SLICE102_LINES)
set(SLICE102_SOURCES "")
foreach(line IN LISTS SLICE102_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE102_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 103: STAR_SWITCH (12), Whomp's Fortress (ov002). Same class body as
# EXCLAMATION_SWITCH (id 11, registered at gate 51, installs _ZTV10StarSwitch);
# all five methods are already compiled and the vtable filled with its PMF
# state seat. This slice is the one new symbol, the factory daObjSwitch_c_classInit_STAR_SWITCH;
# the SpawnInfo mount is in ov002_syms.txt and the registry row reuses
# hal_fill_exclamation_switch_vtable (fill 0). See slice_gate103.txt and the
# EXCLAMATION_SWITCH section in hal/actor_classes_bob_world.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate103.txt" SLICE103_LINES)
set(SLICE103_SOURCES "")
foreach(line IN LISTS SLICE103_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE103_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 128: EXCLAMATION_BLOCK (21), Jolly Roger Bay's sunken-ship sublevel
# (level 9, ov017), the class living in ov102. Same class shape as QUESTION_BLOCK
# (id 20, registered at gate 23, installs _ZTV13QuestionBlock); all of
# QuestionBlock's methods are already compiled and the vtable filled. This slice
# is the one new symbol, the factory daObjHatenaBlock_c_classInit_ITEM_BLOCK; the SpawnInfo mount
# is already in ov102_syms.txt and the registry row reuses
# hal_fill_question_block_vtable (fill 0). See slice_gate128.txt and the
# QUESTION_BLOCK section in hal/actor_classes.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate128.txt" SLICE128_LINES)
set(SLICE128_SOURCES "")
foreach(line IN LISTS SLICE128_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE128_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 209: KOOPA_SHELL (285), Bob-omb Battlefield (ov102). A new Enemy subclass
# (its own vtable _ZTV10KoopaShell / daShl_c), not a vtable-sharer: the eight
# class TUs, its OnYoshiTryEat body and the four Behavior/InitResources helpers
# not already compiled. The vtable fill hal_fill_koopa_shell_vtable and the eight
# faces are hal/actor_classes_bob_enemy.cpp; the SpawnInfo and the PMF state
# statics are already mounted/seated (ov102_syms.txt + __sinit_ov102_0214dfac).
# Spawned dynamically by GREEN_SHELL_BLOCK_TAG (323) and a stomped Koopa (203).
# See slice_gate209.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate209.txt" SLICE209_LINES)
set(SLICE209_SOURCES "")
foreach(line IN LISTS SLICE209_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE209_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 210 (lane SEAT-OV002-RUNTIME): FIREBALL (254, ov002), BOWSER_SHOCKWAVES
# (281, ov060), BUBBLE (291, ov002), YOSHI_EGG (9, ov002). Four run-time spawns
# asked for by code already in the link (Actor::SpawnFireball, Bowser's stomp,
# the treasure chest's open state, Player::St_Swallow_Main); none is on any
# level's object table. Fills and faces in hal/actor_classes_runtime_spawns.cpp;
# the two host render copies are appended to unmatched/ModelAnim_Renders.cpp
# and unmatched/Ov060_Renders.cpp; YoshiEgg's PMF state seat is
# unmatched/YoshiEgg_StateDispatch.cpp. See slice_gate210.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate210.txt" SLICE210_LINES)
set(SLICE210_SOURCES "")
foreach(line IN LISTS SLICE210_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE210_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 121: STATIC_ROCK (61), Jolly Roger Bay (ov102). Shares _ZTV13FortressTower
# (WARP_PIPE gate 33, FORTRESS_TOWER gate 102 install it); the one new symbol is
# the factory daObjSimpleBg_c_classInit_KI_IWA. Registry row reuses hal_fill_warp_pipe_vtable.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate121.txt" SLICE121_LINES)
set(SLICE121_SOURCES "")
foreach(line IN LISTS SLICE121_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE121_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 122: BRICK_BLOCK_SWITCH_ACTIVATED (19), Jolly Roger Bay (ov002). Same body
# as BIG_BRICK_BLOCK (_ZTV13BigBrickBlock, gate 16); the one new symbol is the
# factory daObjBlockL_c_classInit_SW_BLOCK_L. SpawnInfo in ov002_syms.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate122.txt" SLICE122_LINES)
set(SLICE122_SOURCES "")
foreach(line IN LISTS SLICE122_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE122_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 123: GREEN_SHELL_BLOCK_TAG (323), Jolly Roger Bay (ov002). A tag body
# sharing _ZTV10BrickBlock (gate 49); the one new symbol is the factory
# daObjBlockItemTag_c_classInit_BLK_GNSHELL_TAG. SpawnInfo in ov002_syms.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate123.txt" SLICE123_LINES)
set(SLICE123_SOURCES "")
foreach(line IN LISTS SLICE123_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE123_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 142/143: IceSlideManager (356), Cool Cool Mountain's slide (ov019), level
# 11's one own-overlay class. The matched closure (factory, InitResources,
# Behavior, sinit) is slice_gate142.txt; the vtable fill is
# hal/actor_classes_ccm.cpp and the two method faces are in hal/method_faces.cpp.
# The per-symbol ov019 mount (ov019_syms.txt) and this class's sinit
# (__sinit_ov019_02112b14, run from hal/actor_overlays.cpp) seat its SpawnInfo
# and construction data.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate142.txt" SLICE142_LINES)
set(SLICE142_SOURCES "")
foreach(line IN LISTS SLICE142_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE142_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 149: Big Boo's Haunt's level-local furniture (ov020, level 12) --
# HAUNTED_CHAIR (326) hosted, the bookend/bookshot cast deferred. ov020 is joined
# to the per-symbol mounts so the classes reach their SpawnInfo/statics by name;
# the vtable fills and faces are in hal/actor_classes_bbh.cpp. See slice_gate149.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate149.txt" SLICE149_LINES)
set(SLICE149_SOURCES "")
foreach(line IN LISTS SLICE149_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE149_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 172: CRATE (194), Hazy Maze Cave's first fresh hosting candidate.
# ov098 was already mounted per symbol; the closure is the factory, the four
# C++ methods, both destructors, the four owned virtual-slot bodies, the
# fourteen state halves and their ov098 helpers. The two state dispatchers are
# host copies (unmatched/Crate_StateDispatch.cpp, with the table seat); the
# vtable fill is hal/actor_classes_hmc.cpp. See slice_gate172.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate172.txt" SLICE172_LINES)
set(SLICE172_SOURCES "")
foreach(line IN LISTS SLICE172_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE172_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 173: UP_DOWN_LIFT_HMC (33), Hazy Maze Cave's second fresh class (ov095).
# ov095 was mounted per symbol at gate 83; the closure is the factory, the two
# lifecycle methods + Render, both destructors and the five state bodies with
# their two ov095 helpers. Behavior is a host copy
# (unmatched/UpDownLiftBbh_Behavior.cpp, with the state seat) because it
# dispatches the state table through an incomplete-class pointer-to-member. The
# fill is hal/actor_classes_updownlift.cpp. See slice_gate173.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate173.txt" SLICE173_LINES)
set(SLICE173_SOURCES "")
foreach(line IN LISTS SLICE173_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE173_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 174: MONTY_MOLE (310), first of ov080's enemy cast. ov080 was mounted
# per symbol at gate 50 and already carries every data symbol the mole reads.
# Behavior is a host copy (unmatched/MontyMole_StateDispatch.cpp, with the
# six-record state seat); D1 is a host thunk in the fill (the matched .cpp is
# the auto-emitted-member-dtor form). The fill is
# hal/actor_classes_montymole.cpp. See slice_gate174.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate174.txt" SLICE174_LINES)
set(SLICE174_SOURCES "")
foreach(line IN LISTS SLICE174_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE174_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 175: BLUE_FLAME (317) + RED_FLAME (316), the cave's flames, ov002. One
# class, two factories, one host vtable (hal/actor_classes_flame.cpp, which
# also carries the Player::Burn face); no state table, no seat, no host
# copies. Level 13 names RED_FLAME x17. See slice_gate175.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate175.txt" SLICE175_LINES)
set(SLICE175_SOURCES "")
foreach(line IN LISTS SLICE175_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE175_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 176: SCUTTLEBUG (255), ov071's first mount. The closure is the factory,
# the five lifecycle methods (three real C++ methods, two C forms), D0, the
# eighteen state halves and their ov071 helpers, plus three arm9 C-form
# helpers. The two state dispatchers are host copies with the source-side seat
# (unmatched/Scuttlebug_StateDispatch.cpp); the fill is
# hal/actor_classes_scuttlebug.cpp. See slice_gate176.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate176.txt" SLICE176_LINES)
set(SLICE176_SOURCES "")
foreach(line IN LISTS SLICE176_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE176_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run linkw wave 7, lane w7b: THE MR. I FAMILY -- MR_I (262) and BIG_MR_I (263),
# which share one class and one vtable, plus MR_I_PROJECTILE (264), the shot
# MrI's state 1 fires through Actor::Spawn(0x108). ov071 was already mounted
# per-symbol by gate 176, so this lane adds no overlay: rows, two fills, the
# state seat, and four host copies (the two unmatched per-frame state MAINs,
# the two PMF dispatchers, plus the slot-5 Render and two D1 thunks).
# See slice_w7b.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w7b.txt" SLICE_W7B_LINES)
set(SLICE_W7B_SOURCES "")
foreach(line IN LISTS SLICE_W7B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W7B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Two MR_I_PROJECTILE TUs need hostgen, both mwcc-vs-MSVC syntax quirks the
# byte-verified tree must not be edited for (the gate-32 / gate-64 treatment).
# _ZN8daEyBm_c18SpawnDestroyEffectEv is C++ inside a .c -- `struct Callback {}`, an empty
# struct, which MSVC will not compile as C (C2016); hostgen emits it as .cpp
# with the symbols wrapped back to C linkage.
# _ZN8daEyBm_c10HurtPlayerEv is the decl_common.h HEADER_SHADOW case: that header
# declares it `(void*)` inside its extern "C" block while the TU defines it
# `(char*)` -- one register on the ROM, C2733 to MSVC. This lane adds the
# HEADER_SHADOW table entry in tools/hostgen.py.
# EMPTIED 2026-09-13 (lane SYNC3). main folded both into
# src/game/actors/d_a_ey_bm.cpp and made them real C++ METHODS of daEyBm_c
# rather than extern "C" free functions. The empty-struct-in-a-.c case went with
# the .c, and HurtPlayer's C2733 went with the free function: that TU does not
# include decl_common.h, so the header's declaration of the old C-linkage name
# meets nothing.
set(GATE_W7B_SYMS)
set(GATE_W7B_GEN "")
foreach(sym IN LISTS GATE_W7B_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE_W7B_GEN "${sym_out}")
endforeach()

# Gate 177: BULLY (215) + BIG_BULLY (216) + ROTATING_FIREBAR (81), ov064's
# first mount. No PMF tables; the bullies' D1/D0 and all three Renders are
# host thunks/copies (the fill and unmatched/ModelAnim_Renders.cpp); the
# fills are hal/actor_classes_ov064.cpp. See slice_gate177.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate177.txt" SLICE177_LINES)
set(SLICE177_SOURCES "")
foreach(line IN LISTS SLICE177_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE177_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate178.txt" SLICE178_LINES)
set(SLICE178_SOURCES "")
foreach(line IN LISTS SLICE178_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE178_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---- run linkw wave 9, lane w9-reg: TILTING_PLATFORM_LLL (id 72, ov064) ----
# The largest single class in the wave-8 skip census: fourteen instances, x10 on
# level 44 and x4 on level 48. ov064 is already mounted twice (gates 177/178), so
# this adds no overlay mount -- only the class's own five matched TUs, its four
# extra mount symbols in port/ov064_syms.txt, and the fill in
# hal/actor_classes_ov064_w9.cpp. Its ov002 dependencies (the shared TILTING
# Behavior/Render pair and the base Init/Cleanup pair the two veneers tail-call)
# were all confirmed present in walk_window.map BEFORE the slice was written.
# See port/slice_w9a.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w9a.txt" SLICEW9A_LINES)
set(SLICEW9A_SOURCES "")
foreach(line IN LISTS SLICEW9A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICEW9A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---- run linkw wave 9, lane w9-reg, slice B: three ov084 shared-table siblings
# GOOMBA_LARGE (202) x9, FIRE_PIRANHA_PLANT_BIG (251) x5 and
# FIRE_PIRANHA_PLANT_SMALL (252) x2 -- sixteen instances for three TUs. Both ROM
# tables they use are already host arrays filled by an already-registered id, and
# all three SpawnInfo records are already in port/ov084_syms.txt, so this adds no
# mount and no fill. See port/slice_w9b.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w9b.txt" SLICEW9B_LINES)
set(SLICEW9B_SOURCES "")
foreach(line IN LISTS SLICEW9B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICEW9B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---- run linkw wave 9, lane w9-reg, slice C: three ov091 sliding-platform
# siblings sharing the table the registered id 55 already fills. Four instances
# for three TUs; no mount and no fill added. See port/slice_w9c.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w9c.txt" SLICEW9C_LINES)
set(SLICEW9C_SOURCES "")
foreach(line IN LISTS SLICEW9C_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICEW9C_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---- run linkw wave 9, lane w9-reg, slice D: three ov095 seesaw siblings
# sharing the table the registered id 39 already fills. Four instances for three
# TUs; three records join port/ov095_syms.txt at the 0x1c stride that file
# already measured, and no fill or vtable is added. See port/slice_w9d.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w9d.txt" SLICEW9D_LINES)
set(SLICEW9D_SOURCES "")
foreach(line IN LISTS SLICEW9D_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICEW9D_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate179.txt" SLICE179_LINES)
set(SLICE179_SOURCES "")
foreach(line IN LISTS SLICE179_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE179_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate182.txt" SLICE182_LINES)
set(SLICE182_SOURCES "")
foreach(line IN LISTS SLICE182_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE182_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate KLEPTO: ov062's cap-stealing bird (actor 239). ov062 already mounted
# (gate 32); the seat is HAL (actor_classes_koopa_chuckya.cpp) plus the two-PMF
# host copy unmatched/Klepto_StateDispatch.cpp. See slice_klepto.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_klepto.txt" SLICEKLEPTO_LINES)
set(SLICEKLEPTO_SOURCES "")
foreach(line IN LISTS SLICEKLEPTO_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICEKLEPTO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate180.txt" SLICE180_LINES)
set(SLICE180_SOURCES "")
foreach(line IN LISTS SLICE180_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE180_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 203: the QUESTION_BLOCK / EXCLAMATION_BLOCK's five HIT slots -- the
# vtable tail that ENTERS state 1, which gate 180 then runs. Gate 23 left
# slots 21/22/24/27/28 on ac_trapNN because their ov102 bodies were in no
# slice, so hitting the block raised a fault the quarantine net caught and the
# actor froze instead of opening. Slot 28 (0x021496a4) is OnHitFromUnderneath,
# the jump-into-it-from-below hit that is how the box is meant to be opened.
# See slice_gate203.txt and the QUESTION_BLOCK section in hal/actor_classes.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate203.txt" SLICE203_LINES)
set(SLICE203_SOURCES "")
foreach(line IN LISTS SLICE203_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE203_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 204 (run linkw wave C, lane cat-ov002): the ov002 DELETING DESTRUCTORS.
# Slot 17 on three seated ov002 classes -- PushBlock, HealingHeart and the Cap
# -- was a trap or a hand-spelled copy of the chain, while each class's own
# matched D0 body sat in src/ with nothing referencing it. The seats are in
# hal/actor_classes_bob_world.cpp and hal/actor_classes_ov002g200.cpp; the
# derivation, the RTTI-name aliases and why this is not a behaviour change are
# in slice_gate204.txt. Coin's D0 needed no line: it has been on
# slice_gate33.txt all along and only wanted the reference edge.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate204.txt" SLICE204_LINES)
set(SLICE204_SOURCES "")
foreach(line IN LISTS SLICE204_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE204_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 205 (run link60, lane A1): ov085's WALL_SIGN (183) and TOAD (185), the
# overlay's last two screened classes, nineteen placed instances across levels
# 2, 4, 5 and 50. ov085 has been mounted per symbol since gate 18 and all six
# of its sinits are already called, so the slice is code only. THREE host
# bodies ride beside it: both classes' slot 6 is not decompiled at all
# (unmatched/Ov085_Behaviors.cpp, HOST REIMPLEMENTATIONS written from the ROM),
# and Toad's two PMF dispatchers are the gate-16 case
# (unmatched/Ov085_Toad_StateSeat.cpp). Toad's D1 is held out and spelled in
# the fill, the SlideDecorationSilverStar shape. See slice_gate205.txt and
# hal/actor_classes_ov085.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate205.txt" SLICE205_LINES)
set(SLICE205_SOURCES "")
foreach(line IN LISTS SLICE205_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE205_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run rel0215 wave 3 (lane w3-f): ov085's PRINCESS_PEACH (186, 9daPeach_c), the
# overlay's sixth and last class. The mount and all six sinits have been in
# place since gate 18, so this slice is code only -- the same shape gate 205
# had. TWENTY-ONE matched TUs; FOUR bodies are held out and each is named in
# port/slice_w3f.txt with the reason:
#   * Behavior dispatches its ModelAnim's ROM SLOT 3 and the matched TU spells
#     MSVC index 3, which on an MSVC-numbered _ZTV9ModelAnim is Virtual10 -- one
#     slot high, wrong arity. The wave-19 collision, TWO slots below where
#     LAKITU_BRO and the RABBIT hit it. HOST COPY.
#   * D1 is the shadow-class MSVC destructor shape TOAD's D1 has, spelled inline
#     in the fill from the ROM D1's own five relocs.
#   * the two mwcc pointer-to-member dispatchers, the gate-16 case for the sixth
#     time. HOST COPIES with the {value, adjustment} dispatch hand-rolled, plus
#     a ten-pair state seat in hal/actor_overlays.cpp that runs before
#     __sinit_ov085_0212f3a0 copies them.
# Her Render LINKS: the ROM calls Model::Render non-virtually, so no vtable
# numbering comes into it -- the other half of the same ruling.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w3f.txt" SLICEW3F_LINES)
set(SLICEW3F_SOURCES "")
foreach(line IN LISTS SLICEW3F_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICEW3F_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 208 (run link60, lane A2): MONTY_MOLE_ROCK (311), ov080's second enemy
# class after gate 174's mole. The mole's throw state spawns 0x137, the port
# declined it and the ROM-faithful thrower stored through the NULL, so
# SM64DS_LEVEL=13 SM64DS_SPAWN_ACTOR=310 faulted at +0x98 on the first throw.
# The whole cast is matched and every TU is on the slice -- no host copy, no
# state seat, no thunk standing in for a body, the first ov080 class needing
# none of those. The 31-slot width is re-derived with vtspan on this tree and
# slot 9's wave-19 slot-5 shadow is adjudicated SAFE from how the class
# constructs its +0x110 member (a plain Model, and _ZTV5Model[5] is
# dual-filled) -- the opposite ruling from the mole's own ModelAnim Render one
# class over. The fill is hal/actor_classes_montymolerock.cpp; the derivation,
# the vtspan routes and the seven friendly-name renames are in
# slice_gate208.txt.

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate208.txt" SLICE208_LINES)
set(SLICE208_SOURCES "")
foreach(line IN LISTS SLICE208_LINES)
    string(STRIP "${line}" line)
    if(line STREQUAL "" OR line MATCHES "^#")
        continue()
    endif()
    list(APPEND SLICE208_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# The rock's Behavior is the only TU in the tree that spells seven arm9/ov002
# functions by recovered friendly names that exist nowhere in the binary. Each
# target is pinned by the reloc out of that body's own range (ov080 relocs,
# Behavior = 0x0212459c..0x0212478c) and named from config/arm9/symbols.txt,
# never from the friendly name. A -D and not /alternatename directives on
# purpose: these are single global names of the G0/G1 kind, and an alias LHS
# another overlay's recovery pass reuses for a different address would
# misroute silently the day that overlay lands. A -D cannot be defeated.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13MontyMoleRock8BehaviorEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "Actor_MakeVanishLuigiWork=_ZN8dActor_c19MakeVanishLuigiWorkER5dCc_c;Actor_FindWithID=_ZN8dActor_c10FindWithIDEj;Player_Hurt=_ZN6Player4HurtERK7Vector3j5Fix12IiEjjj;Actor_UpdatePos=_ZN8dActor_c9UpdatePosEP5dCc_c;Enemy_UpdateWMClsn=_ZN12dEnemyBase_c12UpdateWMClsnER10dBgCh_Actrj;CylinderClsn_Clear=_ZN5dCc_c5ClearEv;CylinderClsn_Update=_ZN5dCc_c6UpdateEv")
# Gate 208's arrival cost, and it is the R3 ov071/ov073 shape from the OTHER
# side: seating the rock DEFINES _ZN13MontyMoleRockD0Ev, which silently defeats
# hal/bob_enemy_bridges.cpp's /alternatename with that LHS. King Bob-omb's two
# throw states call ov078 0x02123804 -- his own throw body, relocs 0x02123ac0
# and 0x02123c28 both module:overlay(78), unambiguous -- and dsd named that
# same address for ov080 too, so their C spells it with the rock's destructor
# name. Without this they would have called the rock's destructor.
# tools/alternatename_guard.py failed the build the first time the seat linked;
# the dead directive is deleted there and the routing lands here, where a -D
# cannot be defeated.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daBombking_c.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daBombking_c.cpp"
    # and the generated copy, lane DUPES: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set the property on a source
    # nothing compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/daBombking_c.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/actors/daBombking_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZN13MontyMoleRockD0Ev=func_ov078_02123804")

# Gate 206 (run link60, lane A2): DIAMOND_LIFT (135), ov043's first seated
# class. Six of level 35's eight skipped instances, and the only one of the
# overlay's three placed classes with a clean factory. The 32-slot width is
# vtspan-confirmed on every route, slot 9's slot-5 shadow is adjudicated SAFE
# from construction (a plain Model at +0xd4, and _ZTV5Model[5] is dual-filled),
# and one sinit runs rather than four. The fill and the mount bring-up are
# hal/actor_classes_ov043.cpp; the derivation and the four re-verified traps
# are in slice_gate206.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate206.txt" SLICE206_LINES)
set(SLICE206_SOURCES "")
foreach(line IN LISTS SLICE206_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE206_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# TRAP 1, and it is the live one. src/game/actors/d_a_obj_km1_ukishima.cpp (id 135's
# CleanupResources) releases ov043's own two bss SharedFilePtrs through the
# shared role-name placeholders G0 and G1, and hal/cxx_aliases.cpp has already
# bound _G0 to _data_020a0eac (the GAME HEAP pointer) and _G1 to
# _data_ov002_0210e05c (SignPost's KCL). Neither would fail at link and the
# body would have released the game heap pointer -- the CannonHatch/MetalNet
# shape, the PATH_LIFT case exactly. The two targets are read off this body's
# own literal pool: 0x02111278 -> 0x021125e8 and 0x0211127c -> 0x021125e0,
# both module:overlay(43), each feeding a SharedFilePtr::Release at 0x02111260
# and 0x02111268. The rename goes to private names this lane owns, not
# straight to the mount names, because include/decl_common.h:396 declares
# `extern int G1[];` and MSVC rejects the redeclaration; the two private names
# bind onto the mounted cells in hal/actor_classes_ov043.cpp.
# src/game/actors/d_a_obj_km1_ukishima.cpp IS DELIBERATELY NOT HERE. Its G0 is a DIFFERENT
# object -- the game heap it hands Memory::Deallocate, literal at 0x02111238
# relocating to 0x020a0eac module:main -- which is what cxx_aliases.cpp already
# binds. Renaming it would break a binding that is right today.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_km1_ukishima.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   G0=port_ov043_ukishima_file0  --  dead, the TU does not spell G0
#   G1=port_ov043_ukishima_file1  --  dead, the TU does not spell G1
# Deleted rather than merged. The surviving row is unchanged.
# TRAP 3: src/game/actors/d_a_obj_km1_ukishima.cpp (InitResources) spells ov043's own two bss
# cells with ov047 names. ov043 and ov047 are distinct objects sharing the load
# window and dsd raced the name; the load sites are the same two addresses the
# sinit initialises, both module:overlay(43). Neither ov047 name resolves in
# port/ today, so this is a hard link error rather than a silent miscall. Safe
# as a straight -D to the mount names: decl_common.h declares
# data_ov047_021125e0/e8 as `extern int [];` and declares no data_ov043_
# 021125e0/e8 at all, so there is nothing to conflict with.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_km1_ukishima.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   data_ov047_021125e8=data_ov043_021125e8  --  dead, the TU does not spell data_ov047_021125e8
#   data_ov047_021125e0=data_ov043_021125e0  --  dead, the TU does not spell data_ov047_021125e0
# Deleted rather than merged. The surviving row is unchanged.
# TRAP 4: src/game/actors/d_a_obj_km1_ukishima.cpp (the deleting destructor) writes VT0 then
# VT1 and both are placeholders. Its own literal pool names them:
# 0x02111230 -> 0x021122b8 module:overlay(43), the class's own table, which is
# the host array; 0x02111234 -> 0x0210ae38 module:overlay(2), the Platform base
# table, which hal/actor_classes.cpp:583 already defines and fills. Renamed to
# the two real hosted names, never to a placeholder. Its sibling
# src/game/actors/d_a_obj_km1_ukishima.cpp (the D1) writes the SAME pair BY NAME and needs no
# rename at all.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_km1_ukishima.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV19daObjKm1_Ukishima_c;VT1=_ZTV10dBgActor_c")

# ============================================================================
# lane SEAT-BDW: ov043's remaining cast -- RICKSHAW_BDW (137),
# RICKSHAW_PLATFORM_BDW (136), STAIRS_BDW (134). The ov047 152/151/153 shape
# (Bowser in the Sky's identical siblings) applied to ov043, so every -D bind
# below is the ov047 bind at the matching address. Ids by Spawn-store, not name
# (the naming shift). See port/slice_bdw.txt and hal/actor_classes_ov043.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_bdw.txt" SLICEBDW_LINES)
set(SLICEBDW_SOURCES "")
foreach(line IN LISTS SLICEBDW_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICEBDW_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# Every bind is settled from the TU's own literal pool in
# config/arm9/overlays/ov043/relocs.txt. In the two factories the recovered RTTI
# name means the ov002 INTERMEDIATE base (stored first) and VT1 means the class's
# OWN table (stored second) -- constructor order. In the destructors the same
# RTTI name means the OWN table, _ZTV10dBgActor_c the intermediate base and VT2
# the Platform base 0x0210ae38 (bound to _ZTV10dBgActor_c, the identical-fill twin
# the port keeps at that shape). Left alone the factories install the abstract
# intermediate last and dispatch InitResources through a ZERO slot 0 -- a null
# call invisible to the byte gate.
#
# id 137 (RICKSHAW_BDW) is NOT enrolled: its four own bodies are inferred guesses
# and it is not registered (a live level-35 137 NULL-derefs during spawn once its
# InitResources is declined). Its factory daObjKm1_Kurumajiku_c_classInit.c and sinit
# __sinit_ov043_02111868.c are left out of slice_bdw.txt.
# id 136 (RICKSHAW_PLATFORM_BDW): factory + D1 + D0. Own table 0x0211245c
# (host array _ZTV17daObjKm1_Kuruma_c), intermediate base ov002 0x02109278. Its
# Init/Cleanup .c bodies spell only mounted names and need no -D.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_km1_kuruma.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV17daObjKm1_Kuruma_c=_ZTV13daObjKuruma_c  --  dead, the TU does not spell _ZTV17daObjKm1_Kuruma_c
#   VT1=_ZTV17daObjKm1_Kuruma_c  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_km1_kuruma.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV17daObjKm1_Kuruma_c=_ZTV17daObjKm1_Kuruma_c  --  identity rename, a no-op even if it had run
#   _ZTV10dBgActor_c=_ZTV13daObjKuruma_c  --  dead, the TU does not spell _ZTV10dBgActor_c
#   VT2=_ZTV10dBgActor_c  --  dead, the TU does not spell VT2
# Deleted rather than merged. The surviving row is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_km1_kuruma.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV17daObjKm1_Kuruma_c=_ZTV17daObjKm1_Kuruma_c;_ZTV10dBgActor_c=_ZTV13daObjKuruma_c;VT2=_ZTV10dBgActor_c;G0=data_020a0eac")
# id 134 (STAIRS_BDW): its five TUs spell _ZTV17daObjKm1_Dorifu_c,
# _ZTV13daObjDorifu_c and _ZTV10dBgActor_c -- the three real addresses in ROM order
# -- so they need no -D, the ov047 STAIRS_BS reading. Its sinit does: the
# five-stair file constructor spells sixteen of its own .bss cells with an OV047
# tag and four with an OV052 tag (the naming shift at the shared load window).
# ov047 IS mounted, so the four ov052 names would silently build in Mario's Key
# Course storage and the sixteen ov047 names are unresolvable -- a hard link
# error. All twenty are ov043's own 0x021126xx cells (the mount defines them);
# renamed direct, decl_common.h declares none of them.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/__sinit_ov043_02111940.c"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov047_021126a0=data_ov043_021126a0;data_ov047_021126fc=data_ov043_021126fc;data_ov052_02112680=data_ov043_02112680;data_ov047_02112708=data_ov043_02112708;data_ov047_02112668=data_ov043_02112668;data_ov052_021126a8=data_ov043_021126a8;data_ov052_02112688=data_ov043_02112688;data_ov047_021126b4=data_ov043_021126b4;data_ov052_02112690=data_ov043_02112690;data_ov047_021126c0=data_ov043_021126c0;data_ov047_02112678=data_ov043_02112678;data_ov047_021126cc=data_ov043_021126cc;data_ov047_02112658=data_ov043_02112658;data_ov047_021126d8=data_ov043_021126d8;data_ov047_02112670=data_ov043_02112670;data_ov047_021126e4=data_ov043_021126e4;data_ov047_02112698=data_ov043_02112698;data_ov047_021126f0=data_ov043_021126f0;data_ov047_02112660=data_ov043_02112660;data_ov047_02112714=data_ov043_02112714")

# Gate 207 (run link60, lane A2): four more ov002 slot-17 seats -- VirtualDoor,
# PoppingLavaBubbles, AmbientSoundEffects and MugenBgm. Gate 204's convention
# applied rather than extended, with all three of its conditions re-run against
# this build: the ROM word at table+0x44 is each class's own D0 read as raw
# bytes out of the overlay image, each body is flat C with no inferred-stub
# marker and a closed callee set, and the binary-wide [reg+44h] dispatch count
# is still zero with the slot-16 positive control still landing in
# ActorBase::AfterCleanupResources. Each table is installed by exactly one
# factory plus its own D1/D0, which is the condition BrickBlock fails. The
# derivation, the raw-byte table and the sweep output are in slice_gate207.txt.
# run rel0215 wave 1 (lane cast-ov026): ov026's whole cast, level 18 (Dire Dire
# Docks). Five classes, 49 of the overlay's 54 matched TUs. Per-symbol ov026
# mount (port/ov026_syms.txt), fill hal/actor_classes_ov026.cpp. The five TUs
# NOT in this slice are host-copied and named at the bottom of
# port/slice_ov026cast.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov026cast.txt" SLICE_OV026_LINES)
set(SLICE_OV026_SOURCES "")
foreach(line IN LISTS SLICE_OV026_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV026_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---- lane cast-ov026: the per-source renames -------------------------------
#
# A. THE SHARED ROLE-NAME PLACEHOLDERS. A comment-stripped sweep of all 54
# ov026 TUs for VT/VT0/VT1/VT2/G0/G1/G2/R0/R1/R2/HEAP returns exactly five
# files. hal/cxx_aliases.cpp binds bare G0 -> data_020a0eac (the GAME HEAP) and
# bare G1 -> data_ov002_0210e05c (SignPost's KCL) for the whole link, so an
# unrenamed placeholder here does not fail a link -- it releases the wrong
# storage, the CannonHatch/MetalNet/PathLift shape. Every target below is the
# address that TU's OWN ROM body loads, read out of the literal pool of
# extracted/overlays/overlay_0026.bin:
#
#   _ZN17daObjWlPolelift_cD0Ev (89's D0)   pool 0211122c/1230: VT0=0x02113ae0, G0=0x020a0eac
#   _ZN13BowserShutterD0Ev (91's D0)   pool 02111758/5c/60: VT0=0x02113ba4,
#                                     VT1=0x0210ae38 (_ZTV10dBgActor_c), G0=0x020a0eac
#   _ZN13BowserShutter16CleanupResourcesEv (91 Cleanup) pool 021117a0/a4: G0=0x02113ebc, G1=0x02113eb4
#   _ZN9SubmarineD0Ev (90's D0)   pool 02111948/4c/50: VT0=0x02113c6c,
#                                     VT1=0x0210ae38, G0=0x020a0eac
#   _ZN9Submarine16CleanupResourcesEv (90 Cleanup) pool 02111990/94: G0=0x02113ee4, G1=0x02113edc
#
# VT0 goes to the HOST ARRAY in each case (all five vtables are excluded from
# the mount). VT1 is spelled _ZTV10dBgActor_c to match what the sibling D1s
# (_ZN13BowserShutterD1Ev.c, _ZN9SubmarineD1Ev.c) already write BY NAME;
# hal/actor_classes.cpp:591 defines that array and dual-fills it with
# _ZTV10dBgActor_c.
# The four SharedFilePtr targets and the polelift's collision vector go through
# PRIVATE NAMES this lane owns, bound in hal/actor_classes_ov026.cpp with a
# C-name /alternatename, because include/decl_common.h already declares
# data_ov026_02113ebc/eb4/edc/ee4 as `char[]` and data_ov026_02113a9c as
# `Vector3` while the TUs declare their placeholders as `extern int G0[];` and
# a local `struct V3` -- a direct -D is the C2371/C2372 redeclaration the ov006
# Mg3DEsp block measured. Each private LHS is undefined everywhere else, so
# those aliases cannot be defeated.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN17daObjWlPolelift_cD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV17daObjWlPolelift_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13BowserShutterD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV21daObjWlKoopaShutter_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN9SubmarineD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV18daObjWlSubmarine_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13BowserShutter16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_ov026_shutter_bmd;G1=port_ov026_shutter_kcl")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN9Submarine16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_ov026_submarine_bmd;G1=port_ov026_submarine_kcl")
#
# B. THE SECOND SPELLING OF A HOST-ARRAY VTABLE. Three of the five tables are
# reached under two names by ov026's own sources, and only one host array can
# exist per table because the object's vptr is one word. A -D rather than an
# /alternatename on purpose: a -D cannot be defeated by a later mount (the
# ov071/ov073 R3 failure), and the R5 precedent points the rename AT the host
# array for exactly this case.
#   daObjWlKoopaShutter_c_classInit.c writes _ZTV13BowserShutter, its D1 writes
#     _ZTV21daObjWlKoopaShutter_c -- same address 0x02113ba4.
#   daObjWlSubmarine_c_classInit.c writes _ZTV9Submarine, its D1 writes
#     _ZTV18daObjWlSubmarine_c -- same address 0x02113c6c.
#   _ZN9WhirlpoolD1Ev.c and daWater_Tatumaki_c_classInit.c write _ZTV9Submarine, the D0
#     writes _ZTV18daWater_Tatumaki_c -- same address 0x02113d54, and the
#     _ZTV9Submarine row is the WRONG label (that table's own vtable[-1]
#     typeinfo name string reads 18daWater_Tatumaki_c), so the rename runs
#     toward the right name.
#   _ZN12WaterSuctionD0Ev.c writes _ZTV17daWater_Suikomi_c, the D1 and the
#     Spawn write _ZTV12WaterSuction -- same address 0x02113e24, and here BOTH
#     labels are correct spellings of one class, so the rename is only picking
#     the majority spelling.
# include/decl_common.h declares every one of these as `extern int NAME[];`, so
# each rename produces a duplicate IDENTICAL declaration, which is legal.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_obj_wl_koopa_shutter.c"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV13BowserShutter=_ZTV21daObjWlKoopaShutter_c")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_obj_wl_submarine.c"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV9Submarine=_ZTV18daObjWlSubmarine_c")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN9WhirlpoolD1Ev.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_water_tatumaki.c"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV9Submarine=_ZTV18daWater_Tatumaki_c")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN12WaterSuctionD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV17daWater_Suikomi_c=_ZTV12WaterSuction")
#
# C. THE WRONG-OVERLAY CROSSINGS. ov026 shares the level load window at
# 0x021111a0 with ov014/ov015/ov016/ov020/ov021/ov022/ov029/ov032/ov034/ov036/
# ov045/ov053 and dsd raced the name on four references inside ov026's own
# sources. Each target is ov026's own symbol at the identical address.
#
#   src/func_ov026_021122b0.c calls __sinit_ov045_02112280 where ov026's own
#   func_ov026_02112280 (0x02112280, kind:function, size 0x30) is meant. THIS
#   ONE IS A LIVE HAZARD, not a synonym: ___sinit_ov045_02112280 is ALREADY
#   DEFINED in walk_window by ov013_syms.c.obj (measured in the 0.2.15 baseline
#   map, 0004:000cc184) -- a mounted DATA object at the shared address. Left
#   alone, WaterSuction's state-0 tick would have called into mounted data, and
#   an /alternatename would have been defeated silently. A -D cannot be.
#
#   src/__sinit_ov026_02112d68.c writes data_ov036_02113f58 where ov026's own
#   bss cell data_ov026_02113f58 is meant -- that sinit is ov026's own .init
#   code and the cell it builds is the one WaterSuction::InitResources passes to
#   func_ov026_021122d4. ov036's 0x02113f58 is a real .data symbol of ov036's,
#   which is exactly why this must not be an alias.
#
#   src/_ZN17daObjWlPolelift_c13InitResourcesEv.cpp reads data_ov032_02113a9c (ov026's own
#   0x02113a9c, the polelift's collision half-extents) and calls
#   func_ov053_021112a4 (ov026's own func_ov026_021112a4, the matrix/scale
#   helper immediately above it in the same class block). The first goes
#   through the private name in block A because decl_common.h's own
#   data_ov026_02113a9c declaration would collide; the second is renamed
#   directly -- decl_common.h:1566 declares func_ov053_021112a4 and does not
#   declare func_ov026_021112a4, so there is nothing to conflict with.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov026_021122b0.c"
    PROPERTIES COMPILE_DEFINITIONS
    "__sinit_ov045_02112280=func_ov026_02112280")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/__sinit_ov026_02112d68.c"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov036_02113f58=data_ov026_02113f58")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN17daObjWlPolelift_c13InitResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov032_02113a9c=port_ov026_polelift_clsn;func_ov053_021112a4=func_ov026_021112a4")

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate207.txt" SLICE207_LINES)
set(SLICE207_SOURCES "")
foreach(line IN LISTS SLICE207_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE207_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# All four spell their own table with the shared role name VT, which
# hal/cxx_aliases.cpp binds globally to _data_ov002_021081e4 -- a fifth class's
# table. That is the CannonHatch/MetalNet shape and it would not fail at link,
# so each file is renamed to its own table. The targets come from each body's
# OWN literal pool, read out of extracted/overlays/overlay_0002.bin:
#   0x020b0a04 -> 0x021086b4   0x020b6e5c -> 0x021094a0
#   0x020f19e0 -> 0x0210b4c8   0x020f1c18 -> 0x0210b584
# HEAP is deliberately NOT renamed: the second literal in all four is
# 0x020a0eac, the game heap, which is what cxx_aliases.cpp already binds it to.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_ch_scene.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=_ZTV11daChScene_c")
# and the generated copies, lane CRASH6: these two TUs are on PORT_HOSTGEN_TU
# now, so the raw path alone would set the define on a source nothing compiles,
# and VT would go back to cxx_aliases.cpp's global binding to a fifth class's
# table. The rename is exactly as load-bearing after the substitution as before.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_waterfall.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_obj_waterfall.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=_ZTV16daObjWaterfall_c")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_set_se.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_set_se.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=_ZTV9daSetSE_c")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN8MugenBgmD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=_ZTV8MugenBgm")

# ---- gate 211: ENEMY_SWITCH_TAG (357) and ENEMY_SPAWNER (358), ov002 --------
# Ten matched TUs, five per class (the two complete-object D1 destructors stay
# off the slice -- shadow-class C++ dtors that do not link on host; slot 16 is a
# host thunk in hal/actor_classes_enemy_spawner.cpp). EnemySpawner's D0 spells
# its table through the shared VT placeholder, which hal/cxx_aliases.cpp binds
# globally to _data_ov002_021081e4 (the Enemy base table); rename it per-source
# to its own array. HEAP is left alone -- already the game heap. EnemySwitchTag's
# D0 spells the RTTI dual name _ZTV11daESwitch_c, aliased in the fill.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate211.txt" SLICE211_LINES)
set(SLICE211_SOURCES "")
foreach(line IN LISTS SLICE211_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE211_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN12EnemySpawnerD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=_ZTV12EnemySpawner")

# ---- gate 212: QUESTION_SWITCH (26), ov002 ---------------------------------
# Twelve matched TUs: six class TUs (Render is the ModelAnim slot-5 host copy
# in unmatched/ModelAnim_Renders.cpp, the QuestionBlock case), the slot-21
# OnGroundPounded body (ROM-adjudicated REAL_DECOMP, see
# port/tools/inferred_stub_adjudicated.txt) and the five helpers. The 32-slot Platform table is a host array in
# hal/actor_classes_question_switch.cpp, which also carries the fill, the
# faces and the SM64DS_QS_PROBE tick probe. Both destructors are matched
# extern-C bodies and are enrolled. See port/slice_gate212.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate212.txt" SLICE212_LINES)
set(SLICE212_SOURCES "")
foreach(line IN LISTS SLICE212_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE212_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---- GATE 215: the save system's own medium path (run link100, lane SAVE) ----
#
# Seventeen matched TUs: SaveData::SaveDataToCart and SaveData::ReadDataFromCart
# (both were host shadows in hal/scene_boot.cpp) and the card-backup driver
# under them. The MEDIUM is port/ntr/backup.cpp, listed beside this slice on
# each target rather than inside the ntr library: it defines ROM symbols
# (func_02060f60, func_02057020, func_02057078 and the driver's bss), and the
# small smoke targets that link ntr have no business pulling those in.
# See port/slice_gate215.txt and the header of port/ntr/backup.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate215.txt" SLICE215_LINES)
set(SLICE215_SOURCES "")
foreach(line IN LISTS SLICE215_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE215_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# ---- gate 216: the ROM's own vtable words the link did not carry -------------
#
# Run link100, lane TAIL. Twenty-one matched TUs (fourteen in the first batch,
# seven in the second), every one of them a word the
# ROM puts in a table the port ALREADY hosts and fills: two Actor tail veneers
# at slots 8 and 11 of every Actor table, four abstract ov002 intermediates'
# own destructor pairs, and four words of the Bully/BigBully base. No new
# class, no new mount; four of the six second-batch D1 seats are on live,
# dispatched classes (their teardown now runs the ROM body) -- each slot held a trap or a shortcut
# into the base and now holds the body config/<module>/relocs.txt names at that
# offset. The per-slot reads are reproducible with port/tools/tail_slots.py and
# quoted in port/slice_gate216.txt and at each seat.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate216.txt" SLICE216_LINES)
set(SLICE216_SOURCES "")
foreach(line IN LISTS SLICE216_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE216_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# THE SIX PER-SOURCE RENAMES, and where each target came from. Six of the eight
# intermediate destructors are shared-header recoveries: they spell the class's
# OWN table as _ZTV10dBgActor_c and the base it overwrites it with as VT1, and
# hal/cxx_aliases.cpp binds a bare VT1 to auto_bss's dummy for the whole link
# -- so leaving one unrenamed does not fail the link, it writes the wrong table
# into a live object's vptr (the CannonHatch/MetalNet shape). Each target below
# is the address that TU's OWN ROM body loads, read out of the relocations
# INSIDE the function's span in config/arm9/overlays/ov002/relocs.txt:
#
#   _ZN16daObjKaitendai_cD1Ev (D1)  pool 020b66a0/a4:  0x021091d4, 0x0210ae38
#   _ZN16daObjKaitendai_cD0Ev (D0)  pool 020b6658/5c/60: 0x021091d4, 0x0210ae38, 0x020a0eac
#   _ZN13daObjKuruma_cD1Ev (D1)  pool 020b68a8/ac:  0x02109278, 0x0210ae38
#   _ZN13daObjKuruma_cD0Ev (D0)  pool 020b6860/64/68: 0x02109278, 0x0210ae38, 0x020a0eac
#   _ZN17daObjKurumajiku_cD1Ev (D1)  pool 020b6a78/7c:  0x02109320, 0x0210ae38
#   _ZN17daObjKurumajiku_cD0Ev (D0)  pool 020b6a30/34/38: 0x02109320, 0x0210ae38, 0x020a0eac
#
# 0x0210ae38 is _ZTV10dBgActor_c by config/arm9/overlays/ov002/symbols.txt:2225,
# hosted as `void *_ZTV10dBgActor_c[32]` in hal/actor_vtables.cpp; 0x020a0eac is
# the game heap word. The daObjDorifu_c pair (020b4af8 / 020b4a70) and the four
# ov064 bodies spell every one of their targets by its real name and take no -D
# at all, which is why they are not listed here.
foreach(g216 _ZN16daObjKaitendai_cD1Ev _ZN13daObjKuruma_cD1Ev _ZN17daObjKurumajiku_cD1Ev)
    if(g216 STREQUAL "_ZN16daObjKaitendai_cD1Ev")
        set(G216_OWN _ZTV16daObjKaitendai_c)
    elseif(g216 STREQUAL "_ZN13daObjKuruma_cD1Ev")
        set(G216_OWN _ZTV13daObjKuruma_c)
    else()
        set(G216_OWN _ZTV17daObjKurumajiku_c)
    endif()
    set_source_files_properties(
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/${g216}.c"
        PROPERTIES COMPILE_DEFINITIONS
        "_ZTV10dBgActor_c=${G216_OWN};VT1=_ZTV10dBgActor_c")
endforeach()
foreach(g216 _ZN16daObjKaitendai_cD0Ev _ZN13daObjKuruma_cD0Ev _ZN17daObjKurumajiku_cD0Ev)
    if(g216 STREQUAL "_ZN16daObjKaitendai_cD0Ev")
        set(G216_OWN _ZTV16daObjKaitendai_c)
    elseif(g216 STREQUAL "_ZN13daObjKuruma_cD0Ev")
        set(G216_OWN _ZTV13daObjKuruma_c)
    else()
        set(G216_OWN _ZTV17daObjKurumajiku_c)
    endif()
    set_source_files_properties(
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/${g216}.c"
        PROPERTIES COMPILE_DEFINITIONS
        "_ZTV10dBgActor_c=${G216_OWN};VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
endforeach()
# THE THREE LIVE-CLASS D1 RENAMES. Same rule, different placeholder names: each
# of these three bodies spells its OWN table by a config RTTI name the port
# hosts under an address name, and the base it overwrites it with as
# _ZTV10dBgActor_c. Targets read out of the relocations inside each function's
# span, not from the recovery's names:
#
#   _ZN16daObjC0_Switch_cD1Ev  0x021111dc -> ov012 0x02112344   0x021111e0 -> 0x0210ae38
#   _ZN10RockPillarD1Ev  0x02112a3c -> ov016 0x02114b00   0x02112a40 -> 0x0210ae38
#   _ZN7SkiLiftD1Ev  0x021111dc -> ov018 0x021138cc   0x021111e0 -> 0x0210ae38
#
# _ZN18daObjClockHuriko_cD1Ev and _ZN4DoorD1Ev spell every word they store by a
# name the port already defines, so they take no -D and are deliberately absent
# here. _ZN13daObjKi_Ita_cD1Ev is not in the gate at all: its MIDDLE store is ov002
# 0x02108fdc, and that intermediate base table is hosted nowhere in this port --
# a table to host, not a rename.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_c0_switch.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV16daObjC0_Switch_c=_ZTV16daObjC0_Switch_c  --  identity rename, a no-op even if it had run
#   _ZTV10dBgActor_c=_ZTV10dBgActor_c  --  identity rename, a no-op even if it had run
# Deleted rather than merged. The surviving row is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10RockPillarD1Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV16daObjKi_Hasira_c=_ZTV10RockPillar;_ZTV10dBgActor_c=_ZTV10dBgActor_c")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN7SkiLiftD1Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV14daObjSm_Lift_c=_ZTV7SkiLift;_ZTV10dBgActor_c=_ZTV10dBgActor_c")
# ---- gate 214 (run link100, lane BOOT): THE ROM'S OWN BOOT CHAIN ------------
#
# The port boots through tests/walk_window.cpp's main(), which stands in for
# the ROM's Entry and main(). Two of the ROM's boot steps were already on that
# path and named as such -- Heap::InitializeRootHeap and
# Heap::InitializeGameHeap(0x3b000, 0) -- and the rest of the chain was not
# there at all, which is why 503 matched translation units reachable ONLY
# through Entry/main were unlinked. hal/boot_os.cpp transcribes the runnable
# spans of src/func_02019780.c, src/main.c and src/func_0201a054.c and calls
# the ROM's own bodies at the points the ROM calls them; everything in this
# slice is reached from there by the ROM's own call graph, never by a call
# added to make a file link.
#
# hal/boot_hw.cpp is the OTHER half and does NOT raise the count: the ARM
# primitives at the leaves of that chain (CP15 cache/MPU, CPSR mode toggles,
# `swp`, the literal-pool veneers, MSL's hand-written format DFA). Each one
# carries a PORT_HOST_ABI: tag naming the instruction MSVC cannot assemble, so
# port/tools/linkage.py counts them as documented exceptions rather than as
# work still owed.
#
# WHAT IS NOT IN HERE, and it is hardware and not effort: the four PXI arms of
# func_02058c84 spin on the ARM7's channel-ready bits at 0x027ffc00 + 0x388 and
# port/ntr models no IPC at all, so calling them never returns; func_02058ec8
# and func_02059594 reach func_02058764, which reads the Slot-2 magic at
# 0x08000000 and no ntr::kRegions entry covers that address. The header block
# of hal/boot_os.cpp lists every skipped step with its measurement.
#
# On the two targets that compile tests/walk_window.cpp, because that file is
# where the boot calls live. See port/slice_gate214.txt.
# ---- lane IPCSEND: the channel-8 firmware read, re-seated -------------------
# Four matched TUs run link100 lane BOOT2 backed out because the ARM9 could not
# send. It can now (IPCSend is in GATE2IPC_SYMS below), so func_020196cc goes
# back at its own point in hal/boot_os.cpp's port_boot_rom_game_init_tail. This
# list rides with SLICE214_SOURCES rather than with the PXI slice, because
# hal/boot_os.cpp is what calls it and that file is on the two walk_window
# targets only -- putting the four on smoke_player as well would add object
# files whose externs (data_0208ee3c, data_0209d4b8) that target does not host.
# See port/slice_ipcsend.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ipcsend.txt" SLICE_IPCSEND_LINES)
set(SLICE_IPCSEND_SOURCES "")
foreach(line IN LISTS SLICE_IPCSEND_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_IPCSEND_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate214.txt" SLICE214_LINES)
# hal/globals_link100.cpp: the card driver's control block, hosted as the one
# ROM object dsd split into three names. It is on this list because that block
# is the storage the func_02042f68 refusal in hal/boot_os.cpp is about, and the
# refusal and the storage should not drift apart.
set(SLICE214_SOURCES hal/boot_os.cpp hal/boot_hw.cpp hal/boot_globals.cpp)
# hal/globals_link100.cpp rides beside ntr/backup.cpp on all three targets: the
# save gate's SaveData bodies reference the card span from smoke_player too.
foreach(line IN LISTS SLICE214_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE214_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---- run link100 rung R3F: THE THREE `G` PLACEHOLDERS THAT ARE REGISTERS ----
#
# Read blocker B4 in hal/boot_os.cpp's placeholder table first, and lane R3E's
# derivation (runs/link100/out/R3E/e1_blocker.txt) second. The short of it:
# `G` is the decomp's GENERIC placeholder for an absolute address a function
# pools, so several unrelated TUs spell completely different things with the
# same identifier. One of them means it: _ZN4Heap10SetDefaultEv's pool word at
# 0x0203c338 carries a RELOC (config/arm9/relocs.txt: from:0x0203c338
# kind:load to:0x020a0ea0), so THERE `G` really is Memory::defaultHeapPtr and
# the /alternatename in hal/lk4_solidheap_seat.cpp is right. Three others pool
# an I/O address with NO reloc, because an absolute register needs none:
#
#     func_02055454  pool 0x02055460  0x04000010  BG0HOFS/BG0VOFS, str (word)
#     func_02057128  pool 0x0205713c  0x04000204  EXMEMCNT, ldrh/orr 0x80/strh
#     func_02057140  pool 0x02057154  0x04000204  EXMEMCNT, ldrh/bic 0x80/strh
#
# and those three, resolving `G` through the alias, were reading and writing
# the DEFAULT HEAP POINTER. func_02019144's else arm calls func_02055454 with
# the BG0 scroll on every VBlank of every 3D level, which is 0, so under
# SM64DS_ROM_LOOP=1 the allocator's default heap went NULL once per frame and
# the next free faulted at Heap::Deallocate+0x3 (R3E, frame 31, levels
# 1/5/9/13). The other two are the same landmine on the card-lock path: they
# OR and AND bit 7 of that pointer through func_02057158/func_02057178.
#
# THE FIX IS IN THE DECOMP AND IT COSTS NOTHING. src/ now spells each register
# the way src/func_0205583c.c and src/func_02057320.cpp already spell theirs,
# and all three still byte-verify against the ROM -- BETTER than before, since
# the placeholder made the pool word a reloc slot the byte gate WILDCARDED and
# a literal address is compared for real:
#
#     tools/match.py func_02055454 0x02055454 0x10  4/4 words OK  2004/b56
#     tools/match.py func_02057128 0x02057128 0x18  6/6 words OK  2004/b56
#     tools/match.py func_02057140 0x02057140 0x18  6/6 words OK  2004/b56
#
# Spelling it is only half. port/ntr/io.cpp's rule is that a store reaches
# ntr::io_write only if its TU was rewritten by tools/hostgen.py; built plain
# it latches in the mapped window and triggers nothing. So the three go through
# hostgen exactly the way rung BSWAP took the ROM's frame swap
# (func_020190b8, the R3B_SWAP block above), with the same kill switch
# discipline: the arm is PRINTED ON EVERY CONFIGURE in both directions,
# because a CMake option() caches and a switch that announces only one arm
# silently keeps the wrong one.
#
# The three come off port/slice_gate214.txt, so the cut below is against
# SLICE214_SOURCES and has to sit after that list is built. SLICE214_SOURCES
# goes to walk_window and walk_window_hires only, and R3F_GREG_GEN is appended
# to exactly those two targets: the LINK SET does not change, only the route.
option(R3F_GREG_PLAIN
       "run link100 R3F: build the three register TUs PLAIN (pre-fix arm)"
       OFF)
set(R3F_GREG_SYMS
    func_02055454          # BG0HOFS/BG0VOFS, the VBlank display commit
    func_02057128          # EXMEMCNT |= 0x80
    func_02057140)         # EXMEMCNT &= ~0x80
list(LENGTH R3F_GREG_SYMS R3F_GREG_WANT)
# GREG2 (run link100 lane GREG2, 09-09): a fourth `G` I/O reader, found by R3F
# but left unowned -- src/func_0205f650.c pools 0x04000304 (POWCNT1) with NO
# reloc and reads bit 0, so through the SetDefault alias it was reading bit 0
# of Memory::defaultHeapPtr instead. Its caller src/func_02019a58.c is the
# wait loop `while (func_0205f66c(1) != 1)` that polls this bit for the LCDs
# to come back on. It ships off port/slice_gate220.txt, not slice_gate214.txt
# (Stage::Behavior's gate, not this one's), so it cannot be cut out of
# SLICE214_SOURCES above -- the cut against SLICE220_SOURCES is further down
# this file, right after that list is built, and kept in its OWN counter so
# this addition cannot silently perturb R3F's already-verified 3/3 SLICE214
# accounting. It rides the SAME R3F_GREG_PLAIN switch and the SAME hostgen
# discipline as the three above.
set(R3F_GREG2_SYMS func_0205f650)   # POWCNT1 & 1 -- the LCD-power wait read
set(R3F_GREG_ALL_SYMS ${R3F_GREG_SYMS} ${R3F_GREG2_SYMS})
if(R3F_GREG_PLAIN)
    message(STATUS "R3F: R3F_GREG_PLAIN=ON -- the four register TUs build "
                   "PLAIN. This is the PRE-FIX arm: the stores latch in the "
                   "mapped I/O window and no register is told, and the "
                   "POWCNT1 read (GREG2) sees whatever that window has "
                   "instead of the seeded value.")
else()
    message(STATUS "R3F: R3F_GREG_PLAIN=OFF -- the four register TUs route "
                   "through hostgen (shipped arm).")
endif()
set(R3F_GREG_GEN "")
if(NOT R3F_GREG_PLAIN)
    foreach(sym IN LISTS R3F_GREG_ALL_SYMS)
        set(sym_in "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        if(NOT EXISTS "${sym_in}")
            set(sym_in "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
        endif()
        set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
        add_custom_command(OUTPUT "${sym_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
            DEPENDS "${sym_in}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${sym}")
        list(APPEND R3F_GREG_GEN "${sym_out}")
    endforeach()
endif()
# Cut the plain slice entries in the SAME block that adds the generated ones,
# for the BSWAP block's reason: the real net is the LINKER either way, and the
# count guard below is only a signpost for a reader looking at a failed link.
set(R3F_GREG_CUT 0)
set(SLICE214_SRC_R3F "")
foreach(src IN LISTS SLICE214_SOURCES)
    set(_cut OFF)
    if(NOT R3F_GREG_PLAIN)
        foreach(sym IN LISTS R3F_GREG_SYMS)
            if(src MATCHES "/${sym}\.(c|cpp)$")
                set(_cut ON)
            endif()
        endforeach()
    endif()
    if(_cut)
        math(EXPR R3F_GREG_CUT "${R3F_GREG_CUT}+1")
    else()
        list(APPEND SLICE214_SRC_R3F "${src}")
    endif()
endforeach()
set(SLICE214_SOURCES ${SLICE214_SRC_R3F})
if(R3F_GREG_PLAIN)
    set(R3F_GREG_CUT ${R3F_GREG_WANT})
endif()
if(NOT R3F_GREG_CUT EQUAL R3F_GREG_WANT)
    message(STATUS "R3F: expected to cut ${R3F_GREG_WANT} plain register-TU "
                   "entries and cut ${R3F_GREG_CUT}. If slice_gate214.txt "
                   "stopped listing one of them the hostgen copy is still "
                   "added and the link will say so; if a SECOND slice started "
                   "listing one, this cut missed it and the link will say that "
                   "too")
endif()

# ---- gate seat1 (run link100 wave 7, lane SEAT1) ---------------------------
#
# port/slice_seat1.txt carries the whole derivation, including the nine rows
# the REMAIN2 census assigned this lane that do NOT survive reading. Three do.
#
# ROW 1 is a dsd LABEL SHIFT and its fix is the alternatename guard's own R1/R2
# recipe, the one lane SMALLS used for the mother penguin's tenth TU: ov031,
# ov039 and ov044 share load base 0x021111a0, and the label picker gave ov031's
# own 0x02111214 a sibling's name in the one TU that calls it. The ROM's
# relocation is unambiguous (ov031/relocs.txt:14, from:0x0211132c
# kind:arm_call to:0x02111214 module:overlay(31)), so the CALLER is recompiled
# with a per-source -DLHS=RHS and ov031's body links under its own name.
# src/_ZN19daObjKb1Billboard_c20UpdateModelTransformEv.c keeps its own ov044 caller
# (_ZN19daObjKb1Billboard_c13InitResourcesEv, reloc from:0x021112c8
# to:0x02111214 module:overlay(44)) and stays in the link.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_seat1.txt" SLICE_SEAT1_LINES)
set(SLICE_SEAT1_SOURCES "")
foreach(line IN LISTS SLICE_SEAT1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SEAT1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# RETIRED at the main->port sync (lane SYNC5). The label shift this -D worked
# around is gone on main: src/game/actors/d_a_obj_hs_billboard.cpp is the ov031
# TU that both DEFINES func_ov031_02111214 (its own @symbol, line 73) and CALLS
# it (line 49), so the caller no longer spells the callee with ov044's name and
# there is nothing left to rewrite. ov044's own body is
# _ZN19daObjKb1Billboard_c20UpdateModelTransformEv in
# src/game/actors/d_a_obj_kb1_billboard.cpp, a different TU with a different
# name, so the two no longer collide by spelling either. The slice_seat1 row
# that named the per-function file is quarantined for the same reason.
# set_source_files_properties(
#     "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN25SlideDecorationSilverStar13InitResourcesEv.cpp"
#     PROPERTIES COMPILE_DEFINITIONS "func_ov044_02111214=func_ov031_02111214")
#
# ROWS 2 AND 3 are R3F's recipe one bit over: src/func_020570c0.c and
# src/func_020570d8.c set and clear EXMEMCNT bit 11 (the NDS slot's ARM7/ARM9
# access right) and used to spell the address as the placeholder `G`, which
# resolves in this binary to the default-heap word. They now spell 0x04000204
# the way src/func_02057128.c and src/func_02057140.c do, one page down and one
# bit over, and both still byte-verify on 2004/b56 with the pool word compared
# for real. They ride the SAME R3F_GREG_PLAIN switch and the same hostgen
# discipline as R3F's three, in their OWN counter for the GREG2 reason: an
# addition must not silently perturb R3F's already-verified 3/3 accounting.
#
# They were never on a slice (port/slice_nitrofs.txt lists them under "NOT
# HERE"), so unlike R3F's three there is nothing to cut -- the generated pair is
# simply added. It goes to walk_window and walk_window_hires, beside
# R3F_GREG_GEN, because that is where their two callers ship: src/func_020570f0.c
# and src/func_0205710c.c are on port/slice_nitrofs.txt and smoke_player carries
# hal/nitrofs_face.cpp instead. Under R3F_GREG_PLAIN=ON the pair is not built at
# all and the link says so at the two call sites, which is the honest pre-fix
# arm: there is no plain slice entry that could quietly stand in for them.
set(SEAT1_GREG_SYMS
    func_020570c0          # EXMEMCNT |= 0x800, the card to the ARM7
    func_020570d8)         # EXMEMCNT &= ~0x800, the card to the ARM9
list(LENGTH SEAT1_GREG_SYMS SEAT1_GREG_WANT)
set(SEAT1_GREG_GEN "")
if(R3F_GREG_PLAIN)
    message(STATUS "SEAT1: R3F_GREG_PLAIN=ON -- the two EXMEMCNT card-bit TUs "
                   "are NOT built. This is the PRE-FIX arm and the link names "
                   "func_020570c0/func_020570d8 at their two call sites in "
                   "src/func_020570f0.c and src/func_0205710c.c.")
else()
    message(STATUS "SEAT1: R3F_GREG_PLAIN=OFF -- the two EXMEMCNT card-bit TUs "
                   "route through hostgen (shipped arm).")
    foreach(sym IN LISTS SEAT1_GREG_SYMS)
        set(sym_in "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        if(NOT EXISTS "${sym_in}")
            set(sym_in "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
        endif()
        set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
        add_custom_command(OUTPUT "${sym_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
            DEPENDS "${sym_in}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${sym}")
        list(APPEND SEAT1_GREG_GEN "${sym_out}")
    endforeach()
endif()
list(LENGTH SEAT1_GREG_GEN SEAT1_GREG_HAVE)
if(NOT R3F_GREG_PLAIN AND NOT SEAT1_GREG_HAVE EQUAL SEAT1_GREG_WANT)
    message(FATAL_ERROR "SEAT1: expected ${SEAT1_GREG_WANT} hostgen'd register "
                        "TUs and built ${SEAT1_GREG_HAVE}. A missing src file "
                        "is the only way this happens.")
endif()

# ---- gate 2ipc: the PXI layer (the ARM9<->ARM7 link) -----------------------
#
# port/docs/mmio-inventory.md counted eight IPC registers and zero modelled,
# and that zero is what kept the ROM's own inter-processor layer out of the
# link: src/func_0205bad8.c's IPCSYNC handshake never converged and four
# matched channel initialisers spun forever on an ARM7 readiness word nothing
# ever wrote. port/ntr/ipc.cpp is the register model (added to the three ntr
# libraries above, since ntr/io.cpp dispatches into it) and
# port/hal/boot2_ipc.cpp is the host ARM7 and the PXI bss. Neither is
# decompiled code. The nine matched TUs this makes linkable, the ROM edges
# that reach them and the four channels deliberately left out are all in
# port/slice_gate2ipc.txt.
#
# THREE OF THEM MUST BE HOSTGEN'D. func_0205bad8 reaches IPCSYNC through a
# pointer bound to a literal, so built plain its reads come off the mapped
# latch and the ARM7's nibble is always zero. IRQ::IPCRxFifoNotEmptyHandler
# reads IPCFIFORECV at 0x04100000, which is outside every region ntr/io.cpp
# maps -- built plain that is an access violation, not a stale read.
#
# IPCSend IS THE THIRD, and until run link100 lane IPCSEND it was the one that
# was missing. Its `*(volatile unsigned int *)0x4000188 = cmd.raw` is exactly
# hostgen's MMIO_DEREF shape, and built plain it LATCHED IN THE MAPPED WINDOW:
# this port had never made an ARM9->ARM7 send at all, which is why every
# [ipc:rom-boot] line in the tree read send=0, and why lane BOOT2 had to back
# func_020196cc out again (it hung at func_0205ff08 + 0 with data_020a8114 == 1,
# waiting for a reply to a request that was never delivered).
# ITS PLAIN LINE IS COMMENTED OUT OF port/slice_gate10.txt, and the two lists go
# to the same three targets, so the LINK SET does not change -- only the route.
# NOTHING ELSE ABOUT THE FUNCTION CHANGES. Its two IPCFIFOCNT reads used to come
# off the window ntr::ipc_publish keeps truthful and now come from
# ntr/ipc.cpp's fifocnt_value() directly, which is the same number by
# construction; its error arm's `|= 0xc000` stops being a store into a latch and
# becomes the acknowledge ipc_reg_write documents; and with SM64DS_IPC_MODEL=0
# ipc_reg_read/ipc_reg_write both decline, so io.cpp falls through to the same
# mapped window a plain build used and the negative control is untouched.
set(GATE2IPC_SYMS func_0205bad8 _ZN3IRQ24IPCRxFifoNotEmptyHandlerEv IPCSend)
set(GATE2IPC_GEN "")
foreach(sym IN LISTS GATE2IPC_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE2IPC_GEN "${sym_out}")
endforeach()
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate2ipc.txt" SLICE2IPC_LINES)
set(SLICE2IPC_SOURCES "")
foreach(line IN LISTS SLICE2IPC_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE2IPC_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# ---- gate 213: the last three trapped _ZTV5Stage slots ----------------------
# Five matched TUs behind three ROM vtable words the port filled with a named
# abort: slot 3 (0x020921cc -> Stage::CleanupResources, with its two leaves
# Sound::ResetPlayerVoiceGroup and Message::ResetAllGlobals) and slots 16/17
# (0x02092200/0x02092204 -> ~Stage D2 and D0). The seat, the slot-3 face and
# the SM64DS_STAGE_SEAT_PROBE control are in hal/stage_bridges.cpp. None of the
# three is dispatched by the port today -- the cleanup Process only walks
# actors marked for destruction and nothing deletes the Stage -- so this is a
# reference edge and not a frame change. See port/slice_gate213.txt.
# D2 and D0 are also on slice_w8a, which only walk_window carries; listing them
# here is what gives smoke_player and walk_window_hires the same TUs, and CMake
# de-duplicates the identical path on walk_window.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate213.txt" SLICE213_LINES)
set(SLICE213_SOURCES "")
foreach(line IN LISTS SLICE213_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE213_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# ---- link100 SCENE ----
# ---- gate 218: the two ARM9-RESIDENT SCENE CLASSES --------------------------
# dScBoot_c (actor id 0, vtable 0x02091528, SpawnInfo 0x020914a8, factory
# 0x02023624) and dScMB_c (id 360, vtable 0x020943c4, SpawnInfo 0x0209435c,
# factory 0x020352b4) -- the ROM's two boot scenes, the fork
# Scene::PrepareToSpawnBoot picks between. Both are arm9-resident, so unlike
# every scene the port had seated before them there is no overlay to mount:
# hal/scene_link100_boot.cpp and hal/scene_link100_mb.cpp host their vtables
# and SpawnInfo records as arrays under the ROM's own data names, and the
# seven .data blobs their InitResources bodies decompress come from
# port/tools/romdata.py's NAMED list. The slice is the LINK closure, measured
# with port/tools/closure.py against the pre-seat walk_window.map and iterated
# to a fixpoint rather than taken from the ROM's own call graph -- the two
# differ by a factor of several, because the port's host bodies already own
# most of the ROM's edges. port/slice_gate218.txt carries the derivation.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate218.txt" SLICE218_LINES)
set(SLICE218_SOURCES "")
foreach(line IN LISTS SLICE218_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE218_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# ---- end link100 SCENE ----

# ---- THE GAPLESS PER-ENTRY CORRECTION: the five G-adding OAM routers ---------
#
# Read THE ROUTER HOOK at the foot of port/hal/screen_gap.cpp before this. The
# gapless minigame mod zeroes the framework's screen-gap word, which takes G out
# of every submission these five bodies make to the top engine, and the fix has
# to put it back for THOSE submissions and for no others -- the score rows and
# the top screen's artwork are placed in screen space and were never displaced.
# Nothing in the finished OAM tells the two apart, so the routed set is recorded
# at the call, and this is the only place a call can be got at without editing
# src/.
#
# TWO RENAMES PER TU, and both are the R-series remedy this file already uses a
# dozen times over:
#
#   <router>=<router>__rom   the TU defines its body under a private name, and
#                            hal/screen_gap.cpp defines the real name as a
#                            wrapper that captures the world row and calls it.
#                            Every caller in the program links the wrapper.
#   OAM::Render=port_...     the TU declares its OAM::Render overload extern "C"
#                            by mangled name, so renaming that name redirects
#                            THAT TU's calls -- and only that TU's -- to the
#                            shim in hal/screen_gap.cpp. The overload's own
#                            definition, and every other caller of it in the
#                            program, is untouched.
#
# EACH FILE IS ON EXACTLY ONE SLICE and those slices ride smoke_player,
# walk_window and walk_window_hires, all three of which link hal/screen_gap.cpp,
# so the shims and wrappers are present wherever the renamed TUs are. Checked
# rather than assumed: the five appear once each across every port/slice_*.txt.
#
# WHICH OVERLOAD EACH TU CALLS, off the TU's own declaration:
#   func_ov004_020aff38   ..._Fix12IiEi        8 args   -> port_oam_render_routed_8
#   func_ov004_020afdd0   ..._Fix12IiES3_ii   10 args   -> port_oam_render_routed_10
#   func_ov004_020b023c   ...P9Matrix2x2       7 args   -> port_oam_render_routed_mtx
#   func_ov004_020b0380   ...P9Matrix2x2       7 args   -> port_oam_render_routed_mtx
#   RenderOamBothScreens  ...P9Matrix2x2       7 args   -> port_oam_render_routed_mtx
# func_ov004_020afdd0 also calls OAM::RenderSub for the bottom engine, which is
# a different symbol, is not renamed, and needs no correction: the bottom
# engine's y is the world row itself in every arm.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov004_020aff38.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_ov004_020aff38=func_ov004_020aff38__rom;_ZN3OAM6RenderEbP7OamAttriiii5Fix12IiEi=port_oam_render_routed_8")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov004_020afdd0.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_ov004_020afdd0=func_ov004_020afdd0__rom;_ZN3OAM6RenderEbP7OamAttriiii5Fix12IiES3_ii=port_oam_render_routed_10")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov004_020b023c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_ov004_020b023c=func_ov004_020b023c__rom;_ZN3OAM6RenderEbP7OamAttriiiiP9Matrix2x2=port_oam_render_routed_mtx")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov004_020b0380.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_ov004_020b0380=func_ov004_020b0380__rom;_ZN3OAM6RenderEbP7OamAttriiiiP9Matrix2x2=port_oam_render_routed_mtx")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/RenderOamBothScreens.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "RenderOamBothScreens=RenderOamBothScreens__rom;_ZN3OAM6RenderEbP7OamAttriiiiP9Matrix2x2=port_oam_render_routed_mtx")

# Lane w8-shadows (run linkw): the SHADOWS bucket. One matched TU by name --
# TextureTransformer::Prepare, whose header declares it STATIC, which is what
# makes the matched body callable through the C-name face that used to
# duplicate it. The lane's other two seats need no line here: they were already
# in slice_gate16.txt and only wanted a reference edge. See slice_w8shadows.txt
# for the full triage of all twelve shadows and the derivation of the one that
# is deliberately still open.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w8shadows.txt" SLICE_W8SHADOWS_LINES)
set(SLICE_W8SHADOWS_SOURCES "")
foreach(line IN LISTS SLICE_W8SHADOWS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W8SHADOWS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 188: Jolly Roger Bay's six MOVER classes' matched lifecycle closure. The
# host copies (the three slot-5 renders + Unagi's PMF dispatch/Behavior) are
# unmatched/{Jrb_Renders,Unagi_StateDispatch}.cpp, added beside the slice at
# each target. The body-segment near-miss copy that used to stand beside them,
# unmatched/Unagi_BodyChain.cpp, is RETIRED (run link100 wave 14, lane
# SHADOWS3): its own banner said it stood in "until the decomp lands a
# byte-match", and PR #2289 (d01c61f09) landed it, so src/func_ov016_02111c40.c
# is on port/slice_shadows3.txt in its place.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate188.txt" SLICE188_LINES)
set(SLICE188_SOURCES "")
foreach(line IN LISTS SLICE188_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE188_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 190: Cool Cool Mountain's CCM slice A -- ICE_SHEET (295) and
# POWER_STAR_CREATE (355), ov018's own overlay, plus ONE_UP_LOGO (331) on the
# already-mounted ov002. The fill is appended to hal/actor_classes_ccm.cpp
# (already carries gate 142's IceSlideManager).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate190.txt" SLICE190_LINES)
set(SLICE190_SOURCES "")
foreach(line IN LISTS SLICE190_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE190_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 191: SKI_LIFT (63) + MOTHER_PENGUIN (257), ov018, extending the
# gate-190 ov018 per-symbol mount (port/ov018_syms.txt). The fill is
# appended to hal/actor_classes_ccm.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate191.txt" SLICE191_LINES)
set(SLICE191_SOURCES "")
foreach(line IN LISTS SLICE191_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE191_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate mpg (run link100 lane MPG): MOTHER_PENGUIN's own state machine -- the
# eleven ov018 TUs behind the pointer-to-member table gate 191 seated ONE
# record of. The table is three 16-byte {enter, tick} entries, not six cells,
# and the universe is closed by the eight r1 values the ROM sets before its
# eight calls to func_ov018_021123d0. port/slice_mpg.txt carries the
# derivation and the per-file notes; the seat, the raw-__cdecl face ruling
# (both dispatchers tail-jump under MSVC) and the three port-side defects
# this gate had to fix are in port/unmatched/MotherPenguin_AfterClsnSeat.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_mpg.txt" SLICE_MPG_LINES)
set(SLICE_MPG_SOURCES "")
foreach(line IN LISTS SLICE_MPG_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_MPG_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# src/game/actors/d_a_pg_mthr.cpp IS SLICED NOW, on port/slice_smalls.txt (gate
# smalls, below). It was not when this gate landed: its symbol was spoken for by
# gate 188's alias in unmatched/Jrb_Aliases.cpp
# (_func_ov018_02111bf0 -> _func_ov016_02111bf0), which three LINKED ov016
# UNAGI bodies depend on -- they spell their own module's 0x02111bf0 with the
# ov018 prefix, and ov016/ov018 share load base 0x021111a0. Defining the LHS
# DEFEATED that alias and rerouted Unagi into the mother penguin's collision
# pass; alternatename_guard.py failed this gate's first link on exactly that
# (LHS 0001:00188350 vs RHS 0001:00148d00), so the body was host copied under a
# port name in unmatched/MotherPenguin_ClsnPass.cpp and this gate's two callers
# were renamed onto it. Gate smalls applied the guard's own R1/R2 recipe
# instead -- the dead alternatename deleted, the three ov016 callers renamed
# per source onto func_ov016_02111bf0 -- so the ov018 name is free, both
# callers below reach the ROM's own body under its own name, and the host copy
# is retired. The rename that stood on func_ov018_02112234.c is gone with it.
# The literal at 0x02112230 is 0x02113bf0 and carries NO relocation row, so
# it is ov018's OWN bss -- the Animation SharedFilePtr __sinit_ov018_02112c80
# constructs with file id 0x406, which func_ov018_021122ec already reads as
# data_ov018_02113bf0[1]. The source's data_ov027 spelling is the
# #1308-#1310 cross-overlay family (ov018/ov022/ov027/ov036/ov056 share load
# base 0x021111a0 and are never co-resident) and the port DEFINES
# data_ov027_02113bf0 in ov027's own mount, so without this rename the link
# succeeds against the wrong storage. Renamed, not edited, the way
# _ZN13RollingLogLll16CleanupResourcesEv's func_021270dc is: the declaration
# is local to this TU and no header here declares either name, so the
# rewrite cannot collide.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_pg_mthr.cpp"
    PROPERTIES COMPILE_DEFINITIONS "data_ov027_02113bf0=data_ov018_02113bf0")
# RETIRED at the main -> port sync, lane FACES1. The rename that used to sit
# here read:
#
#     "func_ov018_021123d0=port_mpg_set_state_zero"
#
# and it existed because the legacy one-function TU DECLARED
# func_ov018_021123d0 with ONE parameter and called it with one, while the ROM
# body takes two (the ROM sets r1 = 0 at 0x02111ef8, a `mov r1,#0` the source
# spelled as the neighbouring `*(int*)(s+0x374) = 0`, which is why it still
# byte-matched on ARM). On x86 the missing second argument was a stack slot the
# caller never wrote: the callee read [ebp+0Ch], shifted it left by four and
# parked a wild pointer in self+0x370. port_mpg_set_state_zero, in
# unmatched/MotherPenguin_AfterClsnSeat.cpp, supplied the ROM's own 0.
#
# TWO THINGS CHANGED AT THE SYNC, and together they turn the rename from a fix
# into a defect:
#
#   1. main's consolidated src/game/actors/d_a_pg_mthr.cpp now DEFINES
#      func_ov018_021123d0 (line 297, `void func_ov018_021123d0(char *self,
#      int i)`), so a -D rename of that identifier renames the DEFINITION as
#      well as the calls, and the TU emitted a second port_mpg_set_state_zero
#      beside the seat file's. That was one of walk_window's 17 remaining
#      LNK2005 rows (runs/link100/out/ALIAS2/host_abi_conflicts.txt, the row
#      marked "THIS ONE IS DIFFERENT and is the cheapest of the seventeen").
#   2. every call site in that TU now spells BOTH arguments -- lines 206, 400,
#      445, 472, 504, 626, 691 and 711, each passing an explicit 0, 1 or 2 --
#      so there is nothing left for the shim to supply.
#
# So the rename is deleted rather than re-scoped: a -D cannot tell a definition
# from a call, and there is no call left that needs it. The seat file's
# port_mpg_set_state_zero stays defined and unreferenced, which /OPT:REF drops.
#
# AND THE ROW ABOVE COMES BACK. set_source_files_properties REPLACES a property
# rather than appending to it, and both blocks named the same file, so the
# data_ov027_02113bf0 -> data_ov018_02113bf0 rename immediately above was being
# overwritten by this one and had not been applied since the sync folded the
# two TUs together. Deleting this block restores it.

# Gate mpg2 (run link100 lane MPG2): dScGameOver_c, scene id 8 -- ov003's
# third and last scene class. port/slice_mpg2.txt carries the derivation and
# the per-file notes; the seat, the eighteen-word transcription and the
# table-word proof are in port/hal/scene_boot.cpp beside dScStarSel_c's.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_mpg2.txt" SLICE_MPG2_LINES)
set(SLICE_MPG2_SOURCES "")
foreach(line IN LISTS SLICE_MPG2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_MPG2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# THE TWO dtor TUs SPELL THEIR VPTR WRITES AS PER-TU PLACEHOLDERS, and four of
# the seven names already resolve to host storage at an address the ROM never
# stores. Renamed rather than edited, the way every gate above does it: the
# declarations are local to each TU (include/decl_common.h declares them, and
# nothing else in either TU names the targets), so the rewrite cannot collide.
#
# The values are read out of each body's OWN literal pool in
# extracted/overlays/overlay_0003.bin, not inferred from the sibling class:
#   _ZN13dScGameOver_cD1Ev (D2)  0x020b05b0/b4/b8 = 020b179c, 02092680, 0208e4b8
#   _ZN13dScGameOver_cD0Ev (D0)  0x020b05fc/00/04/08 = the same three, then
#                             020a0eac (the game heap, Memory::Deallocate)
#
# WHY THIS MATTERS AND IS NOT BELT AND BRACES: _ZTV7dBase_c is a LIVE
# definition in hal/sub_actors.cpp (the trap-filled array) and VT0/VT1/VT2 are
# live shared stand-ins in hal/actor_vtables.cpp and hal/auto_bss.cpp. Without
# the renames the link SUCCEEDS and both dtors write the wrong word.
# _ZTV8dScene_c and VT1 go through a fresh name of this gate's own,
# port_go_vt_scene, which hal/scene_boot.cpp /alternatename's onto _ZTV8dScene_c;
# a direct rename onto _ZTV8dScene_c is a C2371, because include/decl_common.h
# declares it void*[] at :2982 and the placeholders int[] at :412/:790.
# G0 is renamed too even though hal/cxx_aliases.cpp already binds bare _G0 to
# _data_020a0eac: one statement per ROM word reads better here than a rule
# that depends on which other gate's alias happens to be live.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names dScGameOver_c.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV13dScGameOver_c=data_ov003_020b179c  --  dead, the TU does not spell _ZTV13dScGameOver_c
#   _ZTV7dBase_c=data_0208e4b8  --  dead, the TU does not spell _ZTV7dBase_c
#   _ZTV8dScene_c=port_go_vt_scene  --  dead, the TU does not spell _ZTV8dScene_c
# Deleted rather than merged. The surviving row is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/dScGameOver_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=data_ov003_020b179c;VT1=port_go_vt_scene;VT2=data_0208e4b8;G0=data_020a0eac")

# Gate title (run link100 wave 14, lane SEAT14D): dScTitle_c, scene id 2 --
# ov003's LAST unseated scene class, the one port/slice_scene1.txt named as
# still outstanding after the mpg2 block above took the game over.
# port/slice_title.txt carries the derivation and the per-file notes; the seat,
# the eighteen-word transcription and the registry row are in
# port/hal/scene_boot.cpp beside dScStarSel_c's and dScGameOver_c's, and the
# seven vtable faces are in port/hal/title_vtable_seat14d.cpp.
#
# NO set_source_files_properties ROW FOLLOWS THIS ONE, and that is measured
# rather than an oversight. The mpg2 block above needs per-TU renames because
# src/actors/dScGameOver_c.cpp SPELLS VT0/VT1/VT2/G0 in source text and four of
# those names already resolve to host storage at an address the ROM never
# stores. src/_ZN10dScTitle_cD1Ev.cpp spells none of them: its destructor body
# is empty and the three vptr stores come out of the compiler. The placeholder
# trio port/slice_scene1.txt records for this class (_ZTV10dScTitle_c /
# _ZTV8dScene_c / _ZTV7dBase_c) is a mwcc-side spelling with nothing for this
# host build to rename, and a row here would be dead the way the one lane CDEFS
# deleted from the mpg2 block was dead.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_title.txt" SLICE_TITLE_LINES)
set(SLICE_TITLE_SOURCES "")
foreach(line IN LISTS SLICE_TITLE_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_TITLE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate smalls (run link100 lane SMALLS): two leftovers earlier lanes measured,
# wrote down and did not take. port/slice_smalls.txt carries the derivation of
# each and the per-file notes.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_smalls.txt" SLICE_SMALLS_LINES)
set(SLICE_SMALLS_SOURCES "")
foreach(line IN LISTS SLICE_SMALLS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SMALLS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# RUNG 1, the guard's own R1/R2 recipe (port/tools/alternatename_guard.py's
# header, the wave-5 review): src/game/actors/d_a_pg_mthr.cpp defines the LHS of gate
# 188's /alternatename:_func_ov018_02111bf0=_func_ov016_02111bf0, so the alias
# is DELETED from unmatched/Jrb_Aliases.cpp and the three TUs that referenced
# the LHS are recompiled with a per-source -DLHS=RHS. All three are ov016 UNAGI
# state bodies that spell their own module's 0x02111bf0 with the ov018 prefix
# (ov016 and ov018 share load base 0x021111a0), all three are linked through
# slice_gate188.txt, and each names the function exactly once:
#   src/func_ov016_02111534.c:14, its own local `extern void (void*, void*)`
#   src/func_ov016_02111758.cpp:39 and src/func_ov016_021118b4.cpp:33, both
#   through include/decl_common.h:1551, which is inside its extern "C" block --
#   so the renamed declaration keeps C linkage and resolves to the ov016 body.
# Nothing else in the tree references the ov018 spelling: the declaration in
# unmatched/Unagi_StateDispatch.cpp:103 is never called, and ov018's own two
# callers (func_ov018_02112234, func_ov018_02111e28) now reach the real body
# under its own name, which is what the ROM's relocs say at both sites.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov016_02111534.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov016_02111758.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov016_021118b4.cpp"
    PROPERTIES COMPILE_DEFINITIONS "func_ov018_02111bf0=func_ov016_02111bf0")
# src/game/actors/d_a_pg_mthr.cpp is a //cpp-marked .c: it opens a top-level
# `extern "C" {` block, which is not C. Same LANGUAGE CXX row every other
# //cpp-marked .c on a slice gets.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_pg_mthr.cpp"
    PROPERTIES LANGUAGE CXX)

# Gate shadows (run link100 lane SHADOWS): the two rows of the 29-row shadow
# queue whose ROM body can take the seat once the seam its host copy was
# written for becomes a BRIDGE. Both are the dropped-second-argument state
# setter; both call sites read `mov r1, #0` in the overlay image, quoted
# instruction by instruction in port/slice_shadows.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_shadows.txt" SLICE_SHADOWS_LINES)
set(SLICE_SHADOWS_SOURCES "")
foreach(line IN LISTS SLICE_SHADOWS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SHADOWS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# The per-source rename that turns each dropped-argument call into a call of
# the zero-index forwarder in hal/method_faces.cpp. One name per TU, and in
# both TUs the rename moves the DECLARATION with the call:
#   BabyPenguin's declaration is the src TU's own local
#     `extern "C" void func_ov072_02121d50(void *c);` -- decl_common.h has no
#     declaration of that name at all, so nothing else is touched;
#   CrazedCrate's is include/decl_common.h:2857, inside that header's extern
#     "C" block, and only this TU compiles with the rename, so every other
#     caller of the setter keeps the ROM name and the ROM body.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11BabyPenguin13InitResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_ov072_02121d50=port_ov072_bp_state_i0")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11CrazedCrate13InitResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_ov080_0212513c=port_ov080_cc_state_i0")
# Rung 2, the other direction: the matched TU is right about the ROM (r0 and r1
# only at 0x0212ec44, r2 written after the branch) and the port's own three-
# parameter Prepare wrapper is what wants a third argument. So the rename points
# at a forwarder that supplies it, and both of this TU's Prepare call sites move
# with its own local declaration.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN9LakituBro13InitResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZN15TextureSequence7PrepareER8BMD_FileR8BTP_File=port_texseq_prepare_r1")

# Gate shadows3 (run link100 wave 14, lane SHADOWS3): the rows of the shadow
# queue whose host stand-in was written because no matched TU existed at that
# ROM address, and where the main-to-port sync has since landed one. Each row's
# evidence -- the host file's own retirement condition, the commit that banked
# the TU, and the map check on every external it declares -- is in
# port/slice_shadows3.txt. The host bodies they replace are retired in the same
# commit; none of these rows is a vtable fill, so no seat changes what any live
# object dispatches.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_shadows3.txt" SLICE_SHADOWS3_LINES)
set(SLICE_SHADOWS3_SOURCES "")
foreach(line IN LISTS SLICE_SHADOWS3_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SHADOWS3_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 192: the ov081 trio -- ICE_BLOCK (18), MR_BLIZZARD (223), SPINDRIFT
# (312). Fresh per-symbol ov081 mount (port/ov081_syms.txt). The fill is
# hal/actor_classes_ov081.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate192.txt" SLICE192_LINES)
set(SLICE192_SOURCES "")
foreach(line IN LISTS SLICE192_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE192_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Run rel0215 wave 3, lane w3-b: SNOWBALL (224) + MONEYBAG (261), the two
# classes gate 192 left unregistered when it mounted ov081 for the trio. NOT a
# second mount -- ov081 is already on PORT_ACTOR_OVERLAYS above and both fills
# are appended to the same hal/actor_classes_ov081.cpp. The only mount change
# is that _ZTV8Snowball and _ZTV8Moneybag leave port/ov081_syms.txt (a
# registered class's table has to be the host array its factory stores) and
# the two SpawnInfo records ahead of them are pinned :0x24.
#
# TWO TUs ARE HOST-COPIED and must NOT appear in the slice, or two definitions
# of the same symbol reach the link (LNK2005):
#   src/actors/daGmch_c.cpp      the auto-emitted-member-dtor .cpp form; slot
#                                 16 is a thunk in hal/actor_classes_ov081.cpp
#   src/actors/daGmch_c.cpp the ModelAnim slot-5 collision; the body is
#                                 in port/unmatched/ModelAnim_Renders.cpp
# The guard below is the slice_ov096 shape: a later slice edit that adds
# either line fails at CONFIGURE with the reason rather than at link with a
# mangled symbol name.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w3b.txt" SLICE_W3B_LINES)
set(SLICE_W3B_SOURCES "")
foreach(line IN LISTS SLICE_W3B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W3B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# R10, run rel0215 wave 3 (lane w3-b): THE R9 PREDICATE IS TOO NARROW BY ONE
# SHAPE, and this lane found the gap by CRASHING rather than by reading.
#
# R9 above defines the pointer-to-member width class as "a pointer-to-member of
# an INCOMPLETE class AND a NONZERO offset applied to it", and rules the pp[0]
# siblings "correct BY LUCK and deliberately NOT listed here". That reading has
# an unstated premise: that MSVC's default representation is the FOUR-BYTE one,
# so an index-0 read lands on the function word. It is four bytes only when the
# class is DEFINED SOMEWHERE IN THE SAME TU, which is true of every one of the
# twenty-one TUs R9 scanned -- they all spell
#     struct C; typedef void (C::*PMF)(); struct C { char pad[N]; PMF *pp; };
# and MSVC picks the representation from C's real (single-inheritance) layout.
#
# src/_ZN8Snowball8BehaviorEv.cpp NEVER DEFINES ITS CLASS. It spells
#     struct Klass; typedef void (Klass::*PMF)();
#     struct M { char pad[8]; PMF pmf; };
#     M *m = *(M **)&unk_378;  if (m->pmf != 0) (this->*(m->pmf))();
# and `Klass` is never completed, so MSVC falls back to the MOST GENERAL
# representation -- SIXTEEN bytes, {fn, delta, vbptr offset, vbindex}. The
# index is still zero and it still breaks, because the width decides where the
# FIELDS are, not just the stride. MEASURED, in the obj and then in a crash:
#
#   without the option, the FULL measured sequence (the out-of-bounds reads
#   are CONDITIONAL; the fault fires because the garbage "vbindex" word past
#   the cell is nonzero, which routes the guarded virtual path):
#                         mov edx,[esi+378h]     ; the cell
#                         mov edi,[edx+8]        ; fn        -- correct
#                         push ebx
#                         mov ebx,[edx+14h]      ; "vbindex" -- past the cell
#                         test ebx,ebx           ; guard: zero would take the
#                         jne .virt              ;   non-virtual path and live
#                         mov eax,[edx+0Ch]      ; (not taken here)
#                         jmp .join
#                  .virt: mov ecx,[edx+10h]      ; "vbptr"   -- past the cell
#                         mov eax,[ecx+esi]
#                         mov eax,[eax+ebx]      <- FAULT, +0x37
#                         add eax,ecx
#                         add eax,[edx+0Ch]
#   The ROM cell is SIXTEEN bytes TOTAL (enter {fn,delta} then tick {fn,delta}),
#   so [edx+10h] and [edx+14h] are past the end of the record entirely.
#   FAULT c0000005 at ?Behavior@Snowball@@QAEHXZ+0x37 accessing 78531c75,
#   walker node id 0xe0, frame 1 of
#   SM64DS_LEVEL=19 SM64DS_SPAWN_ACTOR=224 SM64DS_FAULTS_FATAL=1.
#
#   with /vmg /vmm        sizeof(PMF) is 8, so `m->pmf` is {[m+8], [m+0Ch]} --
#                         exactly the ROM's tick record -- and the call adds
#                         delta (zero on both of Snowball's records) to `this`
#                         and jumps to fn. The ROM's own dispatch.
#
# THE OTHER THREE PMF SITES IN THIS SEAT WERE DISASSEMBLED TOO rather than
# assumed, and all three are right as they stand:
#   func_ov081_021261d4  Snowball's installer -- 4-byte PMF (its `struct C` IS
#                        defined in the TU), reads [pp] = the enter fn, and
#                        tail-JUMPS, so the host body reads its receiver off
#                        the reused cdecl frame. R9's index-0 case, genuinely.
#   _ZN8daGmch_c14CallStateEnterEv  Moneybag's enter dispatcher -- same shape, same
#                        4-byte read of [pp], same tail jump.
#   _ZN8daGmch_c15CallStateUpdateEv  Moneybag's tick dispatcher -- ALREADY on R9's list
#                        above; with the option it reads [pp+0Ch] as delta and
#                        [pp+8] as fn, which is the tick record. Confirmed in
#                        the obj, not taken on trust.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN8Snowball8BehaviorEv.cpp"
    PROPERTIES COMPILE_OPTIONS "/vmg;/vmm")

# R11, run rel0215 wave 3 (lane w3-d, ov070 FlyGuy): THE PMF CALLING
# CONVENTION IS A PROPERTY OF THE SITE, NOT THE CLASS. Before seating raw
# cdecl bodies into a pointer-to-member table, disassemble EVERY live
# dispatch site from the build's own objects. A site MSVC compiles as a
# one-call forwarder ends `pop ebp / jmp eax` and reuses the caller's cdecl
# frame, so the receiver is still at [esp+4] and a raw body is correct. A
# site that does work after the dispatch cannot be a forwarder: it emits
# `call eax` with the receiver in ECX and NOTHING PUSHED, and needs a
# __fastcall thunk (push ecx / call / add esp,4 / ret). The two sets can be
# disjoint halves of the SAME class's cells -- FlyGuy's enter halves are
# tail-jumped and its tick halves are not.
#
# THIS FAILURE IS SILENT. With the wrong convention live,
# func_ov070_0211fa80 wrote *(int*)(c+0x3dc)=0 through a stray pointer
# every FlyGuy frame while the byte gate, the linkage count, all five ABI
# checkers, the guards, the census and rc stayed green. The only instrument
# that caught it was a before/after state trace (level 19 player y: 720.1
# flat with the raw seat vs 800-820 oscillating with the thunks). Enumerate
# sites by disassembly, never by grepping for a source shape -- FlyGuy's
# Behavior reads a Holder{char pad[8]; PMF fn;} at +8, which R9's
# `c->pp + 1` grep could not see.
#
# THE MAP GIVES A FAST FIRST READ (run rel0215, lanes prop16/prop17): grep
# walk_window.map for the DISPATCHER symbol and read the .obj column. A
# dispatcher from a src/*.cpp.obj is MSVC's own lowering of a real
# member-pointer call: receiver in ECX, nothing pushed -- seat a
# __fastcall(self, dummy) thunk. A dispatcher from a port/unmatched/*.obj
# host copy has usually rewritten the call as void(*)(void*): plain cdecl
# indirect call, receiver on the stack -- seat the bare cdecl body, and a
# thunk would MIS-RECEIVE (ov074's state 0 puts state_index*16 = 0 in ECX,
# so the thunked call hands the body a null this). The .obj column decides
# the DEFAULT; the per-site disassembly above remains the confirmation,
# because one class's halves can split (FlyGuy) and a forwarder can hide in
# a src obj. Fastcall iff no push of the receiver before the call.

# R12, run rel0215 (lane tagfix): THE PREDICATE MISSES A RUNTIME INDEX, AND
# THE WIDTH IT LANDS ON IS THE SIXTEEN-BYTE ONE, MEASURED.
#
# R9 finds its twenty-one TUs by scanning src/ for "a pointer-to-member of an
# INCOMPLETE class AND a NONZERO offset applied to it", and every one of those
# offsets is a LITERAL -- `pp + 1`, `pp[2]`, a `+ 8` in a guard. So the sweep
# is blind to a site whose index is a RUNTIME VALUE, which is exactly the shape
# of src/_ZN10BrickBlock8BehaviorEv.cpp:
#
#     struct C; typedef void (C::*PMF)();
#     extern "C" PMF data_ov002_0210dd30[];
#     ...
#     int idx = unk_0d7;                     <- 0..3, written by InitResources
#     (((C*)((char*)this))->*data_ov002_0210dd30[idx])();
#
# Nothing in that source spells an offset at all. The index comes from the
# actor's own id at InitResources time (0x141 -> 0, 0x142 -> 1, 0x143 -> 2,
# 0x144 -> 3), so three of the four live ids stride, and a grep cannot see it.
#
# MEASURED IN THIS LANE'S OWN BASE OBJECT, not derived. R9 says MSVC's default
# is FOUR bytes and R10 says it is SIXTEEN when the class is never completed.
# This TU does complete `struct C` -- but only AFTER the array of pointers to
# members of it has been declared -- and MSVC takes the general form:
#
#   base, no option        movzx eax,byte ptr [edi+0D7h]   ; idx
#                          shl   eax,4                     ; idx * SIXTEEN
#                          mov   ecx,_data_ov002_0210dd30[eax+4]
#                          mov   eax,_data_ov002_0210dd30[eax]
#                          add   ecx,edi
#                          call  eax
#
# `shl eax,4` is the whole defect. data_ov002_0210dd30 is THIRTY-TWO bytes of
# bss (0x0210dd30..0x0210dd50, four 8-byte records) and the four indices read:
#
#     idx 0  ->  +0   record 0, correct by luck
#     idx 1  ->  +16  record 2's function word -- the WRONG handler
#     idx 2  ->  +32  PAST THE ARRAY, into whatever the linker put next
#     idx 3  ->  +48  further past
#
# and idx 0 and 1 then CALL what they read, which until this lane's seat is a
# raw DS text address (0x020b429c / 0x020b41f8), mapped-but-NX on the host.
# There is no benign index: every one of the four ids is a fault.
#
# With /vmg /vmm sizeof(PMF) is 8. No shift is emitted at all -- the multiply
# folds into the scaled index, so the `shl` disappears and the two reads become
#                          mov ecx,_data_ov002_0210dd30[eax*8+4]
#                          mov eax,_data_ov002_0210dd30[eax*8]
# which is the record's own {fn, delta} -- the ROM's dispatch exactly. Both
# halves of the fix are needed and neither is sufficient alone: the width puts
# the read on the right record, and hal/actor_classes_bob_world.cpp's
# port_itemtag_states_seat() puts a HOST address in that record. The seat
# verifies the four ROM words before rewriting and aborts on anything else.
#
# THE CALL IS NOT A FORWARDER, so R11 applies and the four bodies cannot be
# seated raw. `call eax` with the receiver in ECX and NOTHING PUSHED -- the
# TU does real work after the dispatch (MarkForDestruction, then `return 1`),
# which is R11's own test for a frame that cannot be tail-jumped. The four
# matched bodies are flat cdecl C names taking `char *`, so the seat points
# the table at four __fastcall thunks rather than at the bodies themselves.
# Read off this lane's build, before and after, in the lane's evidence.
#
# PER-SOURCE, NEVER GLOBAL, R9's rule unchanged. This TU includes only
# BrickBlock.h (which declares no `::*`) and its own four-line struct, so
# nothing crosses a header boundary and no type in it changes size.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10BrickBlock8BehaviorEv.cpp"
    PROPERTIES COMPILE_OPTIONS "/vmg;/vmm")

# Run rel0215, lane tagfix: the four item-tag handlers the gate-33 dispatcher
# has always indexed and nothing ever defined, plus the position helper all
# four call. Full derivation, the dup screen and the match gate are in the
# head of slice_tagfix.txt. data_ov002_020ff090 joins port/ov002_syms.txt in
# the same commit because _ZN10BrickBlock11GetSpawnPosER7Vector3RS_ indexes it.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_tagfix.txt" SLICE_TAGFIX_LINES)
set(SLICE_TAGFIX_SOURCES "")
foreach(line IN LISTS SLICE_TAGFIX_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_TAGFIX_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run rel0215 wave 3, lane w3-b: the ONE fall-off-the-end body in this seat.
# src/actors/daGmch_c.cpp is declared `int` and never returns. mwccarm
# accepts that; MSVC refuses the TU with `error C4716: must return a value`.
# hostgen's FALLS_OFF_RETURN table appends the return, so the TU stays in the
# linkage count instead of costing one -- the route lane w5-c built for
# func_ov070_0211f0a4 (OV70GEN below) and the route port/slice_ov096.txt
# section D says its own twin should have taken. The value is unobservable at
# both ends; the derivation is in the table's note in port/tools/hostgen.py.
# EMPTIED 2026-09-13 (lane SYNC3). main folded this body into
# src/actors/daGmch_c.cpp, which the guard below already refuses to let into
# slice_w3b because the port host-copies its dispatchers; the TU is quarantined
# out of every slice it was in. The FALLS_OFF_RETURN string no longer appears in
# main's spelling of the body either, so there is nothing left to substitute for
# and no target a generated copy could be compiled into.
set(W3BGEN_SYMS)
set(W3BGEN "")
foreach(sym IN LISTS W3BGEN_SYMS)
    set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND W3BGEN "${sym_out}")
endforeach()
foreach(dup IN ITEMS src/actors/daGmch_c.cpp src/actors/daGmch_c.cpp)
    if(dup IN_LIST SLICE_W3B_LINES)
        message(FATAL_ERROR
            "slice_w3b.txt lists ${dup}, which the port host-copies "
            "(hal/actor_classes_ov081.cpp's mn_d1 thunk / "
            "unmatched/ModelAnim_Renders.cpp). Both would define the same "
            "symbol (LNK2005). Remove the slice line.")
    endif()
endforeach()

# Gate 193: BABY_PENGUIN (256) + the actual SNOWMAN (272, the unnamed
# daBgSnwmn_c block), ov072. Fresh per-symbol ov072 mount
# (port/ov072_syms.txt). The fill is hal/actor_classes_ov072.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate193.txt" SLICE193_LINES)
set(SLICE193_SOURCES "")
foreach(line IN LISTS SLICE193_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE193_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# ---- link100 OV ----
# Gate 217: the last two overlay ACTOR classes in the ROM's spawn table
# whose whole vtable is matched src with no guessed body -- id 348 (ov002
# 0x021085f8, RTTI 10daChRoom_c) and id 314 (ov039 0x02111858, RTTI
# 11daObjKumo_c). The fill is hal/actor_classes_ov_link100.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate217.txt" SLICE217_LINES)
set(SLICE217_SOURCES "")
foreach(line IN LISTS SLICE217_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE217_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# GATE 220 (run link100, lane FRAME): _ZTV5Stage slot 6 takes the ROM's own
# Stage::Behavior, and port/tests/walk_window.cpp stops being the port's copy of
# it. Fifty-six matched TUs -- the pause screen and its five menu arms, the nine
# Message::Display* bodies they draw through, the VS-exit pair, LC_Update,
# VE_Init/VE_Update and Behavior itself. The whole derivation, including why the
# pause tree could not be seamed and which single body could not be enrolled,
# is in port/slice_gate220.txt's own header; section 13 of
# port/stage_lifecycle_map.txt is the accounting.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate220.txt" SLICE220_LINES)
set(SLICE220_SOURCES "")
foreach(line IN LISTS SLICE220_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE220_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# GREG2 cut: src/func_0205f650.c comes off THIS slice (see the R3F_GREG block
# far above, where R3F_GREG2_SYMS and the R3F_GREG_PLAIN switch are defined).
# Same discipline as the SLICE214 cut above, own counter on purpose.
set(R3F_GREG2_CUT 0)
set(SLICE220_SRC_GREG2 "")
foreach(src IN LISTS SLICE220_SOURCES)
    set(_cut OFF)
    if(NOT R3F_GREG_PLAIN)
        foreach(sym IN LISTS R3F_GREG2_SYMS)
            if(src MATCHES "/${sym}\.(c|cpp)$")
                set(_cut ON)
            endif()
        endforeach()
    endif()
    if(_cut)
        math(EXPR R3F_GREG2_CUT "${R3F_GREG2_CUT}+1")
    else()
        list(APPEND SLICE220_SRC_GREG2 "${src}")
    endif()
endforeach()
set(SLICE220_SOURCES ${SLICE220_SRC_GREG2})
list(LENGTH R3F_GREG2_SYMS R3F_GREG2_WANT)
if(R3F_GREG_PLAIN)
    set(R3F_GREG2_CUT ${R3F_GREG2_WANT})
endif()
if(NOT R3F_GREG2_CUT EQUAL R3F_GREG2_WANT)
    message(STATUS "R3F/GREG2: expected to cut ${R3F_GREG2_WANT} plain "
                   "POWCNT1-read entry from slice_gate220.txt and cut "
                   "${R3F_GREG2_CUT}. If slice_gate220.txt stopped listing it "
                   "the hostgen copy is still added and the link will say so; "
                   "if a SECOND slice started listing it, this cut missed it "
                   "and the link will say that too")
endif()

# GATE SLOT9 (run link100, lane RENDER9): _ZTV5Stage slot 9 takes the ROM's own
# Stage::Render, and port/tests/walk_window.cpp stops being the port's copy of
# it. Six matched TUs -- Render itself, func_020391f0, RenderFog and its two
# leaves, and RenderNumber -- plus three bodies deliberately NOT enrolled and
# seamed in hal/stage_frame.cpp, on unmounted ov001/ov002 sprite templates that
# belong to the mount lane's files. The whole derivation, including what each
# seam wants and which already-linked TUs the seat brings back off /OPT:REF,
# is in port/slice_slot9.txt's own header; section 18 of
# port/stage_lifecycle_map.txt is the accounting.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_slot9.txt" SLICE_SLOT9_LINES)
set(SLICE_SLOT9_SOURCES "")
foreach(line IN LISTS SLICE_SLOT9_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SLOT9_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# The id-348 deleting destructor spells the VT placeholder; its ROM store
# relocates to its own table (ov002 from:0x020b084c -> 0x021085f8), the
# host array the fill writes and daChRoom_c_classInit installs. HEAP is left
# alone: its binding to the game heap pointer 0x020a0eac is what that body
# means, and hal/cxx_aliases.cpp already carries that alias.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_ch_room.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT=_ZTV10daChRoom_c")
# Cloud::InitResources carries TWO sibling-overlay spellings of addresses
# that are ov039's own in this class's module: it calls
# _ZN19daObjKb1Billboard_c20UpdateModelTransformEv and bumps data_ov041_021118e0, while the ROM relocs
# at 0x02111354 and 0x02111378 both read module:overlay(39). Routed per
# source, which a definition cannot defeat the way an /alternatename can.
# func_ov039_02111214 is the matched TU on slice_gate217;
# data_ov039_021118e0 is the four-byte counter the fill defines.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_kumo.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZN19daObjKb1Billboard_c20UpdateModelTransformEv=func_ov039_02111214  --  dead, the TU does not spell _ZN19daObjKb1Billboard_c20UpdateModelTransformEv
#   data_ov041_021118e0=data_ov039_021118e0  --  dead, the TU does not spell data_ov041_021118e0
# Deleted rather than merged. The surviving row is unchanged.
# Cloud::Behavior is a flat .c TU that spells decl_common.h's two generic
# placeholder names, FindWithActorID and SetPolygonID. Both are real arm9
# functions the ROM relocs name outright -- 0x02010ef0
# _ZN8dActor_c15FindWithActorIDEjPS_ and 0x02016abc _ZN5Model12SetPolygonIDEi,
# read out of config/arm9/overlays/ov039/relocs.txt inside the Behavior
# span -- and both already have a C-linkage definition in this link
# (hal/actor_faces_bob.cpp aliases the static onto its ROM name;
# hal/actor_classes_ov063.cpp defines the SetPolygonID face for exactly
# this reason). Bound PER SOURCE rather than by a global /alternatename on
# a bare placeholder name, so no other TU that spells either word is
# steered by this lane.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_kumo.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "FindWithActorID=_ZN8dActor_c15FindWithActorIDEjPS_;SetPolygonID=_ZN5Model12SetPolygonIDEi")

# Gate 194: HOOT_THE_OWL (234), ov094. Fresh per-symbol ov094 mount
# (port/ov094_syms.txt). The fill is hal/actor_classes_ov094.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate194.txt" SLICE194_LINES)
set(SLICE194_SOURCES "")
foreach(line IN LISTS SLICE194_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE194_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 199: SWITCH_PILLAR (34) + BASEMENT_WATER (35), ov012 (level 4). Per-
# symbol ov012 mount (port/ov012_syms.txt). The fill is
# hal/actor_classes_ov012.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate199.txt" SLICE199_LINES)
set(SLICE199_SOURCES "")
foreach(line IN LISTS SLICE199_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE199_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 200: PUSH_BLOCK (306, the "PowerFlower" id-decoy) + MUGEN_BGM (351),
# both ov002. The fill is hal/actor_classes_ov002g200.cpp; the state
# dispatch + dest seat is unmatched/PushBlock_StateDispatch.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate200.txt" SLICE200_LINES)
set(SLICE200_SOURCES "")
foreach(line IN LISTS SLICE200_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE200_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate BULLET: actor 233, ov002's Snufit-fired projectile. ov002 already mounted;
# the fill is hal/actor_classes_bullet.cpp, the one-PMF state dispatch + dest seat
# is unmatched/Bullet_StateDispatch.cpp. See slice_bullet.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_bullet.txt" SLICEBULLET_LINES)
set(SLICEBULLET_SOURCES "")
foreach(line IN LISTS SLICEBULLET_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICEBULLET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 202: CLOCK_HAND_SHORT (292) + CLOCK_HAND_LONG (293) + CLOCK_PENDULUM
# (294), ov013 (level 5, the 2F clock-painting furniture). Per-symbol ov013
# mount (port/ov013_syms.txt). The fill is hal/actor_classes_ov013.cpp; the
# four D1/D0 TUs are host thunks there, everything else rides from src.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate202.txt" SLICE202_LINES)
set(SLICE202_SOURCES "")
foreach(line IN LISTS SLICE202_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE202_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run rel0215 wave 1 (lane cast-ov077): HEAVE_HO (238) + SPINY (260) +
# LAKITU (265), ov077. Fresh per-symbol ov077 mount (port/ov077_syms.txt). The
# fill and the PMF state seat are hal/actor_classes_ov077.cpp; the twelve
# host-copied TUs (three ModelAnim slot-5 Renders, six PMF dispatch sites, two
# real-C++ destructors MSVC cannot name, one implicit-r1 caller) are the three
# unmatched/*_HostSites.cpp files, each refusal itemised in
# port/slice_ov077.txt; unmatched/Lakitu_ShadowFaces.cpp carries the slice's
# measured closure gap, which was eight naming mismatches and no missing body.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov077.txt" SLICE_OV077_LINES)
set(SLICE_OV077_SOURCES "")
foreach(line IN LISTS SLICE_OV077_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV077_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run rel0215 wave 1 (lane cast-ov030): ROLLING_LOG_TTM (102), UKIKI_CAGE (103),
# UKIKI_THIEF (267) and UKIKI_STAR (268) -- ov030, Tall Tall Mountain (level 22).
# Fresh per-symbol ov030 mount (port/ov030_syms.txt) beside the existing whole
# mount. The three vtable fills, the eleven-cell PMF state seat, the loud face
# for the overlay's ONE missing body and the two RollingLogTtm method faces are
# in hal/actor_classes_ov030.cpp; the three host copies carry the two
# pointer-to-member dispatch sites and the ModelAnim slot-3 shadow. The gate-64
# shape: the hal file and the host copies ride in the slice's own SOURCES list,
# so the target lists take one token.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov030cast.txt" SLICE_OV030CAST_LINES)
set(SLICE_OV030CAST_SOURCES "")
foreach(line IN LISTS SLICE_OV030CAST_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV030CAST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_OV030CAST_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_ov030.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Ukiki_Behavior.cpp")

# lane cast-ov030, TRAP: THREE ov030 TUs SPELL A VTABLE WITH THE WRONG NAME AND
# TWO SPELL IT WITH A PLACEHOLDER. Each rename is read off that TU's OWN literal
# pool in config/arm9/overlays/ov030/relocs.txt, the ov043 trap-4 discipline
# (line 8300 above), never guessed from the placeholder's usual meaning.
#
#   src/d_a_obj_hm_maruta.c   stores TWO tables, in this ROM order:
#       from:0x02111680 -> 0x02128338  _ZTV13daObjMaruta_c, an INTERMEDIATE base
#                                      table that lives in ov080 (level 22 loads
#                                      ov080, not ov078, so that is the live
#                                      spelling of `module:overlays(79,80)`);
#                                      already mounted by port/ov080_syms.txt
#       from:0x02111684 -> 0x02115a48  the class's OWN table, the host array
#     and src spells them `_ZTV15daObjHmMaruta_c` then `VT1` -- the FIRST name is
#     on the WRONG store. VT1 is renamed to _ZTV13RollingLogTtm rather than straight
#     to _ZTV15daObjHmMaruta_c because a macro whose body is another macro is
#     rescanned and both stores would collapse onto the same array.
#     _ZTV13RollingLogTtm is config's own (mis-attributed) name for 0x02115a48 and
#     hal/actor_classes_ov030.cpp aliases it onto the one host array with
#     /alternatename, so this is ONE storage under two names -- the
#     _ZTV10dBgActor_c / _ZTV10dBgActor_c shape at hal/actor_classes.cpp:591.
#
#   src/_ZN13RollingLogTtmD1Ev.cpp and src/_ZN13RollingLogTtmD0Ev.cpp (BOTH are really
#   RollingLogTtm's destructors) store THREE tables, ROM order:
#       0x02115a48  the class's own      -- spelled _ZTV15daObjHmMaruta_c, RIGHT
#       0x02128338  ov080's intermediate -- spelled _ZTV10dBgActor_c,      WRONG
#       0x0210ae38  Platform's base      -- spelled VT2, a placeholder
#     0x0210ae38 is config's _ZTV10dBgActor_c, which hal/actor_classes.cpp already
#     defines and fills (it fills _ZTV10dBgActor_c and _ZTV10dBgActor_c with the
#     same contents for exactly this reason), so VT2 goes straight to it.
#     Neither replacement is itself a macro here, so no rescan collision.
#     D0 additionally spells the heap `G0`; its pool word is 0x0211160c ->
#     0x020a0eac, the same global _ZN7daMky_cD0Ev.c names outright.
#
#   src/_ZN13daObjHmBskt_cD0Ev.cpp (UkikiCage's D0) spells all three by placeholder;
#     its pool is 0x02111240 -> 0x02115974, 0x02111244 -> 0x0210ae38 and
#     0x02111248 -> 0x020a0eac, so VT0/VT1/G0 map to the class's own table,
#     Platform's base and the heap. Its sibling src/_ZN13daObjHmBskt_cD1Ev.cpp (the
#     D1) spells the SAME pair BY NAME and correctly, and needs no rename.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_obj_hm_maruta.c"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV15daObjHmMaruta_c=_ZTV13daObjMaruta_c;VT1=_ZTV13RollingLogTtm")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13RollingLogTtmD1Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV10dBgActor_c=_ZTV13daObjMaruta_c;VT2=_ZTV10dBgActor_c")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13RollingLogTtmD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV10dBgActor_c=_ZTV13daObjMaruta_c;VT2=_ZTV10dBgActor_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13daObjHmBskt_cD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV13daObjHmBskt_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
# lane cast-ov030, the SECOND rename shape: src/actors/daMky_c.cpp calls
# three arm9 helpers by their func_ADDRESS PLACEHOLDER while config names all
# three and the port already links them under those real names. Measured off
# the first link's own unresolved list, then read back out of
# config/arm9/symbols.txt rather than guessed from the call site:
#   0x0203cfdc  line 1644  Vec3_Dist
#   0x0200f97c  line  234  _ZN8dActor_c13SpawnSoundObjEj
#   0x02015024  line  500  _ZN5dCc_c5ClearEv
# All three are already in walk_window.map on the BASE tree as _Vec3_Dist,
# __ZN8dActor_c13SpawnSoundObjEj and __ZN5dCc_c5ClearEv, so this is a
# spelling bridge onto bodies that already link and adds no TU to the count.
# BOTH PATHS, run link100 lane HOSTGEN4. This TU is on PORT_HOSTGEN_TU now,
# so the compile the build runs is the generated copy. These three renames
# are what bind the placeholder spellings to bodies that already link; on
# the raw path alone they would go missing and the three names would come
# straight back onto the unresolved wall. The src/ row is kept so the
# property is still right if the substitution is ever retired.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daMky_c.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/actors/daMky_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_0203cfdc=Vec3_Dist;func_0200f97c=_ZN8dActor_c13SpawnSoundObjEj;func_02015024=_ZN5dCc_c5ClearEv")
# lane cast-ov030, THE G0/G1 TRAP, LIVE, and this row is the whole reason
# port/tools/alias_audit.py exists (its own docstring opens on this shape).
# src/_ZN13daObjHmBskt_c16CleanupResourcesEv.cpp is UkikiCage's CleanupResources and it Releases TWO
# SharedFilePtrs, spelled G0 and G1. hal/cxx_aliases.cpp binds those names ONCE
# for the whole link -- _G0 to _data_020a0eac (the GAME HEAP POINTER, line 1272)
# and _G1 to _data_ov002_0210e05c (an ov002 SharedFilePtr, line 1721) -- so
# without this row that function would have called SharedFilePtr::Release on the
# game heap pointer and on another overlay's object every time the cage tore
# down. It fails at NO link, shows in NO map, and no byte gate can see it.
# WHAT THE TU ACTUALLY MEANS, decoded from its own literal pool in the shipped
# image rather than from the placeholder's usual meaning:
#   0x0211132c  ldr r0,[pc,#0x14] -> 0x02111348 = 0x02115c88  = G0
#   0x02111334  ldr r0,[pc,#0x10] -> 0x0211134c = 0x02115c80  = G1
# Both are ov030's own .bss SharedFilePtrs and both are mounted by
# port/ov030_syms.txt. A comment-stripped sweep of all 67 slice TUs for
# G0/G1/G2/VT/VT0/VT1/VT2/HEAP/R0/R1/R2 finds placeholders in exactly five
# files, and all five are bound per source by the rows above and this one.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13daObjHmBskt_c16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=data_ov030_02115c88;G1=data_ov030_02115c80")



# ============================================================================
# RUN REL0215 WAVE 1, LANE CAST-SWEEP1 -- the small-cast sweep.
#
# Six level overlays whose whole cast is one or two classes with a tiny vtable
# set: ov035 (27), ov024 (16), ov033 (25), ov023 (15), ov017 (9), ov058 (50).
# Each lands as its own commit; this region grows by one block per overlay and
# is the ONLY place in this file the lane appends more than once. The three
# target source lists take ${SWEEP1_SOURCES} exactly once, so a second overlay
# costs the coordinator nothing outside this region.
#
# Every overlay here is already whole-mounted in PORT_LEVEL_OVERLAYS, so each
# per-symbol mount is the SECOND mount of the same overlay -- the
# ov012/ov013/ov025/ov045/ov052/ov056 dual shape. --whole emits
# port_ovNNN_image/_patch/_at and nothing by name; --from-list --pack emits the
# named arrays plus port_ovNNN_syms_patch. Every mount bring-up runs from the
# lane's own hal/actor_classes_ovNNN.cpp behind a DSSTATE-bracketed done-guard
# (the ov025/ov045/ov052/ov056/ov073 lane-ownership pattern), so this lane
# appends NOTHING to hal/actor_overlays.cpp.
set(SWEEP1_SOURCES "")

# ---- 1/6: ov035, level 27 (Tick Tock Clock) --------------------------------
# ROTATING_CLOCK_HAND (119) x2, SPINNING_PLATFORM (120) x13, ROTATING_COG_BIG
# (121) x2, ROTATING_COG_SMALL (122) x2 -- nineteen of level 27's 57 skipped
# instances. All twenty of ov035's TUs, no host copy, no refusal. Two 32-slot
# Platform tables hosted in hal/actor_classes_ov035.cpp; ov035 is ALREADY in
# PORT_ACTOR_OVERLAYS (wave 18 landed the list for the ov065 Ttc cluster's
# cross-overlay reads) and this lane adds the cast's own symbols to that list
# and, for the first time, a caller for port_ov035_syms_patch(). See
# port/ov035_syms.txt's second header and port/slice_sweep1_ov035.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sweep1_ov035.txt" SLICE_SWEEP1_OV035_LINES)
set(SLICE_SWEEP1_OV035_SOURCES "")
foreach(line IN LISTS SLICE_SWEEP1_OV035_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SWEEP1_OV035_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# THE TWO SHARED-WINDOW ALIAS RACES (T6). ov017/ov023/ov035/ov045/ov055/ov056
# all link at 0x021111a0 and the decomp was written against whichever dsd
# export won the naming race, so two ov035 TUs spell ov035's own bytes with a
# sibling overlay's name. data_ov045_02112cb0 IS DEFINED in this link
# (port/ov045_syms.txt:123 mounts it), so an /alternatename with it on the left
# would be defeated silently -- the R3 ov071/ov073 failure -- and left alone
# the ov035 sinit would construct a SharedFilePtr over LEVEL 37's mounted data.
# A -D is the remedy T6 prescribes. The second is routed the same way so the
# pair cannot drift apart.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/__sinit_ov035_02111fc0.c"
    PROPERTIES COMPILE_DEFINITIONS "data_ov045_02112cb0=data_ov035_02112cb0")
# ...and this one goes to a PRIVATE name rather than straight to
# data_ov035_02112c68, for the ov100 path-lift reason: decl_common.h declares
# BOTH spellings, `extern char data_ov056_02112c68[]` at line 262 and
# `extern int data_ov035_02112c68[]` at line 1149, so a direct -D makes 262
# redeclare 1149 with a different element type. C2371, measured on the first
# build of this seat, not predicted. hal/actor_classes_ov035.cpp binds it.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN16RotatingCogSmall16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS "data_ov056_02112c68=port_ov035_rcs_clsn")
# G0/G1 in id 120's CleanupResources are the two SharedFilePtrs at 0x02112cb0
# and 0x02112cb8 (pool order read off the ROM body at 0x0211192c/0x02111930).
# They go to PRIVATE names this lane owns rather than straight to
# data_ov035_02112cb0/b8, because that TU includes decl_common.h, which
# already declares both of those as `extern char` scalars -- a direct -D is a
# C2040 redeclaration, the ov100 path-lift trap. hal/actor_classes_ov035.cpp
# binds each private name onto the mounted object, and both LHS are undefined
# everywhere so neither alias can be defeated.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN16SpinningPlatform16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_ov035_sp_file0;G1=port_ov035_sp_file1")
# G0 in the two deleting destructors is the GAME HEAP, 0x020a0eac -- the same
# name meaning something else in a different TU, which is why every one of
# these is per-source. Read off the ROM bodies' own literal pools
# (0x02111238 and 0x02111794).
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN16RotatingCogSmallD0Ev.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN16SpinningPlatformD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS "G0=data_020a0eac")
list(APPEND SWEEP1_SOURCES hal/actor_classes_ov035.cpp ${SLICE_SWEEP1_OV035_SOURCES})

# ---- 2/6: ov024, level 16 (Shifting Sand Land) -----------------------------
# PYRAMID_TOP (85) x1 and PYRAMID_TAG (86) x4 -- five of level 16's nineteen
# skipped instances. SIXTEEN of the overlay's seventeen TUs; the seventeenth,
# src/_ZN10PyramidTagD1Ev.cpp, is the //cpp real-destructor shape MSVC cannot
# deliver (it would call ??1Actor@@UAE@XZ and ??1MovingCylinderClsn@@QAE@XZ as
# thiscall against cdecl C bodies) and is transcribed from the ROM in
# hal/actor_classes_ov024.cpp -- the gate-199/200 treatment ov013 used on
# ClockPaintingHandShort's D1. Two host vtables of DIFFERENT lengths, 31 and
# 32. See port/ov024_syms.txt and port/slice_sweep1_ov024.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sweep1_ov024.txt" SLICE_SWEEP1_OV024_LINES)
set(SLICE_SWEEP1_OV024_SOURCES "")
foreach(line IN LISTS SLICE_SWEEP1_OV024_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SWEEP1_OV024_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# G0 in id 85's deleting destructor is the GAME HEAP, 0x020a0eac, read off that
# body's own literal pool at 0x02111240. No alias race in this overlay: every
# ov024 symbol its TUs name is spelled with ov024's own prefix.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10PyramidTopD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS "G0=data_020a0eac")
list(APPEND SWEEP1_SOURCES hal/actor_classes_ov024.cpp ${SLICE_SWEEP1_OV024_SOURCES})

# ---- 3/6: ov033, level 25 (Tiny-Huge Island, small side) -------------------
# TINY_COVER (104) x1 and TINY_WATER (105) x1 -- two of level 25's three
# skipped instances. All seventeen of the overlay's TUs, no host copy and no
# refusal. Two 32-slot Platform tables, and dsd's one vtable label is on the
# wrong one. See port/ov033_syms.txt and port/slice_sweep1_ov033.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sweep1_ov033.txt" SLICE_SWEEP1_OV033_LINES)
set(SLICE_SWEEP1_OV033_SOURCES "")
foreach(line IN LISTS SLICE_SWEEP1_OV033_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SWEEP1_OV033_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# id 104's deleting destructor: VT0 is the OWN table 0x0211237c, VT1 is
# Platform's base 0x0210ae38, G0 is the game heap -- pool order read off the
# ROM body at 0x02111230/0x02111234/0x02111238. Private names because VT0/VT1
# mean different objects in the id-105 pair below.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN9TinyCoverD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=port_ov033_tc_vt_own;VT1=port_ov033_vt_base;G0=data_020a0eac")
# id 105's D1/D0: THE RESOLVER'S TWO LABELS ARE INVERTED. The source writes
# _ZTV10dBgActor_c first and VT1 second; the ROM writes the OWN table first
# (0x021113e4 stores the word at pool 0x02111418 = 0x02112440) and Platform's
# base second (0x021113f4 stores pool 0x0211141c = 0x0210ae38). Left alone the
# destructor would install the base table before the TextureTransformer
# teardown and leave the OWN table installed after Actor::D2 -- exactly
# inverted, and invisible to both the byte gate and the linkage count. A direct
# -D onto _ZTV10dBgActor_c is impossible anyway: that name is a live host array
# for every Platform in the port.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN9TinyWaterD1Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV10dBgActor_c=port_ov033_tw_vt_own;VT1=port_ov033_vt_base")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN9TinyWaterD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV10dBgActor_c=port_ov033_tw_vt_own;VT1=port_ov033_vt_base;G0=data_020a0eac")
# THE ALIAS RACE (T6). id 104's InitResources hands the collider a CLPS block
# it spells data_ov035_02111bfc -- OV035's name for the same shared-window
# address -- and ov035's 0x02111bfc IS MOUNTED (port/ov035_syms.txt, wave 18's
# seeds), so the name resolves and the collider would take level 27's data.
# decl_common.h declares the ov035 spelling and not the ov033 one, so this
# rename is direct and needs no private name.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN9TinyCover13InitResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS "data_ov035_02111bfc=data_ov033_02111bfc")
list(APPEND SWEEP1_SOURCES hal/actor_classes_ov033.cpp ${SLICE_SWEEP1_OV033_SOURCES})

# ---- 4/6: ov023, level 15 (Lethal Lava Land's volcano) ---------------------
# SQUASHER (84) x1 -- and it is the WHOLE of level 15's skip list, so this seat
# takes that level to zero skipped classes. All ten of the overlay's TUs, no
# host copy and no refusal. One 32-slot Platform table; the dsd landing
# OVER-reads it by seven slots. See port/ov023_syms.txt and
# port/slice_sweep1_ov023.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sweep1_ov023.txt" SLICE_SWEEP1_OV023_LINES)
set(SLICE_SWEEP1_OV023_SOURCES "")
foreach(line IN LISTS SLICE_SWEEP1_OV023_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SWEEP1_OV023_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# The destructors' two vtable stores are LABELLED BACKWARDS by the resolver:
# the source writes _ZTV10dBgActor_c first and VT1 second, the ROM writes the
# OWN table first (pool 0x021111e4 = 0x02111fe4) and Platform's base second
# (0x021111e8 = 0x0210ae38). Same inversion ov033's id-105 pair carries. A
# direct -D onto _ZTV10dBgActor_c is impossible: it is a live host array for
# every Platform in the port.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_fm_battan.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV10dBgActor_c=port_ov023_vt_own  --  dead, the TU does not spell _ZTV10dBgActor_c
#   VT1=port_ov023_vt_base  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_fm_battan.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV10dBgActor_c=port_ov023_vt_own  --  dead, the TU does not spell _ZTV10dBgActor_c
#   VT1=port_ov023_vt_base  --  dead, the TU does not spell VT1
#   G0=data_020a0eac  --  dead, the TU does not spell G0
# Deleted rather than merged. The surviving row is unchanged.
# CleanupResources releases the model file then the collision one, in that
# order (pool 0x02111380 then 0x02111384). Private names because that TU
# includes decl_common.h, which already declares 0x02112088 as a scalar.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_fm_battan.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   G0=port_ov023_sq_file0  --  dead, the TU does not spell G0
#   G1=port_ov023_sq_file1  --  dead, the TU does not spell G1
# Deleted rather than merged. The surviving row is unchanged.
# TWO LIVE ALIAS RACES IN ONE BODY (T6), both pinned to the ROM:
#   the call at 0x021116a4 relocates to 0x02111308 module ov023 -- the source
#     calls it _ZN17daObjWlPolelift_c6RenderEv, and lane W1-A is seating ov026 in this same
#     wave, so that name is about to become DEFINED and the call would land in
#     another level's overlay. A direct -D collides with decl_common.h's own
#     _ZN16daObjFm_Battan_c20UpdateModelTransformEv(char*) declaration, so it goes to a private name.
#   pool 0x0211171c holds 0x02112080, ov023's collision SharedFilePtr -- the
#     source spells it &_ZN15daObjWc_Obj07_cD1Ev, an OV029
#     FUNCTION name at ov023's data address. Left alone MeshCollider::LoadFile
#     takes the address of a destructor as a file pointer.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_fm_battan.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZN17daObjWlPolelift_c6RenderEv=port_ov023_xform;_ZN15daObjWc_Obj07_cD1Ev=port_ov023_clsn_file")
list(APPEND SWEEP1_SOURCES hal/actor_classes_ov023.cpp ${SLICE_SWEEP1_OV023_SOURCES})

# ---- 5/6: ov017, level 9 (Jolly Roger Bay's sunken ship) -------------------
# SHIP_WATER (62) x1 -- one of level 9's two skipped instances, and a blocker
# hal/level_boot.cpp's own level-9 block named and deferred. All eight of the
# overlay's TUs, no host copy and no refusal. One 32-slot Platform table; dsd's
# landing reads TEN. See port/ov017_syms.txt and port/slice_sweep1_ov017.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sweep1_ov017.txt" SLICE_SWEEP1_OV017_LINES)
set(SLICE_SWEEP1_OV017_SOURCES "")
foreach(line IN LISTS SLICE_SWEEP1_OV017_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SWEEP1_OV017_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# THREE ALIAS RACES IN ONE FUNCTION (T6), every one pinned to the ROM's own
# literal pool at 0x02111470..0x0211147c, over which the relocations resolve
# ALL FOUR of InitResources's objects to OV017 symbols:
#     pool 0x02111474 -> 0x02111a60  spelled data_ov056_02111a60
#     pool 0x02111478 -> 0x02111c80  spelled &_ZN15daObjKm2_Gura_cD0Ev
#     pool 0x0211147c -> 0x02111a94  spelled data_ov055_02111a94
# THE MIDDLE ONE IS LIVE ON THIS TIP: src/game/actors/d_a_obj_km2_gura.cpp is in
# port/slice_w1l4.txt and the symbol is in build/port/walk_window.map, so
# without this rename MeshCollider::LoadFile is handed the ADDRESS OF AN OV045
# DESTRUCTOR as a file pointer -- resolving cleanly, failing nowhere at link.
# The other two are undefined today and latent, but ov056 IS mounted and a
# later lane adding either name turns them live silently. The TU includes no
# headers at all, so all three renames are direct.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_ks_water.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   data_ov056_02111a60=data_ov017_02111a60  --  dead, the TU does not spell data_ov056_02111a60
#   _ZN15daObjKm2_Gura_cD0Ev=data_ov017_02111c80  --  dead, the TU does not spell _ZN15daObjKm2_Gura_cD0Ev
#   data_ov055_02111a94=data_ov017_02111a94  --  dead, the TU does not spell data_ov055_02111a94
# Deleted rather than merged. The surviving row is unchanged.
# G0 in the deleting destructor is the game heap. Note this overlay's D1/D0 get
# their TWO VTABLE STORES IN THE RIGHT ORDER, unlike ov023's and ov033's: pool
# 0x021111e4 holds the own table and 0x021111e8 Platform's base, which is the
# order the source writes them, so neither store needs renaming.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_ks_water.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   G0=data_020a0eac  --  dead, the TU does not spell G0
# Deleted rather than merged. The surviving row is unchanged.
# CleanupResources releases the model file then the collision one (pool
# 0x02111288 then 0x0211128c). Private names because that TU includes
# decl_common.h, which already declares both.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_ks_water.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=port_ov017_sw_file0;G1=port_ov017_sw_file1")
list(APPEND SWEEP1_SOURCES hal/actor_classes_ov017.cpp ${SLICE_SWEEP1_OV017_SOURCES})

# ---- 6/6: ov058, level 50 (the Rec Room) -----------------------------------
# REC_ROOM_CUPBOARD (182) x1 -- and it is the WHOLE of level 50's skip list, so
# this seat takes that level to zero skipped, the second in this lane after
# level 15. All six of the overlay's TUs, no host copy, no refusal and NOT ONE
# per-source -D: no placeholder reaches code, no TU spells a sibling's name,
# and dsd's vtable label is on the table its own factory installs. One 31-slot
# ACTOR table (the ov024 PYRAMID_TAG shape, not a Platform one); dsd's landing
# reads TWO. See port/ov058_syms.txt and port/slice_sweep1_ov058.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sweep1_ov058.txt" SLICE_SWEEP1_OV058_LINES)
set(SLICE_SWEEP1_OV058_SOURCES "")
foreach(line IN LISTS SLICE_SWEEP1_OV058_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SWEEP1_OV058_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SWEEP1_SOURCES hal/actor_classes_ov058.cpp ${SLICE_SWEEP1_OV058_SOURCES}
    unmatched/RecRoomCupboard_ActorDtorSeam.cpp)
# ---- end lane cast-sweep1 --------------------------------------------------



# run rel0215 wave 1 (lane cast-ov036): ov036's Rainbow Cruise cast --
# SWINGING_PLATFORM (127), ROTATING_PLATFORM_RR (129), SHIP_WING (125),
# DONUT_BLOCK (126), ARMED_ROTATING_PLATFORM (132), TRICKY_TRIANGLES (123) and
# FLYING_CARPET (130), level 28. Per-symbol ov036 mount (port/ov036_syms.txt).
# The fill is hal/actor_classes_ov036.cpp. Two TUs are NOT in the slice:
# _ZN14daObjRc_Hane_cD1Ev.cpp (SHIP_WING's D1, an MSVC-synthesised
# destructor over a local shadow class that provides no C name -- the chain is
# spelled as sw_d1 in the fill) and _ZN15daObjRcCarpet_c6RenderEv.cpp (FLYING_CARPET's
# Render, the ModelAnim slot-5 collision -- host copy in
# unmatched/FlyingCarpet_Render.cpp). The last four lines of the slice are the
# MEASURED external closure: four ov002 bodies TRICKY_TRIANGLES needs, taken
# off the map rather than guessed.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov036cast.txt" SLICE_OV036CAST_LINES)
set(SLICE_OV036CAST_SOURCES "")
foreach(line IN LISTS SLICE_OV036CAST_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV036CAST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run rel0215 wave 2 (lane cast-ov066): EYEROK (176, 10daIwante_c), ov066, the
# SSL pyramid boss. Fresh per-symbol ov066 mount (port/ov066_syms.txt). The
# 32-slot vtable fill, the NINETEEN-cell pointer-to-member state seat and the
# three slot traps are in hal/actor_classes_ov066.cpp; four TUs are host-copied
# (the PMF enter half, the PMF tick half inside Behavior, the BlendModelAnim
# slot-5 Render and the receiver-dropping ClosestPlayer reader), each refusal
# itemised in port/slice_ov066.txt. The gate-64 / cast-ov030 shape: the hal file
# and the four host copies ride in the slice's own SOURCES list, so the three
# target lists take ONE token.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov066.txt" SLICE_OV066_LINES)
set(SLICE_OV066_SOURCES "")
foreach(line IN LISTS SLICE_OV066_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV066_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_OV066_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_ov066.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Eyerok_Behavior.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Eyerok_ClosestPlayerRead.cpp")
# unmatched/Eyerok_Render.cpp RETIRED (run link100, lane FOLD2): its only
# divergence was the BlendModelAnim slot-5 shadow the destructor fold created,
# and src/actors/Eyerok.cpp is on port/slice_fold2.txt now. No face: the
# matched TU defines ?Render@Eyerok@@QAEHXZ, which is the symbol
# hal/actor_classes_ov066.cpp's ov66_render already calls as a C++ method.
# run link100 lane PMF2: src/actors/Eyerok.cpp LEFT this list. Its host
# copy (unmatched/Eyerok_StateEnter.cpp) is deleted and the matched TU is on
# port/slice_pmf2.txt, so listing it here would refuse a slice line that is
# now correct. The other three are still host-copied and still guarded.
# src/actors/Eyerok.cpp LEFT this guard with lane FOLD2's retirement --
# it is a slice row again, on port/slice_fold2.txt, so refusing it here would
# refuse a line that is now correct. The other two are still host-copied.
foreach(dup IN ITEMS src/actors/Eyerok.cpp
                     src/actors/Eyerok.cpp)
    if(dup IN_LIST SLICE_OV066_LINES)
        message(FATAL_ERROR
            "slice_ov066.txt lists ${dup}, which port/unmatched/ host-copies. "
            "Both would define the same symbol (LNK2005). Remove the slice line.")
    endif()
endforeach()

# ---- lane cast-ov066: THE SIX ALIASES THIS MOUNT DEFEATS --------------------
# THE TREE PREDICTED THIS LANE IN WRITING. port/build-port.cmd:92 and
# port/tools/alternatename_guard.py:20 both say "EyerokD0 and the data_ov075
# aliases flip the same way if their overlays land". SIX live /alternatename
# directives carried an ov066 name as their LHS, and defining that name defeats
# the alias SILENTLY -- no link error, a wrong object at run time, the
# Coffin/Spindrift shape. All six are removed from their hal files and replaced
# by per-source -D renames on the FOREIGN CALLER, which is the remedy
# hal/actor_classes_koopa_chuckya.cpp's own note already prescribes for exactly
# this case (the w5b_review.md R2 func_ov065_02117994 precedent).
#
# Every one was checked BOTH ways before the conversion: the caller TU is on a
# live slice, and the -D target is defined in the link. A -D onto an undefined
# name would have turned a silent bug into a link error, which is better, but
# neither is what this lane is for.
#
# (1) src/actors/daYurei_Mucho_c.cpp (slice_w5b) -- a Snufit state body. It calls
#     0x02115f84 and the reloc `from:0x02116314 kind:arm_call to:0x02115f84
#     module:overlay(65)` puts that body in ov065's OWN image as
#     func_ov065_02115f84, size 0x6c. Eyerok's D0 at the same address is size
#     0xb8 -- a DIFFERENT body, and the sizes alone settle it. Undefeated this
#     calls a destructor on a live Snufit.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daYurei_Mucho_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZN6EyerokD0Ev=func_ov065_02115f84")
# (2) src/func_ov062_02117acc.c (slice_gate182) -- a Chuckya/Koopa body whose
#     callees dsd named under ov066 because it saw that overlay first. Both
#     targets are ov062's own and both are sliced by gate 182.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov062_02117acc.c"
    PROPERTIES COMPILE_DEFINITIONS
    "func_ov066_02118cdc=func_ov062_02118cdc;func_ov066_02118a50=func_ov062_02118a50")
# (3) src/func_ov060_02111c68.c (slice_w5e) and (4) src/func_ov060_02112350.c
#     (slice_w5e) -- three of ov060's OWN bss cells at addresses ov066's mount
#     now names as Eyerok PMF source pairs (port/ov060_syms.txt lines 128/131/
#     135 carry the ov060 storage). Undefeated, ov060 would read Eyerok's state
#     table.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov060_02111c68.c"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov066_0211ac20=data_ov060_0211ac20;data_ov066_0211ac68=data_ov060_0211ac68")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov060_02112350.c"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov066_0211acd0=data_ov060_0211acd0")

# ---- lane cast-ov066: THREE MIS-SPELLED NAMES IN ONE OWN TU -----------------
# src/func_ov066_021166c8.cpp (InitResources' resource half) spells three
# symbols nothing in the tree defines. All three are settled off that TU's OWN
# literal pool in config/arm9/overlays/ov066/relocs.txt, disassembled out of
# extracted/overlays/overlay_0066.bin, never by name -- the ov036/ov043 trap-4
# discipline.
#
#   func_02112cc8            pool 0x02116890 -> 0x02112cc8   an ov025 CLPS_Block
#   func_02112c88            pool 0x021168a0 -> 0x02112c88   an ov025 CLPS_Block
#   func_02112cd8_updatepos  pool 0x021168a8 -> 0x02039348   NOT 0x02112cd8
#
# The first two are collision-parameter blocks handed to
# MovingMeshCollider::SetFile. Their addresses fall in the LEVEL window and
# dsd's module column names eleven level overlays, every one `ambiguous`; ov066
# is loaded on level 17 alone and level 17's overlay is ov025, so ov025's are
# the ones the ROM means. Both joined port/ov025_syms.txt with this lane (one
# of them pinned to 0x20, see that file). This is the ov046 arena-CLPS shape
# (hal/actor_classes_ov060.cpp:201) with the alias written as a -D instead.
#
# THE THIRD NAME IS SIMPLY WRONG. There is NO reloc to 0x02112cd8 anywhere in
# ov066. The pool word func_020393d4's second argument is loaded from holds
# 0x02039348, module:main, which config/arm9/symbols.txt names
# MeshColliderBase::UpdatePosWithTransform -- an arm9 body, and the callback
# the collider genuinely wants. The recovered name invented an overlay address
# out of the "updatepos" role. src/ is not edited; the rename fixes the one
# call site.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov066_021166c8.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_02112cc8=data_ov025_02112cc8;func_02112c88=data_ov025_02112c88;func_02112cd8_updatepos=_ZN4dBgW22UpdatePosWithTransformERS_P8dActor_cR5dBgPiR7Vector3P10Vector3_16S8_")
# THREE MORE OF THE SAME BLOCKS, in five more TUs, MEASURED off the FIRST
# link's own unresolved list rather than predicted: _func_02112c08,
# _func_02112ca8 and _func_02112d48 came back undefined from
# _ZN6Eyerok13InitResourcesEv.cpp.obj, func_ov066_02116db0.c.obj,
# func_ov066_021175e8.c.obj, func_ov066_02117bf0.c.obj and
# func_ov066_02118188.c.obj. Every one is another ov025 CLPS_Block handed to
# MovingMeshCollider::SetFile, settled the same way -- the TU's own pool word,
# then the level-17 roster. 0x02112d48 is the sharpest of the five: ov060
# claims that address with a real FUNCTION (func_ov060_02112d48, size 0x94)
# and ov060 is NOT on level 17's roster, so the CLPS block is what is resident
# when Eyerok runs. The four .c TUs declare them with C linkage and the one
# .cpp declares them inside its extern "C" block, so all five come out
# undecorated and the rename lands directly on the mount's C name.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN6Eyerok13InitResourcesEv.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov066_02116db0.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov066_021175e8.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov066_02117bf0.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov066_02118188.c"
    PROPERTIES COMPILE_DEFINITIONS
    "func_02112c08=data_ov025_02112c08;func_02112ca8=data_ov025_02112ca8;func_02112d48=data_ov025_02112d48")

# ---- lane cast-ov036: SIX PER-SOURCE PLACEHOLDER AND CROSS-NAME BINDINGS ----
# Every one is settled from the TU's OWN literal pool in
# config/arm9/overlays/ov036/relocs.txt, disassembled out of
# extracted/overlays/overlay_0036.bin, never by name. VT0/VT1/VT2 are the
# dangerous half: all three are DEFINED in this link (actor_vtables.cpp:407,
# `int VT0[20]` and its siblings), so an unrenamed store lands silently on a
# twenty-word shared dummy instead of failing at link -- the CMakeLists:2600
# class. G1 is the safe half (no cdecl row, so it would be a hard link error),
# and bare G0 in a .c resolves through `/alternatename:_G0=_data_020a0eac`,
# which is RIGHT for the three deleting destructors whose pools hold the game
# heap and WRONG for the one Cleanup whose pool holds its own two files.
#
# (1) src/game/actors/d_a_obj_rc_buranko.cpp -- SWINGING_PLATFORM's D0. Pool, in store order:
#     0x02111230 -> 0x02113a98 (its own table, host storage) and
#     0x02111234 -> 0x0210ae38 (_ZTV10dBgActor_c, the dBgActor_c base, already
#     host-filled by hal_fill_platform_vtable). Its G0 is NOT renamed: the third
#     pool word 0x02111238 -> 0x020a0eac module:main is the game heap
#     Memory::Deallocate takes, which is exactly what the cdecl row binds.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_rc_buranko.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   VT0=_ZTV16daObjRcBuranko_c  --  dead, the TU does not spell VT0
#   VT1=_ZTV10dBgActor_c  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
# (2) src/game/actors/d_a_obj_rc_buranko.cpp -- SWINGING_PLATFORM's CleanupResources.
#     Releases two SharedFilePtrs as G0/G1, and its own pool names them:
#     0x021112c0 -> 0x02114028 then 0x021112c4 -> 0x02114020, both
#     module:overlay(36), both in this lane's own mount. Unrenamed, G0 would
#     Release the game heap and G1 would not link. Renamed straight to the mount
#     names rather than to private ones: include/decl_common.h declares neither
#     data_ov036_02114020 nor data_ov036_02114028, so there is nothing to
#     conflict with (the ov043 TRAP-3 reading; the ov100 C2040 needed private
#     names only because the target was already declared as a scalar).
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_rc_buranko.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   G0=data_ov036_02114028  --  dead, the TU does not spell G0
#   G1=data_ov036_02114020  --  dead, the TU does not spell G1
# Deleted rather than merged. The surviving row is unchanged.
# (3) src/game/actors/d_a_obj_rc_kaitendai.cpp -- NO COMPILE_DEFINITIONS AT ALL,
#     AND THAT IS THE FIX (wave 10, lane UNHOSTED). Before the main-to-port sync
#     this class was three one-function files, each with a row of its own:
#       src/func_ov036_02111444.c (D1)
#         _ZTV19daObjRc_Kaitendai_c=data_ov036_02113b74;_ZTV10dBgActor_c=data_ov002_021091d4;VT2=_ZTV8Platform
#       src/func_ov036_02111494.c (D0)
#         VT0=data_ov036_02113b74;VT1=data_ov002_021091d4;VT2=_ZTV8Platform
#       src/RotatingPlatformRr_Spawn.c (the factory)
#         _ZTV19daObjRc_Kaitendai_c=data_ov002_021091d4;VT1=data_ov036_02113b74
#     The factory row existed because the RECOVERED source spelled the BASE store
#     with the DERIVED class's name. The synced TU does not. Its
#     daObjRc_Kaitendai_c_classInit writes
#       p[0] = (int)_ZTV16daObjKaitendai_c;     the ov002 intermediate, 0x021091d4
#       p[0] = (int)_ZTV19daObjRc_Kaitendai_c;  its own table,          0x02113b74
#     which is the cartridge's own order and the cartridge's own two values:
#       0211155c ldr r1,[pc,#0x14] -> 0x02111578 -> 0x021091d4 daObjKaitendai_c
#       02111560 ldr r0,[pc,#0x14] -> 0x0211157c -> 0x02113b74 its own table
#       02111564 str r1,[r4]   02111568 str r0,[r4]
#     and the TU spells no VT0/VT1/VT2/G0 placeholder anywhere. It does not write
#     the destructors either: the inline ~daObjRc_Kaitendai_c() in the header is
#     the whole source of both variants, so _ZTV10dBgActor_c never appears in it.
#     The three rows were carried across the sync BY NAME instead of by address,
#     and only the LAST set_source_files_properties for a file takes effect, so
#     once the TU merge collapsed all three onto one path the surviving binding
#     was _ZTV19daObjRc_Kaitendai_c=_ZTV16daObjKaitendai_c: BOTH stores then wrote
#     the abstract intermediate, every ROTATING_PLATFORM_RR on level 28 dispatched
#     through the base table, and its slot 0 is ov36_base_trap0 -- "UNHOSTED:
#     vtable slot 0 (abstract base InitResources)", the ROM word there being zero.
# (6) THE THREE ROM-NAME SPELLINGS OF A TABLE THIS LANE ALREADY HOSTS UNDER ITS
#     config NAME. Each pair is the SAME address under two labels dsd emitted,
#     and the port needs one storage, so the ROM spelling is folded onto the
#     config one the fill declares. Confirmed per TU against its own pool:
#       _ZN14daObjRc_Hane_cD0Ev.c  0x021115ec -> 0x02113c38 == _ZTV18RotatingPlatformRr
#       _ZN10DonutBlockD1Ev.c             0x02111980 -> 0x02113cf8 == _ZTV8ShipWing
#       _ZN10DonutBlockD0Ev.c             0x021119dc -> 0x02113cf8 == _ZTV8ShipWing
#       _ZN18daObjRc_Guruguru_cD1Ev.c          0x02111d50 -> 0x02113dcc == _ZTV18daObjRc_Guruguru_c
#       _ZN18daObjRc_Guruguru_cD0Ev.c          0x02111da4 -> 0x02113dcc == _ZTV18daObjRc_Guruguru_c
#       _ZN16daObjRcBuranko_cD1Ev.c          0x02111230 -> 0x02113a98 == _ZTV16daObjRcBuranko_c
#     The last one goes the OTHER way -- onto the config name rather than onto
#     the _ZTV one -- because config names 0x02113a98 only _ZTV16daObjRcBuranko_c,
#     and vtspan --sweep can only size an array whose name it can look up.
#     The _ZTV10dBgActor_c in the four ShipWing/DonutBlock destructors is NOT
#     renamed: their pools hold 0x0210ae38, which is what the port's own
#     _ZTV10dBgActor_c array already is (hal/actor_classes.cpp fills it and
#     _ZTV10dBgActor_c with identical contents). Only the ROTATING_PLATFORM_RR pair
#     above spells that name for a different table.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_rc_hane.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZTV14daObjRc_Hane_c=_ZTV18RotatingPlatformRr")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10DonutBlockD1Ev.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10DonutBlockD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZTV16daObjRc_Tikuwa_c=_ZTV8ShipWing")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_rc_guruguru.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_rc_guruguru.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZTV18daObjRc_Guruguru_c=_ZTV18daObjRc_Guruguru_c")
#     daObjRcBuranko_c_classInit.c needs NO rename: it already spells
#     _ZTV16daObjRcBuranko_c, which is the canonical host array name (see the
#     vtspan note in hal/actor_classes_ov036.cpp -- config names 0x02113a98
#     only that way, so the host-only _ZTV16daObjRcBuranko_c spelling would
#     have gone unsized). src/game/actors/d_a_obj_rc_buranko.cpp, SWINGING_PLATFORM's D1,
#     is the one TU that spells the host-only name; its pool at 0x02111230 is
#     0x02113a98, module:overlay(36).
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_rc_buranko.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZTV16daObjRcBuranko_c=_ZTV16daObjRcBuranko_c")
# (7) AN ALIAS THIS MOUNT DEFEATS, AND THE ONE LIVE READER IT HAD.
# ov018, ov022, ov036 and ov056 share the level-overlay base 0x021111a0, and
# ov036's dsd export won the naming race at 0x021140d4, so
# src/_ZN21FloatingFloorLllSmall13InitResourcesEv.cpp (ov022's
# FLOATING_FLOOR_LLL_SMALL, id 76, level 14, LINKED via
# port/slice_w8packs.txt:51) reaches ov022's OWN six-word file/CLPS table under
# ov036's spelling. hal/actor_classes_ov022.cpp routed that with
# `/alternatename:_data_ov036_021140d4=_data_ov022_021140d4`, and an
# /alternatename is defeated the moment its LHS is DEFINED -- which is exactly
# what this lane's mount now does (data_ov036_021140d4 is one of
# TRICKY_TRIANGLES' ten SharedFilePtrs, built by __sinit_ov036_0211279c).
# Unfixed, FLOATING_FLOOR_LLL_SMALL on level 14 would load its models out of
# Rainbow Cruise's cells: no link error, no byte-gate signal, wrong object at
# run time -- the Coffin/Spindrift shape, caught here by
# port/tools/alternatename_guard.py's post-link map check.
# The guard's own remedy, and the wave-5 R1/R2 recipe: the reader gets a
# per-source -D onto the name it actually means, and the now-inert directive is
# retired at its own site rather than left reading as live routing.
# FOUR MORE TUs spell an ov036 name for another overlay's object at the shared
# base -- src/__sinit_ov025_021129dc.c (02113a98), src/actors/daDgr_c.cpp
# (02113a60), src/__sinit_ov026_02112d68.c (02113f58) and
# src/__sinit_ov027_02112df8.cpp (02113cb4/cc0/ccc). NONE of the four is in any
# slice or in any map, so nothing races today; they are ov025's, ov026's and
# ov027's names to fix when those lanes land, and alternatename_guard will say
# so at the link if one arrives.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN21FloatingFloorLllSmall13InitResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS "data_ov036_021140d4=data_ov022_021140d4")

# run rel0215 wave 2 (lane cast-ov090): SKEETER (230) + MANTA_RAY (226) +
# CHEEP_CHEEP (227) + SHARK (225), ov090, the water enemy pack levels 18 and 21
# both name. Fresh per-symbol ov090 mount (port/ov090_syms.txt). The four
# vtable fills and the sixteen-record PMF state seat are
# hal/actor_classes_ov090.cpp; the twelve host-copied TUs (four ModelAnim
# slot-5 Renders, four PMF state setters, four Behaviors whose tick half
# dispatches the same way, two of which additionally construct a PathPtr as a
# real C++ object) are the four unmatched/*_HostSites.cpp files, each refusal
# itemised in port/slice_ov090.txt. The gate-64 shape: the hal file and the
# host copies ride in the slice's own SOURCES list, so the target lists take
# one token. ov090 has NO missing and NO NONMATCHING body -- 70 of 70 present
# -- so there is no loud L2 face in this pack.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov090.txt" SLICE_OV090_LINES)
set(SLICE_OV090_SOURCES "")
foreach(line IN LISTS SLICE_OV090_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV090_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_OV090_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_ov090.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Skeeter_HostSites.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/MantaRay_HostSites.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/CheepCheep_HostSites.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Shark_HostSites.cpp")

# ---- lane cast-ov090: THREE CROSS-OVERLAY NAME BINDINGS, ALL BY ADDRESS ----
# Every one is settled from the crossing TU's OWN relocation in
# config/arm9/overlays/<ov>/relocs.txt -- the `module:` column, read against
# the raw bytes in extracted/overlays/ -- never from a dsd label. Two point
# outward from ov090 and one points inward at it. All three are -D renames
# rather than /alternatename for the same reason the ov036 lane's (7) is: this
# lane's mount DEFINES the names an alias would need to leave undefined.
#
# (a) src/func_ov090_02131608.cpp spells _ZN6Fwoosh13OnYoshiTryEatEv for ov090's OWN
#     data_ov090_02134498. ov090's own pool reloc is
#     `from:0x02131644 kind:load to:0x02134498 module:overlay(90)`. 0x02134498
#     is a SharedFilePtr in ov090's .bss that __sinit_ov090_02133ce8 constructs
#     with file id 0x3a3, and the TU reads its second word as a FILE POINTER
#     and hands it to ModelAnim::SetAnim. ov091's .text runs to 0x021344e8, so
#     the ov091 name is a real FUNCTION there and src/_ZN6Fwoosh13OnYoshiTryEatEv.cpp
#     exists -- left alone this links clean and calls the wrong thing.
#
# (b) src/func_ov090_02133830.c spells _ZN5Stump6RenderEv for ov090's OWN
#     func_ov090_02133710. ov090's own pool reloc is
#     `from:0x02133874 kind:load to:0x02133710 module:overlay(90)`, and
#     0x02133710 sits inside SHARK's .text block (0x0213367c..0x02133ca0) --
#     as does 0x02133830 itself, which is Shark's own body. src/
#     _ZN5Stump6RenderEv.cpp exists, so this too links clean and runs the
#     wrong body on any level that loads both overlays.
#
# (c) AN ALIAS THIS MOUNT DEFEATS, AND ITS ONE LIVE READER -- the ov036 (7)
#     shape exactly. src/func_ov006_020d5e5c.c declares
#     `extern int data_ov090_021343b0[]` for what is ov006's own minigame table
#     (`from:0x020d5eb4 kind:load to:0x021343b0 module:overlay(6)`, and
#     0x020d5eb4 is that TU's own literal pool). In ov090 the same address is
#     SHARK's typeinfo NAME STRING, "9daShark_c".
#     port/unmatched/MgBomroom_Faces.cpp routed that with
#       /alternatename:_data_ov090_021343b0=_data_ov006_021343b0
#     whose own header recorded that its LHS is "DEFINED NOWHERE ELSE IN THE
#     LINK". THIS MOUNT DEFINES IT, so the alias goes inert and mg6's
#     dScMgBomroom_c would read Shark's name string as an OAM table -- no link
#     error, no byte-gate signal, wrong object at run time. The routing is the
#     -D below, the guard's own remedy, and it survives the LHS becoming
#     defined the way the alias could not.
#
#     WHAT THE RETIRED SEAT FILE SAID, folded here because the file is gone.
#     port/unmatched/MgBomroom_Faces.cpp was deleted in run rel0215 (lane
#     cleanup-w2): the ov090 lane took its one directive out and left 68 lines
#     of comment compiling to an empty object, and prose belongs beside the
#     routing that is live rather than in a translation unit that emits
#     nothing. Three things it recorded that are not obvious from the -D:
#       * AN ADDRESS ALONE DOES NOT NAME A SYMBOL. 0x021343b0 is a live symbol
#         in BOTH config trees -- ov090/symbols.txt:108 data_ov090_021343b0 and
#         ov006/symbols.txt:2381 data_ov006_021343b0 -- because the two
#         overlays share an address window. Only the relocation's module field
#         decides, which is why every one of these three notes quotes it. It is
#         the finding lane CCN's closure walker hit when resolving by address
#         reported the overlay window four times over.
#       * THE DECOMP-SIDE FIX IS ROUTED, NOT TAKEN. src/func_ov006_020d5e5c.c
#         should declare data_ov006_021343b0; whether it still builds
#         byte-identically under mwccarm is a byte-gated-tree question. src/ is
#         not edited from here, so the -D is the whole port-side answer.
#       * ov090 IS NOT CO-RESIDENT WITH A MINIGAME SCENE ANYWAY. The resident
#         set for scene 370 is main + itcm + ov001 + ov004 + ov006, which is
#         what makes this mount define the ov006 name and nothing define the
#         ov090 one.
#     Same retirement, same reason, as lane cast-ov036's on
#     hal/actor_classes_ov022.cpp's data_ov036_021140d4 alias one wave earlier.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov090_02131608.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZN6Fwoosh13OnYoshiTryEatEv=data_ov090_02134498")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov090_02133830.c"
    PROPERTIES COMPILE_DEFINITIONS "_ZN5Stump6RenderEv=func_ov090_02133710")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020d5e5c.c"
    PROPERTIES COMPILE_DEFINITIONS "data_ov090_021343b0=data_ov006_021343b0")

# run rel0215 wave 3 (lane w3-f2): ov091's THREE DECLINED IDS --
# ARROW_PATH_LIFT (157) and SQUARE_METAL_NET_LIFT (144), which SHARE ONE CLASS
# (RotatingUpDownPlatform / 13daLinelift2_c, ov091 0x02134ec0, 32 slots -- both
# factories' single pool literal), and FWOOSH (231) (Stump / 10daHyuhyu_c,
# 0x021353ac, 31 slots). Placed on levels 39, 37 and 22 and declined on all
# three in this branch's base censuses.
#
# NO MOUNT IS ADDED, which is what makes this seat cheap. ov091 is already
# mounted whole per symbol by port/ov091_syms.txt (gate 32, the mount
# ChainChomp::InitResources drags in) and BOTH vtable spans are already gaps in
# that list -- 0x02134ec0..0x02134f40 between g_profile_KM2_SUSUMU and
# _ZTI17daObjSimpleLift_c, 0x021353a4..0x02135440 between g_profile_HYUHYU and
# data_ov091_02135440. All nine pointer-to-member SOURCE records and all three
# of FWOOSH's bss cells are mounted at their true sizes too, so there is no T3
# size audit here: no syms row was added.
#
# The two fills and the nine-record PMF state seat are
# hal/actor_classes_ov091.cpp; the five host-copied TUs (three pointer-to-member
# dispatch sites, FWOOSH's ModelAnim slot-5 Render, and one MSVC front-end
# refusal on a NONMATCHING body's ARM asm hatch -- the last two both found by
# running rather than by reading) are unmatched/Ov091_HostSites.cpp, itemised in
# port/slice_w3f2.txt. The gate-64 shape: the hal file and the host copy ride in
# the slice's own SOURCES list, so the target lists take one token.
#
# THE SHARED-WINDOW CROSS-SPELLING AUDIT, BOTH DIRECTIONS. ov090, ov091 and
# ov092 all load at 0x02130f00 and the two landed ov090/ov092 seats are in this
# link. This slice DEFINES _ZN6Fwoosh13OnYoshiTryEatEv for the first time, which is the
# right-hand side of the ov090 lane's rename twenty lines above. Nothing breaks
# and the reason is worth stating: that routing is a per-source -D, a
# compile-time textual rename inside ov090's own TU, and a -D cannot be defeated
# by a definition appearing elsewhere. An /alternatename in its place WOULD have
# gone inert the moment this slice landed -- this seat is exactly the event lane
# cast-ov090 chose -D to survive. Checked the other direction too: no
# /alternatename anywhere in port/ has an LHS this slice defines, and the two
# aliases below have LHS names that are declared in include/decl_common.h
# (446, 531) and defined nowhere.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w3f2.txt" SLICE_W3F2_LINES)
set(SLICE_W3F2_SOURCES "")
foreach(line IN LISTS SLICE_W3F2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W3F2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_W3F2_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_ov091.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Ov091_HostSites.cpp")
# ONE OF THIS SLICE'S TWENTY .c FILES IS REALLY C++ -- a //cpp marker and
# top-level `extern "C"` declarations, which as C is a syntax error on line 3.
# Found by the comment-stripped token sweep over all twenty (//cpp, extern "C",
# class, virtual, ::), not by waiting for a compile failure. The other nineteen
# are C, and all thirty-one were syntax-checked with this slice's own flags.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov091_02133c6c.cpp"
    PROPERTIES LANGUAGE CXX)


# run rel0215 wave 2 (lane cast-ov027): ov027's Snowman's Land cast --
# SLIDING_ICE_SPAWNER (92), SLIDING_ICE (93), CHILL_BULLY (217), DA_PG_DFDR
# (258) and SNOWMAN_BREATH (275), level 19. Per-symbol ov027 mount
# (port/ov027_syms.txt). The fill is hal/actor_classes_ov027.cpp. Two TUs are
# NOT in the slice: src/actors/daPgDfdr_c.cpp and src/actors/daPgDfdr_c.cpp,
# DA_PG_DFDR's two pointer-to-member dispatch sites -- host-copied in
# unmatched/DaPgDfdr_StateDispatch.cpp, originals byte-locked in src/. There is
# NO external closure line: every arm9/ov002/ov062/ov064 body this closure
# reaches was already linked on the base tip, checked against walk_window.map
# before the first configure and confirmed by the first link's own unresolved
# list.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov027cast.txt" SLICE_OV027CAST_LINES)
set(SLICE_OV027CAST_SOURCES "")
foreach(line IN LISTS SLICE_OV027CAST_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV027CAST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# ---- lane cast-ov027: NINE WRONG-OVERLAY NAMES AND SIX PLACEHOLDER BINDINGS -
# Every one is settled from the TU's OWN literal pool or its own call reloc in
# config/arm9/overlays/ov027/relocs.txt, disassembled out of
# extracted/overlays/overlay_0027.bin, never by name.
#
# ov009/ov014/ov015/ov016/ov018/ov020/ov021/ov022/ov024/ov025/ov026/ov027/
# ov029/ov030/ov032/ov033/ov034/ov035/ov036/ov043/ov045/ov053/ov056 all share
# the level-overlay load window at base 0x021111a0, and dsd's export won the
# naming race at nine addresses that are ov027's OWN. The task sheet flagged
# two of them. A sweep of all 53 TUs against every overlay's symbol table found
# SEVEN MORE SPELLINGS, and five of the nine are SILENT today -- the name is
# already DEFINED in this link, so the reference binds to another overlay's
# object with no link error and no byte-gate signal (the Coffin/Spindrift
# shape, T6). Status measured against build/port/walk_window.map on the base
# tip, not assumed:
#
#   spelling                      really            defined now?  failure mode
#   data_ov036_02113cb4/cc0/ccc   ov027 bss nodes   YES ov036     SILENT
#   data_ov035_02112ca4           ov027 rodata      YES ov035     SILENT
#   _ZN7daMky_c11EnterState2Ev           ov027 bss ptr     YES ov030     SILENT, worst
#   _ZTS17daObjKm1_Kuruma_c           ov027 CODE        YES ov043     SILENT
#   g_profile_RC_KAITEN  ov027 vtable      YES ov036     SILENT
#   data_ov056_02112158           ov027 CODE        no            hard link error
#   data_ov033_0211233c           ov027 CODE        no            hard link error
#   data_ov053_021123b0           ov027 CODE        no            hard link error
#
# (1) src/__sinit_ov027_02112df8.cpp -- THE TASK SHEET'S FIRST TRAP. Three
#     names, all ov027's own destructor-chain nodes. Its own literal pool, in
#     source order, is at 0x02112f08..0x02112f5c and the three rows are:
#       from:0x02112f30 kind:load to:0x02113cb4 module:overlay(27)
#       from:0x02112f3c kind:load to:0x02113cc0 module:overlay(27)
#       from:0x02112f4c kind:load to:0x02113ccc module:overlay(27)
#     config/arm9/overlays/ov027/symbols.txt lists all three as ov027 bss.
#     ov036's mount landed in wave 1 and port/ov036_syms.txt:294-295 DEFINES
#     all three, so unrouted this sinit registers DA_PG_DFDR's three Anim-file
#     destructor nodes into Rainbow Cruise's mounted cells.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/__sinit_ov027_02112df8.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov036_02113cb4=data_ov027_02113cb4;data_ov036_02113cc0=data_ov027_02113cc0;data_ov036_02113ccc=data_ov027_02113ccc")
# (2) src/actors/daPgDfdr_c.cpp -- THE TASK SHEET'S SECOND TRAP. DA_PG_DFDR's
#     CleanupResources, whose three-iteration SharedFilePtr::Release loop reads
#     data[0..2]. Both of this TU's loads of that address say overlay(27):
#       from:0x02111df0 kind:load to:0x02112ca4 module:overlay(27)
#       from:0x02112050 kind:load to:0x02112ca4 module:overlay(27)
#     and 0x02112ca4's own three words relocate to 0x02113c84/0x02113c74/
#     0x02113c8c, the three Anim SharedFilePtrs sinit 02112df8 builds -- so the
#     table is unmistakably this class's. port/ov035_syms.txt:295 DEFINES
#     data_ov035_02112ca4:0xc (ov035's id-119 collision chain node), so
#     unrouted this TU Releases Tick Tock Clock's chain node three times.
#     include/decl_common.h:3079 already declares data_ov027_02112ca4 as
#     void*[3], which is the right type and the right width.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names daPgDfdr_c.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   data_ov035_02112ca4=data_ov027_02112ca4  --  dead, the TU does not spell data_ov035_02112ca4
# Deleted rather than merged. The surviving row is unchanged.
# (3) SLIDING_ICE's TWO RESOURCE METHODS, and this is the worst of the nine.
#     Both spell _ZN7daMky_c11EnterState2Ev for ov027's own model SharedFilePtr, and
#     ov030's 0x02113be8 is a 0x138-byte FUNCTION that wave 1 linked
#     (walk_window.map: _func_ov030_02113be8 in _ZN7daMky_c11EnterState2Ev.c.obj).
#     InitResources passes it to Model::LoadFile and reads [1] back out;
#     CleanupResources calls SharedFilePtr::Release on it. Unrouted, the port
#     WRITES the loaded BMD_File pointer into Tall Tall Mountain's code. Each
#     TU's own pool names the address:
#       from:0x02111554 kind:load to:0x02113be8 module:overlay(27)   (Init)
#       from:0x021112ac kind:load to:0x02113be8 module:overlay(27)   (Cleanup)
#     and __sinit_ov027_02112cb0 constructs 0x02113be8 with asset 1713.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10SlidingIce13InitResourcesEv.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10SlidingIce16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZN7daMky_c11EnterState2Ev=data_ov027_02113be8")
# (4) src/_ZN13SnowmanBreath6RenderEv.cpp -- a CALL, not a load. The body loops
#     `_ZTS17daObjKm1_Kuruma_c(p)` fifty times over the object's fifty sub-elements
#     at +0xd4 stride 0x60. The reloc is a call and it names this overlay:
#       from:0x0211277c kind:arm_call to:0x02112424 module:overlay(27)
#     0x02112424 is _ZN21SnowmanBreathParticle6RenderEv, inside ov027's own .text. ov043's
#     mount DEFINES _ZTS17daObjKm1_Kuruma_c (port/ov043_syms.txt:153), so unrouted
#     this Render executes ov043 romdata BYTES as code, fifty times a frame.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13SnowmanBreath6RenderEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTS17daObjKm1_Kuruma_c=_ZN21SnowmanBreathParticle6RenderEv")
# (5) SNOWMAN_BREATH's TWO DESTRUCTORS, two wrong names each. Both spell
#     g_profile_RC_KAITEN for the VPTR STORE -- and that is ov036's id
#     129 record, at 0x02113b50, which is exactly where ov027 parks
#     SnowmanBreath's own vtable. Wave 1 mounted it, so unrouted these two
#     destructors write the address of Rainbow Cruise's SpawnInfo record into
#     the object's vptr and every virtual after that reads a spawn record as a
#     table. Both also spell data_ov056_02112158 for the per-element destructor
#     they hand __cxa_vec_cleanup, which is ov027's own _ZN21SnowmanBreathParticleD1Ev (that
#     one is undefined today, so it would at least fail loudly). Pools:
#       D1  from:0x021120fc load -> 0x02113b50 module:overlay(27)
#           from:0x02112100 load -> 0x02112158 module:overlay(27)
#       D0  from:0x0211214c load -> 0x02113b50 module:overlay(27)
#           from:0x02112150 load -> 0x02112158 module:overlay(27)
#     daSnmBth_c_classInit's own pool holds the same two words and spells them
#     correctly (_ZTV13SnowmanBreath and _ZN21SnowmanBreathParticleD1Ev), which is the
#     third read that settles both.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13SnowmanBreathD1Ev.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13SnowmanBreathD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "g_profile_RC_KAITEN=_ZTV13SnowmanBreath;data_ov056_02112158=_ZN21SnowmanBreathParticleD1Ev")
# (6) src/_ZN21SnowmanBreathParticle8BehaviorEv.cpp -- two calls, two wrong overlays, both really
#     ov027's own bodies. Neither name is defined in the link today, so this
#     pair fails loudly rather than silently; routed anyway, by address:
#       from:0x021124a0 kind:arm_call to:0x021123b0 module:overlay(27)
#       from:0x021124a8 kind:arm_call to:0x0211233c module:overlay(27)
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN21SnowmanBreathParticle8BehaviorEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov033_0211233c=_ZN21SnowmanBreathParticle12CheckSnowmanEv;data_ov053_021123b0=_ZN21SnowmanBreathParticle14UpdatePositionEv")
# ---- the placeholder half: VT0/VT1 and the host-only _ZTV spellings ---------
# VT0/VT1 are the dangerous ones: both are DEFINED in this link
# (hal/actor_classes.cpp, `int VT0[20]` and its sibling), so an unrenamed store
# lands silently on a twenty-word shared dummy instead of failing at link.
# Every VT0/VT1 in this overlay's 53 TUs is bound below; the sweep found four
# TUs using them and no others. G0 is NOT renamed anywhere here: all three
# bodies that spell it (SlidingIce's D0, CHILL_BULLY's D0, DA_PG_DFDR's D0)
# carry 0x020a0eac in their pools, which is the game heap Memory::Deallocate
# takes and exactly what `/alternatename:_G0=_data_020a0eac`
# (hal/cxx_aliases.cpp:1272) resolves it to. _ZTV10dBgActor_c is NOT renamed
# either: both pools that spell it hold 0x0210ae38, which is what the port
# already defines that name as.
#
# (7) SLIDING_ICE's D1 and D0 spell _ZTV17daObjSlIceBlock_c (the ROM RTTI name)
#     for the table config calls _ZTV10SlidingIce. Same address under two
#     labels; the port needs one storage, so the ROM spelling folds onto the
#     config one the fill declares. Both pools, in store order (disassembled:
#     `ldr r2 <- 02113824; ldr r1 <- 0210ae38; str r2,[r4]; str r1,[r4]`):
#       D1  0x021111dc -> 0x02113824      0x021111e0 -> 0x0210ae38
#       D0  0x02111230 -> 0x02113824      0x02111234 -> 0x0210ae38
#                                         0x02111238 -> 0x020a0eac (G0, left)
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10SlidingIceD1Ev.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10SlidingIceD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV17daObjSlIceBlock_c=_ZTV10SlidingIce")
# (8) CHILL_BULLY's D1: _ZTV12daIDonketu_c is its OWN table and VT1 is ov064's
#     Bully base. Pool in store order, disassembled at 0x021115c8:
#       ldr r2 <- @02111610 -> 0x02113930   (own table)
#       ldr r1 <- @02111614 -> 0x0211b768   (ov064 Bully/BigBully base, 37)
#       str r2,[r4] ; str r1,[r4]
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_i_donketu.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV12daIDonketu_c=data_ov027_02113930  --  dead, the TU does not spell _ZTV12daIDonketu_c
#   VT1=data_ov064_0211b768  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
# (9) CHILL_BULLY's D0: the same two stores in the same order, plus the heap.
#       0x02111674 -> 0x02113930   0x02111678 -> 0x0211b768
#       0x0211167c -> 0x020a0eac (G0, left on the cdecl row)
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_i_donketu.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   VT0=data_ov027_02113930  --  dead, the TU does not spell VT0
#   VT1=data_ov064_0211b768  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
# (10) src/game/actors/d_a_i_donketu.cpp -- THE ONE MIS-BOUND PAIR INSIDE A TU, and it is
#      the exact inverse of (8). The ROM stores the BASE table first and the
#      derived one last, which is the correct constructor shape, but the
#      recovered source calls the FIRST store _ZTV12daIDonketu_c (the derived
#      class's own name, on the base object) and the LAST one VT1. Settled by
#      DISASSEMBLY, not by pool order -- the pool is laid out the other way
#      round from the store order, which is exactly the trap:
#        02111880  bl 020aed98              Enemy::C2
#        02111884  ldr r1,[pc,#52] -> @021118c0 -> 0211b768
#        0211188c  str r1,[r4,#0]           FIRST store  = the ov064 BASE
#        02111890  bl 02016958              ModelAnim::C1     at +0x110
#        02111898  bl 02037430              WithMeshClsn::C1  at +0x174
#        021118a0  bl 020149c8              MovingCylinderClsn::C1 at +0x33c
#        021118a8  bl 02016068              ShadowModel::C1   at +0x370
#        021118ac  ldr r0,[pc,#16] -> @021118c4 -> 02113930
#        021118b0  str r0,[r4,#0]           SECOND store = its OWN table
#      So the SAME spelling means the opposite table in this TU and in (8),
#      which is why an /alternatename could never have routed this pair and the
#      binding has to be per source. Neither definition expands to the other,
#      so there is no macro rescan.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_i_donketu.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV12daIDonketu_c=data_ov064_0211b768;VT1=data_ov027_02113930")
# (11) DA_PG_DFDR's D1 and its factory both spell _ZTV10daPgDfdr_c for the
#      table config calls _ZTV10daPgDfdr_c. Pools, disassembled:
#        D1       0x0211191c -> 0x02113a90   then 0x02111920 -> 0x0210ae38
#                 (store order: own table, four member teardowns, then dBgActor)
#        factory  0x021120c0 -> 0x02113a90
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names daPgDfdr_c.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV10daPgDfdr_c=_ZTV10daPgDfdr_c  --  identity rename, a no-op even if it had run
# Deleted rather than merged. The surviving row is unchanged.
# (12) DA_PG_DFDR's D0: the same two stores as its D1 twin, same order, plus
#      the heap. 0x02111988 -> 0x02113a90, 0x0211198c -> 0x0210ae38,
#      0x02111990 -> 0x020a0eac (G0, left).
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daPgDfdr_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV10daPgDfdr_c;VT1=_ZTV10dBgActor_c")


# run rel0215 wave 2 (lane w2-ov074): GOOMBOSS (198) + EXPLOSION_GOOMBA (199),
# ov074, level 45 (Mario's key arena). Fresh per-symbol ov074 mount
# (port/ov074_syms.txt). The fill, the nine-cell PMF state seat and the three
# loud faces for the overlay's three missing bodies are
# hal/actor_classes_ov074.cpp; the four host-copied TUs (two ModelAnim slot-5
# Renders, two PMF dispatch sites) are unmatched/Goomboss_HostSites.cpp and
# unmatched/Goomboss_StateDispatch.cpp, each refusal itemised in
# port/slice_ov074.txt. The gate-64 shape: the hal file and the host copies
# ride in the slice's own SOURCES list, so the target lists take one token.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov074.txt" SLICE_OV074_LINES)
set(SLICE_OV074_SOURCES "")
foreach(line IN LISTS SLICE_OV074_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV074_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# run link100 lane PMF3 (R9c): unmatched/Goomboss_StateDispatch.cpp was the
# two pointer-to-member dispatchers and nothing else, and both are back on the
# slice as matched TUs, so the file is deleted and its row comes out here.
list(APPEND SLICE_OV074_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_ov074.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Goomboss_HostSites.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Goomboss_InitResources.cpp")

# lane w2-ov074: THE TWO .c FILES IN THIS SLICE THAT ARE REALLY C++.
# The comment-stripped token sweep (`extern "C"`, virtual, class, namespace,
# bool, new, delete, template, true, false, ::) plus the //cpp marker check was
# run over all the .c lines rather than waiting for a compile error. A third
# file hit the sweep and is a HOST COPY rather than a slice line
# (src/_ZN8Goomboss13InitResourcesEv.cpp -- MSVC C2561, see
# unmatched/Goomboss_InitResources.cpp). A fourth matched and is NOT C++:
# src/actors/Goomboss.cpp matches `false` because it DEFINES it
# (`#define false 0`), which is the false positive that sweep has to tolerate
# to stay cheap -- and compiling it as C++ would break on the macro.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/Goomboss.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov074_02121800.c"
    PROPERTIES LANGUAGE CXX)

# lane w2-ov074: THE ENEMY CONSTRUCTOR, one of the three plain C names off the
# first link's own unresolved list. Both factories call `func_020aed98(p)` --
# ov074's relocation reads `to:0x020aed98 module:overlays(2,7)`, ambiguous, and
# the class settles it: _ZTV8Goomboss's vtable[-1] typeinfo names base
# 0x021081c0, whose name string reads "12dEnemyBase_c". The port's spelling of
# that constructor is _ZN12dEnemyBase_cC2Ev (hal/cxx_aliases.cpp:1434, and the ov073
# lane's port_factory_chief_chilly calls it under that name).
# BOTH FACTORIES NAME THE RECEIVER, so the ChainChomp / ChiefChilly r0
# ride-through problem (port/hal/bob_enemy_bridges.cpp:308) does not apply here
# and neither factory needs a host copy -- a rename is enough.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_kuri_king_kuriking.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_kuri_king_kuriking_vanish.cpp"
    PROPERTIES COMPILE_DEFINITIONS "func_020aed98=_ZN12dEnemyBase_cC2Ev")

# lane w2-ov074: TWO ALIASES THIS MOUNT DEFEATS, AND BOTH HAVE A LIVE READER.
# ov070, ov071, ov073 and ov074 share the load window at base 0x0211f000, and
# two /alternatename pragmas in the tree have an ov074 NAME as their LHS. An
# /alternatename is defeated the moment its LHS is DEFINED, which is exactly
# what this lane's mount and slice now do. The wave-5 R1/R2 recipe, the same
# one the ov036 block above applies: the reader gets a per-source -D onto the
# name it actually means, and the now-inert directive is retired at its own
# site rather than left reading as live routing. Unfixed, neither would fail at
# link and neither would show in the byte gate -- the Coffin/Spindrift shape,
# caught by port/tools/alternatename_guard.py's post-link map check.
#
# (4a) src/func_ov071_021209c8.cpp spells its texture-sequence SharedFilePtr
#      `data_ov074_02123038`. ov071's own relocation from 0x02120a1c is
#      module:overlay(71), so it means ov071's bss -- the ruling
#      hal/actor_classes_ov071.cpp already recorded, unchanged. ov074's own
#      relocations cite the same address three times as module:overlay(74) and
#      its sinit Constructs it with file id 0x38f, so this mount defines the
#      name for real. The TU includes no headers, so the rename is direct.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov071_021209c8.cpp"
    PROPERTIES COMPILE_DEFINITIONS "data_ov074_02123038=data_ov071_02123038")
# (4b) src/game/actors/daBrq_c.cpp reads
#      `struct SharedFilePtr *func_ov074_021222e0[2]` -- ov070's own
#      two-pointer file table at the same window address -- under the ov074
#      FUNCTION spelling. hal/cxx_aliases.cpp's own comment predicted this
#      collision word for word. ov074's function there is real (0xdc bytes) and
#      Goomboss::Render calls it, so the name has to resolve to CODE now.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/daBrq_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS "func_ov074_021222e0=data_ov070_021222e0")


# ============================================================================
# RUN REL0215 WAVE 2, LANE CAST-SWEEP2 -- the four-overlay cast sweep.
#
# ov032 (24), ov034 (26), ov047 (39), ov055 (47), each landing as its own
# commit. This region grows by one block per overlay and is the ONLY place in
# this file the lane appends more than once. The three target source lists take
# ${SWEEP2_SOURCES} exactly once, so a second overlay costs the coordinator
# nothing outside this region -- the wave-1 cast-sweep1 shape, chosen for the
# same reason.
set(SWEEP2_SOURCES "")

# ---- 1/4: ov032, level 24 (Tiny-Huge Island, big side) ---------------------
# HUGE_COVER (106) x1, HUGE_WATER (107) x1 and BUBBA (228) x2 -- four of level
# 24's seven skipped instances. Thirty-eight of the overlay's forty-one TUs;
# the other three are BUBBA's PMF state-enter setter, its Behavior and its
# ModelAnim slot-5 Render, all three host-copied below. Two 32-slot Platform
# tables and one 31-slot Enemy table, and dsd's only vtable label sits twice on
# the wrong one. See port/ov032_syms.txt and port/slice_sweep2_ov032.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sweep2_ov032.txt" SLICE_SWEEP2_OV032_LINES)
set(SLICE_SWEEP2_OV032_SOURCES "")
foreach(line IN LISTS SLICE_SWEEP2_OV032_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SWEEP2_OV032_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# id 106's deleting destructor: VT0 is the OWN table 0x021138e0, VT1 is
# Platform's base 0x0210ae38 and G0 is the game heap -- pool order read off the
# ROM body at 0x02112538/0x0211253c/0x02112540, and the ROM stores r2 (own)
# BEFORE r1 (base), which is the order the source already writes. Checked, not
# assumed: ov033's twin pair one overlay along had the two labels INVERTED.
# VT0/VT1 are DEFINED in this link (actor_vtables.cpp `int VT0[20]` and
# siblings), so an unrenamed store would land silently on a twenty-word shared
# dummy rather than failing at link -- the ov036 (1) reading.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_td_futa.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV13daObjTdFuta_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
# id 107's deleting destructor spells both its tables by name and needs only the
# heap: its pool at 0x02112740 is 0x020a0eac module:main. Its D1 twin needs
# nothing at all.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_td_water.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   G0=data_020a0eac  --  dead, the TU does not spell G0
# Deleted rather than merged. The surviving row is unchanged.
# id 107's CleanupResources releases two SharedFilePtrs as G0/G1, and its own
# pool names them: 0x02112780 -> 0x02113afc then 0x02112784 -> 0x02113af4, both
# module:overlay(32), both in this lane's own mount. Unrenamed, G0 resolves
# through `/alternatename:_G0=_data_020a0eac` and would Release the GAME HEAP,
# and G1 would not link. Renamed straight to the mount names: decl_common.h
# declares neither, so there is nothing to conflict with (the ov036 (2)
# reading).
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_td_water.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=data_ov032_02113afc;G1=data_ov032_02113af4")
# THE WRONG-NAME AT THE SHARED WINDOW (T6). BUBBA's state-2 tick calls a
# function it spells _ZN21daObjKm3_Kurumajiku_c16CleanupResourcesEv -- OV047's name for the same
# shared-window address -- and OV047 IS SEATED BY THIS SAME LANE two commits
# later, so the name would resolve to Bowser-in-the-Sky's body. relocs.txt
# resolves the ROM's own arm_call at 0x02111d84 to 0x02111254
# module:overlay(32), which is func_ov032_02111254. decl_common.h declares
# neither spelling, so the rename is direct and needs no private name.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_bakubaku.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZN21daObjKm3_Kurumajiku_c16CleanupResourcesEv=func_ov032_02111254")
list(APPEND SWEEP2_SOURCES hal/actor_classes_ov032.cpp ${SLICE_SWEEP2_OV032_SOURCES}
    unmatched/Bubba_Behavior.cpp unmatched/Bubba_ChaseGate.cpp)
# unmatched/Bubba_Render.cpp RETIRED (run link100, lane FOLD2): the ModelAnim
# slot-5 shadow, dead with the destructor unfold. src/game/actors/d_a_bakubaku.cpp
# carries it on port/slice_fold2.txt and needs no face -- it is an
# address-named C symbol its matched source already defines at C linkage.

# ---- 2/4: ov034, level 26 (Tiny-Huge Island's cave) ------------------------
# WIGGLER (248) x1 -- level 26's WHOLE skip list, so this takes the level to
# zero skipped. THIRTY-THREE of the overlay's thirty-six TUs since run rel0215
# lane prop18: the last unhosted body, _ZN7Wiggler8BehaviorEv, was matched on
# the decomp line (main 36e8cbcce, PR #2008) and propagated here by address, so
# the loud face for it is gone and slot 6 runs the ROM's own frame. That body
# is a DECLARED NONMATCHING DRAFT (div 20 of 440 words, all of it register and
# scheduling routing) and its slice row says so. The remaining three held-out
# TUs are host copies: the two pointer-to-member state dispatch sites and the
# five-ModelAnim slot-5 Render. One 31-slot Enemy table, and no identity shift.
# See port/ov034_syms.txt and port/slice_sweep2_ov034.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sweep2_ov034.txt" SLICE_SWEEP2_OV034_LINES)
set(SLICE_SWEEP2_OV034_SOURCES "")
foreach(line IN LISTS SLICE_SWEEP2_OV034_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SWEEP2_OV034_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# THE WRONG-NAME AT THE SHARED WINDOW (T6), the same rename twice. State 9
# DAMAGE_WAIT's tick and state 6 DAMAGETALK's tick both CALL a function they
# spell data_ov052_021125b8 -- an OV052 name, and a DATA-kind one, for this
# overlay's own state setter. The ROM's own arm_calls at 0x021115b0,
# 0x021119ec and 0x02111a00 all resolve to 0x021125b8 module:overlay(34) =
# func_ov034_021125b8. OV052 IS MOUNTED (PORT_ACTOR_OVERLAYS), so the ov052
# spelling resolves and both bodies would call into ov052's DATA -- no link
# error, no byte-gate signal, a jump into a data array at run time. Renamed
# straight to the ov034 spelling: decl_common.h declares neither name.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov034_02111588.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov034_021119ac.c"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov052_021125b8=func_ov034_021125b8")
# AN ALIAS THIS MOUNT DEFEATS, AND ITS ONE LIVE READER (the ov036 (7) shape).
# ov014, ov015, ov021, ov022 and ov034 share the level-overlay base 0x021111a0,
# and ov034's dsd export won the naming race at 0x02114538, so
# src/game/actors/d_a_obj_bk_dossunbar.cpp:30 (ov015's KNOCK_DOWN_PLANK,
# LINKED via port/slice_gate59.txt:93) reaches OV015's OWN collider-file table
# under ov034's spelling. hal/actor_classes_wf.cpp routed that with
# `/alternatename:_data_ov034_02114538=_data_ov015_02114538`, and an
# /alternatename is defeated the moment its LHS is DEFINED -- which is exactly
# what this lane's mount now does: data_ov034_02114538 is the Wiggler's
# ELEVEN-ENTRY STATE TABLE. Unfixed, KNOCK_DOWN_PLANK on level 7 would load its
# collider file out of the Wiggler's state machine: no link error, no byte-gate
# signal, wrong object at run time -- the Coffin/Spindrift shape, caught here by
# port/tools/alternatename_guard.py's post-link map check, which is where this
# lane found it. The now-inert directive is retired at its own site.
# THE SECOND DEFEATED ALIAS NEEDED NO REPLACEMENT:
# `/alternatename:_data_ov034_021147ec=__ZTV10daWanwan_c` in
# hal/bob_enemy_bridges.cpp had NO reader left -- src/game/actors/d_a_wanwan.cpp and
# src/game/actors/d_a_wanwan.cpp both spell _ZTV10daWanwan_c directly today -- so
# it is deleted rather than re-routed.
# A PRIVATE NAME, not a direct rename: include/decl_common.h declares BOTH
# spellings, at line 224 `extern char data_ov015_02114538[]` and at line 1146
# `extern int data_ov034_02114538[]`, so a direct -D makes one identifier carry
# two basic types in one TU and MSVC refuses it (C2371). That is the ov100 C2040
# reading. The private name is declared and never defined, and
# hal/actor_classes_ov034.cpp aliases it onto the mounted ov015 symbol.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_bk_dossunbar.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov034_02114538=port_ov015_kdp_clsn_files")
list(APPEND SWEEP2_SOURCES hal/actor_classes_ov034.cpp ${SLICE_SWEEP2_OV034_SOURCES})
# unmatched/Wiggler_StateEnter.cpp and unmatched/Wiggler_StateTick.cpp RETIRED
# (run link100, lane PMFB1): one state dispatcher each, and
# src/func_ov034_021125b8.cpp and src/func_ov034_02112604.cpp carry both on
# port/slice_pmfc.txt (block R9d). port_wiggler_states_seat in
# hal/actor_classes_ov034.cpp still fills all eleven entries and still aborts
# on a wrong function word or a nonzero adjustment; it is untouched.
# unmatched/Wiggler_Render.cpp RETIRED (run link100, lane FOLD2): five
# ModelAnims drawn through a six-virtual shadow's index 5, which
# _ZTV9ModelAnim holds Render at again. src/_ZN7Wiggler6RenderEv.cpp carries it
# and hal/fold2_faces.cpp holds the cdecl face the slot-9 fill calls.

# ---- 3/4: ov047, level 39 (Bowser in the Sky) ------------------------------
# RICKSHAW_BS (152) x3, STAIRS_BS (153) x1 and ROTATING_PLATFORM_BS (156) x3 --
# seven of level 39's nine skipped instances -- plus RICKSHAW_PLATFORM_BS (151),
# which is not placed on this level and is registered because both attribution
# routes name it. ALL TWENTY-FOUR of the overlay's TUs, no host copy, no face
# and no refusal, plus EIGHT ov002 bodies that are the measured external
# closure. Four 32-slot Platform tables, and dsd's two vtable names are each
# attached ONE TABLE LATE. See port/ov047_syms.txt and
# port/slice_sweep2_ov047.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sweep2_ov047.txt" SLICE_SWEEP2_OV047_LINES)
set(SLICE_SWEEP2_OV047_SOURCES "")
foreach(line IN LISTS SLICE_SWEEP2_OV047_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SWEEP2_OV047_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# NINE PER-SOURCE BINDINGS, and every one is settled from the TU's OWN literal
# pool in config/arm9/overlays/ov047/relocs.txt, disassembled out of
# extracted/overlays/overlay_0047.bin, never by name.
#
# THE RECOVERED SOURCE USES THE RTTI-DERIVED VTABLE NAMES AND GETS THE CLASS
# RIGHT EVERY TIME -- but in the three factories it gets the ORDER backwards.
# The ROM stores the ov002 INTERMEDIATE BASE first and the class's OWN table
# second, which is the correct constructor order:
#   02111298 ldr r1,[pc,#0x14] -> 0x021112b4 -> 0x02109320   the base
#   0211129c ldr r0,[pc,#0x14] -> 0x021112b8 -> 0x021122a0   its own table
#   021112a0 str r1,[r4]   021112a4 str r0,[r4]
# while src/game/actors/d_a_obj_km3_kurumajiku.cpp writes `p[0] = _ZTV21daObjKm3_Kurumajiku_c;`
# FIRST and `p[0] = VT1;` second. So in the three factories the RTTI name means
# the BASE and VT1 means the own table; in the six destructors the same RTTI
# name means the OWN table. Both readings are bound per source. Left alone the
# factories would install the abstract intermediate LAST, and every one of these
# actors would dispatch InitResources through a table whose slot 0 is ZERO in
# the ROM -- a null call on the first frame, invisible to both the byte gate and
# the linkage count.
#
# _ZTV10dBgActor_c IS THE OTHER TRAP, the ov036 (3) one: three destructors spell
# their ov002 INTERMEDIATE base that way, and the port defines _ZTV10dBgActor_c
# as the PLATFORM base (0x0210ae38). Unrenamed those bodies would store the
# Platform table where the ROM stores the intermediate.
# id 153's five TUs need no rename at all: they spell _ZTV17daObjKm3_Dorifu_c,
# _ZTV13daObjDorifu_c and _ZTV10dBgActor_c, which are the three addresses the ROM
# writes, in the ROM's own order.
#
# SUPERSEDED FOR THE THREE FACTORIES (wave 10, lane UNHOSTED). Everything above
# describes the PRE-SYNC recovered sources. The synced TUs spell all three
# factories in the cartridge's own order, base first and own table second, under
# their real names and with no VT1 anywhere, so the three factory rows are gone;
# each class says so in its own block below.
# src/game/actors/d_a_obj_km3_kurumajiku.cpp -- NO COMPILE_DEFINITIONS AT ALL, same stale-by-name
# family as d_a_obj_km3_kaitendai.cpp above (wave 10, lane UNHOSTED). Three rows
# came across the sync, the TU merge collapsed them onto one path, and only the
# last one takes effect: _ZTV21daObjKm3_Kurumajiku_c=_ZTV17daObjKurumajiku_c. The synced
# TU spells its own factory correctly --
#   *(int *)actor = (int)_ZTV17daObjKurumajiku_c;
#   *(int *)actor = (int)&_ZTV21daObjKm3_Kurumajiku_c[2];
# and the cartridge's relocation run for the factory at 0x02111280 says the same pair
# in the same order:
#   from:0x021112b4 kind:load to:0x02109320   _ZTV17daObjKurumajiku_c (the ov002 intermediate)
#   from:0x021112b8 kind:load to:0x021122a0   its own table
# so the rename turned both stores into the abstract intermediate. id 152 RICKSHAW_BS, ov047, levels 39 and 40.
# src/game/actors/d_a_obj_km3_kaitendai.cpp -- NO COMPILE_DEFINITIONS AT ALL, AND
# THAT IS THE FIX (wave 10, lane UNHOSTED). This is the ov036 (3) case one
# overlay over: the same three rows the pre-sync one-function files carried (D1,
# D0, and the factory's mis-bound name) were brought across the sync BY NAME and
# collapsed onto one path when the TU merged. Only the LAST
# set_source_files_properties for a file takes effect, so the row that actually
# ran was the factory one, _ZTV20daObjKm3_Kaitendai_c=_ZTV16daObjKaitendai_c.
# The synced TU needs none of them. Its daObjKm3_Kaitendai_c_classInit writes
#   *(int *)actor = (int)_ZTV16daObjKaitendai_c;        the ov002 intermediate
#   *(int *)actor = (int)&_ZTV20daObjKm3_Kaitendai_c[2]; its own table
# (hostgen rewrites the +8 address point to the host array's own start, which is
# where the port's tables put slot 0), and the cartridge's own relocation run for
# the factory at 0x021113bc says exactly that pair, in that order:
#   from:0x021113f0 kind:load to:0x021091d4 module:overlay(2)    daObjKaitendai_c
#   from:0x021113f4 kind:load to:0x0211237c module:overlay(47)   its own table
# With the stale row in place both stores wrote the abstract intermediate, so
# every ROTATING_PLATFORM_BS on level 39 dispatched slot 0 into ov36_base_trap0
# ("UNHOSTED: vtable slot 0 (abstract base InitResources)"). The TU spells no
# VT0/VT1/VT2/G0 placeholder and does not name _ZTV10dBgActor_c anywhere.
# src/game/actors/d_a_obj_km3_kuruma.cpp -- NO COMPILE_DEFINITIONS AT ALL, same stale-by-name
# family as d_a_obj_km3_kaitendai.cpp above (wave 10, lane UNHOSTED). Three rows
# came across the sync, the TU merge collapsed them onto one path, and only the
# last one takes effect: _ZTV17daObjKm3_Kuruma_c=_ZTV13daObjKuruma_c. The synced
# TU spells its own factory correctly --
#   *(int *)actor = (int)_ZTV13daObjKuruma_c;
#   *(int *)actor = (int)&_ZTV17daObjKm3_Kuruma_c[2];
# and the cartridge's relocation run for the factory at 0x021114d0 says the same pair
# in the same order:
#   from:0x02111508 kind:load to:0x02109278   _ZTV13daObjKuruma_c (the ov002 intermediate)
#   from:0x0211150c kind:load to:0x0211244c   its own table
# so the rename turned both stores into the abstract intermediate. id 151 RICKSHAW_PLATFORM_BS, ov047, levels 39 and 40.
# FOUR WRONG-NAMES AT THE SHARED WINDOW (T6), all in one sinit. STAIRS_BS's file
# constructor spells FOUR of its own .bss symbols with an OV052 tag, and ov052
# IS MOUNTED (PORT_ACTOR_OVERLAYS), so all four resolve: the sinit would
# construct three SharedFilePtrs and register one destructor chain node in
# MARIO'S KEY COURSE's storage instead of its own. The ROM's own pool words at
# 0x02111958, 0x02111970, 0x0211197c and 0x0211196c all resolve to
# module:overlay(47). decl_common.h declares none of the eight names, so the
# renames are direct.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/__sinit_ov047_0211181c.c"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov052_02112680=data_ov047_02112680;data_ov052_02112688=data_ov047_02112688;data_ov052_02112690=data_ov047_02112690;data_ov052_021126a8=data_ov047_021126a8")
list(APPEND SWEEP2_SOURCES hal/actor_classes_ov047.cpp ${SLICE_SWEEP2_OV047_SOURCES})

# ---- 4/4: ov055, level 47 (Luigi's key arena) ------------------------------
# MIRROR_LUIGI (195) x1 -- level 47's WHOLE skip list, so this takes the level
# to zero skipped. Ten of the overlay's thirteen TUs: two are the
# pointer-to-member dispatch sites and one is the //cpp real-destructor shape,
# hand-spelled in the seat. One 31-slot ACTOR table (not Platform), no identity
# shift, and the ONLY overlay in this lane that needs no per-source -D at all.
# See port/ov055_syms.txt and port/slice_sweep2_ov055.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_sweep2_ov055.txt" SLICE_SWEEP2_OV055_LINES)
set(SLICE_SWEEP2_OV055_SOURCES "")
foreach(line IN LISTS SLICE_SWEEP2_OV055_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SWEEP2_OV055_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SWEEP2_SOURCES hal/actor_classes_ov055.cpp ${SLICE_SWEEP2_OV055_SOURCES}
    unmatched/MirrorLuigi_StateEnter.cpp unmatched/MirrorLuigi_Behavior.cpp)
# ---- end lane cast-sweep2 --------------------------------------------------

# ---- run rel0215 wave 3, lane w3-e ----------------------------------------
#
# THREE PARTIALLY-SEATED LEVEL OVERLAYS' REMAINING TAILS. Each overlay gets its
# own slice and its own block; all three feed ONE ${W3E_SOURCES} into the three
# player targets, the ${SWEEP2_SOURCES} shape, so the target lists move once.
#
# The lane's gap census, taken before any edit -- every kind:function row in
# config/arm9/overlays/ovNNN/symbols.txt joined to its delinks.txt src TU and
# to walk_window's own object list in build/port/build.ninja:
#
#   overlay  fn rows  src TUs  LINKED  UNLINKED
#   ov019      37       37        5       32
#   ov022      83       83       40       43
#   ov025      41       41       19       22
#
# ZERO missing bodies, ZERO NONMATCHING banners, ZERO rows without a delink
# row across all three. The whole 97-row tail was ONE class of gap: UNSLICED.
set(W3E_SOURCES "")

# ---- w3-e / ov022, level 14 (Lethal Lava Land) ----------------------------
#
# The five ids wave 8 and wave 16 left: ROLLING_LOG_LLL (70), LAVA_BRIDGE (73),
# LAVA_SEESAW (77), ROTATING_PLATFORM_LLL (80) and VOLCANO_FIRE (243). 70/73/
# 77/80 are the WHOLE of level 14's baseline skip list (5 instances, 4 classes,
# measured on cons cc10acd4e). The cast map, the widths, the naming shift, the
# fourteen inferred-stub rulings and the one held-out TU are in
# port/slice_w3e_ov022.txt and hal/actor_classes_ov022_w3e.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w3e_ov022.txt" SLICE_W3E_OV022_LINES)
set(SLICE_W3E_OV022_SOURCES "")
foreach(line IN LISTS SLICE_W3E_OV022_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W3E_OV022_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND W3E_SOURCES hal/actor_classes_ov022_w3e.cpp ${SLICE_W3E_OV022_SOURCES})

# W1, THE TWO INHERITED CROSS-NAME DEBTS, filed by wave 2 and taken here.
# Both are the alias race in its silent form: the TU spells ANOTHER overlay's
# name for an object that ov022's own relocs resolve to ov022, and the other
# overlay's mount DEFINES that name -- so an /alternatename would be defeated
# without a diagnostic and the reference would bind to the wrong storage. The
# reloc line is quoted for each, and each is a per-source -D.
#
#   src/__sinit_ov022_021130bc.c   (243's two pointer-to-member state records)
#     from:0x021130ec kind:load to:0x0211442c module:overlay(22)
#     from:0x021130f4 kind:load to:0x02114690 module:overlay(22)
#   port/ov034_syms.txt:228 and :255 define data_ov034_0211442c and
#   data_ov034_02114690 (wave 2's ov034 mount). ov022's own mount already has
#   both under the right names (ov022_syms.txt:171 and :187).
#   THE FILED "SECOND SITE" NEEDS NO SECOND -D, and this was checked rather
#   than carried: 0x02114690's other reference is at 0x02112914, inside
#   src/_ZN21daObj_volcanoCannon_c13InitResourcesEv.cpp, and that TU already spells
#   data_ov022_02114690 correctly in its own text.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/__sinit_ov022_021130bc.c"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov034_0211442c=data_ov022_0211442c;data_ov034_02114690=data_ov022_02114690")
#   src/_ZN13RollingLogLll8BehaviorEv.cpp   (70's slot 6)
#     from:0x0211258c kind:load to:0x02112c98 module:overlay(22)
#   port/ov035_syms.txt:294 defines data_ov035_02112c98 (wave 1's ov035 mount);
#   ov022_syms.txt:132 already has data_ov022_02112c98.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13RollingLogLll8BehaviorEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS "data_ov035_02112c98=data_ov022_02112c98")
#
# W2, A THIRD ONE THIS LANE FOUND, and it is the worse shape of the two -- a
# CALL through a data name. src/func_ov022_021126ac.c (243's first PMF state)
# ends in `data_ov025_02112654(c)`, with no declaration, so it compiles as an
# implicit call. ov022's own relocs say what it is:
#     from:0x021126fc kind:arm_call to:0x02112654 module:overlay(22)
# 0x02112654 is func_ov022_02112654, on this lane's slice. No mount defines
# data_ov025_02112654, so today the reference is simply undefined and the TU
# could not be seated; left unrenamed with an ov025 mount that did define it,
# this would have been the ov006 "seating one CALLS INTO A DATA ARRAY" shape.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov022_021126ac.c"
    PROPERTIES COMPILE_DEFINITIONS "data_ov025_02112654=func_ov022_02112654")
#
# W3, THE TWO CleanupResources BODIES THAT SPELL THEIR SharedFilePtrs G0/G1.
# hal/cxx_aliases.cpp binds _G0 to the game heap pointer and _G1 to SignPost's
# ov002 collision file, so linking either of these as written would Release a
# live pointer on every level-14 teardown -- the failure that made wave 8 host
# -thunk LAVA_PLANK's slot 3. Each pool says what its two really are, and both
# are already in port/ov022_syms.txt:
#   73  _ZN16daObjFl_London_c16CleanupResourcesEv: 0x02111aa0 -> 0x02114580, 0x02111aa4 -> 0x02114578
#   77  _ZN10LavaSeesaw16CleanupResourcesEv: 0x02111dcc -> 0x021145a8, 0x02111dd0 -> 0x021145a0
# (Both files are .c, so both names carry C linkage and bind straight onto the
# mount's plain C symbols -- no decorated-name bridge is needed here.)
# BOTH W3 RENAMES RETIRED at the SYNC6 main -> port sync, and the first one had
# become a defect rather than a fix. main's consolidation gave both TUs the real
# symbols in their own text -- src/actors/daObjFl_London_c.cpp lines 46-47 spell
# `extern void *data_ov022_02114580;` and `extern void *data_ov022_02114578;`
# themselves, and neither file contains the identifiers G0 or G1 any more (grep,
# on the merged tree) -- so there is nothing left for a -D to rewrite.
#
# The harm: include/decl_common.h(394) declares `extern int G1[];` for a
# different symbol entirely, and a -D rewrites THAT declaration too, in every
# TU it is applied to. So the London TU compiled decl_common's line as
# `extern int data_ov022_02114578[];` and then met its own
# `extern void *data_ov022_02114578;` eleven lines later:
#
#   src/actors/daObjFl_London_c.cpp(47): error C2372: 'data_ov022_02114578':
#   redefinition; different types of indirection
#   include/decl_common.h(394): note: see declaration of 'data_ov022_02114578'
#
# That is the C2372 lane SYNC5 quarantined this TU for and lane FACES2 recorded
# as a decomp-side question ("which spelling is right is a ROM question").  It
# is neither: it is this rename, firing on a header declaration it was never
# meant to see. The LavaSeesaw row goes with it for the same reason -- unused,
# and the same latent collision on decl_common's G1.
#
# The pool derivations above stay as the record of what the two words are.
#
# W4, THE SAME FIX DOES NOT RETIRE WAVE 8's ONE HOST THUNK, AND THE REFUSAL IS
# MEASURED. LAVA_PLANK (82)'s slot 3,
# src/_ZN9LavaPlank16CleanupResourcesEv.cpp, is the third body of
# exactly this shape, and the rename is KNOWN: its pool reads
# 0x02112208 -> 0x02114620 and 0x0211220c -> 0x02114618, both
# module:overlay(22) and both already mounted. It still cannot be used. This
# body's two targets are declared in include/decl_common.h (lines 238-239,
# `extern char data_ov022_02114618[]` and `..._02114620[]`) and so is G1 (line
# 396, `extern int G1[]`), so -DG1=data_ov022_02114618 rewrites one into a
# redefinition of the other with a different type. MEASURED, not predicted:
# error C2371 on decl_common.h(396) and on the .cpp's own line 9. That is the
# ov006 Mg3DEsp wall recorded at line ~6295 of this file, and the test that
# separates the two cases is whether the TARGET is in that header --
# 0x02114580, 0x02114578, 0x021145a8 and 0x021145a0 are not, which is exactly
# why W3 above works. hal/actor_classes_ov022.cpp therefore KEEPS lp_clean and
# this one ov022 TU stays unlinked; the way out is a header change, not a slice
# change, and the owner is wave 8's thunk.
#
# W5, THE TWO FACTORIES THAT WRITE THEIR OWN TABLE THROUGH `VT1`. 80's and 70's
# Spawns end in `str r1,[r4]; str r0,[r4]` -- base table then own table, two
# stores back to back -- and the recovered source puts the RTTI name on the
# dead first store and the shared-header VT1 placeholder on the live second
# one. VT1 is hal/actor_vtables.cpp's zeroed [20], so a raw spawn would leave a
# live object dispatching through zeros. Binding VT1 per source to the host
# table makes the ROM's own final store correct and saves a port_factory
# wrapper; the pool words are 0x021116c0 -> 0x02113de8 and
# 0x021125dc -> 0x021143a4.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_obj_fl_koma_d.c"
    PROPERTIES COMPILE_DEFINITIONS "VT1=_ZTV19RotatingPlatformLll")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_obj_fl_maruta.c"
    PROPERTIES COMPILE_DEFINITIONS "VT1=_ZTV13RollingLogLll")
#
# W5b, ONE arm9-STYLE PLACEHOLDER NAME, off the first link's own unresolved
# list. src/_ZN13RollingLogLll16CleanupResourcesEv.cpp (70's slot 3) calls
# `func_021270dc`, the bare-address spelling, and the reloc says which module
# owns that address:
#     from:0x02112558 kind:load to:0x021270dc module:overlays(78,80)
# ov078 and ov080 share base 0x02123740; level 14's object overlays are
# ov064/ov071/ov080/ov084/ov095 and ov078 is not among them, and this class's
# two OTHER cross-overlay slots (9 and 27) are ov080's as well -- so ov080.
# src/func_ov080_021270dc.c is already on port/slice_ov030cast.txt for
# RollingLogTtm, this class's ROM twin. Safe as a rename because BOTH names are
# declared in include/decl_common.h with the IDENTICAL type (lines 1381 and
# 1601, `extern int f(void*, void*)`), so the rewrite is a duplicate
# declaration and not the C2371 the W4 block records.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13RollingLogLll16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS "func_021270dc=func_ov080_021270dc")
#
# W6, THE TWO POINTER-TO-MEMBER DISPATCHERS, the R9 wave-18 ruling applied to
# VOLCANO_FIRE. Both take a pointer-to-member of an INCOMPLETE class and apply
# a NONZERO offset to it, which is the exact predicate R9 measured: without
# /vmg /vmm MSVC's representation is FOUR bytes and `pp + 1` strides onto the
# adj word of record 0, which is ROM-zero -- a `jmp 0`. With them it is the
# ROM's own 8-byte {fn, delta} record. src/_ZN21daObj_volcanoCannon_c11ChangeStateEPNS_5StateE.cpp is the
# `c->pp` setter that calls record 0 (offset 0, correct either way, listed for
# representation agreement with its sibling) and
# src/_ZN21daObj_volcanoCannon_c8BehaviorEv.cpp reads the record at BYTE offset 8 --
# the source's own arithmetic pins sizeof(PMF) at 8, the KingBobOmb proof.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN21daObj_volcanoCannon_c11ChangeStateEPNS_5StateE.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN21daObj_volcanoCannon_c8BehaviorEv.cpp"
    PROPERTIES COMPILE_OPTIONS "/vmg;/vmm")
# ---- w3-e / ov025, level 17 (SSL, the pyramid interior) -------------------
#
# The two ids wave 15 did not take: GRINDEL (162, x3) and SPINDEL (163, x1) --
# together the whole of level 17's own remaining skip list, and the last of
# ov025's four-id cast. The both-route derivation, the widths, the nine
# inferred-stub rulings and the reclaimed host thunk are in
# port/slice_w3e_ov025.txt and hal/actor_classes_ov025_w3e.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w3e_ov025.txt" SLICE_W3E_OV025_LINES)
set(SLICE_W3E_OV025_SOURCES "")
foreach(line IN LISTS SLICE_W3E_OV025_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W3E_OV025_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND W3E_SOURCES hal/actor_classes_ov025_w3e.cpp ${SLICE_W3E_OV025_SOURCES})

# W7, THREE MORE CROSS-NAME RENAMES, the same silent shape as W1/W2. Each TU
# spells another overlay's name for an object ov025's own relocs resolve to
# ov025, and those names are DEFINED elsewhere in this link, so an
# /alternatename would be defeated without a diagnostic. Where, exactly:
# _ZTV10daPgDfdr_c is hal/actor_classes_ov027.cpp:327's 32-slot host
# vtable array (DA_PG_DFDR's live dispatch table), _ZTV16daObjRcBuranko_c is
# hal/actor_classes_ov036.cpp:413's (SWINGING_PLATFORM's), and
# _ZTS16daObjRcBuranko_c is on the ov036 mount (ov036_syms.txt:289). Unrouted,
# ov025's sinit would write into the first two LIVE dispatch tables:
#   src/__sinit_ov025_021129dc.c   (162's model/collision pair)
#     from:0x02112a34 kind:load to:0x02113a90 module:overlay(25)  spelled ov027
#     from:0x02112a30 kind:load to:0x02113a98 module:overlay(25)  spelled ov036
#   src/actors/daDgr_c.cpp    (163's CleanupResources)
#     from:0x021113c4 kind:load to:0x02113a60 module:overlay(25)  spelled ov036
# All three right-hand names join port/ov025_syms.txt with this lane.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/__sinit_ov025_021129dc.c"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV10daPgDfdr_c=data_ov025_02113a90;_ZTV16daObjRcBuranko_c=data_ov025_02113a98")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daDgr_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZTS16daObjRcBuranko_c=data_ov025_02113a60")
#
# W8, GRINDEL'S FACTORY, the same VT1 shape as ov022's 80 and 70. The ROM's two
# stores are `str r1,[r4]` with the base 0x021351fc (the reloc reads
# module:overlays(6,91) -- ambiguous between the two base-sharing overlays,
# and nothing depends on it, being the dead first store) and then, after the
# TextureSequence and ShadowModel constructors, `str r0,[r4]` with its own
# 0x02113850 (pool words 0x02111d38 and 0x02111d3c). The recovered source has
# the RTTI name on the dead first store and VT1 on the live second one.
# DEAD at the main->port sync (lane SYNC7, wave 9): main folded src/d_a_dkk.c
# (ov025 .text 0x02111cf4..0x02111d40) into src/actors/daDkk_c.cpp, which spells
# no VT1 placeholder at all -- it declares the class, so the TU emits
# _ZTV7daDkk_c itself. The property row has no file and nothing to define.
#set_source_files_properties(
#    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_dkk.c"
#    PROPERTIES COMPILE_DEFINITIONS "VT1=_ZTV7daDkk_c")
#
# W9, THE RECLAIM W4 COULD NOT DO. src/_ZN11PyramidStep16CleanupResourcesEv.cpp
# (id 87, slot 3) is the same G0/G1 SharedFilePtr shape as ov022's LAVA_PLANK
# body, and wave 15 host-thunked it for the same reason. Here the rename
# COMPILES, and the difference is exactly the test W4 records: this body's
# targets are NOT declared in include/decl_common.h, so -DG1=... rewrites only
# that header's own `extern int G1[]` and collides with nothing. The pool:
#   from:0x02111ea0 kind:load to:0x02113ab8 module:overlay(25)   model file
#   from:0x02111ea4 kind:load to:0x02113ab0 module:overlay(25)   collision file
# Both are already in port/ov025_syms.txt (0x02113ab8 pinned to 8 there).
# hal/actor_classes_ov025.cpp's slot-3 fill now calls the method.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11PyramidStep16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "G0=data_ov025_02113ab8;G1=data_ov025_02113ab0")
# ---- w3-e / ov019, level 11 (Cool Cool Mountain's slide) ------------------
#
# RACING_PENGUIN (259), the one class gate 142/143 left in level 11's own
# overlay. It is on NO mounted level's object list and nothing spawns it at run
# time, so this block moves the LINKAGE count and not the census -- level 11's
# baseline is already 84 spawned / 0 skipped. Said plainly here because a
# reviewer reading the battery alone would see nothing move.
# Also here: ICE_SLIDE_MANAGER's deleting destructor, whose slot 17 gate 143
# trap-filled, so that class had no hosted D0 at all.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w3e_ov019.txt" SLICE_W3E_OV019_LINES)
set(SLICE_W3E_OV019_SOURCES "")
foreach(line IN LISTS SLICE_W3E_OV019_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W3E_OV019_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# ONE ov019 TU IS GENERATED RATHER THAN SLICED. src/func_ov019_0211140c.cpp is
# declared `int` and falls off the end -- legal for mwccarm, C4716 and a hard
# error for MSVC -- so it goes through tools/hostgen.py's FALLS_OFF_RETURN
# table, exactly the shape OV70GEN above already uses for
# func_ov070_0211f0a4, and src/ is not touched. The returned value is dead on
# both sides: the ROM body ends with r0 holding SurfaceInfo::CopyNormalTo's
# leftover, and all four call sites discard it.
set(OV19GEN_SYMS func_ov019_0211140c)
set(OV19GEN "")
foreach(sym IN LISTS OV19GEN_SYMS)
    set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND OV19GEN "${sym_out}")
endforeach()
list(APPEND W3E_SOURCES hal/actor_classes_ov019_w3e.cpp
    ${SLICE_W3E_OV019_SOURCES} ${OV19GEN}
    unmatched/RacingPenguin_ShadowFaces.cpp)
# unmatched/RacingPenguin_Render.cpp RETIRED (run link100, lane FOLD2): the
# same slot-5 shadow one overlay over. src/_ZN13RacingPenguin6RenderEv.cpp
# carries it; the face is in hal/fold2_faces.cpp and is spelled with a char*
# receiver to match this file's own declaration of the C name.

# W10, THE ONE DATA CROSS-NAME IN ov019, and it is the worst spelling in this
# lane: src/_ZN13RacingPenguin16CleanupResourcesEv.cpp declares its seven
# animation file pointers as `_ZN14daObjTdWater_c6RenderEv[7]` -- ov032's
# HugeCover::Render, a FUNCTION this link DEFINES since wave 2 seated that
# class. Linked as written it would call SharedFilePtr::Release on seven words
# read out of ov032's code, and an /alternatename would be defeated without a
# diagnostic. ov019's own reloc says what the address is:
#     from:0x02112354 kind:load to:0x02112788 module:overlay(19)
# The TU includes only types.h, so the rename collides with nothing in
# decl_common.h (which declares data_ov019_02112788 with a different element
# type -- the reason this is safe here and would not be if that header were in
# scope).
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13RacingPenguin16CleanupResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS "_ZN14daObjTdWater_c6RenderEv=data_ov019_02112788")
#
# W11, ICE_SLIDE_MANAGER's DELETING DESTRUCTOR. Its transient base-table
# restore is spelled `VT`, which hal/cxx_aliases.cpp binds to ov002's
# data_ov002_021081e4; its own pool says the store is its OWN table:
#     from:0x02112670 kind:load to:0x021133cc module:overlay(19)
# `HEAP` needs no row -- cxx_aliases already binds it to _data_020a0eac, which
# is what the second pool word (0x02112674) holds. Safe as a rename because
# both names are declared in include/decl_common.h with the IDENTICAL type
# (`extern int VT[]` at 415, `extern int _ZTV10daSldMng_c[]` at 582), so
# the rewrite is a duplicate declaration.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_sld_mng.cpp"
    PROPERTIES COMPILE_DEFINITIONS "VT=_ZTV10daSldMng_c")
#
# W12, THE TWO POINTER-TO-MEMBER DISPATCHERS, the R9 wave-18 ruling again.
# src/func_ov019_02112268.cpp applies a NONZERO offset (`c->pp + 1`) and is
# R9's exact predicate; it is ALREADY in R9's `set_source_files_properties`
# list above as an "ABSENT, inert today" row, and this lane makes that row
# live. Its sibling src/func_ov019_021122a4.cpp reads record 0 and is listed
# here so the two agree on the representation -- a TU that keeps MSVC's default
# 4-byte form while its sibling uses the ROM's 8-byte one is the drift R9's
# "PER-SOURCE, NEVER GLOBAL" paragraph warns about.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov019_021122a4.cpp"
    PROPERTIES COMPILE_OPTIONS "/vmg;/vmm")
#
# W13, AN ALIAS THIS LANE DEFEATS, RE-ROUTED. hal/bob_enemy_bridges.cpp carried
# /alternatename:_func_ov019_02111f54=_func_ov014_02111f54, because ChainChomp's
# state-2 main (src/game/actors/d_a_wanwan.cpp) spells an ov014 body with an ov019
# tag -- dsd's per-overlay naming attaching a reference to the wrong one of the
# four overlays that share this base -- and ov014's own reloc settles it:
#     from:0x02111afc kind:arm_call to:0x02111f54 module:overlay(14)
# RACING_PENGUIN's sixth pointer-to-member state body IS func_ov019_02111f54,
# so seating it DEFINES that LHS and the alias goes inert. Caught by
# alternatename_guard on this lane's first link, not reasoned about afterwards.
# Left unrouted it is a wrong-object bind that never fails the link: the chomp's
# state-2 main calling the penguin's body. The reader declares the name itself
# and includes no header that declares it either, so the -D is exact.
# BOTH PATHS, lane HOSTGEN4. This rename is the wrong-object bind lane w3-e
# caught with alternatename_guard; on the raw path alone it would go missing
# the moment the substitution moved the compile, and the chomp's state-2
# main would call the penguin's body again.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_wanwan.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_wanwan.cpp"
    PROPERTIES COMPILE_DEFINITIONS "func_ov019_02111f54=func_ov014_02111f54")
# ---- end lane w3-e ---------------------------------------------------------

# Gates 64-69: ov079's four static initialisers plus the six enemy classes'
# matched lifecycle closures -- WHOMP (164), WHOMP_KING (165), BULLET_BILL (222),
# BILL_BLASTER (43), FORTRESS_WALL (47), FORTRESS_WALL_BREAKABLE (48). The two
# Behaviors that are host copies (WHOMP's and BULLET_BILL's PMF dispatch) are the
# unmatched/ files appended below, not in the slice. See slice_gate64.txt and
# hal/actor_classes_wf_enemy.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate64.txt" SLICE64_LINES)
set(SLICE64_SOURCES "")
foreach(line IN LISTS SLICE64_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE64_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE64_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_wf_enemy.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/wf_enemy_bridges.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Whomp_Behavior.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/BulletBill_Behavior.cpp")

# Gate 89: POWER_STAR (178, ov002), and gate 90: STAR_CAMERA (177, ov002).
# PowerStar's matched lifecycle closure (slice_gate89.txt) plus the vtable
# fill / method faces (hal/actor_classes_star.cpp) and the host-copy Behavior
# with its fourteen-entry PMF state seat (unmatched/PowerStar_States.cpp).
# STAR_CAMERA needs no slice of its own: it is a bare Actor whose base vtable
# (_ZTV5Actor / data_0208e3a4) is filled by hal_fill_actor_base_vtable in the
# same star file; every base method is already linked.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate89.txt" SLICE89_LINES)
set(SLICE89_SOURCES "")
foreach(line IN LISTS SLICE89_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE89_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE89_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_star.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/PowerStar_States.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/PowerStar_KingGuards.cpp")

# Two ov079 TUs need hostgen, both mwcc-vs-MSVC syntax quirks the byte-verified
# tree must not be edited for. _ZN5Whomp13InitResourcesEv is the decl_common.h
# HEADER_SHADOW case (func_01ffb07c/func_020396d0 declared with one pointer
# type in the header and another in the TU -- one register on the ROM, C2733 to
# MSVC). _ZN11BillBlaster8BehaviorEv (BillBlaster::Behavior) declares its local struct's
# members out of line as well as in-struct, which mwccarm tolerates and MSVC
# rejects as C2761; hostgen's MEMBER_REDECL deletes the redundant copies.
set(GATE64_SYMS _ZN5Whomp13InitResourcesEv _ZN11BillBlaster8BehaviorEv)
set(GATE64_GEN "")
foreach(sym IN LISTS GATE64_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE64_GEN "${sym_out}")
endforeach()

# Gate 15: the per-frame actor spine (BeforeBehavior/Behavior/AfterBehavior),
# which is what makes the real WithMeshClsn tracking work -- see the header of
# slice_gate15.txt for why prev-pos is load-bearing.
#
# Actor::BeforeBehavior defines its eight engine BSS symbols at file scope the
# way mwccarm accepts (tentative definitions the linker merges). MSVC's C++
# front end makes them strong and they all belong to the HAL, so the file goes
# through hostgen with --extern-data.
set(GATE15_SYMS _ZN8dActor_c14BeforeBehaviorEv)
set(GATE15_GEN "")
foreach(sym IN LISTS GATE15_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" --extern-data ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE15_GEN "${sym_out}")
endforeach()

# HOST-ABI RETIREMENT: Player::InitResources, the host copy that existed only
# because hostgen could not read one asm block, now that it can.
#
# The file said so in its own header, and it was the vacuous-pass shape rather
# than a link failure: the hand copy compiled, linked and ran, and only a
# reader comparing it line by line with the matched source could tell whether
# it had drifted.
#
# The match note explains the block -- it is there to force mwccarm's CLEAR
# codegen shape (5 x 4 strb post-inc), not to compute anything, and what it
# computes is a 20-byte zero over a fresh allocation. hostgen's ASM_EXCISION
# substitutes the C semantics, per-symbol and exact-text, so the day the
# source moves the build stops rather than silently substituting C for
# instructions nobody re-read.
#
# --extern-data because the TU defines a dozen data_<hex> latches at file
# scope that hal/level_boot.cpp and the dsstate section own.
#
# ActorBase::AfterCleanupResources, the OTHER file this retirement was written
# for, turned out not to need a block of its own: gate 9 was already hostgen'ing
# that symbol for the actor smokes, just without --extern-data. See GATE9_SYMS.
# Lane shadow-A: Scene::AfterCleanupResources, the second symbol of the same
# shape. The matched TU spells `unsigned char data_02092660;` inside extern
# "C", a strong definition to MSVC's C++ front end, and the byte is DS state
# hal/scene_boot.cpp owns inside the .dsstate bracket (dsstate_guard refuses
# it anywhere else). --extern-data turns that one line into a declaration and
# the body links as it stands. port/unmatched/Scene_AfterCleanupResources.cpp
# used to be the matched source with that one word added; it is deleted.
set(HOSTABI_RETIRE_SYMS _ZN6Player13InitResourcesEv
    _ZN8dScene_c21AfterCleanupResourcesEj)
set(HOSTABI_RETIRE_GEN "")
foreach(sym IN LISTS HOSTABI_RETIRE_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" --extern-data ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND HOSTABI_RETIRE_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate15.txt" SLICE15_LINES)
set(SLICE15_SOURCES "")
foreach(line IN LISTS SLICE15_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE15_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 16: real objects on the castle grounds -- the ROM's own actor frame
# (the five processing lists) plus one matched lifecycle closure per class the
# registry carries. See the header of slice_gate16.txt.
#
# The hostgen set is the gate-9 case each time: C++ syntax (a real method, or
# a `virtual` shadow class) inside a .c file, which mwccarm accepted and MSVC
# will not compile as C. hostgen emits .cpp with the symbols wrapped back to
# C linkage, so the byte-verified tree is never edited.
# TWO ENTRIES LEFT THIS LIST 2026-09-13 (lane SYNC3), both the C++-inside-a-.c
# case and both answered by main itself: func_ov002_020aefb8 is now in
# src/actors/da1up_c.cpp and _ZN11daWarpkun_c8BehaviorEv in
# src/game/actors/d_a_warpkun.cpp, both real .cpp translation units. hostgen's
# only effect on either was the C-linkage wrap a .c source needs.
set(GATE16_SYMS _ZN8dActor_c22BeforeCleanupResourcesEv
    # Lane lk4 seat 3: Heap::ResizeToFit is a virtual shadow class inside a
    # .c -- the same case again.
    _ZN4Heap11ResizeToFitEv)
set(GATE16_GEN "")
foreach(sym IN LISTS GATE16_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND GATE16_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate16.txt" SLICE16_LINES)
set(SLICE16_SOURCES "")
foreach(line IN LISTS SLICE16_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE16_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# argfix: Actor::DistToCPlayer (gate 16) and Actor::FarthestPlayer (gate 89) both
# call Actor::ClosestPlayer() with no argument and rely on `this` riding ARM r0.
# One host copy carries both wrappers; it is added here (both gates ship on the
# same three targets, so add it once). Src lines commented out in slice_gate16.txt
# and slice_gate89.txt.
list(APPEND SLICE16_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Actor_ClosestPlayerWrappers.cpp")

# BigBrickBlock::OnAttacked2 (slot 23, the bro PUNCH) USED TO BE A HOST COPY
# appended here. Its src reaches Kill (slot 31) through a C++ virtual now, so
# the copy is retired and the src itself links from the RS5A block at the end
# of this file (run linkfull, lane RS5A).

# run linkw wave C, lane cat-2d, slice 2d1. One TU: src/func_ov004_020adc4c.c,
# the only ov004 body a LINKED arm9 caller reaches (src/LoadFont.cpp's
# data_0209d698 == 2 arm calls it twice). It reads one ov004 BSS word,
# data_ov004_020beb60, and hal/oam2d_ov004_bss.cpp used to host that word by
# hand -- which is what retired the PORT_HOST_ABI printf stand-in for it in
# hal/sub_screen.cpp. The ov004 mount now hosts the word itself, from the same
# ROM span and with the same four zero bytes, so the hand-hosted file is gone
# (run link60 lane s2-m46). The slice still ships on exactly the three targets
# that link hal/sub_screen.cpp, and all three carry the mount. Why the slice is
# one line and not 276: port/ov004_ov007_2d_map.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_2d1.txt" SLICE_2D1_LINES)
set(SLICE_2D1_SOURCES "")
foreach(line IN LISTS SLICE_2D1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_2D1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# run mg9 lane S364: dScMgSlot1_c, actor id 0x16c = scene 364. The ROM gives
# this id no Mg*_SpawnInfo symbol and no naming import has ever named it, so
# the class name is the ROM's own RTTI, reached through the type_info the word
# BEFORE the vtable points at: data_ov006_0213eb40[-1] is 0x0213e5a0, whose
# name pointer 0x0213e5bc reads "12dScMgSlot1_c".
#
# THE WIDTH IS THE REASON THIS BLOCK IS WORTH READING. port/mg_fanout_costs.txt
# section 11 names 0x16c by hand as the second class whose phantom slot 36 is
# LIVE DATA BELONGING TO A SHIPPED GAME: index 36 of this table is
# g_profile_MG_SMARTBALL's factory word, and scene 376 is seated in
# this tree. hal/scene_mg_slot1.cpp fills 36 and port/slice_s364.txt section 3
# carries all four checks -- span, terminal slot, what the word is, and the
# relocation count.
#
# ONE VARIABLE FOR THE SLICE, for the reason the CCN and PPP blocks state.
# hal/scene_boot.cpp's port_scene_classes table carries the scene-364 row, so
# every target that compiles scene_boot.cpp references port_mg_slot1_spawn and
# port_scene_fill_slot1 by name -- the same coupling every minigame row has.
#
# NO STATE DISPATCHER HOST COPY AND NO stategen OUTPUT. This class has no mwcc
# pointer-to-member state machine: its own machine is a fourteen-arm jump-table
# switch, no overlay constructor builds a pair table for it, and a `::*` sweep
# over every TU in the slice is clean. That is the second counterexample to
# section 4's "the wall is the same one for all thirty", after the flower.
#
# ONE TU BUILDS FROM A HOSTGEN COPY. src/_ZN12dScMgSlot1_c13InitResourcesEv.cpp is slot 0,
# InitResources, and it does thirty-seven literal-address accesses in the
# 0x04xxxxxx window -- both engines' DISPCNT and BGxCNT at 0x0400000c /
# 0x0400000e / 0x04001008 / 0x0400100a / 0x0400100c / 0x0400100e, BLDCNT at
# 0x04000050 and the sub-engine blend at 0x04001050. Compiled straight from
# src/ those land in the memory ntr maps across the I/O window and stop there.
# src/ itself is never edited; the hostgen copy stands in for it and the
# substitution asserts rather than hopes, exactly as the FLW block's does.
set(S364_HOSTGEN_SYMS _ZN12dScMgSlot1_c13InitResourcesEv)
set(S364_HOSTGEN_GEN "")
set(S364_HOSTGEN_SKIP "")
foreach(sym IN LISTS S364_HOSTGEN_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        list(APPEND S364_HOSTGEN_SKIP "src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
        list(APPEND S364_HOSTGEN_SKIP "src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND S364_HOSTGEN_GEN "${sym_out}")
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_s364.txt" SLICE_S364_LINES)
set(SLICE_S364_SOURCES ${S364_HOSTGEN_GEN})
foreach(line IN LISTS SLICE_S364_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    # The hostgen'd copy stands in for the src/ one; taking both would be a
    # duplicate symbol, and taking neither would drop the body silently.
    if(line IN_LIST S364_HOSTGEN_SKIP)
        continue()
    endif()
    list(APPEND SLICE_S364_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(LENGTH S364_HOSTGEN_SYMS s364_hg_want)
list(LENGTH S364_HOSTGEN_GEN s364_hg_have)
if(NOT s364_hg_want EQUAL s364_hg_have)
    message(FATAL_ERROR "slice_s364 hostgen substitution incomplete: "
            "${s364_hg_have} of ${s364_hg_want} generated")
endif()
foreach(skip IN LISTS S364_HOSTGEN_SKIP)
    if(NOT skip IN_LIST SLICE_S364_LINES)
        message(FATAL_ERROR "slice_s364.txt no longer lists ${skip}; the "
                "hostgen substitution for it is now dead and the display "
                "control writes in it would go back to latching silently")
    endif()
endforeach()

# TWO NAME-SPELLING DEFECTS, BOTH SECTION 6's FOURTH KIND, BOTH RESOLVED OFF
# THE ROM RATHER THAN OFF THE NAME. The first link wave asked for seven
# externals and all seven are decomp-side spellings of DATA symbols under a
# func_ prefix. Per-source -D and not /alternatename, for lane A2's reason: the
# right-hand symbols are DEFINED in this binary by the ov004 mount, and an
# alias with a defined symbol on the left is defeated silently.
#
# (a) THE SIX ov004 WINDOW WORDS slot 0 writes -- 0x80, 0x40, 0x80, 0x40, 0x80,
#     0x40 into 0x020bc88c, _020bc860, _020bc878, _020bc890, _020bc8b8 and
#     _020bc8b4. include/decl_common.h declares all six as `extern int
#     func_020bcXXX;`, config names every one of them data_ov004_020bcXXX at
#     four bytes each, and port/ov004_syms.txt already mounts the whole run.
#     port/mg_fanout_costs.txt section 12 records dScMgCup_c's InitResources
#     writing "the six ov004 window words" as well, so this rename is the
#     family's and not this class's.
set_source_files_properties(
    "${CMAKE_BINARY_DIR}/host-src/src/_ZN12dScMgSlot1_c13InitResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_020bc860=data_ov004_020bc860;func_020bc878=data_ov004_020bc878;func_020bc88c=data_ov004_020bc88c;func_020bc890=data_ov004_020bc890;func_020bc8b4=data_ov004_020bc8b4;func_020bc8b8=data_ov004_020bc8b8")

# (b) THE SUB-OBJECT'S BASE VTABLE, and this one had to be ADJUDICATED BETWEEN
#     TWO OVERLAYS rather than looked up. The factory and both destructors
#     store 0x020ad494 into this+0x4660 and then store the betIcon table over
#     it -- a base-then-derived vptr pair. 0x020ad494 is `ambiguous` in config:
#     ov000 and ov001 share the base 0x020aa420 and both name a symbol there.
#     hal/scene_mg_faces.cpp already hosts the ov000 reading, a 24-byte
#     filename string "thum_shinkei_ncg.bin", AND THAT IS THE WRONG MODULE FOR
#     THIS CLASS. The ROM decides it:
#
#       overlay_0001.bin at 0x020ad478 is a type_info record {0x0209a774,
#       0x020ad480} and 0x020ad480 reads "9dThIcon_c";
#       0x020ad490 holds 0x020ad478, i.e. that type_info, which is the word
#       before a vtable;
#       0x020ad494 and 0x020ad498 hold 0x020ab550 and 0x020ab54c, a two-slot
#       table -- and src/_ZN12dScMgSlot1_c9betIcon_c8BehaviorEv.cpp, the DERIVED betIcon slot 0,
#       calls _ZN9dThIcon_c8BehaviorEv directly, which is the base calling
#       convention showing through;
#       overlay_0000.bin at the same address is the middle of the string
#       "...ogezo/togezo.bmd", which is not a type_info and not a table.
#
#     So dScMgSlot1_c::betIcon_c derives from dThIcon_c in ov001. The ov001
#     per-symbol mount covers 0x020ab800..0x020abb00 only (port/ov001_syms.txt
#     says why), so the table is HOSTED in hal/scene_mg_slot1.cpp with faces
#     for its two ROM bodies rather than mounted, which is the same treatment
#     and the same reasoning hal/scene_mg_faces.cpp gives for the ov000
#     reading of this very address. Expanding the ov001 mount instead would be
#     the wrong trade for two words and would put a raw DS code address in the
#     table anyway.
foreach(s364_thicon_tu
        "${PORT_REPO_ROOT_ABS}/src/_ZN12dScMgSlot1_cD1Ev.cpp"
        "${PORT_REPO_ROOT_ABS}/src/_ZN12dScMgSlot1_cD0Ev.cpp"
        "${PORT_REPO_ROOT_ABS}/src/d_s_mg_slot1.cpp")
    set_source_files_properties("${s364_thicon_tu}"
        PROPERTIES COMPILE_DEFINITIONS
        "func_020ad494=data_ov001_020ad494")
endforeach()

set(SCENE_MG_SLOT1_SOURCES hal/scene_mg_slot1.cpp)

# Run mg11 lane MUG: dScMgSlot3_c, the "Mix-a-Mug" slot machine, actor id
# 0x16d = scene 365, and the NINTH class the port seats under
# dScMgSingle3DBase_c (eight at base; port/slice_mug.txt has the sweep that
# counts them).
#
#   Scene -> dScMgBase_c (ov004 0x020bc0c0) -> dScMgSingle3DBase_c
#         (ov006 0x0213e448) -> dScMgSlot3_c (ov006 0x0213eaa8)
#
# both new tables 36 slots wide and checked FIVE ways before a word was written
# (port/slice_mug.txt): the span, the terminal slot, what the words past the
# end are, the relocation count inside the span, and the relocation stride.
# THE SPAN READS 38 AND THE WIDTH IS 36, which port/mg_fanout_costs.txt line
# 1287 already resolved; what the slice adds is the mechanism, and it names a
# live victim -- the two extra words are the {0, &typeinfo} RTTI HEADER of
# dScMgSlot1_c's vtable, so a 38-slot fill here would write a host thunk over
# scene 364's typeinfo pointer. The ROM gives this id no spawn symbol at all,
# so the whole identity -- class name, hierarchy and player title -- is derived
# from the ROM in that file's header.
#
# THE WALL IS THE ORDINARY TABLE FORM AND IT IS PAID ONCE. Eight states in
# data_ov006_02142bdc, filled by __sinit_ov006_02132894 and dispatched from
# vtable slot 6 at stride eight with arity 0. unmatched/MgSlot3_StateDispatch.cpp
# host-copies _ZN12dScMgSlot3_c8BehaviorEv and routes the dispatch through an address
# switch, so src/_ZN12dScMgSlot3_c8BehaviorEv.cpp is OUT of slice_mug.txt: listing both
# copies would be a duplicate symbol, and listing neither would drop the whole
# state machine silently. A word-by-word decode of the class's code block finds
# exactly THREE Itanium-sequence instructions and all three are in that one
# body, so there is no second dispatcher and no open-coded third shape.
#
# THE ONE BODILESS STATE IS RETIRED (run mg12, lane MAM). func_ov006_0210adac
# (slot 2, 0x1b8, the face-evaluation step after the third reel stops) had a
# config symbol, no delink block and no src in any module, so mg11 left it out
# of the slice and invented no definition for it. It is now byte-matched:
# src/func_ov006_0210adac.c is in slice_mug.txt, the delink block covers
# 0x0210adac..0x0210af64, and unmatched/MgSlot3_StateDispatch.cpp calls it. The
# per-slot census still prints the former floor counter so an mg11 log and an
# mg12 log compare field for field.
#
# NO HOSTGEN SUBSTITUTION, for the reason the S381 block above gives: the two
# bodies in this class that dereference a 0x04xxxxxx literal
# (src/_ZN12dScMgSlot3_c13InitResourcesEv.cpp's BG0CNT/BG1CNT/BG2CNT/BG3CNT writes and
# src/_ZN12dScMgSlot3_c9Virtual80Ev.cpp's BG1CNT read-modify-writes) are ordinary PPU
# control registers the display reads back out of the memory ntr maps there.
# The write-TRIGGERED registers this class touches are all inside
# _ZN19dScMgSingle3DBase_c9Virtual84Ev, which comes in through FLW_HOSTGEN_GEN already
# substituted.
#
# ONE VARIABLE, for the reason the flower and S381 blocks give: the slice and
# the .cpp are not separable. hal/scene_boot.cpp's port_scene_classes table
# carries the scene-365 row, so every target that compiles scene_boot.cpp
# references port_mg_slot3_spawn and port_scene_fill_slot3 by name.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_mug.txt" SLICE_MUG_LINES)
set(SLICE_MUG_SOURCES hal/scene_mg_slot3.cpp
                      unmatched/MgSlot3_StateDispatch.cpp)
# unmatched/MgSlot3_SubObjCtor.cpp RETIRED (run linkfull, lane RS4PORT): main
# #3107 spells the two file ids 0x205/0x206, so src/func_ov006_020c221c.c is
# on slice_mug.txt.
# unmatched/MgSlot3_SubObjUpdate_020c1f4c.cpp RETIRED (run link100, lane
# FOLD2): its shadow's v3() is ROM index 3, BlendModelAnim::UpdateVerts, which
# is what _ZTV14BlendModelAnim[3] holds again. src/func_ov006_020c1f4c.cpp
# carries it (port/slice_fold2.txt).
foreach(line IN LISTS SLICE_MUG_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_MUG_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# THE SIX ov004 WINDOW WORDS AGAIN, and this is the second class to write them.
# src/_ZN12dScMgSlot3_c13InitResourcesEv.cpp (slot 0 InitResources) assigns eight ov004 words
# spelled with a func_ prefix: include/decl_common.h declares all eight as
# `extern int func_020bcXXX;` while config names each of them
# data_ov004_020bcXXX, and port/ov004_syms.txt mounts the whole run. Per-source
# -D and not /alternatename, for the reason the S364 block below the SLOT1
# sources gives: the right-hand symbols are DEFINED in this binary by the ov004
# mount. Six of the eight are the same run dScMgSlot1_c's InitResources and
# dScMgCup_c's write; the other two (0x020bc864 and 0x020bc888) already have
# /alternatename rows in unmatched/MgLuigi_Faces.cpp and
# unmatched/MgSmartball_Faces.cpp, and are renamed here too rather than left to
# those -- one mechanism per TU is what makes "this TU spells eight ov004 data
# words under a func_ prefix" a checkable sentence. Those two alias rows keep
# their own callers and are untouched.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN12dScMgSlot3_c13InitResourcesEv.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "func_020bc860=data_ov004_020bc860;func_020bc864=data_ov004_020bc864;func_020bc878=data_ov004_020bc878;func_020bc888=data_ov004_020bc888;func_020bc88c=data_ov004_020bc88c;func_020bc890=data_ov004_020bc890;func_020bc8b4=data_ov004_020bc8b4;func_020bc8b8=data_ov004_020bc8b8")

# Run mg11 lane RLT: dScMgRoulette_c, actor id 0x17f = scene 383, "Mushroom
# Roulette", and the FIFTH class the port seats under dScMgSingle3DBase_c.
#
#   Scene -> dScMgBase_c (ov004 0x020bc0c0) -> dScMgSingle3DBase_c
#         (ov006 0x0213e448) -> dScMgRoulette_c (ov006 0x0213e39c)
#
# both new tables 36 slots wide and checked FOUR ways before a word was written
# (port/slice_rlt.txt): span, terminal slot, what the word past the end is, and
# the relocation count inside the span with no row at index 36. The class name
# is the ROM's own type_info, "15dScMgRoulette_c" at 0x0213e30c, reached through
# the relocation the word before the vtable carries.
#
# THREE HOST COPIES, AND EACH IS A DIFFERENT DEFECT:
#
#   MgRoulette_Factory.cpp        REPLACES src/dScMgRoulette_c_classInit.cpp. The
#     SECOND AND LAST factory in the family that calls _ZN11dScMgBase_cC2Ev with
#     no argument -- port/unmatched/MgCup_Factory.cpp names this exact TU as the
#     other one. On ARM r0 still holds the object after `movs r4,r0`; on the
#     host the callee reads [esp+4] and writes three vtable words through it.
#     The displacement ruling is port/mg_fanout_costs.txt section 12's, spent
#     here for the other id that paragraph names.
#   MgRoulette_WheelDispatch.cpp  REPLACES src/actors/dScMgRoulette_c.cpp, which
#     carries TWO defects in eleven lines: the class's ONE mwcc member-pointer
#     dispatch (pair at offset 0 of the wheel object at +0x530c, universe of
#     exactly two code words bounded from the relocation set) and a local
#     shadow-class call of ROM vtable slot 3 on a HOST Model.
#   MgRoulette_ModelRender_02107d80.cpp  REPLACES src/actors/dScMgRoulette_c.cpp,
#     the same shadow defect at ROM slot 5, twice, on the DRAW path. A separate
#     file because the two failures look nothing alike and only one of them is
#     what a rendered frame depends on.
#
# All three src TUs are therefore OUT of port/slice_rlt.txt; listing both copies
# would be an LNK2005 and listing neither would drop the body silently. The
# assertion below is here rather than at the link because a duplicate-symbol
# wall reports far from its cause.
#
# NO LANGUAGE CXX ROW AND NO PER-SOURCE -D ROW, and both are sweeps rather than
# absences. All 41 TUs in the class's code block were scanned for the //cpp
# marker and for extern "C", virtual, class and namespace before the first
# build: the six hits are all already .cpp files (02107920, 02107a6c, 02107d80,
# 02107db8, 0210a194 and the factory), so CMake compiles each as C++ on its
# extension and no .c path in this slice is really C++. A scan of every source
# this seat adds for the bare placeholders VT, VT0, HEAP, G0, G1, G2, R0, R1 and
# R2 returns nothing.
#
# NO HOSTGEN SUBSTITUTION EITHER, and it is a decision rather than an omission,
# the same one the S381 block above records. The one body of this class's chain
# that writes a WRITE-TRIGGERED register is _ZN19dScMgSingle3DBase_c9Virtual84Ev (slot 33,
# LIGHT_COLOR at 0x040004cc), and that comes in already substituted through
# FLW_HOSTGEN_GEN. Slot 0's own writes -- 0x0400100c, 0x04001008 and 0x04000008
# -- are ordinary PPU control registers the display reads back out of the memory
# ntr maps there.
#
# ONE VARIABLE, for the reason the flower, fader and S381 blocks give: the slice
# and the .cpp are not separable. hal/scene_boot.cpp's port_scene_classes table
# now carries the scene-383 row, so every target that compiles scene_boot.cpp
# references port_mg_roulette_spawn and port_scene_fill_roulette by name.
#
# THE SLICE IS THE DELTA ONLY. slice_mg1.txt carries the ov004 framework, the
# thirty-five overlay constructors and the arm9 waves under them; slice_mem.txt
# carries the +0x4f38 model sub-object family this class shares with
# dScMgMemory2_c (including MgMemory2_FieldPmf.cpp, which routes the field
# member pointer this class's slot 6 dispatches every frame); slice_flw.txt and
# slice_mga361.txt carry the eight dScMgSingle3DBase_c bodies. CMake appends
# every list to the same targets and dedupes identical absolute paths, so
# nothing is compiled twice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_rlt.txt" SLICE_RLT_LINES)
set(SLICE_RLT_SOURCES hal/scene_mg_roulette.cpp
                      unmatched/MgRoulette_Factory.cpp
                      unmatched/MgRoulette_WheelDispatch.cpp)
# unmatched/MgRoulette_ModelRender_02107d80.cpp RETIRED (run link100, lane
# FOLD2): two plain Models drawn through a six-virtual shadow's index 5, and
# _ZTV5Model[5] is Model::Render again. src/actors/dScMgRoulette_c.cpp carries it
# (port/slice_fold2.txt).
foreach(line IN LISTS SLICE_RLT_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_RLT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(dup IN ITEMS src/minigames/d_s_mg_roulette.cpp src/actors/dScMgRoulette_c.cpp
                     src/actors/dScMgRoulette_c.cpp)
    if(dup IN_LIST SLICE_RLT_LINES)
        message(FATAL_ERROR
            "slice_rlt.txt lists ${dup}, which port/unmatched/ host-copies. "
            "Both would define the same symbol (LNK2005). Remove the slice line.")
    endif()
endforeach()

# run rel0215 wave 2 (lane cast-lvl16pair, sub-job 1 of 2): TOX_BOX (309),
# ov092. Fresh per-symbol ov092 mount (port/ov092_syms.txt). The 32-slot
# Platform fill, the nine-state PMF seat and the two method faces are
# hal/actor_classes_ov092.cpp; the ONE host-copied TU (the pointer-to-member
# dispatch site in ToxBox::Behavior, where MSVC's unknown-inheritance form is
# 16 bytes against the ROM's 8 and the array stride breaks with it) is
# unmatched/ToxBox_HostSites.cpp, the refusal itemised in port/slice_ov092.txt.
# ToxBox::Render is deliberately NOT refused: its six-virtual local shadow is
# over a plain Model at +0xd4, which cxxname_bridge.cpp:511 dual-fills, not
# over a ModelAnim -- the ov017 case, not the ov077 one.
# unmatched/ToxBox_ShadowFaces.cpp carries the slice's MEASURED closure gap,
# taken off the first link's own unresolved list rather than guessed: ONE
# symbol, ?GetNode@PathPtr@@QBEHAAUVector3@@I@Z, a naming mismatch against the
# already-linked flat _ZNK7PathPtr7GetNodeER7Vector3j, not a missing body.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov092.txt" SLICE_OV092_LINES)
set(SLICE_OV092_SOURCES "")
foreach(line IN LISTS SLICE_OV092_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV092_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
if("src/_ZN6ToxBox8BehaviorEv.cpp" IN_LIST SLICE_OV092_LINES)
    message(FATAL_ERROR
        "slice_ov092.txt lists src/_ZN6ToxBox8BehaviorEv.cpp, which "
        "port/unmatched/ToxBox_HostSites.cpp host-copies. Both would define "
        "_ZN6ToxBox8BehaviorEv (LNK2005). Remove the slice line.")
endif()

# run rel0215 wave 2 (lane cast-lvl16pair, sub-job 2 of 2): POKEY (240) +
# POKEY_SEGMENT (241, the same class) + TORNADO (308), ov096. Fresh per-symbol
# ov096 mount (port/ov096_syms.txt). The two 31-slot fills, the six-state PMF
# seat, the two RTTI-spelling bridges and the seven method faces are
# hal/actor_classes_ov096.cpp; the FIVE host-copied TUs (two real-C++
# destructors MSVC cannot name, the two pointer-to-member dispatch halves, and
# TORNADO's ModelAnim slot-5 Render) are the two unmatched/*_HostSites.cpp
# files, each refusal itemised in port/slice_ov096.txt.
# POKEY's Render is deliberately NOT refused even though it is the same
# six-virtual shadow shape: it dispatches on a plain Model at +0xd4, which
# cxxname_bridge.cpp:511 dual-fills, while TORNADO's is on a ModelAnim at
# +0x2c4, which cannot be. Two Renders in one overlay, one refused and one not.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov096.txt" SLICE_OV096_LINES)
set(SLICE_OV096_SOURCES "")
foreach(line IN LISTS SLICE_OV096_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV096_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(dup IN ITEMS src/actors/daSanbo_c.cpp src/_ZN7TornadoD1Ev.cpp
                     src/_ZN7Tornado6RenderEv.cpp src/actors/daSanbo_c.cpp
                     src/actors/daSanbo_c.cpp src/actors/daSanbo_c.cpp
                     src/_ZN7Tornado8BehaviorEv.cpp src/_ZN7Tornado6State1Ev.cpp
                     src/_ZN7Tornado13InitResourcesEv.cpp)
    if(dup IN_LIST SLICE_OV096_LINES)
        message(FATAL_ERROR
            "slice_ov096.txt lists ${dup}, which port/unmatched/ host-copies. "
            "Both would define the same symbol (LNK2005). Remove the slice line.")
    endif()
endforeach()
# src/_ZN7Tornado6State0Ev.cpp is a .c FILE THAT CARRIES C++: it opens with //cpp
# and wraps its declarations in `extern "C" { ... }`, which as C is
# `error C2059: syntax error: 'string'` on line 2. It is the ONLY .c file in
# either of this lane's two overlays that does -- found by a comment-stripped
# token sweep that includes `extern "C"` and the //cpp marker, the form ov077's
# slice specifies and which a narrower first sweep in this lane missed. It
# needs no host copy, only the language: unlike src/_ZN7Tornado6State1Ev.cpp it
# includes no headers at all, so compiling it as C++ cannot reach the
# decl_common.h redeclaration that forced that one out of the slice.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN7Tornado6State0Ev.cpp"
    PROPERTIES LANGUAGE CXX)

# run rel0215 wave 3 (lane w3-c): ov064's LAST THREE spawn-table classes --
# JET_STREAM (245, 18daWater_Hakidasi_c), WATER_RING (244, 14daWater_Ring_c) and
# TREASURE_CHEST (13, 11daObjTbox_c). ov064 is already mounted (gate 177); this
# lane appends their data to port/ov064_syms.txt and their TUs here. The two
# 31-slot fills, the TreasureChest D1 host chain and the two sinits' bring-up
# are in hal/actor_classes_ov064_w3c.cpp; six TUs are host-copied and one ROM
# body that has no source anywhere in the tree (_ZN13TreasureChest6State0Ev) is
# transcribed, each refusal itemised in port/slice_w3c.txt. The cast-ov066 /
# gate-64 shape: the hal file and the two new host copies ride in the slice's
# own SOURCES list, so the three target lists take ONE token.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w3c.txt" SLICE_W3C_LINES)
set(SLICE_W3C_SOURCES "")
foreach(line IN LISTS SLICE_W3C_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W3C_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_W3C_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_ov064_w3c.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Ov064_WaterRing.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/Ov064_TreasureChest.cpp")
# Both halves of the duplicate-definition guard the cast-ov066 lane wrote. The
# first set is host-copied in port/unmatched: listing any of them in the slice
# would define the same symbol twice (LNK2005). The last is
# src/func_ov064_02119ea0.c, which slice_gate179.txt ALREADY carries -- it is
# WaterRing's state-enter body, which gate 179 read as a stray pair behind "the
# Piece" table, so it is correct where it is and must not be listed again here.
foreach(dup IN ITEMS src/_ZN9WaterRing8BehaviorEv.cpp
                     src/func_ov064_02119ecc.cpp src/func_ov064_02119afc.cpp
                     src/_ZN13TreasureChest8SetStateEi.cpp
                     src/_ZN13TreasureChest17CallStateBehaviorEv.cpp src/_ZN13TreasureChest6RenderEv.cpp
                     src/_ZN13TreasureChestD1Ev.cpp src/func_ov064_02119ea0.c)
    if(dup IN_LIST SLICE_W3C_LINES)
        message(FATAL_ERROR
            "slice_w3c.txt lists ${dup}, which is already defined elsewhere in "
            "the link (a port/unmatched host copy, or slice_gate179.txt). Both "
            "would define the same symbol (LNK2005). Remove the slice line.")
    endif()
endforeach()

# Lane VSPOPUP: NUMBER (330) and WING_FEATHER (345), the two ov002 ids every
# live VS match declines. Both are RUN-TIME spawns on no level's object table,
# so the seat moves no boot census -- it only changes what a played frame can
# build. The fill is hal/actor_classes_vspopup.cpp (appended to the slice
# below); the mount is two SpawnInfo lines in port/ov002_syms.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_vspopup.txt" SLICE_VSPOPUP_LINES)
set(SLICE_VSPOPUP_SOURCES "")
foreach(line IN LISTS SLICE_VSPOPUP_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_VSPOPUP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_VSPOPUP_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_vspopup.cpp")
# The two D1s are deliberately NOT in the slice: both are MSVC-synthesised
# member destructors over LOCAL shadow hierarchies (the ONE_UP_LOGO recipe) and
# the fill spells each chain directly. Listing either would compile a shadow
# Actor/Model/... with no bodies and define the slot twice. The two callers,
# src/_ZN8dActor_c11SpawnNumberERK7Vector3jbtPS_.cpp and src/func_ov002_020f0918.c,
# are already in slice_gate10 and would be LNK2005 here.
foreach(dup IN ITEMS src/_ZN6NumberD1Ev.cpp src/game/actors/WingFeather/_ZN11WingFeatherD1Ev.cpp
                     src/_ZN8dActor_c11SpawnNumberERK7Vector3jbtPS_.cpp
                     src/func_ov002_020f0918.c)
    if(dup IN_LIST SLICE_VSPOPUP_LINES)
        message(FATAL_ERROR
            "slice_vspopup.txt lists ${dup}. The two D1s are spelled in the "
            "fill instead of compiled (hal/actor_classes_vspopup.cpp), and the "
            "two callers are already in slice_gate10 -- either way the link "
            "would carry the symbol twice (LNK2005). Remove the slice line.")
    endif()
endforeach()

# Lane CAPSHOW: the cap-visibility manager behind Stage::Render. Eleven matched
# TUs, no new mount -- the three ov001 tables func_ov001_020aa420 reads are
# already in port/ov001_syms.txt and ov001 is already in PORT_ACTOR_OVERLAYS.
# The derivation, the record census that says three of six caps show, and the
# ROM addresses are in the head of slice_cap.txt. The call site is one line in
# tests/walk_window.cpp, in Stage::Render's own order (after
# CylinderClsn::Process).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_cap.txt" SLICE_CAP_LINES)
set(SLICE_CAP_SOURCES "")
foreach(line IN LISTS SLICE_CAP_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_CAP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# The four ov001 functions on the same chain that slice_gate32/gate33 already
# compile. Listing one here would define it twice (LNK2005), and the failure
# reads as an unrelated duplicate-symbol wall three thousand objects later.
foreach(dup IN ITEMS src/func_ov001_020aa6b0.c src/func_ov001_020aa6cc.c
                     src/_ZN10dCapIcon_c6UnlinkEv.cpp src/func_ov001_020ab228.c)
    if(dup IN_LIST SLICE_CAP_LINES)
        message(FATAL_ERROR
            "slice_cap.txt lists ${dup}, which slice_gate32.txt / "
            "slice_gate33.txt already compile into the same link (LNK2005). "
            "Remove the slice line.")
    endif()
endforeach()

# ============================================================================
# ov029: level 21's own eight actors (water_city, Dire Dire Docks city).
# The fill is hal/actor_classes_ov029.cpp; the matched src closure is
# port/slice_ov029.txt; the SpawnInfo/resource/bss mount is port/ov029_syms.txt
# (ov029 is on PORT_ACTOR_OVERLAYS). Every consumer target gets ${OV029_SOURCES}.
# ============================================================================
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov029.txt" SLICE_OV029_LINES)
set(SLICE_OV029_SOURCES "")
foreach(line IN LISTS SLICE_OV029_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV029_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# The per-source vtable-store bindings. Each _Spawn/dtor stores its object's
# vptr through recovered names (VT0/VT1/VT2 and _ZTV<recovered>) whose ADDRESS
# is per source: the SAME recovered name is a different table in a different TU
# (_ZTV15daObjWc_Obj07_c is 0x021091d4 in daObjWc_Obj07_c_classInit but the own
# table 0x02114018 in the RectangleD1 TU -- the ov065 disease). Read off each
# body's own literal pool. Rule applied: the LIVE (last) store gets its true
# target (the own host array for a spawn; _ZTV10dBgActor_c for a destructor, the
# base reached at the bottom of the dtor chain); every DEAD earlier store is
# pointed at a guaranteed-defined host symbol (the class's own array), because
# it is immediately overwritten and its value never reaches a virtual call. The
# ROM's own ov002 base tables (_ZTV17daObjFloatBoard_c/021091d4) are NOT host arrays,
# so a dead store is never bound to them.
#
# Spawns -- live store is the own table:
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_wc_obj01.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV14daObjWcObj01_c=_ZTV14daObjWcObj01_c  --  identity rename, a no-op even if it had run
#   VT1=_ZTV14daObjWcObj01_c  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_wc_obj06.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV14daObjWcObj06_c=_ZTV14daObjWcObj06_c  --  identity rename, a no-op even if it had run
#   VT1=_ZTV14daObjWcObj06_c  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_wc_obj07.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV15daObjWc_Obj07_c=_ZTV15daObjWc_Obj07_c  --  identity rename, a no-op even if it had run
#   VT1=_ZTV15daObjWc_Obj07_c  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
# (ArrowLift/WaterDiamond/CageLift/SwitchActivatedPlank/WDW_Water spawns store
#  their own already-defined host symbol and need no binding.)
#
# Destructors -- live (last) store is _ZTV10dBgActor_c; dead stores to the own array:
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_wc_obj01.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV14daObjWcObj01_c=_ZTV14daObjWcObj01_c  --  identity rename, a no-op even if it had run
#   _ZTV10dBgActor_c=_ZTV14daObjWcObj01_c  --  dead, the TU does not spell _ZTV10dBgActor_c
#   VT2=_ZTV10dBgActor_c  --  dead, the TU does not spell VT2
# Deleted rather than merged. The surviving row is unchanged.
# GATE 229 CORRECTION (lane SEAT3). This row predates any seat of the TU, so it
# was never compiled and never checked. VT1 read the class's OWN table where the
# body's literal pool at 0x02111248 holds the ov002 base 0x02108fdc, and G0 was
# missing entirely, which would have left `extern void *G0;` unresolved. Both
# fixed from config/arm9/overlays/ov029/relocs.txt inside the body's own span.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wc_obj01.cpp"
    # and the generated copy, lane VPTR16: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set this for a source nothing
    # compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_obj_wc_obj01.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV14daObjWcObj01_c;VT1=_ZTV17daObjFloatBoard_c;VT2=_ZTV10dBgActor_c;G0=data_020a0eac")
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_wc_obj05.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV15daObjWc_Obj05_c=_ZTV15daObjWc_Obj05_c  --  identity rename, a no-op even if it had run
#   _ZTV10dBgActor_c=_ZTV10dBgActor_c  --  identity rename, a no-op even if it had run
# Deleted rather than merged. The surviving row is unchanged.
# link100 SPAWN2 CORRECTION, the third instance of the defect lane SEAT3 fixed
# twice at gate 229 and for the same reason: this row was written for a seat
# that never happened, so nothing had ever compiled it. G0 was missing
# entirely and `extern void *G0;` in the body would have gone unresolved
# (or, worse, bound to the global cxx_aliases G0). Read from the body's own
# literal pool in config/arm9/overlays/ov029/relocs.txt: 0x02111b54 ->
# 0x02113e74 (VT0, the class's own table), 0x02111b58 -> 0x0210ae38
# (VT1 = _ZTV10dBgActor_c), 0x02111b5c -> 0x020a0eac (G0, the game heap
# pointer Memory::Deallocate takes). VT0/VT1 were already right.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wc_obj05.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV15daObjWc_Obj05_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_wc_obj06.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV14daObjWcObj06_c=_ZTV14daObjWcObj06_c  --  identity rename, a no-op even if it had run
#   _ZTV10dBgActor_c=_ZTV14daObjWcObj06_c  --  dead, the TU does not spell _ZTV10dBgActor_c
#   VT2=_ZTV10dBgActor_c  --  dead, the TU does not spell VT2
# Deleted rather than merged. The surviving row is unchanged.
# GATE 229 CORRECTION (lane SEAT3), the same two defects as the 021111f0 row
# above: VT1 belongs to the ov002 base 0x02108fdc (pool word 0x02111f4c), not to
# the class's own table, and G0 was missing.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wc_obj06.cpp"
    # and the generated copy, lane VPTR16: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set this for a source nothing
    # compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_obj_wc_obj06.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV14daObjWcObj06_c;VT1=_ZTV17daObjFloatBoard_c;VT2=_ZTV10dBgActor_c;G0=data_020a0eac")
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_wc_obj02.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV15daObjWc_Obj02_c=_ZTV15daObjWc_Obj02_c  --  identity rename, a no-op even if it had run
#   _ZTV10dBgActor_c=_ZTV10dBgActor_c  --  identity rename, a no-op even if it had run
# Deleted rather than merged. The surviving row is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wc_obj02.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV15daObjWc_Obj02_c=_ZTV15daObjWc_Obj02_c;_ZTV10dBgActor_c=_ZTV10dBgActor_c")
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_wc_obj07.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV15daObjWc_Obj07_c=_ZTV15daObjWc_Obj07_c  --  identity rename, a no-op even if it had run
#   _ZTV10dBgActor_c=_ZTV15daObjWc_Obj07_c  --  dead, the TU does not spell _ZTV10dBgActor_c
#   VT2=_ZTV10dBgActor_c  --  dead, the TU does not spell VT2
# Deleted rather than merged. The surviving row is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wc_obj07.cpp"
    # and the generated copy, lane VPTR16: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set this for a source nothing
    # compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_obj_wc_obj07.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV15daObjWc_Obj07_c=_ZTV15daObjWc_Obj07_c;_ZTV10dBgActor_c=_ZTV15daObjWc_Obj07_c;VT2=_ZTV10dBgActor_c")
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_wc_mizu.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV14daObjWc_Mizu_c=_ZTV19RotatingPlatformWdw  --  dead, the TU does not spell _ZTV14daObjWc_Mizu_c
#   _ZTV10dBgActor_c=_ZTV10dBgActor_c  --  identity rename, a no-op even if it had run
# Deleted rather than merged. The surviving row is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wc_mizu.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV14daObjWc_Mizu_c=_ZTV19RotatingPlatformWdw;_ZTV10dBgActor_c=_ZTV10dBgActor_c")
# BOTH PATHS, run link100 lane HOSTGEN4: this TU joined PORT_HOSTGEN_TU for
# its decorated dBgW callback address, so the compile the build runs is the
# generated copy. These two vtable renames are what make the class dispatch
# through SwitchActivatedPlank's table at all; naming only the src/ row
# would drop them silently, which is the drift the check near line 400
# refuses. The src/ row is kept so the property is still right if the
# substitution is ever retired.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_wc_obj04.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV15daObjWc_Obj04_c=_ZTV20SwitchActivatedPlank  --  dead, the TU does not spell _ZTV15daObjWc_Obj04_c
#   _ZTV10dBgActor_c=_ZTV10dBgActor_c  --  identity rename, a no-op even if it had run
# Deleted rather than merged. The surviving row is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wc_obj04.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_obj_wc_obj04.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV15daObjWc_Obj04_c=_ZTV20SwitchActivatedPlank;_ZTV10dBgActor_c=_ZTV10dBgActor_c")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wc_obj03.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV15daObjWc_Obj03_c=_ZTV9ArrowLift")
# __sinit_ov029_02112c10.c (ArrowLift's SharedFilePtr) writes its destruct-node
# cell through dsd's cross-overlay name _ZN7daMky_c8BehaviorEv, which is a
# real ov030 FUNCTION this link may define. Bind it to ov029's own bss cell at
# 0x02114278, the W10/RacingPenguin remedy. The reloc says the address:
#   from:0x02112c34 kind:load to:0x02114278 module:overlay(29)
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/__sinit_ov029_02112c10.c"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZN7daMky_c8BehaviorEv=data_ov029_02114278")

# Two ov029 bodies are //cpp-marked .c files (a top-level `extern "C" {` block,
# invalid C): compile them as C++.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wc_obj01.cpp"
    # and the generated copy, lane VPTR16: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set this for a source nothing
    # compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_obj_wc_obj01.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_wc_obj06.cpp"
    # and the generated copy, lane VPTR16: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set this for a source nothing
    # compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_obj_wc_obj06.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN8dActor_c17GetWaterHeightWDWEv.cpp"
    PROPERTIES LANGUAGE CXX)

set(OV029_SOURCES hal/actor_classes_ov029.cpp unmatched/Ov029_MethodFaces.cpp ${SLICE_OV029_SOURCES})

# Lane DTOR-FACES-CPP (status/DTORFACES.md): the real-C++ D1 TUs of seated
# classes, seated in slot 16 through hal/dtor_faces_cpp.cpp. The slice rides
# the same four targets as the fills it serves (smoke_player, walk_window and
# the two derived windows), next to hal/dtor_seats_base.cpp.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_dtorfaces.txt" SLICE_DTORFACES_LINES)
set(SLICE_DTORFACES_SOURCES "")
foreach(line IN LISTS SLICE_DTORFACES_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_DTORFACES_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# The camera slice is on both binaries. The gate-13 State objects carry real
# DS function addresses, and Player::ChangeState already reaches
# func_0200d81c -> Camera::ChangeState on every state change, so the smoke
# needs the host dispatcher too or the first ChangeState calls a mwcc
# member-function pointer.
# SMOKELINK6 (run link100, wave 10 round 6, 2026-09-17): EXCLUDE_FROM_ALL.
# This target does not link -- two names outstanding, Stage::Behavior and
# Stage::Render (SMOKELINK5B's finding, out/SMOKELINK5B/bugs.md item 2): the
# compiler-generated _ZTV5Stage vtable asks for both directly, and their
# matched bodies reach the window's message pump, pause screen, vignette
# effect and level-complete closure whole, none of which this harness --
# "Mario standing for a BMP capture" -- has ever hosted (GATE 220 / RENDER9's
# own ruling). A scope question, not a missing row. Excluded from the default
# build so port/build-port.cmd (no -k) completes; still buildable by name
# (`ninja smoke_player`) once the scope question is settled.
add_executable(smoke_player EXCLUDE_FROM_ALL tests/smoke_player.cpp "${OV002DATA_C}" ${LEVEL_OV_DATA}
    # hal/sub_screen.cpp is in this target's list below, and since the screen
    # gap landed it asks hal/screen_gap.cpp for the stacked layout -- which in
    # turn asks hal/host_settings.cpp for the player's four gap keys. Neither
    # of those was in this harness before: it never read settings.json and
    # never composed a stacked image. They are here to close the link, and a
    # harness with no settings.json beside it gets every default.
    hal/screen_gap.cpp hal/host_settings.cpp hal/gap_art.cpp hal/gap_continuity.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/meshcolliderbase_vtable.cpp hal/meshcollider_dtor_seat.cpp hal/lk1_eh_vmax_seat.cpp hal/lk2_platform_dtor_seat.cpp hal/model_dtor_seat.cpp hal/dtor_seats_base.cpp hal/dtor_faces_cpp.cpp hal/actorport_dtor_bridge.cpp hal/actorport_dtor_faces.cpp ${SLICE_DTORFACES_SOURCES} hal/lk4_eh_dtor_seat.cpp hal/lk4_solidheap_seat.cpp hal/gx_upload_bridge.cpp hal/cstd_div.c
    hal/clsn_vtable.cpp hal/actor_vtables.cpp hal/anim_bridge.cpp
    ${SLICE_W8SHADOWS_SOURCES}
    # hal/megachar_stub.cpp is NOT here any more (lane w8-shadows). Its
    # `return 0` stand-in for Platform::UpdateKillByMegaChar is now compiled
    # only into the three narrow gate-9 harnesses above, which cannot build the
    # real closure. In this target the ROM's C name is the face at the bottom
    # of hal/wf_enemy_bridges.cpp and the body is the matched TU that has been
    # sitting in slice_gate16.txt line 178 all along, dropped by /OPT:REF for
    # want of a reference edge. Removing the stub from here is what makes the
    # matched body reachable; leaving it would be a duplicate definition.
    "${PORT_FACES_SYNC_GEN}" hal/cxxname_bridge.cpp hal/player_bridges.cpp hal/luigi_infection.cpp hal/cxx_aliases.cpp hal/auto_bss.cpp hal/reverse_bridges.cpp hal/method_faces.cpp hal/door_ring_faces.cpp hal/fader_wipes.cpp "${CMAKE_CURRENT_SOURCE_DIR}/../src/engine/fader/_ZN9FaderWipe14LoadAndSetFileEt.cpp" hal/level_boot.cpp hal/stage_mods.cpp hal/scene_boot.cpp hal/title_vtable_seat14d.cpp ${SLICE_TITLE_SOURCES} hal/title_doodle_probe.cpp hal/scene_actor_faces.cpp ${SLICE_SCENE1_SOURCES} ${SLICE_CARDFS_SOURCES} ${SLICE_OV007_SOURCES} ${SC1_INTERIM_SOURCES} ${SLICE_MG1_SOURCES} ${SCENE_MG_SOURCES} ${SLICE_LUI_SOURCES} ${SLICE_PCH_SOURCES} ${SLICE_SMB_SOURCES} ${SCENE_SMB_SOURCES} ${SLICE_CCN_SOURCES} ${SLICE_PPP_SOURCES} ${SLICE_FLW_SOURCES} ${SCENE_MG_FLOWER_SOURCES} ${SLICE_MEM_SOURCES} ${SLICE_S381_SOURCES} ${SLICE_MMT_SOURCES} ${SLICE_LKT_SOURCES} ${SLICE_SOS_SOURCES} ${SLICE_S75_SOURCES} ${SCENE_MG_CURLING2_SOURCES} ${SLICE_PSY_SOURCES} ${SLICE_LKY_SOURCES} ${SLICE_SNW_SOURCES} ${SLICE_TTE_SOURCES} ${SLICE_BOO_SOURCES} ${SLICE_WIG_SOURCES} ${SLICE_S371_SOURCES} ${SLICE_BOX_SOURCES} ${SLICE_S364_SOURCES} ${SCENE_MG_SLOT1_SOURCES} ${SLICE_CUP_SOURCES} ${SLICE_MUG_SOURCES} ${SLICE_BNP_SOURCES} ${SLICE_BNT_SOURCES} ${SLICE_PKR_SOURCES} ${SLICE_PGO_SOURCES} ${SLICE_RLT_SOURCES} ${SLICE_TTI_SOURCES} ${SLICE_MGM_SOURCES} ${SLICE_VS_SOURCES} ${FDR_FADER_SOURCES} ${NFS_NAMES_SOURCES}
    # run link60 lane L2: hal/w8a_stage_storage.cpp is pure zero arm9 BSS and it
    # owns data_0209d4a8, which dScDSMT_c's InitResources and CleanupResources
    # both touch. walk_window already had it; smoke_player and walk_window_hires
    # did not, so it joins all three rather than the symbol being defined a
    # second time next to the one that already exists.
    hal/w8a_stage_storage.cpp hal/cannon_probe.cpp hal/message_boot.cpp hal/message_gen_text.cpp hal/message_compositor.cpp hal/actor_registry.cpp hal/actor_classes.cpp hal/actor_slot30_seat.cpp hal/actor_classes_bob_world.cpp hal/actor_faces_bob.cpp hal/actor_class_faces.cpp hal/mmc_vtable.cpp hal/ov009_boot.cpp hal/actor_overlays.cpp hal/sub_screen.cpp ${SLICE_2D1_SOURCES} hal/sub_actors.cpp hal/stage_bridges.cpp "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN5Stage16OnPendingDestroyEv.cpp" hal/level_change.cpp hal/title_entry.cpp hal/star_flow.cpp hal/oam_lists.cpp hal/blend_vtable.cpp hal/particle_vtable.cpp hal/particle_bridges.cpp unmatched/Particle_RideThroughs.cpp
    # Run link100 wave 17, lane PAINT5. The PAINTING's twelfth state body,
    # ov080 0x021261f4, which has no src TU and no near-miss draft and was a
    # named trap in hal/actor_overlays.cpp's g_painting_states until now. It
    # rides EVERY target that compiles hal/actor_overlays.cpp and is optional
    # on none of them: that file's pt_f_021261f4 face calls
    # func_ov080_021261f4 by name, so a target that takes the seat and not
    # this file fails the link on that symbol.
    unmatched/Painting_StateRender_021261f4.cpp
    ${CAMERA_HOST_SOURCES} ${LEVELBOOT_HOST_SOURCES} ${SOUND_HOST_SOURCES}
    ${MODELFAMILY_HOST_SOURCES}
    ${SLICE_W23_MODELDTOR_SOURCES}
    ${SLICE_PTR_SOURCES}
    # Stage 4, lane SD0: slot 0's closure. On all THREE targets rather than
    # walk_window alone, and not by preference: all three compile
    # hal/stage_bridges.cpp, which is where the Stage vtable and its slot-0
    # occupant live, so a face or a body that only one of them carried would
    # fail the other two at link. hal/stage_slot0.cpp holds the three
    # PORT_HOST_ABI bodies, the four C-name faces, two 4-byte arm9 BSS words
    # and the data_02075720 alias; the slice holds the ROM's own TUs.
    hal/stage_slot0.cpp ${SLICE_S4_SLOT0_SOURCES}
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_HOSTGEN_SOURCES}
    ${SLICE7_SOURCES} ${SLICE8_SOURCES} ${SLICE9_CAM_SOURCES}
    ${SLICE10_CAM_SOURCES} ${SLICE_COMMS_SOURCES} ${SLICE13_SOURCES} ${SLICE14_SOURCES}
    ${SLICE15_SOURCES} ${SLICE16_SOURCES} ${SLICE17_SOURCES}
    ${SLICE18_SOURCES} ${SLICE19_SOURCES} ${SLICE20_SOURCES}
    ${SLICE_W1L1_SOURCES} ${SLICE_W1L2_SOURCES} ${SLICE_W1L3_SOURCES}
    ${SLICE_W1L4_SOURCES} ${SLICE_W1L5_SOURCES} ${SLICE_W5D_SOURCES} ${SLICE_W5E_SOURCES}
    ${SLICE_W6A_SOURCES}
    ${SLICE_W9HARVEST_SOURCES} ${SLICE_L15CP_SOURCES}
    ${SLICE_W5C_SOURCES} ${SQRTUNIT_GEN} ${OV70GEN}
    ${SLICE_W5B_SOURCES} ${SLICE_W5A_SOURCES} ${SLICE_W6D_SOURCES}
    ${SLICE_W3A_SOURCES}
    ${SLICE_W7C_SOURCES}
    hal/actor_classes_ov022.cpp ${SLICE_W8PACKS_SOURCES} ${SLICE_LAVA_SOURCES}
    hal/actor_classes_ov031_w10.cpp ${SLICE_W10A_SOURCES}
    ${SLICE_W10B_SOURCES}
    ${SLICE_W11_SOURCES}
    hal/actor_classes_ov073.cpp unmatched/Ov073_State.cpp
    # unmatched/Ov073_Render.cpp RETIRED (run link100, lane EXCEPT): the
    # ROM-order BlendModelAnim slot-5 reason died with SLOT5F's respelling.
    # src/_ZN11ChiefChilly6RenderEv.cpp is on port/slice_except2.txt and its
    # C name comes from hal/except_faces.cpp.
    ${SLICE_W12_SOURCES}
    hal/actor_classes_ov052.cpp ${SLICE_W12B_SOURCES}
    hal/actor_classes_ov064_w12.cpp
    # unmatched/Ov064_Clam.cpp RETIRED (run link100, lane EXCEPT): both its
    # bodies were the slot-5 reading. src/_ZN4Clam6RenderEv.cpp and
    # src/_ZN13TreasureChest6RenderEv.cpp are on port/slice_except2.txt.
    ${SLICE_W12C_SOURCES}
    hal/actor_classes_ov056.cpp ${SLICE_W15_SOURCES}
    hal/actor_classes_ov002_w15.cpp ${SLICE_W15B_SOURCES}
    hal/actor_classes_ov025.cpp ${SLICE_W15C_SOURCES}
    hal/actor_classes_ov022_w16.cpp ${SLICE_W16A_SOURCES}
    hal/actor_classes_ov002_w17.cpp ${SLICE_W17A_SOURCES}
    ${SLICE_W18A_SOURCES} ${SLICE_PMF2_SOURCES} ${SLICE_PMF3_SOURCES} hal/pmf3_aliases.cpp hal/ttc_level_data_seat.cpp
    ${SLICE_PMFC_SOURCES} hal/pmfc_aliases.cpp
    unmatched/Ov070_PmfDispatch.cpp
    ${SLICE21_SOURCES} ${SLICE22_SOURCES} ${SLICE23_SOURCES} ${SLICE25_SOURCES} ${SLICE26_SOURCES}
    ${SLICE27_SOURCES} ${SLICE28_SOURCES} ${SLICE33_SOURCES} ${SLICE_TAGFIX_SOURCES} ${GATE6_GEN} ${SLICE31_SOURCES} ${SLICE35_SOURCES} ${SLICEINTRO_SOURCES} ${SLICE219_SOURCES}
    ${SLICE27_SOURCES} ${SLICE28_SOURCES} ${SLICE32_SOURCES}
    ${GATE32_HOST_SOURCES} ${GATE32_GEN} ${GATE6_GEN}
    ${GATE4A_GEN} ${GATE4B_GEN} ${GATE8_GEN} ${GATE10_GEN}
    ${GATE13_GEN} ${GATE14_GEN} ${GATE15_GEN} ${GATE16_GEN} ${GATE35_GEN} ${GATE29_GEN} ${T2_DIV_GEN} ${TI2_MOD_GEN} ${SQ_DIST_GEN} ${TITEX_GX_GEN} ${TIDEP_RESET_GEN} ${R3B_SWAP_GEN}
    ${GATE9_GEN} ${HOSTABI_RETIRE_GEN}
    ${SLICE40_SOURCES} ${SLICE41_SOURCES} ${SLICE42_SOURCES}
    hal/actor_classes_painting.cpp ${SLICE50_SOURCES} hal/actor_classes_wf.cpp
    unmatched/Cap_StateDispatch.cpp unmatched/ExclamationSwitch_StateDispatch.cpp ${SLICE51_SOURCES} ${SLICE59_SOURCES} ${SLICE78_SOURCES} ${SLICE79_SOURCES} ${SLICE82_SOURCES} ${SLICE83_SOURCES} ${SLICE64_SOURCES} ${GATE64_GEN} ${SLICE89_SOURCES} ${SLICE102_SOURCES} ${SLICE103_SOURCES} ${SLICE128_SOURCES} ${SLICE121_SOURCES} ${SLICE122_SOURCES} ${SLICE123_SOURCES} ${SLICE209_SOURCES} hal/actor_classes_runtime_spawns.cpp ${SLICE210_SOURCES} unmatched/YoshiEgg_StateDispatch.cpp
    hal/actor_classes_ccm.cpp ${SLICE142_SOURCES} ${SLICE190_SOURCES} ${SLICE191_SOURCES} ${SLICE_MPG_SOURCES} ${SLICE_MPG2_SOURCES} unmatched/SoundObject_Behavior.cpp unmatched/MotherPenguin_AfterClsnSeat.cpp unmatched/MotherPenguin_ChaseGate.cpp ${SLICE_SMALLS_SOURCES} ${SLICE_SEAT1_SOURCES} unmatched/MotherPenguin_Behavior.cpp hal/actor_classes_ov081.cpp ${SLICE192_SOURCES} unmatched/MrBlizzard_Behavior.cpp ${SLICE_W3B_SOURCES} ${W3BGEN} hal/actor_classes_ov072.cpp ${SLICE193_SOURCES} unmatched/Snowman_InitResources.cpp ${SLICE_SHADOWS_SOURCES} ${SLICE_SHADOWS3_SOURCES} hal/actor_classes_ov094.cpp ${SLICE194_SOURCES} unmatched/HootTheOwl_StateDispatch.cpp hal/actor_classes_ov012.cpp ${SLICE199_SOURCES} hal/actor_classes_ov002g200.cpp ${SLICE200_SOURCES} unmatched/PushBlock_StateDispatch.cpp hal/actor_classes_ov013.cpp ${SLICE202_SOURCES} hal/actor_classes_ov077.cpp ${SLICE_OV077_SOURCES} unmatched/Lakitu_HostSites.cpp unmatched/Spiny_HostSites.cpp unmatched/HeaveHo_HostSites.cpp unmatched/Lakitu_ShadowFaces.cpp ${SLICE_OV030CAST_SOURCES} hal/actor_classes_ov092.cpp ${SLICE_OV092_SOURCES} unmatched/ToxBox_HostSites.cpp unmatched/ToxBox_ShadowFaces.cpp hal/actor_classes_ov096.cpp ${SLICE_OV096_SOURCES} unmatched/Pokey_HostSites.cpp unmatched/Tornado_HostSites.cpp unmatched/Ov072_MethodFaces.cpp ${SLICE_VSPOPUP_SOURCES} ${SLICE_CAP_SOURCES} ${SLICEBULLET_SOURCES} unmatched/Bullet_StateDispatch.cpp hal/actor_classes_bullet.cpp
    # run rel0215 wave 1 (lane cast-ov026): ov026's whole cast, level 18.
    hal/actor_classes_ov026.cpp ${SLICE_OV026_SOURCES} unmatched/Whirlpool_Behavior.cpp unmatched/WaterSuction_Behavior.cpp
    hal/actor_classes_ov036.cpp ${SLICE_OV036CAST_SOURCES}
    # run rel0215 wave 2 (lane cast-ov090): ov090's whole four-class water cast.
    ${SLICE_OV090_SOURCES}
    # run rel0215 wave 3 (lane w3-f2): ov091's ARROW_PATH_LIFT (157) +
    # SQUARE_METAL_NET_LIFT (144) -- one class, two ids -- and FWOOSH (231).
    ${SLICE_W3F2_SOURCES}
    # run rel0215 wave 2 (lane cast-ov066): EYEROK (176), ov066, level 17.
    ${SLICE_OV066_SOURCES}
    ${SLICE_W3C_SOURCES}
    hal/actor_classes_ov027.cpp ${SLICE_OV027CAST_SOURCES} unmatched/DaPgDfdr_StateDispatch.cpp
    # unmatched/Player_BlowAway.cpp RETIRED (run link100, lane FACEF): its tag
    # read "cdecl C name the caller wants versus the matched TU's thiscall
    # Player::BlowAway method, whose src ALSO cannot compile in-tree
    # (decomp-side Player.h gap)". The first half is the ordinary face repair;
    # the second half was MEASURED FALSE -- src/_ZN6Player8BlowAwayEs.cpp
    # compiles clean standalone under this build's own flags today, because
    # include/Player.h now carries BlowAway (:534), mIsMetal (:236) and
    # mIsBalloon (:240) and include/Actor.h mAngleY (:92) and mPrevAngleY
    # (:95), which are the four fields the ROM listing in the retired file
    # names. src/_ZN6Player8BlowAwayEs.cpp is on port/slice_facef.txt and its
    # C name comes from hal/except_faces.cpp.
    ${SLICE_OV074_SOURCES}
    hal/actor_classes_bbh.cpp ${SLICE149_SOURCES}
    hal/actor_classes_hmc.cpp ${SLICE172_SOURCES} unmatched/Crate_StateDispatch.cpp
    hal/actor_classes_updownlift.cpp ${SLICE173_SOURCES} unmatched/UpDownLiftBbh_Behavior.cpp
    hal/actor_classes_montymole.cpp ${SLICE174_SOURCES} unmatched/MontyMole_StateDispatch.cpp unmatched/MontyMole_1Up.cpp
    hal/actor_classes_flame.cpp ${SLICE175_SOURCES}
    hal/actor_classes_flamethrower.cpp ${SLICE_W6F_SOURCES}
    ${SLICE_W8FACES_SOURCES}
    hal/actor_classes_scuttlebug.cpp ${SLICE176_SOURCES} unmatched/Scuttlebug_StateDispatch.cpp
    hal/actor_classes_ov071.cpp ${SLICE_W7B_SOURCES} ${GATE_W7B_GEN} unmatched/MrI_StateDispatch.cpp
    # unmatched/MrI_Render.cpp RETIRED (run link100, lane EXCEPT): its own
    # header said "If _ZTV9ModelAnim ever gains a ROM-order view, this
    # retires", and SLOT5F gave it one. src/_ZN3MrI6RenderEv.cpp is on
    # port/slice_except2.txt.
    hal/actor_classes_ov064.cpp ${SLICE177_SOURCES} unmatched/Bully_AfterClsn.cpp
    hal/actor_classes_ov064_gate178.cpp ${SLICE178_SOURCES} unmatched/Ov064Gate178_States.cpp
    hal/actor_classes_ov064_w9.cpp ${SLICEW9A_SOURCES} ${SLICEW9B_SOURCES} ${SLICEW9C_SOURCES} ${SLICEW9D_SOURCES}
    hal/actor_classes_jrb.cpp ${SLICE188_SOURCES}
    # unmatched/Jrb_Renders.cpp RETIRED (run link100, lane FACEF): all four of
    # its bodies were the ROM-order model slot-5 draw, and both halves of its
    # stated reason are dead -- the numbering with lane SLOT5F's respelling,
    # and the return-type half because an indirect call through the object's
    # own vptr decorates nothing. src/_ZN6ShipUp6RenderEv.cpp,
    # src/_ZN10SlidingBox6RenderEv.cpp, src/_ZN10RockPillar6RenderEv.cpp
    # and src/actors/daObjFloatBoard_c.cpp are on port/slice_facef.txt; the two
    # method recoveries take a cdecl face in hal/except_faces.cpp and the two
    # C names need none.
    unmatched/Unagi_StateDispatch.cpp unmatched/Jrb_Aliases.cpp
    ${SLICE_SMALL7_SOURCES}
    hal/actor_classes_bowserpuzzle.cpp ${SLICE179_SOURCES} unmatched/BowserPuzzle_StateDispatch.cpp
    hal/actor_classes_koopa_chuckya.cpp hal/koopa_chuckya_faces.cpp ${SLICE182_SOURCES} unmatched/KoopaChuckya_StateDispatch.cpp ${SLICEKLEPTO_SOURCES} unmatched/Klepto_StateDispatch.cpp unmatched/Klepto_PathPtrFaces.cpp
    ${SLICE180_SOURCES} ${SLICE203_SOURCES} ${SLICE204_SOURCES}
    hal/actor_classes_ov085.cpp ${SLICE205_SOURCES}
    unmatched/Ov085_Behaviors.cpp
    # unmatched/Ov085_Toad_StateSeat.cpp RETIRED (run link100, lane PMFB1):
    # it held only Toad's two state dispatchers and their static helper, and
    # src/_ZN4Toad8SetStateEi.cpp and src/_ZN4Toad8RunStateEv.cpp carry both on
    # port/slice_pmfc.txt (block R9d). The seat that fills their table is
    # port_toad_states_seat in hal/actor_overlays.cpp and is untouched.
    # run rel0215 wave 3 (lane w3-f): ov085's PRINCESS_PEACH, the sixth
    # and last class. ONE host copy rides beside the slice now, the two PMF
    # dispatchers; unmatched/Ov085_PrincessPeach_Behavior.cpp RETIRED (run
    # link100, lane FOLD2) because the slot-6 body's whole reason was the
    # ModelAnim slot-3 numbering, and _ZTV9ModelAnim[3] is UpdateVerts again.
    ${SLICEW3F_SOURCES}
    unmatched/Ov085_PrincessPeach_Declshapes.cpp
    hal/actor_classes_montymolerock.cpp ${SLICE208_SOURCES}
    hal/actor_classes_ov043.cpp ${SLICE206_SOURCES} ${SLICE207_SOURCES} ${SLICEBDW_SOURCES}
    # gate 215 (run link100, lane SAVE): the save system's own medium path,
    # plus the hosted backup medium the ARM7 would otherwise answer for.
    ntr/backup.cpp ${SLICE215_SOURCES} hal/os_lockid.cpp hal/globals_link100.cpp
    hal/scene_link100_base_faces.cpp hal/scene_link100_boot.cpp
    hal/scene_link100_mb.cpp ${SLICE218_SOURCES} hal/boot_globals.cpp hal/stage_globals.cpp
    hal/actor_classes_enemy_spawner.cpp ${SLICE211_SOURCES} hal/actor_classes_question_switch.cpp ${SLICE212_SOURCES} ${SLICE216_SOURCES}
    hal/boot2_ipc.cpp ${SLICE2IPC_SOURCES} ${GATE2IPC_GEN}
    hal/actor_classes_enemy_spawner.cpp ${SLICE211_SOURCES} hal/actor_classes_question_switch.cpp ${SLICE212_SOURCES} ${SLICE213_SOURCES}
    # ---- link100 SCENE ---- the two arm9-resident scene classes, gate 218
    hal/actor_classes_l7.cpp ${SLICE_L7_SOURCES} ${GATE_L7_GEN} unmatched/PiranhaPlant_States.cpp
    unmatched/WaterBomb_StateDispatch.cpp
    unmatched/KnockDownPlank_Behavior.cpp
    # unmatched/FallBlockWf_InitVeneer.cpp RETIRED (run link100 wave 15, lane
    # SEAT15A): it held ONE body, func_ov098_0213a794, under a PORT_HOST_ABI tag
    # saying MSVC C2733 rejects the matched TU's second extern-C declaration of
    # itself. Re-measured on this tree with the port's own command line,
    # src/func_ov098_0213a794.cpp compiles clean and emits the same flat cdecl
    # name, so the tag was stale and the file had no reason left. The TU is on
    # port/slice_l15enab.txt, which carries the measurement.
    # run rel0215 wave 1 (lane cast-sweep1): the six small-cast overlays
    ${SWEEP1_SOURCES}
    # run rel0215 wave 2 (lane cast-sweep2): the four-overlay cast sweep
    ${SWEEP2_SOURCES}
    # run rel0215 wave 3 (lane w3-e): three partially-seated level
    # overlays' remaining tails (ov022, ov019, ov025)
    ${W3E_SOURCES}
    # ov029: level 21's water_city actors, ids 94..101
    ${OV029_SOURCES}
    # ---- link100 OV ---- ids 348 (ov002, daChRoom_c) and 314 (ov039, Cloud)
    hal/actor_classes_ov_link100.cpp ${SLICE217_SOURCES}
    # run link100 wave 15, lane SEAT15E: LINK15 BATCH 4 seats (slice_l15ov7)
    ${SLICE_L15OV7_SOURCES}
    "${ROMDATA_C}" "${OV009SYMS_C}" ${ACTOR_OV_SYMS} "${OVCROSS_C}")
target_include_directories(smoke_player PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(smoke_player PRIVATE ntr)
target_compile_definitions(smoke_player PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF}
    # GATE SHADOWS RUNG 3 (run link100, lane SHADOWS2): this target carries
    # port/slice_shadows.txt AND port/slice_gate16.txt, so the ROM's own
    # SharedFilePtr::ReallocateModelFile is in the link with func_02017060
    # under it.  The define retires the empty stand-in in
    # hal/gx_upload_bridge.cpp, which would otherwise defeat that file's
    # /alternatename by defining its LHS.  The ten narrow harnesses link the
    # caller without the callee and keep the stand-in.
    SM64DS_SFP_REALLOC_ROM=1
    # this target links hal/cxx_aliases.cpp, which already carries
    # the Heap::_Deallocate face hal/blend_vtable.cpp repeats
    PORT_CXX_ALIASES_LINKED)
if(MSVC)
    target_compile_options(smoke_player PRIVATE /wd4311 /wd4312 /wd4068 /wd4576)
endif()

# run linkw wave 8 (lane w8-a): THE STAGE CLASS CLOSURE, first landed piece.
#
# Eight matched Stage bodies plus the one callee they drag (nine TUs), the
# class's own arm9 BSS (hal/w8a_stage_storage.cpp) and the C-name faces that
# reach them (hal/w8a_stage_faces.cpp). There are no /include: link roots here
# and NOTHING REACHES THESE YET: every one of the nine is /OPT:REF-stripped and
# every alias LHS is unused, which is why this lands at the linkage floor. The
# slice head records, per held-out TU, the measured blocker that keeps the other
# twenty-one out; the faces file records that the reach does not exist, because
# the ROM reaches all of these through _ZTV5Stage, which hal/stage_bridges.cpp
# still trap-fills. Seating that table is what turns this groundwork live.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w8a.txt" SLICE_W8A_LINES)
set(SLICE_W8A_SOURCES "")
foreach(line IN LISTS SLICE_W8A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W8A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()

# Gate 12: the interactive window (same stack, windowed loop).
#
# tests/io_pressure.cpp is the negative control for ntr/io.cpp's fixed-address
# reservation: it takes 0x02000000 before the game asks for it, so the failure a
# player hit can be reproduced on demand against THIS binary rather than against
# a special build of it. Inert unless SM64DS_IO_PRESSURE_AT is set in the
# environment, and nothing in the tree sets it.

add_executable(walk_window tests/walk_window.cpp tests/io_pressure.cpp
    hal/resource_pack.cpp "${OV002DATA_C}" ${LEVEL_OV_DATA}
    # run link100 lane BOOT: the ROM's own boot chain, called from the four
    # port_boot_rom_* seams in tests/walk_window.cpp's main. See the gate-214
    # block above and the header of hal/boot_os.cpp.
    ${SLICE214_SOURCES} ${SLICE_IPCSEND_SOURCES}
    # dialogue pipeline (2026-08-08): the box pump (Stage::UpdateMessage's
    # dialogue arm), the engine-A 2D-over-3D compositor, and the headless probe.
    hal/message_pump.cpp hal/message_compositor.cpp hal/message_probe.cpp hal/message_gen_text.cpp hal/input_probe.cpp
    # the launcher's settings.json, read by the game (camera turn direction,
    # and the four screen-gap keys hal/screen_gap.cpp reads)
    hal/host_settings.cpp hal/screen_gap.cpp
    # run perf1: the player performance log, playlog/perf-<id>.jsonl beside the
    # flight recorder. A second reader of what the F3 overlay already measures,
    # so it adds no measurement path and no picture; the frame pump hands it
    # one struct a frame and it writes one line every five seconds. Every
    # hardware string it names is reached through LoadLibraryA/GetProcAddress
    # or the CPUID instruction, so the import table does not move -- the same
    # rule the two graphics-card files below keep.
    hal/perf_log.cpp
    # the controller backend: XInput slots 0..3, then a DirectInput pad
    # (Switch Pro, DualShock, DualSense, generic HID) mapped onto the XInput
    # mask. Both DLLs loaded dynamically; no xinput/dinput8/dxguid lib. On
    # both targets that compile tests/walk_window.cpp, which is its caller.
    hal/pad_backend.cpp
    # run hd2 lane GPU1: the optional Direct3D 11 present path. Off by default
    # and inert when off: with PresentBackend absent or 0 it loads nothing,
    # creates nothing and prints nothing. d3d11 is LoadLibrary'd and its one
    # entry point GetProcAddress'd, the same rule hal/pad_backend.cpp keeps
    # above, so no d3d11, dxgi or dxguid lib is linked and the exe's import
    # table does not move. Its shaders are compiled offline into
    # hal/gpu_present_shaders.h, so d3dcompiler never loads either. On both
    # targets that compile tests/walk_window.cpp, which is its caller.
    hal/gpu_present.cpp
    # run hd2 lane GPU2: the ONE Direct3D 11 device this process makes. It
    # exists because a second optional setting is about to want a device and
    # two devices would be two copies of every texture on the card and two
    # claims on a 32-bit process's address space, which the stage-0 probe
    # measured as the tightest resource here. Nothing asks it for a device
    # unless a setting that needs one is on, so with every key absent it loads
    # nothing and allocates nothing. Same LoadLibrary rule as the file above:
    # no d3d11, dxgi or dxguid lib is linked and the import table does not move.
    hal/gpu_device.cpp
    # run hd2 lane GPU2: the optional renderer that draws the opaque 3D pass
    # on that device. Off by default and inert when off: with Renderer absent
    # or 0 it registers no backend, asks for no device and allocates nothing.
    # Its shaders are compiled offline into hal/gpu_raster_shaders.h, same as
    # the present path's, so d3dcompiler never loads here either.
    hal/gpu_raster.cpp
    # run lvled lane B: the editor control channel on 127.0.0.1:7355, the link
    # the Studio's editor talks to. Compiled in unconditionally but INERT unless
    # SM64DS_EDITOR_CHANNEL=1 -- no thread, no socket, no listener without it.
    # It is on BOTH targets that compile tests/walk_window.cpp (walk_window and
    # walk_window_hires), because the frame loop's drain call lives in that
    # shared file and a target without this source fails the link.
    hal/editor_channel.cpp
    # run lvled lane g3: live skybox switching for the editor's `skyset` verb.
    # Same story as the channel and the same flag: compiled in unconditionally,
    # INERT until editor_channel_init calls port_editor_sky_arm(), which it
    # does only under SM64DS_EDITOR_CHANNEL=1. Unarmed it runs no line,
    # allocates nothing and writes no game state, which is what lets the
    # battery -- which runs unarmed -- stand as the proof that it changed
    # nothing. On both walk_window targets for the channel's reason.
    hal/editor_sky.cpp
    # the Mods panel's file-layer half: installs hal/fs.cpp's mod hooks
    # (LovesMeCharacter). Game-shaped targets only; every smoke keeps the
    # null hooks and stock file serving.
    hal/fs_mods.cpp
    # SM64DS_STAGE_GEOM: a level's stage model and collision served out of an
    # external folder. CHAINS onto the hook above rather than replacing it --
    # its installer sits in .CRT$XCV so it runs after every ordinary one -- so
    # it goes beside hal/fs_mods.cpp on the same targets and nowhere else.
    hal/stage_geom.cpp
    # the scene's hand-drawn gap band and the band's per-scene continuity
    # table, both asked for at the same latch hal/screen_gap.cpp does
    hal/gap_art.cpp hal/gap_continuity.cpp
    # in-memory save state (lane lk6): F8/F9 snapshot and restore of the hosted
    # DS arena plus the out-of-arena game globals.
    hal/lk6_savestate.cpp hal/lk7_persist.cpp hal/dsstate_seg.cpp hal/rollback_probe.cpp hal/rollback.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/meshcolliderbase_vtable.cpp hal/meshcollider_dtor_seat.cpp hal/lk1_eh_vmax_seat.cpp hal/lk2_platform_dtor_seat.cpp hal/model_dtor_seat.cpp hal/dtor_seats_base.cpp hal/dtor_faces_cpp.cpp hal/actorport_dtor_bridge.cpp hal/actorport_dtor_faces.cpp ${SLICE_DTORFACES_SOURCES} hal/lk4_eh_dtor_seat.cpp hal/lk4_solidheap_seat.cpp hal/gx_upload_bridge.cpp hal/cstd_div.c
    hal/clsn_vtable.cpp hal/actor_vtables.cpp hal/anim_bridge.cpp
    ${SLICE_W8SHADOWS_SOURCES}
    # hal/megachar_stub.cpp is NOT here any more (lane w8-shadows). Its
    # `return 0` stand-in for Platform::UpdateKillByMegaChar is now compiled
    # only into the three narrow gate-9 harnesses above, which cannot build the
    # real closure. In this target the ROM's C name is the face at the bottom
    # of hal/wf_enemy_bridges.cpp and the body is the matched TU that has been
    # sitting in slice_gate16.txt line 178 all along, dropped by /OPT:REF for
    # want of a reference edge. Removing the stub from here is what makes the
    # matched body reachable; leaving it would be a duplicate definition.
    "${PORT_FACES_SYNC_GEN}" hal/cxxname_bridge.cpp hal/player_bridges.cpp hal/luigi_infection.cpp hal/cxx_aliases.cpp hal/auto_bss.cpp hal/reverse_bridges.cpp hal/method_faces.cpp hal/door_ring_faces.cpp hal/fader_wipes.cpp "${CMAKE_CURRENT_SOURCE_DIR}/../src/engine/fader/_ZN9FaderWipe14LoadAndSetFileEt.cpp" hal/level_boot.cpp hal/stage_mods.cpp hal/scene_boot.cpp hal/title_vtable_seat14d.cpp ${SLICE_TITLE_SOURCES} hal/title_doodle_probe.cpp hal/scene_actor_faces.cpp ${SLICE_SCENE1_SOURCES} ${SLICE_CARDFS_SOURCES} ${SLICE_OV007_SOURCES} ${SC1_INTERIM_SOURCES} ${SLICE_MG1_SOURCES} ${SCENE_MG_SOURCES} ${SLICE_LUI_SOURCES} ${SLICE_PCH_SOURCES} ${SLICE_SMB_SOURCES} ${SCENE_SMB_SOURCES} ${SLICE_CCN_SOURCES} ${SLICE_PPP_SOURCES} ${SLICE_FLW_SOURCES} ${SCENE_MG_FLOWER_SOURCES} ${SLICE_MEM_SOURCES} ${SLICE_S381_SOURCES} ${SLICE_MMT_SOURCES} ${SLICE_LKT_SOURCES} ${SLICE_SOS_SOURCES} ${SLICE_S75_SOURCES} ${SCENE_MG_CURLING2_SOURCES} ${SLICE_PSY_SOURCES} ${SLICE_LKY_SOURCES} ${SLICE_SNW_SOURCES} ${SLICE_TTE_SOURCES} ${SLICE_BOO_SOURCES} ${SLICE_WIG_SOURCES} ${SLICE_S371_SOURCES} ${SLICE_BOX_SOURCES} ${SLICE_S364_SOURCES} ${SCENE_MG_SLOT1_SOURCES} ${SLICE_CUP_SOURCES} ${SLICE_MUG_SOURCES} ${SLICE_BNP_SOURCES} ${SLICE_BNT_SOURCES} ${SLICE_PKR_SOURCES} ${SLICE_PGO_SOURCES} ${SLICE_RLT_SOURCES} ${SLICE_TTI_SOURCES} ${SLICE_MGM_SOURCES} ${SLICE_VS_SOURCES} ${FDR_FADER_SOURCES} ${NFS_NAMES_SOURCES}
    # run link60 lane L2: hal/w8a_stage_storage.cpp is pure zero arm9 BSS and it
    # owns data_0209d4a8, which dScDSMT_c's InitResources and CleanupResources
    # both touch. walk_window already had it; smoke_player and walk_window_hires
    # did not, so it joins all three rather than the symbol being defined a
    # second time next to the one that already exists.
    hal/w8a_stage_storage.cpp hal/cannon_probe.cpp hal/message_boot.cpp hal/actor_registry.cpp hal/actor_classes.cpp hal/actor_slot30_seat.cpp hal/actor_classes_bob_world.cpp hal/actor_faces_bob.cpp hal/actor_class_faces.cpp hal/mmc_vtable.cpp hal/ov009_boot.cpp hal/actor_overlays.cpp hal/sub_actors.cpp hal/sub_screen.cpp ${SLICE_2D1_SOURCES} hal/stage_bridges.cpp hal/level_change.cpp hal/title_entry.cpp hal/star_flow.cpp hal/oam_lists.cpp hal/blend_vtable.cpp hal/particle_vtable.cpp hal/particle_bridges.cpp unmatched/Particle_RideThroughs.cpp
    # Run link100 wave 17, lane PAINT5. The PAINTING's twelfth state body,
    # ov080 0x021261f4, which has no src TU and no near-miss draft and was a
    # named trap in hal/actor_overlays.cpp's g_painting_states until now. It
    # rides EVERY target that compiles hal/actor_overlays.cpp and is optional
    # on none of them: that file's pt_f_021261f4 face calls
    # func_ov080_021261f4 by name, so a target that takes the seat and not
    # this file fails the link on that symbol.
    unmatched/Painting_StateRender_021261f4.cpp
    ${CAMERA_HOST_SOURCES} ${LEVELBOOT_HOST_SOURCES} ${SOUND_HOST_SOURCES}
    ${MODELFAMILY_HOST_SOURCES}
    ${SLICE_W23_MODELDTOR_SOURCES}
    ${SLICE_PTR_SOURCES}
    # Stage 4, lane SD0: slot 0's closure. On all THREE targets rather than
    # walk_window alone, and not by preference: all three compile
    # hal/stage_bridges.cpp, which is where the Stage vtable and its slot-0
    # occupant live, so a face or a body that only one of them carried would
    # fail the other two at link. hal/stage_slot0.cpp holds the three
    # PORT_HOST_ABI bodies, the four C-name faces, two 4-byte arm9 BSS words
    # and the data_02075720 alias; the slice holds the ROM's own TUs.
    hal/stage_slot0.cpp ${SLICE_S4_SLOT0_SOURCES}
    # GATE 220, lane FRAME: the ROM's own Stage::Behavior in _ZTV5Stage
    # slot 6, its faces, and the eighteen arm9 .bss words its closure
    # reads.  On the TWO walk_window targets and NOT on smoke_player,
    # which is the one place this differs from the slot-0 row above.
    # Stage::Behavior calls Stage::UpdateMessage, whose body on this
    # port is port_message_pump (hal/message_pump.cpp), and that file is
    # on these two targets only -- it pulls the message compositor and
    # the generated text with it.  smoke_player therefore keeps the host
    # occupant in slot 6, selected by the SM64DS_STAGE_SLOT6_ROM compile
    # definition below rather than by a second copy of the thunk.
    hal/stage_frame.cpp hal/stage_globals.cpp ${SLICE220_SOURCES}
    # GATE SLOT9 (run link100, lane RENDER9): slot 9's own six TUs.
    # Same two targets and the same reason -- hal/stage_frame.cpp
    # carries slot 9's faces and its three seams too.
    ${SLICE_SLOT9_SOURCES}
    # and the one face that cannot share a translation unit with the rest:
    # the seven-argument OAM::Render has two decorated names in this link,
    # differing only in return type, and one file can declare one of them.
    hal/slot9_oam_face.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_HOSTGEN_SOURCES}
    ${SLICE7_SOURCES} ${SLICE8_SOURCES} ${SLICE9_CAM_SOURCES}
    ${SLICE10_CAM_SOURCES} ${SLICE_COMMS_SOURCES} ${SLICE13_SOURCES} ${SLICE14_SOURCES}
    ${SLICE15_SOURCES} ${SLICE16_SOURCES} ${SLICE17_SOURCES}
    ${SLICE18_SOURCES} ${SLICE19_SOURCES} ${SLICE20_SOURCES}
    ${SLICE_W1L1_SOURCES} ${SLICE_W1L2_SOURCES} ${SLICE_W1L3_SOURCES}
    ${SLICE_W1L4_SOURCES} ${SLICE_W1L5_SOURCES} ${SLICE_W5D_SOURCES} ${SLICE_W5E_SOURCES}
    ${SLICE_W6A_SOURCES}
    ${SLICE_W9HARVEST_SOURCES} ${SLICE_L15CP_SOURCES}
    ${SLICE_W5C_SOURCES} ${SQRTUNIT_GEN} ${OV70GEN}
    ${SLICE_W5B_SOURCES} ${SLICE_W5A_SOURCES} ${SLICE_W6D_SOURCES}
    ${SLICE_W3A_SOURCES}
    ${SLICE_W7C_SOURCES}
    hal/actor_classes_ov022.cpp ${SLICE_W8PACKS_SOURCES} ${SLICE_LAVA_SOURCES}
    hal/actor_classes_ov031_w10.cpp ${SLICE_W10A_SOURCES}
    ${SLICE_W10B_SOURCES}
    ${SLICE_W11_SOURCES}
    hal/actor_classes_ov073.cpp unmatched/Ov073_State.cpp
    # unmatched/Ov073_Render.cpp RETIRED (run link100, lane EXCEPT): the
    # ROM-order BlendModelAnim slot-5 reason died with SLOT5F's respelling.
    # src/_ZN11ChiefChilly6RenderEv.cpp is on port/slice_except2.txt and its
    # C name comes from hal/except_faces.cpp.
    ${SLICE_W12_SOURCES}
    hal/actor_classes_ov052.cpp ${SLICE_W12B_SOURCES}
    hal/actor_classes_ov064_w12.cpp
    # unmatched/Ov064_Clam.cpp RETIRED (run link100, lane EXCEPT): both its
    # bodies were the slot-5 reading. src/_ZN4Clam6RenderEv.cpp and
    # src/_ZN13TreasureChest6RenderEv.cpp are on port/slice_except2.txt.
    ${SLICE_W12C_SOURCES}
    hal/actor_classes_ov056.cpp ${SLICE_W15_SOURCES}
    hal/actor_classes_ov002_w15.cpp ${SLICE_W15B_SOURCES}
    hal/actor_classes_ov025.cpp ${SLICE_W15C_SOURCES}
    hal/actor_classes_ov022_w16.cpp ${SLICE_W16A_SOURCES}
    hal/actor_classes_ov002_w17.cpp ${SLICE_W17A_SOURCES}
    ${SLICE_W18A_SOURCES} ${SLICE_PMF2_SOURCES} ${SLICE_PMF3_SOURCES} hal/pmf3_aliases.cpp hal/ttc_level_data_seat.cpp
    ${SLICE_PMFC_SOURCES} hal/pmfc_aliases.cpp
    unmatched/Ov070_PmfDispatch.cpp
    ${SLICE21_SOURCES} ${SLICE22_SOURCES} ${SLICE23_SOURCES}
    ${SLICE25_SOURCES} ${SLICE27_SOURCES} ${SLICE28_SOURCES} ${SLICE26_SOURCES}
    ${SLICE33_SOURCES} ${SLICE_TAGFIX_SOURCES} ${GATE6_GEN}
    ${SLICE25_SOURCES} ${SLICE27_SOURCES} ${SLICE28_SOURCES} ${SLICE26_SOURCES} ${SLICE31_SOURCES} ${GATE6_GEN} ${SLICEINTRO_SOURCES} ${SLICE219_SOURCES}
    ${SLICE25_SOURCES} ${SLICE27_SOURCES} ${SLICE28_SOURCES} ${SLICE26_SOURCES} ${SLICE35_SOURCES} ${GATE6_GEN}
    ${SLICE32_SOURCES} ${GATE32_HOST_SOURCES} ${GATE32_GEN} ${GATE6_GEN}
    ${GATE4A_GEN} ${GATE4B_GEN} ${GATE8_GEN} ${GATE10_GEN}
    ${GATE13_GEN} ${GATE14_GEN} ${GATE15_GEN} ${GATE16_GEN} ${GATE35_GEN} ${GATE29_GEN} ${T2_DIV_GEN} ${TI2_MOD_GEN} ${SQ_DIST_GEN} ${TITEX_GX_GEN} ${TIDEP_RESET_GEN} ${R3B_SWAP_GEN} ${R3F_GREG_GEN} ${SEAT1_GREG_GEN}
    ${GATE9_GEN} ${HOSTABI_RETIRE_GEN}
    ${SLICE40_SOURCES} ${SLICE41_SOURCES} ${SLICE42_SOURCES}
    hal/actor_classes_painting.cpp ${SLICE50_SOURCES} hal/actor_classes_wf.cpp
    unmatched/Cap_StateDispatch.cpp unmatched/ExclamationSwitch_StateDispatch.cpp ${SLICE51_SOURCES} ${SLICE59_SOURCES} ${SLICE78_SOURCES} ${SLICE79_SOURCES} ${SLICE82_SOURCES} ${SLICE83_SOURCES} ${SLICE64_SOURCES} ${GATE64_GEN} ${SLICE89_SOURCES} ${SLICE102_SOURCES} ${SLICE103_SOURCES} ${SLICE128_SOURCES} ${SLICE121_SOURCES} ${SLICE122_SOURCES} ${SLICE123_SOURCES} ${SLICE209_SOURCES} hal/actor_classes_runtime_spawns.cpp ${SLICE210_SOURCES} unmatched/YoshiEgg_StateDispatch.cpp
    hal/actor_classes_ccm.cpp ${SLICE142_SOURCES} ${SLICE190_SOURCES} ${SLICE191_SOURCES} ${SLICE_MPG_SOURCES} ${SLICE_MPG2_SOURCES} unmatched/SoundObject_Behavior.cpp unmatched/MotherPenguin_AfterClsnSeat.cpp unmatched/MotherPenguin_ChaseGate.cpp ${SLICE_SMALLS_SOURCES} ${SLICE_SEAT1_SOURCES} unmatched/MotherPenguin_Behavior.cpp hal/actor_classes_ov081.cpp ${SLICE192_SOURCES} unmatched/MrBlizzard_Behavior.cpp ${SLICE_W3B_SOURCES} ${W3BGEN} hal/actor_classes_ov072.cpp ${SLICE193_SOURCES} unmatched/Snowman_InitResources.cpp ${SLICE_SHADOWS_SOURCES} ${SLICE_SHADOWS3_SOURCES} hal/actor_classes_ov094.cpp ${SLICE194_SOURCES} unmatched/HootTheOwl_StateDispatch.cpp hal/actor_classes_ov012.cpp ${SLICE199_SOURCES} hal/actor_classes_ov002g200.cpp ${SLICE200_SOURCES} unmatched/PushBlock_StateDispatch.cpp hal/actor_classes_ov013.cpp ${SLICE202_SOURCES} hal/actor_classes_ov077.cpp ${SLICE_OV077_SOURCES} unmatched/Lakitu_HostSites.cpp unmatched/Spiny_HostSites.cpp unmatched/HeaveHo_HostSites.cpp unmatched/Lakitu_ShadowFaces.cpp ${SLICE_OV030CAST_SOURCES} hal/actor_classes_ov092.cpp ${SLICE_OV092_SOURCES} unmatched/ToxBox_HostSites.cpp unmatched/ToxBox_ShadowFaces.cpp hal/actor_classes_ov096.cpp ${SLICE_OV096_SOURCES} unmatched/Pokey_HostSites.cpp unmatched/Tornado_HostSites.cpp unmatched/Ov072_MethodFaces.cpp ${SLICE_VSPOPUP_SOURCES} ${SLICE_CAP_SOURCES} ${SLICEBULLET_SOURCES} unmatched/Bullet_StateDispatch.cpp hal/actor_classes_bullet.cpp
    # run rel0215 wave 1 (lane cast-ov026): ov026's whole cast, level 18.
    hal/actor_classes_ov026.cpp ${SLICE_OV026_SOURCES} unmatched/Whirlpool_Behavior.cpp unmatched/WaterSuction_Behavior.cpp
    hal/actor_classes_ov036.cpp ${SLICE_OV036CAST_SOURCES}
    # run rel0215 wave 2 (lane cast-ov090): ov090's whole four-class water cast.
    ${SLICE_OV090_SOURCES}
    # run rel0215 wave 3 (lane w3-f2): ov091's ARROW_PATH_LIFT (157) +
    # SQUARE_METAL_NET_LIFT (144) -- one class, two ids -- and FWOOSH (231).
    ${SLICE_W3F2_SOURCES}
    # run rel0215 wave 2 (lane cast-ov066): EYEROK (176), ov066, level 17.
    ${SLICE_OV066_SOURCES}
    ${SLICE_W3C_SOURCES}
    hal/actor_classes_ov027.cpp ${SLICE_OV027CAST_SOURCES} unmatched/DaPgDfdr_StateDispatch.cpp
    # unmatched/Player_BlowAway.cpp RETIRED (run link100, lane FACEF): its tag
    # read "cdecl C name the caller wants versus the matched TU's thiscall
    # Player::BlowAway method, whose src ALSO cannot compile in-tree
    # (decomp-side Player.h gap)". The first half is the ordinary face repair;
    # the second half was MEASURED FALSE -- src/_ZN6Player8BlowAwayEs.cpp
    # compiles clean standalone under this build's own flags today, because
    # include/Player.h now carries BlowAway (:534), mIsMetal (:236) and
    # mIsBalloon (:240) and include/Actor.h mAngleY (:92) and mPrevAngleY
    # (:95), which are the four fields the ROM listing in the retired file
    # names. src/_ZN6Player8BlowAwayEs.cpp is on port/slice_facef.txt and its
    # C name comes from hal/except_faces.cpp.
    ${SLICE_OV074_SOURCES}
    hal/actor_classes_bbh.cpp ${SLICE149_SOURCES}
    hal/actor_classes_hmc.cpp ${SLICE172_SOURCES} unmatched/Crate_StateDispatch.cpp
    hal/actor_classes_updownlift.cpp ${SLICE173_SOURCES} unmatched/UpDownLiftBbh_Behavior.cpp
    hal/actor_classes_montymole.cpp ${SLICE174_SOURCES} unmatched/MontyMole_StateDispatch.cpp unmatched/MontyMole_1Up.cpp
    hal/actor_classes_flame.cpp ${SLICE175_SOURCES}
    hal/actor_classes_flamethrower.cpp ${SLICE_W6F_SOURCES}
    ${SLICE_W8FACES_SOURCES}
    hal/actor_classes_scuttlebug.cpp ${SLICE176_SOURCES} unmatched/Scuttlebug_StateDispatch.cpp
    hal/actor_classes_ov071.cpp ${SLICE_W7B_SOURCES} ${GATE_W7B_GEN} unmatched/MrI_StateDispatch.cpp
    # unmatched/MrI_Render.cpp RETIRED (run link100, lane EXCEPT): its own
    # header said "If _ZTV9ModelAnim ever gains a ROM-order view, this
    # retires", and SLOT5F gave it one. src/_ZN3MrI6RenderEv.cpp is on
    # port/slice_except2.txt.
    hal/actor_classes_ov064.cpp ${SLICE177_SOURCES} unmatched/Bully_AfterClsn.cpp
    hal/actor_classes_ov064_gate178.cpp ${SLICE178_SOURCES} unmatched/Ov064Gate178_States.cpp
    hal/actor_classes_ov064_w9.cpp ${SLICEW9A_SOURCES} ${SLICEW9B_SOURCES} ${SLICEW9C_SOURCES} ${SLICEW9D_SOURCES}
    hal/actor_classes_jrb.cpp ${SLICE188_SOURCES}
    # unmatched/Jrb_Renders.cpp RETIRED (run link100, lane FACEF): all four of
    # its bodies were the ROM-order model slot-5 draw, and both halves of its
    # stated reason are dead -- the numbering with lane SLOT5F's respelling,
    # and the return-type half because an indirect call through the object's
    # own vptr decorates nothing. src/_ZN6ShipUp6RenderEv.cpp,
    # src/_ZN10SlidingBox6RenderEv.cpp, src/_ZN10RockPillar6RenderEv.cpp
    # and src/actors/daObjFloatBoard_c.cpp are on port/slice_facef.txt; the two
    # method recoveries take a cdecl face in hal/except_faces.cpp and the two
    # C names need none.
    unmatched/Unagi_StateDispatch.cpp unmatched/Jrb_Aliases.cpp
    ${SLICE_SMALL7_SOURCES}
    hal/actor_classes_bowserpuzzle.cpp ${SLICE179_SOURCES} unmatched/BowserPuzzle_StateDispatch.cpp
    hal/actor_classes_koopa_chuckya.cpp hal/koopa_chuckya_faces.cpp ${SLICE182_SOURCES} unmatched/KoopaChuckya_StateDispatch.cpp ${SLICEKLEPTO_SOURCES} unmatched/Klepto_StateDispatch.cpp unmatched/Klepto_PathPtrFaces.cpp
    ${SLICE180_SOURCES} ${SLICE203_SOURCES} ${SLICE204_SOURCES}
    hal/actor_classes_ov085.cpp ${SLICE205_SOURCES}
    unmatched/Ov085_Behaviors.cpp
    # unmatched/Ov085_Toad_StateSeat.cpp RETIRED (run link100, lane PMFB1):
    # it held only Toad's two state dispatchers and their static helper, and
    # src/_ZN4Toad8SetStateEi.cpp and src/_ZN4Toad8RunStateEv.cpp carry both on
    # port/slice_pmfc.txt (block R9d). The seat that fills their table is
    # port_toad_states_seat in hal/actor_overlays.cpp and is untouched.
    # run rel0215 wave 3 (lane w3-f): ov085's PRINCESS_PEACH, the sixth
    # and last class. ONE host copy rides beside the slice now, the two PMF
    # dispatchers; unmatched/Ov085_PrincessPeach_Behavior.cpp RETIRED (run
    # link100, lane FOLD2) because the slot-6 body's whole reason was the
    # ModelAnim slot-3 numbering, and _ZTV9ModelAnim[3] is UpdateVerts again.
    ${SLICEW3F_SOURCES}
    unmatched/Ov085_PrincessPeach_Declshapes.cpp
    hal/actor_classes_montymolerock.cpp ${SLICE208_SOURCES}
    hal/actor_classes_ov043.cpp ${SLICE206_SOURCES} ${SLICE207_SOURCES} ${SLICEBDW_SOURCES}
    # gate 215 (run link100, lane SAVE): the save system's own medium path,
    # plus the hosted backup medium the ARM7 would otherwise answer for.
    ntr/backup.cpp ${SLICE215_SOURCES} hal/os_lockid.cpp hal/globals_link100.cpp
    hal/actor_classes_enemy_spawner.cpp ${SLICE211_SOURCES} hal/actor_classes_question_switch.cpp ${SLICE212_SOURCES} ${SLICE216_SOURCES}
    hal/boot2_ipc.cpp ${SLICE2IPC_SOURCES} ${GATE2IPC_GEN}
    hal/actor_classes_enemy_spawner.cpp ${SLICE211_SOURCES} hal/actor_classes_question_switch.cpp ${SLICE212_SOURCES} ${SLICE213_SOURCES}
    # ---- link100 SCENE ---- the two arm9-resident scene classes, gate 218
    hal/scene_link100_base_faces.cpp hal/scene_link100_boot.cpp
    hal/scene_link100_mb.cpp ${SLICE218_SOURCES}
    hal/actor_classes_l7.cpp ${SLICE_L7_SOURCES} ${GATE_L7_GEN} unmatched/PiranhaPlant_States.cpp
    unmatched/WaterBomb_StateDispatch.cpp
    unmatched/KnockDownPlank_Behavior.cpp
    # unmatched/FallBlockWf_InitVeneer.cpp RETIRED (run link100 wave 15, lane
    # SEAT15A): it held ONE body, func_ov098_0213a794, under a PORT_HOST_ABI tag
    # saying MSVC C2733 rejects the matched TU's second extern-C declaration of
    # itself. Re-measured on this tree with the port's own command line,
    # src/func_ov098_0213a794.cpp compiles clean and emits the same flat cdecl
    # name, so the tag was stale and the file had no reason left. The TU is on
    # port/slice_l15enab.txt, which carries the measurement.
    # run rel0215 wave 1 (lane cast-sweep1): the six small-cast overlays
    ${SWEEP1_SOURCES}
    # run rel0215 wave 2 (lane cast-sweep2): the four-overlay cast sweep
    ${SWEEP2_SOURCES}
    # run rel0215 wave 3 (lane w3-e): three partially-seated level
    # overlays' remaining tails (ov022, ov019, ov025)
    ${W3E_SOURCES}
    # ov029: level 21's water_city actors, ids 94..101
    ${OV029_SOURCES}
    # ---- link100 OV ---- ids 348 (ov002, daChRoom_c) and 314 (ov039, Cloud)
    hal/actor_classes_ov_link100.cpp ${SLICE217_SOURCES}
    # _ZTV5Stage SLOT 12 (run link60, lane L4). src/_ZN5Stage16OnPendingDestroyEv.cpp
    # is named on smoke_player and walk_window_hires above, because those two
    # targets compile hal/stage_bridges.cpp -- which seats the slot -- and do
    # NOT carry SLICE_W8A_SOURCES, which is how walk_window gets the same TU.
    # Naming it here as well would put the object in this link twice.
    #
    # It has to be seated on all three: the seat in hal/stage_bridges.cpp runs
    # Scene::BeforeBehavior on the Stage every frame, and that function reaches
    # ActorBase::MarkForDestruction, which calls slot 12 through the vptr.
    #
    # THE FADER TU IS NAMED THE SAME WAY (run link60, lane SL0).
    # src/engine/fader/_ZN9FaderWipe14LoadAndSetFileEt.cpp is named beside
    # hal/fader_wipes.cpp on all THREE targets that compile that file --
    # smoke_player, walk_window and walk_window_hires -- rather than put on a
    # slice, because it is not optional for any of them: hal/fader_wipes.cpp
    # now defines the C-name face _ZN9FaderWipe14LoadAndSetFileEt, and that
    # face calls the method this TU is the only definition of. Face and body
    # link together or the target does not link at all. Measured, not
    # predicted: naming the face without the body failed all three links with
    # LNK2019 on ?LoadAndSetFile@FaderWipe@@QAEXG@Z.
    # run linkw wave 8 (lane w8-a): the Stage class closure, first piece.
    hal/w8a_stage_storage.cpp hal/w8a_stage_faces.cpp ${SLICE_W8A_SOURCES}
    "${PORT_GITTIP_C}"
    # run link100 wave 15, lane SEAT15E: LINK15 BATCH 4 seats (slice_l15ov7)
    ${SLICE_L15OV7_SOURCES}
    "${ROMDATA_C}" "${OV009SYMS_C}" ${ACTOR_OV_SYMS} "${OVCROSS_C}")
target_include_directories(walk_window PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
# The runtime-selectable 16:9 layer. Off (the default) it renders the 512x384
# 4:3 window ZOOM 2 the port has always shipped -- the software raster is
# fill-bound and 2x is ~12ms -> 60fps; on it renders the full 1024x576 16:9. One
# exe, the Aspect settings key (a ratio, 0 = native) picks it at boot. Was ntr_2x
# (NTR_HIRES2, the fixed 512x384 tier); the wide-max buffer with a 4:3 default
# active size is byte-for-byte that build when the key is off.
target_link_libraries(walk_window PRIVATE ntr_wide_rt lua_resource_pack)
target_sources(walk_window PRIVATE hal/coop_media_decode.cpp)
target_compile_definitions(walk_window PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF}
    # GATE STARSEL (run link100, lane STARSELENTRY): this target carries
    # hal/input_probe.cpp, so hal/scene_boot.cpp's port_scene_tick can call
    # port_input_probe_apply.  smoke_player does not compile input_probe.cpp
    # (see its own source list), so the call there stays guarded off.
    SM64DS_SCENE_PAD_PROBE=1
    # GATE 220 (run link100, lane FRAME): this target carries
    # port/slice_gate220.txt and hal/stage_frame.cpp, so _ZTV5Stage
    # slot 6 dispatches the ROM's own Stage::Behavior instead of the
    # host occupant.  smoke_player does not define this and keeps the
    # occupant; see the gate row above it for why.
    SM64DS_STAGE_SLOT6_ROM=1
    # GATE SLOT9 (run link100, lane RENDER9): the same for slot 9 and
    # Stage::Render.  SM64DS_STAGE_SLOT9_HOST=1 in the ENVIRONMENT makes the
    # seated thunk decline at run time, which is how the BMP A/B is captured
    # on ONE binary; the compile definition is what puts the ROM body in the
    # slot at all.
    SM64DS_STAGE_SLOT9_ROM=1
    # GATE SHADOWS RUNG 3 (run link100, lane SHADOWS2): this target carries
    # port/slice_shadows.txt AND port/slice_gate16.txt, so the ROM's own
    # SharedFilePtr::ReallocateModelFile is in the link with func_02017060
    # under it.  The define retires the empty stand-in in
    # hal/gx_upload_bridge.cpp, which would otherwise defeat that file's
    # /alternatename by defining its LHS.  The ten narrow harnesses link the
    # caller without the callee and keep the stand-in.
    SM64DS_SFP_REALLOC_ROM=1
    # this target links hal/cxx_aliases.cpp, which already carries
    # the Heap::_Deallocate face hal/blend_vtable.cpp repeats
    PORT_CXX_ALIASES_LINKED)
# ROM-CLEAN: the shipped window loads its ROM tables from romdata.bin at boot.
# The dispatch (generated) + loader come in as extra sources, PORT_ROM_CLEAN
# turns on the port_romdata_load() call in walk_window.cpp, and a custom target
# makes the blob + self-check a build prerequisite.
if(PORT_ROM_CLEAN)
    # hal/asset_root_refuse.cpp: the shipping build has NO PORT_REPO_ROOT
    # fallback for assets. It is in this block and only this block, so the
    # developer build keeps the fallback every lane in this tree relies on.
    # Run link60 lane KIT1; port/kit_pipeline.txt is the write-up.
    target_sources(walk_window PRIVATE "${ROMDATA_DISPATCH_C}"
                   hal/romdata_loader.cpp hal/asset_root_refuse.cpp)
    target_compile_definitions(walk_window PRIVATE PORT_ROM_CLEAN)
    add_custom_target(romblob_ready_ww DEPENDS "${ROMDATA_BIN}"
        "${CMAKE_BINARY_DIR}/assets/romblob_verified.stamp"
        "${ROMDATA_RECIPE}")
    add_dependencies(walk_window romblob_ready_ww)
    if(WIN32)
        # Only extraction code and offsets/hashes enter the executable. Never
        # embed romdata.bin, cartridge files, extracted assets, or player saves.
        enable_language(RC)
        file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/coop_setup.rc" CONTENT
            "310 RCDATA \"${PORT_REPO_ROOT_ABS}/tools/portable_kit/extract_assets.ps1\"\n311 RCDATA \"${ROMDATA_RECIPE}\"\n312 RCDATA \"${ROMDATA_MANIFEST}\"\n")
        target_sources(walk_window PRIVATE "${CMAKE_BINARY_DIR}/coop_setup.rc")
        if(MSVC)
            target_link_options(walk_window PRIVATE /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup)
        endif()
    endif()
endif()
if(MSVC)
    target_compile_options(walk_window PRIVATE /wd4311 /wd4312 /wd4068 /wd4576)
    # No ASLR for the shipped window: a disk save state (hal/lk7_persist
    # .cpp) stores absolute pointers into the exe image -- every actor's
    # vtable pointer -- and they only relocate if the image loads at the
    # SAME base on the next launch. ASLR rebases once per boot, which
    # would refuse every state written before a reboot. The header still
    # checks the base, so if anything rebases the exe anyway the state is
    # refused with a message rather than loaded onto dangling pointers.
    target_link_options(walk_window PRIVATE /DYNAMICBASE:NO)
endif()

# The save state captures the whole .dsstate section (hal/dsstate_seg.h). Fail
# the build if a hosted DS global landed OUTSIDE it: that symbol would not roll
# back on a restore, which is exactly the class of bug that shipped in 0.2.0
# (the ANIM_PTRS table crashing Player::SetAnim on a null BCA_File*). The map
# the guard reads is the one /MAP already writes next to the exe.
add_custom_command(TARGET walk_window POST_BUILD
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/dsstate_guard.py"
            "$<TARGET_FILE_DIR:walk_window>/walk_window.map"
    VERBATIM
    COMMENT "dsstate_guard: hosted DS globals all inside .dsstate")

# A FACE MUST NEVER FORWARD TO ANOTHER FACE. The port reaches the ROM's code
# through one-line forwarders, and each shape rests on a premise about the other
# side: the flat-name face assumes the member is a real body, the member face
# assumes the flat name is. Nothing checked either premise, so two faces written
# against each other -- in two files, by two people, months apart -- resolve
# cleanly, duplicate nothing, leave nothing unresolved, pass every static gate,
# and then call themselves forever. SYNC6 caught the LOUD version of this, where
# a translation unit came back and the generated forwarder became a second
# definition and the linker said LNK2005. The silent version has no such signal,
# and on 2026-09-14 the shipped artifact carried eight of them; the first one to
# run took the whole process down with a stack overflow on level 28's first
# frame. This guard reads the map and the image the link just wrote and fails on
# any cycle of trivial forwarders, which makes the class self-announcing at build
# time instead of as a crash in front of a player. Lane FACEFIX, run link100.
add_custom_command(TARGET walk_window POST_BUILD
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/facecycle_guard.py"
            "$<TARGET_FILE_DIR:walk_window>/walk_window.map"
            --allow "${CMAKE_CURRENT_SOURCE_DIR}/facecycle_allow.txt"
    VERBATIM
    COMMENT "facecycle_guard: no face forwards to another face")

# A HOSTED DS GLOBAL MUST BE AT LEAST AS BIG AS WHAT THE ROM WRITES THROUGH
# IT. This class has shipped five times (memory note
# sm64ds-port-undersized-globals): a DS global takes hal/auto_bss.cpp's
# generous `int name[8]` default, the ROM routine that owns it writes its full
# extent, and the write lands on whatever the linker put next. It never
# presents as a bug in the subsystem that owns the buffer -- data_0209d74c
# cleared 3808 bytes through hal_wipes[0]'s vtable pointer and faulted
# HUD::Behavior the first time Mario talked, and the fix for it carried a
# comment asking the next person to re-run the audit after adding a symbol.
# Nobody did, the file grew from 152 symbols to 205, and on 2026-09-15 the
# re-audit found two more live instances seventy lines above that comment.
# A comment asking a human to remember is not a control, so this is the
# control: the check runs on every link instead of when somebody remembers.
# It reads only checked-in sources and config/arm9, so it needs no map, and
# it self-validates against seven fixtures on every run -- three that must
# fire and four that must not -- and fails the build if any of them comes
# back with the wrong verdict, so deleting or weakening a rule breaks the
# build rather than silently disarming the check. Lane BSSFIX, run link100.
add_custom_command(TARGET walk_window POST_BUILD
    COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/arm9_globals_guard.py"
            --root "${CMAKE_CURRENT_SOURCE_DIR}/.."
            --allow "${CMAKE_CURRENT_SOURCE_DIR}/arm9_globals_allow.txt"
    VERBATIM
    COMMENT "arm9_globals_guard: no ROM write runs past a hosted arm9 global")

# hires clone for screenshot sessions (4x resolution, ~1/16 the fps)
add_executable(walk_window_hires tests/walk_window.cpp hal/resource_pack.cpp
    "${OV002DATA_C}" ${LEVEL_OV_DATA}
    # run link100 lane BOOT: same slice as walk_window, for the same reason --
    # this target compiles tests/walk_window.cpp, which carries the boot calls.
    ${SLICE214_SOURCES} ${SLICE_IPCSEND_SOURCES}
    # dialogue pipeline (2026-08-08): pump, engine-A compositor, headless probe.
    hal/message_pump.cpp hal/message_compositor.cpp hal/message_probe.cpp hal/message_gen_text.cpp hal/input_probe.cpp
    # the launcher's settings.json, read by the game (camera turn direction,
    # and the four screen-gap keys hal/screen_gap.cpp reads)
    hal/host_settings.cpp hal/screen_gap.cpp
    # run perf1: the player performance log, playlog/perf-<id>.jsonl beside the
    # flight recorder. A second reader of what the F3 overlay already measures,
    # so it adds no measurement path and no picture; the frame pump hands it
    # one struct a frame and it writes one line every five seconds. Every
    # hardware string it names is reached through LoadLibraryA/GetProcAddress
    # or the CPUID instruction, so the import table does not move -- the same
    # rule the two graphics-card files below keep.
    hal/perf_log.cpp
    # the controller backend: XInput slots 0..3, then a DirectInput pad
    # (Switch Pro, DualShock, DualSense, generic HID) mapped onto the XInput
    # mask. Both DLLs loaded dynamically; no xinput/dinput8/dxguid lib. On
    # both targets that compile tests/walk_window.cpp, which is its caller.
    hal/pad_backend.cpp
    # run hd2 lane GPU1: the optional Direct3D 11 present path. Off by default
    # and inert when off: with PresentBackend absent or 0 it loads nothing,
    # creates nothing and prints nothing. d3d11 is LoadLibrary'd and its one
    # entry point GetProcAddress'd, the same rule hal/pad_backend.cpp keeps
    # above, so no d3d11, dxgi or dxguid lib is linked and the exe's import
    # table does not move. Its shaders are compiled offline into
    # hal/gpu_present_shaders.h, so d3dcompiler never loads either. On both
    # targets that compile tests/walk_window.cpp, which is its caller.
    hal/gpu_present.cpp
    # run hd2 lane GPU2: the ONE Direct3D 11 device this process makes. It
    # exists because a second optional setting is about to want a device and
    # two devices would be two copies of every texture on the card and two
    # claims on a 32-bit process's address space, which the stage-0 probe
    # measured as the tightest resource here. Nothing asks it for a device
    # unless a setting that needs one is on, so with every key absent it loads
    # nothing and allocates nothing. Same LoadLibrary rule as the file above:
    # no d3d11, dxgi or dxguid lib is linked and the import table does not move.
    hal/gpu_device.cpp
    # run hd2 lane GPU2: the optional renderer that draws the opaque 3D pass
    # on that device. Off by default and inert when off: with Renderer absent
    # or 0 it registers no backend, asks for no device and allocates nothing.
    # Its shaders are compiled offline into hal/gpu_raster_shaders.h, same as
    # the present path's, so d3dcompiler never loads here either.
    hal/gpu_raster.cpp
    # run lvled lane B: the editor control channel on 127.0.0.1:7355, the link
    # the Studio's editor talks to. Compiled in unconditionally but INERT unless
    # SM64DS_EDITOR_CHANNEL=1 -- no thread, no socket, no listener without it.
    # It is on BOTH targets that compile tests/walk_window.cpp (walk_window and
    # walk_window_hires), because the frame loop's drain call lives in that
    # shared file and a target without this source fails the link.
    hal/editor_channel.cpp
    # run lvled lane g3: live skybox switching for the editor's `skyset` verb.
    # Same story as the channel and the same flag: compiled in unconditionally,
    # INERT until editor_channel_init calls port_editor_sky_arm(), which it
    # does only under SM64DS_EDITOR_CHANNEL=1. Unarmed it runs no line,
    # allocates nothing and writes no game state, which is what lets the
    # battery -- which runs unarmed -- stand as the proof that it changed
    # nothing. On both walk_window targets for the channel's reason.
    hal/editor_sky.cpp
    # the Mods panel's file-layer half: installs hal/fs.cpp's mod hooks
    # (LovesMeCharacter). Game-shaped targets only; every smoke keeps the
    # null hooks and stock file serving.
    hal/fs_mods.cpp
    # SM64DS_STAGE_GEOM: a level's stage model and collision served out of an
    # external folder. CHAINS onto the hook above rather than replacing it --
    # its installer sits in .CRT$XCV so it runs after every ordinary one -- so
    # it goes beside hal/fs_mods.cpp on the same targets and nowhere else.
    hal/stage_geom.cpp
    # the scene's hand-drawn gap band and the band's per-scene continuity
    # table, both asked for at the same latch hal/screen_gap.cpp does
    hal/gap_art.cpp hal/gap_continuity.cpp
    # in-memory save state (lane lk6): F8/F9 snapshot and restore of the hosted
    # DS arena plus the out-of-arena game globals.
    hal/lk6_savestate.cpp hal/lk7_persist.cpp hal/dsstate_seg.cpp hal/rollback_probe.cpp hal/rollback.cpp
    hal/heap_globals.cpp hal/os_arena.cpp hal/heap_vtable.cpp hal/fs.cpp
    hal/model_host.cpp hal/meshcolliderbase_vtable.cpp hal/meshcollider_dtor_seat.cpp hal/lk1_eh_vmax_seat.cpp hal/lk2_platform_dtor_seat.cpp hal/model_dtor_seat.cpp hal/dtor_seats_base.cpp hal/dtor_faces_cpp.cpp hal/actorport_dtor_bridge.cpp hal/actorport_dtor_faces.cpp ${SLICE_DTORFACES_SOURCES} hal/lk4_eh_dtor_seat.cpp hal/lk4_solidheap_seat.cpp hal/gx_upload_bridge.cpp hal/cstd_div.c
    hal/clsn_vtable.cpp hal/actor_vtables.cpp hal/anim_bridge.cpp
    ${SLICE_W8SHADOWS_SOURCES}
    # hal/megachar_stub.cpp is NOT here any more (lane w8-shadows). Its
    # `return 0` stand-in for Platform::UpdateKillByMegaChar is now compiled
    # only into the three narrow gate-9 harnesses above, which cannot build the
    # real closure. In this target the ROM's C name is the face at the bottom
    # of hal/wf_enemy_bridges.cpp and the body is the matched TU that has been
    # sitting in slice_gate16.txt line 178 all along, dropped by /OPT:REF for
    # want of a reference edge. Removing the stub from here is what makes the
    # matched body reachable; leaving it would be a duplicate definition.
    "${PORT_FACES_SYNC_GEN}" hal/cxxname_bridge.cpp hal/player_bridges.cpp hal/luigi_infection.cpp hal/cxx_aliases.cpp hal/auto_bss.cpp hal/reverse_bridges.cpp hal/method_faces.cpp hal/door_ring_faces.cpp hal/fader_wipes.cpp "${CMAKE_CURRENT_SOURCE_DIR}/../src/engine/fader/_ZN9FaderWipe14LoadAndSetFileEt.cpp" hal/level_boot.cpp hal/stage_mods.cpp hal/scene_boot.cpp hal/title_vtable_seat14d.cpp ${SLICE_TITLE_SOURCES} hal/title_doodle_probe.cpp hal/scene_actor_faces.cpp ${SLICE_SCENE1_SOURCES} ${SLICE_CARDFS_SOURCES} ${SLICE_OV007_SOURCES} ${SC1_INTERIM_SOURCES} ${SLICE_MG1_SOURCES} ${SCENE_MG_SOURCES} ${SLICE_LUI_SOURCES} ${SLICE_PCH_SOURCES} ${SLICE_SMB_SOURCES} ${SCENE_SMB_SOURCES} ${SLICE_CCN_SOURCES} ${SLICE_PPP_SOURCES} ${SLICE_FLW_SOURCES} ${SCENE_MG_FLOWER_SOURCES} ${SLICE_MEM_SOURCES} ${SLICE_S381_SOURCES} ${SLICE_MMT_SOURCES} ${SLICE_LKT_SOURCES} ${SLICE_SOS_SOURCES} ${SLICE_S75_SOURCES} ${SCENE_MG_CURLING2_SOURCES} ${SLICE_PSY_SOURCES} ${SLICE_LKY_SOURCES} ${SLICE_SNW_SOURCES} ${SLICE_TTE_SOURCES} ${SLICE_BOO_SOURCES} ${SLICE_WIG_SOURCES} ${SLICE_S371_SOURCES} ${SLICE_BOX_SOURCES} ${SLICE_S364_SOURCES} ${SCENE_MG_SLOT1_SOURCES} ${SLICE_CUP_SOURCES} ${SLICE_MUG_SOURCES} ${SLICE_BNP_SOURCES} ${SLICE_BNT_SOURCES} ${SLICE_PKR_SOURCES} ${SLICE_PGO_SOURCES} ${SLICE_RLT_SOURCES} ${SLICE_TTI_SOURCES} ${SLICE_MGM_SOURCES} ${SLICE_VS_SOURCES} ${FDR_FADER_SOURCES} ${NFS_NAMES_SOURCES}
    # run link60 lane L2: hal/w8a_stage_storage.cpp is pure zero arm9 BSS and it
    # owns data_0209d4a8, which dScDSMT_c's InitResources and CleanupResources
    # both touch. walk_window already had it; smoke_player and walk_window_hires
    # did not, so it joins all three rather than the symbol being defined a
    # second time next to the one that already exists.
    hal/w8a_stage_storage.cpp hal/cannon_probe.cpp hal/message_boot.cpp hal/actor_registry.cpp hal/actor_classes.cpp hal/actor_slot30_seat.cpp hal/actor_classes_bob_world.cpp hal/actor_faces_bob.cpp hal/actor_class_faces.cpp hal/mmc_vtable.cpp hal/ov009_boot.cpp hal/actor_overlays.cpp hal/sub_actors.cpp hal/sub_screen.cpp ${SLICE_2D1_SOURCES} hal/stage_bridges.cpp "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN5Stage16OnPendingDestroyEv.cpp" hal/level_change.cpp hal/title_entry.cpp hal/star_flow.cpp hal/oam_lists.cpp hal/blend_vtable.cpp hal/particle_vtable.cpp hal/particle_bridges.cpp unmatched/Particle_RideThroughs.cpp
    # Run link100 wave 17, lane PAINT5. The PAINTING's twelfth state body,
    # ov080 0x021261f4, which has no src TU and no near-miss draft and was a
    # named trap in hal/actor_overlays.cpp's g_painting_states until now. It
    # rides EVERY target that compiles hal/actor_overlays.cpp and is optional
    # on none of them: that file's pt_f_021261f4 face calls
    # func_ov080_021261f4 by name, so a target that takes the seat and not
    # this file fails the link on that symbol.
    unmatched/Painting_StateRender_021261f4.cpp
    ${CAMERA_HOST_SOURCES} ${LEVELBOOT_HOST_SOURCES} ${SOUND_HOST_SOURCES}
    ${MODELFAMILY_HOST_SOURCES}
    ${SLICE_W23_MODELDTOR_SOURCES}
    ${SLICE_PTR_SOURCES}
    # Stage 4, lane SD0: slot 0's closure. On all THREE targets rather than
    # walk_window alone, and not by preference: all three compile
    # hal/stage_bridges.cpp, which is where the Stage vtable and its slot-0
    # occupant live, so a face or a body that only one of them carried would
    # fail the other two at link. hal/stage_slot0.cpp holds the three
    # PORT_HOST_ABI bodies, the four C-name faces, two 4-byte arm9 BSS words
    # and the data_02075720 alias; the slice holds the ROM's own TUs.
    hal/stage_slot0.cpp ${SLICE_S4_SLOT0_SOURCES}
    # GATE 220, lane FRAME: the ROM's own Stage::Behavior in _ZTV5Stage
    # slot 6, its faces, and the eighteen arm9 .bss words its closure
    # reads.  On the TWO walk_window targets and NOT on smoke_player,
    # which is the one place this differs from the slot-0 row above.
    # Stage::Behavior calls Stage::UpdateMessage, whose body on this
    # port is port_message_pump (hal/message_pump.cpp), and that file is
    # on these two targets only -- it pulls the message compositor and
    # the generated text with it.  smoke_player therefore keeps the host
    # occupant in slot 6, selected by the SM64DS_STAGE_SLOT6_ROM compile
    # definition below rather than by a second copy of the thunk.
    # AND hal/w8a_stage_faces.cpp WITH IT, on this target only.
    # walk_window has carried that file since lane w8-a and this target
    # has not; it is alias-only (five /alternatename rows and one marker
    # byte) and three of those rows are the plumbing gate 220 needs --
    # ?CanPause@Stage@@SAHXZ, ?IsPauseDisabled@Stage@@SAHXZ and
    # ?CheckInput@Stage@@QAEXXZ, every one referenced only by
    # Stage::Behavior, which is exactly what this gate adds.  Without it
    # walk_window_hires fails with three LNK2019s that walk_window does
    # not, which is how the omission was found.
    hal/stage_frame.cpp hal/stage_globals.cpp hal/w8a_stage_faces.cpp
    ${SLICE220_SOURCES}
    # GATE SLOT9 (run link100, lane RENDER9): slot 9's own six TUs.
    # Same two targets and the same reason -- hal/stage_frame.cpp
    # carries slot 9's faces and its three seams too.
    ${SLICE_SLOT9_SOURCES}
    # and the one face that cannot share a translation unit with the rest:
    # the seven-argument OAM::Render has two decorated names in this link,
    # differing only in return type, and one file can declare one of them.
    hal/slot9_oam_face.cpp
    ${SLICE2_SOURCES} ${SLICE3A_SOURCES} ${SLICE3B_SOURCES} ${SLICE4B_HOSTGEN_SOURCES}
    ${SLICE7_SOURCES} ${SLICE8_SOURCES} ${SLICE9_CAM_SOURCES}
    ${SLICE10_CAM_SOURCES} ${SLICE_COMMS_SOURCES} ${SLICE13_SOURCES} ${SLICE14_SOURCES}
    ${SLICE15_SOURCES} ${SLICE16_SOURCES} ${SLICE17_SOURCES}
    ${SLICE18_SOURCES} ${SLICE19_SOURCES} ${SLICE20_SOURCES}
    ${SLICE_W1L1_SOURCES} ${SLICE_W1L2_SOURCES} ${SLICE_W1L3_SOURCES}
    ${SLICE_W1L4_SOURCES} ${SLICE_W1L5_SOURCES} ${SLICE_W5D_SOURCES} ${SLICE_W5E_SOURCES}
    ${SLICE_W6A_SOURCES}
    ${SLICE_W9HARVEST_SOURCES} ${SLICE_L15CP_SOURCES}
    ${SLICE_W5C_SOURCES} ${SQRTUNIT_GEN} ${OV70GEN}
    ${SLICE_W5B_SOURCES} ${SLICE_W5A_SOURCES} ${SLICE_W6D_SOURCES}
    ${SLICE_W3A_SOURCES}
    ${SLICE_W7C_SOURCES}
    hal/actor_classes_ov022.cpp ${SLICE_W8PACKS_SOURCES} ${SLICE_LAVA_SOURCES}
    hal/actor_classes_ov031_w10.cpp ${SLICE_W10A_SOURCES}
    ${SLICE_W10B_SOURCES}
    ${SLICE_W11_SOURCES}
    hal/actor_classes_ov073.cpp unmatched/Ov073_State.cpp
    # unmatched/Ov073_Render.cpp RETIRED (run link100, lane EXCEPT): the
    # ROM-order BlendModelAnim slot-5 reason died with SLOT5F's respelling.
    # src/_ZN11ChiefChilly6RenderEv.cpp is on port/slice_except2.txt and its
    # C name comes from hal/except_faces.cpp.
    ${SLICE_W12_SOURCES}
    hal/actor_classes_ov052.cpp ${SLICE_W12B_SOURCES}
    hal/actor_classes_ov064_w12.cpp
    # unmatched/Ov064_Clam.cpp RETIRED (run link100, lane EXCEPT): both its
    # bodies were the slot-5 reading. src/_ZN4Clam6RenderEv.cpp and
    # src/_ZN13TreasureChest6RenderEv.cpp are on port/slice_except2.txt.
    ${SLICE_W12C_SOURCES}
    hal/actor_classes_ov056.cpp ${SLICE_W15_SOURCES}
    hal/actor_classes_ov002_w15.cpp ${SLICE_W15B_SOURCES}
    hal/actor_classes_ov025.cpp ${SLICE_W15C_SOURCES}
    hal/actor_classes_ov022_w16.cpp ${SLICE_W16A_SOURCES}
    hal/actor_classes_ov002_w17.cpp ${SLICE_W17A_SOURCES}
    ${SLICE_W18A_SOURCES} ${SLICE_PMF2_SOURCES} ${SLICE_PMF3_SOURCES} hal/pmf3_aliases.cpp hal/ttc_level_data_seat.cpp
    ${SLICE_PMFC_SOURCES} hal/pmfc_aliases.cpp
    unmatched/Ov070_PmfDispatch.cpp
    ${SLICE21_SOURCES} ${SLICE22_SOURCES} ${SLICE23_SOURCES}
    ${SLICE25_SOURCES} ${SLICE27_SOURCES} ${SLICE28_SOURCES} ${SLICE26_SOURCES}
    ${SLICE33_SOURCES} ${SLICE_TAGFIX_SOURCES} ${GATE6_GEN}
    ${SLICE25_SOURCES} ${SLICE27_SOURCES} ${SLICE28_SOURCES} ${SLICE26_SOURCES} ${SLICE31_SOURCES} ${GATE6_GEN} ${SLICEINTRO_SOURCES} ${SLICE219_SOURCES}
    ${SLICE25_SOURCES} ${SLICE27_SOURCES} ${SLICE28_SOURCES} ${SLICE26_SOURCES} ${SLICE35_SOURCES} ${GATE6_GEN}
    ${SLICE32_SOURCES} ${GATE32_HOST_SOURCES} ${GATE32_GEN} ${GATE6_GEN}
    ${GATE4A_GEN} ${GATE4B_GEN} ${GATE8_GEN} ${GATE10_GEN}
    ${GATE13_GEN} ${GATE14_GEN} ${GATE15_GEN} ${GATE16_GEN} ${GATE35_GEN} ${GATE29_GEN} ${T2_DIV_GEN} ${TI2_MOD_GEN} ${SQ_DIST_GEN} ${TITEX_GX_GEN} ${TIDEP_RESET_GEN} ${R3B_SWAP_GEN} ${R3F_GREG_GEN} ${SEAT1_GREG_GEN}
    ${GATE9_GEN} ${HOSTABI_RETIRE_GEN}
    ${SLICE40_SOURCES} ${SLICE41_SOURCES} ${SLICE42_SOURCES}
    hal/actor_classes_painting.cpp ${SLICE50_SOURCES} hal/actor_classes_wf.cpp
    unmatched/Cap_StateDispatch.cpp unmatched/ExclamationSwitch_StateDispatch.cpp ${SLICE51_SOURCES} ${SLICE59_SOURCES} ${SLICE78_SOURCES} ${SLICE79_SOURCES} ${SLICE82_SOURCES} ${SLICE83_SOURCES} ${SLICE64_SOURCES} ${GATE64_GEN} ${SLICE89_SOURCES} ${SLICE102_SOURCES} ${SLICE103_SOURCES} ${SLICE128_SOURCES} ${SLICE121_SOURCES} ${SLICE122_SOURCES} ${SLICE123_SOURCES} ${SLICE209_SOURCES} hal/actor_classes_runtime_spawns.cpp ${SLICE210_SOURCES} unmatched/YoshiEgg_StateDispatch.cpp
    hal/actor_classes_ccm.cpp ${SLICE142_SOURCES} ${SLICE190_SOURCES} ${SLICE191_SOURCES} ${SLICE_MPG_SOURCES} ${SLICE_MPG2_SOURCES} unmatched/SoundObject_Behavior.cpp unmatched/MotherPenguin_AfterClsnSeat.cpp unmatched/MotherPenguin_ChaseGate.cpp ${SLICE_SMALLS_SOURCES} ${SLICE_SEAT1_SOURCES} unmatched/MotherPenguin_Behavior.cpp hal/actor_classes_ov081.cpp ${SLICE192_SOURCES} unmatched/MrBlizzard_Behavior.cpp ${SLICE_W3B_SOURCES} ${W3BGEN} hal/actor_classes_ov072.cpp ${SLICE193_SOURCES} unmatched/Snowman_InitResources.cpp ${SLICE_SHADOWS_SOURCES} ${SLICE_SHADOWS3_SOURCES} hal/actor_classes_ov094.cpp ${SLICE194_SOURCES} unmatched/HootTheOwl_StateDispatch.cpp hal/actor_classes_ov012.cpp ${SLICE199_SOURCES} hal/actor_classes_ov002g200.cpp ${SLICE200_SOURCES} unmatched/PushBlock_StateDispatch.cpp hal/actor_classes_ov013.cpp ${SLICE202_SOURCES} hal/actor_classes_ov077.cpp ${SLICE_OV077_SOURCES} unmatched/Lakitu_HostSites.cpp unmatched/Spiny_HostSites.cpp unmatched/HeaveHo_HostSites.cpp unmatched/Lakitu_ShadowFaces.cpp ${SLICE_OV030CAST_SOURCES} hal/actor_classes_ov092.cpp ${SLICE_OV092_SOURCES} unmatched/ToxBox_HostSites.cpp unmatched/ToxBox_ShadowFaces.cpp hal/actor_classes_ov096.cpp ${SLICE_OV096_SOURCES} unmatched/Pokey_HostSites.cpp unmatched/Tornado_HostSites.cpp unmatched/Ov072_MethodFaces.cpp ${SLICE_VSPOPUP_SOURCES} ${SLICE_CAP_SOURCES} ${SLICEBULLET_SOURCES} unmatched/Bullet_StateDispatch.cpp hal/actor_classes_bullet.cpp
    # run rel0215 wave 1 (lane cast-ov026): ov026's whole cast, level 18.
    hal/actor_classes_ov026.cpp ${SLICE_OV026_SOURCES} unmatched/Whirlpool_Behavior.cpp unmatched/WaterSuction_Behavior.cpp
    hal/actor_classes_ov036.cpp ${SLICE_OV036CAST_SOURCES}
    # run rel0215 wave 2 (lane cast-ov090): ov090's whole four-class water cast.
    ${SLICE_OV090_SOURCES}
    # run rel0215 wave 3 (lane w3-f2): ov091's ARROW_PATH_LIFT (157) +
    # SQUARE_METAL_NET_LIFT (144) -- one class, two ids -- and FWOOSH (231).
    ${SLICE_W3F2_SOURCES}
    # run rel0215 wave 2 (lane cast-ov066): EYEROK (176), ov066, level 17.
    ${SLICE_OV066_SOURCES}
    ${SLICE_W3C_SOURCES}
    hal/actor_classes_ov027.cpp ${SLICE_OV027CAST_SOURCES} unmatched/DaPgDfdr_StateDispatch.cpp
    # unmatched/Player_BlowAway.cpp RETIRED (run link100, lane FACEF): its tag
    # read "cdecl C name the caller wants versus the matched TU's thiscall
    # Player::BlowAway method, whose src ALSO cannot compile in-tree
    # (decomp-side Player.h gap)". The first half is the ordinary face repair;
    # the second half was MEASURED FALSE -- src/_ZN6Player8BlowAwayEs.cpp
    # compiles clean standalone under this build's own flags today, because
    # include/Player.h now carries BlowAway (:534), mIsMetal (:236) and
    # mIsBalloon (:240) and include/Actor.h mAngleY (:92) and mPrevAngleY
    # (:95), which are the four fields the ROM listing in the retired file
    # names. src/_ZN6Player8BlowAwayEs.cpp is on port/slice_facef.txt and its
    # C name comes from hal/except_faces.cpp.
    ${SLICE_OV074_SOURCES}
    hal/actor_classes_bbh.cpp ${SLICE149_SOURCES}
    hal/actor_classes_hmc.cpp ${SLICE172_SOURCES} unmatched/Crate_StateDispatch.cpp
    hal/actor_classes_updownlift.cpp ${SLICE173_SOURCES} unmatched/UpDownLiftBbh_Behavior.cpp
    hal/actor_classes_montymole.cpp ${SLICE174_SOURCES} unmatched/MontyMole_StateDispatch.cpp unmatched/MontyMole_1Up.cpp
    hal/actor_classes_flame.cpp ${SLICE175_SOURCES}
    hal/actor_classes_flamethrower.cpp ${SLICE_W6F_SOURCES}
    ${SLICE_W8FACES_SOURCES}
    hal/actor_classes_scuttlebug.cpp ${SLICE176_SOURCES} unmatched/Scuttlebug_StateDispatch.cpp
    hal/actor_classes_ov071.cpp ${SLICE_W7B_SOURCES} ${GATE_W7B_GEN} unmatched/MrI_StateDispatch.cpp
    # unmatched/MrI_Render.cpp RETIRED (run link100, lane EXCEPT): its own
    # header said "If _ZTV9ModelAnim ever gains a ROM-order view, this
    # retires", and SLOT5F gave it one. src/_ZN3MrI6RenderEv.cpp is on
    # port/slice_except2.txt.
    hal/actor_classes_ov064.cpp ${SLICE177_SOURCES} unmatched/Bully_AfterClsn.cpp
    hal/actor_classes_ov064_gate178.cpp ${SLICE178_SOURCES} unmatched/Ov064Gate178_States.cpp
    hal/actor_classes_ov064_w9.cpp ${SLICEW9A_SOURCES} ${SLICEW9B_SOURCES} ${SLICEW9C_SOURCES} ${SLICEW9D_SOURCES}
    hal/actor_classes_jrb.cpp ${SLICE188_SOURCES}
    # unmatched/Jrb_Renders.cpp RETIRED (run link100, lane FACEF): all four of
    # its bodies were the ROM-order model slot-5 draw, and both halves of its
    # stated reason are dead -- the numbering with lane SLOT5F's respelling,
    # and the return-type half because an indirect call through the object's
    # own vptr decorates nothing. src/_ZN6ShipUp6RenderEv.cpp,
    # src/_ZN10SlidingBox6RenderEv.cpp, src/_ZN10RockPillar6RenderEv.cpp
    # and src/actors/daObjFloatBoard_c.cpp are on port/slice_facef.txt; the two
    # method recoveries take a cdecl face in hal/except_faces.cpp and the two
    # C names need none.
    unmatched/Unagi_StateDispatch.cpp unmatched/Jrb_Aliases.cpp
    ${SLICE_SMALL7_SOURCES}
    hal/actor_classes_bowserpuzzle.cpp ${SLICE179_SOURCES} unmatched/BowserPuzzle_StateDispatch.cpp
    hal/actor_classes_koopa_chuckya.cpp hal/koopa_chuckya_faces.cpp ${SLICE182_SOURCES} unmatched/KoopaChuckya_StateDispatch.cpp ${SLICEKLEPTO_SOURCES} unmatched/Klepto_StateDispatch.cpp unmatched/Klepto_PathPtrFaces.cpp
    ${SLICE180_SOURCES} ${SLICE203_SOURCES} ${SLICE204_SOURCES}
    hal/actor_classes_ov085.cpp ${SLICE205_SOURCES}
    unmatched/Ov085_Behaviors.cpp
    # unmatched/Ov085_Toad_StateSeat.cpp RETIRED (run link100, lane PMFB1):
    # it held only Toad's two state dispatchers and their static helper, and
    # src/_ZN4Toad8SetStateEi.cpp and src/_ZN4Toad8RunStateEv.cpp carry both on
    # port/slice_pmfc.txt (block R9d). The seat that fills their table is
    # port_toad_states_seat in hal/actor_overlays.cpp and is untouched.
    # run rel0215 wave 3 (lane w3-f): ov085's PRINCESS_PEACH, the sixth
    # and last class. ONE host copy rides beside the slice now, the two PMF
    # dispatchers; unmatched/Ov085_PrincessPeach_Behavior.cpp RETIRED (run
    # link100, lane FOLD2) because the slot-6 body's whole reason was the
    # ModelAnim slot-3 numbering, and _ZTV9ModelAnim[3] is UpdateVerts again.
    ${SLICEW3F_SOURCES}
    unmatched/Ov085_PrincessPeach_Declshapes.cpp
    hal/actor_classes_montymolerock.cpp ${SLICE208_SOURCES}
    hal/actor_classes_ov043.cpp ${SLICE206_SOURCES} ${SLICE207_SOURCES} ${SLICEBDW_SOURCES}
    # gate 215 (run link100, lane SAVE): the save system's own medium path,
    # plus the hosted backup medium the ARM7 would otherwise answer for.
    ntr/backup.cpp ${SLICE215_SOURCES} hal/os_lockid.cpp hal/globals_link100.cpp
    hal/actor_classes_enemy_spawner.cpp ${SLICE211_SOURCES} hal/actor_classes_question_switch.cpp ${SLICE212_SOURCES} ${SLICE216_SOURCES}
    hal/boot2_ipc.cpp ${SLICE2IPC_SOURCES} ${GATE2IPC_GEN}
    hal/actor_classes_enemy_spawner.cpp ${SLICE211_SOURCES} hal/actor_classes_question_switch.cpp ${SLICE212_SOURCES} ${SLICE213_SOURCES}
    # ---- link100 SCENE ---- the two arm9-resident scene classes, gate 218
    hal/scene_link100_base_faces.cpp hal/scene_link100_boot.cpp
    hal/scene_link100_mb.cpp ${SLICE218_SOURCES}
    hal/actor_classes_l7.cpp ${SLICE_L7_SOURCES} ${GATE_L7_GEN} unmatched/PiranhaPlant_States.cpp
    unmatched/WaterBomb_StateDispatch.cpp
    unmatched/KnockDownPlank_Behavior.cpp
    # unmatched/FallBlockWf_InitVeneer.cpp RETIRED (run link100 wave 15, lane
    # SEAT15A): it held ONE body, func_ov098_0213a794, under a PORT_HOST_ABI tag
    # saying MSVC C2733 rejects the matched TU's second extern-C declaration of
    # itself. Re-measured on this tree with the port's own command line,
    # src/func_ov098_0213a794.cpp compiles clean and emits the same flat cdecl
    # name, so the tag was stale and the file had no reason left. The TU is on
    # port/slice_l15enab.txt, which carries the measurement.
    # run rel0215 wave 1 (lane cast-sweep1): the six small-cast overlays
    ${SWEEP1_SOURCES}
    # run rel0215 wave 2 (lane cast-sweep2): the four-overlay cast sweep
    ${SWEEP2_SOURCES}
    # run rel0215 wave 3 (lane w3-e): three partially-seated level
    # overlays' remaining tails (ov022, ov019, ov025)
    ${W3E_SOURCES}
    # ov029: level 21's water_city actors, ids 94..101
    ${OV029_SOURCES}
    # ---- link100 OV ---- ids 348 (ov002, daChRoom_c) and 314 (ov039, Cloud)
    hal/actor_classes_ov_link100.cpp ${SLICE217_SOURCES}
    "${PORT_GITTIP_C}"
    # run link100 wave 15, lane SEAT15E: LINK15 BATCH 4 seats (slice_l15ov7)
    ${SLICE_L15OV7_SOURCES}
    "${ROMDATA_C}" "${OV009SYMS_C}" ${ACTOR_OV_SYMS} "${OVCROSS_C}")
target_include_directories(walk_window_hires PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(walk_window_hires PRIVATE ntr_hires lua_resource_pack)
target_compile_definitions(walk_window_hires PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF}
    # GATE STARSEL (run link100, lane STARSELENTRY): this target carries
    # hal/input_probe.cpp, so hal/scene_boot.cpp's port_scene_tick can call
    # port_input_probe_apply.  smoke_player does not compile input_probe.cpp
    # (see its own source list), so the call there stays guarded off.
    SM64DS_SCENE_PAD_PROBE=1
    # GATE 220 (run link100, lane FRAME): this target carries
    # port/slice_gate220.txt and hal/stage_frame.cpp, so _ZTV5Stage
    # slot 6 dispatches the ROM's own Stage::Behavior instead of the
    # host occupant.  smoke_player does not define this and keeps the
    # occupant; see the gate row above it for why.
    SM64DS_STAGE_SLOT6_ROM=1
    # GATE SLOT9 (run link100, lane RENDER9): the same for slot 9 and
    # Stage::Render.  SM64DS_STAGE_SLOT9_HOST=1 in the ENVIRONMENT makes the
    # seated thunk decline at run time, which is how the BMP A/B is captured
    # on ONE binary; the compile definition is what puts the ROM body in the
    # slot at all.
    SM64DS_STAGE_SLOT9_ROM=1
    # GATE SHADOWS RUNG 3 (run link100, lane SHADOWS2): this target carries
    # port/slice_shadows.txt AND port/slice_gate16.txt, so the ROM's own
    # SharedFilePtr::ReallocateModelFile is in the link with func_02017060
    # under it.  The define retires the empty stand-in in
    # hal/gx_upload_bridge.cpp, which would otherwise defeat that file's
    # /alternatename by defining its LHS.  The ten narrow harnesses link the
    # caller without the callee and keep the stand-in.
    SM64DS_SFP_REALLOC_ROM=1
    # this target links hal/cxx_aliases.cpp, which already carries
    # the Heap::_Deallocate face hal/blend_vtable.cpp repeats
    PORT_CXX_ALIASES_LINKED)
if(PORT_ROM_CLEAN)
    target_sources(walk_window_hires PRIVATE "${ROMDATA_DISPATCH_C}"
                   hal/romdata_loader.cpp hal/asset_root_refuse.cpp)
    target_compile_definitions(walk_window_hires PRIVATE PORT_ROM_CLEAN)
    add_dependencies(walk_window_hires romblob_ready_ww)
endif()
if(MSVC)
    target_compile_options(walk_window_hires PRIVATE /wd4311 /wd4312 /wd4068 /wd4576)
    # No ASLR for the shipped window: a disk save state (hal/lk7_persist
    # .cpp) stores absolute pointers into the exe image -- every actor's
    # vtable pointer -- and they only relocate if the image loads at the
    # SAME base on the next launch. ASLR rebases once per boot, which
    # would refuse every state written before a reboot. The header still
    # checks the base, so if anything rebases the exe anyway the state is
    # refused with a message rather than loaded onto dangling pointers.
    target_link_options(walk_window_hires PRIVATE /DYNAMICBASE:NO)
endif()


# ---------------------------------------------------------------------------
# WIDESCREEN IS A RUNTIME TOGGLE NOW, not a separate exe.
#
# The old walk_window_wide (a second exe built against a fixed NTR_WIDE169 tier)
# is gone: walk_window links ntr_wide_rt (defined near the top of this file),
# whose framebuffer is the wide maximum and whose active render size is chosen at
# boot from the Aspect settings key (a ratio). One binary presents either aspect --
# 512x384 4:3 (the shipped default) with the key off, 1024x576 16:9 with it on --
# with no aspect distortion off and no second source set to keep in sync. The
# NTR_WIDE169 tier (ppu.h) is still defined for a fixed-compile wide build, but
# nothing here builds one.


# The SDAT player on its own: parser, sequencer and mixer with no game code
# and no command queue, so a failure is localised to the player itself.
add_executable(smoke_sdat tests/smoke_sdat.cpp
    hal/sdat/sdat.cpp hal/sdat/mixer.cpp hal/sdat/sseq.cpp hal/sdat/out_win.cpp)
target_include_directories(smoke_sdat PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_compile_definitions(smoke_sdat PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(smoke_sdat PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# settings.json's control bindings and camera mode (hal/host_settings.cpp),
# proved on the file alone: one child process per case because the loader
# reads once, no ROM, no window. tests/smoke_settings.cpp carries the cases.
# hal/pad_backend.cpp is on it too, for the PadLayouts translation case
# (port_pad_selftest): no window, no worker thread, kernel32 only.
add_executable(smoke_settings tests/smoke_settings.cpp hal/host_settings.cpp
    hal/pad_backend.cpp)
target_include_directories(smoke_settings PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_compile_definitions(smoke_settings PRIVATE SM64DS_PLATFORM_PC)
if(MSVC)
    target_compile_options(smoke_settings PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# ---------------------------------------------------------------------------
# THE ABI DEFECT DETECTORS
#
# port/tools/run_checks.py fires the receiver / calling-convention / vtable
# shape detectors and fails on any red, and on any VACUOUS pass (a checker
# that parsed nothing must not read as green):
#
#   aliascheck            an /alternatename that crosses the receiver boundary
#   vtspan --sweep        a host vtable array shorter than its ROM span
#   vtspan --fills        a fill loop that leaves a ROM slot unwritten
#   aritycheck            a declaration and a definition of one extern "C"
#                         symbol that disagree about how many parameters it
#                         takes (census, plus ratchets on the receiver shape
#                         and the plain-name func_* shape)
#   abicheck              a vtable thunk whose emitted `ret` breaks its slot's
#                         frame contract (needs this build's hal objects)
#
# TWO TARGETS, AND NEITHER IS IN ALL. That is deliberate. The port has no CI,
# so a target wired into ALL is the only thing that would run these for other
# people -- and turning a currently-green build red for every contributor is a
# decision for the port's owner, not for the lane that recovered the tools.
# Both are one command away:
#
#   ninja -C build/port port_checks_nobuild    the four no-build checkers
#   ninja -C build/port port_checks            + abicheck over THIS build
#
# port_checks_nobuild depends on nothing, so it runs even when the port does
# not fully link. port_checks depends on smoke_actor (which compiles
# actor_vtables.cpp and the other vtable-fill HAL objects), disassembles the
# build's hal objects with /disasm:nobytes, and runs the whole gate.
#
# THE DISASSEMBLY GOES IN THE BUILD DIRECTORY, never a fixed absolute path.
# The recovered wiring wrote to a shared C:/tmp/sm64ds-abisweep/_disasm, so
# two lanes running the suite at once would have written each other's input
# and each measured the other's build -- green, and meaningless.
find_program(PORT_PYTHON NAMES python python3 py)
if(PORT_PYTHON)
    add_custom_target(port_checks_nobuild
        COMMAND "${PORT_PYTHON}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/run_checks.py"
                "${PORT_REPO_ROOT_ABS}"
        WORKING_DIRECTORY "${PORT_REPO_ROOT_ABS}"
        COMMENT "port ABI checks (no build): aliascheck + vtspan + aritycheck"
        USES_TERMINAL VERBATIM)

    add_custom_target(port_abi_prove
        COMMAND "${PORT_PYTHON}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/abi_prove.py"
                "${PORT_REPO_ROOT_ABS}"
                --disasm-dir "${CMAKE_BINARY_DIR}/_abicheck_disasm"
        WORKING_DIRECTORY "${PORT_REPO_ROOT_ABS}"
        COMMENT "prove each ABI checker green here and red on a re-broken copy"
        USES_TERMINAL VERBATIM)

    if(MSVC)
        # gen_disasm.cmd emits ONLY /disasm:nobytes. Plain /disasm makes
        # abicheck parse zero stores; abicheck refuses a zero-fill run and
        # run_checks refuses it again, but generating the wrong format is the
        # mistake that causes it, so the generator never produces anything
        # else.
        add_custom_target(port_checks
            COMMAND "${CMAKE_COMMAND}" -E echo
                    "== generating /disasm:nobytes for abicheck =="
            COMMAND cmd /c "${CMAKE_CURRENT_SOURCE_DIR}/tools/gen_disasm.cmd"
                    "${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/_abicheck_disasm"
            COMMAND "${PORT_PYTHON}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/run_checks.py"
                    "${PORT_REPO_ROOT_ABS}"
                    --disasm-dir "${CMAKE_BINARY_DIR}/_abicheck_disasm"
            DEPENDS smoke_actor
            WORKING_DIRECTORY "${PORT_REPO_ROOT_ABS}"
            COMMENT "port ABI checks (full): + abicheck over this build"
            USES_TERMINAL VERBATIM)
    endif()
else()
    message(WARNING "python not found: the port ABI check targets were not "
                    "created")
endif()

# THE EXE'S OWN VERSION STRING, FOR THE CODE THAT HAS TO SAY IT.
#
# The performance log's header line names the game's version, and a report
# whose version came from a second copy of the number is a report that will one
# day name the wrong one. res/walk_window.rc below already holds the release
# version, is already bumped by hand per release, and is already the number a
# player sees in the exe's file properties -- so it is the one source, and this
# block lifts its ProductVersion string out at configure time into a
# compile-time define. Nothing to keep in step, and a release that bumps the
# resource bumps the report with it.
#
# The rc file joins the configure-time inputs so editing it reconfigures by
# itself (see "THE CONFIGURE-TIME INPUTS, REGISTERED" above); without that the
# define would keep the previous release's number until something else forced a
# configure.
set(PORT_GAME_VERSION "")
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/res/walk_window.rc"
     PORT_RC_PRODUCTVERSION_LINES REGEX "VALUE[ \t]+\"ProductVersion\"")
foreach(rcline IN LISTS PORT_RC_PRODUCTVERSION_LINES)
    if(rcline MATCHES "\"ProductVersion\"[ \t]*,[ \t]*\"([0-9][0-9.]*)\"")
        set(PORT_GAME_VERSION "${CMAKE_MATCH_1}")
    endif()
endforeach()
if(PORT_GAME_VERSION STREQUAL "")
    message(WARNING "res/walk_window.rc has no readable ProductVersion: the "
                    "performance report's gameVersion will be empty")
endif()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
             "${CMAKE_CURRENT_SOURCE_DIR}/res/walk_window.rc")
target_compile_definitions(walk_window PRIVATE
    PORT_GAME_VERSION="${PORT_GAME_VERSION}")
target_compile_definitions(walk_window_hires PRIVATE
    PORT_GAME_VERSION="${PORT_GAME_VERSION}")

# Windows identity resources: version info + icon for the game-shaped exes a
# player can meet (the bundle ships walk_window; hires is its sibling build of
# the same sources). Resources land in .rsrc and move nothing in .text, so the
# map-reading guards are untouched. The smokes stay bare on purpose: they are
# dev tools, not shipped artifacts. Version numbers live in res/walk_window.rc
# and are bumped by the release lane next to version.json.
if(WIN32)
    enable_language(RC)
    target_sources(walk_window PRIVATE res/walk_window.rc)
    target_sources(walk_window_hires PRIVATE res/walk_window.rc)
endif()

# ===========================================================================
# run mg15 lane MP1: THE SLEEP/WAKE PROBE.
#
# runs/mg15/out/MP/FRONTIER.md section 10.2 names the ROM wireless lockstep's
# OS_SleepThread as the largest unknown in the whole radio-seam plan. These two
# targets are the experiment it asked for, and they are a matched pair on ONE
# source file: same probe, two thread implementations.
#
#   mp_sleepwake_rom  links the ROM bodies port/slice_gate10.txt already puts
#                     in every shipped binary (lines 340/347/349) and calls the
#                     sleep through the real veneer under a structured-exception
#                     guard. It MEASURES port/nfs_names_map.txt:402's claim that
#                     "OS_SleepThread would fault in this port anyway".
#   mp_sleepwake      links port/hal/os_thread.cpp instead.
#
# Both link src/func_02042778.c and src/func_0201a4d0.c AS THEMSELVES, so the
# call really is func_02042778 -> func_0201a4d0 -> OS_SleepThread(data_0209d4fc)
# and not a transcription of it. Console-only, no window, no BMP.
add_executable(mp_sleepwake tests/mp_sleepwake.cpp
    hal/os_thread.cpp
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_02042778.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0201a4d0.c")
target_include_directories(mp_sleepwake PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/hal"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(mp_sleepwake PRIVATE ntr)
target_compile_definitions(mp_sleepwake PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(mp_sleepwake PRIVATE /wd4311 /wd4312 /wd4068)
endif()

add_executable(mp_sleepwake_rom tests/mp_sleepwake.cpp
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/OS_SleepThread.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/OS_WakeupThread.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_02057f54.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_02042778.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0201a4d0.c")
target_include_directories(mp_sleepwake_rom PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/hal"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(mp_sleepwake_rom PRIVATE ntr)
target_compile_definitions(mp_sleepwake_rom PRIVATE SM64DS_PLATFORM_PC
    MP_PROBE_ROM_THREADS
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(mp_sleepwake_rom PRIVATE /wd4311 /wd4312 /wd4068 /EHa)
endif()

# run mg15 lane MP1: THE SEAM PROBE. The seam's solo answers and the ROM's
# four-slot fan-out, exercised with the ROM's own code (src/func_0203e0ac.c,
# src/func_0203bb60.c, src/func_0203bc7c.c and the two slot-index accessors)
# and the hosted seam faces. Console-only, no window, no BMP.
add_executable(mp_comms_seam tests/mp_comms_seam.cpp
    hal/comms_seam.cpp hal/os_thread.cpp
    hal/comms_fanout_wide.cpp
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0203e0ac.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0203bb60.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0203bc7c.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0203dabc.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0203dae4.c")
target_include_directories(mp_comms_seam PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/hal"
    "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_link_libraries(mp_comms_seam PRIVATE ntr)
target_compile_definitions(mp_comms_seam PRIVATE SM64DS_PLATFORM_PC
    ${PORT_REPO_ROOT_DEF})
if(MSVC)
    target_compile_options(mp_comms_seam PRIVATE /wd4311 /wd4312 /wd4068)
endif()

# ---- gate 2thr: THE RETIRED HOST PAIR, KEPT ONLY WHERE IT IS MEASURED ------
# run link2, lane THR.
#
# hal/os_thread.cpp's OS_SleepThread / OS_WakeupThread now compile only under
# PORT_OS_THREAD_HOST_PAIR, and these are the two targets that define it. Both
# are console probes with no window and no BMP, and mp_sleepwake's whole reason
# to exist is the A/B: ARM 1 links the ROM bodies with the manager globals
# stubbed at zero and MEASURES the 0xC0000005, ARM 2 links the host pair. Give
# ARM 2 the ROM bodies instead and the comparison it was written to make stops
# existing, so the retired stand-in stays reachable HERE and nowhere else.
#
# It is not reachable in a shipped target: walk_window, walk_window_hires and
# smoke_player take SLICE_COMMS_SOURCES, which now carries src/OS_SleepThread.c
# and src/OS_WakeupThread.c themselves. Neither probe links hal/cxx_aliases.cpp,
# so the ROM bodies could not link into them anyway -- the thread manager BSS
# they read (data_020a612c, data_020a6134, data_020a6128) lives there.
#
# WHAT THIS OWES: mp_sleepwake's ARM 2 half now describes a stand-in that no
# shipped binary carries. The probe still builds and still runs; its prose is a
# lane behind. port/tests/mp_sleepwake.cpp is not this lane's file.
target_compile_definitions(mp_sleepwake PRIVATE PORT_OS_THREAD_HOST_PAIR)
target_compile_definitions(mp_comms_seam PRIVATE PORT_OS_THREAD_HOST_PAIR)

# GATE 221 (run link100, lane DF40): three host stand-ins retired out of the
# func_0203df40 / func_0203ea5c census -- the VS carousel's poll
# (hal/scene_vs_menu.cpp's VS_SEAM block) and the WM status-word
# read-modify-write pair (hal/comms_seam.cpp's g_wm_status). The whole census,
# including why the other 299 rows of those two closures are NOT work, is in
# port/slice_gate221.txt's own header.
#
# ON ALL THREE BIG TARGETS, and not by preference. Each retired host body lived
# in a file every one of them compiles -- hal/comms_seam.cpp rides
# SLICE_COMMS_SOURCES and hal/scene_vs_menu.cpp rides SLICE_VS_SOURCES, and both
# variables go to exactly walk_window, walk_window_hires and smoke_player. A
# target that lost the face without gaining the body would fail at link, so the
# three move together. Appended as target_sources ABOVE the sharing block below,
# which reads the three targets' SOURCES back off them: a source on all three
# joins the single shared compile by itself.
#
# mp_comms_seam also links hal/comms_seam.cpp directly and does NOT get these
# rows. It does not need them: nothing that probe links references
# func_02040a5c or func_02040a84 (only src/func_0203ea5c.c and the wide copy do,
# and neither is in it), so the two names are simply never referenced there.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate221.txt" SLICE221_LINES)
set(SLICE221_SOURCES "")
foreach(line IN LISTS SLICE221_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE221_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_t221 walk_window walk_window_hires smoke_player)
    target_sources(${_t221} PRIVATE ${SLICE221_SOURCES})
endforeach()
# ---- gate 222 (run link100, lane BOOT2): THE REST OF func_0201a054 ---------
#
# Lane BOOT (gate 214) transcribed func_0201a054 and left four of its arms
# marked "left for the next step": func_02053c40 and func_02019440, the two
# halves of the graphics bring-up (the first turns the VRAM banks off, the
# second turns them back on with func_02054430(0x1ff)), plus their tails.
# They run from hal/boot_os.cpp at the ROM's own points now. Seating them also
# closes the gap hal/sub_screen.cpp:947 records: the ROM body seeds all eight
# BG affine words, where the port seeded four by hand.
#
# walk_window and walk_window_hires only: smoke_player does not run the boot
# spine. Appended ABOVE the sharing block below.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate222.txt" SLICE222_LINES)
set(SLICE222_SOURCES "")
foreach(line IN LISTS SLICE222_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE222_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
target_sources(walk_window PRIVATE ${SLICE222_SOURCES})
target_sources(walk_window_hires PRIVATE ${SLICE222_SOURCES})

# ---- gate 223 (run link100, lane THREAD): THREAD CREATION -----------------
#
# run link2's lane THR made the ROM's thread SWITCH real and wrote down, in
# hal/boot2_thread.cpp's own header, that CREATION was not modelled: "the only
# two threads are the two seated below. A restore of a context this file has
# never seen is REFUSED loudly rather than guessed at." Three subsystems were
# measured as blocked on exactly that sentence. This gate removes it:
# src/func_02058200.c (the ROM's OS_CreateThread), its slot allocator, its exit
# thunk, and the card driver's own bring-up func_0206002c, which is the ROM's
# one caller of it that this build's boot reaches. The whole derivation --
# which stores are reproduced byte for byte, which single thing is a host-ABI
# exception, and what is deliberately NOT here -- is in
# port/slice_gate223.txt's header and in hal/boot2_thread.cpp's.
#
# ON ALL THREE BIG TARGETS, and not by preference. hal/scene_vs_menu.cpp rides
# SLICE_VS_SOURCES, which goes to exactly walk_window, walk_window_hires and
# smoke_player, and this lane retires TWO of its VS_SEAM faces (func_02058200
# and func_02058048) because the ROM bodies now cover them. A target that lost
# a face without gaining its body would fail at link, so the three move
# together. Appended as target_sources ABOVE the sharing block below, which
# reads the three targets' SOURCES back off them: a source on all three joins
# the single shared compile by itself.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate223.txt" SLICE223_LINES)
set(SLICE223_SOURCES "")
foreach(line IN LISTS SLICE223_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE223_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_t223 walk_window walk_window_hires smoke_player)
    target_sources(${_t223} PRIVATE ${SLICE223_SOURCES})
endforeach()
#
# THE PROBE IS NOT ON ALL THREE. hal/thread_create.cpp is called from
# hal/boot_os.cpp, which is SLICE214_SOURCES and goes to walk_window and
# walk_window_hires only -- smoke_player does not run the boot spine. Same
# split as the gate 222 block above.
target_sources(walk_window PRIVATE hal/thread_create.cpp)
target_sources(walk_window_hires PRIVATE hal/thread_create.cpp)


# ---- gate 224 (run link100, lane OV6): SIX ov002 BASE TABLES --------------
#
# port/CMakeLists.txt has said, at the gate-216 rename block above, that
# _ZTV17daObjFloatBoard_c is "a table to host, not a rename", and the ov029 binding
# block adds that "the ROM's own ov002 base tables (_ZTV17daObjFloatBoard_c/
# 021091d4) are NOT host arrays, so a dead store is never bound to them". Lane
# TAIL hosted 0x021091d4 in hal/actor_classes_ov036.cpp. This gate hosts the
# other five plus 0x02108284 (CapEnemy's), in hal/actor_base_tables_ov002.cpp,
# and seats the ROM's own words in every slot the port has a body for. The
# widths come from the next-symbol delta in config/arm9/overlays/ov002/
# symbols.txt and the slot contents from that overlay's relocs.txt; the whole
# derivation, including the seven slots on 0x021096b0 that TRAP because their
# ROM word names a guessed body, is in that file's header.
#
# ON ALL THREE BIG TARGETS. The seat's shared half calls Actor/ActorBase faces
# and port_actor_s30_base out of hal/actor_classes.cpp, which walk_window,
# walk_window_hires and smoke_player all compile; a target that got the arrays
# without the faces would fail at link, so the three move together. Appended as
# target_sources ABOVE the sharing block below.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate224.txt" SLICE224_LINES)
set(SLICE224_SOURCES "")
foreach(line IN LISTS SLICE224_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE224_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_t224 walk_window walk_window_hires smoke_player)
    target_sources(${_t224} PRIVATE ${SLICE224_SOURCES} hal/actor_base_tables_ov002.cpp)
endforeach()
#
# THE NINE DESTRUCTORS' vptr BINDINGS. Every one of these bodies was recovered
# through a shared header, so it spells its two vptr stores with placeholder
# names (_ZTV10dBgActor_c / _ZTV11dCapEnemy_c / _ZTV16daObjPushblock_c, then
# VT1), and the same placeholder is a DIFFERENT table in a different TU -- the
# ov065 disease the ov029 block above documents. Each row is read out of that
# body's OWN literal pool in config/arm9/overlays/ov002/relocs.txt, never out
# of the recovery's names, and the rule is the ov029 block's unchanged: the
# LIVE (last) store gets its true target and the DEAD earlier store is bound to
# the class's own array, which gate 224 is what makes definable.
#
#   _ZN17daObjFloatBoard_cD0Ev  0x020b5a64 -> 0x02108fdc   0x020b5a68 -> 0x0210ae38
#   _ZN17daObjFloatBoard_cD1Ev  0x020b5aac -> 0x02108fdc   0x020b5ab0 -> 0x0210ae38
#   _ZN15daObjGuragura_cD0Ev  0x020b6024 -> 0x02109084   0x020b6028 -> 0x0210ae38
#   _ZN15daObjGuragura_cD1Ev  0x020b606c -> 0x02109084   0x020b6070 -> 0x0210ae38
#   _ZN14daObjUkiyuka_cD0Ev  0x020b63d4 -> 0x0210912c   0x020b63d8 -> 0x0210ae38
#   _ZN14daObjUkiyuka_cD1Ev  0x020b641c -> 0x0210912c   0x020b6420 -> 0x0210ae38
#   _ZN16daObjPushblock_cD1Ev  0x020b8c34 -> 0x021096b0   0x020b8c38 -> 0x0210ae38
#   _ZN13daObjSwdoor_cD0Ev  0x020bab58 -> 0x021099e4   0x020bab5c -> 0x0210ae38
#   _ZN13daObjSwdoor_cD1Ev  0x020baba0 -> 0x021099e4   0x020baba4 -> 0x0210ae38
#
# 0x0210ae38 is _ZTV10dBgActor_c on all nine.
foreach(_g224 _ZN17daObjFloatBoard_cD0Ev _ZN17daObjFloatBoard_cD1Ev)
    set_source_files_properties(
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/${_g224}.c"
        PROPERTIES COMPILE_DEFINITIONS
        "_ZTV10dBgActor_c=_ZTV17daObjFloatBoard_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
endforeach()
foreach(_g224 _ZN15daObjGuragura_cD0Ev _ZN15daObjGuragura_cD1Ev)
    set_source_files_properties(
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/${_g224}.c"
        PROPERTIES COMPILE_DEFINITIONS
        "_ZTV10dBgActor_c=_ZTV15daObjGuragura_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
endforeach()
foreach(_g224 _ZN14daObjUkiyuka_cD0Ev _ZN14daObjUkiyuka_cD1Ev)
    set_source_files_properties(
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/${_g224}.c"
        PROPERTIES COMPILE_DEFINITIONS
        "_ZTV10dBgActor_c=_ZTV14daObjUkiyuka_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
endforeach()
foreach(_g224 _ZN13daObjSwdoor_cD0Ev _ZN13daObjSwdoor_cD1Ev)
    set_source_files_properties(
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/${_g224}.c"
        PROPERTIES COMPILE_DEFINITIONS
        "_ZTV10dBgActor_c=_ZTV13daObjSwdoor_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
endforeach()
# 020b8bf0 stores its OWN table first (the config RTTI name) and _ZTV10dBgActor_c
# last, so here the placeholder that gets the live target is _ZTV10dBgActor_c.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names daObjPushblock_c.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV16daObjPushblock_c=_ZTV16daObjPushblock_c  --  identity rename, a no-op even if it had run
#   _ZTV10dBgActor_c=_ZTV10dBgActor_c  --  identity rename, a no-op even if it had run
# Deleted rather than merged. The surviving row is unchanged.
# CapEnemy's pair is ALREADY in port/slice_gate32.txt and was dropped by
# /OPT:REF for want of a reference edge; gate 224's slot 16/17 seat is that
# edge. Both bodies name their table by the config RTTI placeholder, and D0
# also takes the heap global as G0:
#   _ZN11dCapEnemy_cD1Ev  0x02006550 -> ov002 0x02108284      (arm9 pool)
#   _ZN11dCapEnemy_cD0Ev  0x020aee38 -> ov002 0x02108284, 0x020aee3c -> 0x020a0eac
# D2 spells data_ov002_02108284 by its real name and needs no binding.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11dCapEnemy_cD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZTV11dCapEnemy_c=data_ov002_02108284;G0=data_020a0eac")


# ---- gate 225 (run link100, lane ARM9T): FIVE arm9 .data TABLES -----------
#
# The gate-224 block above hosts six ov002 base tables the port hosted nowhere.
# This gate is the same shape on the MAIN MODULE: two arm9 .data tables whose
# ROM words name matched TUs the port never links, hosted and filled in
# hal/arm9_tables_link100.cpp, plus one already-hosted vtable slot that was
# left trapped for want of a slice line.
#
#   data_02099fe4  the arm9 IRQ vector table, 22 words (next-symbol delta to
#                  data_0209a03c is 0x58, and both ROM readers walk i < 0x16).
#                  Nine distinct bodies; the eight forwarders tail into
#                  0x02056cc0 so _ZN3IRQ13DmaTimHandlerEj rides in with them.
#                  Its bit-number companion data_02099fd4 (16 bytes, no
#                  relocation inside it) is hosted alongside with the ROM's own
#                  eight halfwords, because that handler indexes it.
#   data_02094390  dScMB_c's graph descriptor, 4 words (delta to _ZTSN7dScMB_c15graphCallback_cE
#                  is 0x10). Three bodies plus func_02034d34 behind
#                  _ZN7dScMB_c15graphCallback_c14GraphCallback3Ev.
#   data_02092188  the Stage's graph callback table, 4 words. One body, slot 1;
#                  slot 2 traps on port/slice_w8a.txt's standing ruling that
#                  Stage::GraphCallback2 is not hostable at all.
#   data_0209a424  a two-word callback pair, both bodies new to the link.
#   _ZTVSt9type_info  a two-slot vtable hosted at its 4-word symbol span. One body,
#                  slot 0; slot 1 is an .exceptix census row and traps.
#   data_0208ea6c  slot +0x04 only. hal/scene_boot.cpp seated nine of that
#                  table's ten slots in an earlier gate and left the deleting
#                  destructor trapped, saying in the slot's own comment that
#                  "the reason is a slice line, not a missing body ... which is
#                  outside this change's one-file scope". slice_gate225.txt is
#                  that line and the slot calls src/_ZN10dFdDummy_cD0Ev.cpp now.
#
# BOTH TABLES ARE DEAD STORAGE IN THIS PORT and the seat claims no behaviour
# change from them: every ROM reader of either is itself outside the link --
# the IRQ table's two are _ZN3IRQ13GetIRQHandlerEj / SetIRQHandler, which
# ntr/runtime.cpp DEFINES itself under a PORT_HOST_ABI tag naming this very
# table, and data_02094390's are __sinit_02074fb8 and _ZN7dScMB_c13InitResourcesEv, both
# unlinked. The 0208ea6c slot is the one live-path change in the gate and it
# takes the destructor shape slot +0x00 already rests on.
#
# THE THIRD TABLE THIS LANE WAS HANDED, data_020927ec, IS RULED OUT AND STAYS
# UNHOSTED. It is real and its seven words were read, but resolved symbol by
# symbol against this build's own walk_window.map its four bodies require 40
# unlinked TUs and 17 unhosted arm9 data symbols -- the wireless/WM stack
# through func_0203d950 and func_02030790 -- and one of the 40 is
# src/_ZN3IRQ13SetIRQHandlerEjPFvvE.cpp, an LNK2005 against ntr/runtime.cpp on
# sight. The closure is written down in hal/arm9_tables_link100.cpp so the next
# lane does not measure it twice.
#
# ON ALL THREE BIG TARGETS, and not optionally: hal/scene_boot.cpp's +0x04 slot
# calls _ZN10dFdDummy_cD0Ev by name and all three of walk_window, walk_window_hires
# and smoke_player compile scene_boot.cpp, so a target that got the file
# without the slice would fail at link. Appended as target_sources ABOVE the
# sharing block below.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate225.txt" SLICE225_LINES)
set(SLICE225_SOURCES "")
foreach(line IN LISTS SLICE225_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE225_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_t225 walk_window walk_window_hires smoke_player)
    target_sources(${_t225} PRIVATE ${SLICE225_SOURCES}
                   hal/arm9_tables_link100.cpp)
endforeach()
#
# THE EIGHT FORWARDERS' CALLEE NAME. src/_ZN3IRQ11Dma0HandlerEv.cpp and its
# seven siblings each declare `extern "C" void func_02056cc0(int irq);` and
# call it; config/arm9/symbols.txt names 0x02056cc0 _ZN3IRQ13DmaTimHandlerEj,
# which is what src/_ZN3IRQ13DmaTimHandlerEj.cpp defines. ONE ADDRESS, TWO
# NAMES -- the gate-216 rename block's case, and it takes gate 224's answer: a
# COMPILE_DEFINITIONS row, not an /alternatename. Same arity (one word in r0 /
# on the stack) and same C linkage on both sides, so nothing is bridged but the
# spelling.
#
# GATE 225b: THE THREE SIBLING FADER TABLES' DESTRUCTOR PAIR. gate 219 above
# seated all ten slots of data_0208eacc / data_0208eb2c and both function words
# of data_0208eafc and was backed out after a crash bisect, with the note that
# re-seating needs "the same kind of dispatch-site audit port/fader_boot_map.txt
# section 9c did for data_0208ea6c, extended to data_0209f5bc / data_0209d4ac's
# OTHER readers". That audit was done: every reader of those two pointers in
# arm9 and all 101 overlay reloc files was resolved to its owning function and
# each owner's src TU read for the slot index it dispatches. Forty functions
# read the pointers and they dispatch slots 2, 3, 4, 5, 6, 7 and 8. SLOTS 0, 1
# AND 9 HAVE NO DISPATCH SITE ANYWHERE IN THE IMAGE, so the two destructor
# slots are seated here and everything from +0x08 up keeps gate 219's trap --
# including slot 5, which is where the c0000005 was. The enumeration is written
# out at THE THREE SIBLING TABLES in hal/scene_boot.cpp.
#
# TWO PLACEHOLDER NAMES. src/engine/fader/_ZN5FaderD0Ev.cpp spells its vtable
# `vtbl_Fader` (declared in include/decl_common.h, defined nowhere in this
# build) and Memory::operator_delete2 `base_dtor_Fader`. Both bindings are read
# off that body's OWN literal pool in config/arm9/relocs.txt and not off the
# recovery's names:
#   from:0x02017858 kind:arm_call to:0x0203cbcc  _ZN6Memory16operator_delete2EPv
#   from:0x02017868 kind:load     to:0x0208eafc  the table it writes
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/engine/fader/_ZN5FaderD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "vtbl_Fader=data_0208eafc;base_dtor_Fader=_ZN6Memory16operator_delete2EPv")

foreach(_g225 _ZN3IRQ11Dma0HandlerEv _ZN3IRQ11Dma1HandlerEv
              _ZN3IRQ11Dma2HandlerEv _ZN3IRQ11Dma3HandlerEv
              _ZN3IRQ19Tim0OverflowHandlerEv _ZN3IRQ19Tim1OverflowHandlerEv
              _ZN3IRQ19Tim2OverflowHandlerEv _ZN3IRQ19Tim3OverflowHandlerEv)
    set_source_files_properties(
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/${_g225}.cpp"
        PROPERTIES COMPILE_DEFINITIONS
        "func_02056cc0=_ZN3IRQ13DmaTimHandlerEj")
endforeach()

# ===========================================================================
# GATE 226 -- the seven guessed slots of _ZTV16daObjPushblock_c, ruled and seated
# ===========================================================================
#
# Gate 224 above hosts six ov002 base tables and fills every slot it has a body
# for. On 0x021096b0 (daObjPushblock_c) it had to leave SEVEN calling
# ob2_guessN, because each of those ROM words names a src/ body carrying
# "recovered from vtable slot identity" and inferred_stub_guard.py refuses to
# seat a guess. That was the right call on the evidence gate 224 had.
#
# The evidence changed. Lane STUBADJ read all seven at their ROM ADDRESS (the
# table word in config/arm9/overlays/ov002/relocs.txt, the target in that
# overlay's symbols.txt -- never off a class name, because the tree's class
# names are shifted and the addresses are not), confirmed each is a real
# function entry rather than an interior address of a tail-shared body, and ran
# tools/match.py at that address and size under the pinned mwccarm 2004/b56
# with --strict-relocs. All seven reproduce the ROM: every non-relocated word
# identical and every resolvable relocation landing on the destination config
# records. The marker was recording how the NAME was recovered, not where the
# BODY came from -- which is the same thing lanes w16, w13 and link100's MATCH
# lane each found on their own batches. Rulings:
# port/tools/inferred_stub_adjudicated.txt; transcript:
# runs/link100/out/STUBADJ/verify.txt.
#
# ON ALL THREE BIG TARGETS, for gate 224's reason unchanged: these seven are
# reached only through the table hal/actor_base_tables_ov002.cpp fills, and
# that file is already on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate226.txt" SLICE226_LINES)
set(SLICE226_SOURCES "")
foreach(line IN LISTS SLICE226_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE226_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_t226 walk_window walk_window_hires smoke_player)
    target_sources(${_t226} PRIVATE ${SLICE226_SOURCES})
endforeach()
#
# TWO OF THE SEVEN NEED A BINDING, and both rows are read out of the body's OWN
# literal pool in config/arm9/overlays/ov002/relocs.txt, never out of the
# recovery's names -- the rule the gate 224 block above states and the ov029
# block before it.
#
#   _ZN16daObjPushblock_c16CleanupResourcesEv  0x020b8da4 -> 0x0210df9c   0x020b8da8 -> 0x0210df94
#         The two SharedFilePtr the CleanupResources releases, in that order:
#         the ROM's first ldr (pc+0x14 at 0x020b8d88) reaches 0x020b8da4, the
#         second (pc+0x10 at 0x020b8d90) reaches 0x020b8da8. src spells them G0
#         and G1 in the same order. They are the same pair slot 0 loads by their
#         REAL names at 0x020b9100/0x020b9104, so this is a naming difference
#         between two recoveries of one class, not two different globals.
#
#   _ZN16daObjPushblock_cD0Ev  0x020b8c90 -> 0x021096b0   0x020b8c94 -> 0x0210ae38
#                        0x020b8c98 -> 0x020a0eac
#         The D0's two vptr stores and its heap. Unlike the nine destructors in
#         gate 224, BOTH stores here get their true target: the ROM writes the
#         class's own table first (str r1,[r4] at 0x020b8c4c, r1 loaded from
#         0x020b8c90) and _ZTV10dBgActor_c second (0x020b8c5c from 0x020b8c94), so
#         there is no dead store to redirect. 0x020a0eac is the heap global,
#         the same G0 gate 224 binds on _ZN11dCapEnemy_cD0Ev.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names daObjPushblock_c.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   G0=data_ov002_0210df9c  --  dead, the TU does not spell G0
#   G1=data_ov002_0210df94  --  dead, the TU does not spell G1
# Deleted rather than merged. The surviving row is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/daObjPushblock_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    # SYNC4: VT0 used to bind to data_ov002_021096b0, a name no header
    # declared. main's include/daObjPushblock_c.h now declares the host
    # object's own name `void *_ZTV16daObjPushblock_c[]` while
    # include/decl_common.h declares the placeholder `int VT0[]`, so binding
    # VT0 straight to it is two declarations of one name with different
    # element types (C2040). The placeholder binds to an alias spelling
    # instead; port/hal/actor_base_tables_ov002.cpp resolves it to the same
    # object with an /alternatename, which is the same binding the linker had.
    "VT0=port_vt_daObjPushblock_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")

# ===========================================================================
# GATE 227 -- ten more ruled bodies, on four hosted tables and one trap pair
# ===========================================================================
#
# Gate 226 above seated the seven slots of one ov002 table. This seats ten more
# out of the same ruling set: the four tail slots of _ZTV8SignPost, one tail
# slot of BLACK_BRICK_BLOCK's table, the three POPPING_LAVA_BUBBLES bodies that
# hal/actor_classes_ov070.cpp had re-typed by hand from the listing, and the two
# deleting destructors gate 22 and gate 50 excluded for a placeholder collision.
#
# The per-body evidence -- table word, function entry, call shape, bindings --
# is in slice_gate227.txt, one block per table. The rulings are lane STUBADJ's
# rows in port/tools/inferred_stub_adjudicated.txt.
#
# ON ALL THREE BIG TARGETS, gate 226's reason unchanged: every one of these is
# reached only through a table its own hal file already fills, and all four of
# those hal files are already on all three targets.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate227.txt" SLICE227_LINES)
set(SLICE227_SOURCES "")
foreach(line IN LISTS SLICE227_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE227_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_t227 walk_window walk_window_hires smoke_player)
    target_sources(${_t227} PRIVATE ${SLICE227_SOURCES})
endforeach()
#
# THREE BINDINGS, each read out of the body's OWN literal pool in
# config/<module>/relocs.txt -- the rule the gate 226 block above states.
#
#   _ZN11daObjLava_cD0Ev  0x020b6d7c -> 0x021093e0   0x020b6d80 -> 0x020a0eac
#         The lava bubbles' D0. VT is the class's own table, which
#         hal/actor_classes_ov070.cpp hosts under that same C name; HEAP is
#         Memory::gameHeapPtr, the same word gate 226 binds as G0.
#
#   _ZN4DoorD0Ev  0x02144460 -> 0x02148188   0x02144464 -> 0x020a0eac
#         The plain door's D0. config calls the table 0x02148188 _ZTV4Door and
#         the ROM's own RTTI at 0x02148158 calls it 8daDoor_c; both spellings
#         name that one address, and hal/actor_classes.cpp gate 22 now hosts it
#         under the config name with the second spelling aliased onto it.
#         ov100_syms.txt keeps 0x02148188 out of the mount, so the host array is
#         the only object and the binding names it. (Lane CRASH12 corrected the
#         old note here, which said config had swapped the two doors' names.
#         It had not: 0x021483cc is a separate table, the STAR door's.)
#
#   _ZN8PaintingD0Ev  0x02125458 -> 0x021282b4   0x0212545c -> 0x020a0eac
#         The painting's D0. ov080_syms.txt likewise keeps 0x021282b4 out of
#         the mount and hal/actor_classes_painting.cpp declares the host array
#         under the config name, so VT binds to that name directly.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daObjLava_c.cpp"
    # and the generated copy, lane VPTR16: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set this for a source nothing
    # compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/daObjLava_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT=_ZTV11daObjLava_c;HEAP=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN4DoorD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV4Door;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN8PaintingD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT=_ZTV8Painting;HEAP=data_020a0eac")

# ===========================================================================
# GATE 228 -- eleven more ruled bodies, nine of them over a hand thunk
# ===========================================================================
#
# The same ruling set as gate 227. What is different is what these replace:
# nine of the eleven sit on slots hal already dispatched through a destructor
# thunk this port typed out by hand, and each of those hal files says in prose
# that the inferred-stub marker is the only reason the real body was not used.
# slice_gate228.txt quotes each of those sentences next to the body it refused.
#
# THE ELIDED VPTR STORE IS WHAT COMES BACK. Every hand thunk is the ROM body
# minus its second (and for _ZTV13daObjKi_Ita_c, second and third) vptr store,
# because the port could not name the shared-header placeholder those stores
# spell. The -D rows below name it per TU out of each body's own literal pool.
# The tables they land on are live host arrays -- _ZTV10dBgActor_c and
# _ZTV10dBgActor_c are one ROM table under two host arrays that
# hal/actor_classes.cpp dual-fills, and _ZTV17daObjFloatBoard_c is hosted in
# hal/actor_base_tables_ov002.cpp -- and the store happens inside a destructor
# whose next act is Memory::Deallocate, so nothing dispatches through it.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate228.txt" SLICE228_LINES)
set(SLICE228_SOURCES "")
foreach(line IN LISTS SLICE228_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE228_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_t228 walk_window walk_window_hires smoke_player)
    target_sources(${_t228} PRIVATE ${SLICE228_SOURCES})
endforeach()
#
# NINE BINDINGS. Every address on the right of an = was read at the address on
# the left in config/<module>/relocs.txt, inside the body's own span. Nothing
# here comes from a recovered name.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_abuku.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV12daObjAbuku_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_warpkun.cpp"
    # and the generated copy, lane VPTR16: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set this for a source nothing
    # compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/game/actors/d_a_warpkun.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV11daWarpkun_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/daSCoin_c.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV9daSCoin_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_c0_switch.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV16daObjC0_Switch_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_clock_huriko.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV18daObjClockHuriko_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN7SkiLiftD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV7SkiLift;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN10RockPillarD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV10RockPillar;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_ki_ita.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV13daObjKi_Ita_c;VT1=_ZTV17daObjFloatBoard_c;VT2=_ZTV10dBgActor_c;G0=data_020a0eac")
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN5StumpD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV11daObjPile_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")

# ===========================================================================
# GATE 229 -- three more ruled bodies, all deleting destructors
# ===========================================================================
#
# The same ruling set as gates 227 and 228 (lane STUBADJ's REAL_DECOMP rows in
# port/tools/inferred_stub_adjudicated.txt). What is left in that set after
# those two gates is mostly NOT seatable, and port/slice_gate229.txt says which
# and why so the next lane does not re-derive it: eighteen rows sit on tables
# the port hosts nowhere (their class is unregistered), seven are already
# DEFINED as host copies in port/unmatched, five are the ldr-ip/bx-ip
# interworking veneers that are register ride-throughs by construction, and
# five are the PMF exceptions gate 227 already recorded.
#
# These three are the remainder: each is the ROM's own deleting destructor in
# slot 17 of a table the port ALREADY fills, and each is dispatched today by a
# trap (the two ov029 float platforms) or by a hand-written thunk with the
# second vptr store elided (the ov064 Amilift). Every one of the three hal
# sites says in prose that the inferred-stub marker is the only reason the real
# body was not used, which is exactly what gate 228 was about.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate229.txt" SLICE229_LINES)
set(SLICE229_SOURCES "")
foreach(line IN LISTS SLICE229_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE229_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_t229 walk_window walk_window_hires smoke_player)
    target_sources(${_t229} PRIVATE ${SLICE229_SOURCES})
endforeach()
#
# ONE BINDING. The two ov029 rows are NOT here: they already existed further up
# this file, written for a seat that never happened, and this lane corrected
# them in place rather than shadowing them with a second row (a second
# set_source_files_properties on the same file wins silently, which is a worse
# thing to leave behind than a corrected row). The Amilift's row is new, read at
# 0x02117a08 and 0x02117a0c inside the body's own span in
# config/arm9/overlays/ov064/relocs.txt: 0x0211bc68 is the class's own table,
# which hal/actor_classes_ov064_gate178.cpp hosts as _ZTV17daObjFl_Amilift_c and
# the ov064 mount deliberately leaves out, and 0x0210ae38 is _ZTV10dBgActor_c.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN12MetalNetLiftD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV17daObjFl_Amilift_c;VT1=_ZTV10dBgActor_c;G0=data_020a0eac")

# ===========================================================================
# GATE 230 -- actor id 192, daObjPushblock_c, joins the registry
# ===========================================================================
#
# Not a decomp gate: the class's nine own bodies are all linked already and
# its vtable is filled with no traps (gate 226). This links the FACTORY and
# lets the spawn spine reach it, which is the last of the three things lane
# SPAWNPREP's dossier said id 192 was missing -- the other two are the
# SpawnInfo row in port/ov002_syms.txt and the registry row in
# hal/actor_classes.inc. Seven placed instances across levels 0, 21 and 39.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_gate230.txt" SLICE230_LINES)
set(SLICE230_SOURCES "")
foreach(line IN LISTS SLICE230_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE230_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_t230 walk_window walk_window_hires smoke_player)
    target_sources(${_t230} PRIVATE ${SLICE230_SOURCES})
endforeach()
#
# ONE BINDING, read at 0x020b9144 inside daObjPushblock_c_classInit's own span in
# config/arm9/overlays/ov002/relocs.txt: the placeholder the source spells is
# this class's own table, hosted in hal/actor_base_tables_ov002.cpp.
# DEAD at the main->port sync (lane SYNC7, wave 9): main folded
# src/d_a_obj_pushblock.cpp (ov002 .text 0x020b910c..0x020b9148) into
# src/game/actors/daObjPushblock_c.cpp, whose classInit is new daObjPushblock_c()
# and spells no placeholder, so this identity mapping has no file and nothing to
# define.
#set_source_files_properties(
#    "${CMAKE_CURRENT_SOURCE_DIR}/../src/d_a_obj_pushblock.cpp"
#    PROPERTIES COMPILE_DEFINITIONS
#    "_ZTV16daObjPushblock_c=_ZTV16daObjPushblock_c")
# GATE SLOT5 -- the thirty Render bodies the destructor fold kept unlinked
# ===========================================================================
#
# mwccarm spends TWO vtable entries on `virtual ~X()` (the Itanium D1/D0 pair)
# and MSVC folds them into one, so every virtual declared after the destructor
# sat one slot early on the host through the whole model hierarchy. The ROM's
# _ZTV9ModelAnim spends slot 5 on Render; the folded host table spent it on
# Virtual18, which takes an argument more. Thirty matched Render bodies that
# dispatch that slot through a local six-virtual shadow were therefore dropped
# from their own gates' slices and hand-transcribed into
# unmatched/ModelAnim_Renders.cpp and unmatched/BobEnemy_Renders.cpp.
#
# include/ModelBase.h and its six siblings now spell the destructor pair as two
# plain virtuals under _MSC_VER, so the host numbers the table the ROM's way
# and the hand copies have nothing left to work around. slice_slot5.txt carries
# the thirty sources, each verified against the word at its class vtable's
# slot 9 in config/arm9/overlays/<ov>/relocs.txt before it was enrolled.
#
# THE FACES ARE THE OTHER HALF. Every one of the thirty fill sites declares the
# Itanium name at C linkage and calls it, because the host copy it reached was
# an extern "C" definition; the matched sources define __thiscall methods, and
# no linker alias bridges ecx against the stack. hal/cxxname_bridge.cpp carries
# the thirty one-line faces, so no fill site changes.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_slot5.txt" SLICE_SLOT5_LINES)
set(SLICE_SLOT5_SOURCES "")
foreach(line IN LISTS SLICE_SLOT5_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SLOT5_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tslot5 walk_window walk_window_hires smoke_player)
    target_sources(${_tslot5} PRIVATE ${SLICE_SLOT5_SOURCES})
endforeach()

# ===========================================================================
# GATE 231 (run link100, lane SPAWN2) -- two actor classes the port had never
# been able to register, and their ruled bodies
# ===========================================================================
#
# Both classes were held out by the same reading and both are released by the
# same ruling. Their lifecycle bodies carry the "recovered from vtable slot
# identity" marker, so hal/actor_classes_ov029.cpp and hal/actor_classes_ov043.cpp
# each wrote in print that the class stays unregistered rather than put a guessed
# body behind a live vtable. Lane STUBADJ then compared every one of them against
# the ROM with match.py 2004/b56 and ruled them REAL_DECOMP -- "every
# non-relocated word identical ... 0 WRONG-DEST, 0 EXTRA, 0 config reloc missing"
# -- which is recorded in port/tools/inferred_stub_adjudicated.txt. They are
# decompilations. The two slice files carry the per-slot ROM derivation.
#
#   id 99  CAGE_LIFT      ov029  _ZTV15daObjWc_Obj05_c  6 own slots  level 21 x2
#   id 137 RICKSHAW_BDW   ov043  _ZTV21daObjKm1_Kurumajiku_c  4 own slots  level 35 x1
#
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_spawn2_cagelift.txt" SLICE231A_LINES)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_spawn2_rickshaw.txt" SLICE231B_LINES)
set(SLICE231_SOURCES "")
foreach(line IN LISTS SLICE231A_LINES SLICE231B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE231_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_t231 walk_window walk_window_hires smoke_player)
    target_sources(${_t231} PRIVATE ${SLICE231_SOURCES})
endforeach()
#
# THE BINDINGS, every one read out of the referring body's OWN literal pool in
# config/arm9/overlays/ov043/relocs.txt and cross-checked against the ARM store
# order, because the recovered placeholder names are not in ROM order here.
#
# daObjKm1_Kurumajiku_c_classInit (0x021114dc) makes TWO stores and the source spells the
# named one FIRST:
#     021114f4  ldr r1,[pc,#20]  -> [02111510] = 02109320
#     021114f8  ldr r0,[pc,#20]  -> [02111514] = 0211238c
#     021114fc  str r1,[r4]                       <- dead first store
#     02111500  str r0,[r4]                       <- LIVE store, own table
# so _ZTV21daObjKm1_Kurumajiku_c is the ov002 intermediate base 0x02109320 (a
# host array in hal/actor_classes_ov047.cpp) and VT1 is the class's own table.
# Binding the named one to the own table would land the right vptr by accident
# and still be a wrong reloc destination, which is what linkcheck catches.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_km1_kurumajiku.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV21daObjKm1_Kurumajiku_c=_ZTV17daObjKurumajiku_c  --  dead, the TU does not spell _ZTV21daObjKm1_Kurumajiku_c
#   VT1=_ZTV21daObjKm1_Kurumajiku_c  --  dead, the TU does not spell VT1
# Deleted rather than merged. The surviving row is unchanged.
#
# The D1 (0x021113fc) and the D0 (0x0211144c) both make THREE stores in the same
# order -- own table, ov002 base, _ZTV10dBgActor_c -- and there the source order and
# the pool order agree:
#     02111400  ldr r1 -> [02111440] = 0211238c ; 0211140c str r1,[r4]
#     02111408  ldr r0 -> [02111444] = 02109320 ; 02111414 str r0,[r4]
#     02111410  ldr r1 -> [02111448] = 0210ae38 ; 0211141c str r1,[r4]
# and the D0 adds 0x021114ac -> 0x020a0eac, the game heap pointer it hands to
# Memory::Deallocate as G0. 0x0210ae38 is _ZTV10dBgActor_c in ov002/symbols.txt.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_km1_kurumajiku.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV21daObjKm1_Kurumajiku_c=_ZTV21daObjKm1_Kurumajiku_c  --  identity rename, a no-op even if it had run
#   _ZTV10dBgActor_c=_ZTV17daObjKurumajiku_c  --  dead, the TU does not spell _ZTV10dBgActor_c
#   VT2=_ZTV10dBgActor_c  --  dead, the TU does not spell VT2
# Deleted rather than merged. The surviving row is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_km1_kurumajiku.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "VT0=_ZTV21daObjKm1_Kurumajiku_c;VT1=_ZTV17daObjKurumajiku_c;VT2=_ZTV10dBgActor_c;G0=data_020a0eac")
#
# CAGE_LIFT needs no new row. Its factory spells _ZTV15daObjWc_Obj05_c by name and
# that is the host array; its D1 and D0 rows already exist above (the D0's is
# corrected in place for the missing G0).

# ===========================================================================
# GATE 232 (run link100, lane SPAWN2) -- ov010's TRAP (actor 36) is bound to
# the WRONG vtable, and this is the correction
# ===========================================================================
#
# hal/actor_classes.cpp binds /alternatename:__ZTV14daObjC1_Trap_c=__ZTV4Trap on
# the reading that one ov010 table wears three names. The ROM says two tables of
# two classes: the RTTI name string at each table's vtable-4 record reads
# "14daObjC1_Trap_c" (0x02112ae4, via 0x02112aa0 -> 0x02112aac) and
# "15daObjC1Hikari_c" (0x02112ba8, via 0x02112b64 -> 0x02112b70), and each
# factory's own literal pool loads its own one -- daObjC1_Trap_c_classInit's word at 0x021119cc
# is 0x02112ae4, daObjC1Hikari_c_classInit's at 0x02111e0c is 0x02112ba8. The full
# derivation, and the four independent reads it rests on, is the header of
# hal/actor_classes_ov010.cpp. The alias itself is NOT removed: once the two
# per-source rows below rename the only two spellings of it, no TU asks for the
# bare name and the directive simply stops firing, which keeps this gate out of
# a file it does not own.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_spawn2_trap36.txt" SLICE232_LINES)
set(SLICE232_SOURCES "")
foreach(line IN LISTS SLICE232_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE232_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# The fill itself rides the same list rather than being threaded into the three
# long per-target source blocks above; target_sources appends either way.
list(APPEND SLICE232_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_ov010.cpp")
foreach(_t232 walk_window walk_window_hires smoke_player)
    target_sources(${_t232} PRIVATE ${SLICE232_SOURCES})
endforeach()
#
# THE TWO SPELLINGS OF THE TABLE. src/game/actors/d_a_obj_c1_trap.cpp makes ONE vptr store and its
# pool holds one word (0x021119cc -> 0x02112ae4), so there is no dead first store
# to disentangle here. src/game/actors/d_a_obj_c1_trap.cpp (the D1) makes two, and the pool
# order matches the source order: 0x021111e4 -> 0x02112ae4 for the class's own
# table, 0x021111e8 -> 0x0210ae38 which is _ZTV10dBgActor_c.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_c1_trap.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV14daObjC1_Trap_c=_ZTV14daObjC1_Trap_c  --  identity rename, a no-op even if it had run
# Deleted rather than merged. The surviving row is unchanged.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_c1_trap.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   _ZTV14daObjC1_Trap_c=_ZTV14daObjC1_Trap_c  --  identity rename, a no-op even if it had run
#   _ZTV10dBgActor_c=_ZTV10dBgActor_c  --  identity rename, a no-op even if it had run
# Deleted rather than merged. The surviving row is unchanged.
# The D0 (0x021111ec) spells all three of its words as placeholders. Its pool, in
# store order: 0x02111240 -> 0x02112ae4 (VT0), 0x02111244 -> 0x0210ae38 (VT1,
# _ZTV10dBgActor_c), 0x02111248 -> 0x020a0eac (G0, the game heap pointer it hands to
# Memory::Deallocate). G0 is written out rather than left to the global
# cxx_aliases binding, the gate-229 lesson: a -D row that has never been compiled
# is a row nothing has ever checked.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_c1_trap.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   VT0=_ZTV14daObjC1_Trap_c  --  dead, the TU does not spell VT0
#   VT1=_ZTV10dBgActor_c  --  dead, the TU does not spell VT1
#   G0=data_020a0eac  --  dead, the TU does not spell G0
# Deleted rather than merged. The surviving row is unchanged.
#
# SLOT 3'S TWO CROSS-OVERLAY MISNAMES. src/game/actors/d_a_obj_c1_trap.cpp spells
# data_ov025_02112d08 and data_ov024_02112d00; the ROM's loads inside that body,
# at 0x021115a0 and 0x021115a4, are data_ov010_02112d08 and data_ov010_02112d00,
# both mounted. An /alternatename onto the dsd spellings would be DEFEATED AND
# SILENT -- data_ov025_02112d08 is really defined by ov025's own mount and is in
# walk_window.map today -- and a -D straight onto the mount names is a C2040,
# because decl_common.h declares data_ov024_02112d00 as `char[]` while declaring
# data_ov010_02112d00 as a scalar `void *`. So both take the PATH_LIFT remedy: a
# -D to two private names this seat owns, bound onto the mounted objects by
# /alternatename in hal/actor_classes_ov010.cpp.
# lane CDEFS 2026-09-16: a dead COMPILE_DEFINITIONS row stood here.
# A LATER set_source_files_properties() names d_a_obj_c1_trap.cpp for the same
# property, and that call REPLACES this one, so nothing on this row ever
# reached the compiler. Each definition it carried, against the synced TU:
#   data_ov025_02112d08=port_ov010_trap_modelfile  --  dead, the TU does not spell data_ov025_02112d08
#   data_ov024_02112d00=port_ov010_trap_clsnfile  --  dead, the TU does not spell data_ov024_02112d00
# Deleted rather than merged. The surviving row is unchanged.
#
# SLOT 6'S DISPATCH CELLS. src/game/actors/d_a_obj_c1_trap.cpp declares
# `extern PMF data_ov010_02112d28[];` OUTSIDE extern "C" over a forward-declared
# class, so MSVC decorates it with the pointer-to-member type and no C-named
# mount object can satisfy the reference. Renaming it here to a symbol
# hal/actor_classes_ov010.cpp DEFINES with the identical two declarations makes
# both TUs mangle to the same name, so it resolves with no alias and no
# decoration guessed off a link error. The cells are filled by
# port_trap36_states_seat() from the five mounted ROM records, each verified
# against the address its own relocation names before it is used.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/game/actors/d_a_obj_c1_trap.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "data_ov010_02112d28=port_trap36_states")
# LANE UNMATCH, batch 1: four host copies whose reason died with the unfold
# ===========================================================================
#
# Lane SLOT5F respelled the ROM's D1/D0 destructor pair as two plain virtuals
# under _MSC_VER, so every host model-family table is ROM-numbered again and
# three separate workarounds in port/unmatched have nothing left to work
# around: two ROM-order slot-5 Render shadows (SWITCH_PILLAR's own Render and
# METAL_NET_LIFT's) and one ROM-slot-1 deleting-destructor shadow (the door's
# CleanupResources, which hal/model_dtor_seat.cpp now seats at
# _ZTV5Model[1] / _ZTV9ModelAnim[1] / _ZTV10ModelAnim2[1]). The fourth is
# CutsceneObject::Render, whose host copy SLOT5F itself corrected into a
# line-for-line copy of the matched source plus a trace.
#
# Every row is verified by ROM address against the word at its class vtable's
# own slot, and the three ruled bodies are REAL_DECOMP rows in
# port/tools/inferred_stub_adjudicated.txt. No fill site changes and no face is
# added: all three ruled bodies are extern "C" symbols their thunks already
# call by name, and CutsceneObject::Render's cdecl face already exists at
# hal/actor_classes_intro.cpp:655. The per-row referrer and the reloc line are
# in port/slice_unmatch.txt, together with the four rows of SEAT3's census that
# STAY host copies and the measured reason for each.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_unmatch.txt" SLICE_UNMATCH_LINES)
set(SLICE_UNMATCH_SOURCES "")
foreach(line IN LISTS SLICE_UNMATCH_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_UNMATCH_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tunmatch walk_window walk_window_hires smoke_player)
    target_sources(${_tunmatch} PRIVATE ${SLICE_UNMATCH_SOURCES})
endforeach()

# ===========================================================================
# LANE UNMATCH, batch 2: the two tables nothing re-seated, and the one
# dispatcher shape no seat in this tree served
# ===========================================================================
#
# Lane PMF3 landed twenty member-pointer host copies and named three families
# it would not force. None of the three was a width or a form problem -- all
# three measure as the ROM's own record under /vmg /vmm -- and all three needed
# a SECOND fix, which is what this block is.
#
#   DA_PG_DFDR (ov027)  nothing rewrote data_ov027_02113ce4, so the table held
#                       DS code addresses for the life of the process. The seat
#                       moved into port/unmatched/DaPgDfdr_StateDispatch.cpp,
#                       called from hal/actor_overlays.cpp BEFORE
#                       __sinit_ov027_02112df8 copies the four pairs.
#   YOSHI_EGG (ov002)   the same, one overlay over. Its sinit runs from the
#                       harness at startup so the source pairs are out of
#                       reach; the seat rewrites the destination table from
#                       port_actor_overlays_sinits() at level boot instead.
#   THE PAINTING (ov080) its three dispatchers end `return 1;` after the
#                       dispatch, so MSVC emits `call eax` and not the tail
#                       jump every other seated table in this tree relies on to
#                       leave the receiver at [esp+4]. The twelve seated
#                       records now hold a one-line __fastcall face each.
#
# Every pair behind all three was re-read out of the raw overlay images for
# this lane and every adjustment word is ROM zero; the seats abort by name on
# anything else and are idempotent, so a .dsstate rollback is repaired rather
# than fatal. The per-row evidence, the listings and the referrers are in
# port/slice_unmatch2.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_unmatch2.txt" SLICE_UNMATCH2_LINES)
set(SLICE_UNMATCH2_SOURCES "")
foreach(line IN LISTS SLICE_UNMATCH2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_UNMATCH2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tunmatch2 walk_window walk_window_hires smoke_player)
    target_sources(${_tunmatch2} PRIVATE ${SLICE_UNMATCH2_SOURCES}
                   "${CMAKE_CURRENT_SOURCE_DIR}/hal/unmatch_aliases.cpp")
endforeach()

# ===========================================================================
# LANE FOLD2, batch 1: the ov006 minigame host copies the unfold retired
# ===========================================================================
#
# Nine host copies whose ONLY stated reason was the MSVC destructor fold. Lane
# SLOT5F respelled the ROM's D1/D0 pair as two plain virtuals under _MSC_VER in
# include/ModelBase.h and its five siblings, so the host's model-family tables
# are ROM-numbered again: index 3 is UpdateVerts and index 5 is Render on
# _ZTV5Model, _ZTV9ModelAnim, _ZTV10ModelAnim2 and _ZTV14BlendModelAnim, which
# is what config/arm9/relocs.txt says the ROM's own four tables hold at
# 0x0208e90c, 0x0208e980, 0x0208e9b4 and 0x0208e94c. Every one of these matched
# sources dispatches a model member through a LOCAL shadow class counted in ROM
# numbering, so all nine now reach the body their source means.
#
# NO FILL SITE CHANGES AND NO FACE IS ADDED. All nine ROM bodies are
# address-named ov006 functions whose matched sources define them at C linkage
# under the exact name their callers use, so there is nothing to bridge.
#
# THREE of the nine are NOT in this list. They carry a second, still-live
# difference from src -- a raw store into the DS I/O window at 0x040004c8 /
# 0x040004cc, the geometry engine's LIGHT_VECTOR and LIGHT_COLOR -- and the
# port already owns the answer to that: tools/hostgen.py's MMIO_DEREF rewrite,
# the mechanism gate 4a, gate 4b, gate 6 and Animation::Advance all use. They
# build from ${CMAKE_BINARY_DIR}/host-src through the FOLD2 hostgen block at
# the very bottom of this file. hostgen's rewrite on all three is the MMIO
# substitution and nothing else, diffed line by line against src/ first.
#
# The per-row referrer (an arm_call address in ov006, or the ROM vtable word),
# the kind:function(arm,size=..) record and the first three ARM words of each
# body are in port/slice_fold2.txt, together with the ONE ov006 row of the ten
# that stays: MgSnowball_ModelRender.cpp, whose source reads the vtable word by
# hand and calls it CDECL against a __fastcall face. That is a receiver
# convention, not the fold, and its repair is a VIRTUAL_CALL row in
# port/tools/hostgen.py, which this lane does not own.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_fold2.txt" SLICE_FOLD2_LINES)
set(SLICE_FOLD2_SOURCES "")
foreach(line IN LISTS SLICE_FOLD2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_FOLD2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# BATCH 2 (the same gate, one wave on): fifteen more host copies in
# port/unmatched whose only stated reason was the fold, carrying SIXTEEN matched
# TUs -- unmatched/Ov060_Renders.cpp held two bodies. Ten of the sixteen fill
# sites call the ROM's Itanium name at C linkage while the matched source
# defines a __thiscall METHOD, so hal/fold2_faces.cpp defines that C name onto
# the method, one cdecl line each, and NOT ONE FILL SITE CHANGES. The other six
# need nothing: five matched sources already define the C name themselves and
# Eyerok's fill calls the C++ method directly. The per-row vtable word, the
# kind:function(arm,size=..) record and the ARM prologue are in
# hal/fold2_faces.cpp's header and in port/slice_fold2.txt.
list(APPEND SLICE_FOLD2_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/fold2_faces.cpp")
foreach(_tfold2 walk_window walk_window_hires smoke_player)
    target_sources(${_tfold2} PRIVATE ${SLICE_FOLD2_SOURCES})
endforeach()

# ===========================================================================
# LANE EXCEPT, batch 1: two rows off the documented host-ABI exception queue
# ===========================================================================
#
# The census these came from is out/EXCEPT/census.md in the run directory:
# every one of the 414 rows `port/tools/linkage.py --exceptions` prints,
# grouped by the mechanism its own header states. 209 of them are not port
# work at any price (ARM assembly, unmodelled DS hardware, register
# ride-throughs the decomp has to declare, MSVC refusals on the matched TU's
# own text). These two are the cheapest that are.
#
#   src/_ZN8daDemo_c10anmModel_cD0Ev.cpp   was unmatched/Ov002_ModelAnimD0_020f6778.cpp
#       The cutscene ModelAnim's deleting destructor. Unblocked by seating
#       _ZTV15TextureSequence[1] -- the slot the ROM fills with
#       _ZN15TextureSequenceD0Ev and the host left null -- with a CDECL thunk
#       in hal/model_dtor_seat.cpp. Referrer: data_ov002_0210bcc4[1], the
#       CUTSCENE_OBJECT ModelAnim vtable's own ROM slot 1, which
#       hal/actor_classes_intro.cpp already checks the mount against.
#
#   src/_ZN15dScMgSnowball_c6RenderEv.cpp     was unmatched/MgSnowball_ModelRender.cpp
#       NOT in this list -- it builds through tools/hostgen.py, so it is in
#       the LANE EXCEPT hostgen block at the very bottom of this file for the
#       same reason lane FOLD2's identical block is down there.
#
# NO FILL SITE CHANGES AND NO FACE. Both ROM bodies are address-named C
# functions the matched sources define under the exact name their callers
# already use.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_except.txt" SLICE_EXCEPT_LINES)
set(SLICE_EXCEPT_SOURCES "")
foreach(line IN LISTS SLICE_EXCEPT_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_EXCEPT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_texcept walk_window walk_window_hires smoke_player)
    target_sources(${_texcept} PRIVATE ${SLICE_EXCEPT_SOURCES})
endforeach()

# ===========================================================================
# LANE EXCEPT, batch 2: the slot-5 family, seventeen Renders
# ===========================================================================
#
# Seventeen matched Render TUs across sixteen actor classes whose documented
# host-ABI reason is a vtable numbering THAT NO LONGER EXISTS. Lane SLOT5F
# respelled the ROM's destructor pair under _MSC_VER in include/ModelBase.h,
# so hal/cxxname_bridge.cpp fills index 5 of _ZTV5Model, _ZTV9ModelAnim and
# _ZTV10ModelAnim2 with Render again, and every one of these matched sources
# -- each dispatching through a local six-virtual shadow counted in ROM
# numbering -- reaches the body it means.
#
# LANE UNMATCH'S FOLD SWEEP DID NOT LIST THEM, and the reason is not in the
# evidence: six of these files satisfy that enumeration's own stated rule by
# the letter (they carry both `HOST COPY OF` and the unhyphenated `slot 5` in
# their first 4 KB) and were still not on its list of thirty. An enumeration is
# not a census; port/slice_except2.txt and out/EXCEPT/census.md carry the
# counts.
#
# Sixteen of the seventeen matched sources are `real C++ method` recoveries,
# so hal/except_faces.cpp defines the Itanium C name each fill site calls onto
# the __thiscall method, one cdecl line each, and NOT ONE FILL SITE CHANGES.
# src/_ZN7Tornado6RenderEv.cpp defines the C name itself and needs no face.
#
# Every row's referrer is the class's own vtable slot 9 word read out of the
# RAW overlay image at that overlay's .text base, and every destination has a
# kind:function(arm,size=..) record: seventeen of seventeen agreed, and the
# generator refuses a mismatch. The table is port/slice_except2.txt.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_except2.txt" SLICE_EXCEPT2_LINES)
set(SLICE_EXCEPT2_SOURCES "")
foreach(line IN LISTS SLICE_EXCEPT2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_EXCEPT2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_EXCEPT2_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/except_faces.cpp")
foreach(_texcept2 walk_window walk_window_hires smoke_player)
    target_sources(${_texcept2} PRIVATE ${SLICE_EXCEPT2_SOURCES})
endforeach()

# ===========================================================================
# LANE FACEF: the calling-convention-face rows (family F + family E leftovers)
# ===========================================================================
#
# out/EXCEPT/census.md ranked the port's 414 documented host-ABI exceptions by
# the mechanism each row's own tag states, and left family F -- "calling-
# convention face through a raw vtable word", 19 rows -- plus twelve family E
# slot-5 rows that carried a NAMED SECOND REASON, for a later lane. This is
# that lane. Every row was re-derived from the ROM one at a time: the referrer
# is the class's own vtable slot 9 word read out of the RAW overlay image (with
# the RTTI name string at vtable-4, so the table is identified by what the ROM
# calls it), or the arm_call row in that overlay's relocs.txt for a body the
# ROM calls directly; the destination carries a kind:function(arm,size=..)
# record; and the matched TU's one dispatch instruction was read at its own
# address. The table, per row, is port/slice_facef.txt.
#
# A matched source that recovered as a real C++ method needs a cdecl face for
# the Itanium C name its fill site calls (hal/except_faces.cpp, appended to
# lane EXCEPT's own file because it is the same mechanism); a matched source
# that defines the plain C name itself needs nothing. NOT ONE FILL SITE
# CHANGES in either case.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_facef.txt" SLICE_FACEF_LINES)
set(SLICE_FACEF_SOURCES "")
foreach(line IN LISTS SLICE_FACEF_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_FACEF_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tfacef walk_window walk_window_hires smoke_player)
    target_sources(${_tfacef} PRIVATE ${SLICE_FACEF_SOURCES} ${TTE_HOSTGEN_GEN})
endforeach()

# ===========================================================================
# R10a, run link100 lane PMFB2: THE SEATED-TABLE ROWS
# ===========================================================================
#
# Rows that were host-copied only because the DATA under them held a DS code
# word, taken off their host copies once a boot-time installer puts a host
# address there. Nothing in this block changes a ROM reference, a linker
# option or a call the ROM does not make; the per-row derivation, the ROM
# stride and the emitted stride are in port/slice_pmfb2.txt.
#
# THE /Zp4 IS LANE PMFB1's BLOCK R9d LEVER, CARRIED. PMFB1 found that MSVC
# gives any struct CONTAINING a pointer-to-member an alignment of eight, which
# rounded eleven twenty-byte ROM records up to twenty-four and would have made
# every state after state 0 read the wrong record, silently. Every TU listed
# here had its ROM stride re-derived out of the overlay image and its emitted
# stride read off a /FAsc listing for THIS lane, and the option is on the set
# whether or not it moves that TU today, so that a later header edit cannot
# reintroduce the defect without the measurement being redone.
#
# WHICH TUs IN THIS BLOCK THE OPTION ACTUALLY MOVES, measured one at a time:
#   src/_ZN16dPathLiftActor_c12BaseBehaviorEv.cpp   24 -> 20, and the ROM strides 20.
#       Its record is {char pad[8]; PLFn fn; char tail[4]} -- a struct that
#       CONTAINS a pointer-to-member, which is PMFB1's exact case.
#   the two ov006 rows                     8 either way; their record is two
#       plain ints, so the listings are identical but for the TITLE line.
# The other three batch-3 rows are NOT on this list at all: their tables are
# arrays of the bare pointer-to-member, which is eight bytes with or without
# the option, and adding it would be a claim nothing measured.
# lane CDEFS 2026-09-16: dScMgSound_c.cpp was listed here AND in a later
# set_source_files_properties() for COMPILE_OPTIONS. That later call REPLACES
# this one (the property is set, not appended), so this row never reached
# the compiler for that TU. Removed from this row only; the other sources
# in the row keep it, and the surviving row for dScMgSound_c.cpp is unchanged.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN16dPathLiftActor_c12BaseBehaviorEv.cpp"
    PROPERTIES COMPILE_OPTIONS "/Zp4")
# dScMgSound_c.cpp also carries a fall-off-the-end body (dScMgSound_c::Virtual50),
# so it takes /wd4716 as well -- in THIS row, because COMPILE_OPTIONS is one
# property and a second set_source_files_properties would drop the /Zp4 above.
# The block at the end of this file explains the option.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/dScMgSound_c.cpp"
    # and the generated copy, lane DUPES: this TU is on PORT_HOSTGEN_TU
    # now, so the raw path alone would set the property on a source
    # nothing compiles.
    "${CMAKE_BINARY_DIR}/host-src/src/actors/dScMgSound_c.cpp"
    PROPERTIES COMPILE_OPTIONS "/Zp4;/wd4716")
# src/func_ov002_020aea30.cpp is a //cpp-marked .c: its own text spells
# `typedef void (C::*PMF)(int, int);`, which is not C. The tree's standing
# treatment for that is LANGUAGE CXX on the source, and this is one more of
# them.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov002_020aea30.cpp"
    PROPERTIES LANGUAGE CXX)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pmfb2.txt" SLICE_PMFB2_LINES)
set(SLICE_PMFB2_SOURCES "")
foreach(line IN LISTS SLICE_PMFB2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PMFB2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tpmfb2 walk_window walk_window_hires smoke_player)
    target_sources(${_tpmfb2} PRIVATE ${SLICE_PMFB2_SOURCES})
endforeach()

# ===========================================================================
# R10b, run link100 lane PMFB3: dScMgSound_c's THIRTEEN LEVEL-2 DISPATCHERS
# ===========================================================================
#
# The rows block R10a's own text left for the next lane: "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." Lane PMFB3
# extended port_mg_sound_states_seat (port/unmatched/MgSound_StateDispatch.cpp)
# to the thirty-nine level-2 slots, so all fifteen of this class's tables now
# hold host addresses installed at boot, every one of them compared against the
# ROM's own code word and a zero adjustment word before it is written, and no
# host copy of a dScMgSound_c dispatcher is left. Nothing here changes a ROM
# reference, a linker option or a call the ROM does not make; the per-row
# derivation, the ROM stride and the emitted stride are in
# port/slice_pmfb3.txt.
#
# NO /Zp4 ON THIS BLOCK, and that is the measurement and not an omission. Block
# R10a carries lane PMFB1's lever because a record that is a struct CONTAINING a
# pointer to member gets eight-byte alignment from MSVC and silently strides
# twenty-four where the ROM strides twenty. Each of these thirteen tables is an
# array of the BARE pointer to member, which is eight bytes either way: every one
# of the thirteen TUs was compiled both ways for this lane and the two /FAsc
# listings came back byte-identical, zero diff lines, with the operand
# _data_ov006_XXXXXXXX[eax*8] against the ROM's own `add ip, r3, r2, lsl #3`.
# R10a's own rule for exactly that case is to leave the option off rather than
# make a claim nothing measured, and this block follows it.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pmfb3.txt" SLICE_PMFB3_LINES)
set(SLICE_PMFB3_SOURCES "")
foreach(line IN LISTS SLICE_PMFB3_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PMFB3_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tpmfb3 walk_window walk_window_hires smoke_player)
    target_sources(${_tpmfb3} PRIVATE ${SLICE_PMFB3_SOURCES})
endforeach()

# ===========================================================================
# R10c, run link100 lane PMFB4: THE CALL-SHAPE ROWS OVER UNSEATED TABLES
# ===========================================================================
#
# Blocks R10a and R10b took the family-C rows whose table already had an
# installing seat, and then the rest of one class's tables one level down. This
# block takes rows whose table had NO seat at all: each one needs the boot
# installer written first, in the file that owns the table, and then the host
# copy comes off. Nothing here changes a ROM reference, a linker option or a
# call the ROM does not make; the per-row ROM stride, emitted stride, source
# pairs, dispatch shape and alias spelling are in port/slice_pmfb4.txt and the
# raw measurements in runs/link100/out/PMFB4/.
#
# NO /Zp4 ON THIS BLOCK, and it is measured per TU rather than inherited. R10a
# carries lane PMFB1's lever because MSVC gives any struct CONTAINING a pointer
# to member eight-byte alignment, which silently strides twenty-four where the
# ROM strides twenty. Every TU in this block was compiled under the port's own
# flags with and without the option for this lane, and each pair of /FAsc
# listings came back identical except for the TITLE line naming the .obj -- the
# tables are arrays of the bare pointer to member or of a one-member Entry
# wrapping one, eight bytes either way, against the ROM's own
# `add r3, rTable, rIndex, lsl #3`. R10a's rule for that case is to leave the
# option off rather than make a claim nothing measured.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pmfb4.txt" SLICE_PMFB4_LINES)
set(SLICE_PMFB4_SOURCES "")
foreach(line IN LISTS SLICE_PMFB4_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PMFB4_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tpmfb4 walk_window walk_window_hires smoke_player)
    target_sources(${_tpmfb4} PRIVATE ${SLICE_PMFB4_SOURCES})
endforeach()

# ===========================================================================
# R10d, run link100 lane MGWRITER: THE OBJECT-FIELD ROWS AND THEIR WRITER
# ===========================================================================
#
# Blocks R10a, R10b and R10c took rows that read a TABLE. This block takes rows
# that read an OBJECT FIELD: there is no table for a boot installer to verify
# and rewrite, so what the installer seats is the SOURCE the writer copies from,
# and the field carries a host word from the moment the writer runs. Four of the
# six rows lane PMFB3 measured and left, plus the writer that fills two of the
# fields, come off their host copies here. Nothing in this block changes a ROM
# reference, a linker option or a call the ROM does not make; the per-row ROM
# disassembly, emitted dispatch shape, source pairs, sweep and alias spelling
# are in port/slice_mgwriter.txt and the raw measurements in
# runs/link100/out/MGWRITER/.
#
# NO /Zp4 ON THIS BLOCK, measured per TU rather than inherited. R10a carries
# lane PMFB1's lever because MSVC gives any struct CONTAINING a pointer to
# member eight-byte alignment, which silently strides twenty-four where the ROM
# strides twenty. Four of these five TUs hold the pointer to member as a FIELD
# rather than in a table, and the fifth reads an array of the bare pointer to
# member; every one was compiled under the port's own flags with and without the
# option for this lane and each pair of /FAsc listings came back identical
# except for the TITLE line naming the .obj. R10a's rule for that case is to
# leave the option off rather than make a claim nothing measured.
#
# WHAT MAKES THE FOUR FIELD ROWS COMPILE AT ALL is block R8's /vmg /vmm on the
# whole target: their src structs put a state word after a pointer to member and
# the ROM reads it at +0x20, which is only true at the ROM's own eight-byte
# member pointer. The four emitted field offsets (+0x0c, +0x04, +0x14, +0x0c)
# agree with the ROM's own word for word, so the structs are right and the old
# note in unmatched/MgBase_StateDispatch.cpp about a four-byte member pointer
# moving every later field is a premise that expired when R8 landed.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_mgwriter.txt" SLICE_MGWRITER_LINES)
set(SLICE_MGWRITER_SOURCES "")
foreach(line IN LISTS SLICE_MGWRITER_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_MGWRITER_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tmgw walk_window walk_window_hires smoke_player)
    target_sources(${_tmgw} PRIVATE ${SLICE_MGWRITER_SOURCES})
endforeach()

# ===========================================================================
# R10d, run link100 lane PMFB5: THE REMAINING SINGLE-ROW TABLES
# ===========================================================================
#
# Block R10c took the call-shape rows whose table had no seat, grouped by the
# file that owns several tables at once. This block takes what it left: the
# tables that carry exactly ONE dispatching row each, so every one needs its own
# boot installer written in the file that owns it before the host copy can come
# off. Nothing here changes a ROM reference, a linker option or a call the ROM
# does not make; the per-row ROM stride, emitted stride, source pairs, dispatch
# shape, alias spelling and the four rows this lane REFUSED are in
# port/slice_pmfb5.txt and the raw measurements in runs/link100/out/PMFB5/.
#
# NO /Zp4 ON THIS BLOCK, and it is measured per TU rather than inherited, for
# the reason R10a and R10c both give: MSVC gives any struct CONTAINING a pointer
# to member eight-byte alignment, which silently strides twenty-four where the
# ROM strides twenty. Every TU in this block was compiled under the port's own
# flags with and without the option for this lane, and each pair of /FAsc
# listings came back identical except for the TITLE line naming the .obj --
# these tables are arrays of the bare pointer to member or of a one-member Entry
# wrapping one, eight bytes either way, against the ROM's own
# `add r3, rTable, rIndex, lsl #3`. R10a's rule for that case is to leave the
# option off rather than make a claim nothing measured.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pmfb5.txt" SLICE_PMFB5_LINES)
set(SLICE_PMFB5_SOURCES "")
foreach(line IN LISTS SLICE_PMFB5_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PMFB5_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tpmfb5 walk_window walk_window_hires smoke_player)
    target_sources(${_tpmfb5} PRIVATE ${SLICE_PMFB5_SOURCES})
endforeach()

# ===========================================================================
# R10e, run link100 lane FWD: THE MEMBER-DEFINING Behavior ROWS
# ===========================================================================
#
# Blocks R10a through R10d took rows whose matched TU defines the FLAT C symbol
# the port's face calls. This block takes the nine that do not: their matched
# TU defines a real C++ MEMBER (`int BowserFire::Behavior()`), which MSVC
# decorates ?Behavior@BowserFire@@QAEHXZ and calls __thiscall, while the port's
# actor-class face calls the flat name with the receiver on the stack. Two
# symbols, two conventions; an /alternatename cannot bridge them and lane PMFB5
# paid a link to establish it. The bridge is port/hal/fwd_forwarders.cpp, one
# forwarder per class in the flat name's own convention, and it rides this
# block's slice file so the forwarders and the TUs they reach land together.
# Nothing here changes a ROM reference, a linker option or a call the ROM does
# not make. The per-row ROM stride, emitted stride, arity, source pairs, config
# span and alias spelling are in port/slice_fwd.txt and the raw measurements in
# runs/link100/out/FWD/.
#
# NO /Zp4 ON THIS BLOCK, measured per TU rather than inherited, for the reason
# R10a, R10c and R10d all give. Every one of these nine TUs was compiled under
# the port's own flags with and without the option for this lane and each pair
# of /FAsc listings came back identical outside the TITLE line naming the .obj.
# R10a's rule for that case is to leave the option off rather than make a claim
# nothing measured.
# GATE 2. src/_ZN12MetalNetLift8BehaviorEv.cpp is a //cpp-marked .c whose own text spells
# `typedef void (C::*PMF)();`, which is not C. The tree's standing treatment for
# that is LANGUAGE CXX on the source (lane PMFB2 did it for
# src/func_ov002_020aea30.cpp), and this is one more of them.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN12MetalNetLift8BehaviorEv.cpp"
    PROPERTIES LANGUAGE CXX)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_fwd.txt" SLICE_FWD_LINES)
set(SLICE_FWD_SOURCES "")
foreach(line IN LISTS SLICE_FWD_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_FWD_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tfwd walk_window walk_window_hires smoke_player)
    target_sources(${_tfwd} PRIVATE ${SLICE_FWD_SOURCES})
endforeach()

# ===========================================================================
# R10f, run link100 lane PMFB6: THE TEN CUTSCENE_OBJECT STATE DISPATCHERS
# ===========================================================================
#
# port/hal/cutscene_states_link100.cpp hosted all ten readers of
# CUTSCENE_OBJECT's ten pointer-to-member state tables as an ADDRESS SWITCH,
# because lane TAIL2 measured in wave 1 that MSVC forms a pointer-to-member
# over an incomplete class as the four-word GENERAL representation. Block R8
# above turns /vmg /vmm on for every C++ source in this target and that stopped
# being true; re-measured for this block on all ten readers' own /FAsc
# listings, the emitted operand is [reg*8] and [reg*8+4] -- the two words of one
# ROM record. The file is now the SEAT over the sixty-nine source records
# __sinit_ov002_02107370 copies into the ten tables, one __fastcall face per
# CELL, and the ten readers are the decomp's own TUs in the slice below.
#
# NO /Zp4 ON THIS BLOCK, measured per TU rather than inherited, for the reason
# R10a gives. Every one of the ten was compiled under the port's own flags with
# and without the option and each pair of listings came back identical outside
# the TITLE line naming the .obj.
#
# The per-row ROM read, emitted operand, arity, source records and reference
# sweep are in port/slice_pmfb6.txt and in that host file's header; the raw
# measurements are in runs/link100/out/PMFB6/.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pmfb6.txt" SLICE_PMFB6_LINES)
set(SLICE_PMFB6_SOURCES "")
foreach(line IN LISTS SLICE_PMFB6_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PMFB6_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# GATE 3. /Zp4 ON ONE SOURCE, MEASURED AND NOT INHERITED.
# src/actors/dMgJump3DMario_c.cpp spells `struct C { char pad[0x3c]; PMF m; };` and
# the ROM's field is at +0x3c. MSVC aligns an eight-byte member to eight, so
# without /Zp4 the TU reads [edi+64] and [edi+68] -- FOUR BYTES LATE -- and with
# it the same listing reads [edi+60] and [edi+64], the ROM's own offsets. Those
# two instructions are the ONLY difference between the two /FAsc listings
# (runs/link100/out/PMFB6/emit_gate3_out.txt). The other two gate-3 rows were
# compiled both ways and their listings are identical outside the TITLE, so the
# option is claimed on this ONE source and on nothing else -- the treatment lane
# MGWRITER named for func_ov006_020c07e8, measured here rather than inherited.
#
# BOTH PATHS, run link100 lane HOSTGEN4: this TU joined PORT_HOSTGEN_TU for its
# nine decorated ROM data rows, so the compile the build actually runs is the
# generated copy under build/port/host-src. /Zp4 is the pack that puts the PMF
# at the ROM's +0x3c; naming only the src/ row would leave the generated copy
# reading four bytes late, which is the exact drift the check near line 380
# refuses. The src/ row is kept so the property is still right if the
# substitution is ever retired.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/actors/dMgJump3DMario_c.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/actors/dMgJump3DMario_c.cpp"
    PROPERTIES COMPILE_OPTIONS "/Zp4")
foreach(_tpmfb6 walk_window walk_window_hires smoke_player)
    target_sources(${_tpmfb6} PRIVATE ${SLICE_PMFB6_SOURCES})
endforeach()

# ===========================================================================
# THE WIRELESS PLAN, RUNG W0 (run link100, lane WM1)
# ===========================================================================
#
# src/func_02040714.c and src/func_02040704.c: the two bodies of the radio seam
# that touch no radio. Each is one global read, and both globals are hosted --
# both data_020a0f94 and data_020a0f24 by
# hal/comms_seam.cpp, which is also where the two host faces of these names are
# DELETED by the same commit. The reasoning, the ABI ruling and the freshness
# argument for the two words are in port/slice_wm1.txt and in
# comms_publish_link_words' banner in hal/comms_seam.cpp.
#
# Plain C, no per-source properties: neither TU has a struct, a pointer-to-member
# or a packed field for an option to argue with.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_wm1.txt" SLICE_WM1_LINES)
set(SLICE_WM1_SOURCES "")
foreach(line IN LISTS SLICE_WM1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_WM1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_twm1 walk_window walk_window_hires smoke_player)
    target_sources(${_twm1} PRIVATE ${SLICE_WM1_SOURCES})
endforeach()
# AND THE SEAM PROBE, which is where this rung's first link error came from.
# Unlike the gate-221 rows above, mp_comms_seam DOES reference these two:
# tests/mp_comms_seam.cpp declares func_02040714 and func_02040704 at :84-85 and
# asserts their solo answers at :148-149. It links hal/comms_seam.cpp -- the file
# the two host faces were deleted from -- so a probe that loses the faces without
# gaining the bodies does not link. That is the same rule gate 221's note states,
# applied the other way round. (Its OTHER unresolved symbol, data_020a0f94, is
# why that word moved out of hal/comms_conductor.cpp, which this probe does not
# link, and into hal/comms_seam.cpp, which it does.)
target_sources(mp_comms_seam PRIVATE ${SLICE_WM1_SOURCES})

# ===========================================================================
# THE WIRELESS PLAN, RUNG W1 (run link100, lane WM2)
# ===========================================================================
#
# src/func_020408b0.c and the eleven TUs its closure reaches: the ROM's own WM
# bring-up, up to and including WM_Init registering the ARM9's channel-0xa
# reply handler. The ARM7 answers nothing on this rung and nothing asks it to;
# the whole argument, the measured closure and the two things that had to move
# in the port are in port/slice_wm2.txt's own header.
#
# Plain C, no per-source properties: no struct layout option, no
# pointer-to-member and no packed field in any of the twelve.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_wm2.txt" SLICE_WM2_LINES)
set(SLICE_WM2_SOURCES "")
foreach(line IN LISTS SLICE_WM2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_WM2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_twm2 walk_window walk_window_hires smoke_player)
    target_sources(${_twm2} PRIVATE ${SLICE_WM2_SOURCES})
endforeach()
# AND NOT THE SEAM PROBE, which is the opposite of what rung W0 needed and for
# the same reason stated the other way round. tests/mp_comms_seam.cpp calls
# func_020408b0(2) at :147 to check the seam's SOLO answers, and the ROM body of
# that name allocates eight buffers off the game heap through Memory::Allocate.
# The probe links neither a heap nor Memory::Allocate nor anything else in the
# twelve TUs' closure, so giving it the bodies is a wall of unresolved externals
# and, if they were supplied, a null dereference in a probe whose whole point is
# that it needs no world. It keeps the retired host face instead, under a define
# of its own -- exactly the way mp_sleepwake and this probe keep the retired
# OS_SleepThread/OS_WakeupThread pair alive under PORT_OS_THREAD_HOST_PAIR: a
# retired stand-in stays reachable WHERE IT IS MEASURED and nowhere else. The
# same define also compiles out hal/comms_seam.cpp's call into the host ARM7,
# which the probe does not link either.
target_compile_definitions(mp_comms_seam PRIVATE
    PORT_COMMS_SEAM_PROBE_FACE_020408B0)

# SLICE pmfb7 -- run link100 lane PMFB7: the object-field rows whose class-block
# range sweep closes. Twelve matched Behaviors that dispatch a pointer to member
# held in a per-instance field, one per state cell at +8. No /Zp4 on this block:
# the member sits at offset 8 of its holder and the two listings are identical
# outside the TITLE line on all twelve. The per-row universe, ROM read, emitted
# shape and the enter/per-frame split are in port/slice_pmfb7.txt and the raw
# measurements in runs/link100/out/PMFB7/.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pmfb7.txt" SLICE_PMFB7_LINES)
set(SLICE_PMFB7_SOURCES "")
foreach(line IN LISTS SLICE_PMFB7_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PMFB7_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# GATE 3. /Zp4 ON TWO SOURCES, MEASURED PER SOURCE AND NOT INHERITED.
# src/minigames/d_s_mg_trampoline2.cpp and src/_ZN11dScMgJump_c8BehaviorEv.cpp both hold their
# member pointer at the ROM's 0x5004, which is 4 mod 8, and MSVC aligns the
# eight-byte member to eight: without the option they read [reg+20488] and
# [reg+20492], FOUR BYTES LATE, and with it [reg+20484] and [reg+20488], the
# ROM's own 0x5004/0x5008. Four listing lines differ on each and nothing else
# (runs/link100/out/PMFB7/emit_gate3_out.txt). src/minigames/d_s_mg_jump2.cpp is at
# the SAME ROM offset and does NOT need it -- its struct comes from the tree's
# own dScMgJump2_c.h and MSVC already lays the member at 0x5004, 0 diff lines --
# which is why the option is measured per source rather than predicted from the
# offset alone. src/_ZN15dMg3DEspModel_c8BehaviorEv.cpp is at 0x210, 0 mod 8, 0 diff lines.
# REPAIRED 2026-09-13 (lane SYNC3). src/minigames/d_s_mg_trampoline2.cpp has
# been substituted by its hostgen copy since lane SYNC2 widened the TTE
# substitution to the whole TU, so this row named a file no target compiles and
# the packing option stopped applying without any diagnostic. The measurement
# above is about the member at 0x5004 and it is the generated copy that has to
# carry it, so the generated path is named here too.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/minigames/d_s_mg_trampoline2.cpp"
    "${CMAKE_BINARY_DIR}/host-src/src/minigames/d_s_mg_trampoline2.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN11dScMgJump_c8BehaviorEv.cpp"
    PROPERTIES COMPILE_OPTIONS "/Zp4")
foreach(_tpmfb7 walk_window walk_window_hires smoke_player)
    target_sources(${_tpmfb7} PRIVATE ${SLICE_PMFB7_SOURCES} ${BNT_HOSTGEN_GEN} ${TTE_HOSTGEN_GEN})
endforeach()

# SLICE pmfb8 -- run link100 lane PMFB8: the rows lane PMFB7 measured and left
# on the clock. GATE 1 is src/func_ov055_021112c4.cpp, MirrorLuigi's ENTER
# dispatcher: an ARITY-ONE field-held pointer-to-member row whose class-derived
# block sweeps to exactly two {code,0} pairs with no by-value sentinel. NO /Zp4
# on this block, measured rather than inherited: the member sits at offset 0 of
# its record and the two /FAsc listings are identical outside the TITLE line.
# The per-row universe, ROM read, emitted shape, arity and second-reader
# measurement are in port/slice_pmfb8.txt and the raw measurements in
# runs/link100/out/PMFB8/.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_pmfb8.txt" SLICE_PMFB8_LINES)
set(SLICE_PMFB8_SOURCES "")
foreach(line IN LISTS SLICE_PMFB8_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_PMFB8_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# GATE 3. /Zp4 ON ONE SOURCE, MEASURED ON THAT SOURCE AND NOT INHERITED.
# src/func_ov006_020c07e8.cpp holds its member pointer at the ROM's 0xb4, which
# is 4 mod 8, and MSVC aligns the eight-byte member to eight: without the option
# it emits mov ecx,[esi+188] / mov eax,[esi+184] -- 0xbc and 0xb8, FOUR BYTES
# LATE -- and with it mov ecx,[esi+184] / mov eax,[esi+180], the ROM's own
# 0xb8/0xb4. Sixteen listing lines differ and nothing else
# (runs/link100/out/PMFB8/emit_g3_out.txt). The gate-1 and gate-2 sources are
# all 0 mod 8 at their holders and are measured to need nothing, which is why
# this is one file and not the block.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_ov006_020c07e8.cpp"
    PROPERTIES COMPILE_OPTIONS "/Zp4")
foreach(_tpmfb8 walk_window walk_window_hires smoke_player)
    target_sources(${_tpmfb8} PRIVATE ${SLICE_PMFB8_SOURCES})
endforeach()

# SLICE seat5 -- run link100 wave 7, lane SEAT5: census batch B5, the family-C
# pointer-to-member rows outside ov006 that no prior lane had scouted. THREE
# rows land here: _ZN5Unagi8BehaviorEv (ov016, a per-instance field, five bss
# state cells), func_ov102_021498e0 (ov102, two bss content tables) and
# _ZN11MirrorLuigi8BehaviorEv (ov055, one cell, the ARITY-ONE one). The first
# two are ARITY ZERO with the receiver in ecx and nothing pushed; MirrorLuigi
# pushes the one word its face never pops. All three read their
# pair at the ROM's own stride of EIGHT, which is what /vmg /vmm (block R8)
# makes an incomplete-class pointer to member. NO /Zp4 on this block, measured
# on both sources rather than inherited: 0 listing lines differ outside the
# TITLE (Unagi's member sits at offset 8 of its holder, the ov102 tables are
# indexed by the compiler's own lsl #5 / lsl #3). The per-row universe proof,
# the sentinel check, the emitted shape and the four rows this lane did NOT
# seat are in port/slice_seat5.txt and the raw measurements in
# runs/link100/out/SEAT5/. port/hal/pmf_seat5.cpp rides on the same list: it
# carries the flat C name for Unagi's matched C++ member and the three
# C++-linkage data spellings the two TUs need.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_seat5.txt" SLICE_SEAT5_LINES)
set(SLICE_SEAT5_SOURCES "")
foreach(line IN LISTS SLICE_SEAT5_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SEAT5_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tseat5 walk_window walk_window_hires smoke_player)
    target_sources(${_tseat5} PRIVATE ${SLICE_SEAT5_SOURCES})
endforeach()

# SLICE seat4 -- run link100 lane SEAT4, census batch B4 OV006-PMF-SWEEP: the
# eighteen ov006 state-table dispatchers whose eight-byte mwcc {code, adjust}
# pairs were host-copied. Their nineteen tables are seated in
# port/hal/pmf_seat4.cpp, added to the same three targets below, from inside the
# per-class installers hal/scene_mg.cpp already calls at overlay load -- so no
# new call site, and the seat order the tree already establishes is the one the
# tables get. The per-class universe proof (every cell filled from slot 0, no
# gap, every ROM pair {code, 0}, every source record referenced exactly once and
# only by its own class sinit, every table reachable from exactly two places),
# the emitted side of each dispatcher read off its own /FAsc listing, and the
# reason two of the eighteen tail-jump and one takes cdecl faces are all in
# port/slice_seat4.txt; the raw measurements are in runs/link100/out/SEAT4/.
#
# NO /Zp4 ON THIS BLOCK, MEASURED AND NOT INHERITED. Lane PMFB6's rule is about
# a member pointer held in an object FIELD at an offset 4 mod 8. Every row here
# reads a TABLE, and all eighteen compile to the same listing with and without
# the option: zero lines differ outside the TITLE on every one of them
# (runs/link100/out/SEAT4/emit_tables.txt).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_seat4.txt" SLICE_SEAT4_LINES)
set(SLICE_SEAT4_SOURCES "")
foreach(line IN LISTS SLICE_SEAT4_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SEAT4_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tseat4 walk_window walk_window_hires smoke_player)
    target_sources(${_tseat4} PRIVATE ${SLICE_SEAT4_SOURCES}
                   "${CMAKE_CURRENT_SOURCE_DIR}/hal/pmf_seat4.cpp")
endforeach()

# ===========================================================================
# THE WIRELESS PLAN, RUNGS W4 AND W5 (run link100, lane WM3)
# ===========================================================================
#
# src/func_02040820.c and src/func_02040790.c -- the ROM's own become-parent and
# become-child state machines -- src/func_02040724.c (leave), and the 128 TUs
# their call closure reaches: the NITRO WM command layer, the game's own
# wireless framework and the 0x02065xxx work-queue band. The list, the measured
# closure, the three non-matched things it needed and what the host ARM7 does
# and does not fabricate are all in port/slice_wm3.txt's own header.
#
# THE ANSWERING HALF IS hal/wm_arm7.cpp, added to the same three targets right
# below. It goes exactly where hal/boot2_ipc.cpp goes and nowhere else: it is
# the other half of the same host ARM7, and mp_comms_seam links neither.
#
# Plain C except for four .cpp TUs the tree already carries as C++
# (func_02062aa4, func_02062bdc, func_02062d10, func_020627e8 and the others
# with a //cpp marker are picked up by the same LANGUAGE CXX rule every other
# slice uses); no struct layout option, no pointer-to-member, no packed field in
# any of the 131.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_wm3.txt" SLICE_WM3_LINES)
set(SLICE_WM3_SOURCES "")
foreach(line IN LISTS SLICE_WM3_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_WM3_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_twm3 walk_window walk_window_hires smoke_player)
    target_sources(${_twm3} PRIVATE ${SLICE_WM3_SOURCES}
                   "${CMAKE_CURRENT_SOURCE_DIR}/hal/wm_arm7.cpp")
endforeach()
# AND NOT THE SEAM PROBE, for the same reason rung W1 kept it out: tests/
# mp_comms_seam.cpp calls func_02040820, func_02040790 and func_02040724 at
# :159-167 to check the seam's SOLO answers, and it links neither the WM command
# layer, nor a heap, nor the host ARM7 that would have to answer the commands
# these bodies send. It keeps the three retired stand-ins instead, under a
# define of its own -- the same shape as PORT_COMMS_SEAM_PROBE_FACE_020408B0
# above and PORT_OS_THREAD_HOST_PAIR before it.
target_compile_definitions(mp_comms_seam PRIVATE
    PORT_COMMS_SEAM_PROBE_FACES_W4)

# ===========================================================================
# THE WIRELESS PLAN, RUNG W2 (run link100, lane WM4)
# ===========================================================================
#
# src/func_0204068c.c and src/func_02062778.c: the ROM's own MP receive
# unpacker. The list and the argument are in port/slice_wm4.txt's own header;
# the buffer they read is filled by hal/wm_arm7.cpp, which rung W4 already
# added to these same three targets right above.
#
# Plain C, two files, no struct layout option and no pointer-to-member.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_wm4.txt" SLICE_WM4_LINES)
set(SLICE_WM4_SOURCES "")
foreach(line IN LISTS SLICE_WM4_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_WM4_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_twm4 walk_window walk_window_hires smoke_player)
    target_sources(${_twm4} PRIVATE ${SLICE_WM4_SOURCES})
endforeach()
# AND NOT THE SEAM PROBE. tests/mp_comms_seam.cpp:155-156 checks that
# func_0204068c answers null for aids 0 and 1 with no transport installed, and
# it links neither this unpacker nor the host ARM7 that fills the buffer it
# reads, so it keeps the retired stand-in under a define of its own -- the same
# shape as the two above it.
target_compile_definitions(mp_comms_seam PRIVATE
    PORT_COMMS_SEAM_PROBE_FACE_0204068C)

# ===========================================================================
# THE WIRELESS PLAN, RUNG W6 (run link100, lane WM5)
# ===========================================================================
#
# src/func_02040c34.c -- the ROM's own wireless worker-thread bring-up -- and
# nineteen more from its call closure. The list, the eleven TUs it refuses and
# why, and the two rows that look like hardware and are not, are all in
# port/slice_wm5.txt's own header.
#
# THE STORAGE HALF IS hal/wm_thread.cpp, added to the same three targets below.
# It goes exactly where hal/wm_arm7.cpp goes and nowhere else: it carries the
# 0x2b80-byte work-area band, the four faces into the table band this rung
# refuses, and the worker-thread census, and mp_comms_seam links none of them.
#
# Plain C, twenty files, no struct layout option and no pointer-to-member.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_wm5.txt" SLICE_WM5_LINES)
set(SLICE_WM5_SOURCES "")
foreach(line IN LISTS SLICE_WM5_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_WM5_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
#
# TWO TARGETS, NOT THREE, AND THAT IS FORCED RATHER THAN CHOSEN. Rungs W1, W2
# and W4 went to all three; this one cannot. src/func_02042254.c (the worker
# body) and src/func_020424c0.c (the header-region reads) both call
# func_0205d5e8, which is on port/slice_gate214.txt, and SLICE214_SOURCES goes
# to walk_window and walk_window_hires only -- smoke_player has never carried
# the boot spine (see the SLICE214 note above). Measured, not assumed: the
# first build of this rung linked walk_window and walk_window_hires clean and
# failed smoke_player on exactly that one unresolved external.
foreach(_twm5 walk_window walk_window_hires)
    target_sources(${_twm5} PRIVATE ${SLICE_WM5_SOURCES}
                   "${CMAKE_CURRENT_SOURCE_DIR}/hal/wm_thread.cpp")
endforeach()
# AND THE OTHER TWO LINK hal/wm_thread_face.cpp INSTEAD. smoke_player for the
# reason just given, mp_comms_seam because it links hal/comms_seam.cpp without
# the WM command layer, without a heap and without the host ARM7. That file
# carries the retired func_02040c34 body, the standalone data_020a3fc0 those
# two still need (src/func_02040a5c.c and src/func_02040a84.c are on
# port/slice_gate221.txt, which does go to smoke_player), and no-op versions of
# the two census entry points hal/boot2_ipc.cpp calls on all three big targets.
#
# A PER-TARGET DEFINE ON hal/comms_seam.cpp COULD NOT HAVE DONE THIS, which is
# the one way this retirement differs in shape from rungs W1, W2 and W4: that
# file is compiled ONCE for all three big targets (SLICE_COMMS_SOURCES rides
# the sharing block below), so a define on smoke_player would have changed
# walk_window's object too. Rungs W1/W2/W4 only ever had to keep a body for
# mp_comms_seam, which compiles hal/comms_seam.cpp separately.
foreach(_twm5f mp_comms_seam smoke_player)
    target_sources(${_twm5f} PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/hal/wm_thread_face.cpp")
endforeach()

# ===========================================================================
# THE WIRELESS PLAN, RUNG W7 (run link100, lane WM8)
# ===========================================================================
#
# The eleven TUs of the 0x02063E-0x020655 message-layer band that rung W6 left
# behind four faces in hal/wm_thread.cpp. Why they were refused, why the
# refusal rested on a decimal misread, and what the band actually is are all in
# port/slice_wm8.txt's own header and at the top of hal/wm_thread.cpp.
#
# THE ACCESSOR RENAME, WHICH IS THE HALF THAT MAKES THE SLICE SAFE.
# src/func_02065b94.c and src/func_02065b88.c are matched ROM bodies that
# return DS addresses -- 0x020A94D4 and 0x020A9570, both named by a relocation
# in config/arm9/relocs.txt -- and the port hosts those two objects at the host
# addresses hal/wm_arm7.cpp's ".dsstate$ywmd18a" and "$ywmd19" land at. Left
# alone, the band would WRITE the cartridge's address (which is mapped DS main
# RAM in this process, so not a fault, just the wrong bytes) while
# src/func_02065af0.c READS the host object: one ROM object, two host objects.
#
# So every TU that CALLS one of the two accessors is compiled with that call
# renamed onto the host answer in hal/wm_arm7.cpp. The two ROM bodies keep
# their own names, their bytes and their place in the link; only the call sites
# move. This is the port's romdata pointer-table contract in its smallest form:
# a DS address the port cannot use is bound to the host object before anything
# dereferences it.
#
# NINE TUs, NOT FOUR, AND THAT IS THE POINT. Five of the nine came in with rung
# W4 on port/slice_wm3.txt and have been loading the literal ever since --
# src/func_02065170.c, src/func_020653cc.c, src/func_02065538.c and
# src/func_020659a0.c call func_02065b94, src/func_02065af0.c calls
# func_02065b88. None of them was ever ENTERED, because data_020a94c0 stays 0
# until one of the two initialisers rung W6 faced sets it. Renaming only the
# four TUs this slice adds would have left exactly the split object the rename
# exists to close, so all nine are renamed.
#
# THE RENAME IS A SOURCE PROPERTY, hence one define per file rather than a
# target_compile_definitions: these TUs ride the shared compile below (one
# object for walk_window, walk_window_hires and smoke_player), so a per-target
# define could not reach them. hal/wm_arm7.cpp, which defines the two answers,
# goes to exactly the three targets port/slice_wm3.txt goes to.
foreach(_wm8ren
        src/func_02065170.c src/func_020653cc.c src/func_02065538.c
        src/func_020659a0.c src/func_020652fc.c src/func_02065234.c
        src/func_020654d0.c src/func_02065500.c)
    set_source_files_properties(
        "${CMAKE_CURRENT_SOURCE_DIR}/../${_wm8ren}"
        PROPERTIES COMPILE_DEFINITIONS "func_02065b94=port_wm8_wmq_base")
endforeach()
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_02065af0.c"
    PROPERTIES COMPILE_DEFINITIONS "func_02065b88=port_wm8_wmq_head")

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_wm8.txt" SLICE_WM8_LINES)
set(SLICE_WM8_SOURCES "")
foreach(line IN LISTS SLICE_WM8_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_WM8_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# TWO TARGETS, NOT THREE, for the same forced reason rung W6 gave: the four
# bodies this slice takes back were faced in hal/wm_thread.cpp, which
# walk_window and walk_window_hires carry and the other two do not. Adding them
# to smoke_player would collide with hal/wm_thread_face.cpp's own stand-ins.
foreach(_twm8 walk_window walk_window_hires)
    target_sources(${_twm8} PRIVATE ${SLICE_WM8_SOURCES})
endforeach()

# ===========================================================================
# ONE COMPILE OF THE TIER-INDEPENDENT SLICE
# ===========================================================================
#
# THE PROBLEM. Three targets compile the whole matched slice: walk_window,
# walk_window_hires and smoke_player. Their command lines are byte-identical
# except for ONE define apiece -- NTR_WIDE_RT on the first (from ntr_wide_rt),
# NTR_HIRES on the second (from ntr_hires), neither on the third. So the build
# carried 32,716 compile edges over 10,276 distinct sources: a 3.2x duplicate
# compile, and most of the port's build was cl.exe producing three identical
# objects from one file.
#
# THE RULE. A translation unit can only differ between those three targets if a
# DIVERGENT MACRO -- one defined for some of them and not the others -- is
# visible in its include closure. Everything else compiles to the same bytes
# under all three and needs to be compiled once. In this tree the divergent set
# is NTR_WIDE_RT and NTR_HIRES, and only four files in the whole port mention
# either: ntr/include/ntr/ppu.h, ntr/ppu.cpp, ntr/ppu_sub.cpp and
# tests/walk_window.cpp. Nothing under src/ or include/ reaches them at all.
#
# HOW IT IS DECIDED. Not by a hand-kept list. The divergent set is computed
# below as the SYMMETRIC DIFFERENCE of the three targets own compile
# definitions, and tools/tierscan.py walks each candidate's transitive include
# closure over this build's own -I set and asks whether any file in it MENTIONS
# a divergent name. Mentioning is coarser than using on purpose: a comment
# about NTR_HIRES is enough to keep a TU per-target. Add a define to one of
# these targets and not the others and the split re-derives itself; the shared
# library shrinks and the build stays correct with no edit here.
#
# WHY IT IS AT THE BOTTOM OF THE FILE. Every lane appends slice_gate rows to
# these targets. This block reads the SOURCES property back off the targets
# after all of that has happened, so an appended row is picked up with no
# knowledge of this block at all. A row appended to ALL THREE targets joins the
# shared compile; a row appended to ONE stays per-target, which is what it has
# to do. A block appended BELOW this one still builds -- its sources just
# compile per target, the way every source did before this block existed.
#
# WHAT DOES NOT CHANGE. The three target names, their link lines, their
# defines, their /MAP output, and every source-file property (the per-TU
# COMPILE_DEFINITIONS the vtable and global slices set, the /vmg /vmm rows, the
# forced includes). Source properties are directory-scoped and the object
# library is in this same directory, so it inherits all of them.

set(PORT_SHARE_TARGETS walk_window walk_window_hires smoke_player)

set(_share_targets "")
foreach(_t IN LISTS PORT_SHARE_TARGETS)
    if(TARGET ${_t})
        list(APPEND _share_targets ${_t})
    endif()
endforeach()
list(LENGTH _share_targets _share_n)

if(_share_n GREATER 1)
    # -- the divergent macro set: names defined for some of these, not all.
    set(_defs_all "")
    set(_defs_common "")
    set(_first TRUE)
    foreach(_t IN LISTS _share_targets)
        get_target_property(_d ${_t} COMPILE_DEFINITIONS)
        if(NOT _d)
            set(_d "")
        endif()
        # A PUBLIC definition inherited through a linked library (NTR_WIDE_RT
        # from ntr_wide_rt, NTR_HIRES from ntr_hires) is not in
        # COMPILE_DEFINITIONS, so read it off the linked targets as well --
        # those two ARE the divergence this block exists for.
        get_target_property(_libs ${_t} LINK_LIBRARIES)
        if(_libs)
            foreach(_l IN LISTS _libs)
                if(TARGET ${_l})
                    get_target_property(_ld ${_l} INTERFACE_COMPILE_DEFINITIONS)
                    if(_ld)
                        list(APPEND _d ${_ld})
                    endif()
                endif()
            endforeach()
        endif()
        # Divergence is decided on the NAME (PORT_REPO_ROOT="..." is one name
        # with a value), but what the shared library must be COMPILED with is
        # the full definition, value and all -- so both are collected.
        set(_names "")
        foreach(_one IN LISTS _d)
            string(REGEX REPLACE "=.*$" "" _n "${_one}")
            list(APPEND _names "${_n}")
        endforeach()
        list(APPEND _defs_all ${_names})
        if(_first)
            set(_defs_common ${_d})
            set(_first FALSE)
        else()
            set(_keep "")
            foreach(_one IN LISTS _defs_common)
                if("${_one}" IN_LIST _d)
                    list(APPEND _keep "${_one}")
                endif()
            endforeach()
            set(_defs_common ${_keep})
        endif()
    endforeach()
    # _defs_common carries values; the divergence test needs names.
    set(_common_names "")
    foreach(_one IN LISTS _defs_common)
        string(REGEX REPLACE "=.*$" "" _one "${_one}")
        list(APPEND _common_names "${_one}")
    endforeach()
    list(REMOVE_DUPLICATES _defs_all)
    set(PORT_DIVERGENT_DEFINES ${_defs_all})
    if(_common_names)
        list(REMOVE_ITEM PORT_DIVERGENT_DEFINES ${_common_names})
    endif()
    message(STATUS "SLICE SHARE: divergent defines = ${PORT_DIVERGENT_DEFINES}")

    # -- the candidate set: sources every sharing target compiles.
    set(_common_srcs "")
    set(_first TRUE)
    foreach(_t IN LISTS _share_targets)
        get_target_property(_s ${_t} SOURCES)
        set(_abs "")
        set(_genex_${_t} "")
        foreach(_one IN LISTS _s)
            if(_one MATCHES "\\$<")
                # A generator expression is not a file and can never
                # be part of the shared compile, but it must survive
                # back onto the target it was already on.
                list(APPEND _genex_${_t} "${_one}")
                continue()
            endif()
            if(NOT IS_ABSOLUTE "${_one}")
                set(_one "${CMAKE_CURRENT_SOURCE_DIR}/${_one}")
            endif()
            get_filename_component(_one "${_one}" ABSOLUTE)
            list(APPEND _abs "${_one}")
        endforeach()
        set(_srcs_${_t} ${_abs})
        if(_first)
            set(_common_srcs ${_abs})
            set(_first FALSE)
        else()
            # Hash the membership test instead of a per-item IN_LIST scan.
            # IN_LIST here cost 46.1s over 23,216 evaluations, a linear scan
            # of _abs (~10,700 elements) for every _common_srcs element --
            # CFGTIME run100, out/CFGTIME/top20.txt. Index _abs once (O(n))
            # with a set() per element, then test membership with
            # if(DEFINED ...); the full absolute path is the variable-name
            # key itself (not a hash or sanitised form of it), so two
            # different paths can never collide onto the same _seen_
            # variable. Cleared right after use so it cannot leak into the
            # next target's test.
            foreach(_one IN LISTS _abs)
                set("_seen_abs_${_one}" 1)
            endforeach()
            set(_keep "")
            foreach(_one IN LISTS _common_srcs)
                if(DEFINED "_seen_abs_${_one}")
                    list(APPEND _keep "${_one}")
                endif()
            endforeach()
            foreach(_one IN LISTS _abs)
                unset("_seen_abs_${_one}")
            endforeach()
            set(_common_srcs ${_keep})
        endif()
    endforeach()
    list(REMOVE_DUPLICATES _common_srcs)

    # -- split it. A GENERATED source does not exist on a fresh configure, so
    # tierscan cannot read it. Those are emitted by tools/romdata.py and
    # tools/ovdata.py, whose only emitted includes are <string.h> and
    # <stdio.h>, so they can carry no divergent macro by construction and are
    # classified shared without a scan. Nothing else is trusted unread.
    set(_scan_srcs "")
    set(_gen_srcs "")
    foreach(_one IN LISTS _common_srcs)
        string(FIND "${_one}" "${CMAKE_BINARY_DIR}" _in_build)
        if(_in_build EQUAL 0)
            list(APPEND _gen_srcs "${_one}")
        else()
            list(APPEND _scan_srcs "${_one}")
        endif()
    endforeach()

    string(REPLACE ";" "\n" _scan_txt "${_scan_srcs}")
    file(WRITE "${CMAKE_BINARY_DIR}/tierscan_candidates.txt" "${_scan_txt}\n")
    set(_tierscan_args
        "${CMAKE_CURRENT_SOURCE_DIR}/tools/tierscan.py"
        --sources "${CMAKE_BINARY_DIR}/tierscan_candidates.txt"
        --out "${CMAKE_BINARY_DIR}/tierscan_split.cmake"
        --cache "${CMAKE_BINARY_DIR}/tierscan_cache.json"
        --incdir "${CMAKE_CURRENT_SOURCE_DIR}"
        --incdir "${PORT_REPO_ROOT_ABS}/include"
        --incdir "${CMAKE_CURRENT_SOURCE_DIR}/ntr/include")
    foreach(_m IN LISTS PORT_DIVERGENT_DEFINES)
        list(APPEND _tierscan_args --macro "${_m}")
    endforeach()
    execute_process(COMMAND python ${_tierscan_args}
                    RESULT_VARIABLE _tierscan_rc)
    if(NOT _tierscan_rc EQUAL 0)
        message(FATAL_ERROR "tierscan.py failed (${_tierscan_rc}); refusing to "
                            "guess which TUs are tier-independent")
    endif()
    include("${CMAKE_BINARY_DIR}/tierscan_split.cmake")
    list(APPEND PORT_TIER_SHARED ${_gen_srcs})
    list(LENGTH PORT_TIER_SHARED _n_shared)
    list(LENGTH PORT_TIER_PERTGT _n_pertgt)
    message(STATUS "SLICE SHARE: ${_n_shared} sources compiled ONCE, "
                   "${_n_pertgt} still per target, across ${_share_n} targets")

    if(_n_shared GREATER 0)
        add_library(port_slice_shared OBJECT ${PORT_TIER_SHARED})
        target_include_directories(port_slice_shared PRIVATE
            "${CMAKE_CURRENT_SOURCE_DIR}"
            "${CMAKE_CURRENT_SOURCE_DIR}/../include"
            "${CMAKE_CURRENT_SOURCE_DIR}/ntr/include")
        # Exactly the definitions all sharing targets agree on. A name in the
        # divergent set is what kept a TU out of here in the first place, so by
        # construction nothing in this library can see one.
        foreach(_one IN LISTS _defs_common)
            target_compile_definitions(port_slice_shared PRIVATE "${_one}")
        endforeach()
        if(MSVC)
            target_compile_options(port_slice_shared PRIVATE
                                   /wd4311 /wd4312 /wd4068 /wd4576)
        endif()

        # Swap each target's copy of the shared sources for the one build of
        # them. Nothing else about the target is touched.
        #
        # Hash the membership test instead of a per-item IN_LIST scan. The
        # IN_LIST below cost 61.4s over 34,500 evaluations, a linear scan of
        # PORT_TIER_SHARED (~10,700 elements) for every source of every
        # target -- the single largest cost in Configuring, CFGTIME run100,
        # out/CFGTIME/top20.txt. PORT_TIER_SHARED does not change across the
        # foreach(_t) loop below, so it is indexed ONCE (O(n)), not once per
        # target. As above the full absolute path is the variable-name key
        # itself, so two different paths can never collide onto the same
        # _seen_ variable; the index is cleared after the loop.
        foreach(_one IN LISTS PORT_TIER_SHARED)
            set("_seen_shared_${_one}" 1)
        endforeach()
        foreach(_t IN LISTS _share_targets)
            set(_keep ${_genex_${_t}})
            foreach(_one IN LISTS _srcs_${_t})
                if(NOT DEFINED "_seen_shared_${_one}")
                    list(APPEND _keep "${_one}")
                endif()
            endforeach()
            set_property(TARGET ${_t} PROPERTY SOURCES ${_keep})
            target_sources(${_t} PRIVATE $<TARGET_OBJECTS:port_slice_shared>)
        endforeach()
        foreach(_one IN LISTS PORT_TIER_SHARED)
            unset("_seen_shared_${_one}")
        endforeach()
    endif()
endif()


# ===========================================================================
# LANE FOLD2 hostgen: the three ov006 draws that also poke the light registers
# ===========================================================================
#
# WHY THIS BLOCK IS BELOW THE TIER-INDEPENDENT SECTION AND NOT ABOVE IT. That
# section reads each target's SOURCES property back and rewrites it, and it
# decides the shared set by walking every candidate's include closure with
# tools/tierscan.py. These three sources do not exist at configure time -- they
# are produced by an add_custom_command into ${CMAKE_BINARY_DIR}/host-src. The
# section's own header states the rule for exactly this case: "A block appended
# BELOW this one still builds -- its sources just compile per target." Three
# files compiled three times is the whole price, and it buys a generated source
# no scanner has to guess about.
#
# WHAT THE REWRITE IS. Each of the three matched sources stores to the geometry
# engine's LIGHT_VECTOR (0x040004c8) or LIGHT_COLOR (0x040004cc) through a
# plain literal-address cast. Those are NOT harmless on the host: port/io.cpp
# maps real memory across the DS I/O window, so an unrewritten store latches
# into dead memory and the geometry engine never sees the light -- the finding
# tools/hostgen.py's own header records for MTX_SCALE, and the reason the two
# MgShared4f38 host copies spelled their four stores NTR_MMIO by hand.
# hostgen.py's MMIO_DEREF turns each one into NTR_MMIO(T, addr) and touches
# nothing else in these three files (1, 2 and 4 rewrites respectively; the
# generated text was diffed against src/ line by line before this block was
# written).
#
#   src/func_ov006_020c3bf4.cpp   was unmatched/MgFlower_ModelRender_020c3bf4.cpp
#   src/func_ov006_020c1804.cpp   was unmatched/MgMemory2_ModelRender_020c1804.cpp
#   src/func_ov006_020c29dc.cpp   was unmatched/MgShared4f38_ModelRender_020c29dc.cpp
#
# The fold half of each is the same as the plain rows in slice_fold2.txt: a
# local shadow class dispatching ROM index 5, which _ZTV5Model,
# _ZTV9ModelAnim and _ZTV14BlendModelAnim all hold Render at again.
set(FOLD2_HOSTGEN_SYMS func_ov006_020c3bf4 func_ov006_020c1804
                       func_ov006_020c29dc)
set(FOLD2_HOSTGEN_GEN "")
foreach(sym IN LISTS FOLD2_HOSTGEN_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND FOLD2_HOSTGEN_GEN "${sym_out}")
endforeach()
foreach(_tfold2g walk_window walk_window_hires smoke_player)
    target_sources(${_tfold2g} PRIVATE ${FOLD2_HOSTGEN_GEN})
endforeach()

# ===========================================================================
# LANE EXCEPT hostgen: dScMgSnowball_c's Render, ROM vtable slot 9
# ===========================================================================
#
# WHY THIS BLOCK IS BELOW THE TIER-INDEPENDENT SECTION. The same reason lane
# FOLD2's block above it is: the source does not exist at configure time, it
# is produced by an add_custom_command into ${CMAKE_BINARY_DIR}/host-src, and
# that section's own header states the rule -- "A block appended BELOW this
# one still builds -- its sources just compile per target."
#
# WHAT THE REWRITE IS. Three hunks, and the generated text was diffed line by
# line against src/ before this block was written:
#
#   (1) the dispatch. The ROM reads BYTE +0x14 of the model's vptr,
#
#         02127e50  add  r0,sb,r0        ; the Model at this+0xaba4
#         02127e54  ldr  r2,[r0]         ; its vptr
#         02127e58  ldr  r2,[r2,#0x14]   ; word 5
#         02127e5c  blx  r2
#
#       and word 5 of _ZTV5Model is Render on the host as well, since lane
#       SLOT5F's respelling of include/ModelBase.h made every model table
#       ROM-numbered (hal/cxxname_bridge.cpp:522 writes mv_render there). So
#       the INDEX was never the problem. The CONVENTION was: the matched
#       source reads the word into a `void (*)(void*, int*)` and calls it
#       cdecl, while the seated body is
#       `void __fastcall mv_render(void *self, void *unused, const void *s)`,
#       so the receiver arrived on the stack, `s` read the model pointer, and
#       the callee cleaned four bytes the caller had counted too. The retired
#       host copy recorded the fault that came from -- scene 377, c0000005,
#       eip equal to the actor's own address, a frame that returned into the
#       object it was drawing. hostgen's VIRTUAL_CALL row keeps the ROM's word
#       index and the ROM's arguments and only spells the entry.
#
#   (2) and (3) the two geometry-register stores, 0x040004c8 LIGHT_VECTOR and
#       0x040004cc LIGHT_COLOR, through MMIO_DEREF with no table row of their
#       own (the pattern takes both the volatile and the non-volatile
#       spelling). Unrewritten they latch into the mapped I/O window and the
#       geometry engine never gets the light -- the same defect FOLD2 repaired
#       on this file's three ov006 siblings.
#
#   src/_ZN15dScMgSnowball_c6RenderEv.cpp   was unmatched/MgSnowball_ModelRender.cpp
#
# The referrer, the kind:function record and the ADJUDICATED REAL_DECOMP
# ruling that licenses the seat (port/tools/inferred_stub_adjudicated.txt:1283)
# are in port/slice_except.txt.
set(EXCEPT_HOSTGEN_SYMS _ZN15dScMgSnowball_c6RenderEv)
set(EXCEPT_HOSTGEN_GEN "")
foreach(sym IN LISTS EXCEPT_HOSTGEN_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND EXCEPT_HOSTGEN_GEN "${sym_out}")
endforeach()
foreach(_texceptg walk_window walk_window_hires smoke_player)
    target_sources(${_texceptg} PRIVATE ${EXCEPT_HOSTGEN_GEN})
endforeach()

# ===========================================================================
# THE ROM'S OWN main() AS THE PORT'S BOOT SPINE (run link100, lanes BOOTSCOUT
# and BOOTR1).
# ===========================================================================
#
# src/main.c is the ROM's eighteen-line main at arm9 0x02007000. The port's
# tests/walk_window.cpp defines main() for Windows, so until this block the
# matched TU was an undocumented SHADOW with 141 further matched TUs behind it.
# port/hal/rom_main.cpp carries the whole derivation, the ROM disassembly the
# seams are read off, and the one known deviation.
#
# The per-source rename is the same mechanism as func_0203bb60_narrow above:
# the matched TU stays in the link byte for byte and only the names it emits
# and calls move, so the CRT's main and the ROM's main can both exist, and
# main's two not-yet-ROM edges (func_0201a054 and func_020197b8, neither of
# them enrolled on any slice list) are visible in one place instead of becoming
# two new shadow rows. The gate SM64DS_ROM_MAIN defaults ON; SM64DS_ROM_MAIN=0
# keeps the host's transcribed head in hal/boot_os.cpp.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/main.c"
    PROPERTIES COMPILE_DEFINITIONS
    "main=rom_main;func_0201a054=port_rom_a054_seam;func_020197b8=port_rom_loop_seam")
# smoke_player is DELIBERATELY not in this list. It carries no hal/boot_os.cpp,
# so src/main.c's four externs (func_02059788, func_02059bc0, func_02059578,
# data_020a621c) have no definition in that target and it fails LNK2019.
foreach(_tbootmain walk_window walk_window_hires)
    target_sources(${_tbootmain} PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/main.c"
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN4Heap9SetNodeIDEj.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/hal/rom_main.cpp")
endforeach()

# THE ROM'S FRAME STATE (run link100, boot plan rung R3a, lane R3A).
#
# hal/rom_frame.cpp hosts data_0209d50c -- the ROM game loop's PHASE ID, which
# nothing in this port defined and nothing read, because its only ROM writer is
# func_020197b8 and the block above renames that TU to port_rom_loop_seam. It
# also carries the phase-6 step count the test harness now reads its frame
# number from, and the cross-check that refuses to return a number the host
# loop's own counter disagrees with.
#
# R3a enrolled the same two targets as rom_main.cpp above, on the reason that
# they are the only ones that compile tests/walk_window.cpp, which was then the
# only caller. RUNG R3b STEP B0 ADDS smoke_player, and the LINK is what said so:
# B0 puts the same three calls into hal/scene_boot.cpp's HEADLESS scene loop --
# the loop the battery's 36 scene rows and tail2's title actually take -- and
# scene_boot.cpp is compiled into all three of these targets, so smoke_player
# answered with four unresolved externals (_port_rom_frame_begin, _phase6,
# _checked, _report, referenced in _port_scene_run). rom_frame.cpp is host code
# with no matched TU behind it, so enrolling it in the third target that
# compiles its caller changes no count; it is the same problem the walker's
# installed filter pointer solved in lane R3CFIX, one step simpler, because
# there is nothing here for a smoke binary to be unable to pay for. This rung
# still enrols no matched TU and moves the linkage count by zero, by design.
foreach(_tromframe walk_window walk_window_hires smoke_player)
    target_sources(${_tromframe} PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/hal/rom_frame.cpp")
endforeach()

# ===========================================================================
# THE REFUSED ARMS OF func_0201a054 (run link100, lane R2ABC, rungs R2a-R2c)
# ===========================================================================
#
# hal/rom_main.cpp left main's fifth call -- func_0201a054 -- as a seam that
# only counted its hits, because hal/boot_os.cpp's transcription of that body
# refuses four of its arms. port/slice_r2abc.txt carries the arms this lane
# retired, each with the refusal it answers quoted beside it, and
# port/hal/boot_arms.cpp is what the seam calls: one entry point that runs them
# in the ROM's own order, with the storage checks each one needs.
#
# walk_window and walk_window_hires only, for hal/rom_main.cpp's own reason:
# smoke_player carries no hal/boot_os.cpp and does not run the boot spine, so
# nothing in that target reaches the seam.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_r2abc.txt" SLICE_R2ABC_LINES)
set(SLICE_R2ABC_SOURCES "")
foreach(line IN LISTS SLICE_R2ABC_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_R2ABC_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# RUNG R2d's TWO HOSTGEN'd TUs (run link100, lane R2D2). src/func_0205f0e0.c
# and src/func_0205eb58.c are the touch calibration's arithmetic and both drive
# the DS's HARDWARE DIVIDER through literal MMIO -- DIVCNT 0x4000280, NUMER
# 0x4000290, DENOM 0x4000298, RESULT 0x40002a0. Built plain, those stores latch
# in the window ntr/io.cpp maps and never reach io_write's
# `if (addr == DIV_DENOM || addr == DIV_NUMER || addr == DIVCNT) run_divide()`,
# so every result would read back as whatever was latched there. That is not a
# cosmetic difference: src/func_0205f0e0.c's results ARE the scale factors
# src/func_0205ea28.c multiplies every stylus sample by, and a zero scale is a
# stylus that always reads (0,0). The rest of the rung touches no register and
# is plain.
set(R2D_SYMS func_0205f0e0 func_0205eb58)
set(R2D_GEN "")
foreach(sym IN LISTS R2D_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND R2D_GEN "${sym_out}")
endforeach()
foreach(_tr2abc walk_window walk_window_hires)
    target_sources(${_tr2abc} PRIVATE ${SLICE_R2ABC_SOURCES} ${R2D_GEN}
        "${CMAKE_CURRENT_SOURCE_DIR}/hal/boot_arms.cpp")
endforeach()
# AND THE DRIVER ON smoke_player TOO, which is not the same list and not an
# oversight. hal/boot2_ipc.cpp is in all three of these targets and it is the
# file that claims channel 6 and hands a word on it over, so the driver has to
# be wherever the channel is. smoke_player carries no hal/boot_arms.cpp and
# never reaches the a054 seam, so nothing ever sends on the channel there and
# its census reads zero -- which is the measurement that harness owes, the same
# way a solo boot owes a zero on tag 10.
foreach(_ttsc smoke_player walk_window walk_window_hires)
    target_sources(${_ttsc} PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/hal/tsc_arm7.cpp")
endforeach()
# RUNG R2d's PER-SOURCE RENAME, the same mechanism as func_02060890 below and
# for a reason of the same kind. src/func_0205ea10.c is
# `while (*(volatile u16 *)(data_020a80cc + 0x36) & mask);` -- a spin waiting
# for the OTHER PROCESSOR's interrupt, which on the DS arrives the moment
# src/func_0205edd8.cpp's closing IRQ::Restore re-enables interrupts, i.e. after
# the bit is set and before the wait. A single-threaded host has no
# "meanwhile", so func_0203bbc0's two waits go through hal/tsc_arm7.cpp's
# port_tsc_wait: the ROM's own exit test with the ARM7's turn inside the loop,
# which is the same move ntr/ipc.cpp makes for src/func_0205bad8.c's IPCSYNC
# handshake. src/func_0205ea10.c itself is NOT displaced -- it stays in the link
# under its own name for its other caller src/func_0205efc0.c -- so this creates
# no SHADOW row in port/tools/linkage.py's queue and invents no count.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0203bbc0.c"
    PROPERTIES COMPILE_DEFINITIONS
    "func_0205ea10=port_tsc_wait")
# THE PER-SOURCE RENAME THAT STOOD HERE IS RETIRED (run linkfull, lane S4CARD).
# src/func_02042f68.c was built with func_02060890=port_rom_card_bringup because
# two of func_02060890's statements would not link: `data_020a8780 =
# func_02060a64` and func_02061138 -> func_020610fc. Both link now.
# data_020a8780 is hal/card_globals.cpp's, func_02060a64 is the card's CPU ROM
# read (the page reader, not a FLASH path as this note used to say),
# func_020610fc is plain C (an IPCSend loop and a `for (;;)`), and each is a
# row of port/slice_w28_card.txt. So func_02042f68's arm 1 is src/func_02060890.c
# itself, run where func_02042f68 already runs; its other two arms were the
# ROM's already.

# Run link100, lane NITROFS: the NitroFS seat's target lists, in the shape the
# rename above uses, and for the reason spelled out beside SLICE_NITROFS_SOURCES
# -- the seat needs hal/boot_hw.cpp's four OS primitives and smoke_player does
# not carry that file, so the two window targets get the cartridge's own
# func_0205d96c and smoke_player keeps the face. The two are exclusive: a
# target with both would have func_0205d96c defined twice.
foreach(_tnitrofs walk_window walk_window_hires)
    target_sources(${_tnitrofs} PRIVATE ${SLICE_NITROFS_SOURCES})
endforeach()
target_sources(smoke_player PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/nitrofs_face.cpp")

# Run link100, lane LOADOV: the overlay-unload seat, on the same split and for
# the same reason (see beside SLICE_LOADOV_SOURCES). hal/nitrofs_face.cpp is
# already on smoke_player from the line above and now carries the second face,
# so there is nothing to add on that side.
foreach(_tloadov walk_window walk_window_hires)
    target_sources(${_tloadov} PRIVATE ${SLICE_LOADOV_SOURCES})
endforeach()

# Run link100, lane CTOR, rung C1a: the ROM's own static-initialiser runner at
# Entry's own point (arm9 0x020048a8, one instruction before the tail jump to
# main). port/slice_ctor.txt is the derivation and hal/ctor_runner.cpp carries
# the table, the binds, the thirteen faces and the two once-only counters.
#
# ALL THREE TARGETS, not the two window ones. hal/level_boot.cpp and
# hal/fdr_arm9_fader_seat.cpp are on smoke_player as well, and this commit
# DELETES the two hand calls those files made (__sinit_02073e6c and
# __sinit_02074f80). Leaving smoke_player off this list would take both
# initialisers out of that binary altogether -- exactly the split the fader
# block above warns about, arriving from the other direction. smoke_player has
# no Entry seam to call the runner from, so on that target the two initialisers
# are linked and not run; it renders a Player into a BMP and touches neither
# the wipe fader nor the opening's script blobs, and the smoke suite is the
# check that this stays true.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ctor.txt" SLICE_CTOR_LINES)
set(SLICE_CTOR_SOURCES "")
foreach(line IN LISTS SLICE_CTOR_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_CTOR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_CTOR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/hal/ctor_runner.cpp")
foreach(_tctor walk_window walk_window_hires smoke_player)
    target_sources(${_tctor} PRIVATE ${SLICE_CTOR_SOURCES})
endforeach()

# Run link100, lane SND1, rung R1: the sound-init seat, and it goes to ALL
# THREE sound targets rather than the two-plus-a-face split NITROFS and LOADOV
# use above. The reason is the direction of the call: hal/sdat/consumer.cpp
# calls func_0204f070 and func_0205b358 now, and that file is on all three, so
# a target without the slice would not link at all. Only ONE symbol under the
# seat is missing from smoke_player -- func_02059d8c, the ARM busy-wait
# hal/boot_hw.cpp transcribes and that target does not carry -- and it comes
# from its own file below. Everything else src/func_0205ae64.c and
# src/func_0205b358.c reach (func_0205ba3c, func_0205ba64, func_020587dc,
# CP15::FlushAndInvalidateDataCache, IRQ::Disable/Restore, data_020a7fc8) is
# already on all three.
foreach(_tsnd1 smoke_player walk_window walk_window_hires)
    target_sources(${_tsnd1} PRIVATE ${SLICE_SND1_SOURCES})
endforeach()
target_sources(smoke_player PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/sdat/snd_smoke_face.cpp")

# Run link100, lane SND1, rungs R8/R9/R10: the sound frame, same three targets.
# ONE SOURCE GOES TO smoke_player ALONE. src/func_0205ac28.c is the command-9
# sender src/func_0204ffcc.c calls, and it is already on port/slice_gate220.txt
# for the two window targets -- listing it in slice_snd8.txt would put a second
# object with the same definition into those two links. smoke_player is the only
# target that lacks it, so it is added here rather than to the slice.
foreach(_tsnd8 smoke_player walk_window walk_window_hires)
    target_sources(${_tsnd8} PRIVATE ${SLICE_SND8_SOURCES})
endforeach()
target_sources(smoke_player PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0205ac28.c")

# ===========================================================================
# SEAT2 -- the ROM's second destructor word for four cartridge vtables
# (run link100 wave 7, census batch B2 DTOR-THUNK-VTABLES)
# ===========================================================================
#
# port/slice_seat2.txt is the derivation and hal/vtables_seat2.cpp carries the
# seat, the ROM addresses each word was read at, and the refusals.  Three
# matched TUs and one host file; the fourth row of the gate is seated without a
# slice entry, and that asymmetry is the point of the two blocks below.
#
# WALK_WINDOW ONLY, deliberately.  The three TUs' closures
# (_ZTV11ShadowModel + data_0209cef4 + ModelBase::~ModelBase(D2), _ZTV9FaderWipe
# + Model::~Model + Color::~Color, _ZTV7Clipper) were each checked against
# walk_window.map at 0046a2d11 before this block was written; none of the three
# was checked against smoke_player's or walk_window_hires' narrower links, and
# a seat that has not been measured on a target does not belong on it.  Nothing
# regresses on the other two: the words this file writes were null or a named
# trap there before and still are.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_seat2.txt" SLICE_SEAT2_LINES)
set(SLICE_SEAT2_SOURCES "")
foreach(line IN LISTS SLICE_SEAT2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SEAT2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_SEAT2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/hal/vtables_seat2.cpp")
target_sources(walk_window PRIVATE ${SLICE_SEAT2_SOURCES})

# TWO PLACEHOLDER NAMES, the gate-225b technique one class over.
# src/_ZN7ClipperD0Ev.c spells its own vtable `vtbl_Clipper` (declared in
# include/decl_common.h:3174, defined nowhere in this build) and
# Memory::operator_delete2 `base_dtor_Clipper`.  Both bindings are read off
# that body's OWN literal pool and call, not off the recovery's names:
#   0x0201571c  .word 0x0208e730             _ZTV7Clipper, the table it writes
#   from:0x0201570c kind:arm_call to:0x0203cbcc  _ZN6Memory16operator_delete2EPv
# which is the same shape as src/engine/fader/_ZN5FaderD0Ev.c's pair above.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN7ClipperD0Ev.cpp"
    PROPERTIES COMPILE_DEFINITIONS
    "vtbl_Clipper=_ZTV7Clipper;base_dtor_Clipper=_ZN6Memory16operator_delete2EPv")

# _ZTV5Stage SLOT 1, and it is named here rather than on port/slice_seat2.txt
# for the reason src/_ZN5Stage16OnPendingDestroyEv.cpp is named beside
# hal/stage_bridges.cpp three targets up: walk_window already compiles
# src/_ZN5Stage19BeforeInitResourcesEv.cpp through SLICE_W8A_SOURCES, and
# SLICE_W8A_SOURCES is on walk_window ALONE.  smoke_player and
# walk_window_hires compile hal/stage_bridges.cpp -- whose st_binit is now the
# reference that seats this TU -- and would fail with LNK2019 on
# __ZN5Stage19BeforeInitResourcesEv without the body.  Naming it on
# walk_window as well would put the object in that link twice.
#
# AND _ZTV9FaderWipe SLOT 0x04 RIDES WITH IT, the same rule from the other
# direction, measured rather than predicted: hal/fader_wipes.cpp is compiled
# into port_slice_shared and therefore into ALL THREE targets, so the moment
# HalFaderWipe::DtorDeleting became the seat every target needed the body.  The
# first build of this gate said so --
#   fader_wipes.cpp.obj : error LNK2019: unresolved external symbol
#   __ZN9FaderWipeD0Ev referenced in function "public: virtual void __thiscall
#   HalFaderWipe::DtorDeleting(void)" (?DtorDeleting@HalFaderWipe@@UAEXXZ)
# on smoke_player and walk_window_hires, with walk_window itself linking clean
# at 10527.  It is the rule the LoadAndSetFile block three targets up states in
# advance: face and body link together or the target does not link at all.  All
# four of the body's externals are already in both narrow links --
# _ZN5ModelD1Ev and _ZN10FaderColorD2Ev are in each target's own .rsp,
# Memory::operator_delete2 comes from hal/cxxname_bridge.cpp which both
# compile, and _ZTV9FaderWipe is the alias hal/fader_wipes.cpp defines itself.
# LANE SMOKELINK2 (run link100 wave 10 round 2): THE FADERWIPE D0 ROW IS
# RETIRED HERE, and the paragraph above is the record of why it was right when
# it was written.  The 09-14 sync took the flat name away from it.
#
# What the row bought was __ZN9FaderWipeD0Ev, the flat name
# hal/fader_wipes.cpp's HalFaderWipe::DtorDeleting calls, and the block above
# quotes the LNK2019 that proved these two narrow targets needed the body.
# port/faces_sync.txt now carries that same name as a D row --
#   __ZN9FaderWipeD0Ev   _ZN9FaderWipeD1Ev   0x02017418   D
#     _ZN6Memory16operator_delete2EPv   -
# (line 2272) -- so port/tools/facegen.py --sync generates the definition into
# build/port/host-src/faces_sync_gen.cpp, and ${PORT_FACES_SYNC_GEN} is on all
# three of walk_window, walk_window_hires and smoke_player.  The row is paying
# for a name the generated face already defines.
#
# And it is no longer free.  src/engine/fader/_ZN9FaderWipeD0Ev.cpp compiles as
# C++ on the synced line, so MSVC emits ??1FaderWipe@@UAE@XZ out of it -- the
# same symbol src/engine/fader/_ZN9FaderWipeD1Ev.cpp emits, which
# port/slice_gate36.txt already puts on these targets.  That is the only
# LNK2005 in a full ninja -k 0 over all targets at 79388ffe5, once on
# smoke_player and once on walk_window_hires:
#   _ZN9FaderWipeD0Ev.cpp.obj : error LNK2005:
#     "public: virtual __thiscall FaderWipe::~FaderWipe(void)"
#     (??1FaderWipe@@UAE@XZ) already defined in _ZN9FaderWipeD1Ev.cpp.obj
# port/slice_seat2.txt:57 states the rule it breaks in as many words: MSVC
# folds the ROM's destructor variants into one symbol, so only one of a class's
# two per-function destructor translation units can be compiled.  walk_window
# never had this row and never had the collision.
#
# src/_ZN5Stage19BeforeInitResourcesEv.cpp stays: its reason is unchanged and
# nothing else in any of the three links defines __ZN5Stage19BeforeInitResourcesEv.
foreach(_tseat2s smoke_player walk_window_hires)
    target_sources(${_tseat2s} PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN5Stage19BeforeInitResourcesEv.cpp")
endforeach()

# ===========================================================================
# Run link100 wave 7, lane SEAT6: BATCH B6, SLOT-DISPATCH (families E and F)
# ===========================================================================
#
# Seventeen rows of the eighteen out/REMAIN2/BATCHES.md section B6 lists, each
# derived from the ROM one at a time. The per-row evidence -- the vtable word
# or arm_call that reaches the body, the RTTI name at vtable-4, the
# kind:function record, and the dispatch instruction read at its own address --
# is in port/slice_seat6.txt, which also states the single row NOT taken and
# why.
#
# FOURTEEN OF THE SEVENTEEN ARE GENERATED, and that is the whole lever of this
# batch. Each is a matched TU whose ONE host problem is how a call is entered:
# a vtable word read raw and called __cdecl where the seated word wants the
# receiver in ECX (VIRTUAL_CALL), an argument the ROM left riding in a register
# that a cdecl caller has to spell (REG_RIDE_ARG), a return the callee only
# ever wrote a byte of (ARG_WIDTH), or a declaration the TU and
# include/decl_common.h disagree about (HEADER_SHADOW). Every one of those is
# an EXACT-STRING row in port/tools/hostgen.py that hard-errors if the source
# ever moves, and every one of them makes the same one-line change the host
# copy it retires already makes by hand. What runs does not change; what
# changes is that the byte-locked TU is the thing compiled. The precedent is
# lane FOLD2's own proposal for dScMgSnowball_c, shipped as VIRTUAL_CALL row
# _ZN15dScMgSnowball_c6RenderEv.
#
# THE OTHER THREE NEED NO RESPELLING AT ALL and are ordinary slice lines in
# port/slice_seat6.txt: two InitResources bodies held out by ONE missing member
# decoration (?NumNodes@PathPtr@@QBEHXZ, supplied by hal/dispatch_seat6.cpp)
# and one whose two stated reasons both expired -- the slot-5 numbering with
# lane SLOT5F, the ov070/ov074 name race with the per-source
# COMPILE_DEFINITIONS at line 12640 of this file.
set(SEAT6_GEN_SYMS
    # VIRTUAL_CALL: the raw vtable read respelled at the one disagreeing site
    _ZN9RabbitKey6RenderEv          # ov085, Model +0x110 word 5
    func_ov002_020eeeb8             # ov002, actor word 24 (OnKicked)
    func_ov002_020ef070             # ov002, actor word 23 (OnAttacked2)
    func_ov004_020b6b40             # ov004, dScMgBase_c word 19
    func_ov004_020b6c9c             # ov004, the same body at its second address
    func_ov006_020c2924             # ov006, HalFaderWipe word 6 (IsAtEnd)
#   _ZN14ArrowSignRight11OnAttacked1ER8dActor_c LEFT THIS LIST at the main ->
#   port sync (lane SYNC5): main calls Kill() as a member there, so the
#   VIRTUAL_CALL row had nothing left to respell, and the TU is quarantined
#   for C2561 besides.
    # REG_RIDE_ARG: an argument the ROM's caller left in a register
    _ZN15ModelComponents6RenderEP9Matrix4x3P7Vector3   # arm9, the r1 material index
    func_ov002_020e5948             # ov002, TextureSequence::Prepare's r2
    # ARG_WIDTH: a return the callee only wrote a byte of
    func_0200ee8c                   # arm9, GetStarCameraSetting returns u8
    # HEADER_SHADOW: two declarations of one function, C2733
    _ZN6Player16CleanupResourcesEv) # ov002
# THREE OF THIS LANE'S ROWS LEFT THE LIST AT THE MAIN -> PORT SYNC (lane SYNC5),
# because main folded their per-function TUs into consolidated ones and a
# per-symbol generation of a file that no longer exists stops the build before
# ninja reaches a compiler:
#   func_ov002_020cef84 (ov002, actor word 28) is inside src/actors/Player.cpp,
#     already a whole-TU substitution; its VIRTUAL_CALL patch moved to that TU's
#     key and a second generation would have compiled the body twice.
#   func_ov032_02111350 (ov032, the ClosestPlayer receiver) is inside
#     src/game/actors/d_a_bakubaku.cpp, which four live slices already compile,
#     and main's own spelling there declares and calls ClosestPlayer WITH the
#     receiver -- the patch's reason is gone, so hostgen.py drops the row.
#   _ZN11daBgSnwmn_c13InitResourcesEv (ov072, Prepare's third register) is inside
#     src/game/actors/d_a_bg_snwmn.cpp, added to PORT_HOSTGEN_TU at the top of
#     this file; its REG_RIDE_ARG patch is re-keyed on that TU's stem.
set(SEAT6_GEN "")
foreach(sym IN LISTS SEAT6_GEN_SYMS)
    if(EXISTS "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.c")
    else()
        set(sym_src "${PORT_REPO_ROOT_ABS}/src/${sym}.cpp")
    endif()
    set(sym_out "${CMAKE_BINARY_DIR}/host-src/src/${sym}.cpp")
    add_custom_command(OUTPUT "${sym_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${sym}
        DEPENDS "${sym_src}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${sym}")
    list(APPEND SEAT6_GEN "${sym_out}")
    if(sym STREQUAL "_ZN15ModelComponents6RenderEP9Matrix4x3P7Vector3")
        set(SEAT6_MODELCOMP_GEN "${sym_out}")
    endif()
endforeach()

port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_seat6.txt" SLICE_SEAT6_LINES)
set(SLICE_SEAT6_SOURCES "")
foreach(line IN LISTS SLICE_SEAT6_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SEAT6_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# The one member decoration two of the plain rows need and nothing else in this
# link defines; see the file's own banner for why it is a real __thiscall
# forwarder and not an /alternatename alias.
list(APPEND SLICE_SEAT6_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/dispatch_seat6.cpp")
# The same three targets every host copy this batch retires already rides
# (SLICE10_CAM_SOURCES and the per-overlay cast lists all land here).
foreach(_tseat6 walk_window walk_window_hires smoke_player)
    target_sources(${_tseat6} PRIVATE ${SLICE_SEAT6_SOURCES} ${SEAT6_GEN})
endforeach()

# ModelComponents::Render IS THE ONE ROW THAT RIDES WIDER THAN THOSE THREE, and
# the gate-1 link is what said so rather than a reading: port/unmatched/
# ModelComponents_Render.cpp is enrolled through port/slice_gate4b.txt, which
# ten of the narrow smoke harnesses consume, and src/_ZN5Model6RenderEPK7Vector3
# .cpp calls ?Render@ModelComponents@@QAEXPAUMatrix4x3@@PAUVector3@@@Z in every
# one of them. Cutting the host body without following it to those targets left
# exactly one unresolved external in each (LNK2019, ten times, one symbol).
#
# The generated TU goes to the targets that REFERENCE the symbol, and nowhere
# else: the point of a narrow harness is that it links a narrow set, and the
# other thirteen rows of this batch have no business in smoke_heap. This list
# is the ten the link named, and it is a list rather than a slice edit so that
# port/slice_gate4b.txt -- a file ten targets share and this lane does not own
# -- keeps its line and keeps compiling the (now bodyless) host file.
# THE LIST IS THE LINKER'S, NOT A READING. It is every target whose link line
# in build/port/build.ninja carries _ZN5Model6RenderEPK7Vector3.cpp.obj -- the
# TU that calls ?Render@ModelComponents@@QAEXPAUMatrix4x3@@PAUVector3@@@Z --
# minus the three above, which already have the whole batch. Eleven narrow
# harnesses; taking the first ten from one failed link and stopping there left
# smoke_persist red on the next build, which is why this enumeration is
# mechanical.
foreach(_tseat6mc smoke_model smoke_soak smoke_anim smoke_frames
                  smoke_soak_anim smoke_modelanim smoke_oam smoke_clsn
                  smoke_actor smoke_savestate smoke_persist)
    target_sources(${_tseat6mc} PRIVATE ${SEAT6_MODELCOMP_GEN})
endforeach()

# Run link100, lane SND2: the sound bring-up, same three targets and the same
# reason (hal/sdat/consumer.cpp calls it).
foreach(_tsnd2 smoke_player walk_window walk_window_hires)
    target_sources(${_tsnd2} PRIVATE ${SLICE_SND2_SOURCES})
endforeach()

# THE CONFIGURE-DEPENDS SELF-CHECK (run link100, lane CMAKEDEPS).  Every list
# read at configure time has to be registered, or an edit to it will not
# reconfigure and the build will look clean while compiling the old set of
# sources.  port_read_lines makes that automatic; this counts the reads that did
# NOT go through it.  Five are expected and correct: the four REGEX predicate
# reads (SC1, RT1, IR1, AE1), each of which carries its own
# port_configure_input line, and the file(STRINGS) inside port_read_lines
# itself.  A sixth means somebody wrote a raw read and its input is invisible to
# RERUN_CMAKE.  This warns rather than fails, so that it can never be the thing
# that stops another lane's build.
file(READ "${CMAKE_CURRENT_LIST_FILE}" _PORT_SELF_TEXT)
string(REGEX MATCHALL "\n[ \t]*file\\(STRINGS" _PORT_RAW_READS "${_PORT_SELF_TEXT}")
list(LENGTH _PORT_RAW_READS _PORT_RAW_READ_N)
unset(_PORT_SELF_TEXT)
if(NOT _PORT_RAW_READ_N EQUAL 5)
    message(WARNING
        "CONFIGURE DEPS: ${_PORT_RAW_READ_N} raw file(STRINGS) reads in "
        "port/CMakeLists.txt, expected 5. A read written as file(STRINGS ...) "
        "is NOT registered in CMAKE_CONFIGURE_DEPENDS, so editing the list it "
        "reads will not re-run cmake and the new sources will never compile. "
        "Write it as port_read_lines(<path> <var>) instead, or put a "
        "port_configure_input(<path>) line beside it and raise the 5 here.")
endif()
get_property(_PORT_CONFIGURE_DEPS DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
             PROPERTY CMAKE_CONFIGURE_DEPENDS)
list(LENGTH _PORT_CONFIGURE_DEPS _PORT_CONFIGURE_DEPS_N)
message(STATUS "CONFIGURE DEPS: ${_PORT_CONFIGURE_DEPS_N} configure-time inputs "
               "registered, ${_PORT_RAW_READ_N} raw reads")

# The whole-TU hostgen COUNT assertion used to stand here. It now stands at the
# very END of this file, because here it only saw the slice lists read above it:
# run link100 lane HOSTGEN4 put src/actors/dMgJump3DMario_c.cpp on
# PORT_HOSTGEN_TU and this copy refused it, naming a TU that IS on a slice row
# (slice_slice1.txt line 71) simply because that list is read 130 lines further
# down. The same blindness runs the other way and is the dangerous direction: a
# substitution with one hit from an early slice and none from a late one passed
# here while the late slice went on compiling the raw TU.

# ===========================================================================
# INT BODIES THAT FALL OFF THE END (C4716), PER SOURCE
# ===========================================================================
#
# mwccarm lets a non-void function reach its closing brace without a return:
# the caller reads whatever r0 holds. MSVC reports the same shape as C4716,
# which is an ERROR by default, and refuses the translation unit.
#
# main's 2026-09 consolidation brought twenty such bodies into the port's
# slices at once -- the dActor_c interaction defaults (OnPushed, OnAttacked1/2,
# OnHitFromUnderneath, OnHitByCannonBlastedChar), the dScMgBase_c placeholder
# virtuals, and a handful of InitResources bodies. Every one of them is a ROM
# body that sets no return register: `int dActor_c::OnAttacked1(dActor_c &)` at
# 0x02010144 is a bare `bx lr`, and the files say so in their own headers.
#
# /wd4716 is what the port asks MSVC for here, and it is the FAITHFUL answer
# rather than a lenient one: with the diagnostic off, MSVC compiles the
# fall-through and the caller reads whatever EAX holds, which is exactly what
# the DS does with r0. The alternative the tree already carries --
# hostgen's FALLS_OFF_RETURN table -- INVENTS a value (0 or 1) and has to
# derive it per body; that is the better answer for a body whose return is
# actually read, and those three entries stay as they are. Nothing here is
# read: each of these is a vtable slot the ROM fills with a body that computes
# no result.
#
# SCOPE IS PER SOURCE ON PURPOSE. The option is never put on a target, so a
# NEW fall-off-the-end body still fails the build and gets looked at.
set(PORT_FALLS_OFF_END_SOURCES
    src/_ZN10dScEntry_c19BeforeInitResourcesEv.cpp
    src/_ZN11dScMgBase_c9Virtual50Ev.cpp
    src/_ZN11dScMgBase_c9Virtual7CEv.cpp
    src/_ZN12FortressWall24OnHitByCannonBlastedCharER8dActor_c.cpp
    src/_ZN12dScMgAmida_c9Virtual7CEv.cpp
    src/_ZN12dScMgSlot1_c19OnHitFromUnderneathEv.cpp
    src/_ZN12dScMgSlot3_c16OnAimedAtWithEggEv.cpp
    src/_ZN16dScMgSmartball_c9Virtual7CEv.cpp
    src/_ZN21FloatingFloorLllSmall13InitResourcesEv.cpp
    src/_ZN3OAM12EnableSubOAMEv.cpp
    src/_ZN5Bully13InitResourcesEv.cpp
    src/_ZN8SignPost11OnAttacked1ER8dActor_c.cpp
    src/_ZN8dActor_c11OnAttacked1ERS_.cpp
    src/_ZN8dActor_c11OnAttacked2ERS_.cpp
    src/_ZN8dActor_c19OnHitFromUnderneathERS_.cpp
    src/_ZN8dActor_c24OnHitByCannonBlastedCharERS_.cpp
    src/_ZN8dActor_c8OnPushedERS_.cpp
    src/actors/dScMgCup_c.cpp
    src/actors/daOts_c.cpp
    # Added at the main -> port sync (lane SYNC5). Lane SEAT2 seats _ZTV5Stage
    # slot 1 on the ROM's own three-word veneer, so smoke_player and
    # walk_window_hires compile this TU for the first time; its body is the
    # veneer, which names no parameter and falls off the end with the receiver
    # still in r0. Same row, same reason, as the twenty above.
    src/_ZN5Stage19BeforeInitResourcesEv.cpp
    # Added by lane SLICE1's batch 1, which puts this TU on a slice for the
    # first time: RotatingPlatformLll::InitResources is an int body whose ROM
    # code reaches the closing brace with the result still in r0, exactly the
    # shape the twenty rows above cover. Nothing else in the batch raises
    # C4716.
    src/_ZN19RotatingPlatformLll13InitResourcesEv.cpp
    # Added by lane SYNC6 when today's main un-quarantined five TUs that lane
    # SYNC5 had held for C2561. main's #2663 spells their valueless early exits
    # as nested ifs instead of `return;`, which is the statement C2561 was
    # raised on, and what is left is the plain fall-off-the-end the rows above
    # already cover: each body is a ROM vtable slot that sets no return
    # register. Measured per source with the build's own flags before these
    # rows were written: these five are the only ones of the twenty-five
    # restored TUs that raise C4716.
    src/_ZN11dScMgBase_c19OnHitFromUnderneathEv.cpp
    src/_ZN13QuestionBlock11OnAttacked1ER8dActor_c.cpp
    src/_ZN13QuestionBlock19OnHitFromUnderneathER8dActor_c.cpp
    src/game/actors/daObjPushblock_c.cpp
    # d_a_wanwan.cpp raises C4716 twice as well (func_ov014_02111fb8 and
    # func_ov014_0211150c). Lane SYNC6 wrote the row here as a comment
    # against the day the TU was seated. Lane HOSTGEN4 seated it, so the
    # row is live now.
    src/game/actors/d_a_wanwan.cpp
    # Added by lane HOSTGEN4 with the dScMgD3DBase_c seat. FOUR bodies in
    # that TU reach the closing brace with the result still in r0 --
    # Virtual7C, OnHitFromUnderneath, OnAimedAtWithEgg and
    # func_ov006_020e6e3c -- which is the same shape as every row above.
    # The loop below puts the option on the generated path too, so the
    # substitution does not lose it.
    src/actors/dScMgD3DBase_c.cpp
    # Added by lane SEATS3 with the daGmch_c seat. ONE body in that TU,
    # daGmch_c::ApplySlopeToVertSpeed, is an int member whose ROM code reaches
    # the closing brace with the result still in r0. Measured with the build's
    # own flags on the generated copy, not predicted: C4716 on that member and
    # on nothing else in the file. The loop below puts the option on the
    # generated path too, which is the path this TU is compiled from.
    src/actors/daGmch_c.cpp
    # And the dScMgBase_c member seated beside it, same lane. The body reaches
    # its closing brace with nothing to return on every path -- the decomp's
    # own note at the top of that file says the ROM leaves r0 holding whatever
    # the last call left there -- so MSVC raises C4716 on it. Measured on the
    # generated copy: that member and nothing else.
    src/_ZN11dScMgBase_c16OnAimedAtWithEggEv.cpp
    # Run link100 wave 9c, lane LINK21. ArrowSignRight::OnAttacked1 joins its two
    # already-seated siblings, SignPost::OnAttacked1 and QuestionBlock::OnAttacked1,
    # both of them a few rows above in this list. It could not join them before
    # because its body carried a bare `return;` as well, which is a C2561 that
    # /wd4716 cannot answer; hostgen's FALLS_OFF_RETURN row turns that early exit
    # into the absence of the call, and what is left is the ordinary C4716 shape
    # the other two have. It is a PORT_HOSTGEN_TU row, so the loop below puts the
    # option on the generated path as well.
    src/_ZN14ArrowSignRight11OnAttacked1ER8dActor_c.cpp
    )
# A WHOLE-TU HOSTGEN SUBSTITUTION MOVES THE COMPILE, AND A PER-SOURCE PROPERTY
# DOES NOT FOLLOW IT. Run link100, lane HOSTGEN2, measured: putting
# src/actors/dScMgCup_c.cpp on PORT_HOSTGEN_TU made the build compile
# build/port/host-src/src/actors/dScMgCup_c.cpp instead, the /wd4716 row above
# stayed on the raw path, and the TU came back as `error C4716:
# 'dScMgCup_c::Virtual50': must return a value` -- a fall-off-the-end body the
# tree adjudicated long ago, reported as if it were new. Every future
# substitution of a row in this list would do the same, so the fix is here
# rather than a second row per TU: set the option on BOTH paths, the raw one
# for the targets that still read it and the generated one for the targets the
# substitution redirects.
foreach(_foe_rel IN LISTS PORT_FALLS_OFF_END_SOURCES)
    if(NOT EXISTS "${PORT_REPO_ROOT_ABS}/${_foe_rel}")
        message(FATAL_ERROR "falls-off-the-end row names a source that does not "
                "exist: ${_foe_rel}")
    endif()
    set(_foe_paths "${PORT_REPO_ROOT_ABS}/${_foe_rel}")
    if(DEFINED PORT_HOSTGEN_TU_ROW_${_foe_rel})
        list(APPEND _foe_paths
             "${PORT_REPO_ROOT_ABS}/${PORT_HOSTGEN_TU_ROW_${_foe_rel}}")
    endif()
    # AND IT MUST NOT WIPE AN OPTION ANOTHER BLOCK ALREADY PUT ON THE SOURCE.
    # COMPILE_OPTIONS is one property and set_source_files_properties REPLACES
    # it, and this loop is the LAST word in the file, so a /FI set higher up
    # silently stopped applying. Measured, run link100 lane CRASH8: the
    # QuestionBlock host-ABI shadow went on all ten of that class's TUs and came
    # back on eight, because OnAttacked1 and OnHitFromUnderneath are rows in the
    # list above and this loop overwrote them with /wd4716 alone. Nothing
    # reported it -- the build was green and the two TUs simply kept the wrong
    # member offsets. So read what is there and append.
    foreach(_foe_path IN LISTS _foe_paths)
        get_source_file_property(_foe_prev "${_foe_path}" COMPILE_OPTIONS)
        if(_foe_prev)
            set_source_files_properties("${_foe_path}"
                PROPERTIES COMPILE_OPTIONS "${_foe_prev};/wd4716")
        else()
            set_source_files_properties("${_foe_path}"
                PROPERTIES COMPILE_OPTIONS "/wd4716")
        endif()
    endforeach()
endforeach()

# ===========================================================================
# DSSTATE FORCE-INCLUDE (run link100 wave 9c, lane LINK21)
# ===========================================================================
#
# THE FIRST BUILD IN THIS CAMPAIGN THAT REACHED A LINK ran dsstate_guard for the
# first time. That guard reads build/port/walk_window.map, which has been zero
# bytes for every wave because the link failed, so it has been checking nothing.
# With walk_window.exe linked it named 32 hosted DS symbols outside the captured
# [dsstate_lo, dsstate_hi) span, where a save state would not roll them back.
# One was lane LINK21's own and is bracketed in hal/link21_rows.cpp; the other
# thirty one are in the eleven translation units below.
#
# THEY ARE THERE BECAUSE OF THE SYNC, not because of a lane. port/ov044_syms.txt
# lines 91-97 and port/ov100_syms.txt lines 1-6 both record retiring the MOUNT of
# exactly these objects, because the class TU main folded them into defines them
# itself now and the mount was a second definition. tools/ovdata.py brackets
# everything it emits; an ordinary file-scope definition in a src TU is not
# bracketed by anything. So the objects kept their names and their sizes and
# quietly left the snapshot, and nothing could say so until the tree linked.
#
# THE FIX IS PORT-SIDE AND TOUCHES NO DECOMP FILE. cl /FI force-includes
# hal/dsstate_all.h, which opens the captured segment for the whole translation
# unit; that header's own banner carries the argument, including why opening it
# for the whole TU is SAFER than a DSSTATE_BEGIN/END bracket in the source
# (hal/dsstate_seg.h's "a later extern re-declaration undoes this" trap needs a
# back-to-default moment, and this shape has none).
#
# BOTH PATHS for a whole-TU hostgen row, for the reason the /wd4716 loop above
# states: a substitution moves the compile and a per-source property does not
# follow it. One of the eleven, d_a_star_gate.cpp, is such a row today.
set(PORT_DSSTATE_FI_SOURCES
    src/minigames/d_s_mg_trampoline.cpp
    src/minigames/d_s_mg_trampoline2.cpp
    src/game/actors/d_a_obj_fm_battan.cpp
    src/game/actors/d_a_obj_rc_carpet.cpp
    src/game/actors/d_a_obj_km1_dorifu.cpp
    src/game/actors/d_a_obj_kb1_billboard.cpp
    src/game/actors/d_a_obj_km2_gura.cpp
    src/game/actors/d_a_obj_km3_kurumajiku.cpp
    src/game/actors/d_a_obj_km3_kaitendai.cpp
    src/game/actors/d_a_obj_km3_kuruma.cpp
    src/game/actors/d_a_star_gate.cpp)
if(MSVC)
    foreach(_dsfi_rel IN LISTS PORT_DSSTATE_FI_SOURCES)
        if(NOT EXISTS "${PORT_REPO_ROOT_ABS}/${_dsfi_rel}")
            message(FATAL_ERROR "dsstate force-include row names a source that "
                    "does not exist: ${_dsfi_rel}")
        endif()
        set(_dsfi_paths "${PORT_REPO_ROOT_ABS}/${_dsfi_rel}")
        if(DEFINED PORT_HOSTGEN_TU_ROW_${_dsfi_rel})
            list(APPEND _dsfi_paths
                 "${PORT_REPO_ROOT_ABS}/${PORT_HOSTGEN_TU_ROW_${_dsfi_rel}}")
        endif()
        # AND THE PER-GATE SUBSTITUTIONS, which are not PORT_HOSTGEN_TU rows and
        # so are invisible to the branch above. The first build of this block
        # measured it: 32 uncaptured symbols went to 11, and all eleven were
        # d_s_mg_trampoline2.cpp's, because that TU is substituted by
        # TTE_HOSTGEN_GEN (the set at the TTE block) rather than by the whole-TU
        # list, so only its raw path took the option and nothing compiles the
        # raw path. The generated name is the same relative path under host-src
        # whichever generator writes it, so naming it unconditionally costs
        # nothing: a property on a path no target compiles is inert.
        string(REGEX REPLACE "[.](c|cpp)$" ".cpp" _dsfi_gen "${_dsfi_rel}")
        list(APPEND _dsfi_paths "${CMAKE_BINARY_DIR}/host-src/${_dsfi_gen}")
        list(REMOVE_DUPLICATES _dsfi_paths)
        # APPEND, NEVER SET. set_source_files_properties REPLACES the whole
        # COMPILE_OPTIONS list, and one of these eleven already carries a
        # measured option it must not lose: d_s_mg_trampoline2.cpp is on /Zp4 at
        # the GATE 3 block above, which is what keeps its pointer-to-member at
        # the ROM's 0x5004 instead of four bytes late.
        foreach(_dsfi_one IN LISTS _dsfi_paths)
            set_property(SOURCE "${_dsfi_one}" APPEND PROPERTY COMPILE_OPTIONS
                "/FI${CMAKE_CURRENT_SOURCE_DIR}/hal/dsstate_all.h")
        endforeach()
    endforeach()
endif()

# ===========================================================================
# THE CONSOLIDATION GAP, BATCH 1 (run link100, lane SLICE1)
# ===========================================================================
#
# Translation units that exist in src/ on this branch, own at least one of the
# flat ROM names walk_window.exe reported unresolved in the first link after the
# main -> port sync, and are compiled by nothing at all: not on a slice list, not
# in a CMake block, not in a hostgen generation list. main's 2026-09
# consolidation folded one-function TUs into class TUs and the port never took
# the new files. 115 TUs qualified, 74 went on the list, MSVC refused two of
# those and the link showed sixteen more duplicating a body already in the
# build, so 56 rows are live and the other eighteen are commented out in place
# with their reason.
#
# The derivation is in port/slice_slice1.txt whole. The two things worth
# repeating here: liveness was read off walk_window OWN link line in
# build/port/build.ninja (8794 objects), not off the slice lists, and the
# duplicate check is per ROM symbol and definition-shaped, so a row is on this
# list only when nothing already on that link line defines any body inside it.
# Nothing is retired by this block and no host copy moves.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_slice1.txt" SLICE_SLICE1_LINES)
set(SLICE_SLICE1_SOURCES "")
foreach(line IN LISTS SLICE_SLICE1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SLICE1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# ---- run link100 lane MODESEL: THE TITLE MENU'S CELL SUBMITTER -------------
#
# THE SAME DEFECT THE TITLETEX BLOCK ABOVE FIXED, ON A TU THAT ARRIVED AFTER
# TITLETEX MEASURED ITS SET. src/func_ov007_020c4684.c is the routine the title
# screen and its menu page draw every cell through, and its literal pool is
# twelve geometry command ports and nothing else. TITLETEX's comment names it
# by address and says so; on that day it was still unmatched and the port drew
# through port/unmatched/Ov007_CellQuad_020c4684.cpp, a host transcription that
# reached the engine through NTR_MMIO. The match has since landed, the interim
# retired itself on SC1's own terms, and the matched TU joined walk_window
# through slice_slice1.txt -- BUILT PLAIN. Every store in it now latches a word
# into mapped memory and the geometry engine is never told.
#
# WHAT THAT COSTS, MEASURED ON THIS TREE rather than argued (lane MODESEL, the
# main menu after the title is touched; SM64DS_STAR_GEO's per-object census
# with this lane's DS-pixel rectangle):
#
#     obj0 verts=320 scale(1,1,1) trans(0.000 -0.184 -2.062)  ds 392.0 x 391.9
#     obj1 verts=160 scale(1,1,1) trans(-0.240 -0.184 -2.062) ds 392.0 x 391.9
#     obj2 verts=160 scale(1,1,1) trans(0.240 -0.184 -2.062)  ds 392.0 x 391.9
#     obj3 verts=64  scale(1,1,1) trans(0.275 0.194 -2.062)   ds 392.0 x 392.0
#
# Four menu panels, every one of them EXACTLY 392 by 392 DS pixels on a 256x192
# screen, each anchored at its own correct point: their rectangles start at DS x
# 34, 128, 222 and 236 and end at y 168, 168, 168 and 20, which are the centres
# of the ROM's OWN element boxes 1, 0, 2 and 7 (SM64DS_TITLE_ELEMS on the same
# frame). So the placement, the camera and the projection were all right and the
# panels were a UNIT QUAD DRAWN AT UNIT SIZE: 020c4684 pushes the matrix,
# translates by (vec - w/2, -h/2), scales by the cell's own WIDTH and HEIGHT
# read from self+0x20 and self+0x24, submits a unit quad through
# func_ov007_020c49bc -- which IS routed and DOES arrive -- and pops. The push,
# the translate, the scale and the pop are the four that do not arrive, so the
# quad keeps unit size and its anchor corner, and 1.0 model unit is 392 DS
# pixels under that scene's own projection.
#
# ppu_audit's command census is the independent witness: MTX_TRANS executed
# ZERO times in 600 frames of this scene, against three writes per cell and
# about fifty cells a frame.
#
# THE TREATMENT IS TITLETEX'S, unchanged: tools/hostgen.py rewrites the literal
# derefs to NTR_MMIO so each store dispatches through ntr::io_write, src/ is not
# edited and the TU stays byte-matched. Run standalone first and diffed: 25 MMIO
# rewrites, every one a geometry command port, and the two volatile reads of
# self+0x20 and self+0x24 left alone.
#
# IT IS CUT AND ADDED HERE rather than in TITLETEX's list because this row lives
# on slice_slice1.txt and TITLETEX's cut walks slice_ov007.txt only. Same block,
# same branch, so the cut cannot drift from the copy.
option(TITLEQUAD_GX_PLAIN
       "run link100 MODESEL: build ov007's cell submitter PLAIN (pre-fix arm)"
       OFF)
set(TITLEQUAD_SYM func_ov007_020c4684)
set(TITLEQUAD_GEN "")
set(TITLEQUAD_CUT 0)
if(NOT TITLEQUAD_GX_PLAIN)
    message(STATUS "TITLEQUAD: TITLEQUAD_GX_PLAIN=OFF -- ov007's cell "
                   "submitter routes through hostgen (shipped arm).")
    set(_tq_in "${PORT_REPO_ROOT_ABS}/src/${TITLEQUAD_SYM}.c")
    if(NOT EXISTS "${_tq_in}")
        set(_tq_in "${PORT_REPO_ROOT_ABS}/src/${TITLEQUAD_SYM}.cpp")
    endif()
    set(_tq_out "${CMAKE_BINARY_DIR}/host-src/src/${TITLEQUAD_SYM}.cpp")
    add_custom_command(OUTPUT "${_tq_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${TITLEQUAD_SYM}
        DEPENDS "${_tq_in}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${TITLEQUAD_SYM}")
    list(APPEND TITLEQUAD_GEN "${_tq_out}")
    set(_tq_keep "")
    foreach(src IN LISTS SLICE_SLICE1_SOURCES)
        if(src MATCHES "/${TITLEQUAD_SYM}\\.(c|cpp)$")
            math(EXPR TITLEQUAD_CUT "${TITLEQUAD_CUT}+1")
        else()
            list(APPEND _tq_keep "${src}")
        endif()
    endforeach()
    set(SLICE_SLICE1_SOURCES ${_tq_keep})
    if(NOT TITLEQUAD_CUT EQUAL 1)
        message(STATUS "TITLEQUAD: expected to cut 1 plain slice_slice1 row "
                       "for ${TITLEQUAD_SYM} and cut ${TITLEQUAD_CUT}. If the "
                       "row moved to another slice the hostgen copy is still "
                       "added and the link will say so as a duplicate; if it "
                       "left the build entirely the link will say undefined.")
    endif()
else()
    message(STATUS "TITLEQUAD: TITLEQUAD_GX_PLAIN=ON -- ov007's cell submitter "
                   "builds PLAIN. This is the PRE-FIX arm: MTX_PUSH, MTX_TRANS, "
                   "MTX_SCALE and MTX_POP latch in mapped memory and the "
                   "geometry engine is never told.")
endif()
foreach(_tslice1 walk_window walk_window_hires smoke_player)
    target_sources(${_tslice1} PRIVATE ${SLICE_SLICE1_SOURCES} ${TITLEQUAD_GEN})
endforeach()

# ===========================================================================
# THE CONSOLIDATION GAP, THE SEAT HALF (lane FACES2, the same sync)
# ===========================================================================
#
# Lane SLICE1's batch 1 continued, against the wall that is left after lane
# FACES1's 1464 generated faces. The rule is the same and so is the shape: a
# translation unit that exists in src/, owns at least one symbol walk_window
# still reports unresolved, and is compiled by nothing -- not on a slice list,
# not in a CMake block, not in a hostgen generation list, and not an object on
# walk_window's, walk_window_hires' or smoke_player's own link line.
#
# What is different is the COLLISION PREDICTION, which is per symbol and goes
# through the delinks rather than through a name grep: config/**/delinks.txt
# gives each src file its ROM address ranges, that module's symbols.txt names
# every function body inside them, and a candidate is on this list only when
# nothing already on the link line defines any of those bodies. 29 candidates
# fail that test and are NOT here even though they answer 464 rows between
# them; each needs a host copy retired or a hostgen substitution first and is
# listed with its colliding object in runs/link100/out/FACES2/slice_held.txt.
#
# The derivation is in port/slice_faces2.txt whole. Nothing is retired by this
# block and no host copy moves.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_faces2.txt" SLICE_FACES2_LINES)
set(SLICE_FACES2_SOURCES "")
foreach(line IN LISTS SLICE_FACES2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_FACES2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tfaces2 walk_window walk_window_hires smoke_player)
    target_sources(${_tfaces2} PRIVATE ${SLICE_FACES2_SOURCES})
endforeach()

# ===========================================================================
# SLICE HOSTGEN4 (run link100, lane HOSTGEN4)
# ===========================================================================
#
# One translation unit, src/actors/daMky_c.cpp, seated through the whole-TU
# hostgen substitution declared near the top of this file. It answers fourteen
# flat ROM names on walk_window's wall and had never been on a slice because
# MSVC refused it: eighteen C2556/C2371 pairs where a member's block-scope
# redeclaration disagrees with the TU's own file-scope spelling about a return
# type, and six C2624 where a function-local class is used to declare an
# extern. Nothing under src/ is touched; the repair is hostgen's
# REDECL_CONFLICT and ALTNAME tables. port/slice_hostgen4.txt carries the
# derivation, the fourteen rows it closes, the nine it costs and the collision
# measurement against walk_window's whole link universe.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_hostgen4.txt"
                SLICE_HOSTGEN4_LINES)
set(SLICE_HOSTGEN4_SOURCES "")
foreach(line IN LISTS SLICE_HOSTGEN4_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_HOSTGEN4_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
# Three ROM bodies that are in the binary under their MSVC-decorated spelling
# because their sources carry the decomp's //cpp marker and are compiled
# LANGUAGE CXX, while their callers are .c files asking for the flat ROM
# name. The file is three /alternatename directives and its own banner; it
# adds no body and no slice row. A second slice row was tried first and just
# compiled each object twice.
list(APPEND SLICE_HOSTGEN4_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/HostGen4_CxxNameBridges.cpp")
foreach(_thg4 walk_window walk_window_hires smoke_player)
    target_sources(${_thg4} PRIVATE ${SLICE_HOSTGEN4_SOURCES})
endforeach()

# run link100 wave 9b, lane DTORS-A -- THE INLINE-IN-HEADER DESTRUCTORS.
#
# 192 rows on walk_window's wall are flat Itanium destructor names whose owning
# src TU is already compiled into this binary and does not define them, because
# main's header declares the destructor inline (`virtual ~daCamTag_c() {}`).
# mwccarm emits the body out of line anyway, because the class's vtable odr-uses
# it; MSVC emits nothing, because the port's vtables are hand-written arrays in
# hal/actor_classes_*.cpp and nothing here odr-uses the destructor.  No slice row
# fixes that: what is missing is a definition, not a file.
#
# hal/dtor_forwarders_gen.cpp is that definition, generated by
# port/tools/dtorfwd.py: it includes the real header and defines each flat ROM
# name as a forwarder whose QUALIFIED call odr-uses the inline body, so MSVC
# emits it.  The ruling it exists under, and the ROM measurement behind it, are
# in port/tools/dtor_store_guard.py, which re-derives the measurement from
# extracted/ in the pre-configure guard wave on every build and refuses a class
# that flips.
#
# port/slice_dtors_a.txt carries the generated files themselves and no src rows,
# and its header says why: every owning src TU is already compiled into this
# binary, so nothing here is a seat.  There is more than one generated file
# because include/Stage.h and include/dScMgSingle3DBase_c.h each define struct
# Particle::SysTracker and cannot share a translation unit; tools/dtorfwd.py's
# SPLITS block carries that measurement and --verify refuses if the list stops
# naming exactly what the generator produces.
#
# WALK_WINDOW ONLY, on the port/slice_seat2.txt rule: the wall these rows were
# measured against is walk_window's own unresolved block, and a definition that
# has not been measured on a target does not belong on it.  walk_window_hires
# and smoke_player keep the rows they had.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_dtors_a.txt"
                SLICE_DTORS_A_LINES)
set(SLICE_DTORS_A_SOURCES "")
foreach(line IN LISTS SLICE_DTORS_A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_DTORS_A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
target_sources(walk_window PRIVATE ${SLICE_DTORS_A_SOURCES})


# ===========================================================================
# THE WAVE-9c DESTRUCTOR FORWARDERS (run link100 wave 9c, lane DTORS2)
# ===========================================================================
#
# Seventeen more flat Itanium destructor rows off walk_window's own wall, in one
# generated file beside lane DTORS-A's two.  Same generator (tools/dtorfwd.py),
# same guard (tools/dtor_store_guard.py), same PORT_HOST_ABI ruling; the file is
# separate so DTORS-A's two stay byte-identical through a rebase.
#
# Seven of the rows are DTORS-A's own premise and were simply out of reach when
# it ran: the class header spells the destructor inline and the owning src TU
# was not compiled at 8dc06444f.  Lanes SEATS2 and HOSTGEN4 have seated
# d_a_wanwan.cpp, daPkn_c.cpp and the three ov029 water TUs since.
#
# The other ten stand on the OUT-OF-LINE premise: the header only declares the
# destructor, the class's own per-function structor TU defines it, that TU is on
# a live slice row, so ??1<Cls>@@UAE@XZ is already in this link and the forwarder
# only CALLS it instead of making MSVC emit one.  out/SEATS2/seat_table.md is why
# compiling such a TU is not itself the answer: under MSVC it does not define its
# own flat ROM name, so seating one never closed the row it was seated for.
#
# WALK_WINDOW ONLY, on the slice_dtors_a.txt rule: the wall these rows were
# measured against is walk_window's own unresolved block.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_dtors2.txt"
                SLICE_DTORS2_LINES)
set(SLICE_DTORS2_SOURCES "")
foreach(line IN LISTS SLICE_DTORS2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_DTORS2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
target_sources(walk_window PRIVATE ${SLICE_DTORS2_SOURCES})


# ===========================================================================
# SEATS, BOTTOM-UP: GATE 3 (run link100 wave 9b, lane SEATS2, staged by INT3)
# ===========================================================================
#
# Two one-row seats a SOURCE-SIDE sweep found, and the name-bridge translation
# unit they need.  Neither goes through hostgen.  Gates 1 and 2 of that lane
# are not here: the coordinator's fold ruling seats gate 1's three consolidated
# actor TUs through lane HOSTGEN4 instead, and holds gate 2.  The rows and the
# bridges are reproduced from the lane's own commit b214e6def; see
# port/slice_seats2.txt for the derivation and the measured counts.
#
# All three hosting targets, not walk_window alone: nothing here is measured
# against one target's wall.  The seats define members, and the bridge file is
# /alternatename directives, which a linker that never sees the left-hand side
# simply does not fire.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_seats2.txt" SLICE_SEATS2_LINES)
set(SLICE_SEATS2_SOURCES "")
foreach(line IN LISTS SLICE_SEATS2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SEATS2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tseats2 walk_window walk_window_hires smoke_player)
    target_sources(${_tseats2} PRIVATE ${SLICE_SEATS2_SOURCES})
endforeach()

# ===========================================================================
# LANE SEATS3, run link100 wave 9c: the last four class/member seats
# ===========================================================================
#
# Four translation units on no live slice row and the name-bridge file they
# need. port/slice_seats3.txt carries the derivation and the measured counts
# per row; all four are also on PORT_HOSTGEN_TU at the top of this file, so
# port_read_lines rewrites each row to its generated path as the list is read
# and the raw text is never compiled.
#
# TWO OF THE FOUR ARE HALF OF A CORRECTNESS CHANGE and not only a count. The
# daGmch_c and daMip_c seats land in the same commit as the retirement of five
# rows in port/faces_sync.txt, because those five faces and the hand faces in
# port/hal/ called each other with no body at the bottom: Moneybag and MIPS
# each recursed until the stack ran out on the first call of their spawn path.
# Retiring a row alone leaves the decorated name undefined and seating alone is
# a duplicate symbol, so neither half stands without the other.
#
# The block goes on all three hosting targets rather than walk_window alone.
# Nothing here is measured against one target's wall, the seats define members
# every hosting target's vtables reach, and the bridge file holds
# /alternatename directives, which a link that never sees the left-hand side
# does not fire.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_seats3.txt" SLICE_SEATS3_LINES)
set(SLICE_SEATS3_SOURCES "")
foreach(line IN LISTS SLICE_SEATS3_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_SEATS3_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tseats3 walk_window walk_window_hires smoke_player)
    target_sources(${_tseats3} PRIVATE ${SLICE_SEATS3_SOURCES})
endforeach()



# ===========================================================================
# SLICE FACES4 (run link100, lane FACES4, wave 9c)
# ===========================================================================
#
# One host file, port/hal/faces4_rows.cpp, carrying thirty NAME rows of
# walk_window's wall: twenty-three destructor adapters the main -> port sync
# renamed on one side only, five ROM free functions a caller spells at C++
# linkage, and two real faces whose left hand sides are __thiscall. No src TU
# is compiled here and no ROM body enters the link because of it, so this is
# not a seat list. port/slice_faces4.txt carries the derivation and the file
# itself carries the evidence for every row, including what the tidy version of
# each looks like once a lane owns hal/dtor_faces_cpp.h and the fillers.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_faces4.txt"
                SLICE_FACES4_LINES)
set(SLICE_FACES4_SOURCES "")
foreach(line IN LISTS SLICE_FACES4_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_FACES4_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tfaces4 walk_window walk_window_hires smoke_player)
    target_sources(${_tfaces4} PRIVATE ${SLICE_FACES4_SOURCES})
endforeach()

# ===========================================================================
# SLICE INT4 (run link100 wave 9c, lane INT4, the fold)
# ===========================================================================
#
# Two per-function structor translation units nobody claimed, seated so lane
# DTORS2's out-of-line forwarder premise reaches KnockDownPlank and TowerStep.
# port/slice_int4.txt carries the derivation, the four rows it closes and the
# reason only one half of each D0/D1 pair goes on.
#
# walk_window alone, matching port/slice_dtors2.txt's own scope: the forwarders
# that call these definitions are on that target only.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_int4.txt" SLICE_INT4_LINES)
set(SLICE_INT4_SOURCES "")
foreach(line IN LISTS SLICE_INT4_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_INT4_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
target_sources(walk_window PRIVATE ${SLICE_INT4_SOURCES})


# ===========================================================================
# SLICE VTD1 (run link100 wave 14, lane SEAT14C, BATCH 2)
# ===========================================================================
#
# Vtable-held destructor pairs in small overlays. port/slice_vtd1.txt carries
# the per-row derivation, including the two rows of BATCH 2 that are REFUSED
# there rather than seated (daObjMaruta_c ov080 and daObjFallBlock_c ov098:
# both class tables are raw per-symbol data mounts whose slot-16 word is a DS
# code address, so there is no port slot to seat and no honest reference to
# give the body).
#
# ALL THREE HOSTING TARGETS, the slice_link21 shape and not slice_int4's.
# Measured, not assumed: hal/actor_classes_bowserpuzzle.cpp is compiled into
# port_slice_shared, which every one of the three executables links, so the
# slot-16 thunk's reference to ??1BowserPuzzleManager@@QAE@XZ appears on all
# three link lines. Seating the TU on walk_window alone built walk_window fine
# and broke walk_window_hires with LNK2019 on exactly that name (the first
# build of this batch, tmp/b2_build.log line 262).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_vtd1.txt" SLICE_VTD1_LINES)
set(SLICE_VTD1_SOURCES "")
foreach(line IN LISTS SLICE_VTD1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_VTD1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tvtd1 walk_window walk_window_hires smoke_player)
    target_sources(${_tvtd1} PRIVATE ${SLICE_VTD1_SOURCES})
endforeach()


# ===========================================================================
# SLICE OV2T (run link100 wave 14, lane SEAT14C, BATCH 6)
# ===========================================================================
#
# ov002 data-table roots. port/slice_ov2t.txt carries the per-row derivation
# and the three rows of BATCH 6 that are refused there rather than seated.
# The two rows here are CUTSCENE_OBJECT pointer-to-member state cells whose
# faces in hal/cutscene_states_link100.cpp were ST_FACEX aborts written when
# neither had a src file; both do now.
#
# ALL THREE HOSTING TARGETS, the slice_link21 shape and for the same reason as
# the slice_vtd1 block above: hal/cutscene_states_link100.cpp is compiled into
# port_slice_shared, so the two faces' references appear on every one of the
# three link lines.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_ov2t.txt" SLICE_OV2T_LINES)
set(SLICE_OV2T_SOURCES "")
foreach(line IN LISTS SLICE_OV2T_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_OV2T_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tov2t walk_window walk_window_hires smoke_player)
    target_sources(${_tov2t} PRIVATE ${SLICE_OV2T_SOURCES})
endforeach()


# ===========================================================================
# SLICE LINK21 (run link100 wave 9c, lane LINK21, the last lane before the link)
# ===========================================================================
#
# The two bannered NONMATCHING drafts main gained today, and this lane's own hal
# rows. port/slice_link21.txt carries the derivation, the four wall rows the two
# drafts close and the standalone-compile census taken before either went on a
# row.
#
# ALL THREE HOSTING TARGETS and not walk_window alone, unlike the slice_int4
# block above. Both drafts' four rows are on walk_window's, walk_window_hires's
# and smoke_player's LNK1120 blocks alike, and the two reverse faces that answer
# the flat half of each pair are rows in port/faces_sync.txt, which reaches all
# three targets. Seating the decorated half on one target only would leave the
# other two asking for a name the ledger's own face calls.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_link21.txt" SLICE_LINK21_LINES)
set(SLICE_LINK21_SOURCES "")
foreach(line IN LISTS SLICE_LINK21_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_LINK21_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tlink21 walk_window walk_window_hires smoke_player)
    target_sources(${_tlink21} PRIVATE ${SLICE_LINK21_SOURCES})
endforeach()

# ===========================================================================
# SLICE L15STALE (run link100 wave 15, lane SEAT15A, BATCH 1)
# ===========================================================================
#
# THE STALE-BANNER HARVEST, ROUND 2. Two port host copies whose own banners
# said "no matched TU of this name exists" while src/ on this tip has one.
# Same shape as the SLICE_W9HARVEST block above, one sync later:
#
#   src/func_ov060_021140c0.c            ov060 0x021140c0  matched 83691debd
#     retires unmatched/Ov060_StateDispatch.cpp's HOST COPY 7
#   src/_ZN13TreasureChest6State0Ev.cpp  ov064 0x0211a4c4  from 6e10cbbd1
#     retires unmatched/Ov064_TreasureChest.cpp's transcription; the flat name
#     stays in that file as a receiver face, because the matched TU is a
#     __thiscall member and the seat's thunk calls the flat C name
#
# port/slice_l15stale.txt carries the per-row derivation, the extern closure
# checked against this tree's own map before the edit, and the reach argument
# for each (a seat row that takes the body's address, in both cases).
#
# ALL THREE HOSTING TARGETS, like the SLICE_LINK21 block above: both host
# files are on walk_window's, walk_window_hires's and smoke_player's source
# lists, so a definition retired on one target and not the others would leave
# the other two asking for a name nothing defines.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_l15stale.txt" SLICE_L15STALE_LINES)
set(SLICE_L15STALE_SOURCES "")
foreach(line IN LISTS SLICE_L15STALE_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_L15STALE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tl15stale walk_window walk_window_hires smoke_player)
    target_sources(${_tl15stale} PRIVATE ${SLICE_L15STALE_SOURCES})
endforeach()

# ===========================================================================
# SLICE L15ENAB (run link100 wave 15, lane SEAT15A, BATCH 2)
# ===========================================================================
#
# THE NAMED-ENABLER ROWS. One slice row, one reference fix, and one enabler
# that turned out not to exist:
#
#   src/func_ov098_0213a794.cpp   ov098 0x0213a794. The host copy
#     unmatched/FallBlockWf_InitVeneer.cpp existed only because of a claimed
#     MSVC C2733 on the matched TU's second extern-C declaration. Re-measured
#     with this build's own command line the TU compiles clean, so the host
#     file is retired (its three target rows above are now comments) and the
#     matched TU rides here.
#
#   The ov006 dokan RestoreInitial row is NOT on this slice: it is already on
#   port/slice_smb.txt and only needed a reference, which hal/scene_mg.cpp's
#   smb_dok_s2 thunk now makes. Listing it twice would be LNK2005.
#
# port/slice_l15enab.txt carries both measurements, the symbol dumps and the
# reason the flat dokan name is still not defined anywhere.
#
# ALL THREE HOSTING TARGETS, because the retired host file was on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_l15enab.txt" SLICE_L15ENAB_LINES)
set(SLICE_L15ENAB_SOURCES "")
foreach(line IN LISTS SLICE_L15ENAB_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_L15ENAB_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tl15enab walk_window walk_window_hires smoke_player)
    target_sources(${_tl15enab} PRIVATE ${SLICE_L15ENAB_SOURCES})
endforeach()

# ===========================================================================
# R-L15B3 (run link100 wave 15, lane SEAT15A, BATCH 3): THE ov063 -> ov055
# CROSS-OVERLAY EDGE, resolved by disassembly. The 22nd symscope crossing.
# ===========================================================================
#
# THE AMBIGUITY. config/arm9/overlays/ov063/relocs.txt line 184 reads
#     from:0x02118004 kind:arm_call to:0x02111264 module:overlays(27,55)
# because ov027 and ov055 share one DS load window (both base 0x021111a0) and
# both name a symbol at 0x02111264:
#     ov027  _ZN10SlidingIce16CleanupResourcesEv  size 0x50, a __thiscall member
#     ov055  func_ov055_02111264                  size 0x24, void(void)
# src/unnamed/ov063/func_ov063_02117cdc.c (Boo's talk state, ov063
# 0x02117cdc) picked the ov027 spelling: it declares
# `extern void _ZN10SlidingIce16CleanupResourcesEv(void);` at line 25 and
# calls it at line 148.
#
# IT IS ov055, read off the cartridge. extracted/overlays/overlay_0063.bin at
# base 0x02115ee0 (never the dsd copy -- those are shifted) disassembles the
# site as
#     0x02117ff0  e1d000b0  ldrh  r0, [r0]
#     0x02117ff4  e350001e  cmp   r0, #0x1e
#     0x02117ff8  328dd01c  addlo sp, sp, #0x1c      (the early return)
#     0x02117ffc  38bd40f0  ldmlo sp!, {r4-r7, lr}
#     0x02118000  312fff1e  bxlo  lr
#     0x02118004  ebffe496  bl    0x02111264
# so at the call r0 holds a halfword that just tested >= 0x1e, not an object.
# SlidingIce::CleanupResources takes `this` in r0 and would be handed 0x1e or
# more as a receiver; func_ov055_02111264 takes nothing. The matched TU's own
# call site agrees -- `if (*(u16 *)(arg0 + 0x100) < 0x1e) return;` and then a
# call with no arguments. Two further marks in the same function's literal
# pool: 0x02118434 holds 0x02111b6c, inside ov055's bss window
# (0x02111b60..0x02111b80), whose reloc module column lists 55 and not 27; and
# the function calls func_0201277c, which is the one call
# src/func_ov055_02111264.c itself makes.
#
# WHAT THIS ROW DOES. A per-source rename, not an /alternatename, exactly like
# the d_a_obj_emm_log.cpp row above (ov052/ov056, the same overlapping-base
# name race): the ov027 name is a LIVE symbol in this build
# (?CleanupResources@SlidingIce@@UAEHXZ plus its flat face in
# hal/faces_sync_gen.cpp), so an alias would be defeated and would also be
# wrong -- both names are real, they just belong to different overlays.
# src/ is never edited; the defect is reported in out/SEAT15A/bugs.md.
#
# IT IS ALSO A LIVE DEFECT REMOVAL, not only a linkage row. The flat face for
# the ov027 name is a __cdecl body that reads its receiver from the first
# stack slot, and this caller pushes nothing, so before this row the Boo talk
# state called SlidingIce::CleanupResources on whatever happened to be at
# [esp+4] -- which then reads actorID off it and, on a match, calls
# dBgW::Disable through it. Afterwards it calls the 36-byte ov055 body the
# cartridge calls, which sets data_ov055_02111b68 to 2 and plays sound 0x179.
#
# It also gives src/func_ov055_02111264.c its first reference, so /OPT:REF
# stops stripping it: port/slice_sweep2_ov055.txt has carried that TU unlinked
# since the sweep-2 lane wrote "it becomes live the day that ov063 caller is
# seated", and this is that day.
set_source_files_properties(
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/unnamed/ov063/func_ov063_02117cdc.c"
    PROPERTIES COMPILE_DEFINITIONS
    "_ZN10SlidingIce16CleanupResourcesEv=func_ov055_02111264")




# LANE SMOKELINK2 (run link100 wave 10 round 2): walk_window_hires ALSO NEEDS
# THESE DEFINITIONS, and it has needed them since the 09-14 sync.
#
# The three blocks above each say WALK_WINDOW ONLY because the wall they were
# measured against was walk_window's own unresolved block.  That was true when
# each was written and it is no longer the whole picture: the REFERENCES that
# need these definitions live in hal/dtor_faces_cpp.cpp, hal/model_dtor_seat.cpp
# and the thirty-odd hal/actor_classes_*.cpp files, every one of which is on
# walk_window_hires as well.  The bodies went on one target and the callers went
# on two, so walk_window links and walk_window_hires has never linked since.
#
# MEASURED, per name, on the untouched baseline (79388ffe5, a full ninja -k 0
# over all targets, out/SMOKELINK2/build_smokelink2_0.log): walk_window_hires
# reports 321 unresolved externals, and all 321 are defined by these three
# slices and nothing else --
#   253  hal/dtor_forwarders_gen.cpp                 (SLICE_DTORS_A)
#     6  hal/dtor_forwarders_gen_stage.cpp           (SLICE_DTORS_A)
#    30  hal/dtor_forwarders_gen_w9c.cpp             (SLICE_DTORS2)
#     8  hal/dtor_forwarders_gen_w9c_structors.cpp   (SLICE_DTORS2)
#    18  hal/int4_rows.cpp, its own definitions      (SLICE_INT4)
#     5  hal/int4_rows.cpp, its /alternatename block at line 335 (the five
#        ArrowSignRight / Enemy / Particle spellings whose bodies are already
#        in this link through slice_gate10, 16, 29 and 32)
#     1  hal/int4_rows.cpp's flat face at its line 126,
#        __ZN22ExpandingHeapAllocator13DeallocateAllEPFvPvPS_jEj, which
#        hal/lk4_eh_dtor_seat.cpp:300 calls on all three targets.  It is the
#        only one of the 321 that walk_window.map does not print, so it reads
#        as missing everywhere; dumpbin /symbols on
#        build/port/CMakeFiles/walk_window.dir/hal/int4_rows.cpp.obj shows it
#        SECT22 External, which is what settles it.
#
# SLICE_SEAT2 IS DELIBERATELY NOT ADDED.  It is the fourth walk_window-only
# block and the obvious fourth row here, and it defines NONE of the 321:
# hal/vtables_seat2.cpp appears against zero of walk_window_hires' unresolved
# names.  Its own block states the rule -- a seat that has not been measured on
# a target does not belong on it -- and putting an unmeasured vtable word on
# this target would change what a live object dispatches and buy nothing.
#
# Nothing here is a new definition, a new seat or a keep-alive reference: every
# file already builds, already carries its own derivation and its own ROM
# evidence, and every one is already in walk_window's link.  This only makes
# the two window targets agree about which of them are present.
foreach(_tsmokelink2 walk_window_hires)
    target_sources(${_tsmokelink2} PRIVATE ${SLICE_DTORS_A_SOURCES}
                                           ${SLICE_DTORS2_SOURCES}
                                           ${SLICE_INT4_SOURCES})
endforeach()

# SMOKELINK5 (run link100 wave 10 round 5): smoke_player MEASURED against the
# same three slices, the way SMOKELINK2 measured walk_window_hires above.
# out/SMOKELINK5's classify.py run against smoke_player's own -k 0 residual
# (363 rows, 220 distinct names) reads walk_window.map's object column for
# every name and the overwhelming majority come back
# hal/dtor_forwarders_gen.cpp.obj -- the same file SMOKELINK2's block above
# measured as walk_window_hires' entire 253-row share. See
# out/SMOKELINK5/player_route.md for the per-name count this measured.
foreach(_tsmokeplayer smoke_player)
    target_sources(${_tsmokeplayer} PRIVATE ${SLICE_DTORS_A_SOURCES}
                                            ${SLICE_DTORS2_SOURCES}
                                            ${SLICE_INT4_SOURCES})
endforeach()

# SMOKELINK5: what SLICE_DTORS_A/DTORS2/INT4 and SLICE_FACES4 did not close.
# 363 -> 42 -> 5, measured round by round (out/SMOKELINK5/bugs.md). Two of
# the five (OAM::Render, and func_0205ff08/00/fbd0 that a first pass at
# func_0205f68c's own chain assumed were missing) turned out to already be on
# this target through port/slice_gate10.txt and port/slice_gate27.txt --
# adding them again read LNK2005, corrected by removing the duplicate. Left:
# func_0205f77c.cpp's own flat call, out/SMOKELINK3/next_targets.md's
# predicted one genuinely new pair for this target -- func_0205f68c and the
# two one-function dependencies its own body calls. func_0205f68c reaches
# data_020a8110, hal/boot2_ipc.cpp's own storage, already on this target
# (unlike the actor batch), so nothing further is needed for those three.
target_sources(smoke_player PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0205f68c.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0205fa78.c"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0205fab4.c"
    )

# SMOKELINK5B, run link100 wave 10 round 5: OAM::Render's YA (free-function)
# spelling closed. SMOKELINK5 measured that hal/sub_actors.cpp:1032's existing
# bridge (YA to the STATIC-MEMBER INT spelling) is unconditional and shared by
# all three targets that build the HUD, and that its right-hand side is only
# defined on the two walk_window targets (hal/stage_frame.cpp's own
# `int OAM::Render`, deliberately not on smoke_player -- see the GATE 220
# comment above). A second, competing /alternatename for the same LHS does not
# fire (tried and reverted; link.exe honours the first directive for an
# undefined symbol). hal/smoke_player_oam_bridge.cpp instead gives smoke_player
# its OWN copy of that same six-line forwarding body, so the EXISTING bridge
# resolves here without touching the shared file or the two targets that
# already pass through it. Full derivation in that file's own header.
target_sources(smoke_player PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/smoke_player_oam_bridge.cpp"
    )

# NOT PLACED, two names, pre-existing rather than introduced here:
#
# Stage::Behavior and Stage::Render (_ZN5StageD1Ev.cpp's own vtable fill, not
# a row remaining.md or next_targets.md named). Measured once: src/
# _ZN5Stage8BehaviorEv.cpp and src/_ZN5Stage6RenderEv.cpp's real bodies reach
# the pause screen, the vignette effect and the level-complete flow whole
# (PS_Cleanup/PS_Init/PS_Update/PS_Render, VE_Init/VE_Update, LC_Update/
# LC_Render, UpdateMessage, CanPause, IsPauseDisabled, RenderVsModeNewStar,
# RenderNumber and their own further calls), which this harness -- Mario
# standing for a BMP capture, by its own file header -- has never hosted.
#
# out/SMOKELINK5B/bugs.md carries this finding with the measured call list.


# ===========================================================================
# SLICE L15FS (run link100 wave 15, lane SEAT15C, LINK15 BATCH 2)
# ===========================================================================
#
# The arm9 SharedFilePtr / FS veneer family. port/slice_l15fs.txt carries the
# per-row re-read: every one of these was host-copied over an ARM register
# ride-through the matched source could not then spell, and every one of those
# sources now spells both arguments. The retired host bodies were in
# hal/cxx_aliases.cpp and hal/fs_names.cpp.
#
# ALL THREE HOSTING TARGETS, and it is measured rather than assumed. Both
# retired host files are on all three source lists -- hal/cxx_aliases.cpp is
# named literally in smoke_player's, walk_window's and walk_window_hires's, and
# hal/fs_names.cpp reaches the same three through NFS_NAMES_SOURCES -- and the
# call sites are the ov006 and ov080 static initialisers in SLICE_MG1_SOURCES,
# which is on all three as well. Seating the matched TUs on walk_window alone
# would take the flat names away from two targets that still reference them,
# which is exactly the shape the SMOKELINK2 banner above describes.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_l15fs.txt" SLICE_L15FS_LINES)
set(SLICE_L15FS_SOURCES "")
foreach(line IN LISTS SLICE_L15FS_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_L15FS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tl15fs walk_window walk_window_hires smoke_player)
    target_sources(${_tl15fs} PRIVATE ${SLICE_L15FS_SOURCES})
endforeach()

# ===========================================================================
# W23-4 OS ARENA (LINK15 batch W23-4)
# ===========================================================================
#
# Run linkfull wave 23, lane OSARENA1. Three NitroSDK OS arena accessors
# (func_02058eb4 OS_GetArenaHi, func_02058d58 OS_SetArenaLo, func_02058cd0
# OS_AllocFromArenaLo) run as the ROM's own bodies over the arena table in
# the shared system block, which ntr/io.cpp maps as a required region.
# hal/os_arena.cpp seeds the table's OS_ARENA_MAIN words from the port's own
# arena block at the first arena read. port/slice_w23_arena.txt carries the
# per-row ROM-address verification and the two rows that stay out.
#
# TWO PARTS, both scoped to the three hosting targets:
#   1. the slice rows, on all three (hal/os_arena.cpp is in the shared object
#      every one of them links, so the host bodies retire on all three);
#   2. SM64DS_OS_ARENA_ROM on hal/os_arena.cpp's compile for exactly those
#      targets. It is a SOURCE property keyed on the compiling target's name,
#      not a target definition, for two measured reasons: the slice-share
#      block above has already read the targets' COMPILE_DEFINITIONS by the
#      time this block runs (a target define here would never reach the
#      shared object that compiles this file), and a target define would
#      change the command line of every source the targets compile. The
#      fourteen smoke_* harnesses compile the same file WITHOUT it and keep
#      its host stand-ins: they do not take this slice, and smoke_roots and
#      smoke_fs link no ntr (no shared block under the table). The name list
#      includes port_slice_shared (the object library that compiles this file
#      once for all three) and the three targets themselves (the fallback when
#      the share is off and each compiles it on its own).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w23_arena.txt" SLICE_W23_ARENA_LINES)
set(SLICE_W23_ARENA_SOURCES "")
foreach(line IN LISTS SLICE_W23_ARENA_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W23_ARENA_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw23arena walk_window walk_window_hires smoke_player)
    target_sources(${_tw23arena} PRIVATE ${SLICE_W23_ARENA_SOURCES})
endforeach()
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/hal/os_arena.cpp" APPEND PROPERTY
    COMPILE_DEFINITIONS
    "$<$<IN_LIST:$<TARGET_PROPERTY:NAME>,port_slice_shared;walk_window;walk_window_hires;smoke_player>:SM64DS_OS_ARENA_ROM=1>")

# W23-6 HOSTGEN REFUSALS (LINK15 batch W23-6)
# ===========================================================================
# run linkfull wave 23, lane HGFRONT1. Four matched TUs whose host copies were
# held by a PORT_HOST_ABI tag naming an MSVC front-end refusal: three of those
# refusals are gone from the synced src, and the fourth is answered by
# tools/hostgen.py (its row is on PORT_HOSTGEN_TU near the top of this file).
# port/slice_w23_hostgen.txt carries the rows, the measurements and the two rows
# of the batch that stay out. The three targets are the three that compiled the
# host copies.
#
# ABOVE THE HOSTGEN COUNT ON PURPOSE: src/func_ov002_020f7780.c is a
# PORT_HOSTGEN_TU row and this slice is the only list that names it, so the
# count below has to see this port_read_lines call.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w23_hostgen.txt"
                SLICE_W23_HOSTGEN_LINES)
set(SLICE_W23_HOSTGEN_SOURCES "")
foreach(line IN LISTS SLICE_W23_HOSTGEN_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W23_HOSTGEN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw23hg walk_window walk_window_hires smoke_player)
    target_sources(${_tw23hg} PRIVATE ${SLICE_W23_HOSTGEN_SOURCES})
endforeach()


# MOVED BACK TO LAST IN THE FILE at the wave-9c fold (lane INT4). Its own banner
# below says every port_read_lines call has to be above it, and two blocks had
# landed underneath: lane FACES4's slice_faces4 block and this fold's slice_int4
# block. Neither names a PORT_HOSTGEN_TU row today, so the count was right by
# luck rather than by construction, and the invariant is cheaper to keep than to
# re-check every wave.
# ---- WHOLE-TU HOSTGEN SUBSTITUTION: THE COUNT ------------------------------
#
# Every substitution declared in PORT_HOSTGEN_TU near the top of this file has
# to have replaced at least one slice row.  A substitution that matched nothing
# generated a file no target compiles, which reads as green and ships the raw TU
# with the defect the substitution exists to remove.  This is the assertion that
# the FLW/BNT/TTE blocks make per slice, made once for the central mechanism.
#
# LAST IN THE FILE, run link100 lane HOSTGEN4. It used to sit beside the
# configure-deps summary, where it could only see the slice lists read above it,
# so a substitution named only by a late list read as "no slice row names it"
# and a substitution named by an early list AND a late one read as fully
# covered when the late list was still compiling the raw TU. Every
# port_read_lines call is above this point, so the count here is the whole
# count.
foreach(_hgt_rel IN LISTS PORT_HOSTGEN_TU)
    if(NOT DEFINED "PORT_HOSTGEN_TU_HITS_${_hgt_rel}")
        message(FATAL_ERROR "whole-TU hostgen: no hit counter for ${_hgt_rel}")
    endif()
    if("${PORT_HOSTGEN_TU_HITS_${_hgt_rel}}" EQUAL 0)
        message(FATAL_ERROR "whole-TU hostgen: no slice row names ${_hgt_rel}, "
                "so its generated copy is compiled by nothing and the raw TU "
                "would carry its defects into the link")
    endif()
    message(STATUS "HOSTGEN TU: ${_hgt_rel} substituted in "
                   "${PORT_HOSTGEN_TU_HITS_${_hgt_rel}} slice row(s)")
endforeach()

# ===========================================================================
# TAIL-PADDING HOST ABI (run link100, lane OVERRIDE24)
# ===========================================================================
#
# THE DEFECT. The Itanium ABI that mwccarm implements lets a derived class put
# its own fields in its base class's TAIL PADDING: it starts them at the base's
# DATA size. MSVC will not, and starts them at sizeof(base). dBgActor_c has a
# data size of 0x31e and a sizeof of 0x320, so every class below it starts its
# own fields two bytes high on the host, and alignment turns that into two or
# four bytes on every field the class owns. include/dBgActor_c.h states the rule
# itself under unk_31d and names daObjRc_Guruguru_c::mAngVelY as a class that
# relies on it. FaderColor has the same shape at 0x0e/0x10, and include/dWipe_c.h
# says in as many words that 0x0e/0x0f reuse FaderColor tail padding.
#
# CRASH8 found this on QuestionBlock, where the ROM own C factory constructed a
# ModelAnim at +0x320 and the C++ TUs reached it at +0x324, so the first question
# block the level loader spawned faulted on a null vtable pointer. TAILPAD and
# TAILPAD2 then closed 58 classes at source with a guarded filler. The 24 classes
# these rows serve cannot be closed that way: their first own field IS the field
# that lives in the tail padding, so there is no filler to delete.
#
# THE FIX is unmatched/dBgActor_c_TailPad_HostAbi.h and its FaderColor twin,
# which cap the base alignment so its sizeof equals its data size. Both headers
# carry the full reading. Measured per class with MSVC own
# /d1reportAllClassLayout: all 24 come back with every own field on the offset
# its header records and a total size equal to the header _size_must_be_ value.
#
# THE ROW LIST IS MEASURED, NOT COUNTED. out/TAILPAD2/remaining.tsv own_tus
# column is an undercount for all 24 (daObjWanwanShutter_c 1 against 5 real,
# Stump 18 against 25, dWipe_c 10 against 18): it counts the class own TUs and
# not the sibling TUs that also compute its offsets. Every C++ compile edge in
# build.ninja that names one of the 24 was compiled BOTH WAYS and kept only if
# the wrapper actually moves one of the 24 in it. That is CRASH8 eight-of-ten
# trap: a list built from the census column would have been green and wrong.
#
# FOUR TUs ARE DELIBERATELY NOT HERE, each with its reason:
#   build/port/host-src/faces_sync_gen.cpp REFUSES the header (it spells its own
#     method-only stubs for Model, dActor_c, dBgActor_c, fBase_c and FaderColor
#     instead of including them). It declares every one of the 24 at size 4 with
#     zero data members, so it computes no offsets and needs nothing.
#   hal/actor_classes_bob_world.cpp, hal/actor_classes_ov060.cpp and
#     hal/fwd_forwarders.cpp each carry a class the wrapper would move OFF the
#     cartridge layout (a subclass that adds no own fields keeps a sizeof rounded
#     to four, and capping the alignment would round it to two). Compiled both
#     ways to assembly, the ONLY differences in all three are the object own
#     TITLE line and the order of EXTRN declarations. Not one instruction moves,
#     so leaving them alone costs the 24 nothing and nothing is inconsistent.
#
# hal/dtor_forwarders_gen.cpp IS here although it carries fourteen such classes,
# and that is measured rather than argued: compiled both ways, all 46 changed
# assembly lines are `lea` member-address computations moving DOWN by four, in
# twenty destructor forwarders over eight classes. Seven of the eight are classes
# the wrapper puts back on the cartridge (PoleLift, dPathLiftActor_c,
# daObjPathLift_c, daObjRcCarpet_c, daObjKsWater_c, daObjMcWater_c,
# daObjTdWater_c) and the eighth is daObjFm_Battan_c. Not one of the fourteen
# emits a single layout-dependent instruction there, so its size changing in the
# report costs nothing, and those twenty forwarders stop destroying a sub-object
# four bytes past where it lives.
#
# APPEND, NEVER SET, the rule the /wd4716 loop and the DSSTATE block above both
# state: COMPILE_OPTIONS is one property and set_source_files_properties
# REPLACES it. One row here already carries another force-include,
# src/game/actors/d_a_obj_fm_battan.cpp on the DSSTATE list, and several are rows
# in PORT_FALLS_OFF_END_SOURCES.
#
# BOTH PATHS for every row, for the reason the DSSTATE block gives: a whole-TU
# hostgen substitution moves the compile and a per-source property does not
# follow it. Five of these rows compile from host-src today. A property on a path
# no target compiles is inert, so naming the generated twin unconditionally costs
# nothing.
set(PORT_TAILPAD_DBGACTOR_SOURCES
    port/hal/actor_classes.cpp
    port/hal/actor_classes_bob_enemy.cpp
    port/hal/actor_classes_jrb.cpp
    port/hal/actor_classes_l7.cpp
    port/hal/actor_classes_ov023.cpp
    port/hal/actor_classes_ov027.cpp
    port/hal/actor_classes_ov035.cpp
    port/hal/actor_classes_ov091.cpp
    port/hal/actor_classes_wf_enemy.cpp
    port/hal/dtor_forwarders_gen.cpp
    port/hal/except_faces.cpp
    src/_ZN10BrickBlock8BehaviorEv.cpp
    src/_ZN10LavaSeesaw13InitResourcesEv.cpp
    src/_ZN10LavaSeesaw16CleanupResourcesEv.cpp
    src/_ZN10LavaSeesaw6RenderEv.cpp
    src/_ZN10LavaSeesaw8BehaviorEv.cpp
    src/_ZN10LavaSeesawD1Ev.cpp
    # StarSwitch is a 25th class with the same defect and the list missed it,
    # because the list was built from the 24 and StarSwitch was not one of them.
    # Its first own field is pad_31e[2], which IS the field that lives in
    # dBgActor_c's tail padding, so without the wrapper every field it owns sits
    # four bytes high: InitResources wrote mEventBit at 0x352 while
    # BigBrickBlock::Behavior, which IS on this list, read it at the cartridge's
    # 0x34e. BigBrickBlock::Behavior asks FindWithActorID for star switches until
    # one answers with its own mEventID, and that is a do/while with no other
    # exit, so on level 35 it spun at 88% of one core forever with no fault and
    # no crash report. Render reads the same object's mTimer/mTimeLimit and had
    # the same split. Run link100, lane LEVELHANG.
    #
    # BOTH WAYS, the rule this block states: all seven rows below move under the
    # wrapper (InitResources 32 assembly lines, Behavior 30, the destructor pair
    # 12 each, CleanupResources 4, Render and OnGroundPounded 2), and every moved
    # line lands on the offset include/StarSwitch.h records. The other three TUs
    # that name StarSwitch were compiled both ways too and are deliberately NOT
    # here, because nothing in them moves: unmatched/ExclamationSwitch_StateDispatch.cpp,
    # hal/actorport_dtor_bridge.cpp and hal/actor_classes_bob_world.cpp, the last
    # of which this block already excludes by name.
    src/_ZN10StarSwitch13InitResourcesEv.cpp
    src/_ZN10StarSwitch15OnGroundPoundedER8dActor_c.cpp
    src/_ZN10StarSwitch16CleanupResourcesEv.cpp
    src/_ZN10StarSwitch6RenderEv.cpp
    src/_ZN10StarSwitch8BehaviorEv.cpp
    src/_ZN10StarSwitchD0Ev.cpp
    src/_ZN10StarSwitchD1Ev.cpp
    src/_ZN10SlidingIce13InitResourcesEv.cpp
    src/_ZN10SlidingIce15OnHitByMegaCharER6Player.cpp
    src/_ZN10SlidingIce16CleanupResourcesEv.cpp
    src/_ZN10SlidingIce6RenderEv.cpp
    src/_ZN10SlidingIce8BehaviorEv.cpp
    src/_ZN10SlidingIceD1Ev.cpp
    src/_ZN10daKpa2Bg_c13InitResourcesEv.cpp
    src/_ZN10daKpa2Bg_c16CleanupResourcesEv.cpp
    src/_ZN10daKpa2Bg_c6RenderEv.cpp
    src/_ZN10daKpa2Bg_c8BehaviorEv.cpp
    src/_ZN10daKpa2Bg_cD1Ev.cpp
    src/_ZN11VolcanoRing13InitResourcesEv.cpp
    src/_ZN11VolcanoRing16CleanupResourcesEv.cpp
    src/_ZN11VolcanoRing6RenderEv.cpp
    src/_ZN11VolcanoRing8BehaviorEv.cpp
    src/_ZN11VolcanoRingD1Ev.cpp
    src/_ZN12FortressWall13InitResourcesEv.cpp
    src/_ZN12FortressWall16CleanupResourcesEv.cpp
    src/_ZN12FortressWall24OnHitByCannonBlastedCharER8dActor_c.cpp
    src/_ZN12FortressWall4KillEv.cpp
    src/_ZN12FortressWall6RenderEv.cpp
    src/_ZN12FortressWall8BehaviorEv.cpp
    src/_ZN12FortressWallD1Ev.cpp
    src/_ZN13BigBrickBlock13InitResourcesEv.cpp
    src/_ZN13BigBrickBlock15OnGroundPoundedER8dActor_c.cpp
    src/_ZN13BigBrickBlock15OnHitByMegaCharER6Player.cpp
    src/_ZN13BigBrickBlock16CleanupResourcesEv.cpp
    src/_ZN13BigBrickBlock16HasNonzeroAngleXEv.cpp
    src/_ZN13BigBrickBlock17NotifyLinkedActorEv.cpp
    src/_ZN13BigBrickBlock4KillEv.cpp
    src/_ZN13BigBrickBlock6RenderEv.cpp
    src/_ZN13BigBrickBlock8BehaviorEv.cpp
    src/_ZN13BigBrickBlock8OnKickedER8dActor_c.cpp
    src/_ZN13BigBrickBlockD1Ev.cpp
    src/_ZN13TTC_MovingBar13InitResourcesEv.cpp
    src/_ZN13TTC_MovingBar16CleanupResourcesEv.cpp
    src/_ZN13TTC_MovingBar6RenderEv.cpp
    src/_ZN13TTC_MovingBarD1Ev.cpp
    src/_ZN16RotatingCogSmall13InitResourcesEv.cpp
    src/_ZN16RotatingCogSmall16CleanupResourcesEv.cpp
    src/_ZN16RotatingCogSmall6RenderEv.cpp
    src/_ZN16RotatingCogSmall8BehaviorEv.cpp
    src/_ZN16RotatingCogSmallD1Ev.cpp
    src/_ZN16SpinningPlatform11UpdateModelEv.cpp
    src/_ZN16SpinningPlatform12UpdateShadowEv.cpp
    src/_ZN16SpinningPlatform13InitResourcesEv.cpp
    src/_ZN16SpinningPlatform16CleanupResourcesEv.cpp
    src/_ZN16SpinningPlatform6RenderEv.cpp
    src/_ZN16SpinningPlatform8BehaviorEv.cpp
    src/_ZN16SpinningPlatformD1Ev.cpp
    src/_ZN17SlidingPlatformWf13InitResourcesEv.cpp
    src/_ZN17SlidingPlatformWf16CleanupResourcesEv.cpp
    src/_ZN17SlidingPlatformWf6RenderEv.cpp
    src/_ZN17SlidingPlatformWf8BehaviorEv.cpp
    src/_ZN17SlidingPlatformWfD1Ev.cpp
    src/_ZN5Stump13InitResourcesEv.cpp
    src/_ZN5Stump15OnGroundPoundedER8dActor_c.cpp
    src/_ZN5Stump15OnHitByMegaCharER6Player.cpp
    src/_ZN5Stump16CleanupResourcesEv.cpp
    src/_ZN5Stump6RenderEv.cpp
    src/_ZN5Stump8BehaviorEv.cpp
    src/_ZN5StumpD1Ev.cpp
    src/_ZN6ShipUp13InitResourcesEv.cpp
    src/_ZN6ShipUp16CleanupResourcesEv.cpp
    src/_ZN6ShipUp6RenderEv.cpp
    src/_ZN6ShipUp8BehaviorEv.cpp
    src/_ZN6ShipUpD1Ev.cpp
    src/_ZN9SeesawBob13InitResourcesEv.cpp
    src/_ZN9SeesawBob15OnGroundPoundedER8dActor_c.cpp
    src/_ZN9SeesawBob16CleanupResourcesEv.cpp
    src/_ZN9SeesawBob6RenderEv.cpp
    src/_ZN9SeesawBob8BehaviorEv.cpp
    src/_ZN9SeesawBobD1Ev.cpp
    src/actors/daObjCtMecha03_c.cpp
    src/actors/daObjFl_London_c.cpp
    src/game/actors/d_a_obj_bk_rotebar.cpp
    src/game/actors/d_a_obj_c0_switch.cpp
    src/game/actors/d_a_obj_emm_log.cpp
    src/game/actors/d_a_obj_fm_battan.cpp
    src/game/actors/d_a_obj_km1_ukishima.cpp
    src/game/actors/d_a_obj_rc_buranko.cpp
    src/game/actors/d_a_obj_rc_guruguru.cpp
    src/game/actors/d_a_obj_wanwan_shutter.cpp
    )
set(PORT_TAILPAD_FADERCOLOR_SOURCES
    src/_ZN7dWipe_c10SetToStartEv.cpp
    src/_ZN7dWipe_c11AdvanceFadeEv.cpp
    src/_ZN7dWipe_c14SetForwardTimeEj.cpp
    src/_ZN7dWipe_c20IsBetweenStartAndEndEv.cpp
    src/_ZN7dWipe_c7IsAtEndEv.cpp
    src/_ZN7dWipe_c8SetToEndEv.cpp
    src/_ZN7dWipe_c9IsAtStartEv.cpp
    src/_ZN7dWipe_cD1Ev.cpp
    )
if(MSVC)
    foreach(_tp_row IN ITEMS
            "dBgActor_c_TailPad_HostAbi.h;PORT_TAILPAD_DBGACTOR_SOURCES"
            "FaderColor_TailPad_HostAbi.h;PORT_TAILPAD_FADERCOLOR_SOURCES")
        list(GET _tp_row 0 _tp_hdr)
        list(GET _tp_row 1 _tp_list)
        if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/${_tp_hdr}")
            message(FATAL_ERROR "tail-padding host-ABI header is missing: "
                    "unmatched/${_tp_hdr}")
        endif()
        foreach(_tp_rel IN LISTS ${_tp_list})
            if(NOT EXISTS "${PORT_REPO_ROOT_ABS}/${_tp_rel}")
                message(FATAL_ERROR "tail-padding host-ABI row names a source "
                        "that does not exist: ${_tp_rel}")
            endif()
            set(_tp_paths "${PORT_REPO_ROOT_ABS}/${_tp_rel}")
            if(DEFINED PORT_HOSTGEN_TU_ROW_${_tp_rel})
                list(APPEND _tp_paths
                     "${PORT_REPO_ROOT_ABS}/${PORT_HOSTGEN_TU_ROW_${_tp_rel}}")
            endif()
            string(REGEX REPLACE "[.](c|cpp)$" ".cpp" _tp_gen "${_tp_rel}")
            list(APPEND _tp_paths "${CMAKE_BINARY_DIR}/host-src/${_tp_gen}")
            list(REMOVE_DUPLICATES _tp_paths)
            foreach(_tp_one IN LISTS _tp_paths)
                set_property(SOURCE "${_tp_one}" APPEND PROPERTY COMPILE_OPTIONS
                    "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/${_tp_hdr}")
            endforeach()
        endforeach()
    endforeach()
endif()

# ---- NARROW-RETURN PROBE (run rel042, lane NARROWRET1) ----------------------
# tools/hostgen.py's NARROW_RETURN wrappers report every call to
# port_narrowret_hook. hal/narrow_return.cpp defines it for walk_window and
# arms it only under SM64DS_NARROWRET=1 (a per-call-site count of the reads a
# wide caller got wrong, written out at exit); every other target that links
# a wrapper gets the null default the generated TUs carry by /alternatename.
target_sources(walk_window PRIVATE hal/narrow_return.cpp)


# ===========================================================================
# W23-3 STALE BANNERS 3 (LINK15 batch W23-3, run linkfull, lane BANNER3)
# ===========================================================================
#
# Six re-read rows from LINK15's stale-banner sweep; four seat here. The
# fifth (fdiv) does NOT seat -- BLOCKED, see hal/cstd_div.c's comment: its
# real TU is already real C++ (`namespace cstd { fdiv }`) and collides,
# LNK2005, with hal/reverse_bridges.cpp's now-redundant bridge of the same
# symbol, a file outside this lane's owned files. The sixth
# (func_020178b4) stays a host no-op on its own evidence. See
# hal/cxx_aliases.cpp and hal/cstd_div.c for the per-row comments and
# port/slice_w23_stale3.txt for the full per-row list, including the two
# not enrolled here.
#
# ONE TARGET SET, corrected by two failed builds rather than assumed the
# first time. hal/cxx_aliases.cpp (the four fileptr rows' old home) is
# target_sourced into exactly three targets: smoke_player, walk_window and
# walk_window_hires (measured by grep, not assumed).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w23_stale3.txt" SLICE_W23_STALE3_LINES)
set(SLICE_W23_STALE3_SOURCES "")
foreach(line IN LISTS SLICE_W23_STALE3_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W23_STALE3_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw23s3 smoke_player walk_window walk_window_hires)
    target_sources(${_tw23s3} PRIVATE ${SLICE_W23_STALE3_SOURCES})
endforeach()

# ===========================================================================
# W23-2 D0 ARM PILOT (LINK15 batch W23-2)
# ===========================================================================
#
# Run linkfull, lane D0ARM1. Five per-function src D0 TUs that define their own
# flat ROM name under MSVC now, through the Model family's `#ifdef _MSC_VER`
# arm, in place of the generated faces port/faces_sync.txt used to emit for
# them (those five D rows are retired in the same commit, so each flat name has
# exactly one definition). port/slice_w23_d0arm.txt carries the rows, the delete
# each arm makes and the byte gate.
#
# ALL THREE HOSTING TARGETS, the slice_vtd1 shape: faces_sync_gen.cpp.obj, which
# defined the five names, and the three hal files whose slot-17 thunks call them
# are on walk_window's, walk_window_hires' and smoke_player's link lines alike
# (build.ninja), so the retired faces must be answered on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w23_d0arm.txt" SLICE_W23_D0ARM_LINES)
set(SLICE_W23_D0ARM_SOURCES "")
foreach(line IN LISTS SLICE_W23_D0ARM_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W23_D0ARM_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw23d0 walk_window walk_window_hires smoke_player)
    target_sources(${_tw23d0} PRIVATE ${SLICE_W23_D0ARM_SOURCES})
endforeach()

# W23-5 IRQ TABLE (LINK15 batch W23-5)
# ---- run linkfull, lane IRQTAB1: the game's own interrupt registry ----------
# port/slice_w23_irq.txt names the matched IRQ::GetIRQHandler /
# IRQ::SetIRQHandler (and, from the second step, the IE-latch pair) and they
# go on the two GAME targets, the ones whose ntr library carries
# NTR_ROM_IRQ_TABLE below. With that define ntr/runtime.cpp stops defining the
# flat names, aliases them onto the matched C++ bodies, and dispatches HBlank
# and the geometry FIFO out of data_02099fe4, the ROM's vector table that
# hal/arm9_tables_link100.cpp already hosts on exactly these targets (the
# gate-225 block above). smoke_player also links that table but links the
# plain ntr library, which keeps the host copies, so it is left as it was: it
# gets neither the define nor the slice, and its registry stays one model.
#
# THE IE PAIR BUILDS FROM HOSTGEN COPIES, in this block's own custom commands
# (GATE4A's shape) rather than on PORT_HOSTGEN_TU, whose region belongs to
# another lane this wave: IRQ::EnableIRQs and IRQ::DisableIRQs poke IME and IE
# through literal casts, and the rewrite routes those through ntr/mmio.h the
# way IRQ::SetIRQs is routed for slice_link21.txt. A slice row named in
# W235_HOSTGEN_TU compiles its build/host-src copy and never the raw file.
set(W235_HOSTGEN_TU
    src/_ZN3IRQ10EnableIRQsEj.cpp
    src/_ZN3IRQ11DisableIRQsEj.cpp)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w23_irq.txt" SLICEW235_LINES)
set(SLICEW235_SOURCES "")
foreach(line IN LISTS SLICEW235_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(line IN_LIST W235_HOSTGEN_TU)
        set(_w235_out "${CMAKE_BINARY_DIR}/host-src/${line}")
        add_custom_command(OUTPUT "${_w235_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${line}
            DEPENDS "${PORT_REPO_ROOT_ABS}/${line}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${line}")
        list(APPEND SLICEW235_SOURCES "${_w235_out}")
    else()
        list(APPEND SLICEW235_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
    endif()
endforeach()
foreach(_tw235 walk_window walk_window_hires)
    target_sources(${_tw235} PRIVATE ${SLICEW235_SOURCES})
endforeach()
foreach(_lw235 ntr_wide_rt ntr_hires)
    target_compile_definitions(${_lw235} PRIVATE NTR_ROM_IRQ_TABLE)
endforeach()

# ===========================================================================
# CAMP1 D0 ARM CAMPAIGN (run linkfull, batches D0ARM-01/02/03)
# ===========================================================================
#
# Run linkfull, lane CAMP1. The remaining per-function src D0 TUs from the
# reviewed-safe campaign plan (out/D0ARM1/campaign_recipe.txt,
# campaign_batches.txt) that now define their own flat ROM name under MSVC,
# through the Model family's `#ifdef _MSC_VER` arm, in place of the generated
# faces port/faces_sync.txt used to emit for them (those D rows are retired
# in the same commits, so each flat name has exactly one definition).
# port/slice_w24_camp1.txt carries the rows.
#
# ALL THREE HOSTING TARGETS, the slice_vtd1 shape: faces_sync_gen.cpp.obj,
# which defined these names, and the three hal files whose slot-17 thunks
# call them are on walk_window's, walk_window_hires' and smoke_player's link
# lines alike (build.ninja), so the retired faces must be answered on all
# three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w24_camp1.txt" SLICE_W24_CAMP1_LINES)
set(SLICE_W24_CAMP1_SOURCES "")
foreach(line IN LISTS SLICE_W24_CAMP1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W24_CAMP1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw24camp1 walk_window walk_window_hires smoke_player)
    target_sources(${_tw24camp1} PRIVATE ${SLICE_W24_CAMP1_SOURCES})
endforeach()

# ===========================================================================
# W24 CAMP2 D0 ARM CAMPAIGN (batches D0ARM-04, D0ARM-05, D0ARM-06)
# ===========================================================================
#
# Run linkfull, lane CAMP2, following the D0-arm campaign recipe banked by
# lane D0ARM1 (reviewed SAFE by REVD0ARM1). Per-function src D0 TUs across
# overlays ov019-ov026, ov027-ov060 and ov062-ov065 that now define their own
# flat ROM name under MSVC, through the Model family's `#ifdef _MSC_VER` arm,
# in place of the generated faces port/faces_sync.txt used to emit for them
# (each retired D row is commented out in the same commit that adds the file
# here, so each flat name has exactly one definition). port/slice_w24_camp2.txt
# carries the rows, grown by one section per batch; the delete each arm makes
# and the byte gate are recorded there and in this lane's own status/out files.
#
# ALL THREE HOSTING TARGETS, the slice_w23_d0arm shape: faces_sync_gen.cpp.obj,
# which defined these names, and the three hal files whose slot-17 thunks call
# them are on walk_window's, walk_window_hires' and smoke_player's link lines
# alike (build.ninja), so the retired faces must be answered on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w24_camp2.txt" SLICE_W24_CAMP2_LINES)
set(SLICE_W24_CAMP2_SOURCES "")
foreach(line IN LISTS SLICE_W24_CAMP2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W24_CAMP2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw24camp2 walk_window walk_window_hires smoke_player)
    target_sources(${_tw24camp2} PRIVATE ${SLICE_W24_CAMP2_SOURCES})
endforeach()

# ===========================================================================
# W24 CAMP3 D0 ARM CAMPAIGN (LINK15 batches D0ARM-07/08/09)
# ===========================================================================
#
# Run linkfull, lane CAMP3. Continues D0ARM1's pilot (reviewed PASS by
# REVD0ARM1, campaign_recipe.txt / campaign_batches.txt): per-function src D0
# TUs across ov066..ov102 that now define their own flat ROM name under MSVC
# through the Model family's `#ifdef _MSC_VER` arm (qualified call -- main's
# headers declare these destructors virtual), in place of the generated faces
# port/faces_sync.txt used to emit for them. port/slice_w24_camp3.txt carries
# the rows, appended one batch's checkpoint commit at a time.
#
# ALL THREE HOSTING TARGETS, the same slice_vtd1 shape D0ARM1 used:
# faces_sync_gen.cpp.obj (which defined these flat names) and the three hal
# files whose slot-17 thunks call them are on walk_window's, walk_window_hires'
# and smoke_player's link lines alike (checked against build.ninja per batch).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w24_camp3.txt" SLICE_W24_CAMP3_LINES)
set(SLICE_W24_CAMP3_SOURCES "")
foreach(line IN LISTS SLICE_W24_CAMP3_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W24_CAMP3_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw24camp3 walk_window walk_window_hires smoke_player)
    target_sources(${_tw24camp3} PRIVATE ${SLICE_W24_CAMP3_SOURCES})
endforeach()

# W24 FACEFLIP1 (run linkfull wave 24, lane FACEFLIP1)
# ===========================================================================
# Matched TUs that a FORWARD row in port/faces_sync.txt held out of the link:
# each of those rows is flipped to REVERSE and its host copy retired, so the
# matched body runs as the game's own code. port/slice_w24_faceflip.txt
# carries the rows and the evidence. All three targets take them, because the
# reverse faces that define the flat names are in ${PORT_FACES_SYNC_GEN},
# which all three link, and each face calls the member these TUs define. The
# slice names no PORT_HOSTGEN_TU row, so sitting below the hostgen count (as
# the other end-of-file blocks do) leaves that count whole.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w24_faceflip.txt" SLICE_W24_FACEFLIP_LINES)
set(SLICE_W24_FACEFLIP_SOURCES "")
foreach(line IN LISTS SLICE_W24_FACEFLIP_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W24_FACEFLIP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_w24ff_t walk_window walk_window_hires smoke_player)
    target_sources(${_w24ff_t} PRIVATE ${SLICE_W24_FACEFLIP_SOURCES})
endforeach()

# ===========================================================================
# D0ARM10 THE REFUSED D0 ROWS (run linkfull, lane D0ARM10)
# ===========================================================================
#
# Run linkfull, lane D0ARM10. Per-function src D0 TUs the D0-arm campaign's
# generator had refused on a shape check (out/D0ARM1/refusal_groups.txt),
# armed by hand with the campaign's `#ifdef _MSC_VER` shape and gated per
# file. Each now defines its own flat ROM name under MSVC in place of the
# generated face port/faces_sync.txt used to emit for it (those D rows are
# retired in the same commits, so each flat name has exactly one
# definition). port/slice_w25_d0arm10.txt carries the rows.
#
# ALL THREE HOSTING TARGETS, the campaign's shape: faces_sync_gen.cpp.obj,
# which defined these names, is on walk_window's, walk_window_hires' and
# smoke_player's link lines alike (build.ninja), so the retired faces must
# be answered on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w25_d0arm10.txt" SLICE_W25_D0ARM10_LINES)
set(SLICE_W25_D0ARM10_SOURCES "")
foreach(line IN LISTS SLICE_W25_D0ARM10_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W25_D0ARM10_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw25d0arm10 walk_window walk_window_hires smoke_player)
    target_sources(${_tw25d0arm10} PRIVATE ${SLICE_W25_D0ARM10_SOURCES})
endforeach()
# THE ONE PER-SOURCE PROPERTY IN THIS BLOCK. src/_ZN13QuestionBlockD0Ev.cpp
# compiles under the same force-included host-ABI view as every other
# QuestionBlock TU the port links: the PORT_QUESTIONBLOCK_HOSTABI_SOURCES
# block above says to add the D0 "if it is ever compiled", and it is now.
# Under that view the class's destructor is ??1QuestionBlock@@UAE@XZ, the
# name its D1 file's object defines and the arm's qualified call reaches.
# APPEND, never SET, for the reason that block gives.
set_property(SOURCE "${PORT_REPO_ROOT_ABS}/src/_ZN13QuestionBlockD0Ev.cpp"
    APPEND PROPERTY COMPILE_OPTIONS
    "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/QuestionBlock_HostAbi.h")

# W25 PMFMG1 (run linkfull wave 25): the minigame member-pointer rows
# ---- run linkfull, lane PMFMG1 ----------------------------------------------
# port/slice_w25_pmfmg1.txt names eleven matched minigame state dispatchers
# whose host copies this lane retired: each table or field pair run they read
# is seated with host words at overlay load by the class's own installer in
# port/unmatched/ (the slice file names the file per row), so the ROM's own
# compiled dispatch reaches a host body. They go on the three targets that
# carry the minigame stack (SCENE_MG_SOURCES and the per-class slices).
#
# TWO ROWS BUILD FROM HOSTGEN COPIES in this block's own custom commands (the
# W235 / GATE4A shape, not PORT_HOSTGEN_TU, whose region belongs to another
# lane): src/func_ov006_020c8f20.cpp and src/func_ov006_020cb030.cpp each
# redeclare two members at namespace scope, which MSVC refuses as C2761, and
# port/tools/hostgen.py's MEMBER_REDECL rows for exactly those two files delete
# the redeclarations. A slice row named in W25MG_HOSTGEN_TU compiles its
# build/host-src copy and never the raw file.
set(W25MG_HOSTGEN_TU
    src/func_ov006_020c8f20.cpp
    src/func_ov006_020cb030.cpp)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w25_pmfmg1.txt" SLICEW25MG_LINES)
set(SLICEW25MG_SOURCES "")
foreach(line IN LISTS SLICEW25MG_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(line IN_LIST W25MG_HOSTGEN_TU)
        set(_w25mg_out "${CMAKE_BINARY_DIR}/host-src/${line}")
        add_custom_command(OUTPUT "${_w25mg_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${line}
            DEPENDS "${PORT_REPO_ROOT_ABS}/${line}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${line}")
        list(APPEND SLICEW25MG_SOURCES "${_w25mg_out}")
    else()
        list(APPEND SLICEW25MG_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
    endif()
endforeach()
foreach(_tw25mg walk_window walk_window_hires smoke_player)
    target_sources(${_tw25mg} PRIVATE ${SLICEW25MG_SOURCES})
endforeach()

# ===========================================================================
# VARIANT2 (run linkfull, lane VARIANT2): D0 FILES A dtorfwd FORWARDER ANSWERED
# ===========================================================================
#
# port/slice_w26_variant2.txt carries per-function src D0 TUs whose flat ROM
# name port/tools/dtorfwd.py used to generate as a forwarder
# (hal/dtor_forwarders_gen_w9c.cpp). Each file defines that name itself now, in
# its `#ifdef _MSC_VER` arm, and the forwarder row is retired in the same
# commit, so each flat name has exactly one definition.
#
# ALL THREE HOSTING TARGETS: the generated forwarders, and the hal tables and
# thunks that call these names, are on walk_window's, walk_window_hires' and
# smoke_player's link lines alike (build.ninja), so the retired forwarders
# must be answered on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w26_variant2.txt" SLICE_W26_VARIANT2_LINES)
set(SLICE_W26_VARIANT2_SOURCES "")
foreach(line IN LISTS SLICE_W26_VARIANT2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W26_VARIANT2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw26v2 walk_window walk_window_hires smoke_player)
    target_sources(${_tw26v2} PRIVATE ${SLICE_W26_VARIANT2_SOURCES})
endforeach()

# ===========================================================================
# V3A (run linkfull, lane V3A): THE ADJUSTOR-THUNK ROWS
# ===========================================================================
#
# port/slice_w27_v3a.txt carries the per-function src TUs of the ROM's
# this-adjusting destructor thunks (_ZThn<N>_...). Each file's `#ifdef
# _MSC_VER` arm defines only the flat thunk name, and the port's copy of the
# ROM secondary vtable that holds the thunk names it from the ROM's slot.
#
# ALL THREE HOSTING TARGETS: the tables' fills (hal/w2_dtor_heads.cpp,
# hal/cxxname_bridge.cpp, hal/blend_vtable.cpp) are on walk_window's,
# walk_window_hires' and smoke_player's link lines alike (build.ninja).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w27_v3a.txt" SLICE_W27_V3A_LINES)
set(SLICE_W27_V3A_SOURCES "")
foreach(line IN LISTS SLICE_W27_V3A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W27_V3A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw27v3a walk_window walk_window_hires smoke_player)
    target_sources(${_tw27v3a} PRIVATE ${SLICE_W27_V3A_SOURCES})
endforeach()
# smoke_modelanim links hal/blend_vtable.cpp, whose fill names the two
# BlendModelAnim thunks, and its own flat BlendModelAnim D0 / D1 (the
# ModelBaseModelBlend host copy), so it takes those two thunk TUs as well.
target_sources(smoke_modelanim PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZThn80_N14BlendModelAnimD0Ev.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZThn80_N14BlendModelAnimD1Ev.cpp")

# ===========================================================================
# RUN LINKFULL WAVE 27, LANE V3B: THE VARIANT ROWS THAT WAITED ON HAL FILES
# ===========================================================================
#
# port/slice_w27_v3b.txt carries per-function src destructor TUs that now
# define the ROM's flat name themselves, in their `#ifdef _MSC_VER` arm, where
# a hand-written host body used to (the slice's header names each one and
# what it replaced). Each flat name keeps exactly one definition.
#
# ALL THREE HOSTING TARGETS: the hal tables and host files that call these
# names are on walk_window's, walk_window_hires' and smoke_player's link lines
# alike (build.ninja: port_slice_shared and int4_rows.cpp), so the names must
# be answered on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w27_v3b.txt" SLICE_W27_V3B_LINES)
set(SLICE_W27_V3B_SOURCES "")
foreach(line IN LISTS SLICE_W27_V3B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W27_V3B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw27v3b walk_window walk_window_hires smoke_player)
    target_sources(${_tw27v3b} PRIVATE ${SLICE_W27_V3B_SOURCES})
endforeach()

# ===========================================================================
# PMF2 (run linkfull, lane PMF2): MEMBER-POINTER ROWS, SECOND WAVE
# ===========================================================================
#
# port/slice_w27_pmf2.txt carries the matched TUs this lane arms. A line whose
# path is followed by the word `hostgen` compiles its build/host-src copy made
# by port/tools/hostgen.py (the W25MG / GATE35 shape: a custom command per row,
# output under host-src with a .cpp suffix) and never the raw file; every other
# line compiles as it stands, and a raw path keeps whatever per-source property
# an earlier block set on it.
#
# ALL THREE HOSTING TARGETS: each armed TU replaces a host copy that
# walk_window, walk_window_hires and smoke_player all link today, so all three
# take the slice.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w27_pmf2.txt" SLICE_W27_PMF2_LINES)
set(SLICE_W27_PMF2_SOURCES "")
foreach(line IN LISTS SLICE_W27_PMF2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(line MATCHES "^(src/[^ ]+)[ ]+hostgen$")
        set(_w27pmf2_src "${CMAKE_MATCH_1}")
        string(REGEX REPLACE "\\.c$" ".cpp" _w27pmf2_rel "${_w27pmf2_src}")
        set(_w27pmf2_out "${CMAKE_BINARY_DIR}/host-src/${_w27pmf2_rel}")
        add_custom_command(OUTPUT "${_w27pmf2_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${_w27pmf2_src}
            DEPENDS "${PORT_REPO_ROOT_ABS}/${_w27pmf2_src}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${_w27pmf2_src}")
        list(APPEND SLICE_W27_PMF2_SOURCES "${_w27pmf2_out}")
    else()
        list(APPEND SLICE_W27_PMF2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
    endif()
endforeach()
foreach(_tw27pmf2 walk_window walk_window_hires smoke_player)
    target_sources(${_tw27pmf2} PRIVATE ${SLICE_W27_PMF2_SOURCES})
endforeach()

# ===========================================================================
# S1 (run linkfull wave 27, lane S1): THE CLOSESTPLAYER RECEIVER FAMILY,
# THE FIRST MAIN -> PORT FILE SYNC
# ===========================================================================
#
# port/slice_w28_s1.txt seats five matched TUs whose host copies are retired
# in the same commit (port/unmatched/Actor_ClosestPlayerWrappers.cpp keeps only
# the IsPlayerInRange(s32) bridge and the Vector3 overload;
# port/unmatched/Book_WindowAndReceiverFixes.cpp defines nothing now). The two
# arm9 members' flat ROM names are carried by reverse faces in
# port/faces_sync.txt.
#
# ALL THREE HOSTING TARGETS: the retired host copies were linked into
# walk_window, walk_window_hires and smoke_player alike (SLICE16_SOURCES and
# SLICE_W5A_SOURCES ship on all three), and so is faces_sync_gen.cpp, whose
# reverse faces now call these members, so the seats must be on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w28_s1.txt" SLICE_W28_S1_LINES)
set(SLICE_W28_S1_SOURCES "")
foreach(line IN LISTS SLICE_W28_S1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W28_S1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw28s1 walk_window walk_window_hires smoke_player)
    target_sources(${_tw28s1} PRIVATE ${SLICE_W28_S1_SOURCES})
endforeach()

# ===========================================================================
# PSYCHE1 (run linkfull, lane PSYCHE1): THE MINIGAME EXIT PATH -- its
# force-included seam on src/minigames/d_s_mg_base.cpp
# (unmatched/MgBase_Slot5_HostAbi.h) is RETIRED (run linkfull, lane RS2PORT):
# the TU passes func_0203cbc0 the block it frees itself now (main
# 59013376ce's one call), so the rename, its configure check and the /FI
# are gone. PSYCHE1's other three fixes need no CMake.
# ===========================================================================

# ===========================================================================
# RS2PORT (run linkfull, lane RS2PORT): MAIN'S ARGUMENT RE-SPELLS (#3092) INTO
# THE PORT, AND THE ROWS WHOSE HOST REASONS WERE STALE
# ===========================================================================
#
# port/slice_w28_rs2port.txt seats matched TUs whose host copies are retired
# in the same commits; each row group's commit says which body left and why its
# reason no longer holds.
#
# ALL THREE HOSTING TARGETS: the host copies these rows retire were linked
# into walk_window, walk_window_hires and smoke_player alike
# (CAMERA_HOST_SOURCES, SLICE_PTR_SOURCES and unmatched/Particle_RideThroughs.cpp
# ship on all three), so the seats are on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w28_rs2port.txt" SLICE_W28_RS2PORT_LINES)
set(SLICE_W28_RS2PORT_SOURCES "")
foreach(line IN LISTS SLICE_W28_RS2PORT_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W28_RS2PORT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
if(SLICE_W28_RS2PORT_SOURCES)
    foreach(_tw28rs2 walk_window walk_window_hires smoke_player)
        target_sources(${_tw28rs2} PRIVATE ${SLICE_W28_RS2PORT_SOURCES})
    endforeach()
endif()

# RS2PORT row group 2: func_0203cbc0, the ROM veneer onto _ZdlPv. Its host
# body lived in unmatched/func_02073244_hostcopy.c because src spelled it
# (void); main 59013376ce spells the pointer it frees, so the body left that
# file (which still defines the DS global data_0209a6fc and stays on every
# list that names it) and src/func_0203cbc0.c joins every target that
# compiles it: the three game targets (SLICE31_SOURCES, or the shared object
# library when the tier split put it there) and the smoke targets
# (smoke_modelanim's own block, smoke_model's, PORT_SMOKE_MODEL_SRC's five and
# smoke_clsn). Read off the targets rather than listed, so a target that
# takes the host file later still gets the veneer it used to carry.
get_property(_rs2_all_targets DIRECTORY PROPERTY BUILDSYSTEM_TARGETS)
set(_rs2_cbc0_into "")
foreach(_rs2_t IN LISTS _rs2_all_targets)
    get_target_property(_rs2_type ${_rs2_t} TYPE)
    if(_rs2_type STREQUAL "INTERFACE_LIBRARY" OR _rs2_type STREQUAL "UTILITY")
        continue()
    endif()
    get_target_property(_rs2_srcs ${_rs2_t} SOURCES)
    if(_rs2_srcs MATCHES "unmatched/func_02073244_hostcopy[.]c")
        target_sources(${_rs2_t} PRIVATE
            "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0203cbc0.c")
        list(APPEND _rs2_cbc0_into ${_rs2_t})
    endif()
endforeach()
if(NOT _rs2_cbc0_into)
    message(FATAL_ERROR "no target compiles unmatched/func_02073244_hostcopy.c "
            "any more, so src/func_0203cbc0.c reached none; re-read this block")
endif()
message(STATUS "RS2PORT: src/func_0203cbc0.c joins ${_rs2_cbc0_into}")

# ===========================================================================
# W27 SMALLS1 (run linkfull wave 27, lane SMALLS1): cstd::fdiv,
# IRQ::ClearInterrupts, OS_GetArenaLo, OS_InitAlloc
# ===========================================================================
#
# port/slice_w27_smalls1.txt carries the rows. A row goes on all three hosting
# targets (walk_window, walk_window_hires, smoke_player) unless it is named in
# W27S_GAME_ONLY (the two game targets whose ntr library carries
# NTR_ROM_IRQ_TABLE: IRQTAB1's W23-5 shape); a row named in W27S_HOSTGEN_TU
# compiles its build/host-src copy (hostgen routes its register stores through
# ntr/mmio.h into ntr/io.cpp's io_write) and never the raw file.
#
# cstd::fdiv: src/_ZN4cstd4fdivEii.cpp defines ?fdiv@cstd@@YAHHH@Z;
# hal/reverse_bridges.cpp (compiled on exactly the three targets) aliases the
# flat name onto it; hal/cstd_div.c's host body is compiled out on the same
# three by SM64DS_PORT_FDIV_SEATED (a per-target generator expression, the
# W23-4 os_arena.cpp shape; the three compile it once, in the shared object
# library port_slice_shared), so it stays only on the six narrow harnesses
# that link no divider model.
#
# IRQ::ClearInterrupts: the two game targets only, from its hostgen copy, so
# its IME / IF stores reach ntr/io.cpp's io_write (IF clears
# write-one-to-clear there); ntr/runtime.cpp aliases the flat name onto it on
# the NTR_ROM_IRQ_TABLE libraries and keeps the no-op for the smoke probes.
#
# OS_GetArenaLo (func_02058ea0): all three targets, the W23-4 arena rows'
# set; hal/os_arena.cpp's host copy under SM64DS_OS_ARENA_ROM is retired and
# the table's seed runs at OS_InitArena's point (hal/boot_os.cpp's pre-main,
# smoke_player's main).
#
# OS_InitAlloc (func_02059040): the same three targets; its SM64DS_OS_ARENA_ROM
# stand-in in hal/os_arena.cpp is retired, so the root heap starts 0x60 into
# the arena (the heap-info block the SDK writes at the base), the
# cartridge's own layout.
set(W27S_GAME_ONLY
    src/_ZN3IRQ15ClearInterruptsEj.cpp)
set(W27S_HOSTGEN_TU
    src/_ZN3IRQ15ClearInterruptsEj.cpp)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w27_smalls1.txt" SLICE_W27S_LINES)
set(SLICE_W27S_ALL3 "")
set(SLICE_W27S_GAME "")
foreach(line IN LISTS SLICE_W27S_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(line IN_LIST W27S_HOSTGEN_TU)
        set(_w27s_src "${CMAKE_BINARY_DIR}/host-src/${line}")
        add_custom_command(OUTPUT "${_w27s_src}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${line}
            DEPENDS "${PORT_REPO_ROOT_ABS}/${line}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${line}")
    else()
        set(_w27s_src "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
    endif()
    if(line IN_LIST W27S_GAME_ONLY)
        list(APPEND SLICE_W27S_GAME "${_w27s_src}")
    else()
        list(APPEND SLICE_W27S_ALL3 "${_w27s_src}")
    endif()
endforeach()
if(SLICE_W27S_ALL3)
    foreach(_tw27s walk_window walk_window_hires smoke_player)
        target_sources(${_tw27s} PRIVATE ${SLICE_W27S_ALL3})
    endforeach()
endif()
if(SLICE_W27S_GAME)
    foreach(_tw27s walk_window walk_window_hires)
        target_sources(${_tw27s} PRIVATE ${SLICE_W27S_GAME})
    endforeach()
endif()
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/hal/cstd_div.c" APPEND PROPERTY
    COMPILE_DEFINITIONS
    "$<$<IN_LIST:$<TARGET_PROPERTY:NAME>,port_slice_shared;walk_window;walk_window_hires;smoke_player>:SM64DS_PORT_FDIV_SEATED=1>")

# ===========================================================================
# P1 (run linkfull wave 27, lane P1): SIX MATCHED TUs WHOSE HOST REASONS WENT
# STALE
# ===========================================================================
#
# port/slice_w28_p1.txt seats matched TUs whose host copies retire in the same
# commits (one commit per row group; the list names each row's host file and
# the reason it no longer holds). The flat ROM names are carried by reverse
# faces in port/faces_sync.txt where the matched TU defines only a member.
#
# ALL THREE HOSTING TARGETS: every retired host copy was linked into
# walk_window, walk_window_hires and smoke_player alike, and so is
# faces_sync_gen.cpp, whose reverse faces now call these members.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w28_p1.txt" SLICE_W28_P1_LINES)
set(SLICE_W28_P1_SOURCES "")
foreach(line IN LISTS SLICE_W28_P1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W28_P1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw28p1 walk_window walk_window_hires smoke_player)
    target_sources(${_tw28p1} PRIVATE ${SLICE_W28_P1_SOURCES})
endforeach()
#
# TWO HOST FILES ARE ALSO COMPILED BY THE NARROW HARNESSES. hal/fs.cpp and
# hal/model_host.cpp are on the smoke_* harnesses as well, which link no
# faces_sync_gen.cpp and none of these slice rows, so their stand-ins for
# SharedFilePtr::Construct and func_01ffde98 retire only where the matched TU
# is linked: behind SM64DS_SFP_CONSTRUCT_ROM and SM64DS_DMA_GXFIFO_ROM, set as a
# SOURCE property keyed on the compiling target's name. That is the
# SM64DS_OS_ARENA_ROM shape above and for its two measured reasons (the
# slice-share block has already read the targets' definitions by now, and a
# target define would change every command line the targets compile). The
# name list includes port_slice_shared (the object library that compiles a
# shared file once for all three) and the three targets themselves (the
# fallback when the share is off).
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/hal/fs.cpp" APPEND PROPERTY
    COMPILE_DEFINITIONS
    "$<$<IN_LIST:$<TARGET_PROPERTY:NAME>,port_slice_shared;walk_window;walk_window_hires;smoke_player>:SM64DS_SFP_CONSTRUCT_ROM=1>")
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/hal/model_host.cpp" APPEND PROPERTY
    COMPILE_DEFINITIONS
    "$<$<IN_LIST:$<TARGET_PROPERTY:NAME>,port_slice_shared;walk_window;walk_window_hires;smoke_player>:SM64DS_DMA_GXFIFO_ROM=1>")

# ===========================================================================
# W28 S4CARD (run linkfull, lane S4CARD): the game card's read path and
# bring-up
# ===========================================================================
#
# ntr/card.cpp is the cartridge on the far side of ROMCTRL (0x040001A4), the
# command latch (0x040001A8) and the data port (0x04100010): it registers two
# ranges in ntr/io.cpp's hook table and answers the driver's B7h reads out of
# hal/fs_names.cpp's virtual ROM image. Only a ROUTED access reaches a hook, so
# the model is inert until a hostgen'd card TU talks to those registers. It goes
# on the two game targets, which carry the card driver; smoke_player keeps
# hal/nitrofs_face.cpp's synchronous FS_Init face and has no card.
foreach(_tw28c walk_window walk_window_hires)
    target_sources(${_tw28c} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/ntr/card.cpp")
endforeach()
#
# THE ROWS: port/slice_w28_card.txt, the driver's read path, its DMA arm (dead
# while FS_Init's channel is -1) and the bring-up, on the same two targets, with
# hal/card_globals.cpp for the storage and the two ARM-only answers they name.
# Two rows build from hostgen copies (W28C_HOSTGEN_TU, R2D's shape):
# src/func_02060d98.c sends a command through the byte registers at
# 0x040001A1..AF and src/func_02060a64.c stores ROMCTRL and reads the data port.
# Built plain, those accesses would latch in the window (and the data port,
# outside it, would fault) and never reach ntr/card.cpp. The DMA arm's computed
# register stores stay plain; stage B, which would run them, is not this block.
set(W28C_HOSTGEN_TU
    src/func_02060d98.c
    src/func_02060a64.c)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w28_card.txt" SLICE_W28C_LINES)
set(SLICE_W28C_SOURCES "")
foreach(line IN LISTS SLICE_W28C_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(line IN_LIST W28C_HOSTGEN_TU)
        get_filename_component(_w28c_sym "${line}" NAME_WE)
        set(_w28c_src "${CMAKE_BINARY_DIR}/host-src/src/${_w28c_sym}.cpp")
        add_custom_command(OUTPUT "${_w28c_src}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${_w28c_sym}
            DEPENDS "${PORT_REPO_ROOT_ABS}/${line}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${_w28c_sym}")
    else()
        set(_w28c_src "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
    endif()
    list(APPEND SLICE_W28C_SOURCES "${_w28c_src}")
endforeach()
foreach(_tw28c walk_window walk_window_hires)
    target_sources(${_tw28c} PRIVATE ${SLICE_W28C_SOURCES}
        "${CMAKE_CURRENT_SOURCE_DIR}/hal/card_globals.cpp")
endforeach()

# ===========================================================================
# DPAD1 (run linkfull, lane DPAD1): THE TITLE MENU'S D-PAD FAULT
# ===========================================================================
#
# A D-pad press on the file-select menu of scene 1 (dScDSMT_c) faulted in
# func_ov007_020b3d30, which indexed its tables with a word of its caller's
# stack; the scene actor was quarantined and the menu stopped answering with
# a blank bottom screen. Two matched ov007 frames drop an argument the ROM
# passes in r1 (port/ov007_seat.txt section 5d, CLASS A rows b3c54 <- b3360
# and b3d30 <- b3c54). tools/hostgen.py's REG_RIDE_ARG rows for the two TUs
# spell it; src/ is untouched and the bodies stay the ROM's.
#
# port/slice_w28_dpad1.txt carries the two rows (moved out of
# port/slice_ov007.txt, which marks where each was) and every row builds from
# its build/host-src copy in this block's own custom commands: the W25MG /
# W235 shape, since PORT_HOSTGEN_TU's region is not this lane's. hostgen
# emits a .c source as a .cpp wrapped whole in extern "C", so the symbols keep
# C linkage and each object keeps its TU's stem. The same three targets
# SLICE_OV007_SOURCES feeds.
set(DPAD1_HOSTGEN_TU
    src/func_ov007_020b3360.c
    src/func_ov007_020b3c54.c)
foreach(_dpad1_tu IN LISTS DPAD1_HOSTGEN_TU)
    list(FIND SLICE_OV007_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${_dpad1_tu}" _dpad1_idx)
    if(NOT _dpad1_idx LESS 0)
        message(FATAL_ERROR "${_dpad1_tu} is a raw port/slice_ov007.txt row "
                "again, so it would be compiled twice: once raw, with the "
                "argument the ROM passes in r1 dropped, and once from the "
                "hostgen copy the DPAD1 block builds")
    endif()
endforeach()
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w28_dpad1.txt" SLICE_W28_DPAD1_LINES)
set(SLICE_W28_DPAD1_SOURCES "")
foreach(line IN LISTS SLICE_W28_DPAD1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(NOT line IN_LIST DPAD1_HOSTGEN_TU)
        message(FATAL_ERROR "port/slice_w28_dpad1.txt row ${line} is not on "
                "DPAD1_HOSTGEN_TU: every row there exists to build from its "
                "hostgen copy")
    endif()
    string(REGEX REPLACE "[.](c|cpp)$" ".cpp" _dpad1_rel "${line}")
    set(_dpad1_out "${CMAKE_BINARY_DIR}/host-src/${_dpad1_rel}")
    add_custom_command(OUTPUT "${_dpad1_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${line}
        DEPENDS "${PORT_REPO_ROOT_ABS}/${line}"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${line}")
    list(APPEND SLICE_W28_DPAD1_SOURCES "${_dpad1_out}")
endforeach()
list(LENGTH SLICE_W28_DPAD1_SOURCES _dpad1_n)
list(LENGTH DPAD1_HOSTGEN_TU _dpad1_want)
if(NOT _dpad1_n EQUAL _dpad1_want)
    message(FATAL_ERROR "port/slice_w28_dpad1.txt lists ${_dpad1_n} of the "
            "${_dpad1_want} DPAD1 rows; a missing row is an undefined symbol "
            "on every title-screen build")
endif()
foreach(_tw28dpad1 walk_window walk_window_hires smoke_player)
    target_sources(${_tw28dpad1} PRIVATE ${SLICE_W28_DPAD1_SOURCES})
endforeach()

# ===========================================================================
# BOOBRICK1 (run linkfull, lane BOOBRICK1), R3: KING BOO'S GATE READS THE
# ov055 WORD MIRROR LUIGI WRITES
# ===========================================================================
#
# src/unnamed/ov063/func_ov063_02117cdc.c is King Boo's cutscene (ov063
# 0x02117cdc). Its step 5 waits for (&data_ov008_02111b6c)[0] == 0x1f000
# (line 160), and the name it spells picks ov008, the test map's level
# overlay, out of the thirteen overlays that claim 0x02111b6c
# (config/arm9/overlays/ov063/relocs.txt line 199, the literal at 0x02118434).
# The same function's call at 0x02118004 lists overlays 27 and 55 (line 184),
# and the R-L15B3 block above settled that one as ov055 by disassembly. The
# two lists meet only at ov055: level 47's own level overlay, .bss
# 0x02111b60..0x02111b80, and level 47 is the one level that places the
# type-15 King Boo (actor 210, param 0xff03; port/tools/ov_places.py --id 210
# gives level 12 x2 and level 47 x1, and level 12's two are Big Boo types).
# So on the cartridge this read is always ov055's word: Mirror Luigi's fade,
# data_ov055_02111b6c, which src/_ZN11MirrorLuigi8BehaviorEv.cpp moves toward
# 0x1ffff by 0x400 a frame, landing on 0x1f000 at tick 124, the frame the
# gate accepts.
#
# The port bound the ov008 name to a frozen host copy (port/hal/link21_rows.cpp
# row 8, retired in the same change as this block), so the gate never opened:
# the player stayed in the talk state after Luigi appeared and King Boo never
# came. A per-source rename, not an /alternatename, for R-L15B3's reason: both
# names are real ROM addresses of different overlays, and only this one TU's
# read belongs to ov055. APPEND, so R-L15B3's define on the same source stays.
# src/ is untouched; the object's only change is the symbol it references.
set_property(SOURCE
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/unnamed/ov063/func_ov063_02117cdc.c"
    APPEND PROPERTY COMPILE_DEFINITIONS
    "data_ov008_02111b6c=data_ov055_02111b6c")

# ===========================================================================
# BOOBRICK1 (run linkfull, lane BOOBRICK1), R7: THE BRICK'S OWN SLOT 22
# ===========================================================================
#
# _ZTV13daObjBlockL_c (ov002 0x02108adc) is the table BRICK_BLOCK (15),
# BIG_BRICK_BLOCK (16), BLACK_BRICK_BLOCK (17), BRICK_BLOCK_SWITCH_ACTIVATED
# (19) and FORTRESS_TOWER_WALL (46) all install, and it holds 0x020b37ec at
# slot 22 (0x02108b34, config/arm9/overlays/ov002/relocs.txt line 13722):
# BigBrickBlock::OnAttacked1, src/_ZN13BigBrickBlock11OnAttacked1ER8dActor_c.cpp.
# The port trapped that slot. A Bob-omb's blast or a thrown crate against a
# brick dispatches it (func_ov002_020ef228 calls slot 22 on the owner of the
# wall the attacker touches), so the trap froze the brick in the quarantine
# (gone from view, still solid) and unwound the Bob-omb before its blast
# ended, and the Bob-omb blew up again every four frames (0.4.2 forum report
# R7). hal/actor_classes.cpp now seats slot 22 on the ROM body, which calls
# the brick's own Kill (slot 31) unless it is id 0x11.
#
# The TU was refused at port/slice_ov2t.txt for MSVC C2561, a bare `return;`
# in an int body. Its _MSC_VER arm spells that early exit as the absence of
# the call, the shape SignPost::OnAttacked1 and QuestionBlock::OnAttacked1 are
# seated in, so it falls off the end like them and takes /wd4716, per source,
# for the reason the PORT_FALLS_OFF_END_SOURCES block gives: the ROM sets no
# return value on either path and nothing reads one. mwccarm builds the
# unchanged #else arm, byte-identical.
#
# It also takes the tail-pad force-include every other BigBrickBlock TU gets
# from the PORT_TAILPAD_DBGACTOR_SOURCES block, so all of the class's TUs in
# the link see one class layout. APPEND, never SET, for that block's reason.
#
# The three targets that compile hal/actor_classes.cpp, whose slot-22 seat
# references this body.
set(BOOBRICK1_R7_SRC
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13BigBrickBlock11OnAttacked1ER8dActor_c.cpp")
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_boobrick1.txt" SLICE_BOOBRICK1_LINES)
set(SLICE_BOOBRICK1_SOURCES "")
foreach(line IN LISTS SLICE_BOOBRICK1_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_BOOBRICK1_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
if(MSVC)
    set_property(SOURCE "${BOOBRICK1_R7_SRC}" APPEND PROPERTY COMPILE_OPTIONS
        /wd4716
        "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/dBgActor_c_TailPad_HostAbi.h")
endif()
foreach(_tboobrick1 walk_window walk_window_hires smoke_player)
    target_sources(${_tboobrick1} PRIVATE ${SLICE_BOOBRICK1_SOURCES})
endforeach()

# ===========================================================================
# VARIANT4 (run linkfull, lane VARIANT4): THE LAST D0 ROWS THE CAMPAIGN HELD
# ===========================================================================
#
# port/slice_w31_variant4.txt carries per-function src D0 TUs in the D0-arm
# campaign's shape: each file's `#ifdef _MSC_VER` arm defines the flat ROM D0
# name itself (the qualified call to the class's one host destructor body, then
# the class's own operator delete), and the generated face in
# port/faces_sync.txt that used to define it is retired in the same commit, so
# each flat name has exactly one definition.
#
# ALL THREE HOSTING TARGETS: the generated faces (port_slice_shared) and the
# hal tables and thunks that call these names are on walk_window's,
# walk_window_hires' and smoke_player's link lines alike (build.ninja), so the
# retired faces must be answered on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_variant4.txt" SLICE_W31_VARIANT4_LINES)
set(SLICE_W31_VARIANT4_SOURCES "")
foreach(line IN LISTS SLICE_W31_VARIANT4_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W31_VARIANT4_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw31v4 walk_window walk_window_hires smoke_player)
    target_sources(${_tw31v4} PRIVATE ${SLICE_W31_VARIANT4_SOURCES})
endforeach()

# ===========================================================================
# W31 SMALLS2 (run linkfull wave 31, lane SMALLS2)
# ===========================================================================
# Matched TUs the linkage census listed as MSVC front-end refusals. Each
# refusal is gone from the synced src and each TU compiles clean here; what
# held it out was a FORWARD row in port/faces_sync.txt, which defined the
# member the TU defines. The rows are flipped to REVERSE and the host copies
# retired, so the matched bodies run as the game's own code (the FACEFLIP1
# shape above). port/slice_w31_smalls2.txt carries the rows and the evidence.
# All three targets take them, because the reverse faces are in
# ${PORT_FACES_SYNC_GEN}, which all three link, and the ROM-shaped callers
# (the ov063 / ov085 slot thunks, Peach's InitState0 / InitState4) are in all
# three. The slice also carries ModelBase's D2 (LINK15 W23-1's stretch row),
# whose _MSC_VER arm replaces the body in
# port/unmatched/ModelFamily_Dtors_HostCopy.c; that file is on the same three
# targets and its D1 bodies call the D2 by its flat name. The slice names no
# PORT_HOSTGEN_TU row.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_smalls2.txt" SLICE_W31_SMALLS2_LINES)
set(SLICE_W31_SMALLS2_SOURCES "")
foreach(line IN LISTS SLICE_W31_SMALLS2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W31_SMALLS2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_w31s2_t walk_window walk_window_hires smoke_player)
    target_sources(${_w31s2_t} PRIVATE ${SLICE_W31_SMALLS2_SOURCES})
endforeach()

# THE HOSTGEN HALF OF THE SAME BLOCK (lane SMALLS2, batch 4). A matched TU that
# needs a tools/hostgen.py row to compile as the ROM's own body is built from
# its build/host-src copy here, in custom commands of this block's own (the
# DPAD1 / W235 shape, since the PORT_HOSTGEN_TU region belongs to another
# lane). port/slice_w31_smalls2_hostgen.txt carries the rows and the
# evidence; every row must be on SMALLS2_HOSTGEN_TU and on no raw slice.
set(SMALLS2_HOSTGEN_TU
    src/_ZN8Goomboss13InitResourcesEv.cpp)
foreach(_s2_tu IN LISTS SMALLS2_HOSTGEN_TU)
    list(FIND SLICE_W31_SMALLS2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${_s2_tu}" _s2_idx)
    if(NOT _s2_idx LESS 0)
        message(FATAL_ERROR "${_s2_tu} is a raw port/slice_w31_smalls2.txt row, "
                "so it would be compiled twice: once raw, where MSVC decorates "
                "its ROM data externs, and once from the hostgen copy")
    endif()
endforeach()
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_smalls2_hostgen.txt" SLICE_W31_SMALLS2_HG_LINES)
set(SLICE_W31_SMALLS2_HG_SOURCES "")
foreach(line IN LISTS SLICE_W31_SMALLS2_HG_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(NOT line IN_LIST SMALLS2_HOSTGEN_TU)
        message(FATAL_ERROR "port/slice_w31_smalls2_hostgen.txt row ${line} is "
                "not on SMALLS2_HOSTGEN_TU: every row there exists to build "
                "from its hostgen copy")
    endif()
    string(REGEX REPLACE "[.](c|cpp)$" ".cpp" _s2_rel "${line}")
    set(_s2_out "${CMAKE_BINARY_DIR}/host-src/${_s2_rel}")
    add_custom_command(OUTPUT "${_s2_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${line}
        DEPENDS "${PORT_REPO_ROOT_ABS}/${line}"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${line}")
    list(APPEND SLICE_W31_SMALLS2_HG_SOURCES "${_s2_out}")
endforeach()
list(LENGTH SLICE_W31_SMALLS2_HG_SOURCES _s2_n)
list(LENGTH SMALLS2_HOSTGEN_TU _s2_want)
if(NOT _s2_n EQUAL _s2_want)
    message(FATAL_ERROR "port/slice_w31_smalls2_hostgen.txt lists ${_s2_n} of "
            "the ${_s2_want} SMALLS2 hostgen rows; a missing row is an "
            "undefined symbol on every level build")
endif()
foreach(_w31s2hg_t walk_window walk_window_hires smoke_player)
    target_sources(${_w31s2hg_t} PRIVATE ${SLICE_W31_SMALLS2_HG_SOURCES})
endforeach()

# ===========================================================================
# W31 S4OV0 (run linkfull wave 31, lane S4OV0): THE OV0 HANDLE TABLE
# ===========================================================================
# The cartridge builds its handle -> file id table at boot with ov000's own
# entry. port/slice_w31_s4ov0.txt carries the entry, its three helpers and the
# reader src/func_02018a24.c; hal/s4ov0_ov0table.cpp hosts the two words the
# build writes (data_0209d3b8, data_0209d3b0, in .dsstate). The entry's data
# is mounted mid-file (ov000 on PORT_ACTOR_OVERLAYS, kept out of the cross
# pass) for the reasons given there. The entry
# runs from hal/boot_os.cpp's port_boot_rom_worker, which hal/rom_main.cpp's
# loop seam calls; both files are on the two game targets only, so those two
# take the whole slice.
#
# hal/fs.cpp is compiled ONCE for all three hosting targets (port_slice_shared),
# so its catalog face for func_02018a24 retires behind SM64DS_OV0_TABLE_ROM on
# that whole name list, the SM64DS_SFP_CONSTRUCT_ROM shape above; the smoke_*
# harnesses keep it. smoke_player therefore takes the reader and the data file
# and nothing else: it runs no boot and carries none of the builder's callees
# (it is EXCLUDE_FROM_ALL and does not link today, SMOKELINK6), so it gains no
# new unresolved name and builds no table.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_s4ov0.txt" SLICE_W31_S4OV0_LINES)
set(SLICE_W31_S4OV0_SOURCES "")
foreach(line IN LISTS SLICE_W31_S4OV0_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W31_S4OV0_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
set(S4OV0_READER_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_02018a24.c")
if(NOT S4OV0_READER_SRC IN_LIST SLICE_W31_S4OV0_SOURCES)
    message(FATAL_ERROR "port/slice_w31_s4ov0.txt does not list "
            "src/func_02018a24.c, the reader hal/fs.cpp's face retires for")
endif()
foreach(_ts4ov0 walk_window walk_window_hires)
    target_sources(${_ts4ov0} PRIVATE ${SLICE_W31_S4OV0_SOURCES}
        "${CMAKE_CURRENT_SOURCE_DIR}/hal/s4ov0_ov0table.cpp")
endforeach()
target_sources(smoke_player PRIVATE "${S4OV0_READER_SRC}"
    "${CMAKE_CURRENT_SOURCE_DIR}/hal/s4ov0_ov0table.cpp")
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/hal/fs.cpp" APPEND PROPERTY
    COMPILE_DEFINITIONS
    "$<$<IN_LIST:$<TARGET_PROPERTY:NAME>,port_slice_shared;walk_window;walk_window_hires;smoke_player>:SM64DS_OV0_TABLE_ROM=1>")
#
# THE FOUR FILE POINTERS THE CRT BUILT BEFORE MAIN. Three matched C++ TUs define
# overlay SharedFilePtrs with constructors (ov023's two, ov044's, ov100's), and
# MSVC hands those constructors to the CRT, which runs them before main -- so
# each looked its handle up before any table could exist (the only four
# lookups before the loop seam, measured under cdb on the INT55 build). On the
# cartridge they run in each overlay's __sinit at its load, and the port runs
# those bodies at each overlay's bring-up already. hal/s4ov0_overlay_sinit.h
# moves the three TUs' initialisers into a section the CRT does not walk; its
# banner has the derivation. BOTH PATHS for each row, the DSSTATE block's rule
# (d_a_star_gate.cpp compiles from its hostgen twin today), and APPEND, never
# SET: all three already carry hal/dsstate_all.h and two carry more.
if(MSVC)
    foreach(_s4ov0_rel IN ITEMS
            src/game/actors/d_a_obj_fm_battan.cpp
            src/game/actors/d_a_obj_kb1_billboard.cpp
            src/game/actors/d_a_star_gate.cpp)
        if(NOT EXISTS "${PORT_REPO_ROOT_ABS}/${_s4ov0_rel}")
            message(FATAL_ERROR "S4OV0: ${_s4ov0_rel} does not exist")
        endif()
        foreach(_s4ov0_one IN ITEMS "${PORT_REPO_ROOT_ABS}/${_s4ov0_rel}"
                                    "${CMAKE_BINARY_DIR}/host-src/${_s4ov0_rel}")
            set_property(SOURCE "${_s4ov0_one}" APPEND PROPERTY COMPILE_OPTIONS
                "/FI${CMAKE_CURRENT_SOURCE_DIR}/hal/s4ov0_overlay_sinit.h")
        endforeach()
    endforeach()
endif()

# ===========================================================================
# W31 S4ARC (run linkfull wave 31, lane S4ARC): THE ARCHIVE LOADER
# ===========================================================================
# The cartridge mounts and unmounts its thirteen NARC archives itself; the port
# published them as permanently resident from a static initialiser in
# hal/card_mount.cpp. That publish is retired, the ROM's own LoadArchive mounts
# (its branch was already linked, port/slice_cardfs.txt), and
# port/slice_w31_s4arc.txt carries the rest of the loader: LoadFileAt's reader
# func_02018270 with the open (func_020185c0, func_02018598, func_0204eda4) and
# the unmount (UnloadArchive, UnloadArchives, func_02018908, func_0204ee10).
# Their empty faces in hal/stage_slot0.cpp and hal/scene_boot.cpp are gone; the
# level boot replays Stage::InitResources' archive lines (hal/level_boot.cpp).
#
# All three hosting targets compile hal/stage_slot0.cpp, hal/scene_boot.cpp,
# hal/level_boot.cpp and hal/card_mount.cpp, so all three take the slice.
# hal/fs.cpp is compiled ONCE for them (port_slice_shared), so its host copy of
# func_02018270 retires behind SM64DS_LOADAT_ROM on that whole name list, the
# SM64DS_OV0_TABLE_ROM shape above; the smoke_* harnesses keep it.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_s4arc.txt" SLICE_W31_S4ARC_LINES)
set(SLICE_W31_S4ARC_SOURCES "")
foreach(line IN LISTS SLICE_W31_S4ARC_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W31_S4ARC_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
set(S4ARC_READER_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_02018270.c")
if(NOT S4ARC_READER_SRC IN_LIST SLICE_W31_S4ARC_SOURCES)
    message(FATAL_ERROR "port/slice_w31_s4arc.txt does not list "
            "src/func_02018270.c, the reader hal/fs.cpp's copy retires for")
endif()
foreach(_ts4arc walk_window walk_window_hires smoke_player)
    target_sources(${_ts4arc} PRIVATE ${SLICE_W31_S4ARC_SOURCES})
endforeach()
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/hal/fs.cpp" APPEND PROPERTY
    COMPILE_DEFINITIONS
    "$<$<IN_LIST:$<TARGET_PROPERTY:NAME>,port_slice_shared;walk_window;walk_window_hires;smoke_player>:SM64DS_LOADAT_ROM=1>")

# ===========================================================================
# ASMCPORT (run linkfull, lane ASMCPORT): ROM ROUTINES THE PORT HOSTED FOR
# THEIR OLD src SPELLINGS, BUILT AS THE ROM'S OWN BODIES
# ===========================================================================
#
# A1. src/MultiCopyHalf.c, the halfword block copy (C since main #3167), on the
# three targets that compile hal/cxx_aliases.cpp. It is compiled under a
# per-source rename, MultiCopyHalf=MultiCopyHalf_rom: hal/cxx_aliases.cpp keeps
# the ROM name as the one call into this body, with the PPU audit's copy census
# in front of it. src/ is untouched; the ARM object is main's.
set(ASMCPORT_A1_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../src/MultiCopyHalf.c")
set_property(SOURCE "${ASMCPORT_A1_SRC}" APPEND PROPERTY COMPILE_DEFINITIONS
    "MultiCopyHalf=MultiCopyHalf_rom")
foreach(_tasmc1 walk_window walk_window_hires smoke_player)
    target_sources(${_tasmc1} PRIVATE "${ASMCPORT_A1_SRC}")
endforeach()

# A2. src/_ZN6Memory13operator_new2Ej.cpp (its real signature since main #1243)
# on every target that compiles hal/model_host.cpp, whose host copy of the flat
# name is retired for an /alternatename onto this body. All fourteen already
# carry src/func_0203cc0c.c, the veneer's one callee.
foreach(_tasmc2 walk_window walk_window_hires smoke_player smoke_actor
                smoke_anim smoke_clsn smoke_frames smoke_model smoke_modelanim
                smoke_oam smoke_persist smoke_savestate smoke_soak smoke_soak_anim)
    target_sources(${_tasmc2} PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN6Memory13operator_new2Ej.cpp")
endforeach()

# A3. src/_ZN6Memory16operator_delete2EPv.cpp on the six targets that compile
# hal/cxxname_bridge.cpp, whose host body of the flat name is retired for an
# /alternatename onto this one; all six carry src/_ZdlPv.cpp, its one callee.
# The ten smoke targets that already build it (PORT_SMOKE_HEAP_TEARDOWN_SRC,
# slice_gate24) are not listed again. smoke_player, smoke_actor,
# smoke_savestate and smoke_persist stay EXCLUDE_FROM_ALL; they take A1-A3 so
# their link lines keep the symbols the retired host bodies defined.
foreach(_tasmc3 walk_window walk_window_hires smoke_player smoke_actor
                smoke_savestate smoke_persist)
    target_sources(${_tasmc3} PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN6Memory16operator_delete2EPv.cpp")
endforeach()

# ===========================================================================
# W31 S4FILE (run linkfull wave 31, lane S4FILE): THE FILE LOADER, PART A
# ===========================================================================
# The game's own LoadFile, func_0201817c and the func_0201818c they share, with
# the archive-member lookup behind it (func_020186c0, func_0204ede8), in place
# of hal/level_boot.cpp's host LoadFile (a SharedFilePtr load plus a per-handle
# table, both retired) and hal/fs.cpp's host func_0201817c. Loose files read
# through FS off the card; hal/fs_names.cpp's image keeps a file's bytes after
# the first block that touches it and serves mod files out of a patched range.
#
# All three hosting targets compile hal/level_boot.cpp, where the host LoadFile
# was, so all three take the slice. hal/fs.cpp is compiled ONCE for them
# (port_slice_shared), so its host func_0201817c retires behind
# SM64DS_LOADFILE_ROM on that whole name list, the SM64DS_LOADAT_ROM shape
# above; the smoke_* harnesses keep it.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_s4file.txt" SLICE_W31_S4FILE_LINES)
set(SLICE_W31_S4FILE_SOURCES "")
foreach(line IN LISTS SLICE_W31_S4FILE_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W31_S4FILE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
set(S4FILE_READER_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../src/func_0201817c.c")
if(NOT S4FILE_READER_SRC IN_LIST SLICE_W31_S4FILE_SOURCES)
    message(FATAL_ERROR "port/slice_w31_s4file.txt does not list "
            "src/func_0201817c.c, the reader hal/fs.cpp's copy retires for")
endif()
foreach(_ts4file walk_window walk_window_hires smoke_player)
    target_sources(${_ts4file} PRIVATE ${SLICE_W31_S4FILE_SOURCES})
endforeach()
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/hal/fs.cpp" APPEND PROPERTY
    COMPILE_DEFINITIONS
    "$<$<IN_LIST:$<TARGET_PROPERTY:NAME>,port_slice_shared;walk_window;walk_window_hires;smoke_player>:SM64DS_LOADFILE_ROM=1>")

# ===========================================================================
# W32 FILEB (run linkfull wave 32, lane FILEB): THE FILE LOADER, PART B
# ===========================================================================
# The game's own SharedFilePtr::Load in place of hal/fs.cpp's host Load and its
# decoded-file cache: an archive member comes out of the NARC the ROM's
# LoadArchive mounted, a loose file off the card (hal/fs_names.cpp's image).
# Mods are served by the card: hal/fs.cpp puts every claimed file in the
# card's patched range, an archive member inside a rebuilt copy of its NARC.
# Same shape as S4FILE's block above: the three hosting targets take the
# slice, and hal/fs.cpp (compiled once for them as port_slice_shared) retires
# its host Load behind SM64DS_SFP_LOAD_ROM on that whole name list; the smoke_*
# harnesses keep it. The flat name is a reverse face (port/faces_sync.txt).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w32_fileb.txt" SLICE_W32_FILEB_LINES)
set(SLICE_W32_FILEB_SOURCES "")
foreach(line IN LISTS SLICE_W32_FILEB_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W32_FILEB_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
set(FILEB_LOAD_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13SharedFilePtr4LoadEv.cpp")
if(NOT FILEB_LOAD_SRC IN_LIST SLICE_W32_FILEB_SOURCES)
    message(FATAL_ERROR "port/slice_w32_fileb.txt does not list "
            "src/_ZN13SharedFilePtr4LoadEv.cpp, the Load hal/fs.cpp's copy retires for")
endif()
foreach(_tfileb walk_window walk_window_hires smoke_player)
    target_sources(${_tfileb} PRIVATE ${SLICE_W32_FILEB_SOURCES})
endforeach()
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/hal/fs.cpp" APPEND PROPERTY
    COMPILE_DEFINITIONS
    "$<$<IN_LIST:$<TARGET_PROPERTY:NAME>,port_slice_shared;walk_window;walk_window_hires;smoke_player>:SM64DS_SFP_LOAD_ROM=1>")

# B5INPUT (run linkfull): THE GAME LOOP'S OWN INPUT STEPS. port/slice_w31_b5input.txt
# lists the ROM TUs tests/walk_window.cpp's level loop calls at the frame loop's
# input phases (0x15, the pad read; 0x17, PadData, the ring and the soft-reset
# latch). The two targets that compile tests/walk_window.cpp take them; nothing
# in smoke_player calls them.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_b5input.txt" SLICE_B5INPUT_LINES)
set(SLICE_B5INPUT_SOURCES "")
foreach(line IN LISTS SLICE_B5INPUT_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_B5INPUT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tb5input walk_window walk_window_hires)
    target_sources(${_tb5input} PRIVATE ${SLICE_B5INPUT_SOURCES})
endforeach()

# ===========================================================================
# PMF3 (run linkfull, lane PMF3): THE LAST MEMBER-POINTER ROWS
# ===========================================================================
#
# port/slice_w31_pmf3.txt carries the matched TUs this lane arms, each in place
# of a host stand-in the same commit retires (the slice file names which). A
# line whose path is followed by the word `hostgen` compiles its
# build/host-src copy made by port/tools/hostgen.py (the PMF2 block's shape);
# every other line compiles as it stands. All three hosting targets take the
# slice, because each retired stand-in is linked by all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_pmf3.txt" SLICE_W31_PMF3_LINES)
set(SLICE_W31_PMF3_SOURCES "")
foreach(line IN LISTS SLICE_W31_PMF3_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(line MATCHES "^(src/[^ ]+)[ ]+hostgen$")
        set(_w31pmf3_src "${CMAKE_MATCH_1}")
        string(REGEX REPLACE "[.]c$" ".cpp" _w31pmf3_rel "${_w31pmf3_src}")
        set(_w31pmf3_out "${CMAKE_BINARY_DIR}/host-src/${_w31pmf3_rel}")
        add_custom_command(OUTPUT "${_w31pmf3_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${_w31pmf3_src}
            DEPENDS "${PORT_REPO_ROOT_ABS}/${_w31pmf3_src}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${_w31pmf3_src}")
        list(APPEND SLICE_W31_PMF3_SOURCES "${_w31pmf3_out}")
    else()
        list(APPEND SLICE_W31_PMF3_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
    endif()
endforeach()
# hal/pmf3_cells.cpp hosts the twelve virtual member-pointer records the four
# ActorBase::Process wrappers hand fBase_c::Process (arm9 0x02099e74..ecc).
list(APPEND SLICE_W31_PMF3_SOURCES hal/pmf3_cells.cpp)
# hal/pmf3_player_states.cpp seats the Player::State cells the matched
# ChangeState and Behavior dispatch through.
list(APPEND SLICE_W31_PMF3_SOURCES hal/pmf3_player_states.cpp)
foreach(_tw31pmf3 walk_window walk_window_hires smoke_player)
    target_sources(${_tw31pmf3} PRIVATE ${SLICE_W31_PMF3_SOURCES})
endforeach()

# ===========================================================================
# RS5A (run linkfull, lane RS5A), R9: THE BRICK'S OWN SLOT 23
# ===========================================================================
#
# _ZTV13daObjBlockL_c (ov002 0x02108adc), the table the brick-block family
# installs, holds 0x020b3788 at slot 23 (0x02108b38,
# config/arm9/overlays/ov002/relocs.txt line 13723): BigBrickBlock::OnAttacked2,
# src/_ZN13BigBrickBlock11OnAttacked2ER8dActor_c.cpp, the handler a bro's punch
# dispatches (func_ov002_020ef070). It rode a thiscall host copy,
# unmatched/BigBrickBlock_OnAttacked2.cpp, appended to SLICE16_SOURCES, while its
# src reached Kill through a cdecl `fn(c)`. The src makes a C++ virtual call now,
# so the copy is retired and hal/actor_classes.cpp seats slot 23 on the ROM body
# (bbb_atk2), the way BOOBRICK1's block above seats slot 22.
#
# The TU needs what OnAttacked1's does, for the same reasons: its _MSC_VER arm
# answers C2561 (valueless returns in an int body) by falling off the end, so it
# takes /wd4716 per source (the PORT_FALLS_OFF_END_SOURCES ruling: the ROM sets
# no return value and nothing reads one), and the tail-pad force-include every
# other BigBrickBlock TU gets from PORT_TAILPAD_DBGACTOR_SOURCES, so all of the
# class's TUs in the link see one class layout. APPEND, never SET.
#
# The three targets that compile hal/actor_classes.cpp, whose slot-23 seat
# references this body.
set(RS5A_R9_SRC
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN13BigBrickBlock11OnAttacked2ER8dActor_c.cpp")
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_rs5a.txt" SLICE_W31_RS5A_LINES)
set(SLICE_W31_RS5A_SOURCES "")
foreach(line IN LISTS SLICE_W31_RS5A_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W31_RS5A_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
if(MSVC)
    set_property(SOURCE "${RS5A_R9_SRC}" APPEND PROPERTY COMPILE_OPTIONS
        /wd4716
        "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/dBgActor_c_TailPad_HostAbi.h")
endif()
foreach(_trs5a walk_window walk_window_hires smoke_player)
    target_sources(${_trs5a} PRIVATE ${SLICE_W31_RS5A_SOURCES})
endforeach()

# ===========================================================================
# RS5B (run linkfull wave 31B, lane RS5B): OPERATOR NEW, STAGE::UPDATEMESSAGE
# AND THE SPHERE PASS RUN AS THE ROM'S OWN BODIES
# ===========================================================================
#
# R3. port/slice_w31_rs5b.txt: src/_Znwj.cpp, the DS global operator new with
# its real signature (main #1394). hal/cxxname_bridge.cpp's host body of the
# same C symbol is retired in the same change, so the six targets that compile
# that file take the src TU instead (smoke_actor / smoke_savestate /
# smoke_persist stay EXCLUDE_FROM_ALL; they get it so their link line keeps the
# symbol).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_rs5b.txt" SLICE_W31_RS5B_LINES)
set(SLICE_W31_RS5B_SOURCES "")
foreach(line IN LISTS SLICE_W31_RS5B_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W31_RS5B_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_trs5b walk_window walk_window_hires smoke_player smoke_actor
                smoke_savestate smoke_persist)
    target_sources(${_trs5b} PRIVATE ${SLICE_W31_RS5B_SOURCES})
endforeach()

# R7. port/slice_w31_rs5b_stage.txt: src/_ZN5Stage13UpdateMessageEv.cpp, main's
# blob, on the two targets that compile Stage::Behavior and hal/message_pump.cpp.
# hal/stage_frame.cpp (another lane's file this wave) still defines
# ?UpdateMessage@Stage@@SAXXZ as a face onto port_message_pump, so this TU is
# compiled under a per-source rename and hal/message_pump.cpp's pump is one call
# into it; the two decorated data names it asks for that nothing bridged are
# aliased in that file. When the stage_frame.cpp face is deleted, delete this
# define with it. src/ is untouched; the ARM object is main's.
set(RS5B_R7_SRC
    "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN5Stage13UpdateMessageEv.cpp")
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_rs5b_stage.txt" SLICE_W31_RS5B_STAGE_LINES)
set(SLICE_W31_RS5B_STAGE_SOURCES "")
foreach(line IN LISTS SLICE_W31_RS5B_STAGE_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W31_RS5B_STAGE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
set_property(SOURCE "${RS5B_R7_SRC}" APPEND PROPERTY COMPILE_DEFINITIONS
    "UpdateMessage=UpdateMessage_rom")
foreach(_trs5bs walk_window walk_window_hires)
    target_sources(${_trs5bs} PRIVATE ${SLICE_W31_RS5B_STAGE_SOURCES})
endforeach()

# R10. port/slice_w31_rs5b_hostgen.txt: dBgW_Kc::DetectClsn(dBgCh_SphCrr &),
# the matched sphere pass, from its tools/hostgen.py copy (the DATA / MMIO
# custom-command shape of the SMALLS2 block above): its DS square-root unit
# stores reach port/ntr/io.cpp that way. It replaces the host transcription
# port/unmatched/MeshCollider_DetectClsn_Sphere.cpp, retired off
# port/slice_gate8.txt, on exactly the seven targets that slice fed.
set(RS5B_HOSTGEN_TU
    src/_ZN7dBgW_Kc10DetectClsnER12dBgCh_SphCrr.cpp)
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_rs5b_hostgen.txt" SLICE_W31_RS5B_HG_LINES)
set(SLICE_W31_RS5B_HG_SOURCES "")
foreach(line IN LISTS SLICE_W31_RS5B_HG_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(NOT line IN_LIST RS5B_HOSTGEN_TU)
        message(FATAL_ERROR "port/slice_w31_rs5b_hostgen.txt row ${line} is "
                "not on RS5B_HOSTGEN_TU: every row there exists to build from "
                "its hostgen copy")
    endif()
    string(REGEX REPLACE "[.](c|cpp)$" ".cpp" _rs5b_rel "${line}")
    set(_rs5b_out "${CMAKE_BINARY_DIR}/host-src/${_rs5b_rel}")
    add_custom_command(OUTPUT "${_rs5b_out}"
        COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                --out "${CMAKE_BINARY_DIR}/host-src" ${line}
        DEPENDS "${PORT_REPO_ROOT_ABS}/${line}"
                "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
        COMMENT "hostgen ${line}")
    # The body makes a REAL virtual call, GetSurfaceInfo(triID, data_020a0cec),
    # and every live collider carries the THIRTEEN-slot table the dBgW ctor TUs
    # emit under unmatched/dBgW_HostAbi.h (the PORT_DBGW_HOSTABI_SOURCES block).
    # Compiled against the twelve-slot include/dBgW.h the call is [eax+8], the
    # empty HostRomD0SlotPad: the SurfaceInfo is never filled and the eight
    # argument bytes are never popped, so the epilogue restores the caller's
    # registers from the wrong slots (measured: level 1 faults on frame 1). The
    # same /FI gives it slot 3, the cartridge's.
    if(MSVC)
        set_property(SOURCE "${_rs5b_out}" APPEND PROPERTY COMPILE_OPTIONS
            "/FI${CMAKE_CURRENT_SOURCE_DIR}/unmatched/dBgW_HostAbi.h")
    endif()
    list(APPEND SLICE_W31_RS5B_HG_SOURCES "${_rs5b_out}")
endforeach()
list(LENGTH SLICE_W31_RS5B_HG_SOURCES _rs5b_n)
list(LENGTH RS5B_HOSTGEN_TU _rs5b_want)
if(NOT _rs5b_n EQUAL _rs5b_want)
    message(FATAL_ERROR "port/slice_w31_rs5b_hostgen.txt lists ${_rs5b_n} of "
            "the ${_rs5b_want} RS5B hostgen rows; a missing row is an "
            "undefined sphere pass on every collision target")
endif()
foreach(_trs5bhg smoke_clsn smoke_actor smoke_savestate smoke_persist
                 smoke_player walk_window walk_window_hires)
    target_sources(${_trs5bhg} PRIVATE ${SLICE_W31_RS5B_HG_SOURCES})
endforeach()

# ===========================================================================
# S42D (run linkfull, wave 31B): THE PAUSE SCREEN, THE LEVEL-CLEAR BANNER AND
# THE CONTROLLER-MODE CAPTIONS
# ===========================================================================
#
# port/slice_w31_s42d.txt carries the four matched TUs this lane arms, each in
# place of a host stand-in the same commit retires (the slice file names
# which). Stage::PS_Render and Stage::LC_Render go to the two targets that
# compile hal/stage_frame.cpp, whose seams they replace; a line ending in the
# word `alltargets` (LoadControllerModeText and func_0201d590, replacing the
# stub in hal/sub_screen.cpp) goes to all three hosting targets, because that
# file is on all three. The sprite template data both renderers read is in
# port/ov002_syms.txt and port/ov001_syms.txt, consumed by the mounts above;
# nothing here is hostgen'd (no raw MMIO in any of the four).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_s42d.txt" SLICE_W31_S42D_LINES)
set(SLICE_W31_S42D_SOURCES "")
set(SLICE_W31_S42D_ALL_SOURCES "")
foreach(line IN LISTS SLICE_W31_S42D_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(line MATCHES "^(src/[^ ]+)[ ]+alltargets$")
        list(APPEND SLICE_W31_S42D_ALL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${CMAKE_MATCH_1}")
    else()
        list(APPEND SLICE_W31_S42D_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
    endif()
endforeach()
foreach(_tw31s42d walk_window walk_window_hires)
    target_sources(${_tw31s42d} PRIVATE ${SLICE_W31_S42D_SOURCES})
endforeach()
foreach(_tw31s42d walk_window walk_window_hires smoke_player)
    target_sources(${_tw31s42d} PRIVATE ${SLICE_W31_S42D_ALL_SOURCES})
endforeach()

# ===========================================================================
# RESET2 (run linkfull, lane RESET2): THE GAME LOOP'S OWN PHASE 2
# ===========================================================================
#
# port/slice_w31b_reset2.txt carries func_02019390, the ROM's frame phase 2
# (src/func_020197b8.c: `data_0209d50c = 2; func_02019390();`), and the four
# TUs only it calls. hal/fader_wipes.cpp's port_frame_phase2 calls it, and both
# host loops call that at the ROM's point (tests/walk_window.cpp's level loop,
# hal/scene_boot.cpp's port_scene_tick). A line whose path is followed by the
# word `hostgen` compiles its build/host-src copy made by port/tools/hostgen.py
# (the PMF3 block's shape): func_0200f4b4's three stores are geometry command
# ports. All three hosting targets take the slice, because hal/fader_wipes.cpp
# is compiled once for all of them and hal/scene_boot.cpp by each of them.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31b_reset2.txt" SLICE_W31B_RESET2_LINES)
set(SLICE_W31B_RESET2_SOURCES "")
foreach(line IN LISTS SLICE_W31B_RESET2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    if(line MATCHES "^(src/[^ ]+)[ ]+hostgen$")
        set(_w31breset2_src "${CMAKE_MATCH_1}")
        string(REGEX REPLACE "[.]c$" ".cpp" _w31breset2_rel "${_w31breset2_src}")
        set(_w31breset2_out "${CMAKE_BINARY_DIR}/host-src/${_w31breset2_rel}")
        add_custom_command(OUTPUT "${_w31breset2_out}"
            COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
                    --out "${CMAKE_BINARY_DIR}/host-src" ${_w31breset2_src}
            DEPENDS "${PORT_REPO_ROOT_ABS}/${_w31breset2_src}"
                    "${CMAKE_CURRENT_SOURCE_DIR}/tools/hostgen.py"
            COMMENT "hostgen ${_w31breset2_src}")
        list(APPEND SLICE_W31B_RESET2_SOURCES "${_w31breset2_out}")
    else()
        list(APPEND SLICE_W31B_RESET2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
    endif()
endforeach()
foreach(_tw31breset2 walk_window walk_window_hires smoke_player)
    target_sources(${_tw31breset2} PRIVATE ${SLICE_W31B_RESET2_SOURCES})
endforeach()

# ===========================================================================
# VARIANT5 (run linkfull, lane VARIANT5): THE TWO ABSTRACT BASE TABLES
# ===========================================================================
#
# _ZTV13daObjMaruta_c (ov080 0x02128338) and _ZTV16daObjFallBlock_c (ov098
# 0x0213c5bc) leave their per-symbol mounts (port/ov080_syms.txt,
# port/ov098_syms.txt) for host arrays holding the ROM contents slot for slot,
# hal/actor_classes_ov080.cpp and hal/actor_classes_ov098.cpp. Words 16 and 17
# of each are the class's own D1 and D0, whose flat ROM names the `#ifdef
# _MSC_VER` arms of the four src files on port/slice_w31_variant5.txt define.
# No ovdata mount is added or re-listed here (two tokens left two existing
# lists), so the XREL1 mount-deps block above still covers every mount.
#
# ALL THREE HOSTING TARGETS: the per-symbol mounts that used to define the two
# names (ACTOR_OV_SYMS) and the leaves' factories and destructors that store
# them are on walk_window's, walk_window_hires' and smoke_player's link lines
# alike, so the two arrays must be answered on all three.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_variant5.txt" SLICE_W31_VARIANT5_LINES)
set(SLICE_W31_VARIANT5_SOURCES "")
foreach(line IN LISTS SLICE_W31_VARIANT5_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W31_VARIANT5_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
list(APPEND SLICE_W31_VARIANT5_SOURCES
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_ov080.cpp"
     "${CMAKE_CURRENT_SOURCE_DIR}/hal/actor_classes_ov098.cpp")
foreach(_tw31v5 walk_window walk_window_hires smoke_player)
    target_sources(${_tw31v5} PRIVATE ${SLICE_W31_VARIANT5_SOURCES})
endforeach()

# VARIANT5, THE DROPPABLE HALF: fBase_c's base-object constructor. The
# transcription of arm9 0x02043dec that hal/actor_vtables.cpp carried moves,
# statement for statement, into the #ifdef _MSC_VER arm of
# src/_ZN7fBase_cC2Ev.cpp (the ROM's first store, the transient table
# data_02099edc, included), and hal/actor_vtables.cpp keeps only the storage
# the constructor reads. EVERY TARGET THAT COMPILES hal/actor_vtables.cpp takes
# the arm, so none of them loses the definition: the three hosting targets and
# the three excluded smokes (smoke_actor, smoke_savestate, smoke_persist).
set(VARIANT5_C2_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../src/_ZN7fBase_cC2Ev.cpp")
foreach(_tw31v5c2 walk_window walk_window_hires smoke_player smoke_actor
                  smoke_savestate smoke_persist)
    target_sources(${_tw31v5c2} PRIVATE "${VARIANT5_C2_SRC}")
endforeach()

# ===========================================================================
# LOOPIN2 (run linkfull, lane LOOPIN2): THE END OF PHASE 0x17, AND PHASE 7
# ===========================================================================
#
# port/slice_w31_loopin2.txt carries func_02023498 (the ROM's soft-reset latch,
# the last call of src/func_020197b8.c's phase 0x17) with the two clears it
# makes, and func_0201a4bc (phase 7, the VBlank sleep). tests/walk_window.cpp's
# level loop and hal/scene_boot.cpp's port_scene_tick / port_scene_run call
# them, and hal/scene_boot.cpp is compiled by all three hosting targets, so all
# three take the slice. smoke_player also takes hal/b5input_globals.cpp here:
# that file hosts data_0209f1dc, the latch's "combo still held" word, and the
# lane's census, and lane B5INPUT's block gives it to the two window targets
# only.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w31_loopin2.txt" SLICE_W31_LOOPIN2_LINES)
set(SLICE_W31_LOOPIN2_SOURCES "")
foreach(line IN LISTS SLICE_W31_LOOPIN2_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W31_LOOPIN2_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw31loopin2 walk_window walk_window_hires smoke_player)
    target_sources(${_tw31loopin2} PRIVATE ${SLICE_W31_LOOPIN2_SOURCES})
endforeach()
target_sources(smoke_player PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/hal/b5input_globals.cpp")

# ===========================================================================
# K1LOOP (run linkfull, lane K1LOOP): THE ROM'S ACTOR FRAME AT PHASE 4
# ===========================================================================
#
# port/slice_w32_k1loop.txt carries func_02044120 (the ROM's phase-4 actor
# frame, called by hal/actor_registry.cpp's port_actor_frame from both host
# loops) and __sinit_02075154 (the five list heads, bound in
# hal/ctor_runner.cpp's table). hal/actor_registry.cpp and hal/ctor_runner.cpp
# are compiled by all three hosting targets, so all three take the slice (a
# target that compiles a caller without its callee answers LNK2019).
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w32_k1loop.txt" SLICE_W32_K1LOOP_LINES)
set(SLICE_W32_K1LOOP_SOURCES "")
foreach(line IN LISTS SLICE_W32_K1LOOP_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W32_K1LOOP_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw32k1loop walk_window walk_window_hires smoke_player)
    target_sources(${_tw32k1loop} PRIVATE ${SLICE_W32_K1LOOP_SOURCES})
endforeach()

# ===========================================================================
# K2RENDER (run linkfull, lane K2RENDER): THE ROM'S PHASE 5
# ===========================================================================
#
# port/slice_w32_k2render.txt carries func_02019404 (the ROM's phase-5 step,
# the graphics block's word 1, called by hal/rom_frame.cpp's port_frame_phase5
# from both host loops). hal/rom_frame.cpp is compiled by all three hosting
# targets, so all three take the slice (a target that compiles a caller
# without its callee answers LNK2019). Placed above XREL1's block, which stays
# last.
port_read_lines("${CMAKE_CURRENT_SOURCE_DIR}/slice_w32_k2render.txt" SLICE_W32_K2RENDER_LINES)
set(SLICE_W32_K2RENDER_SOURCES "")
foreach(line IN LISTS SLICE_W32_K2RENDER_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^#" OR line STREQUAL "")
        continue()
    endif()
    list(APPEND SLICE_W32_K2RENDER_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${line}")
endforeach()
foreach(_tw32k2render walk_window walk_window_hires smoke_player)
    target_sources(${_tw32k2render} PRIVATE ${SLICE_W32_K2RENDER_SOURCES})
endforeach()

# ===========================================================================
# CROSSPATCH1 (run hunt4): THE PER-LOADED-LEVEL CROSS-POINTER SEAT
# ===========================================================================
#
# hal/cross_level_seat.cpp re-patches, on every level mount, the cross-mount
# words ovdata.py --cross has to leave raw (their target window is shared by
# several level or object overlays), from the table the same pass now appends
# to ov_cross.c. Its caller is hal/level_boot.cpp's port_level_mount_at, which
# all three hosting targets compile, so all three take the file. The generator
# scans hal/*.cpp for existing hand-seat rows and leaves those words to their
# seats, so the cross step depends on every hal source (a seat added or edited
# re-runs it; it takes a second). Placed above XREL1's block, which stays last.
foreach(_tcp1 walk_window walk_window_hires smoke_player)
    target_sources(${_tcp1} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/hal/cross_level_seat.cpp")
endforeach()
file(GLOB _cp1_hal_seats CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hal/*.cpp")
add_custom_command(OUTPUT "${OVCROSS_C}" APPEND
    DEPENDS ${_cp1_hal_seats})

# BBILL1 (run hunt4): THE ENDING'S LAST ICON STATE, HOSTED FROM THE ROM BODY.
#
# data_ov002_02110eec[8] (func_ov002_020f3de4) had an aborting face in
# hal/cutscene_states_link100.cpp because the function has no byte-matching
# src file. With any unlocked character (one is enough) the ending enters it
# right after Peach's cake line, so the port aborted there. port/unmatched/
# func_ov002_020f3de4.c is the banked near-miss of that body (register choice
# and one swapped independent pair away from the ROM); it reads
# data_ov002_021000c0, which port/ov002_syms.txt now mounts. All three hosting
# targets, the SLICE OV2T shape: the face that calls it is compiled into
# port_slice_shared, so the reference is on every one of the three link lines.
foreach(_tbbill1 walk_window walk_window_hires smoke_player)
    target_sources(${_tbbill1} PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/unmatched/func_ov002_020f3de4.c")
endforeach()

# XREL1 (run linkfull): EVERY OVERLAY MOUNT DEPENDS ON THE CONFIG IT READS.
#
# tools/ovdata.py builds each mount out of its overlay's config/arm9/overlays/
# <ov>/relocs.txt (which words are addresses), delinks.txt (the base and the
# section ends) and symbols.txt (the per-symbol ranges), and the cross pass
# builds on the mounts' sidecar maps. None of the add_custom_command calls
# above names those three files, so a config edit -- a relocation row removed
# because the word is not a pointer, a symbol moved -- left host-src/<ov>_data.c,
# <ov>_syms.c and ov_cross.c holding the OLD patch lists in every incremental
# build, and only a clean build saw the change. That is how a removed false
# relocation can look fixed in one tree and still ship from another.
#
# So append the three files of each mount's OWN overlay to that mount's
# command. The cross pass already depends on every sidecar map, so it re-runs
# whenever a mount does. A mount whose name does not start ovNNN_ is refused
# here rather than skipped: it would be the one that goes stale.
set(_xrel1_mounts 0)
foreach(_xrel1_map IN LISTS OV_DATA_MAPS)
    string(REGEX REPLACE "[.]map$" "" _xrel1_out "${_xrel1_map}")
    get_filename_component(_xrel1_name "${_xrel1_out}" NAME)
    if(NOT _xrel1_name MATCHES "^(ov[0-9][0-9][0-9])_")
        message(FATAL_ERROR "ovdata mount ${_xrel1_name} does not name its "
                "overlay (ovNNN_...), so the XREL1 block cannot tie it to "
                "its config/arm9/overlays/<ov>/ files")
    endif()
    set(_xrel1_cfg "${PORT_REPO_ROOT_ABS}/config/arm9/overlays/${CMAKE_MATCH_1}")
    add_custom_command(OUTPUT "${_xrel1_out}" APPEND
        DEPENDS "${_xrel1_cfg}/relocs.txt" "${_xrel1_cfg}/delinks.txt"
                "${_xrel1_cfg}/symbols.txt")
    math(EXPR _xrel1_mounts "${_xrel1_mounts} + 1")
endforeach()
message(STATUS "XREL1: ${_xrel1_mounts} ovdata mount(s) rebuild when their overlay's config changes")

# Port-only gameplay scripts; retail source and DS structure layouts stay intact.
include(hal/coop_mods.cmake)
coop_add_mods(walk_window lua_resource_pack)
coop_add_mods(walk_window_hires lua_resource_pack)

target_sources(walk_window PRIVATE hal/coop_texture_tools.cpp)
target_sources(walk_window_hires PRIVATE hal/coop_texture_tools.cpp)
