/* testZEN() */ /* Rip_ZEN() */ /* Depack_ZEN() */ #include "globals.h" #include "extern.h" int16_t testZEN ( void ) { /* test #1 */ if ( PW_i<9 ) { return BAD; } /* test #2 */ PW_Start_Address = PW_i-9; PW_l = ( (in_data[PW_Start_Address]*256*256*256)+ (in_data[PW_Start_Address+1]*256*256)+ (in_data[PW_Start_Address+2]*256)+ in_data[PW_Start_Address+3] ); if ( (PW_l<502) || (PW_l>2163190l) || (PW_l>(PW_in_size-PW_Start_Address)) ) { /*printf ( "#1 Start:%ld\n" , PW_Start_Address );*/ return BAD; } /* PW_l is the address of the pattern list */ /* volumes */ for ( PW_k = 0 ; PW_k < 31 ; PW_k ++ ) { if ( (( PW_Start_Address + 9 + (16*PW_k) ) > PW_in_size )|| (( in_data[PW_Start_Address + 9 + (16*PW_k)] > 0x40 ))) { /*printf ( "#2 Start:%ld\n" , PW_Start_Address );*/ return BAD; } } /* fine */ for ( PW_k = 0 ; PW_k < 31 ; PW_k ++ ) { PW_j = (in_data[PW_Start_Address+6+(PW_k*16)]*256)+in_data[PW_Start_Address+7+(PW_k*16)]; if ( ((PW_j/72)*72) != PW_j ) { /*printf ( "#3 Start:%ld\n" , PW_Start_Address );*/ return BAD; } } /* smp sizes .. */ PW_n = 0; for ( PW_k = 0 ; PW_k < 31 ; PW_k ++ ) { PW_o = (in_data[PW_Start_Address+10+PW_k*16]*256)+in_data[PW_Start_Address+11+PW_k*16]; PW_m = (in_data[PW_Start_Address+12+PW_k*16]*256)+in_data[PW_Start_Address+13+PW_k*16]; PW_j = ((in_data[PW_Start_Address+14+PW_k*16]*256*256*256)+ (in_data[PW_Start_Address+15+PW_k*16]*256*256)+ (in_data[PW_Start_Address+16+PW_k*16]*256)+ in_data[PW_Start_Address+17+PW_k*16] ); PW_o *= 2; PW_m *= 2; /* sample size and loop size > 64k ? */ if ( (PW_o > 0xFFFF)|| (PW_m > 0xFFFF) ) { /*printf ( "#4 Start:%ld\n" , PW_Start_Address );*/ return BAD; } /* sample address < pattern table address ? */ if ( PW_j < PW_l ) { /*printf ( "#4,1 Start:%ld\n" , PW_Start_Address );*/ return BAD; } /* too big an address ? */ if ( PW_j > PW_in_size ) { /*printf ( "#4,2 Start:%ld\n" , PW_Start_Address );*/ return BAD; } /* get the nbr of the highest sample address and its size */ if ( PW_j > PW_n ) { PW_n = PW_j; PW_WholeSampleSize = PW_o; } } /* PW_n is the highest sample data address */ /* PW_WholeSampleSize is the size of the same sample */ /* test size of the pattern list */ PW_j = in_data[PW_Start_Address+5]; if ( (PW_j > 0x7f) || (PW_j == 0) ) { /*printf ( "#5 Start:%ld\n" , PW_Start_Address );*/ return BAD; } /* test if the end of pattern list is $FFFFFFFF */ if ( (in_data[PW_Start_Address+PW_l+PW_j*4] != 0xFF ) || (in_data[PW_Start_Address+PW_l+PW_j*4+1] != 0xFF ) || (in_data[PW_Start_Address+PW_l+PW_j*4+2] != 0xFF ) || (in_data[PW_Start_Address+PW_l+PW_j*4+3] != 0xFF ) ) { /*printf ( "#6 Start:%ld\n" , PW_Start_Address );*/ return BAD; } /* PW_n is the highest address of a sample data */ /* PW_WholeSampleSize is its size */ return GOOD; } void Rip_ZEN ( void ) { /* PW_n is the highest sample data address */ /* PW_WholeSampleSize if its size */ OutputSize = PW_WholeSampleSize + PW_n; CONVERT = GOOD; Save_Rip ( "ZEN Packer module", ZEN ); if ( Save_Status == GOOD ) PW_i += (OutputSize - 10); /* 9 should do but call it "just to be sure" :) */ } /* * Zen_Packer.c 1998 (c) Asle / ReDoX * * Converts ZEN packed MODs back to PTK MODs ******************************************************** * 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 an size optimizings. * 03 april 2000 : Update * - small bug correction (harmless) * again pointed out by Thomas Neumann * Another Update : 26 nov 2003 * - used htonl() so that use of addy is now portable on 68k archs */ void Depack_ZEN ( void ) { uint8_t PatPos; uint8_t *Whatever; uint8_t PatMax; uint8_t poss[37][2]; uint8_t Note,Smp,Fx,FxVal; int32_t WholeSampleSize=0; int32_t Pattern_Address[128]; int32_t Pattern_Address_Real[128]; int32_t Pattern_Table_Address; int32_t Sample_Data_Address=999999l; int32_t i,j,k,z; int32_t Where=PW_Start_Address; /* main pointer to prevent fread() */ FILE *out; fillPTKtable(poss); if ( Save_Status == BAD ) return; BZERO ( Pattern_Address , 128*4); BZERO ( Pattern_Address_Real , 128*4); sprintf ( Depacked_OutName , "%d.mod" , Cpt_Filename-1 ); out = PW_fopen ( Depacked_OutName , "w+b" ); /* read pattern table address */ Pattern_Table_Address = (in_data[Where]*256*256*256)+ (in_data[Where+1]*256*256)+ (in_data[Where+2]*256)+ in_data[Where+3]; Where += 4; /* read patmax */ PatMax = in_data[Where++]; /* read size of pattern table */ PatPos = in_data[Where++]; /*printf ( "Size of pattern list : %d\n" , PatPos );*/ /* write title */ Whatever = (uint8_t *) malloc (1024); BZERO ( Whatever , 1024 ); fwrite ( Whatever , 20 , 1 , out ); for ( i=0 ; i<31 ; i++ ) { fwrite ( Whatever , 22 , 1 , out ); /* read sample size */ WholeSampleSize += (((in_data[Where+4]*256)+in_data[Where+5])*2); fwrite ( &in_data[Where+4] , 2 , 1 , out ); /* write fine */ Whatever[32] = ((in_data[Where]*256)+in_data[Where+1])/0x48; fwrite ( &Whatever[32] , 1 , 1 , out ); /* write volume */ fwrite ( &in_data[Where+3] , 1 , 1 , out ); /* read sample start address */ k = (in_data[Where+8]*256*256*256)+ (in_data[Where+9]*256*256)+ (in_data[Where+10]*256)+ in_data[Where+11]; if ( k>4)&0x0f); Fx = in_data[Where+2]&0x0f; /*fprintf ( info , "<-- note:%-2x smp:%-2x fx:%-2x fxval:%-2x\n" , Note,Smp,Fx,FxVal );*/ k=in_data[Where]; Whatever[k*4] = Smp&0xf0; Whatever[k*4] |= poss[Note][0]; Whatever[k*4+1] = poss[Note][1]; Whatever[k*4+2] = Fx | ((Smp<<4)&0xf0); Whatever[k*4+3] = FxVal; j = in_data[Where]; Where += 4; } fwrite ( Whatever , 1024 , 1 , out ); /*printf ( "." );*/ } free ( Whatever ); /*printf ( " ok\n" );*/ /* sample data */ fwrite ( &in_data[PW_Start_Address+Sample_Data_Address] , WholeSampleSize , 1 , out ); /* crap ... */ Crap ( " ZEN Packer " , BAD , BAD , out ); fflush ( out ); fclose ( out ); printf ( "done\n" ); return; /* useless ... but */ }