Skip to content

Commit

Permalink
added small sprites example
Browse files Browse the repository at this point in the history
  • Loading branch information
steux committed Aug 30, 2023
1 parent 791fbe1 commit a5c7347
Show file tree
Hide file tree
Showing 2 changed files with 230 additions and 0 deletions.
60 changes: 60 additions & 0 deletions examples/example_small_sprites.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "prosystem.h"
#include "multisprite.h"

char i, xpos, ypos;

#define NB_SMALL_SPRITES 64
ramchip short sp_xpos[NB_SMALL_SPRITES], sp_ypos[NB_SMALL_SPRITES];
ramchip char sp_direction[NB_SMALL_SPRITES];

const signed short dx[24] = {300, 289, 259, 212, 149, 77, 0, -77, -150, -212, -259, -289, -300, -289, -259, -212, -149, -77, 0, 77, 149, 212, 259, 289};
const signed short dy[24] = {0, 124, 240, 339, 415, 463, 480, 463, 415, 339, 240, 124, 0, -124, -239, -339, -415, -463, -480, -463, -415, -339, -240, -124};
const char horizontal_pingpong[24] = { 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13 };
const char vertical_pingpong[24] = { 0, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };

// Generated with sprites7800 missile.yaml
holeydma reversed scattered(16,1) char missile[16] = {
0x18, 0x96, 0x7a, 0x7e, 0x7e, 0x6e, 0x9a, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
holeydma reversed scattered(16,1) char missile_ex[16] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x96, 0x7a, 0x7e, 0x7e, 0x6e, 0x9a, 0x28
};

void main()
{
multisprite_init();

*P0C1 = multisprite_color(0x1c); // Yellow
*P0C2 = multisprite_color(0x37); // Orange
*P0C3 = multisprite_color(0x43); // Red

// Initialize small sprites
for (ypos = 0, xpos = 0, i = 0, X = 0; X != NB_SMALL_SPRITES; xpos++, ypos++, X++) {
sp_xpos[X] = xpos << 8;
sp_ypos[X] = ypos << 8;
sp_direction[X] = i++;
if (i == 24) i = 0;
}

// Main loop
do {
multisprite_flip();
for (i = 0; i != NB_SMALL_SPRITES; i++) {
X = i;
Y = sp_direction[X];
sp_xpos[X] += dx[Y];
sp_ypos[X] += dy[Y];
xpos = sp_xpos[X] >> 8;
ypos = sp_ypos[X] >> 8;
if ((xpos < 5 && (dx[Y] >> 8) < 0) ||
(xpos >= 150 && (dx[Y] >> 8) >= 0)) {
sp_direction[X] = horizontal_pingpong[Y];
}
if ((ypos < 5 && (dy[Y] >> 8) < 0) ||
(ypos >= MS_YMAX - 20 && (dy[Y] >> 8) >= 0)) {
sp_direction[X] = vertical_pingpong[Y];
}
multisprite_display_small_sprite(xpos, ypos, missile, 1, 0);
}
} while(1);
}
170 changes: 170 additions & 0 deletions headers/multisprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,92 @@ void multisprite_flip();
}\
}

