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/poly_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/poly_dsk.cpp')
-rw-r--r-- | src/lib/formats/poly_dsk.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/lib/formats/poly_dsk.cpp b/src/lib/formats/poly_dsk.cpp index a865729864e..8845643eb72 100644 --- a/src/lib/formats/poly_dsk.cpp +++ b/src/lib/formats/poly_dsk.cpp @@ -10,6 +10,9 @@ #include "poly_dsk.h" +#include "ioprocs.h" + + poly_cpm_format::poly_cpm_format() { } @@ -34,30 +37,35 @@ bool poly_cpm_format::supports_save() const return true; } -int poly_cpm_format::identify(io_generic *io, uint32_t form_factor, const std::vector<uint32_t> &variants) +int poly_cpm_format::identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants) { - uint8_t boot[16]; - uint64_t size = io_generic_size(io); + uint64_t size; + if (io.length(size)) + return 0; // check for valid sizes if (size == 630784 || size == 622592 || size == 256256) { // check for Poly CP/M boot sector - io_generic_read(io, boot, 0, 16); + uint8_t boot[16]; + size_t actual; + io.read_at(0, boot, 16, actual); if (memcmp(boot, "\x86\xc3\xb7\x00\x00\x8e\x10\xc0\xbf\x00\x01\xbf\xe0\x60\x00\x00", 16) == 0) { return 100; } } + return 0; } -bool poly_cpm_format::load(io_generic *io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image) +bool poly_cpm_format::load(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image) { - int total_tracks, spt, bps, head_num; - - uint64_t size = io_generic_size(io); + uint64_t size; + if (io.length(size) || io.seek(0, SEEK_SET)) + return false; + int total_tracks, spt, bps, head_num; switch (size) { case 622592: @@ -83,8 +91,7 @@ bool poly_cpm_format::load(io_generic *io, uint32_t form_factor, const std::vect break; } - int cell_count = (form_factor == floppy_image::FF_525) ? 50000 : 100000; - int offset = 0; + int const cell_count = (form_factor == floppy_image::FF_525) ? 50000 : 100000; for (int track = 0; track < total_tracks; track++) for (int head = 0; head < head_num; head++) @@ -105,8 +112,8 @@ bool poly_cpm_format::load(io_generic *io, uint32_t form_factor, const std::vect sects[i].deleted = false; sects[i].bad_crc = false; sects[i].data = §_data[sdatapos]; - io_generic_read(io, sects[i].data, offset, bps); - offset += bps; + size_t actual; + io.read(sects[i].data, bps, actual); sdatapos += bps; } // gap sizes unverified |