#include <stdio.h> unsigned short CalculateCRC( unsigned char *buf, short num ); void shortCRC( void ); void searchID_CRC( void ); void MFM512_CRC( void ); void MFM256_CRC( void ); void searchID_CRC2( void ); void MFM512_CRC2( void ); void MFM256_CRC2( void ); void shortCRC2( void ); /******** main ***************/ void main( void ) { // shortCRC(); searchID_CRC(); // MFM512_CRC(); // MFM256_CRC(); // searchID_CRC2(); // MFM512_CRC2(); // MFM256_CRC2(); // shortCRC2(); } /****************************/ void shortCRC( void ) // To test crc for short run of data. { char msg[32]; unsigned short crc; *(msg+0)= 0x02; *(msg+1)= 0x00; *(msg+2)= 0x03; *(msg+3)= 0x02; *(msg+4)= 0x41; *(msg+5)= 0x65; crc = CalculateCRC( (unsigned char*)(msg+0), 6 ); printf(" crc= %4x \n",crc ); } /*************************/ void searchID_CRC( void ) // To search for init value for ID data. { // The answer is 0x00377500. char msg[32]; short i,j; unsigned short *pt; unsigned short crc; pt = (unsigned short*)msg; *(msg+2)= 0x02; *(msg+3)= 0x00; *(msg+4)= 0x03; *(msg+5)= 0x02; *(msg+6)= 0x41; *(msg+7)= 0x65; for( i=0x0000; ; i++) { *pt = i; if( i % 256 == 0 ) printf ("%4x\n",i); crc = CalculateCRC( (unsigned char*)msg, 8 ); if ( crc == 0 ) break; } printf("found! %4x CRC(forID)=%4x \n", i, crc); } /******************************/ void MFM512_CRC( void ) // To search for init value for // MFM-disk 512 data. { // The answer is 0x00377000; char msg[600]; short i,j; unsigned short *pt, *pt2; unsigned short crc; pt = (unsigned short*)msg; for( i=0 ; i< 512; i++ ) *(msg+i+2) = 0xf6; pt2 = (unsigned short*)(msg+2+512); *pt2 = 0x2bf6; // given CRC value for( i=0x2000; ; i++) { *pt = i; if( i % 256 == 0 ) printf ("%4x\n",i); crc = CalculateCRC( (unsigned char*)msg, 512+4 ); if ( crc == 0 ) break; } printf("found! %4x CRC(forMFM512)=%4x \n", i, crc); } /**************************/ void MFM256_CRC( void ) // To search for init value for // MFM-disk 256 data. { // The answer is 0x00377000. char msg[300]; short i,j; unsigned short *pt, *pt2; unsigned short crc; pt = (unsigned short*)msg; for( i=0 ; i< 256; i++ ) *(msg+i+2) = 0x21; pt2 = (unsigned short*)(msg+2+256); *pt2 = 0x84ed; // given CRC value for( i=0x0000; ; i++) { *pt = i; if( i % 256 == 0 ) printf ("%4x\n",i); crc = CalculateCRC( (unsigned char*)msg, 256+4 ); if ( crc == 0 ) break; } printf("found! %4x CRC(forMFM256)=%4x \n", i, crc ); } /*************************/ void searchID_CRC2( void ) // To search for init value for // ID data including IAM. { // The answer is 0x0084CF00. char msg[32]; short i,start; unsigned short *pt; unsigned short crc; start=0; pt = (unsigned short*)(msg+start); *(msg+2)= 0xA1; *(msg+3)= 0xA1; *(msg+4)= 0xA1; *(msg+5)= 0xFE; *(msg+6)= 0x02; *(msg+7)= 0x00; *(msg+8)= 0x03; *(msg+9)= 0x02; *(msg+10)= 0x41; *(msg+11)= 0x65; for( i=0x0000; i<= 0xffff; i++) { *pt = i; if( i % 256 == 0 ) printf ("%4x\n",i); crc = CalculateCRC( (unsigned char*)(msg+start), 12-start ); if ( crc == 0 ) break; } printf("found! %4x CRC(forID)=%4x \n", i, crc); } /******************************/ void MFM512_CRC2( void ) // To search for init value for MFM-disk // 512 data including IAM. { // The answer is 0x0084CF00. char msg[600]; short i,j; unsigned short *pt, *pt2; unsigned short crc; pt = (unsigned short*)msg; *(pt+1) = 0xA1A1; *(pt+2) = 0xA1FB; for( i=0 ; i< 512; i++ ) *(msg+i+6) = 0xF6; pt2 = (unsigned short*)(msg+6+512); *pt2 = 0x2BF6; // given CRC value for( i=0x7000; ; i++) { *pt = i; if( i % 256 == 0 ) printf ("%4x\n",i); crc = CalculateCRC( (unsigned char*)msg, 512+8 ); if ( crc == 0 ) break; } printf("found! %4x CRC(forMFM512)=%4x \n", i, crc); } /**************************/ void MFM256_CRC2( void ) // To search for init value for MFM-disk // 256 data including IAM. { // The answer is 0x0084CF00. char msg[300]; short i,j; unsigned short *pt, *pt2; unsigned short crc; pt = (unsigned short*)msg; *(pt+1) = 0xA1A1; *(pt+2) = 0xA1FB; for( i=0 ; i< 256; i++ ) *(msg+i+6) = 0x21; pt2 = (unsigned short*)(msg+6+256); *pt2 = 0x84ed; // given CRC value for( i=0x6000; ; i++) { *pt = i; if( i % 256 == 0 ) printf ("%4x\n",i); crc = CalculateCRC( (unsigned char*)msg, 256+8 ); if ( crc == 0 ) break; } printf("found! %4x CRC(forMFM256)=%4x \n", i, crc ); } /****************************/ void shortCRC2( void ) // To test crc for short run // of data including IAM. { char msg[32]; unsigned short crc; *(msg+0)= 0x84; *(msg+1)= 0xCF; *(msg+2)= 0xA1; *(msg+3)= 0xA1; *(msg+4)= 0xA1; *(msg+5)= 0xFE; *(msg+6)= 0x02; *(msg+7)= 0x00; *(msg+8)= 0x03; *(msg+9)= 0x02; *(msg+10)= 0x41; *(msg+11)= 0x65; crc = CalculateCRC( (unsigned char*)(msg+0), 12 ); printf(" crc= %4x \n",crc ); }