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/Core.h
Views: 1401
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 <string>
21
#include <string_view>
22
23
#include "Core/System.h"
24
#include "Core/CoreParameter.h"
25
26
class GraphicsContext;
27
28
// called from emu thread
29
void UpdateRunLoop(GraphicsContext *ctx);
30
31
// Returns false when an UI exit state is detected.
32
bool Core_Run(GraphicsContext *ctx);
33
void Core_Stop();
34
35
// For platforms that don't call Core_Run
36
void Core_SetGraphicsContext(GraphicsContext *ctx);
37
38
// called from gui
39
void Core_EnableStepping(bool step, const char *reason = nullptr, u32 relatedAddress = 0);
40
41
bool Core_ShouldRunBehind();
42
bool Core_MustRunBehind();
43
44
bool Core_NextFrame();
45
void Core_DoSingleStep();
46
void Core_UpdateSingleStep();
47
void Core_ProcessStepping();
48
49
// Changes every time we enter stepping.
50
int Core_GetSteppingCounter();
51
struct SteppingReason {
52
const char *reason = nullptr;
53
u32 relatedAddress = 0;
54
};
55
SteppingReason Core_GetSteppingReason();
56
57
enum class CoreLifecycle {
58
STARTING,
59
// Note: includes failure cases. Guaranteed call after STARTING.
60
START_COMPLETE,
61
STOPPING,
62
// Guaranteed call after STOPPING.
63
STOPPED,
64
65
// Sometimes called for save states. Guaranteed sequence, and never during STARTING or STOPPING.
66
MEMORY_REINITING,
67
MEMORY_REINITED,
68
};
69
70
// Callback is called on the Emu thread.
71
typedef void (* CoreLifecycleFunc)(CoreLifecycle stage);
72
void Core_ListenLifecycle(CoreLifecycleFunc func);
73
void Core_NotifyLifecycle(CoreLifecycle stage);
74
75
// Callback is executed on requesting thread.
76
typedef void (* CoreStopRequestFunc)();
77
void Core_ListenStopRequest(CoreStopRequestFunc callback);
78
79
bool Core_IsStepping();
80
81
bool Core_IsActive();
82
bool Core_IsInactive();
83
// Warning: these currently work only on Windows.
84
void Core_WaitInactive();
85
void Core_WaitInactive(int milliseconds);
86
87
bool UpdateScreenScale(int width, int height);
88
89
// Don't run the core when minimized etc.
90
void Core_NotifyWindowHidden(bool hidden);
91
bool Core_IsWindowHidden();
92
93
void Core_SetPowerSaving(bool mode);
94
bool Core_GetPowerSaving();
95
96
enum class MemoryExceptionType {
97
NONE,
98
UNKNOWN,
99
READ_WORD,
100
WRITE_WORD,
101
READ_BLOCK,
102
WRITE_BLOCK,
103
ALIGNMENT,
104
};
105
enum class ExecExceptionType {
106
JUMP,
107
THREAD,
108
};
109
110
// Separate one for without info, to avoid having to allocate a string
111
void Core_MemoryException(u32 address, u32 accessSize, u32 pc, MemoryExceptionType type);
112
113
void Core_MemoryExceptionInfo(u32 address, u32 accessSize, u32 pc, MemoryExceptionType type, std::string_view additionalInfo, bool forceReport);
114
115
void Core_ExecException(u32 address, u32 pc, ExecExceptionType type);
116
void Core_Break(u32 pc);
117
// Call when loading save states, etc.
118
void Core_ResetException();
119
120
enum class MIPSExceptionType {
121
NONE,
122
MEMORY,
123
BREAK,
124
BAD_EXEC_ADDR,
125
};
126
127
struct MIPSExceptionInfo {
128
MIPSExceptionType type;
129
std::string info;
130
std::string stackTrace; // if available.
131
132
// Memory exception info
133
MemoryExceptionType memory_type;
134
uint32_t pc;
135
uint32_t address;
136
uint32_t accessSize;
137
uint32_t ra = 0;
138
139
// Reuses pc and address from memory type, where address is the failed destination.
140
ExecExceptionType exec_type;
141
};
142
143
const MIPSExceptionInfo &Core_GetExceptionInfo();
144
145
const char *ExceptionTypeAsString(MIPSExceptionType type);
146
const char *MemoryExceptionTypeAsString(MemoryExceptionType type);
147
const char *ExecExceptionTypeAsString(ExecExceptionType type);
148
149