Z80 Routines:Graphic:getPixel

From WikiTI
Jump to: navigation, search


The getPixel routine is a utility that simplifies pixel manipulation in the graph buffer.

Code

; brief : utility for pixel manipulation
; input : a -> x coord, l -> y coord
; output : hl -> address in graph buffer, a -> pixel mask
; destroys : b, de
getPixel:
	ld	h, 0
	ld	d, h
	ld	e, l
	
	add	hl, hl
	add	hl, de
	add	hl, hl
	add	hl, hl
	
	ld	e, a
	srl	e
	srl	e
	srl	e
	add	hl, de
	
	ld	de, PlotSScreen       ; it might be a good idea to have buffer indirection here, i.e : ld de, (buffer_addr)
	add	hl, de
	
	and	7
	ld	b, a
	ld	a, $80
	ret	z
	
	rrca
	djnz	$-1
	
	ret
 

Example usage

; brief : set (darkens) a pixel in the graph buffer
; input : a -> x coord, l -> y coord
; output : none
; destroys : a, b, de, hl
setPixel:
	call	getPixel
	or	(hl)
	ld	(hl), a
	ret

; brief : reset (lighten) a pixel in the graph buffer
; input : a -> x coord, l -> y coord
; output : none
; destroys : a, b, de, hl
resetPixel:
	call	getPixel
	cpl
	and	(hl)
	ld	(hl), a
	ret

; brief : flip (invert) a pixel in the graph buffer
; input : a -> x coord, l -> y coord
; output : none
; destroys : a, b, de, hl
flipPixel:
	call	getPixel
	xor	(hl)
	ld	(hl), a
	ret
 

Comments

  • Don't use this to plot sprites! Use putSprite
  • Not that usually used but can be used to get hl pointing to the wanted place in graph buffer