summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--scripts/src/formats.lua2
-rw-r--r--src/devices/imagedev/diablo.cpp2
-rw-r--r--src/devices/imagedev/flopdrv.h4
-rw-r--r--src/devices/imagedev/harddriv.cpp2
-rw-r--r--src/emu/diimage.cpp1
-rw-r--r--src/emu/diimage.h2
-rw-r--r--src/emu/emu.h1
-rw-r--r--src/lib/formats/a26_cas.cpp2
-rw-r--r--src/lib/formats/a5105_dsk.cpp2
-rw-r--r--src/lib/formats/abc800_dsk.cpp2
-rw-r--r--src/lib/formats/abcfd2_dsk.cpp2
-rw-r--r--src/lib/formats/ace_tap.cpp2
-rw-r--r--src/lib/formats/acorn_dsk.cpp3
-rw-r--r--src/lib/formats/adam_cas.cpp3
-rw-r--r--src/lib/formats/adam_dsk.cpp2
-rw-r--r--src/lib/formats/agat840k_hle_dsk.cpp5
-rw-r--r--src/lib/formats/agat840k_hle_dsk.h2
-rw-r--r--src/lib/formats/ap2_dsk.h1
-rw-r--r--src/lib/formats/ap_dsk35.cpp3
-rw-r--r--src/lib/formats/ap_dsk35.h1
-rw-r--r--src/lib/formats/apd_dsk.cpp4
-rw-r--r--src/lib/formats/apf_apt.cpp2
-rw-r--r--src/lib/formats/applix_dsk.cpp2
-rw-r--r--src/lib/formats/aquarius_caq.cpp2
-rw-r--r--src/lib/formats/asst128_dsk.cpp2
-rw-r--r--src/lib/formats/atari_dsk.cpp2
-rw-r--r--src/lib/formats/atari_dsk.h2
-rw-r--r--src/lib/formats/atom_tap.cpp2
-rw-r--r--src/lib/formats/basicdsk.cpp6
-rw-r--r--src/lib/formats/basicdsk.h2
-rw-r--r--src/lib/formats/bw12_dsk.cpp2
-rw-r--r--src/lib/formats/bw2_dsk.cpp2
-rw-r--r--src/lib/formats/c3040_dsk.cpp2
-rw-r--r--src/lib/formats/c4040_dsk.cpp2
-rw-r--r--src/lib/formats/camplynx_cas.cpp2
-rw-r--r--src/lib/formats/camplynx_dsk.cpp2
-rw-r--r--src/lib/formats/cassimg.h6
-rw-r--r--src/lib/formats/cbm_crt.cpp2
-rw-r--r--src/lib/formats/cbm_tap.cpp3
-rw-r--r--src/lib/formats/cgen_cas.cpp4
-rw-r--r--src/lib/formats/comx35_dsk.cpp2
-rw-r--r--src/lib/formats/cqm_dsk.cpp1
-rw-r--r--src/lib/formats/csw_cas.cpp4
-rw-r--r--src/lib/formats/d64_dsk.cpp4
-rw-r--r--src/lib/formats/d71_dsk.cpp2
-rw-r--r--src/lib/formats/d81_dsk.cpp2
-rw-r--r--src/lib/formats/d82_dsk.cpp2
-rw-r--r--src/lib/formats/d88_dsk.cpp2
-rw-r--r--src/lib/formats/dfi_dsk.cpp2
-rw-r--r--src/lib/formats/dim_dsk.cpp101
-rw-r--r--src/lib/formats/dim_dsk.h4
-rw-r--r--src/lib/formats/dmv_dsk.cpp2
-rw-r--r--src/lib/formats/ds9_dsk.cpp35
-rw-r--r--src/lib/formats/ds9_dsk.h3
-rw-r--r--src/lib/formats/dsk_dsk.cpp1
-rw-r--r--src/lib/formats/ep64_dsk.cpp2
-rw-r--r--src/lib/formats/esq8_dsk.cpp2
-rw-r--r--src/lib/formats/excali64_dsk.cpp2
-rw-r--r--src/lib/formats/fc100_cas.cpp2
-rw-r--r--src/lib/formats/fdd_dsk.cpp4
-rw-r--r--src/lib/formats/fdi_dsk.cpp3
-rw-r--r--src/lib/formats/fl1_dsk.cpp2
-rw-r--r--src/lib/formats/flopimg.cpp883
-rw-r--r--src/lib/formats/flopimg.h201
-rw-r--r--src/lib/formats/flopimg_legacy.cpp880
-rw-r--r--src/lib/formats/flopimg_legacy.h214
-rw-r--r--src/lib/formats/fm7_cas.cpp2
-rw-r--r--src/lib/formats/fmsx_cas.cpp5
-rw-r--r--src/lib/formats/fmtowns_dsk.cpp2
-rw-r--r--src/lib/formats/fsd_dsk.cpp3
-rw-r--r--src/lib/formats/fsd_dsk.h2
-rw-r--r--src/lib/formats/g64_dsk.cpp2
-rw-r--r--src/lib/formats/gtp_cas.cpp3
-rw-r--r--src/lib/formats/h8_cas.cpp2
-rw-r--r--src/lib/formats/hect_dsk.cpp6
-rw-r--r--src/lib/formats/hect_dsk.h2
-rw-r--r--src/lib/formats/hect_tap.cpp1
-rw-r--r--src/lib/formats/hp_ipc_dsk.cpp2
-rw-r--r--src/lib/formats/hpi_dsk.cpp2
-rw-r--r--src/lib/formats/hxchfe_dsk.cpp2
-rw-r--r--src/lib/formats/hxcmfm_dsk.cpp2
-rw-r--r--src/lib/formats/ibmxdf_dsk.cpp1
-rw-r--r--src/lib/formats/imageutl.h4
-rw-r--r--src/lib/formats/imd_dsk.cpp3
-rw-r--r--src/lib/formats/img_dsk.cpp2
-rw-r--r--src/lib/formats/ipf_dsk.cpp2
-rw-r--r--src/lib/formats/iq151_dsk.cpp2
-rw-r--r--src/lib/formats/itt3030_dsk.cpp2
-rw-r--r--src/lib/formats/jfd_dsk.cpp2
-rw-r--r--src/lib/formats/jvc_dsk.cpp2
-rw-r--r--src/lib/formats/kaypro_dsk.cpp2
-rw-r--r--src/lib/formats/kc85_dsk.cpp2
-rw-r--r--src/lib/formats/kc_cas.cpp2
-rw-r--r--src/lib/formats/kim1_cas.cpp2
-rw-r--r--src/lib/formats/lviv_lvt.cpp3
-rw-r--r--src/lib/formats/m5_dsk.cpp2
-rw-r--r--src/lib/formats/mbee_cas.cpp2
-rw-r--r--src/lib/formats/mfi_dsk.cpp2
-rw-r--r--src/lib/formats/mm_dsk.cpp2
-rw-r--r--src/lib/formats/ms0515_dsk.cpp2
-rw-r--r--src/lib/formats/mz_cas.cpp1
-rw-r--r--src/lib/formats/nanos_dsk.cpp2
-rw-r--r--src/lib/formats/naslite_dsk.cpp2
-rw-r--r--src/lib/formats/nes_dsk.cpp6
-rw-r--r--src/lib/formats/nes_dsk.h2
-rw-r--r--src/lib/formats/nfd_dsk.cpp4
-rw-r--r--src/lib/formats/orao_cas.cpp3
-rw-r--r--src/lib/formats/oric_dsk.cpp2
-rw-r--r--src/lib/formats/oric_tap.cpp3
-rw-r--r--src/lib/formats/p2000t_cas.cpp1
-rw-r--r--src/lib/formats/p6001_cas.cpp2
-rw-r--r--src/lib/formats/pasti_dsk.cpp3
-rw-r--r--src/lib/formats/pc98_dsk.cpp5
-rw-r--r--src/lib/formats/pc98fdi_dsk.cpp2
-rw-r--r--src/lib/formats/phc25_cas.cpp2
-rw-r--r--src/lib/formats/pmd_cas.cpp2
-rw-r--r--src/lib/formats/poly_dsk.cpp2
-rw-r--r--src/lib/formats/ppg_dsk.cpp2
-rw-r--r--src/lib/formats/primoptp.cpp3
-rw-r--r--src/lib/formats/pyldin_dsk.cpp1
-rw-r--r--src/lib/formats/ql_dsk.cpp2
-rw-r--r--src/lib/formats/rk_cas.cpp3
-rw-r--r--src/lib/formats/sc3000_bit.cpp3
-rw-r--r--src/lib/formats/sf7000_dsk.cpp2
-rw-r--r--src/lib/formats/smx_dsk.cpp2
-rw-r--r--src/lib/formats/sol_cas.cpp3
-rw-r--r--src/lib/formats/sorc_cas.cpp3
-rw-r--r--src/lib/formats/sorc_dsk.cpp5
-rw-r--r--src/lib/formats/sorc_dsk.h2
-rw-r--r--src/lib/formats/sord_cas.cpp2
-rw-r--r--src/lib/formats/spc1000_cas.cpp3
-rw-r--r--src/lib/formats/st_dsk.cpp2
-rw-r--r--src/lib/formats/svi_cas.cpp2
-rw-r--r--src/lib/formats/swd_dsk.cpp2
-rw-r--r--src/lib/formats/tandy2k_dsk.cpp2
-rw-r--r--src/lib/formats/td0_dsk.cpp2
-rw-r--r--src/lib/formats/thom_cas.cpp3
-rw-r--r--src/lib/formats/ti99_dsk.cpp1
-rw-r--r--src/lib/formats/tiki100_dsk.cpp2
-rw-r--r--src/lib/formats/trs80_dsk.cpp2
-rw-r--r--src/lib/formats/trs_cas.cpp3
-rw-r--r--src/lib/formats/tvc_cas.cpp3
-rw-r--r--src/lib/formats/tvc_dsk.cpp2
-rw-r--r--src/lib/formats/tzx_cas.cpp1
-rw-r--r--src/lib/formats/uef_cas.cpp2
-rw-r--r--src/lib/formats/upd765_dsk.cpp4
-rw-r--r--src/lib/formats/vg5k_cas.cpp3
-rw-r--r--src/lib/formats/victor9k_dsk.cpp5
-rw-r--r--src/lib/formats/victor9k_dsk.h4
-rw-r--r--src/lib/formats/vt_cas.cpp2
-rw-r--r--src/lib/formats/wavfile.cpp5
-rw-r--r--src/lib/formats/wd177x_dsk.cpp4
-rw-r--r--src/lib/formats/x07_cas.cpp2
-rw-r--r--src/lib/formats/x1_tap.cpp3
-rw-r--r--src/lib/formats/xdf_dsk.cpp2
-rw-r--r--src/lib/formats/zx81_p.cpp2
-rw-r--r--src/lib/util/utilfwd.h4
-rw-r--r--src/mame/machine/psion_pack.cpp2
-rw-r--r--src/tools/castool.cpp1
-rw-r--r--src/tools/imgtool/charconv.cpp3
-rw-r--r--src/tools/imgtool/filtbas.cpp2
-rw-r--r--src/tools/imgtool/filteoln.cpp5
-rw-r--r--src/tools/imgtool/filter.cpp4
-rw-r--r--src/tools/imgtool/filter.h3
-rw-r--r--src/tools/imgtool/formats/coco_dsk.cpp2
-rw-r--r--src/tools/imgtool/formats/coco_dsk.h2
-rw-r--r--src/tools/imgtool/formats/pc_dsk_legacy.cpp2
-rw-r--r--src/tools/imgtool/formats/pc_dsk_legacy.h2
-rw-r--r--src/tools/imgtool/formats/vt_dsk_legacy.cpp7
-rw-r--r--src/tools/imgtool/formats/vt_dsk_legacy.h2
-rw-r--r--src/tools/imgtool/iflopimg.cpp6
-rw-r--r--src/tools/imgtool/iflopimg.h2
-rw-r--r--src/tools/imgtool/imghd.cpp5
-rw-r--r--src/tools/imgtool/imghd.h7
-rw-r--r--src/tools/imgtool/imgterrs.cpp3
-rw-r--r--src/tools/imgtool/imgtool.cpp5
-rw-r--r--src/tools/imgtool/imgtool.h15
-rw-r--r--src/tools/imgtool/library.cpp13
-rw-r--r--src/tools/imgtool/library.h18
-rw-r--r--src/tools/imgtool/main.cpp6
-rw-r--r--src/tools/imgtool/modules.cpp1
-rw-r--r--src/tools/imgtool/modules/amiga.cpp13
-rw-r--r--src/tools/imgtool/modules/bml3.cpp11
-rw-r--r--src/tools/imgtool/modules/concept.cpp9
-rw-r--r--src/tools/imgtool/modules/cybiko.cpp2
-rw-r--r--src/tools/imgtool/modules/dgndos.cpp13
-rw-r--r--src/tools/imgtool/modules/fat.cpp12
-rw-r--r--src/tools/imgtool/modules/fat.h3
-rw-r--r--src/tools/imgtool/modules/hp48.cpp2
-rw-r--r--src/tools/imgtool/modules/hp85_tape.cpp2
-rw-r--r--src/tools/imgtool/modules/hp9845_tape.cpp3
-rw-r--r--src/tools/imgtool/modules/mac.cpp20
-rw-r--r--src/tools/imgtool/modules/macbin.cpp9
-rw-r--r--src/tools/imgtool/modules/macutil.cpp2
-rw-r--r--src/tools/imgtool/modules/macutil.h2
-rw-r--r--src/tools/imgtool/modules/os9.cpp9
-rw-r--r--src/tools/imgtool/modules/pc_flop.cpp7
-rw-r--r--src/tools/imgtool/modules/pc_hard.cpp2
-rw-r--r--src/tools/imgtool/modules/prodos.cpp3
-rw-r--r--src/tools/imgtool/modules/psion.cpp4
-rw-r--r--src/tools/imgtool/modules/rsdos.cpp13
-rw-r--r--src/tools/imgtool/modules/thomson.cpp5
-rw-r--r--src/tools/imgtool/modules/ti99.cpp11
-rw-r--r--src/tools/imgtool/modules/ti990hd.cpp9
-rw-r--r--src/tools/imgtool/modules/vzdos.cpp18
-rw-r--r--src/tools/imgtool/stream.h2
206 files changed, 1473 insertions, 1518 deletions
diff --git a/scripts/src/formats.lua b/scripts/src/formats.lua
index 7e80512175b..349324dca58 100644
--- a/scripts/src/formats.lua
+++ b/scripts/src/formats.lua
@@ -43,6 +43,8 @@ project "formats"
MAME_DIR .. "src/lib/formats/flopimg.cpp",
MAME_DIR .. "src/lib/formats/flopimg.h",
+ MAME_DIR .. "src/lib/formats/flopimg_legacy.cpp",
+ MAME_DIR .. "src/lib/formats/flopimg_legacy.h",
MAME_DIR .. "src/lib/formats/cqm_dsk.cpp",
MAME_DIR .. "src/lib/formats/cqm_dsk.h",
diff --git a/src/devices/imagedev/diablo.cpp b/src/devices/imagedev/diablo.cpp
index be09c263719..0a4107ac90a 100644
--- a/src/devices/imagedev/diablo.cpp
+++ b/src/devices/imagedev/diablo.cpp
@@ -11,6 +11,8 @@
#include "harddisk.h"
#include "romload.h"
+#include "opresolv.h"
+
OPTION_GUIDE_START(dsk_option_guide)
OPTION_INT('C', "cylinders", "Cylinders")
diff --git a/src/devices/imagedev/flopdrv.h b/src/devices/imagedev/flopdrv.h
index 4f893bca965..43e3497445e 100644
--- a/src/devices/imagedev/flopdrv.h
+++ b/src/devices/imagedev/flopdrv.h
@@ -7,7 +7,7 @@
#pragma once
-#include "formats/flopimg.h"
+#include "formats/flopimg_legacy.h"
#include "softlist_dev.h"
#define FLOPPY_TYPE_REGULAR 0
@@ -116,7 +116,7 @@ public:
virtual bool is_reset_on_load() const noexcept override { return false; }
virtual const char *image_interface() const noexcept override;
virtual const char *file_extensions() const noexcept override { return m_extension_list; }
- virtual const util::option_guide &create_option_guide() const override { return floppy_option_guide; }
+ virtual const util::option_guide &create_option_guide() const override { return floppy_option_guide(); }
floppy_image_legacy *flopimg_get_image();
void floppy_drive_set_geometry(floppy_type_t type);
diff --git a/src/devices/imagedev/harddriv.cpp b/src/devices/imagedev/harddriv.cpp
index 5a7b9fe8109..384bc8c3e92 100644
--- a/src/devices/imagedev/harddriv.cpp
+++ b/src/devices/imagedev/harddriv.cpp
@@ -20,6 +20,8 @@
#include "harddisk.h"
#include "romload.h"
+#include "opresolv.h"
+
OPTION_GUIDE_START(hd_option_guide)
OPTION_INT('C', "cylinders", "Cylinders")
diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp
index e38b4939a2b..2c8d389c826 100644
--- a/src/emu/diimage.cpp
+++ b/src/emu/diimage.cpp
@@ -18,6 +18,7 @@
#include "ui/uimain.h"
#include "corestr.h"
+#include "opresolv.h"
#include "zippath.h"
#include <algorithm>
diff --git a/src/emu/diimage.h b/src/emu/diimage.h
index 05f714f2647..6e5f74d7484 100644
--- a/src/emu/diimage.h
+++ b/src/emu/diimage.h
@@ -17,6 +17,8 @@
#ifndef MAME_EMU_DIIMAGE_H
#define MAME_EMU_DIIMAGE_H
+#include "utilfwd.h"
+
#include <memory>
#include <string>
#include <system_error>
diff --git a/src/emu/emu.h b/src/emu/emu.h
index 481f414328c..d648ee932de 100644
--- a/src/emu/emu.h
+++ b/src/emu/emu.h
@@ -65,7 +65,6 @@
#include "addrmap.h" // Needs optional_device<> and required_device<>
#include "distate.h"
#include "dimemory.h"
-#include "opresolv.h"
#include "dipalette.h"
#include "digfx.h"
#include "diimage.h"
diff --git a/src/lib/formats/a26_cas.cpp b/src/lib/formats/a26_cas.cpp
index 09d7e2479e5..46522bd50de 100644
--- a/src/lib/formats/a26_cas.cpp
+++ b/src/lib/formats/a26_cas.cpp
@@ -8,8 +8,6 @@ Atari 2600 SuperCharger support
#include "formats/a26_cas.h"
-#include <cassert>
-
#define A26_CAS_SIZE 8448
#define A26_WAV_FREQUENCY 44100
diff --git a/src/lib/formats/a5105_dsk.cpp b/src/lib/formats/a5105_dsk.cpp
index f44c8c5f263..261effea2fc 100644
--- a/src/lib/formats/a5105_dsk.cpp
+++ b/src/lib/formats/a5105_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/a5105_dsk.h"
a5105_format::a5105_format() : upd765_format(formats)
diff --git a/src/lib/formats/abc800_dsk.cpp b/src/lib/formats/abc800_dsk.cpp
index af1f92ec75c..93250b6a388 100644
--- a/src/lib/formats/abc800_dsk.cpp
+++ b/src/lib/formats/abc800_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/abc800_dsk.h"
abc800_format::abc800_format() : wd177x_format(formats)
diff --git a/src/lib/formats/abcfd2_dsk.cpp b/src/lib/formats/abcfd2_dsk.cpp
index 94684f0ef5d..19b1dab50d3 100644
--- a/src/lib/formats/abcfd2_dsk.cpp
+++ b/src/lib/formats/abcfd2_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/abcfd2_dsk.h"
abc_fd2_format::abc_fd2_format() : wd177x_format(formats)
diff --git a/src/lib/formats/ace_tap.cpp b/src/lib/formats/ace_tap.cpp
index 1619280b66b..1d64ca7a027 100644
--- a/src/lib/formats/ace_tap.cpp
+++ b/src/lib/formats/ace_tap.cpp
@@ -12,8 +12,6 @@ For more information see:
#include "ace_tap.h"
-#include <cassert>
-
#define SMPLO -32768
#define SILENCE 0
diff --git a/src/lib/formats/acorn_dsk.cpp b/src/lib/formats/acorn_dsk.cpp
index 40ab6eb1029..d568d3140ab 100644
--- a/src/lib/formats/acorn_dsk.cpp
+++ b/src/lib/formats/acorn_dsk.cpp
@@ -9,9 +9,12 @@
***************************************************************************/
#include "acorn_dsk.h"
+#include "imageutl.h"
#include "ioprocs.h"
+#include <cstring>
+
acorn_ssd_format::acorn_ssd_format() : wd177x_format(formats)
{
diff --git a/src/lib/formats/adam_cas.cpp b/src/lib/formats/adam_cas.cpp
index 4c678bb0796..b0abdb9be2d 100644
--- a/src/lib/formats/adam_cas.cpp
+++ b/src/lib/formats/adam_cas.cpp
@@ -1,8 +1,7 @@
// license:BSD-3-Clause
// copyright-holders:Curt Coder
-#include "adam_cas.h"
-#include <cassert>
+#include "adam_cas.h"
// This code will reproduce the timing of an adam tape played back on a standard tape deck with a 1 7/8ips speed.
diff --git a/src/lib/formats/adam_dsk.cpp b/src/lib/formats/adam_dsk.cpp
index 3010aa309b2..c0e6b8628ee 100644
--- a/src/lib/formats/adam_dsk.cpp
+++ b/src/lib/formats/adam_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/adam_dsk.h"
adam_format::adam_format() : wd177x_format(formats)
diff --git a/src/lib/formats/agat840k_hle_dsk.cpp b/src/lib/formats/agat840k_hle_dsk.cpp
index 682b0edd7ad..e873a8563c8 100644
--- a/src/lib/formats/agat840k_hle_dsk.cpp
+++ b/src/lib/formats/agat840k_hle_dsk.cpp
@@ -12,9 +12,10 @@
************************************************************************/
-#include <cassert>
+#include "agat840k_hle_dsk.h"
+#include "imageutl.h"
-#include "formats/agat840k_hle_dsk.h"
+#include <cstring>
static FLOPPY_IDENTIFY(agat840k_hle_dsk_identify)
diff --git a/src/lib/formats/agat840k_hle_dsk.h b/src/lib/formats/agat840k_hle_dsk.h
index 6e8ad4036ee..32c4bd03808 100644
--- a/src/lib/formats/agat840k_hle_dsk.h
+++ b/src/lib/formats/agat840k_hle_dsk.h
@@ -10,7 +10,7 @@
#pragma once
-#include "flopimg.h"
+#include "flopimg_legacy.h"
#include "formats/basicdsk.h"
LEGACY_FLOPPY_OPTIONS_EXTERN(agat840k_hle);
diff --git a/src/lib/formats/ap2_dsk.h b/src/lib/formats/ap2_dsk.h
index bab61cf96b8..f70483bd072 100644
--- a/src/lib/formats/ap2_dsk.h
+++ b/src/lib/formats/ap2_dsk.h
@@ -13,6 +13,7 @@
#pragma once
#include "flopimg.h"
+#include "flopimg_legacy.h"
/***************************************************************************
diff --git a/src/lib/formats/ap_dsk35.cpp b/src/lib/formats/ap_dsk35.cpp
index 6a3fa5d742b..a39f5a684af 100644
--- a/src/lib/formats/ap_dsk35.cpp
+++ b/src/lib/formats/ap_dsk35.cpp
@@ -99,11 +99,14 @@
*********************************************************************/
#include "ap_dsk35.h"
+#include "imageutl.h"
#include "ioprocs.h"
+#include "opresolv.h"
#include <cassert>
#include <cstdio>
+#include <cstring>
struct apple35_tag
diff --git a/src/lib/formats/ap_dsk35.h b/src/lib/formats/ap_dsk35.h
index f4a8ec7bff8..2af46e15f5b 100644
--- a/src/lib/formats/ap_dsk35.h
+++ b/src/lib/formats/ap_dsk35.h
@@ -13,6 +13,7 @@
#pragma once
#include "flopimg.h"
+#include "flopimg_legacy.h"
void sony_filltrack(uint8_t *buffer, size_t buffer_len, size_t *pos, uint8_t data);
uint8_t sony_fetchtrack(const uint8_t *buffer, size_t buffer_len, size_t *pos);
diff --git a/src/lib/formats/apd_dsk.cpp b/src/lib/formats/apd_dsk.cpp
index f882d90fe23..312de073304 100644
--- a/src/lib/formats/apd_dsk.cpp
+++ b/src/lib/formats/apd_dsk.cpp
@@ -64,8 +64,12 @@
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*, little_endianize_int32
+
#include <zlib.h>
+#include <cstring>
+
static const uint8_t APD_HEADER[8] = { 'A', 'P', 'D', 'X', '0', '0', '0', '1' };
static const uint8_t GZ_HEADER[2] = { 0x1f, 0x8b };
diff --git a/src/lib/formats/apf_apt.cpp b/src/lib/formats/apf_apt.cpp
index e820090ef04..dd1d119b010 100644
--- a/src/lib/formats/apf_apt.cpp
+++ b/src/lib/formats/apf_apt.cpp
@@ -36,8 +36,6 @@ e. A checksum byte (8-bit addition)
#include "formats/apf_apt.h"
-#include <cassert>
-
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
diff --git a/src/lib/formats/applix_dsk.cpp b/src/lib/formats/applix_dsk.cpp
index 70a52c42ccb..41a303c73a6 100644
--- a/src/lib/formats/applix_dsk.cpp
+++ b/src/lib/formats/applix_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/applix_dsk.h"
applix_format::applix_format() : wd177x_format(formats)
diff --git a/src/lib/formats/aquarius_caq.cpp b/src/lib/formats/aquarius_caq.cpp
index 16460d2eac8..b7b6cfec4f9 100644
--- a/src/lib/formats/aquarius_caq.cpp
+++ b/src/lib/formats/aquarius_caq.cpp
@@ -12,8 +12,6 @@
#include "coretmpl.h" // BIT
-#include <cassert>
-
/*-------------------------------------------------
CassetteModulation aquarius_caq_modulation
diff --git a/src/lib/formats/asst128_dsk.cpp b/src/lib/formats/asst128_dsk.cpp
index e0c90636484..0509cf7e7e4 100644
--- a/src/lib/formats/asst128_dsk.cpp
+++ b/src/lib/formats/asst128_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/asst128_dsk.h"
asst128_format::asst128_format() : upd765_format(formats)
diff --git a/src/lib/formats/atari_dsk.cpp b/src/lib/formats/atari_dsk.cpp
index 4008ec32fe3..317447986cb 100644
--- a/src/lib/formats/atari_dsk.cpp
+++ b/src/lib/formats/atari_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/atari_dsk.h"
static FLOPPY_IDENTIFY( atari_dsk_identify )
diff --git a/src/lib/formats/atari_dsk.h b/src/lib/formats/atari_dsk.h
index 7f9a5bd194e..816ef6ffa75 100644
--- a/src/lib/formats/atari_dsk.h
+++ b/src/lib/formats/atari_dsk.h
@@ -12,7 +12,7 @@
#pragma once
-#include "flopimg.h"
+#include "flopimg_legacy.h"
LEGACY_FLOPPY_OPTIONS_EXTERN(atari_only);
diff --git a/src/lib/formats/atom_tap.cpp b/src/lib/formats/atom_tap.cpp
index 02a2416f856..db29798d51d 100644
--- a/src/lib/formats/atom_tap.cpp
+++ b/src/lib/formats/atom_tap.cpp
@@ -44,8 +44,6 @@
#include "csw_cas.h"
#include "uef_cas.h"
-#include <cassert>
-
/***************************************************************************
PARAMETERS
***************************************************************************/
diff --git a/src/lib/formats/basicdsk.cpp b/src/lib/formats/basicdsk.cpp
index c654362309e..2eea96f6e00 100644
--- a/src/lib/formats/basicdsk.cpp
+++ b/src/lib/formats/basicdsk.cpp
@@ -8,12 +8,14 @@
*********************************************************************/
+#include "basicdsk.h"
+
+#include "opresolv.h"
+
#include <cstdlib>
#include <cstring>
#include <cassert>
-#include "basicdsk.h"
-
static floperr_t basicdsk_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen);
static floperr_t basicdsk_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam);
static floperr_t basicdsk_read_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen);
diff --git a/src/lib/formats/basicdsk.h b/src/lib/formats/basicdsk.h
index dabe9afc278..8adfd9ed985 100644
--- a/src/lib/formats/basicdsk.h
+++ b/src/lib/formats/basicdsk.h
@@ -12,7 +12,7 @@
#pragma once
-#include "flopimg.h"
+#include "flopimg_legacy.h"
struct basicdsk_geometry
{
diff --git a/src/lib/formats/bw12_dsk.cpp b/src/lib/formats/bw12_dsk.cpp
index 407db641d9c..56baeecd8a8 100644
--- a/src/lib/formats/bw12_dsk.cpp
+++ b/src/lib/formats/bw12_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/bw12_dsk.h"
bw12_format::bw12_format() : upd765_format(formats)
diff --git a/src/lib/formats/bw2_dsk.cpp b/src/lib/formats/bw2_dsk.cpp
index 297f78f863f..5e359d365a1 100644
--- a/src/lib/formats/bw2_dsk.cpp
+++ b/src/lib/formats/bw2_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/bw2_dsk.h"
bw2_format::bw2_format() : upd765_format(formats)
diff --git a/src/lib/formats/c3040_dsk.cpp b/src/lib/formats/c3040_dsk.cpp
index b5c35f9d2e5..3400aef4342 100644
--- a/src/lib/formats/c3040_dsk.cpp
+++ b/src/lib/formats/c3040_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/c3040_dsk.h"
c3040_format::c3040_format() : d64_format(file_formats)
diff --git a/src/lib/formats/c4040_dsk.cpp b/src/lib/formats/c4040_dsk.cpp
index 69d371525c1..8851f4db478 100644
--- a/src/lib/formats/c4040_dsk.cpp
+++ b/src/lib/formats/c4040_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/c4040_dsk.h"
c4040_format::c4040_format() : d64_format(file_formats)
diff --git a/src/lib/formats/camplynx_cas.cpp b/src/lib/formats/camplynx_cas.cpp
index 5945650ca0a..7ffad54707e 100644
--- a/src/lib/formats/camplynx_cas.cpp
+++ b/src/lib/formats/camplynx_cas.cpp
@@ -25,6 +25,8 @@ Each byte is 8 bits (MSB first) with no start or stop bits.
#include "camplynx_cas.h"
+#include "osdcore.h" // osd_printf_*
+
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
diff --git a/src/lib/formats/camplynx_dsk.cpp b/src/lib/formats/camplynx_dsk.cpp
index 46cd4f2a55d..ea508aa9e3e 100644
--- a/src/lib/formats/camplynx_dsk.cpp
+++ b/src/lib/formats/camplynx_dsk.cpp
@@ -19,8 +19,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/camplynx_dsk.h"
camplynx_format::camplynx_format() : wd177x_format(formats)
diff --git a/src/lib/formats/cassimg.h b/src/lib/formats/cassimg.h
index 765b860b659..d96139cfa19 100644
--- a/src/lib/formats/cassimg.h
+++ b/src/lib/formats/cassimg.h
@@ -14,16 +14,10 @@
#include "ioprocs.h"
-#include "osdcore.h"
-
#include <memory>
#include <string>
#include <vector>
-#ifndef LOG_FORMATS
-#define LOG_FORMATS(...) do { if (0) osd_printf_info(__VA_ARGS__); } while (false)
-#endif
-
// hack to get around rogues that define this
#ifdef UNSUPPORTED
#undef UNSUPPORTED
diff --git a/src/lib/formats/cbm_crt.cpp b/src/lib/formats/cbm_crt.cpp
index 9ca4312e43e..a61c3247844 100644
--- a/src/lib/formats/cbm_crt.cpp
+++ b/src/lib/formats/cbm_crt.cpp
@@ -41,6 +41,8 @@
#include "cbm_crt.h"
+#include "osdcore.h" // osd_printf_*
+
//**************************************************************************
// MACROS/CONSTANTS
diff --git a/src/lib/formats/cbm_tap.cpp b/src/lib/formats/cbm_tap.cpp
index 542c0c3ea87..9ae77bffb7d 100644
--- a/src/lib/formats/cbm_tap.cpp
+++ b/src/lib/formats/cbm_tap.cpp
@@ -94,9 +94,8 @@ Unfortunately, I have no such a .tap file to test, so my implementation
below could be not working. FP ]
*/
-#include <cassert>
-
#include "cbm_tap.h"
+#include "imageutl.h"
#define CBM_WAV_FREQUENCY 44100
diff --git a/src/lib/formats/cgen_cas.cpp b/src/lib/formats/cgen_cas.cpp
index 8a208044960..c0737db635b 100644
--- a/src/lib/formats/cgen_cas.cpp
+++ b/src/lib/formats/cgen_cas.cpp
@@ -18,9 +18,9 @@ NOTE: There exist multiples type of .cas files for Colour Genie
We now support these three types below...
********************************************************************/
-#include "formats/cgen_cas.h"
+#include "cgen_cas.h"
-#include <cassert>
+#include <cstring>
#define TAPE_HEADER "Colour Genie - Virtual Tape File"
diff --git a/src/lib/formats/comx35_dsk.cpp b/src/lib/formats/comx35_dsk.cpp
index a06f1a2dd6c..e0c5734f3e6 100644
--- a/src/lib/formats/comx35_dsk.cpp
+++ b/src/lib/formats/comx35_dsk.cpp
@@ -36,8 +36,6 @@
*/
-#include <cassert>
-
#include "formats/comx35_dsk.h"
comx35_format::comx35_format() : wd177x_format(formats)
diff --git a/src/lib/formats/cqm_dsk.cpp b/src/lib/formats/cqm_dsk.cpp
index 6639e50f801..f2eacc1d6fc 100644
--- a/src/lib/formats/cqm_dsk.cpp
+++ b/src/lib/formats/cqm_dsk.cpp
@@ -9,6 +9,7 @@
*********************************************************************/
#include "cqm_dsk.h"
+#include "flopimg_legacy.h"
#include "ioprocs.h"
diff --git a/src/lib/formats/csw_cas.cpp b/src/lib/formats/csw_cas.cpp
index e55346cef4e..4fa4050c0e3 100644
--- a/src/lib/formats/csw_cas.cpp
+++ b/src/lib/formats/csw_cas.cpp
@@ -21,11 +21,13 @@
*/
#include "csw_cas.h"
+#include "imageutl.h"
#include "uef_cas.h"
+#include "osdcomm.h" // little_endianize_int*
+
#include <zlib.h>
-#include <cassert>
#include <cstring>
diff --git a/src/lib/formats/d64_dsk.cpp b/src/lib/formats/d64_dsk.cpp
index 149130f0b3c..6099413e680 100644
--- a/src/lib/formats/d64_dsk.cpp
+++ b/src/lib/formats/d64_dsk.cpp
@@ -14,6 +14,10 @@
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
+#include <cstring>
+
d64_format::d64_format()
{
diff --git a/src/lib/formats/d71_dsk.cpp b/src/lib/formats/d71_dsk.cpp
index 16c8efea2e9..4150638568b 100644
--- a/src/lib/formats/d71_dsk.cpp
+++ b/src/lib/formats/d71_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/d71_dsk.h"
d71_format::d71_format() : d64_format(formats)
diff --git a/src/lib/formats/d81_dsk.cpp b/src/lib/formats/d81_dsk.cpp
index a7f01c9c92e..e7e3ac29299 100644
--- a/src/lib/formats/d81_dsk.cpp
+++ b/src/lib/formats/d81_dsk.cpp
@@ -73,8 +73,6 @@ PER SECTOR ORGANIZATION:
*/
-#include <cassert>
-
#include "formats/d81_dsk.h"
d81_format::d81_format() : wd177x_format(formats)
diff --git a/src/lib/formats/d82_dsk.cpp b/src/lib/formats/d82_dsk.cpp
index 0d79ad891ae..b4b7d5790f3 100644
--- a/src/lib/formats/d82_dsk.cpp
+++ b/src/lib/formats/d82_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/d82_dsk.h"
d82_format::d82_format() : d80_format(file_formats)
diff --git a/src/lib/formats/d88_dsk.cpp b/src/lib/formats/d88_dsk.cpp
index 6e29f10df6a..918f0ed9ebd 100644
--- a/src/lib/formats/d88_dsk.cpp
+++ b/src/lib/formats/d88_dsk.cpp
@@ -29,7 +29,7 @@
*
*/
-#include "flopimg.h"
+#include "flopimg_legacy.h"
#include "imageutl.h"
#include "ioprocs.h"
diff --git a/src/lib/formats/dfi_dsk.cpp b/src/lib/formats/dfi_dsk.cpp
index 607be56f741..d78db94d772 100644
--- a/src/lib/formats/dfi_dsk.cpp
+++ b/src/lib/formats/dfi_dsk.cpp
@@ -15,6 +15,8 @@
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
#define NUMBER_OF_MULTIREADS 3
// thresholds for brickwall windowing
diff --git a/src/lib/formats/dim_dsk.cpp b/src/lib/formats/dim_dsk.cpp
index 04f6e3b8995..53359b2fd1c 100644
--- a/src/lib/formats/dim_dsk.cpp
+++ b/src/lib/formats/dim_dsk.cpp
@@ -9,112 +9,11 @@
*********************************************************************/
#include "dim_dsk.h"
-#include "basicdsk.h"
#include "ioprocs.h"
#include <cstring>
-
-FLOPPY_IDENTIFY(dim_dsk_identify)
-{
- uint8_t dim_header[16];
-
- floppy_image_read(floppy, (uint8_t*)dim_header,0xab,16);
-
- if(strncmp((const char*)dim_header,"DIFC HEADER",11) == 0)
- *vote = 100;
- else
- *vote = 0;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-FLOPPY_CONSTRUCT(dim_dsk_construct)
-{
- struct basicdsk_geometry geometry;
- // DIM disk image header, most of this is guesswork
- int tracks = 77;
- int heads = 2;
- int sectors = 8; // per track
- int sectorlen = 1024;
- int firstsector = 0x01;
- uint8_t format_tmp;
- int x;
- uint16_t temp;
-
- if(params)
- {
- // create
- return FLOPPY_ERROR_UNSUPPORTED;
- }
-
- // Offset + 0 : disk format type (1 byte):
- // 0 = 2HD / 2HDA (8 sector/track, 1024 bytes/sector, GAP#3 = 0x74)
- // 1 = 2HS (9 sector/track, 1024 bytes/sector, GAP#3 = 0x39)
- // 2 = 2HC (15 sector/track, 512 bytes/sector, GAP#3 = 0x54)
- // 3 = 2HDE(68) (9 sector/track, 1024 bytes/sector, GAP#3 = 0x39)
- // 9 = 2HQ (18 sector/track, 512 bytes/sector, GAP#3 = 0x54)
- // 17 = N88-BASIC (26 sector/track, 256 bytes/sector, GAP#3 = 0x33)
- // or (26 sector/track, 128 bytes/sector, GAP#3 = 0x1a)
- //
- floppy_image_read(floppy, &format_tmp,0,1);
-
- switch(format_tmp)
- {
- case 0x00:
- sectors = 8;
- sectorlen = 1024;
- break;
- case 0x01:
- case 0x03:
- sectors = 9;
- sectorlen = 1024;
- break;
- case 0x02:
- sectors = 15;
- sectorlen = 512;
- break;
- case 0x09:
- sectors = 18;
- sectorlen = 512;
- break;
- case 0x11:
- sectors = 26;
- sectorlen = 256;
- break;
- }
- tracks = 0;
- for (x=0;x<86;x++)
- {
- floppy_image_read(floppy,&temp,(x*2)+1,2);
- if(temp == 0x0101)
- tracks++;
- }
- // TODO: expand on this basic implementation
-
- LOG_FORMATS("FDD: DIM image loaded - type %i, %i tracks, %i sectors per track, %i bytes per sector\n", format_tmp,tracks, sectors,sectorlen);
-
- memset(&geometry, 0, sizeof(geometry));
- geometry.heads = heads;
- geometry.first_sector_id = firstsector;
- geometry.sector_length = sectorlen;
- geometry.tracks = tracks+1;
- geometry.sectors = sectors;
- geometry.offset = 0x100;
- return basicdsk_construct(floppy, &geometry);
-}
-
-
-/*********************************************************************
-
- formats/dim_dsk.c
-
- DIM disk images
-
-*********************************************************************/
-
-#include "dim_dsk.h"
-
dim_format::dim_format()
{
}
diff --git a/src/lib/formats/dim_dsk.h b/src/lib/formats/dim_dsk.h
index 5c84f329cb6..1eb27e46e66 100644
--- a/src/lib/formats/dim_dsk.h
+++ b/src/lib/formats/dim_dsk.h
@@ -16,10 +16,6 @@
/**************************************************************************/
-FLOPPY_IDENTIFY(dim_dsk_identify);
-FLOPPY_CONSTRUCT(dim_dsk_construct);
-
-
class dim_format : public floppy_image_format_t
{
public:
diff --git a/src/lib/formats/dmv_dsk.cpp b/src/lib/formats/dmv_dsk.cpp
index b64fea5b318..de7075e13f2 100644
--- a/src/lib/formats/dmv_dsk.cpp
+++ b/src/lib/formats/dmv_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/dmv_dsk.h"
dmv_format::dmv_format() : upd765_format(formats)
diff --git a/src/lib/formats/ds9_dsk.cpp b/src/lib/formats/ds9_dsk.cpp
index c97a2cced51..deab3d2539b 100644
--- a/src/lib/formats/ds9_dsk.cpp
+++ b/src/lib/formats/ds9_dsk.cpp
@@ -18,41 +18,8 @@
#include "ioprocs.h"
+#include <cstring>
-static FLOPPY_IDENTIFY(ds9_dsk_identify)
-{
- switch (floppy_image_size(floppy))
- {
- case (80 * 2 * 21 * 256):
- case 860164:
- case 860288:
- *vote = 100;
- break;
-
- default:
- *vote = 0;
- break;
- }
-
- return FLOPPY_ERROR_SUCCESS;
-}
-
-static FLOPPY_CONSTRUCT(ds9_dsk_construct)
-{
- struct basicdsk_geometry geometry;
- memset(&geometry, 0, sizeof(geometry));
- geometry.heads = 2;
- geometry.first_sector_id = 0;
- geometry.sector_length = 256;
- geometry.tracks = 80;
- geometry.sectors = 21;
- return basicdsk_construct(floppy, &geometry);
-}
-
-LEGACY_FLOPPY_OPTIONS_START( ds9 )
- LEGACY_FLOPPY_OPTION( ds9_dsk, "ds9,dsk,raw", "Agat 840K DSK image",
- ds9_dsk_identify, ds9_dsk_construct, nullptr, nullptr)
-LEGACY_FLOPPY_OPTIONS_END
// exactly 6500 bytes
const floppy_image_format_t::desc_e ds9_format::ds9_desc[] = {
diff --git a/src/lib/formats/ds9_dsk.h b/src/lib/formats/ds9_dsk.h
index abdf152b2b3..519d425561d 100644
--- a/src/lib/formats/ds9_dsk.h
+++ b/src/lib/formats/ds9_dsk.h
@@ -11,9 +11,6 @@
#pragma once
#include "flopimg.h"
-#include "formats/basicdsk.h"
-
-LEGACY_FLOPPY_OPTIONS_EXTERN(ds9);
class ds9_format : public floppy_image_format_t
{
diff --git a/src/lib/formats/dsk_dsk.cpp b/src/lib/formats/dsk_dsk.cpp
index fcf967edcb1..3d5ca544c33 100644
--- a/src/lib/formats/dsk_dsk.cpp
+++ b/src/lib/formats/dsk_dsk.cpp
@@ -9,6 +9,7 @@
*********************************************************************/
#include "dsk_dsk.h"
+#include "flopimg_legacy.h"
#include "imageutl.h"
#include "ioprocs.h"
diff --git a/src/lib/formats/ep64_dsk.cpp b/src/lib/formats/ep64_dsk.cpp
index f47615c76d9..6e1e864e3e3 100644
--- a/src/lib/formats/ep64_dsk.cpp
+++ b/src/lib/formats/ep64_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/ep64_dsk.h"
ep64_format::ep64_format() : wd177x_format(formats)
diff --git a/src/lib/formats/esq8_dsk.cpp b/src/lib/formats/esq8_dsk.cpp
index 952dd16edbd..493d2f5f1f5 100644
--- a/src/lib/formats/esq8_dsk.cpp
+++ b/src/lib/formats/esq8_dsk.cpp
@@ -16,6 +16,8 @@
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
const floppy_image_format_t::desc_e esq8img_format::esq_6_desc[] = {
{ MFM, 0x4e, 80 },
diff --git a/src/lib/formats/excali64_dsk.cpp b/src/lib/formats/excali64_dsk.cpp
index cc255052800..cb5febfc0d3 100644
--- a/src/lib/formats/excali64_dsk.cpp
+++ b/src/lib/formats/excali64_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/excali64_dsk.h"
excali64_format::excali64_format() : wd177x_format(formats)
diff --git a/src/lib/formats/fc100_cas.cpp b/src/lib/formats/fc100_cas.cpp
index 56c7b8294db..da2247d49b5 100644
--- a/src/lib/formats/fc100_cas.cpp
+++ b/src/lib/formats/fc100_cas.cpp
@@ -12,8 +12,6 @@ it's all a guess.
#include "fc100_cas.h"
-#include <cassert>
-
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
diff --git a/src/lib/formats/fdd_dsk.cpp b/src/lib/formats/fdd_dsk.cpp
index 8c8249c9452..1a5a1d54c1b 100644
--- a/src/lib/formats/fdd_dsk.cpp
+++ b/src/lib/formats/fdd_dsk.cpp
@@ -35,6 +35,10 @@
#include "ioprocs.h"
+#include "osdcomm.h" // little_endianize_int32
+
+#include <cstring>
+
fdd_format::fdd_format()
{
diff --git a/src/lib/formats/fdi_dsk.cpp b/src/lib/formats/fdi_dsk.cpp
index 57083f1230e..71805508ab2 100644
--- a/src/lib/formats/fdi_dsk.cpp
+++ b/src/lib/formats/fdi_dsk.cpp
@@ -16,9 +16,8 @@
*/
-#include <cassert>
#include "imageutl.h"
-#include "flopimg.h"
+#include "flopimg_legacy.h"
/***************************************************************************
PARAMETERS
diff --git a/src/lib/formats/fl1_dsk.cpp b/src/lib/formats/fl1_dsk.cpp
index 89419233056..b37e356e436 100644
--- a/src/lib/formats/fl1_dsk.cpp
+++ b/src/lib/formats/fl1_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/fl1_dsk.h"
fl1_format::fl1_format() : wd177x_format(formats)
diff --git a/src/lib/formats/flopimg.cpp b/src/lib/formats/flopimg.cpp
index 55d00d1bb83..8e9dbaf47a2 100644
--- a/src/lib/formats/flopimg.cpp
+++ b/src/lib/formats/flopimg.cpp
@@ -1,893 +1,22 @@
// license:BSD-3-Clause
-// copyright-holders:Nathan Woods
-/*********************************************************************
+// copyright-holders:Olivier Galibert
+/***************************************************************************
- flopimg.c
+ flopimg.cpp
- Floppy disk image abstraction code
+ Floppy disk image abstraction code (new implementation)
-*********************************************************************/
+****************************************************************************/
#include "flopimg.h"
-#include "imageutl.h"
#include "ioprocs.h"
+#include "strformat.h"
-#include "osdcore.h"
-
-#include <cassert>
-#include <cctype>
-#include <climits>
#include <cstdio>
-#include <cstdlib>
#include <cstring>
#include <stdexcept>
-#define TRACK_LOADED 0x01
-#define TRACK_DIRTY 0x02
-
-using util::BIT;
-
-
-struct floppy_image_legacy
-{
- util::random_read_write::ptr io = nullptr;
-
- const struct FloppyFormat *floppy_option = nullptr;
- struct FloppyCallbacks format = { 0 };
-
- /* loaded track stuff */
- int loaded_track_head = 0;
- int loaded_track_index = 0;
- uint32_t loaded_track_size = 0;
- std::unique_ptr<uint8_t[]> loaded_track_data;
- uint8_t loaded_track_status = 0;
- uint8_t flags = 0;
-
- /* tagging system */
- std::unique_ptr<uint8_t[]> tag_data;
-};
-
-
-
-struct floppy_params
-{
- int param;
- int value;
-};
-
-
-
-static floperr_t floppy_track_unload(floppy_image_legacy *floppy);
-
-OPTION_GUIDE_START(floppy_option_guide)
- OPTION_INT('H', "heads", "Heads")
- OPTION_INT('T', "tracks", "Tracks")
- OPTION_INT('S', "sectors", "Sectors")
- OPTION_INT('L', "sectorlength", "Sector Bytes")
- OPTION_INT('I', "interleave", "Interleave")
- OPTION_INT('F', "firstsectorid", "First Sector")
-OPTION_GUIDE_END
-
-
-static void floppy_close_internal(floppy_image_legacy *floppy);
-
-/*********************************************************************
- opening, closing and creating of floppy images
-*********************************************************************/
-
-/* basic floppy_image_legacy initialization common to floppy_open() and floppy_create() */
-static floppy_image_legacy *floppy_init(util::random_read_write::ptr &&io, int flags)
-{
- floppy_image_legacy *floppy;
-
- floppy = new floppy_image_legacy;
-
- floppy->io = std::move(io);
- floppy->flags = (uint8_t) flags;
- return floppy;
-}
-
-
-
-/* main code for identifying and maybe opening a disk image; not exposed
- * directly because this function is big and hideous */
-static floperr_t floppy_open_internal(util::random_read_write::ptr &&io, const std::string &extension,
- const struct FloppyFormat *floppy_options, int max_options, int flags, floppy_image_legacy **outfloppy,
- int *outoption)
-{
- floperr_t err;
- floppy_image_legacy *floppy;
- int best_option = -1;
- int best_vote = 0;
- int vote;
- size_t i;
-
- floppy = floppy_init(std::move(io), flags);
- if (!floppy)
- {
- err = FLOPPY_ERROR_OUTOFMEMORY;
- goto done;
- }
-
- /* vote on the best format */
- for (i = 0; (i < max_options) && floppy_options[i].construct; i++)
- {
- if (extension.empty() || !floppy_options[i].extensions || image_find_extension(floppy_options[i].extensions, extension.c_str()))
- {
- if (floppy_options[i].identify)
- {
- vote = 0;
- err = floppy_options[i].identify(floppy, &floppy_options[i], &vote);
- if (err)
- goto done;
- }
- else
- {
- vote = 1;
- }
-
- /* is this option a better one? */
- if (vote > best_vote)
- {
- best_vote = vote;
- best_option = i;
- }
- }
- }
-
- /* did we find a format? */
- if (best_option == -1)
- {
- err = FLOPPY_ERROR_INVALIDIMAGE;
- goto done;
- }
-
- if (outfloppy)
- {
- /* call the format constructor */
- err = floppy_options[best_option].construct(floppy, &floppy_options[best_option], nullptr);
- if (err)
- goto done;
-
- floppy->floppy_option = &floppy_options[best_option];
- }
- if (best_vote != 100)
- {
- printf("Loading image that is not 100%% recognized\n");
- }
- err = FLOPPY_ERROR_SUCCESS;
-
-done:
- /* if we have a floppy disk and we either errored or are not keeping it, close it */
- if (floppy && (!outfloppy || err))
- {
- floppy_close_internal(floppy);
- floppy = nullptr;
- }
-
- if (outoption)
- *outoption = err ? -1 : best_option;
- if (outfloppy)
- *outfloppy = floppy;
- return err;
-}
-
-
-
-floperr_t floppy_identify(util::random_read_write::ptr &&io, const char *extension,
- const struct FloppyFormat *formats, int *identified_format)
-{
- return floppy_open_internal(std::move(io), extension, formats, INT_MAX, FLOPPY_FLAGS_READONLY, nullptr, identified_format);
-}
-
-
-
-floperr_t floppy_open(util::random_read_write::ptr &&io, const std::string &extension,
- const struct FloppyFormat *format, int flags, floppy_image_legacy **outfloppy)
-{
- return floppy_open_internal(std::move(io), extension, format, 1, flags, outfloppy, nullptr);
-}
-
-
-
-floperr_t floppy_open_choices(util::random_read_write::ptr &&io, const std::string &extension,
- const struct FloppyFormat *formats, int flags, floppy_image_legacy **outfloppy)
-{
- return floppy_open_internal(std::move(io), extension, formats, INT_MAX, flags, outfloppy, nullptr);
-}
-
-
-
-floperr_t floppy_create(util::random_read_write::ptr &&io, const struct FloppyFormat *format, util::option_resolution *parameters, floppy_image_legacy **outfloppy)
-{
- floppy_image_legacy *floppy = nullptr;
- floperr_t err;
- int heads, tracks, h, t;
- std::unique_ptr<util::option_resolution> alloc_resolution;
-
- assert(format);
-
- /* create the new image */
- floppy = floppy_init(std::move(io), 0);
- if (!floppy)
- {
- err = FLOPPY_ERROR_OUTOFMEMORY;
- goto done;
- }
-
- /* if this format expects creation parameters and none were specified, create some */
- if (!parameters && format->param_guidelines)
- {
- try { alloc_resolution = std::make_unique<util::option_resolution>(floppy_option_guide); }
- catch (...)
- {
- err = FLOPPY_ERROR_OUTOFMEMORY;
- goto done;
- }
- alloc_resolution->set_specification(format->param_guidelines);
- parameters = alloc_resolution.get();
- }
-
- /* call the format constructor */
- err = format->construct(floppy, format, parameters);
- if (err)
- goto done;
-
- /* format the disk, ignoring if formatting not implemented */
- if (floppy->format.format_track)
- {
- heads = floppy_get_heads_per_disk(floppy);
- tracks = floppy_get_tracks_per_disk(floppy);
-
- for (h = 0; h < heads; h++)
- {
- for (t = 0; t < tracks; t++)
- {
- err = floppy->format.format_track(floppy, h, t, parameters);
- if (err)
- goto done;
- }
- }
- }
-
- /* call the post_format function, if present */
- if (floppy->format.post_format)
- {
- err = floppy->format.post_format(floppy, parameters);
- if (err)
- goto done;
- }
-
- floppy->floppy_option = format;
- err = FLOPPY_ERROR_SUCCESS;
-
-done:
- if (err && floppy)
- {
- floppy_close_internal(floppy);
- floppy = nullptr;
- }
-
- if (outfloppy)
- *outfloppy = floppy;
- else if (floppy)
- floppy_close_internal(floppy);
- return err;
-}
-
-
-
-static void floppy_close_internal(floppy_image_legacy *floppy)
-{
- if (floppy) {
- floppy_track_unload(floppy);
-
- if(floppy->floppy_option && floppy->floppy_option->destruct)
- floppy->floppy_option->destruct(floppy, floppy->floppy_option);
-
- delete floppy;
- }
-}
-
-
-
-void floppy_close(floppy_image_legacy *floppy)
-{
- floppy_close_internal(floppy);
-}
-
-
-
-/*********************************************************************
- functions useful in format constructors
-*********************************************************************/
-
-struct FloppyCallbacks *floppy_callbacks(floppy_image_legacy *floppy)
-{
- assert(floppy);
- return &floppy->format;
-}
-
-
-
-void *floppy_tag(floppy_image_legacy *floppy)
-{
- assert(floppy);
- return floppy->tag_data.get();
-}
-
-
-
-void *floppy_create_tag(floppy_image_legacy *floppy, size_t tagsize)
-{
- floppy->tag_data = std::make_unique<uint8_t[]>(tagsize);
- return floppy->tag_data.get();
-}
-
-
-
-uint8_t floppy_get_filler(floppy_image_legacy *floppy)
-{
- // FIXME: remove this function, it's here for legacy reasons
- // the caller actually sets the filler byte - in practice it's always 0xff but there's no actual guarantee
- return 0xff;
-}
-
-
-
-util::random_read_write &floppy_get_io(floppy_image_legacy *floppy)
-{
- return *floppy->io;
-}
-
-
-
-/*********************************************************************
- calls for accessing the raw disk image
-*********************************************************************/
-
-void floppy_image_read(floppy_image_legacy *floppy, void *buffer, uint64_t offset, size_t length)
-{
- size_t actual;
- floppy->io->read_at(offset, buffer, length, actual);
-}
-
-
-
-void floppy_image_write(floppy_image_legacy *floppy, const void *buffer, uint64_t offset, size_t length)
-{
- size_t actual;
- floppy->io->write_at(offset, buffer, length, actual);
-}
-
-
-
-void floppy_image_write_filler(floppy_image_legacy *floppy, uint8_t filler, uint64_t offset, size_t length)
-{
- uint8_t buffer[512];
- memset(buffer, filler, std::min(sizeof(buffer), length));
-
- while (length)
- {
- size_t const block = std::min(sizeof(buffer), length);
- size_t actual;
- floppy->io->write_at(offset, buffer, block, actual);
- offset += block;
- length -= block;
- }
-}
-
-
-
-uint64_t floppy_image_size(floppy_image_legacy *floppy)
-{
- uint64_t result;
- floppy->io->length(result);
- return result;
-}
-
-
-
-/*********************************************************************
- calls for accessing disk image data
-*********************************************************************/
-
-static floperr_t floppy_readwrite_sector(floppy_image_legacy *floppy, int head, int track, int sector, int offset,
- void *buffer, size_t buffer_len, bool writing, bool indexed, int ddam)
-{
- floperr_t err;
- const struct FloppyCallbacks *fmt;
- size_t this_buffer_len;
- std::vector<uint8_t> alloc_buf;
- uint32_t sector_length;
- uint8_t *buffer_ptr = (uint8_t *)buffer;
- floperr_t (*read_sector)(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen);
- floperr_t (*write_sector)(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam);
-
- fmt = floppy_callbacks(floppy);
-
- /* choose proper calls for indexed vs non-indexed */
- if (indexed)
- {
- read_sector = fmt->read_indexed_sector;
- write_sector = fmt->write_indexed_sector;
- if (!fmt->get_indexed_sector_info)
- {
- err = FLOPPY_ERROR_UNSUPPORTED;
- goto done;
- }
- }
- else
- {
- read_sector = fmt->read_sector;
- write_sector = fmt->write_sector;
- if (!fmt->get_sector_length)
- {
- err = FLOPPY_ERROR_UNSUPPORTED;
- goto done;
- }
- }
-
- /* check to make sure that the operation is supported */
- if (!read_sector || (writing && !write_sector))
- {
- err = FLOPPY_ERROR_UNSUPPORTED;
- goto done;
- }
-
- /* main loop */
- while(buffer_len > 0)
- {
- /* find out the size of this sector */
- if (indexed)
- err = fmt->get_indexed_sector_info(floppy, head, track, sector, nullptr, nullptr, nullptr, &sector_length, nullptr);
- else
- err = fmt->get_sector_length(floppy, head, track, sector, &sector_length);
- if (err)
- goto done;
-
- /* do we even do anything with this sector? */
- if (offset < sector_length)
- {
- /* ok we will be doing something */
- if ((offset > 0) || (buffer_len < sector_length))
- {
- /* we will be doing an partial read/write; in other words we
- * will not be reading/writing a full sector */
- alloc_buf.resize(sector_length);
-
- /* read the sector (we need to do this even when writing */
- err = read_sector(floppy, head, track, sector, &alloc_buf[0], sector_length);
- if (err)
- goto done;
-
- this_buffer_len = std::min(buffer_len, size_t(sector_length - offset));
-
- if (writing)
- {
- memcpy(&alloc_buf[offset], buffer_ptr, this_buffer_len);
-
- err = write_sector(floppy, head, track, sector, &alloc_buf[0], sector_length, ddam);
- if (err)
- goto done;
- }
- else
- {
- memcpy(buffer_ptr, &alloc_buf[offset], this_buffer_len);
- }
- offset += this_buffer_len;
- offset %= sector_length;
- }
- else
- {
- this_buffer_len = sector_length;
-
- if (writing)
- err = write_sector(floppy, head, track, sector, buffer_ptr, sector_length, ddam);
- else
- err = read_sector(floppy, head, track, sector, buffer_ptr, sector_length);
- if (err)
- goto done;
- }
- }
- else
- {
- /* skip this sector */
- offset -= sector_length;
- this_buffer_len = 0;
- }
-
- buffer_ptr += this_buffer_len;
- buffer_len -= this_buffer_len;
- sector++;
- }
-
- err = FLOPPY_ERROR_SUCCESS;
-
-done:
- return err;
-}
-
-
-
-floperr_t floppy_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, int offset, void *buffer, size_t buffer_len)
-{
- return floppy_readwrite_sector(floppy, head, track, sector, offset, buffer, buffer_len, false, false, 0);
-}
-
-
-
-floperr_t floppy_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, int offset, const void *buffer, size_t buffer_len, int ddam)
-{
- return floppy_readwrite_sector(floppy, head, track, sector, offset, (void *) buffer, buffer_len, true, false, ddam);
-}
-
-
-
-floperr_t floppy_read_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector_index, int offset, void *buffer, size_t buffer_len)
-{
- return floppy_readwrite_sector(floppy, head, track, sector_index, offset, buffer, buffer_len, false, true, 0);
-}
-
-
-
-floperr_t floppy_write_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector_index, int offset, const void *buffer, size_t buffer_len, int ddam)
-{
- return floppy_readwrite_sector(floppy, head, track, sector_index, offset, (void *) buffer, buffer_len, true, true, ddam);
-}
-
-
-static floperr_t floppy_get_track_data_offset(floppy_image_legacy *floppy, int head, int track, uint64_t *offset)
-{
- floperr_t err;
- const struct FloppyCallbacks *callbacks;
-
- *offset = 0;
- callbacks = floppy_callbacks(floppy);
- if (callbacks->get_track_data_offset)
- {
- err = callbacks->get_track_data_offset(floppy, head, track, offset);
- if (err)
- return err;
- }
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static floperr_t floppy_read_track_offset(floppy_image_legacy *floppy, int head, int track, uint64_t offset, void *buffer, size_t buffer_len)
-{
- floperr_t err;
- const struct FloppyCallbacks *format;
-
- format = floppy_callbacks(floppy);
-
- if (!format->read_track)
- return FLOPPY_ERROR_UNSUPPORTED;
-
- err = floppy_track_unload(floppy);
- if (err)
- return err;
-
- err = format->read_track(floppy, head, track, offset, buffer, buffer_len);
- if (err)
- return err;
-
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-floperr_t floppy_read_track(floppy_image_legacy *floppy, int head, int track, void *buffer, size_t buffer_len)
-{
- return floppy_read_track_offset(floppy, head, track, 0, buffer, buffer_len);
-}
-
-
-
-floperr_t floppy_read_track_data(floppy_image_legacy *floppy, int head, int track, void *buffer, size_t buffer_len)
-{
- floperr_t err;
- uint64_t offset;
-
- err = floppy_get_track_data_offset(floppy, head, track, &offset);
- if (err)
- return err;
-
- return floppy_read_track_offset(floppy, head, track, offset, buffer, buffer_len);
-}
-
-
-
-static floperr_t floppy_write_track_offset(floppy_image_legacy *floppy, int head, int track, uint64_t offset, const void *buffer, size_t buffer_len)
-{
- floperr_t err;
-
- /* track writing supported? */
- if (!floppy_callbacks(floppy)->write_track)
- return FLOPPY_ERROR_UNSUPPORTED;
-
- /* read only? */
- if (floppy->flags & FLOPPY_FLAGS_READONLY)
- return FLOPPY_ERROR_READONLY;
-
- err = floppy_track_unload(floppy);
- if (err)
- return err;
-
- err = floppy_callbacks(floppy)->write_track(floppy, head, track, offset, buffer, buffer_len);
- if (err)
- return err;
-
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-floperr_t floppy_write_track(floppy_image_legacy *floppy, int head, int track, const void *buffer, size_t buffer_len)
-{
- return floppy_write_track_offset(floppy, head, track, 0, buffer, buffer_len);
-}
-
-
-
-floperr_t floppy_write_track_data(floppy_image_legacy *floppy, int head, int track, const void *buffer, size_t buffer_len)
-{
- floperr_t err;
- uint64_t offset;
-
- err = floppy_get_track_data_offset(floppy, head, track, &offset);
- if (err)
- return err;
-
- return floppy_write_track_offset(floppy, head, track, offset, buffer, buffer_len);
-}
-
-
-
-floperr_t floppy_format_track(floppy_image_legacy *floppy, int head, int track, util::option_resolution *parameters)
-{
- floperr_t err;
- struct FloppyCallbacks *format;
- std::unique_ptr<util::option_resolution> alloc_resolution;
-
- /* supported? */
- format = floppy_callbacks(floppy);
- if (!format->format_track)
- return FLOPPY_ERROR_UNSUPPORTED;
-
- /* create a dummy resolution; if no parameters were specified */
- if (!parameters)
- {
- try
- {
- alloc_resolution = std::make_unique<util::option_resolution>(floppy_option_guide);
- }
- catch (...)
- {
- return FLOPPY_ERROR_OUTOFMEMORY;
- }
- alloc_resolution->set_specification(floppy->floppy_option->param_guidelines);
-
- parameters = alloc_resolution.get();
- }
-
- err = format->format_track(floppy, head, track, parameters);
- if (err)
- return err;
-
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-int floppy_get_tracks_per_disk(floppy_image_legacy *floppy)
-{
- return floppy_callbacks(floppy)->get_tracks_per_disk(floppy);
-}
-
-
-
-int floppy_get_heads_per_disk(floppy_image_legacy *floppy)
-{
- return floppy_callbacks(floppy)->get_heads_per_disk(floppy);
-}
-
-
-
-uint32_t floppy_get_track_size(floppy_image_legacy *floppy, int head, int track)
-{
- const struct FloppyCallbacks *fmt;
-
- fmt = floppy_callbacks(floppy);
- if (!fmt->get_track_size)
- return 0;
-
- return fmt->get_track_size(floppy, head, track);
-}
-
-
-
-floperr_t floppy_get_sector_length(floppy_image_legacy *floppy, int head, int track, int sector, uint32_t *sector_length)
-{
- const struct FloppyCallbacks *fmt;
-
- fmt = floppy_callbacks(floppy);
- if (!fmt->get_sector_length)
- return FLOPPY_ERROR_UNSUPPORTED;
-
- return fmt->get_sector_length(floppy, head, track, sector, sector_length);
-}
-
-
-
-floperr_t floppy_get_indexed_sector_info(floppy_image_legacy *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, uint32_t *sector_length, unsigned long *flags)
-{
- const struct FloppyCallbacks *fmt;
-
- fmt = floppy_callbacks(floppy);
- if (!fmt->get_indexed_sector_info)
- return FLOPPY_ERROR_UNSUPPORTED;
-
- return fmt->get_indexed_sector_info(floppy, head, track, sector_index, cylinder, side, sector, sector_length, flags);
-}
-
-
-
-floperr_t floppy_get_sector_count(floppy_image_legacy *floppy, int head, int track, int *sector_count)
-{
- floperr_t err;
- int sector_index = 0;
-
- do
- {
- err = floppy_get_indexed_sector_info(floppy, head, track, sector_index, nullptr, nullptr, nullptr, nullptr, nullptr);
- if (!err)
- sector_index++;
- }
- while(!err);
-
- if (sector_index && (err == FLOPPY_ERROR_SEEKERROR))
- err = FLOPPY_ERROR_SUCCESS;
- if (sector_count)
- *sector_count = err ? 0 : sector_index;
- return err;
-}
-
-
-
-int floppy_is_read_only(floppy_image_legacy *floppy)
-{
- return floppy->flags & FLOPPY_FLAGS_READONLY;
-}
-
-
-
-uint8_t floppy_random_byte(floppy_image_legacy *floppy)
-{
- /* can't use mame_rand(); this might not be in the core */
-#ifdef rand
-#undef rand
-#endif
- return rand();
-}
-
-
-
-/*********************************************************************
- calls for track based IO
-*********************************************************************/
-
-floperr_t floppy_load_track(floppy_image_legacy *floppy, int head, int track, int dirtify, void **track_data, size_t *track_length)
-{
- floperr_t err;
- uint32_t track_size;
-
- /* have we already loaded this track? */
- if (((floppy->loaded_track_status & TRACK_LOADED) == 0) || (head != floppy->loaded_track_head) || (track != floppy->loaded_track_index))
- {
- err = floppy_track_unload(floppy);
- if (err)
- goto error;
-
- track_size = floppy_callbacks(floppy)->get_track_size(floppy, head, track);
-
- floppy->loaded_track_data = std::make_unique<uint8_t[]>(track_size);
- floppy->loaded_track_size = track_size;
- floppy->loaded_track_head = head;
- floppy->loaded_track_index = track;
-
- err = floppy_callbacks(floppy)->read_track(floppy, floppy->loaded_track_head, floppy->loaded_track_index, 0, floppy->loaded_track_data.get(), floppy->loaded_track_size);
- if (err)
- goto error;
-
- floppy->loaded_track_status |= TRACK_LOADED | (dirtify ? TRACK_DIRTY : 0);
- }
- else
- floppy->loaded_track_status |= (dirtify ? TRACK_DIRTY : 0);
-
- if (track_data)
- *track_data = floppy->loaded_track_data.get();
- if (track_length)
- *track_length = floppy->loaded_track_size;
- return FLOPPY_ERROR_SUCCESS;
-
-error:
- if (track_data)
- *track_data = nullptr;
- if (track_length)
- *track_length = 0;
- return err;
-}
-
-
-
-static floperr_t floppy_track_unload(floppy_image_legacy *floppy)
-{
- int err;
- if (floppy->loaded_track_status & TRACK_DIRTY)
- {
- err = floppy_callbacks(floppy)->write_track(floppy, floppy->loaded_track_head, floppy->loaded_track_index, 0, floppy->loaded_track_data.get(), floppy->loaded_track_size);
- if (err)
- return (floperr_t)err;
- }
-
- floppy->loaded_track_status &= ~(TRACK_LOADED | TRACK_DIRTY);
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-/*********************************************************************
- accessors for meta information about the image
-*********************************************************************/
-
-const char *floppy_format_description(floppy_image_legacy *floppy)
-{
- return floppy->floppy_option->description;
-}
-
-
-
-/*********************************************************************
- misc calls
-*********************************************************************/
-
-const char *floppy_error(floperr_t err)
-{
- static const char *const error_messages[] =
- {
- "The operation completed successfully",
- "Fatal internal error",
- "This operation is unsupported",
- "Out of memory",
- "Seek error",
- "Invalid image",
- "Attempted to write to read only image",
- "No space left on image",
- "Parameter out of range",
- "Required parameter not specified"
- };
-
- if ((err < 0) || (err >= std::size(error_messages)))
- return nullptr;
- return error_messages[err];
-}
-
-
-LEGACY_FLOPPY_OPTIONS_START(default)
-LEGACY_FLOPPY_OPTIONS_END
-
-
-// license:BSD-3-Clause
-// copyright-holders:Olivier Galibert
-/***************************************************************************
-
- New implementation
-
-****************************************************************************/
-
floppy_image::floppy_image(int _tracks, int _heads, uint32_t _form_factor)
{
diff --git a/src/lib/formats/flopimg.h b/src/lib/formats/flopimg.h
index 550c9a62fa8..d9f4582985d 100644
--- a/src/lib/formats/flopimg.h
+++ b/src/lib/formats/flopimg.h
@@ -7,213 +7,20 @@
Floppy disk image abstraction code
*********************************************************************/
+
#ifndef MAME_FORMATS_FLOPIMG_H
#define MAME_FORMATS_FLOPIMG_H
#pragma once
-#include "coretmpl.h"
-#include "opresolv.h"
#include "utilfwd.h"
-#include "osdcore.h"
-
#include <memory>
#include <vector>
-#ifndef LOG_FORMATS
-#define LOG_FORMATS if (0) printf
-#endif
-
-
-/***************************************************************************
-
- Constants
-
-***************************************************************************/
-
-#define FLOPPY_FLAGS_READWRITE 0
-#define FLOPPY_FLAGS_READONLY 1
-
-/* sector has a deleted data address mark */
-#define ID_FLAG_DELETED_DATA 0x0001
-/* CRC error in id field */
-#define ID_FLAG_CRC_ERROR_IN_ID_FIELD 0x0002
-/* CRC error in data field */
-#define ID_FLAG_CRC_ERROR_IN_DATA_FIELD 0x0004
-
-
-/***************************************************************************
-
- Type definitions
-
-***************************************************************************/
-
-enum floperr_t
-{
- FLOPPY_ERROR_SUCCESS, /* no error */
- FLOPPY_ERROR_INTERNAL, /* fatal internal error */
- FLOPPY_ERROR_UNSUPPORTED, /* this operation is unsupported */
- FLOPPY_ERROR_OUTOFMEMORY, /* ran out of memory */
- FLOPPY_ERROR_SEEKERROR, /* attempted to seek to nonexistent location */
- FLOPPY_ERROR_INVALIDIMAGE, /* this image in invalid */
- FLOPPY_ERROR_READONLY, /* attempt to write to read-only image */
- FLOPPY_ERROR_NOSPACE,
- FLOPPY_ERROR_PARAMOUTOFRANGE,
- FLOPPY_ERROR_PARAMNOTSPECIFIED
-};
-
-struct floppy_image_legacy;
-
-struct FloppyCallbacks
-{
- floperr_t (*read_sector)(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen);
- floperr_t (*write_sector)(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam);
- floperr_t (*read_indexed_sector)(floppy_image_legacy *floppy, int head, int track, int sector_index, void *buffer, size_t buflen);
- floperr_t (*write_indexed_sector)(floppy_image_legacy *floppy, int head, int track, int sector_index, const void *buffer, size_t buflen, int ddam);
- floperr_t (*read_track)(floppy_image_legacy *floppy, int head, int track, uint64_t offset, void *buffer, size_t buflen);
- floperr_t (*write_track)(floppy_image_legacy *floppy, int head, int track, uint64_t offset, const void *buffer, size_t buflen);
- floperr_t (*format_track)(floppy_image_legacy *floppy, int head, int track, util::option_resolution *params);
- floperr_t (*post_format)(floppy_image_legacy *floppy, util::option_resolution *params);
- int (*get_heads_per_disk)(floppy_image_legacy *floppy);
- int (*get_tracks_per_disk)(floppy_image_legacy *floppy);
- int (*get_sectors_per_track)(floppy_image_legacy *floppy, int head, int track);
- uint32_t (*get_track_size)(floppy_image_legacy *floppy, int head, int track);
- floperr_t (*get_sector_length)(floppy_image_legacy *floppy, int head, int track, int sector, uint32_t *sector_length);
- floperr_t (*get_indexed_sector_info)(floppy_image_legacy *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, uint32_t *sector_length, unsigned long *flags);
- floperr_t (*get_track_data_offset)(floppy_image_legacy *floppy, int head, int track, uint64_t *offset);
-};
-
-
-
-struct FloppyFormat
-{
- const char *name;
- const char *extensions;
- const char *description;
- floperr_t (*identify)(floppy_image_legacy *floppy, const struct FloppyFormat *format, int *vote);
- floperr_t (*construct)(floppy_image_legacy *floppy, const struct FloppyFormat *format, util::option_resolution *params);
- floperr_t (*destruct)(floppy_image_legacy *floppy, const struct FloppyFormat *format);
- const char *param_guidelines;
-};
-
-#define FLOPPY_IDENTIFY(name) floperr_t name(floppy_image_legacy *floppy, const struct FloppyFormat *format, int *vote)
-#define FLOPPY_CONSTRUCT(name) floperr_t name(floppy_image_legacy *floppy, const struct FloppyFormat *format, util::option_resolution *params)
-#define FLOPPY_DESTRUCT(name) floperr_t name(floppy_image_legacy *floppy, const struct FloppyFormat *format)
-
-FLOPPY_IDENTIFY(td0_dsk_identify);
-FLOPPY_CONSTRUCT(td0_dsk_construct);
-FLOPPY_DESTRUCT(td0_dsk_destruct);
-
-FLOPPY_IDENTIFY(imd_dsk_identify);
-FLOPPY_CONSTRUCT(imd_dsk_construct);
-
-FLOPPY_IDENTIFY(cqm_dsk_identify);
-FLOPPY_CONSTRUCT(cqm_dsk_construct);
-
-FLOPPY_IDENTIFY(dsk_dsk_identify);
-FLOPPY_CONSTRUCT(dsk_dsk_construct);
-
-FLOPPY_IDENTIFY(d88_dsk_identify);
-FLOPPY_CONSTRUCT(d88_dsk_construct);
-
-FLOPPY_IDENTIFY(fdi_dsk_identify);
-FLOPPY_CONSTRUCT(fdi_dsk_construct);
-
-#define LEGACY_FLOPPY_OPTIONS_NAME(name) floppyoptions_##name
-
-#define LEGACY_FLOPPY_OPTIONS_START(name) \
- const struct FloppyFormat floppyoptions_##name[] = \
- {
-#define LEGACY_FLOPPY_OPTIONS_END0 \
- { nullptr } \
- };
-
-#define LEGACY_FLOPPY_OPTIONS_EXTERN(name) \
- extern const struct FloppyFormat floppyoptions_##name[]
-#define LEGACY_FLOPPY_OPTION(name, extensions_, description_, identify_, construct_, destruct_, ranges_)\
- { #name, extensions_, description_, identify_, construct_, destruct_, ranges_ },
-#define LEGACY_FLOPPY_OPTIONS_END \
- LEGACY_FLOPPY_OPTION( fdi, "fdi", "Formatted Disk Image", fdi_dsk_identify, fdi_dsk_construct, nullptr, nullptr) \
- LEGACY_FLOPPY_OPTION( td0, "td0", "Teledisk floppy disk image", td0_dsk_identify, td0_dsk_construct, td0_dsk_destruct, nullptr) \
- LEGACY_FLOPPY_OPTION( imd, "imd", "IMD floppy disk image", imd_dsk_identify, imd_dsk_construct, nullptr, nullptr) \
- LEGACY_FLOPPY_OPTION( cqm, "cqm,dsk", "CopyQM floppy disk image", cqm_dsk_identify, cqm_dsk_construct, nullptr, nullptr) \
- LEGACY_FLOPPY_OPTION( dsk, "dsk", "DSK floppy disk image", dsk_dsk_identify, dsk_dsk_construct, nullptr, nullptr) \
- LEGACY_FLOPPY_OPTION( d88, "d77,d88,1dd", "D88 Floppy Disk image", d88_dsk_identify, d88_dsk_construct, nullptr, nullptr) \
- LEGACY_FLOPPY_OPTIONS_END0
-
-LEGACY_FLOPPY_OPTIONS_EXTERN(default);
-
-#define PARAM_END '\0'
-#define PARAM_HEADS 'H'
-#define PARAM_TRACKS 'T'
-#define PARAM_SECTORS 'S'
-#define PARAM_SECTOR_LENGTH 'L'
-#define PARAM_INTERLEAVE 'I'
-#define PARAM_FIRST_SECTOR_ID 'F'
-
-#define HEADS(range) "H" #range
-#define TRACKS(range) "T" #range
-#define SECTORS(range) "S" #range
-#define SECTOR_LENGTH(range) "L" #range
-#define INTERLEAVE(range) "I" #range
-#define FIRST_SECTOR_ID(range) "F" #range
-
-/***************************************************************************
-
- Prototypes
-
-***************************************************************************/
-
-OPTION_GUIDE_EXTERN(floppy_option_guide);
-
-/* opening, closing and creating of floppy images */
-floperr_t floppy_open(std::unique_ptr<util::random_read_write> &&io, const std::string &extension, const struct FloppyFormat *format, int flags, floppy_image_legacy **outfloppy);
-floperr_t floppy_open_choices(std::unique_ptr<util::random_read_write> &&io, const std::string &extension, const struct FloppyFormat *formats, int flags, floppy_image_legacy **outfloppy);
-floperr_t floppy_create(std::unique_ptr<util::random_read_write> &&io, const struct FloppyFormat *format, util::option_resolution *parameters, floppy_image_legacy **outfloppy);
-void floppy_close(floppy_image_legacy *floppy);
-
-/* useful for identifying a floppy image */
-floperr_t floppy_identify(std::unique_ptr<util::random_read_write> &&io, const char *extension, const struct FloppyFormat *formats, int *identified_format);
-
-/* functions useful within format constructors */
-void *floppy_tag(floppy_image_legacy *floppy);
-void *floppy_create_tag(floppy_image_legacy *floppy, size_t tagsize);
-struct FloppyCallbacks *floppy_callbacks(floppy_image_legacy *floppy);
-uint8_t floppy_get_filler(floppy_image_legacy *floppy);
-util::random_read_write &floppy_get_io(floppy_image_legacy *floppy);
-
-/* calls for accessing disk image data */
-floperr_t floppy_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, int offset, void *buffer, size_t buffer_len);
-floperr_t floppy_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, int offset, const void *buffer, size_t buffer_len, int ddam);
-floperr_t floppy_read_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector_index, int offset, void *buffer, size_t buffer_len);
-floperr_t floppy_write_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector_index, int offset, const void *buffer, size_t buffer_len, int ddam);
-floperr_t floppy_read_track(floppy_image_legacy *floppy, int head, int track, void *buffer, size_t buffer_len);
-floperr_t floppy_write_track(floppy_image_legacy *floppy, int head, int track, const void *buffer, size_t buffer_len);
-floperr_t floppy_read_track_data(floppy_image_legacy *floppy, int head, int track, void *buffer, size_t buffer_len);
-floperr_t floppy_write_track_data(floppy_image_legacy *floppy, int head, int track, const void *buffer, size_t buffer_len);
-floperr_t floppy_format_track(floppy_image_legacy *floppy, int head, int track, util::option_resolution *params);
-int floppy_get_tracks_per_disk(floppy_image_legacy *floppy);
-int floppy_get_heads_per_disk(floppy_image_legacy *floppy);
-uint32_t floppy_get_track_size(floppy_image_legacy *floppy, int head, int track);
-floperr_t floppy_get_sector_length(floppy_image_legacy *floppy, int head, int track, int sector, uint32_t *sector_length);
-floperr_t floppy_get_indexed_sector_info(floppy_image_legacy *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, uint32_t *sector_length, unsigned long *flags);
-floperr_t floppy_get_sector_count(floppy_image_legacy *floppy, int head, int track, int *sector_count);
-floperr_t floppy_load_track(floppy_image_legacy *floppy, int head, int track, int dirtify, void **track_data, size_t *track_length);
-int floppy_is_read_only(floppy_image_legacy *floppy);
-uint8_t floppy_random_byte(floppy_image_legacy *floppy);
-
-/* accessors for meta information about the image */
-const char *floppy_format_description(floppy_image_legacy *floppy);
-
-/* calls for accessing the raw disk image */
-void floppy_image_read(floppy_image_legacy *floppy, void *buffer, uint64_t offset, size_t length);
-void floppy_image_write(floppy_image_legacy *floppy, const void *buffer, uint64_t offset, size_t length);
-void floppy_image_write_filler(floppy_image_legacy *floppy, uint8_t filler, uint64_t offset, size_t length);
-uint64_t floppy_image_size(floppy_image_legacy *floppy);
-
-/* misc */
-const char *floppy_error(floperr_t err);
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
//////////////////////////////////////////////////////////
diff --git a/src/lib/formats/flopimg_legacy.cpp b/src/lib/formats/flopimg_legacy.cpp
new file mode 100644
index 00000000000..5b8aee0a72b
--- /dev/null
+++ b/src/lib/formats/flopimg_legacy.cpp
@@ -0,0 +1,880 @@
+// license:BSD-3-Clause
+// copyright-holders:Nathan Woods
+/*********************************************************************
+
+ flopimg_legacy.cpp
+
+ Floppy disk image abstraction code (legacy implementation)
+
+*********************************************************************/
+
+#include "flopimg_legacy.h"
+#include "imageutl.h"
+
+#include "ioprocs.h"
+#include "opresolv.h"
+
+#include <cassert>
+#include <climits>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#define TRACK_LOADED 0x01
+#define TRACK_DIRTY 0x02
+
+
+struct floppy_image_legacy
+{
+ util::random_read_write::ptr io = nullptr;
+
+ const struct FloppyFormat *floppy_option = nullptr;
+ struct FloppyCallbacks format = { 0 };
+
+ /* loaded track stuff */
+ int loaded_track_head = 0;
+ int loaded_track_index = 0;
+ uint32_t loaded_track_size = 0;
+ std::unique_ptr<uint8_t[]> loaded_track_data;
+ uint8_t loaded_track_status = 0;
+ uint8_t flags = 0;
+
+ /* tagging system */
+ std::unique_ptr<uint8_t[]> tag_data;
+};
+
+
+
+struct floppy_params
+{
+ int param;
+ int value;
+};
+
+
+
+static floperr_t floppy_track_unload(floppy_image_legacy *floppy);
+
+OPTION_GUIDE_START(floplgcy_option_guide)
+ OPTION_INT('H', "heads", "Heads")
+ OPTION_INT('T', "tracks", "Tracks")
+ OPTION_INT('S', "sectors", "Sectors")
+ OPTION_INT('L', "sectorlength", "Sector Bytes")
+ OPTION_INT('I', "interleave", "Interleave")
+ OPTION_INT('F', "firstsectorid", "First Sector")
+OPTION_GUIDE_END
+
+const util::option_guide &floppy_option_guide()
+{
+ return floplgcy_option_guide;
+}
+
+
+static void floppy_close_internal(floppy_image_legacy *floppy);
+
+/*********************************************************************
+ opening, closing and creating of floppy images
+*********************************************************************/
+
+/* basic floppy_image_legacy initialization common to floppy_open() and floppy_create() */
+static floppy_image_legacy *floppy_init(util::random_read_write::ptr &&io, int flags)
+{
+ floppy_image_legacy *floppy;
+
+ floppy = new floppy_image_legacy;
+
+ floppy->io = std::move(io);
+ floppy->flags = (uint8_t) flags;
+ return floppy;
+}
+
+
+
+/* main code for identifying and maybe opening a disk image; not exposed
+ * directly because this function is big and hideous */
+static floperr_t floppy_open_internal(util::random_read_write::ptr &&io, const std::string &extension,
+ const struct FloppyFormat *floppy_options, int max_options, int flags, floppy_image_legacy **outfloppy,
+ int *outoption)
+{
+ floperr_t err;
+ floppy_image_legacy *floppy;
+ int best_option = -1;
+ int best_vote = 0;
+ int vote;
+ size_t i;
+
+ floppy = floppy_init(std::move(io), flags);
+ if (!floppy)
+ {
+ err = FLOPPY_ERROR_OUTOFMEMORY;
+ goto done;
+ }
+
+ /* vote on the best format */
+ for (i = 0; (i < max_options) && floppy_options[i].construct; i++)
+ {
+ if (extension.empty() || !floppy_options[i].extensions || image_find_extension(floppy_options[i].extensions, extension.c_str()))
+ {
+ if (floppy_options[i].identify)
+ {
+ vote = 0;
+ err = floppy_options[i].identify(floppy, &floppy_options[i], &vote);
+ if (err)
+ goto done;
+ }
+ else
+ {
+ vote = 1;
+ }
+
+ /* is this option a better one? */
+ if (vote > best_vote)
+ {
+ best_vote = vote;
+ best_option = i;
+ }
+ }
+ }
+
+ /* did we find a format? */
+ if (best_option == -1)
+ {
+ err = FLOPPY_ERROR_INVALIDIMAGE;
+ goto done;
+ }
+
+ if (outfloppy)
+ {
+ /* call the format constructor */
+ err = floppy_options[best_option].construct(floppy, &floppy_options[best_option], nullptr);
+ if (err)
+ goto done;
+
+ floppy->floppy_option = &floppy_options[best_option];
+ }
+ if (best_vote != 100)
+ {
+ printf("Loading image that is not 100%% recognized\n");
+ }
+ err = FLOPPY_ERROR_SUCCESS;
+
+done:
+ /* if we have a floppy disk and we either errored or are not keeping it, close it */
+ if (floppy && (!outfloppy || err))
+ {
+ floppy_close_internal(floppy);
+ floppy = nullptr;
+ }
+
+ if (outoption)
+ *outoption = err ? -1 : best_option;
+ if (outfloppy)
+ *outfloppy = floppy;
+ return err;
+}
+
+
+
+floperr_t floppy_identify(util::random_read_write::ptr &&io, const char *extension,
+ const struct FloppyFormat *formats, int *identified_format)
+{
+ return floppy_open_internal(std::move(io), extension, formats, INT_MAX, FLOPPY_FLAGS_READONLY, nullptr, identified_format);
+}
+
+
+
+floperr_t floppy_open(util::random_read_write::ptr &&io, const std::string &extension,
+ const struct FloppyFormat *format, int flags, floppy_image_legacy **outfloppy)
+{
+ return floppy_open_internal(std::move(io), extension, format, 1, flags, outfloppy, nullptr);
+}
+
+
+
+floperr_t floppy_open_choices(util::random_read_write::ptr &&io, const std::string &extension,
+ const struct FloppyFormat *formats, int flags, floppy_image_legacy **outfloppy)
+{
+ return floppy_open_internal(std::move(io), extension, formats, INT_MAX, flags, outfloppy, nullptr);
+}
+
+
+
+floperr_t floppy_create(util::random_read_write::ptr &&io, const struct FloppyFormat *format, util::option_resolution *parameters, floppy_image_legacy **outfloppy)
+{
+ floppy_image_legacy *floppy = nullptr;
+ floperr_t err;
+ int heads, tracks, h, t;
+ std::unique_ptr<util::option_resolution> alloc_resolution;
+
+ assert(format);
+
+ /* create the new image */
+ floppy = floppy_init(std::move(io), 0);
+ if (!floppy)
+ {
+ err = FLOPPY_ERROR_OUTOFMEMORY;
+ goto done;
+ }
+
+ /* if this format expects creation parameters and none were specified, create some */
+ if (!parameters && format->param_guidelines)
+ {
+ try { alloc_resolution = std::make_unique<util::option_resolution>(floplgcy_option_guide); }
+ catch (...)
+ {
+ err = FLOPPY_ERROR_OUTOFMEMORY;
+ goto done;
+ }
+ alloc_resolution->set_specification(format->param_guidelines);
+ parameters = alloc_resolution.get();
+ }
+
+ /* call the format constructor */
+ err = format->construct(floppy, format, parameters);
+ if (err)
+ goto done;
+
+ /* format the disk, ignoring if formatting not implemented */
+ if (floppy->format.format_track)
+ {
+ heads = floppy_get_heads_per_disk(floppy);
+ tracks = floppy_get_tracks_per_disk(floppy);
+
+ for (h = 0; h < heads; h++)
+ {
+ for (t = 0; t < tracks; t++)
+ {
+ err = floppy->format.format_track(floppy, h, t, parameters);
+ if (err)
+ goto done;
+ }
+ }
+ }
+
+ /* call the post_format function, if present */
+ if (floppy->format.post_format)
+ {
+ err = floppy->format.post_format(floppy, parameters);
+ if (err)
+ goto done;
+ }
+
+ floppy->floppy_option = format;
+ err = FLOPPY_ERROR_SUCCESS;
+
+done:
+ if (err && floppy)
+ {
+ floppy_close_internal(floppy);
+ floppy = nullptr;
+ }
+
+ if (outfloppy)
+ *outfloppy = floppy;
+ else if (floppy)
+ floppy_close_internal(floppy);
+ return err;
+}
+
+
+
+static void floppy_close_internal(floppy_image_legacy *floppy)
+{
+ if (floppy) {
+ floppy_track_unload(floppy);
+
+ if(floppy->floppy_option && floppy->floppy_option->destruct)
+ floppy->floppy_option->destruct(floppy, floppy->floppy_option);
+
+ delete floppy;
+ }
+}
+
+
+
+void floppy_close(floppy_image_legacy *floppy)
+{
+ floppy_close_internal(floppy);
+}
+
+
+
+/*********************************************************************
+ functions useful in format constructors
+*********************************************************************/
+
+struct FloppyCallbacks *floppy_callbacks(floppy_image_legacy *floppy)
+{
+ assert(floppy);
+ return &floppy->format;
+}
+
+
+
+void *floppy_tag(floppy_image_legacy *floppy)
+{
+ assert(floppy);
+ return floppy->tag_data.get();
+}
+
+
+
+void *floppy_create_tag(floppy_image_legacy *floppy, size_t tagsize)
+{
+ floppy->tag_data = std::make_unique<uint8_t[]>(tagsize);
+ return floppy->tag_data.get();
+}
+
+
+
+uint8_t floppy_get_filler(floppy_image_legacy *floppy)
+{
+ // FIXME: remove this function, it's here for legacy reasons
+ // the caller actually sets the filler byte - in practice it's always 0xff but there's no actual guarantee
+ return 0xff;
+}
+
+
+
+util::random_read_write &floppy_get_io(floppy_image_legacy *floppy)
+{
+ return *floppy->io;
+}
+
+
+
+/*********************************************************************
+ calls for accessing the raw disk image
+*********************************************************************/
+
+void floppy_image_read(floppy_image_legacy *floppy, void *buffer, uint64_t offset, size_t length)
+{
+ size_t actual;
+ floppy->io->read_at(offset, buffer, length, actual);
+}
+
+
+
+void floppy_image_write(floppy_image_legacy *floppy, const void *buffer, uint64_t offset, size_t length)
+{
+ size_t actual;
+ floppy->io->write_at(offset, buffer, length, actual);
+}
+
+
+
+void floppy_image_write_filler(floppy_image_legacy *floppy, uint8_t filler, uint64_t offset, size_t length)
+{
+ uint8_t buffer[512];
+ memset(buffer, filler, std::min(sizeof(buffer), length));
+
+ while (length)
+ {
+ size_t const block = std::min(sizeof(buffer), length);
+ size_t actual;
+ floppy->io->write_at(offset, buffer, block, actual);
+ offset += block;
+ length -= block;
+ }
+}
+
+
+
+uint64_t floppy_image_size(floppy_image_legacy *floppy)
+{
+ uint64_t result;
+ floppy->io->length(result);
+ return result;
+}
+
+
+
+/*********************************************************************
+ calls for accessing disk image data
+*********************************************************************/
+
+static floperr_t floppy_readwrite_sector(floppy_image_legacy *floppy, int head, int track, int sector, int offset,
+ void *buffer, size_t buffer_len, bool writing, bool indexed, int ddam)
+{
+ floperr_t err;
+ const struct FloppyCallbacks *fmt;
+ size_t this_buffer_len;
+ std::vector<uint8_t> alloc_buf;
+ uint32_t sector_length;
+ uint8_t *buffer_ptr = (uint8_t *)buffer;
+ floperr_t (*read_sector)(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen);
+ floperr_t (*write_sector)(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam);
+
+ fmt = floppy_callbacks(floppy);
+
+ /* choose proper calls for indexed vs non-indexed */
+ if (indexed)
+ {
+ read_sector = fmt->read_indexed_sector;
+ write_sector = fmt->write_indexed_sector;
+ if (!fmt->get_indexed_sector_info)
+ {
+ err = FLOPPY_ERROR_UNSUPPORTED;
+ goto done;
+ }
+ }
+ else
+ {
+ read_sector = fmt->read_sector;
+ write_sector = fmt->write_sector;
+ if (!fmt->get_sector_length)
+ {
+ err = FLOPPY_ERROR_UNSUPPORTED;
+ goto done;
+ }
+ }
+
+ /* check to make sure that the operation is supported */
+ if (!read_sector || (writing && !write_sector))
+ {
+ err = FLOPPY_ERROR_UNSUPPORTED;
+ goto done;
+ }
+
+ /* main loop */
+ while(buffer_len > 0)
+ {
+ /* find out the size of this sector */
+ if (indexed)
+ err = fmt->get_indexed_sector_info(floppy, head, track, sector, nullptr, nullptr, nullptr, &sector_length, nullptr);
+ else
+ err = fmt->get_sector_length(floppy, head, track, sector, &sector_length);
+ if (err)
+ goto done;
+
+ /* do we even do anything with this sector? */
+ if (offset < sector_length)
+ {
+ /* ok we will be doing something */
+ if ((offset > 0) || (buffer_len < sector_length))
+ {
+ /* we will be doing an partial read/write; in other words we
+ * will not be reading/writing a full sector */
+ alloc_buf.resize(sector_length);
+
+ /* read the sector (we need to do this even when writing */
+ err = read_sector(floppy, head, track, sector, &alloc_buf[0], sector_length);
+ if (err)
+ goto done;
+
+ this_buffer_len = std::min(buffer_len, size_t(sector_length - offset));
+
+ if (writing)
+ {
+ memcpy(&alloc_buf[offset], buffer_ptr, this_buffer_len);
+
+ err = write_sector(floppy, head, track, sector, &alloc_buf[0], sector_length, ddam);
+ if (err)
+ goto done;
+ }
+ else
+ {
+ memcpy(buffer_ptr, &alloc_buf[offset], this_buffer_len);
+ }
+ offset += this_buffer_len;
+ offset %= sector_length;
+ }
+ else
+ {
+ this_buffer_len = sector_length;
+
+ if (writing)
+ err = write_sector(floppy, head, track, sector, buffer_ptr, sector_length, ddam);
+ else
+ err = read_sector(floppy, head, track, sector, buffer_ptr, sector_length);
+ if (err)
+ goto done;
+ }
+ }
+ else
+ {
+ /* skip this sector */
+ offset -= sector_length;
+ this_buffer_len = 0;
+ }
+
+ buffer_ptr += this_buffer_len;
+ buffer_len -= this_buffer_len;
+ sector++;
+ }
+
+ err = FLOPPY_ERROR_SUCCESS;
+
+done:
+ return err;
+}
+
+
+
+floperr_t floppy_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, int offset, void *buffer, size_t buffer_len)
+{
+ return floppy_readwrite_sector(floppy, head, track, sector, offset, buffer, buffer_len, false, false, 0);
+}
+
+
+
+floperr_t floppy_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, int offset, const void *buffer, size_t buffer_len, int ddam)
+{
+ return floppy_readwrite_sector(floppy, head, track, sector, offset, (void *) buffer, buffer_len, true, false, ddam);
+}
+
+
+
+floperr_t floppy_read_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector_index, int offset, void *buffer, size_t buffer_len)
+{
+ return floppy_readwrite_sector(floppy, head, track, sector_index, offset, buffer, buffer_len, false, true, 0);
+}
+
+
+
+floperr_t floppy_write_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector_index, int offset, const void *buffer, size_t buffer_len, int ddam)
+{
+ return floppy_readwrite_sector(floppy, head, track, sector_index, offset, (void *) buffer, buffer_len, true, true, ddam);
+}
+
+
+static floperr_t floppy_get_track_data_offset(floppy_image_legacy *floppy, int head, int track, uint64_t *offset)
+{
+ floperr_t err;
+ const struct FloppyCallbacks *callbacks;
+
+ *offset = 0;
+ callbacks = floppy_callbacks(floppy);
+ if (callbacks->get_track_data_offset)
+ {
+ err = callbacks->get_track_data_offset(floppy, head, track, offset);
+ if (err)
+ return err;
+ }
+ return FLOPPY_ERROR_SUCCESS;
+}
+
+
+
+static floperr_t floppy_read_track_offset(floppy_image_legacy *floppy, int head, int track, uint64_t offset, void *buffer, size_t buffer_len)
+{
+ floperr_t err;
+ const struct FloppyCallbacks *format;
+
+ format = floppy_callbacks(floppy);
+
+ if (!format->read_track)
+ return FLOPPY_ERROR_UNSUPPORTED;
+
+ err = floppy_track_unload(floppy);
+ if (err)
+ return err;
+
+ err = format->read_track(floppy, head, track, offset, buffer, buffer_len);
+ if (err)
+ return err;
+
+ return FLOPPY_ERROR_SUCCESS;
+}
+
+
+
+floperr_t floppy_read_track(floppy_image_legacy *floppy, int head, int track, void *buffer, size_t buffer_len)
+{
+ return floppy_read_track_offset(floppy, head, track, 0, buffer, buffer_len);
+}
+
+
+
+floperr_t floppy_read_track_data(floppy_image_legacy *floppy, int head, int track, void *buffer, size_t buffer_len)
+{
+ floperr_t err;
+ uint64_t offset;
+
+ err = floppy_get_track_data_offset(floppy, head, track, &offset);
+ if (err)
+ return err;
+
+ return floppy_read_track_offset(floppy, head, track, offset, buffer, buffer_len);
+}
+
+
+
+static floperr_t floppy_write_track_offset(floppy_image_legacy *floppy, int head, int track, uint64_t offset, const void *buffer, size_t buffer_len)
+{
+ floperr_t err;
+
+ /* track writing supported? */
+ if (!floppy_callbacks(floppy)->write_track)
+ return FLOPPY_ERROR_UNSUPPORTED;
+
+ /* read only? */
+ if (floppy->flags & FLOPPY_FLAGS_READONLY)
+ return FLOPPY_ERROR_READONLY;
+
+ err = floppy_track_unload(floppy);
+ if (err)
+ return err;
+
+ err = floppy_callbacks(floppy)->write_track(floppy, head, track, offset, buffer, buffer_len);
+ if (err)
+ return err;
+
+ return FLOPPY_ERROR_SUCCESS;
+}
+
+
+
+floperr_t floppy_write_track(floppy_image_legacy *floppy, int head, int track, const void *buffer, size_t buffer_len)
+{
+ return floppy_write_track_offset(floppy, head, track, 0, buffer, buffer_len);
+}
+
+
+
+floperr_t floppy_write_track_data(floppy_image_legacy *floppy, int head, int track, const void *buffer, size_t buffer_len)
+{
+ floperr_t err;
+ uint64_t offset;
+
+ err = floppy_get_track_data_offset(floppy, head, track, &offset);
+ if (err)
+ return err;
+
+ return floppy_write_track_offset(floppy, head, track, offset, buffer, buffer_len);
+}
+
+
+
+floperr_t floppy_format_track(floppy_image_legacy *floppy, int head, int track, util::option_resolution *parameters)
+{
+ floperr_t err;
+ struct FloppyCallbacks *format;
+ std::unique_ptr<util::option_resolution> alloc_resolution;
+
+ /* supported? */
+ format = floppy_callbacks(floppy);
+ if (!format->format_track)
+ return FLOPPY_ERROR_UNSUPPORTED;
+
+ /* create a dummy resolution; if no parameters were specified */
+ if (!parameters)
+ {
+ try
+ {
+ alloc_resolution = std::make_unique<util::option_resolution>(floplgcy_option_guide);
+ }
+ catch (...)
+ {
+ return FLOPPY_ERROR_OUTOFMEMORY;
+ }
+ alloc_resolution->set_specification(floppy->floppy_option->param_guidelines);
+
+ parameters = alloc_resolution.get();
+ }
+
+ err = format->format_track(floppy, head, track, parameters);
+ if (err)
+ return err;
+
+ return FLOPPY_ERROR_SUCCESS;
+}
+
+
+
+int floppy_get_tracks_per_disk(floppy_image_legacy *floppy)
+{
+ return floppy_callbacks(floppy)->get_tracks_per_disk(floppy);
+}
+
+
+
+int floppy_get_heads_per_disk(floppy_image_legacy *floppy)
+{
+ return floppy_callbacks(floppy)->get_heads_per_disk(floppy);
+}
+
+
+
+uint32_t floppy_get_track_size(floppy_image_legacy *floppy, int head, int track)
+{
+ const struct FloppyCallbacks *fmt;
+
+ fmt = floppy_callbacks(floppy);
+ if (!fmt->get_track_size)
+ return 0;
+
+ return fmt->get_track_size(floppy, head, track);
+}
+
+
+
+floperr_t floppy_get_sector_length(floppy_image_legacy *floppy, int head, int track, int sector, uint32_t *sector_length)
+{
+ const struct FloppyCallbacks *fmt;
+
+ fmt = floppy_callbacks(floppy);
+ if (!fmt->get_sector_length)
+ return FLOPPY_ERROR_UNSUPPORTED;
+
+ return fmt->get_sector_length(floppy, head, track, sector, sector_length);
+}
+
+
+
+floperr_t floppy_get_indexed_sector_info(floppy_image_legacy *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, uint32_t *sector_length, unsigned long *flags)
+{
+ const struct FloppyCallbacks *fmt;
+
+ fmt = floppy_callbacks(floppy);
+ if (!fmt->get_indexed_sector_info)
+ return FLOPPY_ERROR_UNSUPPORTED;
+
+ return fmt->get_indexed_sector_info(floppy, head, track, sector_index, cylinder, side, sector, sector_length, flags);
+}
+
+
+
+floperr_t floppy_get_sector_count(floppy_image_legacy *floppy, int head, int track, int *sector_count)
+{
+ floperr_t err;
+ int sector_index = 0;
+
+ do
+ {
+ err = floppy_get_indexed_sector_info(floppy, head, track, sector_index, nullptr, nullptr, nullptr, nullptr, nullptr);
+ if (!err)
+ sector_index++;
+ }
+ while(!err);
+
+ if (sector_index && (err == FLOPPY_ERROR_SEEKERROR))
+ err = FLOPPY_ERROR_SUCCESS;
+ if (sector_count)
+ *sector_count = err ? 0 : sector_index;
+ return err;
+}
+
+
+
+int floppy_is_read_only(floppy_image_legacy *floppy)
+{
+ return floppy->flags & FLOPPY_FLAGS_READONLY;
+}
+
+
+
+uint8_t floppy_random_byte(floppy_image_legacy *floppy)
+{
+ /* can't use mame_rand(); this might not be in the core */
+#ifdef rand
+#undef rand
+#endif
+ return rand();
+}
+
+
+
+/*********************************************************************
+ calls for track based IO
+*********************************************************************/
+
+floperr_t floppy_load_track(floppy_image_legacy *floppy, int head, int track, int dirtify, void **track_data, size_t *track_length)
+{
+ floperr_t err;
+ uint32_t track_size;
+
+ /* have we already loaded this track? */
+ if (((floppy->loaded_track_status & TRACK_LOADED) == 0) || (head != floppy->loaded_track_head) || (track != floppy->loaded_track_index))
+ {
+ err = floppy_track_unload(floppy);
+ if (err)
+ goto error;
+
+ track_size = floppy_callbacks(floppy)->get_track_size(floppy, head, track);
+
+ floppy->loaded_track_data = std::make_unique<uint8_t[]>(track_size);
+ floppy->loaded_track_size = track_size;
+ floppy->loaded_track_head = head;
+ floppy->loaded_track_index = track;
+
+ err = floppy_callbacks(floppy)->read_track(floppy, floppy->loaded_track_head, floppy->loaded_track_index, 0, floppy->loaded_track_data.get(), floppy->loaded_track_size);
+ if (err)
+ goto error;
+
+ floppy->loaded_track_status |= TRACK_LOADED | (dirtify ? TRACK_DIRTY : 0);
+ }
+ else
+ floppy->loaded_track_status |= (dirtify ? TRACK_DIRTY : 0);
+
+ if (track_data)
+ *track_data = floppy->loaded_track_data.get();
+ if (track_length)
+ *track_length = floppy->loaded_track_size;
+ return FLOPPY_ERROR_SUCCESS;
+
+error:
+ if (track_data)
+ *track_data = nullptr;
+ if (track_length)
+ *track_length = 0;
+ return err;
+}
+
+
+
+static floperr_t floppy_track_unload(floppy_image_legacy *floppy)
+{
+ int err;
+ if (floppy->loaded_track_status & TRACK_DIRTY)
+ {
+ err = floppy_callbacks(floppy)->write_track(floppy, floppy->loaded_track_head, floppy->loaded_track_index, 0, floppy->loaded_track_data.get(), floppy->loaded_track_size);
+ if (err)
+ return (floperr_t)err;
+ }
+
+ floppy->loaded_track_status &= ~(TRACK_LOADED | TRACK_DIRTY);
+ return FLOPPY_ERROR_SUCCESS;
+}
+
+
+
+/*********************************************************************
+ accessors for meta information about the image
+*********************************************************************/
+
+const char *floppy_format_description(floppy_image_legacy *floppy)
+{
+ return floppy->floppy_option->description;
+}
+
+
+
+/*********************************************************************
+ misc calls
+*********************************************************************/
+
+const char *floppy_error(floperr_t err)
+{
+ static const char *const error_messages[] =
+ {
+ "The operation completed successfully",
+ "Fatal internal error",
+ "This operation is unsupported",
+ "Out of memory",
+ "Seek error",
+ "Invalid image",
+ "Attempted to write to read only image",
+ "No space left on image",
+ "Parameter out of range",
+ "Required parameter not specified"
+ };
+
+ if ((err < 0) || (err >= std::size(error_messages)))
+ return nullptr;
+ return error_messages[err];
+}
+
+
+LEGACY_FLOPPY_OPTIONS_START(default)
+LEGACY_FLOPPY_OPTIONS_END
diff --git a/src/lib/formats/flopimg_legacy.h b/src/lib/formats/flopimg_legacy.h
new file mode 100644
index 00000000000..02953e15bdb
--- /dev/null
+++ b/src/lib/formats/flopimg_legacy.h
@@ -0,0 +1,214 @@
+// license:BSD-3-Clause
+// copyright-holders:Nathan Woods
+/*********************************************************************
+
+ flopimg_legacy.h
+
+ Floppy disk image abstraction code (legacy implementation)
+
+*********************************************************************/
+
+#ifndef MAME_FORMATS_FLOPIMG_LEGACY_H
+#define MAME_FORMATS_FLOPIMG_LEGACY_H
+
+#pragma once
+
+#include "utilfwd.h"
+
+#include <memory>
+#include <string>
+
+#include <cstddef>
+#include <cstdint>
+
+
+/***************************************************************************
+
+ Constants
+
+***************************************************************************/
+
+#define FLOPPY_FLAGS_READWRITE 0
+#define FLOPPY_FLAGS_READONLY 1
+
+/* sector has a deleted data address mark */
+#define ID_FLAG_DELETED_DATA 0x0001
+/* CRC error in id field */
+#define ID_FLAG_CRC_ERROR_IN_ID_FIELD 0x0002
+/* CRC error in data field */
+#define ID_FLAG_CRC_ERROR_IN_DATA_FIELD 0x0004
+
+
+/***************************************************************************
+
+ Type definitions
+
+***************************************************************************/
+
+enum floperr_t
+{
+ FLOPPY_ERROR_SUCCESS, /* no error */
+ FLOPPY_ERROR_INTERNAL, /* fatal internal error */
+ FLOPPY_ERROR_UNSUPPORTED, /* this operation is unsupported */
+ FLOPPY_ERROR_OUTOFMEMORY, /* ran out of memory */
+ FLOPPY_ERROR_SEEKERROR, /* attempted to seek to nonexistent location */
+ FLOPPY_ERROR_INVALIDIMAGE, /* this image in invalid */
+ FLOPPY_ERROR_READONLY, /* attempt to write to read-only image */
+ FLOPPY_ERROR_NOSPACE,
+ FLOPPY_ERROR_PARAMOUTOFRANGE,
+ FLOPPY_ERROR_PARAMNOTSPECIFIED
+};
+
+struct floppy_image_legacy;
+
+struct FloppyCallbacks
+{
+ floperr_t (*read_sector)(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen);
+ floperr_t (*write_sector)(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam);
+ floperr_t (*read_indexed_sector)(floppy_image_legacy *floppy, int head, int track, int sector_index, void *buffer, size_t buflen);
+ floperr_t (*write_indexed_sector)(floppy_image_legacy *floppy, int head, int track, int sector_index, const void *buffer, size_t buflen, int ddam);
+ floperr_t (*read_track)(floppy_image_legacy *floppy, int head, int track, uint64_t offset, void *buffer, size_t buflen);
+ floperr_t (*write_track)(floppy_image_legacy *floppy, int head, int track, uint64_t offset, const void *buffer, size_t buflen);
+ floperr_t (*format_track)(floppy_image_legacy *floppy, int head, int track, util::option_resolution *params);
+ floperr_t (*post_format)(floppy_image_legacy *floppy, util::option_resolution *params);
+ int (*get_heads_per_disk)(floppy_image_legacy *floppy);
+ int (*get_tracks_per_disk)(floppy_image_legacy *floppy);
+ int (*get_sectors_per_track)(floppy_image_legacy *floppy, int head, int track);
+ uint32_t (*get_track_size)(floppy_image_legacy *floppy, int head, int track);
+ floperr_t (*get_sector_length)(floppy_image_legacy *floppy, int head, int track, int sector, uint32_t *sector_length);
+ floperr_t (*get_indexed_sector_info)(floppy_image_legacy *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, uint32_t *sector_length, unsigned long *flags);
+ floperr_t (*get_track_data_offset)(floppy_image_legacy *floppy, int head, int track, uint64_t *offset);
+};
+
+
+
+struct FloppyFormat
+{
+ const char *name;
+ const char *extensions;
+ const char *description;
+ floperr_t (*identify)(floppy_image_legacy *floppy, const struct FloppyFormat *format, int *vote);
+ floperr_t (*construct)(floppy_image_legacy *floppy, const struct FloppyFormat *format, util::option_resolution *params);
+ floperr_t (*destruct)(floppy_image_legacy *floppy, const struct FloppyFormat *format);
+ const char *param_guidelines;
+};
+
+#define FLOPPY_IDENTIFY(name) floperr_t name(floppy_image_legacy *floppy, const struct FloppyFormat *format, int *vote)
+#define FLOPPY_CONSTRUCT(name) floperr_t name(floppy_image_legacy *floppy, const struct FloppyFormat *format, util::option_resolution *params)
+#define FLOPPY_DESTRUCT(name) floperr_t name(floppy_image_legacy *floppy, const struct FloppyFormat *format)
+
+FLOPPY_IDENTIFY(td0_dsk_identify);
+FLOPPY_CONSTRUCT(td0_dsk_construct);
+FLOPPY_DESTRUCT(td0_dsk_destruct);
+
+FLOPPY_IDENTIFY(imd_dsk_identify);
+FLOPPY_CONSTRUCT(imd_dsk_construct);
+
+FLOPPY_IDENTIFY(cqm_dsk_identify);
+FLOPPY_CONSTRUCT(cqm_dsk_construct);
+
+FLOPPY_IDENTIFY(dsk_dsk_identify);
+FLOPPY_CONSTRUCT(dsk_dsk_construct);
+
+FLOPPY_IDENTIFY(d88_dsk_identify);
+FLOPPY_CONSTRUCT(d88_dsk_construct);
+
+FLOPPY_IDENTIFY(fdi_dsk_identify);
+FLOPPY_CONSTRUCT(fdi_dsk_construct);
+
+#define LEGACY_FLOPPY_OPTIONS_NAME(name) floppyoptions_##name
+
+#define LEGACY_FLOPPY_OPTIONS_START(name) \
+ const struct FloppyFormat floppyoptions_##name[] = \
+ {
+#define LEGACY_FLOPPY_OPTIONS_END0 \
+ { nullptr } \
+ };
+
+#define LEGACY_FLOPPY_OPTIONS_EXTERN(name) \
+ extern const struct FloppyFormat floppyoptions_##name[]
+#define LEGACY_FLOPPY_OPTION(name, extensions_, description_, identify_, construct_, destruct_, ranges_)\
+ { #name, extensions_, description_, identify_, construct_, destruct_, ranges_ },
+#define LEGACY_FLOPPY_OPTIONS_END \
+ LEGACY_FLOPPY_OPTION( fdi, "fdi", "Formatted Disk Image", fdi_dsk_identify, fdi_dsk_construct, nullptr, nullptr) \
+ LEGACY_FLOPPY_OPTION( td0, "td0", "Teledisk floppy disk image", td0_dsk_identify, td0_dsk_construct, td0_dsk_destruct, nullptr) \
+ LEGACY_FLOPPY_OPTION( imd, "imd", "IMD floppy disk image", imd_dsk_identify, imd_dsk_construct, nullptr, nullptr) \
+ LEGACY_FLOPPY_OPTION( cqm, "cqm,dsk", "CopyQM floppy disk image", cqm_dsk_identify, cqm_dsk_construct, nullptr, nullptr) \
+ LEGACY_FLOPPY_OPTION( dsk, "dsk", "DSK floppy disk image", dsk_dsk_identify, dsk_dsk_construct, nullptr, nullptr) \
+ LEGACY_FLOPPY_OPTION( d88, "d77,d88,1dd", "D88 Floppy Disk image", d88_dsk_identify, d88_dsk_construct, nullptr, nullptr) \
+ LEGACY_FLOPPY_OPTIONS_END0
+
+LEGACY_FLOPPY_OPTIONS_EXTERN(default);
+
+#define PARAM_END '\0'
+#define PARAM_HEADS 'H'
+#define PARAM_TRACKS 'T'
+#define PARAM_SECTORS 'S'
+#define PARAM_SECTOR_LENGTH 'L'
+#define PARAM_INTERLEAVE 'I'
+#define PARAM_FIRST_SECTOR_ID 'F'
+
+#define HEADS(range) "H" #range
+#define TRACKS(range) "T" #range
+#define SECTORS(range) "S" #range
+#define SECTOR_LENGTH(range) "L" #range
+#define INTERLEAVE(range) "I" #range
+#define FIRST_SECTOR_ID(range) "F" #range
+
+/***************************************************************************
+
+ Prototypes
+
+***************************************************************************/
+
+/* opening, closing and creating of floppy images */
+floperr_t floppy_open(std::unique_ptr<util::random_read_write> &&io, const std::string &extension, const struct FloppyFormat *format, int flags, floppy_image_legacy **outfloppy);
+floperr_t floppy_open_choices(std::unique_ptr<util::random_read_write> &&io, const std::string &extension, const struct FloppyFormat *formats, int flags, floppy_image_legacy **outfloppy);
+floperr_t floppy_create(std::unique_ptr<util::random_read_write> &&io, const struct FloppyFormat *format, util::option_resolution *parameters, floppy_image_legacy **outfloppy);
+void floppy_close(floppy_image_legacy *floppy);
+
+/* useful for identifying a floppy image */
+floperr_t floppy_identify(std::unique_ptr<util::random_read_write> &&io, const char *extension, const struct FloppyFormat *formats, int *identified_format);
+
+/* functions useful within format constructors */
+void *floppy_tag(floppy_image_legacy *floppy);
+void *floppy_create_tag(floppy_image_legacy *floppy, size_t tagsize);
+struct FloppyCallbacks *floppy_callbacks(floppy_image_legacy *floppy);
+uint8_t floppy_get_filler(floppy_image_legacy *floppy);
+util::random_read_write &floppy_get_io(floppy_image_legacy *floppy);
+
+/* calls for accessing disk image data */
+floperr_t floppy_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, int offset, void *buffer, size_t buffer_len);
+floperr_t floppy_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, int offset, const void *buffer, size_t buffer_len, int ddam);
+floperr_t floppy_read_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector_index, int offset, void *buffer, size_t buffer_len);
+floperr_t floppy_write_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector_index, int offset, const void *buffer, size_t buffer_len, int ddam);
+floperr_t floppy_read_track(floppy_image_legacy *floppy, int head, int track, void *buffer, size_t buffer_len);
+floperr_t floppy_write_track(floppy_image_legacy *floppy, int head, int track, const void *buffer, size_t buffer_len);
+floperr_t floppy_read_track_data(floppy_image_legacy *floppy, int head, int track, void *buffer, size_t buffer_len);
+floperr_t floppy_write_track_data(floppy_image_legacy *floppy, int head, int track, const void *buffer, size_t buffer_len);
+floperr_t floppy_format_track(floppy_image_legacy *floppy, int head, int track, util::option_resolution *params);
+int floppy_get_tracks_per_disk(floppy_image_legacy *floppy);
+int floppy_get_heads_per_disk(floppy_image_legacy *floppy);
+uint32_t floppy_get_track_size(floppy_image_legacy *floppy, int head, int track);
+floperr_t floppy_get_sector_length(floppy_image_legacy *floppy, int head, int track, int sector, uint32_t *sector_length);
+floperr_t floppy_get_indexed_sector_info(floppy_image_legacy *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, uint32_t *sector_length, unsigned long *flags);
+floperr_t floppy_get_sector_count(floppy_image_legacy *floppy, int head, int track, int *sector_count);
+floperr_t floppy_load_track(floppy_image_legacy *floppy, int head, int track, int dirtify, void **track_data, size_t *track_length);
+int floppy_is_read_only(floppy_image_legacy *floppy);
+uint8_t floppy_random_byte(floppy_image_legacy *floppy);
+
+/* accessors for meta information about the image */
+const char *floppy_format_description(floppy_image_legacy *floppy);
+
+/* calls for accessing the raw disk image */
+void floppy_image_read(floppy_image_legacy *floppy, void *buffer, uint64_t offset, size_t length);
+void floppy_image_write(floppy_image_legacy *floppy, const void *buffer, uint64_t offset, size_t length);
+void floppy_image_write_filler(floppy_image_legacy *floppy, uint8_t filler, uint64_t offset, size_t length);
+uint64_t floppy_image_size(floppy_image_legacy *floppy);
+
+/* misc */
+const char *floppy_error(floperr_t err);
+
+const util::option_guide &floppy_option_guide();
+
+#endif // MAME_FORMATS_FLOPIMG_LEGACY_H
diff --git a/src/lib/formats/fm7_cas.cpp b/src/lib/formats/fm7_cas.cpp
index a0c0151be7b..63032336518 100644
--- a/src/lib/formats/fm7_cas.cpp
+++ b/src/lib/formats/fm7_cas.cpp
@@ -6,7 +6,7 @@
#include "fm7_cas.h"
-#include <cassert>
+#include <cstring>
#define WAVE_HIGH 0x5a9e
#define WAVE_LOW -0x5a9e
diff --git a/src/lib/formats/fmsx_cas.cpp b/src/lib/formats/fmsx_cas.cpp
index 7bda85782b5..b6642568b55 100644
--- a/src/lib/formats/fmsx_cas.cpp
+++ b/src/lib/formats/fmsx_cas.cpp
@@ -1,8 +1,9 @@
// license:BSD-3-Clause
// copyright-holders:Sean Young
-#include <cassert>
-#include "formats/fmsx_cas.h"
+#include "fmsx_cas.h"
+
+#include <cstring>
#define CAS_PERIOD (16)
diff --git a/src/lib/formats/fmtowns_dsk.cpp b/src/lib/formats/fmtowns_dsk.cpp
index 13d1408ba4b..e07fc7c894e 100644
--- a/src/lib/formats/fmtowns_dsk.cpp
+++ b/src/lib/formats/fmtowns_dsk.cpp
@@ -8,8 +8,6 @@
* Created on: 23/03/2014
*/
- #include <cassert>
-
#include "formats/fmtowns_dsk.h"
fmtowns_format::fmtowns_format() : wd177x_format(formats)
diff --git a/src/lib/formats/fsd_dsk.cpp b/src/lib/formats/fsd_dsk.cpp
index ffb23035420..5f25c857e1f 100644
--- a/src/lib/formats/fsd_dsk.cpp
+++ b/src/lib/formats/fsd_dsk.cpp
@@ -9,9 +9,12 @@
***************************************************************************/
#include "fsd_dsk.h"
+#include "imageutl.h"
#include "ioprocs.h"
+#include <cstring>
+
/*********************************************************************
diff --git a/src/lib/formats/fsd_dsk.h b/src/lib/formats/fsd_dsk.h
index 779ee28ec02..556ae5b96d0 100644
--- a/src/lib/formats/fsd_dsk.h
+++ b/src/lib/formats/fsd_dsk.h
@@ -12,7 +12,7 @@
#pragma once
-#include "flopimg.h"
+#include "flopimg_legacy.h"
#include "wd177x_dsk.h"
/**************************************************************************/
diff --git a/src/lib/formats/g64_dsk.cpp b/src/lib/formats/g64_dsk.cpp
index 8e6b9c75e44..47592b37e42 100644
--- a/src/lib/formats/g64_dsk.cpp
+++ b/src/lib/formats/g64_dsk.cpp
@@ -14,6 +14,8 @@
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
#define G64_FORMAT_HEADER "GCR-1541"
diff --git a/src/lib/formats/gtp_cas.cpp b/src/lib/formats/gtp_cas.cpp
index f8ac6917d64..85caa73fd02 100644
--- a/src/lib/formats/gtp_cas.cpp
+++ b/src/lib/formats/gtp_cas.cpp
@@ -6,9 +6,8 @@
Miodrag Milanovic
*/
-#include "gtp_cas.h"
-#include <cassert>
+#include "gtp_cas.h"
#define GTP_WAV_FREQUENCY 44100
diff --git a/src/lib/formats/h8_cas.cpp b/src/lib/formats/h8_cas.cpp
index 9cef5b6ef81..c0d5d6dd925 100644
--- a/src/lib/formats/h8_cas.cpp
+++ b/src/lib/formats/h8_cas.cpp
@@ -13,8 +13,6 @@ We output a leader, followed by the contents of the H8T file.
#include "h8_cas.h"
-#include <cassert>
-
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
diff --git a/src/lib/formats/hect_dsk.cpp b/src/lib/formats/hect_dsk.cpp
index cf8fc2cacc4..d1fa695ed57 100644
--- a/src/lib/formats/hect_dsk.cpp
+++ b/src/lib/formats/hect_dsk.cpp
@@ -8,10 +8,10 @@
*********************************************************************/
-#include <cassert>
+#include "hect_dsk.h"
+#include "basicdsk.h"
-#include "formats/hect_dsk.h"
-#include "formats/basicdsk.h"
+#include <cstring>
/*****************************************************************************/
/****** Management of the floppy images 200Ko and 800Ko *********************/
diff --git a/src/lib/formats/hect_dsk.h b/src/lib/formats/hect_dsk.h
index c8c185d316b..7a373b6b1f3 100644
--- a/src/lib/formats/hect_dsk.h
+++ b/src/lib/formats/hect_dsk.h
@@ -12,7 +12,7 @@
#pragma once
-#include "flopimg.h"
+#include "flopimg_legacy.h"
/**************************************************************************/
diff --git a/src/lib/formats/hect_tap.cpp b/src/lib/formats/hect_tap.cpp
index a450b9507b4..867d95cf4b0 100644
--- a/src/lib/formats/hect_tap.cpp
+++ b/src/lib/formats/hect_tap.cpp
@@ -14,7 +14,6 @@ You can find some *.K7 file on serveral server in France
Updated 3/1/10 : use real value for timing.
********************************************************************/
-#include <cassert>
#include "hect_tap.h"
diff --git a/src/lib/formats/hp_ipc_dsk.cpp b/src/lib/formats/hp_ipc_dsk.cpp
index 66485b461be..6f78142bed2 100644
--- a/src/lib/formats/hp_ipc_dsk.cpp
+++ b/src/lib/formats/hp_ipc_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/hp_ipc_dsk.h"
hp_ipc_format::hp_ipc_format() : wd177x_format(formats)
diff --git a/src/lib/formats/hpi_dsk.cpp b/src/lib/formats/hpi_dsk.cpp
index bdccc66803d..83e187afe6b 100644
--- a/src/lib/formats/hpi_dsk.cpp
+++ b/src/lib/formats/hpi_dsk.cpp
@@ -50,6 +50,8 @@
#include "coretmpl.h" // BIT
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
// Debugging
#define VERBOSE 0
diff --git a/src/lib/formats/hxchfe_dsk.cpp b/src/lib/formats/hxchfe_dsk.cpp
index 15598bbd746..9c94b1833a4 100644
--- a/src/lib/formats/hxchfe_dsk.cpp
+++ b/src/lib/formats/hxchfe_dsk.cpp
@@ -103,6 +103,8 @@
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
#define HFE_FORMAT_HEADER "HXCPICFE"
diff --git a/src/lib/formats/hxcmfm_dsk.cpp b/src/lib/formats/hxcmfm_dsk.cpp
index e7bf03acd2f..4a70ca8cd7d 100644
--- a/src/lib/formats/hxcmfm_dsk.cpp
+++ b/src/lib/formats/hxcmfm_dsk.cpp
@@ -5,6 +5,8 @@
#include "ioprocs.h"
+#include <cstring>
+
#define MFM_FORMAT_HEADER "HXCMFM"
diff --git a/src/lib/formats/ibmxdf_dsk.cpp b/src/lib/formats/ibmxdf_dsk.cpp
index 5a44290a337..c2c5f71b366 100644
--- a/src/lib/formats/ibmxdf_dsk.cpp
+++ b/src/lib/formats/ibmxdf_dsk.cpp
@@ -31,6 +31,7 @@
*********************************************************************/
#include "ibmxdf_dsk.h"
+#include "imageutl.h"
#include "ioprocs.h"
diff --git a/src/lib/formats/imageutl.h b/src/lib/formats/imageutl.h
index f04624a46db..09213dc20af 100644
--- a/src/lib/formats/imageutl.h
+++ b/src/lib/formats/imageutl.h
@@ -14,6 +14,10 @@
#include "osdcore.h"
+#ifndef LOG_FORMATS
+#define LOG_FORMATS(...) do { if (0) osd_printf_info(__VA_ARGS__); } while (false)
+#endif
+
/* -----------------------------------------------------------------------
* CRC stuff
* ----------------------------------------------------------------------- */
diff --git a/src/lib/formats/imd_dsk.cpp b/src/lib/formats/imd_dsk.cpp
index b0e9a4159d9..6c905f46e2d 100644
--- a/src/lib/formats/imd_dsk.cpp
+++ b/src/lib/formats/imd_dsk.cpp
@@ -9,9 +9,12 @@
*********************************************************************/
#include "imd_dsk.h"
+#include "flopimg_legacy.h"
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
#include <cstring>
diff --git a/src/lib/formats/img_dsk.cpp b/src/lib/formats/img_dsk.cpp
index 73ae499c764..2b9feca0417 100644
--- a/src/lib/formats/img_dsk.cpp
+++ b/src/lib/formats/img_dsk.cpp
@@ -19,6 +19,8 @@
#include "coretmpl.h" // BIT
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
// Debugging
#define VERBOSE 0
diff --git a/src/lib/formats/ipf_dsk.cpp b/src/lib/formats/ipf_dsk.cpp
index 10c9ba2c4a9..da919d4ba0a 100644
--- a/src/lib/formats/ipf_dsk.cpp
+++ b/src/lib/formats/ipf_dsk.cpp
@@ -4,7 +4,7 @@
#include "ioprocs.h"
-#include <cassert>
+#include <cstring>
const floppy_format_type FLOPPY_IPF_FORMAT = &floppy_image_format_creator<ipf_format>;
diff --git a/src/lib/formats/iq151_dsk.cpp b/src/lib/formats/iq151_dsk.cpp
index b085cca0d37..91b3487c186 100644
--- a/src/lib/formats/iq151_dsk.cpp
+++ b/src/lib/formats/iq151_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/iq151_dsk.h"
iq151_format::iq151_format() : upd765_format(formats)
diff --git a/src/lib/formats/itt3030_dsk.cpp b/src/lib/formats/itt3030_dsk.cpp
index 9f0022f197b..48e9d302e4d 100644
--- a/src/lib/formats/itt3030_dsk.cpp
+++ b/src/lib/formats/itt3030_dsk.cpp
@@ -10,8 +10,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/itt3030_dsk.h"
itt3030_format::itt3030_format() : wd177x_format(formats)
diff --git a/src/lib/formats/jfd_dsk.cpp b/src/lib/formats/jfd_dsk.cpp
index 7a1da472356..6a07d5c2fef 100644
--- a/src/lib/formats/jfd_dsk.cpp
+++ b/src/lib/formats/jfd_dsk.cpp
@@ -162,6 +162,8 @@
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
#include <zlib.h>
diff --git a/src/lib/formats/jvc_dsk.cpp b/src/lib/formats/jvc_dsk.cpp
index c71f2c3be06..de5d85cecd4 100644
--- a/src/lib/formats/jvc_dsk.cpp
+++ b/src/lib/formats/jvc_dsk.cpp
@@ -108,6 +108,8 @@
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
jvc_format::jvc_format()
{
diff --git a/src/lib/formats/kaypro_dsk.cpp b/src/lib/formats/kaypro_dsk.cpp
index 9d85ced697c..b4a8cd4c075 100644
--- a/src/lib/formats/kaypro_dsk.cpp
+++ b/src/lib/formats/kaypro_dsk.cpp
@@ -16,8 +16,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/kaypro_dsk.h"
kayproii_format::kayproii_format() : upd765_format(formats)
diff --git a/src/lib/formats/kc85_dsk.cpp b/src/lib/formats/kc85_dsk.cpp
index 0648289af71..afd81658594 100644
--- a/src/lib/formats/kc85_dsk.cpp
+++ b/src/lib/formats/kc85_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/kc85_dsk.h"
kc85_format::kc85_format() : upd765_format(formats)
diff --git a/src/lib/formats/kc_cas.cpp b/src/lib/formats/kc_cas.cpp
index 74397e3f89a..035d18fb4cd 100644
--- a/src/lib/formats/kc_cas.cpp
+++ b/src/lib/formats/kc_cas.cpp
@@ -15,7 +15,7 @@
#include "kc_cas.h"
-#include <cassert>
+#include <cstring>
#define SMPLO -32768
#define SMPHI 32767
diff --git a/src/lib/formats/kim1_cas.cpp b/src/lib/formats/kim1_cas.cpp
index 0ae96280ee3..8fb89ff4206 100644
--- a/src/lib/formats/kim1_cas.cpp
+++ b/src/lib/formats/kim1_cas.cpp
@@ -2,7 +2,7 @@
// copyright-holders:Wilbert Pol
#include "kim1_cas.h"
-#include <cassert>
+#include <cstring>
#define SMPLO -32768
#define SMPHI 32767
diff --git a/src/lib/formats/lviv_lvt.cpp b/src/lib/formats/lviv_lvt.cpp
index 3725c181f3c..c2ffe37d9c9 100644
--- a/src/lib/formats/lviv_lvt.cpp
+++ b/src/lib/formats/lviv_lvt.cpp
@@ -1,9 +1,8 @@
// license:BSD-3-Clause
// copyright-holders:Krzysztof Strzecha
/* .LVT tape images */
-#include "lviv_lvt.h"
-#include <cassert>
+#include "lviv_lvt.h"
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
diff --git a/src/lib/formats/m5_dsk.cpp b/src/lib/formats/m5_dsk.cpp
index 764dfeea6f1..f172c99348b 100644
--- a/src/lib/formats/m5_dsk.cpp
+++ b/src/lib/formats/m5_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/m5_dsk.h"
m5_format::m5_format() : upd765_format(formats)
diff --git a/src/lib/formats/mbee_cas.cpp b/src/lib/formats/mbee_cas.cpp
index 855b4757581..cd11f7bb041 100644
--- a/src/lib/formats/mbee_cas.cpp
+++ b/src/lib/formats/mbee_cas.cpp
@@ -56,8 +56,6 @@ TAP - has an ID header of TAP_DGOS_BEE or MBEE, null terminated.
********************************************************************/
-#include <cassert>
-
#include "mbee_cas.h"
#define WAVEENTRY_LOW -32768
diff --git a/src/lib/formats/mfi_dsk.cpp b/src/lib/formats/mfi_dsk.cpp
index 8272253c36a..d77892ddfef 100644
--- a/src/lib/formats/mfi_dsk.cpp
+++ b/src/lib/formats/mfi_dsk.cpp
@@ -6,6 +6,8 @@
#include <zlib.h>
+#include <cstring>
+
/*
Mess floppy image structure:
diff --git a/src/lib/formats/mm_dsk.cpp b/src/lib/formats/mm_dsk.cpp
index 0dea3646fce..1c4109cc216 100644
--- a/src/lib/formats/mm_dsk.cpp
+++ b/src/lib/formats/mm_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/mm_dsk.h"
mm1_format::mm1_format() : upd765_format(formats)
diff --git a/src/lib/formats/ms0515_dsk.cpp b/src/lib/formats/ms0515_dsk.cpp
index c89dae8018f..7c4d6a730a4 100644
--- a/src/lib/formats/ms0515_dsk.cpp
+++ b/src/lib/formats/ms0515_dsk.cpp
@@ -10,8 +10,6 @@
#include "formats/ms0515_dsk.h"
-#include <cassert>
-
ms0515_format::ms0515_format() : wd177x_format(formats)
{
}
diff --git a/src/lib/formats/mz_cas.cpp b/src/lib/formats/mz_cas.cpp
index 0ab4cec8e84..6bc82a43bd1 100644
--- a/src/lib/formats/mz_cas.cpp
+++ b/src/lib/formats/mz_cas.cpp
@@ -3,7 +3,6 @@
#include "mz_cas.h"
#include <cstring>
-#include <cassert>
#ifndef VERBOSE
#define VERBOSE 0
diff --git a/src/lib/formats/nanos_dsk.cpp b/src/lib/formats/nanos_dsk.cpp
index ef466f024a0..b41eeea795f 100644
--- a/src/lib/formats/nanos_dsk.cpp
+++ b/src/lib/formats/nanos_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/nanos_dsk.h"
nanos_format::nanos_format() : upd765_format(formats)
diff --git a/src/lib/formats/naslite_dsk.cpp b/src/lib/formats/naslite_dsk.cpp
index fdd63ca0ecc..69b12bbd43d 100644
--- a/src/lib/formats/naslite_dsk.cpp
+++ b/src/lib/formats/naslite_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/naslite_dsk.h"
naslite_format::naslite_format() : upd765_format(formats)
diff --git a/src/lib/formats/nes_dsk.cpp b/src/lib/formats/nes_dsk.cpp
index dd311862ca7..237fd2c4fd7 100644
--- a/src/lib/formats/nes_dsk.cpp
+++ b/src/lib/formats/nes_dsk.cpp
@@ -8,13 +8,11 @@
*********************************************************************/
-
-#include <cstring>
-#include <cassert>
-
#include "formats/nes_dsk.h"
#include "formats/basicdsk.h"
+#include <cstring>
+
/*****************************************************************************
diff --git a/src/lib/formats/nes_dsk.h b/src/lib/formats/nes_dsk.h
index d222beb03f9..a6b589380cb 100644
--- a/src/lib/formats/nes_dsk.h
+++ b/src/lib/formats/nes_dsk.h
@@ -12,7 +12,7 @@
#pragma once
-#include "flopimg.h"
+#include "flopimg_legacy.h"
LEGACY_FLOPPY_OPTIONS_EXTERN(nes_only);
diff --git a/src/lib/formats/nfd_dsk.cpp b/src/lib/formats/nfd_dsk.cpp
index 4a51e0db54c..91d60b6a2ab 100644
--- a/src/lib/formats/nfd_dsk.cpp
+++ b/src/lib/formats/nfd_dsk.cpp
@@ -81,6 +81,10 @@
#include "ioprocs.h"
+#include "osdcomm.h" // little_endianize_int*
+
+#include <cstring>
+
nfd_format::nfd_format()
{
diff --git a/src/lib/formats/orao_cas.cpp b/src/lib/formats/orao_cas.cpp
index a6930e18d1f..a580fdef077 100644
--- a/src/lib/formats/orao_cas.cpp
+++ b/src/lib/formats/orao_cas.cpp
@@ -5,9 +5,8 @@
Tape support for Orao TAP format
*/
-#include "orao_cas.h"
-#include <cassert>
+#include "orao_cas.h"
#define ORAO_WAV_FREQUENCY 44100
diff --git a/src/lib/formats/oric_dsk.cpp b/src/lib/formats/oric_dsk.cpp
index f5b0783a112..df6fa1a2ba9 100644
--- a/src/lib/formats/oric_dsk.cpp
+++ b/src/lib/formats/oric_dsk.cpp
@@ -12,6 +12,8 @@
#include "ioprocs.h"
+#include <cstring>
+
const char *oric_dsk_format::name() const
{
diff --git a/src/lib/formats/oric_tap.cpp b/src/lib/formats/oric_tap.cpp
index 9dc98239fac..97cdc8097e0 100644
--- a/src/lib/formats/oric_tap.cpp
+++ b/src/lib/formats/oric_tap.cpp
@@ -1,8 +1,7 @@
// license:BSD-3-Clause
// copyright-holders:Kevin Thacker
#include "oric_tap.h"
-
-#include <cassert>
+#include "imageutl.h"
#define ORIC_WAV_DEBUG 0
diff --git a/src/lib/formats/p2000t_cas.cpp b/src/lib/formats/p2000t_cas.cpp
index de6652d41ad..2e84cf0fdd8 100644
--- a/src/lib/formats/p2000t_cas.cpp
+++ b/src/lib/formats/p2000t_cas.cpp
@@ -5,7 +5,6 @@
#include "coretmpl.h" // BIT
-#include <cassert>
#include <ostream>
diff --git a/src/lib/formats/p6001_cas.cpp b/src/lib/formats/p6001_cas.cpp
index 425a4e8dd2c..c4689eb9be4 100644
--- a/src/lib/formats/p6001_cas.cpp
+++ b/src/lib/formats/p6001_cas.cpp
@@ -6,8 +6,6 @@
#include "p6001_cas.h"
-#include <cassert>
-
#define WAVE_HIGH 0x5a9e
#define WAVE_LOW -0x5a9e
diff --git a/src/lib/formats/pasti_dsk.cpp b/src/lib/formats/pasti_dsk.cpp
index 1a418096cd3..1822bf7e5ad 100644
--- a/src/lib/formats/pasti_dsk.cpp
+++ b/src/lib/formats/pasti_dsk.cpp
@@ -1,9 +1,12 @@
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
#include "pasti_dsk.h"
+#include "imageutl.h"
#include "ioprocs.h"
+#include <cstring>
+
// Pasti format supported using the documentation at
// http://www.sarnau.info/atari:pasti_file_format
diff --git a/src/lib/formats/pc98_dsk.cpp b/src/lib/formats/pc98_dsk.cpp
index 1add267da8f..125a23b13dd 100644
--- a/src/lib/formats/pc98_dsk.cpp
+++ b/src/lib/formats/pc98_dsk.cpp
@@ -8,11 +8,10 @@
*********************************************************************/
-#include <cstring>
-#include <cassert>
-
#include "formats/pc98_dsk.h"
+#include <cstring>
+
/* ----------------------------------------------------------------------- */
diff --git a/src/lib/formats/pc98fdi_dsk.cpp b/src/lib/formats/pc98fdi_dsk.cpp
index 61fb8fb8fe3..3dd8694c981 100644
--- a/src/lib/formats/pc98fdi_dsk.cpp
+++ b/src/lib/formats/pc98fdi_dsk.cpp
@@ -12,6 +12,8 @@
#include "ioprocs.h"
+#include "osdcomm.h" // little_endianize_int32
+
pc98fdi_format::pc98fdi_format()
{
diff --git a/src/lib/formats/phc25_cas.cpp b/src/lib/formats/phc25_cas.cpp
index ee8864adbb5..8294df07628 100644
--- a/src/lib/formats/phc25_cas.cpp
+++ b/src/lib/formats/phc25_cas.cpp
@@ -31,8 +31,6 @@ enough to make it work.
#include "phc25_cas.h"
-#include <cassert>
-
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
diff --git a/src/lib/formats/pmd_cas.cpp b/src/lib/formats/pmd_cas.cpp
index 20e4a64bbe1..ca38ac21c13 100644
--- a/src/lib/formats/pmd_cas.cpp
+++ b/src/lib/formats/pmd_cas.cpp
@@ -12,8 +12,6 @@
#include "pmd_cas.h"
-#include <cassert>
-
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
diff --git a/src/lib/formats/poly_dsk.cpp b/src/lib/formats/poly_dsk.cpp
index 8845643eb72..45efe6ec451 100644
--- a/src/lib/formats/poly_dsk.cpp
+++ b/src/lib/formats/poly_dsk.cpp
@@ -12,6 +12,8 @@
#include "ioprocs.h"
+#include <cstring>
+
poly_cpm_format::poly_cpm_format()
{
diff --git a/src/lib/formats/ppg_dsk.cpp b/src/lib/formats/ppg_dsk.cpp
index 0c844a753fc..97c208baf1a 100644
--- a/src/lib/formats/ppg_dsk.cpp
+++ b/src/lib/formats/ppg_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/ppg_dsk.h"
ppg_format::ppg_format() : wd177x_format(formats)
diff --git a/src/lib/formats/primoptp.cpp b/src/lib/formats/primoptp.cpp
index 6e04f01bc62..ccadcb6d70d 100644
--- a/src/lib/formats/primoptp.cpp
+++ b/src/lib/formats/primoptp.cpp
@@ -3,8 +3,7 @@
/* .PTP Microkey Primo tape images */
#include "primoptp.h"
-
-#include <cassert>
+#include "imageutl.h"
#define PRIMO_WAVEENTRY_LOW -32768
diff --git a/src/lib/formats/pyldin_dsk.cpp b/src/lib/formats/pyldin_dsk.cpp
index 89a75ce5555..b1f6ab2cdd9 100644
--- a/src/lib/formats/pyldin_dsk.cpp
+++ b/src/lib/formats/pyldin_dsk.cpp
@@ -8,7 +8,6 @@
*********************************************************************/
-#include <cassert>
#include "formats/pyldin_dsk.h"
pyldin_format::pyldin_format() : upd765_format(formats)
diff --git a/src/lib/formats/ql_dsk.cpp b/src/lib/formats/ql_dsk.cpp
index 6be088439cc..19ae4b4050c 100644
--- a/src/lib/formats/ql_dsk.cpp
+++ b/src/lib/formats/ql_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/ql_dsk.h"
ql_format::ql_format() : wd177x_format(formats)
diff --git a/src/lib/formats/rk_cas.cpp b/src/lib/formats/rk_cas.cpp
index a31c47592db..4747ccd50ed 100644
--- a/src/lib/formats/rk_cas.cpp
+++ b/src/lib/formats/rk_cas.cpp
@@ -5,9 +5,8 @@
Tape support for RK format
*/
-#include "rk_cas.h"
-#include <cassert>
+#include "rk_cas.h"
#define RK_WAV_FREQUENCY 44000
diff --git a/src/lib/formats/sc3000_bit.cpp b/src/lib/formats/sc3000_bit.cpp
index e1ee814e147..1cf015f2b6d 100644
--- a/src/lib/formats/sc3000_bit.cpp
+++ b/src/lib/formats/sc3000_bit.cpp
@@ -7,9 +7,8 @@
Cassette code for Sega SC-3000 *.bit files
*********************************************************************/
-#include "sc3000_bit.h"
-#include <cassert>
+#include "sc3000_bit.h"
/***************************************************************************
diff --git a/src/lib/formats/sf7000_dsk.cpp b/src/lib/formats/sf7000_dsk.cpp
index 8e063ceba35..bd6694ecb1c 100644
--- a/src/lib/formats/sf7000_dsk.cpp
+++ b/src/lib/formats/sf7000_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/sf7000_dsk.h"
sf7000_format::sf7000_format() : upd765_format(formats)
diff --git a/src/lib/formats/smx_dsk.cpp b/src/lib/formats/smx_dsk.cpp
index 7ddcc1ae35f..d23b030fb57 100644
--- a/src/lib/formats/smx_dsk.cpp
+++ b/src/lib/formats/smx_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/smx_dsk.h"
smx_format::smx_format() : wd177x_format(formats)
diff --git a/src/lib/formats/sol_cas.cpp b/src/lib/formats/sol_cas.cpp
index 2d60023b23f..1e54963953b 100644
--- a/src/lib/formats/sol_cas.cpp
+++ b/src/lib/formats/sol_cas.cpp
@@ -33,9 +33,8 @@ SVT - The full explanation may be found on the Solace web site,
escaped characters
********************************************************************/
-#include "sol_cas.h"
-#include <cassert>
+#include "sol_cas.h"
#define WAVEENTRY_LOW -32768
diff --git a/src/lib/formats/sorc_cas.cpp b/src/lib/formats/sorc_cas.cpp
index 21b3f8b5c2c..78417e80fc0 100644
--- a/src/lib/formats/sorc_cas.cpp
+++ b/src/lib/formats/sorc_cas.cpp
@@ -24,9 +24,8 @@ header and leader bytes.
********************************************************************/
-#include "sorc_cas.h"
-#include <cassert>
+#include "sorc_cas.h"
#define WAVEENTRY_LOW -32768
diff --git a/src/lib/formats/sorc_dsk.cpp b/src/lib/formats/sorc_dsk.cpp
index 35d293be3fc..2e7b30d2a3d 100644
--- a/src/lib/formats/sorc_dsk.cpp
+++ b/src/lib/formats/sorc_dsk.cpp
@@ -8,12 +8,11 @@
*********************************************************************/
-#include <cstring>
-#include <cassert>
-
#include "sorc_dsk.h"
#include "basicdsk.h"
+#include <cstring>
+
static FLOPPY_IDENTIFY(sorc_dsk_identify)
{
*vote = (floppy_image_size(floppy) == 332640) ? 100 : 0;
diff --git a/src/lib/formats/sorc_dsk.h b/src/lib/formats/sorc_dsk.h
index 6988fa08b52..db98ea424ff 100644
--- a/src/lib/formats/sorc_dsk.h
+++ b/src/lib/formats/sorc_dsk.h
@@ -12,7 +12,7 @@
#pragma once
-#include "flopimg.h"
+#include "flopimg_legacy.h"
/**************************************************************************/
diff --git a/src/lib/formats/sord_cas.cpp b/src/lib/formats/sord_cas.cpp
index 600751088d0..acf89476e88 100644
--- a/src/lib/formats/sord_cas.cpp
+++ b/src/lib/formats/sord_cas.cpp
@@ -7,10 +7,10 @@
Format code for Sord M5 cassette files
**************************************************************************/
+
#include "sord_cas.h"
#include <cstring>
-#include <cassert>
#define SORDM5_WAVESAMPLES_HEADER 1
#define SORDM5_WAVESAMPLES_TRAILER 1
diff --git a/src/lib/formats/spc1000_cas.cpp b/src/lib/formats/spc1000_cas.cpp
index e5d4bc1d0c3..e6b3959e2e7 100644
--- a/src/lib/formats/spc1000_cas.cpp
+++ b/src/lib/formats/spc1000_cas.cpp
@@ -20,9 +20,8 @@ STA: This format has not been investigated yet, but is assumed to
IPL: This seems a quickload format containing RAM dump, not a real tape
********************************************************************/
-#include "spc1000_cas.h"
-#include <cassert>
+#include "spc1000_cas.h"
#define WAVEENTRY_LOW -32768
diff --git a/src/lib/formats/st_dsk.cpp b/src/lib/formats/st_dsk.cpp
index d044bc5bdac..3d81221ea72 100644
--- a/src/lib/formats/st_dsk.cpp
+++ b/src/lib/formats/st_dsk.cpp
@@ -12,6 +12,8 @@
#include "ioprocs.h"
+#include <cstring>
+
st_format::st_format()
{
diff --git a/src/lib/formats/svi_cas.cpp b/src/lib/formats/svi_cas.cpp
index dfd695dd5ec..137eaa27a52 100644
--- a/src/lib/formats/svi_cas.cpp
+++ b/src/lib/formats/svi_cas.cpp
@@ -2,7 +2,7 @@
// copyright-holders:Sean Young
#include "svi_cas.h"
-#include <cassert>
+#include <cstring>
#define CAS_PERIOD_0 (37)
#define CAS_PERIOD_1 (18)
diff --git a/src/lib/formats/swd_dsk.cpp b/src/lib/formats/swd_dsk.cpp
index 47b5fc9266e..bf55a2527d6 100644
--- a/src/lib/formats/swd_dsk.cpp
+++ b/src/lib/formats/swd_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/swd_dsk.h"
swd_format::swd_format() : wd177x_format(formats)
diff --git a/src/lib/formats/tandy2k_dsk.cpp b/src/lib/formats/tandy2k_dsk.cpp
index f811483251d..7577fd5a089 100644
--- a/src/lib/formats/tandy2k_dsk.cpp
+++ b/src/lib/formats/tandy2k_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/tandy2k_dsk.h"
tandy2k_format::tandy2k_format() : upd765_format(formats)
diff --git a/src/lib/formats/td0_dsk.cpp b/src/lib/formats/td0_dsk.cpp
index 345a242c86b..b6ab2753c14 100644
--- a/src/lib/formats/td0_dsk.cpp
+++ b/src/lib/formats/td0_dsk.cpp
@@ -14,7 +14,7 @@
* Edited and translated to English by Kenji RIKITAKE
*/
-#include "flopimg.h"
+#include "flopimg_legacy.h"
#include "ioprocs.h"
diff --git a/src/lib/formats/thom_cas.cpp b/src/lib/formats/thom_cas.cpp
index 2eef0a3eb66..02bab6217fe 100644
--- a/src/lib/formats/thom_cas.cpp
+++ b/src/lib/formats/thom_cas.cpp
@@ -10,8 +10,9 @@
#include "thom_cas.h"
-#include <cassert>
#include <cmath>
+#include <cstdio>
+#include <cstring>
/***************************** configuration **************************/
diff --git a/src/lib/formats/ti99_dsk.cpp b/src/lib/formats/ti99_dsk.cpp
index 507d7dc0ae0..12ad80707e9 100644
--- a/src/lib/formats/ti99_dsk.cpp
+++ b/src/lib/formats/ti99_dsk.cpp
@@ -49,7 +49,6 @@
#include <cstring>
#include <ctime>
-#include <cassert>
#include <iomanip>
#define SECTOR_SIZE 256
diff --git a/src/lib/formats/tiki100_dsk.cpp b/src/lib/formats/tiki100_dsk.cpp
index 9dd6555c9ff..209ae11aa1d 100644
--- a/src/lib/formats/tiki100_dsk.cpp
+++ b/src/lib/formats/tiki100_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/tiki100_dsk.h"
tiki100_format::tiki100_format() : wd177x_format(formats)
diff --git a/src/lib/formats/trs80_dsk.cpp b/src/lib/formats/trs80_dsk.cpp
index acd48368239..60422a92081 100644
--- a/src/lib/formats/trs80_dsk.cpp
+++ b/src/lib/formats/trs80_dsk.cpp
@@ -68,6 +68,8 @@ Description of JV3:
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
jv1_format::jv1_format() : wd177x_format(formats)
{
diff --git a/src/lib/formats/trs_cas.cpp b/src/lib/formats/trs_cas.cpp
index 6fa711db683..8b1ede7ec81 100644
--- a/src/lib/formats/trs_cas.cpp
+++ b/src/lib/formats/trs_cas.cpp
@@ -14,9 +14,8 @@ The Model 3 and 4 can load either Level II tapes (by answering L
to the Cass? prompt), or the fast format by hitting enter at Cass?
********************************************************************/
-#include "formats/trs_cas.h"
-#include <cassert>
+#include "formats/trs_cas.h"
#define SILENCE 0
diff --git a/src/lib/formats/tvc_cas.cpp b/src/lib/formats/tvc_cas.cpp
index 8fe50cdfd14..b512b4008cc 100644
--- a/src/lib/formats/tvc_cas.cpp
+++ b/src/lib/formats/tvc_cas.cpp
@@ -7,9 +7,8 @@
http://tvc.homeserver.hu/html/konvertformatum.html
********************************************************************/
-#include "tvc_cas.h"
-#include <cassert>
+#include "tvc_cas.h"
#define TVC64_BIT0_FREQ 1812
diff --git a/src/lib/formats/tvc_dsk.cpp b/src/lib/formats/tvc_dsk.cpp
index 303a5c2c09d..1ea4389c945 100644
--- a/src/lib/formats/tvc_dsk.cpp
+++ b/src/lib/formats/tvc_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/tvc_dsk.h"
tvc_format::tvc_format() : wd177x_format(formats)
diff --git a/src/lib/formats/tzx_cas.cpp b/src/lib/formats/tzx_cas.cpp
index 6452faefda8..171eeda89cd 100644
--- a/src/lib/formats/tzx_cas.cpp
+++ b/src/lib/formats/tzx_cas.cpp
@@ -30,7 +30,6 @@ TODO:
#include "tzx_cas.h"
#include "imageutl.h"
-#include <cassert>
#include <cmath>
diff --git a/src/lib/formats/uef_cas.cpp b/src/lib/formats/uef_cas.cpp
index 1b4fb1bc271..15638e5f025 100644
--- a/src/lib/formats/uef_cas.cpp
+++ b/src/lib/formats/uef_cas.cpp
@@ -18,10 +18,10 @@ Not nice, but it works...
*/
#include "uef_cas.h"
+#include "imageutl.h"
#include <zlib.h>
-#include <cassert>
#include <cmath>
#include <cstring>
diff --git a/src/lib/formats/upd765_dsk.cpp b/src/lib/formats/upd765_dsk.cpp
index d0afab39352..7c82e9b769a 100644
--- a/src/lib/formats/upd765_dsk.cpp
+++ b/src/lib/formats/upd765_dsk.cpp
@@ -12,6 +12,10 @@
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
+#include <cstring>
+
upd765_format::upd765_format(const format *_formats) : file_header_skip_bytes(0), file_footer_skip_bytes(0), formats(_formats)
{
diff --git a/src/lib/formats/vg5k_cas.cpp b/src/lib/formats/vg5k_cas.cpp
index f73049299b1..ab6787ab850 100644
--- a/src/lib/formats/vg5k_cas.cpp
+++ b/src/lib/formats/vg5k_cas.cpp
@@ -5,9 +5,8 @@
Support for VG-5000 .k7 cassette images
********************************************************************/
-#include "vg5k_cas.h"
-#include <cassert>
+#include "vg5k_cas.h"
#define SMPLO -32768
diff --git a/src/lib/formats/victor9k_dsk.cpp b/src/lib/formats/victor9k_dsk.cpp
index 3a142629726..c4402db5402 100644
--- a/src/lib/formats/victor9k_dsk.cpp
+++ b/src/lib/formats/victor9k_dsk.cpp
@@ -99,8 +99,13 @@
#include "formats/victor9k_dsk.h"
+#include "coretmpl.h" // util::BIT
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
+#include <cstring>
+
victor9k_format::victor9k_format()
{
diff --git a/src/lib/formats/victor9k_dsk.h b/src/lib/formats/victor9k_dsk.h
index aafd8fdcb14..90391d60a15 100644
--- a/src/lib/formats/victor9k_dsk.h
+++ b/src/lib/formats/victor9k_dsk.h
@@ -61,8 +61,4 @@ protected:
extern const floppy_format_type FLOPPY_VICTOR_9000_FORMAT;
-FLOPPY_IDENTIFY( victor9k_dsk_identify );
-
-FLOPPY_CONSTRUCT( victor9k_dsk_construct );
-
#endif // MAME_FORMATS_VICTOR9K_DSK_H
diff --git a/src/lib/formats/vt_cas.cpp b/src/lib/formats/vt_cas.cpp
index 735ec067d7b..046e97880d8 100644
--- a/src/lib/formats/vt_cas.cpp
+++ b/src/lib/formats/vt_cas.cpp
@@ -2,8 +2,6 @@
// copyright-holders:Juergen Buchmueller
#include "formats/vt_cas.h"
-#include <cassert>
-
/*********************************************************************
vtech 1/2 agnostic
*********************************************************************/
diff --git a/src/lib/formats/wavfile.cpp b/src/lib/formats/wavfile.cpp
index 74976ef997e..95b6d8bb7c8 100644
--- a/src/lib/formats/wavfile.cpp
+++ b/src/lib/formats/wavfile.cpp
@@ -10,8 +10,11 @@
#include "wavfile.h"
-#include <cstdio>
+#include "osdcomm.h" // little_endianize_int16
+
#include <cassert>
+#include <cstdio>
+#include <cstring>
static const char magic1[4] = { 'R', 'I', 'F', 'F' };
static const char magic2[4] = { 'W', 'A', 'V', 'E' };
diff --git a/src/lib/formats/wd177x_dsk.cpp b/src/lib/formats/wd177x_dsk.cpp
index 75f3396020f..5675e3bd5aa 100644
--- a/src/lib/formats/wd177x_dsk.cpp
+++ b/src/lib/formats/wd177x_dsk.cpp
@@ -12,6 +12,10 @@
#include "ioprocs.h"
+#include "osdcore.h" // osd_printf_*
+
+#include <cstring>
+
wd177x_format::wd177x_format(const format *_formats)
{
diff --git a/src/lib/formats/x07_cas.cpp b/src/lib/formats/x07_cas.cpp
index 182a1303cd8..71e8b304efc 100644
--- a/src/lib/formats/x07_cas.cpp
+++ b/src/lib/formats/x07_cas.cpp
@@ -8,8 +8,6 @@
#include "x07_cas.h"
-#include <cassert>
-
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
diff --git a/src/lib/formats/x1_tap.cpp b/src/lib/formats/x1_tap.cpp
index cbd261f6610..d4fb5db50ae 100644
--- a/src/lib/formats/x1_tap.cpp
+++ b/src/lib/formats/x1_tap.cpp
@@ -21,8 +21,9 @@
*
*/
#include "x1_tap.h"
+#include "imageutl.h"
-#include <cassert>
+#include <cstring>
#define WAVE_HIGH 0x5a9e
diff --git a/src/lib/formats/xdf_dsk.cpp b/src/lib/formats/xdf_dsk.cpp
index 698b8799abc..585d81f4570 100644
--- a/src/lib/formats/xdf_dsk.cpp
+++ b/src/lib/formats/xdf_dsk.cpp
@@ -8,8 +8,6 @@
*********************************************************************/
-#include <cassert>
-
#include "formats/xdf_dsk.h"
xdf_format::xdf_format() : upd765_format(formats)
diff --git a/src/lib/formats/zx81_p.cpp b/src/lib/formats/zx81_p.cpp
index 186815507fe..e31b5f58933 100644
--- a/src/lib/formats/zx81_p.cpp
+++ b/src/lib/formats/zx81_p.cpp
@@ -34,8 +34,6 @@ medium transfer rate is approx. 307 bps (38 bytes/sec) for files that contain
#include "zx81_p.h"
#include "tzx_cas.h"
-#include <cassert>
-
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767
diff --git a/src/lib/util/utilfwd.h b/src/lib/util/utilfwd.h
index fefe0631c68..9cd11f565b1 100644
--- a/src/lib/util/utilfwd.h
+++ b/src/lib/util/utilfwd.h
@@ -28,6 +28,10 @@ class random_read;
class random_write;
class random_read_write;
+// opresolv.h
+class option_guide;
+class option_resolution;
+
// unzip.h
class archive_file;
diff --git a/src/mame/machine/psion_pack.cpp b/src/mame/machine/psion_pack.cpp
index 9953a711a5a..09c523e09e5 100644
--- a/src/mame/machine/psion_pack.cpp
+++ b/src/mame/machine/psion_pack.cpp
@@ -23,6 +23,8 @@
#include "emu.h"
#include "psion_pack.h"
+#include "opresolv.h"
+
// Datapack control lines
#define DP_LINE_CLOCK 0x01
#define DP_LINE_RESET 0x02
diff --git a/src/tools/castool.cpp b/src/tools/castool.cpp
index 896c0bde5c2..b5fa9cf7d39 100644
--- a/src/tools/castool.cpp
+++ b/src/tools/castool.cpp
@@ -54,6 +54,7 @@
#include "corestr.h"
#include "ioprocs.h"
+#include "osdcomm.h"
#include <cassert>
#include <cctype>
diff --git a/src/tools/imgtool/charconv.cpp b/src/tools/imgtool/charconv.cpp
index 5bdd1c6bb35..3ff6de62081 100644
--- a/src/tools/imgtool/charconv.cpp
+++ b/src/tools/imgtool/charconv.cpp
@@ -11,7 +11,8 @@
#include "charconv.h"
#include "corestr.h"
-#include "coretmpl.h"
+
+#include <algorithm>
imgtool::simple_charconverter imgtool::charconverter_iso_8859_1(nullptr, nullptr);
diff --git a/src/tools/imgtool/filtbas.cpp b/src/tools/imgtool/filtbas.cpp
index 49dfeb57ddd..acd11a77d3a 100644
--- a/src/tools/imgtool/filtbas.cpp
+++ b/src/tools/imgtool/filtbas.cpp
@@ -23,6 +23,8 @@
#include <cctype>
#include "imgtool.h"
+#include "filter.h"
+
#include "formats/imageutl.h"
diff --git a/src/tools/imgtool/filteoln.cpp b/src/tools/imgtool/filteoln.cpp
index 5a4c2f873a3..6d80e9b2180 100644
--- a/src/tools/imgtool/filteoln.cpp
+++ b/src/tools/imgtool/filteoln.cpp
@@ -8,9 +8,10 @@
*****************************************************************************/
-#include <cstring>
-
#include "imgtool.h"
+#include "filter.h"
+
+#include <cstring>
#define EOLN (CRLF == 1 ? "\r" : (CRLF == 2 ? "\n" : (CRLF == 3 ? "\r\n" : NULL)))
diff --git a/src/tools/imgtool/filter.cpp b/src/tools/imgtool/filter.cpp
index df9c6ea28ac..647ab151471 100644
--- a/src/tools/imgtool/filter.cpp
+++ b/src/tools/imgtool/filter.cpp
@@ -8,9 +8,9 @@
***************************************************************************/
-#include <cstring>
+#include "filter.h"
-#include "imgtool.h"
+#include <cstring>
/* ----------------------------------------------------------------------- */
diff --git a/src/tools/imgtool/filter.h b/src/tools/imgtool/filter.h
index e46d3781262..75c131906d0 100644
--- a/src/tools/imgtool/filter.h
+++ b/src/tools/imgtool/filter.h
@@ -11,9 +11,6 @@
#ifndef FILTER_H
#define FILTER_H
-#include <cstdlib>
-#include <cstdio>
-
#include "library.h"
struct imgtool_filter;
diff --git a/src/tools/imgtool/formats/coco_dsk.cpp b/src/tools/imgtool/formats/coco_dsk.cpp
index 4e5bc4aa7c6..33363b2245e 100644
--- a/src/tools/imgtool/formats/coco_dsk.cpp
+++ b/src/tools/imgtool/formats/coco_dsk.cpp
@@ -15,7 +15,7 @@
#include "formats/coco_dsk.h"
#include "formats/basicdsk.h"
#include "formats/imageutl.h"
-#include "coretmpl.h"
+#include "opresolv.h"
#include <algorithm>
/* -----------------------------------------------------------------------
diff --git a/src/tools/imgtool/formats/coco_dsk.h b/src/tools/imgtool/formats/coco_dsk.h
index 797911d40a1..bf9bccc5621 100644
--- a/src/tools/imgtool/formats/coco_dsk.h
+++ b/src/tools/imgtool/formats/coco_dsk.h
@@ -11,7 +11,7 @@
#ifndef COCO_DSK_H
#define COCO_DSK_H
-#include "formats/flopimg.h"
+#include "formats/flopimg_legacy.h"
/**************************************************************************/
diff --git a/src/tools/imgtool/formats/pc_dsk_legacy.cpp b/src/tools/imgtool/formats/pc_dsk_legacy.cpp
index 10bf22153f5..771f0de8638 100644
--- a/src/tools/imgtool/formats/pc_dsk_legacy.cpp
+++ b/src/tools/imgtool/formats/pc_dsk_legacy.cpp
@@ -11,6 +11,8 @@
#include "formats/pc_dsk_legacy.h"
#include "formats/basicdsk.h"
+#include "opresolv.h"
+
struct pc_disk_sizes
{
uint32_t image_size;
diff --git a/src/tools/imgtool/formats/pc_dsk_legacy.h b/src/tools/imgtool/formats/pc_dsk_legacy.h
index 86fbc7a2546..14cb33f389d 100644
--- a/src/tools/imgtool/formats/pc_dsk_legacy.h
+++ b/src/tools/imgtool/formats/pc_dsk_legacy.h
@@ -11,7 +11,7 @@
#ifndef PC_DSK_LEGACY_H
#define PC_DSK_LEGACY_H
-#include "formats/flopimg.h"
+#include "formats/flopimg_legacy.h"
/**************************************************************************/
diff --git a/src/tools/imgtool/formats/vt_dsk_legacy.cpp b/src/tools/imgtool/formats/vt_dsk_legacy.cpp
index 0d68db7cb33..6cf57856574 100644
--- a/src/tools/imgtool/formats/vt_dsk_legacy.cpp
+++ b/src/tools/imgtool/formats/vt_dsk_legacy.cpp
@@ -8,12 +8,13 @@
*********************************************************************/
-#include <cstdio>
-#include <cstring>
-#include <cassert>
#include "formats/vt_dsk_legacy.h"
#include "formats/basicdsk.h"
+#include "opresolv.h"
+
+#include <cstring>
+
static FLOPPY_IDENTIFY(vz_identify)
{
uint64_t size = floppy_image_size(floppy);
diff --git a/src/tools/imgtool/formats/vt_dsk_legacy.h b/src/tools/imgtool/formats/vt_dsk_legacy.h
index 3f31b107f4e..fe8f0ddf6a3 100644
--- a/src/tools/imgtool/formats/vt_dsk_legacy.h
+++ b/src/tools/imgtool/formats/vt_dsk_legacy.h
@@ -11,7 +11,7 @@
#ifndef VT_DSK_LEGACY_H
#define VT_DSK_LEGACY_H
-#include "formats/flopimg.h"
+#include "formats/flopimg_legacy.h"
LEGACY_FLOPPY_OPTIONS_EXTERN(vz);
diff --git a/src/tools/imgtool/iflopimg.cpp b/src/tools/imgtool/iflopimg.cpp
index 951b75978e8..2d785c92a0d 100644
--- a/src/tools/imgtool/iflopimg.cpp
+++ b/src/tools/imgtool/iflopimg.cpp
@@ -13,10 +13,10 @@
#include "imgtool.h"
#include "library.h"
-#include "formats/flopimg.h"
-
#include "ioprocs.h"
+#include <cstdio>
+
imgtoolerr_t imgtool_floppy_error(floperr_t err)
{
@@ -231,7 +231,7 @@ static void imgtool_floppy_get_info(const imgtool_class *imgclass, uint32_t stat
case IMGTOOLINFO_PTR_OPEN: info->open = imgtool_floppy_open; break;
case IMGTOOLINFO_PTR_CREATE: info->create = imgtool_floppy_create; break;
case IMGTOOLINFO_PTR_CLOSE: info->close = imgtool_floppy_close; break;
- case IMGTOOLINFO_PTR_CREATEIMAGE_OPTGUIDE: info->createimage_optguide = format->param_guidelines ? &floppy_option_guide : nullptr; break;
+ case IMGTOOLINFO_PTR_CREATEIMAGE_OPTGUIDE: info->createimage_optguide = format->param_guidelines ? &floppy_option_guide() : nullptr; break;
case IMGTOOLINFO_PTR_READ_SECTOR: info->read_sector = imgtool_floppy_read_sector; break;
case IMGTOOLINFO_PTR_WRITE_SECTOR: info->write_sector = imgtool_floppy_write_sector; break;
diff --git a/src/tools/imgtool/iflopimg.h b/src/tools/imgtool/iflopimg.h
index d27ba952e16..43bbb1ecda3 100644
--- a/src/tools/imgtool/iflopimg.h
+++ b/src/tools/imgtool/iflopimg.h
@@ -14,7 +14,7 @@
#include "library.h"
-#include "formats/flopimg.h"
+#include "formats/flopimg_legacy.h"
/***************************************************************************
diff --git a/src/tools/imgtool/imghd.cpp b/src/tools/imgtool/imghd.cpp
index 8e077295b93..09a694cd544 100644
--- a/src/tools/imgtool/imghd.cpp
+++ b/src/tools/imgtool/imghd.cpp
@@ -10,8 +10,11 @@
*/
#include "imghd.h"
-#include "imgtool.h"
+#include "library.h"
+#include "stream.h"
+
#include "harddisk.h"
+#include "opresolv.h"
static imgtoolerr_t map_chd_error(std::error_condition chderr)
diff --git a/src/tools/imgtool/imghd.h b/src/tools/imgtool/imghd.h
index 0eadc6e2eb3..0f96603a502 100644
--- a/src/tools/imgtool/imghd.h
+++ b/src/tools/imgtool/imghd.h
@@ -11,11 +11,16 @@
#ifndef IMGHD_H
#define IMGHD_H
-#include "stream.h"
+#include "imgterrs.h"
#include "harddisk.h"
+namespace imgtool
+{
+ class stream;
+}
+
struct mess_hard_disk_file
{
imgtool::stream *stream;
diff --git a/src/tools/imgtool/imgterrs.cpp b/src/tools/imgtool/imgterrs.cpp
index 863e61e2d3e..9018ed79170 100644
--- a/src/tools/imgtool/imgterrs.cpp
+++ b/src/tools/imgtool/imgterrs.cpp
@@ -8,8 +8,9 @@
***************************************************************************/
-#include "imgtool.h"
#include "imgterrs.h"
+
+#include <cassert>
#include <iterator>
static const char *const msgs[] =
diff --git a/src/tools/imgtool/imgtool.cpp b/src/tools/imgtool/imgtool.cpp
index ce4dd22d186..c407b5576f5 100644
--- a/src/tools/imgtool/imgtool.cpp
+++ b/src/tools/imgtool/imgtool.cpp
@@ -9,13 +9,18 @@
***************************************************************************/
#include "imgtool.h"
+#include "charconv.h"
+#include "filter.h"
#include "library.h"
#include "modules.h"
#include "formats/imageutl.h"
#include "corefile.h"
+#include "corestr.h"
+#include "opresolv.h"
+#include <cstdio>
#include <cstring>
#include <cctype>
#include <iostream>
diff --git a/src/tools/imgtool/imgtool.h b/src/tools/imgtool/imgtool.h
index c7b59aafeee..4a66d7f249d 100644
--- a/src/tools/imgtool/imgtool.h
+++ b/src/tools/imgtool/imgtool.h
@@ -11,18 +11,15 @@
#ifndef IMGTOOL_H
#define IMGTOOL_H
-#include <cstdlib>
-#include <cstdio>
-#include <cassert>
-#include <functional>
-
-#include "corestr.h"
-#include "formats/flopimg.h"
-#include "opresolv.h"
#include "library.h"
-#include "filter.h"
+#include "stream.h"
+
#include "osdcomm.h"
+#include <cassert>
+#include <cstdlib>
+#include <functional>
+
/* ----------------------------------------------------------------------- */
#define EOLN_CR "\x0d"
diff --git a/src/tools/imgtool/library.cpp b/src/tools/imgtool/library.cpp
index 48d440ec701..f53db6fd4a7 100644
--- a/src/tools/imgtool/library.cpp
+++ b/src/tools/imgtool/library.cpp
@@ -9,12 +9,13 @@
****************************************************************************/
-#include <cstring>
-#include <algorithm>
-
-#include "imgtool.h"
#include "library.h"
+#include "corestr.h"
+
+#include <algorithm>
+#include <cstring>
+
namespace imgtool {
datetime::imgtool_clock::duration datetime::s_gmt_offset = datetime::calculate_gmt_offset();
@@ -179,8 +180,8 @@ void library::add_class(const imgtool_class *imgclass)
module->tracks_are_called_cylinders = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_TRACKS_ARE_CALLED_CYLINDERS) ? true : false;
module->writing_untested = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_WRITING_UNTESTED) ? true : false;
module->creation_untested = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_CREATION_UNTESTED) ? true : false;
- module->open = (imgtoolerr_t (*)(imgtool::image &, imgtool::stream::ptr &&)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_OPEN);
- module->create = (imgtoolerr_t (*)(imgtool::image &, imgtool::stream::ptr &&, util::option_resolution *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CREATE);
+ module->open = (imgtoolerr_t (*)(imgtool::image &, std::unique_ptr<imgtool::stream> &&)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_OPEN);
+ module->create = (imgtoolerr_t (*)(imgtool::image &, std::unique_ptr<imgtool::stream> &&, util::option_resolution *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CREATE);
module->close = (void (*)(imgtool::image &)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CLOSE);
module->info = (void (*)(imgtool::image &, std::ostream &)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_INFO);
module->read_sector = (imgtoolerr_t (*)(imgtool::image &, uint32_t, uint32_t, uint32_t, std::vector<uint8_t> &)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_READ_SECTOR);
diff --git a/src/tools/imgtool/library.h b/src/tools/imgtool/library.h
index f0e0532e502..a7463ec55a8 100644
--- a/src/tools/imgtool/library.h
+++ b/src/tools/imgtool/library.h
@@ -17,17 +17,15 @@
#pragma once
-#include "charconv.h"
-#include "stream.h"
+#include "imgterrs.h"
-#include "corestr.h"
-#include "opresolv.h"
#include "timeconv.h"
-#include "unicode.h"
+#include "utilfwd.h"
#include <chrono>
#include <ctime>
#include <list>
+#include <memory>
namespace imgtool
@@ -35,6 +33,8 @@ namespace imgtool
class image;
class partition;
class directory;
+ class charconverter;
+ class stream;
};
enum imgtool_suggestion_viability_t
@@ -382,9 +382,9 @@ union imgtoolinfo
void * f; /* generic function pointers */
char * s; /* generic strings */
- imgtoolerr_t (*open) (imgtool::image &image, imgtool::stream::ptr &&stream);
+ imgtoolerr_t (*open) (imgtool::image &image, std::unique_ptr<imgtool::stream> &&stream);
void (*close) (imgtool::image &image);
- imgtoolerr_t (*create) (imgtool::image &image, imgtool::stream::ptr &&stream, util::option_resolution *opts);
+ imgtoolerr_t (*create) (imgtool::image &image, std::unique_ptr<imgtool::stream> &&stream, util::option_resolution *opts);
imgtoolerr_t (*create_partition) (imgtool::image &image, uint64_t first_block, uint64_t block_count);
void (*info) (imgtool::image &image, std::ostream &stream);
imgtoolerr_t (*begin_enum) (imgtool::directory &enumeration, const char *path);
@@ -476,10 +476,10 @@ struct imgtool_module
bool writing_untested = false; /* used when we support writing, but not in main build */
bool creation_untested = false; /* used when we support creation, but not in main build */
- imgtoolerr_t (*open) (imgtool::image &image, imgtool::stream::ptr &&stream) = nullptr;
+ imgtoolerr_t (*open) (imgtool::image &image, std::unique_ptr<imgtool::stream> &&stream) = nullptr;
void (*close) (imgtool::image &image) = nullptr;
void (*info) (imgtool::image &image, std::ostream &stream) = nullptr;
- imgtoolerr_t (*create) (imgtool::image &image, imgtool::stream::ptr &&stream, util::option_resolution *opts) = nullptr;
+ imgtoolerr_t (*create) (imgtool::image &image, std::unique_ptr<imgtool::stream> &&stream, util::option_resolution *opts) = nullptr;
imgtoolerr_t (*get_geometry) (imgtool::image &image, uint32_t *track, uint32_t *heads, uint32_t *sectors) = nullptr;
imgtoolerr_t (*read_sector) (imgtool::image &image, uint32_t track, uint32_t head, uint32_t sector, std::vector<uint8_t> &buffer) = nullptr;
imgtoolerr_t (*write_sector) (imgtool::image &image, uint32_t track, uint32_t head, uint32_t sector, const void *buffer, size_t len) = nullptr;
diff --git a/src/tools/imgtool/main.cpp b/src/tools/imgtool/main.cpp
index 77b3d8c6874..d8a166e247f 100644
--- a/src/tools/imgtool/main.cpp
+++ b/src/tools/imgtool/main.cpp
@@ -9,11 +9,17 @@
***************************************************************************/
#include "imgtool.h"
+#include "filter.h"
#include "main.h"
#include "modules.h"
#include "corefile.h"
+#include "corestr.h"
+#include "opresolv.h"
#include "strformat.h"
+#include "unicode.h"
+
+#include "osdcore.h" // osd_get_command_line
#include <cstdio>
#include <cstring>
diff --git a/src/tools/imgtool/modules.cpp b/src/tools/imgtool/modules.cpp
index 2ccd369976a..de1595c1a79 100644
--- a/src/tools/imgtool/modules.cpp
+++ b/src/tools/imgtool/modules.cpp
@@ -8,7 +8,6 @@
***************************************************************************/
-#include "imgtool.h"
#include "modules.h"
#ifndef MODULES_RECURSIVE
diff --git a/src/tools/imgtool/modules/amiga.cpp b/src/tools/imgtool/modules/amiga.cpp
index b4f005cb6f5..aa5cc26c68e 100644
--- a/src/tools/imgtool/modules/amiga.cpp
+++ b/src/tools/imgtool/modules/amiga.cpp
@@ -13,14 +13,17 @@
Includes
*****************************************************************************/
-
-#include <ctime>
-#include <cstring>
-#include <cctype>
-
#include "imgtool.h"
+#include "charconv.h"
#include "iflopimg.h"
+
#include "formats/imageutl.h"
+#include "corestr.h"
+#include "opresolv.h"
+
+#include <cctype>
+#include <cstring>
+#include <ctime>
diff --git a/src/tools/imgtool/modules/bml3.cpp b/src/tools/imgtool/modules/bml3.cpp
index 579a1e6d137..ecb33c0a2e8 100644
--- a/src/tools/imgtool/modules/bml3.cpp
+++ b/src/tools/imgtool/modules/bml3.cpp
@@ -18,12 +18,17 @@
- (used with MP-1802 floppy disk controller card)
*/
-#include <cstdio>
-#include <cstring>
-#include <cstdlib>
#include "imgtool.h"
+#include "filter.h"
#include "iflopimg.h"
+#include "corestr.h"
+#include "opresolv.h"
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
#define MAX_SECTOR_SIZE 256
struct bml3_diskinfo
diff --git a/src/tools/imgtool/modules/concept.cpp b/src/tools/imgtool/modules/concept.cpp
index 71417b5aafb..7bfa7b4d269 100644
--- a/src/tools/imgtool/modules/concept.cpp
+++ b/src/tools/imgtool/modules/concept.cpp
@@ -8,11 +8,14 @@
Raphael Nabet, 2003
*/
+#include "imgtool.h"
+
+#include "opresolv.h"
+
+#include <climits>
#include <cstdio>
-#include <cstring>
#include <cstdlib>
-#include <climits>
-#include "imgtool.h"
+#include <cstring>
struct UINT16xE
{
diff --git a/src/tools/imgtool/modules/cybiko.cpp b/src/tools/imgtool/modules/cybiko.cpp
index 1b9f43ee298..f508e423ad5 100644
--- a/src/tools/imgtool/modules/cybiko.cpp
+++ b/src/tools/imgtool/modules/cybiko.cpp
@@ -10,6 +10,8 @@
#include "imgtool.h"
+#include "opresolv.h"
+
#include <zlib.h>
struct cybiko_file_system
diff --git a/src/tools/imgtool/modules/dgndos.cpp b/src/tools/imgtool/modules/dgndos.cpp
index 9542cc648c6..13fbbfc55ef 100644
--- a/src/tools/imgtool/modules/dgndos.cpp
+++ b/src/tools/imgtool/modules/dgndos.cpp
@@ -10,13 +10,18 @@
****************************************************************************/
-#include <cstdio>
-#include <cstring>
-#include <cstdlib>
#include "imgtool.h"
-#include "formats/coco_dsk.h"
+#include "filter.h"
#include "iflopimg.h"
+#include "formats/coco_dsk.h"
+#include "corestr.h"
+#include "opresolv.h"
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
#ifdef _MSC_VER
#pragma pack(push,1)
#define A_PACKED
diff --git a/src/tools/imgtool/modules/fat.cpp b/src/tools/imgtool/modules/fat.cpp
index dba4b7cc03e..3b5b670f606 100644
--- a/src/tools/imgtool/modules/fat.cpp
+++ b/src/tools/imgtool/modules/fat.cpp
@@ -134,12 +134,16 @@
****************************************************************************/
-#include <ctime>
-#include <cctype>
-#include "imgtool.h"
+#include "fat.h"
+
#include "formats/imageutl.h"
+
+#include "corestr.h"
#include "unicode.h"
-#include "fat.h"
+
+#include <cctype>
+#include <cstdio>
+#include <ctime>
#define FAT_DIRENT_SIZE 32
#define FAT_SECLEN 512
diff --git a/src/tools/imgtool/modules/fat.h b/src/tools/imgtool/modules/fat.h
index 77c56f5f9f1..8e7c60d89af 100644
--- a/src/tools/imgtool/modules/fat.h
+++ b/src/tools/imgtool/modules/fat.h
@@ -1,3 +1,6 @@
// license:BSD-3-Clause
// copyright-holders:Raphael Nabet
+
+#include "imgtool.h"
+
void fat_get_info(const imgtool_class *imgclass, uint32_t state, union imgtoolinfo *info);
diff --git a/src/tools/imgtool/modules/hp48.cpp b/src/tools/imgtool/modules/hp48.cpp
index 4d237f3c470..4a008adaeb5 100644
--- a/src/tools/imgtool/modules/hp48.cpp
+++ b/src/tools/imgtool/modules/hp48.cpp
@@ -86,6 +86,8 @@
#include "imgtool.h"
+#include "opresolv.h"
+
/*****************************************************************************
diff --git a/src/tools/imgtool/modules/hp85_tape.cpp b/src/tools/imgtool/modules/hp85_tape.cpp
index fa32042efd3..14103fc3975 100644
--- a/src/tools/imgtool/modules/hp85_tape.cpp
+++ b/src/tools/imgtool/modules/hp85_tape.cpp
@@ -13,7 +13,9 @@
#include "formats/imageutl.h"
#include "ioprocs.h"
+#include "opresolv.h"
+#include <cstdio>
#include <iostream>
diff --git a/src/tools/imgtool/modules/hp9845_tape.cpp b/src/tools/imgtool/modules/hp9845_tape.cpp
index a1ae0377180..5254c26b9d4 100644
--- a/src/tools/imgtool/modules/hp9845_tape.cpp
+++ b/src/tools/imgtool/modules/hp9845_tape.cpp
@@ -109,14 +109,17 @@
*********************************************************************/
#include "imgtool.h"
+#include "filter.h"
#include "formats/hti_tape.h"
#include "formats/imageutl.h"
#include "corefile.h"
#include "ioprocs.h"
+#include "opresolv.h"
#include <bitset>
+#include <cstdio>
// Constants
diff --git a/src/tools/imgtool/modules/mac.cpp b/src/tools/imgtool/modules/mac.cpp
index b6f0c076f37..a6eadf45d9e 100644
--- a/src/tools/imgtool/modules/mac.cpp
+++ b/src/tools/imgtool/modules/mac.cpp
@@ -89,17 +89,21 @@
*****************************************************************************/
-#include <cctype>
-#include <cstring>
-#include <ctime>
-#include <climits>
-#include <cstddef>
-
-#include "formats/imageutl.h"
#include "imgtool.h"
-#include "macutil.h"
+#include "charconv.h"
#include "iflopimg.h"
+
+#include "macutil.h"
+
#include "formats/ap_dsk35.h"
+#include "formats/imageutl.h"
+#include "opresolv.h"
+
+#include <cctype>
+#include <climits>
+#include <cstddef>
+#include <cstring>
+#include <ctime>
/* if 1, check consistency of B-Tree (most of the checks will eventually be
suppressed when the image is opened as read-only and only enabled when
diff --git a/src/tools/imgtool/modules/macbin.cpp b/src/tools/imgtool/modules/macbin.cpp
index 29fa90f9e59..b75ea3d0225 100644
--- a/src/tools/imgtool/modules/macbin.cpp
+++ b/src/tools/imgtool/modules/macbin.cpp
@@ -46,12 +46,15 @@
*****************************************************************************/
-#include <cstring>
-
#include "imgtool.h"
-#include "formats/imageutl.h"
+#include "filter.h"
+
#include "macutil.h"
+#include "formats/imageutl.h"
+
+#include <cstring>
+
static uint32_t pad128(uint32_t length)
diff --git a/src/tools/imgtool/modules/macutil.cpp b/src/tools/imgtool/modules/macutil.cpp
index 08c8b84989f..18385554773 100644
--- a/src/tools/imgtool/modules/macutil.cpp
+++ b/src/tools/imgtool/modules/macutil.cpp
@@ -10,6 +10,8 @@
*****************************************************************************/
#include "macutil.h"
+#include "filter.h"
+
#include "timeconv.h"
diff --git a/src/tools/imgtool/modules/macutil.h b/src/tools/imgtool/modules/macutil.h
index 0ab3315874b..ce364f6bc7f 100644
--- a/src/tools/imgtool/modules/macutil.h
+++ b/src/tools/imgtool/modules/macutil.h
@@ -12,7 +12,7 @@
#ifndef MACUTIL_H
#define MACUTIL_H
-#include "imgtool.h"
+#include "library.h"
enum mac_fork_t
{
diff --git a/src/tools/imgtool/modules/os9.cpp b/src/tools/imgtool/modules/os9.cpp
index 8c9f24959ce..104e48bd0f0 100644
--- a/src/tools/imgtool/modules/os9.cpp
+++ b/src/tools/imgtool/modules/os9.cpp
@@ -8,12 +8,15 @@
****************************************************************************/
-#include <ctime>
-
#include "imgtool.h"
+#include "iflopimg.h"
+
#include "formats/imageutl.h"
#include "formats/coco_dsk.h"
-#include "iflopimg.h"
+#include "opresolv.h"
+
+#include <cstdio>
+#include <ctime>
enum creation_policy_t
{
diff --git a/src/tools/imgtool/modules/pc_flop.cpp b/src/tools/imgtool/modules/pc_flop.cpp
index ea2a8f8abe0..fd08b8ed3c7 100644
--- a/src/tools/imgtool/modules/pc_flop.cpp
+++ b/src/tools/imgtool/modules/pc_flop.cpp
@@ -9,11 +9,14 @@
****************************************************************************/
#include "imgtool.h"
-#include "formats/imageutl.h"
-#include "formats/pc_dsk_legacy.h"
#include "fat.h"
#include "iflopimg.h"
+#include "formats/imageutl.h"
+#include "formats/pc_dsk_legacy.h"
+
+#include "opresolv.h"
+
#define FAT_SECLEN 512
diff --git a/src/tools/imgtool/modules/pc_hard.cpp b/src/tools/imgtool/modules/pc_hard.cpp
index 57e88d6c2a4..c65db873e25 100644
--- a/src/tools/imgtool/modules/pc_hard.cpp
+++ b/src/tools/imgtool/modules/pc_hard.cpp
@@ -53,6 +53,8 @@
#include "formats/imageutl.h"
#include "imghd.h"
+#include "opresolv.h"
+
#define FAT_SECLEN 512
OPTION_GUIDE_START( pc_chd_create_optionguide )
diff --git a/src/tools/imgtool/modules/prodos.cpp b/src/tools/imgtool/modules/prodos.cpp
index 2bce71da781..e196d53b491 100644
--- a/src/tools/imgtool/modules/prodos.cpp
+++ b/src/tools/imgtool/modules/prodos.cpp
@@ -128,8 +128,11 @@
#include "formats/ap2_dsk.h"
#include "formats/ap_dsk35.h"
#include "iflopimg.h"
+
#include "macutil.h"
+#include "opresolv.h"
+
#define ROOTDIR_BLOCK 2
#define BLOCK_SIZE 512
diff --git a/src/tools/imgtool/modules/psion.cpp b/src/tools/imgtool/modules/psion.cpp
index 82a78388e11..007650084b6 100644
--- a/src/tools/imgtool/modules/psion.cpp
+++ b/src/tools/imgtool/modules/psion.cpp
@@ -24,6 +24,10 @@
#include "imgtool.h"
+#include "opresolv.h"
+
+#include <cstdio>
+
#define MAXFILES 256
struct psion_file
diff --git a/src/tools/imgtool/modules/rsdos.cpp b/src/tools/imgtool/modules/rsdos.cpp
index f1ae197c03b..09b8131fa30 100644
--- a/src/tools/imgtool/modules/rsdos.cpp
+++ b/src/tools/imgtool/modules/rsdos.cpp
@@ -8,13 +8,18 @@
****************************************************************************/
-#include <cstdio>
-#include <cstring>
-#include <cstdlib>
#include "imgtool.h"
-#include "formats/coco_dsk.h"
+#include "filter.h"
#include "iflopimg.h"
+#include "formats/coco_dsk.h"
+#include "corestr.h"
+#include "opresolv.h"
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
/* this structure mirrors the structure of an RS-DOS directory entry on disk */
struct rsdos_dirent
{
diff --git a/src/tools/imgtool/modules/thomson.cpp b/src/tools/imgtool/modules/thomson.cpp
index 131fd422c17..be584bde240 100644
--- a/src/tools/imgtool/modules/thomson.cpp
+++ b/src/tools/imgtool/modules/thomson.cpp
@@ -112,9 +112,14 @@
*/
#include "imgtool.h"
+#include "filter.h"
#include "iflopimg.h"
+
#include "formats/imageutl.h"
+#include "corestr.h"
+#include "opresolv.h"
+#include <cstdio>
#include <ctime>
diff --git a/src/tools/imgtool/modules/ti99.cpp b/src/tools/imgtool/modules/ti99.cpp
index bc1968976d0..37367a82bf9 100644
--- a/src/tools/imgtool/modules/ti99.cpp
+++ b/src/tools/imgtool/modules/ti99.cpp
@@ -18,14 +18,17 @@
- check allocation bitmap against corruption when an image is opened
*/
+#include "imgtool.h"
+#include "harddisk.h"
+#include "imghd.h"
+
+#include "opresolv.h"
+
#include <climits>
#include <cstdio>
-#include <cstring>
#include <cstdlib>
+#include <cstring>
#include <ctime>
-#include "imgtool.h"
-#include "harddisk.h"
-#include "imghd.h"
/*
Concepts shared by both disk structures:
diff --git a/src/tools/imgtool/modules/ti990hd.cpp b/src/tools/imgtool/modules/ti990hd.cpp
index 7bf610b3260..ed1be9c61c5 100644
--- a/src/tools/imgtool/modules/ti990hd.cpp
+++ b/src/tools/imgtool/modules/ti990hd.cpp
@@ -8,11 +8,14 @@
Raphael Nabet, 2003
*/
+#include "imgtool.h"
+
+#include "opresolv.h"
+
+#include <climits>
#include <cstdio>
-#include <cstring>
#include <cstdlib>
-#include <climits>
-#include "imgtool.h"
+#include <cstring>
/* Max sector length is bytes. Generally 256, except for a few older disk
units which use 288-byte-long sectors, and SCSI units which generally use
diff --git a/src/tools/imgtool/modules/vzdos.cpp b/src/tools/imgtool/modules/vzdos.cpp
index 135df100119..5a4c7f2f122 100644
--- a/src/tools/imgtool/modules/vzdos.cpp
+++ b/src/tools/imgtool/modules/vzdos.cpp
@@ -8,15 +8,21 @@
****************************************************************************/
-#include <cstdio>
-#include <cstring>
-#include <cstdlib>
-#include <cmath>
#include "imgtool.h"
-#include "formats/imageutl.h"
-#include "formats/vt_dsk_legacy.h"
+#include "filter.h"
#include "iflopimg.h"
+#include "formats/vt_dsk_legacy.h"
+
+#include "formats/imageutl.h"
+#include "corestr.h"
+#include "opresolv.h"
+
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
/*
sector format
diff --git a/src/tools/imgtool/stream.h b/src/tools/imgtool/stream.h
index e7cfca9e425..36872e33c2a 100644
--- a/src/tools/imgtool/stream.h
+++ b/src/tools/imgtool/stream.h
@@ -12,8 +12,6 @@
#pragma once
-#include "imgterrs.h"
-
#include "utilfwd.h"
#include "osdcomm.h"