summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/mdos_dsk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/formats/mdos_dsk.cpp')
-rw-r--r--src/lib/formats/mdos_dsk.cpp68
1 files changed, 42 insertions, 26 deletions
diff --git a/src/lib/formats/mdos_dsk.cpp b/src/lib/formats/mdos_dsk.cpp
index a86558428ad..a14df309db4 100644
--- a/src/lib/formats/mdos_dsk.cpp
+++ b/src/lib/formats/mdos_dsk.cpp
@@ -1,7 +1,7 @@
// license:BSD-3-Clause
// copyright-holders: 68bit
/*
- * mdos_dsk.c - Motorola MDOS compatible disk images
+ * mdos_dsk.cpp - Motorola MDOS compatible disk images
*
* The format is largely IBM 3740 compatible, with 77 tracks, and 26 sectors
* per track, and a sector size of 128 bytes. Single sided disks were initially
@@ -50,38 +50,44 @@
*/
#include "mdos_dsk.h"
-#include "formats/imageutl.h"
+#include "imageutl.h"
+
+#include "ioprocs.h"
+#include "multibyte.h"
+
+#include <tuple>
mdos_format::mdos_format() : wd177x_format(formats)
{
}
-const char *mdos_format::name() const
+const char *mdos_format::name() const noexcept
{
return "mdos";
}
-const char *mdos_format::description() const
+const char *mdos_format::description() const noexcept
{
return "Motorola MDOS compatible disk image";
}
-const char *mdos_format::extensions() const
+const char *mdos_format::extensions() const noexcept
{
return "dsk";
}
-int mdos_format::identify(io_generic *io, uint32_t form_factor)
+int mdos_format::identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants) const
{
- int type = find_size(io, form_factor);
+ int const type = find_size(io, form_factor, variants);
if (type != -1)
- return 75;
+ return FIFID_SIZE | FIFID_STRUCT;
+
return 0;
}
-bool mdos_format::check_ascii(uint8_t *str, size_t len, const char* name)
+bool mdos_format::check_ascii(const uint8_t *str, size_t len, const char* name)
{
LOG_FORMATS(" %s: \"", name);
for (int i = 0; i < len; i++) {
@@ -98,7 +104,7 @@ bool mdos_format::check_ascii(uint8_t *str, size_t len, const char* name)
return 1;
}
-int mdos_format::parse_date_field(uint8_t *str)
+int mdos_format::parse_date_field(const uint8_t *str)
{
uint8_t high = str[0];
uint8_t low = str[1];
@@ -109,16 +115,24 @@ int mdos_format::parse_date_field(uint8_t *str)
return (high - 0x30) * 10 + (low - 0x30);
}
-int mdos_format::find_size(io_generic *io, uint32_t form_factor)
+int mdos_format::find_size(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants) const
{
- uint64_t size = io_generic_size(io);
+ std::error_condition err;
+ size_t actual;
- // Look at the disk id sector.
- io_generic_read(io, &info, 0, sizeof(struct disk_id_sector));
+ uint64_t size;
+ if (io.length(size))
+ return -1;
+
+ // Look at the disk ID sector.
+ disk_id_sector info;
+ std::tie(err, actual) = read_at(io, 0, &info, sizeof(disk_id_sector));
+ if (err || (sizeof(disk_id_sector) != actual))
+ return -1;
LOG_FORMATS("MDOS floppy dsk: size %d bytes, %d total sectors, %d remaining bytes, expected form factor %x\n", (uint32_t)size, (uint32_t)size / 128, (uint32_t)size % 128, form_factor);
- // The 'unused' area is not necessarily zero filled and is ignoded
+ // The 'unused' area is not necessarily zero filled and is ignored
// in the identification of a MDOS format image.
// Expect an ASCII id, version, revision, and 'user name' strings.
@@ -138,9 +152,9 @@ int mdos_format::find_size(io_generic *io, uint32_t form_factor)
return -1;
// The date should be the numeric day, month and year.
- int month = parse_date_field(info.date);
- int day = parse_date_field(info.date + 2);
- int year = parse_date_field(info.date + 4);
+ int const month = parse_date_field(info.date);
+ int const day = parse_date_field(info.date + 2);
+ int const year = parse_date_field(info.date + 4);
LOG_FORMATS(" day %d, month %d, year %d\n", day, month, year);
if (day < 1 || day > 32 || month < 1 || month > 12 || year < 0)
@@ -151,9 +165,7 @@ int mdos_format::find_size(io_generic *io, uint32_t form_factor)
// 10 words. The area beyond the zero word is not always zero filled,
// and is ignored here. Check that it is consistent with this.
for (int i = 0; i < 10; i++) {
- uint8_t high = info.rib_addr[i * 2];
- uint8_t low = info.rib_addr[i * 2 + 1];
- uint16_t cluster = (high << 8) | low;
+ uint16_t cluster = get_u16be(&info.rib_addr[i * 2]);
if (cluster == 0)
break;
@@ -176,8 +188,12 @@ int mdos_format::find_size(io_generic *io, uint32_t form_factor)
// the extent of the disk are free or available.
uint8_t cluster_allocation[128], cluster_available[128];
- io_generic_read(io, &cluster_allocation, 1 * 128, sizeof(cluster_allocation));
- io_generic_read(io, &cluster_available, 2 * 128, sizeof(cluster_available));
+ std::tie(err, actual) = read_at(io, 1 * 128, &cluster_allocation, sizeof(cluster_allocation));
+ if (err || (sizeof(cluster_allocation) != actual))
+ return -1;
+ std::tie(err, actual) = read_at(io, 2 * 128, &cluster_available, sizeof(cluster_available));
+ if (err || (sizeof(cluster_available) != actual))
+ return -1;
for (int cluster = 0; cluster < sizeof(cluster_allocation) * 8; cluster++) {
if (cluster * 4 * 128 + 4 * 128 > size) {
@@ -196,7 +212,7 @@ int mdos_format::find_size(io_generic *io, uint32_t form_factor)
}
}
- for (int i=0; formats[i].form_factor; i++) {
+ for (int i = 0; formats[i].form_factor; i++) {
const format &f = formats[i];
LOG_FORMATS(" checking format %d with form factor %02x, %d sectors, %d heads\n",
i, f.form_factor, f.sector_count, f.head_count);
@@ -221,7 +237,7 @@ int mdos_format::find_size(io_generic *io, uint32_t form_factor)
return -1;
}
-const wd177x_format::format &mdos_format::get_track_format(const format &f, int head, int track)
+const wd177x_format::format &mdos_format::get_track_format(const format &f, int head, int track) const
{
int n = -1;
@@ -281,4 +297,4 @@ const mdos_format::format mdos_format::formats_head1[] = {
{}
};
-const floppy_format_type FLOPPY_MDOS_FORMAT = &floppy_image_format_creator<mdos_format>;
+const mdos_format FLOPPY_MDOS_FORMAT;