snes: pcx_to_tiles_4bpp

clean up code, add command line argument for label name
This commit is contained in:
Vince Weaver 2013-01-21 13:12:53 -05:00
parent 2687dfe6a2
commit 8e77643bb4
2 changed files with 36 additions and 57 deletions

View File

@ -7,8 +7,10 @@
#include <sys/stat.h> /* for file modes */
#include <stdlib.h> /* exit() */
char label_prefix[BUFSIZ]="tile";
/* Convert to 15-bpp bgr */
int rgb2bgr(int r,int g, int b) {
static int rgb2bgr(int r,int g, int b) {
int r2,g2,b2,bgr;
r2=(r>>3)&0x1f;
@ -21,7 +23,7 @@ int rgb2bgr(int r,int g, int b) {
}
int vmwLoadPCX(int pcx_fd) {
static int vmwLoadPCX(int pcx_fd) {
int debug=1,bpp;
int x,y;
@ -31,14 +33,6 @@ int vmwLoadPCX(int pcx_fd) {
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);
@ -136,7 +130,7 @@ int vmwLoadPCX(int pcx_fd) {
unsigned int plane0,plane1,plane2,plane3,offset;
printf("tile_data:\n");
printf("%s_data:\n",label_prefix);
int ychunk,xchunk;
for(ychunk=0;ychunk<ysize/Y_CHUNKSIZE;ychunk++) {
for(xchunk=0;xchunk<xsize/X_CHUNKSIZE;xchunk++) {
@ -171,13 +165,7 @@ int vmwLoadPCX(int pcx_fd) {
}
}
// for(i=0;i<1008;i++) {
// printf("\t.word $ffff\n");
// }
printf("tile_palette:\n");
printf("%s_palette:\n",label_prefix);
/* read in palette */
read(pcx_fd,&temp_byte,1);
@ -205,24 +193,15 @@ int vmwLoadPCX(int pcx_fd) {
int main(int argc, char **argv) {
int result;//,x,y;
// FILE *fff;
//char filename[]="butterfinger.pcx";
int result;
/* 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;
}