Redefined Character Sets: Custom Fonts and Character Graphics

GRAPHICS 0 screen where the @ key now prints a smiley face and # prints a solid diamond

The Atari doesn't draw text from a fixed font baked into the video hardware. ANTIC looks up every character's shape in a table whose address you control. Point it at a table of your own and every letter on the screen changes instantly — into a new typeface, a foreign alphabet, or graphic tiles for a game map. De Re Atari calls this "graphics indirection", and it was the secret behind countless Atari games whose detailed scenery used only a few hundred bytes of screen memory.

What you'll learn: how characters are encoded, the internal character order, how to copy the ROM font into RAM safely, how to redefine characters from BASIC (with a fast machine-language copy), and how to use four-colour characters and character-set animation.

What you need: Atari BASIC on any 8-bit Atari, graph paper (or a font editor), and patience for typing DATA statements.

How a character is stored

Each character is an 8 × 8 grid of pixels stored as 8 bytes, one per row, top row first. A lit pixel is a 1 bit, with the leftmost pixel as bit 7 (value 128) and the rightmost as bit 0 (value 1). De Re Atari's example is the letter A:

00000000  =   0
00011000  =  24
00111100  =  60
01100110  = 102
01100110  = 102
01111110  = 126
01100110  = 102
00000000  =   0

A full set holds 128 characters × 8 bytes = 1,024 bytes, and must start on a 1K boundary. (Inverse video characters are not stored separately; the hardware inverts them.) In GRAPHICS 1 and 2, only 64 characters are used — the top two bits of each screen byte choose the colour instead — so those sets are 512 bytes on a 512-byte boundary.

Charles Brannon's article in COMPUTE!'s Second Book of Atari Graphics adds a practical tip: TVs show thin vertical lines poorly, so design characters with two-pixel-wide vertical strokes — this also avoids NTSC colour artifacts in GRAPHICS 0.

The internal character order

The table is not in ATASCII order. ANTIC uses "internal" codes:

Internal codes Characters ATASCII codes
0–63 space, punctuation, digits, uppercase 32–95
64–95 control-key graphics symbols 0–31
96–127 lowercase letters and a few symbols 96–127

So the definition of internal character n starts at CHSET + 8*n. For example, "@" (ATASCII 64) is internal 32, and the letter "A" (ATASCII 65) is internal 33.

Where to put your character set

The ROM font lives at 57344 ($E000). To change it you must copy it to RAM. The OS register that tells ANTIC where to look is CHBAS at 756 ($2F4), the shadow of the hardware register CHBASE at 54281 ($D409). It holds a page number; the default is 224 (224 × 256 = 57344).

The usual place for the RAM copy is just under the top of memory. Lower RAMTOP (location 106) and issue a GRAPHICS statement so the screen moves down out of the way. But mind the "RAMTOP Dragon" documented by K. W. Harms: GRAPHICS and screen-clears erase the first 64 bytes above RAMTOP (that would wipe your first eight characters), and scrolling the text window of a GRAPHICS 3–8 split screen can erase up to 800 bytes. The safe pattern, used by Orson Scott Card in the same book, is to reserve 2K and put the set in the upper 1K:

10 A=INT((PEEK(106)-8)/4)*4:POKE 106,A:GRAPHICS 0
20 CH=A+4:CHSET=CH*256

INT(.../4)*4 makes sure the address is a multiple of 1K.

Copying the ROM font quickly

