mirror of
https://github.com/rdolbeau/VintageBusFPGA_Common.git
synced 2026-04-11 06:47:28 +00:00
add sun3 checksumming helper
This commit is contained in:
@@ -10,7 +10,7 @@ YACC=bison -d #--report-file=bison.log --report=all
|
||||
CC=gcc
|
||||
CFLAGS=-O2
|
||||
|
||||
all: patcher genlink
|
||||
all: patcher genlink sun3_checksum
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $< -c -o $@
|
||||
@@ -21,6 +21,9 @@ patcher: $(PATCHEROBJ) $(OOBJ)
|
||||
genlink: $(GENLINKOBJ) $(OOBJ)
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
sun3_checksum: sun3_checksum.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
parser_par.h: parser_par.o
|
||||
|
||||
parser_par.o: parser_par.y
|
||||
|
||||
49
RomPatcher/patcher/sun3_checksum.c
Normal file
49
RomPatcher/patcher/sun3_checksum.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
int
|
||||
main ( int argc, char **argv )
|
||||
{
|
||||
int fd, r;
|
||||
unsigned char* adr = NULL;
|
||||
struct stat st;
|
||||
size_t size, i;
|
||||
unsigned short int sum;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "One argument needed: path to file to checksum\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_RDONLY );
|
||||
if (fd <= 0) {
|
||||
fprintf(stderr, "Can't open file\n");
|
||||
exit(-2);
|
||||
}
|
||||
r = fstat(fd, &st);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "Can't stat file\n");
|
||||
exit(-3);
|
||||
}
|
||||
size = st.st_size;
|
||||
|
||||
adr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (adr == MAP_FAILED) {
|
||||
fprintf(stderr, "Can't mmap file\n");
|
||||
exit(-3);
|
||||
}
|
||||
|
||||
sum = 0;
|
||||
for (i = 0 ; i < size-2 ; i++) {
|
||||
sum += adr[i];
|
||||
}
|
||||
|
||||
printf("Checksum is 0x%04x\n", sum);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user