diff options
author | 2021-08-22 09:06:15 +1000 | |
---|---|---|
committer | 2021-08-22 09:06:15 +1000 | |
commit | e8bbea1fc6e94e14768509d322f6c624403ffb36 (patch) | |
tree | 74dd1606a900d83de8aecff17a6737af4113308d /src/lib/formats/oric_dsk.cpp | |
parent | e319bde5fc3696d7f48f62b15b6366c4377fe5d1 (diff) |
formats, osd, util: Started refactoring file I/O stuff. (#8456)
Added more modern generic I/O interfaces with implementation backed by stdio, osd_file and core_file, replacing io_generic. Also replaced core_file's build-in zlib compression with a filter.
unzip.cpp, un7z.cpp: Added option to supply abstract I/O interface rather than filename.
Converted osd_file, core_file, archive_file, chd_file and device_image_interface to use std::error_condition rather than their own error enums.
Allow mounting TI-99 RPK from inside archives.
Diffstat (limited to 'src/lib/formats/oric_dsk.cpp')
-rw-r--r-- | src/lib/formats/oric_dsk.cpp | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/src/lib/formats/oric_dsk.cpp b/src/lib/formats/oric_dsk.cpp index 22d70124572..f5b0783a112 100644 --- a/src/lib/formats/oric_dsk.cpp +++ b/src/lib/formats/oric_dsk.cpp @@ -8,7 +8,9 @@ *********************************************************************/ -#include "formats/oric_dsk.h" +#include "oric_dsk.h" + +#include "ioprocs.h" const char *oric_dsk_format::name() const @@ -31,10 +33,11 @@ bool oric_dsk_format::supports_save() const return true; } -int oric_dsk_format::identify(io_generic *io, uint32_t form_factor, const std::vector<uint32_t> &variants) +int oric_dsk_format::identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants) { uint8_t h[256]; - io_generic_read(io, h, 0, 256); + size_t actual; + io.read_at(0, h, 256, actual); if(memcmp(h, "MFM_DISK", 8)) return 0; @@ -43,27 +46,30 @@ int oric_dsk_format::identify(io_generic *io, uint32_t form_factor, const std::v int tracks = (h[15] << 24) | (h[14] << 16) | (h[13] << 8) | h[12]; int geom = (h[19] << 24) | (h[18] << 16) | (h[17] << 8) | h[16]; - int size = io_generic_size(io); + uint64_t size; + if(io.length(size)) + return 0; if(sides < 0 || sides > 2 || geom != 1 || size != 256+6400*sides*tracks) return 0; return 100; } -bool oric_dsk_format::load(io_generic *io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image) +bool oric_dsk_format::load(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image) { + size_t actual; uint8_t h[256]; uint8_t t[6250+3]; t[6250] = t[6251] = t[6252] = 0; - io_generic_read(io, h, 0, 256); + io.read_at(0, h, 256, actual); int sides = (h[11] << 24) | (h[10] << 16) | (h[ 9] << 8) | h[ 8]; int tracks = (h[15] << 24) | (h[14] << 16) | (h[13] << 8) | h[12]; for(int side=0; side<sides; side++) for(int track=0; track<tracks; track++) { - io_generic_read(io, t, 256+6400*(tracks*side + track), 6250); + io.read_at(256+6400*(tracks*side + track), t, 6250, actual); std::vector<uint32_t> stream; int sector_size = 128; for(int i=0; i<6250; i++) { @@ -99,8 +105,9 @@ bool oric_dsk_format::load(io_generic *io, uint32_t form_factor, const std::vect return true; } -bool oric_dsk_format::save(io_generic *io, const std::vector<uint32_t> &variants, floppy_image *image) +bool oric_dsk_format::save(util::random_read_write &io, const std::vector<uint32_t> &variants, floppy_image *image) { + // FIXME: surely this should return false, since it does't actually save anything? return true; } @@ -127,28 +134,35 @@ bool oric_jasmin_format::supports_save() const return true; } -int oric_jasmin_format::identify(io_generic *io, uint32_t form_factor, const std::vector<uint32_t> &variants) +int oric_jasmin_format::identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants) { - int size = io_generic_size(io); - bool can_ds = variants.empty() || has_variant(variants, floppy_image::DSDD); + uint64_t size; + if(io.length(size)) + return 0; + + bool const can_ds = variants.empty() || has_variant(variants, floppy_image::DSDD); if(size == 41*17*256 || (can_ds && size == 41*17*256*2)) return 50; return 0; } -bool oric_jasmin_format::load(io_generic *io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image) +bool oric_jasmin_format::load(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image) { - int size = io_generic_size(io); - bool can_ds = variants.empty() || has_variant(variants, floppy_image::DSDD); + uint64_t size; + if(io.length(size)) + return false; + + bool const can_ds = variants.empty() || has_variant(variants, floppy_image::DSDD); if(size != 41*17*256 && (!can_ds || size != 41*17*256*2)) return false; - int heads = size == 41*17*256 ? 1 : 2; + int const heads = size == 41*17*256 ? 1 : 2; std::vector<uint8_t> data(size); - io_generic_read(io, data.data(), 0, size); + size_t actual; + io.read_at(0, data.data(), size, actual); for(int head = 0; head != heads; head++) for(int track = 0; track != 41; track++) { @@ -173,7 +187,7 @@ bool oric_jasmin_format::load(io_generic *io, uint32_t form_factor, const std::v return true; } -bool oric_jasmin_format::save(io_generic *io, const std::vector<uint32_t> &variants, floppy_image *image) +bool oric_jasmin_format::save(util::random_read_write &io, const std::vector<uint32_t> &variants, floppy_image *image) { int tracks, heads; image->get_actual_geometry(tracks, heads); @@ -191,8 +205,9 @@ bool oric_jasmin_format::save(io_generic *io, const std::vector<uint32_t> &varia for(int track = 0; track != 41; track++) { auto sectors = extract_sectors_from_bitstream_mfm_pc(generate_bitstream_from_track(track, head, 2000, image)); for(unsigned int sector = 0; sector != 17; sector ++) { - const uint8_t *data = sector+1 < sectors.size() && !sectors[sector+1].empty() ? sectors[sector+1].data() : zero; - io_generic_write(io, data, 256 * (sector + track*17 + head*17*41), 256); + uint8_t const *const data = (sector+1 < sectors.size() && !sectors[sector+1].empty()) ? sectors[sector+1].data() : zero; + size_t actual; + io.write_at(256 * (sector + track*17 + head*17*41), data, 256, actual); } } return true; |