Classic Computer Magazine Archive COMPUTE! ISSUE 42 / NOVEMBER 1983 / PAGE 273

All About The TI Character Set

Michael A Covington

This brief outline of the TI character set explains how the computer recognizes each character. The author discusses some uses of the characters' numeric codes and indicates which characters' graphic representations can be assigned or changed.

Chances are you've never given your computer's character set much thought. You press keys on the keyboard and the characters appear on the screen; that's all there is to it, or so it seems. But there's a lot more going on than meets the eye.

Inside the computer, each character is represented by a numeric code – a number between 0 and 255 inclusive. For instance, the code for capital E is 69; the code for an exclamation mark is 33; the code for a blank (a blank is a character just like all the others) is 32. To associate these codes with the characters you see on the screen, the computer has to know two more things about each of them: a graphic representation that describes how the character is supposed to look on the screen, and a key assignment that indicates what key or combination of keys you can hit on the keyboard to type the character. For instance, the character string "HELLO THERE!" (not counting the quotation marks) involves the following:

Graphic representation: H E L L O T H E R E !
Numeric code: 72 69 76 76 79 32 84 72 69 82 69 33
Key assignment: H Key E Key L Key L Key O Key space bar T Key H Key E Key R Key E Key Shift & 1 keys

Statements Using Numeric Codes

Normally (when you type characters in response to a string INPUT statement or when you type them as part of a program) you enter characters by hitting the keys that correspond to them. That is, you access them by means of their key assignments, and within the program you treat them as character-string data. But there are ways of referring to characters by their numeric codes and treating them as numbers. For instance, the CALL HCHAR and CALL VCHAR statements, which you meet at an early stage as you work through the manuals that come with the computer, refer to characters by their numbers. The statement

CALL  HCHAR(3, 3, 69, 20)

will place a row of 20 capital E's (character number 69) on the screen beginning at row 3, column 3.

Also, you can input characters as numeric codes. The CALL KEY statement senses whether a particular key on the keyboard is up or down; when a key is pressed, CALL KEY gives you the numeric code corresponding to it. For instance, here is a program which will tell you the numeric code of any key on the keyboard:

30 IF STATUS < > 1 THEN 20
50 GO TO 10

The heart of the program is lines 20 and 30. Line 20 tells the CALL KEY subroutine to look at the keyboard and report what's going on. The variable STATUS will equal 1 only if the condition of the keyboard has changed since the last time the routine looked at it. If STATUS does not equal 1, we simply go back to line 20, since we don't want to do anything more if the user hasn't pressed a key or hasn't yet let go of the one already looked at. The variable CODE contains the numeric code associated with the key being pressed, if any. (The first parameter of CALL KEY, the number 5, simply indicates that we want the usual BASIC set of codes; specifying other numbers there instructs the computer to use other sets of key assignments for various special purposes.)

The ASC and CHR$ functions allow you to convert back and forth between numeric codes and character strings. If A$ is a character string, ASC(A$) is the numeric code of its first character; thus ASC("E") is 69. Conversely, if N is a number, CHR$(N) is a one-character string of which N is the numeric code; thus CHR$(69) is E. If we want the program above to print the characters themselves rather than their codes, we can convert the codes into characters by changing line 40 to:


The CALL CHAR subroutine allows you to alter graphic representations using a hexadecimal code that the manual describes in detail. For instance, if you want to change the dollar sign ($) into a British pound sign (£), just execute the statement:

CALL CHAR(36, "001C22207C20207E")

That will do it, at least as long as the program is running: the key assignment and numeric code will be the same, but the dollar sign will look like a pound sign. (It will revert to its original appearance when your program stops executing.)

What's Not In The Manual

