Z80 Routines:Graphic:getPixel: Difference between revisions

From WikiTI
Jump to navigationJump to search
Galandros (talk | contribs)
mNo edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
[[Category:Z80 Routines:Graphic|GetPixel]][[Category:Z80 Routines|GetPixel]]
[[Category:Z80 Routines:Graphic|GetPixel]]
The '''getPixel''' routine is used change a pixel in the graph buffer.
[[Category:Z80 Routines|GetPixel]]
{{stub}}
 
The '''getPixel''' routine is a utility that simplifies pixel manipulation in the graph buffer.


== Code ==
== Code ==
  <nowiki>
  <nowiki>
 
; 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
  </nowiki>
  </nowiki>


== Example ==
== Example usage ==
  <nowiki>
  <nowiki>
;pixel On (black)
; brief : set (darkens) a pixel in the graph buffer
 
; input : a -> x coord, l -> y coord
;pixel Off (white)
; output : none
; destroys : a, b, de, hl
setPixel:
call getPixel
or (hl)
ld (hl), a
ret


;pixel change
; 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
  </nowiki>
  </nowiki>



Latest revision as of 16:58, 5 November 2009


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