Classic Computer Magazine Archive COMPUTE! ISSUE 53 / OCTOBER 1984 / PAGE 149

Multiscreen Atari Animation

D.K. Tichenell

Often when creating computer graphics, it is useful to be able to draw more than one picture at a time using alternate screens. It also helps to be able to flip through the pictures to compare them. This flexible graphics editor lets you use a joystick to draw, and allows you to flip, copy, erase, easily animate portions of a screen, and more—using up to three screens simultaneously.

Of the many remarkable graphics facilities provided by Atari's video chip, ANTIC, the load memory scan feature, is one of the most powerful. Among many other things, it permits screen flipping by allowing the programmer to select the area or areas of memory to be used for screen display.

Screen flipping, the process in which multiple screens are displayed in rapid succession, has been covered fairly thoroughly. But in order to implement this feature easily and to greatest advantage, an editor designed specifically for the purpose is needed. Such an editor should ideally contain a sketchpad utility, and provide special features for coordinating and offsetting images on multiple screens. In addition, the ability to save and reload the completed animation screens, display facilities, and color control is desirable.

The Sketchpad

Select option D (Draw) in the main menu to enter the sketchpad mode where all the plotting is done. It is impractical to implement a cursor in this mode because the cursor would need to be too small. With a cursor of about the size of one pixel, it would be difficult to distinguish between colors. The best solution is to make the cursor a player-missile that changes colors under user control.

As much as possible, input is restricted to the joystick. With just the stick and one button you won't have great input flexibility, but it can be improved considerably. When drawing, each push of the joystick button advances the color register to the next color, cycling through all four, including the background color, then repeating. Keep the button depressed, however, and the cursor may be moved freely and rapidly about the screen without plotting. This permits detailed work, but doesn't make it easy to color large areas. The special XIO 18 fill function is designed for this purpose, but does not lend itself particularly well to this application.

Rather than use it as it was intended, it serves here as a one-dimensional fill function—it simply draws a line from the cursor to the right until it encounters a previously plotted point or wraps around. The second dimension is added by moving the cursor while the fill function is turned on. Large and complex areas can be thus filled by drawing the right border first and turning on FILL before drawing the left side. Having stretched the joystick to its limits, the fill function is activated by pressing the console START switch. It turns off as soon as the joystick button is pressed.

Animation

Some interesting and practical effects can be created using full-screen cyclic animation. One of the easiest and most obvious is the dotted line. The dots seem to flow along in an endless stream and can be used to illustrate the flow of fluid in a piping diagram or the movement of current through an electrical circuit.

Many other figures are also possible though—wheels turning, lights flashing, objects expanding or contracting. To draw several screens separately with the intent of animating them requires a great deal of calculation and time. The desired result is far more easily achieved if you can draw from one screen to another while retaining your relative position on each. That is easily accomplished: Each time the OPTION button is pushed while in (D)raw mode the next screen appears. Draw a line while flipping the screen every few pixels and an animated dotted line appears as if by magic. Other figures require just a little more thought.

Because the dotted line is such a basic device and as its creation is so straightforwardly mechanical, a special feature is included in the editor. If the 1, 2, 3, 4, or 5 key is pressed while in (D)raw mode, the screen will automatically flip after one, two, three, four, or five pixels are plotted. In all cases except the single-pixel option, an overlap of one pixel between the images in the flipping sequence helps to make the motion flow more smoothly. In single-pixel plotting, this is obviously not possible and that case is handled differently. The more pixels drawn between screen changes, the longer the individual dots in the line will be and the more rapidly they will appear to move. This feature is also turned off as soon as the joystick button is pushed or if any other key is pressed.

Summary Of Draw Mode Controls

•The joystick controls cursor motion and the trigger changes color registers. Holding the trigger down permits motion without plotting. Use of the trigger also turns off the fill function or the line animation feature.

•Keyboard keys 1, 2, 3, 4, and 5 turn on the automatic line animator.

•The START console switch turns on the fill function.

•The OPTION console switch flips to the next screen.

•The SELECT console switch exits the draw mode, returning execution to the main menu.

Menu Options

•F—flip screen. This is how to display the final picture. Press any console switch to return.

