XSharp

X2 cooperative graphics loading and held logic updates

The autonomous Gap Jumps.bk2 run first diverges on display frame 2185, although BizHawk reports no joypad lag. Read-only BSNESv115+ callbacks confirm that no game update executes on this frame. This is separate from player physics. The optional native cadence diagnostic supplies the held update explicitly; the engine does not yet derive it from its own simulated loading workload.

The MegaManX2Recomp source audit pins an additional original-code runtime reference and its framework dependency. It distinguishes existing CPU/NMI/DMA/CX4 support from engine-independent gameplay ports, and records the host-frame, DMA-alignment and refresh-placement differences that still require comparison with the BizHawk acceptance capture.

parity/gap-graphics-scheduler-boundaries.csv records executed scheduler and decompressor boundaries in two independent windows. Frame numbers identify the input/display frame currently executing. cycles is the value returned by BizHawk’s emu.totalexecutedcycles(). Source/destination fields are diagnostic register observations: Y temporarily becomes a back-reference source offset inside a copy, so source on display-start is not necessarily a ROM pointer.

Both windows request graphics resource 25 decimal ($19), compressed at $1D:C7C9, with $0160 output bytes. The scheduler runs that cooperative task at $00:B25E; $00:8184 checks 09CE between groups/tokens and yields if a new display update has arrived. The compressed copy itself has no such check. On completion $00:B342 clears 00F5, and $00:8125 clears 09CE before returning to its wait loop.

Boundary Native observation
1833, task starts Cycle 4,641,982,264; logic counter 07
1834, next yield point 32 bytes remain; 09CE=FF, so task yields
1834, task resumes Logic counter advances to 08 before decompression resumes
1834, completion Cycle 4,642,294,408; 09CE=00
2184, task starts Cycle 4,767,405,438; logic counter 66
2184, final yield point Cycle 4,767,567,722; 10 bytes remain, 09CE=00
2185, completion Cycle 4,767,588,902; 09CE=FF, logic counter still 66
2185, scheduler end Cycle 4,767,589,210; clears pending 09CE without running game logic
2186 Next game update advances logic counter to 67

The final copy at 2184 crosses the display boundary and completes before another yield check. The scheduler then discards the pending update signal. The earlier 1833 request of the same resource instead reaches another yield point after the boundary and retains normal game updates. This comparison rules out a policy that always stalls for this resource ID or byte length. An autonomous compatibility policy needs task phase, execution budget and yield boundaries, independently of the renderer/audio and the player’s selected physics profile. Hardcoding a movie frame or feeding the reference counter back into a certified run would not reproduce that behavior.

Provenance: X2 USA SHA-1 637079014421563283CDED6AEAA0604597B2E33C, movie SHA-256 7A880EF4635D2B15F8AF963DF6E2915C7D37A09B43160ED37F4E5BEC62134E4E. The normalized LF UTF-8 CSV SHA-256 is 03E70EC904851F86FFA089AC38EBB9F093C03D4842803148BE37FDFB6C9150A6. The private emulator uses an isolated configuration and an unchanged movie copy; callbacks only read memory/registers and observe execution. No ROM, state or input writes are used by the measurement.

Measured workload phases

parity/gap-graphics-workload-phases.csv independently records main-update, player/actor, camera, small-object, trigger and cooperative-task boundaries in 1829..1835 and 2181..2187. Relative to each display start:

Boundary / interval 1833 master cycles 2184 master cycles
Main update entry (CE75) 28,178 15,936
Player dispatcher (CEA4..CEA8) 12,940 14,878
Late player pass (CF1A..CF1E) 17,050 24,604
Main camera (CF26..CF29) 36,246 35,926
Background camera (CF2C..CF2F) 33,190 33,190
Small-object pool (CF39..CF3C) 21,228 16,660
Main update return (CF4E) 175,746 169,906
Graphics task entry (B25E) 205,756 193,462

These intervals include native execution and intervening hardware work. They are measurements of two different workloads, not constant costs that can be assigned to every update. In particular, the 12,242-cycle difference before main-update entry and the differing later scheduler work rule out deriving the complete start phase from just the player’s state or resource length.

parity/gap-graphics-nmi-dma.csv narrows that pre-update difference using read-only NMI and DMA-register observations. The native NMI is relocated to $7E:2000, returns at $7E:2042, and writes DMA enable at 2073, 226D and 2451 in these windows. The CSV lists only channels selected by the actual enable mask, rather than stale register contents of unselected channels.

