/* (3rd of april 2000) * bugs pointed out by Thomas Neumann .. thx :) */ /* testKRIS() */ /* Rip_KRIS() */ /* Depack_KRIS() */ #include "globals.h" #include "extern.h" int16_t testKRIS ( void ) { /* test 1 */ if ( (PW_i<952) || ((PW_Start_Address+977)>PW_in_size) ) { return BAD; } /* test 2 */ PW_Start_Address = PW_i-952; for ( PW_j=0 ; PW_j<31 ; PW_j++ ) { /* volume > 64 ? */ if ( in_data[PW_Start_Address+47+PW_j*30] > 0x40 ) { return BAD; } /* finetune > 15 ? */ if ( in_data[PW_Start_Address+46+PW_j*30] > 0x0f ) { return BAD; } } return GOOD; } /* * Update: 20/12/2000 * - debug .. correct size calculated now. * Update: 01/09/2010 * - debug .. pattern data size scan only on patternlist size */ void Rip_KRIS ( void ) { /* nothing was calculated in the test part */ PW_WholeSampleSize = 0; for ( PW_k=0 ; PW_k<31 ; PW_k++ ) PW_WholeSampleSize += (((in_data[PW_Start_Address+44+PW_k*30]*256)+in_data[PW_Start_Address+45+PW_k*30])*2); /*printf ("\nKRIS:smpsiz:%ld\n", PW_WholeSampleSize);*/ PW_l = 0; /*printf ("KRIS:");*/ /* 20100901 : 128 replaced by patternlist size */ for ( PW_k=0 ; PW_k<(in_data[PW_Start_Address+956]*4) ; PW_k++ ) { /*printf ( "%2x-%2x ",in_data[PW_Start_Address+958+PW_k*2],in_data[PW_Start_Address+959+PW_k*2]);*/ if ( (in_data[PW_Start_Address+958+PW_k*2]*256)+in_data[PW_Start_Address+959+PW_k*2] > PW_l ) PW_l = (in_data[PW_Start_Address+958+PW_k*2]*256)+in_data[PW_Start_Address+959+PW_k*2]; } /*printf ("\nKRIS:patsiz:%ld\n",PW_l);*/ PW_k = 1984 + PW_l + 256; OutputSize = PW_k + PW_WholeSampleSize; CONVERT = GOOD; Save_Rip ( "KRIS Tracker module", KRIS_tracker ); if ( Save_Status == GOOD ) PW_i += 954; /* 953 should do but call it "just to be sure" :) */ } /* * Kris_packer.c 1997-2000 (c) Asle / ReDoX * * Kris Tracker to Protracker. * * Update: 28/11/1999 * - removed fopen() * - Overall Speed and Size optimizings. * Update: 03/04/2000 * - no more sample beginning with $01 :) (Thomas Neumann again ... thx) * Update: 20/12/2000 * - major debugging around the patterntable ... * Update: 02/10/2005 * - testing fopen() */ void Depack_KRIS ( void ) { uint8_t *Whatever; uint8_t c1=0x00,c2=0x00; uint8_t poss[37][2]; uint8_t Max=0x00; uint8_t Note,Smp,Fx,FxVal; uint8_t TrackData[512][256]; uint8_t PatternTableSize=0x00; uint8_t PatternTable[128]; int16_t TrackAddressTable[128][4]; int32_t i=0,j=0,k=0; int32_t WholeSampleSize=0; int32_t Where = PW_Start_Address; int16_t MaxTrackAddress=0; FILE *out; /*FILE *debug;*/ if ( Save_Status == BAD ) return; sprintf ( Depacked_OutName , "%d.mod" , Cpt_Filename-1 ); out = PW_fopen ( Depacked_OutName , "w+b" ); /*debug = fopen ( "debug.txt" , "w+b" );*/ fillPTKtable(poss); BZERO ( TrackAddressTable , 128*4*2 ); BZERO ( TrackData , 512*256 ); BZERO ( PatternTable , 128 ); /* title */ fwrite ( &in_data[Where] , 20 , 1 , out ); Where += 22; /* 20 + 2 */ /* 31 samples */ Whatever = (uint8_t *) malloc (1024); BZERO (Whatever , 1024); for ( i=0 ; i<31 ; i++ ) { /* sample name,siz,fine,vol */ if ( in_data[Where] == 0x01 ) { fwrite ( Whatever , 20 , 1 , out ); fwrite ( &in_data[Where+20] , 6 , 1 , out ); } else fwrite ( &in_data[Where] , 26 , 1 , out ); /* size */ WholeSampleSize += (((in_data[Where+22]*256)+in_data[Where+23])*2); /* loop start */ c1 = in_data[Where+26]/2; c2 = in_data[Where+27]/2; if ( (c1*2) != in_data[Where+26] ) c2 += 1; fwrite ( &c1 , 1 , 1 , out ); fwrite ( &c2 , 1 , 1 , out ); /* loop size */ fwrite ( &in_data[Where+28] , 2 , 1 , out ); Where += 30; } /*printf ( "Whole sample size : %ld\n" , WholeSampleSize );*/ /* bypass ID "KRIS" */ Where += 4; /* number of pattern in pattern list */ /* Noisetracker restart byte */ PatternTableSize = in_data[Where]; fwrite ( &in_data[Where] , 2 , 1 , out ); Where += 2; /* pattern table (read,count and write) */ c1 = 0x00; k=0; for ( i=0 ; i MaxTrackAddress ) MaxTrackAddress = TrackAddressTable[k][j]; Where += 2; /*fprintf ( debug , "- %4d" , TrackAddressTable[k][j] );*/ } /*fprintf ( debug , "\n" );*/ for ( j=0 ; j patterntable[%ld] : %ld\n" , i , PatternTable[i] );*/ k-=1; j = 9999l; /* hum ... sure now ! */ break; } /*fprintf ( debug , "\n" );*/ } if ( k == j ) { PatternTable[i] = c1; c1 += 0x01; /*fprintf ( debug , "---> patterntable[%ld] : %d\n" , i , PatternTable[i] );*/ } fwrite ( &PatternTable[i] , 1 , 1 , out ); } Max = c1; c1 = 0x00; while (i++<128) { fwrite (&c1,1,1,out); Where += 8; } /*printf ( "Number of patterns : %d\n" , Max );*/ /* ptk ID */ Whatever[0] = 'M'; Whatever[1] = '.'; Whatever[2] = 'K'; Whatever[3] = '.'; fwrite ( Whatever , 4 , 1 , out ); /* bypass two unknown bytes */ Where += 2; /* Track data ... */ for ( i=0 ; i<=(MaxTrackAddress/256) ; i+=1 ) { BZERO ( Whatever , 1024 ); for ( j=0 ; j<256 ; j++ ) Whatever[j] = in_data[Where+j]; Where += 256; /*printf ("[track %ld] (%ld)\n",i,Where);*/ for ( j=0 ; j<64 ; j++ ) { Note = Whatever[j*4]; Smp = Whatever[j*4+1]; Fx = Whatever[j*4+2] & 0x0f; FxVal = Whatever[j*4+3]; TrackData[i][j*4] = (Smp & 0xf0); /*if ( (Note < 0x46) || (Note > 0xa8) )*/ /*printf ( "!! Note value : %x (beside ptk 3 octaves limit)\n" , Note );*/ if ( Note != 0xa8 ) { TrackData[i][j*4] |= poss[(Note/2)-35][0]; TrackData[i][j*4+1] |= poss[(Note/2)-35][1]; } TrackData[i][j*4+2] = (Smp<<4)&0xf0; TrackData[i][j*4+2] |= (Fx & 0x0f); TrackData[i][j*4+3] = FxVal; } } for ( i=0 ; i