ATASCII and Keyboard Codes: The Atari Character Set Reference

A grid of the 128 ATASCII characters on a black Atari screen, 16 per row, with hexadecimal row and column labels; graphics characters fill rows 00 and 10

Atari characters come in three numberings, and a lot of confusion (and many bugs) comes from mixing them up:

  • Keyboard codes are what POKEY reports and the OS stores in location 764 (CH). They follow the wiring of the keyboard: A is 63, S is 62.
  • ATASCII is the Atari's version of ASCII, used by PRINT, GET, CHR$ and ASC, by files, and by the printer. A is 65.
  • Internal (screen) codes are what actually sits in screen memory and the order of shapes in the character set. A is 33.

This reference covers all three, with conversion rules taken from the original OS source and a BASIC program that draws the whole character set.

What you'll learn: the layout of ATASCII, the internal-code conversion, every screen-editor control code and how to put it in a string, the complete key-code table, and code to convert between them.

What you need: Atari BASIC. The programs were tested on revision C.

1. ATASCII at a glance

ATASCII matches ASCII for codes 32–95 (space, digits, punctuation and capitals) and for the lower-case letters 97–122. The rest differ: 96 is a diamond (♦) rather than a backquote, 123 is a spade (♠), 124 is the vertical bar, and 125–127 display as arrows, because they are the clear-screen, backspace and tab controls. Codes 0–31 are graphics characters (lines, corners, card suits, arrows) rather than invisible controls. Codes 128–255 are the same 128 shapes in inverse video. Bit 7 simply means "inverse".

The chart above was drawn by this program:

10 REM ATASCII CHART: CODES 0-127, 16 PER ROW
20 GRAPHICS 0:POKE 752,1:POKE 710,0
30 DIM H$(16):H$="0123456789ABCDEF"
40 ? "     ATASCII CHARACTERS 0-127"
50 ? :? "    ";:FOR C=1 TO 16:? H$(C,C);" ";:NEXT C:?
60 S=PEEK(88)+256*PEEK(89)
70 FOR R=0 TO 7
80 POSITION 2,R*2+4:? H$(R+1,R+1);"0"
90 FOR C=0 TO 15
100 A=R*16+C:I=A-32:IF A<32 THEN I=A+64
110 IF A>95 THEN I=A
120 POKE S+(R*2+4)*40+6+C*2,I
130 NEXT C:NEXT R
140 POSITION 2,21:? "ADD 128 FOR INVERSE VIDEO";
150 GOTO 150

It POKEs straight into screen memory (address in 88–89), so it has to convert each ATASCII code to an internal code first (lines 100–110). Printing the characters instead would execute control codes such as 125 (clear screen). Press BREAK to stop it.

2. ATASCII to internal code and back

The OS converts with a four-entry table indexed by bits 5 and 6 of the code. The rule, for codes 0–127 (keep bit 7 for inverse):

ATASCII Internal Contents
0–31 64–95 graphics characters
32–95 0–63 space, digits, punctuation, capitals
96–127 96–127 lower case and the last few symbols (unchanged)

In BASIC:

1000 REM ATASCII A TO INTERNAL I
1010 B=A-128*(A>127):I=B-32:IF B<32 THEN I=B+64
1020 IF B>95 THEN I=B
1030 I=I+128*(A>127):RETURN

The internal order is also the order of the character set in memory. Shape n starts at CHBASE×256 + 8×n. The ROM font is at 57344 ($E000), which is why the letter A's shape starts at 57344+33×8. This matters when you redefine characters (see Redefined Character Sets) and in ANTIC modes 6 and 7 (GRAPHICS 1 and 2), where only 64 shapes are available and bits 6–7 choose the colour.

3. Screen-editor control codes

When these codes are PRINTed to the screen editor (E:), they perform actions instead of displaying. This is the complete list from the editor's dispatch table in the OS source:

Code Hex Action Typed as
27 $1B ESC: display the next character literally ESC
28 $1C Cursor up CTRL-−
29 $1D Cursor down CTRL-=
30 $1E Cursor left CTRL-+
31 $1F Cursor right CTRL-*
125 $7D Clear screen SHIFT-CLEAR or CTRL-CLEAR
126 $7E Backspace BACK S
127 $7F Tab TAB
155 $9B End of line (RETURN) RETURN
156 $9C Delete line SHIFT-BACK S
157 $9D Insert line SHIFT-INSERT
158 $9E Clear tab stop CTRL-TAB
159 $9F Set tab stop SHIFT-TAB
253 $FD Bell (buzzer) CTRL-2
254 $FE Delete character CTRL-BACK S
255 $FF Insert character CTRL-INSERT

To put one into a program string, type ESC first and then the key. The editor shows the control character's symbol instead of performing it. That is how magazine listings contain {CLEAR} and cursor arrows (see Typing In Magazine Listings). Alternatively, build the string with CHR$: ? CHR$(125) clears the screen, and ? CHR$(253) rings the buzzer.

