// license:BSD-3-Clause // copyright-holders:Sandro Ronco /******************************************************************** Support for PMD 85 cassette images Supported formats: - pmd: raw image - ptp: PMD 85 tape package ********************************************************************/ #include "pmd_cas.h" #define WAVEENTRY_LOW -32768 #define WAVEENTRY_HIGH 32767 #define PMD85_WAV_FREQUENCY 7200 #define PMD85_TIMER_FREQUENCY 1200 #define PMD85_BIT_LENGTH (PMD85_WAV_FREQUENCY/PMD85_TIMER_FREQUENCY) #define PMD85_PILOT_BITS (PMD85_TIMER_FREQUENCY*3) #define PMD85_PAUSE_BITS (PMD85_TIMER_FREQUENCY/2) #define PMD85_HEADER_BYTES 63 #define PMD85_BITS_PER_BYTE 11 // image size static int pmd85_image_size; static int pmd85_emit_level(INT16 *buffer, int sample_pos, int count, int level) { if (buffer) { for (int i=0; i>i) & 0x01); /* stop */ samples += pmd85_output_bit (buffer, sample_pos + samples, 1); samples += pmd85_output_bit (buffer, sample_pos + samples, 1); return samples; } static bool pmd85_is_header_block(const UINT8 *bytes) { for (int i=0; i<0x10; i++) { if (bytes[i] != 0xff || bytes[i + 0x10] != 0x00 || bytes[i + 0x20] != 0x55) return false; } return true; } static void pmd85_printf_image_info(const UINT8 *bytes, int sample_count) { #if 0 char track_name[9]; UINT32 sec = (UINT32)(sample_count/PMD85_WAV_FREQUENCY); UINT16 addr = (bytes[0x33]<<8) | bytes[0x32]; strncpy(track_name, (char*)&bytes[0x36], 8); track_name[8] = '\0'; printf("Block ID: %02d %s 0x%04x Tape pos: %02d:%02d\n", bytes[0x30], track_name, addr, sec/60, sec%60); #endif } static int pmd85_handle_cassette(INT16 *buffer, const UINT8 *bytes) { int sample_count = 0; if (pmd85_is_header_block(bytes)) { // PMD file /* pilot */ for (int i=0; i