Classic Computer Magazine Archive COMPUTE! ISSUE 38 / JULY 1983 / PAGE 239

Atari Laser Gunner II

A Vertical Blank Enhancement

Thomas A. Marshall

The improvements to this previously published game — and the author's explanations of the techniques he used — easily justify a second look at Laser Gunner. This version, Laser Gunner II, mixes machine language and BASIC to make Laser Gunner (originally published in November 1982) an even more exciting game. The enhancements include having both missiles on screen simultaneously and smoothing out the animation, even as missiles are fired.

The concept of Laser Gunner (COMPUTE!, November 1982) is excellent, but anything can be improved. For example, all other motions stop when the missiles are fired. For continuous and smooth motion, the computer could process the missile horizontal positioning during the vertical blank (VB) period.

The VB is the time during which the television's electron beam is turned off while it returns from the lower right corner of the screen to the top left. Depending on the graphics mode and other interrupts, there are approximately 7980 machine cycles available during a single VB. (A machine cycle is the smallest measurement of time on your computer's internal "clock.")

Bringing VB Into The Picture

To utilize the VB, we first have to tell the Operating System (OS) where to go. We do this by performing a Vertical Blank Interrupt (VBI) through the Set Vertical Blank Vector (SETVBV) routine. Before jumping to the SETVBV, we have to load the least significant byte (LSB) in the Y-register and the most significant byte (MSB) in the X-register of our VB machine language routine.

Into the accumulator we can place either a 6 or a 7. Six is for deferred mode; the OS does its housekeeping operations before it executes our code. Seven is for immediate mode; the OS executes our code first during the VB. Since we will be checking the collision registers, we will be loading a 6 into the accumulator. The BASIC program initializes the SETVBV through the USR statement on line 1460. To return control to the OS, we jump back through $E45F.

The BASIC and the machine language (ML) programs interact through several PEEKs and POKEs. The ML program checks the STRIG(0), location $0284, for the press of a button, and moves both missiles horizontally. Since the player/missile graphics are defined in strings, it is easier to have BASIC draw and erase the missiles by PEEKing the flags that the ML program sets.

In the enhanced version, both missiles appear on the screen at the same time. This requires the additional coding located at $06D7. The missiles are defined as

Since it is difficult for Atari BASIC to selectively turn bits off and on, we will use ML to change the bits. The AND instruction is used to set bits to zero (off). ANDing a bit with zero sets the bit to zero. The ORA instruction is used to set bits to one (on). By ORAing a bit with one, we set the bit to one. The flipping of the missile bits is done in the subroutines at lines 1300-1330. The original Laser Gunner BASIC program with the vertical blank enhancements appears below.

All the lines after 1280 are new, and the other major changes are from lines 630 to 735, and from lines 880 to 900. In addition, to speed up the vertical motion of the defender, the vertical step size was increased by two. The changes for this enhancement are in lines 110, 530, 540, 560, 630, 640, and 650.

Further Enhancements

The programming technique of performing graphics movement during the vertical blank enhances Laser Gunner almost to the level of difficulty of professional arcade games. Further program execution speed can be achieved by removing the REMs and moving the part of the program that does most of the action to the beginning. This shortens the memory that BASIC has to search to find line number references. An additional enhancement would be to add a sound routine during the VB each time the trigger is pressed.