machinepdm: properly insert SCSI hard disk image.

Skip SCSI hard disk registration if no disk image was given.
This commit is contained in:
Maxim Poliakovski 2022-10-31 23:48:19 +01:00
parent 6ffe28a8a4
commit 8abefb8f8d
2 changed files with 14 additions and 9 deletions

View File

@ -40,12 +40,11 @@ using namespace std;
ScsiHardDisk::ScsiHardDisk(int my_id) : ScsiDevice(my_id) { ScsiHardDisk::ScsiHardDisk(int my_id) : ScsiDevice(my_id) {
supports_types(HWCompType::SCSI_DEV); supports_types(HWCompType::SCSI_DEV);
} }
void ScsiHardDisk::insert_image(std::string filename) {
void ScsiHardDisk::insert_image(std::string filename) {
//We don't want to store everything in memory, but //We don't want to store everything in memory, but
//we want to keep the hard disk available. //we want to keep the hard disk available.
this->hdd_img.open(filename, ios::out | ios::in | ios::binary); this->hdd_img.open(filename, ios::out | ios::in | ios::binary);
// Taken from: // Taken from:
// https://stackoverflow.com/questions/22984956/tellg-function-give-wrong-size-of-file/22986486 // https://stackoverflow.com/questions/22984956/tellg-function-give-wrong-size-of-file/22986486
@ -247,7 +246,7 @@ static const PropMap SCSI_HD_Properties = {
{"hdd_wr_prot", new BinProperty(0)}, {"hdd_wr_prot", new BinProperty(0)},
}; };
static const DeviceDescription SCSI_HD_Descriptor = static const DeviceDescription SCSI_HD_Descriptor =
{ScsiHardDisk::create, {}, SCSI_HD_Properties}; {ScsiHardDisk::create, {}, SCSI_HD_Properties};
REGISTER_DEVICE(ScsiDevice, SCSI_HD_Descriptor); REGISTER_DEVICE(ScsiHD, SCSI_HD_Descriptor);

View File

@ -83,9 +83,15 @@ int initialize_pdm(std::string& id)
gMachineObj->add_device("SCSI0", std::unique_ptr<ScsiBus>(new ScsiBus())); gMachineObj->add_device("SCSI0", std::unique_ptr<ScsiBus>(new ScsiBus()));
auto scsi_bus = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("SCSI0")); auto scsi_bus = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("SCSI0"));
// attach SCSI HD to the main bus, ID #0 std::string hd_image_path = GET_STR_PROP("hdd_img");
gMachineObj->add_device("SCSI_HD", std::unique_ptr<ScsiHardDisk>(new ScsiHardDisk(0))); if (!hd_image_path.empty()) {
scsi_bus->register_device(0, dynamic_cast<ScsiDevice*>(gMachineObj->get_comp_by_name("SCSI_HD"))); // attach SCSI HD to the main bus, ID #0
gMachineObj->add_device("SCSI_HD", std::unique_ptr<ScsiHardDisk>(new ScsiHardDisk(0)));
scsi_bus->register_device(0, dynamic_cast<ScsiDevice*>(gMachineObj->get_comp_by_name("SCSI_HD")));
// insert specified disk image
auto my_hd = dynamic_cast<ScsiHardDisk*>(gMachineObj->get_comp_by_name("SCSI_HD"));
my_hd->insert_image(hd_image_path);
}
// Init virtual CPU and request MPC601 // Init virtual CPU and request MPC601
ppc_cpu_init(hmc_obj, PPC_VER::MPC601, 7812500ULL); ppc_cpu_init(hmc_obj, PPC_VER::MPC601, 7812500ULL);
@ -113,7 +119,7 @@ static const PropMap pm6100_settings = {
}; };
static vector<string> pm6100_devices = { static vector<string> pm6100_devices = {
"HMC", "Amic" "HMC", "Amic", "ScsiHD"
}; };
static const MachineDescription pm6100_descriptor = { static const MachineDescription pm6100_descriptor = {