LZ-Adv: prog. question, code included


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

LZ-Adv: prog. question, code included



i've stumbled onto somthing really weird. I think it has to do with the
line routine. I'm trying to draw three lines but only one is drawn. i has
to do somthing with ret's but i'm not sure what. here is the code.


; _____________________________________________________________________
;|                                                                     |
;|                                   ** ** ***                         |
;|  MMMM    MMMM                        * *** *                        |
;|  MMMMM  MMMMM   EE   GGGG   AAAA      * **                          |
;|  MM MM  MM MM  E    G      A    A      **                           |
;|  MM  MMMM  MM  EEE  G  GG  AAAAAA     * *    _________              |
;|  MM   MM   MM  E    G   G  A    A     **   __ _\_______\_           |
;|  MM   MM   MM   EE   GGG   A    A     **  /  \           \-\-\____  |
;|                                        * | () |_______________/ \_\ |
;|  RRRRRR                                   \__/                \_/   |
;|  RR   RR    AAAA    CCCC   EE  RRRR                                 |
;|  RRRRRR    A    A  C      E    R   R      Mega Racer (c.)           |
;|  RR  RR    AAAAAA  C      EEE  RRRR       Will Stokes               |
;|  RR   RR   A    A  C      E    R   R      Version 1.01              |
;|  RR    RR  A    A   CCCC   EE  R   R      December 1996             |
;|                                                                     |
;|_____________________________________________________________________|
;|                                                                     |
;| Will Stokes               wstokes@vertex.ucls.uchicago.edu          |
;|                                                                     |
;| My Personal Homepage:     http://www.uic.edu/~hhstokes/will.htm     |
;|                                                                     |
;|   My Calculator Website:     http://www.uic.edu/~hhstokes/          |
;|(The TI-85 Calculator Center)                                        |
;|_____________________________________________________________________|








;  ___________________________________________________________
; /                                                           \
;|  BASIC STUFF YOU HAVE TO DO TO SETUP FILE/GAME STRUCTURE    |
; \___________________________________________________________/










#include "TI-85.H"              ;\_____Setup
.org 0                          ;/     Stuff
.db "Mega Racer Beta A", 0  ;<-----Name that appears in ZShell menu.






;  ___________________________________________________
; /                                                   \
;|  Set Variables and discribe what they are used for  |
; \___________________________________________________/






HX = TEXT_MEM             ; x value of point on horizen
I = TEXT_MEM+3            ; x value of car on horizen
endgame = TEXT_MEM+6      ;check bit for quiting sequence.


arg1 = TEXT_MEM+7   ;\
arg2 = TEXT_MEM+8   ; )---used in math routines at very bottom of prog.
res1 = TEXT_MEM+9   ;/


temp1 = TEXT_MEM+10 ;\___Additional temp. space for storage.
temp2 = TEXT_MEM+13 ;/   LOTS OF SPACE HERE
temp3 = TEXT_MEM+16


ty = TEXT_MEM+19    ;<----ty=1 turn point on, else, turn point off.


Way = TEXT_MEM+20   ;<-- used in line routine




;  __________________________________________
; /                                          \
;|   SET FIRST VALUES OF VARIABLES AS NEEDED  |
; \__________________________________________/










        ld a, 63       ;\__Setup starting position of road, center.
        ld (HX), a     ;/
        ld a, 1
        ld (I), a








;  ___________________________________________________________________
; /                                                                   \
;|    FIRST EXECUTION OF CODE........BEGIN GAME...THEN QUIT TO ZSHELL  |
; \___________________________________________________________________/




        ld a, 4
        out (5), a




        CALL_(game)   ;<---start actual execution of game, afterwards
        ret           ; return to ZShell, but you'll never want
                      ;  to do that.








;  _______________________________________________________
; /                                                       \
;|   MAIN GAME LOOP........DRAW ROAD....MOVE CAR...QUIT    |
; \_______________________________________________________/










