[Main] Name=Sprite8 Type=Function Subtype=tigcc.a Header Files=sprites.h Definition=void Sprite8 (short x, short y, short height, const unsigned char *sprite, void *vm_addr, short mode); [Library Call] Asm=1 [Registers] x=d0 y=d1 height=d2 sprite=a0 vm_addr=a1 mode=d3 [Description] Draws a sprite with a width of 8 pixels or less on the screen. [Explanation] Sprite8 draws a sprite with a width of 8 pixels or less on the screen. Use Sprite16 or Sprite32 for wider sprites. This routine is many times faster than TIOS routines like DrawIcon, BitmapPut, etc. x and y are the coordinates of the upper left corner of the sprite. height is the height of the sprite. sprite is a pointer to the array of unsigned characters which define the shape of the sprite (line by line). vm_addr is the pointer to the video plane; it should be LCD_MEM if you are not using grayscale or the PortSet function. mode is the drawing mode, and it may have one of the following values (these constants are defined in the enum SprtModes):

SPRT_XOR XOR the sprite into a background. This is used only for non-masked sprites. XOR mode switches every pixel with a corresponding '1' bit in the sprite array from white to black and verse vica.
SPRT_OR OR the sprite into a background. This is mainly used for masked sprites together with SPRT_AND. OR means that every pixel with a corresponding '1' bit in the sprite array will be set to black, but all other pixels stay the same. If you want to turn all other pixels to white instead, use SPRT_RPLC.
SPRT_AND AND the sprite into a background. This is used for masked sprites together with SPRT_OR. AND turns off every pixel with a corresponding '0' bit in the sprite array, but all other pixels remain untouched. If you want to turn all other pixels to black instead, use SPRT_RPLC.
SPRT_RPLC RePLaCe the sprite into a background. RPLC sets every pixel with a corresponding '1' bit to black and every pixel with a corresponding '0' bit to white. This is equivalent to calling Sprite8(x,y,h,sprite,plane,SPRT_AND); Sprite8(x,y,h,sprite,plane,SPRT_OR);.

In fact, you can use one of two techniques to draw sprites: Here is a simple example (called "Masked Sprite"), which first draws a simple "background", then draws a "masked" sprite (which is a simple 8x8 square with solid edges and blank interior) at (30,30): $$EXAMPLE(Masked Sprite.c) Here the sprite mask is {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, but it needs to be inverted before passing it to the Sprite8 function. For this purpose, the operator '~' may be very useful. Note that '~' is "bitwise NOT". Of course, ~0xFF is the same as 0x00, but this notation makes the program more clear (and it does not increase the code size, because the inverting will be performed at compilation time). And if you want to use Sprite16 or Sprite32, the notation ~0xFF will still be valid in a short int array, or in a long int array if you add the 'L' suffix (see the respective info about Sprite32). Without this notation, you must use 0x00 in Sprite8, but 0xFF00 in Sprite16, and 0xFFFFFF00 in Sprite32. This is why a notation like ~0xFF is more universal.

Starting from TIGCC v0.91, you can use binary numbers to define your sprites. On the one hand, it makes the program incompatible with other C dialects as well as previous (ancient) versions of TIGCC. On the other hand, it makes designing a sprite much easier and also allows for editing the sprite at a later time without having to reconvert it. The binary representation of the sprite presented above would look like this:
static const unsigned char sprite[]={
0b11111111,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b11111111};