From 6ab094b76b234a6aaae2019096a1691875138536 Mon Sep 17 00:00:00 2001 From: Nigel Barnes Date: Mon, 16 Jul 2018 21:19:55 +0100 Subject: camplynx_cas: Added support for multiple files (concatenated) in TAP file. --- src/lib/formats/camplynx_cas.cpp | 123 ++++++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 42 deletions(-) diff --git a/src/lib/formats/camplynx_cas.cpp b/src/lib/formats/camplynx_cas.cpp index d6181d845ff..bcf6c1caa6b 100644 --- a/src/lib/formats/camplynx_cas.cpp +++ b/src/lib/formats/camplynx_cas.cpp @@ -1,5 +1,5 @@ // license:BSD-3-Clause -// copyright-holders:Robbbert +// copyright-holders:Robbbert,Nigel Barnes /******************************************************************** Support for Camputers Lynx cassette images @@ -82,52 +82,91 @@ static int camplynx_handle_cassette(int16_t *buffer, const uint8_t *bytes) { uint32_t sample_count = 0; uint32_t byte_count = 0; + uint32_t data_size = 0; uint32_t i; + uint8_t file_type; + std::string pgmname = ""; - /* header zeroes */ - for (i=0; i<555; i++) - sample_count += camplynx_output_byte(buffer, sample_count, 0); - - if (bytes[0] == 0x22) + while (byte_count < camplynx_image_size) { - std::string pgmname = " LOAD \""; - byte_count++; + /* initial SYNC + A5 applies to all file types */ + for (i = 0; i < 555; i++) + sample_count += camplynx_output_byte(buffer, sample_count, 0); sample_count += camplynx_output_byte(buffer, sample_count, 0xA5); - sample_count += camplynx_output_byte(buffer, sample_count, 0x22); - /* program name - include protection in case tape is corrupt */ - for (i=1; bytes[i]!=0x22; i++) + /* some TAPs have a spurious A5 at the start, ignore */ + while (bytes[byte_count] == 0xA5) + byte_count++; + + if (bytes[byte_count] == 0x22) { - if (i < camplynx_image_size) + pgmname = " LOAD \""; + byte_count++; + sample_count += camplynx_output_byte(buffer, sample_count, 0x22); + + /* output program name - include protection in case tape is corrupt */ + for (i = byte_count; bytes[i] != 0x22; i++) { - sample_count += camplynx_output_byte(buffer, sample_count, bytes[i]); - pgmname.append(1, (char)bytes[i]); + if (i < camplynx_image_size) + { + sample_count += camplynx_output_byte(buffer, sample_count, bytes[i]); + pgmname.append(1, (char)bytes[i]); + } + else + return sample_count; + byte_count++; } - else - return sample_count; - byte_count++; - } - pgmname.append(1, (char)0x22); - sample_count += camplynx_output_byte(buffer, sample_count, bytes[byte_count++]); // should be 0x22 + pgmname.append(1, (char)0x22); + sample_count += camplynx_output_byte(buffer, sample_count, bytes[byte_count++]); // should be 0x22 - // if a machine-language program, say to use MLOAD - if (bytes[byte_count] == 0x4D) - pgmname[0] = (char)0x4D; + /* read file type letter, should be 'B' or 'M' */ + file_type = bytes[byte_count]; - // Tell user how to load the tape - osd_printf_info("%s",pgmname.c_str()); + /* if a machine-language program, say to use MLOAD */ + if (file_type == 'M') pgmname[0] = 'M'; - /* data zeroes */ - for (i=0; i<555; i++) - sample_count += camplynx_output_byte(buffer, sample_count, 0); + /* tell user how to load the tape */ + if (buffer) + osd_printf_info("%s\n", pgmname.c_str()); - sample_count += camplynx_output_byte(buffer, sample_count, 0xA5); - } + /* second SYNC + A5 */ + for (i = 0; i < 555; i++) + sample_count += camplynx_output_byte(buffer, sample_count, 0); + sample_count += camplynx_output_byte(buffer, sample_count, 0xA5); + } - /* data */ - for (i=byte_count; i