CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/Debugger/WebSocket/GameSubscriber.cpp
Views: 1401
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_IsInited())
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
std::string resetError;
53
if (!PSP_Reboot(&resetError)) {
54
ERROR_LOG(Log::Boot, "Error resetting: %s", resetError.c_str());
55
return req.Fail("Could not reset");
56
}
57
58
System_Notify(SystemNotification::BOOT_DONE);
59
System_Notify(SystemNotification::DISASSEMBLY);
60
61
req.Respond();
62
}
63
64
// Check game status (game.status)
65
//
66
// No parameters.
67
//
68
// Response (same event name):
69
// - game: null or an object with properties:
70
// - id: string disc ID (such as ULUS12345.)
71
// - version: string disc version.
72
// - title: string game title.
73
// - paused: boolean, true when gameplay is paused (not the same as stepping.)
74
void WebSocketGameStatus(DebuggerRequest &req) {
75
JsonWriter &json = req.Respond();
76
if (PSP_IsInited()) {
77
json.pushDict("game");
78
json.writeString("id", g_paramSFO.GetDiscID());
79
json.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
80
json.writeString("title", g_paramSFO.GetValueString("TITLE"));
81
json.pop();
82
} else {
83
json.writeNull("game");
84
}
85
json.writeBool("paused", GetUIState() == UISTATE_PAUSEMENU);
86
}
87
88
// Notify debugger version info (version)
89
//
90
// Parameters:
91
// - name: string indicating name of app or tool.
92
// - version: string version.
93
//
94
// Response (same event name):
95
// - name: string, "PPSSPP" unless some special build.
96
// - version: string, typically starts with "v" and may have git build info.
97
void WebSocketVersion(DebuggerRequest &req) {
98
JsonWriter &json = req.Respond();
99
100
std::string version = req.client->version;
101
if (!req.ParamString("version", &version, DebuggerParamType::OPTIONAL_LOOSE))
102
return;
103
std::string name = req.client->name;
104
if (!req.ParamString("name", &name, DebuggerParamType::OPTIONAL_LOOSE))
105
return;
106
107
req.client->version = version;
108
req.client->name = name;
109
110
json.writeString("name", "PPSSPP");
111
json.writeString("version", PPSSPP_GIT_VERSION);
112
}
113
114