mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-02-09 23:30:51 +00:00
While Emscripten has an SDL compabtility layer, it assumes that the code is executing in the main browser process (and thus has access to them DOM). The Infinite Mac project runs emulators in a worker thread (for better performance) and has a custom API for the display, sound, input, etc. Similarly, it does not need the cross-platform sound support from cubeb, there there is a sound API as well. This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be skipped when targeting Emscripten, and instead *_js.cpp files are used instead (this is the cross-platform convention used by Chromium[^1], and could be extended for other targets). For hostevents.cpp and soundserver.cpp the entire file was replaced, whereas for videoctrl.cpp there was enough shared logic that it was kept, and the platform-specific bits were moved behind a Display class that can have per-platform implementations. For cases where we need additional private fields in the platform-specific classes, we use a PIMPL pattern. The *_js.cpp files with implementations are not included in this commit, since they are closely tied to the Infinite Mac project, and will live in its fork of DingusPPC. [^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
224 lines
6.4 KiB
C++
224 lines
6.4 KiB
C++
/*
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
|
Copyright (C) 2018-23 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/>.
|
|
*/
|
|
|
|
// The main runfile - main.cpp
|
|
// This is where the magic begins
|
|
|
|
#include <core/hostevents.h>
|
|
#include <core/timermanager.h>
|
|
#include <cpu/ppc/ppcemu.h>
|
|
#include <debugger/debugger.h>
|
|
#include <machines/machinefactory.h>
|
|
#include <machines/machineproperties.h>
|
|
#include <utils/profiler.h>
|
|
#include <main.h>
|
|
|
|
#include <cinttypes>
|
|
#include <csignal>
|
|
#include <cstring>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <stdio.h>
|
|
#include <CLI11.hpp>
|
|
#include <loguru.hpp>
|
|
|
|
using namespace std;
|
|
|
|
void sigint_handler(int signum) {
|
|
enter_debugger();
|
|
|
|
LOG_F(INFO, "Shutting down...");
|
|
|
|
delete gMachineObj.release();
|
|
cleanup();
|
|
exit(0);
|
|
}
|
|
|
|
void sigabrt_handler(int signum) {
|
|
LOG_F(INFO, "Shutting down...");
|
|
|
|
delete gMachineObj.release();
|
|
cleanup();
|
|
}
|
|
|
|
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"
|
|
);
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
uint32_t execution_mode = interpreter;
|
|
|
|
CLI::App app(appDescription);
|
|
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");
|
|
|
|
auto list_cmd = app.add_subcommand("list",
|
|
"Display available machine configurations and exit");
|
|
|
|
string sub_arg;
|
|
|
|
list_cmd->add_option("machines", sub_arg, "List supported machines");
|
|
list_cmd->add_option("properties", sub_arg, "List available properties");
|
|
|
|
CLI11_PARSE(app, argc, argv);
|
|
|
|
if (*list_cmd) {
|
|
if (sub_arg == "machines") {
|
|
MachineFactory::list_machines();
|
|
} else if (sub_arg == "properties") {
|
|
MachineFactory::list_properties();
|
|
} else {
|
|
cout << "Unknown list subcommand " << sub_arg << endl;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
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 = loguru::Verbosity_INFO;
|
|
loguru::init(argc, argv);
|
|
}
|
|
|
|
if (*machine_opt) {
|
|
LOG_F(INFO, "Machine option was passed in: %s", machine_str.c_str());
|
|
} else {
|
|
machine_str = MachineFactory::machine_name_from_rom(bootrom_path);
|
|
if (machine_str.empty()) {
|
|
LOG_F(ERROR, "Could not autodetect machine");
|
|
return 1;
|
|
}
|
|
else {
|
|
LOG_F(INFO, "Machine was autodetected as: %s", machine_str.c_str());
|
|
}
|
|
}
|
|
|
|
/* handle overriding of machine settings from command line */
|
|
map<string, string> settings;
|
|
if (MachineFactory::get_machine_settings(machine_str, settings) < 0) {
|
|
return 1;
|
|
}
|
|
|
|
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! */
|
|
|
|
MachineFactory::set_machine_settings(settings);
|
|
|
|
cout << "BootROM path: " << bootrom_path << endl;
|
|
cout << "Execution mode: " << execution_mode << endl;
|
|
|
|
if (!init()) {
|
|
LOG_F(ERROR, "Cannot initialize");
|
|
return 1;
|
|
}
|
|
|
|
// initialize global profiler object
|
|
gProfilerObj.reset(new Profiler());
|
|
|
|
if (MachineFactory::create_machine_for_id(machine_str, bootrom_path) < 0) {
|
|
goto bail;
|
|
}
|
|
|
|
// graceful handling of fatal errors
|
|
loguru::set_fatal_handler([](const loguru::Message& message) {
|
|
// Make sure the reason for the failure is visible (it may have been
|
|
// sent to the logfile only).
|
|
cerr << message.preamble << message.indentation << message.prefix << message.message << endl;
|
|
enter_debugger();
|
|
|
|
abort();
|
|
});
|
|
|
|
// redirect SIGINT to our own handler
|
|
signal(SIGINT, sigint_handler);
|
|
|
|
// redirect SIGABRT to our own handler
|
|
signal(SIGABRT, sigabrt_handler);
|
|
|
|
// set up system wide event polling using
|
|
// default Macintosh polling rate of 11 ms
|
|
TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(11), [] {
|
|
EventManager::get_instance()->poll_events();
|
|
});
|
|
|
|
switch (execution_mode) {
|
|
case interpreter:
|
|
ppc_exec();
|
|
break;
|
|
case debugger:
|
|
enter_debugger();
|
|
break;
|
|
default:
|
|
LOG_F(ERROR, "Invalid EXECUTION MODE");
|
|
return 1;
|
|
}
|
|
|
|
bail:
|
|
LOG_F(INFO, "Cleaning up...");
|
|
|
|
delete gMachineObj.release();
|
|
|
|
cleanup();
|
|
|
|
return 0;
|
|
}
|