finished the tile deduplication and tilemap generation in pngdump
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 6 Jan 2024 20:19:56 +0000 (22:19 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 6 Jan 2024 20:19:56 +0000 (22:19 +0200)
.gitignore
Makefile
doc/vmem
src/data.s
src/part_life.c [new file with mode: 0644]
tools/pngdump/tiles.c

index 8497e91..0f77bed 100644 (file)
@@ -12,3 +12,6 @@ disasm
 *.json
 *.png
 data/
+*.img
+*.tmap
+*.cmap
index 107e9d9..bcbcdc5 100644 (file)
--- 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 $<
index efdd934..dfbf3c6 100644 (file)
--- 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
index ad75a4c..574b140 100644 (file)
@@ -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 (file)
index 0000000..6a7affd
--- /dev/null
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdint.h>
+#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;
+       }
+}
index 92f404f..9421a06 100644 (file)
@@ -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<ntiles; i++) {
                if(memcmp(pa, pb, tilesz) == 0) {