Re: A83: Pixel/Line/Rectangle Routines. =)


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

Re: A83: Pixel/Line/Rectangle Routines. =)




Just let me know when you want it posted, and I'll do it.

-- 
Bryan Rabeler <brabeler@ticalc.org>
   File Archives, News, Features, and HTML
   the ticalc.org project - http://www.ticalc.org/

On Sun, 20 Dec 1998 Jkhum98@aol.com wrote:

> 
> Ok, I followed up on that Pixel Routine that I posted about earlier today,
> with these Line and Rectangle Routines. I've tested them all, and they work
> just fine, but I'd like everybody look at them and see if theres a better way
> to do these. Maybe tell me how to speed them up much more, or if there's a few
> shortcuts I can use to save bytes. I'm thinking about posting these routines
> at 'ticalc.org', and I'll be sure to give credit where credit is due in the
> text files, but help me to optimize these routines some more before then.
> Thanks a lot everybody for ANY feedback... =)
> 															--Jason K.
> 
> ;-----------------------------------------------------------------------;
> ; Pixel Plotting Routine - By Jason Kovacs, with ZLIB's GetPix Routine.	;
> ;-----------------------------------------------------------------------;
> ; Input:  D = X, E = Y, C = Pixel Color (0-Clear, 1-Plot, 2-XOR Pixel).	;
> ; Output: Pixel is Plotted to Graph Buffer according to Command in 'C'.	;
> ;-----------------------------------------------------------------------;
> 
> PIXEL:
> 	push bc			; Save Loop Value and Color
> 	push de			; Save the Coordinates
> 	ld a, c			; Load this to check which Color
> 	cp 0
> 	call z, PIXEL_WHITE	; Execute PIXEL_WHITE if C=0
> 	cp 1
> 	call z, PIXEL_BLACK	; Execute PIXEL_BLACK if C=1
> 	cp 2
> 	call z, PIXEL_XORIT	; Execute PIXEL_XORIT if C=2
> 	pop de			; Retrieve the Coords for Other Routines
> 	pop bc			; Retrieve the Loop Value and Color
> 	ret		
> 
> PIXEL_WHITE:
> 	ld a, d			; 'a' now has X Coordinate
> 	call GETPIX		; Call the Pixel Routine from ZLIB
> 	CPL			; Compliment 'a' for the correct Bit Mask
> 	AND (hl)		; 'AND' to Clear the Pixel
> 	ld (hl), a		; Write the new byte to Graph Buffer
> 	ld a, 0			; Reload this for use with the CPs above
> 	ret
> PIXEL_BLACK:
> 	ld a, d			; 'a' now has X Coordinate
> 	call GETPIX		; Call the Pixel Routine from ZLIB
>      	OR (hl)			; 'OR' to Plot the Pixel
> 	ld (hl), a		; Write the new byte to Graph Buffer
> 	ld a, 1			; Reload this for use with the CPs above			
> 	ret	
> PIXEL_XORIT:
> 	ld a, d			; 'a' now has X Coordinate
> 	call GETPIX		; Call the Pixel Routine from ZLIB
> 	XOR (hl)		; 'XOR' to Toggle the Pixel
> 	ld (hl), a		; Write the new byte to Graph Buffer
> 	ret			; No need to reload A, done with CPs.
> 
> ;-----------------------------------------------------------------------;
> ; Horizontal Line Routine - By Jason Kovacs - Used with PIXEL Routine.	;
> ;-----------------------------------------------------------------------;
> ; Input:  DE = Starting (X,Y)  B = Length of Line (Including first X).	;
> ;	   C = Color Of Line (0-White Line, 1-Black Line, 2-XOR Line).	;
> ; Output: Horizontal Line drawn to Graph Buffer according to the Color.	;
> ;-----------------------------------------------------------------------;
> 
> H_Line:
> 	push de
> 	push hl
> H_Line_Loop:
> 	call PIXEL
> 	inc d
> 	djnz H_Line_Loop
> 	pop hl
> 	pop de
> 	ret
> 
> ;-----------------------------------------------------------------------;
> ; Vertical Line Routine - By Jason Kovacs - Used with PIXEL Routine.	;
> ;-----------------------------------------------------------------------;
> ; Input:  DE = Starting (X,Y)  B = Length of Line (Including first Y).	;
> ;	   C = Color Of Line (0-White Line, 1-Black Line, 2-XOR Line).	;
> ; Output: Vertical Line drawn to Graph Buffer according to the Color.	;
> ;-----------------------------------------------------------------------;
> 
> V_Line:
> 	push de
> 	push hl
> V_Line_Loop:
> 	call PIXEL
> 	inc e
> 	djnz V_Line_Loop
> 	pop hl
> 	pop de
> 	ret
> 
> ;-----------------------------------------------------------------------;
> ; Rectangle Drawing Routine - By Jason K. - Uses H_Line and V_Line.	;
> ;-----------------------------------------------------------------------;
> ; Input:  DE = Upper-Left Coordinates,  HL = Lower-Right Coordinates.	;
> ;	  C = Color Of Lines (0-White Line, 1-Black Line, 2-XOR Line). 	;
> ; Output: The Outline of a Rectangle is Drawn to the Graph Buffer.	;
> ;-----------------------------------------------------------------------;
> 
> RECT_OUTLINE:
> 	call H_Distance
> 	call H_Line
> 	call V_Distance
> 	call V_Line
> 	push de
> 	call V_Distance
> 	ld d, h
> 	call V_Line
> 	pop de
> 	push de
> 	call H_Distance
> 	ld e, l
> 	call H_Line
> 	pop de
> 	ret
> H_Distance:
> 	ld a, h
> 	sub d
> 	inc a
> 	ld b, a
> 	ret
> V_Distance:
> 	ld a, l
> 	sub e
> 	inc a
> 	ld b, a
> 	ret
> 
> ;-----------------------------------------------------------------------;
> ; Rectangle Filling Routine - By Jason K. - Uses H_Line & Dist.Routines	;
> ;-----------------------------------------------------------------------;
> ; Input:  DE = Upper-Left Coordinates,  HL = Lower-Right Coordinates.	;
> ;	  C = Color Of Lines (0-White Line, 1-Black Line, 2-XOR Line). 	;
> ; Output: Rectangular Section of Graph Buffer is filled according to C.	;
> ;-----------------------------------------------------------------------;
> 
> RECT_FILL:
> 	call H_Distance
> 	ld h, b
> 	call V_Distance
> RECT_LOOP:
> 	push bc
> 	ld b, h
> 	call H_Line
> 	inc e
> 	pop bc
> 	djnz RECT_LOOP
> 	ret
> H_Distance:
> 	ld a, h
> 	sub d
> 	inc a
> 	ld b, a
> 	ret
> V_Distance:
> 	ld a, l
> 	sub e
> 	inc a
> 	ld b, a
> 	ret
> 


References: