From 460278695e12e31c5de2bf0a1f5fd0ae1dd3c539 Mon Sep 17 00:00:00 2001 From: Nigel Barnes Date: Sat, 22 Jul 2023 16:39:01 +0100 Subject: machine/psion_ssd.cpp: Can now create new SSD, default to be 128K RAM. - Flash SSD's are write-protected, RAM SSD's are not. - RAM SSD's from softlist will write to nvram, non-softlist will write back to file. --- src/devices/machine/psion_ssd.cpp | 65 ++++++++++++++++++++++++++++++++------- src/devices/machine/psion_ssd.h | 3 +- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/devices/machine/psion_ssd.cpp b/src/devices/machine/psion_ssd.cpp index 8af3cd41876..3041ddacb70 100644 --- a/src/devices/machine/psion_ssd.cpp +++ b/src/devices/machine/psion_ssd.cpp @@ -158,15 +158,13 @@ TIMER_CALLBACK_MEMBER(psion_ssd_device::close_door) std::pair psion_ssd_device::call_load() { - device_image_interface *image = nullptr; - interface(image); - - uint32_t size = image->length(); + uint32_t const size = length(); if (size < 0x10000 || size > 0x800000 || (size & (size - 1)) != 0) return std::make_pair(image_error::INVALIDLENGTH, "Invalid size, must be 64K, 128K, 256K, 512K, 1M, 2M, 4M, 8M"); - image->fread(m_ssd_data.get(), size); + if (fread(m_ssd_data, size) != size) + return std::make_pair(std::errc::io_error, std::string()); // check for Flash header if ((m_ssd_data[0] | (m_ssd_data[1] << 8)) == 0xf1a5) // Flash @@ -174,6 +172,30 @@ std::pair psion_ssd_device::call_load() else set_info_byte(size, SSD_RAM); + if (loaded_through_softlist()) + battery_load(m_ssd_data.get(), size, nullptr); + + // open the door + m_door_cb(ASSERT_LINE); + + // setup the timer to close the door + m_door_timer->adjust(attotime::from_msec(200)); + + return std::make_pair(std::error_condition(), std::string()); +} + + +std::pair psion_ssd_device::call_create(int format_type, util::option_resolution *create_args) +{ + uint32_t const size = 0x20000; + + // 128k RAM Solid State Disk by default + set_info_byte(size, SSD_RAM); + + std::fill_n(m_ssd_data.get(), sizeof(m_ssd_data), 0); + + fwrite(m_ssd_data.get(), size); + // open the door m_door_cb(ASSERT_LINE); @@ -186,8 +208,32 @@ std::pair psion_ssd_device::call_load() void psion_ssd_device::call_unload() { - memset(m_ssd_data.get(), 0, sizeof(m_ssd_data)); + uint32_t const size = length(); + + if ((m_info_byte & 0xe0) == 0x00) // not write protected + { + if (!loaded_through_softlist()) + { + // write to original file + fseek(0, SEEK_SET); + fwrite(m_ssd_data.get(), size); + } + else + { + // write to nvram + battery_save(m_ssd_data.get(), size); + } + } + set_info_byte(0); + + std::fill_n(m_ssd_data.get(), sizeof(m_ssd_data), 0); + + // open the door + m_door_cb(ASSERT_LINE); + + // setup the timer to close the door + m_door_timer->adjust(attotime::from_msec(200)); } @@ -203,7 +249,7 @@ void psion_ssd_device::set_info_byte(uint32_t size, uint8_t type) // Type 1 Flash or RAM if (type != SSD_RAM) - m_info_byte |= 0x20; + m_info_byte |= 0xe0; // write protected // No. devices and size switch (size) @@ -218,9 +264,6 @@ void psion_ssd_device::set_info_byte(uint32_t size, uint8_t type) case 0x800000: m_info_byte |= 0x1f; m_mem_width = 21; break; // 8M (4 x 2M) } - // write protected - m_info_byte |= 0xe0; - // set pull-ups on ASIC5 m_asic5->set_info_byte(m_info_byte); } @@ -235,7 +278,7 @@ uint8_t psion_ssd_device::data_r() return 0x00; } -void psion_ssd_device::data_w(uint16_t data) +void psion_ssd_device::data_w(uint16_t data) { if (m_info_byte & 7) { diff --git a/src/devices/machine/psion_ssd.h b/src/devices/machine/psion_ssd.h index 3d994895dbe..7dd9cb777aa 100644 --- a/src/devices/machine/psion_ssd.h +++ b/src/devices/machine/psion_ssd.h @@ -30,7 +30,7 @@ public: auto door_cb() { return m_door_cb.bind(); } uint8_t data_r(); - void data_w(uint16_t data); + void data_w(uint16_t data); protected: // device_t implementation @@ -41,6 +41,7 @@ protected: // device_image_interface implementation virtual std::pair call_load() override; + virtual std::pair call_create(int format_type, util::option_resolution *create_args) override; virtual void call_unload() override; virtual bool is_reset_on_load() const noexcept override { return false; } -- cgit v1.2.3