Compile Assembly Code for the Atari 2600 (10-15 mins)

Task: Compile Assembly Code for the Atari 2600

Needed: DASM cross-compiler, assembly code

Time: 10-15 mins

Introduction

I had an Atari 2600 in the late 1970s before we got our first Atari 400 and 800 computers. I recall standing in line at Sears to purchase Pac-Man when it first came out. I had so much fun with that machine. When I started collecting Atari hardware and software in 2000 the 2600 was a prime target. I was able to put together a great collection of consoles and cartridges. Around that time I discovered the homebrew community and a few years later decided to learn assembly language so I could make a game for the 2600. This of course is not easy both due to the challenges of assembly language itself and, more importantly, the severe limitations of the 2600 hardware that only had 128 bytes of RAM and no GPU. I picked this project up and dropped it numerous times over the years due to busy career and family obligations. However, I decided to roll up my sleeves and get it done in 2017 which I did with the release of my first homebrew. I made a retro edutainment game that envisions a time when clinicians can edit a patient’s DNA to cure their disease. The game is called Gene Medic and the source code and playable binary are on Github. In this post I illustrate how to compile assembly source code for the 2600 using the DASM cross-compiler for the 6502 processor and others. Interestingly, the original Atari programmers for the 2600 also used cross-compilers because the 2600 didn’t and couldn’t have a development environment. The following are assuming a PC running Windows since that is what I use.

Instructions

Step 1

Download DASM from Sourceforge. The zip file contains a DASM.exe file.

Step 2

Download GeneMedic.asm from Github.

Also download the two header files that include some important assembly macros that provide shortcuts in the Gene Medic code. These are necessary for compiling the code. You will need vcs.h and macro.h. Note that the original link to the source of these files is dead. Details are in the files themselves.

Step 3

Make sure DASM.exe, GeneMedic.asm, and the two header files are saved to the same directory.

Step 4

Open a Windows PowerShell command line prompt and navigate to the right directory.

Step 5

Enter this command to produce the binary file: 

./DASM “genemedic.asm” -o”genemedic.bin” -f3

The -o tells DASM which file will be the binary (o for output). -f3 indicates the output format. This is required. Your prompt will be slightly different for Mac or Linux (e.g. remove ./ and quotes).

Comments

Once finished you should be able to load the binary you produced into an emulator such as Stella or Javatari. You should also be able to put it on flash card to run on original hardware using a Harmony cartridge. As a side note, Gene Medic worked fine on Stella but had some issues on original hardware. I had to change my initialization routine to get it to work. Just clearing the RAM at the start was not enough. This is noted in the source code.

Cross-compiling is a necessity if you want to learn assembly and start making your own games. I will will post more about 2600 programming in the future.