Graphics


Designing Your Own Atari Graphics Modes

Craig Patchett

This one is on the list of "things you 'gotta know" about the Atari. Get set for some video magic.

The graphics modes that Atari supplies with their 400 and 800 computers are nice, but what if you want a little more? For example, how about a large-type heading, with a smaller-type subheading below it, all over a graphics display? Terrific, you say, but you're not an Atari engineer? Don't worry about a thing. With this article, a little concentration, and some time in front of the keyboard, you'll have Atari graphics modes performing at the snap of your fingers.

First, a simple explanation of what we'll be doing. In a series of memory locations deep inside your Atari rests a special list of numbers that tell the computer which graphics mode it's in. Each time you change graphics modes, this list also changes. But wait a minute. Why a list of numbers instead of just one? Because there is one number for each graphics row on the screen. For example, in graphics mode 2+16 (no text window) there are twelve graphics rows, so there would be twelve numbers in the list. For graphics mode 7+16, there would be 96 rows, or 96 numbers. The table labeled Modes and Screen Formats in your Atari BASIC reference manual shows the number of rows in each graphics mode. We'll he referring to it again later.

As I said before, when you change graphics modes, using the GRAPHICS command, the list changes. It may become longer or shorter, depending on the mode, and the numbers in it will change. But the numbers will all be the same. Obviously, since they stand for the graphics mode of each row on the screen, if half of them were one number and the other half another, then half of the screen would be one mode and the other half another. This is not how Atari BASIC was designed. It is, however, what we want. So what we're going to be doing is changing the numbers in the list to make the screen behave the way we want it to. Let's take a look at exactly how it's done.

How Much Of Each Mode Should I Have?

The first thing we have to do is figure out exactly how we want the screen to look. Let's take the example from the beginning of the article - a large-type heading (mode 2), with a smaller-type subheading below it (mode 1), all over a graphics display (mode 3). Unfortunately, we can't just decide to have, for instance, four rows of mode 2, two rows of mode 1, and nine rows of mode 3. There's a simple rule we have to follow in deciding how many rows of each mode we're going to have.

You may already know that your television picture is made up of hundreds of little lines going across the screen from top to bottom (if you don't, you know now!) If you look closely at the screen, you can probably see them. These lines are formed by a single beam of light that scans the screen very quickly (sixty times a second) to make the picture, so we'll call them scan lines. The part of the screen that your Atari lets you use for graphics has 192 of these lines.

Each graphics row is a certain number of scan lines "high." In mode 1, for example, each row is eight scan lines high. If you look at the Table of Modes and Screen Formats that I have mentioned before, you'll see that there are 24 rows in mode 1 (remember, we're only interested in "full screen.") Surprise! Twenty-four rows, each eight scan lines high, means 8 x 24 = 192 scan lines in all. To figure out how many scan lines high the rows in other modes are, just look at the table and divide 192 by the number of rows in a full screen.

The reason we need to know all this is because we must make our new mode so that it has a total of 192 scan lines. No more, no less. This means you have to do a little bit of juggling around with the different modes you want to use, but it's really not all that difficult. I'll demonstrate with our example. Let's suppose we need three rows of mode 2 and two rows of mode 1. All we need to do is figure out how many rows of mode 3 we should have to make a total of 192 scan lines. We look at the table and figure out that in mode 2, each row is sixteen (192 scan lines/12 rows) scan lines high. Since we want three rows of mode 2, that makes forty-eight scan lines so far. Similarly, we want two rows of mode 1, which uses eight (192 scan lines/24 rows) scan lines for each row. So that makes another sixteen scan lines, or sixty-four all together, which leaves us 192 - 64 = 128 scan lines still left over. We'll use these for mode 3. We look at the table again and see that mode 3 uses eight scan lines for each row also, so how many rows do we need? 128 leftover scan lines/8 scan lines per row of mode 3 = 16 rows of mode 3.

So now we know that our graphics mode is going to have three rows of mode 2, two rows of mode 1, and sixteen rows of mode 3. Let's tell the computer.

How Do I Tell The Computer?

We have to start by telling the Atari in a graphics mode it understands. Of course, we can't use just any mode, but this time the rule is a lot easier. Out of the modes you're going to be using, take the one that uses the most memory (look at the table under "RAM required"). In our example, mode 1 uses the most memory, so the first line in our program is:

10 GRAPHICS 1

The next step is to find out where the list of numbers begins. Since it isn't always in exactly the same place, we must PEEK into the computer's memory at two locations that tell us where it is. Since we'll need to use the number that tells us where the list begins later, we'll give it a name:

20 BEGIN = PEEK(560) + PEEK(561)*256 + 4

