startropics-recomp
startropics-recomp is a native PC port of StarTropics for Windows, Linux, macOS, and Android that recompiles your own cartridge dump into C.
- Type: PC port
- Game: StarTropics
- Runs on Windows, Linux, macOS and Android
- By jsp244
- Latest release v1.3.4, 2026-11-17
- Source: https://github.com/jsp244/startropics-recomp
README
StarTropics native PC port (static recompilation)
▶ Video: https://youtu.be/DCeECN3S5bE
A native Windows/Linux/macOS build of Nintendo's StarTropics (NES, 1990), produced by statically recompiling your own cartridge dump into C and linking it against a small hardware runtime (PPU, APU, MMC6 mapper, input).
This repository contains no game data and no game code. The recompiler,
the runtime and the frontend are original work (MIT licence). The game's
6502 program, graphics, music, text and level data all come from the .nes
file you supply from a cartridge you own; the C code generated from it lives
in generated/, which git ignores, and the executable loads the ROM file again
at start-up for the assets. Without your dump nothing here runs.
your StarTropics (USA).nes ──► recomp/recomp.py ──► generated/*.c ─┐
├─► gcc ─► build/startropics
runtime/ (PPU, APU, MMC6, CPU fallback) + frontend/ (SDL2) ────────┘
▲
your .nes again, at run time, for CHR graphics, level data, text, music
For players: the launcher
make dist packages a single executable (SDL2 linked statically, no DLLs) with a
launcher in the style of the N64 recompilation projects: a tabbed menu
(Play / Graphics / Audio / Controls / Achievements / ROM / Updates) over a hero backdrop. On the ROM tab
"Choose ROM file..." opens the system file dialog; dropping a .nes file onto the
window or passing it on the command line also works, and so does the RetComM
launcher, which names the file in a rom.cfg beside the program. The file's hash is checked
and anything that is not a StarTropics dump is refused. Once a valid dump is
loaded the launcher runs the game's own intro, title screen and demo in the
background with sound, so the intro and title music play straight from the ROM
and the dimmed, upscaled title screen becomes the backdrop. Put a
launcher-background.bmp next to the executable to use a picture of your own
instead (no artwork is bundled: Nintendo's promotional art cannot be shipped).
Options (all saved to startropics.ini): windowed / fullscreen / exclusive
fullscreen, a resolution list built from the display's own modes plus 1920x1080
and 3840x2160 (the window size, the exclusive display mode, or the render size in
borderless fullscreen), window size 1x-6x, scaling (integer / fit / stretch), aspect
ratio (square pixels 8:7, 4:3 CRT, 16:9 or 16:10 widescreen: below), filter
(nearest / linear / sharp), CRT-style shaders (scanlines, aperture mask, glow,
curvature; three strengths), overscan crop, a no-sprite-limit mode (every sprite
on a line is drawn, so nothing flickers), remastered textures and music (below), volume,
and rebinding of the eight NES buttons and the rewind key. Nine save state
slots, rewind (hold a key to step back through the last minutes of play),
RetroAchievements (log in on the Achievements tab; unlocks pop up in game;
hardcore mode supported) and updates from the GitHub releases (the Updates tab,
below) are built in.
A line under the Graphics rows reports the picture the settings produce and why it
does not fill the screen when it does not (integer multiples, or a 16:9 picture on a
16:10 screen). The window works in real pixels on high-DPI displays (per-monitor DPI
aware), so a 1920x1080 preset is 1920x1080 pixels. Esc in game opens the same menu
as a pause screen. XInput and other gamepads are handled through SDL's game
controller API (NES A on A, NES B on X, Start, Back = Select, D-pad or left stick;
Start + Select together, the Guide button or LB opens the menu, and LT + RT on Android and
the Steam Deck); pads SDL has no mapping for fall back to
a generic joystick layout, and startropics --list-controllers out.txt writes
what SDL detected.
Note on distribution: a prebuilt executable necessarily embeds the recompiled game logic (as the N64 recompilation releases do), while every asset still comes from the player's own ROM at run time. Building from source as described below keeps everything derived from the ROM on your own machine.
16:9 (widescreen) and 16:10 (widescreen), the third and fourth aspect ratios, are real widescreen views, not a stretch: a tile-based
NES game has no picture beyond the 256-pixel edge, so the port decodes the
overworld's map data from your ROM (the screen grid, the run-length coded
metatile rows and the metatile table; docs/MAP_FORMATS.md) and draws the
world around the normal picture with the same CHR banks, palette and scroll
the PPU used, so there is no seam. The centre stays the game's own output
(the 16 lines the overworld leaves blank at the bottom show the map too). The people
are there as well: the game keeps every villager in memory but shows and moves
only those on its own screen, so the others stand where they were, drawn with the
game's own sprite rules (a hut's inside hides the people outside, as in the game).
Scenes whose format is not decoded (dungeons, menus, text screens) show the
normal 4:3 picture between black bars. The pixels keep their 4:3 CRT shape: a 16:9 picture shows 341
columns (318 with the overscan crop). With Integer scaling in fullscreen the
picture fills the whole screen at the largest whole multiple, with the map
above, below and beside it (1280x800 at 3x on the Steam Deck); the decoder
covers up to 704x336 pixels, enough for a 32:9 screen. Nothing is ever stretched: the
Scaling row's "Stretch (distorts)" is the one option that changes the pixel shape.
What works
Verified in this session (headless, scripted input, screenshots inspected):
- boot, intro cinematic, title screen, attract mode (island map)
- file select, name registration (letter grid, END, slot select), battery-backed MMC6 save RAM
- chapter 1 prelude text, arrival on C-Island, overworld walking and scrolling in all directions
- the recompiled code is bit-identical to the reference interpreter over a 6,500-frame session (14.6 million instructions; CPU registers and cycle counts, RAM, save RAM, framebuffer, OAM, palettes, nametables and bank registers compared every frame)
- the interpreter passes nestest (all 8,991 instructions incl. unofficial opcodes and
exact cycle counts) and 44 of the 63 blargg accuracy test ROMs; the failures are
dot-exact NMI latency, PPU open-bus decay and exotic unofficial-opcode tests that
this game does not depend on (see
docs/ARCHITECTURE.md)
Not yet verified by the author: dungeon (action) scenes with the IRQ-driven status bar, boss fights, later chapters, and listening to the audio output (the APU passes blargg's length/sweep/envelope/frame-counter/DMC-rate tests and writes sane WAVs). Any code the static analysis did not reach still runs correctly through the built-in interpreter fallback, so missing coverage costs speed, never correctness.
Legal note
StarTropics is a trademark and copyright of Nintendo. You need your own legally
obtained cartridge dump; the project does not include, download or write one.
Everything derived from your ROM (the generated C, disassembly listings, builds,
saves) stays on your machine. Do not redistribute generated/ or the built
executable, since those contain the recompiled game.
Building
Requirements: a C11 compiler (gcc/clang), GNU make, Python 3, SDL2 (frontend only).
Windows (MSYS2): install MSYS2, open the MINGW64 shell and
pacman -S --needed mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2 make python
Linux: sudo apt install build-essential python3 libsdl2-dev libcurl4-openssl-dev (or your
distro's equivalent) for a local build; portable packages are built in a container (below).
macOS: Xcode's command line tools (xcode-select --install), Python 3 and CMake;
tools/macos/build.sh builds SDL2 itself (below).
Then:
git clone <this repo> startropics-recomp
cd startropics-recomp
cp "/path/to/StarTropics (USA).nes" rom/ # your own dump
make recomp # disassemble + translate your ROM -> generated/*.c (a few seconds)
make -j8 startropics # compile ~60k lines of generated C + runtime + frontend (~20 s)
build/startropics # looks for rom/*.nes next to the executable; or pass a path
make recomp prints how many instructions and routines it found (about 24,200
instructions in 430 routines for the USA dump from static analysis alone, a few
hundred more with coverage data). Run make recomp again after collecting more
coverage (below) and rebuild. make dist zips the executable with the player
notes (docs/PLAYERS.md) into dist/. A build carries its version (git describe: the
newest v* tag, plus the commits after it) and the GitHub repository of the checkout
(its origin remote), which the Updates tab compares and downloads from;
make ST_VERSION=... ST_REPO=owner/name sets them where there is no git.
Linux and Steam Deck packages
tools/linux/Dockerfile is an Ubuntu 22.04 build environment with SDL2 built from
source as a static library that loads X11, Wayland, PipeWire, PulseAudio, ALSA and
udev at run time. The resulting binary needs only glibc 2.34+ and libm, so it runs on
SteamOS 3 and current distributions without installing anything; libcurl (for
RetroAchievements and updates) is loaded at run time when present. After make recomp
(the container has no git, so the version and repository come in from the environment):
docker build -t startropics-linux tools/linux
export ST_VERSION="$(git describe --tags --match 'v[0-9]*' --dirty)" ST_REPO=owner/name
docker run --rm --user "$(id -u):$(id -g)" -e HOME=/tmp -e ST_VERSION -e ST_REPO -v "$PWD":/src -w /src startropics-linux sh tools/linux/build.sh
This builds, runs the cosimulation and the frontend self-tests headless (SDL's
offscreen driver), and writes dist/startropics-linux-x86_64.tar.gz and
dist/startropics-steamdeck.tar.gz. The Steam Deck edition (make DECK_EDITION=1)
starts fullscreen at the Deck's 1280x800 in the 16:10 widescreen view with pad-first
hints; the generic Linux build does the same when it finds itself on a Deck. Setup on
the Deck: docs/STEAMDECK.md.
macOS package
tools/macos/build.sh (on a Mac, after make recomp, with ST_VERSION and ST_REPO set as
for Linux) builds SDL2 as a static library for Apple silicon and Intel Macs, then the game
for both in one program for macOS 11 and newer, runs the cosimulation and the self-tests
(offscreen, the Intel half again under Rosetta, then the app itself in a real window, opened
with a ROM dropped on it), and writes dist/startropics-macos.zip: the folder startropics
with StarTropics.app, README.txt and the licences. The app is signed ad hoc (Apple silicon
runs nothing unsigned), not through Apple's developer program, so macOS asks the player to
allow it once (docs/PLAYERS.md). It links only macOS's own libraries, libcurl among them for
RetroAchievements and updates, and never writes into itself: settings and saves go to
~/Library/Application Support/StarTropicsPort/StarTropics/, and the folder the app is in
takes the place of the program's folder for a ROM, rom.cfg, remaster.pak or
launcher-background.bmp. frontend/macos.m holds the little Cocoa it needs (the open-file
panel, the Trash).
.github/workflows/macos.yml runs the script on GitHub's Macs for the macos branch and for
v* tags. The cartridge dump it recompiles comes from a private repository, read with a
deploy key kept as a secret; the package and the test pictures leave the job only encrypted
(openssl enc -d -aes-256-cbc -pbkdf2 -iter 200000 -pass ... opens the artifact). Run by hand
with update_test_from set to an older version, it also lets the app it built install the
published release over itself through its own Updates tab (UPDATE_TEST_FROM in the script).
Android
android/build_apk.py builds two APKs straight from the Android SDK tools (no Gradle):
dist/startropics-android-handheld.apk for gaming handhelds with built-in controls and
dist/startropics-android-phone.apk for phones, the same app with a translucent on-screen
controller (frontend/touchpad.c) under its own name ("StarTropics Touch"). They hold
SDL2's Java glue and native library from the SDL source (fetched once), the game as
libmain.so for arm64-v8a and x86_64 (NDK + CMake), a small activity for the system file
picker and for RetroAchievements' HTTP, and launcher icons drawn from the port's own
artwork; the phone edition differs only in its manifest. It needs a platform 34+,
build-tools, an NDK and CMake from the SDK manager, plus a JDK; both are signed with a key
kept in ~/.android/startropics-release.keystore (created on first use).
python android/build_apk.py # after make recomp
python android/build_apk.py --edition phone --install # one of them, and adb install it
Player notes for handhelds and phones: docs/ANDROID.md.
Controls
| NES | Keyboard | Gamepad (SDL) |
|---|---|---|
| D-pad | Arrow keys | D-pad / left stick |
| A (jump) | X | A (bottom face button) |
| B (attack) | Z | X (left face button: B sits left of A, as on the NES pad) |
| Start | Enter | Start |
| Select | Right Shift | Back |
Both the keys and the pad buttons are rebindable on the Controls tab (select a row, press Enter, then the new key or pad button). Every connected controller is opened and merged, so a pad that Windows exposes twice (Xbox over Bluetooth) works whichever instance reports input.
Latency
The port is tuned to feel like real hardware or better; see
docs/LATENCY.md for the full breakdown. In short: the loop is
phase-locked to the display's vertical blank and reads the controller about
3 ms before each frame is presented (frame delay), the GPU queue is one frame
deep, run-ahead (default 2 frames, the game's own reaction time) removes
StarTropics' built-in input lag entirely, and audio sits at 25-45 ms with dynamic
rate control. Exclusive fullscreen bypasses the desktop compositor. All of this is
adjustable on the Graphics and Audio tabs, and startropics --play --stats out.txt logs the measured pacing once a second. On Android each frame is locked to
the compositor's own deadlines (Choreographer frame timelines) and the display runs at
120 Hz where it can; on Linux and the Steam Deck frames go out without vsync, as in
Mesen's default, so none waits in a queue. LATENCY.md compares the port with Mesen 2 and RetroArch.
Hotkeys: Esc or Start + Select together (pad or keyboard) menu, LT + RT together on Android and the Steam Deck, F11 / Alt+Enter fullscreen, F2 toggle overscan crop,
Tab / pad RT (hold) fast-forward (within 1.5 s after a rewind it first goes forward again to where the rewind began), P pause, F5 / F8 save / load state,
F6 / F7 previous / next save state slot (nine per ROM), Backspace (hold;
pad RB) rewind, F12 screenshot (screenshots/), Ctrl+R reset. Keys and
display settings are in the menu and in startropics.ini next to the executable.
Battery saves go to saves/<rom name>.sav (the raw 1 KiB MMC6 RAM, written when
it changes and on exit); save states to saves/<rom name>.state1 .. .state9.
Shaders, rewind, achievements
The shader presets are composed from textured render passes on the SDL renderer (a scanline beam profile stretched over the picture, an aperture-grille mask multiplied in at screen resolution, a glow added back from a small copy of the frame, and barrel curvature with vignette drawn through a mesh), so they work on every backend without a shader language and add nothing to the input path.
Rewind keeps a history of machine states as run-length-coded XOR deltas
(frontend/rewind.c): a state is about 24 KB, a delta typically under 1 KB, so
the 32 MB history holds many minutes at 30 snapshots a second. Holding the key
steps back two frames per frame shown, re-running each restored state for its
picture and sound.
RetroAchievements support uses the official
rcheevos client library,
vendored under third_party/rcheevos (MIT licence; the licence text ships with
the package). The ROM is identified by the RetroAchievements hash (the MD5 of
the headerless image; StarTropics USA is game 1985), achievement logic reads the
emulated memory through a side-effect-free peek, HTTP runs on worker threads
(WinHTTP on Windows, libcurl elsewhere when available) and only the session
token is stored. Hardcore mode disables save state loading and rewind.
Remastered textures
Graphics > Textures > Remastered redraws the game the way the Pixel Remaster editions of the early Final Fantasy games redid their 8-bit art: the same pixel grid, many more colors per tile, and shading in hue-shifted steps (shadows lean toward blue, lights toward yellow). The PPU records for every pixel which cartridge tile, row, column and palette it came from, and each pixel of a tile takes an "ink": one of the tile's four palette colors, a number of steps darker or lighter. Inks are relative to the palette, so the game's palette swaps, fades and color cycling keep working. Out of the box the inks are worked out from each tile's own pattern (a region is lit where its edge faces up or left and shaded where it faces down or right; lettering, told apart by its thin strokes in one color, stays flat and crisp), and the colors StarTropics leans on most get natural tones: a deep sea whose blues, as in the Pixel Remaster's water, keep their saturation in shadow and turn turquoise in the light, turquoise shallows, grass and forest greens, warm browns, warm grey stone, and sand where the NES has pink beaches. The widescreen view's decoded map is remastered the same way. The steps are computed in OKLCH, so each one is an even change of lightness and pale colors deepen instead of turning garish; the cost is well under a millisecond a frame.
A pack of hand-made tiles, remaster.pak, replaces the automatic inks tile by tile.
Packs are made with tools/remaster/remaster_art.py from frames that
nes-headless --hd-dump writes (each pixel's source tile): art painted over a frame
is mapped back to the tiles that drew it. An ink may also name another of the tile's
colors: the PPU keeps every palette a frame was drawn with (StarTropics changes them
under the dungeons' status bar), so such inks take the colors of their own line.
Because a pack is drawn over the cartridge's own tiles it belongs with your copy of
the game; none is included here.
The program loads remaster.pak from its own folder or its data folder (on Android,
the app's files folder on the shared storage).
Remastered music
Audio > Music > Remastered plays the game's own music on the SNES's sound chip, the
S-DSP. It is off until you choose it there, even with the remastered textures on.
StarTropics' sound engine reads every note from the cartridge as it plays: each note
and rest of the music's four channels passes through one routine of the engine, and the
program takes it there and plays it on an emulated S-DSP (LakeSnes's emulation, MIT
licence) with instruments made for it: the first pulse channel on a steel drum and the
second on a marimba (two voices each, so a note rings on while the next one sounds), the
triangle on a plucked bass an octave lower, the noise on a shaker or a conga, all with the
S-DSP's echo. Sound effects stay on the NES's chip: the engine plays them on streams of
their own, and only the channels that carry the song leave the NES's output. The
instruments are synthesized by tools/snesmusic/instruments.py (no recorded samples)
into runtime/snesmusic_bank.c; the notes still come from your cartridge, so none of the
game's music is in this repository. The music is matched to the loudness of the NES's
and costs about 0.1 ms a frame; the emulated machine is the same either way, so save
states, rewind and achievements are unaffect