home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- * spr_misc.c
- *
- * Miscellaneous (internal) utility routines for the sprite support
- **********************************************************************
- This file is part of
-
- STK -- The sprite toolkit -- version 1.1
-
- Copyright (C) Jari Karjala 1991
-
- The sprite toolkit (STK) is a FreeWare toolkit for creating high
- resolution sprite graphics with PCompatible hardware. This toolkit
- is provided as is without any warranty or such thing. See the file
- COPYING for further information.
-
- **********************************************************************/
-
-
- #include "sprP.h"
-
-
- /**********************************************************************
- * Shift the given shape and mask bitmaps given number of bits to the
- * right and combine the result bytewise as required in sprite data
- * buffer.
- *
- * shape The original bitmap
- * mask The original mask
- * step The size of the step to the right in pixels (0-7)
- * shift If zero then shape and mask are as wide as w (ie destination)
- * w The width of the destination bitmap
- * h The height of the bitmap
- * mask Pad the result with ones if this is non-zero
- * bp Pointer into the destination buffer
- **********************************************************************/
- static void shift_combine(BITMAP shape, BITMAP mask,
- BYTE step, BYTE shift, BYTE w, BYTE h, FARMAP bp)
- {
- WORD i,j;
- BYTE mask1;
-
- mask1 = 0xFF << (8-step);
-
- if (shift) /** shape/mask width is one less than given w **/
- w--;
-
- for (j=0; j < h; j++) { /* shift all scanlines */
- *bp++ = *shape >> step; /* first shape byte */
- *bp++ = (*mask >> step) | mask1; /* first mask byte */
- for (i=0; i < w-1; i++, shape++, mask++) { /* next bytes */
- *bp++ = (*shape << (8-step)) | (*(shape+1) >> step);
- *bp++ = (*mask << (8-step)) | (*(mask+1) >> step);
- }
- if (shift) { /** fix the shift overflow byte **/
- *bp++ = (*shape << (8-step));
- *bp++ = (*mask << (8-step)) | (0xFF >> step);
- }
- shape++;
- mask++;
- }
- }
-
- /**********************************************************************
- * Create the shape data from the given shape and mask bitmaps
- *
- * spr The sprite used
- * shape The shape bitmap
- * mask The mask bitmap
- * res The resolution used (1,2,4 or 8)
- **********************************************************************/
- void spr_misc_create_data(SPRITE spr, BITMAP shape, BITMAP mask)
- {
- WORD size = spr->size, i;
-
- if (spr->res==1)
- shift_combine(shape, mask, 0, 0, spr->w, spr->hp, spr->data);
- else
- for(i=0; i < spr->res; i++)
- shift_combine(shape, mask,
- (8/spr->res)*i,1, spr->w,spr->hp, spr->data+size*i);
- }
-
- /**********************************************************************
- * Shift the given shape into the destination buffer word aligned.
- *
- * shape The original bitmap
- * step The size of the step to the right in pixels (0-7)
- * shift If zero then shape and mask are as wide as w (ie destination)
- * w The width of the destination bitmap
- * h The height of the bitmap
- * mask Pad the result with ones if this is non-zero
- * bp Pointer into the destination buffer
- **********************************************************************/
- static void xor_shift(BITMAP shape,
- BYTE step, BYTE shift, BYTE w, BYTE h, FARMAP bp)
- {
- WORD i,j;
-
- if (shift) /** shape width is one less than given w **/
- w--;
-
- for (j=0; j < h; j++) { /* shift all scanlines */
- *bp++ = *shape >> step; /* first shape byte */
- for (i=0; i < w-1; i++, shape++) /* next bytes */
- *bp++ = (*shape << (8-step)) | (*(shape+1) >> step);
-
- if (shift) /** fix the shift overflow byte **/
- *bp++ = (*shape << (8-step));
-
- shape++;
- }
- }
-
- /**********************************************************************
- * Create the XOR shape data from the given shape bitmas
- *
- * spr The sprite used
- * shape The shape bitmap
- * mask The mask bitmap
- * res The resolution used (1,2,4 or 8)
- **********************************************************************/
- void spr_misc_create_xor_data(SPRITE spr, BITMAP shape)
- {
- WORD size = spr->size, i;
-
- if (spr->res==1)
- xor_shift(shape, 0, 0, spr->w, spr->hp, spr->data);
- else
- for(i=0; i < spr->res; i++)
- xor_shift(shape,
- (8/spr->res)*i,1, spr->w,spr->hp, spr->data+size*i);
- }
-
- /**********************************************************************
- * Delete the given sprite from the display list for the given page.
- * Set the coordinates of the sprite to (WORD)-1,(WORD)-1
- *
- * spr The sprite to delete
- * spr_page The page number (0/1)
- **********************************************************************/
- void spr_misc_delete(SPRITE spr, int spr_page)
- {
- SPRITE s;
-
- spr->x = spr->y = (WORD)-1;
-
- s = spr_sprites[spr_page];
- if (s==spr) /** it was the first one **/
- spr_sprites[spr_page] = spr_sprites[spr_page]->next[spr_page];
- else
- while (s!=NULL) {
- if (s->next[spr_page]!=NULL && s->next[spr_page]==spr) {
- s->next[spr_page] = s->next[spr_page]->next[spr_page];
- break;
- }
- s = s->next[spr_page];
- }
- }
-