CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/Debugger/WebSocket/ReplaySubscriber.cpp
Views: 1401
// Copyright (c) 2021- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include <cstdint>18#include "Common/Data/Encoding/Base64.h"19#include "Common/Swap.h"20#include "Core/HLE/sceRtc.h"21#include "Core/Replay.h"22#include "Core/System.h"23#include "Core/Debugger/WebSocket/ReplaySubscriber.h"2425DebuggerSubscriber *WebSocketReplayInit(DebuggerEventHandlerMap &map) {26// No need to bind or alloc state, these are all global.27map["replay.begin"] = &WebSocketReplayBegin;28map["replay.abort"] = &WebSocketReplayAbort;29map["replay.flush"] = &WebSocketReplayFlush;30map["replay.execute"] = &WebSocketReplayExecute;31map["replay.status"] = &WebSocketReplayStatus;32map["replay.time.get"] = &WebSocketReplayTimeGet;33map["replay.time.set"] = &WebSocketReplayTimeSet;3435return nullptr;36}3738// Begin or resume recording of replay data (replay.begin)39//40// If a replay was previously being played back, this will keep any executed replay data up to41// this point for the next flush. To discard, break the CPU, abort, and then begin.42//43// No parameters.44//45// Response (same event name) with no extra data.46void WebSocketReplayBegin(DebuggerRequest &req) {47ReplayBeginSave();48req.Respond();49}5051// Abort any replay execution or recording (replay.abort)52//53// This stops executing any replay and discards any in progress recording.54//55// No parameters.56//57// Response (same event name) with no extra data.58void WebSocketReplayAbort(DebuggerRequest &req) {59ReplayAbort();60req.Respond();61}6263// Flush current recording data (replay.flush)64//65// Flushes event data and returns it. Note when combining, you must decode first.66//67// No parameters.68//69// Response (same event name):70// - version: unsigned integer, version number of data.71// - base64: base64 encode of binary data.72void WebSocketReplayFlush(DebuggerRequest &req) {73if (!PSP_IsInited())74return req.Fail("Game not running");7576std::vector<uint8_t> data;77ReplayFlushBlob(&data);7879JsonWriter &json = req.Respond();80json.writeInt("version", ReplayVersion());81json.writeString("base64", Base64Encode(data.data(), data.size()));82}8384// Begin executing a replay (replay.execute)85//86// Parameters:87// - version: unsigned integer, same version from replay.flush.88// - base64: base64 encoded replay data.89//90// Response (same event name) with no extra data.91void WebSocketReplayExecute(DebuggerRequest &req) {92if (!PSP_IsInited())93return req.Fail("Game not running");9495uint32_t version = -1;96if (!req.ParamU32("version", &version))97return;98std::string encoded;99if (!req.ParamString("base64", &encoded))100return;101102std::vector<uint8_t> data = Base64Decode(encoded.data(), encoded.size());103if (!ReplayExecuteBlob(version, data))104return req.Fail("Invalid replay data or version");105106req.Respond();107}108109// Get replay status (replay.status)110//111// No parameters.112//113// Response (same event name):114// - executing: boolean if a replay is being executed.115// - saving: boolean if a replay is being recorded.116void WebSocketReplayStatus(DebuggerRequest &req) {117JsonWriter &json = req.Respond();118json.writeBool("executing", ReplayIsExecuting());119json.writeBool("saving", ReplayIsSaving());120}121122// Get the base RTC (real time clock) time for replay data (replay.time.get)123//124// The base time is constant during a game session, and represents the "power on" time of the125// emulated PSP.126//127// No parameters.128//129// Response (same event name):130// - value: unsigned integer, may have more than 32 integer bits.131void WebSocketReplayTimeGet(DebuggerRequest &req) {132if (!PSP_IsInited())133return req.Fail("Game not running");134135JsonWriter &json = req.Respond();136json.writeUint("value", RtcBaseTime());137}138139// Overwrite the base RTC time (replay.time.set)140//141// Parameters:142// - value: unsigned integer.143//144// Response (same event name) with no extra data.145void WebSocketReplayTimeSet(DebuggerRequest &req) {146if (!PSP_IsInited())147return req.Fail("Game not running");148149uint32_t value;150if (!req.ParamU32("value", &value, false)) {151return;152}153154RtcSetBaseTime((int32_t)value);155req.Respond();156}157158159