3

The Four-Color
Character Modes


titlebar.gif

Orson Scott Card


Here's how to unlock two "hidden" character modes on your Atari: ANTIC 4 and 5. Each character can display up to four colors at a time, and the effect can be exciting. This is a complete introduction to four-color character graphics, including subroutines that will help you use these modes in your own programs and a complete character set you can type in and use.

Two of the programs in this book are designed to help you make use of two "hidden" graphics modes on your Atari: the four-color character modes. "Four-Color Character Editor" allows you to create characters in these modes and save entire character sets to tape or disk. "Fontbyter" allows you to draw large or small screen displays using the character sets you created with the Four-Color Character Editor. To make full use of these utilities, it helps to know how the four-color character modes work.


ANTIC and the Character Modes

The GRAPHICS command automatically changes the way the ANTIC video chip in your Atari computer controls the television screen. GRAPHICS 0, 1, and 2 are text modes, putting characters like A, 7, or % on the screen; GRAPHICS 3 through 8 are pixel modes, in which you control the color of little squares, called pixels, on the screen.

The modes differ from each other in the size of each character or pixel. If you use a mode with larger pixels or characters, you will use up less memory to create your screen display--but you will also get fewer colors or poorer picture resolution.

When your program uses a character mode, the ANTIC processor scans through screen memory. Each byte of memory contains a number from 0 to 255. ANTIC uses that number as an index or pointer into character memory. The number 22 tells ANTIC to skip 22 characters in order to find the one to display in that position on the screen.

Let's go through that process in detail.


The Display List

First, ANTIC checks locations 560 and 561 to get the address of the display list. When ANTIC jumps to the display list, it usually finds that the first three bytes each contain the number 112, which tells ANTIC to output several blank lines to the TV screen.

Screen memory address. ANTIC then finds an instruction that consists of the ANTIC mode number, or mode instruction, plus the number 64. The number 64 is a code that tells ANTIC to look for screen memory at the address contained in the next two bytes. Whenever ANTIC finds a 64 added to a mode instruction in the display list, it looks at the next two bytes to find the address of screen memory.

The first mode instruction must have a 64 and be followed by the screen memory address. If screen memory continues unbroken from there, you never need to give the address of screen memory again. Anytime you want to change screen memory, however, you only need to add 64 to the mode instruction for the line where you want the change to begin, and then give the new screen memory address in the next two bytes.

Mode instructions. The ANTIC mode number that is added to 64 is not the same as the graphics mode number you use with the GRAPHICS command. ANTIC modes range from 2 to 15. (Table 1 shows how the ANTIC mode numbers compare to graphics mode numbers.) ANTIC modes 2 through 7 are character modes; modes 8 through 15 are pixel modes.

There must be a mode instruction for every line on the screen. In ANTIC 2 (GRAPHICS 0) there are 24 lines on the screen--so there must be 24 mode instructions. In ANTIC 15 (GRAPHICS 8) there are 192 lines--and so you must have 192 mode instructions.

Close the display list. After the last mode instruction, there will be a 65--which is the 64 instruction added to 1. The 64 tells ANTIC to look for an address in the next two bytes, but the 1 tells it that it won't be screen memory, but rather the address of the start of the display list. ANTIC then waits until it's time to start displaying at the top-left corner of the TV screen again, then jumps back to the start of the display list and starts over.

Here's a short subroutine you can use in your own programs to create an ANTIC 4 or 5 display list. Lines 5-20 are not part of the subroutine--they're just there so you can RUN the program right now and see what ANTIC 4 and 5 do to the screen.

Atari BASIC will still let you type and enter program lines or instructions as if you were in GRAPHICS 0. That's fine if you're in ANTIC 4, since both GRAPHICS 0 and ANTIC 4 use 24 lines of 40 characters. But ANTIC 5 uses only 12 lines of 40 characters, so BASIC's screen handler will put half the screen display "below" the TV screen, out of sight.


Display List Maker

