Browse code

Port: Add override keyword.

Clarissa Walker authored on 2024/09/16 22:14:51
Showing 1 changed files
... ...
@@ -31,10 +31,10 @@ class XSFPlayer_2SF : public XSFPlayer
31 31
 	bool Load2SF(XSFFile *xSFToLoad);
32 32
 public:
33 33
 	XSFPlayer_2SF(const std::filesystem::path &path);
34
-	~XSFPlayer_2SF() { this->Terminate(); }
35
-	bool Load();
36
-	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples);
37
-	void Terminate();
34
+	~XSFPlayer_2SF() override { this->Terminate(); }
35
+	bool Load() override;
36
+	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples) override;
37
+	void Terminate() override;
38 38
 };
39 39
 
40 40
 const char *XSFPlayer::WinampDescription = "2SF Decoder";
Browse code

Port: Use std::filesystem::path for reading/writing files. - before override

Clarissa Walker authored on 2024/08/22 20:57:20
Showing 1 changed files
... ...
@@ -30,10 +30,7 @@ class XSFPlayer_2SF : public XSFPlayer
30 30
 	bool RecursiveLoad2SF(XSFFile *xSFToLoad, int level);
31 31
 	bool Load2SF(XSFFile *xSFToLoad);
32 32
 public:
33
-	XSFPlayer_2SF(const std::string &filename);
34
-#ifdef _WIN32
35
-	XSFPlayer_2SF(const std::wstring &filename);
36
-#endif
33
+	XSFPlayer_2SF(const std::filesystem::path &path);
37 34
 	~XSFPlayer_2SF() { this->Terminate(); }
38 35
 	bool Load();
39 36
 	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples);
... ...
@@ -43,18 +40,11 @@ public:
43 40
 const char *XSFPlayer::WinampDescription = "2SF Decoder";
44 41
 const char *XSFPlayer::WinampExts = "2sf;mini2sf\0DS Sound Format files (*.2sf;*.mini2sf)\0";
45 42
 
46
-XSFPlayer *XSFPlayer::Create(const std::string &fn)
43
+XSFPlayer *XSFPlayer::Create(const std::filesystem::path &path)
47 44
 {
48
-	return new XSFPlayer_2SF(fn);
45
+	return new XSFPlayer_2SF(path);
49 46
 }
50 47
 
51
-#ifdef _WIN32
52
-XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
53
-{
54
-	return new XSFPlayer_2SF(fn);
55
-}
56
-#endif
57
-
58 48
 volatile bool execute = false;
59 49
 
60 50
 static struct
... ...
@@ -149,11 +139,7 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
149 139
 {
150 140
 	if (level <= 10 && xSFToLoad->GetTagExists("_lib"))
151 141
 	{
152
-#ifdef _WIN32
153
-		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSFToLoad->GetFilename()).parent_path() / xSFToLoad->GetTagValue("_lib")).wstring(), 4, 8);
154
-#else
155
-		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSFToLoad->GetFilename()).parent_path() / xSFToLoad->GetTagValue("_lib")).string(), 4, 8);
156
-#endif
142
+		auto libxSF = std::make_unique<XSFFile>(xSFToLoad->GetFilepath().parent_path() / xSFToLoad->GetTagValue("_lib"), 4, 8);
157 143
 		if (!this->RecursiveLoad2SF(libxSF.get(), level + 1))
158 144
 			return false;
159 145
 	}
... ...
@@ -170,11 +156,7 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
170 156
 		if (xSFToLoad->GetTagExists(libTag))
171 157
 		{
172 158
 			found = true;
173
-#ifdef _WIN32
174
-			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSFToLoad->GetFilename()).parent_path() / xSFToLoad->GetTagValue(libTag)).wstring(), 4, 8);
175
-#else
176
-			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSFToLoad->GetFilename()).parent_path() / xSFToLoad->GetTagValue(libTag)).string(), 4, 8);
177
-#endif
159
+			auto libxSF = std::make_unique<XSFFile>(xSFToLoad->GetFilepath().parent_path() / xSFToLoad->GetTagValue(libTag), 4, 8);
178 160
 			if (!this->RecursiveLoad2SF(libxSF.get(), level + 1))
179 161
 				return false;
180 162
 		}
... ...
@@ -190,17 +172,10 @@ bool XSFPlayer_2SF::Load2SF(XSFFile *xSFToLoad)
190 172
 	return this->RecursiveLoad2SF(xSFToLoad, 1);
191 173
 }
192 174
 
193
-XSFPlayer_2SF::XSFPlayer_2SF(const std::string &filename) : XSFPlayer()
194
-{
195
-	this->xSF.reset(new XSFFile(filename, 4, 8));
196
-}
197
-
198
-#ifdef _WIN32
199
-XSFPlayer_2SF::XSFPlayer_2SF(const std::wstring &filename) : XSFPlayer()
175
+XSFPlayer_2SF::XSFPlayer_2SF(const std::filesystem::path &path) : XSFPlayer()
200 176
 {
201
-	this->xSF.reset(new XSFFile(filename, 4, 8));
177
+	this->xSF.reset(new XSFFile(path, 4, 8));
202 178
 }
203
-#endif
204 179
 
205 180
 bool XSFPlayer_2SF::Load()
206 181
 {
Browse code

Various changes:

* Use enum class instead of enum (except for the enums for the resource IDs, not really necessary there).
* For NCSF specifically, included a function to convert an enum class to its underlying integral type (as this is needed for use with the std::bitset class).
* Cleanup headers so all the ones needed in a file are explicitly included even if they may possibly be included in another header.
* Used forward declarations in a few spots.
* Explicitly namespaced all (u)int*_t uses (this might seem like overkill, but it helps me see when the standard types are being used with a simple search for std::).
* Made sure it all builds with MinGW-w64 as well (both gcc and clang).
* Removed some std::move from DialogBuilder.cpp based on clang's warnings for that.
* Replaced use of std::copy_n on strings in DialogBuilder.cpp with my CopyToString functions that use wcscpy.
* Replaced CHAR_MIN/CHAR_MAX in eqstr.h and ltstr.h with std::numeric_limits<char>::min/max().

Naram Qashat authored on 2021/03/21 03:16:45
Showing 1 changed files
... ...
@@ -10,19 +10,22 @@
10 10
  * http://desmume.org/
11 11
  */
12 12
 
13
+#include <algorithm>
13 14
 #include <filesystem>
14 15
 #include <memory>
16
+#include <string>
17
+#include <vector>
18
+#include <cstdint>
15 19
 #include <zlib.h>
16
-#include "convert.h"
17
-#include "XSFPlayer.h"
18 20
 #include "XSFCommon.h"
21
+#include "XSFPlayer.h"
19 22
 #include "desmume/NDSSystem.h"
20 23
 
21 24
 class XSFPlayer_2SF : public XSFPlayer
22 25
 {
23
-	std::vector<uint8_t> rom;
26
+	std::vector<std::uint8_t> rom;
24 27
 
25
-	void Map2SFSection(const std::vector<uint8_t> &section);
28
+	void Map2SFSection(const std::vector<std::uint8_t> &section);
26 29
 	bool Map2SF(XSFFile *xSFToLoad);
27 30
 	bool RecursiveLoad2SF(XSFFile *xSFToLoad, int level);
28 31
 	bool Load2SF(XSFFile *xSFToLoad);
... ...
@@ -33,7 +36,7 @@ public:
33 36
 #endif
34 37
 	~XSFPlayer_2SF() { this->Terminate(); }
35 38
 	bool Load();
36
-	void GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples);
39
+	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples);
37 40
 	void Terminate();
38 41
 };
39 42
 
... ...
@@ -56,17 +59,17 @@ volatile bool execute = false;
56 59
 
57 60
 static struct
58 61
 {
59
-	std::vector<uint8_t> buf;
62
+	std::vector<std::uint8_t> buf;
60 63
 	unsigned filled, used;
61
-	uint32_t bufferbytes, cycles;
64
+	std::uint32_t bufferbytes, cycles;
62 65
 	int xfs_load, sync_type;
63
-} sndifwork = { std::vector<uint8_t>(), 0, 0, 0, 0, 0, 0 };
66
+} sndifwork = { std::vector<std::uint8_t>(), 0, 0, 0, 0, 0, 0 };
64 67
 
65 68
 static void SNDIFDeInit() { }
66 69
 
67 70
 static int SNDIFInit(int buffersize)
68 71
 {
69
-	uint32_t bufferbytes = buffersize * sizeof(int16_t);
72
+	std::uint32_t bufferbytes = buffersize * sizeof(std::int16_t);
70 73
 	SNDIFDeInit();
71 74
 	sndifwork.buf.resize(bufferbytes + 3);
72 75
 	sndifwork.bufferbytes = bufferbytes;
... ...
@@ -79,17 +82,17 @@ static void SNDIFMuteAudio() { }
79 82
 static void SNDIFUnMuteAudio() { }
80 83
 static void SNDIFSetVolume(int) { }
81 84
 
82
-static uint32_t SNDIFGetAudioSpace()
85
+static std::uint32_t SNDIFGetAudioSpace()
83 86
 {
84 87
 	return sndifwork.bufferbytes >> 2; // bytes to samples
85 88
 }
86 89
 
87
-static void SNDIFUpdateAudio(int16_t *buffer, uint32_t num_samples)
90
+static void SNDIFUpdateAudio(std::int16_t *buffer, std::uint32_t num_samples)
88 91
 {
89
-	uint32_t num_bytes = num_samples << 2;
92
+	std::uint32_t num_bytes = num_samples << 2;
90 93
 	if (num_bytes > sndifwork.bufferbytes)
91 94
 		num_bytes = sndifwork.bufferbytes;
92
-	std::copy_n(reinterpret_cast<uint8_t *>(buffer), num_bytes, &sndifwork.buf[0]);
95
+	std::copy_n(reinterpret_cast<std::uint8_t *>(buffer), num_bytes, &sndifwork.buf[0]);
93 96
 	sndifwork.filled = num_bytes;
94 97
 	sndifwork.used = 0;
95 98
 }
... ...
@@ -118,9 +121,9 @@ SoundInterface_struct *SNDCoreList[] =
118 121
 	nullptr
119 122
 };
120 123
 
121
-void XSFPlayer_2SF::Map2SFSection(const std::vector<uint8_t> &section)
124
+void XSFPlayer_2SF::Map2SFSection(const std::vector<std::uint8_t> &section)
122 125
 {
123
-	uint32_t offset = Get32BitsLE(&section[0]), size = Get32BitsLE(&section[4]), finalSize = size + offset;
126
+	std::uint32_t offset = Get32BitsLE(&section[0]), size = Get32BitsLE(&section[4]), finalSize = size + offset;
124 127
 	finalSize = NextHighestPowerOf2(finalSize);
125 128
 	if (this->rom.empty())
126 129
 		this->rom.resize(finalSize + 10, 0);
... ...
@@ -244,15 +247,15 @@ bool XSFPlayer_2SF::Load()
244 247
 	return XSFPlayer::Load();
245 248
 }
246 249
 
247
-void XSFPlayer_2SF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples)
250
+void XSFPlayer_2SF::GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples)
248 251
 {
249 252
 	static const double HBASE_CYCLES = 33509300.322234;
250 253
 	static const int HLINE_CYCLES = 6 * (99 + 256);
251
-	static const uint32_t HSAMPLES = static_cast<uint32_t>(static_cast<double>(this->sampleRate * HLINE_CYCLES) / HBASE_CYCLES);
254
+	std::uint32_t HSAMPLES = static_cast<std::uint32_t>(static_cast<double>(this->sampleRate * HLINE_CYCLES) / HBASE_CYCLES);
252 255
 	static const int VDIVISION = 100;
253 256
 	static const int VLINES = 263;
254 257
 	static const double VBASE_CYCLES = HBASE_CYCLES / VDIVISION;
255
-	static const uint32_t VSAMPLES = static_cast<uint32_t>(static_cast<double>(this->sampleRate * HLINE_CYCLES * VLINES) / HBASE_CYCLES);
258
+	std::uint32_t VSAMPLES = static_cast<std::uint32_t>(static_cast<double>(this->sampleRate * HLINE_CYCLES * VLINES) / HBASE_CYCLES);
256 259
 
257 260
 	if (!sndifwork.xfs_load)
258 261
 		return;
... ...
@@ -286,19 +289,19 @@ void XSFPlayer_2SF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset,
286 289
 			{
287 290
 				/* vsync */
288 291
 				sndifwork.cycles += (this->sampleRate / VDIVISION) * HLINE_CYCLES * VLINES;
289
-				if (sndifwork.cycles >= static_cast<uint32_t>(VBASE_CYCLES * (VSAMPLES + 1)))
290
-					sndifwork.cycles -= static_cast<uint32_t>(VBASE_CYCLES * (VSAMPLES + 1));
292
+				if (sndifwork.cycles >= static_cast<std::uint32_t>(VBASE_CYCLES * (VSAMPLES + 1)))
293
+					sndifwork.cycles -= static_cast<std::uint32_t>(VBASE_CYCLES * (VSAMPLES + 1));
291 294
 				else
292
-					sndifwork.cycles -= static_cast<uint32_t>(VBASE_CYCLES * VSAMPLES);
295
+					sndifwork.cycles -= static_cast<std::uint32_t>(VBASE_CYCLES * VSAMPLES);
293 296
 			}
294 297
 			else
295 298
 			{
296 299
 				/* hsync */
297 300
 				sndifwork.cycles += this->sampleRate * HLINE_CYCLES;
298
-				if (sndifwork.cycles >= static_cast<uint32_t>(HBASE_CYCLES * (HSAMPLES + 1)))
299
-					sndifwork.cycles -= static_cast<uint32_t>(HBASE_CYCLES * (HSAMPLES + 1));
301
+				if (sndifwork.cycles >= static_cast<std::uint32_t>(HBASE_CYCLES * (HSAMPLES + 1)))
302
+					sndifwork.cycles -= static_cast<std::uint32_t>(HBASE_CYCLES * (HSAMPLES + 1));
300 303
 				else
301
-					sndifwork.cycles -= static_cast<uint32_t>(HBASE_CYCLES * HSAMPLES);
304
+					sndifwork.cycles -= static_cast<std::uint32_t>(HBASE_CYCLES * HSAMPLES);
302 305
 			}
303 306
 			NDS_exec<false>();
304 307
 			SPU_Emulate_user();
Browse code

Correct a few warnings Visual Studio was complaining about.

Naram Qashat authored on 2021/03/20 20:40:21
Showing 1 changed files
... ...
@@ -60,7 +60,7 @@ static struct
60 60
 	unsigned filled, used;
61 61
 	uint32_t bufferbytes, cycles;
62 62
 	int xfs_load, sync_type;
63
-} sndifwork = {std::vector<uint8_t>(), 0, 0, 0, 0, 0, 0};
63
+} sndifwork = { std::vector<uint8_t>(), 0, 0, 0, 0, 0, 0 };
64 64
 
