Add small rom checksum recalculator.

This commit is contained in:
Jeroen Domburg 2017-03-08 20:29:47 +08:00
parent acf550b667
commit 61f6c8dba4
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,7 @@
OBJS=recalcchs.o
TARGET=recalcchs
$(TARGET): $(OBJS)
$(CC) -o $(TARGET) $(OBJS)

View File

@ -0,0 +1,41 @@
#include "stdio.h"
#include "stdint.h"
#include <stdlib.h>
#define MAXROMSZ 3*1024*1024
int main(int argc, char **argv) {
FILE *f;
int l, x;
unsigned int oldchs, newchs;
unsigned char rom[MAXROMSZ];
if (argc!=2) {
printf("Usage: %s mac-rom-image.bin\nRecalculate checksum on modified rom\n");
exit(0);
}
f=fopen(argv[1], "r+");
if (f<=0) {
perror(argv[1]);
exit(1);
}
l=fread(rom, 1, MAXROMSZ, f);
oldchs=(rom[0]<<24)+(rom[1]<<16)+(rom[2]<<8)+(rom[3]);
newchs=0;
for (x=4; x<l; x+=2) {
newchs+=(rom[x]<<8)+rom[x+1];
}
printf("ROM size: %X\n", l);
printf("Old checksum: %04X\n", oldchs);
printf("New checksum: %04X\n", newchs);
if (oldchs!=newchs) {
rom[0]=newchs>>24;
rom[1]=newchs>>16;
rom[2]=newchs>>8;
rom[3]=newchs>>0;
fseek(f, 0, SEEK_SET);
fwrite(rom, 4, 1, f);
}
fclose(f);
}