commit 4637394ed6bb6399e2f1c640db14df56752888c3 Author: Matt Jenkins Date: Tue Mar 24 15:21:33 2026 +0000 Initial import diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a70bf21 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +vaxcheck: vaxcheck.o + $(CC) -o $@ $^ diff --git a/README.md b/README.md new file mode 100644 index 0000000..632b665 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +VaxCheck +======== + +Calculate (and optionally write) VAX ROM checksums + +The method used is a simple rotate-left-and-add over the +bytes of a ROM image, excluding the final checksum byte. + +This is done on a per physical ROM basis, not for the +whole ROM memory space as a whole, so there are four +checksum bytes, one per physical ROM. diff --git a/vaxcheck.c b/vaxcheck.c new file mode 100644 index 0000000..12aecf9 --- /dev/null +++ b/vaxcheck.c @@ -0,0 +1,77 @@ +#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); +}