Re: A85: line


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

Re: A85: line




At 13:23 1998-05-05 -0400, you wrote:
>
>speaking of FLINE, does anyone have the source to it that's willing to
>share it with an 82 programmer who needs it to complete a port?  i know
>that it'll need to be reconfigured for a 96 pixel screen, but i just need
>the source.

I'm not sure the source would help you, because I don't think it
can be ported to the 82 without losing quite some speed (because
of the video device thing). It uses selfmodifying code quite
much, so don't remove any 'add a,0'...

(NOTE: The source is for the 86, but that doesn't make much difference)


; FASTLINE
;
; BRESENHAM'S LINE ALGORITHM
; by Jimmy Mårdell <yarin@acc.umu.se>
;
; Parameters: BC    = memory to put sprite (usually $FC00)
;	      DE,HL = coordinates of line (D,E)-(H,L)
;
; Code size:  145 bytes (excluding FindPixel)
;
; Performance: 4 times faster than Stephane Jantzens line routine
;

FLine:
 push bc
 push de
 push hl
 push bc
 ld a,h
 cp d
 jr nc,DXpos
 ex de,hl
DXpos:
 ld b,d
 ld c,e
 pop de
 push hl
 call FindPixel
 add hl,de
 ex (sp),hl
 ld e,c
 ld c,a
 ld a,h
 sub b
 ld b,a
 ld a,l
 sub e
 ld de,16
 jr nc,DYpos
 neg
 ld de,-16
DYpos:
 push af
 sub b
 jr nc,DY_Greater
 add a,a
 neg
 ld (x_ai+1),a
 pop af
 add a,a
 ld (XDNeg+1),a
 sub b
 pop hl
 push af
 ld a,c
 or (hl)
 ld (hl),a
 pop af
 bit 7,a
 jr nz,XDNeg
XNewRow:
 add hl,de
x_ai:
 sub 0
 push af
 rrc c
 jr nc,XNoWrap1
 inc hl
XNoWrap1:
 ld a,c
 or (hl)
 ld (hl),a
 pop af
 dec b
 jr z,LineDone
 jr nc,XNewRow
XDNeg:
 add a,0
 push af
 rrc c
 jr nc,XNoWrap2
 inc hl
XNoWrap2:
 ld a,c
 or (hl)
 ld (hl),a
 pop af
 dec b
 jr z,LineDone
 jr c,XNewRow
 jr XDNeg
DY_Greater:
 neg
 add a,a
 ld (YNoWrap+1),a
 ld a,b
 add a,a
 ld (YDNeg+1),a
 pop hl
 sub h
 ld b,h
 pop hl
 push af
 ld a,c
 or (hl)
 ld (hl),a
 pop af
YRepeat:
 bit 7,a
 jr nz,YDNeg
 rrc c
 jr nc,YNoWrap
 inc hl
YNoWrap:
 add a,0
 jr YPlot
YDNeg:
 add a,0
YPlot:
 add hl,de
 push af
 ld a,c
 or (hl)
 ld (hl),a
 pop af
 djnz YRepeat
LineDone:
 pop hl
 pop de
 pop bc
 ret

FindPixel:
 push bc
 push de
 ld hl,ExpTable ; 10
 ld d,0         ; 7
 ld a,b         ; 4
 and $07        ; 7
 ld e,a         ; 4
 add hl,de      ; 11
 ld e,(hl)      ; 7
 ld h,d         ; 4
 srl b          ; 8
 srl b          ; 8
 srl b          ; 8
 ld a,c         ; 4
 add a,a        ; 4
 add a,a        ; 4
 ld l,a         ; 4
 add hl,hl      ; 11
 add hl,hl      ; 11
 ld a,e         ; 4
 ld e,b         ; 4
 add hl,de      ; 11
 pop de
 pop bc
 ret

ExpTable:
 .db $80,$40,$20,$10,$08,$04,$02,$01

--
Real name: Jimmy Mårdell                "can't go mucking with a 'void *'"
IRC......: Yarin                                // Apple's MPW C compiler
Email....: mailto:yarin@acc.umu.se        
Homepage.: http://www.algonet.se/~mja/


Follow-Ups: References: