A85: Pinball Routine


[Prev][Next][Index][Thread]

A85: Pinball Routine



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 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)

; Pinball-85 version 1.0
; 1997-08-03
;
;
;-----------------------------------------------------
; Include ZShell Definitions
;-----------------------------------------------------

#include "TI-85.H"

;-----------------------------------------------------
; Data locations starts here
;-----------------------------------------------------



;-----------------------------------------------------
; ZShell Title etc
;-----------------------------------------------------

.org 0
.db "Pinball-85",0

;-----------------------------------------------------
; Program code starts here
;-----------------------------------------------------
   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,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 d
   JUMP_Z(BallDown)
   JUMP_(BallUp)

BallDown:
   CALL GET_KEY
   cp  K_EXIT
   ret z
   CALL_(DrawBall)
   CALL_(DelayLoop)
   CALL_(EraseBall)
   ld a,c
   sbc a,d
   ld c,a
   inc d
   ld a,8
   cp d
   JUMP_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
        ret

;--------------------------------------
; PutPixel
;
; Turns on a pixel on the graph-screen
; at location (x,y)=(b,c).
; Screen layout:
;  (0,63)            (127,63)
;         Center
;  (0,0)             (127,0)
;
; Make SURE that ROM Page 4 is activated!
;--------------------------------------
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
;
; Turns off a pixel on the graph-screen
; at location (x,y)=(b,c).
; Screen layout:
;  (0,63)            (127,63)
;         Center
;  (0,0)             (127,0)
;
; Make SURE that ROM Page 4 is activated!
;--------------------------------------
ClearPixel:
   push bc
   push de
   ROM_CALL(FIND_PIXEL)
   ld  de, $FC00
   add hl, de
   xor 255
   and (hl)
   ld  (hl),a
   pop de
   pop bc
   ret





   ret




;-----------------------------------------------------
; End of program
;-----------------------------------------------------
.end



-- 
-Brandon Turok
-e-mail:   windowswiz@ibm.net
-website:  http://www.geocities.com/SiliconValley/Bay/8790/
-IRC:      RealTurok


Follow-Ups: References: