From 78c011354565692c9b154637f2ab1d841de02764 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 16 Jan 2013 21:49:25 -0500 Subject: [PATCH] snes: checksum working Finally got the checksum working. I had the checksum/complement fields reversed somehow. --- tb_snes/Makefile | 9 ++++++++- tb_snes/checksum.inc | 2 ++ tb_snes/tb1_snes.s | 6 ++---- tb_snes/tools/snes_checksum.c | 19 ++++++++++++++----- 4 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 tb_snes/checksum.inc diff --git a/tb_snes/Makefile b/tb_snes/Makefile index 99224d2..a6e4c8e 100644 --- a/tb_snes/Makefile +++ b/tb_snes/Makefile @@ -2,7 +2,8 @@ AS=cl65 LD=ld65 -all: tb1_snes.sfc +all: checksum.inc + tb1_snes.sfc: tb1_snes.o snes-hirom.cfg $(LD) -o tb1_snes.sfc --config snes-hirom.cfg --obj tb1_snes.o @@ -14,6 +15,12 @@ tb1_snes.o: tb1_snes.s snes_init.s \ tb1_title.tiles: graphics/tb1_title.pcx ./tools/pcx_to_tiles_8bpp ./tools/pcx_to_tiles_8bpp < graphics/tb1_title.pcx > tb1_title.tiles +checksum.inc: ./tools/snes_checksum tb1_snes.sfc + ./tools/snes_checksum < tb1_snes.sfc > checksum.inc + +tools/snes_checksum: + cd tools && make + tools/pcx_to_tiles_8bpp: cd tools && make diff --git a/tb_snes/checksum.inc b/tb_snes/checksum.inc new file mode 100644 index 0000000..7ff8250 --- /dev/null +++ b/tb_snes/checksum.inc @@ -0,0 +1,2 @@ + .word $c807 ; Complement of checksum + .word $37f8 ; Unsigned 16-bit sum of ROM diff --git a/tb_snes/tb1_snes.s b/tb_snes/tb1_snes.s index 6bf9195..3ece6c2 100644 --- a/tb_snes/tb1_snes.s +++ b/tb_snes/tb1_snes.s @@ -293,10 +293,8 @@ output: .byte $01 ; Country Code (1=NTSC,2=PAL) .byte $00 ; License Code (0=unassigned) .byte $00 ; Version - .word $37f8 ; Unsigned 16-bit sum of ROM - .word $c807 ; Complement of checksum - - .word $0,$0 ; unknown? +.include "checksum.inc" + .word $0,$0 ; unknown? ; Interrupt Vectors! diff --git a/tb_snes/tools/snes_checksum.c b/tb_snes/tools/snes_checksum.c index af58b8f..55e2570 100644 --- a/tb_snes/tools/snes_checksum.c +++ b/tb_snes/tools/snes_checksum.c @@ -2,26 +2,35 @@ int main(int argc, char **argv) { - int byte; + int byte,offset=0; unsigned int total=0; unsigned short checksum; + int debug=0; while(1) { byte=fgetc(stdin); if (byte<0) break; + if (debug) { + if (offset==0xffdc) printf("%x\n",byte); + if (offset==0xffdd) printf("%x\n",byte); + if (offset==0xffde) printf("%x\n",byte); + if (offset==0xffdf) printf("%x\n",byte); + } + total+=byte; + offset++; } checksum=total&0xffff; - printf("Checksum: %hx\n",checksum); - printf("Complement: %hx\n",~checksum); - + printf("\t.word\t$%hx\t\t; Complement of checksum\n",~checksum); + printf("\t.word\t$%hx\t\t; Unsigned 16-bit sum of ROM\n",checksum); + return 0; } - \ No newline at end of file +