LASERBASE PROGRAM BREAKDOWN If you wish to customize LaserBase!, go right ahead. The code was written with MADMAC and Tempus, a dynamite programming pair. MADMAC is a very fast 68000 assembler produced for internal use at Atari. Unfortunately, MADMAC is not yet available to the general public, but other than macro calls I've presented no special tricks here, and have attempted to keep the source code as "cleanly 68000" as I can. To modify the code for use with a different assembler, all you need to do is read the source code into a text editor, make any small global changes for syntax, and resave the file. My program text editor is called Tempus, and is a blindingly fast point-and-click style of editor. Starting at the top, we first find a block of lines which describe the title to the program, the copyright and the name of yours truly. Next, we include separate files for program equates and various macro functions. The very first macro encountered describes the proper routine for initializing a TOS application. This is because whenever TOS starts up an application, that particular application "owns" all of RAM memory, and this small macro will determine the size of the program, add in the needed size for any buffers and arrays in the block storage section of the program, and then release the rest of memory, which is not needed now, back to the operating system. We then fall right into the main game loop, which in this case will initialize this application, perform the save the cities subroutine, and then terminate properly, causing the game to return to the desktop. Initialize In this section of the program we assign values to variables whose space was saved either earlier, or down in the block storage section of the program. For example, variables such as the missile arrays are precalculated and stored safely out of the way. These arrays will later be accessed by indexed instructions. In this section we also get to find out what resolution we're operating in, and adjust screen parameters accordingly. Some of the most important sections are here. Notice that, although we saved space for the pre-entered screen data below, we must still save space for a new screen buffer and transfer screen information inside that buffer. Why? Well, although we can pre-insert picture information inside this program, we can't tell beforehand exactly where in memory it's going to live, and the ST demands that its video memory begin on an even "page" boundry, which just means that its address (in hexadecimal) must have zeros as the lowest two digits. To figure this, we first save 32K as a buffer space for our picture. Now somewhere inside that buffer, towards the start of it, is an even page boundry. Our picture is exactly 32000 bytes long, so we have nearly 700 bytes for slop on either end. To actually find the even page number, first get the address of the buffer itself. We then Boolean AND this value with the value $ffffff00, which will force the lowest two digits to be zero. Now there's our page boundry, but it may have fallen just short of the address of the buffer itself, so we add 256 to it, which will keep the buffer page boundry intact, and will advance the image somewhere inside the picture buffer. Once we've transformed the screens, we need to place the cities down in the proper places, equip them with lasers, reset the background, and then we're ready to blast those suckers right out of the sky. Save the Cities Here's where the main game play comes in. After some initial fiddling around, we fall into the REPEAT loop where we first advance any missile in flight, and then check to see if they've reached their targets. If they have, then destroy whatever they touched, and if the cities have all been destroyed, the game is over. Otherwise, we then check the left mouse button. If it's pressed, the computer will select the last known base you touched, and start firing lasers targeted at the point the crosshairs were when you pressed the button. For example, if you were leading the incoming missile by a small amount, and pressed the left-hand mouse button, you would launch a laser beam at the point your cursor was. The idea here is to lead the incoming missiles by a small amount so that the laser you fire may have time to reach the predicted intersection, where it will then evaporate anything that touches its beam. The last subroutine check is made to see if the mouse pointer is currently anywhere inside any one of the rectangles which encompass each of the four possible defense cities. This is how you select which city is currently firing. A simple, quick pass of the mouse is all that's needed, and the computer will acknowledge your selection with a piercing shriek whenever it determines you are pointing at a particular city onscreen. Another way to see quickly which city has been selected is to examine the second number from the left along the bottom of the screen, which always reflects the current city number. Select City This is the subroutine described in the earlier paragraph. Here we actually grab the mouse's position and compare it to the rectangle which encompasses each enabled city onscreen. When the mouse has been determined to actually be inside one of the descriptor rectangles, the machine will emit a shriek, acknowledging you have changed defense postions. Indeed, this is where the difficulty emerges. When each incoming missile has been determined to have reached its goal, it explodes. How can you stop it before it does that? Well, when the laser is fired, the position of the mouse pointer is noted and saved. This position then becomes the final target position. If it coincides with the incoming missile position, a hit is scored. Each missile can withstand a number of direct hits before it overloads and blows up. The harder the difficulty level, the greater the number of hits needed to detonate the incoming warhead.