#include // This program reads an ORCA bit file and converts it to a binary file to // be used by the XBERT. For the Pbert, this conversion is a simple // bit reversal for each byte (after stripping of the 0x41 byte header). // For the remote modules (TBERT, RBERT), 12 bits are packed into a 36-bit // serial word. Each data bit has a start bit (1) and a stop bit (0). void Set_ext(char *Name, char *Ext, int Flag) // Set file extension { char *P= 0; // If (Flag) force it while (*Name) { if (*Name=='/' || *Name=='\\') P=0; if (*Name=='.') P= Name; ++Name; } if (Flag==0 && P) return; // Extension already exists and no Flag if (P==0) P=Name; // No extension, add to end while ((*P++ = *Ext++) !=0); // Copy } int main (int Argc, char *Argv[]) { unsigned long D,L; int I,B; char Name[128]; FILE *In, *Out; if (Argc < 2) { printf("Usage:\n bit2brt [-r] file[.bit]\n"); printf(" Converts ORCA bit files for use by XBERT\n"); printf(" Use -r option for remote modules\n"); return(-1); } for (I=0; (Name[I]= Argv[Argc-1][I])!=0; ++I); Set_ext(Name,".bit",0); if ((In= fopen(Name,"rb")) == NULL) { printf("Couldn't open bit file [%s] for input.\n",Name); return(-1); } fseek(In,0x41,0); // Point to first data byte Set_ext(Name,".brt",1); // Force .brt extension if ((Out= fopen(Name,"wb")) == NULL) { printf("Couldn't open brt file [%s] for output.\n",Name); return(-1); } if (Argc == 2) // If no -r option on command line { while (fread(&B,1,1,In) > 0) { B= ((B<<1)&0xaa) | ((B>>1)&0x55); // Reverse bits... B= ((B<<2)&0xcc) | ((B>>2)&0x33); // Swap 2-bits B= (B<<4) | (B>>4); // Swap nibbles fwrite(&B,1,1,Out); } } else // if -r then prepare to be sent via serial port #define SetBit(Bi,Bo) if (D&(1L<