From 2b17ce4f4042394fd19cd06f44b271a5d1e97e67 Mon Sep 17 00:00:00 2001 From: Michael Zapf Date: Sun, 14 Oct 2018 15:13:42 +0200 Subject: [PATCH] ti99: Added guards against selecting non-existing drives. --- src/devices/bus/ti99/peb/bwg.cpp | 41 ++++++++++++++++++----------- src/devices/bus/ti99/peb/ti_fdc.cpp | 11 +++++++- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/devices/bus/ti99/peb/bwg.cpp b/src/devices/bus/ti99/peb/bwg.cpp index 877485174f2..c7aa2c903b7 100644 --- a/src/devices/bus/ti99/peb/bwg.cpp +++ b/src/devices/bus/ti99/peb/bwg.cpp @@ -482,30 +482,41 @@ void snug_bwg_device::set_drive() { LOGMASKED(LOG_CRU, "new DSEL = %d\n", m_DSEL); - if ((m_DSEL != 0) && (m_DSEL != 1) && (m_DSEL != 2) && (m_DSEL != 4) && (m_DSEL != 8)) + int bits = m_DSEL & 0x0f; + int num = -1; + + // If the selected floppy drive is not attached, remove that line + if (m_floppy[3] == nullptr) bits &= 0x07; // 0111 + if (m_floppy[2] == nullptr) bits &= 0x0b; // 1011 + if (m_floppy[1] == nullptr) bits &= 0x0d; // 1101 + if (m_floppy[0] == nullptr) bits &= 0x0e; // 1110 + + if ((bits != 0) && (bits != 1) && (bits != 2) && (bits != 4) && (bits != 8)) LOGMASKED(LOG_WARN, "Warning - multiple drives selected\n"); // The schematics do not reveal any countermeasures against multiple selection // so we assume that the highest value wins. - int bits = m_DSEL & 0x0f; - int i = -1; - - while (bits != 0) - { - bits >>= 1; - i++; - } - if (i != -1) - { - m_current_floppy = m_floppy[i]; - LOGMASKED(LOG_CRU, "Selected floppy %d\n", i); - } - else + if (bits==0) { m_current_floppy = nullptr; LOGMASKED(LOG_CRU, "All drives deselected\n"); } + else + { + if ((bits & 0x08)!=0) num = 3; + else + { + if ((bits & 0x04)!=0) num = 2; + else + { + if ((bits & 0x02)!=0) num = 1; + else num = 0; + } + } + LOGMASKED(LOG_CRU, "Selected floppy DSK%d\n", num+1); + m_current_floppy = m_floppy[num]; + } m_wd1773->set_floppy(m_current_floppy); } diff --git a/src/devices/bus/ti99/peb/ti_fdc.cpp b/src/devices/bus/ti99/peb/ti_fdc.cpp index 7fd4192757c..530dc71d987 100644 --- a/src/devices/bus/ti99/peb/ti_fdc.cpp +++ b/src/devices/bus/ti99/peb/ti_fdc.cpp @@ -273,7 +273,14 @@ WRITE_LINE_MEMBER(ti_fdc_device::sidsel_w) void ti_fdc_device::set_drive() { - switch (m_DSEL) + int dsel = m_DSEL; + + // If the selected floppy drive is not attached, remove that line + if (m_floppy[2] == nullptr) dsel &= 0x03; // 011 + if (m_floppy[1] == nullptr) dsel &= 0x05; // 101 + if (m_floppy[0] == nullptr) dsel &= 0x06; // 110 + + switch (dsel) { case 0: m_current = NONE; @@ -398,6 +405,8 @@ void ti_fdc_device::device_reset() void ti_fdc_device::device_config_complete() { // Seems to be null when doing a "-listslots" + for (auto &elem : m_floppy) + elem = nullptr; if (subdevice("0")!=nullptr) m_floppy[0] = static_cast(subdevice("0")->subdevices().first()); if (subdevice("1")!=nullptr) m_floppy[1] = static_cast(subdevice("1")->subdevices().first()); if (subdevice("2")!=nullptr) m_floppy[2] = static_cast(subdevice("2")->subdevices().first());