[A83] Re: Sprites
[Prev][Next][Index][Thread]
[A83] Re: Sprites
Here is some code that moves a happy face around the screen:
.nolist
#include "ion.inc" ;tells TASM--the compiler--what file to read
from to define rom call memory addresses and such
.list
GDown = 01h ;key equates
GLeft = 02h
GRight = 03h
GUp = 04h
GClear = 0Fh
xpos = saferam3 ;user defined variables for
ypos = xpos+1 ;x and y coordinates
#ifdef TI83P ;a check for TASM to see whether it is making an 83
program--if so, do the next two commands
.org progstart-2
.db $BB,$6D
#else ;if it isn't an 83 program, then do something
[#]else--the next line
.org progstart
#endif ;simply ends the #ifdef command
ret
jr nc,lblStart ;Jumps to the beginning of the program (this line and
the below three will be
.db "Cole's Sprite Routine",0 ;The title displayed by
ION--anything you want ;defines where label begin is, program
code follows this label
lblStart:
;Position sprite at 16,16
ld hl,$1010
ld (xpos),hl
Loop:
call DrawSprites ;calls lable drawsprites
call Ionfastcopy ;copys buffer to screen
bcall(_cleargbuf) ;clears graphbuffer
call WaitKey ;calls label waitkey
cp gClear ;if it was clear, return to ion
ret z
cp gLeft ;if it was left
jr z,Left ;go to left
cp gRight ;etc...
jr z,Right
cp gUp
jr z,Up
cp gDown
jr z,Down
jr Loop
Left:
ld a,(xpos) ;loads the xpos into a and
sub 4 ;subtracts 4
jr c,Loop ;makes sure sprite is still on screen
ld (xpos),a ;loads a back into xops
jr Loop ;jumps to the loop
Right: ;same as left but adds
ld a,(xpos)
add a,4
cp 96-8
jr nc,Loop
ld (xpos),a
jp Loop
Up:
ld a,(ypos)
sub 4
jp c,Loop
ld (ypos),a
jp loop
Down:
ld a,(ypos)
add a,4
cp 64-8
jp nc,Loop
ld (ypos),a
jp loop
DrawSprites:
ld a,(xpos) ; a = xpos
ld b,8 ;b = sprite height
ld hl,(ypos) ;l = ypos
ld ix,smiley ; ix = sprite
jp ionputsprite ;jumps to ionputsprite which
;copys screen to buffer and returns
WaitKey: ;waits for keypress
ei
WaitKeyLoop:
halt
bcall(_getcsc)
or a
jr z,WaitKeyLoop
ret
smiley: ;smileyface sprite
.db %00111100
.db %01000010
.db %10100101
.db %10000001
.db %10100101
.db %10011001
.db %01000010
.db %00111100
.end
END