65 65
 static void SNDIFDeInit() { }
66 66
 
Browse code

Cleanup a few comments and strings.

Naram Qashat authored on 2021/03/20 20:25:12
Showing 1 changed files
... ...
@@ -211,7 +211,7 @@ bool XSFPlayer_2SF::Load()
211 211
 	if (NDS_Init())
212 212
 		return false;
213 213
 
214
-	static const int BUFFERSIZE = DESMUME_SAMPLE_RATE / 59.837; //truncates to 737, the traditional value, for 44100
214
+	static const int BUFFERSIZE = DESMUME_SAMPLE_RATE / 59.837; // truncates to 737, the traditional value, for 44100
215 215
 	SPU_ChangeSoundCore(SNDIFID_2SF, BUFFERSIZE);
216 216
 
217 217
 	execute = false;
Browse code

Use C++17 std::filesystem functions instead of my own.

Naram Qashat authored on 2021/03/20 20:05:50
Showing 1 changed files
... ...
@@ -10,6 +10,7 @@
10 10
  * http://desmume.org/
11 11
  */
12 12
 
13
+#include <filesystem>
13 14
 #include <memory>
14 15
 #include <zlib.h>
15 16
 #include "convert.h"
... ...
@@ -146,9 +147,9 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
146 147
 	if (level <= 10 && xSFToLoad->GetTagExists("_lib"))
147 148
 	{
148 149
 #ifdef _WIN32
149
-		auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue("_lib")), 4, 8);
150
+		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSFToLoad->GetFilename()).parent_path() / xSFToLoad->GetTagValue("_lib")).wstring(), 4, 8);
150 151
 #else
151
-		auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue("_lib"), 4, 8);
152
+		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSFToLoad->GetFilename()).parent_path() / xSFToLoad->GetTagValue("_lib")).string(), 4, 8);
152 153
 #endif
153 154
 		if (!this->RecursiveLoad2SF(libxSF.get(), level + 1))
154 155
 			return false;
... ...
@@ -167,9 +168,9 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
167 168
 		{
168 169
 			found = true;
169 170
 #ifdef _WIN32
170
-			auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue(libTag)), 4, 8);
171
+			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSFToLoad->GetFilename()).parent_path() / xSFToLoad->GetTagValue(libTag)).wstring(), 4, 8);
171 172
 #else
172
-			auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue(libTag), 4, 8);
173
+			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSFToLoad->GetFilename()).parent_path() / xSFToLoad->GetTagValue(libTag)).string(), 4, 8);
173 174
 #endif
174 175
 			if (!this->RecursiveLoad2SF(libxSF.get(), level + 1))
175 176
 				return false;
Browse code

Use std::make_unique where possible.

Naram Qashat authored on 2021/03/20 04:37:08
Showing 1 changed files
... ...
@@ -146,9 +146,9 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
146 146
 	if (level <= 10 && xSFToLoad->GetTagExists("_lib"))
147 147
 	{
148 148
 #ifdef _WIN32
149
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue("_lib")), 4, 8));
149
+		auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue("_lib")), 4, 8);
150 150
 #else
151
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue("_lib"), 4, 8));
151
+		auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue("_lib"), 4, 8);
152 152
 #endif
153 153
 		if (!this->RecursiveLoad2SF(libxSF.get(), level + 1))
154 154
 			return false;
... ...
@@ -167,9 +167,9 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
167 167
 		{
168 168
 			found = true;
169 169
 #ifdef _WIN32
170
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue(libTag)), 4, 8));
170
+			auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue(libTag)), 4, 8);
171 171
 #else
172
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue(libTag), 4, 8));
172
+			auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue(libTag), 4, 8);
173 173
 #endif
174 174
 			if (!this->RecursiveLoad2SF(libxSF.get(), level + 1))
175 175
 				return false;
Browse code

Replace memcpy/memset with std::copy_n/std::fill_n.

Naram Qashat authored on 2021/03/19 16:25:21
Showing 1 changed files
... ...
@@ -88,7 +88,7 @@ static void SNDIFUpdateAudio(int16_t *buffer, uint32_t num_samples)
88 88
 	uint32_t num_bytes = num_samples << 2;
89 89
 	if (num_bytes > sndifwork.bufferbytes)
90 90
 		num_bytes = sndifwork.bufferbytes;
91
-	memcpy(&sndifwork.buf[0], buffer, num_bytes);
91
+	std::copy_n(reinterpret_cast<uint8_t *>(buffer), num_bytes, &sndifwork.buf[0]);
92 92
 	sndifwork.filled = num_bytes;
93 93
 	sndifwork.used = 0;
94 94
 }
... ...
@@ -125,7 +125,7 @@ void XSFPlayer_2SF::Map2SFSection(const std::vector<uint8_t> &section)
125 125
 		this->rom.resize(finalSize + 10, 0);
126 126
 	else if (this->rom.size() < size + offset)
127 127
 		this->rom.resize(offset + finalSize + 10);
128
-	memcpy(&this->rom[offset], &section[8], size);
128
+	std::copy_n(&section[8], size, &this->rom[offset]);
129 129
 }
130 130
 
131 131
 bool XSFPlayer_2SF::Map2SF(XSFFile *xSFToLoad)
