Click Here To Go To The Your Computer Archive



Written By John Senaghan


Cover Art
Click Here To Enlarge Loading Screen

Loading Screen
Click Here To Enlarge Opening Screen

Opening Screen
Click Here To Enlarge Screenshot

Game Screenshot

Sprite Programming

John Lenaghan produces a sprite command for the BBC

Many microcomputers now on the market have a sprite graphics routine built into the MOS. The BBC Micro, unfortunately, does not, and trying to write your own using the VDU drivers tends to be slow. The sprite animation program given here will allow you to easily define and move a sprite around on a high-resolution screen by Poking data directly into screen RAM.

The definer program, program 1, will only give data for Mode 2 and therefore, is restricted to the Model B. Type in the program and run it.

The program is a series of procedures called up from a menu. Option 3 should be chosen initially. Numbers corresponding to the logical colour number in Mode 2 should be typed into the appropriate position. The cursor is moved around with the cursor control keys. Up to 16 colours can be used and the sprite is made up of 12 by 16 pixels. When you are happy with the defined characters, record the data, read from left to right for the next program.

To light up any byte on the screen in Mode 2, use the expression:

address = HIMEM + 8 * X% + 640 * (Y% DIV 8) + Y% MOD 8

where X% and Y% have values in the range 0 to 79, and 0 to 255, respectively. X% and Y% equal to 79 and 255 respectively, corresponds to the bottom right hand edge of the screen.

Sprite Is Called Up

Program 2 will demonstrate this by filling a block of yellow anywhere on the screen, 12 pixels wide and 16 pixels high. When I translated program 2 into assembly language, it took between 1 and 2 hundredths of a second for a single call. Program 3 is my attempt to speed it up.

Program 3 uses the fact that the difference in address between the top byte of a text character is 633 greater than the address of the bottom byte of the character above. This is tested for in line 120. The assembly listing for this program is shown in program 4.

A space must be set aside in memory for your data. This has to be done for each set of data bytes and is read into a byte array with the pling operator.

The sprite is now called up from your own program will CALL statement with three parameters.

CALL sprite,X%,Y%,char%

Char% is the name of the character you want to move and X% and Y% is its new position. As the sprite has been EOR to the screen it can be erased by a further:

CALL sprite,X%,Y%,char%

without erasing the background. X% and Y% can be replaced by any upper or lower case integer variable.

Program Renumbered

The program has been renumbered from 1,000 in steps of 10. This allows you 1,000 lines for your own program to sit below it in memory.

I would strongly advise anyone saving the program before trying to run it as any mistake at this stage could easily result in a "Bad Program" error.

Page 403 of the User Guide explains how to merge your program with the sprite program.

&70 - X%
&71 - Y%
&72 )
&73 ) - X% * 8
&74 - X% + 6
&75 - Y% MOD 8
&76 - (7 - Y% MOD 8)
&77 - (15 - Y% MOD 8)
&78
&79 - Y% DIV 8 * 128
&7A
&7B - Y% DIV 8 * 512
&7C - counter
&7D - addresslow
&7E - pointer
&80 - pointer + 1
&81 - temp
&82 - temp + 1
&83 - byte