Files
86Box/src/qt/qt_harddrive_common.cpp

156 lines
4.7 KiB
C++
Raw Normal View History

2022-02-07 15:00:02 +06:00
/*
2023-01-08 14:25:18 +01:00
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
2022-02-07 15:00:02 +06:00
*
2023-01-08 14:25:18 +01:00
* This file is part of the 86Box distribution.
2022-02-07 15:00:02 +06:00
*
2023-01-08 14:25:18 +01:00
* Common storage devices module.
2022-02-07 15:00:02 +06:00
*
*
*
2023-01-08 14:25:18 +01:00
* Authors: Joakim L. Gilje <jgilje@jgilje.net>
2022-02-07 15:00:02 +06:00
*
2023-01-08 14:25:18 +01:00
* Copyright 2021 Joakim L. Gilje
2022-02-07 15:00:02 +06:00
*/
2021-11-25 10:20:56 +01:00
#include "qt_harddrive_common.hpp"
#include <cstdint>
extern "C" {
#include <86box/hdd.h>
#include <86box/cdrom.h>
2021-11-25 10:20:56 +01:00
}
#include <QAbstractItemModel>
2022-11-19 08:49:04 -05:00
void
Harddrives::populateBuses(QAbstractItemModel *model)
{
2021-11-25 10:20:56 +01:00
model->removeRows(0, model->rowCount());
model->insertRows(0, 6);
model->setData(model->index(0, 0), "MFM/RLL");
2022-03-04 13:25:51 +06:00
model->setData(model->index(1, 0), "XTA");
2021-11-25 10:20:56 +01:00
model->setData(model->index(2, 0), "ESDI");
model->setData(model->index(3, 0), "IDE");
model->setData(model->index(4, 0), "ATAPI");
model->setData(model->index(5, 0), "SCSI");
model->setData(model->index(0, 0), HDD_BUS_MFM, Qt::UserRole);
model->setData(model->index(1, 0), HDD_BUS_XTA, Qt::UserRole);
model->setData(model->index(2, 0), HDD_BUS_ESDI, Qt::UserRole);
model->setData(model->index(3, 0), HDD_BUS_IDE, Qt::UserRole);
model->setData(model->index(4, 0), HDD_BUS_ATAPI, Qt::UserRole);
model->setData(model->index(5, 0), HDD_BUS_SCSI, Qt::UserRole);
}
2022-11-19 08:49:04 -05:00
void
Harddrives::populateRemovableBuses(QAbstractItemModel *model)
{
2021-11-25 10:20:56 +01:00
model->removeRows(0, model->rowCount());
model->insertRows(0, 4);
2022-01-06 16:58:11 +06:00
model->setData(model->index(0, 0), QObject::tr("Disabled"));
model->setData(model->index(1, 0), QObject::tr("ATAPI"));
model->setData(model->index(2, 0), QObject::tr("SCSI"));
model->setData(model->index(3, 0), QObject::tr("Mitsumi"));
2021-11-25 10:20:56 +01:00
model->setData(model->index(0, 0), HDD_BUS_DISABLED, Qt::UserRole);
model->setData(model->index(1, 0), HDD_BUS_ATAPI, Qt::UserRole);
model->setData(model->index(2, 0), HDD_BUS_SCSI, Qt::UserRole);
model->setData(model->index(3, 0), CDROM_BUS_MITSUMI, Qt::UserRole);
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
Harddrives::populateSpeeds(QAbstractItemModel *model, int bus)
{
int num_preset;
switch (bus) {
case HDD_BUS_IDE:
2022-07-29 00:47:52 +02:00
case HDD_BUS_ESDI:
num_preset = hdd_preset_get_num();
break;
default:
num_preset = 1;
}
model->removeRows(0, model->rowCount());
model->insertRows(0, num_preset);
for (int i = 0; i < num_preset; i++) {
model->setData(model->index(i, 0), QObject::tr(hdd_preset_getname(i)));
model->setData(model->index(i, 0), i, Qt::UserRole);
}
}
2022-11-19 08:49:04 -05:00
void
Harddrives::populateBusChannels(QAbstractItemModel *model, int bus)
{
2021-11-25 10:20:56 +01:00
model->removeRows(0, model->rowCount());
2022-11-19 08:49:04 -05:00
int busRows = 0;
int shifter = 1;
int orer = 1;
2021-11-25 10:20:56 +01:00
int subChannelWidth = 1;
switch (bus) {
2022-11-19 08:49:04 -05:00
case HDD_BUS_MFM:
case HDD_BUS_XTA:
case HDD_BUS_ESDI:
busRows = 2;
break;
case HDD_BUS_IDE:
case HDD_BUS_ATAPI:
busRows = 8;
break;
case HDD_BUS_SCSI:
shifter = 4;
orer = 15;
busRows = 64;
subChannelWidth = 2;
break;
2021-11-25 10:20:56 +01:00
}
model->insertRows(0, busRows);
for (int i = 0; i < busRows; ++i) {
auto idx = model->index(i, 0);
model->setData(idx, QString("%1:%2").arg(i >> shifter).arg(i & orer, subChannelWidth, 10, QChar('0')));
model->setData(idx, ((i >> shifter) << shifter) | (i & orer), Qt::UserRole);
}
}
2022-11-19 08:49:04 -05:00
QString
Harddrives::BusChannelName(uint8_t bus, uint8_t channel)
{
2021-11-25 10:20:56 +01:00
QString busName;
2022-11-19 08:49:04 -05:00
switch (bus) {
case HDD_BUS_DISABLED:
busName = QString(QObject::tr("Disabled"));
break;
case HDD_BUS_MFM:
busName = QString("MFM/RLL (%1:%2)").arg(channel >> 1).arg(channel & 1);
break;
case HDD_BUS_XTA:
busName = QString("XTA (%1:%2)").arg(channel >> 1).arg(channel & 1);
break;
case HDD_BUS_ESDI:
busName = QString("ESDI (%1:%2)").arg(channel >> 1).arg(channel & 1);
break;
case HDD_BUS_IDE:
busName = QString("IDE (%1:%2)").arg(channel >> 1).arg(channel & 1);
break;
case HDD_BUS_ATAPI:
busName = QString("ATAPI (%1:%2)").arg(channel >> 1).arg(channel & 1);
break;
case HDD_BUS_SCSI:
busName = QString("SCSI (%1:%2)").arg(channel >> 4).arg(channel & 15, 2, 10, QChar('0'));
break;
case CDROM_BUS_MITSUMI:
busName = QString("Mitsumi");
break;
2021-11-25 10:20:56 +01:00
}
return busName;
}