Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
RishiRecon
GitHub Repository: RishiRecon/exploits
Path: blob/main/misc/emulator/xnes/snes9x/conffile.h
28515 views
1
/***********************************************************************************
2
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3
4
(c) Copyright 1996 - 2002 Gary Henderson ([email protected]),
5
Jerremy Koot ([email protected])
6
7
(c) Copyright 2002 - 2004 Matthew Kendora
8
9
(c) Copyright 2002 - 2005 Peter Bortas ([email protected])
10
11
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
12
13
(c) Copyright 2001 - 2006 John Weidman ([email protected])
14
15
(c) Copyright 2002 - 2006 funkyass ([email protected]),
16
Kris Bleakley ([email protected])
17
18
(c) Copyright 2002 - 2010 Brad Jorsch ([email protected]),
19
Nach ([email protected]),
20
21
(c) Copyright 2002 - 2011 zones ([email protected])
22
23
(c) Copyright 2006 - 2007 nitsuja
24
25
(c) Copyright 2009 - 2011 BearOso,
26
OV2
27
28
29
BS-X C emulator code
30
(c) Copyright 2005 - 2006 Dreamer Nom,
31
zones
32
33
C4 x86 assembler and some C emulation code
34
(c) Copyright 2000 - 2003 _Demo_ ([email protected]),
35
Nach,
36
zsKnight ([email protected])
37
38
C4 C++ code
39
(c) Copyright 2003 - 2006 Brad Jorsch,
40
Nach
41
42
DSP-1 emulator code
43
(c) Copyright 1998 - 2006 _Demo_,
44
Andreas Naive ([email protected]),
45
Gary Henderson,
46
Ivar ([email protected]),
47
John Weidman,
48
Kris Bleakley,
49
Matthew Kendora,
50
Nach,
51
neviksti ([email protected])
52
53
DSP-2 emulator code
54
(c) Copyright 2003 John Weidman,
55
Kris Bleakley,
56
Lord Nightmare ([email protected]),
57
Matthew Kendora,
58
neviksti
59
60
DSP-3 emulator code
61
(c) Copyright 2003 - 2006 John Weidman,
62
Kris Bleakley,
63
Lancer,
64
z80 gaiden
65
66
DSP-4 emulator code
67
(c) Copyright 2004 - 2006 Dreamer Nom,
68
John Weidman,
69
Kris Bleakley,
70
Nach,
71
z80 gaiden
72
73
OBC1 emulator code
74
(c) Copyright 2001 - 2004 zsKnight,
75
pagefault ([email protected]),
76
Kris Bleakley
77
Ported from x86 assembler to C by sanmaiwashi
78
79
SPC7110 and RTC C++ emulator code used in 1.39-1.51
80
(c) Copyright 2002 Matthew Kendora with research by
81
zsKnight,
82
John Weidman,
83
Dark Force
84
85
SPC7110 and RTC C++ emulator code used in 1.52+
86
(c) Copyright 2009 byuu,
87
neviksti
88
89
S-DD1 C emulator code
90
(c) Copyright 2003 Brad Jorsch with research by
91
Andreas Naive,
92
John Weidman
93
94
S-RTC C emulator code
95
(c) Copyright 2001 - 2006 byuu,
96
John Weidman
97
98
ST010 C++ emulator code
99
(c) Copyright 2003 Feather,
100
John Weidman,
101
Kris Bleakley,
102
Matthew Kendora
103
104
Super FX x86 assembler emulator code
105
(c) Copyright 1998 - 2003 _Demo_,
106
pagefault,
107
zsKnight
108
109
Super FX C emulator code
110
(c) Copyright 1997 - 1999 Ivar,
111
Gary Henderson,
112
John Weidman
113
114
Sound emulator code used in 1.5-1.51
115
(c) Copyright 1998 - 2003 Brad Martin
116
(c) Copyright 1998 - 2006 Charles Bilyue'
117
118
Sound emulator code used in 1.52+
119
(c) Copyright 2004 - 2007 Shay Green ([email protected])
120
121
SH assembler code partly based on x86 assembler code
122
(c) Copyright 2002 - 2004 Marcus Comstedt ([email protected])
123
124
2xSaI filter
125
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
126
127
HQ2x, HQ3x, HQ4x filters
128
(c) Copyright 2003 Maxim Stepin ([email protected])
129
130
NTSC filter
131
(c) Copyright 2006 - 2007 Shay Green
132
133
GTK+ GUI code
134
(c) Copyright 2004 - 2011 BearOso
135
136
Win32 GUI code
137
(c) Copyright 2003 - 2006 blip,
138
funkyass,
139
Matthew Kendora,
140
Nach,
141
nitsuja
142
(c) Copyright 2009 - 2011 OV2
143
144
Mac OS GUI code
145
(c) Copyright 1998 - 2001 John Stiles
146
(c) Copyright 2001 - 2011 zones
147
148
149
Specific ports contains the works of other authors. See headers in
150
individual files.
151
152
153
Snes9x homepage: http://www.snes9x.com/
154
155
Permission to use, copy, modify and/or distribute Snes9x in both binary
156
and source form, for non-commercial purposes, is hereby granted without
157
fee, providing that this license information and copyright notice appear
158
with all copies and any derived work.
159
160
This software is provided 'as-is', without any express or implied
161
warranty. In no event shall the authors be held liable for any damages
162
arising from the use of this software or it's derivatives.
163
164
Snes9x is freeware for PERSONAL USE only. Commercial users should
165
seek permission of the copyright holders first. Commercial use includes,
166
but is not limited to, charging money for Snes9x or software derived from
167
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
168
using Snes9x as a promotion for your commercial product.
169
170
The copyright holders request that bug fixes and improvements to the code
171
should be forwarded to them so everyone can benefit from the modifications
172
in future versions.
173
174
Super NES and Super Nintendo Entertainment System are trademarks of
175
Nintendo Co., Limited and its subsidiary companies.
176
***********************************************************************************/
177
178
179
#ifndef _CONFIG_H_
180
#define _CONFIG_H_
181
182
#include <set>
183
#include <map>
184
#include <vector>
185
#include <string>
186
187
#ifdef UNZIP_SUPPORT
188
#include "unzip/unzip.h"
189
#endif
190
#include "snes9x.h"
191
#include "reader.h"
192
193
#ifndef MAX
194
# define MAX(a,b) ((a) > (b)? (a) : (b))
195
# define MIN(a,b) ((a) < (b)? (a) : (b))
196
#endif
197
198
class ConfigFile {
199
public:
200
ConfigFile(void);
201
202
void Clear(void);
203
204
// return false on failure
205
bool LoadFile(const char *filename);
206
void LoadFile(Reader *r, const char *name=NULL);
207
208
// return false if key does not exist or is empty
209
bool Exists(const char *key);
210
211
// return the value / default
212
std::string GetString(const char *key, std::string def);
213
char *GetString(const char *key, char *out, uint32 outlen); // return NULL if it doesn't exist, out not affected
214
const char *GetString(const char *key, const char *def=NULL); // NOTE: returned pointer becomes invalid when key is deleted/modified, or the ConfigFile is Clear()ed or deleted.
215
char *GetStringDup(const char *key, const char *def=NULL); // Much like "strdup(GetString(key, def))"
216
int32 GetInt(const char *key, int32 def=-1, bool *bad=NULL);
217
uint32 GetUInt(const char *key, uint32 def=0, int base=0, bool *bad=NULL); // base = 0, 8, 10, or 16
218
bool GetBool(const char *key, bool def=false, bool *bad=NULL);
219
const char* GetComment(const char *key); // NOTE: returned pointer becomes invalid when key is deleted/modified, or the ConfigFile is Clear()ed or deleted.
220
221
// return true if the key existed prior to setting
222
bool SetString(const char *key, std::string val, const char *comment="");
223
bool SetInt(const char *key, int32 val, const char *comment="");
224
bool SetUInt(const char *key, uint32 val, int base=10, const char *comment=""); // base = 8, 10, or 16
225
bool SetBool(const char *key, bool val, const char *true_val="TRUE", const char *false_val="FALSE", const char *comment="");
226
bool DeleteKey(const char *key);
227
228
// Operation on entire sections
229
bool DeleteSection(const char *section);
230
typedef std::vector<std::pair<std::string,std::string> > secvec_t;
231
secvec_t GetSection(const char *section);
232
int GetSectionSize(const std::string section);
233
234
// Clears all key-value pairs that didn't receive a Set command, or a Get command with autoAdd on
235
void ClearUnused(void);
236
237
// Clears all stored line numbers
238
void ClearLines(void);
239
240
bool SaveTo(const char *filename);
241
242
static void SetDefaultAutoAdd(bool autoAdd);
243
static void SetNiceAlignment(bool align);
244
static void SetShowComments(bool show);
245
static void SetAlphaSort(bool sort);
246
static void SetTimeSort(bool sort);
247
248
private:
249
std::string Get(const char *key);
250
bool Has(const char *key);
251
252
class ConfigEntry {
253
protected:
254
int line;
255
std::string section;
256
std::string key;
257
std::string val;
258
std::string comment;
259
mutable bool used;
260
261
struct section_then_key_less {
262
bool operator()(const ConfigEntry &a, const ConfigEntry &b);
263
};
264
265
struct key_less {
266
bool operator()(const ConfigEntry &a, const ConfigEntry &b) const{
267
if(a.section!=b.section) return a.section<b.section;
268
return a.key<b.key;
269
}
270
};
271
272
struct line_less {
273
bool operator()(const ConfigEntry &a, const ConfigEntry &b){
274
if(a.line==b.line) return (b.val.empty() && !a.val.empty()) || a.key<b.key;
275
if(b.line<0) return true;
276
if(a.line<0) return false;
277
return a.line<b.line;
278
}
279
};
280
281
static void trim(std::string &s){
282
int i;
283
i=s.find_first_not_of(" \f\n\r\t\v");
284
if(i==-1){
285
s.clear();
286
return;
287
}
288
if(i>0) s.erase(0, i); // erase leading whitespace
289
i=s.find_last_not_of(" \f\n\r\t\v");
290
if(i!=-1) s.erase(i+1); // erase trailing whitespace
291
return;
292
}
293
294
// trims comments and leading/trailing whitespace from s, and returns any trimmed comments
295
// make sure not to call this more than once on the same string
296
static std::string trimCommented(std::string &s){
297
std::string cmt;
298
int i;
299
i=s.find_first_not_of(" \f\n\r\t\v");
300
if(i==-1){
301
s.clear();
302
return cmt;
303
}
304
if(i>0) s.erase(0, i); // erase leading whitespace
305
int off=0;
306
for(;;){
307
i=s.find('#',off); // find trailing comment
308
if(i>=0)
309
{
310
if((int)s.length()>i+1 && s.at(i+1) == '#') {
311
s.erase(i,1); // ignore ## and change to #
312
off = i+1;
313
continue;
314
} else {
315
int j=s.find_first_not_of(" \f\n\r\t\v",i+1);
316
if(j!=-1) cmt = s.substr(j); // store
317
s.erase(i); // erase trailing comment
318
}
319
}
320
break;
321
}
322
i=s.find_last_not_of(" \f\n\r\t\v");
323
if(i!=-1) s.erase(i+1); // erase trailing whitespace
324
return cmt;
325
}
326
327
public:
328
ConfigEntry(int l, const std::string &s, const std::string &k, const std::string &v) :
329
line(l), section(s), key(k), val(v) {
330
trim(section);
331
trim(key);
332
used=false;
333
}
334
335
void parse_key(const std::string &k){
336
int i=k.find("::");
337
if(i==-1){
338
section="Uncategorized"; key=k;
339
} else {
340
section=k.substr(0,i); key=k.substr(i+2);
341
}
342
trim(section);
343
trim(key);
344
used=false;
345
}
346
347
ConfigEntry(const std::string k){
348
parse_key(k);
349
}
350
351
ConfigEntry(const std::string k, const std::string &v) : line(-1), val(v) {
352
parse_key(k);
353
}
354
355
friend class ConfigFile;
356
friend struct key_less;
357
friend struct line_less;
358
};
359
class SectionSizes {
360
protected:
361
std::map<std::string,uint32> sections;
362
363
public:
364
uint32 GetSectionSize(const std::string section) {
365
uint32 count=0;
366
uint32 seclen;
367
std::map<std::string,uint32>::iterator it;
368
for(it=sections.begin(); it!=sections.end(); it++) {
369
seclen = MIN(section.size(),it->first.size());
370
if(it->first==section || !section.compare(0,seclen,it->first,0,seclen)) count+=it->second;
371
}
372
return count;
373
}
374
375
void IncreaseSectionSize(const std::string section) {
376
std::map<std::string,uint32>::iterator it=sections.find(section);
377
if(it!=sections.end())
378
it->second++;
379
else
380
sections.insert(std::pair<std::string,uint32>(section,1));
381
}
382
383
void DecreaseSectionSize(const std::string section) {
384
std::map<std::string,uint32>::iterator it=sections.find(section);
385
if(it!=sections.end())
386
it->second--;
387
}
388
389
void ClearSections() {
390
sections.clear();
391
}
392
393
void DeleteSection(const std::string section) {
394
sections.erase(section);
395
}
396
397
};
398
std::set<ConfigEntry, ConfigEntry::key_less> data;
399
SectionSizes sectionSizes;
400
int linectr;
401
static bool defaultAutoAdd;
402
static bool niceAlignment;
403
static bool showComments;
404
static bool alphaSort;
405
static bool timeSort;
406
};
407
408
/* Config file format:
409
*
410
* Comments are any lines whose first non-whitespace character is ';' or '#'.
411
* Note that comments can also follow a value, on the same line.
412
* To intentionally have a '#' character in the value, use ##
413
*
414
* All parameters fall into sections. To name a section, the first
415
* non-whitespace character on the line will be '[', and the last will be ']'.
416
*
417
* Parameters are simple key=value pairs. Whitespace around the '=', and at the
418
* beginning or end of the line is ignored. Key names may not contain '=' nor
419
* begin with '[', however values can. If the last character of the value is
420
* '\', the next line (sans leading/trailing whitespace) is considered part of
421
* the value as well. Programmatically, the key "K" in section "S" is referred
422
* to as "S::K", much like C++ namespaces. For example:
423
* [Section1]
424
* # this is a comment
425
* foo = bar \
426
* baz\
427
* quux \
428
* ## this is not a comment! # this IS a comment
429
* means the value of "Section1::foo" is "bar bazquux # this is not a comment!"
430
*
431
* Parameters may be of several types:
432
* String - Bare characters. If the first and last characters are both '"',
433
* they are removed (so just double them if you really want quotes
434
* there)
435
* Int - A decimal number from -2147483648 to 2147483647
436
* UInt - A number in decimal, hex, or octal from 0 to 4294967295 (or
437
* 0xffffffff, or 037777777777)
438
* Bool - true/false, 0/1, on/off, yes/no
439
*
440
* Of course, the actual accepted values for a parameter may be further
441
* restricted ;)
442
*/
443
444
445
/* You must write this for your port */
446
void S9xParsePortConfig(ConfigFile &, int pass);
447
448
/* This may or may not be useful to you */
449
const char *S9xParseDisplayConfig(ConfigFile &, int pass);
450
451
#endif
452
453