Those are the preliminaries; now we get to the really interesting part (the part that isn't in the manual, at least not entirely). Internally, the computer can use any number from 0 to 255 as a character code; any such code can be an element in a character string and can be referred to by CALL VCHAR, CALL HCHAR, and CHR$. (In fact, CALL VCHAR, CALL HCHAR, and CHR$ will actually take numbers up to 32767; multiples of 256 are subtracted as necessary to get a number in the 0-to-255 range.) But not all the codes have key assignments or graphic representations. The breakdown (by numeric codes) is as follows:

0 - Undefined (no key assignment, no graphic representation).

1 to 15 - Function keys (Table 1). Most of these characters can be input by means of the CALL KEY statement, but they cannot be typed in normal contexts (for example, in response to an INPUT) because there they are interpreted as requests to perform cursor movements or the like. They have no graphic representations (if you print them, you get blanks or garbled patches).

16 to 29 - Undefined (like 0, these codes have no key assignments and no graphic representations, and there is no straightforward way of giving them either).

30 - The graphic representation of this character is the black square that marks the cursor; thus, CHR$(30) is handy if you want a black square. No key is assigned to it.

31 - This is the screen border character – a blank that is the color of the border rather than the typing area. No key is assigned to it.

32 to 126 - Standard ASCII characters (Table 2). These are the characters you use every day, including the alphabet, the numbers, and all the punctuation marks and mathematical symbols. Their graphic representations can be changed with CALL CHAR but will revert to their original form when the program ends.

127 to 159 - User-defined characters (Table 3). These start out with no graphic representations, but you can define them with CALL CHAR, and, contrary to what the TI manual says, such definitions remain in effect after the program stops running (though most are disrupted when another program is loaded).

What most people don't realize is that these characters can be typed – they have key assignments and are acceptable in the same context as any other character (that is, in response to an INPUT or CALL KEY, or within quotes in a program). All but one of them require you to hold down the CTRL key (at the lower-left corner of the keyboard) when typing them; character number 127 uses the FCTN key instead.

160 to 175-Undefined.

176 to 198-These characters have key assignments (Table 4), but no graphic representations and no direct way of giving them any. They can be used as special function keys of some sort (in response to either CALL KEY or INPUT), but not as displayable characters.

199 to 255-Undefined.

Even the "undefined" character codes (those that cannot be typed on the keyboard or displayed on the screen) are not completely useless. You can refer to them by means of CHR$ and ASC and use them as special markers of various kinds when manipulating character strings. They also may come into play when you are transmitting data to other devices (for example, printers or other computers) that have definitions for characters that are undefined on the TI-99.

Finally, consider this possibility. Each character in a character string has a code between 0 and 255 inclusive, accessible through CHR$ and ASC. Also, the SEG$ function allows you to address individual characters in a string, and the & (concatenation) operator allows you to construct strings out of individual characters. This means that a character string gives you a compact way of storing a set of integers between 0 and 255 – each element occupies only one byte in memory, as compared to the eight bytes normally needed to store a number. So if you have a program that needs to keep track of thousands of small integers – more than will fit in available memory in numeric form – then character strings may be the answer.

Table 1: Function Key Codes
(None of these characters have graphic representations, nor can they be given them. They can be typed only through the CALL KEY statement, not in response to a string INPUT statement, or within a program.)
Code Key
1 FCTN7("AID")
2 None usable. The key definition associated with this code is FCTN 4, but in BASIC, hitting that key interrupts the program.
5 None usable. The key definition associated with this code is FCTN =, but hilling that key forces a machine reset mid the program in memory is lost.
6 FCTN 8 ("REDO")
7 FCTN 3 ("ERASE")
8 FCTN S (left arrow)
9 FCTN D (right arrow)
10 FCTN X (down arrow)
11 FCTN E (up arrow)
12 FCTN6("PROC'D")
14 FCTN 5 ("BEGIN")
15 FCTN 9 ("BACK")
Table 2: ASCII Graphic Characters On The TI-99/4A
(This table gives the numeric codes and graphic representations; the key assignments are marked on the keyboard. The graphic representations can be changed by the CALL CHAR statements but revert to their original form when the program stops running.)
Code Graphic Representation Code Graphic Representation
32 (space) 53 5
33 ! 54 6
34 " 55 7
35 # 56 8
36 $ 57 9
37 % 58 :
38 & 59 ;
39 ' 60 <
40 ( 61 =
41 ) 62 >
42 * 63 ?
43 + 64 @
44 , 65 A
45 -(minus) 66 B
46 . 67 C
47 / 68 D
48 0 69 E
49 1 70 F
50 2 71 G
51 3 72 H
52 4 73 I
74 J 97 a
75 K 98 b
76 L 99 c
77 M 100 d
78 N 101 e
79 O 102 f
80 P 103 g
81 Q 104 h
82 R 105 i
83 S 106 j
84 T 107 k
85 U 108 l
86 V 109 m
87 W 110 n
88 X 111 o
89 Y 112 p
90 Z 113 q
91 [ 114 r
92 \(back slash) 115 s
93 ] 116 t
94 ^ 117 u
95 _(underline) 118 v
96 ' 119 w
120 x
121 y
122 z
123 {
124 |
125 }
126 -
127 See Table 3. TI documentation mistakenly classifies this character with the wrong group.
Table 3: User-definable Graphics Characters
These characters can be typed using the key combinations listed and are acceptable in any context (that is, they can be input using the CALL KEY or INPUT statements and can appear between quotes within a BASIC program).
Graphic representations can be given to these characters with the CALL CHAR statement. Contrary to TI documentation, such representations, once assigned, will persist after the program stops running.
Code Key
128 CTRL, (comma)
129 CTRL A
131 CTRL C
132 CTRL D
134 CTRL I
135 CTRL G
136 CTRL H
137 CTRL1
139 CTRL K
140 CTRL L
142 CTRL N
144 CTRL P
145 CTRL Q
146 CTRL R
147 CTRL S
148 CTRL T
149 CTRL U
150 CTRL V
151 CTRL W
152 CTRL X
153 CTRL Y
154 CTRL Z
155 CTRL. (period)
156 CTRL ;
157 CTRL =
158 CTRL 8
159 CTRL 9
Table 4: Characters With Key Assignments But No Graphic Representations
These characters are not mentioned in TI documentation. They can be typed in any context (that is, in response to an INPUT or CALL KEY statement or between quotes in a program), but they have no graphic representations and cannot be given any.
Code Key
176 CTRL 0
177 CTRL 1
178 CTRL 2
179 CTRL 3
180 CTRL 4
181 CTRL 5
182 CTRL 6
183 CTRL 7
184 FCTN, (comma)
185 FCTN. (period)
186 FCTN/
187 CTRL/
188 FCTN 0 (zero)
189 FCTN;
190 FCTN B
191 FCTN H
192 FCTN J
193 FCTN K
194 FCTN L
195 FCTN M
196 FCTN N
197 FCTN Q
198 FCTN Y