#include #include #include #include #include int main(int argc, char **argv) { if (argc < 2) { printf("Usage: vaxcheck []\n"); return -1; } if (argc > 3) { printf("Usage: vaxcheck []\n"); return -1; } int f = open(argv[1], O_RDONLY); if (!f) { printf("Unable to open %s for reading\n", argv[1]); return -1; } lseek(f, 3, SEEK_SET); uint8_t v[5]; read(f, v, 5); if ((v[1] != 0x55) || (v[2] != 0xAA) || (v[3] != 0x33)) { printf("File is not a VAX ROM image\n"); return -1; } uint32_t romsize = v[4] << 10; printf("ROM is a %d byte VAX ROM image, with rom ID of %d\n", romsize, v[0]); lseek(f, 0, SEEK_SET); int out = -1; if (argc == 3) { out = open(argv[2], O_RDWR | O_TRUNC | O_CREAT, 0644); if (!out) { printf("Unable to open %s for writing\n", argv[2]); } } uint32_t r2 = 0; uint8_t r3 = 0; // Accumulator uint8_t r4 = 0; // Test byte for (r2 = 0; r2 < (romsize-1); r2++) { read(f, &r4, 1); if (out) { write(out, &r4, 1); } uint8_t tmp = r3 >> 7; r3 = (r3 << 1) | tmp; r3 = r3 + r4; } uint8_t cs; read(f, &cs, 1); printf("Current checksum: 0x%02x\n", cs); printf("Calculated checksum: 0x%02x\n", r3); if (out) { write(out, &r3, 1); close(out); } close(f); return !(r3 == cs); }