A86: FindPixel in 84 cycles and 19 bytes!
[Prev][Next][Index][Thread]
A86: FindPixel in 84 cycles and 19 bytes!
; Here it is: a FindPixel using only 84 clock cycles and 19 bytes!
; Call with H = Y coordinate, L = X coordinate
; Returns with A = pixel mask, DE = pixel address
Find_Pixel:
ld de,offsetstable
ld a,l
and 7
add a,e
ld e,a
adc a,d
sub e
ld d,a
ld a,(de) ;48 cycles so far
set 7,h
sla l
ld e,(hl)
inc hl
ld d,(hl) ;84 cycles total
ret
offsetstable:
.db 128,64,32,16,8,4,2,1
; One little inconvenience with this routine is that you must
; initialize it first by calling this routine. The initialization only
; needs to be done once at the start of your program, and you can then
; forget about it. Also, you cannot use any memory in $8000-$BFFF.
; This routine takes about 1/8 of a second, so it should not be
; very noticeable when the program starts.
Find_Pixel_Init:
ld hl,$8000
ld de,$fc00
loop_calc_pixels:
ld b,8
loop_store_addr:
ld (hl),e
inc hl
ld (hl),d
inc hl
djnz loop_store_addr
inc de
ld a,d
or e
jr nz,loop_calc_pixels
ret
; I'm not really sure if there is any use in this particular routine,
; but there might be. Variables which should be initialized with
; specific values at the start of the program can be put inside the
; program's code, and temporary variables can be put in text memory, so
; this thing taking $8000-$BFFF shouldn't be a problem. If you really
; need a fast FindPixel, it might be worth it....
.end
--
Patrick Davidson (ariwsi@juno.com)
Visit my home page! Stuff for Amiga, TI-85, TI-92, even DOS!
http://www.calweb.com/~kwdavids/patrick/
http://www.toptown.com/hp/ariwsi/
Follow-Ups:
References: