2020-02-28 16:04:28 +00:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
// The main runfile - main.cpp
|
|
|
|
// This is where the magic begins
|
2019-07-02 02:15:33 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
#include "debugger/debugger.h"
|
2020-10-16 04:10:17 +00:00
|
|
|
#include "execution/interpreter_loop.h"
|
2020-05-12 18:55:45 +00:00
|
|
|
#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>
|
2019-07-02 02:15:33 +00:00
|
|
|
#include <stdio.h>
|
2020-09-26 00:54:14 +00:00
|
|
|
#include <thirdparty/CLI11/CLI11.hpp>
|
2020-03-23 03:15:12 +00:00
|
|
|
#include <thirdparty/SDL2/include/SDL.h>
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <thirdparty/loguru/loguru.hpp>
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
static string appDescription = string(
|
|
|
|
"\nDingusPPC - Prototype 5bf5 (8/23/2020) "
|
|
|
|
"\nWritten by divingkatae and maximumspatium "
|
|
|
|
"\n(c) 2018-2020 The DingusPPC Dev Team. "
|
|
|
|
"\nThis is not intended for general use. "
|
|
|
|
"\nUse at your own discretion. "
|
|
|
|
"\n"
|
|
|
|
);
|
2020-08-26 03:07:02 +00:00
|
|
|
|
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-10-06 09:01:13 +00:00
|
|
|
uint32_t execution_mode = 0;
|
2020-08-22 18:05:08 +00:00
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
CLI::App app(appDescription);
|
2020-09-20 21:25:29 +00:00
|
|
|
app.allow_windows_style_options(); /* we want Windows-style options */
|
|
|
|
app.allow_extras();
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
auto list_cmd = app.add_subcommand("list",
|
2020-09-20 21:25:29 +00:00
|
|
|
"Display available machine configurations and exit");
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
string sub_arg;
|
|
|
|
|
|
|
|
list_cmd->add_option("machines", sub_arg, "List supported machines");
|
|
|
|
list_cmd->add_option("properties", sub_arg, "List available properties");
|
|
|
|
|
2020-09-20 21:25:29 +00:00
|
|
|
CLI11_PARSE(app, argc, argv);
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
if (*list_cmd) {
|
2020-10-13 02:24:54 +00:00
|
|
|
if (sub_arg == "machines") {
|
|
|
|
list_machines();
|
|
|
|
} else if (sub_arg == "properties") {
|
|
|
|
list_properties();
|
|
|
|
} else {
|
|
|
|
cout << "Unknown list subcommand " << sub_arg << endl;
|
|
|
|
}
|
|
|
|
return 0;
|
2020-10-06 09:01:13 +00:00
|
|
|
}
|
|
|
|
|
2020-09-20 21:25:29 +00:00
|
|
|
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;
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
if (!execution_mode) {
|
2020-09-20 21:25:29 +00:00
|
|
|
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;
|
2020-10-06 09:01:13 +00:00
|
|
|
}
|
2020-10-04 16:58:21 +00:00
|
|
|
else {
|
|
|
|
LOG_F(INFO, "Machine was autodetected as: %s", machine_str.c_str());
|
2020-09-20 21:25:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
/* handle overriding of machine settings from command line */
|
2020-09-20 21:25:29 +00:00
|
|
|
map<string, string> settings;
|
2020-10-06 09:01:13 +00:00
|
|
|
if (get_machine_settings(machine_str, settings) < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2020-09-20 21:25:29 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-10-06 09:01:13 +00:00
|
|
|
if (create_machine_for_id(machine_str, bootrom_path) < 0) {
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
2020-05-08 20:32:29 +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());
|
2020-10-04 16:58:21 +00:00
|
|
|
return 0;
|
2020-03-19 14:09:24 +00:00
|
|
|
}
|
2020-05-08 20:32:29 +00:00
|
|
|
#endif
|
2020-10-06 09:01:13 +00:00
|
|
|
|
2020-10-04 16:58:21 +00:00
|
|
|
switch (execution_mode) {
|
2020-08-22 18:05:08 +00:00
|
|
|
case 0:
|
2020-10-16 04:10:17 +00:00
|
|
|
interpreter_main_loop();
|
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");
|
2020-10-04 16:58:21 +00:00
|
|
|
return 0;
|
2020-09-20 21:25:29 +00:00
|
|
|
}
|
2020-10-06 09:01:13 +00:00
|
|
|
|
|
|
|
bail:
|
2020-03-13 21:49:58 +00:00
|
|
|
LOG_F(INFO, "Cleaning up...");
|
|
|
|
|
|
|
|
delete gMachineObj.release();
|
2019-07-02 02:15:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|