/* * vTIM v.1.0 TIM image viewer for dos by Yannick Suter aka asc/Nowadays 1998 * * for more informations about it, read README.txt * * feel free to use it! Let me know, if you found some bugs or did a own * viewer. * * no more comments! =) if you have some questions or suggestions for * improvements, please email me: asc@netlink.ch * */ #include #include #include //#include #include "detect.c" #include "tim.h" FILE *TIMf; TIMinf TIMinfo; int openTIM(char *file){ if(TIMf = fopen(file,"rb")) return(1); else return(0); } void closeTIM(){ fclose(TIMf); } void readID(){ unsigned char ID[4]; fread(&ID,1,4,TIMf); printf(" ID = 0x%02x\n",ID[0]); printf(" Version = 0x%02x\n",ID[1]); TIMinfo.ID = ID[0]; TIMinfo.version = ID[1]; } void readFLAG(){ unsigned char FLAG[4]; int *t,fl,cts; fread(&FLAG,1,4,TIMf); t = (int *)FLAG; fl = (*t & 7); cts = (*t & 8)>>3; printf(" : FLAG informations\n"); printf(" 4bit = "); if(fl == 0) printf("TRUE"); else printf("- "); printf(" 8bit = "); if(fl == 1) printf("TRUE\n"); else printf("- \n"); printf(" 15bit = "); if(fl == 2) printf("TRUE"); else printf("- "); printf(" 24bit = "); if(fl == 3) printf("TRUE"); else printf("- "); printf(" CTS = "); if(cts)printf("CLUT used\n"); else printf("direct TRUECOLOR used\n"); TIMinfo.pmode = fl; TIMinfo.cts = cts; } void readCLUT(){ unsigned char CLUTlen[4]; unsigned char CLUTframe[4]; unsigned char CLUTsize[4]; unsigned long *t,fx,fy; fread(&CLUTlen,1,4,TIMf); t = (unsigned long *)CLUTlen; printf(" : CLUT informations [%dbytes]\n",*t); fread(&CLUTframe,1,4,TIMf); t = (unsigned long *)CLUTframe; fx = fy = *t; fx = fx & 65535; fy = (fy>>16) & 65535; printf(" DX = %4d",fx); printf(" DY = %4d\n",fy); TIMinfo.cDX = fx; TIMinfo.cDY = fy; fread(&CLUTsize,1,4,TIMf); t = (unsigned long *)CLUTsize; fx = fy = *t; fx = fx & 65535; fy = (fy>>16) & 65535; printf(" WIDTH = %4d",fx); printf(" HEIGHT = %4d\n",fy); TIMinfo.cW = fx; TIMinfo.cH = fy; if(TIMinfo.pmode==0)readPAL_4bit(); if(TIMinfo.pmode==1)readPAL_8bit(); } void readDATA(){ unsigned char CLUTlen[4]; unsigned char CLUTframe[4]; unsigned char CLUTsize[4]; unsigned long *t,fx,fy; fread(&CLUTlen,1,4,TIMf); t = (unsigned long *)CLUTlen; printf(" : PIXEL information [%dbytes]\n",*t); fread(&CLUTframe,1,4,TIMf); t = (unsigned long *)CLUTframe; fx = fy = *t; fx = fx & 65535; fy = (fy>>16) & 65535; printf(" DX = %4d",fx); printf(" DY = %4d\n",fy); TIMinfo.pDX = fx; TIMinfo.pDY = fy; fread(&CLUTsize,1,4,TIMf); t = (unsigned long *)CLUTsize; fx = fy = *t; fx = fx & 65535; fy = (fy>>16) & 65535; printf(" WIDTH = %4d",fx); printf(" HEIGHT = %4d\n",fy); TIMinfo.pW = fx; TIMinfo.pH = fy; if(TIMinfo.pmode == 0)readPIC_4bit(); if(TIMinfo.pmode == 1)readPIC_8bit(); if(TIMinfo.pmode == 2)readPIC_15bit(); if(TIMinfo.pmode == 3)readPIC_24bit(); } void readPAL_4bit(){ unsigned char clutp[2]; unsigned int x,*r,rr,*g,gg,*b,bb,ind = 0; printf(" : PAL informations..\n"); for(x=0;x<16;x++){ fread(&clutp,1,2,TIMf); r = (unsigned int *)clutp; rr = *r; rr = (rr & 31)*1; if(rr>63) rr = 63; g = (unsigned int *)clutp; gg = *g; gg = ((gg>>5) & 31)*1; if(gg>63) gg = 63; b = (unsigned int *)clutp; bb = *b; bb = ((bb>>10) & 31)*1; if(bb>63) bb = 63; TIMinfo.bit4_pal[ind] = rr; TIMinfo.bit4_pal[ind+1] = gg; TIMinfo.bit4_pal[ind+2] = bb; ind+=3; } } void readPAL_8bit(){ unsigned char clutp[2]; unsigned int x,*r,rr,*g,gg,*b,bb,ind = 0; printf(" : PAL informations..\n"); for(x=0;x<256;x++){ fread(&clutp,1,2,TIMf); r = (unsigned int *)clutp; rr = *r; rr = (rr & 31)*1; if(rr>63) rr = 63; g = (unsigned int *)clutp; gg = *g; gg = ((gg>>5) & 31)*1; if(gg>63) gg = 63; b = (unsigned int *)clutp; bb = *b; bb = ((bb>>10) & 31)*1; if(bb>63) bb = 63; TIMinfo.bit8_pal[ind] = rr;TIMinfo.bit8_pal[ind+1] = gg;TIMinfo.bit8_pal[ind+2] = bb; ind+=3; } } void readPIC_4bit(){ long x,y,ind=0; unsigned char c,c1,c2,*picP; TIMinfo.picW = TIMinfo.pW*4; TIMinfo.picH = TIMinfo.pH; TIMinfo.picdata_char = (unsigned char *)malloc(TIMinfo.picW*TIMinfo.picH); picP = TIMinfo.picdata_char; for(y=0;y>4; *picP = c1; picP++; *picP = c2; picP++; } } void readPIC_8bit(){ long x,y,ind=0; unsigned char c,*picP; TIMinfo.picW = TIMinfo.pW*2; TIMinfo.picH = TIMinfo.pH; TIMinfo.picdata_char = (unsigned char *)malloc(TIMinfo.picW*TIMinfo.picH); picP = TIMinfo.picdata_char; for(y=0;y63) rr = 63; g = (unsigned int *)clutp; gg = *g; gg = ((gg>>5) & 31)*1; if(gg>63) gg = 63; b = (unsigned int *)clutp; bb = *b; bb = ((bb>>10) & 31)*1; if(bb>63) bb = 63; farbe = bb + (gg<<5) + (rr<<10); *picP = farbe; picP++; } } void readPIC_24bit(){ unsigned char rgb[3]; unsigned short *picP,farbe; long x,y,datalen = 0; TIMinfo.picW = ((long)(TIMinfo.pW/3)<<1); TIMinfo.picH = TIMinfo.pH; datalen = TIMinfo.picW*TIMinfo.picH*2; TIMinfo.picdata_char = (unsigned char *)malloc(datalen); picP = (unsigned short *)TIMinfo.picdata_char; for(y=0;y>3) + ((rgb[1]>>3)<<5) + ((rgb[0]>>3)<<10); *picP = farbe; picP++; } } void main(int c,char *gc[]){ char *infile; printf("\n TIM image util by Yan aka ASC/Nowadays (c) 1998\n\n"); if (c > 1){ strcpy(infile,gc[1]); if (!strchr(gc[1], '.')) strcat(infile, ".TIM"); if(openTIM(infile)){ printf(" : open TIMfile [%s]\n",infile); readID(); readFLAG(); if(TIMinfo.cts)readCLUT(); readDATA(); closeTIM(); if(detect_vesamode())view_tim(); } else printf(" : couldn't open TIMfile [%s]\n",infile); } else { printf(" Syntax: VTIM.EXE file.TIM\n\n"); printf(" If something won't work, please let me know! [mailto:asc@netlink.ch]\n"); } }