XSharp

Player physics and original-game traces

The active calibration uses Stag Final Climb. The X2 profile now retains horizontally corrected floor contact, gives a new Dash request priority over an immediate walking jump, and includes the final integer pixel in world-floor probes. Other profiles keep their existing probe dimensions. The older Gap Jumps milestones below retain their original validation scope.

For the current acceptance scope, measurements and next divergences, see scene-wide Gap Jumps comparison. It includes camera tracking, entity observations, RNG call provenance and expanded state-restoration checks. The older milestones below describe player-only progress and do not establish full-scene parity.

Selection

Set XSHARP_PHYSICS to common, legacy, x1, x2 or x3 before initializing the engine. The default is legacy. Code can set engine.PlayerPhysics = PlayerPhysicsProfile.MegaManX2; the selection is captured by the next player spawn. Immutable custom profiles can be derived with a record with expression and are validated before selection.

PlayerPhysicsProfile is the common, immutable record. MegaManXPhysicsProfile, MegaManX2PhysicsProfile and MegaManX3PhysicsProfile derive directly from it, in separate files. Shared defaults and validation live in the base; game-specific constructors contain only their overrides. Common exposes the common preset, while Legacy preserves the existing engine default and selection compatibility. A with customization preserves the concrete game profile type. X3 currently has no verified overrides beyond its identity; it deliberately does not inherit X2’s calibrated timing.

AllowHeldDashGroundJumps defaults to true in the shared profile and all three game profiles. This intentional engine feature permits dash-speed ground jumps while Dash remains held, even after the preceding dash has ended. Disable it explicitly for original-game replay comparisons:

engine.PlayerPhysics = PlayerPhysicsProfile.MegaManX2 with
{
    AllowHeldDashGroundJumps = false
};

Select the profile before spawning/loading X. This flag controls horizontal speed independently of prepared/immediate jump timing. Native mode still inherits a currently active or newly accepted dash; holding a dash rejected by a wall does not accelerate a later ordinary ground jump. It does not change wall-kick dash selection. XSharp.MovieParity explicitly disables the extension and records the selected value in its report. Keep the same custom profile when restoring snapshots; arbitrary profile overrides are not embedded in legacy positional save states.

These profiles describe X’s ordinary movement, independently of optional original-hardware constraints. engine.UseOriginalObjectSlots = true opts into native slot capacities, opaque initial occupancy and recycled fractional bytes; set it before loading content. It defaults to false for every physics profile. ContentObjectSlotPool captures this choice and serializes its allocation state. Ordinary mode allocates beyond the native capacity and reports address zero (no original identity), while strict mode delegates to SnesObjectSlotPool. The option is recorded in XSharp demo metadata. Exact SNES scheduling and loading stalls still require separate implementation; selecting a player profile or native slots does not certify those constraints or full-scene movie parity.

The optional SnesNtscCpuClock compatibility component separately tracks intrinsic CPU work, DRAM refresh and video counters without graphics/audio devices. It is shared across game content and serializes its clock phase; it does not alter the common/X1/X2/X3 player profiles or enable hardware restrictions automatically. Its ROM-free regression checks 11,999 native ordinary-instruction intervals. Graphics scheduling documents the supplied initial-clock inputs and the pending NMI/DMA/task integration; this component alone does not establish autonomous engine pacing.

The X2 preset pins the verified walking speed 0178, dash speed 0375, ground-jump impulse 0553, gravity 40 and maximum falling speed 05C0, in original 8-bit subpixel units. Other parameters retain their existing values until separately verified. X1/X3 currently retain the earlier preset conventions; they are not certified full-game physics ports.

The runtime profile is excluded from the legacy positional player snapshot. Restoration resolves it from the engine’s current selection. Keep the same profile/configuration when comparing or replaying a saved state. This milestone tests restoring a pending X2 jump with the same selection; storing arbitrary custom configuration inside snapshots remains future work.

Device-independent physics

XSharp.Physics references only XSharpShared, which supplies the fixed-point math and profile data. It has no reference to the XSharp engine or a graphics/audio backend. Its tests run without native devices, ROM files or an emulator. This boundary can be reused by HunterBaseStudio.

VerticalPhysics.Step integrates a vertical velocity before movement, applies the known floor/ceiling constraints and clamps the first downward remainder to a gravity step. It preserves quantization after each assignment and the previous assigned velocity, so extracting the routine from Sprite keeps the existing LastVelocity contract. Integrate returns only the final velocity for callers that do not need its assignment history. Positions and velocities use XSharp’s signed 16.16 representation with positive Y downward; ordinary sprite assignments retain eight fractional bits.

GroundJumpPhysics.GetAction evaluates the one-based accepted jump age and held button state. The X2 profile prepares standing/dash jumps on age 1 without vertical displacement. A jump accepted while fully walking initializes and executes jump control on age 1, including gravity and air input; releasing the horizontal direction clears VX immediately. Age 2 either launches or cancels on button release. Legacy/X1/X3 keep the previous launch-on-age-2 policy. Player uses the same decisions and supplies the prepared-frame motion override; Sprite uses the extracted vertical integrator. No new serialized actor timer is introduced.

