# famicom-libretro [famicom-rust](https://github.com/alewman/famicom-rust) (the Rust Famicom/NES board checked cycle-for-cycle against [famicom-python](https://github.com/alewman/famicom-python)), in its speed fork [famicom-rust-fast](https://github.com/alewman/famicom-rust-fast) (gated trace-identical to it), as a libretro core, for RetroArch and the distros built on it (ROCKNIX). The libretro API is written by hand in `src/lib.rs`: no bindings crate, no C. ```text cargo build --release # target/release/libfamicom_libretro.so retroarch -L target/release/libfamicom_libretro.so game.nes FAMICOM_LIBRETRO_ROM=game.nes cargo test --release -- --nocapture # a minimal frontend loads the .so and runs 600 frames scripts/build-aarch64.sh # an ARM handheld's core, cross-built with zig (stripped, glibc 2.17) ``` The test frontend loads `target/release`'s `.so`, so build before testing (it refuses a core older than `src/lib.rs`); `FAMICOM_LIBRETRO_SYSTEM` is the system directory it reports; it reports `target/frontend-save` as the save directory. What it does: one emulated frame per `retro_run`; video XRGB8888 256×240; audio 44,100 Hz stereo 16-bit; up to four players and the peripherals (below); battery RAM as the frontend's save RAM; the machine (Famicom, PAL NES, Dendy) as the reference's `System.machine_for` picks it. From RetroArch's system directory (none of them shipped): - `famicom-rust/2C02G_U_wiki.pal` and `famicom-rust/2C07_wiki.pal`: pally's palettes (the reference fetches them into `reference/nesdev-wiki/images`). Without them the picture is grey. - `disksys.rom`: the FDS BIOS, for disk images. - `famicom-rust/nes20db.xml`: nes20db (unpacked from the reference's `reference/docs/nes20db-2026-09-26.7z`), which identifies dumps whose headers are wrong. Without it the header decides. Save states are famicom-rust's (`state.rs`, checked as the reference checks its own: saved, loaded and continued, identical to the run not interrupted). Disk System disks: each side is one image of RetroArch's disk control (Eject, then choose "disk 1 side B", then Insert), and by default the sides also change as the game asks for them (the reference's AutoDisk, `famicom_rust::fds_auto`, identical to famicom-python's on the gate's cases), each change shown on screen. The core option "FDS: change disk sides automatically" turns that off. A save state holds the disk in the drive, not AutoDisk's own count of the program's polls (nor does the reference's). Input goes through famicom-rust's `host` module, the input half of the reference's window (`frontend.py`), checked against it frame by frame on every device (famicom-rust's rung 6). The peripheral is the cartridge's own (nes20db, else the NES 2.0 header), or the core option "Peripheral"'s (the window's `--device` names; it applies when a game loads): | What | How | | --- | --- | | Pads, Four Score, Famicom four players | RetroArch's ports 1-4: B is the lower face button, A the right one | | Zapper, two Zappers, Bandai Hyper Shot | the light gun (or the mouse) aims, trigger (left button) fires, reload (right button) points off screen | | Arkanoid Vaus | the gun's (mouse's) left-right is the knob, left button fires; a second Vaus on port 2's pad | | Power Pad, Family Trainer | keys 1 2 3 4 / Q W E R / A S D F | | Family BASIC, Subor keyboards, Jissen Mahjong | the keyboard (use RetroArch's game focus mode) | | Konami Hyper Shot | each pad's A runs, B jumps | | Super NES, Subor, Yuxing mice, Hori Track | the mouse | | Super NES pads | ports 1-2, X and the shoulders as well | | Pachinko dial, Oeka Kids tablet | the mouse's position, buttons | | R.O.B. | its moves shown on screen; press port 2's buttons for it | | Data Recorder (with the Family BASIC keyboard) | F9 plays the tape from its start, F10 records over it; either again stops | | Turbo File | nothing to press: its 8 KiB is kept | The peripherals' storage is the window's (`src/storage.rs`), in RetroArch's save directory: the Turbo File's RAM as `turbo-file.sav`, one for every game (the device moves between games), and the cassette as `.tape`, the reference's JSON of level changes, so a tape moves between the two. The tape is written when it stops and when the game unloads; the Turbo File also within a second of a change, as a handheld is often switched off without unloading. The test frontend checks both are read and written back (`famicom_device=turbo-file` and `keyboard`); a planted skip of either read fails it. Not yet: the Famicom's microphone through anything but the keyboard's M. MIT.