Display NMI duration Transfers observed
1833 24,346 master cycles 544 OAM bytes; 512+512+224 ROM-to-VRAM bytes
1834 17,846 544 OAM bytes; four 64-byte WRAM-to-VRAM uploads
2184 12,128 544 OAM bytes
2185 17,838 544 OAM bytes; four 64-byte WRAM-to-VRAM uploads
2186 12,128 544 OAM bytes

The extra 1,248 ROM bytes at 1833 come from $2E:A440/A640/A840. The NMI duration difference (12,218 cycles) accounts for almost all of the 12,242-cycle main-entry difference. Identifying those uploads’ producing graphics requests, and deriving the engine’s corresponding queue, remains necessary; assigning their cost based only on a movie frame or a guessed player-state constant would not model the native loading pipeline. The private relocated NMI code dump is kept outside Git; the normalized measurement CSV SHA-256 is 476EE7E1BA83F8257C407D047A39226158F5DB8ACF6827898EBC93F7B017D0D0.

Incremental task component

X2GraphicsDecodeTask in the optional gameplay module reproduces the bounded decompression stream between the native checkpoints, independently of devices and without reference-frame input. It exposes group-start and post-copy boundaries, output/source progress and work counts. It copies overlapping LZ references byte by byte, saves partial groups/output, and offers no checkpoint after the final literal/copy. A copy in the eighth token produces two separate checkpoints: after the copy and before the following group. Coalescing those identical source/output positions would lose a real suspension opportunity.

The original resource-19 test matches all 64 independently captured checkpoint positions and remaining sizes; it serializes/restores at every checkpoint. The completed 352 output bytes also match the hash of an independent native $7F:0000..015F read at B342; the private output binary is not tracked. Synthetic tests cover literal groups, final/overlapping copies, consecutive checkpoints, destination limits and malformed streams. Source/fixture hashes are pinned in XSharp.Tests/Fixtures/X2/x2-graphics-scheduler-source.json.

This is the task component of the pending compatibility scheduler. Its work counts do not estimate CPU/DMA cycles, and it is not yet connected to autonomous engine pacing. Deriving task start phase and hardware work remains necessary before the held update at 2185 can be accepted without reference assistance.

Player tile-transfer planning

The player dispatcher $08:949C..94B1 compares its current image against the cached image before calling $08:C9B8..CA5B. That routine consumes the pending image flag and translates bank-05 frame descriptors into eight-byte entries in the shared queue at $0500, addressed by $00:A4. Repeating an animation entry with the same image does not reload its tiles, even when bit 80 remains set. The descriptors select ROM source bank/offset, byte count, destination VRAM word and the last-entry bit. This is independent of drawing that image on a host GPU.

X2SpriteGraphicsControl reproduces this cache and transfer planning without devices. A fresh read-only callback capture covers 4,185 logic updates of the complete movie: 852 requests, 2,097 transfers and 883,648 transferred bytes. The component test matches every resulting queue entry and retained/consumed frame flag, using original animation decisions as explicit component inputs. At 1832, image 56 queues the three ROM transfers consumed by the 1833 NMI, including $2E:A440/A640/A840 and their 512/512/224-byte sizes. No corresponding new image is queued immediately before the 2184 NMI.

Fixtures and source hashes are pinned by XSharp.Tests/Fixtures/X2/x2-player-graphics-source.json. Final native player/camera/RNG/counter values from this new capture match the independent full-scene capture. Tests also cover cache restoration, unchanged images, forced requests, empty frames, 16-bit source/destination arithmetic and malformed metadata. Hosted native player animation is covered below; the shared video queue and CPU/DMA time accounting remain integration work. This component test does not by itself change or certify the engine’s autonomous pacing.

The module now also contains the 112-frame table’s transfer metadata, rebuilt into an otherwise empty bank-shaped buffer. It embeds only the relative pointer table and 84 bounded descriptor lists, with no sprite tiles or complete ROM bank. The complete 2,097-transfer test and combined animation/graphics test therefore run without a ROM file. A separate opt-in test checks all 112 frame descriptors against the pinned original ROM, including nonzero page/resource-base arithmetic.

Player animation and retained shooting phase

The sprite-00 table at $2F:A222 has 133 bindings, normalized into 108 scripts with 369 entries. Some bindings begin inside a shared walking script and loop back before their initial entry. X2PlayerAnimationClock retains both the alias entry and its shared loop anchor, including original script addresses, countdowns, entry flags and pending-image bit. Native Set/Advance select entries and set the pending-image bit; transfer planning may consume that bit. A repeated image can keep the bit set without queuing another transfer.

