2020-01-05 17:38:32 +00:00
|
|
|
//DingusPPC
|
2019-10-16 04:15:12 +00:00
|
|
|
//Written by divingkatae and maximum
|
|
|
|
//(c)2018-20 (theweirdo) spatium
|
2019-07-02 02:15:33 +00:00
|
|
|
//Please ask for permission
|
|
|
|
//if you want to distribute this.
|
2020-01-05 17:38:32 +00:00
|
|
|
//(divingkatae#1017 or powermax#2286 on Discord)
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
//The main runfile - main.cpp
|
|
|
|
//This is where the magic begins
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <array>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fstream>
|
|
|
|
#include <stdexcept>
|
2019-12-27 19:10:36 +00:00
|
|
|
#include "ppcemu.h"
|
2019-12-27 19:00:53 +00:00
|
|
|
#include "ppcmmu.h"
|
2020-01-06 02:46:23 +00:00
|
|
|
#include "memreadwrite.h"
|
2019-08-18 23:34:24 +00:00
|
|
|
#include "devices/mpc106.h"
|
2019-12-14 12:48:54 +00:00
|
|
|
#include "debugger/debugger.h"
|
2019-10-14 15:38:47 +00:00
|
|
|
#include "devices/machineid.h"
|
2019-08-23 21:34:19 +00:00
|
|
|
#include "devices/macio.h"
|
|
|
|
#include "devices/mpc106.h"
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2019-08-21 06:33:01 +00:00
|
|
|
/**
|
|
|
|
Power Macintosh ROM identification string
|
|
|
|
|
|
|
|
is located in the ConfigInfo structure starting at 0x30D064 (PCI Macs)
|
|
|
|
or 0x30C064 (Nubus Macs). This helps a lot to determine which
|
|
|
|
hardware is to be used.
|
|
|
|
*/
|
|
|
|
static const map<string,string> PPCMac_ROMIdentity = { //Codename Abbreviation for...
|
|
|
|
{"Alch", "Performa 6400"}, //Alchemy
|
|
|
|
{"Come", "PowerBook 2400"}, //Comet
|
|
|
|
{"Cord", "Power Mac 5200/6200 series"}, //Cordyceps
|
|
|
|
{"Gaze", "Power Mac 6500"}, //Gazelle
|
|
|
|
{"Goss", "Power Mac G3 Beige"}, //Gossamer
|
|
|
|
{"GRX ", "PowerBook G3 Wallstreet"}, //(Unknown)
|
|
|
|
{"Hoop", "PowerBook 3400"}, //Hooper
|
|
|
|
{"PBX ", "PowerBook Pre-G3"}, //(Unknown)
|
|
|
|
{"PDM ", "Nubus Power Mac or WGS"}, //Piltdown Man (6100/7100/8100)
|
|
|
|
{"Pip ", "Pippin... uh... yeah..."}, //Pippin
|
|
|
|
{"Powe", "Generic Power Mac"}, //PowerMac?
|
|
|
|
{"Spar", "20th Anniversay Mac, you lucky thing."}, //Spartacus
|
|
|
|
{"Tanz", "Power Mac 4400"}, //Tanzania
|
|
|
|
{"TNT ", "Power Mac 7xxxx/8xxx series"}, //Trinitrotoluene :-)
|
|
|
|
{"Zanz", "A complete engima."}, //Zanzibar (mentioned in Sheepshaver's code, but no match to any known ROM)
|
|
|
|
{"????", "A clone, perhaps?"} //N/A (Placeholder ID)
|
|
|
|
};
|
|
|
|
|
|
|
|
MemCtrlBase *mem_ctrl_instance = 0;
|
2019-08-23 21:34:19 +00:00
|
|
|
HeathrowIC *heathrow = 0;
|
2019-10-14 15:38:47 +00:00
|
|
|
GossamerID *machine_id;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2020-01-28 01:20:18 +00:00
|
|
|
uint32_t rom_filesize;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-28 00:24:12 +00:00
|
|
|
/* Init virtual CPU and request MPC750 CPU aka G3 */
|
|
|
|
ppc_cpu_init(PPC_VER::MPC750);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
uint32_t opcode_entered = 0; //used for testing opcodes in playground
|
|
|
|
|
2019-07-12 05:27:14 +00:00
|
|
|
std::cout << "DingusPPC - Prototype 5bf4 (7/14/2019) " << endl;
|
2019-07-02 02:15:33 +00:00
|
|
|
std::cout << "Written by divingkatae, (c) 2019. " << endl;
|
|
|
|
std::cout << "This is not intended for general use. " << endl;
|
|
|
|
std::cout << "Use at your own discretion. " << endl;
|
|
|
|
|
|
|
|
//Open the ROM File.
|
|
|
|
ifstream romFile;
|
|
|
|
|
|
|
|
romFile.open("rom.bin", ios::in|ios::binary);
|
|
|
|
|
|
|
|
if (romFile.fail()){
|
2019-08-21 06:33:01 +00:00
|
|
|
cerr << "rom.bin not present. Please provide an appropriate ROM file"
|
2019-12-26 23:42:02 +00:00
|
|
|
<< " and restart this program.\n";
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2019-08-21 06:33:01 +00:00
|
|
|
romFile.close();
|
2019-07-02 02:15:33 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-08-21 06:33:01 +00:00
|
|
|
//Calculate and validate ROM file size.
|
2019-07-02 02:15:33 +00:00
|
|
|
romFile.seekg(0, romFile.end);
|
2020-01-05 16:52:46 +00:00
|
|
|
rom_filesize = (uint32_t) romFile.tellg();
|
2019-08-21 06:33:01 +00:00
|
|
|
printf("Rom SIZE: %d \n", rom_filesize);
|
2019-07-02 02:15:33 +00:00
|
|
|
romFile.seekg (0, romFile.beg);
|
|
|
|
|
2019-08-21 06:33:01 +00:00
|
|
|
if (rom_filesize != 0x400000){
|
|
|
|
cerr << "Unsupported ROM File size. Expected size is 4 megabytes.\n";
|
|
|
|
romFile.close();
|
|
|
|
return 1;
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2019-07-02 04:54:12 +00:00
|
|
|
char configGrab = 0;
|
2019-07-02 02:15:33 +00:00
|
|
|
uint32_t configInfoOffset = 0;
|
|
|
|
|
|
|
|
romFile.seekg (0x300082, ios::beg); //This is where the place to get the offset is
|
2019-08-21 06:33:01 +00:00
|
|
|
romFile.get(configGrab); //just one byte to determine ConfigInfo location
|
2019-07-02 04:54:12 +00:00
|
|
|
configInfoOffset = (uint32_t)(configGrab & 0xff);
|
2019-07-19 06:31:16 +00:00
|
|
|
|
2019-07-02 04:54:12 +00:00
|
|
|
uint32_t configInfoAddr = 0x300000 + (configInfoOffset << 8) + 0x69; //address to check the identifier string
|
2019-08-21 06:33:01 +00:00
|
|
|
char memPPCBlock[5]; //First four chars are enough to distinguish between codenames
|
2019-07-02 02:15:33 +00:00
|
|
|
romFile.seekg (configInfoAddr, ios::beg);
|
2019-08-21 06:33:01 +00:00
|
|
|
romFile.read(memPPCBlock, 4);
|
|
|
|
memPPCBlock[4] = 0;
|
2020-01-13 02:04:06 +00:00
|
|
|
uint32_t rom_id = READ_DWORD_BE_A(memPPCBlock);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
std::string string_test = std::string(memPPCBlock);
|
|
|
|
|
|
|
|
//Just auto-iterate through the list
|
|
|
|
for (auto iter = PPCMac_ROMIdentity.begin(); iter != PPCMac_ROMIdentity.end(); ){
|
|
|
|
|
|
|
|
string redo_me = iter->first;
|
|
|
|
|
2019-07-02 04:54:12 +00:00
|
|
|
if (string_test.compare(redo_me) == 0){
|
2019-07-02 02:15:33 +00:00
|
|
|
cout << "The machine is identified as..." << iter->second << endl;
|
|
|
|
romFile.seekg (0x0, ios::beg);
|
|
|
|
break;
|
|
|
|
}
|
2019-07-02 04:54:12 +00:00
|
|
|
else{
|
|
|
|
iter++;
|
|
|
|
}
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2019-08-21 06:33:01 +00:00
|
|
|
switch(rom_id) {
|
2019-08-23 21:34:19 +00:00
|
|
|
case 0x476F7373: {
|
2020-01-05 16:52:46 +00:00
|
|
|
cout << "Initialize Gossamer hardware..." << endl;
|
2019-08-23 21:34:19 +00:00
|
|
|
MPC106 *mpc106 = new MPC106();
|
|
|
|
mem_ctrl_instance = mpc106;
|
2019-10-07 01:21:01 +00:00
|
|
|
if (!mem_ctrl_instance->add_rom_region(0xFFC00000, 0x400000)) {
|
2019-08-23 21:34:19 +00:00
|
|
|
cout << "failure!\n" << endl;
|
|
|
|
delete(mem_ctrl_instance);
|
|
|
|
romFile.close();
|
|
|
|
return 1;
|
|
|
|
}
|
2019-10-14 15:38:47 +00:00
|
|
|
machine_id = new GossamerID(0x3d8c);
|
|
|
|
mpc106->add_mmio_region(0xFF000004, 4096, machine_id);
|
|
|
|
|
2019-08-23 21:34:19 +00:00
|
|
|
heathrow = new HeathrowIC();
|
|
|
|
mpc106->pci_register_device(16, heathrow);
|
|
|
|
cout << "done" << endl;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2019-08-21 06:33:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cout << "This machine not supported yet." << endl;
|
|
|
|
return 1;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
2019-08-21 06:33:01 +00:00
|
|
|
|
2020-01-28 01:20:18 +00:00
|
|
|
/* Read ROM file content and transfer it to the dedicated ROM region */
|
|
|
|
unsigned char *sysrom_mem = new unsigned char[rom_filesize];
|
|
|
|
romFile.read ((char *)sysrom_mem, rom_filesize);
|
|
|
|
mem_ctrl_instance->set_data(0xFFC00000, sysrom_mem, rom_filesize);
|
2019-08-21 06:33:01 +00:00
|
|
|
romFile.close();
|
2020-01-28 01:20:18 +00:00
|
|
|
delete[] sysrom_mem;
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-01-28 01:20:18 +00:00
|
|
|
if (argc > 1) {
|
2019-07-02 02:15:33 +00:00
|
|
|
string checker = argv[1];
|
|
|
|
cout << checker << endl;
|
|
|
|
|
2020-01-28 01:20:18 +00:00
|
|
|
if ((checker == "1") || (checker == "realtime") || (checker == "/realtime")
|
|
|
|
|| (checker == "-realtime")) {
|
2019-12-28 01:49:58 +00:00
|
|
|
ppc_exec();
|
2020-01-28 01:20:18 +00:00
|
|
|
} else if ((checker == "debugger") || (checker == "/debugger") ||
|
|
|
|
(checker == "-debugger")) {
|
2019-07-17 13:24:34 +00:00
|
|
|
enter_debugger();
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-28 01:20:18 +00:00
|
|
|
else {
|
2019-07-02 02:15:33 +00:00
|
|
|
std::cout << " " << endl;
|
2019-07-07 06:10:32 +00:00
|
|
|
std::cout << "Please enter one of the following commands when " << endl;
|
|
|
|
std::cout << "booting up DingusPPC... " << endl;
|
2019-07-02 02:15:33 +00:00
|
|
|
std::cout << " " << endl;
|
|
|
|
std::cout << " " << endl;
|
2019-07-07 06:10:32 +00:00
|
|
|
std::cout << "realtime - Run the emulator in real-time. " << endl;
|
2019-07-19 06:31:16 +00:00
|
|
|
std::cout << "debugger - Enter the interactive debugger. " << endl;
|
2019-07-02 02:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 01:20:18 +00:00
|
|
|
/* Free memory after the emulation is completed. */
|
2019-08-23 21:34:19 +00:00
|
|
|
delete(heathrow);
|
2019-10-14 15:38:47 +00:00
|
|
|
delete(machine_id);
|
2019-08-21 06:33:01 +00:00
|
|
|
delete(mem_ctrl_instance);
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|