•C—color selection. It's always difficult to remember the correct SETCOLOR values. After all, with 128 different possible combinations, you can't really be expected to type them in one after another indefinitely. Usually something fairly acceptable is found, and the search stops there. One solution is a color selection menu option which offers you a visible representation of the colors and the SETCOLOR statements. Be sure to plot something on the screen before using it or you won't see anything. In this mode, each color register in turn may be adjusted using the joy­stick—up and down alter the intensity levels, left and right alter the hue. Both wrap around.

In the text window, the present SETCOLOR command is displayed, keeping up with what­ever changes are made with the stick. Pushing the joystick button advances to the next color register, returning to the main menu when all four have been set. So that text will always be readable, the default color values are used in the menu mode. However, whatever values are chosen in the color selection mode will apply in the Draw and Flip modes. They are also saved with the animation screens to disk and will be reset automatically when the file is read back in.

•K—copy page. Copies the contents of screen one onto the other two screens. In build­ing an animated structure, the animated parts may be only a minor part of the picture. The basic framework can be identical on all of the screens, and the copy page option obviates the need to redraw.

•E—erase. Erases screen number one. To erase all screens, use E and then K.

•S—save and R—read are for saving files to, and reading files from, disk. They can be easily altered for use with cassette. The saving and loading of blocks of memory are not directly supported by BASIC, but are clearly required here. Subroutine REDIN contains a short ma­chine language call to an operating system routine.

The only direct BASIC alternative would be PUTting and GETting byte by byte, which takes a long time on a disk and even longer on cas­sette. To convert to cassette, eliminate the filename input in the SAV and REED subroutines and change the OPEN statements to OPEN #2,8,128,"C:" and OPEN #2,4,128,"C:" respec­tively. This method will permit short inter-record gap writing and reading which speeds things up a great deal, but it will still take seven or eight minutes.

The Program

One machine language routine (contained here in the character string M0V$) is used extensively. As its name implies, it moves information from one place to another, with origin, destination, and quantity determined by the arguments received. The parameter list is FROM, TO, and HOWMUCH, where FROM is the address of origin, TO is the address of destination, and HOWMUCH is the number of bytes to be moved.

MOV$ helps speed up a number of otherwise lengthy operations. It moves the screen data from the first screen to the other two in carrying out the copy page command in lines 2220 and 2230. It also clears P/M RAM in line 450, and moves the color and intensity data into the space between screens two and three in line 1115 before saving, and moves it back again in line 1325 after reading a file. The routine UPDOWN$ which moves the PM cursor around is basically the same routine with a few instructions inserted before the RTS. These are PLA, PLA, STA $D000, which allow for the passing and installation of the horizontal cursor coordinate at the same time, thus permitting pure diagonal motion rather than visibly distinct horizontal and vertical motion. The short CALLIO$ routine is PLA, PLA, PLA, TAX, JMP $E456.

Technical Requirements

Graphics mode 7 consumes 3840 bytes, and the minimum number of screens required for animation is three. That's quite a lot of RAM, and the situation is complicated by the fact that the screen RAM may not be allowed to cross a 4K boundary. Three animation screens will occupy about 12K, so I've left it at three, though four or five would be possible if sufficient memory is available.

Screen 1 is in its normal default position at the top of usable memory. Screens 2 and 3 are 4K and 8K further down respectively. This way 4K boundaries are avoided, and the screens may be changed by simply altering the high byte of the LMS operand. Subroutine PAGDRAW rotates through the screens by doing just this. But letting ANTIC know what to look at is not quite enough. The Operating System would still be looking at the last screen and that's where the plotting would take place. So, each change of screen must be communicated both to ANTIC and to the Operating System.

Although the memory of the three screens is not contiguous, they are saved to disk as though they were. This means that the intervening space is saved and retrieved along with them. This method is much simpler than treating the screens separately, and serves another important purpose, as well. By moving the SETCOLOR data from the arrays COL(4) and IN(4) into these interstices before saving the file (and then later retrieving them after the file is read), the color data becomes linked to the screen data where it belongs.

It's interesting that the display list is located by default between screens one and two, where it is saved and retrieved along with the screen files. Under normal circumstances, it is identical, when read in, to the one already in place, but if the amount of memory in the machine that saved the data differs from the one which reads it, ANTIC will get lost, momentarily displaying some peculiar and sometimes fascinating garbage until the operation is complete. It would certainly be possible to put the display list elsewhere, but then ANTIC's pointer would have to be changed with each graphics mode change and that's really not worth the trouble.