Skip to main content

Module bk2_interop

Module bk2_interop 

Source
Expand description

BizHawk .bk2 movie interop.

Import + export of the text payload of a .bk2 archive (the Header.txt + Input Log.txt members) to and from the native Movie type. It mirrors the FCEUX crate::movie_interop .fm2 design, with one structural difference: a .bk2 is a ZIP archive, not a flat text file.

§no_std and the ZIP split

The rustynes-core chip stack is #![no_std] (core + alloc only), so it does not open or write ZIP containers — that needs std + a zip crate. Instead, the core handles the part that is no_std-clean and shared across every frontend: parsing / emitting the two text members. The frontend reads the two members out of the .bk2 ZIP (and writes them back into one) and hands their string contents here. The split is the same reason .fm2’s text parse lives in core while file I/O lives in the frontend.

§The .bk2 text format (the subset we model)

  • Header.txtKey Value lines (space-separated). The keys we read: Platform (must be an NES family token), rerecordCount, Author, GameName, SHA1 (stored verbatim; the authoritative SHA-256 ROM identity is supplied separately by the caller, exactly like .fm2’s MD5), and the region flag PAL. A StartsFromSavestate/StartsFromSaveRam movie is rejected (cross-emulator save blobs are not portable — same policy as .fm2).
  • Input Log.txt — a [Input][/Input] block. The first line is a LogKey: declaration listing the |-separated controller column groups; subsequent lines are per-frame input, each |-delimited, every button rendered as its mnemonic letter (pressed) or . (released). The first group is the console-buttons group (Reset / Power); then one group per controller port.

§The NES gamepad mnemonic order

BizHawk’s NES standard-controller mnemonics are U D L R S s B A (Up, Down, Left, Right, Start, select, B, A — note the lower-case s for Select, distinct from the upper-case S for Start). Any non-./non-space character in a column means that button is pressed; the column’s position (not the specific letter) selects the button, so we tolerate either the canonical mnemonic letter or any other pressed marker.

§Deliberate limitations (mirroring .fm2)

  • Standard gamepads, players 1 and 2 only. FrameInput models two ports; extra controller groups are parsed but dropped (their presence is not silently misleading — only P1/P2 are mapped). The console Reset bit is parsed but not represented on FrameInput (it has no reset bit), exactly as in .fm2.
  • Power-on start only. See above.

This module is no_std-clean: it uses only core + alloc.

Structs§

Bk2ExportOpts
Options the caller supplies on export that the Movie does not carry. Mirrors the extra header fields surfaced by Bk2Meta on import.
Bk2Meta
Header metadata parsed from a .bk2 that has no home on Movie.
Bk2Text
The two text members of a .bk2 ZIP, returned by export_bk2 for the frontend to pack into the archive (and accepted by import_bk2).

Enums§

Bk2Error
Errors produced by .bk2 text import / export.

Constants§

BK2_HEADER_MEMBER
The filename of the header member inside a .bk2 ZIP.
BK2_INPUT_LOG_MEMBER
The filename of the input-log member inside a .bk2 ZIP.

Functions§

export_bk2
Serialize a Movie into the two text members of a .bk2 ZIP.
import_bk2
Parse the Header.txt + Input Log.txt text of a .bk2 into a Movie plus the leftover header Bk2Meta.