N64 Assembly Tutorial - Lesson 1

Updated: N64 Assembly YouTube Series

The same content updated with more explanation and showing how it's done. Twitch stream style.

https://www.youtube.com/playlist?list=PLjwOF_LvxhqTXVUdWZJEVZxEUG5qt8fsA

Lesson 1

Many have come before me and did this (probably better) but here is my take on the subject.

Thanks of course to 'Mike H a.k.a GbaGuy' for the original series and to 'Peter Lemon' for taking it and running multiple marathons beyond the starting point.

I'll be operating on Windows, please make any adjustments necessary for your platform.

Assumptions:

  1. No fear of a command line

    1. Common commands: CD, MD, DIR.

    2. A few Batch files will be provided: Copy and paste is OK but editing them will make you more productive.

  2. Some programming experience in a compiled language

    1. This really just means less to explain and we can start at a deeper level.

    2. Especially relevant here is the use of Hexidecimal, Binary and Bit Manipulation

  3. Any topics that are important but aren't N64 specific will be links to articles that I've reviewed and found useful. If a concept isn't clear for you, search the internet for other articles.

  4. Experience playing games on the Nintendo 64

    1. This is helpful to understand what is possible using the N64 hardware.

Lesson 1 - Environment

Downloads

Everybody seems to have their favorite assembler, at this time the bass assembler is open source and supports most N64 specific features. It was first created by byuu to support the SNES while he was also creating the SNES cycle accurate emulator bsnes later renamed and expanded under the name higan. The original bass was forked by ARM9 and modified to support many additional platforms.

Download bass assembler package (Also at bottom of page)

The next piece of software that you need is an emulator, once again lots of options many of them haven't been updated or maintained for years or don't provide a debugger. I'll be using MAME (v 0.205) which does include a debugging option.

Download the latest MAME

There is at least one "bios" file that MAME needs in order to run N64 ROMs called n64.zip less than 2kb in size. I'm sorry but you will have to find it yourself, shouldn't be too hard though.

Eventually being able to run your programs on real hardware is the dream, I currently have an Everdrive v3 and the 64drive V2, both receive great reviews for N64 Homebrew Development.

Install

MAME

Install MAME by double clicking the EXE and telling it where to unzip, that's it, so no default shortcuts or anything. I'll be using C:\MAME shorter paths are better when using the command line.

Copy the file n64.zip to the C:\MAME\ROMS folder directly, without unzipping.

MAME is intended for use with a "Frontend" that takes care of the details for most users. Since I'm not using a front end (not needed) MAME being as flexible as possible was placing config and ini files in several places on my hard drive. Not bad but frustrating when your not sure why it's not running or can't find the n64.zip file.

Use the Download package below the "run" command should work if you chose the default folders, otherwise modify as needed.

bass

Install bass by unzipping to a folder on the C drive. I chose C:\bass.

Projects

Create a folder for your projects I'll be using C:\projects_bass\N64 for this series.

Setting up Environment

In the folder C:\Projects_bass I created a text file called gobass.cmd.

@ECHO OFF

path=c:\bass\bin;c:\bass\include;c:\bass\lib;c:\mame;%path%;

Next step is to add a little more to the project folders structure. I created the following sub folders:

  • C:\Projects_bass\N64

  • C:\Projects_bass\N64\LIB

  • C:\Projects_bass\N64\template

Then download the individual files from Peter Lemon's github repository. If you are handy with git go for it, otherwise it's only 7 files (6 text, 1 binary). For now all these files will all go in the LIB folder we just created.

Create a Template

Next we will make a project template we can copy when we starting a new project.

  1. Copy the N64_header.asm file to the Template folder

  2. Create a "make.cmd" text file with the following contents:

@ECHO OFF

set rom_name=Lesson2.N64

REM Space separated list of source files set source_files=Lesson2.asm

if exist %rom_name% (

del /q %rom_name%

)

bass -strict -o %rom_name% %source_files%

if exist %rom_name% (

@chksum64 %rom_name%

)

This make.cmd reduces the error messages that appear in the console. It's fairly standard commands and syntax for batch files so search the web for a tutorial or experiment with modifying it on your own.

Testing Install

Next we need a quick way to run our newly created ROM. I've included a run.cmd in the bass\bin folder of the download package above. This one is a little complex but it's intended to be flexible and easy to use, not necessarily easy to read/modify, see this lessons download for the run.cmd.

Usage is after the make type run. Or especially in the first examples 'run debug'.

Verify

At this point we can do some basic testing, open a command prompt and run the following commands in this order:

  1. CD \Projects_bass

  2. gobass

  3. bass

  4. mame64 (Escape key exits)

At this point we don't want to see any errors for any of these commands.

There are lots of configuration options in mame64 use the TAB key to open the options menu and the arrow and ENTER keys to navigate and change settings. Nothing really needs to be done for now, once our programs can receive input we will take a closer look.

Sorry there was no code this lesson, getting this environment setup correctly will make future lessons much smoother.

Lesson 2