[A83] Re: sprite routine


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

[A83] Re: sprite routine




I'm sure this is in numerous tutorials, but I'll explain anyway.

There are two ways you can draw a sprite without a mask.  You can have the
off pixels be drawn as off, or you can have them transparent (i.e. if they
are on in the background they stay on, otherwise they stay off).

With a mask, you have the pixels in the sprite, then you have the mask.  The
mask determines what to do if the pixel is off.  The most common format for
masks, and the use used by Assembly Studio 8x's sprite editor, is for the
mask to represent solid pixels.  Pixels that are on in the sprite are always
on in the mask.  Pixels that are white (drawn as off) are off in the sprite
and on in the mask.  Clear pixels are off in both.

To render the sprite, you first invert (NOT) the mask.  All the clear bits
will be set, and the non clear bits will be unset.  You then AND this with
the screen.  This will leave any bits on the screen that should be left on,
and clear the rest.  You then OR the sprite data with the result, to get the
resulting data for the screen.

Note that if you go looking at the Zelda 86 sprite routines, the comments
about the AND/OR operations have the registers mixed up, so they say that
the opposite is happening, which wouldn't work.  The comments above where
the registers are loaded are correct.  Don't always trust comments.  When in
doubt, read the source :)

Incidentally, this is a very good reason why not to comment every single
line of source code.  A one or two line comment describing the purpose of a
routine, along with it's inputs and outputs, is much better.

> That was a really good hint, but I'd want it masked (I mean, I want the
whole
> background of the sprite cleared). How to do that?





References: