From: John Tsiombikas Date: Sat, 6 Jan 2024 20:19:56 +0000 (+0200) Subject: finished the tile deduplication and tilemap generation in pngdump X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;ds=sidebyside;h=3ed6f84c7c0a45fc7813d1354a2ed38a750ff630;p=mdlife finished the tile deduplication and tilemap generation in pngdump --- diff --git a/.gitignore b/.gitignore index 8497e91..0f77bed 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ disasm *.json *.png data/ +*.img +*.tmap +*.cmap diff --git a/Makefile b/Makefile index 107e9d9..bcbcdc5 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,8 @@ $(z80bin): $(z80obj) disasm: $(elf) $(OBJDUMP) -D $< >$@ -src/data-asm.o: src/data.s data/font8x8.img data/cellspr.img +src/data-asm.o: src/data.s data/font8x8.img data/cellspr.img data/lifebg.tiles \ + data/lifefg.tiles src/z80prog-asm.o: src/z80prog.s $(z80bin) data/cellspr.img: data/cellspr.png @@ -96,5 +97,8 @@ PNGDUMP = tools/pngdump/pngdump $(PNGDUMP): tools/pngdump/main.c tools/pngdump/image.c tools/pngdump/quant.c $(MAKE) -C tools/pngdump +%.tiles: %.png $(PNGDUMP) + $(PNGDUMP) -o $@ -oc $(@:.tiles=.cmap) -om $(@:.tiles=.tmap) -T 8x8 -D $< + %.img: %.png $(PNGDUMP) $(PNGDUMP) -o $@ -oc $(@:.img=.cmap) -T 8x8 $< diff --git a/doc/vmem b/doc/vmem index efdd934..dfbf3c6 100644 --- a/doc/vmem +++ b/doc/vmem @@ -4,4 +4,5 @@ b400 font 96 glyphs * 8x8 / 2 = 3072 bytes c000 nametable A (64x32 * 2 = 4096) d000 nametable B e000 sprite table (?) +f000 horiz.scroll table ffff diff --git a/src/data.s b/src/data.s index ad75a4c..574b140 100644 --- a/src/data.s +++ b/src/data.s @@ -8,8 +8,14 @@ .globl cellspr_cmap_end .globl lifebg_data .globl lifebg_data_end - .globl lifefg_data - .globl lifefg_data_end + .globl lifebg_cmap + .globl lifebg_cmap_end + .globl lifebg_tmap + .globl lifebg_tmap_end + .globl lifefg_cmap + .globl lifefg_cmap_end + .globl lifefg_tmap + .globl lifefg_tmap_end font8x8_data: .incbin "data/font8x8.img" font8x8_data_end: @@ -26,23 +32,29 @@ cellspr_cmap_end: .align 2 lifebg_data: - .incbin "data/lifebg.img" + .incbin "data/lifebg.tiles" lifebg_data_end: - .align 2 lifebg_cmap: .incbin "data/lifebg.cmap" lifebg_cmap_end: + .align 2 +lifebg_tmap: + .incbin "data/lifebg.tmap" +lifebg_tmap_end: .align 2 lifefg_data: - .incbin "data/lifefg.img" + .incbin "data/lifefg.tiles" lifefg_data_end: - .align 2 lifefg_cmap: .incbin "data/lifefg.cmap" lifefg_cmap_end: + .align 2 +lifefg_tmap: + .incbin "data/lifefg.tmap" +lifefg_tmap_end: diff --git a/src/part_life.c b/src/part_life.c new file mode 100644 index 0000000..6a7affd --- /dev/null +++ b/src/part_life.c @@ -0,0 +1,41 @@ +#include +#include +#include "vdp.h" +#include "parts.h" + +extern uint16_t lifebg_data[], lifebg_data_end[]; +extern unsigned char lifebg_cmap[], lifebg_cmap_end[]; +extern uint16_t lifebg_tmap[], lifebg_tmap_end[]; + +void life_init(void) +{ + uint16_t *src; + + /* upload tiles */ + src = lifebg_data; + vdp_setup_addr(VDP_VRAM, 0); + while(src < lifebg_data_end) { + VDP_DATA = *src++; + } +} + +void life_start(void) +{ + int i; + uint16_t *src; + unsigned char *cptr; + + /* setup tilemaps */ + src = lifebg_tmap; + vdp_setup_addr(VDP_VRAM, 0xd000); /* nametable B */ + while(src < lifebg_tmap_end) { + VDP_DATA = VDP_TILENAME(*src++, 2, 0); + } + + /* setup colormaps */ + cptr = lifebg_cmap; + for(i=0; i<16; i++) { + vdp_setcolor(2, i, cptr[0] >> 4, cptr[1] >> 4, cptr[2] >> 4); + cptr += 3; + } +} diff --git a/tools/pngdump/tiles.c b/tools/pngdump/tiles.c index 92f404f..9421a06 100644 --- a/tools/pngdump/tiles.c +++ b/tools/pngdump/tiles.c @@ -50,18 +50,30 @@ int img2tiles(struct tilemap *tmap, struct image *img, int tw, int th, int dedup } } - if(!dedup || (tid = matchtile(img, tileoffs, th)) == -1) { - tmap->map[tileno] = tileno; - tileoffs += th; /* destination Y offset, inc by th for every tile */ + if(dedup) { + if((tid = matchtile(img, tileoffs, th)) == -1) { + if(tmap) { + tmap->map[tileno++] = tileoffs / th; + } + tileoffs += th; /* destination Y offset, inc by th for every tile */ + } else { + if(tmap) { + tmap->map[tileno++] = tid; + } + } } else { - tmap->map[tileno] = tid; + tileoffs += th; /* destination Y offset, inc by th for every tile */ } - tileno++; x += tw; } y += th; } + if(dedup) { + putchar('\n'); + img->height = tileoffs; + } + free(orig.pixels); return 0; } @@ -74,7 +86,7 @@ static int matchtile(struct image *img, int toffs, int th) tilesz = img->pitch * th; pa = (unsigned char*)img->pixels; - pb = (unsigned char*)img->pixels + toffs * tilesz; + pb = (unsigned char*)img->pixels + toffs * img->pitch; for(i=0; i