A85: Re: Pinball Routine
[Prev][Next][Index][Thread]
A85: Re: Pinball Routine
Brandon Turok wrote:
>
> I have successfully written a gravity-type bouncing-ball routine which I
> can convert to use with Pinball. My only problem is that I can't seem
> to get it to bounce from the same place...it seems to bounce higher and
> higher. The code is pasted below. Please tell me what's wrong with
> this code. Thank you.I have also commented on the code, hope you don't mind.
>
> (I must admit that some of the code isn't my own, so I thank the
> respective authors of that code for making it available to me)
>
> #include "TI-85.H"
>
> .org 0
> .db "Pinball-85",0
>
> ld a,4
> out (5),a ;Switch to memory page 4
>
> ProgStart:
> ROM_CALL(CLEARLCD) ;Clear the screen
>
> ld a,8
> ld d,a ;set vertical velocity
> ld b,a ;set x/y coordinates
> ld c,aWhy do you load reg a?
> BallUp:
> CALL GET_KEY
> cp K_EXIT
> ret z
> CALL_(DrawBall)
> CALL_(DelayLoop)
> CALL_(EraseBall)
> ld a,c
> add a,d
> ld c,a
> dec d
> ld a,0
> cp dJust a note, these two lines aren't nessecary. dec affects flags.
> JUMP_Z(BallDown)
> JUMP_(BallUp)You should probably use jr instead of JUMP. jr is smaller. The difference is
that jr has a limited range. As a general rule ALWAYS use jr, and if you get
a range error, change it to JUMP.
>
> BallDown:
> CALL GET_KEY
> cp K_EXIT
> ret z
> CALL_(DrawBall)
> CALL_(DelayLoop)
> CALL_(EraseBall)
> ld a,c
> sbc a,dShouldn't this be sub?
> ld c,a
> inc d
> ld a,8
> cp d
> JUMP_Z(BallUp)Here's your problem. While the ball is going down the only thing that should
stop the ball is the ground.
try this:
xor a ;same as ld a,0
cp c
jr z,BallUp
> JUMP_(BallDown)
>
>
>
> DrawBall: ;draw the ball
>
> CALL_(PutPixel)
> inc B
> CALL_(PutPixel)
> inc C
> CALL_(PutPixel)
> dec B
> CALL_(PutPixel)
> dec c
>
> ret
>
> EraseBall: ;erase the ball
>
> CALL_(ClearPixel)
> inc B
> CALL_(ClearPixel)
> inc C
> CALL_(ClearPixel)
> dec B
> CALL_(ClearPixel)
> dec c
>
> ret
>
> DelayLoop: ;delay (pretty much taken from TEXAN.ASM (thanks Magnus)
> push af
> push bc
> push de
> ld bc,$1DFF
> dloop:
> dec bc
> ld a,b
> or c
> jr nz,dloop
> pop de
> pop bc
> pop af
> retAnother note, you do not need to save de or af.
>
> PutPixel:
> push bc
> push de
> ROM_CALL(FIND_PIXEL)
> ld de, $FC00
> add hl, de
> or (hl)
> ld (hl),a
> pop de
> pop bc
> ret
> ClearPixel:
> push bc
> push de
> ROM_CALL(FIND_PIXEL)
> ld de, $FC00
> add hl, de
> xor 255I know Magnus wrote this routine, but using
cpl instead of
xor 255 saves one byte
> and (hl)
> ld (hl),a
> pop de
> pop bc
> ret
> ret
> .end
Another comment, push & pop within the drawball or eraseball routines, not
within the pixel routines... it seems picky now but in the long run it will
pay off. Good luck with Pinball-85!
--
Terry Peng
email- tpeng@geocities.com
web- http://www.geocities.com/SiliconValley/Bay/5104/index.html
This site always has the latest versions of my software.
References: