/* testP41A() */ /* Rip_P41A() */ /* Depack_P41A() */ #include "globals.h" #include "extern.h" short testP41A ( void ) { PW_Start_Address = PW_i; /* number of pattern (real) */ PW_j = in_data[PW_Start_Address+4]; if ( PW_j > 0x7f ) { return BAD; } /* number of sample */ PW_k = in_data[PW_Start_Address+6]; if ( (PW_k > 0x1F) || (PW_k == 0) ) { return BAD; } /* test volumes */ for ( PW_l=0 ; PW_l 0x40 ) { return BAD; } } /* test sample sizes */ PW_WholeSampleSize = 0; for ( PW_l=0 ; PW_l 0xFFFF) || (PW_n > 0xFFFF) ) { return BAD; } if ( PW_n > (PW_o+2) ) { return BAD; } PW_WholeSampleSize += PW_o; } if ( PW_WholeSampleSize <= 4 ) { return BAD; } /* PW_WholeSampleSize is the size of the sample data .. WRONG !! */ /* PW_k is the number of samples */ return GOOD; } void Rip_P41A ( void ) { PW_l = ( (in_data[PW_Start_Address+16]*256*256*256) + (in_data[PW_Start_Address+17]*256*256) + (in_data[PW_Start_Address+18]*256) + in_data[PW_Start_Address+19] ); /* get whole sample size */ PW_o = 0; for ( PW_j=0 ; PW_j PW_o ) { PW_o = PW_m; PW_n = ( (in_data[PW_Start_Address+24+PW_j*16]*256) + in_data[PW_Start_Address+25+PW_j*16] ); } } OutputSize = PW_l + PW_o + (PW_n*2) + 4; CONVERT = GOOD; Save_Rip ( "The Player 4.1A module", P41A ); if ( Save_Status == GOOD ) PW_i += (OutputSize - 2); /* 1 should do but call it "just to be sure" :) */ } /* * The_Player_4.1a.c 1997 (c) Asle / ReDoX * * The Player 4.1a to Protracker. * * Note: It's a REAL mess !. It's VERY badly coded, I know. Just dont forget * it was mainly done to test the description I made of P41a format. I * certainly wont dare to beat Gryzor on the ground :). His Prowiz IS * the converter to use !!!. * * Update: 28/11/99 * - removed fopen() and all attached functions. * - overall speed and size optimizings. * Update : 26 nov 2003 * - used htonl() so that use of addy is now portable on 68k archs */ void Depack_P41A ( void ) { Uchar c1,c2,c3,c4,c5; Uchar *Whatever; Uchar PatPos = 0x00; Uchar Nbr_Sample = 0x00; Uchar poss[37][2]; Uchar sample,note,Note[2]; Uchar Track_Data[512][256]; short Track_Addresses[128][4]; long Track_Data_Address = 0; long Track_Table_Address = 0; long Sample_Data_Address = 0; long WholeSampleSize = 0; long SampleAddress[31]; long SampleSize[31]; long i=0,j,k,l,a,c,z; long Where = PW_Start_Address; FILE *out; if ( Save_Status == BAD ) return; BZERO ( Track_Addresses , 128*4*2 ); BZERO ( Track_Data , 512*256 ); BZERO ( SampleAddress , 31*4 ); BZERO ( SampleSize , 31*4 ); fillPTKtable(poss); sprintf ( Depacked_OutName , "%ld.mod" , Cpt_Filename-1 ); out = PW_fopen ( Depacked_OutName , "w+b" ); /* read check ID */ Where += 4; /* bypass Real number of pattern */ Where += 1; /* read number of pattern in pattern list */ PatPos = in_data[Where++]; /* read number of samples */ Nbr_Sample = in_data[Where++]; /* bypass empty byte */ Where += 1; /**********/ /* read track data address */ Track_Data_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 track table address */ Track_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 sample data address */ Sample_Data_Address = (in_data[Where]*256*256*256)+ (in_data[Where+1]*256*256)+ (in_data[Where+2]*256)+ in_data[Where+3]; Where += 4; /* write title */ Whatever = (Uchar *) malloc ( 1024 ); BZERO ( Whatever , 1024 ); fwrite ( Whatever , 20 , 1 , out ); /* sample headers stuff */ for ( i=0 ; i>4)&0x0f); BZERO ( Note , 2 ); note = c1 & 0x7f; Note[0] = poss[(note/2)][0]; Note[1] = poss[(note/2)][1]; switch ( c2&0x0f ) { case 0x08: c2 -= 0x08; break; case 0x05: case 0x06: case 0x0A: c3 = (c3 > 0x7f) ? ((0x100-c3)<<4) : c3; // if ( c3 >= 0x80 ) // c3 = (c3<<4)&0xf0; break; default: break; } Track_Data[i*4+j][k*4] = (sample&0xf0) | (Note[0]&0x0f); Track_Data[i*4+j][k*4+1] = Note[1]; Track_Data[i*4+j][k*4+2] = c2; Track_Data[i*4+j][k*4+3] = c3; if ( (c4 > 0x00) && (c4 <0x80) ) k += c4; if ( (c4 > 0x7f) && (c4 <=0xff) ) { k+=1; for ( l=256 ; l>c4 ; l-- ) { Track_Data[i*4+j][k*4] = (sample&0xf0) | (Note[0]&0x0f); Track_Data[i*4+j][k*4+1] = Note[1]; Track_Data[i*4+j][k*4+2] = c2; Track_Data[i*4+j][k*4+3] = c3; k+=1; } k -= 1; } } else { a = Where; c5 = c2; Where = PW_Start_Address + (c3 * 256) + c4 + Track_Data_Address + 4; /*fprintf ( debug , "%2d (pattern %ld)(at %x)\n" , c2 , i , a-4 );*/ for ( c=0 ; c<=c5 ; c++ ) { /*fprintf ( debug , "%ld," , k );*/ c1 = in_data[Where++]; c2 = in_data[Where++]; c3 = in_data[Where++]; c4 = in_data[Where++]; sample = ((c1<<4)&0x10) | ((c2>>4)&0x0f); BZERO ( Note , 2 ); note = c1 & 0x7f; Note[0] = poss[(note/2)][0]; Note[1] = poss[(note/2)][1]; switch ( c2&0x0f ) { case 0x08: c2 -= 0x08; break; case 0x05: case 0x06: case 0x0A: c3 = (c3 > 0x7f) ? ((0x100-c3)<<4) : c3; // if ( c3 >= 0x80 ) // c3 = (c3<<4)&0xf0; break; default: break; } Track_Data[i*4+j][k*4] = (sample&0xf0) | (Note[0]&0x0f); Track_Data[i*4+j][k*4+1] = Note[1]; Track_Data[i*4+j][k*4+2] = c2; Track_Data[i*4+j][k*4+3] = c3; if ( (c4 > 0x00) && (c4 <0x80) ) k += c4; if ( (c4 > 0x7f) && (c4 <=0xff) ) { k+=1; for ( l=256 ; l>c4 ; l-- ) { Track_Data[i*4+j][k*4] = (sample&0xf0) | (Note[0]&0x0f); Track_Data[i*4+j][k*4+1] = Note[1]; Track_Data[i*4+j][k*4+2] = c2; Track_Data[i*4+j][k*4+3] = c3; k+=1; } k -= 1; } k += 1; } k -= 1; Where = a; /*fprintf ( debug , "\n## back to %x\n" , a );*/ } } } } /*printf ( "ok\n" );*/ /* for ( i=0 ; i