+#include "sprite.h"
+#include "vdp.h"
+#include "demo.h"
+#include "parts.h"
+
+static void particle(int x, int y, int sz);
+
+#define SPRITE_BASE 0x8000
+extern uint16_t cellspr_data[], cellspr_data_end[];
+extern unsigned char cellspr_cmap[], cellspr_cmap_end[];
+
+
+void dna_init(void)
+{
+ int i;
+ uint16_t *src;
+ unsigned char *cptr;
+
+ cptr = cellspr_cmap;
+ for(i=0; i<16; i++) {
+ vdp_setcolor(0, i, i, i, i);
+ vdp_setcolor(1, i, cptr[0] >> 4, cptr[1] >> 4, cptr[2] >> 4);
+ cptr += 3;
+ }
+
+ /* upload sprite tiles */
+ src = cellspr_data;
+ vdp_setup_addr(VDP_VRAM, SPRITE_BASE);
+ while(src < cellspr_data_end) {
+ VDP_DATA = *src++;
+ }
+}
+
+void dna_update(void)
+{
+ particle(160, 120, frameno & 0x1f);
+}
+
+static void particle(int x, int y, int sz)
+{
+ int tile;
+
+ sz >>= 3; /* pixels to levels */
+ if(sz > 4) sz = 4;
+ tile = VDP_ADDR2TILE(SPRITE_BASE) + sz;
+
+ switch(sz) {
+ case 0:
+ case 1:
+ case 2:
+ spr_add(x - 4, y - 4, VDP_TILENAME(tile, 1, VDP_TILE_FG), SPR_SIZE(1, 1));
+ break;
+
+ case 3:
+ spr_add(x - 8, y - 8, VDP_TILENAME(tile, 1, VDP_TILE_FG), SPR_SIZE(1, 1));
+ spr_add(x, y - 8, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_HFLIP), SPR_SIZE(1, 1));
+ spr_add(x - 8, y, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_VFLIP), SPR_SIZE(1, 1));
+ spr_add(x, y, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_HVFLIP), SPR_SIZE(1, 1));
+ break;
+
+ case 4:
+ spr_add(x - 16, y - 16, VDP_TILENAME(tile, 1, VDP_TILE_FG), SPR_SIZE(2, 2));
+ spr_add(x, y - 16, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_HFLIP), SPR_SIZE(2, 2));
+ spr_add(x - 16, y, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_VFLIP), SPR_SIZE(2, 2));
+ spr_add(x, y, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_HVFLIP), SPR_SIZE(2, 2));
+ break;
+ }
+}