dingusppc/main.cpp

309 lines
12 KiB
C++
Raw Normal View History

/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-20 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
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/>.
*/
2020-05-12 18:55:45 +00:00
// The main runfile - main.cpp
// This is where the magic begins
2020-05-12 18:55:45 +00:00
#include "debugger/debugger.h"
#include "machines/machinefactory.h"
2020-08-26 03:07:02 +00:00
#include "machines/machineproperties.h"
2020-05-12 18:55:45 +00:00
#include "ppcemu.h"
#include <cinttypes>
#include <cstring>
2020-03-26 19:32:24 +00:00
#include <fstream>
2020-05-12 18:55:45 +00:00
#include <iostream>
2020-03-26 19:32:24 +00:00
#include <sstream>
#include <stdio.h>
2020-09-20 21:25:29 +00:00
#include <CLI11.hpp>
#include <thirdparty/SDL2/include/SDL.h>
2020-05-12 18:55:45 +00:00
#include <thirdparty/loguru/loguru.hpp>
using namespace std;
2020-08-26 03:07:02 +00:00
void display_help() {
std::cout << " " << endl;
std::cout << "To interact with DingusPPC, please refer to the " << endl;
std::cout << "following command line reference guide: " << endl;
std::cout << "___________________________________________________" << endl;
std::cout << "| COMMAND | FUNCTION |" << endl;
std::cout << "___________________________________________________" << endl;
std::cout << " realtime | Run the emulator in real-time " << endl;
std::cout << " debugger | Enter the interactive debugger " << endl;
std::cout << " ram | Specify the number of RAM banks, " << endl;
std::cout << " | followed by how much each bank holds " << endl;
std::cout << " videocard | Specify the video card to emulate " << endl;
std::cout << " gfxmem | Specify the how much memory " << endl;
std::cout << " | to allocate to the emulated video card" << endl;
std::cout << " romfile | Insert the ROM file to use " << endl;
std::cout << " " << endl;
}
2020-08-29 23:20:22 +00:00
void display_recognized_machines() {
std::cout << " " << endl;
std::cout << "The following machines are supported by DingusPPC: " << endl;
std::cout << "___________________________________________________" << endl;
std::cout << "| COMMAND | MACHINE RECOGNIZED |" << endl;
std::cout << "___________________________________________________" << endl;
std::cout << " pmg3 | Power Mac G3 Beige " << endl;
std::cout << " pm6100 | Power Mac 6100 " << endl;
std::cout << " " << endl;
}
2020-05-12 18:55:45 +00:00
int main(int argc, char** argv) {
2020-08-22 18:05:08 +00:00
/*
Execution Type:
0 = Realtime (Interpreter)
1 = Realtime (Debugger)
2 = Recompiler (to-do)
The rest will be decided later
*/
2020-08-26 03:07:02 +00:00
uint32_t execution_mode = 0;
uint32_t sys_ram_size[12] = {64, 0, 0, 0};
uint32_t gfx_mem = 2;
bool machine_specified = false;
string machine_name = "";
2020-08-22 18:05:08 +00:00
2020-09-20 21:25:29 +00:00
CLI::App app("DingusPPC CLI");
app.allow_windows_style_options(); /* we want Windows-style options */
app.allow_extras();
cout << endl;
cout << "DingusPPC - Prototype 5bf5 (8/23/2020) " << endl;
cout << "Written by divingkatae and maximumspatium " << endl;
cout << "(c) 2018-2020 The DingusPPC Dev Team. " << endl;
cout << "This is not intended for general use. " << endl;
cout << "Use at your own discretion. " << endl;
cout << endl;
bool realtime_enabled, debugger_enabled;
string machine_str;
string bootrom_path("bootrom.bin");
app.add_flag("-r,--realtime", realtime_enabled,
"Run the emulator in real-time");
app.add_flag("-d,--debugger", debugger_enabled,
"Enter the built-in debugger");
app.add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path")
->check(CLI::ExistingFile);
CLI::Option* machine_opt = app.add_option("-m,--machine",
machine_str, "Specify machine ID");
auto list_cmd = app.add_subcommand("machines",
"Display available machine configurations and exit");
CLI11_PARSE(app, argc, argv);
if (debugger_enabled) {
if (realtime_enabled)
cout << "Both realtime and debugger enabled! Using debugger" << endl;
execution_mode = 1;
}
/* initialize logging */
loguru::g_preamble_date = false;
loguru::g_preamble_time = false;
loguru::g_preamble_thread = false;
if (execution_mode) {
loguru::g_stderr_verbosity = loguru::Verbosity_OFF;
loguru::init(argc, argv);
loguru::add_file("dingusppc.log", loguru::Append, 0);
} else {
loguru::g_stderr_verbosity = 0;
loguru::init(argc, argv);
}
if (*machine_opt) {
LOG_F(INFO, "Machine option was passed in: %s", machine_str.c_str());
} else {
machine_str = machine_name_from_rom(bootrom_path);
if (machine_str.empty()) {
LOG_F(ERROR, "Could not autodetect machine");
return 0;
}
LOG_F(INFO, "Machine was autodetected as: %s", machine_str.c_str());
}
/* handle overriding of machine settings from CLI */
map<string, string> settings;
get_machine_settings(machine_str, settings);
CLI::App sa;
sa.allow_extras();
for (auto& s : settings) {
sa.add_option("--" + s.first, s.second);
}
sa.parse(app.remaining_for_passthrough()); /* TODO: handle exceptions! */
set_machine_settings(settings);
cout << "BootROM path: " << bootrom_path << endl;
cout << "Execution mode: " << execution_mode << endl;
return 0;
2020-08-22 18:05:08 +00:00
if (argc < 1) {
2020-08-26 03:07:02 +00:00
display_help();
return 0;
2020-08-22 18:05:08 +00:00
}
else {
2020-09-20 21:25:29 +00:00
2020-03-26 19:32:24 +00:00
std::string rom_file = "rom.bin", disk_file = "disk.img";
2020-08-26 03:07:02 +00:00
int video_card_vendor = 0x1002, video_card_id = 0x4750;
2020-08-22 18:05:08 +00:00
for (int arg_loop = 1; arg_loop < argc; arg_loop++) {
string checker = argv[arg_loop];
cout << checker << endl;
2020-09-20 21:25:29 +00:00
2020-08-22 18:05:08 +00:00
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;
2020-09-20 21:25:29 +00:00
}
2020-08-29 23:20:22 +00:00
else if ((checker == "help") || (checker == "/help") || (checker == "-help")) {
display_help();
return 0;
2020-09-20 21:25:29 +00:00
}
else if ((checker == "pmg3") || (checker == "/pmg3") || (checker == "-pmg3")) {
machine_name = "PowerMacG3";
machine_specified = true;
2020-09-20 21:25:29 +00:00
}
2020-08-29 23:20:22 +00:00
else if ((checker == "pm6100") || (checker == "/pm6100") || (checker == "-pm6100")) {
machine_name = "PowerMac6100";
machine_specified = true;
2020-09-20 21:25:29 +00:00
}
2020-08-29 23:20:22 +00:00
else if ((checker == "machinehelp") || (checker == "/machinehelp") || (checker == "-machinehelp")) {
machine_name = "MachineHelp";
machine_specified = true;
2020-09-20 21:25:29 +00:00
}
2020-08-22 18:05:08 +00:00
else if ((checker == "ram") || (checker == "/ram") || (checker == "-ram")) {
arg_loop++;
2020-08-26 03:07:02 +00:00
string ram_banks = argv[arg_loop];
uint32_t ram_loop = stoi(ram_banks);
for (int check_loop = 0; check_loop < ram_loop; check_loop++) {
sys_ram_size[check_loop] = stoi(argv[arg_loop]);
}
2020-09-20 21:25:29 +00:00
}
2020-08-22 18:05:08 +00:00
else if ((checker == "gfxmem") || (checker == "/gfxmem") || (checker == "-gfxmem")) {
arg_loop++;
string vram_amount = argv[arg_loop];
gfx_mem = stoi(vram_amount);
LOG_F(INFO, "GFX MEMORY set to: %d", gfx_mem);
}
else if ((checker == "romfile") || (checker == "/romfile") || (checker == "-romfile")) {
arg_loop++;
rom_file = argv[arg_loop];
LOG_F(INFO, "ROM FILE will now be: %s", rom_file.c_str());
2020-09-20 21:25:29 +00:00
}
else if ((checker == "diskimg") || (checker == "/diskimg") || (checker == "-diskimg")) {
arg_loop++;
rom_file = argv[arg_loop];
LOG_F(INFO, "Load the DISK IMAGE from: %s", rom_file.c_str());
2020-09-20 21:25:29 +00:00
}
2020-08-26 03:07:02 +00:00
else if ((checker == "videocard") || (checker == "/videocard") || (checker == "-videocard")) {
arg_loop++;
string check_card = argv[arg_loop];
if (checker.compare("RagePro") == 0) {
video_card_vendor = 0x1002;
video_card_id = 0x4750;
2020-09-20 21:25:29 +00:00
}
2020-08-26 03:07:02 +00:00
else if (checker.compare("Rage128") == 0) {
video_card_vendor = 0x1002;
video_card_id = 0x5046;
2020-09-20 21:25:29 +00:00
}
2020-08-26 03:07:02 +00:00
else if (checker.compare("Radeon7000") == 0) {
video_card_vendor = 0x1002;
video_card_id = 0x5159;
}
2020-03-26 19:32:24 +00:00
}
2020-08-22 18:05:08 +00:00
2020-03-26 19:32:24 +00:00
}
if (machine_specified) {
2020-08-30 00:49:50 +00:00
if (machine_name.compare("PowerMacG3") == 0) {
LOG_F(INFO, "Time to build up a machine");
if (establish_machine_presets(rom_file.c_str(), machine_name, sys_ram_size, gfx_mem)) {
goto bail;
}
2020-09-20 21:25:29 +00:00
}
else if (machine_name.compare("PowerMac6100") == 0) {
LOG_F(ERROR, "Board not yet ready for: %s", machine_name.c_str());
return -1;
2020-09-20 21:25:29 +00:00
}
else {
2020-08-29 23:20:22 +00:00
display_recognized_machines();
return -1;
}
2020-09-20 21:25:29 +00:00
}
2020-08-30 23:14:58 +00:00
else {
2020-08-26 03:07:02 +00:00
if (create_machine_for_rom(rom_file.c_str(), sys_ram_size, gfx_mem)) {
goto bail;
}
}
2020-03-19 14:09:24 +00:00
#ifdef SDL
2020-03-19 14:09:24 +00:00
if (SDL_Init(SDL_INIT_AUDIO)){
LOG_F(ERROR, "SDL_Init error: %s", SDL_GetError());
goto bail;
}
#endif
2020-08-22 18:05:08 +00:00
switch (execution_mode) {
case 0:
ppc_exec();
2020-08-22 18:05:08 +00:00
break;
case 1:
2019-07-17 13:24:34 +00:00
enter_debugger();
2020-08-22 18:05:08 +00:00
break;
default:
LOG_F(ERROR, "Invalid EXECUTION MODE");
return 1;
}
2020-09-20 21:25:29 +00:00
}
bail:
LOG_F(INFO, "Cleaning up...");
delete gMachineObj.release();
return 0;
}