From 6e128eb5103ea122800066b5d9279e0fb5897b64 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 30 May 2021 21:12:30 -0700 Subject: [PATCH] Debugger: Expose API to reset game. This can be useful to put the game back to a known-good state before setting up breakpoints, overwriting memory, and processing replay data. --- Core/Debugger/WebSocket/GameSubscriber.cpp | 33 ++++++++++++++++++++++ Core/Debugger/WebSocket/GameSubscriber.h | 1 + Core/System.cpp | 3 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Core/Debugger/WebSocket/GameSubscriber.cpp b/Core/Debugger/WebSocket/GameSubscriber.cpp index 0acd4a9b3e..2d8bb1a116 100644 --- a/Core/Debugger/WebSocket/GameSubscriber.cpp +++ b/Core/Debugger/WebSocket/GameSubscriber.cpp @@ -18,15 +18,48 @@ #include "Core/Debugger/WebSocket/GameSubscriber.h" #include "Core/Debugger/WebSocket/WebSocketUtils.h" #include "Core/ELF/ParamSFO.h" +#include "Core/Host.h" #include "Core/System.h" DebuggerSubscriber *WebSocketGameInit(DebuggerEventHandlerMap &map) { + map["game.reset"] = &WebSocketGameReset; map["game.status"] = &WebSocketGameStatus; map["version"] = &WebSocketVersion; return nullptr; } +// Reset emulation (game.reset) +// +// Use this if you need to break on start and do something before the game starts. +// +// Parameters: +// - break: optional boolean, true to break CPU on start. Use cpu.resume afterward. +// +// Response (same event name) with no extra data or error. +void WebSocketGameReset(DebuggerRequest &req) { + if (!PSP_IsInited()) + return req.Fail("Game not running"); + + bool needBreak = false; + if (!req.ParamBool("break", &needBreak, DebuggerParamType::OPTIONAL)) + return; + + if (needBreak) + PSP_CoreParameter().startBreak = true; + + PSP_Shutdown(); + std::string resetError; + if (!PSP_Init(PSP_CoreParameter(), &resetError)) { + ERROR_LOG(BOOT, "Error resetting: %s", resetError.c_str()); + return req.Fail("Could not reset"); + } + host->BootDone(); + host->UpdateDisassembly(); + + req.Respond(); +} + // Check game status (game.status) // // No parameters. diff --git a/Core/Debugger/WebSocket/GameSubscriber.h b/Core/Debugger/WebSocket/GameSubscriber.h index e3d08f4522..af43c692d0 100644 --- a/Core/Debugger/WebSocket/GameSubscriber.h +++ b/Core/Debugger/WebSocket/GameSubscriber.h @@ -21,5 +21,6 @@ DebuggerSubscriber *WebSocketGameInit(DebuggerEventHandlerMap &map); +void WebSocketGameReset(DebuggerRequest &req); void WebSocketGameStatus(DebuggerRequest &req); void WebSocketVersion(DebuggerRequest &req); diff --git a/Core/System.cpp b/Core/System.cpp index c6e510ed88..d49eb039d7 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -468,7 +468,8 @@ bool PSP_InitUpdate(std::string *error_string) { } bool PSP_Init(const CoreParameter &coreParam, std::string *error_string) { - PSP_InitStart(coreParam, error_string); + if (!PSP_InitStart(coreParam, error_string)) + return false; while (!PSP_InitUpdate(error_string)) sleep_ms(10);