home *** CD-ROM | disk | FTP | other *** search
- /**** esprite.c ****/
- /* By Paul Field
- * See !ReadMe file for distribution/modification restrictions
- */
-
- #include "esprite.h"
-
- #include <assert.h>
- #include <stdlib.h>
- #include "wimp.h"
- #include "bbc.h"
-
- static os_error nomem = {0, "Not enough memory - increase Wimpslot."};
-
- #if FALSE
- static void esprite_setcolour(int logical, wimp_paletteword col)
- { bbc_palette(logical, 16, col.bytes.red, col.bytes.green, col.bytes.blue);
- #if FALSE
- char block[5];
-
- block[0] = logical;
- block[1] = 16; /* Define colour by r,g,b */
- block[2] = col.bytes.red;
- block[3] = col.bytes.green;
- block[4] = col.bytes.blue;
- os_word(12,block);
- #endif
- }
-
-
- static void esprite_setwimppalette(void)
- { int maxcol;
-
- maxcol = bbc_vduvar(bbc_NColour);
- if (maxcol < 64)
- { wimp_palettestr palette;
-
- wimp_readpalette(&palette);
- switch(maxcol)
- { case 1:
- esprite_setcolour(0, palette.c[0]);
- esprite_setcolour(1, palette.c[7]);
- break;
- case 3:
- esprite_setcolour(0, palette.c[0]);
- esprite_setcolour(1, palette.c[2]);
- esprite_setcolour(2, palette.c[4]);
- esprite_setcolour(3, palette.c[7]);
- break;
- case 15:
- for (; maxcol >= 0; maxcol--)
- { esprite_setcolour(maxcol, palette.c[maxcol]);
- }
- break;
- }
- }
- }
- #endif
-
- os_error *esprite_draw(sprite_area **area, int offset, edraw_info *info)
- { int savesize;
- int *savearea;
- sprite_id id;
- os_error *e,*e2;
-
- id.tag = sprite_id_addr;
- id.s.addr = (char *)*area + offset;
-
- if ((e = sprite_sizeof_spritecontext(*area, &id, &savesize)) == NULL)
- { if ((savearea = malloc(savesize)) == NULL)
- { return(&nomem);
- }
- else
- { sprite_state state;
-
- savearea[0] = 0;
- id.s.addr = (char *)*area + offset; /* The malloc may have moved a flex block */
- if ((e = sprite_outputtosprite(*area, &id, savearea, &state)) == NULL)
- { euclid_invalidatepalettecache(); /* Don't know if this is needed */
- /* but best to be on the safe side */
- if (info->structure->cache)
- { *((unsigned int *)info->structure->cache + 1) = 0;
- }
- e = edraw_split(info);
- e2 = sprite_restorestate(state);
- if (!e)
- { e = e2;
- }
- euclid_invalidatepalettecache(); /* Don't know if this is needed */
- /* but best to be on the safe side */
- }
- free(savearea);
- }
- }
- return(e);
- }
-
-