This is the first separated part of simulation. Geometry collision, wall/ladder behavior, entity state machines, and the complete engine scheduler still require further separation from the game/render lifecycle.

Shared ballistic launch API

MovementUtil.GetObliqueLaunchVelocity in XSharpShared remains the shared launch API used by Dig Labour. Its existing five-argument analytic overload and fallback behavior are preserved. A second overload accepts 65 Q13 direction pairs supplied by game content and reproduces the SNES quantized solver with integer positions, 8-bit fractional velocities, Mode 7 multiplication, the original height clamp and a discrete angular search. It returns engine coordinates with positive Y downward. The native solver always chooses a velocity, including unreachable cases, so this overload returns that vector directly without claiming target reachability.

The shared solver owns the arithmetic; the optional X2 content module owns the original direction table. No enemy types, renderer, audio device or ROM reader are referenced by the math API. This keeps the existing API reusable by other actors and HunterBaseStudio.

ObliqueLaunchTests verifies 50 native results captured from X2 USA $04:81C1..8331, as well as both sides, above/below targets, vertical launches, table validation and the existing Dig Labour-style analytic trajectories. The native cases force Aclanda’s far-head-attack branch in private BizHawk states, transplanting player/head fields at source frame 610; entry/return callbacks only observe the helper. This is an explicit controlled experiment, not an unchanged movie playback. Its original table address, ROM SHA-1, CSV hash and all input/output values are pinned in XSharp.Physics.Tests/Fixtures/X2/aclanda-ballistic-aim.json. Original ROM/movie files remain unchanged.

X2 original-runtime evidence

XSharp.Physics.Tests/Fixtures/X2 contains seven CSV captures from the headerless Mega Man X2 USA ROM, SHA-1 637079014421563283CDED6AEAA0604597B2E33C. The recorded core is Snes9x 1.63 185488c; its binary hash, starting coordinates, scenario limits, snapshot hash and CSV SHA-256 hashes are in capture.json.

The probe naturally enters the intro stage with a fixed input sequence, walks away from a nearby enemy and verifies the expected idle state at frame 2300. Every jump case restores that same private core snapshot. Jump holds of 1, 2, 3, 8, 22 and 60 updates exercise preparation, early release and the apex. The script does not modify WRAM for jump captures.

The free-fall case changes only the private emulator’s player Y/velocity/state fields to place X above the same floor. It waits five updates for the existing ground-contact transition to settle, then records 65 uninterrupted falling updates through terminal speed. No ROM, emulator configuration, persistent user save state or original movie is modified. Native video/audio callbacks discard their output without creating a window or device.

For this revision, the sampled WRAM offsets are:

WRAM offset Value
09DC / 09DF X/Y position, three bytes with eight fractional bits
09F2 / 09F4 Signed X/Y velocity, two bytes with eight fractional bits
09F6 Gravity byte
09DA / 09DB Player movement state/substate

Original vertical speed is positive upward. Comparison negates that speed and keeps the original position scale. For XSharp values, use RawValue >> 8 to obtain original subpixel units; multiplying a 16.16 coordinate by 256 can overflow its intermediate representation.

The captured first jump update keeps Y unchanged while setting upward speed to 0553. A one-update tap then releases directly into a downward gravity step, without an upward displacement. The prior engine behavior still launched on that release update. The X2 timing option corrects this pending-jump cancellation. With a held jump, the next update moves upward by 0513, after applying gravity. Near the apex, downward speeds 002D, 0040, 0080 demonstrate the original remainder normalization. Long falling speed saturates at 05C0.

CSV files retain the later ground/contact observations. The automated curve comparison uses each jump’s contiguous unobstructed prefix, determined by the original relation position_delta_y == -vertical_speed and its original movement state. Geometry contact ends that prefix. In total the unit tests compare 129 jump updates and 65 falling updates (194 updates). These checks cover vertical motion, not full movement parity, landing quantization or original animation/state-ID equivalence.

Reproduce using Python 3.10+ and a locally installed libretro core:

