Initial work for configuration

This commit is contained in:
dingusdev 2020-08-22 11:05:08 -07:00
parent 8094fb30f6
commit 2869755819
4 changed files with 230 additions and 70 deletions

101
machines/machineconfig.cpp Normal file
View File

@ -0,0 +1,101 @@
#include "machineproperties.h"
#include "machinepresets.h"
void init_ppc_cpu_map() {
PPC_CPUs.emplace("PPC_MPC601", 0x00010001);
PPC_CPUs.emplace("PPC_MPC603", 0x00030001);
PPC_CPUs.emplace("PPC_MPC604", 0x00040001);
PPC_CPUs.emplace("PPC_MPC603E", 0x00060101);
PPC_CPUs.emplace("PPC_MPC750", 0x00080200);
}
void init_gpu_map() {
GFX_CARDs.emplace("ATI_Rage_Pro", 0x10024750);
GFX_CARDs.emplace("ATI_Rage_128_Pro", 0x10025052);
}
void init_machine_properties() {
PowerMac6100_Properties.emplace("gestalt", StringProperty("100"));
PowerMac6100_Properties.emplace("cputype", StringProperty("PPC_MPC601"));
PowerMac6100_Properties.emplace("motherboard", StringProperty("Nubus"));
PowerMac6100_Properties.emplace("ioboard", StringProperty("Nubus_IO"));
PowerMac6100_Properties.emplace("ram", StringProperty("8"));
PowerMac6100_Properties.emplace("gfxcard", StringProperty("Nubus_Video"));
PowerMac6100_Properties.emplace("gfxmem", StringProperty("1"));
PowerMacG3_Properties.emplace("gestalt", StringProperty("510"));
PowerMacG3_Properties.emplace("cputype", StringProperty("PPC_MPC750"));
PowerMacG3_Properties.emplace("motherboard", StringProperty("Grackle"));
PowerMacG3_Properties.emplace("ioboard", StringProperty("Heathrow"));
PowerMacG3_Properties.emplace("ram", StringProperty("64"));
PowerMacG3_Properties.emplace("gfxcard", StringProperty("ATI_Rage_Pro"));
PowerMacG3_Properties.emplace("gfxmem", StringProperty("2"));
}
uint32_t get_gfx_card(std::string gfx_str) {
if (gfx_str.compare("Nubus_Video")) {
return 0;
} else {
try {
return GFX_CARDs.find(gfx_str)->second;
} catch (std::string bad_string) {
std::cerr << "Could not find the matching GFX card for " << bad_string << std::endl;
return 0x168A523B;
}
}
}
uint32_t get_cpu_type(std::string cpu_str) {
try {
return PPC_CPUs.find(cpu_str)->second;
} catch (std::string bad_string) {
std::cerr << "Could not find the matching CPU value for " << bad_string << std::endl;
return 0x168A523B;
}
}
void search_properties(uint32_t chosen_gestalt) {
std::string cpu_str = "OOPS";
uint32_t cpu_type = 0x168A523B;
uint32_t ram_size = 0;
uint32_t gfx_size = 0;
uint32_t gfx_type = 0;
switch (chosen_gestalt) {
case 100:
cpu_str = PowerMac6100_Properties.find("cputype")->second.getString();
cpu_type = get_cpu_type(cpu_str);
ram_size = PowerMac6100_Properties.find("ram")->second.IntRep();
gfx_size = PowerMac6100_Properties.find("gfxmem")->second.IntRep();
gfx_type = PowerMac6100_Properties.find("gfxcard")->second.IntRep();
break;
case 510:
cpu_str = PowerMacG3_Properties.find("cputype")->second.getString();
cpu_type = get_cpu_type(cpu_str);
ram_size = PowerMacG3_Properties.find("ram")->second.IntRep();
gfx_size = PowerMacG3_Properties.find("gfxmem")->second.IntRep();
gfx_type = PowerMacG3_Properties.find("gfxcard")->second.IntRep();
break;
default:
std::cerr << "Unable to find congifuration for " << chosen_gestalt << std::endl;
}
uint16_t gfx_ven = gfx_type >> 16;
uint16_t gfx_dev = gfx_type & 0xFFFF;
std::cout << "CPU TYPE: 0x" << std::hex << cpu_type << std::endl;
std::cout << "RAM SIZE: " << std::dec << ram_size << std::endl;
std::cout << "GMEM SIZE: " << std::dec << gfx_size << std::endl;
}
void establish_machine_settings(uint32_t starting_setting) {
init_ppc_cpu_map();
init_gpu_map();
init_machine_properties();
search_properties(starting_setting);
}

