From f62037ad64341fa37e2bba9a42acac9b09594ada Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 10 Jan 2023 17:34:06 +0000 Subject: Changed ROM patches. Attempts to fix TAP loading. Still balking at bad files. --- source/snap.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'source/snap.c') diff --git a/source/snap.c b/source/snap.c index 3ef3690..789d7d5 100644 --- a/source/snap.c +++ b/source/snap.c @@ -101,16 +101,17 @@ int TAPLoad(Z80Byte id, Z80Word *addr, Z80Word *len, SNAP_Poke poke) Z80Word blen; Z80Byte type,b,csum,tape_csum; - if (!tapfile) - { - return FALSE; - } - b = 0; blen = GetTAPLSBWord(); type = GetTAPByte(); - csum = id; + csum = type; + + if (!tapfile) + { + SPEC_DEBUG("Tape not open, returning FALSE\n"); + return FALSE; + } SPEC_DEBUG("Read block. len=%u type=%u\n", (unsigned)blen, (unsigned)type); SPEC_DEBUG("Requested block len=%u type=%u addr=%u\n", @@ -142,28 +143,40 @@ int TAPLoad(Z80Byte id, Z80Word *addr, Z80Word *len, SNAP_Poke poke) SPEC_DEBUG("Finished block. Remaining blen=%u len=%u\n", (unsigned)blen, (unsigned)*len); - /* Get the checksum + /* Get the checksum. If the length was correct there should be just + byte left in blen, but decrement it in a loop to skip to the end. */ if (blen) { - tape_csum=GetTAPByte(); - blen--; + while(blen--) + { + tape_csum=GetTAPByte(); + + if (blen) + { + csum ^= tape_csum; + } + } } else { tape_csum=b; } - /* In case we've been request less bytes than the block size + /* Check the checksum */ - while(blen--) + if (csum == tape_csum) { - GetTAPByte(); + SPEC_DEBUG("Checksum %u (calc) and %u (tape) match\n", + (unsigned)csum, (unsigned)tape_csum); + return TRUE; + } + else + { + SPEC_DEBUG("Checksum %u (calc) and %u (tape) DON'T match\n", + (unsigned)csum, (unsigned)tape_csum); + return FALSE; } - - /* Check the checksum - */ - return csum == tape_csum; } else { -- cgit v1.2.3