Blockbreaker

by Dave Hitchens

 

Issue 20

Mar/Apr 86

Next Article >>

<< Prev Article

 

 

BLOCKBREAKER will run on any Atari 400/800/XL/XE with a minimum of 32k RAM. A paddle will be required plugged into jack 1. The Level 1 playfield appears after about one minute of initialisation. Please note - when RUNning BLOCKBREAKER you should start out with clear RAM. If you have just switched on your machine and loaded in the program all will be well (proving you have typed the program correctly!). Otherwise make sure that you have SAVEd or CSAVEd a copy of the program and then type POKE 580,1 in direct mode and hit RETURN then RESET before loading. This process clears RAM in the same manner as switching off and on does but is kinder to the machine.

THE GAME

Blockbreaker is based on one of the classic computer games in which you have to demolish a wall of bricks using a fast moving ball directed by your paddle. Simple in concept, the game can nevertheless become very addictive (and not a little frustrating) as you strive to keep the ball in play to beat the current high score. Two types of brick will be noted 'normal' and 'special', the latter identifiable by pulsing colours. Both types have a points value dependant on their position in the wall. Unlike the normal bricks however, hitting one of the 'specials' will give you additional points as displayed on the bonus counter top right and also initiate a stacking routine transferring them out of the playfield area.

STACKING: During this manoeuvre, attempt to strike any, remaining special bricks because, in this phase, such hits continue to award the player with bonus points but the bricks themselves remain intact. Since the bonus counter resets each time the ball hits a special brick, BIG points can be amassed using skilful paddle control. As the game progresses a stack of bricks will be formed on the left. Losing a ball during play forfeits a part of this stack. Once the whole wall has been demolished each stacked brick becomes worth 300 additional points. An extra ball is then awarded (up to a maximum reserve of 9) after which the next level commences. There are 8 levels in all. Should you succeed in clearing level 8 (no mean feat), levels 5 to 8 will repeat.

BALL MOTION: The ball has two possible speeds selected automatically during game play and is served by pressing the trigger. In the slow phase only two angles of bounce are possible but during the fast phase, shallow bounce angles will result if the ball is struck closer to the centre of the paddle. These angles will be required in order to gain maximum benefit from the special brick scoring routine and in order to complete a level.

RESTARTING: When you have lost all reserve balls the high score is updated, a good target being in the tens of thousands. Press the START key to begin a new game.

TECHNICAL NOTES

Those of you who just want to play the game do not need to read on but if you are interested how the program works I, have provided some notes on various parts of the program.

Except for the initialising period following loading, together with a brief inter-level sequence, the program runs entirely in machine language. A combination of mainline code with vertical blank and display list interrupts is used. The use of interrupt code results in smooth motion (since graphics objects are moved while the screen is blanked out), the ability to use 4 channel sound independently of other operations and the use of multiple colours.

The mainline code looks after the service initialisation for each ball, updates display features and scoring and takes care of 'normal' brick routines. The VBI is responsible for moving paddle, ball and 'special' bricks during the stacking routine. It also checks for collisions between ball and other playfield objects, monitors sound values and scrolls the high score copyright message. Twenty two DLI's are incorporated to impart a unique colour to each row of bricks. In this manner up to 40 colours can be displayed on the screen simultaneously. Additionally, the colours themselves are randomised for each new wall.

SOUND: All sound is processed in a vertical blank interrupt. Because the VBI operates independently of the mainline program in a precisely timed manner it is ideal for such use. Blockbreaker's sound is simple but effective - an example is given in Listing 2. Because our VBI operates 50 times per second, each sound pulse requires several passes. In the example given (ball hitting bat), 7 passes are required. Flag1is the master flag which restarts the routine each time the collision register is set. It does this regardless of whether the routine is currently active from a previous strike or is off. Flag2 simply bypasses the routine if no sound is required. Location 53768 is very important for sound production although few programmers appear to take advantage of it. The insistent beat heard during initialisation owes its effect to this register. As a demonstration try replacing the '7' in line 310 with a default of '0'. The smoothly descending high pitched note of the falling brick is a result of clocking one sound channel with a much higher frequency to that normally used - location 53768 again.

