/* * * I need a program to keep the data but move the address * * The rom is used at 0xE000 to 0xFFFF * The Quartus 11 tool puts the memory at 0x0000 to 0x1FFF * * This needs the checksum and address recalculated * * Status: seems to work */ #include #include /********************************************************************/ /* prototype */ /********************************************************************/ //static int ReadHex(FILE *f); static int ReadHex(FILE *f, int * checksum ); /********************************************************************/ /* Load in Binary or Hex format file */ /********************************************************************/ int LoadObject(char *Object) { FILE *f; //unsigned int PCount,Count,Address,Type,Data,checksum,temp; // Check sum int sum = 0; int chksum = 0; f = fopen(Object,"r"); if (f == NULL){ fprintf(stderr,"usage: hexROMadjust.exe doug.hex > doug_1f.hex\n"); f =stdin ; } // f= STDIN_FILENO; /* These streams are declared in the header file stdio.h. Variable: FILE * stdin The standard input stream, which is the normal source of input for the program. Variable: FILE * stdout The standard output stream, which is used for normal output from the program. Variable: FILE * stderr The standard error stream, which is used for error messages and diagnostics issued by the program. */ PCount = 1; Data = fgetc(f); if (Data != ':') { fclose(f); return(0); } while (PCount != 0) { PCount = Count = ReadHex(f, &sum); printf( ":"); printf( "%02X", Count); //if Address // 0XE000 => 0X000 // Address = ReadHex(f , &sum); printf( "%02X", ( Address+( 0x00-0xE0 ) ) & 0xFF ); temp = ReadHex(f , &sum); printf( "%02X", temp ); Address = (Address << 8) + temp; Type = ReadHex(f, &sum); printf( "%02X", Type ); while (Count-- > 0) { Data = ReadHex(f, &sum); printf( "%02X", Data ); Address++; } // save checksum chksum = sum ; checksum = ReadHex(f, &sum ); printf( "%02X\n", ( checksum + ( 0x00+0xE0 ) ) & 0xFF ); //printf(":%02X:%02X:\n", -chksum & 0xFF ,sum ); if (PCount != 0) while ( fgetc(f) != ':') {} } fclose(f); return(-1); } static int ReadHex(FILE *f, int * checksum ) { int n,i,c; n = 0; for (i = 0;i < 2;i++) { c = fgetc(f);c = toupper(c); // printf("%c",c); if (c > '9') c = c - 'A'+10; else c = c - '0'; n = n * 16 + c; } checksum[0] += n; checksum[0] &= 0xFF; return(n); } int main(int argc, char **argv) { int c; char * filename = ""; fprintf(stderr,"ReAddress $E000 to $0000\n"); if ( argc > 1) { filename = argv[1] ; } else { fprintf(stderr,"usage: type doug.hex | hexROMadjust.exe > doug_1f.hex\n"); fprintf(stderr,"usage: hexROMadjust.exe doug.hex > doug_1f.hex\n"); } LoadObject(filename); }