... ...
@@ -263,7 +263,7 @@ void XSFPlayer_2SF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset,
263 263
 		{
264 264
 			if (remainbytes > bytes)
265 265
 			{
266
-				memcpy(&buf[offset], &sndifwork.buf[sndifwork.used], bytes);
266
+				std::copy_n(&sndifwork.buf[sndifwork.used], bytes, &buf[offset]);
267 267
 				sndifwork.used += bytes;
268 268
 				offset += bytes;
269 269
 				remainbytes -= bytes;
... ...
@@ -272,7 +272,7 @@ void XSFPlayer_2SF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset,
272 272
 			}
273 273
 			else
274 274
 			{
275
-				memcpy(&buf[offset], &sndifwork.buf[sndifwork.used], remainbytes);
275
+				std::copy_n(&sndifwork.buf[sndifwork.used], remainbytes, &buf[offset]);
276 276
 				sndifwork.used += remainbytes;
277 277
 				offset += remainbytes;
278 278
 				bytes -= remainbytes;
Browse code

Some conversion replacements:

* Replace the (w)stringify functions with the standard std::to_(w)string functions.
* Replace convertTo with versions that use type_traits to determine which standard string conversion function to call, as well as handle enums specically.

Naram Qashat authored on 2021/03/19 11:57:21
Showing 1 changed files
... ...
@@ -162,7 +162,7 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
162 162
 	do
163 163
 	{
164 164
 		found = false;
165
-		std::string libTag = "_lib" + stringify(n++);
165
+		std::string libTag = "_lib" + std::to_string(n++);
166 166
 		if (xSFToLoad->GetTagExists(libTag))
167 167
 		{
168 168
 			found = true;
Browse code

Remove last modification date from files.

(I never remember to update these and besides, GitHub history can show when they were last modified.)

Naram Qashat authored on 2021/03/19 10:58:12
Showing 1 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 /*
2 2
  * xSF - 2SF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-24
5 4
  *
6 5
  * Based on a modified vio2sf v0.22c
7 6
  *
Browse code

2sf: fix JIT enable, fix sample rate

Adam Higerd authored on 2021/02/11 18:16:28
Showing 1 changed files
... ...
@@ -224,6 +224,7 @@ bool XSFPlayer_2SF::Load()
224 224
 	}
225 225
 
226 226
 	CommonSettings.use_jit = true;
227
+	CommonSettings.jit_max_block_size = 100;
227 228
 	NDS_Reset();
228 229
 
229 230
 	execute = true;
... ...
@@ -236,8 +237,9 @@ bool XSFPlayer_2SF::Load()
236 237
 	}
237 238
 
238 239
 	sndifwork.xfs_load = true;
239
-	//CommonSettings.spu_advanced = true;
240
-	//CommonSettings.advanced_timing = false;
240
+	CommonSettings.rigorous_timing = true;
241
+	CommonSettings.spu_advanced = true;
242
+	CommonSettings.advanced_timing = true;
241 243
 
242 244
 	return XSFPlayer::Load();
243 245
 }
Browse code

Update XSFPlayer_2SF.cpp

Make it substantially more obvious how to hack the 2sf player to output at a different samplerate by removing the secret implicit 44100 based calculation

zeromus authored on 2017/11/09 16:15:56 • GitHub committed on 2017/11/09 16:15:56
Showing 1 changed files
... ...
@@ -211,7 +211,8 @@ bool XSFPlayer_2SF::Load()
211 211
 	if (NDS_Init())
212 212
 		return false;
213 213
 
214
-	SPU_ChangeSoundCore(SNDIFID_2SF, 737);
214
+	static const int BUFFERSIZE = DESMUME_SAMPLE_RATE / 59.837; //truncates to 737, the traditional value, for 44100
215
+	SPU_ChangeSoundCore(SNDIFID_2SF, BUFFERSIZE);
215 216
 
216 217
 	execute = false;
217 218
 
Browse code

Lots of changes in regards to strings, as follows:

* Removed my custom String class, as well as removed the really old
Unicode ConvertUTF, the UTF Converter, and the UTF Encode/Decode
functions.
* Replaced the above with using standard C++ std::wstring_convert and
std::codecvt_utf8.
* Added headers adapted from llvm's libc++ project for allowing the
above C++ classes to exist with GCC and Clang when libc++ isn't being
used.
* Used std::string over std::wstring whenever possible.
* Added header adapted from llvm's libc++ project to create special
versions of the ifstream and ofstream classes that would utilize _wfopen
on non-MSVC Windows compilers, so those compilers could access files on
Windows that use characters outside the current codepage.
* Removed the -static-libgcc and -static-libstdc++ flags from the
Makefile for non-MSVC builds. The generated DLLs will require extra DLLs
from either Cygwin or MinGW (whichever is used to compile), I've only
tested with MinGW and for some reason they crash Winamp on exit, I have
no idea why.

Naram Qashat authored on 2014/09/24 13:58:55
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - 2SF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-17
4
+ * Last modification on 2014-09-24
5 5
  *
6 6
  * Based on a modified vio2sf v0.22c
7 7
  *
... ...
@@ -28,7 +28,7 @@ class XSFPlayer_2SF : public XSFPlayer
28 28
 	bool Load2SF(XSFFile *xSFToLoad);
29 29
 public:
30 30
 	XSFPlayer_2SF(const std::string &filename);
31
-#ifdef _MSC_VER
31
+#ifdef _WIN32
32 32
 	XSFPlayer_2SF(const std::wstring &filename);
33 33
 #endif
34 34
 	~XSFPlayer_2SF() { this->Terminate(); }
... ...
@@ -45,7 +45,7 @@ XSFPlayer *XSFPlayer::Create(const std::string &fn)
45 45
 	return new XSFPlayer_2SF(fn);
46 46
 }
47 47
 
48
-#ifdef _MSC_VER
48
+#ifdef _WIN32
49 49
 XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
50 50
 {
51 51
 	return new XSFPlayer_2SF(fn);
... ...
@@ -146,10 +146,10 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
146 146
 {
147 147
 	if (level <= 10 && xSFToLoad->GetTagExists("_lib"))
148 148
 	{
149
-#ifdef _MSC_VER
150
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetWStr()) + xSFToLoad->GetTagValue("_lib").GetWStr(), 4, 8));
149
+#ifdef _WIN32
150
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue("_lib")), 4, 8));
151 151
 #else
152
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetAnsi()) + xSFToLoad->GetTagValue("_lib").GetAnsi(), 4, 8));
152
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue("_lib"), 4, 8));
153 153
 #endif
154 154
 		if (!this->RecursiveLoad2SF(libxSF.get(), level + 1))
155 155
 			return false;
... ...
@@ -167,10 +167,10 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
167 167
 		if (xSFToLoad->GetTagExists(libTag))
168 168
 		{
169 169
 			found = true;
170
-#ifdef _MSC_VER
171
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetWStr()) + xSFToLoad->GetTagValue(libTag).GetWStr(), 4, 8));
170
+#ifdef _WIN32
171
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue(libTag)), 4, 8));
172 172
 #else
173
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetAnsi()) + xSFToLoad->GetTagValue(libTag).GetAnsi(), 4, 8));
173
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename()) + xSFToLoad->GetTagValue(libTag), 4, 8));
174 174
 #endif
175 175
 			if (!this->RecursiveLoad2SF(libxSF.get(), level + 1))
176 176
 				return false;
... ...
@@ -192,7 +192,7 @@ XSFPlayer_2SF::XSFPlayer_2SF(const std::string &filename) : XSFPlayer()
192 192
 	this->xSF.reset(new XSFFile(filename, 4, 8));
193 193
 }
194 194
 
195
-#ifdef _MSC_VER
195
+#ifdef _WIN32
196 196
 XSFPlayer_2SF::XSFPlayer_2SF(const std::wstring &filename) : XSFPlayer()
197 197
 {
198 198
 	this->xSF.reset(new XSFFile(filename, 4, 8));
Browse code

* Fixes for gcc and clang (while they can compile the code, the DLLs made aren't functional, but oh well).

* [2SF] Used more up-to-date asmjit, despite the ugly looking code.

Naram Qashat authored on 2014/09/17 19:51:45
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - 2SF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-23
4
+ * Last modification on 2014-09-17
5 5
  *
6 6
  * Based on a modified vio2sf v0.22c
7 7
  *
... ...
@@ -28,7 +28,9 @@ class XSFPlayer_2SF : public XSFPlayer
28 28
 	bool Load2SF(XSFFile *xSFToLoad);
29 29
 public:
30 30
 	XSFPlayer_2SF(const std::string &filename);
31
+#ifdef _MSC_VER
31 32
 	XSFPlayer_2SF(const std::wstring &filename);
33
+#endif
32 34
 	~XSFPlayer_2SF() { this->Terminate(); }
33 35
 	bool Load();
34 36
 	void GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples);
... ...
@@ -43,10 +45,12 @@ XSFPlayer *XSFPlayer::Create(const std::string &fn)
43 45
 	return new XSFPlayer_2SF(fn);
44 46
 }
45 47
 
48
+#ifdef _MSC_VER
46 49
 XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
47 50
 {
48 51
 	return new XSFPlayer_2SF(fn);
49 52
 }
53
+#endif
50 54
 
51 55
 volatile bool execute = false;
52 56
 
... ...
@@ -142,7 +146,7 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
142 146
 {
143 147
 	if (level <= 10 && xSFToLoad->GetTagExists("_lib"))
144 148
 	{
145
-#ifdef _WIN32
149
+#ifdef _MSC_VER
146 150
 		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetWStr()) + xSFToLoad->GetTagValue("_lib").GetWStr(), 4, 8));
147 151
 #else
148 152
 		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetAnsi()) + xSFToLoad->GetTagValue("_lib").GetAnsi(), 4, 8));
... ...
@@ -163,7 +167,7 @@ bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
163 167
 		if (xSFToLoad->GetTagExists(libTag))
164 168
 		{
165 169
 			found = true;
166
-#ifdef _WIN32
170
+#ifdef _MSC_VER
167 171
 			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetWStr()) + xSFToLoad->GetTagValue(libTag).GetWStr(), 4, 8));
168 172
 #else
169 173
 			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetAnsi()) + xSFToLoad->GetTagValue(libTag).GetAnsi(), 4, 8));
... ...
@@ -188,10 +192,12 @@ XSFPlayer_2SF::XSFPlayer_2SF(const std::string &filename) : XSFPlayer()
188 192
 	this->xSF.reset(new XSFFile(filename, 4, 8));
189 193
 }
190 194
 
195
+#ifdef _MSC_VER
191 196
 XSFPlayer_2SF::XSFPlayer_2SF(const std::wstring &filename) : XSFPlayer()
192 197
 {
193 198
 	this->xSF.reset(new XSFFile(filename, 4, 8));
194 199
 }
200
+#endif
195 201
 
196 202
 bool XSFPlayer_2SF::Load()
197 203
 {
Browse code

Added Lanczos interpolation to the NCSF plugin, and cleaned up a bit of the other code, as well as removing pstdint.h since it's no longer needed.

Naram Qashat authored on 2013/04/23 20:29:21
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - 2SF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-17
4
+ * Last modification on 2013-04-23
5 5
  *
6 6
  * Based on a modified vio2sf v0.22c
7 7
  *
... ...
@@ -185,12 +185,12 @@ bool XSFPlayer_2SF::Load2SF(XSFFile *xSFToLoad)
185 185
 
186 186
 XSFPlayer_2SF::XSFPlayer_2SF(const std::string &filename) : XSFPlayer()
187 187
 {
188
-	this->xSF = new XSFFile(filename, 4, 8);
188
+	this->xSF.reset(new XSFFile(filename, 4, 8));
189 189
 }
190 190
 
191 191
 XSFPlayer_2SF::XSFPlayer_2SF(const std::wstring &filename) : XSFPlayer()
192 192
 {
193
-	this->xSF = new XSFFile(filename, 4, 8);
193
+	this->xSF.reset(new XSFFile(filename, 4, 8));
194 194
 }
195 195
 
196 196
 bool XSFPlayer_2SF::Load()
... ...
@@ -199,7 +199,7 @@ bool XSFPlayer_2SF::Load()
199 199
 	sndifwork.sync_type = this->xSF->GetTagValue("_2sf_sync_type", 0);
200 200
 
201 201
 	sndifwork.xfs_load = false;
202
-	if (!this->Load2SF(this->xSF))
202
+	if (!this->Load2SF(this->xSF.get()))
203 203
 		return false;
204 204
 
205 205
 	if (NDS_Init())
Browse code

Updating in_2sf to use a newish version of DeSmuME, 0.9.9 from SVN. Somewhat cleaned up as well, but not everything because it's a pain in the ass.

Naram Qashat authored on 2013/04/18 17:22:55
Showing 1 changed files
... ...
@@ -1,13 +1,13 @@
1 1
 /*
2 2
  * xSF - 2SF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-30
4
+ * Last modification on 2013-04-17
5 5
  *
6 6
  * Based on a modified vio2sf v0.22c
7 7
  *
8 8
  * Partially based on the vio*sf framework
9 9
  *
10
- * Utilizes a modified DeSmuME v0.9.8 for playback
10
+ * Utilizes a modified DeSmuME v0.9.9 SVN for playback
11 11
  * http://desmume.org/
12 12
  */
13 13
 
... ...
@@ -16,10 +16,7 @@
16 16
 #include "convert.h"
17 17
 #include "XSFPlayer.h"
18 18
 #include "XSFCommon.h"
19
-#include "desmume/armcpu.h"
20
-#include "desmume/saves.h"
21 19
 #include "desmume/NDSSystem.h"
22
-#include "desmume/cp15.h"
23 20
 
24 21
 class XSFPlayer_2SF : public XSFPlayer
25 22
 {
... ...
@@ -105,6 +102,8 @@ static SoundInterface_struct SNDIF_2SF =
105 102
 	SNDIFMuteAudio,
106 103
 	SNDIFUnMuteAudio,
107 104
 	SNDIFSetVolume,
105
+	nullptr,
106
+	nullptr,
108 107
 	nullptr
109 108
 };
110 109
 
... ...
@@ -217,6 +216,7 @@ bool XSFPlayer_2SF::Load()
217 216
 		gameInfo.loadData(reinterpret_cast<char *>(&this->rom[0]), this->rom.size() - 1);
218 217
 	}
219 218
 
219
+	CommonSettings.use_jit = true;
220 220
 	NDS_Reset();
221 221
 
222 222
 	execute = true;
Browse code

Removed the save state loading from the 2SF player and updated the VBA-M code to the latest revision.

Naram Qashat authored on 2013/04/12 20:27:27
Showing 1 changed files
... ...
@@ -23,6 +23,12 @@
23 23
 
24 24
 class XSFPlayer_2SF : public XSFPlayer
25 25
 {
26
+	std::vector<uint8_t> rom;
27
+
28
+	void Map2SFSection(const std::vector<uint8_t> &section);
29
+	bool Map2SF(XSFFile *xSFToLoad);
30
+	bool RecursiveLoad2SF(XSFFile *xSFToLoad, int level);
31
+	bool Load2SF(XSFFile *xSFToLoad);
26 32
 public:
27 33
 	XSFPlayer_2SF(const std::string &filename);
28 34
 	XSFPlayer_2SF(const std::wstring &filename);
... ...
@@ -47,329 +53,6 @@ XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
47 53
 
48 54
 volatile bool execute = false;
49 55
 
50
-static struct
51
-{
52
-	std::vector<uint8_t> rom, state;
53
-	unsigned stateptr;
54
-} loaderwork;
55
-
56
-static inline uint16_t Get16BitsLE(const uint8_t *input)
57
-{
58
-	return input[0] | (input[1] << 8);
59
-}
60
-
61
-static void load_getstateinit(unsigned ptr)
62
-{
63
-	loaderwork.stateptr = ptr;
64
-}
65
-
66
-static void load_getsta(Status_Reg *ptr, unsigned l)
67
-{
68
-	unsigned s = l << 2;
69
-	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
70
-		return;
71
-	if (ptr)
72
-		for (unsigned i = 0; i < l; ++i)
73
-		{
74
-			uint32_t st = Get32BitsLE(&loaderwork.state[loaderwork.stateptr + (i << 2)]);
75
-			ptr[i].bits.N = (st >> 31) & 1;
76
-			ptr[i].bits.Z = (st >> 30) & 1;
77
-			ptr[i].bits.C = (st >> 29) & 1;
78
-			ptr[i].bits.V = (st >> 28) & 1;
79
-			ptr[i].bits.Q = (st >> 27) & 1;
80
-			ptr[i].bits.RAZ = (st >> 8) & ((1 << 19) - 1);
81
-			ptr[i].bits.I = (st >> 7) & 1;
82
-			ptr[i].bits.F = (st >> 6) & 1;
83
-			ptr[i].bits.T = (st >> 5) & 1;
84
-			ptr[i].bits.mode = (st >> 0) & 0x1f;
85
-		}
86
-	loaderwork.stateptr += s;
87
-}
88
-
89
-static void load_getbool(bool *ptr, unsigned l)
90
-{
91
-	unsigned s = l << 2;
92
-	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
93
-		return;
94
-	if (ptr)
95
-		for (unsigned i = 0; i < l; ++i)
96
-			ptr[i] = !!Get32BitsLE(&loaderwork.state[loaderwork.stateptr + (i << 2)]);
97
-	loaderwork.stateptr += s;
98
-}
99
-
100
-#ifdef SIGNED_IS_NOT_2S_COMPLEMENT
101
-/* 2's complement */
102
-static inline int32_t u32tos32(uint32_t v) { return static_cast<int32_t>((static_cast<int64_t>(v) ^ 0x8000) - 0x8000); }
103
-#else
104
-/* 2's complement */
105
-static inline int32_t u32tos32(uint32_t v) { return static_cast<int32_t>(v); }
106
-#endif
107
-
108
-static void load_gets32(int32_t *ptr, unsigned l)
109
-{
110
-	unsigned s = l << 2;
111
-	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
112
-		return;
113
-	if (ptr)
114
-		for (unsigned i = 0; i < l; ++i)
115
-			ptr[i] = u32tos32(Get32BitsLE(&loaderwork.state[loaderwork.stateptr + (i << 2)]));
116
-	loaderwork.stateptr += s;
117
-}
118
-
119
-static void load_getu32(uint32_t *ptr, unsigned l)
120
-{
121
-	unsigned s = l << 2;
122
-	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
123
-		return;
124
-	if (ptr)
125
-		for (unsigned i = 0; i < l; ++i)
126
-			ptr[i] = Get32BitsLE(&loaderwork.state[loaderwork.stateptr + (i << 2)]);
127
-	loaderwork.stateptr += s;
128
-}
129
-
130
-static void load_getu16(uint16_t *ptr, unsigned l)
131
-{
132
-	unsigned s = l << 1;
133
-	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
134
-		return;
135
-	if (ptr)
136
-		for (unsigned i = 0; i < l; ++i)
137
-			ptr[i] = Get16BitsLE(&loaderwork.state[loaderwork.stateptr + (i << 1)]);
138
-	loaderwork.stateptr += s;
139
-}
140
-
141
-static void load_getu8(uint8_t *ptr, unsigned l)
142
-{
143
-	unsigned s = l;
144
-	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
145
-		return;
146
-	if (ptr)
147
-		for (unsigned i = 0; i < l; ++i)
148
-			ptr[i] = loaderwork.state[loaderwork.stateptr + i];
149
-	loaderwork.stateptr += s;
150
-}
151
-
152
-/*static void gdb_stub_fix(armcpu_t *armcpu)
153
-{*/
154
-	/* armcpu->R[15] = armcpu->instruct_adr; */
155
-	/*armcpu->next_instruction = armcpu->instruct_adr;
156
-	if(armcpu->CPSR.bits.T == 0)
157
-	{
158
-		armcpu->instruction = MMU_read32(armcpu->proc_ID, armcpu->next_instruction);
159
-		armcpu->instruct_adr = armcpu->next_instruction;
160
-		armcpu->next_instruction += 4;
161
-		armcpu->R[15] = armcpu->next_instruction + 4;
162
-	}
163
-	else
164
-	{
165
-		armcpu->instruction = MMU_read16(armcpu->proc_ID, armcpu->next_instruction);
166
-		armcpu->instruct_adr = armcpu->next_instruction;
167
-		armcpu->next_instruction += 2;
168
-		armcpu->R[15] = armcpu->next_instruction + 2;
169
-	}
170
-}*/
171
-
172
-static void load_setstate()
173
-{
174
-	if (loaderwork.state.empty())
175
-		return;
176
-
177
-	//std::vector<uint8_t> savestate = std::vector<uint8_t>(&loaderwork.state[0], &loaderwork.state[loaderwork.state.size()]);
178
-	EMUFILE_MEMORY f(&loaderwork.state);
179
-	if (!savestate_load(&f))
180
-	{
181
-	//reset the emulator first to clean out the host's state
182
-
183
-		//while the series of resets below should work,
184
-		//we are testing the robustness of the savestate system with this full reset.
185
-		//the full reset wipes more things, so we can make sure that they are being restored correctly
186
-		//extern bool _HACK_DONT_STOPMOVIE;
187
-		//_HACK_DONT_STOPMOVIE = true;
188
-		NDS_Reset();
189
-		//_HACK_DONT_STOPMOVIE = false;
190
-
191
-		//reset some options to their old defaults which werent saved
192
-		//nds.debugConsole = false;
193
-
194
-		/* Skip over "Desmume Save File" crap */
195
-		load_getstateinit(0x17);
196
-
197
-		/* Read ARM7 cpu registers */
198
-		//load_getu32(&NDS_ARM7.proc_ID, 1);
199
-		load_getu32(nullptr, 1);
200
-		load_getu32(&NDS_ARM7.instruction, 1);
201
-		load_getu32(&NDS_ARM7.instruct_adr, 1);
202
-		load_getu32(&NDS_ARM7.next_instruction, 1);
203
-		load_getu32(NDS_ARM7.R, 16);
204
-		load_getsta(&NDS_ARM7.CPSR, 1);
205
-		load_getsta(&NDS_ARM7.SPSR, 1);
206
-		load_getu32(&NDS_ARM7.R13_usr, 1);
207
-		load_getu32(&NDS_ARM7.R14_usr, 1);
208
-		load_getu32(&NDS_ARM7.R13_svc, 1);
209
-		load_getu32(&NDS_ARM7.R14_svc, 1);
210
-		load_getu32(&NDS_ARM7.R13_abt, 1);
211
-		load_getu32(&NDS_ARM7.R14_abt, 1);
212
-		load_getu32(&NDS_ARM7.R13_und, 1);
213
-		load_getu32(&NDS_ARM7.R14_und, 1);
214
-		load_getu32(&NDS_ARM7.R13_irq, 1);
215
-		load_getu32(&NDS_ARM7.R14_irq, 1);
216
-		load_getu32(&NDS_ARM7.R8_fiq, 1);
217
-		load_getu32(&NDS_ARM7.R9_fiq, 1);
218
-		load_getu32(&NDS_ARM7.R10_fiq, 1);
219
-		load_getu32(&NDS_ARM7.R11_fiq, 1);
220
-		load_getu32(&NDS_ARM7.R12_fiq, 1);
221
-		load_getu32(&NDS_ARM7.R13_fiq, 1);
222
-		load_getu32(&NDS_ARM7.R14_fiq, 1);
223
-		load_getsta(&NDS_ARM7.SPSR_svc, 1);
224
-		load_getsta(&NDS_ARM7.SPSR_abt, 1);
225
-		load_getsta(&NDS_ARM7.SPSR_und, 1);
226
-		load_getsta(&NDS_ARM7.SPSR_irq, 1);
227
-		load_getsta(&NDS_ARM7.SPSR_fiq, 1);
228
-		load_getu32(&NDS_ARM7.intVector, 1);
229
-		load_getu8(&NDS_ARM7.LDTBit, 1);
230
-		load_getbool(&NDS_ARM7.waitIRQ, 1);
231
-		bool tmpbool;
232
-		//load_getbool(&NDS_ARM7.wIRQ, 1);
233
-		//loaderwork.stateptr += 4;
234
-		load_getbool(nullptr, 1);
235
-		//load_getbool(&NDS_ARM7.halt_IE_and_IF, 1);
236
-		//load_getbool(&NDS_ARM7.wirq, 1);
237
-		//loaderwork.stateptr += 4;
238
-		//load_getbool(nullptr, 1);
239
-		//load_getbool(&NDS_ARM7.intrWaitARM_state, 1);
240
-		load_getbool(&tmpbool, 1);
241
-		//NDS_ARM7.intrWaitARM_state = tmpbool;
242
-
243
-		/* Read ARM9 cpu registers */
244
-		//load_getu32(&NDS_ARM9.proc_ID, 1);
245
-		load_getu32(nullptr, 1);
246
-		load_getu32(&NDS_ARM9.instruction, 1);
247
-		load_getu32(&NDS_ARM9.instruct_adr, 1);
248
-		load_getu32(&NDS_ARM9.next_instruction, 1);
249
-		load_getu32(NDS_ARM9.R, 16);
250
-		load_getsta(&NDS_ARM9.CPSR, 1);
251
-		load_getsta(&NDS_ARM9.SPSR, 1);
252
-		load_getu32(&NDS_ARM9.R13_usr, 1);
253
-		load_getu32(&NDS_ARM9.R14_usr, 1);
254
-		load_getu32(&NDS_ARM9.R13_svc, 1);
255
-		load_getu32(&NDS_ARM9.R14_svc, 1);
256
-		load_getu32(&NDS_ARM9.R13_abt, 1);
257
-		load_getu32(&NDS_ARM9.R14_abt, 1);
258
-		load_getu32(&NDS_ARM9.R13_und, 1);
259
-		load_getu32(&NDS_ARM9.R14_und, 1);
260
-		load_getu32(&NDS_ARM9.R13_irq, 1);
261
-		load_getu32(&NDS_ARM9.R14_irq, 1);
262
-		load_getu32(&NDS_ARM9.R8_fiq, 1);
263
-		load_getu32(&NDS_ARM9.R9_fiq, 1);
264
-		load_getu32(&NDS_ARM9.R10_fiq, 1);
265
-		load_getu32(&NDS_ARM9.R11_fiq, 1);
266
-		load_getu32(&NDS_ARM9.R12_fiq, 1);
267
-		load_getu32(&NDS_ARM9.R13_fiq, 1);
268
-		load_getu32(&NDS_ARM9.R14_fiq, 1);
269
-		load_getsta(&NDS_ARM9.SPSR_svc, 1);
270
-		load_getsta(&NDS_ARM9.SPSR_abt, 1);
271
-		load_getsta(&NDS_ARM9.SPSR_und, 1);
272
-		load_getsta(&NDS_ARM9.SPSR_irq, 1);
273
-		load_getsta(&NDS_ARM9.SPSR_fiq, 1);
274
-		load_getu32(&NDS_ARM9.intVector, 1);
275
-		load_getu8(&NDS_ARM9.LDTBit, 1);
276
-		load_getbool(&NDS_ARM9.waitIRQ, 1);
277
-		//load_getbool(&NDS_ARM9.wIRQ, 1);
278
-		//loaderwork.stateptr += 4;
279
-		load_getbool(nullptr, 1);
280
-		//load_getbool(&NDS_ARM9.halt_IE_and_IF, 1);
281
-		//load_getbool(&NDS_ARM9.wirq, 1);
282
-		//loaderwork.stateptr += 4;
283
-		//load_getbool(nullptr, 1);
284
-		//load_getbool(&NDS_ARM9.intrWaitARM_state, 1);
285
-		load_getbool(&tmpbool, 1);
286
-		//NDS_ARM9.intrWaitARM_state = tmpbool;
287
-
288
-		/* Read in other internal variables that are important */
289
-		//int32_t tmps32;
290
-		//load_gets32(&nds.ARM9Cycle, 1);
291
-		load_gets32(nullptr, 1);
292
-		//load_gets32(&nds.ARM7Cycle, 1);
293
-		load_gets32(nullptr, 1);
294
-		load_gets32(&nds.cycles, 1);
295
-		int32_t tmps32_array[4];
296
-		//load_getu64(nds.timerCycle[0], 4);
297
-		load_gets32(tmps32_array, 4);
298
-		for (int i = 0; i < 4; ++i)
299
-			nds.timerCycle[0][i] = tmps32_array[i];
300
-		//load_getu64(nds.timerCycle[1], 4);
301
-		load_gets32(tmps32_array, 4);
302
-		for (int i = 0; i < 4; ++i)
303
-			nds.timerCycle[1][i] = tmps32_array[i];
304
-		//bool tmpbool_array[4];
305
-		//load_getbool(nds.timerOver[0], 4);
306
-		//loaderwork.stateptr += 16;
307
-		load_getbool(nullptr, 4);
308
-		//load_getbool(nds.timerOver[1], 4);
309
-		//loaderwork.stateptr += 16;
310
-		load_getbool(nullptr, 4);
311
-		//load_gets32(&nds.nextHBlank, 1);
312
-		//loaderwork.stateptr += 4;
313
-		load_gets32(nullptr, 1);
314
-		load_getu32(&nds.VCount, 1);
315
-		load_getu32(&nds.old, 1);
316
-		//load_gets32(&nds.diff, 1);
317
-		//loaderwork.stateptr += 4;
318
-		load_gets32(nullptr, 1);
319
-		//load_getbool(&nds.lignerendu, 1);
320
-		//loaderwork.stateptr += 4;
321
-		load_getbool(nullptr, 1);
322
-		load_getu16(nullptr, 1);
323
-		load_getu16(nullptr, 1);
324
-
325
-		/* Read in memory/registers specific to the ARM9 */
326
-		//load_getu8 (MMU.ARM9_ITCM, 0x8000);
327
-		load_getu8(nullptr, 0x8000);
328
-		load_getu8 (MMU.ARM9_DTCM, 0x4000);
329
-		//load_getu8 (MMU.MAIN_MEM, 0x1000000);
330
-		//load_getu8(MMU.MAIN_MEM, 0x800000);
331
-		//load_getu8(nullptr, 0x800000);
332
-		//load_getu8(nullptr, 0x1000000);
333
-		load_getu8(nullptr, 0xFF8000);
334
-		load_getu8(MMU.ARM9_ITCM, 0x8000);
335
-		load_getu8 (MMU.MAIN_MEM/*+0x400000*/, 0x400000);
336
-		load_getu8 (MMU.ARM9_REG, 0x10000);
337
-		load_getu8 (MMU.ARM9_VMEM, 0x800);
338
-		load_getu8 (MMU.ARM9_OAM, 0x800);
339
-		//uint8_t tmpu8_ABG[0x80000];
340
-		//load_getu8 (ARM9Mem.ARM9_ABG, 0x80000);
341
-		//loaderwork.stateptr += 0x80000;
342
-		load_getu8(nullptr, 0x80000);
343
-		//uint8_t tmpu8_BBG[0x20000];
344
-		//load_getu8 (ARM9Mem.ARM9_BBG, 0x20000);
345
-		//loaderwork.stateptr += 0x20000;
346
-		load_getu8(nullptr, 0x20000);
347
-		//uint8_t tmpu8_AOBJ[0x40000];
348
-		//load_getu8 (ARM9Mem.ARM9_AOBJ, 0x40000);
349
-		//loaderwork.stateptr += 0x40000;
350
-		load_getu8(nullptr, 0x40000);
351
-		//uint8_t tmpu8_BOBJ[0x20000];
352
-		//load_getu8 (ARM9Mem.ARM9_BOBJ, 0x20000);
353
-		//loaderwork.stateptr += 0x20000;
354
-		load_getu8(nullptr, 0x20000);
355
-		load_getu8 (MMU.ARM9_LCD, 0xA4000);
356
-		//loaderwork.stateptr += 12;
357
-
358
-		/* Read in memory/registers specific to the ARM7 */
359
-		load_getu8 (MMU.ARM7_ERAM, 0x10000);
360
-		load_getu8 (MMU.ARM7_REG, 0x10000);
361
-		load_getu8 (MMU.ARM7_WIRAM, 0x10000);
362
-
363
-		/* Read in shared memory */
364
-		load_getu8 (MMU.SWIRAM, 0x8000);
365
-
366
-		//gdb_stub_fix(&NDS_ARM9);
367
-		//gdb_stub_fix(&NDS_ARM7);
368
-
369
-		loadstate();
370
-	}
371
-}
372
-
373 56
 static struct
374 57
 {
375 58
 	std::vector<uint8_t> buf;
... ...
@@ -432,71 +115,44 @@ SoundInterface_struct *SNDCoreList[] =
432 115
 	nullptr
433 116
 };
434 117
 
435
-static void Map2SFSection(const std::vector<uint8_t> &section, bool isSave)
118
+void XSFPlayer_2SF::Map2SFSection(const std::vector<uint8_t> &section)
436 119
 {
437
-	auto &data = isSave ? loaderwork.state : loaderwork.rom;
438
-
439 120
 	uint32_t offset = Get32BitsLE(&section[0]), size = Get32BitsLE(&section[4]), finalSize = size + offset;
440
-	if (!isSave)
441
-		finalSize = NextHighestPowerOf2(finalSize);
442
-	if (data.empty())
443
-		data.resize(finalSize + 10, 0);
444
-	else if (data.size() < size + offset)
445
-		data.resize(offset + finalSize + 10);
446
-	memcpy(&data[offset], &section[8], size);
121
+	finalSize = NextHighestPowerOf2(finalSize);
122
+	if (this->rom.empty())
123
+		this->rom.resize(finalSize + 10, 0);
124
+	else if (this->rom.size() < size + offset)
125
+		this->rom.resize(offset + finalSize + 10);
126
+	memcpy(&this->rom[offset], &section[8], size);
447 127
 }
448 128
 
449
-static bool Map2SF(XSFFile *xSF)
129
+bool XSFPlayer_2SF::Map2SF(XSFFile *xSFToLoad)
450 130
 {
451
-	if (!xSF->IsValidType(0x24))
131
+	if (!xSFToLoad->IsValidType(0x24))
452 132
 		return false;
453 133
 
454
-	auto &reservedSection = xSF->GetReservedSection(), &programSection = xSF->GetProgramSection();
455
-
456
-	if (!reservedSection.empty())
457
-	{
458
-		size_t reservedPosition = 0, reservedSize = reservedSection.size();
459
-		while (reservedPosition + 12 < reservedSize)
460
-		{
461
-			uint32_t saveSize = Get32BitsLE(&reservedSection[reservedPosition + 4]);
462
-			if (Get32BitsLE(&reservedSection[reservedPosition]) == 0x45564153) // "SAVE"
463
-			{
464
-				if (reservedPosition + 12 + saveSize > reservedSize)
465
-					return false;
466
-
467
-				uint8_t tmpSaveUncompressed[8];
468
-				unsigned long saveUncompressedSize = 8;
469
-				uncompress(tmpSaveUncompressed, &saveUncompressedSize, &reservedSection[reservedPosition + 12], saveSize);
470
-				saveUncompressedSize = Get32BitsLE(&tmpSaveUncompressed[4]) + 8;
471
-				auto saveUncompressed = std::vector<uint8_t>(saveUncompressedSize);
472
-				uncompress(&saveUncompressed[0], &saveUncompressedSize, &reservedSection[reservedPosition + 12], saveSize);
473
-
474
-				Map2SFSection(saveUncompressed, true);
475
-			}
476
-			reservedPosition += saveSize + 12;
477
-		}
478
-	}
134
+	const auto &programSection = xSFToLoad->GetProgramSection();
479 135
 
480 136
 	if (!programSection.empty())
481
-		Map2SFSection(programSection, false);
137
+		this->Map2SFSection(programSection);
482 138
 
483 139
 	return true;
484 140
 }
485 141
 
486
-static bool RecursiveLoad2SF(XSFFile *xSF, int level)
142
+bool XSFPlayer_2SF::RecursiveLoad2SF(XSFFile *xSFToLoad, int level)
487 143
 {
488
-	if (level <= 10 && xSF->GetTagExists("_lib"))
144
+	if (level <= 10 && xSFToLoad->GetTagExists("_lib"))
489 145
 	{
490 146
 #ifdef _WIN32
491
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 4, 8));
147
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetWStr()) + xSFToLoad->GetTagValue("_lib").GetWStr(), 4, 8));
492 148
 #else
493
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 4, 8));
149
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetAnsi()) + xSFToLoad->GetTagValue("_lib").GetAnsi(), 4, 8));
494 150
 #endif
