2020-08-23 02:30:12 +00:00
|
|
|
/*!
|
|
|
|
* @file runtime.cpp
|
|
|
|
* Setup and launcher for the runtime.
|
|
|
|
*/
|
|
|
|
|
2022-12-22 22:12:05 +00:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#ifdef OS_POSIX
|
2020-09-04 02:24:50 +00:00
|
|
|
#include <unistd.h>
|
2022-06-23 03:37:46 +00:00
|
|
|
|
2020-09-04 02:24:50 +00:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#elif _WIN32
|
2020-08-27 01:02:24 +00:00
|
|
|
#include <io.h>
|
2022-06-23 03:37:46 +00:00
|
|
|
|
2022-01-02 23:02:10 +00:00
|
|
|
#include "third-party/mman/mman.h"
|
2022-05-06 22:19:37 +00:00
|
|
|
#define NOMINMAX
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2020-08-27 01:02:24 +00:00
|
|
|
#include <Windows.h>
|
2020-09-04 02:24:50 +00:00
|
|
|
#endif
|
2020-09-04 03:56:35 +00:00
|
|
|
|
2020-09-08 00:00:02 +00:00
|
|
|
#include <chrono>
|
2020-09-04 02:24:50 +00:00
|
|
|
#include <cstring>
|
2020-09-08 00:00:02 +00:00
|
|
|
#include <thread>
|
2020-08-23 02:30:12 +00:00
|
|
|
|
|
|
|
#include "runtime.h"
|
|
|
|
|
2022-06-23 03:37:46 +00:00
|
|
|
#include "common/cross_os_debug/xdbg.h"
|
|
|
|
#include "common/goal_constants.h"
|
|
|
|
#include "common/log/log.h"
|
|
|
|
#include "common/util/FileUtil.h"
|
2022-06-26 22:17:11 +00:00
|
|
|
#include "common/versions.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
|
2023-01-07 15:34:01 +00:00
|
|
|
#include "game/discord.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
#include "game/graphics/gfx.h"
|
2022-06-26 22:17:11 +00:00
|
|
|
#include "game/kernel/common/fileio.h"
|
|
|
|
#include "game/kernel/common/kdgo.h"
|
|
|
|
#include "game/kernel/common/kdsnetm.h"
|
|
|
|
#include "game/kernel/common/klink.h"
|
|
|
|
#include "game/kernel/common/klisten.h"
|
|
|
|
#include "game/kernel/common/kmachine.h"
|
|
|
|
#include "game/kernel/common/kmalloc.h"
|
|
|
|
#include "game/kernel/common/kmemcard.h"
|
|
|
|
#include "game/kernel/common/kprint.h"
|
|
|
|
#include "game/kernel/common/kscheme.h"
|
|
|
|
#include "game/kernel/jak1/kboot.h"
|
|
|
|
#include "game/kernel/jak1/klisten.h"
|
|
|
|
#include "game/kernel/jak1/kscheme.h"
|
|
|
|
#include "game/kernel/jak2/kboot.h"
|
|
|
|
#include "game/kernel/jak2/klisten.h"
|
|
|
|
#include "game/kernel/jak2/kscheme.h"
|
2020-08-23 02:30:12 +00:00
|
|
|
#include "game/overlord/dma.h"
|
|
|
|
#include "game/overlord/fake_iso.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
#include "game/overlord/iso.h"
|
2020-08-23 02:30:12 +00:00
|
|
|
#include "game/overlord/iso_cd.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
#include "game/overlord/iso_queue.h"
|
2020-08-23 02:30:12 +00:00
|
|
|
#include "game/overlord/overlord.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
#include "game/overlord/ramdisk.h"
|
2021-06-12 16:55:38 +00:00
|
|
|
#include "game/overlord/sbank.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
#include "game/overlord/srpc.h"
|
2022-06-10 23:04:16 +00:00
|
|
|
#include "game/overlord/ssound.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
#include "game/overlord/stream.h"
|
|
|
|
#include "game/system/Deci2Server.h"
|
|
|
|
#include "game/system/iop_thread.h"
|
2021-05-01 04:32:19 +00:00
|
|
|
#include "game/system/vm/dmac.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
#include "game/system/vm/vm.h"
|
|
|
|
#include "sce/deci2.h"
|
|
|
|
#include "sce/iop.h"
|
|
|
|
#include "sce/libcdvd_ee.h"
|
|
|
|
#include "sce/sif_ee.h"
|
|
|
|
#include "system/SystemThread.h"
|
2020-10-31 18:07:43 +00:00
|
|
|
|
2020-08-23 02:30:12 +00:00
|
|
|
u8* g_ee_main_mem = nullptr;
|
2021-03-10 04:51:28 +00:00
|
|
|
std::thread::id g_main_thread_id = std::thread::id();
|
2022-06-26 22:17:11 +00:00
|
|
|
GameVersion g_game_version = GameVersion::Jak1;
|
2020-08-23 02:30:12 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-09-26 01:11:27 +00:00
|
|
|
int g_argc = 0;
|
2023-03-18 00:35:26 +00:00
|
|
|
const char** g_argv = nullptr;
|
2020-09-26 01:11:27 +00:00
|
|
|
|
2020-08-23 02:30:12 +00:00
|
|
|
/*!
|
|
|
|
* SystemThread function for running the DECI2 communication with the GOAL compiler.
|
|
|
|
*/
|
2020-08-27 01:02:24 +00:00
|
|
|
|
2020-09-04 03:56:35 +00:00
|
|
|
void deci2_runner(SystemThreadInterface& iface) {
|
2020-09-04 02:24:50 +00:00
|
|
|
// callback function so the server knows when to give up and shutdown
|
2020-09-04 03:56:35 +00:00
|
|
|
std::function<bool()> shutdown_callback = [&]() { return iface.get_want_exit(); };
|
2020-09-04 02:24:50 +00:00
|
|
|
|
|
|
|
// create and register server
|
2022-05-06 22:19:37 +00:00
|
|
|
Deci2Server server(shutdown_callback, DECI2_PORT);
|
2020-09-04 02:24:50 +00:00
|
|
|
ee::LIBRARY_sceDeci2_register(&server);
|
|
|
|
|
|
|
|
// now its ok to continue with initialization
|
2020-09-04 03:56:35 +00:00
|
|
|
iface.initialization_complete();
|
2020-09-04 02:24:50 +00:00
|
|
|
|
|
|
|
// in our own thread, wait for the EE to register the first protocol driver
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("[DECI2] Waiting for EE to register protos");
|
2022-07-07 01:18:08 +00:00
|
|
|
if (!server.wait_for_protos_ready()) {
|
|
|
|
// requested shutdown before protos became ready.
|
|
|
|
return;
|
|
|
|
}
|
2020-09-04 02:24:50 +00:00
|
|
|
// then allow the server to accept connections
|
2022-05-30 15:06:11 +00:00
|
|
|
bool server_ok = server.init_server();
|
|
|
|
if (!server_ok) {
|
|
|
|
lg::error("[DECI2] failed to initialize, REPL will not work.\n");
|
2020-08-28 17:59:20 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("[DECI2] Waiting for listener...");
|
2020-09-04 02:24:50 +00:00
|
|
|
bool saw_listener = false;
|
2020-09-04 03:56:35 +00:00
|
|
|
while (!iface.get_want_exit()) {
|
2022-05-30 15:06:11 +00:00
|
|
|
if (server_ok && server.is_client_connected()) {
|
2020-09-04 02:24:50 +00:00
|
|
|
if (!saw_listener) {
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("[DECI2] Connected!");
|
2020-09-04 02:24:50 +00:00
|
|
|
}
|
|
|
|
saw_listener = true;
|
|
|
|
// we have a listener, run!
|
2022-05-06 22:19:37 +00:00
|
|
|
server.read_data();
|
2020-09-04 02:24:50 +00:00
|
|
|
} else {
|
|
|
|
// no connection yet. Do a sleep so we don't spam checking the listener.
|
2020-09-08 18:12:04 +00:00
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(50000));
|
2020-09-04 02:24:50 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-23 02:30:12 +00:00
|
|
|
}
|
2020-08-27 01:02:24 +00:00
|
|
|
|
2020-08-23 02:30:12 +00:00
|
|
|
// EE System
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* SystemThread Function for the EE (PS2 Main CPU)
|
|
|
|
*/
|
2020-09-04 02:24:50 +00:00
|
|
|
void ee_runner(SystemThreadInterface& iface) {
|
2020-08-23 02:30:12 +00:00
|
|
|
// Allocate Main RAM. Must have execute enabled.
|
|
|
|
if (EE_MEM_LOW_MAP) {
|
|
|
|
g_ee_main_mem =
|
|
|
|
(u8*)mmap((void*)0x10000000, EE_MAIN_MEM_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE,
|
2022-12-22 22:12:05 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// has no map_populate
|
|
|
|
MAP_ANONYMOUS | MAP_32BIT | MAP_PRIVATE, 0, 0);
|
|
|
|
#else
|
2020-08-23 02:30:12 +00:00
|
|
|
MAP_ANONYMOUS | MAP_32BIT | MAP_PRIVATE | MAP_POPULATE, 0, 0);
|
2022-12-22 22:12:05 +00:00
|
|
|
#endif
|
2020-08-23 02:30:12 +00:00
|
|
|
} else {
|
|
|
|
g_ee_main_mem =
|
|
|
|
(u8*)mmap((void*)EE_MAIN_MEM_MAP, EE_MAIN_MEM_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE,
|
|
|
|
MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_ee_main_mem == (u8*)(-1)) {
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("Failed to initialize main memory! {}", strerror(errno));
|
2020-09-04 02:24:50 +00:00
|
|
|
iface.initialization_complete();
|
2020-08-23 02:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("Main memory mapped at 0x{:016x}", (u64)(g_ee_main_mem));
|
|
|
|
lg::debug("Main memory size 0x{:x} bytes ({:.3f} MB)", EE_MAIN_MEM_SIZE,
|
|
|
|
(double)EE_MAIN_MEM_SIZE / (1 << 20));
|
2020-08-23 02:30:12 +00:00
|
|
|
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("[EE] Initialization complete!");
|
2020-09-04 02:24:50 +00:00
|
|
|
iface.initialization_complete();
|
2020-08-23 02:30:12 +00:00
|
|
|
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("[EE] Run!");
|
2020-08-23 02:30:12 +00:00
|
|
|
memset((void*)g_ee_main_mem, 0, EE_MAIN_MEM_SIZE);
|
2020-09-26 01:11:27 +00:00
|
|
|
|
2021-10-02 03:12:34 +00:00
|
|
|
// prevent access to the first 512 kB of memory.
|
2020-09-26 01:11:27 +00:00
|
|
|
// On the PS2 this is the kernel and can't be accessed either.
|
|
|
|
// this may not work well on systems with a page size > 1 MB.
|
2020-10-31 18:07:43 +00:00
|
|
|
mprotect((void*)g_ee_main_mem, EE_MAIN_MEM_LOW_PROTECT, PROT_NONE);
|
2020-08-23 02:30:12 +00:00
|
|
|
fileio_init_globals();
|
2022-06-26 22:17:11 +00:00
|
|
|
jak1::kboot_init_globals();
|
|
|
|
jak2::kboot_init_globals();
|
|
|
|
|
|
|
|
kboot_init_globals_common();
|
2020-08-23 02:30:12 +00:00
|
|
|
kdgo_init_globals();
|
2022-06-26 22:17:11 +00:00
|
|
|
kdsnetm_init_globals_common();
|
2020-08-23 02:30:12 +00:00
|
|
|
klink_init_globals();
|
|
|
|
|
2022-06-26 22:17:11 +00:00
|
|
|
kmachine_init_globals_common();
|
|
|
|
jak1::kscheme_init_globals();
|
|
|
|
jak2::kscheme_init_globals();
|
|
|
|
kscheme_init_globals_common();
|
|
|
|
kmalloc_init_globals_common();
|
2020-08-23 02:30:12 +00:00
|
|
|
|
|
|
|
klisten_init_globals();
|
2022-06-26 22:17:11 +00:00
|
|
|
jak1::klisten_init_globals();
|
|
|
|
jak2::klisten_init_globals();
|
|
|
|
|
2020-08-23 02:30:12 +00:00
|
|
|
kmemcard_init_globals();
|
2022-06-26 22:17:11 +00:00
|
|
|
kprint_init_globals_common();
|
2020-08-23 02:30:12 +00:00
|
|
|
|
2020-12-28 23:37:05 +00:00
|
|
|
// Added for OpenGOAL's debugger
|
|
|
|
xdbg::allow_debugging();
|
|
|
|
|
2022-06-26 22:17:11 +00:00
|
|
|
switch (g_game_version) {
|
|
|
|
case GameVersion::Jak1:
|
|
|
|
jak1::goal_main(g_argc, g_argv);
|
|
|
|
break;
|
|
|
|
case GameVersion::Jak2:
|
|
|
|
jak2::goal_main(g_argc, g_argv);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ASSERT_MSG(false, "Unsupported game version");
|
|
|
|
}
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("[EE] Done!");
|
2020-08-23 02:30:12 +00:00
|
|
|
|
|
|
|
// // kill the IOP todo
|
|
|
|
iop::LIBRARY_kill();
|
|
|
|
|
|
|
|
// after main returns, trigger a shutdown.
|
2020-09-04 02:24:50 +00:00
|
|
|
iface.trigger_shutdown();
|
2020-08-23 02:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* SystemThread function for running the IOP (separate I/O Processor)
|
|
|
|
*/
|
2020-09-04 02:24:50 +00:00
|
|
|
void iop_runner(SystemThreadInterface& iface) {
|
2020-08-23 02:30:12 +00:00
|
|
|
IOP iop;
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("[IOP] Restart!");
|
2020-08-23 02:30:12 +00:00
|
|
|
iop.reset_allocator();
|
|
|
|
ee::LIBRARY_sceSif_register(&iop);
|
|
|
|
iop::LIBRARY_register(&iop);
|
2022-08-14 21:21:02 +00:00
|
|
|
Gfx::register_vsync_callback([&iop]() { iop.kernel.signal_vblank(); });
|
2020-08-23 02:30:12 +00:00
|
|
|
|
|
|
|
// todo!
|
|
|
|
dma_init_globals();
|
|
|
|
iso_init_globals();
|
|
|
|
fake_iso_init_globals();
|
|
|
|
// iso_api
|
|
|
|
iso_cd_init_globals();
|
|
|
|
iso_queue_init_globals();
|
|
|
|
// isocommon
|
|
|
|
// overlord
|
|
|
|
ramdisk_init_globals();
|
2021-06-12 16:55:38 +00:00
|
|
|
sbank_init_globals();
|
2020-08-23 02:30:12 +00:00
|
|
|
// soundcommon
|
|
|
|
srpc_init_globals();
|
|
|
|
// ssound
|
2020-11-22 17:59:55 +00:00
|
|
|
stream_init_globals();
|
2020-08-23 02:30:12 +00:00
|
|
|
|
2020-09-04 02:24:50 +00:00
|
|
|
iface.initialization_complete();
|
2020-08-23 02:30:12 +00:00
|
|
|
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("[IOP] Wait for OVERLORD to start...");
|
2020-08-23 02:30:12 +00:00
|
|
|
iop.wait_for_overlord_start_cmd();
|
|
|
|
if (iop.status == IOP_OVERLORD_INIT) {
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("[IOP] Run!");
|
2020-08-23 02:30:12 +00:00
|
|
|
} else {
|
2021-01-06 17:16:39 +00:00
|
|
|
lg::debug("[IOP] Shutdown!");
|
2020-08-23 02:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
iop.reset_allocator();
|
|
|
|
|
|
|
|
// init
|
|
|
|
|
2022-07-22 15:54:27 +00:00
|
|
|
bool complete = false;
|
|
|
|
start_overlord_wrapper(iop.overlord_argc, iop.overlord_argv, &complete); // todo!
|
|
|
|
while (complete == false) {
|
2022-07-27 01:15:37 +00:00
|
|
|
iop.wait_run_iop(iop.kernel.dispatch());
|
2022-07-22 15:54:27 +00:00
|
|
|
}
|
2020-08-23 02:30:12 +00:00
|
|
|
|
|
|
|
// unblock the EE, the overlord is set up!
|
|
|
|
iop.signal_overlord_init_finish();
|
|
|
|
|
|
|
|
// IOP Kernel loop
|
2020-09-04 02:24:50 +00:00
|
|
|
while (!iface.get_want_exit() && !iop.want_exit) {
|
2022-07-27 01:15:37 +00:00
|
|
|
// The IOP scheduler informs us of how many microseconds are left until it has something to do.
|
|
|
|
// So we can wait for that long or until something else needs it to wake up.
|
|
|
|
iop.wait_run_iop(iop.kernel.dispatch());
|
2020-08-23 02:30:12 +00:00
|
|
|
}
|
2022-08-14 21:21:02 +00:00
|
|
|
|
|
|
|
Gfx::clear_vsync_callback();
|
2020-08-23 02:30:12 +00:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2021-05-01 04:32:19 +00:00
|
|
|
/*!
|
|
|
|
* SystemThread function for running NothingTM.
|
|
|
|
*/
|
|
|
|
void null_runner(SystemThreadInterface& iface) {
|
|
|
|
iface.initialization_complete();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* SystemThread function for running the PS2 DMA controller.
|
|
|
|
* This does not actually emulate the DMAC, it only fakes its existence enough that we can debug
|
|
|
|
* the DMA packets the original game sends. The port will replace all DMAC code.
|
|
|
|
*/
|
|
|
|
void dmac_runner(SystemThreadInterface& iface) {
|
|
|
|
VM::subscribe_component();
|
|
|
|
|
|
|
|
VM::dmac_init_globals();
|
|
|
|
|
|
|
|
iface.initialization_complete();
|
|
|
|
|
|
|
|
while (!iface.get_want_exit() && !VM::vm_want_exit()) {
|
2021-09-26 15:41:58 +00:00
|
|
|
// for (int i = 0; i < 10; ++i) {
|
|
|
|
// if (VM::dmac_ch[i]->chcr.str) {
|
|
|
|
// // lg::info("DMA detected on channel {}, clearing", i);
|
|
|
|
// VM::dmac_ch[i]->chcr.str = 0;
|
|
|
|
// }
|
|
|
|
// }
|
2021-05-01 04:32:19 +00:00
|
|
|
// avoid running the DMAC on full blast (this does not sync to its clockrate)
|
2021-12-26 17:33:51 +00:00
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(50000));
|
2021-05-01 04:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VM::unsubscribe_component();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-23 02:30:12 +00:00
|
|
|
/*!
|
|
|
|
* Main function to launch the runtime.
|
2021-05-01 04:32:19 +00:00
|
|
|
* GOAL kernel arguments are currently ignored.
|
2020-08-23 02:30:12 +00:00
|
|
|
*/
|
2023-03-18 00:35:26 +00:00
|
|
|
RuntimeExitStatus exec_runtime(GameLaunchOptions game_options, int argc, const char** argv) {
|
2020-09-26 01:11:27 +00:00
|
|
|
g_argc = argc;
|
|
|
|
g_argv = argv;
|
2021-03-10 04:51:28 +00:00
|
|
|
g_main_thread_id = std::this_thread::get_id();
|
|
|
|
|
2023-03-10 04:13:01 +00:00
|
|
|
bool enable_display = !game_options.disable_display;
|
|
|
|
VM::use = !game_options.disable_debug_vm;
|
|
|
|
g_game_version = game_options.game_version;
|
2020-08-23 02:30:12 +00:00
|
|
|
|
2023-01-07 15:34:01 +00:00
|
|
|
// set up discord stuff
|
|
|
|
gStartTime = time(nullptr);
|
|
|
|
init_discord_rpc();
|
|
|
|
|
2022-01-22 02:11:57 +00:00
|
|
|
// initialize graphics first - the EE code will upload textures during boot and we
|
|
|
|
// want the graphics system to catch them.
|
|
|
|
if (enable_display) {
|
2022-07-01 01:11:58 +00:00
|
|
|
Gfx::Init(g_game_version);
|
2022-01-22 02:11:57 +00:00
|
|
|
}
|
|
|
|
|
2020-08-23 02:30:12 +00:00
|
|
|
// step 1: sce library prep
|
|
|
|
iop::LIBRARY_INIT();
|
|
|
|
ee::LIBRARY_INIT_sceCd();
|
2020-09-04 02:24:50 +00:00
|
|
|
ee::LIBRARY_INIT_sceDeci2();
|
2020-08-23 02:30:12 +00:00
|
|
|
ee::LIBRARY_INIT_sceSif();
|
|
|
|
|
|
|
|
// step 2: system prep
|
2021-05-01 04:32:19 +00:00
|
|
|
VM::vm_prepare(); // our fake ps2 VM needs to be prepared
|
2020-08-23 02:30:12 +00:00
|
|
|
SystemThreadManager tm;
|
|
|
|
auto& deci_thread = tm.create_thread("DMP");
|
|
|
|
auto& iop_thread = tm.create_thread("IOP");
|
|
|
|
auto& ee_thread = tm.create_thread("EE");
|
2021-05-01 04:32:19 +00:00
|
|
|
auto& vm_dmac_thread = tm.create_thread("VM-DMAC");
|
2020-08-23 02:30:12 +00:00
|
|
|
|
|
|
|
// step 3: start the EE!
|
|
|
|
iop_thread.start(iop_runner);
|
2020-08-28 17:59:20 +00:00
|
|
|
deci_thread.start(deci2_runner);
|
2022-05-06 22:19:37 +00:00
|
|
|
ee_thread.start(ee_runner);
|
2021-05-01 04:32:19 +00:00
|
|
|
if (VM::use) {
|
|
|
|
vm_dmac_thread.start(dmac_runner);
|
|
|
|
}
|
2020-09-04 02:24:50 +00:00
|
|
|
|
2021-03-10 04:51:28 +00:00
|
|
|
// step 4: wait for EE to signal a shutdown. meanwhile, run video loop on main thread.
|
|
|
|
// TODO relegate this to its own function
|
|
|
|
if (enable_display) {
|
2023-01-14 21:26:17 +00:00
|
|
|
try {
|
|
|
|
Gfx::Loop([]() { return MasterExit == RuntimeExitStatus::RUNNING; });
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
fmt::print("Exception thrown from graphics loop: {}\n", e.what());
|
|
|
|
fmt::print("Everything will crash now. good luck\n");
|
|
|
|
throw;
|
|
|
|
}
|
2021-03-10 04:51:28 +00:00
|
|
|
}
|
|
|
|
|
2022-06-10 23:04:16 +00:00
|
|
|
// hack to make the IOP die quicker if it's loading/unloading music
|
|
|
|
gMusicFade = 0;
|
|
|
|
|
2022-08-20 14:32:00 +00:00
|
|
|
// if we have no display, wait here for DECI to shutdown
|
2020-08-23 02:30:12 +00:00
|
|
|
deci_thread.join();
|
2022-08-20 14:32:00 +00:00
|
|
|
|
|
|
|
// fully shut down EE first before stopping the other threads
|
|
|
|
ee_thread.join();
|
2020-08-23 02:30:12 +00:00
|
|
|
|
|
|
|
// to be extra sure
|
|
|
|
tm.shutdown();
|
|
|
|
|
|
|
|
// join and exit
|
|
|
|
tm.join();
|
2022-08-20 14:32:00 +00:00
|
|
|
|
|
|
|
// kill renderer after all threads are stopped.
|
|
|
|
// this makes sure the std::shared_ptr<Display> is destroyed in the main thread.
|
|
|
|
if (enable_display) {
|
|
|
|
Gfx::Exit();
|
|
|
|
}
|
2022-12-22 18:41:33 +00:00
|
|
|
lg::info("GOAL Runtime Shutdown (code {})", fmt::underlying(MasterExit));
|
2022-06-22 01:26:11 +00:00
|
|
|
munmap(g_ee_main_mem, EE_MAIN_MEM_SIZE);
|
2023-01-07 15:34:01 +00:00
|
|
|
Discord_Shutdown();
|
2020-09-06 20:58:25 +00:00
|
|
|
return MasterExit;
|
2020-09-04 02:24:50 +00:00
|
|
|
}
|