Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/Debugger/WebSocket/GameSubscriber.cpp
5654 views
1
// Copyright (c) 2018- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include "Common/System/System.h"
19
#include "Core/Config.h"
20
#include "Core/Debugger/WebSocket/GameSubscriber.h"
21
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
22
#include "Core/ELF/ParamSFO.h"
23
#include "Core/System.h"
24
25
DebuggerSubscriber *WebSocketGameInit(DebuggerEventHandlerMap &map) {
26
map["game.reset"] = &WebSocketGameReset;
27
map["game.status"] = &WebSocketGameStatus;
28
map["version"] = &WebSocketVersion;
29
30
return nullptr;
31
}
32
33
// Reset emulation (game.reset)
34
//
35
// Use this if you need to break on start and do something before the game starts.
36
//
37
// Parameters:
38
// - break: optional boolean, true to break CPU on start. Use cpu.resume afterward.
39
//
40
// Response (same event name) with no extra data or error.
41
void WebSocketGameReset(DebuggerRequest &req) {
42
if (PSP_GetBootState() != BootState::Complete)
43
return req.Fail("Game not running");
44
45
bool needBreak = false;
46
if (!req.ParamBool("break", &needBreak, DebuggerParamType::OPTIONAL))
47
return;
48
49
if (needBreak)
50
PSP_CoreParameter().startBreak = true;
51
52
// We can only support async resets here. A lot of the stuff in init must happen on the EmuThread,
53
// and we are not on it here.
54
System_PostUIMessage(UIMessage::REQUEST_GAME_RESET);
55
56
req.Respond();
57
}
58
59
// Check game status (game.status)
60
//
61
// No parameters.
62
//
63
// Response (same event name):
64
// - game: null or an object with properties:
65
// - id: string disc ID (such as ULUS12345.)
66
// - version: string disc version.
67
// - title: string game title.
68
// - paused: boolean, true when gameplay is paused (not the same as stepping.)
69
void WebSocketGameStatus(DebuggerRequest &req) {
70
JsonWriter &json = req.Respond();
71
if (PSP_GetBootState() == BootState::Complete) {
72
json.pushDict("game");
73
json.writeString("id", g_paramSFO.GetDiscID());
74
json.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
75
json.writeString("title", g_paramSFO.GetValueString("TITLE"));
76
json.pop();
77
} else {
78
json.writeNull("game");
79
}
80
json.writeBool("paused", GetUIState() == UISTATE_PAUSEMENU);
81
}
82
83
// Notify debugger version info (version)
84
//
85
// Parameters:
86
// - name: string indicating name of app or tool.
87
// - version: string version.
88
//
89
// Response (same event name):
90
// - name: string, "PPSSPP" unless some special build.
91
// - version: string, typically starts with "v" and may have git build info.
92
void WebSocketVersion(DebuggerRequest &req) {
93
JsonWriter &json = req.Respond();
94
95
std::string version = req.client->version;
96
if (!req.ParamString("version", &version, DebuggerParamType::OPTIONAL_LOOSE))
97
return;
98
std::string name = req.client->name;
99
if (!req.ParamString("name", &name, DebuggerParamType::OPTIONAL_LOOSE))
100
return;
101
102
req.client->version = version;
103
req.client->name = name;
104
105
json.writeString("name", "PPSSPP");
106
json.writeString("version", PPSSPP_GIT_VERSION);
107
}
108
109