From 290fe3c6727ce61652276d0e01357d25ea050366 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Tue, 31 Jul 2018 20:15:18 +0300 Subject: [PATCH] sprites in progress --- src/sprite.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/sprite.h | 13 +++++++----- 2 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 src/sprite.c 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; + } +} diff --git a/src/sprite.h b/src/sprite.h index bd85467..0428ed0 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -1,20 +1,23 @@ #ifndef SPRITE_H_ #define SPRITE_H_ +#include + struct sprite { - int width, height; - int origx, origy; + int16_t x, y; + uint16_t width, height; + int16_t origx, origy; /* img/mask used for blitter sprites */ void *img, *mask; /* hardware sprite data */ - int hwslices; uint16_t *hwspr[8]; + uint8_t hwslices; }; -void begin_sprites(); -void end_sprites(); +void begin_sprites(void); +void end_sprites(void); void draw_sprite(struct sprite *s, int x, int y); #endif /* SPRITE_H_ */ -- 1.7.10.4