diff options
Diffstat (limited to 'src/lib/formats/coco_cas.cpp')
-rw-r--r-- | src/lib/formats/coco_cas.cpp | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/src/lib/formats/coco_cas.cpp b/src/lib/formats/coco_cas.cpp index c0ed5d616ff..a7afc1eeacf 100644 --- a/src/lib/formats/coco_cas.cpp +++ b/src/lib/formats/coco_cas.cpp @@ -35,7 +35,7 @@ #include "coco_cas.h" -#include "emucore.h" // PAIR +#include <cassert> #define COCO_WAVESAMPLES_HEADER (1.0) @@ -45,8 +45,6 @@ //some games load with only 5s, but most games need 15s #define ALICE32_WAVESAMPLES_HEADER (15.0) -static int synccount; - const cassette_image::Modulation coco_cas_modulation = { cassette_image::MODULATION_SINEWAVE, @@ -63,59 +61,56 @@ static cassette_image::error coco_cas_identify(cassette_image *cassette, cassett -static bool get_cas_block(cassette_image *cassette, uint64_t *offset, uint8_t *block, int *block_len) +static bool get_cas_block(cassette_image *cassette, uint64_t &offset, uint8_t *block, int &block_len, int &synccount) { uint8_t block_length = 0; uint8_t block_checksum = 0; - uint64_t current_offset; - uint64_t image_size; - PAIR p; - int i; int state = 0; int phase = 0; synccount = 0; - p.w.l = 0; - image_size = cassette->image_size(); - current_offset = *offset; + uint16_t p = 0; + uint16_t image_size = cassette->image_size(); - while(current_offset < image_size) + for(uint64_t current_offset = offset; current_offset < image_size; ) { - cassette->image_read(&p.b.h, current_offset, 1); + assert((p & 0xFF00) == 0); + p |= cassette->image_read_byte(current_offset) << 8; current_offset++; - for (i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { - p.w.l >>= 1; + p >>= 1; if (state == 0) { /* searching for a block */ - if (p.b.l == 0x3C) + if ((p & 0xFF) == 0x3C) { /* found one! */ phase = i; state++; } - else if (p.b.l == 0x55) + else if ((p & 0xFF) == 0x55) { synccount++; } } else if (i == phase) { - *(block++) = p.b.l; + uint8_t b = p & 0xFF; + *(block++) = b; switch(state) { case 1: /* found file type */ - block_checksum = p.b.l; + block_checksum = b; state++; break; case 2: /* found file size */ - block_length = p.b.l; - *block_len = ((int) block_length) + 3; - block_checksum += p.b.l; + block_length = b; + block_len = ((int) block_length) + 3; + block_checksum += b; state++; break; @@ -124,12 +119,12 @@ static bool get_cas_block(cassette_image *cassette, uint64_t *offset, uint8_t *b if (block_length) { block_length--; - block_checksum += p.b.l; + block_checksum += b; } else { /* end of block */ - if (p.b.l != block_checksum) + if (b != block_checksum) { /* checksum failure */ return false; @@ -137,7 +132,7 @@ static bool get_cas_block(cassette_image *cassette, uint64_t *offset, uint8_t *b else { /* checksum success */ - *offset = current_offset; + offset = current_offset; return true; } } @@ -163,6 +158,7 @@ static cassette_image::error cas_load(cassette_image *cassette, uint8_t silence) double time_index = 0.0; double time_displacement; static const uint8_t magic_bytes[2] = { 0x55, 0x3C }; + int synccount; #if 0 { @@ -206,7 +202,7 @@ static cassette_image::error cas_load(cassette_image *cassette, uint8_t silence) image_size = cassette->image_size(); /* try to find a block that we can untangle */ - while(get_cas_block(cassette, &offset, block, &block_length)) + while(get_cas_block(cassette, offset, block, block_length, synccount)) { /* Forcing a silence before a filename block, improves the ability to load some */ /* copy protected Dragon games, e.g. Rommel's Revenge */ |