MOVING PLAYERS IN BASIC

16K cassette or disk


by Tom Hudson


Just before issue #9 of A.N.A.L.O.G. went to press, I was handed a letter from Long Mai of Salt Lake City, Utah (see the Reader Comment section of this issue). Like many BASIC programmers, he was frustrated by BASIC's snail-like pace, and asked for a machine-language subroutine that could be used with BASIC to move player-missile graphics around on the screen.

Unfortunately, it was too late to write such an article for issue #9, but here it is, along with fully documented assembly-language code.

THE PROBLEM

Player-missile graphics are one of the most powerful graphic features of the ATARI 400/800 computer systems. Unlike traditional graphics, players and missiles can be moved around on the screen without disturbing the existing display.

In order to use players and missiles, one must first reserve a portion of memory. Once this is done, the user can begin designing and displaying the players and missiles.

The problems begin when the user wants to move a player or missile around on the screen. Horizontal movement is done easily. A POKE to the appropriate horizontal position memory location will move the desired player to any horizontal location on the screen. If the user wants to move a player or missile vertically, he or she must copy the P/M bit image to another location in memory. BASIC is too slow to do this, but it can call a machine-language subroutine to do the "dirty work."

THE PROGRAM

The BASIC program listed here will allow the user move any player around on the screen. It calls the P/M movement subroutine, shown in the Assembly language listing.

As listed, the program will move a shape around the screen at random. The shape of the player is red as a series of bytes in the string "P0$". By altering the data in line 420, you can change the shape that appears on the screen. There are currently 7 bytes in line 420, but this can be changed by altering lines 130, 290 and 420.

Lines 110-180 set up the subroutine and turn on the P/M graphics. Lines 220-310 are for demonstration purposes only. You can put your ram code in this section.

Line 110 - Loads the string PMMOV$ with the P/M movement subroutine.

Line 130 - Places the data that defines the graphics shape into the string P0$.

Line 140 - Tell the system where the P/M memory starts.

Line 150 - Saves the P/M base address.

Line 160 - Saves the graphics data string address.

Line 170 - Turns on P/M direct memory access.

Line 180 - Sets the color of player 0 to light blue.

Line 220 - initialize the X and Y coordinates of the player.

Line 230-280 - Alter the X and Y coordinates to move the player.

Line 290 - This USR call moves the player to the, desired X and Y location. This statement has 7 parameters inside the USR parentheses:

 

A=U5R(MOVE,0,PMB,PMD,X,Y,7)

"MOVE" is set up in line 110. Do not change this variable. It is the address of the P/M mover subroutine.

"0" means that we want to move player zero. This value can range from 0 to 3, moving players 0 through 3.

"PMB" is the P/M base address. Do not change this value.

"PMD" is the address of the string that holds the player image data. This should be set to the address of the string you are using to hold your player shape data. If your player shape data is in a string called "PL$," you could replace "PMD" with "ADR(PL$)".

An "X" and "Y" are the horizontal and vertical coordinates when you want to place your player. X ranges from 0-255, and Y ranges from 0-127.

"7" in this case indicates that our player is 7 bytes long (see line 130 and the player image data in line 420). If your player is 10 bytes long, place a "10" here.

SUMMARY

This program should help out anyone who wants to use player-missile graphics from BASIC. If there are any questions, write me care of A.N.A.L.O.G. (please include a pre-addressed, stamped envelope). If there is a specific application you would like to see appear in a future issue, just ask. You never know there may be hundreds of other readers who would like the same information.