2022-02-07 15:00:02 +06:00
|
|
|
/*
|
2023-01-06 15:36:05 -05: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-06 15:36:05 -05:00
|
|
|
* This file is part of the 86Box distribution.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Program settings UI module.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Authors: Miran Grca <mgrca8@gmail.com>
|
|
|
|
|
* Cacodemon345
|
|
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Copyright 2022 Miran Grca
|
|
|
|
|
* Copyright 2022 Cacodemon345
|
2022-02-07 15:00:02 +06:00
|
|
|
*/
|
2022-01-09 16:41:03 +06:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
#include "86box/hdd.h"
|
|
|
|
|
#include "qt_settings_bus_tracking.hpp"
|
|
|
|
|
|
|
|
|
|
SettingsBusTracking::SettingsBusTracking()
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
mfm_tracking = 0x0000000000000000ULL;
|
2022-01-09 16:41:03 +06:00
|
|
|
esdi_tracking = 0x0000000000000000ULL;
|
2022-11-19 08:49:04 -05:00
|
|
|
xta_tracking = 0x0000000000000000ULL;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
|
if (i < 4)
|
|
|
|
|
ide_tracking[i] = 0x0000000000000000ULL;
|
|
|
|
|
|
|
|
|
|
scsi_tracking[i] = 0x0000000000000000ULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
|
SettingsBusTracking::next_free_mfm_channel()
|
|
|
|
|
{
|
|
|
|
|
if ((mfm_tracking & 0xff00ULL) && !(mfm_tracking & 0x00ffULL))
|
2022-01-10 01:15:49 +06:00
|
|
|
return 1;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
if (!(mfm_tracking & 0xff00ULL) && (mfm_tracking & 0x00ffULL))
|
2022-01-10 01:15:49 +06:00
|
|
|
return 0;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
return CHANNEL_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
|
SettingsBusTracking::next_free_esdi_channel()
|
|
|
|
|
{
|
|
|
|
|
if ((esdi_tracking & 0xff00ULL) && !(esdi_tracking & 0x00ffULL))
|
2022-01-10 01:15:49 +06:00
|
|
|
return 1;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
if (!(esdi_tracking & 0xff00ULL) && (esdi_tracking & 0x00ffULL))
|
2022-01-10 01:15:49 +06:00
|
|
|
return 0;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
return CHANNEL_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
|
SettingsBusTracking::next_free_xta_channel()
|
|
|
|
|
{
|
|
|
|
|
if ((xta_tracking & 0xff00ULL) && !(xta_tracking & 0x00ffULL))
|
2022-01-10 01:15:49 +06:00
|
|
|
return 1;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
if (!(xta_tracking & 0xff00ULL) && (xta_tracking & 0x00ffULL))
|
2022-01-10 01:15:49 +06:00
|
|
|
return 0;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
return CHANNEL_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
|
SettingsBusTracking::next_free_ide_channel()
|
|
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
int i, element;
|
2022-01-09 16:41:03 +06:00
|
|
|
uint64_t mask;
|
2022-11-19 08:49:04 -05:00
|
|
|
uint8_t ret = CHANNEL_NONE;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
|
element = ((i << 3) >> 6);
|
2022-11-19 08:49:04 -05:00
|
|
|
mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f));
|
2022-01-09 16:41:03 +06:00
|
|
|
|
2022-01-10 01:12:23 +06:00
|
|
|
if (!(ide_tracking[element] & mask)) {
|
2022-11-19 08:49:04 -05:00
|
|
|
ret = (uint8_t) i;
|
|
|
|
|
break;
|
2022-01-09 16:41:03 +06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
|
SettingsBusTracking::next_free_scsi_id()
|
|
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
int i, element;
|
2022-01-09 16:41:03 +06:00
|
|
|
uint64_t mask;
|
2022-11-19 08:49:04 -05:00
|
|
|
uint8_t ret = CHANNEL_NONE;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
for (i = 0; i < 64; i++) {
|
|
|
|
|
element = ((i << 3) >> 6);
|
2022-11-19 08:49:04 -05:00
|
|
|
mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f));
|
2022-01-09 16:41:03 +06:00
|
|
|
|
2022-01-10 01:12:23 +06:00
|
|
|
if (!(scsi_tracking[element] & mask)) {
|
2022-11-19 08:49:04 -05:00
|
|
|
ret = (uint8_t) i;
|
|
|
|
|
break;
|
2022-01-09 16:41:03 +06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
SettingsBusTracking::mfm_bus_full()
|
|
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
int i;
|
2022-01-09 16:41:03 +06:00
|
|
|
uint64_t mask;
|
2022-11-19 08:49:04 -05:00
|
|
|
uint8_t count = 0;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
|
mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f));
|
|
|
|
|
|
|
|
|
|
if (mfm_tracking & mask)
|
2022-11-19 08:49:04 -05:00
|
|
|
count++;
|
2022-01-09 16:41:03 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (count == 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
SettingsBusTracking::esdi_bus_full()
|
|
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
int i;
|
2022-01-09 16:41:03 +06:00
|
|
|
uint64_t mask;
|
2022-11-19 08:49:04 -05:00
|
|
|
uint8_t count = 0;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
|
mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f));
|
|
|
|
|
|
|
|
|
|
if (esdi_tracking & mask)
|
2022-11-19 08:49:04 -05:00
|
|
|
count++;
|
2022-01-09 16:41:03 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (count == 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
SettingsBusTracking::xta_bus_full()
|
|
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
int i;
|
2022-01-09 16:41:03 +06:00
|
|
|
uint64_t mask;
|
2022-11-19 08:49:04 -05:00
|
|
|
uint8_t count = 0;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
|
mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f));
|
|
|
|
|
|
|
|
|
|
if (xta_tracking & mask)
|
2022-11-19 08:49:04 -05:00
|
|
|
count++;
|
2022-01-09 16:41:03 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (count == 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
SettingsBusTracking::ide_bus_full()
|
|
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
int i, element;
|
2022-01-09 16:41:03 +06:00
|
|
|
uint64_t mask;
|
2022-11-19 08:49:04 -05:00
|
|
|
uint8_t count = 0;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
|
element = ((i << 3) >> 6);
|
2022-11-19 08:49:04 -05:00
|
|
|
mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f));
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
if (ide_tracking[element] & mask)
|
2022-11-19 08:49:04 -05:00
|
|
|
count++;
|
2022-01-09 16:41:03 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (count == 32);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
SettingsBusTracking::scsi_bus_full()
|
|
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
int i, element;
|
2022-01-09 16:41:03 +06:00
|
|
|
uint64_t mask;
|
2022-11-19 08:49:04 -05:00
|
|
|
uint8_t count = 0;
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
for (i = 0; i < 64; i++) {
|
|
|
|
|
element = ((i << 3) >> 6);
|
2022-11-19 08:49:04 -05:00
|
|
|
mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f));
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
if (scsi_tracking[element] & mask)
|
2022-11-19 08:49:04 -05:00
|
|
|
count++;
|
2022-01-09 16:41:03 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (count == 64);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
SettingsBusTracking::device_track(int set, uint8_t dev_type, int bus, int channel)
|
|
|
|
|
{
|
2022-11-19 08:49:04 -05:00
|
|
|
int element;
|
2022-01-09 16:41:03 +06:00
|
|
|
uint64_t mask;
|
|
|
|
|
|
|
|
|
|
switch (bus) {
|
|
|
|
|
case HDD_BUS_MFM:
|
|
|
|
|
mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f));
|
|
|
|
|
|
|
|
|
|
if (set)
|
|
|
|
|
mfm_tracking |= mask;
|
|
|
|
|
else
|
|
|
|
|
mfm_tracking &= ~mask;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case HDD_BUS_ESDI:
|
|
|
|
|
mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f));
|
|
|
|
|
|
|
|
|
|
if (set)
|
|
|
|
|
esdi_tracking |= mask;
|
|
|
|
|
else
|
|
|
|
|
esdi_tracking &= ~mask;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case HDD_BUS_XTA:
|
|
|
|
|
mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f));
|
|
|
|
|
|
|
|
|
|
if (set)
|
|
|
|
|
xta_tracking |= mask;
|
|
|
|
|
else
|
|
|
|
|
xta_tracking &= ~mask;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case HDD_BUS_IDE:
|
|
|
|
|
case HDD_BUS_ATAPI:
|
|
|
|
|
element = ((channel << 3) >> 6);
|
2022-11-19 08:49:04 -05:00
|
|
|
mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f));
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
if (set)
|
|
|
|
|
ide_tracking[element] |= mask;
|
|
|
|
|
else
|
|
|
|
|
ide_tracking[element] &= ~mask;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case HDD_BUS_SCSI:
|
|
|
|
|
element = ((channel << 3) >> 6);
|
2022-11-19 08:49:04 -05:00
|
|
|
mask = ((uint64_t) dev_type) << ((uint64_t) ((channel << 3) & 0x3f));
|
2022-01-09 16:41:03 +06:00
|
|
|
|
|
|
|
|
if (set)
|
|
|
|
|
scsi_tracking[element] |= mask;
|
|
|
|
|
else
|
|
|
|
|
scsi_tracking[element] &= ~mask;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|