python tools/parity/capture_x2_vertical.py `
    --rom 'C:\path\to\Megaman X2 (USA).sfc' `
    --core 'C:\path\to\snes9x_libretro.dll' `
    --output "$env:TEMP\xsharp-x2-vertical-traces"

The probe rejects an unknown ROM revision, an unexpected startup state and a nonempty output directory. A 512-byte copier header is normalized before identification. Native core and Python architecture must match. The capture was reproduced in a second process with identical hashes for all seven CSV files. Python is used only to regenerate original-runtime fixtures; the C# physics assembly and regression tests do not depend on it.

Validation

dotnet test XSharp.Physics.Tests/XSharp.Physics.Tests.csproj
dotnet test XSharp.Tests/XSharp.Tests.csproj
dotnet build XSharpDemo/XSharpDemo.csproj

The device-independent suite covers original traces, profile selection rules, quantized gravity, apex/terminal boundaries, contacts, suppressed gravity, assignment history and assembly independence. Engine tests check the production player/sprite integration, prepared versus launched frames, the separate wall-kick path and existing content regressions.

For the full player loop and a prepared-jump save-state replay on Windows:

dotnet build tests/XSharp.PhysicsSmoke/XSharp.PhysicsSmoke.csproj
Push-Location tests/XSharp.PhysicsSmoke/bin/Debug/net9.0-windows7.0
try {
    New-Item -ItemType Directory -Force Assets/ROMs | Out-Null
    Copy-Item -LiteralPath 'C:\path\to\Megaman X (USA).sfc' -Destination Assets/ROMs/ShittyDash.mmx
    .\XSharp.PhysicsSmoke.exe
} finally {
    Pop-Location
}

This native integration probe explicitly loads X1 Chill Penguin geometry/resources (stage 8) with the X2 player profile, scripted input and the real Direct3D 9 engine. It checks all six jump scenarios against normalized original X2 observations. For the cancelled one-update tap, geometry keeps X on the floor; that contact update checks cancellation instead of requiring the original game’s landing-coordinate rounding. A snapshot taken during the prepared impulse reproduces the next 30 position/velocity observations exactly after restoration. A second snapshot at the paused walking transition reproduces 20 subsequent updates, including a moving dash jump. The frame-local motion suppression is consumed before each completed-tick snapshot. The probe also switches to the legacy profile and checks its previous release-on-launch behavior. Its explicit initial-stage hook keeps this regression independent of interactive ROM_NAME / INITIAL_LEVEL changes. This does not establish X2 stage-loader parity or eliminate the native lifecycle requirement of the full engine.

User-recorded BizHawk X2 movies now supply additional original-runtime evidence. The X2 profile also prepares wall-kick speed on update 6 and preserves the original exit-substate pause. Three final-ladder clips compare 48 vertical position/speed observations in the production player/collision code without video or audio devices. Continuous Gap Jumps playback now runs all 4,186 inputs on the ROM-loaded Sponge stage. It exposed and corrected a stored-speed walking-transition mismatch and unwanted horizontal movement on the ground-jump preparation update. PreserveWalkingTransitionVelocity pauses transition displacement while retaining the old walking speed; X2 ground-jump preparation clears VX and pauses both axes. The current exact X/Y/VX/VY prefix reaches frame 103; landing/contact behavior still diverges from frame 104. See movie calibration for capture commands, provenance, the RUNASADMIN-free portable workflow and precise coverage limits.

Remaining physics work includes horizontal start/stop and reversal timing, dash transitions, full wall-jump/contact equivalence, the intermittent ladder-gap failure, slopes, water, ladders, ice/conveyors and controlled traces for X1/X3. Each needs its own original-runtime evidence and regression coverage.

The X2 flat-floor analysis records the next contact milestone. DeferFlatFloorContact preserves the original collision-produced Y fraction and delays the grounded controller transition until the following update, using Sprite’s existing serialized landing latch. The complete Gap Jumps comparison now matches through frame 121; wall contact diverges at 122/123. Original ROM write callbacks, an early/late Jump control pair, fractional-boundary tests and a 20-update pending-contact state replay validate this correction. Other contact types and complete movie parity remain open.

The subsequent wall-slide and airborne-input correction extends the exact continuous prefix through frame 158. The 500-input diagnostic passes a 20-update snapshot replay from wall-slide frame 123. Ceiling resolution diverges at frame 159; complete movie parity is still open.

The world-ceiling correction extends that prefix through frame 162 and passes a 20-update pending-contact replay from frame 159. The next mismatch is ladder acquisition at frame 163.

The ladder timing correction extends the exact prefix through frame 292 in a complete 4,186-input run, with no dying/non-alive frames and a passing 20-update mount-state replay from frame 163. Stored speed at dash stop diverges on 293, followed by position on 295; full-movie parity remains pending.

The dash-stop correction extends the continuous prefix through frame 406 and passes a 20-update replay from frame 293. The next mismatch is the last horizontal contact while rising past the edge of a platform, at 407.

The X2 native landing policy uses its own serialized LandingDuration countdown (default four positive controller updates). Completion requests idle before walking/Jump input on its last update and retains stored speed until idle initialization. Visual animation length and render advancement do not control this countdown. Earlier landing updates still permit the native walking/Jump interrupts. See controller evidence.

Moving objects: see support transport and jump detachment for the shared elevator/log repair, source evidence and validation limits.

At a ramp beside a water-surface tile, the lower collision probes can combine the slope flag with a water-surface modifier. The collider now retains the contact triangle whenever it classifies the floor as a slope and clears the triangle on exit. Previously the movement controller received an empty triangle in this case and divided by its zero horizontal length. The headless player regression walks toward a ramp from either side of the tile boundary.