495
-		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
151
+		if (!this->RecursiveLoad2SF(libxSF.get(), level + 1))
496 152
 			return false;
497 153
 	}
498 154
 
499
-	if (!Map2SF(xSF))
155
+	if (!this->Map2SF(xSFToLoad))
500 156
 		return false;
501 157
 
502 158
 	unsigned n = 2;
... ...
@@ -505,15 +161,15 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
505 161
 	{
506 162
 		found = false;
507 163
 		std::string libTag = "_lib" + stringify(n++);
508
-		if (xSF->GetTagExists(libTag))
164
+		if (xSFToLoad->GetTagExists(libTag))
509 165
 		{
510 166
 			found = true;
511 167
 #ifdef _WIN32
512
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 4, 8));
168
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetWStr()) + xSFToLoad->GetTagValue(libTag).GetWStr(), 4, 8));
513 169
 #else
514
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 4, 8));
170
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSFToLoad->GetFilename().GetAnsi()) + xSFToLoad->GetTagValue(libTag).GetAnsi(), 4, 8));
515 171
 #endif
516
-			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
172
+			if (!this->RecursiveLoad2SF(libxSF.get(), level + 1))
517 173
 				return false;
518 174
 		}
519 175
 	} while (found);
... ...
@@ -521,13 +177,11 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
521 177
 	return true;
