1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
/* testSTIM() */
/* Rip_STIM() */
/* Depack_STIM() */
/* update on the 3rd of april 2000 */
/* bug pointes out by Thomas Neumann ... thx */
#include "globals.h"
#include "extern.h"
short testSTIM ( void )
{
PW_Start_Address = PW_i;
/* */
PW_j = ((in_data[PW_Start_Address+4]*256*256*256)+
(in_data[PW_Start_Address+5]*256*256)+
(in_data[PW_Start_Address+6]*256)+
in_data[PW_Start_Address+7]);
if ( PW_j < 406 )
{
return BAD;
}
/* size of the pattern list */
PW_k = ((in_data[PW_Start_Address+18]*256)+
in_data[PW_Start_Address+19]);
if ( PW_k > 128 )
{
return BAD;
}
/* nbr of pattern saved */
PW_k = ((in_data[PW_Start_Address+20]*256)+
in_data[PW_Start_Address+21]);
if ( (PW_k > 64) || (PW_k == 0) )
{
return BAD;
}
/* pattern list */
for ( PW_l=0 ; PW_l<128 ; PW_l++ )
{
if ( in_data[PW_Start_Address+22+PW_l] > PW_k )
{
return BAD;
}
}
/* test sample sizes */
PW_WholeSampleSize = 0;
for ( PW_l=0 ; PW_l<31 ; PW_l++ )
{
/* addresse de la table */
PW_o = PW_Start_Address+PW_j+PW_l*4;
/* address du sample */
PW_k = ((in_data[PW_o]*256*256*256)+
(in_data[PW_o+1]*256*256)+
(in_data[PW_o+2]*256)+
in_data[PW_o+3]);
/* taille du smp */
PW_m = ((in_data[PW_o+PW_k-PW_l*4]*256)+
in_data[PW_o+PW_k+1-PW_l*4])*2;
PW_WholeSampleSize += PW_m;
}
if ( PW_WholeSampleSize <= 4 )
{
return BAD;
}
/* PW_WholeSampleSize is the size of the sample data */
/* PW_j is the address of the sample desc */
return GOOD;
}
void Rip_STIM ( void )
{
OutputSize = PW_WholeSampleSize + PW_j + 31*4 + 31*8;
CONVERT = GOOD;
Save_Rip ( "STIM (Slamtilt) module", STIM );
if ( Save_Status == GOOD )
PW_i += (OutputSize - 1); /* 0 should do but call it "just to be sure" :) */
}
/*
* STIM_Packer.c 1998 (c) Sylvain "Asle" Chipaux
*
* STIM Packer to Protracker.
********************************************************
* 13 april 1999 : Update
* - no more open() of input file ... so no more fread() !.
* It speeds-up the process quite a bit :).
* 28 Nov 1999 : Update
* - Speed & Size optimizings
*/
void Depack_STIM ( void )
{
Uchar *Whatever;
Uchar c1=0x00,c2=0x00,c3=0x00,c4=0x00;
Uchar poss[36][2];
Uchar Max=0x00;
Uchar Note,Smp,Fx,FxVal;
short TracksAdd[4];
long i=0,j=0,k=0;
long WholeSampleSize=0;
long SmpDescAdd=0;
long PatAdds[64];
long SmpDataAdds[31];
long SmpSizes[31];
long Where=PW_Start_Address; /* main pointer to prevent fread() */
FILE *out;
if ( Save_Status == BAD )
return;
fillPTKtable(poss);
BZERO ( PatAdds , 64*4 );
BZERO ( SmpDataAdds , 31*4 );
BZERO ( SmpSizes , 31*4 );
sprintf ( Depacked_OutName , "%ld.mod" , Cpt_Filename-1 );
out = PW_fopen ( Depacked_OutName , "w+b" );
/* write title */
Whatever = (Uchar *) malloc (1024);
BZERO ( Whatever , 1024 );
fwrite ( Whatever , 20 , 1 , out );
/* bypass ID */
Where += 4;
/* read $ of sample description */
SmpDescAdd = (in_data[Where]*256*256*256)+
(in_data[Where+1]*256*256)+
(in_data[Where+2]*256)+
in_data[Where+3];
/* "Where" isn't "+=4" coz it's assigned below */
/*printf ( "SmpDescAdd : %ld\n" , SmpDescAdd );*/
/* convert and write header */
for ( i=0 ; i<31 ; i++ )
{
Where = PW_Start_Address + SmpDescAdd + i*4;
SmpDataAdds[i]=(in_data[Where]*256*256*256)+
(in_data[Where+1]*256*256)+
(in_data[Where+2]*256)+
in_data[Where+3];
SmpDataAdds[i] += SmpDescAdd;
Where = PW_Start_Address + SmpDataAdds[i];
SmpDataAdds[i] += 8;
/* write sample name */
fwrite ( Whatever , 22 , 1 , out );
/* sample size */
SmpSizes[i] = (((in_data[Where]*256)+in_data[Where+1])*2);
WholeSampleSize += (((in_data[Where]*256)+in_data[Where+1])*2);
/* size,fine,vol,loops */
fwrite ( &in_data[Where] , 8 , 1 , out );
/* no "Where += 8" coz it's reassigned inside and after loop */
}
/* size of the pattern list */
Where = PW_Start_Address + 19;
fwrite ( &in_data[Where++] , 1 , 1 , out );
Whatever[0] = 0x7f;
fwrite ( Whatever , 1 , 1 , out );
/* pattern table */
Where += 1;
Max = in_data[Where++];
fwrite ( &in_data[Where] , 128 , 1 , out );
Where += 128;
/*printf ( "number of pattern : %d\n" , Max );*/
/* write Protracker's ID */
Whatever[0] = 'M';
Whatever[1] = '.';
Whatever[2] = 'K';
Whatever[3] = '.';
fwrite ( Whatever , 4 , 1 , out );
/* read pattern addresses */
for ( i=0 ; i<64 ; i++ )
{
PatAdds[i] = (in_data[Where]*256*256*256)+
(in_data[Where+1]*256*256)+
(in_data[Where+2]*256)+
in_data[Where+3];
PatAdds[i] += 0x0c;
Where += 4;
}
/* pattern data */
for ( i=0 ; i<Max ; i++ )
{
Where = PW_Start_Address + PatAdds[i];
for ( k=0 ; k<4 ; k++ )
{
TracksAdd[k] = (in_data[Where]*256)+in_data[Where+1];
Where += 2;
}
BZERO ( Whatever , 1024 );
for ( k=0 ; k<4 ; k++ )
{
Where = PW_Start_Address + PatAdds[i]+TracksAdd[k];
for ( j=0 ; j<64 ; j++ )
{
c1 = in_data[Where++];
if ( (c1&0x80) == 0x80 )
{
j += (c1&0x7F);
continue;
}
c2 = in_data[Where++];
c3 = in_data[Where++];
Smp = c1&0x1F;
Note = c2&0x3F;
Fx = ((c1>>5)&0x03);
c4 = ((c2>>4)&0x0C);
Fx |= c4;
FxVal = c3;
Whatever[j*16+k*4] = (Smp & 0xf0);
if ( Note != 0 )
{
Whatever[j*16+k*4] |= poss[Note-1][0];
Whatever[j*16+k*4+1] = poss[Note-1][1];
}
Whatever[j*16+k*4+2] = ((Smp<<4)&0xf0);
Whatever[j*16+k*4+2] |= Fx;
Whatever[j*16+k*4+3] = FxVal;
}
}
fwrite ( Whatever , 1024 , 1 , out );
/* printf ( "pattern %ld written\n" , i );*/
}
free ( Whatever );
/* sample data */
for ( i=0 ; i<31 ; i++ )
{
Where = PW_Start_Address + SmpDataAdds[i];
fwrite ( &in_data[Where] , SmpSizes[i] , 1 , out );
}
Crap ( " STIM (Slamtilt) " , BAD , BAD , out );
fflush ( out );
fclose ( out );
printf ( "done\n" );
return; /* useless ... but */
}
|