game:


        CALL_(getter)  ;<--Get feedback of what player wants to do.


        ld a, (endgame)      ;\
        cp $37               ; )---if "endgame" is $37 quit game.
        ret z                ;/    (exit has been pressed)


        jr game              ;<--Don't want to quit? Keep playing!!




getter:                     ; Routine used to get and comprehend last
                            ; keystroke.
        call GET_KEY         ;<----Get last keystroke.
        ld (endgame), a      ;<---Store value in endgame.
        cp K_LEFT
        CALL_Z(mleft)
        cp K_RIGHT
        CALL_Z(mright)
        ret                  ;<---Return to basic game stem.("game")


mleft:
        ld a, (HX)
        dec a
        ld (HX), a
        ROM_CALL(CLEARLCD)
        CALL_(drawroad)    ;<--Main substructure that draws road.
        ret






mright:
        ld a, (HX)
        inc a
        ld (HX), a
        ROM_CALL(CLEARLCD)
        CALL_(drawroad)    ;<--Main substructure that draws road.
        ret








drawroad:                    ; Routine used to draw road on screen.


        CALL_(l1)
        CALL_(l2)
        CALL_(l3)
        ret


l1:


        ld d, 0
        ld e, 40
        ld a, (HX)
        ld l, a
        ld a, 50
        ld h, a
        CALL_(line)
        ret
l2:
        ld d, 0
        ld e, 86
        ld a, (HX)
        ld l, a
        ld a, 50
        ld h, a
        CALL_(line)
        ret
l3:
        ld d, 50
        ld e, 0
        ld h, 50
        ld l, 126
        CALL_(line)


        ret   ; Return to basic game stem after road has been drawn.








;  __________________________________________________________________
; /                                                                  \
;|   Some math routines  (multiplication, division, absolute value)   |
; \__________________________________________________________________/


Div32:                                  ; arg1 / arg2 -> arg1 , res1 = remainder
        ld      de,0                    ; uses de, b, hl
        ld      (res1),de
        ld      (res1+2),de
        ld      b,32
        and     a                       ; clear carry
Div32Loop:
        ld      de,(arg1)               ; arg1 >> 1 -> arg1
        rl      e
        rl      d
        ld      (arg1),de
        ld      de,(arg1+2)
        rl      e
        rl      d
        ld      (arg1+2),de
        ld      de,(res1)               ; res1 >> 1 -> res1
        rl      e
        rl      d
        ld      (res1),de
        ld      de,(res1+2)
        rl      e
        rl      d
        ld      (res1+2),de
        ld      hl,(res1)               ; res1 - arg2 -> res1
        ld      de,(arg2)
        sbc     hl,de
        ld      (res1),hl
        ld      hl,(res1+2)
        ld      de,(arg2+2)
        sbc     hl,de
        ld      (res1+2),hl
        jr      nc,Div32NoAdd
        ld      hl,(res1)               ; res1 + arg2 -> res1
        ld      de,(arg2)
        add     hl,de
        ld      (res1),hl
        ld      hl,(res1+2)
        ld      de,(arg2+2)
        adc     hl,de
        ld      (res1+2),hl
Div32NoAdd:
        ccf
        djnz    Div32Loop
        ld      de,(arg1)               ; arg1 >> 1 -> arg1
        rl      e
        rl      d
        ld      (arg1),de
        ld      de,(arg1+2)
        rl      e
        rl      d
        ld      (arg1+2),de
        ret


                   ;This is Jimmy Mardell, thanks again.
                   ;
abs:                          ; input: arg1  output: |arg1| => a
        ld a, (arg1)          ; load value into a
        bit 7, a              ; is it positive?
        ret z                 ; Yes, return.
        neg                   ; abs value.
        ret                   ; abs taken, now return.




int:                ; takes integer value of arg1 and outputs in arg1.
        ld (arg1), a
        ld bc, (arg1)
        ld a, b
        ld (arg1), a
        ret










