Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/Core.h
3185 views
1
// Copyright (c) 2012- 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
#pragma once
19
20
#include <cstdint>
21
#include <string>
22
#include <string_view>
23
24
#include "Common/CommonTypes.h"
25
26
class GraphicsContext;
27
28
// For platforms that don't call Run
29
void Core_SetGraphicsContext(GraphicsContext *ctx);
30
31
// Returns false when an UI exit state is detected.
32
void Core_Stop();
33
34
// X11, sigh.
35
#ifdef None
36
#undef None
37
#endif
38
39
enum class CPUStepType {
40
None,
41
Into,
42
Over,
43
Out,
44
Frame,
45
};
46
47
// Must be set when breaking.
48
enum class BreakReason {
49
None,
50
AssertChoice,
51
DebugBreak,
52
DebugStep,
53
DebugStepInto,
54
UIFocus,
55
AfterFrame,
56
MemoryException,
57
CpuException,
58
BreakInstruction,
59
SavestateLoad,
60
SavestateSave,
61
SavestateRewind,
62
SavestateCrash,
63
MemoryBreakpoint,
64
CpuBreakpoint,
65
MemoryAccess, // ???
66
JitBranchDebug,
67
BreakOnBoot,
68
RABreak,
69
AddBreakpoint,
70
FrameAdvance,
71
UIPause,
72
HLEDebugBreak,
73
};
74
const char *BreakReasonToString(BreakReason reason);
75
76
// Async, called from gui
77
void Core_Break(BreakReason reason, u32 relatedAddress = 0);
78
79
// Resumes execution. Works both when stepping the CPU and the GE.
80
void Core_Resume();
81
82
BreakReason Core_BreakReason();
83
84
// This should be called externally.
85
// Can fail if another step type was requested this frame.
86
bool Core_RequestCPUStep(CPUStepType stepType, int stepSize);
87
88
bool Core_NextFrame();
89
void Core_SwitchToGe(); // Switches from CPU emulation to GE display list execution.
90
91
// Changes every time we enter stepping.
92
int Core_GetSteppingCounter();
93
struct SteppingReason {
94
BreakReason reason;
95
u32 relatedAddress = 0;
96
};
97
SteppingReason Core_GetSteppingReason();
98
99
enum class CoreLifecycle {
100
STARTING,
101
// Note: includes failure cases. Guaranteed call after STARTING.
102
START_COMPLETE,
103
STOPPING,
104
// Guaranteed call after STOPPING.
105
STOPPED,
106
107
// Sometimes called for save states. Guaranteed sequence, and never during STARTING or STOPPING.
108
MEMORY_REINITING,
109
MEMORY_REINITED,
110
};
111
112
// RUNNING must be at 0, NEXTFRAME must be at 1.
113
enum CoreState {
114
// Emulation is running normally.
115
CORE_RUNNING_CPU = 0,
116
// Emulation was running normally, just reached the end of a frame.
117
CORE_NEXTFRAME = 1,
118
// Emulation is paused, CPU thread is sleeping.
119
CORE_STEPPING_CPU, // Can be used for recoverable runtime errors (ignored memory exceptions)
120
// Core is not running.
121
CORE_POWERDOWN,
122
// Unrecoverable runtime error. Recoverable errors should use CORE_STEPPING.
123
CORE_RUNTIME_ERROR,
124
// Stepping the GPU. When done, will switch over to STEPPING_CPU.
125
CORE_STEPPING_GE,
126
// Running the GPU. When done, will switch over to RUNNING_CPU.
127
CORE_RUNNING_GE,
128
};
129
const char *CoreStateToString(CoreState state);
130
131
// Callback is called on the Emu thread.
132
typedef void (* CoreLifecycleFunc)(CoreLifecycle stage);
133
void Core_ListenLifecycle(CoreLifecycleFunc func);
134
void Core_NotifyLifecycle(CoreLifecycle stage);
135
136
bool Core_IsStepping();
137
138
bool Core_IsActive();
139
bool Core_IsInactive();
140
141
// Warning: these three are only used on Windows - debugger integration.
142
void Core_StateProcessed();
143
void Core_WaitInactive();
144
145
void Core_SetPowerSaving(bool mode);
146
bool Core_GetPowerSaving();
147
148
void Core_RunLoopUntil(u64 globalticks);
149
150
extern volatile CoreState coreState;
151
extern volatile bool coreStatePending;
152
153
void Core_UpdateState(CoreState newState);
154
155
enum class MemoryExceptionType {
156
NONE,
157
UNKNOWN,
158
READ_WORD,
159
WRITE_WORD,
160
READ_BLOCK,
161
WRITE_BLOCK,
162
ALIGNMENT,
163
};
164
enum class ExecExceptionType {
165
JUMP,
166
THREAD,
167
};
168
169
// Separate one for without info, to avoid having to allocate a string
170
void Core_MemoryException(u32 address, u32 accessSize, u32 pc, MemoryExceptionType type);
171
172
void Core_MemoryExceptionInfo(u32 address, u32 accessSize, u32 pc, MemoryExceptionType type, std::string_view additionalInfo, bool forceReport);
173
174
void Core_ExecException(u32 address, u32 pc, ExecExceptionType type);
175
void Core_BreakException(u32 pc);
176
// Call when loading save states, etc.
177
void Core_ResetException();
178
179
enum class MIPSExceptionType {
180
NONE,
181
MEMORY,
182
BREAK,
183
BAD_EXEC_ADDR,
184
};
185
186
struct MIPSExceptionInfo {
187
MIPSExceptionType type;
188
std::string info;
189
std::string stackTrace; // if available.
190
191
// Memory exception info
192
MemoryExceptionType memory_type;
193
uint32_t pc;
194
uint32_t address;
195
uint32_t accessSize;
196
uint32_t ra = 0;
197
198
// Reuses pc and address from memory type, where address is the failed destination.
199
ExecExceptionType exec_type;
200
};
201
202
const MIPSExceptionInfo &Core_GetExceptionInfo();
203
204
const char *ExceptionTypeAsString(MIPSExceptionType type);
205
const char *MemoryExceptionTypeAsString(MemoryExceptionType type);
206
const char *ExecExceptionTypeAsString(ExecExceptionType type);
207
208