Moving the Display


Michael P. Surh

A variation on the techniques which allow screen flipping also makes possible screen scrolling--even horizontally. Here's how.

The Atari computers are capable of moving their display memory (that is, the section of memory storing the screen display), and they can have more than one section of display memory stored at the same time. This feature is particularly useful for graphics displays and can be used for animation. It is possible to move the entire screen so that everything you see on the screen moves too, and the technique can be used to create smoother animation and drawing than would otherwise be possible.

Before you try the following programs which demonstrate these tricks, you should have some understanding of how the Atari display works. The Atari has two separate registers that control where it keeps its display (the display list) in the overall computer memory. These registers work by storing the address of the first memory location used by the display list. The computer puts all of the screen data into the memory starting at that first address, and also reads the numbers stored there to display images on the screen. Since what you see on the screen is stored in this memory section, it is possible to modify the display directly by using POKEs instead of the usual BASIC commands PRINT, PLOT, and DRAWTO.

If this is news to you, try Program 1 to modify a GRAPHICS 0 screen with POKEs. This program begins by printing the address for the start of the display list as read from both of the registers (see lines 20 through 50). Then the program POKEs numbers from 0 to 255 into successive locations in the display list. All of the alphanumeric and graphics characters appear on the screen. Also, try changing the graphics mode on line 10 (but remove line 40 if the graphics mode is not mixed with a GRAPHICS 0 text window). This program works on any graphics mode, but its effects are different with various modes. At times this graphics technique is better than using PRINT or PLOT and DRAWTO because it is faster, even though it is more difficult.

The program works because the computer keeps the display of characters or graphics points stored as numbers in the reserved display memory. Each number stored there corresponds to a character or some graphics points on the screen. Whenever the computer prints or draws something, it is going into this memory section and changing something (this is what Program 1 did, without using PRINT or DRAWTO). Changing the display list changes the screen because the computer also reads this memory section from start to finish and sends it to the screen 60 times every second.

Controlling Display Memory

The two registers that store the location of the display list tell the computer where to read from or write to the display memory; without them, the computer would not be able to find it. There is a good reason for storing the display address in two locations--this allows sophisticated graphics and animation. Both of the registers act as pointers to the display memory, and they both store its starting address, but one pointer controls where the computer goes to write in the memory, and the other tells the computer where to start reading the information to be displayed. If you remember, the computer must do both operations to put the display on your screen, and it has a pointer for each function.

The pointer controlling all writing to the screen is located at 88 and 89 in the memory, but the second pointer's location depends on your computer's memory size and the graphics mode you are using. See Program 1, line 20, to find out how to locate the pointer; its position is the variable PNTR and PNTR + 1.

Usually the two pointers store the same address, so if the computer prints something on the third line, the information appears on the third line of the screen in exactly the same place as it was written in the display list. But if you change one of the two pointers, when the computer wants to read or write on the display memory and goes to what it thinks is the start of the memory section, it is in the wrong location. As a result, the information appears in the wrong place.

Program 2 demonstrates what happens when you change the pointer controlling where the computer writes into the memory. The program starts by printing the word leftall the way down the left margin of the screen. Then it clears the screen and starts over, but this time it changes the number stored in 88 each time it prints a word. The computer still prints on the left margin (at least it thinks it does!), but the words are stored in the memory offset from their correct positions, so they appear in the wrong places on the screen.

Once the computer is given the wrong starting address, everything it prints afterward will appear in the wrong place. This is because the computer starts at the location specified by the register in 88 and 89 and counts through the memory until it is where it wants to print. If it starts in the wrong place, it winds up in the wrong place, and whatever is printed or drawn is in a different spot on the screen. If you want to prove that the computer is starting in the wrong place, hit BREAK (not SYSTEM RESET). The READY prompt and anything you type will line up at the new margin, and the lines will overlap onto both sides of the screen.

Notice that whatever was written on the screen before location 88 was changed did not move; only the words printed after the change are displaced. Also, it is not always possible to print at the bottom of the screen, and it sometimes becomes impossible to use the PLOT function after the numbers in 88 or 89 have been changed. Since I can find no way to remedy these problems, I see little use for this even though it is an interesting trick.

The other pointer tells the computer where to start readingthe display memory. Changing the address stored here is much more interesting, because it makes the computer start reading in the wrong place, and the entire screen shifts. By controlling how much the pointer changes from its original value, you can make everything on the screen seem to move horizontally or vertically.

Unfortunately, it is not very practical to move the screen vertically because garbage is sometimes displayed. You can see this in Program 3, which changes the pointer to move any graphics mode horizontally. This pointer is stored in a variable because it is placed just before the start of the display memory, and the display memory's location depends on the graphics mode and your computer's memory size.

Moving the Screen

When you try this program, you may notice certain features of the moving screen. First, in any of the mixed graphics modes, the text window of GRAPHICS 0 at the bottom of the screen remains stationary as the rest of the screen moves. In GRAPHICS 8 and 8 + 16, only the top half of the screen moves while the bottom is at rest. Also, the screen jumps each time the loop is reexecuted, and as the program runs through the loop, part of the screen fills with apparently random data (garbage). Last of all, the edge of the screen that moves out of view horizontally reappears on the other side of the screen.

The text window of GRAPHICS 0 in the mixed graphics modes does not move because it has its own pointer to control the start of its display memory. This is also true for the bottom half of a GRAPHICS 8 or 8 + 16 display. Check Table 1 to find where to POKE to move the bottom half of GRAPHICS 8 and the text window for each of the mixed graphics modes.

There is an advantage to this added complexity. Not only can you move part of the screen and leave the rest still, but you can also move the different parts in different directions or at different rates. In GRAPHICS 8 you can actually move all three parts at different speeds at the same time.

That cures the problem of unmoving parts of the screen, but there are still more problems. When the program finishes its loop and starts over again, there is a large and noticeable jump on the screen. Also, there are unusual problems with the top of the screen; unwanted garbage occasionally appears or part of the display disappears off the top. This is particularly noticeable in GRAPHICS 0 through 2, which are text modes. Strange characters can appear, and if you erase them the display goes haywire.

You can reduce the jump in the screen each time the loop is run. Change the loop in line 70 to match what is in Table 2 for the particular graphics mode. This also remedies the occasional appearance of mysterious characters at the top of the screen. Unfortunately, this means that the top line will periodically disappear and reappear. You could leave it blank to keep this unnoticed.

Still, the method is satisfactory for the higher resolution graphics modes where the screen "bumps" are less obvious. And by carefully adapting the loop, you might find a decent compromise.

Try the programs included with this article, and experiment with different graphics modes to get an idea of the possibilities and limitations of these unusual features.

Table 1. Where to POKE to Move Parts of the Screen
To Move GR.0
Text Window in:


POKE into PNTR - 4 +

26 or 27
16 or l7
26 or 27
46 or 47
46 or 47
86 or 87
86 or 87
168 or 169
To move lower part of GR.8, POKE into PNTR - 4 + 100 or 101.

Table 2. Smoothing the Horizontal Motion of the Screen

Change Line 70 to

X TO X + 39
X TO X + 19
X TO X + 19
X TO X + 9
X TO X + 9
X TO X + 19
X TO X + 19
X TO X + 39
X TO X + 39

Program 1. Display Using POKE

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

Program 2. Changing the Pointer to Screen Memory

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

Program 3. Moving Horizontally

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

Return to Table of Contents | Previous Section | Next Section