10 static struct sprite *spr[MAX_SPRITES];
11 static struct sprite *hwspr[4]; /* 4 channels because we support only attached sprites */
13 static uint16_t nullspr[] = {
18 static uint32_t nullspr_addr = (intptr_t)nullspr;
20 static uint32_t *coplist;
23 void begin_sprites(void)
26 memset(hwspr, 0, sizeof hwspr);
28 coplist = copperlist_end;
31 void end_sprites(void)
35 copperlist_end = coplist;
37 /* initially point all sprites to the null sprite */
40 add_copper(COPPER_MOVE(reg, nullspr_addr >> 16));
41 add_copper(COPPER_MOVE(reg + 2, nullspr_addr));
46 /* sort sprites by increasing start position */
47 for(i=0; i<scount; i++) {
48 for(j=i+1; j<scount; j++) {
49 if(spr[j]->y < spr[i]->y) {
50 struct sprite *tmp = spr[i];
58 /* set sprite positions and populate copperlist to draw
61 for(i=0; i<scount; i++) {
62 struct sprite *s = spr[i];
63 uint16_t sx = 0x80 + s->x;
64 uint16_t sy = 0x2c + s->y;
65 uint16_t vstop = sy + s->height;
72 if(!hwspr[j] || hwspr[j]->y + hwspr[j]->height < s->y) {
76 chan[nchan_found++] = j;
78 if(nchan_found >= s->hwslices) {
83 if(nchan_found < s->hwslices) continue;
86 printf("copper wait: %d\n", (int)s->y - 1);
87 add_copper(COPPER_VWAIT(s->y - 1));
90 for(j=0; j<s->hwslices; j++) {
91 int idx = chan[j] * 2;
92 reg = REGN_SPR0PTH + idx * 4;
94 s->hwspr[idx][0] = s->hwspr[idx + 1][0] = (sx >> 1) | (sy << 8);
95 s->hwspr[idx][1] = s->hwspr[idx + 1][1] = (vstop << 8) |
96 ((vstop >> 7) & 2) | (sx & 1) | 0x80;
98 addr = (intptr_t)s->hwspr[idx];
99 add_copper(COPPER_MOVE(reg, addr >> 16));
100 add_copper(COPPER_MOVE(reg + 2, addr));
102 addr = (intptr_t)s->hwspr[idx + 1];
103 add_copper(COPPER_MOVE(reg, addr >> 16));
104 add_copper(COPPER_MOVE(reg + 2, addr));
110 *copperlist_end = COPPER_END;
111 copperlist_end = coplist;
114 void draw_sprite(struct sprite *s, int x, int y)