Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 10, NO. 12 / DECEMBER 1984 / PAGE 172

MOBs: Simon's Basic sprites for the C64. John J. Anderson.

It would be tough for you to own a C64 very long without knowing that your machine can generate "sprite." A sprite is a piece of color screen data that can be controlled independently from the "normal" screen display. The screen data can be manipulated to move, change color, and even change shape without the need to recalculate backgrounds. Up to eight simultaneous and independent sprite shapes can be programmed in a relatively straightforward manner. Sprites are MOBs

First of all, let's get one peice of terminology straight. In Simon's Basic, a sprite is not a sprite--it is a MOB: a movable object block. So get the word "sprite" out of your head--it is MOB from here on in.

MOBs don't care whether you display them on hi-res or lo-res screens (although you need to do a bit of extra work to get them to appear on hi-res and multi-res screens). You can display a MOB in any single color in the hi-res mode, and in up to three different colors in the multicolor mode. A hi-res MOB is 24 pixels wide by 21 pixels deep. Remember that in multicolor mode pixels are double width, so multicolor MOBs are 12 dots wide by 21 dots deep.

Before you enthusiasm takes you off the deep end, you should realize that working with MOBs can be tricky. There are many things to keep track of and dozens of ways to trip up.

On the bright side, it is much easier to deal with them from Simon's Basic than it is from plain old Basic. Simon's Basic has many special commands specifically designed to make working with MOBs as simple as possible. There is no comparison between learning to handle MOBs from Simon's Basic and controlling "sprites" the hard way. Design

The purpose of the DESIGN command is to allocate memory space for a MOB. Before you do much else, you must tell the computer what kind of MOBs you are designing, and where they will reside in memory. The format for the DESIGN command is as follows: DESIGN mob-res,address where: mob-res = 0 or 1 address = 2048 - 4095 (in multiples of 64)

The first parameter tells whether you are designing a hi-res or a multi-res MOB. If you specify 0 for this parameter, you are designing a hi-res MOB. If you specify 1, you are designing a multi-res MOB. The second parameter tells the computer where to look in memory to find this specific MOB shape.

Because each MOB uses up 64 bytes of memory, each block of available MOB memory is 64 bytes long. MOB memory starts at memory location 2048, and proceeds from there in blocks of 64. Table 1 shows a MOB memory map.

Things start to get a little sticky now, but try to hang on. There is a block number associated with each block of MOB storage space. In Table 1 we can see that the block numbers start at 32, which is associated with the block that begins at memory location 2048. Block 33 starts at location 2048 + 64, block 34 at 2048 + 64 + 64, and so on. To determine what block number is associated with any given memory location, simply divide the memory location by 64.

Let's answer a quick question probably now occurring in many minds--if only 8 MOBs can be displayed at a time, why designate so much room for MOB addresses?

Well, even though we are limited to displaying eight or fewer MOBs at a time, we may want to define many more than that. Once we do, we can change them on the fly--and this is how we animate MOBs. By switching slightly different MOBs quickly, we can make a shape appear to move: we can make a runner run and a jumper jump. Then when we move the MOBs while fipping between them, we have a bona fide moving picture. That's just one reason that we sometimes keep lots more than eight MOBs defined in memory.

Let's go back to the hard-to-digest MOB rules, which will only become clear through experience with them.

It a MOB is to be used on a hi-res graphics screen, you must add a graphics constant value of 49152 to the screen address figure. When calculating a block number, do not take the 49152 graphics constant into consideration. Merely work the calculation as usual--49152 is a flag that a allows the MOB to appear on a hi-res or multi-res screen. If you forget this when putting a sprite on a hi-res or multi-screen, you'll go nuts trying to figure out why it' not working. The @ Command

The @ command is the header that indicates a MOB design grid is to follow. You will use a design grid to construct MOB shapes. The grid is 24 dots wide when you are designing a hi-res MOB, and 12 dots wide when you are designing a multicolor mob.

Something else important: you should ensure that each line number for the grid is the same length--for example, three digits or four digits. By doing this, you will keep the indentation of points on the grid constant and not encounter problems during the MOB design process.

When you are designing a monochrome MOB in the hi-res mode, the color code character to use when "filling in the blanks" is B. That will be the color assigned in the MOB SET command, which we will learn about just up ahead. So the @ grid for a hi-res MOB might take the form shown in Listing 1.

