I wrote a Nintendo Game

About six months ago, I wrapped up my formal schooling and graduated with a Bachelors of Science in Software Engineering. My final course was a Senior Project where I got to dictate the work that I wanted to do. Because it’s been something I’ve wanted to do for a long time, I proposed to write a game for the Nintendo Entertainment System. Yes – the venerable video game console of the mid-1980s. And my instructor (somewhat to my surprise) said yes!

Before I go any further I should clarify that I’ve written some of a video game. It’s not finished. At this point, it’s more of a technical demo. Still, I’ve written a lot more assembly than I ever thought I’d write, and I’m really excited about how much I’ve done and how far I’ve gotten.

Robot Recog is the name of my game. I don’t know what “Robot Recog” means, welcome to the club – I just liked the alliterative nature of it. It’s certainly not the worst game name ever chosen.

In Robot Recog, you take on the role of a Gizmo – a robot that lives in a robot factory. The factory has gone berserk, and robots are everywhere. As Gizmo, you must travel through the factory. Here’s the catch: Gizmo can only travel on his little tank treads. The Factory is full of gaps, and platforms, and all kinds of things. Fortunately Gizmo has a special ability. He can plug other robots in to use their capabilities. If you find a robot that can fly, Gizmo can hook into that robot and fly himself. If you find a robot that can build bridges, you can hook into that robot and build a bridge.

Writing an NES game

I once said to a friend “I think I’d like to learn Assembly” to which he replied “I’ll help Hykel (my wife) plan the funeral…”

Assembly language is about as basic as you can get when you talk about computer programming. Instead of the relatively readable C syntax that is common in a lot of languages:

int a = 1 + 5;  // Add 1 to 5 and store it in an integer   
                // variable 'a'

It looks like this:

LDA 1     ; Put a 1 in the Accumulator 
CLC       ; Clear the carry flag
ADC 5     ; Add with carry, 5, to the accumulator
STA #0001 ; Store the accumulator result in memory location 
          ; 0001

It’s not that it’s complete indecipherable, but it requires so much more headspace to track what’s going on where. I had the advantage of modern development tools – being able to stop the NES running and examine the memory, or writing helper tools. I wrote a python script that would identify – from the state of memory – where the ‘ground’ was supposed to be. The “Collision Map” defines the space a player can stand on and are made up for 8-bit bytes, and the blue and red help clarify where each byte starts and stops. Being able to visualize this data made it easier to program.

I also hugely benefited from other people having provided tools and information about how to accomplish things. I relied entirely on Erik Onarheim’s WebApp for NES sprite generation. I don’t know if there’s any way I would have been able to do this otherwise – the NES’ method for defining sprites is bizarre. The results are this:

The left side is for sprites that move around the screen. The right side is for background tiles. the colors on the bottom are colors that are available to use.

Nintendo games (most of them anyway) are written in 6502 Assembly – 6502 being the processor that the NES uses. On top of understanding the basics of 6502 Assembly, you also need to know how the NES works. Because it’s not just a normal computer with a 6502 processors in it. It’s a special computer that has a special 6502 in it, along with some other special components that make it behave a very specific way.

Even though it’s not really a game, and even though it isn’t really playable, I’m incredibly proud that I got this thing to work. I don’t know if I’ll ever pick it back up again, but for now it’s a strange little arrow in my Quiver – I wrote a Nintendo game. I have this fantasy of walking into the local retro game store with a programmed NES cart with my game on it, and asking if they’d be willing to sell it. Maybe in a few years.

Now, the moment you probably came here for. Here is the entirety of Robot Recog from start screen to finish including the secret 5th level*.

* There is no 5th level, of course. Much like people thought World -1 in Super Mario Brothers was something special, this is actually just a computer bug. In my case it’s the answer to the question “What happens when you try to go to the next level, but there aren’t anymore levels?”

Add Comment

Required fields are marked *. Your email address will not be published.