From c26b5dadc48ad48d8a8cbbad082cb951dfca08e1 Mon Sep 17 00:00:00 2001 From: Robbbert Date: Sun, 24 May 2015 13:58:21 +1000 Subject: [PATCH] (MESS) camplynx: added TAP cassette format. --- scripts/src/lib.lua | 2 + src/lib/formats/camplynx_cas.c | 205 +++++++++++++++++++++++++++++++++ src/lib/formats/camplynx_cas.h | 15 +++ src/mess/drivers/camplynx.c | 3 + 4 files changed, 225 insertions(+) create mode 100644 src/lib/formats/camplynx_cas.c create mode 100644 src/lib/formats/camplynx_cas.h diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index d4738644375..54540f0f630 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -168,6 +168,8 @@ project "formats" MAME_DIR .. "src/lib/formats/c4040_dsk.h", MAME_DIR .. "src/lib/formats/c8280_dsk.c", MAME_DIR .. "src/lib/formats/c8280_dsk.h", + MAME_DIR .. "src/lib/formats/camplynx_cas.c", + MAME_DIR .. "src/lib/formats/camplynx_cas.h", MAME_DIR .. "src/lib/formats/cbm_crt.c", MAME_DIR .. "src/lib/formats/cbm_crt.h", MAME_DIR .. "src/lib/formats/cbm_tap.c", diff --git a/src/lib/formats/camplynx_cas.c b/src/lib/formats/camplynx_cas.c new file mode 100644 index 00000000000..9da4d856dbf --- /dev/null +++ b/src/lib/formats/camplynx_cas.c @@ -0,0 +1,205 @@ +// license:BSD-3-Clause +// copyright-holders:Robbbert +/******************************************************************** + +Support for Camputers Lynx cassette images + + +We support TAP files used by the Pale and Jynx emulators. + +Tape format: +- about 7 seconds of zeroes +- A5 byte +- 22 byte +- program name +- 22 byte +- about 7 seconds of zeroes +- A5 byte +- header +- main program +- checksum + +Each byte is 8 bits (MSB first) with no start or stop bits. + +********************************************************************/ + +#include + +#include "camplynx_cas.h" + +#define WAVEENTRY_LOW -32768 +#define WAVEENTRY_HIGH 32767 + +#define LYNX48K_WAV_FREQUENCY 4000 +#define LYNX128K_WAV_FREQUENCY 8000 + + +// image size +static int camplynx_image_size; + +static int camplynx_put_samples(INT16 *buffer, int sample_pos, int count, int level) +{ + if (buffer) + { + for (int i=0; i> (7-i)) & 1); + + return samples; +} + +static int camplynx_handle_cassette(INT16 *buffer, const UINT8 *bytes) +{ + UINT32 sample_count = 0; + UINT32 byte_count = 1; + UINT32 i; + + + /* header zeroes */ + 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, bytes[0]); // should be 0x22 + + /* program name - include protection in case tape is corrupt */ + for (int i=1; bytes[i]!=0x22; i++) + { + if (i < camplynx_image_size) + sample_count += camplynx_output_byte(buffer, sample_count, bytes[i]); + else + return sample_count; + byte_count++; + } + + sample_count += camplynx_output_byte(buffer, sample_count, bytes[byte_count++]); // should be 0x22 + + /* data zeroes */ + 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