ZX Spectrum character set

From Wikipedia, the free encyclopedia

The ZX Spectrum character set is the variant of ASCII used in the British Sinclair Spectrum computers. It is based on ASCII-1967 (the standard ASCII on which all modern character sets are based), but with one character from ASCII-1963 (the first version of ASCII), two graphics characters nonstandardly assigned, an idiosyncratic use of the control code area and use of the 128 high-bit characters beyond the ASCII range.

In the control codes area (the C0 range), the Spectrum uses its own proprietary controls, such as INK and PAPER to control foreground and background colour. The only similarity to ASCII is having cursor-left for 0x08 (ASCII Back Space) and ENTER for 0x0D (ASCII Carriage Return), which also generates an automatic linefeed. Cursor-down 0x0A (ASCII Line Feed) can be simulated with 32 spaces printed with OVER 1 (transparent overprint) and cursor-up 0x0B (ASCII Vertical Tabulation) can be simulated with 32 backspaces. The system ROM has a fault which prevents cursor-right 0x09 (ASCII Horizontal Tabulation) from working.

Ranges 0x00-0x05, 0x07, 0x0A-0x0C, 0x0E, 0x0F and 0x17-0x1F are undefined. The graphics part of the Spectrum Character Set, 0x20-0x7F, is almost standard, except that 0x60 has the pound sign (£) instead of the grave accent (`) and 0x7F has the copyright sign (©) instead of the control code DEL. Note that the pound sign was mapped to 0x60, and not 0x23 as in the British variant of ASCII (ISO-646-GB), making both pound sign and number sign (#) available universally. Code 0x5E contains an up-arrow (↑) as in ASCII-1963 instead of the ASCII-1967 caret (^); however, 0x5F has an underscore and not a left-arrow.

Beyond 0x7F, the Spectrum character set uses the high-bit range, 0x80-0xFF, for its special purposes. 0x80-0x8F contain block graphics. 0x90-0xA4 contain the User Defined Graphics (UDGs), which the user can customise with a few lines of BASIC. 0xA5-0xFF contain tokens (BASIC keywords represented as single characters): for example, pressing P at the beginning of a line would generate the code 0xF6, which would cause the BASIC keyword PRINT to display on the screen. Codes 0xC7-0xC9 are the shortcuts for the mathematical operators <= (less-than-or-equal), >= (greater-than-or-equal) and <> (not-equal) respectively; unlike the relational operators of most other systems, these are characters in their own right and cannot be achieved by typing the two constituent symbols one after the other.

Mapping the printable Spectrum Character Set to Unicode is possible, but fonts containing some of the block graphics characters are still not commonplace.

The default printable characters (32 (space) to 127 (copyright)) are stored at the end of the Spectrum's ROM at memory address 15616 (0x3D00) to 16383 (0x3FFF) and are referenced by the system variable CHARS which can be found at memory address 23606/7. Interestingly, the value in CHARS is actually 256 bytes lower than the first byte of the space character so that referencing a printable ASCII character does not need to consider the first 32 characters. As such, the CHARS value (by default) holds the address 15360 (0x3C00).

The UDG characters (Gr-A to Gr-U) are stored at the end of the Spectrum's RAM at memory address 65376 (0xFF60) to 65535 (0xFFFF). As such, POKEing this address range has immediate effect on the UDG characters. The USR keyword (when followed by a single quoted character) provides a quick method to reference these addresses from BASIC. As with the printable characters, the location of the UDG characters is stored in the system variable UDG.


Dec Char   Dec Char   Dec Char   Dec Char   Dec Char
0 NOT USED   32 SPACE   64 @   96 &   128
   
   
1 NOT USED   33 !   65 A   97 a   129
   
   
2 NOT USED   34 "   66 B   98 b   130
   
   
3 NOT USED   35 #   67 C   99 c   131
   
   
4 NOT USED   36 $   68 D   100 d   132
   
   
5 NOT USED   37 %   69 E   101 e   133
   
   
6 ,   38 &   70 F   102 f   134
   
   
7 EDIT   39 '   71 G   103 g   135
   
   
8 Cursor Left   40 (   72 H   104 h   136
   
   
9 Cursor Right   41 )   73 I   105 i   137
   
   
10 Cursor Down   42 *   74 J   106 j   138
   
   
11 Cursor Up   43 +   75 K   107 k   139
   
   
12 DELETE   44 ,   76 L   108 l   140
   
   
13 ENTER   45 -   77 M   109 m   141
   
   
14 #   46 .   78 N   110 n   142
   
   
15 NOT USED   47 /   79 O   111 o   143
   
   
16 Controls   48 0   80 P   112 p   144 UDG
17 Controls   49 1   81 Q   113 q   145 UDG
18 Controls   50 2   82 R   114 r   146 UDG
19 Controls   51 3   83 S   115 s   147 UDG
20 Controls   52 4   84 T   116 t   148 UDG
21 Controls   53 5   85 U   117 u   149 UDG
22 Controls   54 6   86 V   118 v   150 UDG
23 Controls   55 7   87 W   119 w   151 UDG
24 NOT USED   56 8   88 X   120 x   152 UDG
25 NOT USED   57 9   89 Y   121 y   153 UDG
26 NOT USED   58 :   90 Z   122 z   154 UDG
27 NOT USED   59 ;   91 [   123 {   155 UDG
28 NOT USED   60 <   92 \   124 |   156 UDG
29 NOT USED   61 =   93 ]   125 }   157 UDG
30 NOT USED   62 >   94   126 ~   158 UDG
31 NOT USED   63 ?   95 _   127 ©   159 UDG


Dec Char
160-164 UDGs
165-255 BASIC keywords


[edit] See also

[edit] External links


Sinclair computers, derivatives, and clones (ZX80/81, ZX Spectrum, and QL clones)

By Sinclair ResearchZX80 | ZX81 | ZX Spectrum, Spectrum+, Spectrum 128K | Sinclair QL
By AmstradSpectrum +2, +3
By Timex SinclairTS 1000 | TS 1500 | TS 2048 | TC 2048 | TS 2068, TC 2068
By others:  Jupiter ACE | SAM Coupé | Didaktik | Dubna 48K | Hobbit | Pentagon | Scorpion | Sprinter