Shooting changes use $08:B76F..B793, while shooting timeout uses $08:B930..B952. Both save the preceding countdown, select the new sequence, then restore that countdown before further animation. Resetting to the new entry duration made the first complete isolated replay differ at frame 550: native countdown 2 versus 3 after advancing. RestorePreviousCountdown retrieves the preceding C# countdown; it does not assign a counter supplied by a trace.

A fresh read-only capture records 8,617 chronological commands over the movie: 481 sequence selections, 3,895 advances, 56 countdown restorations and 4,185 graphics-planning steps. The combined animation/transfer component replay matches every intermediate native countdown, flags, image, script address and resulting transfer queue, with one imported initial state. All 133 generated bindings and their entries/loop targets are separately checked against the pinned ROM. x2-player-animation-source.json records hashes, initial state and command counts.

These tests explicitly supply the original controller’s commands to isolate animation semantics. Hosted command generation is covered below; native video and CPU workload accounting remains pending. The clock alone does not replace player control or establish autonomous whole-scene parity.

Hosted player control and graphics requests

X2PlayerAnimationControl now generates sequence selection, retained shooting phase and transfer requests from the engine’s own resolved player control. Its typed input includes current/previous movement states and vertical speed, resolved movement, ladder motion, wall-kick age, held controls, previous-facing contact and the existing walking-resume timer. Successful native weapon allocations notify the model of their gun poses; rejected allocations do not create shooting poses. No original animation commands or countdown corrections drive this hosted model.

The adapter preserves the distinction between requesting a controller and running its initializer. Ladder release ($08:B362..B380), dash stop ($08:9D85..9DCF), walking release and ceiling cancellation keep their previous sequence until the next control update. Ground-jump preparation and the wall-kick impulse update also hold the old animation and shooting timer. Top-ladder climbing moves first with its animation stopped, then restarts the stationary sequence. Idle shooting uses $08:B79A..B832, which starts a new duration, whereas moving shooting uses $08:B6E7..B799 and retains the preceding duration. Idle timeout resets its normal sequence; moving timeout retains the current phase.

parity/gap-jumps-player-animation-cadence-diagnostic.json records all 4,186 movie inputs: 4,187/4,187 player animation states match, alongside the existing player/camera/RNG, enemy, weapon and small-object audits. A state saved at movie frame 3041 reproduces the following 20 complete engine updates. This remains an explicit timing-assisted diagnostic: native display frame 2185 is held using the reference logic counter, and whole-scene acceptance remains false.

The headless player-animation-control-gap.csv fixture contains engine-generated control inputs and native assertion targets. Its two complete regressions compare all animation states and 2,097 transfers / 883,648 bytes, with and without snapshots at eleven controller/graphics boundaries. The fixture declares the reference cadence assistance; animation commands are generated by the C# model. The tests need neither a ROM file nor visual/audio devices. Separate original-ROM and component-command tests continue to check the metadata and clock semantics.

X2GameplayModule.EnableNativePlayerAnimation enables the simulation controller; it defaults to false and is currently enabled by the comparison host. Shooting coverage requires the native buster module. This experimental adapter covers the movie’s default player sprite 00 and graphics table 9609; other player variants, damage/death/spawn animations and visual substitution are not certified. It does not replace the legacy rendered player art. Native CPU/video workload accounting, autonomous loading cadence and complete scene/pixel comparison remain pending.

Object load sets and cooperative upload planning

X2ObjectGraphicsMetadata reads the native $00:AD38 loader’s metadata without an emulator or graphics device. The nested stage/load-set table is at $2A:B2D4; each six-byte entry selects a resource, a VRAM word destination, a palette offset and a palette page. The stage pointer tables are not in stage-number order. The reader derives their bounds from adjacent greater table offsets and the first list, rather than using the following stage number. The pinned ROM has 15 table entries, including auxiliary stage entries; this is not a claim that it has 15 ordinary playable stages.

The resource descriptor table is $06:FA01, with five bytes per resource: compressed source bus address and output size. The decompression coroutine starts with data bank 06 after $00:ADC9 changes the bank before yielding. Reading this table from bank 2A would produce incorrect pointers. Transfer scripts remain in bank 2A, addressed relative to $2A:FB02. Only metadata is needed by these APIs; they neither embed sprite tiles nor require a complete ROM at runtime.

For Sponge, load set 5 selects resources 15,3C,2D (hexadecimal), while set 6 selects 19,03,3B,57. At 2184, the new set-6 request replaces the set-5 task while its resource 3C is still being decompressed. The original does not finish the old set’s final resource before beginning the replacement. Task replacement therefore also belongs in the future scheduler; merely queuing all region requests in order would model a different workload.

