home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 229
/
229.d81
/
t.js1
< prev
next >
Wrap
Text File
|
2022-08-26
|
7KB
|
305 lines
u
J O Y S P R I T E
by Dave Moorman
What this country needs is a
good, healthy five cent cigar. Yeah,
that will happen! The next best thing
would be a really powerful
Joystick and Sprite Control Module.
And, lo! and behold, we now have
JoySprite -- which will make
designing sprite-loaded programs
almost easy! No more hunting down
register addresses or doing bit-logic
calculations. Here are the
commands you can use in BASIC to make
sprites do their stuff -- and
MORE!
If you are newish at programming,
you will want to read "Build a
Boot," also in this issue. It uses
JoySprite as an example and shows
how to use a boot program to "move up
the Bottom of BASIC," something
many of us do every time we sit down
to write a program. Also, the
article "Sprites Are Fun" will
explain much about how sprites and
video work on the C-64.
JoySprite runs in the background,
using the Jiffy IRQ. So the first
thing you want to do is turn on the
IRQ driver.
The variable AD here refers to the
Load address of the JOYSPRITE ML file.
IRQ ON
SYS AD
This is fully protected and will
work with other IRQ drivers that are
already running on the computer.
Of course, the last thing to do
in your program is turn it off.
IRQ OFF
SYS AD+03
(After testing, I have found that
a SYS AD+3 at the very beginning of
the program resets everything and
makes JoySprite run better -- DMM)
IRQ drivers should be turned off in
the reverse order of how they were
turned on. JoySpirit saves whatever
location was in the IRQ Vector when
started, and when stopped, replaces
this address.
[SPRITES]
[-------]
If you are using a text screen
other than the default at 1024, you
need to use this next command. The
sprite image pointers are always at
TextScreen + 1016. For bitmap
graphics, the pointers are at
VideoColor + 1016. Use this command to
put the value into the program.
SPRITE POINTER
SYS AD+06 , LOC (2040 DEFAULT)
(If you are using the default text
screen, this command is not
needed.) This is the only internal
location you will need to know --
other than the Sprite Image numbers.
Since we are not using any direct
POKEs, the following command will put
the Sprite Image into the sprite's
image pointer.
SPRITE IMAGE
SYS AD+09 ,SP,IMG
where
SP = Sprite Number (0-7)
IMG = Image Number (0-255)
Sprites have many registers to be
set -- and the following command
sets most of them.
SPRITE SET
SYS AD+12 ,SP,CO,MC,XY,PR
where
SP = Sprite Number
CO = Color (0-15)
MC = Multi-Color (0 - Off, 1 - On)
XY = X- and Y-expand
(0 - Both Off)
(1 - X-expand)
(2 - Y-expand)
(3 - Both On)
PR = Priority (0-Sprite in Front)
(1 - Sprite Behind)
This one command replaces 5 POKEs,
and many bit-logic headaches.
Our sprite position command
handles the X-coordinate high bit for
you. All you have to do is remember
the off-sets.
SPRITE AT
SYS AD+15 ,SP,X,Y
where
SP = Sprite Number
X = X-coordinate (0-511)
Y = Y-coordinate (0-255)
Now to turn the sprite on (or
off).
SPRITE ON
SYS AD+18 ,SP,OFF/ON
where
SP = Sprite Number
OFF/ON = Switch (0 - Off, 1 - On)
What? No more POKE53269,byte?
Exactly! Unless you want to, of
course!
To enable IRQ-driven sprite
movement, use the following command:
SPRITE MOVE
SYS AD+21 ,sp,DX,DY,SK
where
SP = Sprite Number
DX = DeltaX -- pixels to change
X-coordinate
DY = DeltaY -- pixels to change
Y-coordinate
SK = Skipped Jiffies
1 fastest,
255 - painfully slow
0 -- no movement
Suppose you want to automatically
move Sprite 7 to the southeast.
You would use this command:
SYS AD+21, 7, 1, 1, 1
If that proves too fast, increase
the SK value. If too slow, increase
the DX and DY values.
One quirk -- I could not find how
to use a negative number after a SYS
command. So for moving right (DX=-1)
or up (DY=-1), subtract the movement
value from 256:
SYS AD+21, 7, 256-1, 256-1, 1
for a northwest diagonal. By
combining different DX an DY values
(and compensating with SK) you can
move the sprite in most any general
direction:
SYS AD+21, 7, 256-3, 1, 2
Modern programming languages such
as C++ and Visual Basic use a new
conceptual model called Object
Oriented Programming Systems (OOPS).
Rather than deal with hardware
registers and numerous variables, each
feature in a program is an Object with
certain attributes. In full OOPS, the
name and attribute function something
like an "active variable." To set set
Sprite7's color, you would use
something like
[Sprite7.color = "blue"]
You can use the same attribute to
find out what Sprite7's color is:
[Color = Sprite7.color]
This is all theoretical for Basic
2.0 people, since we don't have such
"active variables." But JoySprite uses
a quasi-Object Oriented approach. Each
sprite is a programming object with
certain Attributes such as position,
image, color, etc.
For JoySprite, you can access the
Attributes with something like an
array. Use the following SYSes with
the Sprite Number, and the
information is available to BASIC in
integer variables.
SPRITE ASK
SYS AD+24 ,SP
where
SP = Sprite Number
The returned values are in the
following integer variables:
X% - X-coordinate (0-511)
Y% - Y-coordinate (0-255)
I% - Image Number (0-255)
EN% - Sprite Enabled (0-1)
But that's not all. The values
set with SPR.SET are also available.
SET ASK
SYS AD+27 ,SP
where
SP = Sprite Number
The returned values are in the
following integer variables:
CO% - Color (0-15)
MC% - Multi-Color Mode (0-1)
XY% - X- and Y-expansion (0-3)
PR% - Priority (0-1)
JoySprite can be used with any
Video Bank, and up to 208 sprite
images can be used directly. Is that
enough? If not, SPR.CPY will move
Sprite Images from anywhere in open
memory (not under ROM) to the VIC
II Sprite Image area.
JoySprite uses Video Bank/Sprite
Image addressing for SPR.CPY. If you
are using the default text screen,
with Sprite Images beginning at 8192,
the location for the first image would
be VBank = 0, Image = 128. VBank 1
begins at 16384; VBank 2 begins at
32768; VBank 3 begins at 49152. The
Images in each bank are numbered
0-255. So the location of a Sprite
Image can be calculated as:
LOC = VBank * 16384 + Image# * 64
Here are two DEF FNs to calculate
VBank and Image#:
VBank -
DEF FNV(L)=(L-FNV(L)*16384)/64
Image# -
DEF FNI(L)=INT(L/16384)
You will want to use such Defined
Functions for Sprite Copy:
SPRITE COPY
SYS AD+30 ,FBNK,SP,TBNK,SP,#SPS
where
FBNK = From VBank#
FSI = From Sprite Image#
TBNK = To VBank#
TSI = To Sprite Image#
#SPS = Number of Sprites to Move
As you can see, SPR.CPY moves data
in chunks of 64 bytes. Move one,
move 'em all!