How To Design
Custom Graphics Modes
Craig Chamberlain
It is well known that the Atari 400/800 computers have superior graphics. One of the things that makes the Atari graphics superior is the fact that the graphics capabilities are flexible. This versatility is demonstrated by the several unique graphics modes that can be generated by the hardware. The Operating System recognizes 12 of these modes, but there are also five other modes available. The table describes some characteristics of the various graphics modes.
There are two varying factors which distinguish one graphics mode from another. First, the pixel size or resolution(number of pixels it takes to fill the screen) can differ. Second, the number of color possibilities per pixel may change. The various modes offer different combinations of these two qualities. Because there are so many modes to choose from, it is easier to find one to suit a particular application, which is one reason why Atari graphics are so versatile.
In BASIC, the GRAPHICS command (or GR. in Atari BASIC) is used to change the screen from one graphics mode to another. A number from zero to 11 must follow the GRAPHICS command. This number corresponds to the 12 graphics modes supported by the Operating System. An overview of the general characteristics for these modes is given here.
Operating System Graphics Modes
0 1,2 3,5,7 4,6 8 9,10,11 |
primary text (default mode) color text three-color bit-mapped graphics, various resolutions one-color bit-mapped graphics, various resolutions high-resolution mode, one color specialty modes (explained in other articles) |
For all graphics modes except mode zero, a small, four-line text window is provided at the bottom of the screen. If this text window is not desired, it can be eliminated by adding 16 to the number after the GRAPHICS command. Whereas a GRAPHICS 3 changes the screen to mode three with a text window, GRAPHICS 19 changes the screen to mode three with no text window.
Whenever the screen is changed to a new mode using the GRAPHICS command, the screen is automatically cleared, in case any unwanted data might have been left in the screen memory. To defeat this automatic clearing of the screen, add 32 to the number after the GRAPHICS command. This is of little use, however, to BASIC programs.
Using the GRAPHICS command changes the whole screen to a new mode. But is it possible to mix graphics modes? Of course. The text window at the bottom of a screen is actually mode zero combined with the other mode above it. But then, what says that the text window has to be at the bottom of the screen, or that the text must be shown in mode zero? What if it is necessary to use the other graphics modes not supported by the Operating System and BASIC? Doing all these wonderful things requires a little more technical knowledge of Atari graphics, and it starts with something called the display list.
When BASIC is given a GRAPHICS command, the Operating System not only reserves room for display data, but also creates a display list. A display list is a sequence of bytes in memory that, among other things, defines the format of the screen.
We'll talk more about the display list, how to find it and how to change it, but first we must delve just a little deeper into Atari graphics terminology.
When you see a screen of a certain graphics mode, you are actually seeing a screen of several identical mode lines. A mode line is equivalent.to one row of the screen. It is a horizontal strip or section of the screen and is one pixel high. Therefore, the vertical resolution (how many rows) of a graphics mode tells how many mode lines are needed. Each mode line determines the number of pixels and colors that will span from left to right (how many columns).
For example, a mode zero screen offers resolution of 40 across by 24 up and down. In order to produce a mode zero screen, 24 mode lines of mode zero will be required. Each of the those mode lines will consist of 40 characters across.
So, the idea of a full-screen graphics mode does not really apply. Rather, a full screen is a bunch of mode lines stacked vertically to fill up the screen.
A mode line is just as high as a pixel, but the actual height of a mode line can vary. The unit used for measuring the height of a mode line is the scan line. Just as a screen consists of mode lines, a mode line consists of a certain number of scan lines. Different mode lines have different numbers of scan lines. The table shows how many scan lines are contained in each mode line.
Why all the fuss about scan lines? Because there is a limit to how many scan lines can be displayed on a screen. As a rule, whenever the Operating System creates a screen of any graphics mode, it always uses just the right number of mode lines so that the scan line total equals 192. One hundred ninety-two is the maximum number of scan lines that the average television set can display without excessive overscan(cutoff). A screen can have fewer than 192 scan lines without any problem, but to use many more than 192 is only inviting trouble.
Anyway, remember that different mode lines have different numbers of scan lines, and the desirable total scan line count is 192. These two factors control the vertical resolution in a mode as follows:
Given a graphics mode, take 192 scan lines, divide by the number of scan lines per each mode line, and the result is the proper number of mode lines for that particular graphics mode. And, as demonstrated earlier, one mode line corresponds to one horizontal row on the display, so the number of mode lines is the same as the number of rows, which is called vertical resolution.
Now, how was that again? Here's an example using our familiar friend, graphics mode zero. According to the chart, a mode line in mode zero consists of eight scan lines. One hundred ninety-two scan lines divided by eight scan lines per mode line is 24 mode lines. Indeed, the vertical resolution of mode zero is 24 rows.
This is where the display list comes in. The display list describes how many of which mode lines are used to fill the screen from top to bottom. According to our previous example, a display list for a mode zero screen will have to indicate that 24 mode lines of mode zero are to be used. Actually, a mode zero display list looks like this:
Mode Zero Display List
112 112 112 66 XXX XXX 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 65 XXX XXXX |
It is immediately noticeable that there are no zeroes in the display list. On the other hand, the number two is certainly used often enough. This brings up an important point. The number found in a display list to indicate a mode line is not the same number used by the Operating System for that mode. The table presented at the end has a column marked IR CODE. The label IR stands for Instruction Register. The column shows the hardware equivalent (IR number) for all Operating System modes, as well as for modes not supported by the Operating System. Mode three uses an IR code of eight. IR code four is a multicolor character text mode not normally available. Mode zero is indicated in a display list by an IR number two, which explains the frequent occurrence of that number in the display List example.
The number two, however, is not the only number in the display list example. Now it is time to fully explain the structure of the display list and reveal what the other numbers mean.
The number 112 is used three times at the beginning of the display list. Together, these three numbers tell the video hardware to display 24 empty scan lines at the top of the screen before the place where the picture starts. These are not mode lines, and do not count as part of the 192 scan lines. Instead, they are called "blank lines," and they create a border at the top of the screen in the background color, just before the 192 scan lines of display. This convention is used by the Atari to reduce overscan problems.
An entry in the display list can show from one to eight blank lines. The number to be used in the display list is derived using the following process:
To show N blank lines, the display list number is (N-1)*16. To show 8 blank lines, 8-1 = 7 and 7*16 = 112, so every use of the number 112 in the display list causes the hardware to show eight scan lines in the background color. Three uses of 112 gives a total of 24 blank lines.
0 16 32 48 64 80 96 112 |
1 blank line 2 blank lines 3 blank lines 4 blank lines 5 blank lines 6 blank lines 7 blank lines 8 blank lines |
The next number in the display list looks like a 66, but it is not a 66. It is a 64 + 2. The 2 indicates that a mode zero mode line should follow the blank lines. The 64 is a "load memory scan counter" (LMS) command, and means that the next two bytes form an address which points to where the display memory (screen data) starts. Because the display data is always put at the top of memory, the two numbers after the 66 will vary on different computers, according to the amount of RAM installed in each computer.
Since the address of the display memory is broken down into two bytes, a little bit of math will be needed to reconstruct the address. The two bytes are in low-byte, high-byte format. To compute the address, take the high-byte (the second of the two numbers), multiply it by 256, then add it to the low-byte. The result is the address of the first byte of display memory. If a 10 were POKEd at this location on a mode zero screen, the upper leftmost character on the screen would be changed to an asterisk. Adding 20 to the address and doing another POKE will cause an asterisk to appear in the middle of the top row of the screen.
The important point to remember is that by adding 64 to a normal mode line number, in this case a 2, the graphics hardware will not only process the mode line, but perform a LMS command as well. The two bytes immediately following the mode line with the 64 added will form an address that tells the hardware where the following display data resides in memory. The LMS operation actually happens before the mode line starts.
The LMS command is normally used at the beginning of a screen, on the first mode line, but it can be done on any mode line, or on several mode lines, for special applications. Display lists created by the Operating System always have only one LMS command, on the first mode line, except for modes eight through eleven, which for technical reasons require another LMS command in the middle of the display list.
The next numbers in our example display list are a bunch of 2's. There are 23 of them, to be exact. These are the remaining 23 mode lines of mode zero. Remember that the first one was the mode line with the LMS command.
Following the mode lines are a number 65 and a final two bytes. The 65 is another special number which technically means "perform a display list jump and wait for vertical sync." For our purposes, the 65 simply means "this is the end of the display list; go back to the beginning of the display list when the television scanning beam is ready to start drawing another frame." The two bytes after the 65 are in low-byte, high-byte format and represent an address. This address points to the top of the display list. Now would be a good time to tell where the display list is placed. Whenever the Operating System is requested to create a screen of a certain graphics mode, it always puts the display list just before the display data. So, just as the display memory address varies according to the amount of memory in the computer and the graphics mode, so will the display list address vary.
That concludes the explanation for a normal mode zero display list. It should now be obvious that mixing modes on one screen is just as easy as changing the mode lines in the display list. But first, we need to know how to determine exactly where the display list resides in memory. We know that the address of the beginning of the display list is given at the end of the display list, after the 65, but that won't do us any good if we don't know where the display list is located in the first place.
Fortunately, there is a way to find the address of the beginning of the display list. The same address given in the two bytes after the 65 is also stored in memory locations 560 and 561.
SDLSTL $0230 560 shadow display list address low-byte
SDLSTH $0231 561 shadow display list address high-byte
The address is broken down into two bytes and must be reconstructed using the same procedure shown earlier. In BASIC, the standard method is to use the variable DL for the display list address:
DL = PEEK(560) + 256*PEEK(561)
After issuing a GRAPHICS 0 command and assigning DL, a PEEK(DL) should return a 112, as will PEEK(DL + 1) and PEEK(DL + 2). But PEEK(DL + 3) will return a 66.
To change mode lines in the display list, POKE statements must be used. For example, a POKE DL + 20,4 will put a multicolor text mode line in the middle of the mode zero screen. Try typing on that row and see what happens.
Next, type some characters below the multicolor text mode line, do a POKE DL + 20,7, and watch carefully. A mode two line will now be in the middle of the screen, but there will be side effects as well. Two problems will be evident: the bottom of the screen is now a little lower than before, and text below the mode line is not properly aligned.
As for the first problem, a quick glance at the chart will reveal that we replaced a mode zero line of eight scan lines with a mode two line of 16 scan lines. The display now has more than 192 scan lines, hence the bottom of the screen appears lower.
This problem can be fixed, somewhat. It is necessary to delete the eight extra scan lines, which can be easily done by getting rid of the last mode line. Eliminate the last mode line by executing these instructions:
POKE DL + 28,65
POKE DL + 29,PEEK(560)
POKE DL + 30,PEEK(561)
All we did was place the "end of display list" command a little earlier in the display list, which effectively cuts off any display below that point. There is a new problem, however, because now there are only 23 rows, but the Operating System still "thinks" there are 24. Hmmm. We traded one problem for another. Let's change the subject and explore the problem of the incorrectly aligned text.
The text below the mode two line has been displaced by 20 characters. The explanation for this is really quite simple. We replaced a mode zero line that needed 40 bytes of data with a mode line that, according to the chart, requires only 20 bytes. There are now an extra 20 bytes on the screen, but the Operating System again is not aware that a change has been made. The text could be realigned with a POKE DL + 21,7 but then there would be 40 extra bytes, or essentially, enough for another row.
All of these problems are conflicts with the Operating System. The Operating System establishes the display list but does not monitor it. Changes to the display list only affect the hardware and screen display. Such problems are not always easy to deal with, so they are discussed in separate articles. The key things to remember are:
1. The display should not exceed 192 scan lines.
2. When creating a custom display list, the number of mode lines is limited by the number of mode lines normally allotted for the current mode. (You can mix only up to 24 mode lines on a mode zero screen.)
3. Care must be taken that the mode lines do not require a larger total amount of memory than was designated for the current mode. (Changing several 20-character mode lines to 40-character mode lines would be one way to cause this problem.)
We have now covered the main points of what a display list is, why it is needed, what purpose it serves, how to find it in memory, how to change it, and what problems can be expected as a result of these changes. The display list also controls horizontal and vertical fine scrolling, and a special interrupt, but these are more advanced topics.
To further demonstrate how to modify a display list, three BASIC programs have been provided.
Program 1 prints a display list of mode three with a text window, then changes the bottom text lines to mode one. The display list in this case consists of the 24 blank lines (112,112,112), the LMS command on the first mode three mode line (64 + 8 = 72), the address of the display memory, more mode three mode lines (8,8,8,...), another LMS command on the first line of the mode zero text window (64 + 2 = 66), the address of the text window memory, the remaining three mode lines of mode zero (2,2,2), and the return (65) followed by the address of the beginning of the display list.
Program 2 creates a mode three screen with a text window, but then moves the text window to the top of the screen. Brief screen flitter is normal.
Program 3 displays from three to 24 blank lines at the top of the screen, then mixes 14 different modes on the screen. Try moving the cursor around and typing in the different modes.
Table. The Graphics Modes.
OS 0 - - - 1 2 3 4 5 6 - 7 - 8 |
IR 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
C 1 1 4 4 4 4 3 1 3 1 1 3 3 1 |
SL 8 10 8 16 8 16 8 4 4 2 1 2 1 1 |
V 24 - 24 12 24 12 24 48 48 96 192 96 192 192 |
H 40 40 40 40 20 20 40 80 80 160 160 160 160 320 |
B 40 40 40 40 20 20 10 10 20 20 20 40 40 40 |
OS IR C SL V H B |
OS MODE IR CODE COLORS (PLAYFIELDS) SCAN LINES ROWS (MODE LINES) COLUMNS BYTES |
Download P034L1.BAS (Saved BASIC)
Download / View P034L1.LST (Listed BASIC)
Download P034L2.BAS (Saved BASIC)
Download / View P034L2.LST (Listed BASIC)
Download P034L3.BAS (Saved BASIC)
Download / View P034L3.LST (Listed BASIC)
Return to Table of Contents | Previous Section | Next Section