X2ObjectGraphicsTransferTask models $00:AE17..AEFE: sequential decompressed WRAM sources, byte-sized destination-page arithmetic, the shared $1F38 upload budget, explicit FF script markers and the resource page fields. It suspends before an entry when the shared counter is at least 40 hex; an accepted entry may exceed that threshold. A marker always suspends, even with a free budget, and its own wait loop can suspend repeatedly. The caller supplies the current shared counter after each suspension; the task never resets it itself.

Fixtures/X2/object-graphics-load-gap.csv records read-only native callbacks over the first 2,210 display frames. Its 12 completed resource uploads produce 24 queue entries / 19,936 bytes and 13 cooperative upload suspensions. Two headless regressions match every written native queue tuple and suspension, with and without serialization at each pause. The replay explicitly supplies the original shared budgets, so it certifies the transfer component, not native CPU time or autonomous cadence. ROM-gated tests independently check the metadata reader’s stage bounds, the two load sets and all seven observed resource scripts. x2-object-graphics-source.json pins the ROM/movie and fixture hashes. The new capture’s final player, camera, RNG and logic counter match the independent full-scene capture at frame 2210.

Variable work after the main update

A separate read-only instruction trace from CF4E through B25E measured 30,010 master cycles at 1833 versus 23,556 at 2184. Native sprite preparation $00:D42A receives slots 1898,18B8,09D8 at 1833 and only 09D8 at 2184. The relocated $7E:2680 CX4 work also differs: observed loop visits at 26B8 are 18 versus 6, and at 26C5 are 50 versus 33. These are execution observations, not a cost model for arbitrary scenes. The final native player/camera/RNG/counter at 2187 again match the independent capture.

Although the elapsed main-entry-to-task intervals happen to differ by only 52 cycles in these two samples, their internal work is different. The near equality does not establish a fixed graphics-task start budget. The production transfer task deliberately does not convert these observations into a per-frame delay; autonomous native CPU/CX4/NMI workload accounting remains pending.

Decoder CPU work before hardware waits

X2GraphicsDecodeCpuTask wraps the existing data decoder with optional CPU-work accounting. It translates the executed paths of $00:B25E..B342: setup, literal groups, overlapping copies, explicit empty checkpoints, source-bank increments and the retained $7F:D000 comparison. It owns its partial-group counter and serializes it alongside decoded data and accumulated work. The context is bounded to the pinned game’s low slow-ROM banks, aligned direct page and 16-bit indices; unsupported output ranges and bus mappings fail explicitly.

The returned clocks describe uninterrupted CPU bus/internal work. The ordinary checkpoint poll costs 70 clocks before its return; after a scheduler suspension, execution instead returns at $8156 and does not repeat that poll. Saving/restoring the scheduler context, refresh, DMA, NMI and other coroutines are separate work. The 768-clock startup ends at the first $8184 checkpoint. It is not a fixed per-update budget. The bus/internal distinction is consistent with the primary bsnes CPU bus implementation and its 65816 indexed-read implementation; the actual execution paths are observed in BizHawk’s BSNESv115+ core.

A new read-only capture has 12,880 instruction observations over the two resource-19 requests. graphics-decode-cpu-gap.csv retains all 128 executed checkpoint intervals, including the resumed checkpoint after the earlier suspension. The component matches every interval’s nominal CPU clocks, consumed source bytes and remaining output, with restoration at every boundary. Both native startups contain 768 clocks of CPU work and take 808 elapsed clocks. The final 10-byte copy contains 3,116 clocks of CPU work but takes 21,180 elapsed clocks across the NMI. Replacing elapsed time with an instruction count would therefore still lose the hardware work responsible for the held update.

tools/parity/normalize_x2_decode_cpu_trace.py derives the assertion targets from the observed PCs/flags and original opcodes, independently of the C# decoder and its timing model. It rejects unknown instructions, validates the pinned ROM/movie and writes a new output directory. The source JSON records both the normalized fixture hash and private raw-trace hash. Original ROM bytes are not stored in the fixture. The capture’s final player/camera/RNG/logic-counter state at 2187 matches the independent scene capture.

This remains a component milestone. No reference time or frame number drives production execution, and the gameplay host does not yet use this optional model to pace updates. Hardware waits, task replacement/context costs, the shared video queue and the engine-generated task start phase still need integration before autonomous cadence or whole-scene equivalence can pass.

Shared NTSC clock and DRAM refresh

