diff --git a/sim_BuildROMs.c b/sim_BuildROMs.c index cebf2dfb..bb7637b1 100644 --- a/sim_BuildROMs.c +++ b/sim_BuildROMs.c @@ -23,26 +23,30 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. - - +*/ +#include +#include +#include +/* This program builds C include files which can be used to contain the contents of ROM or other boot code needed by simulators. Current Internal ROM files being built: - ROM/Boot File: Include File: - ======================================= - VAX/ka655x.bin VAX/vax_ka655x_bin.h - VAX/vmb.exe VAX/vax780_vmb_exe.h - - + ROM/Boot File: Include File: Size: Checksum: + ======================================================================================= */ +struct ROM_File_Descriptor { + char *BinaryName; char *IncludeFileName; size_t expected_size; unsigned int checksum; char *ArrayName;} ROMs[] = { + {"VAX/ka655x.bin", "VAX/vax_ka655x_bin.h", 131072, 0xFF7673B6, "vax_ka655x_bin"}, + {"VAX/vmb.exe", "VAX/vax780_vmb_exe.h", 44544, 0xFFC014CC, "vax780_vmb_exe"}, + }; -#include -#include -#include -#include + +#include #include +#include #include #if defined(_WIN32) @@ -53,6 +57,114 @@ #include #endif +int sim_read_ROM_include(const char *include_filename, + int *psize, + unsigned char **pROMData, + unsigned int *pchecksum, + char **prom_array_name) +{ +FILE *iFile; +char line[256]; +size_t i; +size_t bytes_written = 0; +size_t allocated_size = 0; + +*psize = 0; +*pchecksum = 0; +*pROMData = NULL; +*prom_array_name = NULL; +if (NULL == (iFile = fopen (include_filename, "r"))) + return -1; + +memset (line, 0, sizeof (line)); + +while (fgets (line, sizeof(line)-1, iFile)) { + unsigned int byte; + char *c; + + switch (line[0]) { + case '#': + case ' ': + case '/': + case '*': + case '\n': + break; + case 'u': /* unsigned char {array_name}[] */ + *prom_array_name = calloc(512, sizeof(char)); + if (1 == sscanf (line, "unsigned char %s[]", *prom_array_name)) { + c = strchr (*prom_array_name, '['); + if (c) + *c = '\0'; + } + break; + case '0': /* line containing byte data */ + c = line; + while (1 == sscanf (c, "0x%2Xd,", &byte)) { + if (bytes_written >= allocated_size) { + allocated_size += 2048; + *pROMData = realloc(*pROMData, allocated_size); + } + *(*pROMData + bytes_written++) = byte; + c += 5; + } + break; + } + if (strchr (line, '}')) + break; + } +fclose (iFile); +for (i=0; i= statb.st_size) - Difference = 1; - else - IncludeData[bytes_written++] = byte; - c += 5; - } - if ((strchr (line,'}')) || Difference) - break; - } - fclose (iFile); - if (!Difference) - Difference = memcmp (IncludeData, ROMData, statb.st_size); - free (IncludeData); - if (!Difference) { +if (0 == sim_read_ROM_include(include_filename, + &include_bytes, + &include_ROMData, + &include_checksum, + &include_array_name)) { + c = ((include_checksum == expected_checksum) && + (include_bytes == expected_size) && + (0 == strcmp (include_array_name, rom_array_name)) && + (0 == memcmp (include_ROMData, ROMData, include_bytes))); + free(include_ROMData); + free(include_array_name); + if (c) { free (ROMData); return 0; } @@ -153,6 +267,7 @@ fprintf (iFile, "/*\n"); fprintf (iFile, " %s produced at %s", include_filename, ctime(&now)); fprintf (iFile, " from %s which was last modified at %s", rom_filename, ctime(&statb.st_mtime)); fprintf (iFile, " file size: %d (0x%X) - checksum: 0x%08X\n", (int)statb.st_size, (int)statb.st_size, checksum); +fprintf (iFile, " This file is a generated file and should NOT be edited or changed by hand.\n"); fprintf (iFile, "*/\n"); fprintf (iFile, "unsigned char %s[] = {", rom_array_name); for (bytes_written=0;bytes_written 2)) + status = sim_make_ROMs_entry (argv[2]); +else { + for (i=0; i