textmode putpixel in two variations

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
Raf
Posts: 19
Joined: 02 Aug 2005
Location: Poland
Contact:

textmode putpixel in two variations

Post by Raf »

Code: Select all

;
; fast textmode putpixel 
; (made for c64 but can be used anywhere)
;
;
; it's real fast but takes 50 bytes of zeropage
; for 25 columns screen
; -> good for demos ;-)
;
;
; how does it work:
; on zeropage there are 2byte columns' pointers
; and there is only Y index reg used to determine
; row of pixel 
; just like STA ([column*2+zeropageptr]),y
; 
; Written from scratch by Rafal Szyja , Poland
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

zeropage= 100 ; zeropage pointer for generating tables

_x= 251	; x coordinate of 
_y= 252	; y

temp= 99	; temporary storage 
	

	*= $1000
	
	JSR gentab	; this is called only once for this routine
			; by altering gentab you can for example make table
			; for different screen posiotion and organization
			; than c64's poweron default 40x25 @ 0400

; this is only testpiece - pixels are to be set somewhere else 
; and then jump to setpix
	LDA #0
	STA _x
	LDA #10
	STA _y

; real start of routine

setpix	
	LDA _y
	ASL
	CLC	; y coor will be always < 128 so you can gain 2 cycles by deleting this line
	ADC #100
	sta dest+1	; program automodification = faster operation
	
	ldy _x
	lda #255	; just to test routine , there is actual pixelval
dest	
	STA ($00),y	
	rts
	
;---------------------------------------------------------)
	
gentab	; generates tables with columns' values
	LDA #$00	; LSB of screen
	LDX #$04	; MSB of screen
	
	LDY #0
	
loop	
	STA zeropage,y
	INY
	sta temp
	txa
	STa zeropage,y
	lda temp
	INY
	CLC
	ADC #40		; 40 rows
	BCC _a
	INX
_a	
	CPY #50
	BEQ stop
	jmp loop

stop 	
	RTS

and slower variation using only 4 zeropage registers (possibly only 2):

Code: Select all

	*= $1000
	
_x= 251	; x
_y= 252	; y
	
dyl = 253	; destination lo
dyh = 254	;	      hi
	
	LDA #2
	STA _y
	LDA #2
	sta _x
	
	LDA #0
	STA dyh
	LDA _y
	ASL ;A
	ROL dyh
	ASL ;a
	ROL dyh
	CLC
	ADC _y
	BCC x1
	INC dyh
x1
	ASL ;A
	ROL dyh
	ASL ;A
	ROL dyh
	ASL ;A
	ROL dyh
	STA dyl
	
	CLC
	LDA dyh
	ADC #$04
	STA dyh
	
	
	LDY _x	
	LDA #160
	STA (dyl),y
	JMP *
owns 1xC128, 1x128D cr ,1xc64 (broken unfortunately) ,1xc64c ,2xc64g (one is broken) ,~4xc64e ,1x1541 ,1x1541-II ,1x1541C and some chips for those machines ;-)

www.vulture.c64.org
www.rafalszyja.republika.pl
Post Reply