SPRITE PONG BALL
[Prev][Next][Index][Thread]
SPRITE PONG BALL
here is a routine that I made to bounce a pong ball around the
screen....but it does not work when it hits the left side of the screen
I basically took four routines that made the ball go each direction and
then used this key to tell which way it is going
up=0
down=1
left=0
right=1
and then I check to see where it has to go by process of elimination. (it
helped me to draw a diagram with a rectangle of screen and diamond inside
the rectangle touching each side, this diamond represents the ball
movements, this way it is easy to see where the ball has to go)
source
.NOLIST
#define equ .equ
#define EQU .equ
#define end .end
#define ballx 8265h
#define bally 8266h
#define dirx 8269h
#define diry 826Ah
#include "ti83asm.inc"
#include "tokens.inc"
.LIST
kclear .equ 191
.org 9327h
call _clrlcdfull
call _runindicoff
call _grbufclr
ld a,45
ld (ballx),a
ld (bally),a
ld a,1
ld (dirx),a ;ball is going up and to the right
ld a,0
ld (diry),a
jp upright
drawball:
call putball
ld a,0ffh
out (1),a
ld a,0fdh
out (1),a
in a,(1)
cp kclear
jp z,quit
checkdir:
ld a,(ballx)
cp 94
jp z,changeup_or_down
cp 0
jp z,changeup2
ld a,(bally)
cp 63
jp z,changeleft2
cp 0
jp z,change_left_or_right
ld a,(diry)
cp 0
jp z,up1
cp 1
jp z,down1
up1:
ld a,(dirx)
cp 1
jp z,upright
cp 0
jp z,upleft
down1:
ld a,(dirx)
cp 1
jp z,downright
cp 0
jp z,downleft
changeup_or_down:
ld a,(diry)
cp 0
jp z,upleft
cp 1
jp z,downleft
changeup2:
ld a,(diry)
cp 0
jp z,upright
cp 1
jp z,downright
change_left_or_right:
ld a,(dirx)
cp 0
jp z,upleft
cp 1
jp z,upright
changeleft2:
ld a,(dirx)
cp 0
jp z,downleft
cp 1
jp z,downright
upright:
call putball
ld a,0
ld (diry),a
ld a,1
ld (dirx),a
ld a,(ballx)
ld b,a
ld a,(bally)
ld c,a
inc b
inc c
ld a,b
ld (ballx),a
ld a,c
ld (bally),a
jp drawball
downright:
call putball
ld a,1
ld (diry),a
ld a,1
ld (diry),a
ld a,(ballx)
ld b,a
ld a,(bally)
ld c,a
inc b
dec c
ld a,b
ld (ballx),a
ld a,c
ld (bally),a
jp drawball
upleft:
call putball
ld a,0
ld (diry),a
ld a,0
ld (dirx),a
ld a,(ballx)
ld b,a
ld a,(bally)
ld c,a
dec b
inc c
ld a,b
ld (ballx),a
ld a,c
ld (bally),a
jp drawball
downleft:
call putball
ld a,1
ld (diry),a
ld a,0
ld (dirx),a
ld a,(ballx)
ld b,a
ld a,(bally)
ld c,a
dec b
dec c
ld a,b
ld (ballx),a
ld a,c
ld (bally),a
jp drawball
putball:
ld a,(bally)
ld e,a
ld a,(ballx)
ld bc,ball
call SPRXOR
call _grbufcpy_v
ret
SPRXOR:
push bc ; Save sprite address
;ÛÛÛÛ Calculate the address in graphbuf ÛÛÛÛ
ld hl,0 ; Do y*12
ld d,0
add hl,de
add hl,de
add hl,de
add hl,hl
add hl,hl
ld d,0 ; Do x/8
ld e,a
srl e
srl e
srl e
add hl,de
ld de,8e29h
add hl,de ; Add address to graphbuf
ld b,00000111b ; Get the remainder of x/8
and b
cp 0 ; Is this sprite aligned to 8*n,y?
jp z,ALIGN
;ÛÛÛÛ Non aligned sprite blit starts here ÛÛÛÛ
pop ix ; ix->sprite
ld d,a ; d=how many bits to shift each line
ld e,8 ; Line loop
LILOP: ld b,(ix+0) ; Get sprite data
ld c,0 ; Shift loop
push de
SHLOP: srl b
rr c
dec d
jp nz,SHLOP
pop de
ld a,b ; Write line to graphbuf
xor (hl)
ld (hl),a
inc hl
ld a,c
xor (hl)
ld (hl),a
ld bc,11 ; Calculate next line address
add hl,bc
inc ix ; Inc spritepointer
dec e
jp nz,LILOP ; Next line
jp DONE1
;ÛÛÛÛ Aligned sprite blit starts here ÛÛÛÛ
ALIGN: ; Blit an aligned sprite to graphbuf
pop de ; de->sprite
ld b,8
ALOP1: ld a,(de)
xor (hl)
ld (hl),a
inc de
push bc
ld bc,12
add hl,bc
pop bc
djnz ALOP1
DONE1:
ret
;ÜÛÛÛÛÛÛÛÛÛÛÛÛÜ SPRXOR
ÜÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ
ÄÄ¿
;³ÛÛÛÛÛ Z80 ÛÛÛÛÛÛ³ Sprite83 ³ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ³ movax
³ÛÛÛÛÛÛÛÛÛÛÛÛ³
;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄ
ÄÄÙ
ball: .db 11000000b
.db 11000000b
.db 00000000b
.db 00000000b
.db 00000000b
.db 00000000b
.db 00000000b
.db 00000000b
quit:
ret
.end
END