Mednafen notes, updated

Updated 2017-06-29. Originally posted 2016-02-22.

Some time ago I switched from pcsxr to mednafen as my emulator for Playstation 1 (hereafter PSX). At the time pcsxr was broken on Debian and its maintainer planned to orphan it. It looks like those problems have been fixed, but other shortcomings remain: pcsxr is inaccurate, it seems most development is focused on the arm version, and there just too many options to fiddle with, with many of these being provided to use on a game-by-game basis.

mednafen, on the other hand, does things right. There are few options to worry about, and what options there are have defaults that favor security and presenting games as they appeared on the original platforms. There are no per-game hacks. The developer makes frequent releases. There are reasonably current ports/packages on Debian and OpenBSD (and recent releases of mednafen explicitly mention improved support for OpenBSD). mednafen emulates many systems, most of them very well. In fact, it's supposed to be the most accurate PSX emulator (and might even be the most accurate Saturn emulator, despite only picking up support for that a few months ago).

At the outset one thing gave me pause, and a great deal of it. mednafen has no GUI. The documentation is extremely copious. The configuration file is over 11,000 lines long.

I figured on a steep learning curve. I planned to take notes so that I could slowly wrap my head around the program.

Fortunately, my first impression turned out wrong. Using mednafen's pretty simple! But I have the notes, and I've got a blog, so...

General usage

mednafen is pretty simple to use. You need not worry about command line options or even a configuration file. Running a game is as simple as typing the program named followed by the name of the game you want to emulate, e.g., mednafen sonic_the_hedgehog.md4. Apparently on Windows you can even start a game by dragging and dropping a file's icon onto mednafen's icon.

Working with .bin and .cue files

One difference between mednafen and pcsxr is that for PSX (and Saturn) emulation mednafen needs very specific kinds of files.

With pcsxr, I downloaded a rip, did whatever convoluted decompressing was necessary to get an .iso or a .bin or an .img file, and then discarded the leftovers. Mostly, pcsxr loaded whatever I threw at it.

mednafen's PSX emulation, on the other hand, requires very specific files: a small plain text .cue file and one or more binary .bin files. You start mednafen by launching the .cue file: mednafen sotn.cue.

The cue file simply contains a description of the layout of the .bin files:

In the case of Symphony of the Night there is just one .bin file described in the .cue file:

$ cat sotn.cue
FILE sotn.bin BINARY
TRACK 01 MODE2/2352
INDEX 01 00:00:00

Some games have fairly complex layouts with many bins and complex .cue files. But that's no big deal. Just download rips that come as .bin/.cue files. The PSX rips that set the standard for digital preservation -- those bearing the name -- seemingly always come in .bin/.cue format.

Multi-disc games like Metal Gear Solid or Final Fantasy VII require an extra file beyond .bin and .cue. mednafen needs to know about each disc in the set or it can't handle disc switching and saves. So, you need another plain text file -- in this case a .m3u file that simply lists each .cue file:

$ cat mgs.m3u

It's easy to type out a .m3u file that lists each .cue file. This is also easy: ls -1 *.cue > mgs.m3u.

When you're playing a game and it comes time to switch discs, press F8 to open the virtual tray, press F6 to select one of the discs listed in your .m3u file, and press F8 again to close the virtual tray. Simple as that.

Which BIOS to use

mednafen needs PSX BIOS files. If you play only NTSC games, you just need the SCPH 5501 BIOS in the form of a file named exactly scph5501.bin. The documentation provides specific filenames and checksums for the BIOS files required to emulate various systems.

The configuration

Setting up controllers

We'll come to mednafen's configuration file in a moment. For now let's consider mapping your physical input device (be it a keyboard or a mouse or a USB gamepad or even a light gun) to the emulated controller in mednafen.

In theory it's possible to edit mednafen's text config file to set-up your controller. In practice it is much better to do it "in game" using the on-screen prompts.

