TRICKS OF THE TRADE
Game Programming
Programming a computer is often more challenging and enjoyable than playing arcade games. This series of articles will describe useful programming techniques for would-be game programmers.
BASIC programming is often not adequate for the game designer. Movements are jerky, action is slow, and play quality suffers. Machine language routines are often the only thing needed to turn a common graphic effect into an eyecatcher. Through this series of articles I will demonstrate the usefulness of such routines. You may copy, improve and use these routines in your own game programming.
I recommend that machine language routines be put into the Vertical Blank Interrupt (VBI). This is that time when the electron beam tracing the TV image returns to the upper left of the screen ready to trace the next image. VBI occurs 60 times per second. This interval is ideal to update counters, move images, generate sounds and change colors. The ATARI operating system allows the programmer easy access to the VBI. The following game illustrates the use of VBI as well as Player/Missiles.
The horizontal screen position of a Player is controlled by one location. In our game the horizontal position of players (baseballs) is updated during VBI. The routine is linked to BASIC through Page Zero locations as follows:
00CE (206)-Horizontal Pos. player 0
00CF (207)-Horizontal Pos. player 1
00D0 (208)-Movement flag player 0
00D1 (209)-Movement flag player 1
In the VBI routine of listing 2 the first six instructions (called by A = USR(1536)) adds our VBI routine on the end of the normal operating system VBI. After this occurs our code is executed every 1/60 second. During these interrupts the movement flags are checked and the corresponding increments or decrements are made. For faster movements use double or triple increments.
P/M graphics area is placed on a 2K boundary (single line resolution), 16 pages down from the top of memory. Ball image data is just poked in the proper player area. There is no vertical movement involved. The balls disappear when their color is changed to background color.
Flags are used as switches or indicators of program state. An example is line 650 which checks the horizontal position of ball 1. If it has reached the window and hasn't before then the crash sequence at line 1000 is initiated and flag CRASH1 is set so it won't occur again. According to line 690 the main loop will continue as long as one of the balls is moving or one hasn't started moving.
After the scores are updated the program returns for another round. An easy way to clear the screen is to execute a graphics command but this disrupts Player/ Missiles. To remedy this set GRACTL (53277) back to 0 and reset some of the CTIA registers as in line 540, then reinitialize P/M graphics.
Changing the text area in split-screen mode is a more appealing display. Lines 560-562 convert the text area to a graphics 2 mode and a graphics 1 mode. Note the row and column pokes in line 564. I find its best to poke the row and column every time. Row zero covers two lines because BASIC thinks the text area is in graphics 0.
Crash-Tinkle-Tinkle was written to illustrate the simple VBI routine. The game itself is quite contrived. Two players each control a baseball as it flies towards a window. The object is to stop the baseball as close to the window as possible without breaking it. To make it more difficult the baseball disappears on its way. Only the closest ball wins points and no points are awarded for a broken window. As described the game has many faults. Baseballs don't become invisible and a glove would be a better target than a window. Better yet stopping a runaway stage coach before it plunges off a cliff would be more exciting. Additional design flaws are that the game rewards failure and the best graphics display occurs if you fail to stop the ball. Also it is not easy to see how close you are to your final goal.
Though the game is not great it does serve to illustrate some good techniques. The use of VBIs in action games is almost mandatory. Use this game as a spring board to better games and programming practices. In future columns I hope to demonstrate more elaborate routines and more exciting possibilities.
01 ; 10 ; Listing #2 20 ; by Stan Ockers 30 ; for ANTIC The ATARI Resource 40 ; a Vertical Blank Interrupt routine 50 ; call from BASIC A=USR(1536) 60 ; 70 *= $600 ; page six location 80 PLA ; ignore parameter count 90 LDY #$0A ; lo-byte VBI routine 0100 LDX #$06 ; hi-byte VBI routine 0110 LDA #07 ; deferred VBI 0120 JMP $E45C ; O.S. inserts VBI 0130 VBI LDA #00 ; zero ? 0140 CMP $D0 ; move flag plyr 0 0150 BEQ SKP ; forget plyr 0 0160 INC $CE ; one space right 0170 LDX $CE ; update 0180 STX $D000 ; horiz pos. plyr 0 0190 SKP CMP $D1 ; mov flag 1 0 ? 0200 BEQ OUT ; yes forget p1yr 1 0210 DEC $CF ; one space left 0220 LDX $CF ; update 0230 STX $D001 ; horiz pos. plyr I 0240 OUT JMP $E462 ; VBI exit thru O.S.
Listing 1: Not available
Listing 2: VBICALL.SRC Download / View