A FOR/NEXT loop that PEEKs and POKEs 1,024 bytes takes around 15 seconds in BASIC (Brannon's estimate). This 34-byte machine-language routine does it instantly. It uses the zero-page bytes 203–206 ($CB–$CE), which the BASIC and Assembler cartridges leave unused:

30 FOR I=0 TO 33:READ D:POKE 1536+I,D:NEXT I
40 X=USR(1536,CH)
50 DATA 104,104,104,133,206,169,224,133,204
60 DATA 169,0,133,203,133,205,162,4,160,0
70 DATA 177,203,145,205,200,208,249,230,204
80 DATA 230,206,202,208,242,96

Disassembled:

        PLA             ; number of USR arguments (1)
        PLA             ; high byte of argument (0)
        PLA             ; low byte = destination page
        STA $CE         ; destination pointer, high byte
        LDA #$E0        ; source = $E000 (ROM font)
        STA $CC
        LDA #0
        STA $CB         ; source low byte
        STA $CD         ; destination low byte
        LDX #4          ; 4 pages = 1024 bytes
        LDY #0
LOOP    LDA ($CB),Y
        STA ($CD),Y
        INY
        BNE LOOP
        INC $CC         ; next page
        INC $CE
        DEX
        BNE LOOP
        RTS

Atari BASIC's USR pushes the argument count and each argument (high byte, then low byte) on the stack, which is why the routine starts with three PLAs.

Redefining characters

Now overwrite whichever characters you want. This replaces "@" (internal 32) with a smiling face and "#" (internal 3) with a solid diamond, then switches ANTIC to the new set:

90 FOR C=1 TO 2:READ N
100 FOR J=0 TO 7:READ D:POKE CHSET+8*N+J,D:NEXT J
110 NEXT C
120 DATA 32,60,66,165,129,165,153,66,60
130 DATA 3,24,60,126,255,255,126,60,24
140 POKE 756,CH
150 PRINT "THE @ KEY NOW TYPES A FACE: @@@"
160 PRINT "AND # IS A DIAMOND: ###"

From now on every "@" on screen — including ones typed in the editor — is a face. The change is instant because nothing on screen is redrawn; only the lookup table changed. Remember that any GRAPHICS statement resets CHBAS to 224, so POKE 756 again after changing modes (the RAM set itself survives).

For GRAPHICS 1 and 2, copy just 512 bytes. The ROM holds two half-sets: POKE 756 with 224 for uppercase, digits and punctuation, or 226 for lowercase and the control graphics.

Other character tricks

Upside down and blinking text. CHACT at 755 (shadow of CHACTL, 54273) controls inverse video and character reflection. The default is 2; add 4 to flip characters upside down (POKE 755,6 here; POKE 755,2 restores). Toggling bit 0 periodically makes inverse-video characters blink.

Character animation. Because every copy of a character shares one definition, changing the 8 bytes animates all of them at once. De Re Atari cites Atari's Space Invaders cartridge, whose invaders are characters with four animation frames each. Try:

200 FOR F=0 TO 1
210 FOR J=0 TO 7:POKE CHSET+8*32+J,PEEK(CHSET+8*(64+F)+J):NEXT J
220 FOR W=1 TO 60:NEXT W
230 NEXT F:GOTO 200

This copies two of the control-graphic shapes (internal 64 and 65) into "@" in turn. In a game you would store your own frames in unused characters.

Whole-set flipping. Keep several complete sets in memory and change CHBAS to switch between them — instant scenery changes, or cyclic animation of an entire screen. De Re Atari's example is just a loop of POKE 756,CHARBASE(I).

Several fonts on one screen. A display list interrupt can store a different page number into the hardware register CHBASE ($D409) partway down the screen; the OS restores CHBAS at the top every frame.

Four-colour characters (ANTIC modes 4 and 5)

GRAPHICS 0 characters have one colour. ANTIC modes 4 and 5 (GRAPHICS 12 and 13 on the XL/XE OS) instead treat each character as 4 pixels wide, each pixel 2 bits: 00 = background (712), 01 = PF0 (708), 10 = PF1 (709), 11 = PF2 (710). If the screen byte has bit 7 set (an "inverse" character), 11 uses PF3 (711) instead, as De Re Atari's Figure 3-3 shows. Mode 4 lines are 8 scan lines high, mode 5 lines 16.

So in mode 4 the byte %00011011 is four pixels: background, PF0, PF1, PF2. This is the basis of most colourful Atari character-graphics games; Card's article includes a complete four-colour character editor. On a 400/800, set up ANTIC 4 by rewriting the GRAPHICS 0 display list (see Custom Display Lists): since both modes are 40 × 24, the OS still prints in the right places.

Design tools

Popular font editors in the 1980s included FontEdit (from the disk magazine Iridis), Online Systems' The Next Step and COMPUTE!'s "SuperFont" (January 1982). COMPUTE!'s Second Book of Atari Graphics includes character editors for both one-colour and four-colour sets plus "Fontbyter" for laying out screens. Any of these can still be run in an emulator, and save sets as 1,024-byte files you can load with a simple OPEN/GET loop or a CIO block read.

Troubleshooting

  • Garbage instead of letters: the set isn't on a 1K boundary (512 for GRAPHICS 1/2), or you POKEd CHBAS before copying the font.
  • First few characters corrupted after GRAPHICS: the set is in the 64 bytes just above RAMTOP. Move it up 1K.
  • New font vanishes after changing modes: GRAPHICS resets 756 to 224; POKE it again.
  • Lowercase missing in GRAPHICS 1/2: those modes show only 64 characters; switch halves with 224/226 or design a set that puts what you need in the first 64.
  • USR call crashes: check the DATA count (34 bytes) and that the argument is a page number (0–255), not a full address.

Further reading

  • De Re Atari (Atari, 1982), Chapter 3.
  • COMPUTE!'s Second Book of Atari Graphics (COMPUTE! Books, 1984), Chapter 3 — character generation, custom characters, four-colour modes and their editors.
  • Mapping the Atari by Ian Chadwick (COMPUTE! Books) — 755, 756 and 54281 entries.
  • Atari Roots by Mark Andrews (Datamost, 1984) — custom character sets in assembly language.

Credits