1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-22 14:33:51 +00:00
8bitworkshop/presets/c64/sprites.c

70 lines
1.6 KiB
C
Raw Normal View History

2020-02-02 18:17:31 +00:00
#include <string.h>
#include "sprites.h"
SpriteShadow sprshad;
void sprite_clear(void) {
memset(&sprshad, 0, sizeof(sprshad));
}
2022-08-11 20:27:20 +00:00
void sprite_update(byte* screenmem) {
2022-07-20 19:32:47 +00:00
memcpy(screenmem + 0x3f8, sprshad.spr_shapes, 8);
2020-02-02 18:17:31 +00:00
memcpy(VIC.spr_pos, sprshad.spr_pos, 16);
memcpy(VIC.spr_color, sprshad.spr_color, 8);
2022-07-20 19:32:47 +00:00
VIC.spr_ena = sprshad.spr_ena;
VIC.spr_hi_x = sprshad.spr_hi_x;
2020-02-02 18:17:31 +00:00
VIC.spr_exp_x = sprshad.spr_exp_x;
VIC.spr_exp_y = sprshad.spr_exp_y;
VIC.spr_bg_prio = sprshad.spr_bg_prio;
VIC.spr_mcolor = sprshad.spr_mcolor;
}
2022-08-11 20:27:20 +00:00
void sprite_set_shapes(const void* sprite_data,
byte index,
byte count)
{
2022-08-09 14:47:55 +00:00
memcpy(get_vic_bank_start() + index * 64,
sprite_data,
2022-08-11 20:27:20 +00:00
64 * count);
2020-02-02 18:17:31 +00:00
}
2020-02-04 17:58:46 +00:00
const byte BITS[8] = {
2022-08-09 14:47:55 +00:00
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
2020-02-04 17:58:46 +00:00
};
2020-02-02 18:17:31 +00:00
void sprite_draw(byte i, word x, byte y, byte shape) {
2020-02-04 17:58:46 +00:00
byte mask = BITS[i]; // 1 << i;
2020-02-02 18:17:31 +00:00
sprshad.spr_ena |= mask;
if (x >> 8)
sprshad.spr_hi_x |= mask;
else
sprshad.spr_hi_x &= ~mask;
sprshad.spr_pos[i].x = x;
sprshad.spr_pos[i].y = y;
sprshad.spr_shapes[i] = shape;
}
byte sprite_get_closest_collision(byte i, byte spr_coll) {
byte j;
byte jmask = 1;
byte dx,dy;
if (spr_coll & BITS[i]) {
spr_coll ^= BITS[i];
for (j=0; j<8; j++, jmask<<=1) {
if (spr_coll & jmask) {
// TODO?
dx = sprshad.spr_pos[i].x - sprshad.spr_pos[j].x + 24;
if (dx < 48) {
dy = sprshad.spr_pos[i].y - sprshad.spr_pos[j].y + 21;
if (dy < 42) {
return j;
}
}
}
}
} else {
return 0xff;
}
2020-02-02 18:17:31 +00:00
}