// STOS sprites to PSX format // Coded by Scott Evans 21/4/97 // Last modified 27/4/97 #include #include #include #include #include "sprconv.h" // Size of header for map blocks file // 2 bytes = no. of blocks // 1 byte = block width (pixels) // 1 byte = block height (pixels) // 4 bytes = offset to palette (from start of file) // 4 bytes = offset to block image data (from start of file) typedef struct { _word nblks; _byte w,h; _long paloff; _long imgoff; }BlockHeader; // Convert sprites into map blocks for PSX // Main function void main(int argc,_byte **argv) { // Need source and destination file names on command line if(argc==3) { void *addr; if(addr=LoadFile(argv[1])) { // Skip junk at start of file (_byte *)addr+=18; // Is it STOS sprite file if(_STEtoPClong(_peekLong(addr))==0x19861987) { _word c1,c2,c3,i,*data,nospr,psxpalt[16]; _long *buffer,offset,pblks,paladdr,fsize; _byte sw,sh; BlockHeader *bh; printf("File %s\n\n",argv[1]); (_byte *)addr+=4; // Find offset to sprite parameter blocks offset=_STEtoPClong(_peekLong(addr)); pblks=((_long)addr)+offset; // Find location of sprite palette offset=_STEtoPClong(_peekLong(pblks)); paladdr=(pblks+offset)-32; (_byte *)addr+=12; // Find number of sprites in file nospr=_STEtoPCword(_peekWord(addr)); // Convert palette data, currently only 4bit CLUT puts("Converting palette to 4bit CLUT ...\n"); for(i=0;i<16;i++) { c1=c2=c3=_STEtoPCword(_peekWord(paladdr)); psxpalt[i]=((c1&0xf)|((c2&0xf0)<<1)|((c3&0xf00)<<2)); // Semi transparency flag on _bset(15,psxpalt[i]); ((_word *)paladdr)++; printf("Colour %2d (%3x) : %3x\n",i,c1,psxpalt[i]); } // Space for sprites buffer=(_long *)malloc((fsize=CalcSprSize(pblks,nospr))+PALSIZE+sizeof(BlockHeader)); // Fill in header information bh=(BlockHeader *)buffer; bh->nblks=nospr; bh->w=16; bh->h=16; bh->paloff=sizeof(BlockHeader); bh->imgoff=sizeof(BlockHeader)+PALSIZE; //_pokeWord(buffer,nospr); //_pokeByte((_byte *)buffer+2,16); //_pokeByte((_byte *)buffer+3,16); //_pokeLong((_byte *)buffer+4,4); //_pokeLong((_byte *)buffer+8,PALSIZE); // Put in palette memcpy((_byte *)buffer+bh->paloff,psxpalt,PALSIZE); printf("\nConverting %3d sprites ...\n",nospr); for(i=0;iimgoff)>>2),sw,sh); } SaveFile(argv[2],(_byte *)buffer,fsize+PALSIZE+sizeof(BlockHeader)); } else printf("File %s not a STOS sprite bank\n",argv[1]); } else puts("Load error"); (_byte *)addr-=34; free(addr); } else puts("Usage : sprconv "); exit(0); }