This line will always be the same no matter what modes you are going to be mixing.

The third step can be ignored if the mode you want at the top of the screen is the same as the one that uses the most memory. If not, as in our example (mode 2 is at the top of the screen, mode 1 uses the most memory), then we have to change the number in the memory location right before the beginning of the list. The table below shows what number to use for the mode at the top of the screen.

MODE    0  1  2  3  4  5  6  7  8
NUMBER 66 70 71 72 73 74 75 77 79

So, for example, we would need: 25 POKE BEGIN-1,71

Remember, only do this step if the first graphics row is not the same mode as the one that uses the most memory.

Now we just have to go down the list and change the numbers that need to be changed. The numbers for the graphics mode with the most memory are already correct, since we start in that mode. Therefore, all we have to change are the other numbers. In our example, that would be the numbers for mode 2 and mode 3. To make the necessary changes, we simply POKE BEGIN + row number with the correct number for the mode we want in that row. What are the correct numbers? Just subtract sixty-four from the numbers in the table I gave above. That would mean, for example, seven for mode 2, and eight for mode 3. So we have:

30 POKE BEGIN + 2,7:POKE BEGIN + 3,7

which takes care of mode 2. Note that we didn't POKE BEGIN + 1. This was automatically taken care of when we POKEd BEGIN - 1 in line 25. Remember that we also don't have to worry about the numbers for mode I, since they are already correct. Therefore, all that's left is to change the numbers for mode 3. Since we want sixteen rows of mode 3, which means changing sixteen numbers, we'll use a FOR/NEXT loop to make life easier:

40 FOR ROW = 6 TO 21:POKE BEGIN + ROW,8:NEXT ROW

Now the list has the correct mode numbers in it. There's still one more thing we must do. Since there may be a fewer number of rows now than there were in the mode we told the computer to start with, we have to tell the computer where the new end of the list is. We do this by POKEing the number 65 into the row number right after the last one we used. This tells the Atari to go back to the beginning of the list. We also tell it where the beginning is. For our example:

50 POKE BEGIN + 22,65:POKE BEGIN + 23,PEEK(560):POKE BEGIN + 24, PEEK(561)

And now we're done. Note that the only changes that you would need to make in line 50 when designing your own modes is in the numbers 22, 23, and 24. These are just the three row numbers after the last one you use on the screen.

How Often Do I Have To Do All This?

This whole procedure must be repeated whenever you want to use a specially designed graphics mode. You can't skip any of the steps except for the third one, and then only under the condition I already described.

So Now What Do I Do?

The last thing I'm going to cover is how to print and draw in your new mode. This only applies if the row you want to print or plot on is within the normal range for whatever mode it is. In simpler terms, if we had put the sixteen rows of mode 3 at the top of the screen, and mode 2 at the bottom, then mode 2 would have been in rows, 19, 20, and 21. But mode 2 usually only has twelve rows, so if you tried to print on line 19 you would get an error message. Now, there is a way around this, but it's somewhat complicated so I'm going to leave it for a future article. For now, however, you can use the following rules as long as you stay within the normal range of the mode you're working with.

The first thing you have to do is POKE location eighty-seven with the number of the graphics mode for the row you want to PRINT or PLOT in. Next, POSITION the cursor and PRINT, or PLOT and DRAWTO. When you tell the Atari to POSITION X, Y or PLOT X, Y, the X value is still the number of spaces in from the left that you want to go. The Y value is still the number of rows down from the top that you want to go, but you may have to experiment with different values to get it exactly where you want it. Just make sure that you remember to POKE 87 with the mode number you're going to PRINT or PLOT in.

To help you understand what I just said, and to show off the example mode we've been working on, try entering these lines, as well as the other ones that are included throughout the article. When you've entered them in, just RUN the program, and BREAK in when you're done. Notice that the commands for colors are the same in the new mode; that is, you can still print different color letters and use the COLOR command for graphics points, etc. The one difficulty that might rise is when you mix mode 0 with other modes. Since mode 0 has a different background color (blue) than the other modes (black) you will have to use the SETCOLOR command to make the mode 0 rows invisible. Otherwise, you should have no problems whatsoever.

Listing: Mixing graphics modes

Download (Saved BASIC)
Download / View (Listed BASIC)

Look, Ma, New Modes!

That's all there is to making your own graphics modes on your Atari computer. The easiest way to make sense of everything I've covered here is to experiment. Start off by changing the example program and watching what happens, and then try designing your own modes. Just a little practice and in no time you'll be an expert. Above all, have fun doing it; after all, the Atari works for you, not the other way around.


Return to Table of Contents | Previous Section | Next Section