Classic Computer Magazine Archive COMPUTE! ISSUE 124 / DECEMBER 1990 / PAGE G-14

BEGINNER BASIC
BOOST YOUR FUN WITH MULTIPLE SPRITES

LARRY COTTON

Happy holidays! In the past few months, we sharpened our BASIC skills with a program that demonstrated how to create and control a sprite, or Movable Object Block. The 64 is not restricted to a single sprite, however; it can simultaneously maneuver up to eight sprites in BASIC.

When dealing with more than one sprite, things get a bit more complicated. Before we actually create some sprites in shapes that are appropriate for the season, here's what we have to do:

  • Create shape data for the sprites.
  • Tell the computer where to look for the data.
  • Locate the sprites horizontally and vertically.
  • Determine their sizes.
  • Assign them one or more colors.
  • Turn them on.

Last month's program contained 63 pieces of data which defined our single sprite's shape. For each additional sprite shape, 63 more pieces of data are required to be POKEd into memory registers.

In addition, you must tell the computer where to look for the data. Memory registers 2040–2047 are the eight sprite data pointers; they tell the computer in which memory registers the sprite shape data can be found.

When we located sprite 0's shape-defining data from 12288 to 12350, we POKEd 2040 with 192. The sprite data pointers and their corresponding data locations are detailed below.

Sprite Data Pointer Value Data At
0 2040 192 12288–12350
1 2041 193 12352–12414
2 2042 194 12416–12478
3 2043 195 12480–12542
4 2044 196 12544–12606
5 2045 197 12608–12670
6 2046 198 12672–12734
7 2047 199 12736–12798

Each sprite doesn't need unique data; one may share the data of another. If you want, say, sprite 7 to have the same shape as sprite 0, you would POKE 2047 with 192.

When you're working with three sprites or fewer, there are other popular locations in which to put sprite shape data. When you use them, the same pointers are used, but different values are POKEd there.

Sprite Data Pointer Value Data At
0 2040 13 832–894
1 2041 14 896–958
2 2042 15 960–1022

This month we'll begin a short program for the 64 that should give you an understanding of how to handle more than one sprite. Be sure to save lines 10–90 because we'll add to them next month. First clear the screen and color the screen white:

10 PRINTCHR$(147) : POKE53280, 1 : POKE53281, 1

Next, because we'll use sound with our sprites (since the 64 is so musically gifted, I almost always include sound in my programs), we must clear the sound-producing chip and set the maximum volume, envelope, and a frequency for voice 3. These have been discussed in previous columns.

20 FOR T = 54272 TO 54295 : POKE T, 0 : NEXT : POKE 54296, 15
30 POKE 54277, 8 : POKE 54278,255 : POKE54287, 3

Read in the sprite shape data:

40 FOR J = 12288 TO 12350 : READ D : POKE J, D : NEXT
50 DATA 0, 16, 0, 0, 0, 0, 0, 16, 0, 0, 56, 0, 0, 124, 0, 0,
       254, 0, 0, 56, 0, 0, 124, 0, 0, 254, 0, , 255
60 DATA 0, 3, 255, 128, 0, 254, 0, 1, 255, 0, 3, 255, 128,
       7, 255, 192, 15, 255, 224, 0, 56, 0, , 56
70 DATA 0, 0, 254, 0, 0, 0, 0, 0, 0, 0

Because we're using only one sprite shape (I won't tell you what it is yet), we can point all eight data pointers to the same data (from 12288 to 12350).

80 FOR T = 2040 TO 2047 : POKE T, 192 : NEXT

Define constants:

90 V = 53248 : X = 157 : Y = 129 : K = 255 : V1 = 54276 : VF = 54273 : M = 79

V is the important first memory register of the 64's sprite-controlling chip. Many other registers will be addressed as an offset of V. X and Y are the starting horizontal and vertical coordinates for all eight sprites. V1 and VF are voice 1 's control and high-frequency registers, respectively.

We'll stop here for this month. Next month I'll explain M and K and finish the program.

Now, you may recall that way back in March I challenged you to send me some examples of programs that use NOT. Thinking that the mail-box wouldn't yield many responses, I shrugged off NOT as a keyword of minimal interest.

I was wrong. Apparently, there are those of you who actually use NOT in your BASIC programming. Several people wrote to explain how they use the NOT statement in various ways. Thanks for the feedback, which I always welcome.

Walt Schumacher, a computer teacher at St. Ferdinand School in Florissant, Missouri, sent in perhaps the clearest and best documented use of the NOT logical operator. He writes:

"My use of NOT stems from seeing its real-world analogy: the ON/ OFF push button. To utilize this function, one must be aware that on Commodore machines, 0 stands for false, and – 1 stands for true. I used this feature recently to toggle between upper- and lowercase for a keyboard practice program."

Here's a slightly revised version of Walt's program.

10 BIG = 0 : CASE = 53272 : UP = 21 : DOWN = 23
20 PRINT CHR$(147)
30 FOR T = 1 TO 11 : PRINT : NEXT
40 PRINT TAB(10)"WATCH THIS MESSAGE!
150 BIG = NOT BIG : REM TOGGLE
160 IF BIG THEN POKE CASE, UP
170 IF NOT BIG THEN POKE CASE, DOWN
180 FOR DELAY = 1 TO 400 : NEXT
190 GOTO 150

Line 10 defines the variable BIG and the constants CASE, UP, and DOWN. In the 64 and 128, memory register 53272 controls, among other things, whether your monitor or TV screen displays upper- or lowercase lettering. POKEing 21 (UP) or 23 (DOWN) to that register determines whether the computer prints in upper- or lowercase, respectively.

Lines 20–40 clear the screen, center the cursor vertically on the screen, and print a message.

Line 150 contains the ON/OFF toggle switch. BIG takes turns having the value 0 or -1. If BIG is 0, for instance, NOT BIG changes it to -1, and vice versa.

Lines 160 and 170 evaluate BIG and alternately POKE 53272 with either 21 or 23. If BIG = 0, the message switches to lowercase; if BIG = -1, the message switches to uppercase. Thanks, Walt, for shedding more light on NOT.