522 178
 }
523 179
 
524
-static bool Load2SF(XSFFile *xSF)
180
+bool XSFPlayer_2SF::Load2SF(XSFFile *xSFToLoad)
525 181
 {
526
-	loaderwork.rom.clear();
527
-	loaderwork.state.clear();
528
-	loaderwork.stateptr = 0;
182
+	this->rom.clear();
529 183
 
530
-	return RecursiveLoad2SF(xSF, 1);
184
+	return this->RecursiveLoad2SF(xSFToLoad, 1);
531 185
 }
532 186
 
533 187
 XSFPlayer_2SF::XSFPlayer_2SF(const std::string &filename) : XSFPlayer()
... ...
@@ -542,11 +196,11 @@ XSFPlayer_2SF::XSFPlayer_2SF(const std::wstring &filename) : XSFPlayer()
542 196
 
543 197
 bool XSFPlayer_2SF::Load()
544 198
 {
545
-	int frames = xSF->GetTagValue("_frames", -1);
546
-	sndifwork.sync_type = xSF->GetTagValue("_2sf_sync_type", 0);
199
+	int frames = this->xSF->GetTagValue("_frames", -1);
200
+	sndifwork.sync_type = this->xSF->GetTagValue("_2sf_sync_type", 0);
547 201
 
548 202
 	sndifwork.xfs_load = false;
549
-	if (!Load2SF(this->xSF))
203
+	if (!this->Load2SF(this->xSF))
550 204
 		return false;
551 205
 
552 206
 	if (NDS_Init())
... ...
@@ -557,103 +211,23 @@ bool XSFPlayer_2SF::Load()
557 211
 	execute = false;
558 212
 
559 213
 	MMU_unsetRom();
560
-	if (!loaderwork.rom.empty())
214
+	if (!this->rom.empty())
561 215
 	{
562
-		NDS_SetROM(&loaderwork.rom[0], loaderwork.rom.size() - 1);
563
-		gameInfo.loadData(reinterpret_cast<char *>(&loaderwork.rom[0]), loaderwork.rom.size() - 1);
216
+		NDS_SetROM(&this->rom[0], this->rom.size() - 1);
217
+		gameInfo.loadData(reinterpret_cast<char *>(&this->rom[0]), this->rom.size() - 1);
564 218
 	}
565 219
 
566 220
 	NDS_Reset();
567 221
 
568 222
 	execute = true;
569 223
 
570
-	if (!loaderwork.state.empty())
571
-	{
572
-		armcp15_t *c9 = reinterpret_cast<armcp15_t *>(NDS_ARM9.coproc[15]);
573
-		//int proc;
574
-		if (frames == -1)
575
-		{
576
-			/* set initial ARM9 coprocessor state */
577
-
578
-			armcp15_moveARM2CP(c9, 0x00000000, 0x01, 0x00, 0, 0);
579
-			armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x05, 0, 0);
580
-			armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x06, 0, 0);
581
-			armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x0a, 0, 4);
582
-			armcp15_moveARM2CP(c9, 0x04000033, 0x06, 0x00, 0, 4);
583
-			armcp15_moveARM2CP(c9, 0x0200002d, 0x06, 0x01, 0, 0);
584
-			armcp15_moveARM2CP(c9, 0x027e0021, 0x06, 0x02, 0, 0);
585
-			armcp15_moveARM2CP(c9, 0x08000035, 0x06, 0x03, 0, 0);
586
-			armcp15_moveARM2CP(c9, 0x027e001b, 0x06, 0x04, 0, 0);
587
-			armcp15_moveARM2CP(c9, 0x0100002f, 0x06, 0x05, 0, 0);
588
-			armcp15_moveARM2CP(c9, 0xffff001d, 0x06, 0x06, 0, 0);
589
-			armcp15_moveARM2CP(c9, 0x027ff017, 0x06, 0x07, 0, 0);
590
-			armcp15_moveARM2CP(c9, 0x00000020, 0x09, 0x01, 0, 1);
591
-
592
-			armcp15_moveARM2CP(c9, 0x027e000a, 0x09, 0x01, 0, 0);
593
-
594
-			armcp15_moveARM2CP(c9, 0x00000042, 0x02, 0x00, 0, 1);
595
-			armcp15_moveARM2CP(c9, 0x00000042, 0x02, 0x00, 0, 0);
596
-			armcp15_moveARM2CP(c9, 0x00000002, 0x03, 0x00, 0, 0);
597
-			armcp15_moveARM2CP(c9, 0x05100011, 0x05, 0x00, 0, 3);
598
-			armcp15_moveARM2CP(c9, 0x15111011, 0x05, 0x00, 0, 2);
599
-			armcp15_moveARM2CP(c9, 0x07dd1e10, 0x01, 0x00, 0, 0);
600
-			armcp15_moveARM2CP(c9, 0x0005707d, 0x01, 0x00, 0, 0);
601
-
602
-			armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x0a, 0, 4);
603
-			armcp15_moveARM2CP(c9, 0x02004000, 0x07, 0x05, 0, 1);
604
-			armcp15_moveARM2CP(c9, 0x02004000, 0x07, 0x0e, 0, 1);
605
-
606
-			/* set initial timer state */
607
-
608
-			/*MMU_write16(0, REG_TM0CNTL, 0x0000);
609
-			MMU_write16(0, REG_TM0CNTH, 0x00C1);
610
-			MMU_write16(1, REG_TM0CNTL, 0x0000);
611
-			MMU_write16(1, REG_TM0CNTH, 0x00C1);
612
-			MMU_write16(1, REG_TM1CNTL, 0xf7e7);
613
-			MMU_write16(1, REG_TM1CNTH, 0x00C1);*/
614
-
615
-			/* set initial interrupt state */
616
-
617
-			MMU.reg_IME[0] = 0x00000001;
618
-			MMU.reg_IE[0]  = 0x00042001;
619
-			MMU.reg_IME[1] = 0x00000001;
620
-			MMU.reg_IE[1]  = 0x0104009d;
621
-		}
622
-		else if (frames > 0)
623
-		{
624
-			/* execute boot code */
625
-			for (int i = 0; i < frames; ++i)
626
-				NDS_exec<true>();
627
-		}
628
-
629
-		/* load state */
630
-
631
-		execute = false;
632
-		SPU_Reset();
633
-
634
-		load_setstate();
635
-		loaderwork.state.clear();
636
-
637
-		if (frames == -1)
638
-			armcp15_moveARM2CP(c9, (NDS_ARM9.R13_irq & 0x0fff0000) | 0x0a, 0x09, 0x01, 0, 0);
639
-
640
-		/* restore timer state */
641
-
642
-		/*for (proc = 0; proc < 2; proc++)
643
-		{
644
-			MMU_write16(proc, REG_TM0CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM0CNTH & 0xFFF));
645
-			MMU_write16(proc, REG_TM1CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM1CNTH & 0xFFF));
646
-			MMU_write16(proc, REG_TM2CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM2CNTH & 0xFFF));
647
-			MMU_write16(proc, REG_TM3CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM3CNTH & 0xFFF));
648
-		}*/
649
-	}
650
-	else if (frames > 0)
224
+	if (frames > 0)
651 225
 	{
652 226
 		/* skip 1 sec */
653 227
 		for (int i = 0; i < frames; ++i)
654 228
 			NDS_exec<false>();
655 229
 	}
656
-	execute = true;
230
+
657 231
 	sndifwork.xfs_load = true;
658 232
 	//CommonSettings.spu_advanced = true;
659 233
 	//CommonSettings.advanced_timing = false;
... ...
@@ -728,7 +302,5 @@ void XSFPlayer_2SF::Terminate()
728 302
 	MMU_unsetRom();
729 303
 	NDS_DeInit();
730 304
 
731
-	loaderwork.rom.clear();
732
-	loaderwork.state.clear();
733
-	loaderwork.stateptr = 0;
305
+	this->rom.clear();
734 306
 }
Browse code

Cleanup of some warnings, updating modification dates, using nullptr instead of NULL in some cases.

Naram Qashat authored on 2013/03/30 16:17:42
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - 2SF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-25
4
+ * Last modification on 2013-03-30
5 5
  *
6 6
  * Based on a modified vio2sf v0.22c
7 7
  *
... ...
@@ -196,7 +196,7 @@ static void load_setstate()
196 196
 
197 197
 		/* Read ARM7 cpu registers */
198 198
 		//load_getu32(&NDS_ARM7.proc_ID, 1);
199
-		load_getu32(NULL, 1);
199
+		load_getu32(nullptr, 1);
200 200
 		load_getu32(&NDS_ARM7.instruction, 1);
201 201
 		load_getu32(&NDS_ARM7.instruct_adr, 1);
202 202
 		load_getu32(&NDS_ARM7.next_instruction, 1);
... ...
@@ -231,18 +231,18 @@ static void load_setstate()
231 231
 		bool tmpbool;
232 232
 		//load_getbool(&NDS_ARM7.wIRQ, 1);
233 233
 		//loaderwork.stateptr += 4;
234
-		load_getbool(NULL, 1);
234
+		load_getbool(nullptr, 1);
235 235
 		//load_getbool(&NDS_ARM7.halt_IE_and_IF, 1);
236 236
 		//load_getbool(&NDS_ARM7.wirq, 1);
237 237
 		//loaderwork.stateptr += 4;
238
-		//load_getbool(NULL, 1);
238
+		//load_getbool(nullptr, 1);
239 239
 		//load_getbool(&NDS_ARM7.intrWaitARM_state, 1);
240 240
 		load_getbool(&tmpbool, 1);
241 241
 		//NDS_ARM7.intrWaitARM_state = tmpbool;
242 242
 
243 243
 		/* Read ARM9 cpu registers */
244 244
 		//load_getu32(&NDS_ARM9.proc_ID, 1);
245
-		load_getu32(NULL, 1);
245
+		load_getu32(nullptr, 1);
246 246
 		load_getu32(&NDS_ARM9.instruction, 1);
247 247
 		load_getu32(&NDS_ARM9.instruct_adr, 1);
248 248
 		load_getu32(&NDS_ARM9.next_instruction, 1);
... ...
@@ -276,11 +276,11 @@ static void load_setstate()
276 276
 		load_getbool(&NDS_ARM9.waitIRQ, 1);
277 277
 		//load_getbool(&NDS_ARM9.wIRQ, 1);
278 278
 		//loaderwork.stateptr += 4;
279
-		load_getbool(NULL, 1);
279
+		load_getbool(nullptr, 1);
280 280
 		//load_getbool(&NDS_ARM9.halt_IE_and_IF, 1);
281 281
 		//load_getbool(&NDS_ARM9.wirq, 1);
282 282
 		//loaderwork.stateptr += 4;
283
-		//load_getbool(NULL, 1);
283
+		//load_getbool(nullptr, 1);
284 284
 		//load_getbool(&NDS_ARM9.intrWaitARM_state, 1);
285 285
 		load_getbool(&tmpbool, 1);
286 286
 		//NDS_ARM9.intrWaitARM_state = tmpbool;
... ...
@@ -288,9 +288,9 @@ static void load_setstate()
288 288
 		/* Read in other internal variables that are important */
289 289
 		//int32_t tmps32;
290 290
 		//load_gets32(&nds.ARM9Cycle, 1);
291
-		load_gets32(NULL, 1);
291
+		load_gets32(nullptr, 1);
292 292
 		//load_gets32(&nds.ARM7Cycle, 1);
293
-		load_gets32(NULL, 1);
293
+		load_gets32(nullptr, 1);
294 294
 		load_gets32(&nds.cycles, 1);
295 295
 		int32_t tmps32_array[4];
296 296
 		//load_getu64(nds.timerCycle[0], 4);
... ...
@@ -304,33 +304,33 @@ static void load_setstate()
304 304
 		//bool tmpbool_array[4];
305 305
 		//load_getbool(nds.timerOver[0], 4);
306 306
 		//loaderwork.stateptr += 16;
307
-		load_getbool(NULL, 4);
307
+		load_getbool(nullptr, 4);
308 308
 		//load_getbool(nds.timerOver[1], 4);
309 309
 		//loaderwork.stateptr += 16;
310
-		load_getbool(NULL, 4);
310
+		load_getbool(nullptr, 4);
311 311
 		//load_gets32(&nds.nextHBlank, 1);
312 312
 		//loaderwork.stateptr += 4;
313
-		load_gets32(NULL, 1);
313
+		load_gets32(nullptr, 1);
314 314
 		load_getu32(&nds.VCount, 1);
315 315
 		load_getu32(&nds.old, 1);
316 316
 		//load_gets32(&nds.diff, 1);
317 317
 		//loaderwork.stateptr += 4;
318
-		load_gets32(NULL, 1);
318
+		load_gets32(nullptr, 1);
319 319
 		//load_getbool(&nds.lignerendu, 1);
320 320
 		//loaderwork.stateptr += 4;
321
-		load_getbool(NULL, 1);
322
-		load_getu16(NULL, 1);
323
-		load_getu16(NULL, 1);
321
+		load_getbool(nullptr, 1);
322
+		load_getu16(nullptr, 1);
323
+		load_getu16(nullptr, 1);
324 324
 
325 325
 		/* Read in memory/registers specific to the ARM9 */
326 326
 		//load_getu8 (MMU.ARM9_ITCM, 0x8000);
327
-		load_getu8(NULL, 0x8000);
327
+		load_getu8(nullptr, 0x8000);
328 328
 		load_getu8 (MMU.ARM9_DTCM, 0x4000);
329 329
 		//load_getu8 (MMU.MAIN_MEM, 0x1000000);
330 330
 		//load_getu8(MMU.MAIN_MEM, 0x800000);
331
-		//load_getu8(NULL, 0x800000);
332
-		//load_getu8(NULL, 0x1000000);
333
-		load_getu8(NULL, 0xFF8000);
331
+		//load_getu8(nullptr, 0x800000);
332
+		//load_getu8(nullptr, 0x1000000);
333
+		load_getu8(nullptr, 0xFF8000);
334 334
 		load_getu8(MMU.ARM9_ITCM, 0x8000);
335 335
 		load_getu8 (MMU.MAIN_MEM/*+0x400000*/, 0x400000);
336 336
 		load_getu8 (MMU.ARM9_REG, 0x10000);
... ...
@@ -339,19 +339,19 @@ static void load_setstate()
339 339
 		//uint8_t tmpu8_ABG[0x80000];
340 340
 		//load_getu8 (ARM9Mem.ARM9_ABG, 0x80000);
341 341
 		//loaderwork.stateptr += 0x80000;
342
-		load_getu8(NULL, 0x80000);
342
+		load_getu8(nullptr, 0x80000);
343 343
 		//uint8_t tmpu8_BBG[0x20000];
344 344
 		//load_getu8 (ARM9Mem.ARM9_BBG, 0x20000);
345 345
 		//loaderwork.stateptr += 0x20000;
346
-		load_getu8(NULL, 0x20000);
346
+		load_getu8(nullptr, 0x20000);
347 347
 		//uint8_t tmpu8_AOBJ[0x40000];
348 348
 		//load_getu8 (ARM9Mem.ARM9_AOBJ, 0x40000);
349 349
 		//loaderwork.stateptr += 0x40000;
350
-		load_getu8(NULL, 0x40000);
350
+		load_getu8(nullptr, 0x40000);
351 351
 		//uint8_t tmpu8_BOBJ[0x20000];
352 352
 		//load_getu8 (ARM9Mem.ARM9_BOBJ, 0x20000);
353 353
 		//loaderwork.stateptr += 0x20000;
354
-		load_getu8(NULL, 0x20000);
354
+		load_getu8(nullptr, 0x20000);
355 355
 		load_getu8 (MMU.ARM9_LCD, 0xA4000);
356 356
 		//loaderwork.stateptr += 12;
357 357
 
... ...
@@ -422,14 +422,14 @@ static SoundInterface_struct SNDIF_2SF =
422 422
 	SNDIFMuteAudio,
423 423
 	SNDIFUnMuteAudio,
424 424
 	SNDIFSetVolume,
425
-	NULL
425
+	nullptr
426 426
 };
427 427
 
428 428
 SoundInterface_struct *SNDCoreList[] =
429 429
 {
430 430
 	&SNDIF_2SF,
431 431
 	&SNDDummy,
432
-	NULL
432
+	nullptr
433 433
 };
434 434
 
435 435
 static void Map2SFSection(const std::vector<uint8_t> &section, bool isSave)
Browse code

Utilized more C++11 constructs. Also attempted to fix issue with the Info Box not wanting to come up anymore if the file doesn't exist.

Naram Qashat authored on 2013/03/30 07:36:38
Showing 1 changed files
... ...
@@ -488,9 +488,9 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
488 488
 	if (level <= 10 && xSF->GetTagExists("_lib"))
489 489
 	{
490 490
 #ifdef _WIN32
491
-		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 4, 8));
491
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 4, 8));
492 492
 #else
493
-		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 4, 8));
493
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 4, 8));
494 494
 #endif
495 495
 		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
496 496
 			return false;
... ...
@@ -509,9 +509,9 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
509 509
 		{
510 510
 			found = true;
511 511
 #ifdef _WIN32
512
-			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 4, 8));
512
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 4, 8));
513 513
 #else
514
-			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 4, 8));
514
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 4, 8));
515 515
 #endif
516 516
 			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
