Emmanuel Vadot's Journal


FreeBSD, Electronics and more


Use Binmisc for starting MegaDrive Roms

binmiscctl(8) is use to add binaries image activator in the kernel. When you execute a binary, the kernel will check what type of file it is and if it knows how to execute it it will do so.

binmiscctl is mainly use to execute arm or mips binary with the help of qemu-static (This is how the packages for thoses archs are built) but you can use it for almost anything and this is what I've done.

Every Sega Megadrive games comes with a header, this is used by the TMSS inside the console. The game needs to have the string "SEGA" at offset 0x100 (256) to be a valid binary so we'll use this to tell the kernel to start an emulator when we want to execute a megadrive rom.

The syntax for binmiscctl is simple, you add a name for the activator, a path (possibly with argument) to the interpreter some magic vaue to check and voila. Additionally you can add an offset for the magic value. I'll use mess here but it will works with every emulator.

# You need to be root of course do to the following
$ binmiscctl add megadrive --interpreter '/usr/local/bin/mess64 megadriv -cart' --magic "\x53\x45\x47\x41" --size 4 --offset 256 --set-enabled

That was hard. Let's check if everything is correct :

$ binmiscctl list
name: megadrive
interpreter: /usr/local/bin/mess64 megadriv -cart
flags: ENABLED
magic size: 4
magic offset: 256
magic: 0x53 0x45 0x47 0x41

Now all I need to do to play a megadrive rom is to go to the directory where all my roms are and do ./gamename.md

And if you're asking yourself what's the point of all that, the anwser is none, just fun.