5 ? "What ANTIC mode do you want? (4 or 5"
10 TRAP 10:INPUT M: IF M<4 OR M>5 THEN M=2
15 ? "Writing a display list in ANTIC ";M:GOSUB 4000 
20 END 
4000 DL=PEEK(560)+256*PEEK(561):POKE DL+3,M+64 
4005 FOR I=DL+6 TO DL+16+12*(M=4):POKE I,M:NEXT I:POKE I,65:POKE I+1,0:
     POKE I+2,DL/256:RETURN

Download P071L1.BAS (Saved BASIC)
Download / View P071L1.LST (Listed BASIC)

This routine works only if you are leaving the display list exactly where the latest GRAPHICS 0 statement left it.


Reading Screen Memory

After each mode instruction in the display list, ANTIC goes to screen memory and reads the next line's worth of information. If a line is 40 units wide, ANTIC reads 40 bytes. In a pixel mode, ANTIC interprets those bytes directly as instructions telling it what color to use for the squares on the screen. In a character mode, however, ANTIC uses the bytes as an index into the character set.

Finding the character set. ANTIC finds the character set by using the number held in location 756. When the computer powers up, that number points to the page number (or high byte) of the address of the built-in character set. You can change that number to point to your own character set. Make sure that your character set begins on a 1K boundary, however. The easiest way to make sure that the address you are POKEing into location 756 is on a 1K boundary is to use the following routine. The variable CHBAS is the high byteof the starting address of your character set. TOP is where you are telling the computer the top of memory is. Anything you put above TOP will be left alone by the computer.

500 TOP=PEEK(106)-8 
510 POKE 106,TOP 
520 CHBAS=TOP+4

This fools the computer into thinking that usable memory ends eight pages (2K) sooner than it really does. Now you have plenty of space that the computer won't touch. The character set itself needs only four pages (1K), but the other four pages will hold your display list and other safe memory. In fact, if you subtract more pages, you can put your screen memory in this safe area, too.

530 CH=CHBAS*256

If you multiply CHBAS by 256, you get CH, the full address of the character set, rather than just the page number, or high byte, of its address.

540 OPEN #1,4,0,"D:CUSTOM.SET":FOR I =0 TO 1024:GET #1,N:
     POKE CH+I,N:NEXT I:CLOSE

This line opens the disk file containing your character set ("D:CUSTOM.SET") and loads it (slowly) into screen memory.

550 POKE 756,CHBAS

From the moment you make this POKE, ANTIC will use your character set instead of the built-in character set.

Fast loading. Here is a subroutine you can add to your own programs. It loads your character set from disk in a few seconds, using a machine language routine, and then writes a display list. Most of the time you will completely eliminate lines 5 and 6, the PRINT ("?") statements in lines 4000 and 4020, and all of lines 4025 and 4030; instead, your program will simply assign your character set's disk filename to the variable CHSET$ and the ANTIC mode number to the variable M. The excess material is included here so that you can try out the routine and see how it works.


Character Set Loader

5 DIM CHSET$(20):CHSET$="D:CASTLE.SET":GOSUB 4000 
6 END
4000 A=PEEK(106):TOP=A-8:CHBAS=TOP+4:DL=256*TOP:POKE 106,TOP:
     CH=CHBAS*256:GRAPHICS 0: ? "Loading ";CHSET$
4005 X=16: ICCOM=834:ICBADR=836:ICBLEN=840:SL=PEEK(88):SH=PEEK(89)
4010 OPEN #1,4,0,CHSET$
4015 POKE ICBADR+X+1,CHBAS:POKE ICBADR+X,0:POKE ICBLEN+X+1,4:
     POKE ICBLEN+X,0
4020 POKE ICCOM+X,7:
     I=USR(ADR("hhh{inverse asterisk}LV{inverse small d}"),X):
     CLOSE #1:? "What ANTIC mode do you want? (4 or 5)"
4025 TRAP 4025:INPUT M:IF M<4 OR M>5 THEN 4025
4030 ? "Writing the display list for ANTIC ";M
4035 FOR I=0 TO 2:POKE DL+I,112:NEXT I:POKE DL+3,M+64:POKE DL+4,SL:
     POKE DL+5,SH
