Re: A85: FIND_PIXEL


[Prev][Next][Index][Thread]

Re: A85: FIND_PIXEL



Find_Pixel basically works like this.  It has 2 inputs.  register b,
the x position and register c, the y position.  the origin is the
bottom left hand corner (though most sprite routines use the origin as
the top left).  It then returns a value in hl which is the *byte*
offset in memory.  Every 8 pixels on the screen make up a byte.  For
each row of the video memory, there are 128 pixels.  So this means
that there are 16 bytes in a row of video memory.  So to move over 8
pixels in the x direction (from the origin), add one byte to hl.  To
move up one row (from the origin) add 16 to hl.  It also returns a bit
mask in a.  This bit mask is used to tell which pixel in the byte you
are trying to find.  the bit mask has a single 1 in it and the rest is
0's.  The 1 will tell you exactly which bit you are looking for.  So,
for example, if you have:
ld b,10			;x position
ld c,5			;y position
call FIND_PIXEL		;hl = offset, a = bit mask
ld de,VIDEO_MEM		;location of memory
add hl,de		;add the offset

After the call to FIND_PIXEL, hl contains c*16 + b/8.  The bit mask in
register a will contain %0010000.  This says that the 3rd pixel in
this byte is the one you are looking for.  The location of the bit
mask can be found using the remainder given by b%8.  If b%8 = 0, the
high bit of a is set, if b%8 = 7, the low bit is set, and of course,
all of the ones inbetween.  Hope that helped.

-mike pearce

On Tue, 19 Aug 97 13:23:00 -0500, you wrote:

>I've already read the ZShell Function Library and would like to use
>FIND_PIXEL.  The explanation provided was not very clear and I'd
>appreciate if someone could explain it to me.
>


Follow-Ups: References: