/* testP41A() */ /* Rip_P41A() */ /* Depack_P41A() */ #include "globals.h" #include "extern.h" int16_t 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 ) { int32_t seed=0; /* potential fake address if rip from memory - thus, start address*/ 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] ); PW_m = ( (in_data[PW_Start_Address+12]*256*256*256) + (in_data[PW_Start_Address+13]*256*256) + (in_data[PW_Start_Address+14]*256) + in_data[PW_Start_Address+15] ); /* check here for memory addresses, which are screwed up */ PW_j = (in_data[PW_Start_Address+6]*16)+4+12; if ( PW_j != PW_m ) { /* it's memory addresses then */ seed = (PW_m - PW_j); PW_l -= seed; } /* get whole sample size */ /* PW_k is the number of samples */ 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 ) { uint8_t c1,c2,c3,c4,c5; uint8_t *Whatever; uint8_t PatPos = 0x00; uint8_t Nbr_Sample = 0x00; uint8_t poss[37][2]; uint8_t sample,note,Note[2]; uint8_t Track_Data[512][256]; int16_t Track_Addresses[128][4]; int32_t Track_Data_Address = 0; int32_t Track_Table_Address = 0; int32_t Sample_Data_Address = 0; int32_t WholeSampleSize = 0; int32_t SampleAddress[31]; int32_t SampleSize[31]; int32_t i=0,j,k,l,a,c,z; int32_t 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 , "%d.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; /* check here for memory addresses, which are screwed up */ i = (Nbr_Sample*16)+4+12; if ( i != Track_Table_Address ) { /* it's memory addresses then */ int32_t seed = (Track_Table_Address - i); Track_Data_Address -= seed; Track_Table_Address -= seed; Sample_Data_Address -= seed; } /* write title */ Whatever = (uint8_t *) 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