emuforge

Development

You need the Rust toolchain that rust-toolchain.toml names.

cargo build --release
cargo test --workspace
tools/check.sh          # everything CI runs; before every push

tools/check.sh also needs Python 3, and two tools:

cargo install --locked cargo-deny
cargo install --locked --git https://github.com/emuforge/forge forge-docs

On Linux, the app also needs libasound2-dev and libudev-dev. To play a game:

cargo run --release -p mdemu -- GAME

cargo build --release -p mdemu-libretro makes the libretro core, target/release/libmdemu_libretro.so on Linux, and forge's forge-libretro-check LIBRARY GAME plays it without a window and checks its frames, a state, and loading it again.

After a change for speed

A change for speed may not change anything that games do. The playbook says how to find and check one. mdemu-dev (apps/mdemu-dev) runs the core without a window, and forge's tools/builds.py compares two builds of it frame by frame, or times them. Without arguments, mdemu-dev says what it can do.

cargo build --release -p mdemu-dev          # the old commit: keep a copy as OLD
cargo build --release -p mdemu-dev          # the new one: keep a copy as NEW

../forge/tools/builds.py cases games.json --games GAMES --end .zip -- --plays 3600
../forge/tools/builds.py compare OLD NEW games.json --out results.jsonl
../forge/tools/builds.py reload NEW games.json
../forge/tools/builds.py times OLD NEW games.json --quiet
  • Use a few games of each kind: Mega Drive, with the SVP, 32X and Mega CD, in H32 and H40, with shadow and highlight, interlaced, and PAL. Each case is in the JSON with its own options.
  • Run games without buttons too (--idle), and look at pictures. The other buttons go past intros. Final Fight CD's intro was black, and no comparison with buttons had shown it. The same output in two builds does not say that it is right.
  • Look at pictures of what is timed (mdemu-dev shot). The buttons can leave a game paused, and then most of its time is spent waiting. --start can end that, and --skip leaves the menus out of the time.
  • The core always makes its picture and sound, so there is no core command or --headless.
  • Keep it to a minute or two, and keep the lists and results outside of every repository, as they have names of your games in them.

Pictures of many games

Forge's tools/pictures.py takes pictures of many games, says which show only plain ones or stand still, compares two builds' pictures, and puts them on sheets. It uses the same lists as builds.py:

../forge/tools/builds.py cases discs.json --games DISCS --end .zip -- --idle 5401
../forge/tools/pictures.py run OLD discs.json old --frames 5401
../forge/tools/pictures.py run NEW discs.json new --frames 5401
../forge/tools/pictures.py compare old new
../forge/tools/pictures.py sheet old sheet.png --new new

Use this after a change to the Mega CD's BIOS, as all discs use it. A BIOS that starts a little later shows the same scenes at other times, so look at the pictures of all games that differ.

What a Mega CD game wants from the BIOS

mdemu-dev has a trace command when it is built with the trace feature. The feature is off by default, is in no build that is published, and such a build refuses to time games (run). tools/bios.py uses it:

cargo build --release -p mdemu-dev --features trace --target-dir target/trace
TRACE=target/trace/release/mdemu-dev

tools/bios.py log $TRACE discs.json log.jsonl -- --bios-reads --calls 0-5401 --repeats 1800-2400
tools/bios.py show log.jsonl                # which addresses and calls, and how many games have them
tools/bios.py show log.jsonl "Name of a game"
tools/bios.py try $TRACE discs.json "Name of a game" --read sub:4389C:5E80 --at 2100,2700 --values byte
  1. Find the frame in which the game stops, with pictures. Run it with and without buttons (--plays and --idle). Look at whether the run got to what you want to test. When it did not, press what a player would: --idle 5400 --press start:600-608,a:3600-3608 holds only Start and then only A, in these frames. Try each button alone to see what it does.
  2. Log what it reads again and again from that frame on (--repeats). That is most likely what it waits for. Its first read of the same address can be long before, and trying values there can show nothing. show has the 25 reads that each processor makes most often. --only A10000-A1001F has all reads of these addresses, such as the controllers' ports, which are read too seldom for that. The core skips some waiting loops, so a place in one is counted too few times. A loop in the main program can also wait for a picture, and then the game waits for something else.
  3. Log what it reads where the BIOS is (--bios-reads), also right before it crashes. A pointer that is 0 reads the start of the BIOS. console is the console's BIOS, sub is the sub CPU's at $0 to $5FFF, window is that part as the console sees it, and dma is the console's DMA. show leaves out the sub CPU's stack and the drive's state, and log has them.
  4. Compare with other games. An address or call that many games have is more likely to be a part of the BIOS.
  5. Try values (try) at the place and address from the log of that very release. The same code is often somewhere else in another release. A value that was never read is refused, as it would look just like one that does not matter. A value is only for one place, so the BIOS itself still reads what it always does. When a place reads a long, it reads two words. Try both, also together: with 1 in the first word, the second one decides whether The Terminator stops.
  6. Find out why a value works, change the BIOS for all games, and compare all discs without buttons, and some with them. The BIOS never recognises a game.

The trace has places, addresses, and registers at BIOS calls. It has no instructions, reads nothing from a game's memory for the log, and needs no BIOS file. A register can still hold a part of a game's data, such as when an interrupt calls the BIOS while it unpacks something. So do not publish logs, use a register's value only for what a call gets, and delete a log that has more. Keep it like that: how the BIOS was made says what it rests on. Keep logs, lists and pictures outside of every repository.

The Android app

The app is a library (apps/mdemu/src/lib.rs), which forge's activity runs on Android, and which a front end with several cores links (CORE, without the activity feature). Every pre-release has the APK (mdemu-<commit>-arm64-android.apk), signed with emuforge's key for apps installed by hand. To build it, with the Android SDK, its NDK, the aarch64-linux-android target and cargo-ndk:

../forge/tools/android-apk.sh mdemu org.emuforge.mdemu mdemu target/android/mdemu.apk
adb install -r target/android/mdemu.apk

Started from its icon, it asks for a game with the system's file picker, and reads only that file. A disc in the picker is a .chd or a .zip: a .cue's tracks are other files, which the picker does not let the app read. adb shell am start -n org.emuforge.mdemu/org.emuforge.app.ForgeActivity --esa args '<game>,--log,debug' starts it with a game in its own folder on the phone (/sdcard/Android/data/org.emuforge.mdemu/files, where log.txt is too). The icon is packaging/android, which ../forge/tools/android-icon.sh assets/logo/mdemu-icon.svg makes from the logo.

This documentation

It is the Markdown in docs/, and emuforge.org makes the pages. The harness says how it is written.

From commit 1fd712ad794d. Edit this page