-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathlibretro.cpp
1689 lines (1439 loc) · 57.3 KB
/
libretro.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "libretro.h"
#include "libretro_core_options.h"
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include <fstream>
#include "../source/core/api/NstApiMachine.hpp"
#include "../source/core/api/NstApiEmulator.hpp"
#include "../source/core/api/NstApiVideo.hpp"
#include "../source/core/api/NstApiCheats.hpp"
#include "../source/core/api/NstApiSound.hpp"
#include "../source/core/api/NstApiInput.hpp"
#include "../source/core/api/NstApiCartridge.hpp"
#include "../source/core/api/NstApiUser.hpp"
#include "../source/core/api/NstApiFds.hpp"
#include "../source/core/NstMachine.hpp"
#include "nstdatabase.hpp"
#define NST_VERSION "1.51.1"
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NES_NTSC_PAR ((Api::Video::Output::WIDTH - (overscan_h ? 16 : 0)) * (8.0 / 7.0)) / (Api::Video::Output::HEIGHT - (overscan_v ? 16 : 0))
#define NES_PAL_PAR ((Api::Video::Output::WIDTH - (overscan_h ? 16 : 0)) * (2950000.0 / 2128137.0)) / (Api::Video::Output::HEIGHT - (overscan_v ? 16 : 0))
#define NES_4_3_DAR (4.0 / 3.0);
#define SAMPLERATE 48000
#define RETRO_DEVICE_AUTO RETRO_DEVICE_JOYPAD
#define RETRO_DEVICE_GAMEPAD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0)
#define RETRO_DEVICE_ARKANOID RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 0)
#define RETRO_DEVICE_ZAPPER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_POINTER, 0)
using namespace Nes;
static retro_log_printf_t log_cb;
static retro_video_refresh_t video_cb;
static retro_audio_sample_t audio_cb;
static retro_audio_sample_batch_t audio_batch_cb;
static retro_environment_t environ_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
#ifdef _3DS
extern "C" void* linearMemAlign(size_t size, size_t alignment);
extern "C" void linearFree(void* mem);
#endif
static uint32_t* video_buffer = NULL;
static int16_t audio_buffer[(SAMPLERATE / 50)];
static int16_t audio_stereo_buffer[2 * (SAMPLERATE / 50)];
static Api::Emulator emulator;
static Api::Machine *machine;
static Api::Fds *fds;
static char g_basename[256];
static char g_rom_dir[256];
static char *g_save_dir;
static char samp_dir[256];
static unsigned blargg_ntsc;
static bool fds_auto_insert;
static bool overscan_v;
static bool overscan_h;
static bool libretro_supports_option_categories = false;
static unsigned aspect_ratio_mode;
static unsigned tpulse;
static enum {
SHOW_CROSSHAIR_DISABLED,
SHOW_CROSSHAIR_OFF,
SHOW_CROSSHAIR_ON,
} show_crosshair;
static bool libretro_supports_bitmasks = false;
static bool show_advanced_av_settings = true;
int16_t video_width = Api::Video::Output::WIDTH;
size_t pitch;
static Api::Video::Output *video;
static Api::Sound::Output *audio;
static Api::Input::Controllers *input;
static unsigned input_type[4];
static Api::Machine::FavoredSystem favsystem;
static void *sram;
static unsigned long sram_size;
static bool is_pal;
static byte custpal[64*3];
static char slash;
static const byte cxa2025as_palette[64][3] =
{
{0x58,0x58,0x58}, {0x00,0x23,0x8C}, {0x00,0x13,0x9B}, {0x2D,0x05,0x85},
{0x5D,0x00,0x52}, {0x7A,0x00,0x17}, {0x7A,0x08,0x00}, {0x5F,0x18,0x00},
{0x35,0x2A,0x00}, {0x09,0x39,0x00}, {0x00,0x3F,0x00}, {0x00,0x3C,0x22},
{0x00,0x32,0x5D}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xA1,0xA1,0xA1}, {0x00,0x53,0xEE}, {0x15,0x3C,0xFE}, {0x60,0x28,0xE4},
{0xA9,0x1D,0x98}, {0xD4,0x1E,0x41}, {0xD2,0x2C,0x00}, {0xAA,0x44,0x00},
{0x6C,0x5E,0x00}, {0x2D,0x73,0x00}, {0x00,0x7D,0x06}, {0x00,0x78,0x52},
{0x00,0x69,0xA9}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xFF,0xFF,0xFF}, {0x1F,0xA5,0xFE}, {0x5E,0x89,0xFE}, {0xB5,0x72,0xFE},
{0xFE,0x65,0xF6}, {0xFE,0x67,0x90}, {0xFE,0x77,0x3C}, {0xFE,0x93,0x08},
{0xC4,0xB2,0x00}, {0x79,0xCA,0x10}, {0x3A,0xD5,0x4A}, {0x11,0xD1,0xA4},
{0x06,0xBF,0xFE}, {0x42,0x42,0x42}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xFF,0xFF,0xFF}, {0xA0,0xD9,0xFE}, {0xBD,0xCC,0xFE}, {0xE1,0xC2,0xFE},
{0xFE,0xBC,0xFB}, {0xFE,0xBD,0xD0}, {0xFE,0xC5,0xA9}, {0xFE,0xD1,0x8E},
{0xE9,0xDE,0x86}, {0xC7,0xE9,0x92}, {0xA8,0xEE,0xB0}, {0x95,0xEC,0xD9},
{0x91,0xE4,0xFE}, {0xAC,0xAC,0xAC}, {0x00,0x00,0x00}, {0x00,0x00,0x00}
};
static const byte pal_palette[64][3] =
{
{0x80,0x80,0x80}, {0x00,0x00,0xBA}, {0x37,0x00,0xBF}, {0x84,0x00,0xA6},
{0xBB,0x00,0x6A}, {0xB7,0x00,0x1E}, {0xB3,0x00,0x00}, {0x91,0x26,0x00},
{0x7B,0x2B,0x00}, {0x00,0x3E,0x00}, {0x00,0x48,0x0D}, {0x00,0x3C,0x22},
{0x00,0x2F,0x66}, {0x00,0x00,0x00}, {0x05,0x05,0x05}, {0x05,0x05,0x05},
{0xC8,0xC8,0xC8}, {0x00,0x59,0xFF}, {0x44,0x3C,0xFF}, {0xB7,0x33,0xCC},
{0xFE,0x33,0xAA}, {0xFE,0x37,0x5E}, {0xFE,0x37,0x1A}, {0xD5,0x4B,0x00},
{0xC4,0x62,0x00}, {0x3C,0x7B,0x00}, {0x1D,0x84,0x15}, {0x00,0x95,0x66},
{0x00,0x84,0xC4}, {0x11,0x11,0x11}, {0x09,0x09,0x09}, {0x09,0x09,0x09},
{0xFE,0xFE,0xFE}, {0x00,0x95,0xFF}, {0x6F,0x84,0xFF}, {0xD5,0x6F,0xFF},
{0xFE,0x77,0xCC}, {0xFE,0x6F,0x99}, {0xFE,0x7B,0x59}, {0xFE,0x91,0x5F},
{0xFE,0xA2,0x33}, {0xA6,0xBF,0x00}, {0x51,0xD9,0x6A}, {0x4D,0xD5,0xAE},
{0x00,0xD9,0xFF}, {0x66,0x66,0x66}, {0x0D,0x0D,0x0D}, {0x0D,0x0D,0x0D},
{0xFE,0xFE,0xFE}, {0x84,0xBF,0xFF}, {0xBB,0xBB,0xFF}, {0xD0,0xBB,0xFF},
{0xFE,0xBF,0xEA}, {0xFE,0xBF,0xCC}, {0xFE,0xC4,0xB7}, {0xFE,0xCC,0xAE},
{0xFE,0xD9,0xA2}, {0xCC,0xE1,0x99}, {0xAE,0xEE,0xB7}, {0xAA,0xF8,0xEE},
{0xB3,0xEE,0xFF}, {0xDD,0xDD,0xDD}, {0x11,0x11,0x11}, {0x11,0x11,0x11}
};
static const byte composite_direct_fbx_palette[64][3] =
{
{0x65,0x65,0x65}, {0x00,0x12,0x7D}, {0x18,0x00,0x8E}, {0x36,0x00,0x82},
{0x56,0x00,0x5D}, {0x5A,0x00,0x18}, {0x4F,0x05,0x00}, {0x38,0x19,0x00},
{0x1D,0x31,0x00}, {0x00,0x3D,0x00}, {0x00,0x41,0x00}, {0x00,0x3B,0x17},
{0x00,0x2E,0x55}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xAF,0xAF,0xAF}, {0x19,0x4E,0xC8}, {0x47,0x2F,0xE3}, {0x6B,0x1F,0xD7},
{0x93,0x1B,0xAE}, {0x9E,0x1A,0x5E}, {0x99,0x32,0x00}, {0x7B,0x4B,0x00},
{0x5B,0x67,0x00}, {0x26,0x7A,0x00}, {0x00,0x82,0x00}, {0x00,0x7A,0x3E},
{0x00,0x6E,0x8A}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xFF,0xFF,0xFF}, {0x64,0xA9,0xFF}, {0x8E,0x89,0xFF}, {0xB6,0x76,0xFF},
{0xE0,0x6F,0xFF}, {0xEF,0x6C,0xC4}, {0xF0,0x80,0x6A}, {0xD8,0x98,0x2C},
{0xB9,0xB4,0x0A}, {0x83,0xCB,0x0C}, {0x5B,0xD6,0x3F}, {0x4A,0xD1,0x7E},
{0x4D,0xC7,0xCB}, {0x4C,0x4C,0x4C}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xFF,0xFF,0xFF}, {0xC7,0xE5,0xFF}, {0xD9,0xD9,0xFF}, {0xE9,0xD1,0xFF},
{0xF9,0xCE,0xFF}, {0xFF,0xCC,0xF1}, {0xFF,0xD4,0xCB}, {0xF8,0xDF,0xB1},
{0xED,0xEA,0xA4}, {0xD6,0xF4,0xA4}, {0xC5,0xF8,0xB8}, {0xBE,0xF6,0xD3},
{0xBF,0xF1,0xF1}, {0xB9,0xB9,0xB9}, {0x00,0x00,0x00}, {0x00,0x00,0x00}
};
static const byte pvm_style_d93_fbx_palette[64][3] =
{
{0x69,0x6B,0x63}, {0x00,0x17,0x74}, {0x1E,0x00,0x87}, {0x34,0x00,0x73},
{0x56,0x00,0x57}, {0x5E,0x00,0x13}, {0x53,0x1A,0x00}, {0x3B,0x24,0x00},
{0x24,0x30,0x00}, {0x06,0x3A,0x00}, {0x00,0x3F,0x00}, {0x00,0x3B,0x1E},
{0x00,0x33,0x4E}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xB9,0xBB,0xB3}, {0x14,0x53,0xB9}, {0x4D,0x2C,0xDA}, {0x67,0x1E,0xDE},
{0x98,0x18,0x9C}, {0x9D,0x23,0x44}, {0xA0,0x3E,0x00}, {0x8D,0x55,0x00},
{0x65,0x6D,0x00}, {0x2C,0x79,0x00}, {0x00,0x81,0x00}, {0x00,0x7D,0x42},
{0x00,0x78,0x8A}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xFF,0xFF,0xFF}, {0x69,0xA8,0xFF}, {0x96,0x91,0xFF}, {0xB2,0x8A,0xFA},
{0xEA,0x7D,0xFA}, {0xF3,0x7B,0xC7}, {0xF2,0x8E,0x59}, {0xE6,0xAD,0x27},
{0xD7,0xC8,0x05}, {0x90,0xDF,0x07}, {0x64,0xE5,0x3C}, {0x45,0xE2,0x7D},
{0x48,0xD5,0xD9}, {0x4E,0x50,0x48}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xFF,0xFF,0xFF}, {0xD2,0xEA,0xFF}, {0xE2,0xE2,0xFF}, {0xE9,0xD8,0xFF},
{0xF5,0xD2,0xFF}, {0xF8,0xD9,0xEA}, {0xFA,0xDE,0xB9}, {0xF9,0xE8,0x9B},
{0xF3,0xF2,0x8C}, {0xD3,0xFA,0x91}, {0xB8,0xFC,0xA8}, {0xAE,0xFA,0xCA},
{0xCA,0xF3,0xF3}, {0xBE,0xC0,0xB8}, {0x00,0x00,0x00}, {0x00,0x00,0x00}
};
static const byte ntsc_hardware_fbx_palette[64][3] =
{
{0x6A,0x6D,0x6A}, {0x00,0x13,0x80}, {0x1E,0x00,0x8A}, {0x39,0x00,0x7A},
{0x55,0x00,0x56}, {0x5A,0x00,0x18}, {0x4F,0x10,0x00}, {0x38,0x21,0x00},
{0x21,0x33,0x00}, {0x00,0x3D,0x00}, {0x00,0x40,0x00}, {0x00,0x39,0x24},
{0x00,0x2E,0x55}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xB9,0xBC,0xB9}, {0x18,0x50,0xC7}, {0x4B,0x30,0xE3}, {0x73,0x22,0xD6},
{0x95,0x1F,0xA9}, {0x9D,0x28,0x5C}, {0x96,0x3C,0x00}, {0x7A,0x51,0x00},
{0x5B,0x67,0x00}, {0x22,0x77,0x00}, {0x02,0x7E,0x02}, {0x00,0x76,0x45},
{0x00,0x6E,0x8A}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xFF,0xFF,0xFF}, {0x68,0xA6,0xFF}, {0x92,0x99,0xFF}, {0xB0,0x85,0xFF},
{0xD9,0x75,0xFD}, {0xE3,0x77,0xB9}, {0xE5,0x8D,0x68}, {0xCF,0xA2,0x2C},
{0xB3,0xAF,0x0C}, {0x7B,0xC2,0x11}, {0x55,0xCA,0x47}, {0x46,0xCB,0x81},
{0x47,0xC1,0xC5}, {0x4A,0x4D,0x4A}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xFF,0xFF,0xFF}, {0xCC,0xEA,0xFF}, {0xDD,0xDE,0xFF}, {0xEC,0xDA,0xFF},
{0xF8,0xD7,0xFE}, {0xFC,0xD6,0xF5}, {0xFD,0xDB,0xCF}, {0xF9,0xE7,0xB5},
{0xF1,0xF0,0xAA}, {0xDA,0xFA,0xA9}, {0xC9,0xFF,0xBC}, {0xC3,0xFB,0xD7},
{0xC4,0xF6,0xF6}, {0xBE,0xC1,0xBE}, {0x00,0x00,0x00}, {0x00,0x00,0x00}
};
static const byte nes_classic_fbx_fs_palette[64][3] =
{
{0x60,0x61,0x5F}, {0x00,0x00,0x83}, {0x1D,0x01,0x95}, {0x34,0x08,0x75},
{0x51,0x05,0x5E}, {0x56,0x00,0x0F}, {0x4C,0x07,0x00}, {0x37,0x23,0x08},
{0x20,0x3A,0x0B}, {0x0F,0x4B,0x0E}, {0x19,0x4C,0x16}, {0x02,0x42,0x1E},
{0x02,0x31,0x54}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xA9,0xAA,0xA8}, {0x10,0x4B,0xBF}, {0x47,0x12,0xD8}, {0x63,0x00,0xCA},
{0x88,0x00,0xA9}, {0x93,0x0B,0x46}, {0x8A,0x2D,0x04}, {0x6F,0x52,0x06},
{0x5C,0x71,0x14}, {0x1B,0x8D,0x12}, {0x19,0x95,0x09}, {0x17,0x84,0x48},
{0x20,0x6B,0x8E}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xFB,0xFB,0xFB}, {0x66,0x99,0xF8}, {0x89,0x74,0xF9}, {0xAB,0x58,0xF8},
{0xD5,0x57,0xEF}, {0xDE,0x5F,0xA9}, {0xDC,0x7F,0x59}, {0xC7,0xA2,0x24},
{0xA7,0xBE,0x03}, {0x75,0xD7,0x03}, {0x60,0xE3,0x4F}, {0x3C,0xD6,0x8D},
{0x56,0xC9,0xCC}, {0x41,0x42,0x40}, {0x00,0x00,0x00}, {0x00,0x00,0x00},
{0xFB,0xFB,0xFB}, {0xBE,0xD4,0xFA}, {0xC9,0xC7,0xF9}, {0xD7,0xBE,0xFA},
{0xE8,0xB8,0xF9}, {0xF5,0xBA,0xE5}, {0xF3,0xCA,0xC2}, {0xDF,0xCD,0xA7},
{0xD9,0xE0,0x9C}, {0xC9,0xEB,0x9E}, {0xC0,0xED,0xB8}, {0xB5,0xF4,0xC7},
{0xB9,0xEA,0xE9}, {0xAB,0xAB,0xAB}, {0x00,0x00,0x00}, {0x00,0x00,0x00}
};
int crossx = 0;
int crossy = 0;
#define CROSSHAIR_SIZE 3
void draw_crosshair(int x, int y)
{
uint32_t w = 0xFFFFFFFF;
uint32_t b = 0x00000000;
int current_width = 256;
if (blargg_ntsc){
x *= 2.36;
current_width = 602;
}
for (int i = MAX(-CROSSHAIR_SIZE, -x); i <= MIN(CROSSHAIR_SIZE, current_width - x); i++) {
video_buffer[current_width * y + x + i] = i % 2 == 0 ? w : b;
}
for (int i = MAX(-CROSSHAIR_SIZE, -y); i <= MIN(CROSSHAIR_SIZE, 239 - y); i++) {
video_buffer[current_width * (y + i) + x] = i % 2 == 0 ? w : b;
}
}
static void load_wav(const char* sampgame, Api::User::File& file)
{
char samp_path[292];
int length = 0;
int blockalign = 0;
int numchannels = 0;
int bitspersample = 0;
char fmt[4] = { 0x66, 0x6d, 0x74, 0x20};
char subchunk2id[4] = { 0x64, 0x61, 0x74, 0x61};
char *wavfile;
char *dataptr;
sprintf(samp_path, "%s%c%s%c%02d.wav", samp_dir, slash, sampgame, slash, file.GetId());
std::ifstream samp_file(samp_path, std::ifstream::in|std::ifstream::binary);
if (samp_file) {
samp_file.seekg(0, samp_file.end);
length = samp_file.tellg();
samp_file.seekg(0, samp_file.beg);
wavfile = (char*)malloc(length * sizeof(char));
samp_file.read(wavfile, length);
// Check to see if it has a valid header
if (memcmp(&wavfile[0x00], "RIFF", 4) != 0) { return; }
if (memcmp(&wavfile[0x08], "WAVE", 4) != 0) { return; }
if (memcmp(&wavfile[0x0c], &fmt, 4) != 0) { return; }
if (memcmp(&wavfile[0x24], &subchunk2id, 4) != 0) { return; }
// Load the sample into the emulator
dataptr = &wavfile[0x2c];
blockalign = wavfile[0x21] << 8 | wavfile[0x20];
numchannels = wavfile[0x17] << 8 | wavfile[0x16];
bitspersample = wavfile[0x23] << 8 | wavfile[0x22];
file.SetSampleContent(dataptr, (length - 44) / blockalign, 0, bitspersample, 44100);
free(wavfile);
}
}
static void NST_CALLBACK file_io_callback(void*, Api::User::File &file)
{
const void *addr;
unsigned long addr_size;
#ifdef _WIN32
slash = '\\';
#else
slash = '/';
#endif
switch (file.GetAction())
{
case Api::User::File::LOAD_SAMPLE_MOERO_PRO_YAKYUU:
load_wav("moepro", file); break;
case Api::User::File::LOAD_SAMPLE_MOERO_PRO_YAKYUU_88:
load_wav("moepro88", file); break;
case Api::User::File::LOAD_SAMPLE_MOERO_PRO_TENNIS:
load_wav("mptennis", file); break;
case Api::User::File::LOAD_SAMPLE_TERAO_NO_DOSUKOI_OOZUMOU:
load_wav("terao", file); break;
case Api::User::File::LOAD_SAMPLE_AEROBICS_STUDIO:
load_wav("ftaerobi", file); break;
case Api::User::File::LOAD_BATTERY:
case Api::User::File::LOAD_EEPROM:
case Api::User::File::LOAD_TAPE:
case Api::User::File::LOAD_TURBOFILE:
file.GetRawStorage(sram, sram_size);
break;
case Api::User::File::SAVE_BATTERY:
case Api::User::File::SAVE_EEPROM:
case Api::User::File::SAVE_TAPE:
case Api::User::File::SAVE_TURBOFILE:
file.GetContent(addr, addr_size);
if (addr != sram || sram_size != addr_size)
if (log_cb)
log_cb(RETRO_LOG_INFO, "[Nestopia]: SRAM changed place in RAM!\n");
break;
case Api::User::File::LOAD_FDS:
{
char base[256];
sprintf(base, "%s%c%s.sav", g_save_dir, slash, g_basename);
if (log_cb)
log_cb(RETRO_LOG_INFO, "Want to load FDS sav from: %s\n", base);
std::ifstream in_tmp(base,std::ifstream::in|std::ifstream::binary);
if (!in_tmp.is_open())
return;
file.SetPatchContent(in_tmp);
}
break;
case Api::User::File::SAVE_FDS:
{
char base[256];
sprintf(base, "%s%c%s.sav", g_save_dir, slash, g_basename);
if (log_cb)
log_cb(RETRO_LOG_INFO, "Want to save FDS sav to: %s\n", base);
std::ofstream out_tmp(base,std::ifstream::out|std::ifstream::binary);
if (out_tmp.is_open())
file.GetPatchContent(Api::User::File::PATCH_UPS, out_tmp);
}
break;
default:
break;
}
}
static void check_system_specs(void)
{
unsigned level = 6;
environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
}
void retro_init(void)
{
struct retro_log_callback log;
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
log_cb = log.log;
else
log_cb = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL))
libretro_supports_bitmasks = true;
check_system_specs();
}
void retro_deinit(void)
{
libretro_supports_bitmasks = false;
}
unsigned retro_api_version(void)
{
return RETRO_API_VERSION;
}
void retro_set_controller_port_device(unsigned port, unsigned device)
{
if (port >= 4)
return;
input_type[port] = device;
}
void retro_get_system_info(struct retro_system_info *info)
{
memset(info, 0, sizeof(*info));
info->library_name = "Nestopia";
#ifdef GIT_VERSION
info->library_version = NST_VERSION GIT_VERSION;
#else
info->library_version = NST_VERSION;
#endif
info->need_fullpath = false;
info->valid_extensions = "nes|fds|unf|unif";
}
double get_aspect_ratio(void)
{
double aspect_ratio = is_pal ? NES_PAL_PAR : NES_NTSC_PAR;
if (aspect_ratio_mode == 1)
{
aspect_ratio = NES_NTSC_PAR;
}
else if (aspect_ratio_mode == 2)
{
aspect_ratio = NES_PAL_PAR;
}
else if (aspect_ratio_mode == 3)
{
aspect_ratio = NES_4_3_DAR;
}
else if (aspect_ratio_mode == 4)
{
aspect_ratio = 0;
}
return aspect_ratio;
}
void retro_get_system_av_info(struct retro_system_av_info *info)
{
const retro_system_timing timing = { is_pal ? 50.0 : 60.0, SAMPLERATE };
info->timing = timing;
// It's better if the size is based on NTSC_WIDTH if the filter is on
const retro_game_geometry geom = {
Api::Video::Output::WIDTH - (overscan_h ? 16 : 0),
Api::Video::Output::HEIGHT - (overscan_v ? 16 : 0),
Api::Video::Output::NTSC_WIDTH,
Api::Video::Output::HEIGHT,
get_aspect_ratio(),
};
info->geometry = geom;
}
void retro_set_environment(retro_environment_t cb)
{
environ_cb = cb;
libretro_set_core_options(environ_cb,
&libretro_supports_option_categories);
static const struct retro_controller_description port1[] = {
{ "Auto", RETRO_DEVICE_AUTO },
{ "Gamepad", RETRO_DEVICE_GAMEPAD },
{ NULL, 0 },
};
static const struct retro_controller_description port2[] = {
{ "Auto", RETRO_DEVICE_AUTO },
{ "Gamepad", RETRO_DEVICE_GAMEPAD },
{ "Arkanoid", RETRO_DEVICE_ARKANOID },
{ "Zapper", RETRO_DEVICE_ZAPPER },
{ NULL, 0 },
};
static const struct retro_controller_description port3[] = {
{ "Auto", RETRO_DEVICE_AUTO },
{ "Gamepad", RETRO_DEVICE_GAMEPAD },
{ NULL, 0 },
};
static const struct retro_controller_description port4[] = {
{ "Auto", RETRO_DEVICE_AUTO },
{ "Gamepad", RETRO_DEVICE_GAMEPAD },
{ NULL, 0 },
};
static const struct retro_controller_info ports[] = {
{ port1, 2 },
{ port2, 4 },
{ port3, 2 },
{ port4, 2 },
{ NULL, 0 },
};
environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void *)ports);
}
void retro_set_audio_sample(retro_audio_sample_t cb)
{
audio_cb = cb;
}
void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb)
{
audio_batch_cb = cb;
}
void retro_set_input_poll(retro_input_poll_t cb)
{
input_poll_cb = cb;
}
void retro_set_input_state(retro_input_state_t cb)
{
input_state_cb = cb;
}
void retro_set_video_refresh(retro_video_refresh_t cb)
{
video_cb = cb;
}
void retro_reset(void)
{
machine->Reset(false);
if (machine->Is(Nes::Api::Machine::DISK))
{
fds->EjectDisk();
if (fds_auto_insert)
fds->InsertDisk(0, 0);
}
}
typedef struct
{
unsigned retro;
unsigned nes;
} keymap;
static enum {
ARKANOID_DEVICE_MOUSE,
ARKANOID_DEVICE_POINTER
} arkanoid_device;
static enum {
ZAPPER_DEVICE_LIGHTGUN,
ZAPPER_DEVICE_MOUSE,
ZAPPER_DEVICE_POINTER
} zapper_device;
static keymap bindmap_default[] = {
{ RETRO_DEVICE_ID_JOYPAD_A, Core::Input::Controllers::Pad::A },
{ RETRO_DEVICE_ID_JOYPAD_B, Core::Input::Controllers::Pad::B },
{ RETRO_DEVICE_ID_JOYPAD_X, Core::Input::Controllers::Pad::A },
{ RETRO_DEVICE_ID_JOYPAD_Y, Core::Input::Controllers::Pad::B },
{ RETRO_DEVICE_ID_JOYPAD_SELECT, Core::Input::Controllers::Pad::SELECT },
{ RETRO_DEVICE_ID_JOYPAD_START, Core::Input::Controllers::Pad::START },
{ RETRO_DEVICE_ID_JOYPAD_UP, Core::Input::Controllers::Pad::UP },
{ RETRO_DEVICE_ID_JOYPAD_DOWN, Core::Input::Controllers::Pad::DOWN },
{ RETRO_DEVICE_ID_JOYPAD_LEFT, Core::Input::Controllers::Pad::LEFT },
{ RETRO_DEVICE_ID_JOYPAD_RIGHT, Core::Input::Controllers::Pad::RIGHT },
};
static keymap bindmap_shifted[] = {
{ RETRO_DEVICE_ID_JOYPAD_B, Core::Input::Controllers::Pad::A },
{ RETRO_DEVICE_ID_JOYPAD_Y, Core::Input::Controllers::Pad::B },
{ RETRO_DEVICE_ID_JOYPAD_A, Core::Input::Controllers::Pad::A },
{ RETRO_DEVICE_ID_JOYPAD_X, Core::Input::Controllers::Pad::B },
{ RETRO_DEVICE_ID_JOYPAD_SELECT, Core::Input::Controllers::Pad::SELECT },
{ RETRO_DEVICE_ID_JOYPAD_START, Core::Input::Controllers::Pad::START },
{ RETRO_DEVICE_ID_JOYPAD_UP, Core::Input::Controllers::Pad::UP },
{ RETRO_DEVICE_ID_JOYPAD_DOWN, Core::Input::Controllers::Pad::DOWN },
{ RETRO_DEVICE_ID_JOYPAD_LEFT, Core::Input::Controllers::Pad::LEFT },
{ RETRO_DEVICE_ID_JOYPAD_RIGHT, Core::Input::Controllers::Pad::RIGHT },
};
static keymap *bindmap = bindmap_default;
static void update_input()
{
input_poll_cb();
input->pad[1].mic = 0;
input->vsSystem.insertCoin = 0;
if (show_crosshair)
show_crosshair = SHOW_CROSSHAIR_OFF;
int min_x = overscan_h ? 8 : 0;
int max_x = overscan_h ? 247 : 255;
int min_y = overscan_v ? 8 : 0;
int max_y = overscan_v ? 231 : 239;
static int cur_x = min_x;
static int cur_y = min_y;
for (unsigned p = 0; p < 4; p++)
{
switch (input_type[p])
{
case RETRO_DEVICE_AUTO:
Api::Input(emulator).AutoSelectController(p);
break;
case RETRO_DEVICE_NONE:
Api::Input(emulator).ConnectController(p, Api::Input::UNCONNECTED);
break;
case RETRO_DEVICE_GAMEPAD:
Api::Input(emulator).ConnectController(p, (Api::Input::Type) (p + 1));
break;
case RETRO_DEVICE_ARKANOID:
Api::Input(emulator).ConnectController(p, Api::Input::PADDLE);
break;
case RETRO_DEVICE_ZAPPER:
Api::Input(emulator).ConnectController(p, Api::Input::ZAPPER);
break;
}
Api::Input::Type connected_controller = Api::Input(emulator).GetConnectedController(p);
if (connected_controller == p + 1)
{
input->pad[p].buttons = 0;
static unsigned tstate = 2;
bool pressed_l3 = false;
bool pressed_l2 = false;
bool pressed_r2 = false;
bool pressed_l = false;
bool pressed_r = false;
int16_t ret;
if (libretro_supports_bitmasks)
ret = input_state_cb(p, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK);
else
{
ret = 0;
for (unsigned i = 0; i < (RETRO_DEVICE_ID_JOYPAD_R3 + 1); i++)
ret |= input_state_cb(p, RETRO_DEVICE_JOYPAD, 0, i) ? (1 << i) : 0;
}
for (unsigned bind = 0; bind < sizeof(bindmap_default) / sizeof(bindmap[0]); bind++)
input->pad[p].buttons |= (ret & (1 << bindmap[bind].retro)) ? bindmap[bind].nes : 0;
if (ret & (1 << bindmap[2].retro))
tstate ? input->pad[p].buttons &= ~Core::Input::Controllers::Pad::A : input->pad[p].buttons |= Core::Input::Controllers::Pad::A;
if (ret & (1 << bindmap[3].retro))
tstate ? input->pad[p].buttons &= ~Core::Input::Controllers::Pad::B : input->pad[p].buttons |= Core::Input::Controllers::Pad::B;
/* Player 0 needs some extra checks */
if (p == 0)
{
pressed_l3 = ret & (1 << RETRO_DEVICE_ID_JOYPAD_L3);
pressed_l2 = ret & (1 << RETRO_DEVICE_ID_JOYPAD_L2);
pressed_r2 = ret & (1 << RETRO_DEVICE_ID_JOYPAD_R2);
}
pressed_l = ret & (1 << RETRO_DEVICE_ID_JOYPAD_L);
pressed_r = ret & (1 << RETRO_DEVICE_ID_JOYPAD_R);
if (tstate) tstate--; else tstate = tpulse;
if (pressed_l3)
input->pad[1].mic |= 0x04;
if (pressed_l2)
input->vsSystem.insertCoin |= Core::Input::Controllers::VsSystem::COIN_1;
if (pressed_r2)
input->vsSystem.insertCoin |= Core::Input::Controllers::VsSystem::COIN_2;
if (machine->Is(Nes::Api::Machine::DISK))
{
bool curL = pressed_l;
static bool prevL = false;
if (curL && !prevL)
{
if (!fds->IsAnyDiskInserted())
fds->InsertDisk(0, 0);
else if (fds->CanChangeDiskSide())
fds->ChangeSide();
}
prevL = curL;
bool curR = pressed_r;
static bool prevR = false;
if (curR && !prevR && (fds->GetNumDisks() > 1))
{
int currdisk = fds->GetCurrentDisk();
fds->EjectDisk();
fds->InsertDisk(!currdisk, 0);
}
prevR = curR;
}
}
else if (connected_controller == Api::Input::PADDLE)
{
switch (arkanoid_device)
{
case ARKANOID_DEVICE_MOUSE:
cur_x += input_state_cb(p, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
input->paddle.button = input_state_cb(p, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT);
break;
case ARKANOID_DEVICE_POINTER:
cur_x = input_state_cb(p, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X);
cur_x = (cur_x + 0x7FFF) * max_x / (0x7FFF * 2);
input->paddle.button = input_state_cb(p, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED);
break;
}
if (cur_x < min_x)
cur_x = min_x;
else if (cur_x > max_x)
cur_x = max_x;
input->paddle.x = cur_x;
}
else if (connected_controller == Api::Input::ZAPPER)
{
input->zapper.fire = 0;
if (show_crosshair)
show_crosshair = SHOW_CROSSHAIR_ON;
switch (zapper_device)
{
case ZAPPER_DEVICE_LIGHTGUN:
if (!input_state_cb(p, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN))
{
cur_x = input_state_cb(p, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X);
cur_y = input_state_cb(p, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y);
cur_x = (cur_x + 0x7FFF) * max_x / (0x7FFF * 2);
cur_y = (cur_y + 0x7FFF) * max_y / (0x7FFF * 2);
}
else
{
cur_x = min_x;
cur_y = min_y;
}
if (input_state_cb(p, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER)) {
input->zapper.x = cur_x;
input->zapper.y = cur_y;
input->zapper.fire = 1;
}
if (input_state_cb(p, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD)) {
input->zapper.x = ~1U;
input->zapper.fire = 1;
}
break;
case ZAPPER_DEVICE_MOUSE:
cur_x += input_state_cb(p, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
cur_y += input_state_cb(p, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
if (cur_x < min_x)
cur_x = min_x;
else if (cur_x > max_x)
cur_x = max_x;
if (cur_y < min_y)
cur_y = min_y;
else if (cur_y > max_y)
cur_y = max_y;
if (input_state_cb(p, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT))
{
input->zapper.x = cur_x;
input->zapper.y = cur_y;
input->zapper.fire = 1;
}
break;
case ZAPPER_DEVICE_POINTER:
cur_x = input_state_cb(p, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X);
cur_y = input_state_cb(p, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y);
cur_x = (cur_x + 0x7FFF) * max_x / (0x7FFF * 2);
cur_y = (cur_y + 0x7FFF) * max_y / (0x7FFF * 2);
if (input_state_cb(p, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED))
{
input->zapper.x = cur_x;
input->zapper.y = cur_y;
input->zapper.fire = 1;
}
break;
default:
break;
}
if (cur_x > max_x) { crossx = max_x; }
else if (cur_x < min_x) { crossx = min_x; }
else { crossx = cur_x; }
if (cur_y > max_y) { crossy = max_y; }
else if (cur_y < min_y) { crossy = min_y; }
else { crossy = cur_y; }
}
}
}
static void check_variables(void)
{
static bool last_ntsc_val_same;
struct retro_variable var = {0};
struct retro_system_av_info av_info;
struct retro_core_option_display option_display;
Api::Sound sound(emulator);
Api::Video video(emulator);
Api::Video::RenderState renderState;
Api::Machine machine(emulator);
Api::Video::RenderState::Filter filter;
var.key = "nestopia_arkanoid_device";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "mouse") == 0)
arkanoid_device = ARKANOID_DEVICE_MOUSE;
if (strcmp(var.value, "pointer") == 0)
arkanoid_device = ARKANOID_DEVICE_POINTER;
}
var.key = "nestopia_zapper_device";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "lightgun") == 0)
zapper_device = ZAPPER_DEVICE_LIGHTGUN;
else if (strcmp(var.value, "mouse") == 0)
zapper_device = ZAPPER_DEVICE_MOUSE;
else if (strcmp(var.value, "pointer") == 0)
zapper_device = ZAPPER_DEVICE_POINTER;
}
var.key = "nestopia_show_crosshair";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "disabled") == 0)
show_crosshair = SHOW_CROSSHAIR_DISABLED;
else
show_crosshair = SHOW_CROSSHAIR_OFF;
}
var.key = "nestopia_button_shift";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "disabled") == 0)
bindmap = bindmap_default;
else if (strcmp(var.value, "enabled") == 0)
bindmap = bindmap_shifted;
}
var.key = "nestopia_favored_system";
is_pal = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "auto") == 0)
{
machine.SetMode(machine.GetDesiredMode());
if (machine.GetMode() == Api::Machine::PAL)
{
is_pal = true;
favsystem = Api::Machine::FAVORED_NES_PAL;
machine.SetMode(Api::Machine::PAL);
}
else
{
favsystem = Api::Machine::FAVORED_NES_NTSC;
machine.SetMode(Api::Machine::NTSC);
}
}
else if (strcmp(var.value, "ntsc") == 0)
{
favsystem = Api::Machine::FAVORED_NES_NTSC;
machine.SetMode(Api::Machine::NTSC);
}
else if (strcmp(var.value, "pal") == 0)
{
favsystem = Api::Machine::FAVORED_NES_PAL;
machine.SetMode(Api::Machine::PAL);
is_pal = true;
}
else if (strcmp(var.value, "famicom") == 0)
{
favsystem = Api::Machine::FAVORED_FAMICOM;
machine.SetMode(Api::Machine::NTSC);
}
else if (strcmp(var.value, "dendy") == 0)
{
favsystem = Api::Machine::FAVORED_DENDY;
machine.SetMode(Api::Machine::PAL);
is_pal = true;
}
else
{
favsystem = Api::Machine::FAVORED_NES_NTSC;
machine.SetMode(Api::Machine::NTSC);
}
}
if (audio) delete audio;
audio = new Api::Sound::Output(audio_buffer, is_pal ? SAMPLERATE / 50 : SAMPLERATE / 60);
var.key = "nestopia_genie_distortion";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "disabled") == 0)
sound.SetGenie(0);
else if (strcmp(var.value, "enabled") == 0)
sound.SetGenie(1);
}
var.key = "nestopia_ram_power_state";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "0x00") == 0)
machine.SetRamPowerState(0);
else if (strcmp(var.value, "0xFF") == 0)
machine.SetRamPowerState(1);
else if (strcmp(var.value, "random") == 0)
machine.SetRamPowerState(2);
}
var.key = "nestopia_nospritelimit";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "disabled") == 0)
video.EnableUnlimSprites(false);
else if (strcmp(var.value, "enabled") == 0)
video.EnableUnlimSprites(true);
}
var.key = "nestopia_overclock";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "1x") == 0)
video.EnableOverclocking(false);
else if (strcmp(var.value, "2x") == 0)
video.EnableOverclocking(true);
}
var.key = "nestopia_fds_auto_insert";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
fds_auto_insert = (strcmp(var.value, "enabled") == 0);
var.key = "nestopia_blargg_ntsc_filter";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
if (strcmp(var.value, "disabled") == 0)
blargg_ntsc = 0;
else if (strcmp(var.value, "composite") == 0)
blargg_ntsc = 2;
else if (strcmp(var.value, "svideo") == 0)
blargg_ntsc = 3;
else if (strcmp(var.value, "rgb") == 0)
blargg_ntsc = 4;
else if (strcmp(var.value, "monochrome") == 0)
blargg_ntsc = 5;
}
switch(blargg_ntsc)
{
case 0:
filter = Api::Video::RenderState::FILTER_NONE;
video_width = Api::Video::Output::WIDTH;
video.SetSaturation(Api::Video::DEFAULT_SATURATION);
break;
case 2:
filter = Api::Video::RenderState::FILTER_NTSC;
video.SetSharpness(Api::Video::DEFAULT_SHARPNESS_COMP);
video.SetColorResolution(Api::Video::DEFAULT_COLOR_RESOLUTION_COMP);
video.SetColorBleed(Api::Video::DEFAULT_COLOR_BLEED_COMP);
video.SetColorArtifacts(Api::Video::DEFAULT_COLOR_ARTIFACTS_COMP);
video.SetColorFringing(Api::Video::DEFAULT_COLOR_FRINGING_COMP);
video.SetSaturation(Api::Video::DEFAULT_SATURATION_COMP);
video_width = Api::Video::Output::NTSC_WIDTH;
break;
case 3:
filter = Api::Video::RenderState::FILTER_NTSC;
video.SetSharpness(Api::Video::DEFAULT_SHARPNESS_SVIDEO);
video.SetColorResolution(Api::Video::DEFAULT_COLOR_RESOLUTION_SVIDEO);
video.SetColorBleed(Api::Video::DEFAULT_COLOR_BLEED_SVIDEO);
video.SetColorArtifacts(Api::Video::DEFAULT_COLOR_ARTIFACTS_SVIDEO);
video.SetColorFringing(Api::Video::DEFAULT_COLOR_FRINGING_SVIDEO);
video.SetSaturation(Api::Video::DEFAULT_SATURATION_SVIDEO);
video_width = Api::Video::Output::NTSC_WIDTH;
break;
case 4:
filter = Api::Video::RenderState::FILTER_NTSC;
video.SetSharpness(Api::Video::DEFAULT_SHARPNESS_RGB);
video.SetColorResolution(Api::Video::DEFAULT_COLOR_RESOLUTION_RGB);
video.SetColorBleed(Api::Video::DEFAULT_COLOR_BLEED_RGB);
video.SetColorArtifacts(Api::Video::DEFAULT_COLOR_ARTIFACTS_RGB);
video.SetColorFringing(Api::Video::DEFAULT_COLOR_FRINGING_RGB);
video.SetSaturation(Api::Video::DEFAULT_SATURATION_RGB);
video_width = Api::Video::Output::NTSC_WIDTH;
break;
case 5:
filter = Api::Video::RenderState::FILTER_NTSC;
video.SetSharpness(Api::Video::DEFAULT_SHARPNESS_MONO);
video.SetColorResolution(Api::Video::DEFAULT_COLOR_RESOLUTION_MONO);
video.SetColorBleed(Api::Video::DEFAULT_COLOR_BLEED_MONO);
video.SetColorArtifacts(Api::Video::DEFAULT_COLOR_ARTIFACTS_MONO);
video.SetColorFringing(Api::Video::DEFAULT_COLOR_FRINGING_MONO);
video.SetSaturation(Api::Video::DEFAULT_SATURATION_MONO);
video_width = Api::Video::Output::NTSC_WIDTH;
break;
}