#define multisprite_display_small_sprite(x, y, gfx, width, palette) \
_ms_tmp2 = (y) + _ms_vscroll_offset; \
_ms_tmp = _ms_tmp2 & 0x0f; \
X = _ms_shift4[Y = (_ms_tmp2 & 0xfe | _ms_buffer)]; \
_ms_dldma[X] -= (8 + width * 3 + 1) / 2; \
if (_ms_dldma[X] < 0) { \
_ms_dmaerror++; \
_ms_dldma[X] += (8 + width * 3 + 1) / 2; \
} else { \
_ms_tmpptr = _ms_dls[X]; \
Y = _ms_dlend[X]; \
if (Y >= _MS_DL_SIZE - 6) { \
_ms_dmaerror++; \
} else { \
_ms_tmpptr[Y++] = (gfx); \
_ms_tmpptr[Y++] = -width & 0x1f | (palette << 5); \
_ms_tmpptr[Y++] = ((gfx) >> 8) | _ms_tmp; \
_ms_tmpptr[Y++] = (x); \
_ms_dlend[X] = Y; \
if (_ms_tmp >= 8) { \
X++; \
_ms_dldma[X] -= (8 + width * 3 + 1) / 2; \
if (_ms_dldma[X] < 0) { \
_ms_dmaerror++; \
_ms_dldma[X] += (8 + width * 3 + 1) / 2; \
} else { \
_ms_tmpptr = _ms_dls[X]; \
Y = _ms_dlend[X]; \
if (Y >= _MS_DL_SIZE - 6) { \
_ms_dmaerror++; \
} else { \
_ms_tmpptr[Y++] = (gfx) + (width); \
_ms_tmpptr[Y++] = -width & 0x1f | (palette << 5); \
_ms_tmpptr[Y++] = ((gfx) >> 8) - 0x18 + _ms_tmp; \
_ms_tmpptr[Y++] = (x); \
_ms_dlend[X] = Y; \
} \
} \
}\
}\
}

#define multisprite_display_sprite_ex(x, y, gfx, width, palette, mode) \
_ms_tmp2 = (y) + _ms_vscroll_offset; \
_ms_tmp = _ms_tmp2 & 0x0f; \
X = _ms_shift4[Y = (_ms_tmp2 & 0xfe | _ms_buffer)]; \
_ms_dldma[X] -= (8 + width * 3 + 1) / 2; \
if (_ms_dldma[X] < 0) { \
_ms_dmaerror++; \
_ms_dldma[X] += (8 + width * 3 + 1) / 2; \
} else { \
_ms_tmpptr = _ms_dls[X]; \
Y = _ms_dlend[X]; \
if (Y >= _MS_DL_SIZE - 7) { \
_ms_dmaerror++; \
} else { \
_ms_tmpptr[Y++] = (gfx); \
_ms_tmpptr[Y++] = (mode)?0xc0:0x40; \
_ms_tmpptr[Y++] = ((gfx) >> 8) | _ms_tmp; \
_ms_tmpptr[Y++] = -width & 0x1f | (palette << 5); \
_ms_tmpptr[Y++] = (x); \
_ms_dlend[X] = Y; \
if (_ms_tmp2 & 0x0f) { \
X++; \
_ms_dldma[X] -= (8 + width * 3 + 1) / 2; \
if (_ms_dldma[X] < 0) { \
_ms_dmaerror++; \
_ms_dldma[X] += (8 + width * 3 + 1) / 2; \
} else { \
_ms_tmpptr = _ms_dls[X]; \
Y = _ms_dlend[X]; \
if (Y >= _MS_DL_SIZE - 7) { \
_ms_dmaerror++; \
} else { \
_ms_tmpptr[Y++] = (gfx); \
_ms_tmpptr[Y++] = (mode)?0xc0:0x40; \
_ms_tmpptr[Y++] = (((gfx) >> 8) - 0x10) | _ms_tmp; \
_ms_tmpptr[Y++] = -width & 0x1f | (palette << 5); \
_ms_tmpptr[Y++] = (x); \
_ms_dlend[X] = Y; \
} \
} \
}\
}\
}

#define multisprite_display_sprite_fast(x, y, gfx, width, palette) \
_ms_tmp2 = (y) + _ms_vscroll_offset; \
_ms_tmp = _ms_tmp2 & 0x0f; \
Expand Down Expand Up @@ -234,6 +320,90 @@ void multisprite_flip();
}\
}

