/* testPMZ() */ /* Rip_PM18a() */ /* Depack_PM18a() */ #include "globals.h" #include "extern.h" int16_t testPMZ ( void ) { PW_Start_Address = PW_i; /* test 1 */ if ( (PW_Start_Address + 4456) > PW_in_size ) { return BAD; } /* test 2 */ /* if ( in_data[PW_Start_Address + 21] != 0xd2 ) { return BAD; }*/ /* test 3 */ PW_j = (in_data[PW_Start_Address+4456]*256*256*256)+(in_data[PW_Start_Address+4457]*256*256)+(in_data[PW_Start_Address+4458]*256)+in_data[PW_Start_Address+4459]; if ( (PW_Start_Address + PW_j + 4456) > PW_in_size ) { return BAD; } /* test 4 */ PW_k = (in_data[PW_Start_Address+4712]*256)+in_data[PW_Start_Address+4713]; PW_l = PW_k/4; PW_l *= 4; if ( PW_l != PW_k ) { return BAD; } /* test 5 */ if ( in_data[PW_Start_Address + 36] != 0x11 ) { return BAD; } /* test 6 */ if ( in_data[PW_Start_Address + 37] != 0x00 ) { return BAD; } return GOOD; } void Rip_PM18a ( void ) { /* we NEED this 'PW_j' value found while testing !,so we keep it :) */ PW_WholeSampleSize = 0; for ( PW_k=0 ; PW_k<31 ; PW_k++ ) PW_WholeSampleSize += (((in_data[PW_Start_Address+4464+8*PW_k]*256)+in_data[PW_Start_Address+4465+8*PW_k])*2); OutputSize = 4460 + PW_j + PW_WholeSampleSize; CONVERT = GOOD; Save_Rip ( "Promizer 1.8a module", Promizer_18a ); if ( Save_Status == GOOD ) PW_i += (OutputSize - 2); /* 1 should do but call it "just to be sure" :) */ } /* * Promizer_18a.c 1997 (c) Asle / ReDoX * * Converts PM18a packed MODs back to PTK MODs * thanks to Gryzor and his ProWizard tool ! ... without it, this prog * would not exist !!! * * update 20 mar 2003 (it's war time again .. brrrr) * - removed all open() funcs. * - optimized more than quite a bit (src is 5kb int16_t er !) * * update 07 jan 2010 * - bug fix in patternlist generation */ #define ON 0 #define OFF 1 void Depack_PM18a ( void ) { uint8_t c1=0x00,c2=0x00; int16_t Ref_Max=0; int32_t Pats_Address[128]; int32_t Read_Pats_Address[128]; uint8_t NOP=0x00; /* number of pattern */ uint8_t *ReferenceTable; uint8_t *Pattern; int32_t i=0,j=0,k=0,l=0,m=0; int32_t Total_Sample_Size=0; int32_t PatDataSize=0l; int32_t SDAV=0l; uint8_t FLAG=OFF; uint8_t Smp_Fine_Table[31]; uint8_t poss[37][2]; uint8_t OldSmpValue[4]; int16_t Period; uint8_t *Whatever; int32_t Where = PW_Start_Address; uint8_t *WholePatternData; FILE *out; /*FILE *info; info = fopen ("info.txt","w+b");*/ #include "tuning.h" fillPTKtable(poss); if ( Save_Status == BAD ) return; sprintf ( Depacked_OutName , "%d.mod" , Cpt_Filename-1 ); out = PW_fopen ( Depacked_OutName , "w+b" ); BZERO ( Smp_Fine_Table , 31 ); BZERO ( OldSmpValue , 4 ); BZERO ( Pats_Address , 128*4 ); Whatever = (uint8_t *) malloc (1085); BZERO (Whatever, 1085); /* title */ /*fwrite ( &Whatever[0] , 20 , 1 , out );*/ /* bypass replaycode routine */ Where = PW_Start_Address + 4464; for ( i=0 ; i<31 ; i++ ) { /*sample name*/ /*fwrite ( &Whatever[32] , 22 , 1 , out );*/ Whatever[42+30*i] = in_data[Where]; Whatever[43+30*i] = in_data[Where+1]; Whatever[44+30*i] = in_data[Where+2]; Whatever[45+30*i] = in_data[Where+3]; Whatever[46+30*i] = in_data[Where+4]; Whatever[47+30*i] = in_data[Where+5]; Whatever[48+30*i] = in_data[Where+6]; Whatever[49+30*i] = in_data[Where+7]; /*fwrite ( &in_data[Where], 8, 1, out );*/ Total_Sample_Size += (((in_data[Where]*256)+in_data[Where+1])*2); Smp_Fine_Table[i] = in_data[Where+2]; Where += 8; } /* pattern table lenght */ NOP = ((in_data[Where]*256)+in_data[Where+1])/4; /*fwrite ( &NOP , 1 , 1 , out );*/ Whatever[950] = NOP; Where += 2; /*printf ( "\nNumber of patterns : %d\n" , NOP );*/ /* NoiseTracker restart byte */ /*Whatever[0] = 0x7f;*/ /*fwrite ( &Whatever[0] , 1 , 1 , out );*/ Whatever[951] = 0x7f; for ( i=0 ; i<128 ; i++ ) { Pats_Address[i] = (in_data[Where]*256*256*256)+ (in_data[Where+1]*256*256)+ (in_data[Where+2]*256)+ in_data[Where+3]; Where += 4; } /* a little pre-calc code ... no other way to deal with these unknown pattern data sizes ! :( */ Where = PW_Start_Address + 4460; PatDataSize = (in_data[Where]*256*256*256)+ (in_data[Where+1]*256*256)+ (in_data[Where+2]*256)+ in_data[Where+3]; /* go back to pattern data starting address */ Where = PW_Start_Address + 5226; /* now, reading all pattern data to get the max value of note */ if (!(WholePatternData = (uint8_t *) malloc (PatDataSize+1))) { /*printf ("can't allocate %ld bytes\n",PatDataSize+1);*/ return; } /*printf ("Where : %ld (PatDataSize:%ld)\n",Where,PatDataSize);*/ BZERO (WholePatternData, PatDataSize+1); for ( j=0 ; j Ref_Max ) Ref_Max = ((WholePatternData[j]*256)+WholePatternData[j+1]); } Where += PatDataSize; /*printf ("Where : %ld (Ref_Max:%ld)\n",Where,Ref_Max);*/ /* read "reference Table" */ Ref_Max += 1; /* coz 1st value is 0 ! */ i = Ref_Max * 4; /* coz each block is 4 bytes int32_t */ if (!(ReferenceTable = (uint8_t *) malloc ( i+1 ))) { /*printf ("can't allocate %ld bytes\n",i+1);*/ return; } BZERO ( ReferenceTable, i+1 ); for ( j=0 ; j new pattern %2d (addy :%ld)\n", c1, j+5226 );*/ fflush (stdout); c1 += 0x01; } m = ((WholePatternData[j]*256)+WholePatternData[j+1])*4; Pattern[i] = ReferenceTable[m]; Pattern[i+1] = ReferenceTable[m+1]; Pattern[i+2] = ReferenceTable[m+2]; Pattern[i+3] = ReferenceTable[m+3]; /*printf ( "[%4x][%3ld][%ld]: %2x %2x %2x %2x", j,i,k%4,Pattern[i],Pattern[i+1],Pattern[i+2],Pattern[i+3]);*/ c2 = ((Pattern[i+2]>>4)&0x0f) | (Pattern[i]&0xf0); if ( c2 != 0x00 ) { OldSmpValue[k%4] = c2; } Period = ((Pattern[i]&0x0f)*256)+Pattern[i+1]; if ( (Period != 0) && (Smp_Fine_Table[OldSmpValue[k%4]-1] != 0x00) ) { for ( l=0 ; l<36 ; l++ ) if ( Tuning[Smp_Fine_Table[OldSmpValue[k%4]-1]][l] == Period ) { Pattern[i] &= 0xf0; Pattern[i] |= poss[l+1][0]; Pattern[i+1] = poss[l+1][1]; break; } } if ( ( (Pattern[i+2] & 0x0f) == 0x0d ) || ( (Pattern[i+2] & 0x0f) == 0x0b ) ) { /*fprintf ( info, " <-- B or D detected" );*/ FLAG = ON; } if ( (FLAG == ON) && ((k%4) == 3) ) { /*fprintf ( info, "\n -> bypassing end of pattern" );*/ FLAG=OFF; while ( (i%1024) != 0) i ++; i -= 4; } k += 1; i += 4; /*fprintf ( info, "\n" );*/ } free ( ReferenceTable ); free ( WholePatternData ); /* write pattern table */ /*BZERO ( Whatever, 128 );*/ for ( c2=0; c2<128 ; c2+=0x01 ) for ( i=0 ; i