X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=retrocrawl;a=blobdiff_plain;f=src%2Fsprite.c;fp=src%2Fsprite.c;h=3a0088189f4152045b586f9916000a808bc67e7d;hp=0000000000000000000000000000000000000000;hb=290fe3c6727ce61652276d0e01357d25ea050366;hpb=235d7bf1e33fbd2977cc3b513edcec7c11cadf48 diff --git a/src/sprite.c b/src/sprite.c new file mode 100644 index 0000000..3a00881 --- /dev/null +++ b/src/sprite.c @@ -0,0 +1,67 @@ +#include +#include "sprite.h" + +#define MAX_SPRITES 32 + +static int scount; +static sprite *spr[MAX_SPRITES]; +static sprite *hwspr[4]; /* 4 channels because we support only attached sprites */ + +void begin_sprites(void) +{ + scount = 0; + memset(hwspr_used, 0, sizeof hwspr_used); +} + +void end_sprites(void) +{ + int i, j; + + /* sort sprites by increasing start position */ + for(i=0; iy < spr[i]->y) { + struct sprite *tmp = spr[i]; + spr[i] = spr[j]; + spr[j] = tmp; + } + } + } + + /* set sprite positions and populate copperlist to draw + * hardware sprites + */ + for(i=0; ix; + uint16_t sy = 0x2c + s->y; + uint16_t vstop = sy + s->height; + + int chan = -1; + for(j=0; j<4; j++) { + if(!hwspr[j] || hwspr[j]->y + hwspr[j]->height < s->y) { + chan = j; + hwspr[j] = s; + } + } + if(chan == -1) continue; + + for(j=0; jhwslices; j++) { + s->hwspr[idx][0] = s->hwspr[idx + 1][0] = (sx >> 1) | (sy << 8); + s->hwspr[idx][1] = s->hwspr[idx + 1][1] = (vstop << 8) | + ((vstop >> 7) & 2) | (sx & 1) | 0x80; + } + } +} + +void draw_sprite(struct sprite *s, int x, int y) +{ + if(s->img) { + /* blitter sprite */ + } else { + /* hw sprites */ + spr[scount++] = s; + s->x = x - origx; + s->y = y - origy; + } +}