Re: LZ-Adv: line routine


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

Re: LZ-Adv: line routine



i dont think you can do addition along the #+# idea.. i think it would be
more like:
ld (textmem),a
ld a,b
ld a,#
add b


something like this????? if im wrong, someone correct me before i corrupt
this person :)
chris






At 09:01 PM 11/14/96 -0600, you wrote:
>I posted this first to the regular zshell list-serve but got no help. I
>know somebody here can help me. Any suggestions? Any help much
>appreciated.
>
>I got that line routine off of ticalc.org but am having some trouble with
>it. Can somebody explain to me what I'm doing wrong?
>
>
>H = 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
>
>ty = TEXT_MEM+41    ;<----ty=1 turn point on, else, turn point off.
>
>Way = TEXT_MEM+42   ;<-- used in line routine
>
>
>;  __________________________________________
>; /                                          \
>;|   SET FIRST VALUES OF VARIABLES AS NEEDED  |
>; \__________________________________________/
>
>
>
>
>
>        ld a, 50      ;\__Setup starting position of road, slightly
>        ld (H), a     ;/  turning right.
>
>
>
>
>
>;  ___________________________________________________________________
>; /                                                                   \
>;|    FIRST EXECUTION OF CODE........BEGIN GAME...THEN QUIT TO ZSHELL  |
>; \___________________________________________________________________/
>
>
>
>
>
>        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:
>
>        ROM_CALL(CLEARLCD)
>        CALL_(drawroad)    ;<--Main substructure that draws road.
>        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!!
>
>        ret
>
>drawroad:     ; Routine used to draw road on screen.
>
>        ld a, 40
>        ld (temp1), a
>        CALL_(drd)
>        ld a, 86
>        ld (temp1), a
>        CALL_(drd)
>        ret
>
>drd:          ; routine that actually draws the road.
>        ld a, 40
>        ld b, a
>        ld a, (H)
>        sub b
>        ld (arg1), a
>        ld a, 2
>        ld (arg2), a
>        CALL_(Div32)
>        ld a, (arg1)
>        ld b, a
>        ld a, 40
>        add a, b
>        ld l, a
>        ld a, 27
>        ld h, a
>        ld a, 0
>        ld d, a
>        ld a, 40
>        ld e, a
>        CALL_(Line)
>
>
>
>
>
>
>
>
>
>        ret   ; Return to basic game stem after road has been drawn.
>
>
>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, (H)
>        dec a
>        ld (H), a
>        ret
>
>mright:
>        ld a, (H)
>        inc a
>        ld (H), a
>        ret
>
>
>;  __________________________________________________________________
>; /                                                                  \
>;|   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.
>
>
>integer:           ; takes integer value of arg1 and outputs in arg1.
>        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      	 *  Comment of the * : ) *
>*      						 *  times:         *     *
>*              My Personal Homepage		 *                 * : ( *
>*     http://www.uic.edu/~hhstokes/will.htm 	 *******************     *
>*						 *                 * . | *
>*           The TI-85 Calculator Center		 *  Oxymoron:      *     *
>* (the website I maintain and update very often) * Power Macintosh * : o *
>*          http://www.uic.edu/~hhstokes/	 *                 *     *
>*						 *                 *     *
>**************************************************************************
>*									 *
>*  Happy, Sad, missing an eye and supprised. -------------------------^  *
>*									 *
>**************************************************************************
>
>
>


References: