-
Notifications
You must be signed in to change notification settings - Fork 2
/
handlestuffnwaccess.cpp
175 lines (146 loc) · 3.43 KB
/
handlestuffnwaccess.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <QtEndian>
#include <QLoggingCategory>
#include <QTemporaryFile>
Q_LOGGING_CATEGORY(log_handleStuffNWA, "HandleStuffNWA")
#define sDebug() qCDebug(log_handleStuffNWA)
#include "handlestuffnwaccess.h"
HandleStuffNWAccess::HandleStuffNWAccess() : HandleStuff ()
{
load = false;
doingState = false;
memoryAccess = false;
controllerStateRequest = false;
QTemporaryFile f("SaveStateSnesNWA");
f.open();
tempFilePath = f.fileName();
memoryTimer.setInterval(20);
connect(&memoryTimer, &QTimer::timeout, this, [=]{
emuclient->cmdCoreReadMemory(gameInfos().memoryPreset.domain, gameInfos().memoryPreset.address , gameInfos().memoryPreset.size);
});
}
void HandleStuffNWAccess::setNWAClient(EmuNWAccessClient *client)
{
emuclient = client;
connect(emuclient, &EmuNWAccessClient::readyRead, this, &HandleStuffNWAccess::onReplyRead);
emuclient->cmdEmulatorInfo();
}
QByteArray HandleStuffNWAccess::getScreenshotData()
{
return QByteArray();
}
bool HandleStuffNWAccess::hasShortcutsEdit()
{
return true;
}
bool HandleStuffNWAccess::hasScreenshots()
{
return false;
}
void HandleStuffNWAccess::setShortcutSave(quint16 shortcut)
{
saveShortcut = shortcut;
}
void HandleStuffNWAccess::setShortcutLoad(quint16 shortcut)
{
loadShortcut = shortcut;
}
quint16 HandleStuffNWAccess::shortcutSave()
{
return saveShortcut;
}
quint16 HandleStuffNWAccess::shortcutLoad()
{
return loadShortcut;
}
bool HandleStuffNWAccess::hasMemoryWatch()
{
return memoryAccess;
}
void HandleStuffNWAccess::startMemoryWatch()
{
memoryTimer.start();
}
void HandleStuffNWAccess::stopMemoryWatch()
{
memoryTimer.stop();
}
void HandleStuffNWAccess::controllerLoadState()
{
controllerStateRequest = true;
loadState(lastLoadedSave);
}
void HandleStuffNWAccess::controllerSaveState()
{
controllerStateRequest = true;
saveState(tempFilePath);
}
bool HandleStuffNWAccess::saveState(bool trigger)
{
Q_UNUSED(trigger);
return false;
}
void HandleStuffNWAccess::loadState(QByteArray data)
{
Q_UNUSED(data);
}
bool HandleStuffNWAccess::saveState(QString path)
{
load = false;
doingState = true;
lastLoadedSave = path;
emuclient->cmdSaveState(path);
return true;
}
bool HandleStuffNWAccess::loadState(QString path)
{
load = true;
doingState = true;
lastLoadedSave = path;
emuclient->cmdLoadState(path);
return true;
}
bool HandleStuffNWAccess::needByteData()
{
return false;
}
void HandleStuffNWAccess::onReplyRead()
{
auto reply = emuclient->readReply();
sDebug() << "Replied for " << reply.cmd;
if (reply.cmd == "EMULATOR_INFO")
{
if (reply["commands"].indexOf("CORE_READ"))
memoryAccess = true;
return ;
}
if (reply.cmd == "CORE_READ")
{
quint64 value = 0;
sDebug() << reply.binary;
for (quint8 i = 0; i < reply.binary.size(); i++)
{
value += reply.binary.at(i) << (i * 8);
}
emit gotMemoryValue(value);
return;
}
if (doingState == false)
return;
if (!controllerStateRequest)
{
if (load)
emit loadStateFinished(!reply.isError);
else
emit saveStateFinished(!reply.isError);
} else {
controllerStateRequest = false;
}
}
bool HandleStuffNWAccess::hasPostSaveScreenshot()
{
return false;
}
bool HandleStuffNWAccess::doScreenshot()
{
return false;
}