;          Optimized Implementation of Bresenham's line algorithm
;         by Stephane JANTZEN (Stephane.Jantzen@scinfo.u-nancy.fr)




line:


        ld      A,D
        sub     H
        jr      NC,DXPositive    ;delta_x > 0
DXNegative:
        neg
DXPositive:
        ld      B,A              ;B <- |delta_x|
        ld      A,E
        sub     L
        jr      NC,DYPositive    ;delta_y > 0
DYNegative:
        neg
DYPositive:
        sub     B               ;|delta_y|
        push    AF
        jr      C,DeltaX        ;|delta_x| > |delta_y|
DeltaY:
        ld      A,H             ;if |delta_x| < |delta_y| then
        ld      H,L             ;then values x and y are swapped
        ld      L,A             ;so the loop will always be performed on the
        ld      A,D             ;x value. A flag must be set to
        ld      D,E             ;remind that data must be drawn (y,x)
        ld      E,A             ;instead of (x,y)


        ;ld      A,$01
        ;ld      (Flag),A        ;the Flag !!!
DeltaX:
        ld      A,D
        sub     H
        jr      NC,TestDY        ;x1 < x2
TestDX:
        ex	DE,HL
TestDY:
        ld      A,E
        sub     L
        ld      A,$01
        jr      NC,StoreA
        neg                     ;y1 > y2 : in case2 the 'y' variable
StoreA:
        ld      (Way),A
InitLine:
        ld      B,H
        ld      C,L
        ld      A,E
        sub     L
        jr      NC,EndInit
        ld      A,L
        ld      L,E
        ld      E,A
EndInit:
        ld      A,E
        sub     L
        rla
        ld      L,A             ;value to add in case1 (d < 0)
        add     A,H
        sub     D
        ld      E,A             ;'d' variable is initialised
        add     A,H
        sub     D
        ld      H,A             ;value to add in case2 (d >= 0)
Loop:
        ld      A,B
        sub     D
        jr      NC,EndLine       ;the line is completely drawn.
        pop     AF
        ;ld      A,(Flag)
        bit     7,A
        push    AF
        push    AF
        push    BC
        jr      Z,DrawPoint
        ld      A,B
        ld      B,C
        ld      C,A
DrawPoint:
        CALL_(PointOn)
        pop     BC
        pop     AF
TestD:
        bit     7,E
        jr      NZ,Case1
Case2:                          ;d >= 0
        ld      A,E
        add     A,H
        ld      E,A
        ld      A,(Way)
        add     A,C
        ld      C,A
        jr      EndLoop
Case1:                          ;d < 0
        ld      A,E
        add     A,L
        ld      E,A
EndLoop:
        inc     B
        jr      Loop
EndLine:
        pop     AF              ;MUST NOT BE REMOVED
        pop     HL              ;can be removed
        pop     DE              ;can be removed
        ret


PointOn:
        push    DE              ;MUST NOT BE REMOVED
        push    HL              ;MUST NOT BE REMOVED
        ROM_CALL(FIND_PIXEL)
        ld      DE,$FC00
        add     HL,DE
        or      (HL)
        ld      (HL),A
        pop     HL              ;MUST NOT BE REMOVED
        pop     DE              ;MUST NOT BE REMOVED
        ret














SetPixel:


        ld a, (ty)
        cp 1
        jr z, Pon
        jr Poff


Pon:
 ROM_CALL(FIND_PIXEL)
 ld de,VIDEO_MEM
 add hl,de
 or (hl)
 ld (hl),a
 ret


Poff:
 ROM_CALL(FIND_PIXEL)
 ld de,VIDEO_MEM
 add hl,de
 xor 255
 and (hl)
 ld (hl),a
 ret












.end       ;<---End label used for compilation...NOTHING BELOW HERE!!!!






*                   Will Stokes		         *
*        wstokes@vertex.ucls.uchicago.edu      	 * 
*     http://www.uic.edu/~hhstokes/will.htm 	 *
*          http://www.uic.edu/~hhstokes/	 *