From 80a4864a925ec6a77fa793d90c868d7610385eb7 Mon Sep 17 00:00:00 2001 From: dingusdev Date: Thu, 24 Feb 2022 07:33:30 -0700 Subject: [PATCH] Floppy disk write protection --- devices/floppy/superdrive.cpp | 4 ++-- devices/floppy/superdrive.h | 2 +- machines/machinefactory.cpp | 5 +++++ machines/machinegossamer.cpp | 3 ++- machines/machinepdm.cpp | 12 +++++++++++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/devices/floppy/superdrive.cpp b/devices/floppy/superdrive.cpp index a0d327f..a78083c 100644 --- a/devices/floppy/superdrive.cpp +++ b/devices/floppy/superdrive.cpp @@ -131,7 +131,7 @@ uint8_t MacSuperDrive::status(uint8_t addr) } } -int MacSuperDrive::insert_disk(std::string& img_path) +int MacSuperDrive::insert_disk(std::string& img_path, bool write_flag = 0) { if (this->has_disk) { LOG_F(ERROR, "Superdrive: drive is not empty!"); @@ -150,7 +150,7 @@ int MacSuperDrive::insert_disk(std::string& img_path) this->img_conv->get_raw_disk_data(this->disk_data.get()); // disk is write-enabled by default - this->wr_protect = 0; + this->wr_protect = write_flag; // everything is set up, let's say we got a disk this->has_disk = 1; diff --git a/devices/floppy/superdrive.h b/devices/floppy/superdrive.h index 86871f0..9394c93 100644 --- a/devices/floppy/superdrive.h +++ b/devices/floppy/superdrive.h @@ -86,7 +86,7 @@ public: void command(uint8_t addr, uint8_t value); uint8_t status(uint8_t addr); - int insert_disk(std::string& img_path); + int insert_disk(std::string& img_path, bool write_flag); double get_current_track_delay(); double get_sector_delay(); void init_track_search(int pos); diff --git a/machines/machinefactory.cpp b/machines/machinefactory.cpp index efd5736..d88ddd1 100644 --- a/machines/machinefactory.cpp +++ b/machines/machinefactory.cpp @@ -80,6 +80,8 @@ static const PropMap GossamerSettings = { new StrProperty("")}, {"fdd_img", new StrProperty("")}, + {"fdd_wr_prot", + new StrProperty("")}, }; /** Monitors supported by the PDM on-board video. */ @@ -99,6 +101,8 @@ static const PropMap PDMSettings = { new StrProperty("HiRes12-14in", PDMBuiltinMonitorIDs)}, {"fdd_img", new StrProperty("")}, + {"fdd_wr_prot", + new StrProperty("")}, }; static const map PropHelp = { @@ -107,6 +111,7 @@ static const map PropHelp = { {"rambank3_size", "specifies RAM bank 3 size in MB"}, {"gfxmem_size", "specifies video memory size in MB"}, {"fdd_img", "specifies path to floppy disk image"}, + {"fdd_wr_prot", "toggles floppy disks write protection"}, {"mon_id", "specifies which monitor to emulate"}, }; diff --git a/machines/machinegossamer.cpp b/machines/machinegossamer.cpp index ec3e1f6..bc5a2a3 100644 --- a/machines/machinegossamer.cpp +++ b/machines/machinegossamer.cpp @@ -110,7 +110,8 @@ int create_gossamer(std::string& id) { } /* check for a floppy image to be inserted into the virtual superdrive */ - std::string fdd_path = GET_STR_PROP("fdd_img"); + std::string fdd_path = GET_STR_PROP("fdd_img"); + std::string fd_write_prot = GET_STR_PROP("fdd_wr_prot"); if (!fdd_path.empty()) { open_floppy_image(fdd_path); } diff --git a/machines/machinepdm.cpp b/machines/machinepdm.cpp index 2818b00..8ac2dcd 100644 --- a/machines/machinepdm.cpp +++ b/machines/machinepdm.cpp @@ -99,12 +99,22 @@ int create_pdm(std::string& id) { // if a floppy image was given "insert" it into the virtual superdrive std::string fd_image_path = GET_STR_PROP("fdd_img"); + std::string fd_write_prot = GET_STR_PROP("fdd_wr_prot"); if (!fd_image_path.empty()) { using namespace MacSuperdrive; MacSuperDrive* fdd = dynamic_cast (gMachineObj->get_comp_by_name("Superdrive")); - fdd->insert_disk(fd_image_path); + + bool write_flag = false; + + if (!fd_write_prot.empty()) { + if (fd_write_prot.compare("on") == 0) { + write_flag = true; + } + } + + fdd->insert_disk(fd_image_path, write_flag); } LOG_F(INFO, "Initialization completed.\n");