View File

@ -0,0 +1,7 @@
#include "machineproperties.h"
std::map<std::string, StringProperty> PowerMac6100_Properties;
std::map<std::string, StringProperty> PowerMacG3_Properties;
void init_machine_properties(); // JANKY FUNCTION TO FIX VS 2019 BUG!

View File

@ -0,0 +1,54 @@
#ifndef MACHINE_PROPERTIES_H
#define MACHINE_PROPERTIES_H
#include "endianswap.h"
#include <cinttypes>
#include <cstring>
#include <map>
#include <iostream>
#include <utility>
using namespace std;
class StringProperty {
public:
StringProperty(string EnterString) {
StringInput = EnterString;
}
string getString() {
return StringInput;
}
uint32_t IntRep() {
try {
return strtoul(getString().c_str(), 0, 0);
} catch (string bad_string) {
cerr << "Could not convert string " << bad_string << "to an ineteger!" << endl;
return 0x168A523B;
}
}
private:
string StringInput = "0x168A523B";
};
map<string, uint32_t> PPC_CPUs;
map<string, uint32_t> GFX_CARDs;
enum GESTALT : uint32_t {
pm6100 = 100,
pmg3 = 510,
};
void init_ppc_cpu_map(); //JANKY FUNCTION TO FIX VS 2019 BUG!
void init_gpu_map(); //JANKY FUNCTION TO FIX VS 2019 BUG!
uint32_t get_gfx_card(std::string gfx_str);
uint32_t get_cpu_type(std::string cpu_str);
void search_properties(uint32_t chosen_gestalt);
#endif /* MACHINE_PROPERTIES_H */

138
main.cpp
View File

