Initial import

This commit is contained in:
2026-03-24 15:21:33 +00:00
commit 4637394ed6
3 changed files with 90 additions and 0 deletions

2
Makefile Normal file
View File

@@ -0,0 +1,2 @@
vaxcheck: vaxcheck.o
$(CC) -o $@ $^

11
README.md Normal file
View File

@@ -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.

77
vaxcheck.c Normal file
View File

@@ -0,0 +1,77 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv) {
if (argc < 2) {
printf("Usage: vaxcheck <filename.rom> [<output.rom>]\n");
return -1;
}
if (argc > 3) {
printf("Usage: vaxcheck <filename.rom> [<output.rom>]\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);
}