cc65
- Publisher
- Open source (GitHub: cc65/cc65)
- Type
- Development tool
- Category
- C cross-compiler and 6502 toolchain
- Developer
- John R. Dunning (original Atari version); Ullrich von Bassewitz (rewrite); Christian Groessler (Atari library maintainer); cc65 team
- Language
- C (host tools); output 6502 machine language
- Requirements
- Windows, Linux or macOS host; output runs on Atari 400/800 (atari target) or XL/XE except 600XL (atarixl target); disk/DOS or cartridge/cassette per linker config
- Tags
- c, compiler, cross-compiler, assembler, ca65, ld65, cl65, modern, open-source, toolchain
- Related
- SpartaDOS X, SpartaDOS, FujiNet, Windows (BASIC Demo), FastBasic, Mad Pascal
Overview
cc65 is a complete cross-development package for 6502 and 65C02 machines. It contains a C compiler (cc65), a macro assembler (ca65), a linker (ld65), an archiver, a simulator and the cl65 front end that runs the whole chain in one command. It supports dozens of platforms, from the Apple II and Commodore 64 to the NES, but it has a particular link with the Atari. Its first version was an Atari-hosted C compiler, and the Atari 8-bit remains one of its best-supported targets. Modern Atari software such as the FujiNet network apps is often written with it.
History
cc65 descends from the Small C compiler by Ron Cain, later enhanced by James E. Hendrix. John R. Dunning wrote the original C compiler and runtime library, and it ran on the Atari itself. Dunning is also known on the Atari for Kermit-65. Ullrich von Bassewitz later moved the code to modern systems, rewrote most of the compiler and all of the runtime library, and turned it into the multi-platform suite it is today. Christian Groessler maintains the Atari, Atari 5200 and CreatiVision libraries. Development continues on GitHub, with snapshot builds for Windows and Linux.
Atari support
cc65 has two Atari targets:
-t atariruns on every Atari 8-bit. The default linker configuration assumes BASIC is disabled, leaving roughly $2000–$BC1F for your program. The startup code reads MEMTOP to find the real top of memory, and the C stack grows down from there.-t atarixlis for XL/XE machines (not the 600XL). It switches off the OS ROM so that nearly all 64K is usable (apart from the $D000–$D7FF I/O area), moves the screen below the program, copies the character set to RAM, and loads at $2400 by default. The documentation advises using plainatariunless you really need the memory.
Both targets write standard multi-segment DOS binary files with a run vector at $2E0. A small first segment at $2E00 checks the machine and available memory. Further linker configurations cover assembly-only programs (atari-asm.cfg), the newer native XEX output (atari-xex.cfg), 8K/16K cartridges (atari-cart.cfg), cassette boot files of up to 32K (atari-cassette.cfg) and overlays.
The atari.h header provides:
- an
OSstructure for the OS shadow registers, with their usual names (OS.color4,OS.savmsc,OS.stick0,OS.ch), plusBASICfor its zero page; ANTIC,GTIA_READ/GTIA_WRITE,POKEY_READ/POKEY_WRITEandPIAstructures that map straight onto the chips;- display-list macros (
DL_LMS(...),DL_DLI(...),DL_CHR20x8x2, and so on) for building ANTIC lists in C; - helpers such as
_graphics(),_setcolor(),_sound(),waitvsync(),get_ostype(),get_tv()and_dos_type.
Loadable drivers include TGI graphics for OS modes 3–11, 14 and 15 (including the GTIA 16-shade modes and two-page "p2" variants), a 130XE extended-memory driver, joystick drivers (standard ports or a MultiJoy adapter for eight sticks), mouse drivers (joystick-emulated, ST mouse, Amiga mouse, trakball) and an RS232 driver that uses an installed R: handler (tested with the 850, up to 9600 baud). With a suitable DOS, command-line arguments reach main(), and the real-time clock is available under SpartaDOS X.
Hello, Atari
#include <stdio.h>
#include <conio.h>
#include <atari.h>
int main(void)
{
OS.color4 = 0x94; /* border colour via the OS shadow */
printf("Hello from cc65!\n");
cgetc(); /* wait for a key */
return 0;
}
cl65 -O -t atari hello.c -o hello.xex
-O adds an optimiser pass, and -Oi inlines more for speed at some cost in size. Load the result from DOS 2/2.5 or any compatible DOS, or simply drop it on an emulator. The cc65 introduction also describes using an emulator's H: host-drive patch so you can run builds straight from your PC folder.
Strengths and gotchas
- Mixed C and assembly is easy.
ca65is a capable macro assembler in its own right, and many Atari coders use it on its own. In a 2020 AtariAge discussion one developer recommended ca65 with a PC text editor and an emulator over coding on the 8-bit. - Character sets. Strings are ATASCII by default, which suits CIO and
printf. For direct screen writes you can switch to the internal (screen-code) mapping. - Size and speed. C on a 6502 produces bigger, slower code than hand-written assembly. Use
unsigned charwherever possible, avoid deep recursion, and move hot loops into assembly. - ANTIC alignment. Display lists, fonts, screen memory and player/missile data have alignment rules. You will usually need a custom linker config with aligned segments.
- conio does not support the XEP80 or 80-column software drivers, and
atarixlclears the screen at start and exit as a side effect of moving display memory.
In the wild
cc65 underpins much Atari networking software, including the IP65 TCP/IP stack and apps built on it, and the FujiNet application collection, which provides a boot-disk-cc65-template project and sample code for FujiNet App Keys.
Credits
- Picture: This entry's C example, built with cl65 -t atari and running in an emulator. — John R. Dunning (original Atari version); Ullrich von Bassewitz (rewrite); Christian Groessler (Atari library maintainer); cc65 team (program); screenshot by the site
- cc65 repository — README — GitHub project authors
- cc65 documentation — Atari specific information (atari.sgml) — cc65.github.io
- cc65 documentation — Introduction (intro.sgml) — cc65.github.io
- comp.sys.atari.8bit FAQ (Michael Current) — network/FujiNet software lists — Michael Current (comp.sys.atari.8bit FAQ)
- AtariAge forum — Atari 800XL ASM programming on emulator — AtariAge forum members
