home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.whtech.com
/
ftp.whtech.com.tar
/
ftp.whtech.com
/
Geneve
/
9640news
/
CAT14
/
SPRITS.ARK
< prev
next >
Wrap
Text File
|
2006-10-19
|
14KB
|
368 lines
?
SPIRITED SPRITES
by Mack Mc Cormick
74206,1522
This tutorial is intended for the advanced assembler programmer (beyond
Molesworth).
Apple pie and motherhood. We all know this but I've got to start someplace.
Sprites may occupy screen positions independently of any character already
present. Once set into motion, they can move independently of direct program
control. You can magnify or make double size by changing VDP register 1.
How can they be used? Up to 32 sprites on the screen at any one time. Can be
used in GRAPHICS and MULTICOLOR modes. Also can be used in BIT MAP mode but not
the automatic motion feature. Sprites cannot be used in the TEXT mode.
There are three tables which contain all the information needed to use
sprites:
1. SPRITE ATTRIBUTE TABLE
a. Sprite Position
b. Sprite Color
2. SPRITE DESCRIPTOR TABLE
a. Sprite Pattern Identifier
b. Specify magnified or double sized sprites.
3. SPRITE MOTION TABLE
a. Define X and Y velocities of Sprites.
DEFAULT LOCATIONS OF SPRITE TABLES
---------------------------------------------------------
Table Table Begins at this VDP address
---------------------------------------------------------
SPRITE ATTRIBUTE TABLE >0300
SPRITE DESCRIPTOR TABLE >0400
SPRITE MOTION TABLE >0780
---------------------------------------------------------
Sprites are numbered from 0 to 31. Here's how the screen is defined for
Sprites:
Columns are labeled starting from the left from 0 to 255 (>00 to >FF). Rows are
numbered from top left, the first row is numbered 255 (>FF) followed by the
numbers 0 to 190 (>0 to >BE). Each screen location defined in this manner is
referred to as a pixel. A pixel is the smallest area of the screen you can turn
on or off. Heres the way it looks:
>00 >01 >02 >03... >FF
>FF
>00 P1
.
.
.
>BE P2
Pixel 1 is in row >00 column >02. P2 is in row >BE column >FF.
Here are the formulas to convert row and column locations to pixel locations:
GRAPHIC TO PIXEL CONVERSIONS
----------------------------------------------------
GRAPHIC ROW TO PIXEL ROW GR*8-7=PR
GRAPHIC COLUMN TO PIXEL COLUMN GC*8-7=PC
PIXEL ROW TO GRAPHIC ROW INT[(PR+7)/8]=GR
PIXEL COLUMN TO GRAPHIC COLUMN INT[(PC+7)/8]=GC
----------------------------------------------------
SPRITE ATTRIBUTE TABLE
Begins at VDP >0300 by default. Contains the present position of sprites and
their colors. Each sprite takes up four bytes in the table. The first byte is
the row or Y position of the sprite. The second byte is the column or X
position. The third byte references the pattern of the sprite as to where it
is located in the Sprite Descriptor Table. The fourth byte is the early clock
attribute and also codes for the color of the sprite.
When the computer moves sprites it updates the information in the sprite
attribute table. The more sprites it has to update the longer it takes to
execute the program. To shorten this time place a value of >D0 as the Y
location of the lowest numbered non-moving sprite. Always let the final unused
sprite be undefined by specifying the Y location as >D0.
The third byte references a pattern in the Pattern Descriptor Table. Can range
from >00 to >FF. For example if the third byte contained >80 it would point to
>0400 through >0407 in the Sprite Descriptor Table.
The forth byte controls the early clock and color. The first four bits control
the early clock. If the last bit (3) is reset to zero the early clock is off
and the location of the sprite is said to be it's upper left hand corner. This
means the sprite will fade in and out on the right hand side of the screen. If
bit 3 is on the sprites location is shifted 32 pixels to the left. The sprite
can then fade in and out from the left side of the screen.
Bits 4-7 of byte four contain the color. Same as other VDP colors 0 to >F.
Heres an example Sprite Attribute:
Sprite 0 Sprite 1
SAL DATA >3356,>8001,>A828,>810F,>D0 -- Third Sprite Undefined
/ / / /
Y X / color
pattern
SPRITE DESCRIPTOR TABLE
Just like the pattern descriptor table for characters. Usually begins at >0400.
Addresses >0400 through >0407 are defined as sprite pattern >80.
You can also make sprites magnified or double sized by writing a value to the
two least significant bits of VDP register 1. See page 340 of the E/A manual
for the values.
SPRITE MOTION TABLE
Describes the X and Y velocities of each sprite. This table begins at >0780.
Before a sprite can be placed into motion several conditions must be met. Your
program must allow interrupts using LIMI 2 but before accessing VDP RAM you
must disable interrupts with a LIMI 0. You must indicate how many sprites will
be in motion by placing a value at CPU address >837A. For example if sprites 2,
5, and 7 are in motion you must place an >8 at address >837A which will allow
motion of 0 through 7. A description of the motion must be placed in the
Sprite Motion Table. Each sprite takes up four bytes in the table. The first
byte is the Y velocity, the second byte is the X velocity. The third and
fourth bytes are used by the interrupt routines, just be sure you leave space
for them. The following are allowed as values for X and Y velocities:
>00 to >FF. >00 to >7F are positive velocities (down for vertical motion and
right for horizontal motion), and velocities >FF to >80 are two's compliment
negative velocities (up for vertical motion and left for horizontal motion).
A value of >01 will cause the sprite to move one pixel every 16 VDP interrupts.
About once every 16/60 of a second.
A thought: Have you ever seen a screen dump program that would dump sprites? It
could be done by obtaining their location and pattern and converting to printer
bit graphics.
Program explanation: I will make the assumption that you understand basic
assembler and therefore will only explain the advanced concepts.
General: You will note right away that only 1/4 of the sprite initially appears
on the screen until you press a key the second time to load VDP R1 with the
value to use double sized sprites, and again to use double size and magnified
sprites. This was intentional to show you what all four sizes look like. When
using double size sprites the sprite generator looks at four consecutive
patterns in memory to make up the sprite.
START LWPI MYREG
You'll note right away that I am using the CPU scratchpad RAM for my workspace.
This is because this is the only RAM that is on a 16 bit data bus and therefore
is twice as fast. Always try to place your workspace in this area when you can.
LI R0,>0400
LI R1,HELI
LI R2,32
Loads all four sprite patterns into the sprite descriptor table.
LI R0,>0300
LI R1,SDATA
LI R2,6
Loads the initial Y location, X location, the sprite number, early clock, and
the color of the sprite in the sprite attribute table. Note the early clock
byte is set so the sprites fades out from the right side of the screen.
Experiment here with the early clock and color to observe the results.
LI R0,>0780
LI R1,SPEED
LI R2,4
Establishes the speed of the sprite as down and right. Remember the next two
bytes must equal 0.
LI R1,>0100
MOVB R1,@>837A
Lets the VDP interrupt routine know you only want to move one sprite by placing
he number 1 at >837A.
The rest of the program scans the keyboard and alters VDP R1 to vary the size
an magnification of the sprites. LIMI 2 enables interrupts. 0 and 2 are the
only values with any meaning on the TI-99. More on LIMI later. Just remember
VDP interrupts must be disabled LIMI 0 before accessing VDP RAM.
I recommend you read the chapter on Sprites in the Editor/Assembler manual
Pages 338-348. Be glad to answer any questions. Until next time...Assembler
Executing.
****************************************
** **
** SPRITES AND TEXT FROM BIT MAP **
** BY MACK MCCORMICK **
** ENTRY POINT START **
** WORKSPACE AT >8300 **
** R0,R1,R2 - GEN VDP **
** NO RESERVED REGISTERS ON EXIT **
** **
****************************************
DEF START
REF VSBW,VMBW,VSBR,VMBR,VWTR
PDT EQU >0000 PATTERN DESCRIPTOR TABLE
SVVDP1 EQU >83D4 SAVE LOC FOR VDP R1
SIT EQU >1800 SCREEN IMAGE TABLE
CT EQU >2000 COLOR TABLE
SATAB EQU >1B00 SPRITE ATTRIBUTE LIST
SDTAB EQU >1C00 SPRITE DESCRIPTOR TABLE
STATUS EQU >837C
WS EQU >8300 MY WORKSPACE IN HIGH SPEED CPU RAM
* DATA STATEMENTS *
VDPREG DATA >02A0,>06FF,>0336,>030F VDP REGS BIT MAP MODE
SPRITE DATA >0001,>0307,>0F0F,>3FFF,>3F0F,>0F07,>0301,0 SPRITE DESCRIPTOR
DATA >F0E0,>E0C0,>8286,>FEFF,>FE86,>82C0,>E0E0,>F000
SALINT DATA >5080,>8005,>D000
CHRTAB BSS >2F8
STRING TEXT 'THIS IS THE TEXT TO BE DISPLAYED'
EVEN
* BEGIN CODE *
START LWPI WS
* SAVE THE CHAR SET FROM E/A LOADER *
LI R0,>900 DASE ADDRESS E/A (START CHAR >20)
NOTEA LI R1,CHRTAB READ THE CHAR SET INTO CHRTAB
LI R2,>2F8
BLWP @VMBR
* SET VDP REGS TO BIT MAP *
CLR R0 VDP REG VALUE
LI R1,VDPREG VDP REG POINTER
LI R2,8 REGISTERS TO WRITE TO
VDPL MOVB *R1+,@WS+1 MOV TO R0 LSB
BLWP @VWTR
AI R0,>0100 NEXT VDP REG
DEC R2
JNE VDPL
MOVB @VDPREG+1,@SVVDP1 BLANK DISABLED
* YOU MUST SAVE A COPY OD VDP R1 AT >83D4 OR KEYSCAN WILL INTERFERE
* FORMAT SCREEN >00->FF THREE TIMES *
LI R0,SIT
CLR R1 BEGIN WITH 0
LI R2,>300 LEN OF SIT
THIRDS BLWP @VSBW
INC R0 NEXT LOCATION
AI R1,>0100 WILL WRAP AFTER >FF00
DEC R2
JNE THIRDS
* CLEAR THE PATTERN AREA BLANK AND MAKE COLOR TABLE RED ON WHITE*
BL @CLRVDP CLEAR PATTERN AREA
DATA PDT,>1800,0 DATA FOR SUBROUTINE
BL @CLRVDP RED ON WHITE COLOR AREA
DATA CT,>1800,>9F9F
* ENABLE THE SCREEN SO YOU CAN SEE *
LI R0,>01E3 WRITE >E3 TO VDP REG 1
BLWP @VWTR DOUBLE/MAGNIFIED SPRITES
SWPB R0
MOVB R0,@SVVDP1 SAVE THE VALUE
* PUT THE TEXT ON THE SCREEN *
BL @DISTEX SUBROUTINE TO PLACE TEXT ON THE SCREEN
DATA >B00,STRING,32
* SET UP SPRITES *
LI R0,SDTAB SPRITE DESCRIPTOR TABLE ADDRESS
LI R1,SPRITE SPRITE CHARACTER DATA
LI R2,32 DOUBLE SIZE SPRITE
BLWP @VMBW
LI R0,SATAB SPRITE ATTRIBUTE TABLE
LI R1,SALINT INIT DATA FOR SPRITE ATTRIBUTE LIST
LI R2,5 FIVE BYTES TO WRITE
BLWP @VMBW >D0 REQUIRED TO DISABLE REMAINING SPRITES
* THE SPRITE IS ON THE SCREEN. NOW TO MOVE IT.
LOOP LI R0,SATAB+1 X POSITION OF THE SPRITE. Y AT SATAB
BLWP @VSBR READ THE CURRENT X POSITION
SRL R1,8 PUT VALUE IN RIGHT BYTE
DEC R1 SUBTRACT 1 FROM THE X VALUE
JNE MOVE IF X=0 THEN
LI R1,>FF X=>FF
MOVE SLA R1,8 MOVE TO MSBYTE
BLWP @VSBW WRITE THE NEW X POSITION UP
LI R2,800 DELAY TO SLOW DOWN THE SPEED OF THE SPRITE
DELAY NOP WASTE TIME
DEC R2
JNE DELAY
JMP LOOP THIS IS WHERE YOU COULD PLACE THE REMAINING PROGRAM
* THIS IS A CONTINUOUS LOOP NO PROVISION FOR EXITING GIVEN *
**************************************
* *
* SUBROUTINE TO FILL VDP WITH DATA *
* RT IS R12 *
* DATA PDT,>1800,>0000 *
* (DEST,LEN,VALUE TO FILL) *
* *
**************************************
CLRVDP MOV *R11+,R0 DEST
CLRLV MOV *R11+,R3 LEN
CLRV MOV *R11+,R4 VALUE(S)
CLR MOV R11,R12 SAVRTN
SRL R3,1 DIVIDE BY 2
LI R2,2 BYTES OF DATA
LI R1,WS+8 FROM R4
CLRVL BLWP @VMBW
INCT R0 NEXT 2 LOCATIONS
DEC R3 DONE?
JNE CLRVL
B *R12 RT
*************************************
* *
* DISPLAY TEXT SUBROUTINE *
* (LOC,TEXT,LENGTH) *
* >388,MMENU,9 *
* *
*************************************
DISTEX MOV *R11+,R0 LOCATION
* LOC=((ROW-1)*256)+((COLUMN-1)*8)
MOV *R11+,R3 ADDRESS OF TEXT TO WRITE
MOV *R11+,R5 LENGTH OF TEXT STRING
LI R2,8 8 BYTES IN A CHAR DESCRIPTION
PUTDIS MOVB *R3+,R1 BYTE TO WRITE
SRL R1,8 RIGHT JUSTIFY
AI R1,-32 STRIP THE ASCII OFFSET
SLA R1,3 MULTIPLY BY 8 FOR OFFSET
AI R1,CHRTAB ADD THE BASE ADDRESS OF THE CHAR TABLE
BLWP @VMBW PUT IT ON THE SCREEN
AI R0,8 NEXT SCREEN LOCATION
DEC R5 DECREMENT LENGTH COUNTER
JNE PUTDIS ANY MORE TO WRITE?
RT
END
Download complete. Turn off Capture File.