@ -37,70 +37,71 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
int main(int argc, char** argv) {
std::cout << "DingusPPC - Prototype 5bf4 (7/14/2019) " << endl;
std::cout << "Written by divingkatae, (c) 2019. " << endl;
/*
Execution Type:
0 = Realtime (Interpreter)
1 = Realtime (Debugger)
2 = Recompiler (to-do)
The rest will be decided later
*/
uint32_t execution_mode = 0;
std::cout << "DingusPPC - Prototype 5bf5 (8/23/2020) " << endl;
std::cout << "Written by divingkatae and maximumspatium " << endl;
std::cout << "(c) 2018-2020 The DingusPPC Dev Team. " << endl;
std::cout << "This is not intended for general use. " << endl;
std::cout << "Use at your own discretion. " << endl;
if (argc > 1) {
string checker = argv[1];
cout << checker << endl;
if ((checker == "1") || (checker == "realtime") || (checker == "-realtime") ||
(checker == "/realtime")) {
loguru::g_stderr_verbosity = loguru::Verbosity_OFF;
loguru::g_preamble_date = false;
loguru::g_preamble_time = false;
loguru::g_preamble_thread = false;
loguru::init(argc, argv);
loguru::add_file("dingusppc.log", loguru::Append, 0);
// Replace the above line with this for maximum debugging detail:
// loguru::add_file("dingusppc.log", loguru::Append, loguru::Verbosity_MAX);
} else if ((checker == "debugger") || (checker == "/debugger") || (checker == "-debugger")) {
loguru::g_stderr_verbosity = 0;
loguru::g_preamble_date = false;
loguru::g_preamble_time = false;
loguru::g_preamble_thread = false;
loguru::init(argc, argv);
}
if (argc < 1) {
std::cout << " " << endl;
std::cout << "Please enter one of the following commands when " << endl;
std::cout << "booting up DingusPPC... " << endl;
std::cout << " " << endl;
std::cout << "realtime - Run the emulator in real-time. " << endl;
std::cout << "debugger - Enter the interactive debugger. " << endl;
}
else {
std::string rom_file = "rom.bin", disk_file = "disk.img";
int ram_size = 64, machine_gestalt = 510, video_card_vendor = 0x1002, video_card_id = 0x4750;
int ram_size = 64, gfx_mem = 2, machine_gestalt = 510, video_card_vendor = 0x1002, video_card_id = 0x4750;
std::ifstream config_input("config.txt");
std::string line;
std::istringstream sin;
if (!config_input) {
LOG_F(ERROR, "Could not open config.txt. Creating a dummy config.txt now.");
std::ofstream config_output("config.txt");
config_output.write("rompath=rom.bin\n", 17);
config_output.write("diskpath=disk.img\n", 19);
config_output.write("ramsize=64\n", 12);
config_output.write("machine_gestalt=510\n", 21);
config_output.write("video_vendor=0x1002\n", 21);
config_output.write("video_card=0x4750\n", 19);
config_output.close();
} else {
while (std::getline(config_input, line)) {
sin.str(line.substr(line.find("=") + 1));
if (line.find("rompath") != std::string::npos) {
sin >> rom_file;
} else if (line.find("diskpath") != std::string::npos) {
sin >> disk_file;
} else if (line.find("ramsize") != std::string::npos) {
sin >> ram_size;
} else if (line.find("machine_gestalt") != std::string::npos) {
sin >> machine_gestalt;
} else if (line.find("video_vendor") != std::string::npos) {
sin >> video_card_vendor;
} else if (line.find("video_card") != std::string::npos) {
sin >> video_card_id;
}
sin.clear();
for (int arg_loop = 1; arg_loop < argc; arg_loop++) {
string checker = argv[arg_loop];
cout << checker << endl;
if ((checker == "realtime") || (checker == "-realtime") || (checker == "/realtime")) {
loguru::g_stderr_verbosity = loguru::Verbosity_OFF;
loguru::g_preamble_date = false;
loguru::g_preamble_time = false;
loguru::g_preamble_thread = false;
loguru::init(argc, argv);
loguru::add_file("dingusppc.log", loguru::Append, 0);
// Replace the above line with this for maximum debugging detail:
// loguru::add_file("dingusppc.log", loguru::Append, loguru::Verbosity_MAX);
execution_mode = 0;
} else if ((checker == "debugger") || (checker == "/debugger") || (checker == "-debugger")) {
loguru::g_stderr_verbosity = 0;
loguru::g_preamble_date = false;
loguru::g_preamble_time = false;
loguru::g_preamble_thread = false;
loguru::init(argc, argv);
execution_mode = 1;
}
else if ((checker == "ram") || (checker == "/ram") || (checker == "-ram")) {
arg_loop++;
string ram_amount = argv[arg_loop];
ram_size = stoi(ram_amount);
LOG_F(INFO, "RAM SET TO: %d", ram_size);
}
else if ((checker == "gfxmem") || (checker == "/gfxmem") || (checker == "-gfxmem")) {
arg_loop++;
string ram_amount = argv[arg_loop];
gfx_mem = stoi(ram_amount);
LOG_F(INFO, "GFX MEMORY SET TO: %d", gfx_mem);
}
}
if (create_machine_for_rom(rom_file.c_str())) {
@ -114,21 +115,18 @@ int main(int argc, char** argv) {
}
#endif
if ((checker == "1") || (checker == "realtime") || (checker == "-realtime") ||
(checker == "/realtime")) {
switch (execution_mode) {
case 0:
ppc_exec();
} else if ((checker == "debugger") || (checker == "/debugger") || (checker == "-debugger")) {
break;
case 1:
enter_debugger();
break;
default:
LOG_F(ERROR, "Invalid EXECUTION MODE");
return 1;
}
} else {
std::cout << " " << endl;
std::cout << "Please enter one of the following commands when " << endl;
std::cout << "booting up DingusPPC... " << endl;
std::cout << " " << endl;
std::cout << " " << endl;
std::cout << "realtime - Run the emulator in real-time. " << endl;
std::cout << "debugger - Enter the interactive debugger. " << endl;
}
}
bail:
LOG_F(INFO, "Cleaning up...");