Dimwitted Sage

This site is being rebuilt. Some pages and posts are still in progress.

The NES Toolchain Foundation

March 8, 2024
Part 2 of 6 in Building an NES Game

Now let’s take a look at the toolchain I’ll be using for NES development. For reference, I previously referenced nesdev.org’s programming guide for finding out what’s available. During my previous endeavor I looked at cc65’s compiler and was able to build it without much difficulty. However, from recollection, it didn’t perform anything in the way of optimizations, so that’s sounded a little suspect. What does provide optimizations out of the box? LLVM! So this goes along with by dual intent for this project, experimenting in game and compiler development.

The LLVM dragon logo

Since 6502 isn’t supported as a part of mainline llvm, we’ll be using 2 repos based on llvm: llvm-mos and llvm-mos-sdk. At first I questioned the need for the SDK to experiment with, I thought I’d just be writing my own macros in support of accessing HW registers, but as I worked through my initial example I realized that there were some other features required that would take a non-trivial amount of effort to achieve (eg. linker ROM output). We’ll spend more time looking at this in the future.

The NES toolchain: hello_world.c is compiled inside a Docker container by llvm-mos's mos-nes-nrom-clang, using llvm-mos-sdk's neslib and NES linker script, into hello_world.nes, which runs in Mesen. hello_world.c written on the Mac Docker container mos-nes-nrom-clang llvm-mos: optimizing C compiler for 6502 llvm-mos-sdk neslib, NES linker script, ROM output hello_world.nes NES ROM image Mesen emulator
Diagram added in 2026. The original image from this spot was not recovered.

The other thing I wanted to do for this cross compiler tool-chain is to make it more portable by “containerizing” the environment. We also want to avoid working within the container, so to the degree that is achievable, we want to run these commands from within each respective OS shell. To this end I’ve created a github repo with docker image instructions to make this easier.

I’ll be using a Mac Mini for this project because it’s where I’ve begun to work on my personal project.