From 33c9828283962283e0fcf107473b8c0a6d461056 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 16 Jan 2013 16:44:45 -0500 Subject: [PATCH] snes: add in snes tools --- tb_snes/tools/Makefile | 104 ++++++++++++++ tb_snes/tools/ansi_to_tile.c | 146 +++++++++++++++++++ tb_snes/tools/bin2byte.c | 29 ++++ tb_snes/tools/color_convert.c | 20 +++ tb_snes/tools/convert_font.c | 41 ++++++ tb_snes/tools/convert_font_4bpp.c | 57 ++++++++ tb_snes/tools/convert_font_bin.c | 24 ++++ tb_snes/tools/dump_font.c | 36 +++++ tb_snes/tools/make_pal.c | 40 ++++++ tb_snes/tools/pcx_to_sprite.c | 214 +++++++++++++++++++++++++++ tb_snes/tools/pcx_to_tiles_4bpp.c | 228 +++++++++++++++++++++++++++++ tb_snes/tools/pcx_to_tiles_8bpp.c | 230 ++++++++++++++++++++++++++++++ tb_snes/tools/string_to_bytes.c | 35 +++++ 13 files changed, 1204 insertions(+) create mode 100644 tb_snes/tools/Makefile create mode 100644 tb_snes/tools/ansi_to_tile.c create mode 100644 tb_snes/tools/bin2byte.c create mode 100644 tb_snes/tools/color_convert.c create mode 100644 tb_snes/tools/convert_font.c create mode 100644 tb_snes/tools/convert_font_4bpp.c create mode 100644 tb_snes/tools/convert_font_bin.c create mode 100644 tb_snes/tools/dump_font.c create mode 100644 tb_snes/tools/make_pal.c create mode 100644 tb_snes/tools/pcx_to_sprite.c create mode 100644 tb_snes/tools/pcx_to_tiles_4bpp.c create mode 100644 tb_snes/tools/pcx_to_tiles_8bpp.c create mode 100644 tb_snes/tools/string_to_bytes.c diff --git a/tb_snes/tools/Makefile b/tb_snes/tools/Makefile new file mode 100644 index 0000000..fffe4da --- /dev/null +++ b/tb_snes/tools/Makefile @@ -0,0 +1,104 @@ +CC = gcc +CFLAGS = -O2 -Wall +LFLAGS = + +all: bin2byte color_convert convert_font convert_font_bin \ + dump_font make_pal pcx_to_sprite \ + pcx_to_tiles_4bpp pcx_to_tiles_8bpp \ + ansi_to_tile string_to_bytes convert_font_4bpp + + +ansi_to_tile: ansi_to_tile.o + $(CC) $(LFLAGS) -o ansi_to_tile ansi_to_tile.o + +ansi_to_tile.o: ansi_to_tile.c + $(CC) $(CFLAGS) -c ansi_to_tile.c + + +bin2byte: bin2byte.o + $(CC) $(LFLAGS) -o bin2byte bin2byte.o + +bin2byte.o: bin2byte.c + $(CC) $(CFLAGS) -c bin2byte.c + + +color_convert: color_convert.o + $(CC) $(LFLAGS) -o color_convert color_convert.o + +color_convert.o: color_convert.c + $(CC) $(CFLAGS) -c color_convert.c + + +convert_font: convert_font.o + $(CC) $(LFLAGS) -o convert_font convert_font.o + +convert_font.o: convert_font.c + $(CC) $(CFLAGS) -c convert_font.c + + +convert_font_4bpp: convert_font_4bpp.o + $(CC) $(LFLAGS) -o convert_font_4bpp convert_font_4bpp.o + +convert_font_4bpp.o: convert_font_4bpp.c + $(CC) $(CFLAGS) -c convert_font_4bpp.c + + +convert_font_bin: convert_font_bin.o + $(CC) $(LFLAGS) -o convert_font_bin convert_font_bin.o + +convert_font_bin.o: convert_font_bin.c + $(CC) $(CFLAGS) -c convert_font_bin.c + + +dump_font: dump_font.o + $(CC) $(LFLAGS) -o dump_font dump_font.o + +dump_dont.o: dump_font.c + $(CC) $(CFLAGS) -c dump_font.c + + +make_pal: make_pal.o + $(CC) $(LFLAGS) -o make_pal make_pal.o + +make_pal.o: make_pal.c + $(CC) $(CFLAGS) -c make_pal.c + + +pcx_to_sprite: pcx_to_sprite.o + $(CC) $(LFLAGS) -o pcx_to_sprite pcx_to_sprite.o + +pcx_to_sprite.o: pcx_to_sprite.c + $(CC) $(CFLAGS) -c pcx_to_sprite.c + + +pcx_to_tiles_4bpp: pcx_to_tiles_4bpp.o + $(CC) $(LFLAGS) -o pcx_to_tiles_4bpp pcx_to_tiles_4bpp.o + +pcx_to_tiles_4bpp.o: pcx_to_tiles_4bpp.c + $(CC) $(CFLAGS) -c pcx_to_tiles_4bpp.c + + + +pcx_to_tiles_8bpp: pcx_to_tiles_8bpp.o + $(CC) $(LFLAGS) -o pcx_to_tiles_8bpp pcx_to_tiles_8bpp.o + +pcx_to_tiles_8bpp.o: pcx_to_tiles_8bpp.c + $(CC) $(CFLAGS) -c pcx_to_tiles_8bpp.c + + + +string_to_bytes: string_to_bytes.o + $(CC) $(LFLAGS) -o string_to_bytes string_to_bytes.o + +string_to_bytes.o: string_to_bytes.c + $(CC) $(CFLAGS) -c string_to_bytes.c + + +clean: + rm -f *.o *~ bin2byte color_convert convert_font \ + convert_font_bin dump_font make_pal pcx_to_sprite \ + pcx_to_tiles_4bpp pcx_to_tiles_8bpp \ + ansi_to_tile string_to_bytes \ + convert_font_4bpp + + diff --git a/tb_snes/tools/ansi_to_tile.c b/tb_snes/tools/ansi_to_tile.c new file mode 100644 index 0000000..2996521 --- /dev/null +++ b/tb_snes/tools/ansi_to_tile.c @@ -0,0 +1,146 @@ +#include + + int offset=0; + + unsigned char font[3][8]={ + {0,0,0,0,0,0,0,0}, /* space */ + {2,2,7,2,2,7,2,2}, /* # */ + {2,5,5,5,5,5,5,2}, /* O */ + }; + + unsigned char screen_byte[8][4]; /* four bit planes */ + +void putfont(unsigned char letter, int forecolor, int backcolor) { + int fx,fy,plane,i; + int symbol; + + if (letter=='#') symbol=1; + else if (letter=='O') symbol=2; + else symbol=0; + + //printf("; Symbol %c=%d\n",letter,symbol); + + for(fx=0;fx<3;fx++) { + + for(fy=0;fy<8;fy++) { + for(plane=0;plane<4;plane++) { + screen_byte[fy][plane]<<=1; + if (font[symbol][fy]&(1<>plane)&1); + printf("; fx=%d fy=%d fore=%d sb[%d]=%x\n", + fx,fy,(forecolor>>plane)&1,plane,screen_byte[fy][plane]); + } + else { + /* background color */ + screen_byte[fy][plane]|=((backcolor>>plane)&1); + printf("; fx=%d fy=%d back=%d sb[%d]=%x\n", + fx,fy,(backcolor>>plane)&1,plane,screen_byte[fy][plane]); + + } + } + } + offset++; + if (offset==8) { + + printf("\t; Planes 1 and 0\n"); + for(i=0;i<8;i++) { + printf("\t.word $%02x%02x\n",screen_byte[i][1],screen_byte[i][0]); + } + printf("\t; Planes 3 and 2\n"); + for(i=0;i<8;i++) { + printf("\t.word $%02x%02x\n",screen_byte[i][3],screen_byte[i][2]); + } + + offset=0; + } + } + +} + + +int main(int argc, char **argv) { + + char buffer[BUFSIZ]; + char *result; + int i,color,newcolor=0; + int fore=0,back=0; + + printf("tile_data:\n"); + + while(1) { + + result=fgets(buffer,BUFSIZ,stdin); + if (result<=0) break; + + i=0; + while(1) { + + /* escape char */ + if (buffer[i]==27) { + i++; + if (buffer[i]=='[') { + i++; + } + color=0; + while(1) { + if ((buffer[i]=='m') || (buffer[i]==';')) { + if (color==0) { + newcolor&=0xbf; + } + else if (color==1) { + newcolor|=0x40; + } + else if ((color>=30) && (color<=39)) { + newcolor&=0xc7; + newcolor|=((color-30)&0x7)<<3; + } + else if ((color>=40) && (color<=49)) { + newcolor&=0xf8; + newcolor|=((color-40)&0x7); + } + + color=0; + + if (buffer[i]=='m') { + printf("; Color=%02x\n",newcolor); + break; + } + i++; + continue; + } + + color*=10; + color+=buffer[i]-0x30; + + i++; + } + } + else { + printf("; Color=%x\n",newcolor); + if (newcolor==0x47) { fore=1; back=3;} + else if (newcolor==0x4f) { fore=2; back=3;} + else if (newcolor==0x5f) { fore=4; back=3;} + else if (newcolor==0x7f) { fore=5; back=3;} + else if (newcolor==0x7) { fore=0; back=3;} + else if (newcolor==0x78) { fore=5; back=0;} + else printf("; Unknown color %x!\n",newcolor); + putfont(buffer[i],fore,back); + } + + if (buffer[i]=='\n') break; + i++; + } + + } + + printf("tile_palette:\n"); + printf("\t.word $0 ; black r=0 g=0 b=0\n"); + printf("\t.word $3def ; d. grey r=7d g=7d b=7d\n"); + printf("\t.word $3dff ; red r=ff g=7d b=7d\n"); + printf("\t.word $56b5 ; l. grey r=aa g=aa b=aa\n"); + printf("\t.word $3ff ; yellow r=ff g=ff b=0\n"); + printf("\t.word $7fff ; white r=ff g=ff b=ff\n"); + + return 0; +} diff --git a/tb_snes/tools/bin2byte.c b/tb_snes/tools/bin2byte.c new file mode 100644 index 0000000..d82ffdb --- /dev/null +++ b/tb_snes/tools/bin2byte.c @@ -0,0 +1,29 @@ +/* converts an .incbin type binary include into an ascii text one */ + +#include + +int main(int argc, char **argv) { + + unsigned char blah; + int result,count=0; + + while(1) { + + result=fread(&blah,1,1,stdin); + if (result<1) break; + + if (count%16==0) { + fprintf(stdout,".byte "); + } + fprintf(stdout,"$%02x",blah); + if (count%16!=15) { + fprintf(stdout,","); + } + else { + fprintf(stdout,"\n"); + } + count++; + } + + return 0; +} diff --git a/tb_snes/tools/color_convert.c b/tb_snes/tools/color_convert.c new file mode 100644 index 0000000..7087a4a --- /dev/null +++ b/tb_snes/tools/color_convert.c @@ -0,0 +1,20 @@ +/* converts a 15-bit BGR SNES style color to HTML #RRGGBB style */ + +#include + +int main(int argc, char **argv) { + + int bgr,b,g,r,html; + + fscanf(stdin,"%x",&bgr); + + b=(bgr>>10)&0x1f; + g=(bgr>>5)&0x1f; + r=bgr&0x1f; + + printf("rgb %x %x %x\n",r,g,b); + html=((r<<3)<<16)|((g<<3)<<8)|(b<<3); + printf("HTML: %x\n",html); + + return 0; +} diff --git a/tb_snes/tools/convert_font.c b/tb_snes/tools/convert_font.c new file mode 100644 index 0000000..60eea87 --- /dev/null +++ b/tb_snes/tools/convert_font.c @@ -0,0 +1,41 @@ +/* converts a VGA type font (well the top half of one) */ +/* into a 2bpp SNES tilemap. */ +/* mainly for use converting my TB1 font */ + +#include + +int main(int argc, char **argv) { + + int i,j,k; + unsigned char temp; + + for(i=0;i<128;i++) { + + if ((i>=0x20) && (i<127)) + printf("; Char : 0x%x %c\n",i,i); + else + printf("; Char : 0x%x\n",i); + + for(j=0;j<16;j++) { + if (fread(&temp,1,1,stdin)<1) return -1; + if (j<8) { + fprintf(stdout,".byte $%02x,$%02x\t",temp,temp); + fprintf(stdout,"; "); + for(k=0;k<8;k++) { + if ((1<<(7-k))&temp) { + printf("#"); + } + else { + printf(" "); + } + } + fprintf(stdout,"\n"); + } + } + } + + return 0; + +} + + diff --git a/tb_snes/tools/convert_font_4bpp.c b/tb_snes/tools/convert_font_4bpp.c new file mode 100644 index 0000000..8666f5d --- /dev/null +++ b/tb_snes/tools/convert_font_4bpp.c @@ -0,0 +1,57 @@ +/* converts a VGA type font (well the top half of one) */ +/* into a 4bpp SNES tilemap. */ +/* mainly for use converting my TB1 font */ + +#define COLOR 15 +#define START_FONT 0x20 +#define END_FONT 0x80 + +#include + +int main(int argc, char **argv) { + + int i,j,k,plane; + unsigned char temp_char[16]; + + /* Skip to right part of code */ + for(i=0;i=0x20) && (i<127)) + printf("; Char : 0x%x %c\n",i,i); + else + printf("; Char : 0x%x\n",i); + + for(j=0;j<16;j++) { + if (fread(&temp_char[j],1,1,stdin)<1) return -1; + } + + for(plane=0;plane<2;plane++) { + fprintf(stdout,"; planes %d and %d\n",plane*2,(plane*2)+1); + for(j=0;j<16;j++) { + if (j<8) { + fprintf(stdout,".byte $%02x,$%02x\t",temp_char[j],temp_char[j]); + fprintf(stdout,"; "); + for(k=0;k<8;k++) { + if ((1<<(7-k))&temp_char[j]) { + printf("#"); + } + else { + printf(" "); + } + } + fprintf(stdout,"\n"); + } + } + } + } + return 0; + +} + + diff --git a/tb_snes/tools/convert_font_bin.c b/tb_snes/tools/convert_font_bin.c new file mode 100644 index 0000000..5371575 --- /dev/null +++ b/tb_snes/tools/convert_font_bin.c @@ -0,0 +1,24 @@ +/* converts a VGA type font (well the top half of one) */ +/* into a 2bpp SNES tilemap. */ +/* mainly for use converting my TB1 font */ + +#include + +int main(int argc, char **argv) { + + int i,j; + unsigned char temp; + + for(i=0;i<128;i++) { + for(j=0;j<16;j++) { + if (fread(&temp,1,1,stdin)<1) return -1; + if (j<8) { + fwrite(&temp,1,1,stdout); /* plane 1 */ + fwrite(&temp,1,1,stdout); /* plane 2 */ + } + } + } + + return 0; + +} diff --git a/tb_snes/tools/dump_font.c b/tb_snes/tools/dump_font.c new file mode 100644 index 0000000..ad92a59 --- /dev/null +++ b/tb_snes/tools/dump_font.c @@ -0,0 +1,36 @@ +/* dumps a 2bpp snes tileset to ASCII asm suitable for including */ + + +#include + +int main(int argc, char **argv) { + + int i,j,k; + unsigned char temp; + + for(i=0;i<256;i++) { + + if ((i>=0x20) && (i<127)) + printf("Char : 0x%x %c\n",i,i); + else + printf("Char : 0x%x\n",i); + + for(j=0;j<16;j++) { + if (fread(&temp,1,1,stdin)<1) return -1; + printf("0x%02x : ",temp); + for(k=0;k<8;k++) { + if ((1<<(7-k))&temp) { + printf("#"); + } + else { + printf(" "); + } + } + printf("\n"); + + } + } + + return 0; + +} diff --git a/tb_snes/tools/make_pal.c b/tb_snes/tools/make_pal.c new file mode 100644 index 0000000..0c2b798 --- /dev/null +++ b/tb_snes/tools/make_pal.c @@ -0,0 +1,40 @@ +#include + +int convert_bgr2rgb(int rgb) { + int r,g,b,bgr; + + r=((rgb>>16)>>3)&0x1f; + g=((rgb>>8)>>3)&0x1f; + b=(rgb>>3)&0x1f; + + bgr=(b<<10)|(g<<5)|r; + + return bgr; +} + +int main(int argc, char **argv) { + + int i,r,g,b,rgb,bgr; + + fprintf(stdout,"; 15-color BGR palette\n"); + for(i=0;i<256;i++) { + if (i%4==0) { + fprintf(stdout,"; palette %d?\n",i/4); + } + if (i%4==3) { + r=((i/4)&1)?0:0xff; + g=((i/4)&2)?0:0xff; + b=((i/4)&4)?0:0xff; + rgb=r<<16|g<<8|b; + bgr=convert_bgr2rgb(rgb); + fprintf(stdout,".word $%04x\t; %06x\n",bgr,rgb); + } + + else { + fprintf(stdout,".word $0000\n"); + } + } + + + return 0; +} diff --git a/tb_snes/tools/pcx_to_sprite.c b/tb_snes/tools/pcx_to_sprite.c new file mode 100644 index 0000000..38f1aca --- /dev/null +++ b/tb_snes/tools/pcx_to_sprite.c @@ -0,0 +1,214 @@ +/* Converts a 24-bit PCX file to a raw file for use in ECE498 Project 1 */ + +#include /* For FILE I/O */ +#include /* For strncmp */ +#include /* for open() */ +#include /* for lseek() */ +#include /* for file modes */ +#include /* exit() */ + +/* Convert to 15-bpp bgr */ +int rgb2bgr(int r,int g, int b) { + int r2,g2,b2,bgr; + + r2=(r>>3)&0x1f; + g2=(g>>3)&0x1f; + b2=(b>>3)&0x1f; + + bgr=(b2<<10)|(g2<<5)|r2; + + return bgr; +} + + +int vmwLoadPCX(int pcx_fd) { + + int debug=1,bpp; + int x,y; + int i,numacross,planes=0; + int xsize,ysize,plane; + int xmin,ymin,xmax,ymax,version; + unsigned char pcx_header[128]; + unsigned char temp_byte; + + /* Open the file */ + // pcx_fd=open(filename,O_RDONLY); + + //if (pcx_fd<0) { + // printf("ERROR! File \"%s\" not found!\n",filename); + // return -1; + // } + + /*************** DECODE THE HEADER *************************/ + + // lseek(pcx_fd,0,SEEK_SET); + + read(pcx_fd,&pcx_header,128); + + xmin=(pcx_header[5]<<8)+pcx_header[4]; + ymin=(pcx_header[7]<<8)+pcx_header[6]; + + xmax=(pcx_header[9]<<8)+pcx_header[8]; + ymax=(pcx_header[11]<<8)+pcx_header[10]; + + version=pcx_header[1]; + bpp=pcx_header[3]; + + if (debug) { + + fprintf(stderr,"Manufacturer: "); + if (pcx_header[0]==10) fprintf(stderr,"Zsoft\n"); + else fprintf(stderr,"Unknown %i\n",pcx_header[0]); + + fprintf(stderr,"Version: "); + + switch(version) { + case 0: fprintf(stderr,"2.5\n"); break; + case 2: fprintf(stderr,"2.8 w palette\n"); break; + case 3: fprintf(stderr,"2.8 w/o palette\n"); break; + case 4: fprintf(stderr,"Paintbrush for Windows\n"); break; + case 5: fprintf(stderr,"3.0+\n"); break; + default: fprintf(stderr,"Unknown %i\n",version); + } + fprintf(stderr,"Encoding: "); + if (pcx_header[2]==1) fprintf(stderr,"RLE\n"); + else fprintf(stderr,"Unknown %i\n",pcx_header[2]); + + fprintf(stderr,"BitsPerPixelPerPlane: %i\n",bpp); + fprintf(stderr,"File goes from %i,%i to %i,%i\n",xmin,ymin,xmax,ymax); + + fprintf(stderr,"Horizontal DPI: %i\n",(pcx_header[13]<<8)+pcx_header[12]); + fprintf(stderr,"Vertical DPI: %i\n",(pcx_header[15]<<8)+pcx_header[14]); + + fprintf(stderr,"Number of colored planes: %i\n",pcx_header[65]); + fprintf(stderr,"Bytes per line: %i\n",(pcx_header[67]<<8)+pcx_header[66]); + fprintf(stderr,"Palette Type: %i\n",(pcx_header[69]<<8)+pcx_header[68]); + fprintf(stderr,"Hscreen Size: %i\n",(pcx_header[71]<<8)+pcx_header[70]); + fprintf(stderr,"Vscreen Size: %i\n",(pcx_header[73]<<8)+pcx_header[72]); + + } + planes=pcx_header[65]; + +// if ((version==5) && (bpp==8) && (pcx_header[65]==3)) type=24; +// else if (version==5) type=8; +// else type=0; + + xsize=((xmax-xmin)+1); + ysize=((ymax-ymin)+1); + + char *output; + + output=calloc((xsize*ysize),sizeof(unsigned int)); + if (output==NULL) return -1; + + x=0; y=0; + + while(y>1); + } + + printf("\t.word $%02x%02x\n",plane1,plane0); + } + + printf("\t; Plane 2 Plane 3\n"); + for(y=0;y>2); + plane3|=(((output[(y*xsize)+x])&8)>>3); + } + + printf("\t.word $%02x%02x\n",plane3,plane2); + } + + for(i=0;i<1008;i++) { + printf("\t.word $ffff\n"); + } + + printf("sprite_palette:\n"); + + /* read in palette */ + read(pcx_fd,&temp_byte,1); + if (temp_byte!=12) { + printf("Error! No palette found!\n"); + } + else { + int r,g,b; + for(i=0;i<16;i++) { + read(pcx_fd,&temp_byte,1); + r=temp_byte; + read(pcx_fd,&temp_byte,1); + g=temp_byte; + read(pcx_fd,&temp_byte,1); + b=temp_byte; + printf("\t.word $%x\t; r=%x g=%x b=%x\n",rgb2bgr(r,g,b),r,g,b); + } + } + + // close(pcx_fd); + + return 0; +} + + +int main(int argc, char **argv) { + + int result;//,x,y; + // FILE *fff; + + //char filename[]="butterfinger.pcx"; + + /* read from stdin */ + + result=vmwLoadPCX(fileno(stdin)); + + if (result<0) { + fprintf(stderr,"Error reading PCX from stdin\n"); + exit(1); + } + + // fff=fopen("input.bin","w"); + //if (fff==NULL) exit(1); + + // fwrite(buffer,sizeof(unsigned int),buffer[0]*buffer[1]+2,stdout); + + return 0; +} diff --git a/tb_snes/tools/pcx_to_tiles_4bpp.c b/tb_snes/tools/pcx_to_tiles_4bpp.c new file mode 100644 index 0000000..c1ac105 --- /dev/null +++ b/tb_snes/tools/pcx_to_tiles_4bpp.c @@ -0,0 +1,228 @@ +/* Converts a 24-bit PCX file to SNES background tiles */ + +#include /* For FILE I/O */ +#include /* For strncmp */ +#include /* for open() */ +#include /* for lseek() */ +#include /* for file modes */ +#include /* exit() */ + +/* Convert to 15-bpp bgr */ +int rgb2bgr(int r,int g, int b) { + int r2,g2,b2,bgr; + + r2=(r>>3)&0x1f; + g2=(g>>3)&0x1f; + b2=(b>>3)&0x1f; + + bgr=(b2<<10)|(g2<<5)|r2; + + return bgr; +} + + +int vmwLoadPCX(int pcx_fd) { + + int debug=1,bpp; + int x,y; + int i,numacross,planes=0; + int xsize,ysize,plane; + int xmin,ymin,xmax,ymax,version; + unsigned char pcx_header[128]; + unsigned char temp_byte; + + /* Open the file */ + // pcx_fd=open(filename,O_RDONLY); + + //if (pcx_fd<0) { + // printf("ERROR! File \"%s\" not found!\n",filename); + // return -1; + // } + + /*************** DECODE THE HEADER *************************/ + + // lseek(pcx_fd,0,SEEK_SET); + + read(pcx_fd,&pcx_header,128); + + xmin=(pcx_header[5]<<8)+pcx_header[4]; + ymin=(pcx_header[7]<<8)+pcx_header[6]; + + xmax=(pcx_header[9]<<8)+pcx_header[8]; + ymax=(pcx_header[11]<<8)+pcx_header[10]; + + version=pcx_header[1]; + bpp=pcx_header[3]; + + if (debug) { + + fprintf(stderr,"Manufacturer: "); + if (pcx_header[0]==10) fprintf(stderr,"Zsoft\n"); + else fprintf(stderr,"Unknown %i\n",pcx_header[0]); + + fprintf(stderr,"Version: "); + + switch(version) { + case 0: fprintf(stderr,"2.5\n"); break; + case 2: fprintf(stderr,"2.8 w palette\n"); break; + case 3: fprintf(stderr,"2.8 w/o palette\n"); break; + case 4: fprintf(stderr,"Paintbrush for Windows\n"); break; + case 5: fprintf(stderr,"3.0+\n"); break; + default: fprintf(stderr,"Unknown %i\n",version); + } + fprintf(stderr,"Encoding: "); + if (pcx_header[2]==1) fprintf(stderr,"RLE\n"); + else fprintf(stderr,"Unknown %i\n",pcx_header[2]); + + fprintf(stderr,"BitsPerPixelPerPlane: %i\n",bpp); + fprintf(stderr,"File goes from %i,%i to %i,%i\n",xmin,ymin,xmax,ymax); + + fprintf(stderr,"Horizontal DPI: %i\n",(pcx_header[13]<<8)+pcx_header[12]); + fprintf(stderr,"Vertical DPI: %i\n",(pcx_header[15]<<8)+pcx_header[14]); + + fprintf(stderr,"Number of colored planes: %i\n",pcx_header[65]); + fprintf(stderr,"Bytes per line: %i\n",(pcx_header[67]<<8)+pcx_header[66]); + fprintf(stderr,"Palette Type: %i\n",(pcx_header[69]<<8)+pcx_header[68]); + fprintf(stderr,"Hscreen Size: %i\n",(pcx_header[71]<<8)+pcx_header[70]); + fprintf(stderr,"Vscreen Size: %i\n",(pcx_header[73]<<8)+pcx_header[72]); + + } + planes=pcx_header[65]; + +// if ((version==5) && (bpp==8) && (pcx_header[65]==3)) type=24; +// else if (version==5) type=8; +// else type=0; + + xsize=((xmax-xmin)+1); + ysize=((ymax-ymin)+1); + + char *output; + + output=calloc((xsize*ysize),sizeof(unsigned int)); + if (output==NULL) return -1; + + x=0; y=0; + + while(y>1); + } + 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); + } + printf("\t.word $%02x%02x\n",plane3,plane2); + } + } + } + + + +// for(i=0;i<1008;i++) { +// printf("\t.word $ffff\n"); +// } + + printf("tile_palette:\n"); + + /* read in palette */ + read(pcx_fd,&temp_byte,1); + if (temp_byte!=12) { + printf("Error! No palette found!\n"); + } + else { + int r,g,b; + for(i=0;i<16;i++) { + read(pcx_fd,&temp_byte,1); + r=temp_byte; + read(pcx_fd,&temp_byte,1); + g=temp_byte; + read(pcx_fd,&temp_byte,1); + b=temp_byte; + printf("\t.word $%x\t; r=%x g=%x b=%x\n",rgb2bgr(r,g,b),r,g,b); + } + } + + // close(pcx_fd); + + return 0; +} + + +int main(int argc, char **argv) { + + int result;//,x,y; + // FILE *fff; + + //char filename[]="butterfinger.pcx"; + + /* read from stdin */ + + result=vmwLoadPCX(fileno(stdin)); + + if (result<0) { + fprintf(stderr,"Error reading PCX from stdin\n"); + exit(1); + } + + // fff=fopen("input.bin","w"); + //if (fff==NULL) exit(1); + + // fwrite(buffer,sizeof(unsigned int),buffer[0]*buffer[1]+2,stdout); + + return 0; +} diff --git a/tb_snes/tools/pcx_to_tiles_8bpp.c b/tb_snes/tools/pcx_to_tiles_8bpp.c new file mode 100644 index 0000000..77c1130 --- /dev/null +++ b/tb_snes/tools/pcx_to_tiles_8bpp.c @@ -0,0 +1,230 @@ +/* Converts a 24-bit PCX file to 256-color SNES background tiles */ + +#include /* For FILE I/O */ +#include /* For strncmp */ +#include /* for open() */ +#include /* for lseek() */ +#include /* for file modes */ +#include /* exit() */ + +/* Convert to 15-bpp bgr */ +int rgb2bgr(int r,int g, int b) { + int r2,g2,b2,bgr; + + r2=(r>>3)&0x1f; + g2=(g>>3)&0x1f; + b2=(b>>3)&0x1f; + + bgr=(b2<<10)|(g2<<5)|r2; + + return bgr; +} + + +/* File already open */ +int vmwLoadPCX(int pcx_fd) { + + int debug=1,bpp; + int x,y; + int i,numacross,planes=0; + int xsize,ysize,plane; + int xmin,ymin,xmax,ymax,version; + unsigned char pcx_header[128]; + unsigned char temp_byte; + + /*************** DECODE THE HEADER *************************/ + + read(pcx_fd,&pcx_header,128); + + xmin=(pcx_header[5]<<8)+pcx_header[4]; + ymin=(pcx_header[7]<<8)+pcx_header[6]; + + xmax=(pcx_header[9]<<8)+pcx_header[8]; + ymax=(pcx_header[11]<<8)+pcx_header[10]; + + version=pcx_header[1]; + bpp=pcx_header[3]; + + if (debug) { + + fprintf(stderr,"Manufacturer: "); + if (pcx_header[0]==10) fprintf(stderr,"Zsoft\n"); + else fprintf(stderr,"Unknown %i\n",pcx_header[0]); + + fprintf(stderr,"Version: "); + + switch(version) { + case 0: fprintf(stderr,"2.5\n"); break; + case 2: fprintf(stderr,"2.8 w palette\n"); break; + case 3: fprintf(stderr,"2.8 w/o palette\n"); break; + case 4: fprintf(stderr,"Paintbrush for Windows\n"); break; + case 5: fprintf(stderr,"3.0+\n"); break; + default: fprintf(stderr,"Unknown %i\n",version); + } + fprintf(stderr,"Encoding: "); + if (pcx_header[2]==1) fprintf(stderr,"RLE\n"); + else fprintf(stderr,"Unknown %i\n",pcx_header[2]); + + fprintf(stderr,"BitsPerPixelPerPlane: %i\n",bpp); + fprintf(stderr,"File goes from %i,%i to %i,%i\n",xmin,ymin,xmax,ymax); + + fprintf(stderr,"Horizontal DPI: %i\n",(pcx_header[13]<<8)+pcx_header[12]); + fprintf(stderr,"Vertical DPI: %i\n",(pcx_header[15]<<8)+pcx_header[14]); + + fprintf(stderr,"Number of colored planes: %i\n",pcx_header[65]); + fprintf(stderr,"Bytes per line: %i\n",(pcx_header[67]<<8)+pcx_header[66]); + fprintf(stderr,"Palette Type: %i\n",(pcx_header[69]<<8)+pcx_header[68]); + fprintf(stderr,"Hscreen Size: %i\n",(pcx_header[71]<<8)+pcx_header[70]); + fprintf(stderr,"Vscreen Size: %i\n",(pcx_header[73]<<8)+pcx_header[72]); + + } + planes=pcx_header[65]; + + xsize=((xmax-xmin)+1); + ysize=((ymax-ymin)+1); + + char *output; + + output=calloc((xsize*ysize),sizeof(unsigned int)); + if (output==NULL) return -1; + + x=0; y=0; + + while(y>1); + } + 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); + } + 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); + } + 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); + } + printf("\t.word $%02x%02x\n",plane7,plane6); + } + + } + } + + printf("tile_palette:\n"); + + /* read in palette */ + read(pcx_fd,&temp_byte,1); + if (temp_byte!=12) { + fprintf(stderr,"Error! No palette found!\n"); + } + else { + int r,g,b; + for(i=0;i<256;i++) { + read(pcx_fd,&temp_byte,1); + r=temp_byte; + read(pcx_fd,&temp_byte,1); + g=temp_byte; + read(pcx_fd,&temp_byte,1); + b=temp_byte; + printf("\t.word $%x\t; r=%x g=%x b=%x\n",rgb2bgr(r,g,b),r,g,b); + } + } + + return 0; +} + + +int main(int argc, char **argv) { + + int result; + + /* read from stdin */ + + result=vmwLoadPCX(fileno(stdin)); + + if (result<0) { + fprintf(stderr,"Error reading PCX from stdin\n"); + exit(1); + } + + return 0; +} diff --git a/tb_snes/tools/string_to_bytes.c b/tb_snes/tools/string_to_bytes.c new file mode 100644 index 0000000..1126ce4 --- /dev/null +++ b/tb_snes/tools/string_to_bytes.c @@ -0,0 +1,35 @@ +#include +#include + +int main(int argc, char **argv) { + + char buffer[BUFSIZ],*result; + int i; + int quotes_open=0; + + while(1) { + result=fgets(buffer,BUFSIZ,stdin); + if (result==NULL) return 0; + + printf("\t.byte "); + for(i=0;i