;*************************************; ;* Find Pixel Routine *; ;*************************************; ; By Yi Lang Mok ; ; 18 instruction -| Assembly ; ; 24 bytes |- Studio ; ; 127 cycles _| 8x ; ; approx 134 cycles counting bus load ; ; ; ; Inputs: (d,e) = (x, y) ; ; bc = base address of mem ; ; Output: hl = address of pixel ; ; a = bit number ; ; b, d, e destroyed ; ;*************************************; ;bc is the base address (eg $fc00 for normal screen) that ;is added onto the address derived from just the x and the ;y coordinates. It can be changed to write to different ;memory position, eg for greyscale use or for buffering. _FindPixelAddress: ld a, d ; a = x sla e ; e = e * 2 = y * 2 sla e ; e = e * 4 = y * 2 ld h, $00 ; h = 0 ld l, e ; l = y so hl = $00(y) add hl, hl ; hl = hl * 2 = y * 8 add hl, hl ; hl = hl * 4 = y * 16 add hl, bc ; hl = e * 16 + base and %11111000 ; for rotation to get x / 8 rrca ; a = a / 2 = x / 2 rrca ; a = a / 4 = x / 4 rrca ; a = a / 8 = x / 8 ld e, a ; e = a = x / 8 ld a, d ; a = x and %00000111 ; a = x - int(x / 8) * 8 = x mod 8 ld d, $00 ; d = 0 add hl, de ; hl = y * 16 + base + x / 8 ret