It's the 90s

I miss the 90s. I won’t even pretend I don’t. I was young and just getting out on my own. Anything seemed possible. The web became a thing, computers got way cooler and suddenly “nerd” went from insult to honorific. I was poor but carefree. Oh, and the video games. The video games. Sigh. Super Nintendo and Sega Genesis were the king and queen of consoles, and by far the most popular even as they aged. It was the golden age of 2D games, and the capabilities for making them were baked right into the hardware. The super rich kids had a NeoGeo, which had just eye-poppingly gorgeous graphics and was smoking fast. I honestly gave very little thought was given to how the games were actually made. It might as well have been wizard magic. I had done some assembler on the 6502 for the Commodore 64, but I had no idea how you would even get games on to consoles, much less how you would write them.

Super Mario World Screenshot Zelda: Link to the Past Screenshot

Fast forward to 2021. I’ve known in the back of my head that there’s a vibrant homebrew scene for 16-bit era consoles. Very Smart PeopleTM have devised clever ways of near perfectly emulating these consoles on modern PCs. You can even buy brand new consoles that run the actual chipsets in FPGAs rather than emulators. There’s also modern development tools that can target these ancient architectures with higher level languages.

I got it in my head that I really wanted to write a Super Nintendo game, as that is my favorite console of all time, and has my two favorite games of all time. Sadly, it lacks the kind of modern tooling that would make it practical. I’d have to write the thing in assembly, and while I’m pretty facile in 6052 assembly, 65816 assembly is a different beast and I lack the patience to learn it right now. There is a way to write code in C, but it’s not pretty and you don’t have access to all the hardware.

Enter the Sega Genesis. It has all the creature comforts, like modern tooling, a nice C library, a good compiler, etc. It was my second choice of platform after the SNES anyway. It’s a tradeoff, though. The Genesis is faster and can display more sprites, but the SNES can display more colors. The tooling is really what makes the difference, though. The Genesis it was. So I fired up some era-accurate Aphex Twin and started down the road of learning what I would need to do.

The rest of this post (and possibly series of posts) is going to be something of a tutorial, but it’s one that I’m writing as I learn how to do it myself.

Setting Up A Dev Environment

I’m going to do this under windows with MSYS2/MinGW, because I know that ecosystem pretty well. I’d love to do this on Linux, and there’s no real reason I couldn’t, but the two machines I want to use to work on this happen to be Windows 10. I thought about using WSL, but in the end I decided I’d just go with what I already have set up.

MSYS2/MinGW Setup

MSYS2/MinGW setup is well beyond the scope of this post. There are plenty of great tutorials on that floating around, say nothing of the documentation itself. Once you’ve got that running, you’ll can install the packages you need from the MSYS2 termial with:

pacman -S make git mingw-w64-x86_64-toolchain texinfo tar diffutils

You’ll also need a JRE (I know, I know…). You can use OpenJDK. You will want to install this in Windows. You can do it with Scoop. If you don’t have Scoop, you should get it, it’s effin’ great. However you install Java, you’ll need to make note of the directory it it installed in. I used scoop, so it’s C:\Users\jaybill\scoop\apps\openjdk\current. Now I need the MinGW bash to know about that, so I add the following to the end of ~/.bash_profile:

export JAVA_HOME="/C/Users/jaybill/scoop/apps/openjdk/current"
export PATH="${PATH}:${JAVA_HOME}/bin/"

Marsdev Toolchain

Now that you’ve got that set up, we can set up the toolchain. I’m going to use Marsdev, which is basically GNU for Genesis and a bunch of other things. It’s cross platform, which is nice. You can grab the latest release (as of this writing it’s 2020.01). Unpack that from your home directory and you should end up with ~/mars.

Test your install with: ~/mars/m68k-elf/bin/m68k-elf-gcc.exe --version

If you get version information, you’re gold. You will also want to download the source archive of the same release so that you can grab the examples/sgdk-skeleton folder. Copy this folder to wherever you keep source files and rename it to hello-genesis. You should be able to run make in this folder and get an out.bin. You should be able to run this file with an emulator.

Visual Studio Code

Look, I’m not telling you what IDE/editor to use, but there’s a very nice integration for Genesis development available for VS Code. (Search for zerasul.genesis-code.) Configuration of that is pretty straightforward, it basically just wants the location of your ~/mars folder.

Your c_cpp_properties.json file for your project will look something like this: (Adjust your paths, obviously.)

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\msys64\\home\\jaybill\\mars\\m68k-elf\\lib\\gcc\\m68k-elf\\9.2.0\\include",
                "C:\\msys64\\home\\jaybill\\mars\\m68k-elf\\include",
                "C:\\msys64\\home\\jaybill\\mars\\m68k-elf\\m68k-elf\\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\msys64\\home\\jaybill\\mars\\m68k-elf\\bin\\m68k-elf-gcc.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

And that’s that! You should have a working development environment!

← Xoth Devlog Pt. 12