Difference between revisions of "Z80 Routines:Graphic:getPixel"
From WikiTI
(New page: LargeSpriteLargeSprite The '''getPixel''' routine is used change a pixel in the graph buffer. {{stub}} == Code == <nowiki> <...) |
|||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | [[Category:Z80 Routines:Graphic| | + | [[Category:Z80 Routines:Graphic|GetPixel]] |
| − | The '''getPixel''' routine is | + | [[Category:Z80 Routines|GetPixel]] |
| − | + | ||
| + | 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> | ||
| − | ; | + | ; 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 | ||
| − | ;pixel | + | ; 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 09: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