forked from hypevhs/audacious-plugin-highly-advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgsf.cpp
More file actions
253 lines (183 loc) · 4.16 KB
/
Copy pathgsf.cpp
File metadata and controls
253 lines (183 loc) · 4.16 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include "./VBA/System.h"
#include "./VBA/Sound.h"
#include "./VBA/Util.h"
#include "./VBA/GBA.h"
#include "./VBA/unzip.h"
#include <string.h>
#ifndef LINUX
#include <windows.h>
#endif
#include <stdio.h>
#ifdef LINUX
#include <stdarg.h>
#endif
int emulating = 0;
struct EmulatedSystem emulator;
bool debugger = false;
bool systemSoundOn = false;
#ifdef MMX
extern "C" bool cpu_mmx;
#endif
extern "C" void writeSound(void);
void systemMessage(int /*number*/, const char */*defaultMsg*/, ...)
{
}
void systemSoundShutdown()
{
}
void systemSoundPause()
{
}
void systemSoundReset()
{
}
void systemSoundResume()
{
}
void systemWriteDataToSoundBuffer() //this one actually outputs the sound, I do believe
{
writeSound();
}
bool systemCanChangeSoundQuality()
{
return true;
}
extern "C"
{
void DisplayError (char * Message, ...) {
char Msg[400];
va_list ap;
va_start( ap, Message );
vsprintf( Msg, Message, ap );
va_end( ap );
#ifndef LINUX
MessageBox(NULL,Msg,"Error",MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
#else
fprintf(stderr, "%s\n", Message);
#endif
//SetActiveWindow(hMainWindow);
}
int GSFRun(const char *);
int soundInitialized = false;
int GSFRun(const char *filename)
{
char tempName[2048];
// char file[2048];
if(rom != NULL) {
CPUCleanUp();
//remoteCleanUp();
emulating = false;
}
//utilGetBaseName(theApp.szFile, tempName);
utilGetBaseName(filename, tempName);
//_fullpath(file, tempName, 1024); //NO CLUE WHAT THIS DOES
//theApp.filename = file;
//int index = theApp.filename.ReverseFind('.');
//if(index != -1)
// theApp.filename = theApp.filename.Left(index);
//if(!theApp.dir.GetLength()) {
// int index = theApp.filename.ReverseFind('\\');
// if(index != -1) {
// theApp.dir = theApp.filename.Left(index-1);
// }
//}
//IMAGE_TYPE type = utilFindType(theApp.szFile);
IMAGE_TYPE type = utilFindType(filename);
if(type == IMAGE_UNKNOWN) {
fprintf(stderr,"Unsupported\n");
// systemMessage(IDS_UNSUPPORTED_FILE_TYPE,
// "Unsupported file type: %s", theApp.szFile);
return false;
}
//theApp.cartridgeType = (int)type;
{
//int size = CPULoadRom(theApp.szFile);
int size = CPULoadRom(filename);
//DisplayError("size = %X", size);
if(!size)
return false;
//theApp.romSize = size;
char *p = strrchr(tempName, '\\');
if(p)
*p = 0;
{
char buffer[5];
strncpy(buffer, (const char *)&rom[0xac], 4);
buffer[4] = 0;
strcat(tempName, "\\vba-over.ini");
}
//theApp.emulator = GBASystem;
}
if(soundInitialized) {
soundReset();
} else {
if(!soundOffFlag)
soundInit();
soundInitialized = true;
}
if(type == IMAGE_GBA) {
//skipBios = theApp.skipBiosFile ? true : false;
//CPUInit((char *)(LPCTSTR)theApp.biosFileName, theApp.useBiosFile ? true : false);
CPUInit((char *)NULL, false); //don't use bios file
CPUReset();
}
emulating = true;
return true;
}
void GSFClose(void)
{
if(rom != NULL /*|| gbRom != NULL*/) {
soundPause();
CPUCleanUp();
//remoteCleanUp();
}
emulating = 0;
}
#define EMU_COUNT 250000
bool EmulationLoop(void)
{
if(emulating /*&& !paused*/) {
for(int i = 0; i < 2; i++) {
CPULoop(EMU_COUNT);
return true;
}
}
return false;
}
bool IsValidGSF ( unsigned char Test[4] ) {
if ( *((unsigned int *)&Test[0]) == 0x22465350 ) { return true; }
return false;
}
bool IsTagPresent ( unsigned char Test[5] ) {
if ( *((unsigned int *)&Test[0]) == 0x4741545b && Test[4]==0x5D) {return true;}
return false;
}
extern int sndBitsPerSample;
extern int sndSamplesPerSec;
extern int sndNumChannels;
}
void setupSound(void)
{
sndNumChannels = 2;
switch(soundQuality) {
case 2:
sndSamplesPerSec = 22050;
soundBufferLen = 736*2;
//soundBufferTotalLen = 7360*2;
break;
case 4:
sndSamplesPerSec = 11025;
soundBufferLen = 368*2;
//soundBufferTotalLen = 3680*2;
break;
default:
soundQuality = 1;
sndSamplesPerSec = 44100;
//soundBufferLen = 1470*2;
soundBufferLen = 576*2*2;
//soundBufferTotalLen = 14700*2;
//soundBufferTotalLen = 576*2*10*2;
}
sndBitsPerSample = 16;
systemSoundOn = true;
}