User Tools

Site Tools


atari_programming

Atari Programming

I will use the Atari 400/800 as an example, with the intention of running it on the Atari 400 mini and in an emulator on a PC.

Compiler

You can use cc65 which is a C and assembly compiler, assembler, and linker. You can write code in C or Assembly. It targets the 6502 chip which is what many Atari systems use like the 400, 800, and 5200. The Apple II and NES also use the same chip. This compiler can target all of those systems and many more.

Documentation

Installing

  • Windows: Download a Windows snapshot to run from the website.
  • Mac: Install it with Homebrew using the command brew install cc65.
  • Debian GNU/Linux: Install from the repository with apt install cc65.
  • Building from source:

Hello World

Hello world example taken from https://cc65.github.io/doc/intro.html#ss1.2. It consists of one C file and one Assembly file showing you how to combine both.

main.c:

#include <stdio.h>
#include <stdlib.h>

extern const char text[];       /* In text.s */

int main (void)
{
    printf ("%s\n", text);
    return EXIT_SUCCESS;
}

text.s:

.export _text
_text:  .asciiz "Hello world!"

To build it:

# Compile the C file hello.c to assembly file hello.s 
cc65 -t atari -C atari-cart.cfg main.c

# Compile the hello.s from assembly to machine code object file hello.o
ca65 -t atari-cart main.s

# Compile text.s from assembly to machine code object file text.o
ca65 -t atari-cart text.s

# Now we have main.o and text.o ready to be linked together

# Create the "myprogram" executable by linking the object files along with
# the corresponding library file for the target system
ld65 -o mygame.rom -t atari-cart main.o text.o atari.lib

The -t flag specifies the target. I am targeting the Atari 400 and 800 with the atari target. You can view all the targets available inside the config directory cc65/cfg/.

You can also compile and link in one step with:

cl65 -t atari -C atari-cart.cfg -o mygame.rom main.c text.s

NOTE: There are multiple targets including atari and atari5200. There are also multiple config files including atari, atari-cart and atari-xex. The atari-cart creates a raw binary dump that would be the equivalent of a cartridge and the atari-xex will create a loadable program. Pick whichever suits your goals. Refer to the cc65 source code, particularly the libsrc/ and cfg/ directories to see a full list.

Emulator

To run any program we make that is targeted for Atari, we will need an Atari emulator.

  • Altirra - Runs on Windows
  • Emulator.js - Runs in a browser. Does not support Atari 400/800 but does support 2600, 5200, and 7800. If you are targeting the Atari 400 mini and want to prototype on your PC, you can target the 5200 which is supported by the Atari 400 mini. When compiling with cc65, use the -t atari5200 target. Their website has a handy tool that will help you package a web page with the playable game.
atari_programming.txt · Last modified: by nanodano

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki