LDA #$F4
LDA $0602
LDA ($D0),Y
There are nine color registers in the ATARI 400/800 Computer; four are for player- missile graphics and will be discussed in Section 4. The remaining five are not always used; depending on the graphics mode used, as few as two registers or as many as five will show up on the screen. In BASIC mode 0, only two and one-half registers are used because the hue value of the characters is ignored; characters take the same hue as playfield register 2 but take their luminance from register 1. The color registers are in CTIA at addresses $D016 through $D01A. They are "shadowed" from OS RAM locations into CTIA during vertical blank. Figure 3-1 gives color register shadow and hardware addresses.
Image Controlled | Hardware | OS Shadow | ||
---|---|---|---|---|
Label | Address | Label | Address | |
Player 0 | COLPM0 | D012 | PCOLR0 | 2C0 |
Player 1 | COLPM1 | D013 | PCOLR1 | 2C1 |
Player 2 | COLPM2 | D014 | PCOLR2 | 2C2 |
Player 3 | COLPM3 | D015 | PCOLR3 | 2C3 |
Playfield 0 | COLPF0 | D016 | COLOR0 | 2C4 |
Playfield 1 | COLPF1 | D017 | COLOR1 | 2C5 |
Playfield 2 | COLPF2 | D018 | COLOR2 | 2C6 |
Playfield 3 | COLPF3 | D019 | COLOR3 | 2C7 |
Background | COLBK | D0lA | COLOR4 | 2C8 |
Figure 3-1 Color Register Labels and Addresses
Colors are encoded in a color register by a simple formula. The upper nybble gives the hue value, which is identical to the second parameter of the BASIC SETCOLOR command. Table 9-3 of the BASIC Reference Manual lists hue values. The lower nybble in the color register gives the luminance value of the color. It is the same as the third parameter in the BASIC SETCOLOR command. The lowest order bit of this nybble is not significant. Thus, there are eight luminances for each hue. There are a total of 128 colors from which to choose (8 luminances times 16 hues). In this book, the term `color' denotes a hue- luminance combination.
Once a color is encoded into a color register, it is mapped onto the screen by referring to the color register that holds it. In map display modes which support four color registers the screen data specifies which color register is to be mapped onto the screen. Since there are four color registers it takes only two bits to encode one pixel. Thus, each screen data byte holds data for four pixels. The value in each pair of bits specifies which color register provides the color for that pixel.
In text display modes (BASIC's GRAPHICS modes 1 and 2) the selection of color registers is made by the top two bits of the character code. This leaves only six bits for defining the character, which is why these two modes have only 64 characters available.
Color register indirection gives you four special capabilities. First, you can choose from 128 different colors for your displays. This allows you to choose the color that most nearly meets your needs.
Second, you can manipulate the color registers in real time to produce pretty effects. The simplest version of this is demonstrated by the following BASIC line:
FOR I=0 TO 254 STEP 2:POKE 712,I:NEXT I
10 GRAPHICS 23
20 FOR X=0 TO 39
30 FOR l=0 TO 3
40 COLOR I
50 PLOT 4*X+I,O
60 DRAWTO 4*X+1,95
70 NEXT I
80 NEXT X
90 A=PEEK(712)
100 POKE 712,PEEK(710)
110 POKE 710,PEEK(709)
120 POKE 709,PEEK(708)
130 POKE 708,A
140 GOTO 90
The fourth and most important application of color registers Is used with display list interrupts. A single color register can be used to put up to 128 colors onto a single screen. This very Important capability will be discussed in Sect ton 5.
Character Image | Binary Representation | Hex Representation |
---|---|---|
00000000 |
00 |
Figure 3-2 Character Encoding
A full character set has 128 characters in it, each with a normal and an inverse video incarnation. Such a character set needs 1024 bytes of space and must start on a 1K boundary. Character sets for BASIC modes 1 and 2 have only 64 distinct characters, and so require only 512 bytes and must start on a 1/2K boundary. The first 8 bytes define the zeroth character, the next 8 bytes define the first character, and so on. Obviously, defining a new character set is a big job. Fortunately, there are software packages on the market to make this job easier.
Once the character set is defined and placed into RAM, you must tell ANTIC where it can find the character set. This is done by poking the page number of the beginning of the character table into location $D409 (decimal 54281). The OS shadow location, which is the location you would normally use, is called CHBAS and resides at $2F4 (decimal 756). The third step in using character sets is to print the character you want onto the screen. This can be done directly from BASIC with simple PRINT statements or by writing numbers directly into the screen memory.
A special capability of the system not supported in BASIC is the four- color character set option. BASIC Graphics modes 1 and 2 support five colors, but each character in these modes is really a two-color character; each one has a foreground color and a background color. The foreground color can be any of four single colors, but only one color at a time can be shown within a single character. This can be a serious hindrance when using character graphics.
There are two other text modes designed especially for character graphics. They are ANTIC modes 4 and 5. Each character in these modes is only four pixels wide, but each pixel can have four colors (counting background) The characters are defined just like BASIC Graphics mode 0 characters, except that each pixel is twice as wide and has two bits assigned to it to specify the color register used. Unlike ANTIC modes 6 and 7 (BASIC modes 1 and 2), color register selection is not made by the character name byte but instead by the defined character set. Each byte in the character table is broken into four bit pairs, each of which selects the color for a pixel. (This is why there are only four horizontal pixels per character.) The highest bit (D7) of the character name byte modifies the color register used. Color register selection is made according to Figure 3-3:
bit pair in character defn | D7 = 0 | D7 = 1 |
---|---|---|
00
|
COLBAK
|
COLBAK
|
Figure 3-3 Color Register Selection for Characters
Using these text modes, multicolored graphics characters can be put onto the screen.
Another interesting ANTIC character mode is the lowercase descenders mode (ANTIC mode 3). This mode displays 10 scan lines per mode line, but since characters use only eight bytes vertically, the lower two scan lines are normally left empty. If a character in the last quarter of the character set is displayed, the top two scan lines of the character will be left empty; the data that should have been displayed there will instead be shown on the bottom two lines. This allows the user to create lowercase characters with descenders.
Figure 3-4 Energy CZAR Bar Charts
In many applications, character sets can be created that show special images. For example, by defining a terrain graphics character set with river characters, forest characters, mountain characters, and so forth, It is possible to make a terrain map of any country. Indeed, with imagination a map of terrain on a different planet can be done just as easily. When doing this, it is best to define five to eight characters for each terrain type. Each variation of a single type should be positioned slightly differently in the character pixel. By mixing the different characters together, It is possible to avoid the monotonous look that Is characteristic of primitive character graphics. Most people won't realize that the resulting map uses character graphics until they study the map closely. Figure 3-5 shows a display of a terrain map created with character set graphics. The reproduction in black and white does not do justice to the original display, which has up to 18 colors.
Figure 3-5 Terrain Map With Character Set Graphics
You could create an electronics character set with transistor characters, diode characters, wire characters, and so forth to produce an electronics schematics program. Or you could create an architectural character set with doorway characters, wall characters, corner characters, and so on to make an architectural blueprint program. The graphics possibilities opened up by character graphics with personal computers have not been fully explored.
Characters can be turned upside down by pokeing a 4 into location 755. One possible application of this feature might be for displaying playing cards (as in a Blackjack game). The upper half of the card can be shown right side up; with a display list interrupt the characters can be turned upside down for the lower half of the card. This feature might also be of some use in displaying images with mirror reflections (reflection pools, lakes, etc.
Even more exciting possibilities spring to mind when you realize that It is quite practical to change character sets while the program is running. A character set costs either 512 bytes or 1024 bytes; in either case It is quite inexpensive to keep multiple character sets in memory and flip between them during program execution. There are three time regimes for such character set multiplexing: human slow (more than 1 second); human fast (1/60 second to 1 second); and machine fast (faster than 1/ 60 sec).
Human-slow character set multiplexing is useful for "change of scenery" work. For example, a space travel program might use one graphics character set for one planet, another set for space, and a third set for another planet. As the traveller changes locations, the program changes the character set to give exotic new scenery. An adventure program might change character sets as the player changes locales.
Human-fast character set multiplexing is primarily of value for animation. This can be done in two ways: changing characters within a single character set, and changing whole character sets. The SPACE INVADERS (trademark of Taito America Corp.) program on the ATARI Home Computer uses the former technique. The invaders are actually characters. By rapidly changing the characters, the programmer was able to animate them. This was easy because there are only six different monsters; each has four different Incarnations.
High-speed cyclic animation of an entire screen is possible by setting up a number of character sets, drawing the screen image, and then simply cycling through the character sets. If each character has a slightly different incarnation in each of the character sets, that character will go through an animated sequence as the character sets are changed. In this way a screen full of objects could be made to cyclically move with a very simple loop. Once the character set data is in place and the screen has been drawn, the code to animate the screen would be this simple:
The use of character sets for graphics and animation has many advantages and some limitations. The biggest advantage is that it costs very little RAM to produce detailed displays. A graphics display using BASIC mode 2 characters (such as the one shown in Figure 3-5) can give as much detail and one more color than a BASIC mode 7 display. Yet the character Image will cost 200 bytes while the map image will cost 4000 bytes. The RAM cost for multiple character sets is only 512 bytes per set, so It Is inexpensive to have multiple character sets. Screen manipulations with character graphics are much faster because you have less data to manipulate. However, character graphics are not as flexible as map graphics. You cannot put anything you want anywhere on the screen. This limitation would preclude the use of character graphics in some applications. However, there remain many graphics applications for which the program need display only a limited number of predefined shapes in fixed locations. In these cases, character graphics provide great utility.