Files
dingusppc/machines/machinegazelle.cpp
Mihai Parparita 2a83f5bddc Create empty CD-ROM drives for SCSI-based machines
We only created SCSI CD-ROM drives when an image was supplied at
startup, so later insertion requests had no drive to go to. The
Beige G3 already worked because its ATAPI drive is always created.

Extend the ATAPI approach (where a `cdr_config` property defines the bus
where a CD-ROM drive should be attached) for SCSI-based machines too.
Use it to define default drive on the appropriate bus for PDM, TNT,
Catalyst, Alchemy, Gazelle, and Pippin. Supplying images at startup still
uses the existing drive allocation behavior.
2026-10-11 15:44:22 -07:00

199 lines
6.4 KiB
C++

/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-26 The DingusPPC Development Team
(See CREDITS.MD for more details)
(You may also contact divingkxt or powermax2286 on Discord)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** Constructs a Gazelle style machine. This family includes
Power Macintosh 5500, 6500 and Twentieth Anniversary Mac.
*/
#include <cpu/ppc/ppcemu.h>
#include <devices/memctrl/psx.h>
#include <devices/common/pci/pcidevice.h>
#include <devices/common/pci/pcihost.h>
#include <devices/deviceregistry.h>
#include <devices/ioctrl/macio.h>
#include <machines/machine.h>
#include <machines/machinebase.h>
#include <machines/machinefactory.h>
#include <machines/machineproperties.h>
#include <memctrl/memctrlbase.h>
#include <loguru.hpp>
static std::vector<PciIrqMap> psx_irq_map = {
{nullptr , DEV_FUN(0x0B,0), IntSrc::BANDIT1},
{"pci_A1", DEV_FUN(0x0D,0), IntSrc::PCI_A},
{"pci_B1", DEV_FUN(0x0E,0), IntSrc::PCI_B},
{"pci_C1", DEV_FUN(0x0F,0), IntSrc::PCI_C},
{nullptr , DEV_FUN(0x10,0), }, // OHare
{"pci_E1", DEV_FUN(0x11,0), IntSrc::PCI_E},
{"pci_F1", DEV_FUN(0x12,0), IntSrc::PCI_F},
};
// TODO: move it to /cpu/ppc
int get_cpu_pll_value(const uint64_t cpu_freq_hz) {
switch (cpu_freq_hz / 1000000) {
case 225:
return 7; // 4.5:1 ratio
case 250:
return 11; // 5:1 ratio
case 275:
return 9; // 5.5:1 ratio
default:
ABORT_F("Unsupported CPU frequency %llu Hz", cpu_freq_hz);
}
}
class MachineGazelle : public Machine {
public:
static std::unique_ptr<HWComponent> create5500() {
return Machine::create_with_id<MachineGazelle>("pm5500");
}
static std::unique_ptr<HWComponent> create6500() {
return Machine::create_with_id<MachineGazelle>("pm6500");
}
static std::unique_ptr<HWComponent> create_tam() {
return Machine::create_with_id<MachineGazelle>("tam");
}
int initialize(const std::string &id);
};
int MachineGazelle::initialize(const std::string &id) {
LOG_F(INFO, "Building machine Gazelle...");
PCIHost *pci_host = dynamic_cast<PCIHost*>(gMachineObj->get_comp_by_name("PsxPci1"));
pci_host->set_irq_map(psx_irq_map);
MacIoTwo* macio_obj = dynamic_cast<MacIoTwo*>(gMachineObj->get_comp_by_name("OHare"));
// select between the standard Macintosh and the TAM startup bong
macio_obj->set_media_bay_id(id == "tam" ? 0x70 : 0x30);
// set Box aka CPU ID and activate factory tests if requested
macio_obj->set_cpu_id(
(
(id == "pm5500" || id == "tam") ?
0xF0 // for 5500 & TAM => CPUID0...CPUID3 pulled high
:
0xE0 // for 6500 => CPUID3...CPUID1 pulled high, CPUID0 pulled low
) & (
GET_BIN_PROP("emmo") ?
~0x40 // pull BOXID2 low --> activate factory tests
:
~0 // No-op
)
);
// register O'Hare I/O controller with the main PCI bus
pci_host->pci_register_device(DEV_FUN(0x10,0), macio_obj);
PsxCtrl* psx_obj = dynamic_cast<PsxCtrl*>(gMachineObj->get_comp_by_name("Psx"));
// allocate ROM region
if (!psx_obj->add_rom_region(0xFFC00000, 0x400000)) {
LOG_F(ERROR, "Could not allocate ROM region!");
return -1;
}
// insert RAM DIMMs
psx_obj->insert_ram_dimm(0, GET_INT_PROP("rambank0_size") * DRAM_CAP_1MB);
psx_obj->insert_ram_dimm(1, GET_INT_PROP("rambank1_size") * DRAM_CAP_1MB);
psx_obj->insert_ram_dimm(3, GET_INT_PROP("rambank2_size") * DRAM_CAP_1MB);
// allocate and map physical RAM
psx_obj->map_phys_ram();
// configure bus speed
psx_obj->set_bus_speed(PSX_BUS_SPEED_50);
// configure CPU clocks
uint64_t bus_freq = 50000000ULL;
uint64_t timebase_freq = bus_freq / 4;
// init virtual CPU and request MPC603ev
ppc_cpu_init(psx_obj, PPC_VER::MPC603EV, false, timebase_freq);
// CPU frequency is hardcoded to 225 MHz for now
ppc_state.spr[SPR::HID1] = get_cpu_pll_value(225000000) << 28;
return 0;
}
static const PropMap pm6500_settings = {
{"rambank0_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32 }))},
{"rambank1_size",
new IntProperty(32, std::vector<uint32_t>({ 4, 8, 16, 32, 64}))},
{"rambank2_size",
new IntProperty( 0, std::vector<uint32_t>({0, 4, 8, 16, 32, 64}))},
{"cdr_config",
new StrProperty("ScsiMesh:3")},
{"emmo",
new BinProperty(0)},
{"hdd_config",
new StrProperty("Ide0:0")},
{"pci_F1",
new StrProperty("AtiRageGT")},
};
static std::vector<std::string> pm6500_devices = {
"Psx", "PsxPci1", "ScreamerSnd", "OHare", "AtaHardDisk"
};
static const DeviceDescription Machine5500_descriptor = {
MachineGazelle::create5500, pm6500_devices, pm6500_settings
};
static const DeviceDescription Machine6500_descriptor = {
MachineGazelle::create6500, pm6500_devices, pm6500_settings
};
static const DeviceDescription MachineTAM_descriptor = {
MachineGazelle::create_tam, pm6500_devices, pm6500_settings
};
REGISTER_DEVICE(MachineGazelle5500, Machine5500_descriptor);
REGISTER_DEVICE(MachineGazelle6500, Machine6500_descriptor);
REGISTER_DEVICE(MachineGazelleTAM, MachineTAM_descriptor);
static const MachineDescription pm5500_descriptor = {
.name = "pm5500",
.description = "Power Macintosh 5500",
.machine_root = "MachineGazelle5500",
};
static const MachineDescription pm6500_descriptor = {
.name = "pm6500",
.description = "Power Macintosh 6500",
.machine_root = "MachineGazelle6500",
};
static const MachineDescription TAM_descriptor = {
.name = "tam",
.description = "Twentieth Anniversary Macintosh",
.machine_root = "MachineGazelleTAM",
};
REGISTER_MACHINE(pm5500, pm5500_descriptor);
REGISTER_MACHINE(pm6500, pm6500_descriptor);
REGISTER_MACHINE(tam, TAM_descriptor);