From d798e031eb93512659774963e584295f2e1d6a11 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 22 Jan 2013 15:30:19 -0500 Subject: [PATCH] snes: make pcx_to_compressed_tilemap_8bpp.c generic It should now work for 4bpp tiles too --- tb1_snes/Makefile | 9 +- tb1_snes/tools/Makefile | 12 +- ...map_8bpp.c => pcx_to_compressed_tilemap.c} | 127 +++++++----------- 3 files changed, 58 insertions(+), 90 deletions(-) rename tb1_snes/tools/{pcx_to_compressed_tilemap_8bpp.c => pcx_to_compressed_tilemap.c} (72%) diff --git a/tb1_snes/Makefile b/tb1_snes/Makefile index cf32daa..8a8b441 100644 --- a/tb1_snes/Makefile +++ b/tb1_snes/Makefile @@ -11,7 +11,7 @@ tb1_snes.sfc: tb1_snes.o snes-hirom.cfg tb1_snes.o: tb1_snes.s \ snes_init.s opening.s title_screen.s level_1.s \ svmwgraph.s \ - tb1_title.tiles tb1_opening.tiles \ + tb1_title.tiles tb1_opening.tiles level1_background.tiles \ level1_pal0.sprites \ tbfont.inc $(AS) -t none -o tb1_snes.o -l tb1_snes.lst -c tb1_snes.s @@ -20,11 +20,14 @@ tb1_snes.o: tb1_snes.s \ level1_pal0.sprites: graphics/level1_pal0.pcx tools/pcx_to_tiles_4bpp ./tools/pcx_to_tiles_4bpp level1_pal0 < graphics/level1_pal0.pcx > level1_pal0.sprites +level1_background.tiles: graphics/level1_background.pcx ./tools/pcx_to_compressed_tilemap + ./tools/pcx_to_compressed_tilemap level1_background 4 < graphics/level1_background.pcx > level1_background.tiles + tb1_opening.tiles: graphics/vmw_logo.pcx ./tools/pcx_to_tiles_8bpp ./tools/pcx_to_tiles_8bpp vmw_logo < graphics/vmw_logo.pcx > tb1_opening.tiles -tb1_title.tiles: graphics/tb1_title.pcx ./tools/pcx_to_compressed_tilemap_8bpp - ./tools/pcx_to_compressed_tilemap_8bpp title_screen < graphics/tb1_title.pcx > tb1_title.tiles +tb1_title.tiles: graphics/tb1_title.pcx ./tools/pcx_to_compressed_tilemap + ./tools/pcx_to_compressed_tilemap title_screen 8 < graphics/tb1_title.pcx > tb1_title.tiles checksum.inc: ./tools/snes_checksum tb1_snes.sfc ./tools/snes_checksum < tb1_snes.sfc > checksum.inc diff --git a/tb1_snes/tools/Makefile b/tb1_snes/tools/Makefile index 6a13784..56e36bf 100644 --- a/tb1_snes/tools/Makefile +++ b/tb1_snes/tools/Makefile @@ -5,7 +5,7 @@ LFLAGS = all: bin2byte color_convert convert_font convert_font_bin \ dump_font make_pal \ pcx_to_tiles_4bpp pcx_to_tiles_8bpp \ - pcx_to_compressed_tilemap_8bpp \ + pcx_to_compressed_tilemap \ ansi_to_tile string_to_bytes convert_font_4bpp \ snes_checksum @@ -80,11 +80,11 @@ pcx_to_tiles_8bpp.o: pcx_to_tiles_8bpp.c $(CC) $(CFLAGS) -c pcx_to_tiles_8bpp.c -pcx_to_compressed_tilemp_8bpp: pcx_to_compressed_tilemap_8bpp.o - $(CC) $(LFLAGS) -o pcx_to_compressed_tilemap_8bpp pcx_to_compressed_tilemap_8bpp.o +pcx_to_compressed_tilemap: pcx_to_compressed_tilemap.o + $(CC) $(LFLAGS) -o pcx_to_compressed_tilemap pcx_to_compressed_tilemap.o -pcx_to_compressed_tilemap_8bpp.o: pcx_to_compressed_tilemap_8bpp.c - $(CC) $(CFLAGS) -c pcx_to_compressed_tilemap_8bpp.c +pcx_to_compressed_tilemap.o: pcx_to_compressed_tilemap.c + $(CC) $(CFLAGS) -c pcx_to_compressed_tilemap.c @@ -106,7 +106,7 @@ clean: rm -f *.o *~ bin2byte color_convert convert_font \ convert_font_bin dump_font make_pal \ pcx_to_tiles_4bpp pcx_to_tiles_8bpp \ - pcx_to_compressed_tilemap_8bpp \ + pcx_to_compressed_tilemap \ ansi_to_tile string_to_bytes \ convert_font_4bpp snes_checksum diff --git a/tb1_snes/tools/pcx_to_compressed_tilemap_8bpp.c b/tb1_snes/tools/pcx_to_compressed_tilemap.c similarity index 72% rename from tb1_snes/tools/pcx_to_compressed_tilemap_8bpp.c rename to tb1_snes/tools/pcx_to_compressed_tilemap.c index 22803b1..45e9d9e 100644 --- a/tb1_snes/tools/pcx_to_compressed_tilemap_8bpp.c +++ b/tb1_snes/tools/pcx_to_compressed_tilemap.c @@ -1,12 +1,15 @@ -/* Converts a 24-bit PCX file to 256-color SNES background tiles */ +/* Converts a 24-bit PCX file to SNES background tiles */ +/* It is "compressed", that is it detects identical tiles */ +/* instead of using just a plain linear tilemap */ -#include /* For FILE I/O */ -#include /* For strncmp */ -#include /* for open() */ -#include /* for lseek() */ +#include /* For FILE I/O */ +#include /* For strncmp */ +#include /* for open() */ +#include /* for lseek() */ #include /* for file modes */ -#include /* exit() */ +#include /* exit() */ +/* Horizontally flip the bits in a byte */ static unsigned int hflip_byte(unsigned int byte) { int new_byte=0,i; @@ -36,14 +39,17 @@ static char symbol_name[BUFSIZ]="temp"; #define MAX_TILE_X 32 #define MAX_TILE_Y 32 +#define MAX_PLANES_DIV2 4 +#define Y_SIZE 8 static unsigned short tilemap[MAX_TILE_X*MAX_TILE_Y]; /* 2k */ -static unsigned short tiledata[MAX_TILE_X*MAX_TILE_Y][8][4]; -static unsigned short tiledata_hflip[MAX_TILE_X*MAX_TILE_Y][8][4]; -static unsigned short temp_tile[8][4]; +static unsigned short tiledata[MAX_TILE_X*MAX_TILE_Y][Y_SIZE][MAX_PLANES_DIV2]; +static unsigned short + tiledata_hflip[MAX_TILE_X*MAX_TILE_Y][Y_SIZE][MAX_PLANES_DIV2]; +static unsigned short temp_tile[Y_SIZE][MAX_PLANES_DIV2]; static int total_tiles=0; static int compressed_tiles=0; - +static int max_planes=8; /* File already open */ @@ -146,83 +152,38 @@ static int vmwLoadPCX(int pcx_fd) { #define Y_CHUNKSIZE 8 - unsigned int plane0,plane1,plane2,plane3; - unsigned int plane4,plane5,plane6,plane7,offset; + unsigned int plane0,plane1,offset; + int ychunk,xchunk; printf("%s_tile_data:\n",symbol_name); - int ychunk,xchunk; + for(ychunk=0;ychunk>1); - } - temp_tile[y][0]=(plane1<<8)|plane0; -// printf("\t.word $%02x%02x\n",plane1,plane0); - } - -// printf("\t; Plane 2 Plane 3\n"); - for(y=0;y>2); - plane3|=(((output[offset])&8)>>3); - } - temp_tile[y][1]=(plane3<<8)|plane2; -// printf("\t.word $%02x%02x\n",plane3,plane2); - } - -// printf("\t; Plane 4 Plane 5\n"); - for(y=0;y>4); - plane5|=(((output[offset])&32)>>5); - } - temp_tile[y][2]=(plane5<<8)|plane4; -// printf("\t.word $%02x%02x\n",plane5,plane4); - } - -// printf("\t; Plane 6 Plane 7\n"); - for(y=0;y>6); - plane7|=(((output[offset])&128)>>7); - } - temp_tile[y][3]=(plane7<<8)|plane6; -// printf("\t.word $%02x%02x\n",plane7,plane6); - } + for(i=0;i> plane); + plane1|=(((output[offset])&(1<<(plane+1)) )>>(plane+1)); + } + temp_tile[y][i]=(plane1<<8)|plane0; + } + } - int i,plane,v=0,h=0,o=0,pal=0,found_tile=0,found=0,match; + int v=0,h=0,o=0,pal=0,found_tile=0,found=0,match; /* see if the new tile matches an existing one */ for(i=0;i>8)&0xff)<<8) | @@ -351,7 +312,7 @@ static int vmwLoadPCX(int pcx_fd) { } else { int r,g,b; - for(i=0;i<256;i++) { + for(i=0;i<(1<2) { + max_planes=atoi(argv[2]); + } + /* read from stdin */ result=vmwLoadPCX(fileno(stdin));