To display a control character's shape rather than act on it, PRINT ESC first: ? CHR$(27);CHR$(125) shows the clear-screen arrow symbol.

4. Keyboard codes

POKEY reports a 6-bit key number, plus bit 6 for SHIFT and bit 7 for CTRL. The OS turns it into ATASCII with three 64-entry tables: lower case, SHIFT and CTRL. This is the complete table, decoded from the original OS source (values are ATASCII; "–" means the combination produces nothing):

Code Key Normal SHIFT CTRL Code Key Normal SHIFT CTRL
0 L 108 76 12 32 , 44 91 [ 0
1 J 106 74 10 33 SPACE 32 32 32
2 ; 59 58 : 123 34 . 46 93 ] 96
5 K 107 75 11 35 N 110 78 14
6 + 43 92 \ 30 37 M 109 77 13
7 * 42 94 ^ 31 38 / 47 63 ? –
8 O 111 79 15 39 Atari (inverse) – – –
10 P 112 80 16 40 R 114 82 18
11 U 117 85 21 42 E 101 69 5
12 RETURN 155 155 155 43 Y 121 89 25
13 I 105 73 9 44 TAB 127 159 158
14 − 45 95 _ 28 45 T 116 84 20
15 = 61 124 \| 29 46 W 119 87 23
16 V 118 86 22 47 Q 113 81 17
18 C 99 67 3 48 9 57 40 ( –
21 B 98 66 2 50 0 48 41 ) –
22 X 120 88 24 51 7 55 39 ' –
23 Z 122 90 26 52 BACK S 126 156 254
24 4 52 36 $ – 53 8 56 64 @ –
26 3 51 35 # EOF 54 < 60 125 125
27 6 54 38 & – 55 > 62 157 255
28 ESC 27 27 27 56 F 102 70 6
29 5 53 37 % – 57 H 104 72 8
30 2 50 34 " 253 58 D 100 68 4
31 1 49 33 ! (pause) 60 CAPS caps toggles
61 G 103 71 7
62 S 115 83 19
63 A 97 65 1

Codes not listed (3, 4, 9, 17, 19, 20, 25, 36, 41, 49 and 59) produce nothing on the 400/800. The XL/XE models use some of them: HELP, and the 1200XL's function keys. Notes:

  • The values in 764 (CH) are these codes, with 64 added for SHIFT and 128 for CTRL. 255 means no key. So PEEK(764)=63 is A, and 127 is SHIFT-A.
  • CTRL-1 never reaches your program. The keyboard interrupt uses it to pause and resume screen output. CTRL-3 makes the K: device return end-of-file (error 136).
  • If both SHIFT and CTRL are held, the OS ignores the key.
  • The Atari key (inverse, code 39) toggles inverse typing, kept in location 694 (INVFLG). CAPS cycles location 702 (SHFLOK) between lower case (0), caps lock (64) and CTRL lock (128).
  • On the XL/XE you can install your own table: location 121–122 (KEYDEF) points to the 192-byte table the OS uses.

5. Reading keys in each form

10 OPEN #1,4,0,"K:"
20 ? "PRESS KEYS (BREAK TO STOP)"
30 POKE 764,255
40 IF PEEK(764)=255 THEN 40
50 K=PEEK(764):GET #1,A
60 ? "KEY CODE ";K;"  ATASCII ";A;"  ";CHR$(27);CHR$(A)
70 GOTO 30

Line 50 reads the raw key code first and then lets K: convert the same key to ATASCII, which empties CH again. The CHR$(27) before the character makes even control codes display as symbols. At power-up, pressing A shows KEY CODE 63 ATASCII 65. Caps lock is on (location 702 holds 64) until you press CAPS, and then the same key gives 97.

Troubleshooting

  • Comparing PEEK(764) with ASC("A") never matches: CH holds key codes, not ATASCII. Use the table, or read through K: with GET.
  • POKEd characters come out wrong: screen memory takes internal codes. Convert from ATASCII first (section 2).
  • A PRINTed string clears the screen or moves the cursor: it contains control codes. Precede each one with CHR$(27) to display it instead.
  • Letters come out lower case or as graphics: location 702 is set to lower case or CTRL lock. POKE 702,64 forces capitals.

Further reading

  • Atari, Inc., Operating System User's Manual (1982): keyboard handler, key-code-to-ATASCII table and display handler sections.
  • Atari, Inc., Atari 400/800 Operating System Source Listing: the ATAINT/INTATA conversion tables and the CNTRLS control-code table.
  • Ian Chadwick, Mapping the Atari: 694, 702, 756 and 764, plus the keyboard-code appendix.
  • On this site: Reading the Keyboard, Console Keys and HELP, Writing an Interrupt-Driven Keyboard Handler, Redefined Character Sets.

Credits