snes: checksum working

Finally got the checksum working.  I had the checksum/complement
fields reversed somehow.
This commit is contained in:
Vince Weaver 2013-01-16 21:49:25 -05:00
parent b25ca3382a
commit 78c0113545
4 changed files with 26 additions and 10 deletions

View File

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

2
tb_snes/checksum.inc Normal file
View File

@ -0,0 +1,2 @@
.word $c807 ; Complement of checksum
.word $37f8 ; Unsigned 16-bit sum of ROM

View File

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

View File

@ -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;
}