Add GameEntry.thread_create_callback (#78)

This commit is contained in:
Ethan Lafrenais 2025-01-12 23:43:53 -05:00 committed by GitHub
parent d17a3f34cb
commit 9721c8de3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View file

@ -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 {

View file

@ -420,12 +420,23 @@ extern "C" void do_break(uint32_t vram) {
exit(EXIT_FAILURE);
}
std::optional<std::u8string> current_game = std::nullopt;
std::atomic<GameStatus> 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<std::u8string> current_game = std::nullopt;
std::atomic<GameStatus> game_status = GameStatus::None;
std::u8string recomp::current_game_id() {
std::lock_guard<std::mutex> lock(current_game_mutex);
return current_game.value();