diff --git a/librecomp/include/librecomp/game.hpp b/librecomp/include/librecomp/game.hpp index 9f11854..37bab29 100644 --- a/librecomp/include/librecomp/game.hpp +++ b/librecomp/include/librecomp/game.hpp @@ -30,6 +30,8 @@ namespace recomp { gpr entrypoint_address; void (*entrypoint)(uint8_t* rdram, recomp_context* context); + void (*thread_create_callback)(uint8_t* rdram, recomp_context* context); + std::u8string stored_filename() const; }; struct Version { diff --git a/librecomp/src/recomp.cpp b/librecomp/src/recomp.cpp index 1c173da..562d382 100644 --- a/librecomp/src/recomp.cpp +++ b/librecomp/src/recomp.cpp @@ -420,12 +420,23 @@ extern "C" void do_break(uint32_t vram) { exit(EXIT_FAILURE); } +std::optional current_game = std::nullopt; +std::atomic game_status = GameStatus::None; + void run_thread_function(uint8_t* rdram, uint64_t addr, uint64_t sp, uint64_t arg) { + auto find_it = game_roms.find(current_game.value()); + const recomp::GameEntry& game_entry = find_it->second; + recomp_context ctx{}; ctx.r29 = sp; ctx.r4 = arg; ctx.mips3_float_mode = 0; ctx.f_odd = &ctx.f0.u32h; + + if (game_entry.thread_create_callback != nullptr) { + game_entry.thread_create_callback(rdram, &ctx); + } + recomp_func_t* func = get_function(addr); func(rdram, &ctx); } @@ -462,9 +473,6 @@ void init(uint8_t* rdram, recomp_context* ctx, gpr entrypoint) { MEM_W(osMemSize, 0) = 8 * 1024 * 1024; // 8MB } -std::optional current_game = std::nullopt; -std::atomic game_status = GameStatus::None; - std::u8string recomp::current_game_id() { std::lock_guard lock(current_game_mutex); return current_game.value();