src/mess/formats/x1_tap.c
| r0 | r5700 | |
| 1 | /* |
| 2 | * |
| 3 | * Sharp X1 TAP image format |
| 4 | * |
| 5 | * "New" header format: |
| 6 | * 0x00: Index - must be "TAPE" (4 bytes) |
| 7 | * 0x04: Image title. (null-terminated string, 17 bytes) |
| 8 | * 0x15: Reserved (5 bytes) |
| 9 | * 0x1a: Write protect (bit 4, 1 byte) |
| 10 | * 0x1b: Format (bit 0, 1 byte) |
| 11 | * if bit 0 is high, uses "speed limit sampling method" |
| 12 | * 0x1c: Sample rate, per bit (in Hz, 4 bytes) |
| 13 | * 0x20: Tape data size, in bits (4 bytes) |
| 14 | * 0x24: Tape position (4 bytes, usually 0) |
| 15 | * 0x28: Tape data (data size / 8) |
| 16 | * |
| 17 | * "Old" header format: |
| 18 | * 0x00: Sampling rate (4 bytes) |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "driver.h" |
| 23 | #include "x1_tap.h" |
| 24 | |
| 25 | #define WAVE_HIGH 0x5a9e |
| 26 | #define WAVE_LOW -0x5a9e |
| 27 | |
| 28 | static int cas_size; |
| 29 | static int samplerate; |
| 30 | |
| 31 | static int x1_fill_wave(INT16* buffer, UINT8 data, int sample_pos) |
| 32 | { |
| 33 | int x; |
| 34 | int sample_count = 0; |
| 35 | |
| 36 | // one byte = 8 samples |
| 37 | for(x=0;x<8;x++) |
| 38 | { |
| 39 | if(buffer) |
| 40 | buffer[sample_pos+x] = (data & (1 << (7-x))) ? WAVE_HIGH : WAVE_LOW; |
| 41 | sample_count++; |
| 42 | } |
| 43 | |
| 44 | return sample_count; |
| 45 | } |
| 46 | |
| 47 | static int x1_handle_tap(INT16* buffer, const UINT8* casdata) |
| 48 | { |
| 49 | int sample_count = 0; |
| 50 | int data_pos = 0x28; |
| 51 | |
| 52 | if(memcmp(casdata, "TAPE",4)) // header check |
| 53 | { |
| 54 | logerror("TAP: image is not a 'new' format TAP image\n"); |
| 55 | return -1; |
| 56 | } |
| 57 | if(samplerate != 8000) |
| 58 | { |
| 59 | logerror("TAP: images that are not 8000Hz are not yet supported\n"); |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | while(sample_count < cas_size) |
| 64 | { |
| 65 | sample_count += x1_fill_wave(buffer,casdata[data_pos],sample_count); |
| 66 | data_pos++; |
| 67 | } |
| 68 | |
| 69 | return sample_count; |
| 70 | } |
| 71 | |
| 72 | /******************************************************************* |
| 73 | Calculate the number of samples needed for this tape image |
| 74 | ********************************************************************/ |
| 75 | static int x1_cas_to_wav_size (const UINT8 *casdata, int caslen) |
| 76 | { |
| 77 | UINT32 ret; |
| 78 | |
| 79 | ret = casdata[0x20] | (casdata[0x21] << 8) | (casdata[0x22] << 16) | (casdata[0x23] << 24); |
| 80 | cas_size = ret; |
| 81 | |
| 82 | samplerate = casdata[0x1c] | (casdata[0x1d] << 8) | (casdata[0x1e] << 16) | (casdata[0x1f] << 24); |
| 83 | |
| 84 | return ret; |
| 85 | } |
| 86 | |
| 87 | /******************************************************************* |
| 88 | Generate samples for the tape image |
| 89 | ********************************************************************/ |
| 90 | static int x1_cas_fill_wave(INT16 *buffer, int sample_count, UINT8 *bytes) |
| 91 | { |
| 92 | return x1_handle_tap(buffer,bytes); |
| 93 | } |
| 94 | |
| 95 | static const struct CassetteLegacyWaveFiller x1_legacy_fill_wave = |
| 96 | { |
| 97 | x1_cas_fill_wave, /* fill_wave */ |
| 98 | -1, /* chunk_size */ |
| 99 | 0, /* chunk_samples */ |
| 100 | x1_cas_to_wav_size, /* chunk_sample_calc */ |
| 101 | 8000, /* sample_frequency */ |
| 102 | 0, /* header_samples */ |
| 103 | 0 /* trailer_samples */ |
| 104 | }; |
| 105 | |
| 106 | static casserr_t x1_cas_identify(cassette_image *cassette, struct CassetteOptions *opts) |
| 107 | { |
| 108 | return cassette_legacy_identify(cassette, opts, &x1_legacy_fill_wave); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | |
| 113 | static casserr_t x1_cas_load(cassette_image *cassette) |
| 114 | { |
| 115 | return cassette_legacy_construct(cassette, &x1_legacy_fill_wave); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | static const struct CassetteFormat x1_cassette_format = { |
| 120 | "tap", |
| 121 | x1_cas_identify, |
| 122 | x1_cas_load, |
| 123 | NULL |
| 124 | }; |
| 125 | |
| 126 | CASSETTE_FORMATLIST_START(x1_cassette_formats) |
| 127 | CASSETTE_FORMAT(x1_cassette_format) |
| 128 | CASSETTE_FORMATLIST_END |
src/mess/drivers/x1.c
| r5699 | r5700 | |
| 156 | 156 | #include "devices/mflopimg.h" |
| 157 | 157 | #include "formats/basicdsk.h" |
| 158 | 158 | #include "formats/fm7_dsk.h" |
| 159 | #include "formats/x1_tap.h" |
| 159 | 160 | #include <ctype.h> |
| 160 | 161 | |
| 161 | 162 | static UINT8 hres_320,io_switch,io_sys,vsync,vdisp; |
| r5699 | r5700 | |
| 1785 | 1786 | // (ym-2151 handler here) |
| 1786 | 1787 | |
| 1787 | 1788 | /************************************* |
| 1789 | * |
| 1790 | * Cassette configuration |
| 1791 | * |
| 1792 | *************************************/ |
| 1793 | |
| 1794 | static const cassette_config x1_cassette_config = |
| 1795 | { |
| 1796 | x1_cassette_formats, |
| 1797 | NULL, |
| 1798 | CASSETTE_PLAY | CASSETTE_MOTOR_DISABLED | CASSETTE_SPEAKER_ENABLED |
| 1799 | }; |
| 1800 | |
| 1801 | |
| 1802 | /************************************* |
| 1788 | 1803 | * |
| 1789 | 1804 | * Machine Functions |
| 1790 | 1805 | * |
| r5699 | r5700 | |
| 1938 | 1953 | MDRV_SOUND_WAVE_ADD("wave","cass") |
| 1939 | 1954 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.20) |
| 1940 | 1955 | |
| 1941 | | MDRV_CASSETTE_ADD("cass",default_cassette_config) |
| 1956 | MDRV_CASSETTE_ADD("cass",x1_cassette_config) |
| 1942 | 1957 | MACHINE_DRIVER_END |
| 1943 | 1958 | |
| 1944 | 1959 | static MACHINE_DRIVER_START( x1turbo ) |