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