3271
ASM / Re: How to display pixel in certain location
« on: May 03, 2011, 08:54:59 pm »
Here is some sample code for pixel routines... Sorry I didn't add many notes to this I am talking on the phone, programming on my calc and typing this up all at the same time
EDIT2: Also, I made it Call GetPixelLoc instead of making it inline because GetPixelLoc has other uses, too, for code.
EDIT3: So I figured if it was in your code, it might work better as a call, but if you aren't using it for anything else, place it inline to save 3 bytes.
Code: [Select]
;===============================
DrawPixel
;===============================
;Inputs:
; A is the drawing method:
; 0=Pixel Off
; 1=Pixel On
; All else=Pixel Invert
; B is the X coordinate
; C is the Y coordinate
;===============================
push af ;F5
call GetPixelLoc ;CD****
pop bc ;C1
inc b ;04
djnz PixelOn ;1004
;Pixel Off
cpl ;2F Inverts A
and (hl) ;A6
ld (hl),a ;77
ret ;C9
djnz PixelInvert ;1003
PixelOn:
or (hl) ;B6
ld (hl),a ;77
ret ;C9
PixelInvert:
xor (hl) ;AE
ld (hl),a ;77
ret ;C9
;===============================
GetPixelLoc:
;===============================
;Inputs:
; B is X coordinate
; C is Y coordinate
;Outputs:
; HL points to the byte in plotSScreen
; A is the mask
; B is 0
; C is unchanged
; DE is C*12 (also BC*12)
;===============================
ld a,b ;78
ld b,0 ;0600
ld h,b ;60
ld l,c ;69
add hl,hl ;29
add hl,bc ;09
add hl,hl ;29
add hl,hl ;29
ld b,a ;47
ld d,h ;54
ld e,l ;5D
rrca ;0F
rrca ;0F
rrca ;0F
and 1Fh ;E61F
add 40h ;C640
ld l,a ;6F
ld h,93h ;2693
add hl,de ;19
ld a,b ;78
and 7 ;E607
ld b,a ;47
inc b ;04
ld a,1 ;3E01
Loop:
rrca ;0F
djnz Loop ;10FD
ret ;C9
EDIT: This can probably be optimised...EDIT2: Also, I made it Call GetPixelLoc instead of making it inline because GetPixelLoc has other uses, too, for code.
EDIT3: So I figured if it was in your code, it might work better as a call, but if you aren't using it for anything else, place it inline to save 3 bytes.