From df239da799038254f1cc9e5d7c40ae6f331bc41c Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 23 Dec 2023 16:30:55 +0200 Subject: [PATCH] starting part_dna --- src/data.s | 7 ++++++ src/demo.h | 11 +++++++++ src/main.c | 39 +++++++------------------------- src/part_dna.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/parts.h | 7 ++++++ 5 files changed, 101 insertions(+), 31 deletions(-) create mode 100644 src/demo.h create mode 100644 src/part_dna.c create mode 100644 src/parts.h diff --git a/src/data.s b/src/data.s index 4bb94b6..328fc12 100644 --- a/src/data.s +++ b/src/data.s @@ -4,6 +4,8 @@ .globl font8x8_data_end .globl cellspr_data .globl cellspr_data_end + .globl cellspr_cmap + .globl cellspr_cmap_end font8x8_data: .incbin "data/font8x8.img" font8x8_data_end: @@ -13,4 +15,9 @@ cellspr_data: .incbin "data/cellspr.img" cellspr_data_end: + .align 2 +cellspr_cmap: + .incbin "data/cellspr.cmap" +cellspr_cmap_end: + | vi:ft=gas68k: diff --git a/src/demo.h b/src/demo.h new file mode 100644 index 0000000..b72b158 --- /dev/null +++ b/src/demo.h @@ -0,0 +1,11 @@ +#ifndef DEMO_H_ +#define DEMO_H_ + +#include + +extern uint32_t frameno; + +void dna_init(void); +void dna_update(void); + +#endif /* DEMO_H_ */ diff --git a/src/main.c b/src/main.c index faa6b9e..261f1a5 100644 --- a/src/main.c +++ b/src/main.c @@ -2,32 +2,21 @@ #include "z80.h" #include "vdp.h" #include "sprite.h" +#include "parts.h" #include "debug.h" -#define SPRITE_BASE 0x8000 -extern uint16_t cellspr_data[], cellspr_data_end[]; - +uint32_t frameno; uint32_t dbgval[4]; int main(void) { - uint16_t *src; - int tile, i; + int i; z80_init(); vdp_init(); dbg_init(); - for(i=0; i<16; i++) { - vdp_setcolor(0, i, i, i, i); - } - - /* upload sprite tiles */ - src = cellspr_data; - vdp_setup_addr(VDP_VRAM, SPRITE_BASE); - while(src < cellspr_data_end) { - VDP_DATA = *src++; - } + dna_init(); dbg_setcursor(0, 0); printf("xyzzy"); @@ -38,25 +27,13 @@ int main(void) printf("%08x\n", (unsigned int)dbgval[i]); } spr_begin(); - tile = VDP_ADDR2TILE(SPRITE_BASE); - spr_add(160, 50, VDP_TILENAME(tile, 0, VDP_TILE_FG), SPR_SIZE(1,1)); - tile++; - spr_add(160, 60, VDP_TILENAME(tile, 0, VDP_TILE_FG), SPR_SIZE(1,1)); - tile++; - spr_add(160, 75, VDP_TILENAME(tile, 0, VDP_TILE_FG), SPR_SIZE(1,1)); - tile++; - spr_add(156, 90, VDP_TILENAME(tile, 0, VDP_TILE_FG), SPR_SIZE(1,1)); - spr_add(164, 90, VDP_TILENAME(tile, 0, VDP_TILE_FG | VDP_TILE_HFLIP), SPR_SIZE(1,1)); - spr_add(156, 98, VDP_TILENAME(tile, 0, VDP_TILE_FG | VDP_TILE_VFLIP), SPR_SIZE(1,1)); - spr_add(164, 98, VDP_TILENAME(tile, 0, VDP_TILE_FG | VDP_TILE_HVFLIP), SPR_SIZE(1,1)); - tile++; - spr_add(148, 120, VDP_TILENAME(tile, 0, VDP_TILE_FG), SPR_SIZE(2, 2)); - spr_add(164, 120, VDP_TILENAME(tile, 0, VDP_TILE_FG | VDP_TILE_HFLIP), SPR_SIZE(2, 2)); - spr_add(148, 136, VDP_TILENAME(tile, 0, VDP_TILE_FG | VDP_TILE_VFLIP), SPR_SIZE(2, 2)); - spr_add(164, 136, VDP_TILENAME(tile, 0, VDP_TILE_FG | VDP_TILE_HVFLIP), SPR_SIZE(2, 2)); + + dna_update(); vdp_wait_vblank(); spr_submit(); + + frameno++; } return 0; diff --git a/src/part_dna.c b/src/part_dna.c new file mode 100644 index 0000000..da0d5a0 --- /dev/null +++ b/src/part_dna.c @@ -0,0 +1,68 @@ +#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; + } +} diff --git a/src/parts.h b/src/parts.h new file mode 100644 index 0000000..85977f5 --- /dev/null +++ b/src/parts.h @@ -0,0 +1,7 @@ +#ifndef PARTS_H_ +#define PARTS_H_ + +void dna_init(void); +void dna_update(void); + +#endif /* PARTS_H_ */ -- 1.7.10.4