Cleanup a lot of the bootup state management.

This commit is contained in:
Henrik Rydgård committed 2025-03-30 14:02:29 +02:00
1 parent e6ea158dcc
commit 088a02bfdb
30 files changed
+239 -257

No files matched your search

@@ -107,12 +107,15 @@ void WebSocketCPUResume(DebuggerRequest &req) {
// - ticks: number of CPU cycles into emulation.
void WebSocketCPUStatus(DebuggerRequest &req) {
JsonWriter &json = req.Respond();
json.writeBool("stepping", PSP_IsInited() && Core_IsStepping() && coreState != CORE_POWERDOWN);
const bool pspInited = PSP_GetBootState() == BootState::Complete;
json.writeBool("stepping", pspInited && Core_IsStepping() && coreState != CORE_POWERDOWN);
json.writeBool("paused", GetUIState() != UISTATE_INGAME);
// Avoid NULL deference.
json.writeUint("pc", PSP_IsInited() ? currentMIPS->pc : 0);
json.writeUint("pc", pspInited ? currentMIPS->pc : 0);
// A double ought to be good enough for a 156 day debug session.
json.writeFloat("ticks", PSP_IsInited() ? CoreTiming::GetTicks() : 0);
json.writeFloat("ticks", pspInited ? CoreTiming::GetTicks() : 0);
}
// Retrieve all regs and their values (cpu.getAllRegs)
@@ -58,7 +58,7 @@ WebSocketGPURecordState::~WebSocketGPURecordState() {
//
// Note: recording may take a moment.
void WebSocketGPURecordState::Dump(DebuggerRequest &req) {
if (!PSP_IsInited()) {
if (PSP_GetBootState() != BootState::Complete) {
return req.Fail("CPU not started");
}
@@ -150,7 +150,7 @@ void WebSocketGPUStatsState::FlipListener() {
// Note: stats are returned after the next flip completes (paused if CPU or GPU in break.)
// Note: info and timing may not be accurate if certain settings are disabled.
void WebSocketGPUStatsState::Get(DebuggerRequest &req) {
if (!PSP_IsInited())
if (PSP_GetBootState() != BootState::Complete)
return req.Fail("CPU not started");
std::lock_guard<std::mutex> guard(pendingLock_);
@@ -169,7 +169,7 @@ void WebSocketGPUStatsState::Get(DebuggerRequest &req) {
//
// Note: info and timing will be accurate after the first frame.
void WebSocketGPUStatsState::Feed(DebuggerRequest &req) {
if (!PSP_IsInited())
if (PSP_GetBootState() != BootState::Complete)
return req.Fail("CPU not started");
bool enable = true;
if (!req.ParamBool("enable", &enable, DebuggerParamType::OPTIONAL))
+3 -3
View File
@@ -27,7 +27,7 @@ struct GameStatusEvent {
JsonWriter j;
j.begin();
j.writeString("event", ev);
if (PSP_IsInited()) {
if (PSP_GetBootState() == BootState::Complete) {
j.pushDict("game");
j.writeString("id", g_paramSFO.GetDiscID());
j.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
@@ -83,10 +83,10 @@ void GameBroadcaster::Broadcast(net::WebSocketServer *ws) {
} else if (state == UISTATE_INGAME && prevState_ == UISTATE_PAUSEMENU) {
ws->Send(GameStatusEvent{"game.resume"});
prevState_ = state;
} else if (state == UISTATE_INGAME && PSP_IsInited()) {
} else if (state == UISTATE_INGAME && PSP_GetBootState() == BootState::Complete) {
ws->Send(GameStatusEvent{"game.start"});
prevState_ = state;
} else if (state == UISTATE_MENU && !PSP_IsInited() && !PSP_IsQuitting() && !PSP_IsRebooting()) {
} else if (state == UISTATE_MENU && PSP_GetBootState() != BootState::Complete) {
ws->Send(GameStatusEvent{"game.quit"});
prevState_ = state;
}
+3 -3
View File
@@ -39,7 +39,7 @@ DebuggerSubscriber *WebSocketGameInit(DebuggerEventHandlerMap &map) {
//
// Response (same event name) with no extra data or error.
void WebSocketGameReset(DebuggerRequest &req) {
if (!PSP_IsInited())
if (PSP_GetBootState() != BootState::Complete)
return req.Fail("Game not running");
bool needBreak = false;
@@ -50,7 +50,7 @@ void WebSocketGameReset(DebuggerRequest &req) {
PSP_CoreParameter().startBreak = true;
std::string resetError;
if (!PSP_Reboot(&resetError)) {
if (PSP_Reboot(&resetError) != BootState::Complete) {
ERROR_LOG(Log::Boot, "Error resetting: %s", resetError.c_str());
return req.Fail("Could not reset");
}
@@ -73,7 +73,7 @@ void WebSocketGameReset(DebuggerRequest &req) {
// - paused: boolean, true when gameplay is paused (not the same as stepping.)
void WebSocketGameStatus(DebuggerRequest &req) {
JsonWriter &json = req.Respond();
if (PSP_IsInited()) {
if (PSP_GetBootState() == BootState::Complete) {
json.pushDict("game");
json.writeString("id", g_paramSFO.GetDiscID());
json.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
+1 -1
View File
@@ -101,7 +101,7 @@ void WebSocketHLEThreadList(DebuggerRequest &req) {
}
static bool ThreadInfoForStatus(DebuggerRequest &req, DebugThreadInfo *result) {
if (!PSP_IsInited()) {
if (PSP_GetBootState() != BootState::Complete) {
req.Fail("CPU not active");
return false;
}
+4 -4
View File
@@ -71,7 +71,7 @@ void WebSocketReplayAbort(DebuggerRequest &req) {
// - version: unsigned integer, version number of data.
// - base64: base64 encode of binary data.
void WebSocketReplayFlush(DebuggerRequest &req) {
if (!PSP_IsInited())
if (PSP_GetBootState() != BootState::Complete)
return req.Fail("Game not running");
std::vector<uint8_t> data;
@@ -90,7 +90,7 @@ void WebSocketReplayFlush(DebuggerRequest &req) {
//
// Response (same event name) with no extra data.
void WebSocketReplayExecute(DebuggerRequest &req) {
if (!PSP_IsInited())
if (PSP_GetBootState() != BootState::Complete)
return req.Fail("Game not running");
uint32_t version = -1;
@@ -130,7 +130,7 @@ void WebSocketReplayStatus(DebuggerRequest &req) {
// Response (same event name):
// - value: unsigned integer, may have more than 32 integer bits.
void WebSocketReplayTimeGet(DebuggerRequest &req) {
if (!PSP_IsInited())
if (PSP_GetBootState() != BootState::Complete)
return req.Fail("Game not running");
JsonWriter &json = req.Respond();
@@ -144,7 +144,7 @@ void WebSocketReplayTimeGet(DebuggerRequest &req) {
//
// Response (same event name) with no extra data.
void WebSocketReplayTimeSet(DebuggerRequest &req) {
if (!PSP_IsInited())
if (PSP_GetBootState() != BootState::Complete)
return req.Fail("Game not running");
uint32_t value;
@@ -57,7 +57,7 @@ private:
//
// Sent unexpectedly with no other properties.
void SteppingBroadcaster::Broadcast(net::WebSocketServer *ws) {
if (PSP_IsInited()) {
if (PSP_GetBootState() == BootState::Complete) {
int steppingCounter = Core_GetSteppingCounter();
// We ignore CORE_POWERDOWN as a stepping state.
if (coreState == CORE_STEPPING_CPU && steppingCounter != lastCounter_) {