9 static struct sprite *spr[MAX_SPRITES];
10 static struct sprite *hwspr[4]; /* 4 channels because we support only attached sprites */
12 static uint16_t nullspr[] = {
17 static uint32_t nullspr_addr = (intptr_t)nullspr;
19 static uint32_t *coplist;
22 void begin_sprites(void)
25 memset(hwspr, 0, sizeof hwspr);
27 coplist = copperlist_end;
30 void end_sprites(void)
34 copperlist_end = coplist;
36 /* initially point all sprites to the null sprite */
39 add_copper(COPPER_MOVE(reg, nullspr_addr >> 16));
40 add_copper(COPPER_MOVE(reg + 2, nullspr_addr));
44 /* sort sprites by increasing start position */
45 for(i=0; i<scount; i++) {
46 for(j=i+1; j<scount; j++) {
47 if(spr[j]->y < spr[i]->y) {
48 struct sprite *tmp = spr[i];
55 /* set sprite positions and populate copperlist to draw
58 for(i=0; i<scount; i++) {
59 struct sprite *s = spr[i];
60 uint16_t sx = 0x80 + s->x;
61 uint16_t sy = 0x2c + s->y;
62 uint16_t vstop = sy + s->height;
69 if(!hwspr[j] || hwspr[j]->y + hwspr[j]->height < s->y) {
73 chan[nchan_found++] = j;
75 if(nchan_found >= s->hwslices) {
80 if(nchan_found < s->hwslices) continue;
83 add_copper(COPPER_VWAIT(sy));
86 for(j=0; j<s->hwslices; j++) {
87 int idx = chan[j] * 2;
88 reg = REGN_SPR0PTH + idx * 4;
90 s->hwspr[idx][0] = s->hwspr[idx + 1][0] = (sx >> 1) | (sy << 8);
91 s->hwspr[idx][1] = s->hwspr[idx + 1][1] = (vstop << 8) |
92 ((vstop >> 7) & 2) | (sx & 1) | 0x80;
94 addr = (intptr_t)s->hwspr[idx];
95 add_copper(COPPER_MOVE(reg, addr >> 16));
96 add_copper(COPPER_MOVE(reg + 2, addr));
98 addr = (intptr_t)s->hwspr[idx + 1];
99 add_copper(COPPER_MOVE(reg, addr >> 16));
100 add_copper(COPPER_MOVE(reg + 2, addr));
106 *copperlist_end = COPPER_END;
107 copperlist_end = coplist;
110 void draw_sprite(struct sprite *s, int x, int y)