summaryrefslogtreecommitdiff
path: root/source/snap.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/snap.c')
-rw-r--r--source/snap.c45
1 files changed, 29 insertions, 16 deletions
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
{