summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/imagedev
diff options
context:
space:
mode:
author Miƫtek Bak <mietek@bak.io>2023-09-14 02:27:47 +0200
committer GitHub <noreply@github.com>2023-09-14 07:27:47 +0700
commit5353a8df14d88a378361902a6954ab4c5c1dc5bf (patch)
treefaeb581bddcf4367980e775ae63ca3540ecb73cd /src/devices/imagedev
parent86c6e83b4c2b8aca18db2565e72b03f90a25dda5 (diff)
nscsi: Add SCSI tape device based on SIMH tape image format (#11430)
Diffstat (limited to 'src/devices/imagedev')
-rw-r--r--src/devices/imagedev/simh_tape_image.cpp85
-rw-r--r--src/devices/imagedev/simh_tape_image.h52
2 files changed, 137 insertions, 0 deletions
diff --git a/src/devices/imagedev/simh_tape_image.cpp b/src/devices/imagedev/simh_tape_image.cpp
new file mode 100644
index 00000000000..fc85c75bac4
--- /dev/null
+++ b/src/devices/imagedev/simh_tape_image.cpp
@@ -0,0 +1,85 @@
+// license:BSD-3-Clause
+// copyright-holders:Mietek Bak
+
+#include "emu.h"
+
+#include "simh_tape_image.h"
+
+// #define VERBOSE LOG_GENERAL
+// #define LOG_OUTPUT_FUNC osd_printf_info
+#include "logmacro.h"
+
+DEFINE_DEVICE_TYPE(SIMH_TAPE_IMAGE, simh_tape_image_device, "simh_tape_image", "SIMH tape image");
+
+//////////////////////////////////////////////////////////////////////////////
+
+// construction
+
+simh_tape_image_device::simh_tape_image_device(const machine_config &config, device_type type, const char *tag, device_t *owner, u32 clock)
+ : microtape_image_device(config, type, tag, owner, clock)
+ , m_file()
+ , m_interface(nullptr)
+{
+}
+
+simh_tape_image_device::simh_tape_image_device(const machine_config &config, const char *tag, device_t *owner, u32 clock)
+ : simh_tape_image_device(config, SIMH_TAPE_IMAGE, tag, owner, clock)
+{
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+// device_image_interface implementation
+
+std::pair<std::error_condition, std::string> simh_tape_image_device::call_load()
+{
+ LOG("simh_tape_image_device::call_load filename=%s\n", filename());
+ try {
+ m_file.reset(new simh_tape_file(image_core_file(), length(), is_readonly()));
+ }
+ catch (std::exception &e) { // error: loading tape failed
+ return std::make_pair(image_error::INTERNAL, std::string(e.what()));
+ }
+ return std::make_pair(std::error_condition(), std::string());
+}
+
+std::pair<std::error_condition, std::string> simh_tape_image_device::call_create(int format_type, util::option_resolution *format_options)
+{
+ LOG("simh_tape_image_device::call_create filename=%s format_type=%d\n", filename(), format_type);
+ try {
+ u64 file_size = 62914560; // we default to 60MB; TODO: allow specifying tape image size, once MAME supports it
+ m_file.reset(new simh_tape_file(image_core_file(), file_size, is_readonly(), true));
+ }
+ catch (std::exception &e) { // error: creating tape failed
+ return std::make_pair(image_error::INTERNAL, std::string(e.what()));
+ }
+ return std::make_pair(std::error_condition(), std::string());
+}
+
+void simh_tape_image_device::call_unload()
+{
+ LOG("simh_tape_image_device::call_unload\n");
+ m_file.reset();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+// device_t implementation
+
+void simh_tape_image_device::device_config_complete()
+{
+ LOG("simh_tape_image_device::device_config_complete\n");
+ add_format(image_brief_type_name(), image_type_name(), file_extensions(), ""); // TODO: not sure these strings are correct
+}
+
+void simh_tape_image_device::device_start()
+{
+ LOG("simh_tape_image_device::device_start\n");
+}
+
+void simh_tape_image_device::device_stop()
+{
+ LOG("simh_tape_image_device::device_stop\n");
+}
+
+//////////////////////////////////////////////////////////////////////////////
diff --git a/src/devices/imagedev/simh_tape_image.h b/src/devices/imagedev/simh_tape_image.h
new file mode 100644
index 00000000000..95f1c70b2e3
--- /dev/null
+++ b/src/devices/imagedev/simh_tape_image.h
@@ -0,0 +1,52 @@
+// license:BSD-3-Clause
+// copyright-holders:Mietek Bak
+
+#ifndef MAME_DEVICES_IMAGEDEV_SIMH_TAPE_IMAGE_H
+#define MAME_DEVICES_IMAGEDEV_SIMH_TAPE_IMAGE_H
+
+#pragma once
+
+#include "magtape.h"
+
+#include "util/simh_tape_file.h"
+
+DECLARE_DEVICE_TYPE(SIMH_TAPE_IMAGE, simh_tape_image_device);
+
+//////////////////////////////////////////////////////////////////////////////
+
+class simh_tape_image_device : public microtape_image_device
+{
+public:
+ // construction
+ simh_tape_image_device(const machine_config &config, const char *tag, device_t *owner, u32 clock = 0);
+
+ // device_image_interface implementation
+ virtual const char *image_interface() const noexcept override { return m_interface; }
+ virtual const char *file_extensions() const noexcept override { return "tap"; }
+ virtual const char *image_type_name() const noexcept override { return "tape"; }
+ virtual const char *image_brief_type_name() const noexcept override { return "tap"; }
+ virtual std::pair<std::error_condition, std::string> call_load() override;
+ virtual std::pair<std::error_condition, std::string> call_create(int format_type, util::option_resolution *format_options) override;
+ virtual void call_unload() override;
+
+ // miscellaneous
+ inline void set_interface(const char *interface) { m_interface = interface; }
+ inline simh_tape_file *get_file() const { return m_file.get(); }
+
+protected:
+ // construction
+ simh_tape_image_device(const machine_config &config, device_type type, const char *tag, device_t *owner, u32 clock);
+
+ // device_t implementation
+ virtual void device_config_complete() override;
+ virtual void device_start() override;
+ virtual void device_stop() override;
+
+ // state
+ std::unique_ptr<simh_tape_file> m_file; // tape image file
+ const char *m_interface; // image interface
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+#endif // MAME_DEVICES_IMAGEDEV_SIMH_TAPE_IMAGE_H