Press F9 to capture the current simulation state and begin recording. Press F9 again to finish an atomic save to demos/latest.bk2, relative to the working directory. BaseEngine.DemoPath changes that shortcut’s path. A failed save leaves the recording active and preserves the previous file so it can be retried. Finish recording before closing the application.
Recording and playback are integrated into master. Rebuild XSharpDemo before using F9/F10; older executables do not contain these shortcuts. To report a gameplay problem, start recording before the trigger, reproduce it, press F9 to save, then preserve the resulting BK2 before recording another session. The default path is reused. Keep the matching executable/core build for full snapshot playback; changing the build requires an aligned input-only replay instead.
Press F10 to restore that demo’s initial XSharp state and replay it. Press F10 again to stop playback. The last frame remains held at end of file, including for an empty movie, until playback is explicitly stopped. Live gameplay buttons are ignored during playback. Pause/Break and the frame-advance shortcut continue to control the host scheduler. A held frame-advance pause consumes no input rows. Game pause and hit-stop frames still occupy rows because they are accepted simulation ticks.
F7/state loading and the N/M debug shortcuts are blocked during an active demo. Visual debug overlays and F5/state saving remain available. Programmatic callers must likewise avoid modifying simulation state or changing configuration during a session. Start a new recording after making such changes.
The starting snapshot contains the existing engine save-state payload, including RNG, entity state, player input history, camera and frame counter. Movie/session state is separate from that snapshot. Full snapshot playback requires the same core assembly build identifier, engine type, ROM SHA-1 and player physics profile name. It validates the stored starting frame and rolls back if restoration fails. The ROM, assets and configuration must remain available and unchanged; custom physics values and runtime camera/weapon policies must also stay fixed. Current snapshots retain the existing save-state implementation’s assumptions about resource paths and serialized callbacks.
using XSharp.Engine.Demos;
engine.Demo.StartRecording(@"demos\jump-test.bk2");
// Let the ordinary game loop run, or advance it with scripted controller input.
DemoMovie recorded = engine.Demo.StopRecording();
engine.Demo.StartPlayback(@"demos\jump-test.bk2");
// Playback reaches DemoMode.Completed and holds the last state.
engine.Demo.StopPlayback();
Call the API on the simulation’s owning thread between complete ticks. DemoController, DemoSession, DemoMovie, IDemoStateHost and Bk2MovieFile do not create graphics or audio devices. The full BaseEngine loop still runs PostThink/physics through its rendering lifecycle; separating that lifecycle is a further modularization task. Passing the independent controller tests does not establish that the complete engine can initialize headlessly.
Files use the BK2 ZIP layout and SNES joypad Input Log.txt syntax. The native XSharp variant sets Core XSharp and adds these entries:
| Entry | Contents |
|---|---|
Header.txt |
SNES platform, source ROM SHA-1 when available, engine type and movie metadata |
Input Log.txt |
One controller row per accepted simulation tick, with an explicit LogKey |
BizState 1.0 |
BK2 archive marker |
XSharp.Movie.json |
Extension version 1, core assembly build GUID, initial frame and state SHA-256 |
XSharp.State |
Native XSharp save-state bytes |
The XSharp snapshot cannot be loaded as a SNES emulator state. Opening a native XSharp movie directly in BizHawk does not provide a playable original-game movie. Use a matching movie recorded by BizHawk as an export template. The exporter preserves its original header, core, sync settings, starting state, SRAM and other opaque entries, and replaces its input log. The template’s starting state must already correspond to the XSharp starting situation.
DemoMovie movie = Bk2MovieFile.Read(@"demos\jump-test.bk2");
Bk2MovieFile.ExportForBizHawk(
@"demos\jump-test-bizhawk.bk2", movie, @"demos\aligned-bizhawk-template.bk2");
The template and recorded movie must use the same ROM SHA-1 when the recording specifies one. Preserve the template’s emulator core and sync settings when running the export. Export copies original header metadata and annotations verbatim, so timing summaries, subtitles and comments inherited from a differently sized template may need updating. Align the game revision, checkpoint, position/subpixels, velocity, RNG, input history and first input frame before interpreting a difference as a physics defect. An import/export round trip confirms controller encoding, without proving behavioral parity between engines.
SNES button mapping follows the default original-game controls:
| SNES control | XSharp input | Keyboard |
|---|---|---|
| D-pad | LEFT / UP / RIGHT / DOWN | Arrow keys |
| Y | SHOT | V |
| B | JUMP | C |
| A | DASH | X |
| X | WEAPON | D |
| L / R | LWS / RWS | L / R |
| Start / Select | START / SELECT | Enter / Escape |
The reader follows the file’s LogKey, including reordered player-one buttons. Reset, Power and player-two controls may appear in the schema only while unpressed. Active reset/power/player-two input, non-SNES platforms, analog devices, unsupported controls, malformed logs, duplicate ZIP entries and corrupted XSharp state hashes are rejected explicitly. Current limits are 2,000,000 input frames, 256 MiB per ZIP entry and 512 MiB total uncompressed archive size.
To apply a foreign BK2 or a recording from another core build, first align the current state manually and opt into input-only playback:
engine.Demo.StartInputPlayback(@"demos\original-bizhawk.bk2", startFrame: 120);
// No foreign emulator state is restored. Input row 120 is the next row consumed.
Offsets are zero-based. Import uses the current engine state, game resources and configuration. The caller is responsible for alignment. Finishing input-only playback holds the final frame in the same way as native playback.
BaseEngine.DemoFrameCompleted observes each accepted demo tick after its PostThink/physics phase, including paused and frozen game ticks and the final movie row. It is not raised for a held host frame or repeated renders at end of file. movie_frame is zero-based. engine_frame is the restored engine counter after the tick. Player values are blank when there is no player.
using var trace = File.CreateText(@"demos\jump-test.bk2.csv");
trace.WriteLine(DemoFrame.CsvHeader);
void WriteFrame(DemoFrame frame) => frame.WriteCsv(trace);
engine.DemoFrameCompleted += WriteFrame;
try
{
engine.Demo.StartPlayback(@"demos\jump-test.bk2");
// Run the ordinary loop until the movie completes.
}
finally
{
engine.DemoFrameCompleted -= WriteFrame;
}
CSV columns are engine_frame,movie_frame,input,x_raw,y_raw,vx_raw,vy_raw,player_state,rng. Coordinates and velocities use signed 16.16 fixed point with positive Y downward. Divide raw values by 65536 for pixels or pixels/tick, or by 256 for the original games’ 8-bit subpixel unit. Original WRAM addresses and state identifiers vary between games and revisions. Normalize their scale, Y velocity convention and frame boundary before comparing. XSharp player_state is its own enum identifier. It is useful for repeatability checks but has no direct numeric equivalence with original WRAM state bytes.
The ladder-transition and wall-jump clearance calibration on 2026-11-06 passed 469 core/demo/combat/content tests and 42 physics tests. A native Direct3D 9 probe on Wire Sponge with the X2 physics profile recorded 360 accepted ticks and reproduced the observed player/physics/RNG trace exactly twice, including held-frame and EOF checks. Original Gap Jumps.bk2 import/export preserved all 4,186 input rows and the template’s core/settings entries. These are deterministic XSharp replay and file-interchange checks, not full gameplay equivalence with the original ROM. The scene comparison records the separate continuous original-game comparison and its remaining divergences.
The unit suite runs without opening a graphics window or audio device:
$env:XSHARP_TEST_ROM_X1 = 'C:\path\to\Megaman X (USA).sfc'
dotnet test XSharp.Tests/XSharp.Tests.csproj
Demo tests exercise all 4096 supported input combinations, 2000 deterministic fake-host ticks, snapshot ownership, replay input suppression, offsets, EOF, incompatible build/ROM metadata, restoration rollback, failed atomic file replacement, BK2 schemas and template preservation. The fake-host tests verify the controller’s contract independently of engine physics.
The Windows integration probe uses the actual Direct3D 9 engine, ROM loader and physics. Build it, supply a local ROM under the configured Consts.ROM_NAME, and run from its output directory so the copied assets can be found:
dotnet build tests/XSharp.DemoSmoke/XSharp.DemoSmoke.csproj
Push-Location tests/XSharp.DemoSmoke/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.DemoSmoke.exe "$env:TEMP\xsharp-demo-smoke.bk2" 'C:\path\to\original-SNES.bk2'
} finally {
Pop-Location
}
The second argument is optional. The probe records 360 ticks with movement, jumps, dashes, shots, game pause and initial hit-stop. It replays twice with conflicting live input and compares every observed player position, velocity, state and RNG value. It also checks held-frame boundaries, EOF and manual-load rejection. An optional original BK2 round trip compares every input row and every retained template entry byte for byte.
Local validation also loaded an exported 7,600-frame Mega Man X2 USA movie through the installed BizHawk 2.11 BasicMovieInfo reader. This establishes archive recognition and input-count preservation. Running that export in the original game and measuring XSharp/original physics parity remain separate checks. No ROM, original movie or complete native state/trace is committed. Selected controller observations and source hashes are retained as regression evidence under docs/parity.
BK2 reference implementation: BizHawk movie code.
The developer console also records successful world-changing
commands in an optional integrity-checked XSharp.Console.json timeline. Replay
executes them once before the corresponding upcoming input frame, using the
initial console snapshot. Live world edits are blocked during replay. Movies
with these XSharp-only commands cannot be exported as original-game input-only
movies; older movies without the timeline remain supported.