ZX BASIC:FastPlot

From BorielWiki
Jump to: navigation, search

This plots a single over0 point on the screen, at speed.

It's been tested at a fill rate of over 8,500 points per second.

 
SUB fastPlot (x AS UBYTE, y AS UBYTE)
ASM
ld d,(IX+5) ;'X
ld e,(IX+7) ;'Y
 
    ld a, 191
	SUB e	
	ret c	
	ld e, a	
	AND a	
	
    rra		
	scf		
	rra		
	AND a	
	rra		
	XOR e			 
	AND 248
	XOR e
	ld h, a
	ld a, d
	rlca
	rlca
	rlca
	XOR e
	AND 199
	XOR e
	rlca
	rlca
	ld l, a
	
    ld a, d
	AND 7
	ld b, a
	inc b
	ld a, 254
plotPoint_loop: rrca
	djnz plotPoint_loop
	ld b, 255
	XOR b	
	ld b, a	
	ld a, (hl)
	OR b	
	ld (hl), a
	
END ASM
END SUB

Even faster, if you want to use the screen tables, is to lookup the screen address. HRPrintFast also uses the same table - it's important to only include it once - there's absolutely no benefit from including more than one copy. include once is the magic, there - and just have one copy of the source, to be sure it's the same one! You have to include this table (and the label "ScreenTables" somewhere in memory so the spectrum can find it.

This version has been tested with a fill rate of about 10,000 pixels per second (over 20% of the screen per second!).

 
SUB fastPlot (x AS UBYTE, y AS UBYTE)
ASM
 
ld d,a ;'X
 
    ld a, 191
	SUB (IX+7) ;' y
    jr c, plotPoint_end	
    ld l,a	
	
ld h,ScreenTables/256
ld a,(HL)
inc h
ld l,(HL)
ld h,a
ld a,d
RRCA
RRCA
RRCA
AND 31
add a,l
ld l,a
	
ld a, d
AND 7
ld b, a
inc b
ld a, 1
    
plotPoint_loop: 
    rrca
djnz plotPoint_loop	
 
    ld b, a	
    ld a, (hl)
    OR b	
    ld (hl), a
 
plotPoint_end:
	
END ASM
END SUB
 
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox
Translate
Google AdSense