diff options
Diffstat (limited to 'src/lib/formats/esq8_dsk.cpp')
-rw-r--r-- | src/lib/formats/esq8_dsk.cpp | 90 |
1 files changed, 57 insertions, 33 deletions
diff --git a/src/lib/formats/esq8_dsk.cpp b/src/lib/formats/esq8_dsk.cpp index c575fe0db2f..b7225d839a9 100644 --- a/src/lib/formats/esq8_dsk.cpp +++ b/src/lib/formats/esq8_dsk.cpp @@ -2,7 +2,7 @@ // copyright-holders:R. Belmont, Olivier Galibert /********************************************************************* - formats/esq8_dsk.c + formats/esq8_dsk.cpp Formats for 8-bit Ensoniq synthesizers and samplers @@ -12,10 +12,12 @@ *********************************************************************/ -#include <assert.h> +#include "esq8_dsk.h" + +#include "ioprocs.h" + +#include "osdcore.h" // osd_printf_* -#include "flopimg.h" -#include "formats/esq8_dsk.h" const floppy_image_format_t::desc_e esq8img_format::esq_6_desc[] = { { MFM, 0x4e, 80 }, @@ -53,60 +55,64 @@ esq8img_format::esq8img_format() { } -const char *esq8img_format::name() const +const char *esq8img_format::name() const noexcept { return "esq8"; } -const char *esq8img_format::description() const +const char *esq8img_format::description() const noexcept { return "Ensoniq Mirage/SQ-80 floppy disk image"; } -const char *esq8img_format::extensions() const +const char *esq8img_format::extensions() const noexcept { return "img"; } -bool esq8img_format::supports_save() const +bool esq8img_format::supports_save() const noexcept { return true; } -void esq8img_format::find_size(io_generic *io, int &track_count, int &head_count, int §or_count) +void esq8img_format::find_size(util::random_read &io, int &track_count, int &head_count, int §or_count) { - uint64_t size = io_generic_size(io); - track_count = 80; - head_count = 1; - sector_count = 6; - - if (size == 5632 * 80) + uint64_t size; + if(!io.length(size)) { - return; - } + track_count = 80; + head_count = 1; + sector_count = 6; + if(size == 5632 * 80) + { + return; + } + } track_count = head_count = sector_count = 0; } -int esq8img_format::identify(io_generic *io, uint32_t form_factor) +int esq8img_format::identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants) const { int track_count, head_count, sector_count; find_size(io, track_count, head_count, sector_count); if(track_count) - return 50; + return FIFID_SIZE; + return 0; } -bool esq8img_format::load(io_generic *io, uint32_t form_factor, floppy_image *image) +bool esq8img_format::load(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image &image) const { int track_count, head_count, sector_count; find_size(io, track_count, head_count, sector_count); uint8_t sectdata[(5*1024) + 512]; desc_s sectors[6]; - for(int i=0; i<sector_count; i++) { - if (i < 5) + for(int i=0; i<sector_count; i++) + { + if(i < 5) { sectors[i].data = sectdata + (1024*i); // 5 1024 byte sectors sectors[i].size = 1024; @@ -126,18 +132,19 @@ bool esq8img_format::load(io_generic *io, uint32_t form_factor, floppy_image *im { for(int head=0; head < head_count; head++) { - io_generic_read(io, sectdata, (track*head_count + head)*track_size, track_size); + /*auto const [err, actual] =*/ read_at(io, (track*head_count + head)*track_size, sectdata, track_size); // FIXME: check for errors and premature EOF generate_track(esq_6_desc, track, head, sectors, sector_count, 109376, image); } } - image->set_variant(floppy_image::DSDD); + image.set_variant(floppy_image::DSDD); return true; } -bool esq8img_format::save(io_generic *io, floppy_image *image) +bool esq8img_format::save(util::random_read_write &io, const std::vector<uint32_t> &variants, const floppy_image &image) const { + uint64_t file_offset = 0; int track_count, head_count, sector_count; get_geometry_mfm_pc(image, 2000, track_count, head_count, sector_count); @@ -151,17 +158,34 @@ bool esq8img_format::save(io_generic *io, floppy_image *image) if(sector_count != 6) sector_count = 6; - uint8_t sectdata[10*512]; - int track_size = (5*1024) + 512; - - for(int track=0; track < track_count; track++) { - for(int head=0; head < head_count; head++) { - get_track_data_mfm_pc(track, head, image, 2000, 512, sector_count, sectdata); - io_generic_write(io, sectdata, (track*head_count + head)*track_size, track_size); + for(int track=0; track < track_count; track++) + { + for(int head=0; head < head_count; head++) + { + auto bitstream = generate_bitstream_from_track(track, head, 2000, image); + auto sectors = extract_sectors_from_bitstream_mfm_pc(bitstream); + int sector_expected_size; + + for(int sector = 0; sector < sector_count; sector++) + { + if(sector < 5) + sector_expected_size = 1024; + else + sector_expected_size = 512; + + if(sectors[sector].size() != sector_expected_size) + { + osd_printf_error("esq8img_format: track %d, sector %d invalid size: %d\n", track, sector, sectors[sector].size()); + return false; + } + + /*auto const [err, actual] =*/ write_at(io, file_offset, sectors[sector].data(), sector_expected_size); // FIXME: check for errors + file_offset += sector_expected_size; + } } } return true; } -const floppy_format_type FLOPPY_ESQ8IMG_FORMAT = &floppy_image_format_creator<esq8img_format>; +const esq8img_format FLOPPY_ESQ8IMG_FORMAT; |