src/lib/formats/pmd_pmd.c
| r14812 | r14813 | |
| 1 | | /* .PMD tape images */ |
| 2 | | #include "pmd_pmd.h" |
| 3 | | |
| 4 | | #define WAVEENTRY_LOW -32768 |
| 5 | | #define WAVEENTRY_HIGH 32767 |
| 6 | | |
| 7 | | #define PMD85_WAV_FREQUENCY 7200 |
| 8 | | #define PMD85_TIMER_FREQUENCY 1200 |
| 9 | | #define PMD85_BIT_LENGTH (PMD85_WAV_FREQUENCY/PMD85_TIMER_FREQUENCY) |
| 10 | | #define PMD85_PILOT_BITS (PMD85_TIMER_FREQUENCY*3) |
| 11 | | #define PMD85_PAUSE_BITS (PMD85_TIMER_FREQUENCY/2) |
| 12 | | #define PMD85_HEADER_BYTES 63 |
| 13 | | #define PMD85_BITS_PER_BYTE 11 |
| 14 | | |
| 15 | | static INT16 *pmd85_emit_level(INT16 *p, int count, int level) |
| 16 | | { |
| 17 | | int i; |
| 18 | | |
| 19 | | for (i=0; i<count; i++) *(p++) = level; |
| 20 | | |
| 21 | | return p; |
| 22 | | } |
| 23 | | |
| 24 | | static INT16* pmd85_output_bit(INT16 *p, UINT8 bit) |
| 25 | | { |
| 26 | | if (bit) |
| 27 | | { |
| 28 | | p = pmd85_emit_level (p, PMD85_BIT_LENGTH/2, WAVEENTRY_LOW); |
| 29 | | p = pmd85_emit_level (p, PMD85_BIT_LENGTH/2, WAVEENTRY_HIGH); |
| 30 | | } |
| 31 | | else |
| 32 | | { |
| 33 | | p = pmd85_emit_level (p, PMD85_BIT_LENGTH/2, WAVEENTRY_HIGH); |
| 34 | | p = pmd85_emit_level (p, PMD85_BIT_LENGTH/2, WAVEENTRY_LOW); |
| 35 | | } |
| 36 | | return p; |
| 37 | | } |
| 38 | | |
| 39 | | static INT16* pmd85_output_byte(INT16 *p, UINT8 byte) |
| 40 | | { |
| 41 | | int i; |
| 42 | | |
| 43 | | /* start */ |
| 44 | | p = pmd85_output_bit (p, 0); |
| 45 | | |
| 46 | | /* data */ |
| 47 | | for (i=0; i<8; i++) |
| 48 | | p = pmd85_output_bit(p,(byte>>i) & 0x01); |
| 49 | | |
| 50 | | /* stop */ |
| 51 | | p = pmd85_output_bit (p, 1); |
| 52 | | p = pmd85_output_bit (p, 1); |
| 53 | | |
| 54 | | return p; |
| 55 | | } |
| 56 | | |
| 57 | | static int pmd85_cassette_calculate_size_in_samples(const UINT8 *bytes, int length) |
| 58 | | { |
| 59 | | return PMD85_BIT_LENGTH * (length * PMD85_BITS_PER_BYTE + PMD85_PILOT_BITS + PMD85_PAUSE_BITS); |
| 60 | | } |
| 61 | | |
| 62 | | static int pmd85_cassette_fill_wave(INT16 *buffer, int length, UINT8 *bytes) |
| 63 | | { |
| 64 | | int i; |
| 65 | | INT16 * p = buffer; |
| 66 | | |
| 67 | | int data_size = ((length/PMD85_BIT_LENGTH-PMD85_PILOT_BITS-PMD85_PAUSE_BITS)/PMD85_BITS_PER_BYTE)-PMD85_HEADER_BYTES; |
| 68 | | |
| 69 | | /* pilot */ |
| 70 | | for (i=0; i<PMD85_PILOT_BITS; i++) |
| 71 | | p = pmd85_output_bit(p, 1); |
| 72 | | |
| 73 | | /* header */ |
| 74 | | for (i=0; i<PMD85_HEADER_BYTES; i++) |
| 75 | | p = pmd85_output_byte(p, bytes[i]); |
| 76 | | |
| 77 | | /* pause */ |
| 78 | | for (i=0; i<PMD85_PAUSE_BITS; i++) |
| 79 | | p = pmd85_output_bit(p, 1); |
| 80 | | |
| 81 | | /* data */ |
| 82 | | for (i=0; i<data_size; i++) |
| 83 | | p = pmd85_output_byte(p, bytes[i+PMD85_HEADER_BYTES]); |
| 84 | | |
| 85 | | return p - buffer; |
| 86 | | } |
| 87 | | |
| 88 | | static const struct CassetteLegacyWaveFiller pmd85_legacy_fill_wave = |
| 89 | | { |
| 90 | | pmd85_cassette_fill_wave, /* fill_wave */ |
| 91 | | -1, /* chunk_size */ |
| 92 | | 0, /* chunk_samples */ |
| 93 | | pmd85_cassette_calculate_size_in_samples, /* chunk_sample_calc */ |
| 94 | | PMD85_WAV_FREQUENCY, /* sample_frequency */ |
| 95 | | 0, /* header_samples */ |
| 96 | | 0 /* trailer_samples */ |
| 97 | | }; |
| 98 | | |
| 99 | | static casserr_t pmd85_pmd_identify(cassette_image *cassette, struct CassetteOptions *opts) |
| 100 | | { |
| 101 | | return cassette_legacy_identify(cassette, opts, &pmd85_legacy_fill_wave); |
| 102 | | } |
| 103 | | |
| 104 | | static casserr_t pmd85_pmd_load(cassette_image *cassette) |
| 105 | | { |
| 106 | | return cassette_legacy_construct(cassette, &pmd85_legacy_fill_wave); |
| 107 | | } |
| 108 | | |
| 109 | | static const struct CassetteFormat pmd85_pmd_image_format = |
| 110 | | { |
| 111 | | "pmd", |
| 112 | | pmd85_pmd_identify, |
| 113 | | pmd85_pmd_load, |
| 114 | | NULL |
| 115 | | }; |
| 116 | | |
| 117 | | CASSETTE_FORMATLIST_START(pmd85_pmd_format) |
| 118 | | CASSETTE_FORMAT(pmd85_pmd_image_format) |
| 119 | | CASSETTE_FORMATLIST_END |
src/lib/formats/pmd_cas.c
| r0 | r14813 | |
| 1 | /******************************************************************** |
| 2 | |
| 3 | Support for PMD 85 cassette images |
| 4 | |
| 5 | Supported formats: |
| 6 | - pmd: raw image |
| 7 | - ptp: PMD 85 tape package |
| 8 | |
| 9 | ********************************************************************/ |
| 10 | |
| 11 | #include "pmd_cas.h" |
| 12 | |
| 13 | #define WAVEENTRY_LOW -32768 |
| 14 | #define WAVEENTRY_HIGH 32767 |
| 15 | |
| 16 | #define PMD85_WAV_FREQUENCY 7200 |
| 17 | #define PMD85_TIMER_FREQUENCY 1200 |
| 18 | #define PMD85_BIT_LENGTH (PMD85_WAV_FREQUENCY/PMD85_TIMER_FREQUENCY) |
| 19 | #define PMD85_PILOT_BITS (PMD85_TIMER_FREQUENCY*3) |
| 20 | #define PMD85_PAUSE_BITS (PMD85_TIMER_FREQUENCY/2) |
| 21 | #define PMD85_HEADER_BYTES 63 |
| 22 | #define PMD85_BITS_PER_BYTE 11 |
| 23 | |
| 24 | // image size |
| 25 | static int pmd85_image_size; |
| 26 | |
| 27 | static int pmd85_emit_level(INT16 *buffer, int sample_pos, int count, int level) |
| 28 | { |
| 29 | if (buffer) |
| 30 | { |
| 31 | for (int i=0; i<count; i++) |
| 32 | buffer[sample_pos + i] = level; |
| 33 | } |
| 34 | |
| 35 | return count; |
| 36 | } |
| 37 | |
| 38 | static int pmd85_output_bit(INT16 *buffer, int sample_pos, UINT8 bit) |
| 39 | { |
| 40 | int samples = 0; |
| 41 | |
| 42 | if (bit) |
| 43 | { |
| 44 | samples += pmd85_emit_level (buffer, sample_pos + samples, PMD85_BIT_LENGTH/2, WAVEENTRY_LOW); |
| 45 | samples += pmd85_emit_level (buffer, sample_pos + samples, PMD85_BIT_LENGTH/2, WAVEENTRY_HIGH); |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | samples += pmd85_emit_level (buffer, sample_pos + samples, PMD85_BIT_LENGTH/2, WAVEENTRY_HIGH); |
| 50 | samples += pmd85_emit_level (buffer, sample_pos + samples, PMD85_BIT_LENGTH/2, WAVEENTRY_LOW); |
| 51 | } |
| 52 | |
| 53 | return samples; |
| 54 | } |
| 55 | |
| 56 | static int pmd85_output_byte(INT16 *buffer, int sample_pos, UINT8 byte) |
| 57 | { |
| 58 | int samples = 0; |
| 59 | |
| 60 | /* start */ |
| 61 | samples += pmd85_output_bit (buffer, sample_pos + samples, 0); |
| 62 | |
| 63 | /* data */ |
| 64 | for (int i=0; i<8; i++) |
| 65 | samples += pmd85_output_bit(buffer,sample_pos + samples, (byte>>i) & 0x01); |
| 66 | |
| 67 | /* stop */ |
| 68 | samples += pmd85_output_bit (buffer, sample_pos + samples, 1); |
| 69 | samples += pmd85_output_bit (buffer, sample_pos + samples, 1); |
| 70 | |
| 71 | return samples; |
| 72 | } |
| 73 | |
| 74 | static bool pmd85_is_header_block(const UINT8 *bytes) |
| 75 | { |
| 76 | for (int i=0; i<0x10; i++) |
| 77 | { |
| 78 | if (bytes[i] != 0xff || bytes[i + 0x10] != 0x00 || bytes[i + 0x20] != 0x55) |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | static void pmd85_printf_image_info(const UINT8 *bytes, int sample_count) |
| 86 | { |
| 87 | #if 0 |
| 88 | char track_name[9]; |
| 89 | UINT32 sec = (UINT32)(sample_count/PMD85_WAV_FREQUENCY); |
| 90 | UINT16 addr = (bytes[0x33]<<8) | bytes[0x32]; |
| 91 | strncpy(track_name, (char*)&bytes[0x36], 8); |
| 92 | track_name[8] = '\0'; |
| 93 | |
| 94 | printf("Block ID: %02d %s 0x%04x Tape pos: %02d:%02d\n", bytes[0x30], track_name, addr, sec/60, sec%60); |
| 95 | #endif |
| 96 | } |
| 97 | |
| 98 | static int pmd85_handle_cassette(INT16 *buffer, const UINT8 *bytes) |
| 99 | { |
| 100 | int sample_count = 0; |
| 101 | |
| 102 | if (pmd85_is_header_block(bytes)) |
| 103 | { |
| 104 | // PMD file |
| 105 | |
| 106 | /* pilot */ |
| 107 | for (int i=0; i<PMD85_PILOT_BITS; i++) |
| 108 | sample_count += pmd85_output_bit(buffer, sample_count, 1); |
| 109 | |
| 110 | if (!buffer) |
| 111 | pmd85_printf_image_info(bytes, sample_count); |
| 112 | |
| 113 | /* header */ |
| 114 | for (int i=0; i<PMD85_HEADER_BYTES; i++) |
| 115 | sample_count += pmd85_output_byte(buffer, sample_count, bytes[i]); |
| 116 | |
| 117 | /* pause */ |
| 118 | for (int i=0; i<PMD85_PAUSE_BITS; i++) |
| 119 | sample_count += pmd85_output_bit(buffer, sample_count, 1); |
| 120 | |
| 121 | /* data */ |
| 122 | for (int i=PMD85_HEADER_BYTES; i<pmd85_image_size; i++) |
| 123 | sample_count += pmd85_output_byte(buffer, sample_count, bytes[i]); |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | // PTP file |
| 128 | |
| 129 | /* pilot */ |
| 130 | for (int i=0; i<PMD85_PILOT_BITS; i++) |
| 131 | sample_count += pmd85_output_bit(buffer, sample_count, 1); |
| 132 | |
| 133 | int data_pos = 0; |
| 134 | while (data_pos < pmd85_image_size) |
| 135 | { |
| 136 | UINT16 block_size = (bytes[data_pos + 1]<<8) | bytes[data_pos]; |
| 137 | int pause_len = PMD85_PAUSE_BITS; |
| 138 | |
| 139 | data_pos += 2; |
| 140 | |
| 141 | if (pmd85_is_header_block(bytes + data_pos)) |
| 142 | { |
| 143 | if (!buffer) |
| 144 | pmd85_printf_image_info(bytes + data_pos, sample_count); |
| 145 | |
| 146 | pause_len *= 2; |
| 147 | } |
| 148 | |
| 149 | for (int i=0; i<pause_len; i++) |
| 150 | sample_count += pmd85_output_bit(buffer, sample_count, 1); |
| 151 | |
| 152 | for (int i=0; i<block_size; i++) |
| 153 | sample_count += pmd85_output_byte(buffer, sample_count, bytes[data_pos + i]); |
| 154 | |
| 155 | data_pos += block_size; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return sample_count; |
| 160 | } |
| 161 | |
| 162 | |
| 163 | /******************************************************************* |
| 164 | Generate samples for the tape image |
| 165 | ********************************************************************/ |
| 166 | |
| 167 | static int pmd85_cassette_fill_wave(INT16 *buffer, int length, UINT8 *bytes) |
| 168 | { |
| 169 | return pmd85_handle_cassette(buffer, bytes); |
| 170 | } |
| 171 | |
| 172 | /******************************************************************* |
| 173 | Calculate the number of samples needed for this tape image |
| 174 | ********************************************************************/ |
| 175 | |
| 176 | static int pmd85_cassette_calculate_size_in_samples(const UINT8 *bytes, int length) |
| 177 | { |
| 178 | pmd85_image_size = length; |
| 179 | |
| 180 | return pmd85_handle_cassette(NULL, bytes); |
| 181 | } |
| 182 | |
| 183 | static const struct CassetteLegacyWaveFiller pmd85_legacy_fill_wave = |
| 184 | { |
| 185 | pmd85_cassette_fill_wave, /* fill_wave */ |
| 186 | -1, /* chunk_size */ |
| 187 | 0, /* chunk_samples */ |
| 188 | pmd85_cassette_calculate_size_in_samples, /* chunk_sample_calc */ |
| 189 | PMD85_WAV_FREQUENCY, /* sample_frequency */ |
| 190 | 0, /* header_samples */ |
| 191 | 0 /* trailer_samples */ |
| 192 | }; |
| 193 | |
| 194 | static casserr_t pmd85_cassette_identify(cassette_image *cassette, struct CassetteOptions *opts) |
| 195 | { |
| 196 | return cassette_legacy_identify(cassette, opts, &pmd85_legacy_fill_wave); |
| 197 | } |
| 198 | |
| 199 | static casserr_t pmd85_cassette_load(cassette_image *cassette) |
| 200 | { |
| 201 | return cassette_legacy_construct(cassette, &pmd85_legacy_fill_wave); |
| 202 | } |
| 203 | |
| 204 | static const struct CassetteFormat pmd85_cassette_image_format = |
| 205 | { |
| 206 | "pmd,tap,ptp", |
| 207 | pmd85_cassette_identify, |
| 208 | pmd85_cassette_load, |
| 209 | NULL |
| 210 | }; |
| 211 | |
| 212 | CASSETTE_FORMATLIST_START(pmd85_cassette_formats) |
| 213 | CASSETTE_FORMAT(pmd85_cassette_image_format) |
| 214 | CASSETTE_FORMATLIST_END |
src/mess/tools/castool/main.c
| r14812 | r14813 | |
| 33 | 33 | #include "formats/mz_cas.h" |
| 34 | 34 | #include "formats/orao_cas.h" |
| 35 | 35 | #include "formats/oric_tap.h" |
| 36 | | #include "formats/pmd_pmd.h" |
| 36 | #include "formats/pmd_cas.h" |
| 37 | 37 | #include "formats/primoptp.h" |
| 38 | 38 | #include "formats/rk_cas.h" |
| 39 | 39 | #include "formats/sord_cas.h" |
| r14812 | r14813 | |
| 70 | 70 | {"mz", mz700_cassette_formats ,"Sharp MZ"}, |
| 71 | 71 | {"orao", orao_cassette_formats ,"Orao"}, |
| 72 | 72 | {"oric", oric_cassette_formats ,"Oric"}, |
| 73 | | {"pmd85", pmd85_pmd_format ,"PMD-85"}, |
| 73 | {"pmd85", pmd85_cassette_formats ,"PMD-85"}, |
| 74 | 74 | {"primo", primo_ptp_format ,"Primo"}, |
| 75 | 75 | {"rku", rku_cassette_formats ,"UT-88"}, |
| 76 | 76 | {"rk8", rk8_cassette_formats ,"Mikro-80"}, |