First, note that mednafen can handle up to eight controllers at once. You don't need to have eight USB pads plugged in; you can easily simulate switching ports.

Switching ports: switch between ports by pressing control+shift+n (where n is a number between 1 and 8).

Switching peripherals on a port: switch between types of peripheral attached to a port by pressing control+shift+n again. For example, if I want to switch to using a Konami Justifier on port four, I press control+shift+4 once to switch to that port, then control+shift+4 a few more times to cycle between the various peripherals that I can emulate.

Mapping the keys for a peripheral: Just press alt+shift+n to map whatever peripheral is attached to port n. You may need to turn number lock off for this to work as expected..

This may seem complex, but it's really not. Here's an example of how it works in practice.

In Metal Gear Solid there is bit of an Easter egg in the form of a boss that becomes easier if you remove your controller from port one and use a controller in port two. In mednafen, that's as simple as pressing alt+shift+1 until the peripheral type on one port one is changed to 'none', and then pressing control+shift+2 to start using a digital gamepad on port two; of course, you can press control+shift+2 to pick a different type of peripheral (a negcon, say) and then alt+shift+2 to get the on-screen prompts for configuring that paddle.

The configuration file

If you look at the configuration file (/home/user/.mednafen/mednafen-09x.cfg) you will see that it is well over 11,000 lines long. Why so many lines?

Most lines control the default keybindings for a particular peripheral on a particular port. For example, 12 whole lines (admittedly including comments and white space) define the default keybindings for a Sega Mega Mouse attached to virtual port eight:

;md, Virtual Port 8, Sega Mega Mouse: Left Button
md.input.port8.megamouse.left mouse 0000000000000000 00000000

;md, Virtual Port 8, Sega Mega Mouse: Middle Button
md.input.port8.megamouse.middle mouse 0000000000000000 00000001

;md, Virtual Port 8, Sega Mega Mouse: Right Button
md.input.port8.megamouse.right mouse 0000000000000000 00000002

;md, Virtual Port 8, Sega Mega Mouse: Start Button
md.input.port8.megamouse.start keyboard 13

Of course, few Genesis made use of eight controllers, and possibly fewer still even made use of one mouse, so I think it's safe to say that nobody has ever needed to set up eight Mega Mice. Likewise, you'll never find a PSX game that uses three or eight (or two?) dual analog flight sticks. Most of these settings, then, are ones you'll never have to worry about. Still, it's nice that mednafen can simulate all the pointless input combinations that the real hardware allowed.

But to reiterate -- controllers don't need to be configured via the config file. Use the on-screen prompts!

In fact, I would encourage you to mostly leave the configuration file alone. See, mednafen writes a new configuration file every time it closes. Mednafen keeps whatever changes you've made to default values, but is merciless in adding new settings, stripping out old settings, and removing any of your comments. As such, I keep with my other configuration files a really short mednafen-09x.cfg file that looks just like this:

; On its first run mednafen will read these values and override its defaults
; for these settings. On close mednafen will write these values and the defaults
; into an 11,000 line file. As such, this file is useful only for 'bootstrapping'
; mednafen's first run.
cd.image_memcache 1
psx.shader goat
psx.xscale 4.000000
psx.yscale 4.000000
ss.shader goat
ss.xscale 5.000000
ss.yscale 5.000000

Changes I make to the configuration file

I change <system>.xscale and <system>.yscale lines to larger values on my desktop and smaller values on my laptop. These settings are adjustable per console (e.g., psx.yscale or ss.yscale).

I change <system>.shader to goat for a neat "simple approximation of a color TV CRT look."

I change cd.image_memcache to 1 so that mednafen loads an entire game into memory. The documentation sends mixed messages on whether this is advisable.

And that's it.

In-game keyboard controls

You can do things like save state, load a state, take a screenshot, display FPS, etc., using the keyboard while playing a game. Here are the commands I use:

Other things