# Names for GGSEA4 (Metal Gear Solid: The Twin Snakes, USA rev 0; main.dol and mgso.rel are the
# same on both discs), identified by analysis: functions and the data words the runtime uses.
# There are no symbols for this game. "sigmatch" = found with tools/sigmatch.py from Red Three's
# identifications in Rebel Strike, which has the same SDK (masked code: call targets,
# small-data offsets and address halves left out).
# <address> <name>
8000519C memcpy                  # Metrowerks runtime (__mem.c, in .init): a byte loop, forward or backward by overlap
80005240 __start                 # the DOL's entry point
# SDK OS (2003 SDK, 0x2301: OS and DVD "Jul 23 2003", most others "Apr 17 2003")
8001E2AC OSSetCurrentContext     # sigmatch exact
8001E308 OSGetCurrentContext     # lis r3,0x8000; lwz r3,0xD4(r3); blr - right after OSSetCurrentContext
8001E314 OSSaveContext           # stmw r13,52(r3); mfspr gqr1..; 0x80 bytes before OSLoadContext, as in Rebel Strike
8001E394 OSLoadContext           # sigmatch exact
8001E46C OSGetStackPointer       # sigmatch exact
8001E4A4 OSClearContext          # sigmatch exact
8001E4C8 OSInitContext           # sigmatch exact
8001E584 OSDumpContext           # sigmatch exact
80020680 OSDisableInterrupts     # sigmatch exact
80020694 OSEnableInterrupts      # sigmatch exact
800206A8 OSRestoreInterrupts     # sigmatch exact
8001BFF0 PPCHalt                 # sigmatch exact (sync; nop; li r3,0; nop; b .)
8001E8F8 OSReport                # sigmatch exact
8001E978 OSPanic                 # sigmatch exact
8001CAD0 OSDefaultExceptionHandler  # sigmatch exact
8002799C DVDReadAsyncPrio        # sigmatch exact
80029AF0 DVDChangeDiskAsync      # (block r3, disc ID r4, callback r5): command 3 (called from the module at 7F2379B0); its assert "DVDChangeDiskAsync(): You can't specify NULL to company name"
80021874 RealMode                # sigmatch exact (2003 SDK): rfi into the BAT setup with IR/DR off
800217F4 Config24MB              # sigmatch exact (two candidates: 800217F4, 80021774)
8002148C OSLink                  # called by the module loader 800066F8 with (module, bss)
8002FF70 AISrcInit               # SDK __AI_SRC_INIT (sigmatch exact, from Red Two's 80041C04): times AISCNT ticks at 32 / 48 kHz with OSGetTime
# The module loader (main.dol): reads shared/mgso.rel (mgso_pal.rel, mgso_kor.rel by region)
# into a heap buffer, copies it to 0x7F008000 (virtual memory), allocates its bss and links it
800066F8 LoadModule              # (name r3, address r4 = 0x7F008000, limit r5 = 0x7C2000)
80006814 LoadGameModule          # picks the module by the disc's region, LoadModule, checks its size
800055E0 VMSetup                 # (0x1A0000 bytes of MEM1 for pages, at the arena's start + 0x580000; 0xA7C000 bytes of VM)
# The SDK's VM library (virtual memory at 0x7E000000-0x7FFFFFFF paged from ARAM; mgso.rel lives there)
800497EC VMSetSdr1               # (msr r3 with IR/DR off, SDR1 r4): rfi to its physical self, mtsdr1, rfi back
80049834 VMInstallVectors        # patches 0x80000300 (DSI) and 0x80000400 (ISI) with branches to the stubs below
800499B0 VMDsiVector             # DSI stub, run untranslated: DAR in 0x7E000000-0x7FFFFFFF and DSISR "no translation" -> VMDsiHandler
80049B58 VMIsiVector             # the same for ISI (never taken: recompiled code fetches nothing)
80049AF4 VMDsiHandler            # (context r3, DAR r4): pager [r13-31028](DAR) in a temporary context, then OSLoadContext(context)
# The SDK's AX library (audio): its DSP ucode is run by src/runtime/hw/ax_dsp.cpp
80032030 AXInit                  # registers the "AX" banner (0x8027DED0 -> 0x801E1B50), AXInitEx(0)
80033434 AXOutInit               # 3 output buffers of 640 bytes at 0x801F3220, the DSP task (ucode 0x801E36C0), AI DMA
80033064 AXOutNewFrame           # builds the list (0x8003297C), mails 0xBABE0180 + its address
8003297C AXBuildCommandList      # (S buffer 0x801F39A0, output buffer): commands 0 7/17 2 3 4 5 19/16 18 14 15
8003321C AXOutAiCallback         # AI DMA interrupt: a new frame unless the DSP is still busy, the next output buffer
800332E4 AXOutResumeCallback     # the DSP's "resume" (0xDCD10001): a frame that came while it was busy
# Game threads in main.dol
8004BED8 GxFifoThread            # loops: GxFifoWork, OSYieldThread (context 8020C120, from boot)
8004BEF0 GxFifoWork              # polls the FIFOs (GetFifoPtrs 800410FC), state block 0x8020BD48 (+188 state, +5884, +10268)
800410FC GXGetFifoPtrs           # (fifo r3, &read r4, &write r5): the CPU FIFO from PI, the GP FIFO from CP 0x30-0x3A
80023F34 OSYieldThread           # OSDisableInterrupts, the scheduler 80023CDC (yield), OSRestoreInterrupts
80023CDC SelectThread            # __OSReschedule's worker: saves the current context, loads the next ready thread's
# Game state (the module's bss, 0x8054A180+; data in the module's virtual memory)
7F493638 StageSlotTable          # two pointers (module data, ADDR32 relocations): StageSlotA, StageSlotB
805A18F8 StageSlotA              # a stage record: its area name at +0x30 ("area01a" at the dock)
805A345C StageSlotB              # the other one (current / next not known yet)
# The game's status record (the one StageSlotTable's first pointer names: the LIFE bar and O2 gauge
# read it): life +0x11E, its most +0x120, O2 +0x122, its most +0x124; s16 arrays per weapon and item
80556C90 WeaponAmmoPtr           # (bss) -> s16 per weapon: its ammo, -1 not had (the record + 0x2D4)
80556C94 WeaponAmmoMaxPtr        # (bss) -> s16 per weapon: the most it can hold
80556C98 ItemCountPtr            # (bss) -> s16 per item: how many (the item box's "%d/%d")
80556C9C ItemCountMaxPtr         # (bss) -> s16 per item: the most
8055780C SnakeActorPtr           # (bss) -> Snake's actor: life +0x5B2 (what damage takes), grip time +0x158
80580936 MagazineSize            # (bss) s16: the rounds a magazine of the weapon in hand holds (15 with the SOCOM)
8058093A MagazineRounds          # (bss) s16: the rounds left in it
# Cameras (the module): every 3D view's projection comes from MakeProjection, at exactly 4:3
7F3BF15C ViewSetup               # at stage load: the view objects' matrices (MakeProjection, 7F114E64, 7F1146A0)
7F114BA0 MakeProjection          # (out r3, zoom f1, x scale f2, y scale f3, offsets f4 f5, depth f6 f7, f8 + stack): zoom x projection
7F3AA360 RenderView              # (view object r3): its 4 matrices (+0x00 .. +0xC0 = projection) to the renderer 0x805ACC24 +0xB80.., GXSetProjection
800468B8 GXSetProjection         # (mtx r3, type r4: 0 perspective, 1 orthographic): XF 0x1020-0x1026
8004695C GXSetProjectionv        # the vector form: XF 0x1020-0x1026
80046C74 GXSetViewport           # XF 0x101A-0x101F
80025B84 MTX44Transpose          # (src r3, dst r4), paired singles