SnesNtscCpuClock lives in the shared, device-independent compatibility code. It advances supplied intrinsic CPU work and inserts the five eight-clock DRAM stalls once per scanline. Revision 1 uses refresh position 530; revision 2 retains the CPU divider phase when selecting the position. Physical horizontal clocks, the two six-clock long dots, field parity and the odd noninterlaced short line are separate from the host’s renderer. Standard 224-line VBlank edges are reported without adding an invented NMI-service duration. NMI/IRQ, DMA/HDMA and coprocessor waits remain separate accounting work.

The implementation follows the primary bsnes refresh timing and PPU counter behavior. Native instruction-boundary observations independently validate the revision-2, noninterlaced ordinary-line path. Boundary tests also cover revision 1, both divider phases, long dots, the short line, interlace field lengths, VBlank/field edges, zero work and snapshot restoration. Those additional paths are unit coverage based on the counter implementation, rather than new hardware captures.

snes-ntsc-refresh-gap.csv.gz contains 11,999 native ordinary-instruction intervals, including 243 refresh stalls. Every elapsed clock count, resulting physical H position, scanline and H dot matches in the ROM-free regression. The normalizer reconstructs the physical H origin uniquely from the native H-dot observations for three continuously traced spans; the later resumed span gets a new origin after the unobserved short scanline. No movie frame number chooses an origin. Interrupt-service and coroutine-suspension intervals are excluded.

Each component case explicitly supplies the observed initial native clock. This validates the clock’s transitions, not the engine’s autonomous phase or CPU work before task entry. The model is currently optional and unconnected to default physics/pacing. Initial clock import, NMI/DMA workload, context switching and task replacement still need integration before the held display update can be generated and accepted independently of reference cadence.

The same read-only instruction trace regenerates both clock fixtures:

python tools/parity/normalize_x2_decode_cpu_trace.py `
    --trace 'C:\path\decode-cpu.csv' `
    --rom 'C:\path\Megaman X2 (USA).sfc' `
    --movie 'C:\path\Gap Jumps.bk2' `
    --output 'C:\path\new-normalized-output'

Normal X2 NMI work from upload queues

SnesCpuBusTiming separates the CPU’s nominal 6/8/12-clock address regions. SnesDmaTiming accounts for general-DMA divider synchronization, shared startup, per-enabled-channel work, transfer bytes and alignment back to the halted CPU cycle. Zero in a hardware size register means 65,536 bytes. Refresh is supplied by the common clock; HDMA interactions remain separate. The primary bsnes DMA implementation and activation/resume edges explain why a fixed per-transfer setup is insufficient. Native uploads halt both eight-clock bus cycles and six-clock internal cycles in these captures.

X2NormalNmiWorkPlanner translates work between the normal driver’s transfers from $7E:2000 to the RTI at $2042. It generates that sequence from pending palette, general-VRAM and tile-upload queues plus semantic audio-queue state. It does not consume original instruction commands, movie frames or elapsed-time corrections. Its scope is video mode 0, clear 09CE/09D0, ordinary OAM, no HDMA, enabled P1 and standard SNES pads. Interrupt entry/vectoring, the 52-clock RTI, other NMI modes and subsequent interrupts remain caller responsibilities. The planner only accounts for work; it does not write emulated PPU/audio registers or replace the engine’s visual/audio devices.

The expanded original capture contains 52 NMIs / 159 DMA transfers, with mixed palettes, one-to-three general uploads, two/four tile uploads and four ordinary audio commands. The ROM-free component test matches every complete handler’s intrinsic CPU work, actual elapsed clocks and final physical H/V counters, with and without restoring its initial clock. Nominal per-instruction analysis independently checked 18,635 transitions in the private capture. Native idle OAM-only handlers take 12,128 or 12,136 clocks depending on alignment; the four-tile handlers include 17,830, 17,838 and 17,846-clock cases. No one of those totals is used as a per-frame constant by the planner.

x2-nmi-work-gap.json and its source JSON pin the semantic cases and raw trace hashes. Original opcode/branch observations generated the assertion targets independently of the C# planner. Field parity is constrained by observed short-line behavior and the recorded display sequence. Final native player/camera/RNG/counter at 2209 match the independent complete-scene capture. The observed audio paths cover empty queues and ordinary ready commands; additional translated audio paths have not received an independent native capture in this milestone.

The fixtures explicitly provide each native initial NMI clock and queue contents. The gameplay host does not yet generate all these queues or dispatch the planner. Consequently this is component timing parity, not autonomous engine cadence or whole-scene movie acceptance. The external runtime audit also records existing implementations to consult before further translation.