In this way you can get some idea of what your MOB will look like. The entire process of designing a MOB in Simon's Basic takes place on the @ grid. CMOB

The command CMOB stands for "color MOB" and allows you to define two additional colors that will be used in the designation of a multi-res MOB. The format for the command is very simply CMOB color 1,color 2 where: color 1 = 0 - 15 color 2 = 0 - 15

These two parameters are the two additional colors you desire. The primary MOB color is designated in the MOB SET statement just as it is in hi-res MOB design.

When designing a multi-res MOB on an @ grid, the characters B, C, and D are used. Note that the color assignment codes don't work the way you might expect them to in multi-res: the B character now represents the first parameter of the CMOB command, the C character represents the color assigned in the MOB SET command, and the D character represents color 2 in the CMOB command. So a multicolor @ grid might take the following form in Listing 2. MOS SET

The MOB SET command allows you to set the stage and lift the curtain on a MOB. It performs the initialization process for any designated MOB. The format for the command is MOB SET mob priority, memory block, color, screen priority, resolution where: mob priority = 0-8 memory block = MOB indentifier color = 0-15 screen priority = 0 or 1 resolution = 0 or 1

The parameter priority specifies the number of the MOB you are setting up. This number must be unique for each MOB. The lower the MOB number, the greater its priority over other MOBs. If two or more MOBs are traveling across the screen, the MOB with the lower number passes over the MOB with the higher number.

The second parameter of the MOB SET command, memory block, defines the memory block from which the MOB shape data will be taken. Use the MOB number of the block to fill this parameter. The next parameter, color, defines the main MOB color. As explained above, the main MOB color is assigned to each mob drawn with a B in the hi-res mode or a C in the multi-res mode.

The next parameter, screen priority, specifies the priority of the MOB over screen data it may encounter. Here you indicate whether you wish the MOB to pass over or under other characters or non-MOB shapes on the screen. A 0 in this position gives the MOB priority over screen data, while a 1 gives screen data priority over MOBs.

The last parameter in the MOB SET command, resolution, indicates whether the MOB was created in multicolor or hires mode. A 0 in this position indicates hi-res. A 1 defines multi-res. MOBs in Motion: MMOB

The MMOB command means "move" or "manifest MOB." It allows you to display a MOB at one point on the screen and then, if you wish, move it to another location. The format for the command is MMOB mob number, beg x, beg y, end x, end y, expansion, speed where: mob number = 0-8 beg x = legal x value for MOB size beg y = legal y value for MOB size end x = legal x value for MOB size end y = legal y value for MOB size expansion = 0-3 speed = 1-255

The first parameter, MOB number, specifies the number of the MOB you wish to display and move. Makes sure this number matches the number of the MOB you set in the MOB SET command. The parameters beg x and beg y are the coordinates of the point on the screen where the MOB will be displayed before it is moved. Parameters end x and end y indicate where finally place the MOB after movement. If you do not wish to move a MOB but just want to display it, use the same values for both start and end screen locations.

Expansion refers to the size of the MOB when it is displayed. The expansion numbers and resulting display sizes are shown in Table 2.

The final parameter is speed. This sets the speed of movement of the MOB and can be a number from 1 to 255. A parameter of 1 is the fastest speed, and 255 is the slowest movement speed attainable. RLOCMOB

The command RLOCMOB stands for "relocate MOB," and enables you to move an already displayed MOB to a different location on the screen. Format for the command is much the same as that of MMOB, except the starting position of the MOB is already known: RLOCMOB mob number, end x, end y, expansion, speed

The parameters end x and end y are the screen coordinates of the point to which the MOB will be moved. All other parameters are the same as encountered in the MMOB command. MOB OFF

The command MOB OFF does just that--it turns off display of a MOB. The format for the command is MOB OFF mob number where: mob number = 0-8 The mob number is the number of the MOB you wish to clear from the screen.

By now you probably feel buried under tons of commands, few of which make any immediate sense to you. Well, here are some programs to help you get a grip. Play with them, change them, see what makes them work and what makes them stop working. Design your own MOBs to replace the ones used here. Look at each of the commands, and remind yourself of what each does.

When you get discouraged, take a look at a sprite how-to book working from plain old Basic. Then thank your lucky stars you have Simon's Basic.

The programs in Listings 3 through 7 have been designed not for sophistication of effect, but for ease of understanding. Play with them until you catch on.