Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger: Expose API to reset game #14494

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Core/Debugger/WebSocket/GameSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Core/Debugger/WebSocket/GameSubscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@

DebuggerSubscriber *WebSocketGameInit(DebuggerEventHandlerMap &map);

void WebSocketGameReset(DebuggerRequest &req);
void WebSocketGameStatus(DebuggerRequest &req);
void WebSocketVersion(DebuggerRequest &req);
3 changes: 2 additions & 1 deletion Core/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down