/* * Copyright (c) 1999-2000 Tony Givargis. Permission to copy is granted * provided that this header remains intact. This software is provided * with no warranties. * * Version : 2.8 */ /*--------------------------------------------------------------------------*/ #include #include #include /*--------------------------------------------------------------------------*/ typedef struct { char *name; int msb; int lsb; int skip; } InsForm; /*--------------------------------------------------------------------------*/ extern const char *RomHeader; extern const char *RomFooter; extern const char *InsBitTbl[]; extern const InsForm InsFormTbl[]; /*--------------------------------------------------------------------------*/ unsigned Hex2Short(const char *buf) { int i; if( sscanf(buf, "%x", &i) != 1 ) { printf("hex file error\n"); exit(1); } return i; } /*--------------------------------------------------------------------------*/ int Load(char *buf, unsigned char *rom, unsigned romSize, unsigned *prgSize) { unsigned len, base, type, i; unsigned char checksum = 0; char hex[16]; if( buf[0] != ':' ) { printf("hex file error\n"); exit(1); } hex[0] = buf[1]; hex[1] = buf[2]; hex[2] = 0; len = Hex2Short(hex); hex[0] = buf[3]; hex[1] = buf[4]; hex[2] = buf[5]; hex[3] = buf[6]; hex[4] = 0; base = Hex2Short(hex); hex[0] = buf[7]; hex[1] = buf[8]; hex[2] = 0; if( (type = Hex2Short(hex)) == 1 ) return 1; if ( (base + len) > (*prgSize) ) { (*prgSize) = base + len + 2; } if( (*prgSize) >= romSize || (base + len) >= romSize ) { printf("program too large\n"); exit(1); } for(i=0; i> i) ? '1' : '0'; } buf[9] = 0; return buf; } /*--------------------------------------------------------------------------*/ void WriteVhdl(unsigned char *rom, unsigned prgSize, const char *fileName) { FILE* fh = fopen("i8051_rom.vhd", "w"); char *binary; unsigned i; assert( fh != 0 ); fprintf(fh, "-- %s \n\n%s", fileName, RomHeader); fprintf(fh, " type ROM_TYPE is array (0 to %i)", prgSize - 1); fprintf(fh, " of UNSIGNED (7 downto 0);\n\n"); fprintf(fh, " constant PROGRAM : ROM_TYPE := (\n\n"); for(i=0; i