Skip to content

Commit 8e984ee

Browse files
Add actual compression to compressed tilemap demo
1 parent 83170bf commit 8e984ee

File tree

9 files changed

+86
-44
lines changed

9 files changed

+86
-44
lines changed

examples/gfx_tilemap_compress/src/main.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212

1313
/* Include the graphics */
1414
#include "gfx/tiles_gfx.h"
15+
#include "tilemap/tilemapdata.h"
1516

1617
/* Tilemap defines */
1718
#define TILE_WIDTH (16)
1819
#define TILE_HEIGHT (16)
19-
2020
#define TILE_SIZE ((TILE_WIDTH * TILE_HEIGHT) + 2) // +2 for width and height bytes
21+
2122
#define TILEMAP_WIDTH (32)
2223
#define TILEMAP_HEIGHT (25)
2324

@@ -27,8 +28,8 @@
2728
#define Y_OFFSET (16)
2829
#define X_OFFSET (0)
2930

30-
/* This is where the tilemap data is stored */
31-
extern uint8_t tilemap_map[];
31+
/* This is where the decompressed tilemap data is to be stored */
32+
uint8_t tilemap_map[TILEMAP_WIDTH * TILEMAP_HEIGHT];
3233

3334
/* Place to hold decompressed tile pointers */
3435
gfx_sprite_t *tileset_tiles[128];
@@ -41,16 +42,14 @@ void main(void) {
4142
unsigned int y_offset = 0;
4243
gfx_sprite_t *tmp_ptr;
4344
gfx_tilemap_t tilemap;
44-
45-
/* For linking purposes */
46-
malloc(0);
4745

4846
/* Decompress the tiles */
49-
for (i = 0; i < 128; i++) {
47+
for (i = 0; i < sizeof(tileset_tiles)/sizeof(gfx_sprite_t*) ; i++) {
5048
tmp_ptr = gfx_MallocSprite(TILE_WIDTH, TILE_HEIGHT);
5149
dzx7_Turbo(tileset_tiles_compressed[i], tmp_ptr); // or dzx7_Standard, but in this case we have a lot of tiles
5250
tileset_tiles[i] = tmp_ptr;
5351
}
52+
dzx7_Turbo(tilemap_compressed, tilemap_map);
5453

5554
/* Initialize the tilemap structure */
5655
tilemap.map = tilemap_map;
@@ -66,8 +65,8 @@ void main(void) {
6665
tilemap.y_loc = Y_OFFSET;
6766
tilemap.x_loc = X_OFFSET;
6867

69-
/* Initialize the 8bpp graphics */
70-
gfx_Begin(gfx_8bpp);
68+
/* Initialize the graphics scene */
69+
gfx_Begin();
7170

7271
/* Set up the palette */
7372
gfx_SetPalette(tiles_gfx_pal, sizeof tiles_gfx_pal, 0);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
4,5,2,0,1,2,3,2,3,0,1,2,3,2,0,1,2,3,0,0,0,0,1,2,3,4,5,0,1,2,4,5
2+
20,21,2,3,0,1,16,16,2,3,1,2,3,1,0,1,2,3,3,0,1,0,1,2,3,20,21,80,81,82,20,21
3+
4,5,80,81,82,1,16,16,1,2,3,1,16,16,16,16,16,16,16,0,1,2,0,1,2,36,37,96,97,98,4,5
4+
20,21,96,97,98,0,1,2,3,1,2,3,2,16,16,16,16,16,16,16,16,16,16,1,2,3,2,112,113,114,20,21
5+
4,5,112,113,114,0,1,2,3,3,1,2,3,3,0,1,2,3,0,1,2,3,0,0,1,2,3,2,3,0,4,5
6+
20,21,3,3,3,0,1,2,3,2,3,1,2,3,0,1,2,0,1,2,3,3,3,0,1,2,16,16,16,3,20,21
7+
4,5,3,3,2,0,1,2,3,2,3,0,1,2,0,1,2,0,1,2,3,2,3,0,1,2,16,2,3,3,4,5
8+
20,21,3,3,2,0,1,2,3,16,16,16,16,16,16,1,0,1,2,3,0,1,2,0,1,2,16,2,3,2,20,21
9+
4,5,3,3,2,16,16,16,16,16,16,16,16,16,16,16,0,1,2,3,2,80,81,82,1,2,3,1,2,3,4,5
10+
20,21,3,2,3,0,1,2,3,1,2,3,2,0,0,0,1,2,3,1,2,96,97,100,1,2,3,1,2,0,20,21
11+
4,5,3,1,2,3,1,2,3,1,2,0,1,2,0,0,1,2,3,1,2,112,115,116,0,1,2,3,2,0,4,5
12+
20,21,3,0,1,2,3,2,3,0,1,0,0,0,1,0,1,2,3,1,2,3,96,98,0,1,0,1,2,0,20,21
13+
4,5,3,0,32,33,33,34,3,0,16,16,16,16,16,16,16,2,3,3,1,2,96,98,3,0,0,1,2,2,4,5
14+
20,21,3,1,48,49,49,50,3,0,1,16,16,16,16,16,16,16,16,16,1,2,96,98,3,0,0,16,2,0,20,21
15+
4,5,3,1,64,83,84,66,3,0,0,1,16,16,16,16,16,16,16,16,16,2,96,98,0,0,16,16,2,2,4,5
16+
20,21,3,1,2,48,50,2,3,0,0,1,2,3,3,2,3,0,2,3,1,2,96,98,16,16,16,16,2,3,20,21
17+
4,5,3,0,1,48,50,2,3,0,0,1,2,3,2,3,3,0,2,3,1,2,96,98,16,16,16,16,2,3,4,5
18+
20,21,3,0,1,48,50,2,3,3,2,0,1,2,3,3,3,80,82,2,3,2,96,98,16,16,16,16,2,3,20,21
19+
4,5,3,0,0,48,50,3,2,3,0,0,0,1,2,3,3,96,100,81,81,81,99,98,3,3,16,16,2,2,4,5
20+
20,21,0,1,0,48,50,16,16,16,16,1,0,1,2,3,80,99,116,113,113,113,113,114,2,3,0,16,2,3,20,21
21+
4,5,0,0,1,48,50,0,16,16,16,16,0,1,2,3,96,97,98,16,2,3,2,3,2,3,0,1,2,3,4,5
22+
20,21,1,0,1,48,50,0,1,2,3,0,0,1,2,3,112,113,114,3,2,3,2,3,2,3,0,1,2,3,20,21
23+
36,37,0,1,2,48,50,0,0,0,0,0,0,0,0,0,1,2,3,1,2,3,2,3,16,3,0,1,2,3,4,5
24+
33,33,33,33,33,67,68,33,33,33,33,33,34,0,1,2,3,0,0,1,2,3,2,16,16,3,0,0,1,2,20,21
25+
65,65,65,65,65,65,65,65,65,65,65,65,66,0,1,2,3,0,1,0,1,16,16,16,16,3,1,2,3,0,36,37
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Converted using ConvTile
2+
#include <stdint.h>
3+
4+
uint8_t tilemap_compressed[339] = {
5+
0x04,0x03,0x05,0x02,0x00,0x01,0x02,0x03,0x01,0xBB,0x05,0x0A,0xFB,0x08,0x00,0x06,0xEB,0x18,0x05,0x04,0x2C,0x14,0x15,0x1A,0x10,0x10,0xFE,0x05,0x0D,0x02,0xEA,0x18,
6+
0x0E,0xF1,0x06,0x18,0x50,0x51,0x52,0xF5,0x04,0x21,0x06,0x56,0x1F,0x1D,0x10,0x97,0x00,0x1D,0xB0,0x47,0x24,0x25,0x60,0x61,0x5D,0x62,0x3F,0x5D,0x06,0x2F,0xF3,0x5E,
7+
0x1B,0xD8,0x00,0x0D,0x70,0x71,0x72,0xBA,0x3F,0x06,0x92,0x56,0x54,0x5A,0x02,0xB3,0x03,0x05,0x93,0xA5,0x3F,0x03,0x16,0x92,0x41,0x59,0x5A,0x69,0x11,0x45,0x03,0x7C,
8+
0x3F,0x0C,0x93,0x13,0xCF,0x1C,0x0B,0xD5,0x1F,0x27,0xCD,0x3F,0x1F,0x34,0x77,0xD2,0x61,0xA6,0x1F,0x02,0x3F,0x44,0x10,0xC9,0x00,0x3E,0x61,0xD2,0x72,0x6F,0xF3,0x3F,
9+
0x06,0x84,0xBF,0xA3,0x99,0xE0,0x02,0xD2,0x64,0xBE,0x07,0x0F,0x49,0x3F,0x65,0x1C,0x7C,0x94,0x1F,0x70,0x73,0x4A,0x74,0xCE,0x32,0x4E,0x3F,0x91,0x17,0x3D,0x31,0x49,
10+
0x60,0x62,0x73,0x0A,0x03,0x3F,0x00,0x20,0x21,0x21,0x22,0x05,0x98,0x80,0x24,0x89,0x1E,0x1F,0x41,0x82,0x90,0xFF,0x70,0x0E,0x30,0x31,0x31,0x32,0xB2,0x84,0x9E,0x00,
11+
0x64,0x1F,0x10,0xE1,0x7F,0x40,0x53,0x54,0x42,0xC5,0x0F,0x57,0x20,0x1F,0x0E,0xCE,0x06,0x3F,0x02,0x26,0x30,0x32,0xD2,0x1B,0x87,0x0E,0x02,0xE5,0x3F,0x6A,0x97,0x7F,
12+
0x60,0x9F,0x1F,0x01,0x8D,0x1F,0xB9,0x3F,0x93,0x1F,0x03,0x09,0xF9,0x50,0x52,0xC7,0x05,0x3B,0x3F,0x00,0x1F,0x58,0x94,0x61,0x60,0x64,0x67,0x51,0x00,0x63,0x62,0x08,
13+
0x3F,0x7F,0x15,0x53,0x1F,0x8E,0xFB,0x3E,0x63,0x29,0x74,0x71,0x00,0x72,0x53,0x2F,0x2D,0x3F,0x00,0x5F,0x00,0x38,0xFB,0xD1,0xAD,0xD4,0x17,0xE9,0x90,0x7D,0x3F,0x36,
14+
0xCE,0x1F,0x94,0x74,0xAD,0x68,0x03,0x9F,0x1F,0x1D,0xE6,0x3A,0x07,0xA9,0x1F,0xE6,0x00,0xA9,0x2E,0x7D,0x65,0x3F,0x21,0x92,0x00,0x43,0x44,0x22,0x06,0x22,0x4F,0xDA,
15+
0x6C,0x93,0x08,0x3F,0x45,0x41,0x25,0x00,0x42,0x9C,0x39,0x46,0xC8,0x43,0xEE,0xE0,0x5D,0x00,0x10
16+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Converted using ConvTile
2+
// This file contains all the tilemap sources for easier inclusion in a project
3+
#ifndef tilemapdata_header
4+
#define tilemapdata_header
5+
#include <stdint.h>
6+
7+
extern uint8_t tilemap_compressed[339];
8+
9+
#endif

examples/gfx_tilemap_compress/src/tilemapdata.c

Lines changed: 0 additions & 31 deletions
This file was deleted.

makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,21 @@ SRCDIR := $(call NATIVEPATH,$(CURDIR)/src)
4646
SPASMDIR := $(call NATIVEPATH,$(TOOLSDIR)/spasm-ng)
4747
CONVHEXDIR := $(call NATIVEPATH,$(TOOLSDIR)/convhex)
4848
CONVPNGDIR := $(call NATIVEPATH,$(TOOLSDIR)/convpng)
49+
CONVTILDIR := $(call NATIVEPATH,$(TOOLSDIR)/convtile)
4950
CEDIR := $(call NATIVEPATH,$(SRCDIR)/ce)
5051
STDDIR := $(call NATIVEPATH,$(SRCDIR)/std)
5152
STARTDIR := $(call NATIVEPATH,$(SRCDIR)/startup)
5253

5354
SPASM := $(call NATIVEPATH,$(SPASMDIR)/spasm)
5455
CONVHEX := $(call NATIVEPATH,$(CONVHEXDIR)/convhex)
5556
CONVPNG := $(call NATIVEPATH,$(CONVPNGDIR)/convpng)
56-
57+
CONVTILE := $(call NATIVEPATH,$(CONVTILDIR)/convtile)
5758

5859
ifeq ($(OS),Windows_NT)
5960
SPASM := $(call NATIVEPATH,$(SPASMDIR)/spasm.exe)
6061
CONVHEX := $(call NATIVEPATH,$(CONVHEXDIR)/convhex.exe)
6162
CONVPNG := $(call NATIVEPATH,$(CONVPNGDIR)/convpng.exe)
63+
CONVTILE := $(call NATIVEPATH,$(CONVTILDIR)/convtile.exe)
6264
endif
6365

6466
BIN := $(call NATIVEPATH,$(TOOLSDIR)/zds)
@@ -74,7 +76,7 @@ INSTALLLIB := $(call NATIVEPATH,$(INSTALLLOC)/$(RELEASE_NAME)/lib)
7476
DIRS := $(INSTALLINC) $(INSTALLINC)/compat $(INSTALLBIN) $(INSTALLLIB)
7577
DIRS := $(call NATIVEPATH,$(DIRS))
7678

77-
all: $(SPASM) $(CONVHEX) $(CONVPNG) graphx fileioc keypadc libload ce std startup
79+
all: $(SPASM) $(CONVHEX) $(CONVPNG) $(CONVTILE) graphx fileioc keypadc libload ce std startup
7880

7981
clean: clean-graphx clean-fileioc clean-keypadc clean-ce clean-std clean-libload clean-startup
8082
$(MAKE) -C $(SPASMDIR) clean
@@ -92,6 +94,8 @@ $(CONVHEX):
9294
$(MAKE) -C $(CONVHEXDIR)
9395
$(CONVPNG):
9496
$(MAKE) -C $(CONVPNGDIR)
97+
$(CONVTILE):
98+
$(MAKE) -C $(CONVTILDIR)
9599
#----------------------------
96100

97101
#----------------------------
@@ -174,6 +178,7 @@ install: $(DIRS) chmod
174178
$(CP) $(SPASM) $(INSTALLBIN)
175179
$(CP) $(CONVHEX) $(INSTALLBIN)
176180
$(CP) $(CONVPNG) $(INSTALLBIN)
181+
$(CP) $(CONVTILE) $(INSTALLBIN)
177182
$(CP) $(call NATIVEPATH,$(BIN)/*) $(INSTALLBIN)
178183
$(MAKE) -C $(GRAPHXDIR) install PREFIX=$(PREFIX) DESTDIR=$(DESTDIR)
179184
$(MAKE) -C $(KEYPADCDIR) install PREFIX=$(PREFIX) DESTDIR=$(DESTDIR)

src/core_makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,31 @@ $(OBJDIR)/$(ICON_OBJ): $(ICONPNG)
233233
$(CD) $(OBJDIR) && \
234234
$(AS) $(ASM_FLAGS) $(ICON_ASM)
235235

236+
$(OBJDIR)/%.obj: $(GFXDIR)/%.c $(USERHEADERS)
237+
@$(CD) $(OBJDIR) && \
238+
$(CC) $(CFLAGS) $(call WINPATH,$(addprefix $(CURDIR)/,$<))
239+
240+
$(OBJDIR)/%.obj: $(GFXDIR)/%.asm $(USERHEADERS)
241+
@$(CD) $(OBJDIR) && \
242+
$(AS) $(ASM_FLAGS) $(call WINPATH,$(addprefix $(CURDIR)/,$<))
243+
236244
# this rule builds the assembly files and places them in the object directory
237245
$(OBJDIR)/%.obj: $(SRCDIR)/%.asm $(USERHEADERS)
238246
@$(CD) $(OBJDIR) && \
239247
$(AS) $(ASM_FLAGS) $(call WINPATH,$(addprefix $(CURDIR)/,$<))
240248

249+
# this rule builds the assembly files and places them in the object directory
250+
$(OBJDIR)/%.obj: $(SRCDIR)/*/%.asm $(USERHEADERS)
251+
@$(CD) $(OBJDIR) && \
252+
$(AS) $(ASM_FLAGS) $(call WINPATH,$(addprefix $(CURDIR)/,$<))
253+
241254
# these rules compile the source files into object files
242255
$(OBJDIR)/%.obj: $(SRCDIR)/%.c $(USERHEADERS)
243256
@$(CD) $(OBJDIR) && \
244257
$(CC) $(CFLAGS) $(call WINPATH,$(addprefix $(CURDIR)/,$<))
245258

246-
$(OBJDIR)/%.obj: $(GFXDIR)/%.c $(USERHEADERS)
259+
# these rules compile the source files into object files
260+
$(OBJDIR)/%.obj: $(SRCDIR)/*/%.c $(USERHEADERS)
247261
@$(CD) $(OBJDIR) && \
248262
$(CC) $(CFLAGS) $(call WINPATH,$(addprefix $(CURDIR)/,$<))
249263

src/graphx/graphx.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ gfx_sprite_t *name = (gfx_sprite_t *)name##_data
9797
* @see gfx_mode_t
9898
*/
9999
int gfx_Begin(gfx_mode_t mode);
100+
101+
/**
102+
* Helper macro to easily initialize the graphics library setup
103+
*/
104+
#define gfx_Begin() gfx_Begin(0x27)
100105

101106
/**
102107
* Closes the graphics setup

tools/convtile

0 commit comments

Comments
 (0)