home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fun CD 26
/
OTACD26.ISO
/
archive
/
game
/
tmspcv00
/
tmspcv00.lzh
/
TMSPCV.C
next >
Wrap
Text File
|
1997-02-15
|
9KB
|
334 lines
/*****************************************
* ときめきメモリアル 対戦ぱずる玉 *<<Saturn版>>
* 画像コンバートプログラム ver0.02β *
* Programmed by Melody-Yoshi 1997/02/15 *
*****************************************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAXCHR 43
static char *name[MAXCHR]={
"FUJISAKI","KISARAGI","HIMOO","KATAGIRI","NIJINO",
"KOSHIKI","KAGAMI","ASAHINA","MIKIHARA",
"YUMI","KOARA","IJUIN","YOSHIO",
"FUJ_INS","KIS_INS","HIM_INS","KAT_INS","NIJ_INS",
"KOS_INS","KAG_INS","ASA_INS","MIK_INS",
"YUM_INS","KOA_INS",
"END_FUJI","END_KISA","END_HIMO","END_KATA","END_NIJI",
"END_KOSI","END_KIYO","END_ASA","END_MIKI",
"END_YUMI",
"OPTION","OHAYOU","OPENING","STF_TIBI","END_PHOT",
"START","RANKING","SELECT1","SELECT2"
};
static int ww[MAXCHR*2]={
200,240,200,240,200,240,200,240,200,240,
200,240,200,240,200,240,200,240,
200,240,200,240,200,240,200,240,
200,240,200,240,200,240,200,240,200,240,
200,240,200,240,200,240,200,240,
200,240,200,240,
320,240,320,240,320,240,320,240,320,240,
320,240,320,240,320,240,320,240,
320,240,
320,240,320,240,320,240,208, 96,320,240,
264,168,192, 64,320,160,160,200
};
static int ofs[MAXCHR*2]={
96,144, 96,144, 96,144, 96,144, 96,144,
96,144, 96,144, 96,144, 96,144,
96,144, 96,144, 96,144, 96,144,
96,144, 96,144, 96,144, 96,144, 96,144,
96,144, 96,144, 96,144, 96,144,
96,144, 96,144,
160,112,160,112,160,112,160,112,160,112,
160,112,160,112,160,112,160,112,
160,112,
144, 32, 80,144,192, 96, 48,24, 96,144,
128,112, 96, 32,152, 80, 72,160
};
unsigned char *by,*bf,*bz;
int minp;
unsigned adr[320];
unsigned short dx[320],dy[320];
short f16,nm;
int wx,wy;
FILE *fp;
int readbeta(int,int),readbeta16(int,int),slidec1(int,int),slidec2(int,int);
void writemem(short,short,int,int);
void writelong(long),writeshort(short),writebmpdata(char *);
main(int argc,char *argv[])
{
int i,j,k,m,n,p,q,r,s,t;
short x,y;
char fn[64],fz[64];
if(argc<2){
printf("tmspcv file[.BIN]\n");exit(1);
}
strcpy(fn,argv[1]);
for(t=0;fn[t];t++)if(fn[t]=='.')break;
fn[t]=0;for(i=0;i<t;i++)if(fn[i]>='a' && fn[i]<='z')fn[i]-=0x20;
strcpy(fz,fn);strcat(fz,".BIN");
for(nm=0;nm<MAXCHR;nm++)if(strcmp(fn,name[nm])==0)break;
if(nm==MAXCHR){
printf("file cannot convert![%s]\n",fz);exit(1);
}
if((fp=fopen(fz,"rb"))==0){
printf("file open error.[%s]\n",fz);exit(1);
}
fseek(fp,0L,2);s=(int)ftell(fp);fseek(fp,0L,0);
bz=(unsigned char *)malloc(s);
if(bz==NULL){
printf("insufficient memory!\n");exit(1);
}
fread(bz,1,s,fp);fclose(fp);
by=(unsigned char *)malloc(0x44000);bf=(unsigned char *)malloc(0x1c000);
if(by==NULL || bf==NULL){
printf("insufficient memory!\n");exit(1);
}
for(i=0;i<t;i++)if(fn[i]>='A' && fn[i]<='Z')fn[i]+=0x20;
strcpy(fz,fn);strcat(fz,"000.bmp");
if(nm!=38){
p=bz[0]*256+bz[1];
if((p<16 || p>0x7FF)|| (!(bz[2]==0 && bz[3]==0 && bz[4]==0))){
printf("cannot convert this file.[%X]\n",p);exit(1);
}
p=p*2+12;
for(q=r=0;q<20;q++){
f16=bz[p+3];p+=4;
m=bz[p+26]*256+bz[p+27]; /* The number of Object */
j=bz[p+29]*65536+bz[p+30]*256+bz[p+31]+p; /* DATA */
k=bz[p+33]*65536+bz[p+34]*256+bz[p+35]; /* DATA LENGTH*/
j-=m*2;if(j&3)j-=2;
for(i=n=0;i<m;i++,j+=2){
adr[i]=n;dx[i]=bz[j];dy[i]=bz[j+1];n+=(bz[j] * bz[j+1]);
}
if(j&3)j+=2;
switch(f16){
case 0:k=(nm!=37)?readbeta(j,k):readbeta16(j,k);break; /*BETA*/
case 1:k=slidec1(j,k);break; /* 256press */
case 2:k=slidec2(j,k);break; /* 16press */
default: printf("Illegal ID![%d]\n",f16);break;
}
n=bz[p+5]*65536+bz[p+6]*256+bz[p+7]+p; /* TOC Start */
m=bz[p+9]*65536+bz[p+10]*256+bz[p+11]+p; /* TOC End */
wx=ww[nm*2];wy=ww[nm*2+1];
for(;n!=m;n+=4){
for(j=0;j<0x1c000;j++)bf[j]=0;
for(minp=0xF00,j=bz[n+1]*65536+bz[n+2]*256+bz[n+3]+p;bz[j]!=0xFF;j+=8){
i=(bz[j+2]*256+bz[j+3])&0x7FF;
if(minp>i)minp=i;
}
if(nm==35 && r>0)minp+=0x100; /* (--; */
else if(nm==36 && r<34)minp+=0x400;
else if(nm==40 && r>94)minp+=0x600;
else if(nm==40 && r>44)minp+=0x400;
else if(nm==41 && r>174)minp+=0x700;
else if(nm==41 && r>151)minp+=0x600;
else if(nm==41 && r>101)minp+=0x400;
for(i=0,j=bz[n+1]*65536+bz[n+2]*256+bz[n+3]+p;bz[j]!=0xFF;j+=8,i++){
x=(short)(bz[j+4]*256+bz[j+5]);y=(short)(bz[j+6]*256+bz[j+7]);
writemem(x,y,bz[j]*256+bz[j+1],((bz[j+2]*256+bz[j+3])&0x7FF)-minp);
}
if(i==0)continue;
if(nm==42)minp+=0x80*q;
i=r;fz[t]=i/100+'0';i%=100;fz[t+1]=i/10+'0';fz[t+2]=i%10+'0';
writebmpdata(fz);r++;
}
for(p=k+1;p<s;p++)if(bz[p]==0x2c)break;
if(p>=s)break;
else p-=7;
}
}
else{
for(wx=320,wy=240,r=p=0;r<23;r++,p+=0x13000){
for(y=i=0;y<240;y+=8){
for(x=0;x<320;x+=8){
for(n=0;n<8;n++){
for(m=0;m<8;m++,i++)bf[y*320+x + m+n*320]=bz[i+p];
}
}
}
minp=(p+i-8)/2;
i=r;fz[t]=i/100+'0';i%=100;fz[t+1]=i/10+'0';fz[t+2]=i%10+'0';
writebmpdata(fz);
}
}
free(by);free(bf);free(bz);
exit(0);
}
int readbeta(int p,int e)
{
int i;
for(i=0;i<e;i++,p++)by[i]=bz[p];
return(p);
}
int readbeta16(int p,int e)
{
int i;
for(i=0;i<e;i++,p++){
by[i<<1]=bz[p]>>4;by[(i<<1)+1]=bz[p]&15;
}
return(p);
}
int slidec1(int p,int e)
{
int i,j,w;
w=0;
while(e>w){
i=bz[p++];
if(i&0x80){
by[w++]=i&0x1F;
j=bz[p++];
by[w++]=((i&0x40)>>2)|(j&0x0F);by[w++]=((i&0x20)>>1)|(j>>4);
}
else{
switch(i&0x70){
case 0x00:
case 0x10:
j=i&0x1F;by[w++]=j;
break;
case 0x20:
case 0x30:
case 0x40:
case 0x50:
j=i&0x1F;
for(i=(i>>6)+2;i>0;i--,w++)by[w]=j;
break;
case 0x60:
case 0x70:
j=i&0x1F;
for(i=bz[p++]+1;i>0;i--,w++)by[w]=j;
break;
}
}
}
return(p);
}
int slidec2(int p,int e)
{
int i,j,w;
w=0;
while(e>w){
i=bz[p++];
if((i&0x80)==0x80){
for(i=(i&0x7F)+1;i>0;i--,w++,p++)by[w]=bz[p];
}
else{
j=i&0x0F;j|=(j<<4);
if((i&0x70)==0x70){
for(i=0;i<9;i++,w++)by[w]=j;
for(i=bz[p++]-8;i>0;i--,w++)by[w]=j;
}
else{
for(i=(i>>4)+2;i>0;i--,w++)by[w]=j;
}
}
}
return(p);
}
void writemem(short x,short y,int n,int m)
{
int i,j,k,r,plus;
x+=ofs[nm*2];y+=ofs[nm*2+1];
r=n&0x6000;n&=0x3FF;
#ifdef DEBUG
if(x<0)fprintf(stderr,"<<%d>>",x);
if(y<0)fprintf(stderr,"[[%d]]",y);
if(x+dx[n]>wx)fprintf(stderr,"<<%d %d>>",x,dx[n]);
if(y+dy[n]>wy)fprintf(stderr,"[[%d %d]]",y,dy[n]);
#endif
if(f16<2){ /* 256color */
if(r&0x4000){
for(i=j=0;j<dy[n];j++){
if(y+j<0 || y+j>=wy)continue;
for(k=0,i+=dx[n]-1;k<dx[n];k++,i--){
if(x+k<0 || x+k>=wx)continue;
if(by[adr[n]+i])bf[(y+j)*wx+k+x]=by[adr[n]+i]+m;
}
i+=dx[n]+1;
}
}
else{
for(i=j=0;j<dy[n];j++){
if(y+j<0 || y+j>=wy)continue;
for(k=0;k<dx[n];k++,i++){
if(x+k<0 || x+k>=wx)continue;
if(by[adr[n]+i])bf[(y+j)*wx+k+x]=by[adr[n]+i]+m;
}
}
}
}
else{
if(r&0x2000){
for(i=0,j=dy[n]-1;j>=0;j--){
if(y+j<0 || y+j>=wy)continue;
for(k=0;k<dx[n];k+=2,i++){
if(x+k<0 || x+k>=wx)continue;
if(by[adr[n]/2+i]>>4)bf[(y+j)*wx+k+x]=(by[(adr[n]/2+i)]>>4)+m;
if(by[adr[n]/2+i]&15)bf[(y+j)*wx+k+1+x]=(by[(adr[n]/2+i)]&15)+m;
}
}
}
else{
for(i=j=0;j<dy[n];j++){
if(y+j<0 || y+j>=wy)continue;
for(k=0;k<dx[n];k+=2,i++){
if(x+k<0 || x+k>=wx)continue;
if(by[adr[n]/2+i]>>4)bf[(y+j)*wx+k+x]=(by[(adr[n]/2+i)]>>4)+m;
if(by[adr[n]/2+i]&15)bf[(y+j)*wx+k+1+x]=(by[(adr[n]/2+i)]&15)+m;
}
}
}
}
}
/* WRITE BMP DATA */
void writebmpdata(char *fn)
{
short i;
unsigned short k;
if((fp=fopen(fn,"wb"))==0){
printf("file create error![%s]",fn);exit(1);
}
fputc('B',fp);fputc('M',fp); /* ID */
writelong(1078L+(long)wx*(long)wy); /* FILE SIZE */
writelong(0L); /* RESERVED */
writelong(1078L); /* IMAGE OFFSET */
writelong(40L); /* INFO SIZE */
writelong((long)wx); /* dx */
writelong((long)wy); /* dy */
writeshort(1); /* PLAIN */
writeshort(8); /* DEPTH */
writelong(0L); /* COMPRESS TYPE */
writelong(0L);
writelong(0L); /* x per meter */
writelong(0L); /* y per meter */
writelong(256L); /* COLOR */
writelong(0L);
for(i=0;i<256;i++){
k=(bz[i*2+minp*2+8]<<8)+bz[i*2+minp*2+9];
fputc((k&0x7c00)>>7,fp); /* BLUE */
fputc((k&0x3e0)>>2,fp); /* GREEN */
fputc((k&0x1f)<<3,fp); /* RED */
fputc(0,fp);
}
for(i=wy-1;i>=0;i--){
if(fwrite(&bf[i*wx],1,wx,fp)!=wx){
printf("file write error!\n");exit(1);
}
}
fclose(fp);
}
/* WRITE SHORT VALUE */
void writeshort(short n)
{
fputc(n&255,fp);fputc((n>>8)&255,fp);
}
/* WRITE LONG VALUE */
void writelong(long n)
{
fputc((int)(n&255),fp);n/=256L;
fputc((int)(n&255),fp);n/=256L;
fputc((int)(n&255),fp);n/=256L;
fputc((int)(n&255),fp);
}