517 517
 				return false;
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,734 @@
1
+/*
2
+ * xSF - 2SF Player
3
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
+ * Last modification on 2013-03-25
5
+ *
6
+ * Based on a modified vio2sf v0.22c
7
+ *
8
+ * Partially based on the vio*sf framework
9
+ *
10
+ * Utilizes a modified DeSmuME v0.9.8 for playback
11
+ * http://desmume.org/
12
+ */
13
+
14
+#include <memory>
15
+#include <zlib.h>
16
+#include "convert.h"
17
+#include "XSFPlayer.h"
18
+#include "XSFCommon.h"
19
+#include "desmume/armcpu.h"
20
+#include "desmume/saves.h"
21
+#include "desmume/NDSSystem.h"
22
+#include "desmume/cp15.h"
23
+
24
+class XSFPlayer_2SF : public XSFPlayer
25
+{
26
+public:
27
+	XSFPlayer_2SF(const std::string &filename);
28
+	XSFPlayer_2SF(const std::wstring &filename);
29
+	~XSFPlayer_2SF() { this->Terminate(); }
30
+	bool Load();
31
+	void GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples);
32
+	void Terminate();
33
+};
34
+
35
+const char *XSFPlayer::WinampDescription = "2SF Decoder";
36
+const char *XSFPlayer::WinampExts = "2sf;mini2sf\0DS Sound Format files (*.2sf;*.mini2sf)\0";
37
+
38
+XSFPlayer *XSFPlayer::Create(const std::string &fn)
39
+{
40
+	return new XSFPlayer_2SF(fn);
41
+}
42
+
43
+XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
44
+{
45
+	return new XSFPlayer_2SF(fn);
46
+}
47
+
48
+volatile bool execute = false;
49
+
50
+static struct
51
+{
52
+	std::vector<uint8_t> rom, state;
53
+	unsigned stateptr;
54
+} loaderwork;
55
+
56
+static inline uint16_t Get16BitsLE(const uint8_t *input)
57
+{
58
+	return input[0] | (input[1] << 8);
59
+}
60
+
61
+static void load_getstateinit(unsigned ptr)
62
+{
63
+	loaderwork.stateptr = ptr;
64
+}
65
+
66
+static void load_getsta(Status_Reg *ptr, unsigned l)
67
+{
68
+	unsigned s = l << 2;
69
+	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
70
+		return;
71
+	if (ptr)
72
+		for (unsigned i = 0; i < l; ++i)
73
+		{
74
+			uint32_t st = Get32BitsLE(&loaderwork.state[loaderwork.stateptr + (i << 2)]);
75
+			ptr[i].bits.N = (st >> 31) & 1;
76
+			ptr[i].bits.Z = (st >> 30) & 1;
77
+			ptr[i].bits.C = (st >> 29) & 1;
78
+			ptr[i].bits.V = (st >> 28) & 1;
79
+			ptr[i].bits.Q = (st >> 27) & 1;
80
+			ptr[i].bits.RAZ = (st >> 8) & ((1 << 19) - 1);
81
+			ptr[i].bits.I = (st >> 7) & 1;
82
+			ptr[i].bits.F = (st >> 6) & 1;
83
+			ptr[i].bits.T = (st >> 5) & 1;
84
+			ptr[i].bits.mode = (st >> 0) & 0x1f;
85
+		}
86
+	loaderwork.stateptr += s;
87
+}
88
+
89
+static void load_getbool(bool *ptr, unsigned l)
90
+{
91
+	unsigned s = l << 2;
92
+	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
93
+		return;
94
+	if (ptr)
95
+		for (unsigned i = 0; i < l; ++i)
96
+			ptr[i] = !!Get32BitsLE(&loaderwork.state[loaderwork.stateptr + (i << 2)]);
97
+	loaderwork.stateptr += s;
98
+}
99
+
100
+#ifdef SIGNED_IS_NOT_2S_COMPLEMENT
101
+/* 2's complement */
102
+static inline int32_t u32tos32(uint32_t v) { return static_cast<int32_t>((static_cast<int64_t>(v) ^ 0x8000) - 0x8000); }
103
+#else
104
+/* 2's complement */
105
+static inline int32_t u32tos32(uint32_t v) { return static_cast<int32_t>(v); }
106
+#endif
107
+
108
+static void load_gets32(int32_t *ptr, unsigned l)
109
+{
110
+	unsigned s = l << 2;
111
+	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
112
+		return;
113
+	if (ptr)
114
+		for (unsigned i = 0; i < l; ++i)
115
+			ptr[i] = u32tos32(Get32BitsLE(&loaderwork.state[loaderwork.stateptr + (i << 2)]));
116
+	loaderwork.stateptr += s;
117
+}
118
+
119
+static void load_getu32(uint32_t *ptr, unsigned l)
120
+{
121
+	unsigned s = l << 2;
122
+	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
123
+		return;
124
+	if (ptr)
125
+		for (unsigned i = 0; i < l; ++i)
126
+			ptr[i] = Get32BitsLE(&loaderwork.state[loaderwork.stateptr + (i << 2)]);
127
+	loaderwork.stateptr += s;
128
+}
129
+
130
+static void load_getu16(uint16_t *ptr, unsigned l)
131
+{
132
+	unsigned s = l << 1;
133
+	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
134
+		return;
135
+	if (ptr)
136
+		for (unsigned i = 0; i < l; ++i)
137
+			ptr[i] = Get16BitsLE(&loaderwork.state[loaderwork.stateptr + (i << 1)]);
138
+	loaderwork.stateptr += s;
139
+}
140
+
141
+static void load_getu8(uint8_t *ptr, unsigned l)
142
+{
143
+	unsigned s = l;
144
+	if (loaderwork.stateptr > loaderwork.state.size() || loaderwork.stateptr + s > loaderwork.state.size())
145
+		return;
146
+	if (ptr)
147
+		for (unsigned i = 0; i < l; ++i)
148
+			ptr[i] = loaderwork.state[loaderwork.stateptr + i];
149
+	loaderwork.stateptr += s;
150
+}
151
+
152
+/*static void gdb_stub_fix(armcpu_t *armcpu)
153
+{*/
154
+	/* armcpu->R[15] = armcpu->instruct_adr; */
155
+	/*armcpu->next_instruction = armcpu->instruct_adr;
156
+	if(armcpu->CPSR.bits.T == 0)
157
+	{
158
+		armcpu->instruction = MMU_read32(armcpu->proc_ID, armcpu->next_instruction);
159
+		armcpu->instruct_adr = armcpu->next_instruction;
160
+		armcpu->next_instruction += 4;
161
+		armcpu->R[15] = armcpu->next_instruction + 4;
162
+	}
163
+	else
164
+	{
165
+		armcpu->instruction = MMU_read16(armcpu->proc_ID, armcpu->next_instruction);
166
+		armcpu->instruct_adr = armcpu->next_instruction;
167
+		armcpu->next_instruction += 2;
168
+		armcpu->R[15] = armcpu->next_instruction + 2;
169
+	}
170
+}*/
171
+
172
+static void load_setstate()
173
+{
174
+	if (loaderwork.state.empty())
175
+		return;
176
+
177
+	//std::vector<uint8_t> savestate = std::vector<uint8_t>(&loaderwork.state[0], &loaderwork.state[loaderwork.state.size()]);
178
+	EMUFILE_MEMORY f(&loaderwork.state);
179
+	if (!savestate_load(&f))
180
+	{
181
+	//reset the emulator first to clean out the host's state
182
+
183
+		//while the series of resets below should work,
184
+		//we are testing the robustness of the savestate system with this full reset.
185
+		//the full reset wipes more things, so we can make sure that they are being restored correctly
186
+		//extern bool _HACK_DONT_STOPMOVIE;
187
+		//_HACK_DONT_STOPMOVIE = true;
188
+		NDS_Reset();
189
+		//_HACK_DONT_STOPMOVIE = false;
190
+
191
+		//reset some options to their old defaults which werent saved
192
+		//nds.debugConsole = false;
193
+
194
+		/* Skip over "Desmume Save File" crap */
195
+		load_getstateinit(0x17);
196
+
197
+		/* Read ARM7 cpu registers */
198
+		//load_getu32(&NDS_ARM7.proc_ID, 1);
199
+		load_getu32(NULL, 1);
200
+		load_getu32(&NDS_ARM7.instruction, 1);
201
+		load_getu32(&NDS_ARM7.instruct_adr, 1);
202
+		load_getu32(&NDS_ARM7.next_instruction, 1);
203
+		load_getu32(NDS_ARM7.R, 16);
204
+		load_getsta(&NDS_ARM7.CPSR, 1);
205
+		load_getsta(&NDS_ARM7.SPSR, 1);
206
+		load_getu32(&NDS_ARM7.R13_usr, 1);
207
+		load_getu32(&NDS_ARM7.R14_usr, 1);
208
+		load_getu32(&NDS_ARM7.R13_svc, 1);
209
+		load_getu32(&NDS_ARM7.R14_svc, 1);
210
+		load_getu32(&NDS_ARM7.R13_abt, 1);
211
+		load_getu32(&NDS_ARM7.R14_abt, 1);
212
+		load_getu32(&NDS_ARM7.R13_und, 1);
213
+		load_getu32(&NDS_ARM7.R14_und, 1);
214
+		load_getu32(&NDS_ARM7.R13_irq, 1);
215
+		load_getu32(&NDS_ARM7.R14_irq, 1);
216
+		load_getu32(&NDS_ARM7.R8_fiq, 1);
217
+		load_getu32(&NDS_ARM7.R9_fiq, 1);
218
+		load_getu32(&NDS_ARM7.R10_fiq, 1);
219
+		load_getu32(&NDS_ARM7.R11_fiq, 1);
220
+		load_getu32(&NDS_ARM7.R12_fiq, 1);
221
+		load_getu32(&NDS_ARM7.R13_fiq, 1);
222
+		load_getu32(&NDS_ARM7.R14_fiq, 1);
223
+		load_getsta(&NDS_ARM7.SPSR_svc, 1);
224
+		load_getsta(&NDS_ARM7.SPSR_abt, 1);
225
+		load_getsta(&NDS_ARM7.SPSR_und, 1);
226
+		load_getsta(&NDS_ARM7.SPSR_irq, 1);
227
+		load_getsta(&NDS_ARM7.SPSR_fiq, 1);
228
+		load_getu32(&NDS_ARM7.intVector, 1);
229
+		load_getu8(&NDS_ARM7.LDTBit, 1);
230
+		load_getbool(&NDS_ARM7.waitIRQ, 1);
231
+		bool tmpbool;
232
+		//load_getbool(&NDS_ARM7.wIRQ, 1);
233
+		//loaderwork.stateptr += 4;
234
+		load_getbool(NULL, 1);
235
+		//load_getbool(&NDS_ARM7.halt_IE_and_IF, 1);
236
+		//load_getbool(&NDS_ARM7.wirq, 1);
237
+		//loaderwork.stateptr += 4;
238
+		//load_getbool(NULL, 1);
239
+		//load_getbool(&NDS_ARM7.intrWaitARM_state, 1);
240
+		load_getbool(&tmpbool, 1);
241
+		//NDS_ARM7.intrWaitARM_state = tmpbool;
242
+
243
+		/* Read ARM9 cpu registers */
244
+		//load_getu32(&NDS_ARM9.proc_ID, 1);
245
+		load_getu32(NULL, 1);
246
+		load_getu32(&NDS_ARM9.instruction, 1);
247
+		load_getu32(&NDS_ARM9.instruct_adr, 1);
248
+		load_getu32(&NDS_ARM9.next_instruction, 1);
249
+		load_getu32(NDS_ARM9.R, 16);
250
+		load_getsta(&NDS_ARM9.CPSR, 1);
251
+		load_getsta(&NDS_ARM9.SPSR, 1);
252
+		load_getu32(&NDS_ARM9.R13_usr, 1);
253
+		load_getu32(&NDS_ARM9.R14_usr, 1);
254
+		load_getu32(&NDS_ARM9.R13_svc, 1);
255
+		load_getu32(&NDS_ARM9.R14_svc, 1);
256
+		load_getu32(&NDS_ARM9.R13_abt, 1);
257
+		load_getu32(&NDS_ARM9.R14_abt, 1);
258
+		load_getu32(&NDS_ARM9.R13_und, 1);
259
+		load_getu32(&NDS_ARM9.R14_und, 1);
260
+		load_getu32(&NDS_ARM9.R13_irq, 1);
261
+		load_getu32(&NDS_ARM9.R14_irq, 1);
262
+		load_getu32(&NDS_ARM9.R8_fiq, 1);
263
+		load_getu32(&NDS_ARM9.R9_fiq, 1);
264
+		load_getu32(&NDS_ARM9.R10_fiq, 1);
265
+		load_getu32(&NDS_ARM9.R11_fiq, 1);
266
+		load_getu32(&NDS_ARM9.R12_fiq, 1);
267
+		load_getu32(&NDS_ARM9.R13_fiq, 1);
268
+		load_getu32(&NDS_ARM9.R14_fiq, 1);
269
+		load_getsta(&NDS_ARM9.SPSR_svc, 1);
270
+		load_getsta(&NDS_ARM9.SPSR_abt, 1);
271
+		load_getsta(&NDS_ARM9.SPSR_und, 1);
272
+		load_getsta(&NDS_ARM9.SPSR_irq, 1);
273
+		load_getsta(&NDS_ARM9.SPSR_fiq, 1);
274
+		load_getu32(&NDS_ARM9.intVector, 1);
275
+		load_getu8(&NDS_ARM9.LDTBit, 1);
276
+		load_getbool(&NDS_ARM9.waitIRQ, 1);
277
+		//load_getbool(&NDS_ARM9.wIRQ, 1);
278
+		//loaderwork.stateptr += 4;
279
+		load_getbool(NULL, 1);
280
+		//load_getbool(&NDS_ARM9.halt_IE_and_IF, 1);
281
+		//load_getbool(&NDS_ARM9.wirq, 1);
282
+		//loaderwork.stateptr += 4;
283
+		//load_getbool(NULL, 1);
284
+		//load_getbool(&NDS_ARM9.intrWaitARM_state, 1);
285
+		load_getbool(&tmpbool, 1);
286
+		//NDS_ARM9.intrWaitARM_state = tmpbool;
287
+
288
+		/* Read in other internal variables that are important */
289
+		//int32_t tmps32;
290
+		//load_gets32(&nds.ARM9Cycle, 1);
291
+		load_gets32(NULL, 1);
292
+		//load_gets32(&nds.ARM7Cycle, 1);
293
+		load_gets32(NULL, 1);
294
+		load_gets32(&nds.cycles, 1);
295
+		int32_t tmps32_array[4];
296
+		//load_getu64(nds.timerCycle[0], 4);
297
+		load_gets32(tmps32_array, 4);
298
+		for (int i = 0; i < 4; ++i)
299
+			nds.timerCycle[0][i] = tmps32_array[i];
300
+		//load_getu64(nds.timerCycle[1], 4);
301
+		load_gets32(tmps32_array, 4);
302
+		for (int i = 0; i < 4; ++i)
303
+			nds.timerCycle[1][i] = tmps32_array[i];
304
+		//bool tmpbool_array[4];
305
+		//load_getbool(nds.timerOver[0], 4);
306
+		//loaderwork.stateptr += 16;
307
+		load_getbool(NULL, 4);
308
+		//load_getbool(nds.timerOver[1], 4);
309
+		//loaderwork.stateptr += 16;
310
+		load_getbool(NULL, 4);
311
+		//load_gets32(&nds.nextHBlank, 1);
312
+		//loaderwork.stateptr += 4;
313
+		load_gets32(NULL, 1);
314
+		load_getu32(&nds.VCount, 1);
315
+		load_getu32(&nds.old, 1);
316
+		//load_gets32(&nds.diff, 1);
317
+		//loaderwork.stateptr += 4;
318
+		load_gets32(NULL, 1);
319
+		//load_getbool(&nds.lignerendu, 1);
320
+		//loaderwork.stateptr += 4;
321
+		load_getbool(NULL, 1);
322
+		load_getu16(NULL, 1);
323
+		load_getu16(NULL, 1);
324
+
325
+		/* Read in memory/registers specific to the ARM9 */
326
+		//load_getu8 (MMU.ARM9_ITCM, 0x8000);
327
+		load_getu8(NULL, 0x8000);
328
+		load_getu8 (MMU.ARM9_DTCM, 0x4000);
329
+		//load_getu8 (MMU.MAIN_MEM, 0x1000000);
330
+		//load_getu8(MMU.MAIN_MEM, 0x800000);
331
+		//load_getu8(NULL, 0x800000);
332
+		//load_getu8(NULL, 0x1000000);
333
+		load_getu8(NULL, 0xFF8000);
334
+		load_getu8(MMU.ARM9_ITCM, 0x8000);
335
+		load_getu8 (MMU.MAIN_MEM/*+0x400000*/, 0x400000);
336
+		load_getu8 (MMU.ARM9_REG, 0x10000);
337
+		load_getu8 (MMU.ARM9_VMEM, 0x800);
338
+		load_getu8 (MMU.ARM9_OAM, 0x800);
339
+		//uint8_t tmpu8_ABG[0x80000];
340
+		//load_getu8 (ARM9Mem.ARM9_ABG, 0x80000);
341
+		//loaderwork.stateptr += 0x80000;
342
+		load_getu8(NULL, 0x80000);
343
+		//uint8_t tmpu8_BBG[0x20000];
344
+		//load_getu8 (ARM9Mem.ARM9_BBG, 0x20000);
345
+		//loaderwork.stateptr += 0x20000;
346
+		load_getu8(NULL, 0x20000);
347
+		//uint8_t tmpu8_AOBJ[0x40000];
348
+		//load_getu8 (ARM9Mem.ARM9_AOBJ, 0x40000);
349
+		//loaderwork.stateptr += 0x40000;
350
+		load_getu8(NULL, 0x40000);
351
+		//uint8_t tmpu8_BOBJ[0x20000];
352
+		//load_getu8 (ARM9Mem.ARM9_BOBJ, 0x20000);
353
+		//loaderwork.stateptr += 0x20000;
354
+		load_getu8(NULL, 0x20000);
355
+		load_getu8 (MMU.ARM9_LCD, 0xA4000);
356
+		//loaderwork.stateptr += 12;
357
+
358
+		/* Read in memory/registers specific to the ARM7 */
359
+		load_getu8 (MMU.ARM7_ERAM, 0x10000);
360
+		load_getu8 (MMU.ARM7_REG, 0x10000);
361
+		load_getu8 (MMU.ARM7_WIRAM, 0x10000);
362
+
363
+		/* Read in shared memory */
364
+		load_getu8 (MMU.SWIRAM, 0x8000);
365
+
366
+		//gdb_stub_fix(&NDS_ARM9);
367
+		//gdb_stub_fix(&NDS_ARM7);
368
+
369
+		loadstate();
370
+	}
371
+}
372
+
373
+static struct
374
+{
375
+	std::vector<uint8_t> buf;
376
+	unsigned filled, used;
377
+	uint32_t bufferbytes, cycles;
378
+	int xfs_load, sync_type;
379
+} sndifwork = {std::vector<uint8_t>(), 0, 0, 0, 0, 0, 0};
380
+
381
+static void SNDIFDeInit() { }
382
+
383
+static int SNDIFInit(int buffersize)
384
+{
385
+	uint32_t bufferbytes = buffersize * sizeof(int16_t);
386
+	SNDIFDeInit();
387
+	sndifwork.buf.resize(bufferbytes + 3);
388
+	sndifwork.bufferbytes = bufferbytes;
389
+	sndifwork.filled = sndifwork.used = 0;
390
+	sndifwork.cycles = 0;
391
+	return 0;
392
+}
393
+
394
+static void SNDIFMuteAudio() { }
395
+static void SNDIFUnMuteAudio() { }
396
+static void SNDIFSetVolume(int) { }
397
+
398
+static uint32_t SNDIFGetAudioSpace()
399
+{
400
+	return sndifwork.bufferbytes >> 2; // bytes to samples
401
+}
402
+
403
+static void SNDIFUpdateAudio(int16_t *buffer, uint32_t num_samples)
404
+{
405
+	uint32_t num_bytes = num_samples << 2;
406
+	if (num_bytes > sndifwork.bufferbytes)
407
+		num_bytes = sndifwork.bufferbytes;
408
+	memcpy(&sndifwork.buf[0], buffer, num_bytes);
409
+	sndifwork.filled = num_bytes;
410
+	sndifwork.used = 0;
411
+}
412
+
413
+static const int SNDIFID_2SF = 1;
414
+static SoundInterface_struct SNDIF_2SF =
415
+{
416
+	SNDIFID_2SF,
417
+	"2sf Sound Interface",
418
+	SNDIFInit,
419
+	SNDIFDeInit,
420
+	SNDIFUpdateAudio,
421
+	SNDIFGetAudioSpace,
422
+	SNDIFMuteAudio,
423
+	SNDIFUnMuteAudio,
424
+	SNDIFSetVolume,
425
+	NULL
426
+};
427
+
428
+SoundInterface_struct *SNDCoreList[] =
429
+{
430
+	&SNDIF_2SF,
431
+	&SNDDummy,
432
+	NULL
433
+};
434
+
435
+static void Map2SFSection(const std::vector<uint8_t> &section, bool isSave)
436
+{
437
+	auto &data = isSave ? loaderwork.state : loaderwork.rom;
438
+
439
+	uint32_t offset = Get32BitsLE(&section[0]), size = Get32BitsLE(&section[4]), finalSize = size + offset;
440
+	if (!isSave)
441
+		finalSize = NextHighestPowerOf2(finalSize);
442
+	if (data.empty())
443
+		data.resize(finalSize + 10, 0);
444
+	else if (data.size() < size + offset)
445
+		data.resize(offset + finalSize + 10);
446
+	memcpy(&data[offset], &section[8], size);
447
+}
448
+
449
+static bool Map2SF(XSFFile *xSF)
450
+{
451
+	if (!xSF->IsValidType(0x24))
452
+		return false;
453
+
454
+	auto &reservedSection = xSF->GetReservedSection(), &programSection = xSF->GetProgramSection();
455
+
456
+	if (!reservedSection.empty())
457
+	{
458
+		size_t reservedPosition = 0, reservedSize = reservedSection.size();
459
+		while (reservedPosition + 12 < reservedSize)
460
+		{
461
+			uint32_t saveSize = Get32BitsLE(&reservedSection[reservedPosition + 4]);
462
+			if (Get32BitsLE(&reservedSection[reservedPosition]) == 0x45564153) // "SAVE"
463
+			{
464
+				if (reservedPosition + 12 + saveSize > reservedSize)
465
+					return false;
466
+
467
+				uint8_t tmpSaveUncompressed[8];
468
+				unsigned long saveUncompressedSize = 8;
469
+				uncompress(tmpSaveUncompressed, &saveUncompressedSize, &reservedSection[reservedPosition + 12], saveSize);
470
+				saveUncompressedSize = Get32BitsLE(&tmpSaveUncompressed[4]) + 8;
471
+				auto saveUncompressed = std::vector<uint8_t>(saveUncompressedSize);
472
+				uncompress(&saveUncompressed[0], &saveUncompressedSize, &reservedSection[reservedPosition + 12], saveSize);
473
+
474
+				Map2SFSection(saveUncompressed, true);
475
+			}
476
+			reservedPosition += saveSize + 12;
477
+		}
478
+	}
479
+
480
+	if (!programSection.empty())
481
+		Map2SFSection(programSection, false);
482
+
483
+	return true;
484
+}
485
+
486
+static bool RecursiveLoad2SF(XSFFile *xSF, int level)
487
+{
488
+	if (level <= 10 && xSF->GetTagExists("_lib"))
489
+	{
490
+#ifdef _WIN32
491
+		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 4, 8));
492
+#else
493
+		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 4, 8));
494
+#endif
495
+		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
496
+			return false;
497
+	}
498
+
499
+	if (!Map2SF(xSF))
500
+		return false;
501
+
502
+	unsigned n = 2;
503
+	bool found;
504
+	do
505
+	{
506
+		found = false;
507
+		std::string libTag = "_lib" + stringify(n++);
508
+		if (xSF->GetTagExists(libTag))
509
+		{
510
+			found = true;
511
+#ifdef _WIN32
512
+			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 4, 8));
513
+#else
514
+			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 4, 8));
515
+#endif
516
+			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
517
+				return false;
518
+		}
519
+	} while (found);
520
+
521
+	return true;
522
+}
523
+
524
+static bool Load2SF(XSFFile *xSF)
525
+{
526
+	loaderwork.rom.clear();
527
+	loaderwork.state.clear();
528
+	loaderwork.stateptr = 0;
529
+
530
+	return RecursiveLoad2SF(xSF, 1);
531
+}
532
+
533
+XSFPlayer_2SF::XSFPlayer_2SF(const std::string &filename) : XSFPlayer()
534
+{
535
+	this->xSF = new XSFFile(filename, 4, 8);
536
+}
537
+
538
+XSFPlayer_2SF::XSFPlayer_2SF(const std::wstring &filename) : XSFPlayer()
539
+{
540
+	this->xSF = new XSFFile(filename, 4, 8);
541
+}
542
+
543
+bool XSFPlayer_2SF::Load()
544
+{
545
+	int frames = xSF->GetTagValue("_frames", -1);
546
+	sndifwork.sync_type = xSF->GetTagValue("_2sf_sync_type", 0);
547
+
548
+	sndifwork.xfs_load = false;
549
+	if (!Load2SF(this->xSF))
550
+		return false;
551
+
552
+	if (NDS_Init())
553
+		return false;
554
+
555
+	SPU_ChangeSoundCore(SNDIFID_2SF, 737);
556
+
557
+	execute = false;
558
+
559
+	MMU_unsetRom();
560
+	if (!loaderwork.rom.empty())
561
+	{
562
+		NDS_SetROM(&loaderwork.rom[0], loaderwork.rom.size() - 1);
563
+		gameInfo.loadData(reinterpret_cast<char *>(&loaderwork.rom[0]), loaderwork.rom.size() - 1);
564
+	}
565
+
566
+	NDS_Reset();
567
+
568
+	execute = true;
569
+
570
+	if (!loaderwork.state.empty())
571
+	{
572
+		armcp15_t *c9 = reinterpret_cast<armcp15_t *>(NDS_ARM9.coproc[15]);
573
+		//int proc;
574
+		if (frames == -1)
575
+		{
576
+			/* set initial ARM9 coprocessor state */
577
+
578
+			armcp15_moveARM2CP(c9, 0x00000000, 0x01, 0x00, 0, 0);
579
+			armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x05, 0, 0);
580
+			armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x06, 0, 0);
581
+			armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x0a, 0, 4);
582
+			armcp15_moveARM2CP(c9, 0x04000033, 0x06, 0x00, 0, 4);
583
+			armcp15_moveARM2CP(c9, 0x0200002d, 0x06, 0x01, 0, 0);
584
+			armcp15_moveARM2CP(c9, 0x027e0021, 0x06, 0x02, 0, 0);
585
+			armcp15_moveARM2CP(c9, 0x08000035, 0x06, 0x03, 0, 0);
586
+			armcp15_moveARM2CP(c9, 0x027e001b, 0x06, 0x04, 0, 0);
587
+			armcp15_moveARM2CP(c9, 0x0100002f, 0x06, 0x05, 0, 0);
588
+			armcp15_moveARM2CP(c9, 0xffff001d, 0x06, 0x06, 0, 0);
589
+			armcp15_moveARM2CP(c9, 0x027ff017, 0x06, 0x07, 0, 0);
590
+			armcp15_moveARM2CP(c9, 0x00000020, 0x09, 0x01, 0, 1);
591
+
592
+			armcp15_moveARM2CP(c9, 0x027e000a, 0x09, 0x01, 0, 0);
593
+
594
+			armcp15_moveARM2CP(c9, 0x00000042, 0x02, 0x00, 0, 1);
595
+			armcp15_moveARM2CP(c9, 0x00000042, 0x02, 0x00, 0, 0);
596
+			armcp15_moveARM2CP(c9, 0x00000002, 0x03, 0x00, 0, 0);
597
+			armcp15_moveARM2CP(c9, 0x05100011, 0x05, 0x00, 0, 3);
598
+			armcp15_moveARM2CP(c9, 0x15111011, 0x05, 0x00, 0, 2);
599
+			armcp15_moveARM2CP(c9, 0x07dd1e10, 0x01, 0x00, 0, 0);
600
+			armcp15_moveARM2CP(c9, 0x0005707d, 0x01, 0x00, 0, 0);
601
+
602
+			armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x0a, 0, 4);
603
+			armcp15_moveARM2CP(c9, 0x02004000, 0x07, 0x05, 0, 1);
604
+			armcp15_moveARM2CP(c9, 0x02004000, 0x07, 0x0e, 0, 1);
605
+
606
+			/* set initial timer state */
607
+
608
+			/*MMU_write16(0, REG_TM0CNTL, 0x0000);
609
+			MMU_write16(0, REG_TM0CNTH, 0x00C1);
610
+			MMU_write16(1, REG_TM0CNTL, 0x0000);
611
+			MMU_write16(1, REG_TM0CNTH, 0x00C1);
612
+			MMU_write16(1, REG_TM1CNTL, 0xf7e7);
613
+			MMU_write16(1, REG_TM1CNTH, 0x00C1);*/
614
+
615
+			/* set initial interrupt state */
616
+
617
+			MMU.reg_IME[0] = 0x00000001;
618
+			MMU.reg_IE[0]  = 0x00042001;
619
+			MMU.reg_IME[1] = 0x00000001;
620
+			MMU.reg_IE[1]  = 0x0104009d;
621
+		}
622
+		else if (frames > 0)
623
+		{
624
+			/* execute boot code */
625
+			for (int i = 0; i < frames; ++i)
626
+				NDS_exec<true>();
627
+		}
628
+
629
+		/* load state */
630
+
631
+		execute = false;
632
+		SPU_Reset();
633
+
634
+		load_setstate();
635
+		loaderwork.state.clear();
636
+
637
+		if (frames == -1)
638
+			armcp15_moveARM2CP(c9, (NDS_ARM9.R13_irq & 0x0fff0000) | 0x0a, 0x09, 0x01, 0, 0);
639
+
640
+		/* restore timer state */
641
+
642
+		/*for (proc = 0; proc < 2; proc++)
643
+		{
644
+			MMU_write16(proc, REG_TM0CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM0CNTH & 0xFFF));
645
+			MMU_write16(proc, REG_TM1CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM1CNTH & 0xFFF));
646
+			MMU_write16(proc, REG_TM2CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM2CNTH & 0xFFF));
647
+			MMU_write16(proc, REG_TM3CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM3CNTH & 0xFFF));
648
+		}*/
649
+	}
650
+	else if (frames > 0)
651
+	{
652
+		/* skip 1 sec */
653
+		for (int i = 0; i < frames; ++i)
654
+			NDS_exec<false>();
655
+	}
656
+	execute = true;
657
+	sndifwork.xfs_load = true;
658
+	//CommonSettings.spu_advanced = true;
659
+	//CommonSettings.advanced_timing = false;
660
+
661
+	return XSFPlayer::Load();
662
+}
663
+
664
+void XSFPlayer_2SF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples)
665
+{
666
+	static const double HBASE_CYCLES = 33509300.322234;
667
+	static const int HLINE_CYCLES = 6 * (99 + 256);
668
+	static const uint32_t HSAMPLES = static_cast<uint32_t>(static_cast<double>(this->sampleRate * HLINE_CYCLES) / HBASE_CYCLES);
669
+	static const int VDIVISION = 100;
670
+	static const int VLINES = 263;
671
+	static const double VBASE_CYCLES = HBASE_CYCLES / VDIVISION;
672
+	static const uint32_t VSAMPLES = static_cast<uint32_t>(static_cast<double>(this->sampleRate * HLINE_CYCLES * VLINES) / HBASE_CYCLES);
673
+
674
+	if (!sndifwork.xfs_load)
675
+		return;
676
+	unsigned bytes = samples << 2;
677
+	while (bytes)
678
+	{
679
+		unsigned remainbytes = sndifwork.filled - sndifwork.used;
680
+		if (remainbytes > 0)
681
+		{
682
+			if (remainbytes > bytes)
683
+			{
684
+				memcpy(&buf[offset], &sndifwork.buf[sndifwork.used], bytes);
685
+				sndifwork.used += bytes;
686
+				offset += bytes;
687
+				remainbytes -= bytes;
688
+				bytes = 0;
689
+				break;
690
+			}
691
+			else
692
+			{
693
+				memcpy(&buf[offset], &sndifwork.buf[sndifwork.used], remainbytes);
694
+				sndifwork.used += remainbytes;
695
+				offset += remainbytes;
696
+				bytes -= remainbytes;
697
+				remainbytes = 0;
698
+			}
699
+		}
700
+		if (!remainbytes)
701
+		{
702
+			if (sndifwork.sync_type == 1)
703
+			{
704
+				/* vsync */
705
+				sndifwork.cycles += (this->sampleRate / VDIVISION) * HLINE_CYCLES * VLINES;
706
+				if (sndifwork.cycles >= static_cast<uint32_t>(VBASE_CYCLES * (VSAMPLES + 1)))
707
+					sndifwork.cycles -= static_cast<uint32_t>(VBASE_CYCLES * (VSAMPLES + 1));
708
+				else
709
+					sndifwork.cycles -= static_cast<uint32_t>(VBASE_CYCLES * VSAMPLES);
710
+			}
711
+			else
712
+			{
713
+				/* hsync */
714
+				sndifwork.cycles += this->sampleRate * HLINE_CYCLES;
715
+				if (sndifwork.cycles >= static_cast<uint32_t>(HBASE_CYCLES * (HSAMPLES + 1)))
716
+					sndifwork.cycles -= static_cast<uint32_t>(HBASE_CYCLES * (HSAMPLES + 1));
717
+				else
718
+					sndifwork.cycles -= static_cast<uint32_t>(HBASE_CYCLES * HSAMPLES);
719
+			}
720
+			NDS_exec<false>();
721
+			SPU_Emulate_user();
722
+		}
723
+	}
724
+}
725
+
726
+void XSFPlayer_2SF::Terminate()
727
+{
728
+	MMU_unsetRom();
729
+	NDS_DeInit();
730
+
731
+	loaderwork.rom.clear();
732
+	loaderwork.state.clear();
733
+	loaderwork.stateptr = 0;
734
+}