# The frame snapshot (the codec's background: the scene as the call came in)
8004CB44 XfbToTexture            # (xfb r3, texture r4): the XFB's YUYV to an RGB565 texture on the CPU (YUV->RGB 8004CA28)
8020BD50 XfbRenderModePtr        # (data) the render mode it reads: fbWidth +4, efbHeight +6, xfbHeight +8
8020E568 XfbToTextureBlack       # (data) nonzero: it fills the texture black instead
# The game's 2D overlay pass: the radar's dark box, the first-person view's tint and head shadow,
# and the crawl view's dark ring (first person in a duct or a gap under a wall). A draw callback
# registered at boot (7F2E4628; its texture setup 7F2E46E8: a white 8x8 RGBA8 at 80581180, texture
# object 80581140), called every frame.
7F2E43A4 OverlayDraw             # the crawl ring: 2 x 32 black quads, alpha 160 inside, 255 outside, orthographic in GS units
# First-person view (Z held, and the crawl view): found by memory diffs in the holding cells
8055772C FirstPersonFlag         # (bss) u32: 1 in first-person view, 0 otherwise
8055774C FirstPersonPitch        # (bss) s16, 4096 a turn: stick up makes it negative (looks up), stops near -600
80556CB8 HudWindowFlags          # (bss) u32: 0x800 the usual HUD, 0x200 the item window open, 0x100 the weapon window (memory diffs, Tank Hangar)
# Psycho Mantis reads the memory card (his actor, 0x710 bytes: the scan's results at +0x6F8 - [0] a
# card, [1] this game's saves, [2] their files, [3..6] Melee / Sunshine / Wind Waker / Eternal Darkness
# files; the scan 7F31C3B4 -> 7F31C158 probe + mount, 7F31C0A8 this game's files, 7F31BFB4 the four
# games, codes at 7F489CF0)
7F0A41E4 TortureUpdate           # (object r3, every frame of Ocelot's torture): its life +0x5F2 -> the record's +0x11E
7F04E08C MantisReadCard          # (actor r3, r4 0 at the first call): his lines on the results, then saves (record +0x15E) > 8 or not
8055774E FirstPersonYaw          # (bss) s16: stick right lowers it; at most ~38 a frame (200 deg/s), linear in the clamped stick to ~58 of 72
# The alert phase (the status record + 0x13E: 0 sneaking, 1 alert, 2 evasion, 3 caution), run every frame by
# 7F17176C (r3 = the alert manager 805724C0, +0x20 the alert level: 1024 or more starts an alert). The radar's
# update (its object's act function, registered at 7F2EE068) asks 7F2EBC94 for its mode - 4 (jammed) when
# game flag 16 or 128 is set, else the phase - into the radar + 0xA4, and 7F2ED0DC (called only from it)
# reads the phase too.
7F2ED5A8 RadarUpdate             # (the radar object r3, every frame in play)