MOTION: All performed in the VBI in order to achieve smoothness. 'Players' are used to represent ball, bat and falling brick, the latter effect produced as follows. Once the VBI has detected a collision between ball and playfield register 2 (a 'special' brick), the struck brick is replaced by Player 1, the playfield brick image is blanked out and motion of the Player commences. Its image is replaced by a playfield image once the brick has been 'stacked' thereby releasing the sprite for further use. When combining playfield graphics with PMG in this manner reference tables should be kept of related positional values (lines 1530, 1540) - see Listing 3.

THE BALL: Variables (in the sense of memory locations) are used to keep track of the ball and bat X/Y coordinates. Once a collision has been registered, the X coordinate of the left edge of the bat is subtracted from the ball's X position to give a value between 0 and 11. This value is used as an index to two Page 6 tables (lines 1500-1520). The first table determines the ball's reflected angle, a '1' informing the VBI to move the image one 'pixel' both horizontally and vertically on each pass - in other words at 45 degrees. The central table locations are poked with a '2' during play showing we require movement of two pixels vertically on each pass to everyone horizontally - that is to say, at a steeper angle. Table 2's value is simply added to the ball's X coordinate so as to move it left or right (adding 255 to the byte being equivalent to subtracting 1). The ball's speed is obtained by simply cycling the above routine once or twice during each VBI pass.

COLOURS: The vertically structured form of the Blockbreaker display is ideal for multiple colour generation by Display List Interrupts. Each DLI (there are 22 of them) selects two colours from tables sited in page 6 of memory. The first colour is POKEd straight into register 53271 and affects the 'normal' bricks. The second colour is incremented by 16 on each DLI pass before POKEing into 53272, the register used for the 'special' bricks, to give the pulsing effect. These two registers correspond to the more commonly used shadow registers at 709 and 710 but when using DLI's we must POKE directly to the GTIA chip. Although 22 DLI'S are operating, because they each perform a similar task, only one master routine is required (see lines 1023 -1025). All we require is a counter which is incremented in each DLI and which is then used as an index to the colour tables. Since we have a VBI operating we use this to reset our counter to 0 in preparation for the next image. In addition the colour tables are refreshed by the VBI for each new level.

SCROLLING: The information line is scrolled conventionally using register 54276 and the VBI. After a game ends, the score/hiscore values are compared digit by digit using offsets from the start of the screen memory/scrolling memory. The latter resides in the unused area set aside for PMG (lines 1006-1008). Hiscore is updated when required, by the mainline code which also sets a flag (1680) to allow BASIC to perform its little routine of message selection (lines 155,25,400-401). Scrolling continues throughout a game - you don't see the message during play because the routine's memory pointer is reset to a clear area of RAM by a single BASIC poke.

MEMORY MANAGEMENT: Line 1000 sets aside wodges of RAM for Player Missiles Graphics, the redefined character set, the vertical blank code and the mainline code - all these reside in the upper reaches of RAM just beneath RAMTOP and safe from the clutches of BASIC. The unused section of PMG is utilised for the scrolling routine (including the latter's unique VBI - lines 1026-1029), the new display list (lines 1010-1022) and the DLI routine (1023-1025). Most of page 6 contains variables and tables used by the machine code. BASIC has little work to perform once initialisation is complete but its speed is optimised by compacting its code and running the loop (lines 100-585) near the start of the program.

SCREEN PRINTING: Since Blockbreaker requires regular attention to the screen display, a machine code PRINTing routine is incorporated into the mainline code. This sets the cursor to the required location (see listing 3 for example), organises IOCB #6 and then JSR's to CIOV itself. The 6502's Y register temporarily holds the character to be printed (we could use the stack via PHA) and this is transferred to the accumulator in the PRINT routine as required by CIO. See Listing 4.

Listing 1

top