summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/poly_dsk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/formats/poly_dsk.cpp')
-rw-r--r--src/lib/formats/poly_dsk.cpp45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/lib/formats/poly_dsk.cpp b/src/lib/formats/poly_dsk.cpp
index cf746b78624..8b8f48780f8 100644
--- a/src/lib/formats/poly_dsk.cpp
+++ b/src/lib/formats/poly_dsk.cpp
@@ -10,54 +10,63 @@
#include "poly_dsk.h"
+#include "ioprocs.h"
+
+#include <cstring>
+
+
poly_cpm_format::poly_cpm_format()
{
}
-const char *poly_cpm_format::name() const
+const char *poly_cpm_format::name() const noexcept
{
return "cpm";
}
-const char *poly_cpm_format::description() const
+const char *poly_cpm_format::description() const noexcept
{
return "Poly CP/M disk image";
}
-const char *poly_cpm_format::extensions() const
+const char *poly_cpm_format::extensions() const noexcept
{
return "cpm";
}
-bool poly_cpm_format::supports_save() const
+bool poly_cpm_format::supports_save() const noexcept
{
return true;
}
-int poly_cpm_format::identify(io_generic *io, uint32_t form_factor)
+int poly_cpm_format::identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants) const
{
- 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);
- if (memcmp(boot, "\x86\xc3\xb7\x00\x00\x8e\x10\xc0\xbf\x00\x01\xbf\xe0\x60\x00\x00", 16) == 0)
+ uint8_t boot[16];
+ auto const [err, actual] = read_at(io, 0, boot, 16);
+ if (!err && (16 == actual) && !memcmp(boot, "\x86\xc3\xb7\x00\x00\x8e\x10\xc0\xbf\x00\x01\xbf\xe0\x60\x00\x00", 16))
{
- return 100;
+ return FIFID_SIZE|FIFID_SIGN;
}
}
+
return 0;
}
-bool poly_cpm_format::load(io_generic *io, uint32_t form_factor, 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) const
{
- 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 +92,7 @@ bool poly_cpm_format::load(io_generic *io, uint32_t form_factor, floppy_image *i
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 +113,7 @@ bool poly_cpm_format::load(io_generic *io, uint32_t form_factor, floppy_image *i
sects[i].deleted = false;
sects[i].bad_crc = false;
sects[i].data = &sect_data[sdatapos];
- io_generic_read(io, sects[i].data, offset, bps);
- offset += bps;
+ /*auto const [err, actual] =*/ read(io, sects[i].data, bps); // FIXME: check for errors and premature EOF
sdatapos += bps;
}
// gap sizes unverified
@@ -115,4 +122,4 @@ bool poly_cpm_format::load(io_generic *io, uint32_t form_factor, floppy_image *i
return true;
}
-const floppy_format_type FLOPPY_POLY_CPM_FORMAT = &floppy_image_format_creator<poly_cpm_format>;
+const poly_cpm_format FLOPPY_POLY_CPM_FORMAT;