#define multisprite_display_small_sprite(x, y, gfx, width, palette) \
_ms_tmp = (y) & 0x0f; \
X = _ms_shift4[Y = (y & 0xfe | _ms_buffer)]; \
_ms_dldma[X] -= (8 + width * 3 + 1) / 2; \
if (_ms_dldma[X] < 0) { \
_ms_dmaerror++; \
_ms_dldma[X] += (8 + width * 3 + 1) / 2; \
} else { \
_ms_tmpptr = _ms_dls[X]; \
Y = _ms_dlend[X]; \
if (Y >= _MS_DL_SIZE - 6) { \
_ms_dmaerror++; \
} else { \
_ms_tmpptr[Y++] = (gfx); \
_ms_tmpptr[Y++] = -width & 0x1f | (palette << 5); \
_ms_tmpptr[Y++] = ((gfx) >> 8) | _ms_tmp; \
_ms_tmpptr[Y++] = (x); \
_ms_dlend[X] = Y; \
if (_ms_tmp >= 8) { \
X++; \
_ms_dldma[X] -= (8 + width * 3 + 1) / 2; \
if (_ms_dldma[X] < 0) { \
_ms_dmaerror++; \
_ms_dldma[X] += (8 + width * 3 + 1) / 2; \
} else { \
_ms_tmpptr = _ms_dls[X]; \
Y = _ms_dlend[X]; \
if (Y >= _MS_DL_SIZE - 6) { \
_ms_dmaerror++; \
} else { \
_ms_tmpptr[Y++] = (gfx) + (width); \
_ms_tmpptr[Y++] = -width & 0x1f | (palette << 5); \
_ms_tmpptr[Y++] = ((gfx) >> 8) - 0x18 + _ms_tmp; \
_ms_tmpptr[Y++] = (x); \
_ms_dlend[X] = Y; \
} \
} \
}\
}\
}

#define multisprite_display_sprite_ex(x, y, gfx, width, palette, mode) \
_ms_tmp = (y) & 0x0f; \
X = _ms_shift4[Y = (y & 0xfe | _ms_buffer)]; \
_ms_dldma[X] -= (8 + width * 3 + 1) / 2; \
if (_ms_dldma[X] < 0) { \
_ms_dmaerror++; \
_ms_dldma[X] += (8 + width * 3 + 1) / 2; \
} else { \
_ms_tmpptr = _ms_dls[X]; \
Y = _ms_dlend[X]; \
if (Y >= _MS_DL_SIZE - 7) { \
_ms_dmaerror++; \
} else { \
_ms_tmpptr[Y++] = (gfx); \
_ms_tmpptr[Y++] = (mode)?0xc0:0x40; \
_ms_tmpptr[Y++] = ((gfx) >> 8) | _ms_tmp; \
_ms_tmpptr[Y++] = -width & 0x1f | (palette << 5); \
_ms_tmpptr[Y++] = (x); \
_ms_dlend[X] = Y; \
if ((y) & 0x0f) { \
X++; \
_ms_dldma[X] -= (8 + width * 3 + 1) / 2; \
if (_ms_dldma[X] < 0) { \
_ms_dmaerror++; \
_ms_dldma[X] += (8 + width * 3 + 1) / 2; \
} else { \
_ms_tmpptr = _ms_dls[X]; \
Y = _ms_dlend[X]; \
if (Y >= _MS_DL_SIZE - 7) { \
_ms_dmaerror++; \
} else { \
_ms_tmpptr[Y++] = (gfx); \
_ms_tmpptr[Y++] = (mode)?0xc0:0x40; \
_ms_tmpptr[Y++] = (((gfx) >> 8) - 0x10) | _ms_tmp; \
_ms_tmpptr[Y++] = -width & 0x1f | (palette << 5); \
_ms_tmpptr[Y++] = (x); \
_ms_dlend[X] = Y; \
} \
} \
}\
}\
}

#define multisprite_display_sprite_fast(x, y, gfx, width, palette) \
_ms_tmp = (y) & 0x0f; \
X = _ms_shift4[Y = (y & 0xfe | _ms_buffer)]; \
Expand Down

0 comments on commit a5c7347

Please sign in to comment.