Dimwitted Sage

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

First Look at LLVM MOS

March 9, 2024
Part 3 of 6 in Building an NES Game

So let’s take a first look at what it looks like to build with our toolchain. I’ll be running my toolchain through docker on MacOS. Clone or download llvm environment container project under your $HOME address, eg.

git clone https://github.com/tennesseedaved/llvm-mos-docker.git

Source the llvm_env.sh script

source llvm-mos-docker/llvm_env.sh
Starting container...
7cce6ac37368ab94e45a681f39d676a3b9432277780df72211ad849e58f65496

Now, you should be able to access llvm commands by prefixing ‘llvm_exec’

llvm_exec clang
clang: error: no input files

Example Program

We’ll be looking at an example courtesy of Memblers post on https://forums.nesdev.org/viewtopic.php?t=23823https://forums.nesdev.org/ which appears to be a modification of another example done for cc65 compiler. Let’s look at the contents

% ls example11-llvm-mos
chars.s ex.bat example11.c tileset.chr

Taking a quick look at the contents, we can assume that ex.bat is responsible for the build and check the contents to execute

% cat example11-llvm-mos/ex.bat
call mos-nes-nrom-clang example11.c chars.s -lneslib -o example11.nes -O3 -flto
pause
example11.nes

We’ll take the call portion of the batch file and execute it within our container.

% cd example11-llvm-mos && llvm_exec mos-nes-nrom-clang example11.c chars.s -lneslib -o example11.nes -O3 -flto
% ls
chars.s example11.c example11.nes tileset.chr
ex.bat example11.mlb example11.nes.elf

So just what do we have here.

example11.nes Nintendo Image
example11.nes.elf Program Generated ELF File
example11.mlb Mesen Lua Script Bytecode for Debugging

Running the Program

Now, load of the image in your favorite emulator and give it a run!

example11.nes running in Mesen: colored lettered tiles with bouncing balls
Recreated in 2026 by running the original March 2024 build of example11.nes in Mesen.