4040 FOR I=DL+6 TO DL+16+12*(M=4):POKE I,M:NEXT I:POKE I,65:
     POKE I+ 1,0:POKE I+2,DL/256
4045 POKE 756,CHBAS:POKE 560,0:POKE 561,DL/256

Download P072L1.BAS (Saved BASIC)
Download / View P072L1.LST (Listed BASIC)

Reading the character set. When ANTIC reads a byte of screen memory, it uses it as an index into the character set. Let's say that ANTIC found a 34 in screen memory. Since each character in the set uses up eight bytes for its definition, ANTIC will look for the character at CH + 8*34, or 272 bytes after the start of the character set. ANTIC reads the eight bytes of that character pattern; it will display the character pattern in the next location on the screen. Then it goes to screen memory, reads the next byte, finds that character pattern in the character set, and so on.


ANTIC 4 and 5 Character Modes

ANTIC 4 handles screen memory exactly like GRAPHICS 0 (ANTIC 2), the normal text mode on the Atari. There are 24 lines of 40 characters each on the screen. However, the charactersare interpreted very differently.

Normal character patterns. No matter what character mode you are using, the characters are created following the pattern formed by eight bytes. Each byte consists of eight bits. Think of the bytes as if they were stacked on top of each other, making a square eight bits wide and eight bytes high, as in Table 2.

ANTIC 2 (GRAPHICS 0) reads the character pattern in a straightforward way. If a bit in the character pattern is set to 1, it is on,and one dot of the character's color is displayed; if the bit is set to 0, the background color is displayed in that spot. The pattern for a letter Amight look like the one shown in Table 3.

Four-color character patterns. ANTIC 4 and 5 cannot use exactly this system, since the same eight bytes must tell ANTIC not only which bits are on and which are off, but also which color the dot on the screen should be. One bit just won't do. So the four-color character modes treat the bits as pairs, so that two bits control each dot on the screen, as shown in Table 4.

However, this would make each character only half as wide, and it would take 80 characters to fill a line. To avoid this, each bit-pair in ANTIC 4 characters controls the color of twodots on the screen. Now the characters are just as wide as the characters in ANTIC 2 (GRAPHICS 0), but the horizontal resolution is only half as good.

That is why, in these four-color character modes, it is nearly impossible to create letters like W and M, and very hard to distinguish between N and H. The four-color modes are not particularly good for alphanumeric characters. However, they are wonderful for making the building blocks of elaborate full-color drawings.

The five colors. Each bit-pair has four possible combinations: 00, 01, 10, and 11. These correspond to the decimal numbers 0, 1, 2, and 3. A bit-pair with the value of 00 will cause the background color, stored at memory location 712, to be displayed. A bit-pair with the value of 01 will display the color stored at location 708; the bit-pair 10 (decimal 2) will display the color at location 709; and the bit-pair 11 (decimal 3) will display the color stored at location 710.

There is a fifth color available. If a character is entered into screen memory in inversemode (the character number plus128), then any bit-pair 11 (decimal 3) in that character will display, not the color at 710, but the color at 711. This means that if you plan your character set carefully, you can have five colors on your screen at one time.

We still call them four-color character modes, however, because no one character can display more than four colors at a time.

Table 5 shows a simple shape, an apple tree with fruit on it. The trunk is brown, the leaves are green, the fruit is red, and the background is black. However, this pattern creates onlyhalf the tree--it is assumed that the other half is held in another character, and the two would be combined to create the full tree.

Also, the fruit is created with the bit-pair 11 (decimal 3). This allows us to enter the same character in inverse mode and display different-colored fruit--orange, for example, instead of red. Or fruit could ripen gradually from green to bright red. Careful planning can result in a great deal of freedom in creating your screen displays.


How to Use the Utilities

The Four-Color Character Editor will let you create your own ANTIC 4 and 5 character sets. This will be a time-consuming project, but once you have a character set made, you can use it again and again to make many different drawings.

