ti99: Added guards against selecting non-existing drives.

This commit is contained in:
Michael Zapf 2018-10-14 15:13:42 +02:00
parent 0313393702
commit 2b17ce4f40
2 changed files with 36 additions and 16 deletions

View File

@ -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);
}

View File

@ -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<floppy_image_device*>(subdevice("0")->subdevices().first());
if (subdevice("1")!=nullptr) m_floppy[1] = static_cast<floppy_image_device*>(subdevice("1")->subdevices().first());
if (subdevice("2")!=nullptr) m_floppy[2] = static_cast<floppy_image_device*>(subdevice("2")->subdevices().first());