diff options
-rw-r--r-- | source/snap.c | 45 | ||||
-rw-r--r-- | source/spec.c | 11 |
2 files changed, 37 insertions, 19 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 { diff --git a/source/spec.c b/source/spec.c index 0dc753f..596acd7 100644 --- a/source/spec.c +++ b/source/spec.c @@ -52,8 +52,8 @@ /* ---------------------------------------- STATICS */ #define ROMLEN 0x4000 -#define ROM_SAVE 0x4c6 -#define ROM_LOAD 0x562 +#define ROM_SAVE 0x4c2 +#define ROM_LOAD 0x556 #define ED_SAVE 0xf0 #define ED_LOAD 0xf1 @@ -179,6 +179,9 @@ static void RomPatch(void) { static const Z80Byte save[]= { + 0x21, 0x3f, 0x05, /* LD HL, $053F */ + 0xe5, /* PUSH HL */ + 0xf3, /* DI */ 0xed, ED_SAVE, /* (SAVE) */ 0xc9, /* RET */ 0xff /* End of patch */ @@ -186,7 +189,9 @@ static void RomPatch(void) static const Z80Byte load[]= { - 0x08, /* EX AF,AF' */ + 0x21, 0x3f, 0x05, /* LD HL, $053F */ + 0xe5, /* PUSH HL */ + 0xf3, /* DI */ 0xed, ED_LOAD, /* (LOAD) */ 0xc9, /* RET */ 0xff /* End of patch */ |