Fontbyter will let you use your own character sets--or the Castle Maker character set included here--to make your own drawings and save them, perhaps to use them in programs. You can make drawings many times the size of the TV screen and scroll through them.

You don't have to have a particular programming goal in mind. Though both programs are long and will take quite a bit of time to type in, they can be used over and over again. You'll have a hard time deciding whether you're programming, creating artwork, or just playing. The truth is, with ANTIC 4 and 5, you can do all three at once.


Table 1. Character Modes

Character Modes Characters or
pixels per
line
Comments
GRAPHICS ANTIC
0 2 40

The default mode of the Atari. The
border and background can be
different colors, but the characters are
the same color as the background--
only the brightness is different.
Twenty-four lines on the screen.

-- 3 40

Rarely used. It is identical to
GRAPHICS 0 except that the top two
lines of each lowercase character are
put on the bottom. It can be used to
create true descenders on lowercase
letters.

12* 4 40

Identical to GRAPHICS 0 in the way it
uses screen memory and the size of
the character set (all 256 characters are
available), but four colors are possible
in eachcharacter, and by using inverse
characters, five colors can be displayed
on the screen at once. However, the
horizontal resolution is only half as
good as in GRAPHICS 0. Twenty-four
lines on the screen.

13* 5 40

Identical to ANTIC 4 except that each
character is twice as tall. This gives the
characters a stretched-out look, but fills
up the screen while using half as much
memory. Twelve lines on the screen.

1 6 20

Uses only 64 characters, but each
character can be displayed with oneof
four different colors. Twenty-four
lines per screen.

2 7 20

The same as GRAPHICS 1 (ANTIC 6)
except the characters are twice as tall.
Twelve lines per screen.

*XL Models


Table 2. The 8 x 8 Character Matrix

Bits
Byte 1
Byte 2
Byte 3
Byte 4
Byte 5
Byte 6
Byte 7
Byte 8
7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

Table 3. GRAPHICS 0 Character Pattern

Bits
Byte 1
Byte 2
Byte 3
Byte 4
Byte 5
Byte 6
Byte 7
Byte 8
7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0
0 0 1 1 1 1 0 0
0 1 1 0 0 1 1 0
0 1 1 1 1 1 1 0
0 1 1 0 0 1 1 0
0 1 1 0 0 1 1 0
0 0 0 0 0 0 0 0
 
    11
   1111 
  11  11 
  111111
  11  11
  11  11

Table 4. The 4 x 8 ANTIC 4 and 5 Matrix

Bits
Byte 1
Byte 2
Byte 3
Byte 4
Byte 5
Byte 6
Byte 7
Byte 8
7-6
00
00
00
00
00
00
00
00
5-4
00
00
00
00
00
00
00
00
3-2
00
00
00
00
00
00
00
00
1-0
00
00
00
00
00
00
00
00

Table 5. An ANTIC 4 Character Pattern

Bits Bit Patterns*   "On" Bits   Colors Displayed

Byte 1
Byte 2
Byte 3
Byte 4
Byte 5
Byte 6
Byte 7
Byte 8
7-6
00
10
10
00
00
00
00
00
5-4
10
11
10
10
10
00
00
00
3-2
00
10
10
11
10
00
00
00
1-0
10
11
10
10
10
01
01
01
 

10
10

10
11
10
10
10


10
10
11
10

10
11
10
10
10
01
01
01
 

GRE
GRE

GRE
RED
GRE
GRE
GRE


GRE
GRE
RED
GRE

GRE
RED
GRE
GRE
GRE
BRN
BRN
BRN


*00 = Color Register 4 (background, memory location 712)
  01 = Color Register 0 (memory location 708)
  10 = Color Register 1 (memory location 709)
  11 = Color Register 2 (memory location 710)
  11 inverse= Color Register 3 (memory location 711)


Castle Maker--A Character Set

Download P078L1.BAS (Saved BASIC)
Download / View P078L1.LST (Listed BASIC)
Download CASTLE.SET (Character set file)

Return to Table of Contents | Previous Section | Next Section