ON DISK!
ASSEMBLED SAUCERS
by Walt Wakefield
Atari ST assembly language gives you fast and powerful access to the ST's graphics and sound abilities, but unraveling its mysteries can be frustrating. In keeping with this issue's theme of graphic arts, START brings you a colorful and musical graphics demo--complete with assembly source code--to show you one way to tap into that power and develop your own programming potential.
Unidentified Flying Objects on Your ST. File SAUCERS.ARC on your START disk. Color monitor required.
|
|||
|
|||
|
Four flying saucers, each a different color, maneuver above the surface of an unnamed planet. The spaceships change directions abruptly as they pass over, around and between a foreground hill and spire. A scene from a new video game? No, it's Assembled Saucers, and if you've ever wanted to program great ST graphics, this assembly language demo will get you started.
I wrote Assembled Saucers as an experiment in assembly language programming. The experiment produced, in about the same disk space as a standard NEOchrome or DEGAS file, a "motion picture" complete with background music.
To run Assembled Saucers, copy the files SAUCERS.ARC and ARCX.TTP onto a blank, formatted disk. Un-ARC SAUCERS.ARC following the Disk Instructions elsewhere in this issue. At the Desktop, double-click on SAUCERS.PRG to start the demo (the file SAUCERS.DAT must be in the same directory). Press the Escape key to exit the demo. Assembled Saucers will run in low or medium resolution. The converted Alcyon AS68 source code is in the file SAUCERS.S.
Action the Hard Way
The ST's four low-resolution color planes provide an easy way to move images around. You can draw an object, erase it and redraw it anywhere on the screen without disturbing other images in other planes. There's a drawback, though. Devoting a plane exclusively to a moving object cuts the number of available colors in half. Giving each of four spaceships its own plane would leave no colors for the landscape.
I had plans for all 16 colors, so Assembled Saucers accomplishes movement the hard way. Before placing a saucer, the program saves a saucer-sized patch of background by copying it from screen memory to a buffer. When the spacecraft is to be moved, the saved patch is restored to the screen, wiping out the saucer. Then background is saved in a new location and the craft is placed there.
A key feature of the program is that the saucers move in three dimensions. In addition to horizontal and vertical movements, their front-to-rear positions relative to one another and to the hill and spire change from time to time. On each pass through the program's main loop, there is one chance in 16 that a given saucer will attempt to trade positions with an object just in front of or just behind it. If the two images overlap, the swap is not permitted.
NEOchrome Artwork
The saucers, spire, foreground hill and distant hills were created as elements of a NE0chrome picture (Figure 1), then saved as separate data segments in the file SAUCERS.DAT.
The demo program transfers the distant hills (lower portion of Figure 1) directly from disk to screen memory and stores the other images (Figure 2) in a buffer. It then sprinkles stars at random across the sky, places the moon in a random position in the upper left, adds the hill and spire to the on-screen landscape and starts the music. After a preliminary background-save at each saucer's initial location, the action begins.
The main-loop sequence goes like this: 1. Select a new destination (random screen coordinates) and horizontal speed (one or two pixels per move) for any saucer that has reached its previous goal; 2. Restore saved backgrounds, beginning with the nearest saucer; 3. Perhaps change the front-to-rear positions of two or more objects; 4. Move the saucers, beginning with the most distant. The new background is saved as part of the move routine; in addition, if the saucer is behind the hill or spire, a section of the appropriate landscape is redrawn on top of it.
The program uses two blocks of screen memory. All changes are made on the hidden screen. Then the program swaps screens and updates the newly hidden one by copying the revised picture to it. (I deliberately limited myself to two screens. Adding a third screen containing the picture without saucers would eliminate the need to save and restore background patches. This "clear" picture would be transferred to the hidden screen prior to each redrawing of the saucers. This shortens the program only slightly however, and makes little difference in execution speed.)
Do-It-Yourself Music
The background music is the result of another experiment, this one in "do-it-yourself" sound control. A vertical blank interrupt routine keeps time and reads specially formatted music data. Whenever a change in pitch or volume is called for, the routine revises a master sound table and passes its address to the ST's sound chip.
With this system, three notes can be started simultaneously, with one alternately rising and falling in volume while another turns on and off intermittently and the third comes on strong, then fades away like a bell sound. On an electronic organ, these three effects are called vibrato, pizzicato and sustain.
Every 1/60 of a second, the vertical blank routine adjusts the volumes of individual voices according to defined patterns. At any point in the music data, a voice can be reprogrammed to follow a different pattern or to maintain a steady volume.
An infinite variety of patterns is possible. Assembled Saucers includes five: vibrato, pizzicato, and short, medium and long sustain.
The program includes 40 bars of music data. The music repeats every 64 seconds as the flying saucers perform their unpredictable maneuvers.
Wrap-Up
I hope my little experiment was helpful. Assembly language isn't easy to learn, but its speed and efficiency are the key to faster and more powerful programs. It is also the best way to take full advantage of the ST graphics and sound capabilities. And before long you'll be producing your own game masterpiece.
Walt Wakefield is freelance writer and software developer in Portland, Oregon. A former newspaperman and public relations counselor, he is the author of Home Casino Poker Etc., an ST game published by Dubl Dubl Funware.