Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
RishiRecon
GitHub Repository: RishiRecon/exploits
Path: blob/main/misc/emulator/xnes/snes9x/crosshairs.cpp
28547 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
#ifdef HAVE_LIBPNG
180
#include <png.h>
181
#endif
182
#include "port.h"
183
#include "crosshairs.h"
184
185
static const char *crosshairs[32] =
186
{
187
"` " // Crosshair 0 (no image)
188
" "
189
" "
190
" "
191
" "
192
" "
193
" "
194
" "
195
" "
196
" "
197
" "
198
" "
199
" "
200
" "
201
" ",
202
203
"` " // Crosshair 1 (the classic small dot)
204
" "
205
" "
206
" "
207
" "
208
" "
209
" "
210
" #. "
211
" "
212
" "
213
" "
214
" "
215
" "
216
" "
217
" ",
218
219
"` " // Crosshair 2 (a standard cross)
220
" "
221
" "
222
" "
223
" .#. "
224
" .#. "
225
" ...#... "
226
" ####### "
227
" ...#... "
228
" .#. "
229
" .#. "
230
" "
231
" "
232
" "
233
" ",
234
235
"` .#. " // Crosshair 3 (a standard cross)
236
" .#. "
237
" .#. "
238
" .#. "
239
" .#. "
240
" .#. "
241
".......#......."
242
"###############"
243
".......#......."
244
" .#. "
245
" .#. "
246
" .#. "
247
" .#. "
248
" .#. "
249
" .#. ",
250
251
"` " // Crosshair 4 (an X)
252
" "
253
" "
254
" . . "
255
" .#. .#. "
256
" .#. .#. "
257
" .#.#. "
258
" .#. "
259
" .#.#. "
260
" .#. .#. "
261
" .#. .#. "
262
" . . "
263
" "
264
" "
265
" ",
266
267
"`. . " // Crosshair 5 (an X)
268
".#. .#."
269
" .#. .#. "
270
" .#. .#. "
271
" .#. .#. "
272
" .#. .#. "
273
" .#.#. "
274
" .#. "
275
" .#.#. "
276
" .#. .#. "
277
" .#. .#. "
278
" .#. .#. "
279
" .#. .#. "
280
".#. .#."
281
" . . ",
282
283
"` " // Crosshair 6 (a combo)
284
" "
285
" "
286
" "
287
" # . # "
288
" # . # "
289
" #.# "
290
" ...#... "
291
" #.# "
292
" # . # "
293
" # . # "
294
" "
295
" "
296
" "
297
" ",
298
299
"` . " // Crosshair 7 (a combo)
300
" # . # "
301
" # . # "
302
" # . # "
303
" # . # "
304
" # . # "
305
" #.# "
306
".......#......."
307
" #.# "
308
" # . # "
309
" # . # "
310
" # . # "
311
" # . # "
312
" # . # "
313
" . ",
314
315
"` # " // Crosshair 8 (a diamond cross)
316
" #.# "
317
" # . # "
318
" # . # "
319
" # . # "
320
" # . # "
321
" # . # "
322
"#......#......#"
323
" # . # "
324
" # . # "
325
" # . # "
326
" # . # "
327
" # . # "
328
" #.# "
329
" # ",
330
331
"` ### " // Crosshair 9 (a circle cross)
332
" ## . ## "
333
" # . # "
334
" # . # "
335
" # . # "
336
" # . # "
337
"# . #"
338
"#......#......#"
339
"# . #"
340
" # . # "
341
" # . # "
342
" # . # "
343
" # . # "
344
" ## . ## "
345
" ### ",
346
347
"` .#. " // Crosshair 10 (a square cross)
348
" .#. "
349
" .#. "
350
" ....#.... "
351
" .#######. "
352
" .# #. "
353
"....# #...."
354
"##### #####"
355
"....# #...."
356
" .# #. "
357
" .#######. "
358
" ....#.... "
359
" .#. "
360
" .#. "
361
" .#. ",
362
363
"` .#. " // Crosshair 11 (an interrupted cross)
364
" .#. "
365
" .#. "
366
" .#. "
367
" .#. "
368
" "
369
"..... ....."
370
"##### #####"
371
"..... ....."
372
" "
373
" .#. "
374
" .#. "
375
" .#. "
376
" .#. "
377
" .#. ",
378
379
"`. . " // Crosshair 12 (an interrupted X)
380
".#. .#."
381
" .#. .#. "
382
" .#. .#. "
383
" .#. .#. "
384
" "
385
" "
386
" "
387
" "
388
" "
389
" .#. .#. "
390
" .#. .#. "
391
" .#. .#. "
392
".#. .#."
393
" . . ",
394
395
"` . " // Crosshair 13 (an interrupted combo)
396
" # . # "
397
" # . # "
398
" # . # "
399
" # . # "
400
" "
401
" "
402
"..... ....."
403
" "
404
" "
405
" # . # "
406
" # . # "
407
" # . # "
408
" # . # "
409
" . ",
410
411
"`#### #### " // Crosshair 14
412
"#.... ....#"
413
"#. .#"
414
"#. .#"
415
"#. .#"
416
" # "
417
" # "
418
" ##### "
419
" # "
420
" # "
421
"#. .#"
422
"#. .#"
423
"#. .#"
424
"#.... ....#"
425
" #### #### ",
426
427
"` .# #. " // Crosshair 15
428
" .# #. "
429
" .# #. "
430
"....# #...."
431
"##### #####"
432
" "
433
" "
434
" "
435
" "
436
" "
437
"##### #####"
438
"....# #...."
439
" .# #. "
440
" .# #. "
441
" .# #. ",
442
443
"` # " // Crosshair 16
444
" # "
445
" # "
446
" ....#.... "
447
" . # . "
448
" . # . "
449
" . # . "
450
"###############"
451
" . # . "
452
" . # . "
453
" . # . "
454
" ....#.... "
455
" # "
456
" # "
457
" # ",
458
459
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
460
};
461
462
463
bool S9xLoadCrosshairFile (int idx, const char *filename)
464
{
465
if (idx < 1 || idx > 31)
466
return (false);
467
468
char *s = (char *) calloc(15 * 15 + 1, sizeof(char));
469
if (s == NULL)
470
{
471
fprintf(stderr, "S9xLoadCrosshairFile: malloc error while reading ");
472
perror(filename);
473
return (false);
474
}
475
476
FILE *fp = fopen(filename, "rb");
477
if (fp == NULL)
478
{
479
fprintf(stderr, "S9xLoadCrosshairFile: Couldn't open ");
480
perror(filename);
481
free(s);
482
return (false);
483
}
484
485
size_t l = fread(s, 1, 8, fp);
486
if (l != 8)
487
{
488
fprintf(stderr, "S9xLoadCrosshairFile: File is too short!\n");
489
free(s);
490
fclose(fp);
491
return (false);
492
}
493
494
#ifdef HAVE_LIBPNG
495
png_structp png_ptr;
496
png_infop info_ptr;
497
498
if (!png_sig_cmp((png_byte *) s, 0, 8))
499
{
500
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
501
if (!png_ptr)
502
{
503
free(s);
504
fclose(fp);
505
return (false);
506
}
507
508
info_ptr = png_create_info_struct(png_ptr);
509
if (!info_ptr)
510
{
511
png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
512
free(s);
513
fclose(fp);
514
return (false);
515
}
516
517
png_init_io(png_ptr, fp);
518
png_set_sig_bytes(png_ptr, 8);
519
png_read_info(png_ptr, info_ptr);
520
521
png_uint_32 width, height;
522
int bit_depth, color_type;
523
524
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL);
525
if (color_type != PNG_COLOR_TYPE_PALETTE)
526
{
527
fprintf(stderr, "S9xLoadCrosshairFile: Input PNG is not a palettized image!\n");
528
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
529
free(s);
530
fclose(fp);
531
return (false);
532
}
533
534
if (bit_depth == 16)
535
png_set_strip_16(png_ptr);
536
537
if (width != 15 || height != 15)
538
{
539
fprintf(stderr, "S9xLoadCrosshairFile: Expecting a 15x15 PNG\n");
540
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
541
free(s);
542
fclose(fp);
543
return (false);
544
}
545
546
png_color *pngpal;
547
png_byte *trans;
548
int num_palette = 0, num_trans = 0;
549
int transcol = -1, fgcol = -1, bgcol = -1;
550
551
png_get_PLTE(png_ptr, info_ptr, &pngpal, &num_palette);
552
png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL);
553
554
if (num_palette != 3 || num_trans != 1)
555
{
556
fprintf(stderr, "S9xLoadCrosshairFile: Expecting a 3-color PNG with 1 trasnparent color\n");
557
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
558
free(s);
559
fclose(fp);
560
return (false);
561
}
562
563
for (int i = 0; i < 3; i++)
564
{
565
if (trans[0] == i)
566
transcol = i;
567
else
568
if (pngpal[i].red == 0 && pngpal[i].green == 0 && pngpal[i].blue == 0)
569
bgcol = i;
570
else
571
if (pngpal[i].red == 255 && pngpal[i].green == 255 && pngpal[i].blue == 255)
572
fgcol = i;
573
}
574
575
if (transcol < 0 || fgcol < 0 || bgcol < 0)
576
{
577
fprintf(stderr, "S9xLoadCrosshairFile: PNG must have 3 colors: white (fg), black (bg), and transparent.\n");
578
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
579
free(s);
580
fclose(fp);
581
return (false);
582
}
583
584
png_set_packing(png_ptr);
585
png_read_update_info(png_ptr, info_ptr);
586
png_byte *row_pointer = new png_byte[png_get_rowbytes(png_ptr, info_ptr)];
587
588
for (int r = 0; r < 15 * 15; r += 15)
589
{
590
png_read_row(png_ptr, row_pointer, NULL);
591
592
for (int i = 0; i < 15; i++)
593
{
594
if (row_pointer[i] == transcol)
595
s[r + i] = ' ';
596
else
597
if (row_pointer[i] == fgcol)
598
s[r + i] = '#';
599
else
600
if (row_pointer[i] == bgcol)
601
s[r + i] = '.';
602
else
603
{
604
fprintf(stderr, "S9xLoadCrosshairFile: WTF? This was supposed to be a 3-color PNG!\n");
605
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
606
free(s);
607
fclose(fp);
608
return (false);
609
}
610
}
611
}
612
613
s[15 * 15] = 0;
614
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
615
}
616
else
617
#endif
618
{
619
l = fread(s + 8, 1, 15 - 8, fp);
620
if (l != 15 - 8)
621
{
622
fprintf(stderr, "S9xLoadCrosshairFile: File is too short!\n");
623
free(s);
624
fclose(fp);
625
return (false);
626
}
627
628
if (getc(fp) != '\n')
629
{
630
fprintf(stderr, "S9xLoadCrosshairFile: Invalid file format! (note: PNG support is not available)\n");
631
free(s);
632
fclose(fp);
633
return (false);
634
}
635
636
for (int r = 1; r < 15; r++)
637
{
638
l = fread(s + r * 15, 1, 15, fp);
639
if (l != 15)
640
{
641
fprintf(stderr, "S9xLoadCrosshairFile: File is too short! (note: PNG support is not available)\n");
642
free(s);
643
fclose(fp);
644
return (false);
645
}
646
647
if (getc(fp) != '\n')
648
{
649
fprintf(stderr, "S9xLoadCrosshairFile: Invalid file format! (note: PNG support is not available)\n");
650
free(s);
651
fclose(fp);
652
return (false);
653
}
654
}
655
656
for (int i = 0; i < 15 * 15; i++)
657
{
658
if (s[i] != ' ' && s[i] != '#' && s[i] != '.')
659
{
660
fprintf(stderr, "S9xLoadCrosshairFile: Invalid file format! (note: PNG support is not available)\n");
661
free(s);
662
fclose(fp);
663
return (false);
664
}
665
}
666
}
667
668
fclose(fp);
669
670
if (crosshairs[idx] != NULL && crosshairs[idx][0] != '`')
671
free((void *) crosshairs[idx]);
672
crosshairs[idx] = s;
673
674
return (true);
675
}
676
677
const char * S9xGetCrosshair (int idx)
678
{
679
if (idx < 0 || idx > 31)
680
return (NULL);
681
682
return (crosshairs[idx]);
683
}
684
685