-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathlibretro.cxx
1372 lines (1157 loc) · 51.5 KB
/
libretro.cxx
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
#ifndef _MSC_VER
#include <sched.h>
#endif
#include <stddef.h>
#include <stdlib.h>
#include <math.h>
#include <boolean.h>
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include <libretro.h>
#include <streams/file_stream.h>
#include "libretro_core_options.h"
#include "Console.hxx"
#include "Cart.hxx"
#include "Props.hxx"
#include "MD5.hxx"
#include "Sound.hxx"
#include "SerialPort.hxx"
#include "TIA.hxx"
#include "Switches.hxx"
#include "StateManager.hxx"
#include "PropsSet.hxx"
#include "Paddles.hxx"
#include "Sound.hxx"
#include "M6532.hxx"
#include "Version.hxx"
#include "Stubs.hxx"
#ifdef _3DS
extern "C" void* linearMemAlign(size_t size, size_t alignment);
extern "C" void linearFree(void* mem);
#endif
static Console *console = 0;
static Cartridge *cartridge = 0;
static Settings *settings = 0;
static OSystem osystem;
static StateManager stateManager(&osystem);
static int videoWidth, videoHeight;
#define FRAME_BUFFER_SIZE (256 * 160 * 4)
static uint8_t *frameBuffer = NULL;
static uint8_t *frameBufferPrev = NULL;
static uint8_t framePixelBytes = 2;
static const uint32_t *currentPalette32 = NULL;
static uint16_t currentPalette16[256] = {0};
#define MAX_RETROPAD_DEVICES 2
#define RETROPAD_STELLA_GAMEPAD RETRO_DEVICE_JOYPAD
#define RETROPAD_STELLA_PADDLES RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 1)
static unsigned retropad_devices[MAX_RETROPAD_DEVICES] = {
RETROPAD_STELLA_GAMEPAD,
RETROPAD_STELLA_GAMEPAD,
};
static const struct retro_controller_description retropad_desc[] = {
{ "Gamepad", RETROPAD_STELLA_GAMEPAD },
{ "Paddles (Stelladaptor)", RETROPAD_STELLA_PADDLES },
{ NULL, 0 },
};
static const struct retro_controller_info retropad_port_info[] = {
{ retropad_desc, 2 },
{ retropad_desc, 2 },
{ NULL, 0 },
};
static struct retro_input_descriptor retropad_inputs_gamepad0_gamepad1[] = {
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Up" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Down" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Fire" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Difficulty A" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Left Difficulty B" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "Color" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Right Difficulty A" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "Right Difficulty B" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "Black/White" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Reset" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Paddle Fire" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Paddle Analog" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Up" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Down" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Fire" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Paddle Fire" },
{ 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Paddle Analog" },
{ 0 },
};
static struct retro_input_descriptor retropad_inputs_gamepad0_paddles1[] = {
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Up" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Down" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Fire" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Difficulty A" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Left Difficulty B" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "Color" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Right Difficulty A" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "Right Difficulty B" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "Black/White" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Reset" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Paddle Fire" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Paddle Analog" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "P3 Fire" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "P4 Fire" },
{ 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "P3 Wheel" },
{ 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "P4 Wheel" },
{ 0 },
};
static struct retro_input_descriptor retropad_inputs_paddles0_gamepad1[] = {
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "P1 Fire" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "P2 Fire" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Difficulty A" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Left Difficulty B" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "Color" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Right Difficulty A" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "Right Difficulty B" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "Black/White" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Reset" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "P1 Wheel" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "P2 Wheel" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Up" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Down" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Fire" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Paddle Fire" },
{ 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Paddle Analog" },
{ 0 },
};
static struct retro_input_descriptor retropad_inputs_paddles0_paddles1[] = {
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "P1 Fire" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "P2 Fire" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Difficulty A" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Left Difficulty B" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "Color" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Right Difficulty A" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "Right Difficulty B" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "Black/White" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Reset" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "P1 Wheel" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "P2 Wheel" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "P3 Fire" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "P4 Fire" },
{ 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "P3 Wheel" },
{ 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "P4 Wheel" },
{ 0 },
};
/* Regular gamepad-related parameters */
static Controller::Type left_controller_type = Controller::Joystick;
static int paddle_digital_sensitivity = 50;
#define PADDLE_ANALOG_RANGE 0x8000
static float paddle_analog_sensitivity = 50.0f;
static bool paddle_analog_is_quadratic = false;
static int paddle_analog_deadzone = (int)(0.15f * (float)PADDLE_ANALOG_RANGE);
static Event::Type MouseAxisValue0 = Event::MouseAxisXValue;
static Event::Type MouseButtonValue0 = Event::MouseButtonLeftValue;
static Event::Type MouseAxisValue1 = Event::MouseAxisYValue;
static Event::Type MouseButtonValue1 = Event::MouseButtonRightValue;
/* Stelladaptor-related parameters
* > This type of paddle control bears no resemblance
* to regular gamepads, thus independent sensitivity
* and offset options are required */
#define STELLADAPTOR_ANALOG_SENSE_DEFAULT 20
#define STELLADAPTOR_ANALOG_SENSE_FACTOR 0.148643628f
#define STELLADAPTOR_ANALOG_SENSE_BASE 1.1f
#define STELLADAPTOR_ANALOG_SENSE_MIN 0
#define STELLADAPTOR_ANALOG_SENSE_MAX 30
#define STELLADAPTOR_ANALOG_CENTER_DEFAULT 0
#define STELLADAPTOR_ANALOG_CENTER_FACTOR 860.0f
#define STELLADAPTOR_ANALOG_CENTER_MIN -10
#define STELLADAPTOR_ANALOG_CENTER_MAX 30
static float stelladaptor_analog_sensitivity = 1.0f;
static float stelladaptor_analog_center = 0.0f;
/* Low pass audio filter */
static bool low_pass_enabled = false;
static int32_t low_pass_range = 0;
static int32_t low_pass_left_prev = 0;
static int32_t low_pass_right_prev = 0;
static retro_log_printf_t log_cb;
static retro_video_refresh_t video_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
static retro_environment_t environ_cb;
static retro_audio_sample_t audio_cb;
static retro_audio_sample_batch_t audio_batch_cb;
static bool libretro_supports_bitmasks = false;
/************************************
* Interframe blending
************************************/
enum frame_blend_method
{
FRAME_BLEND_NONE = 0,
FRAME_BLEND_MIX,
FRAME_BLEND_GHOST_65,
FRAME_BLEND_GHOST_75,
FRAME_BLEND_GHOST_85,
FRAME_BLEND_GHOST_95
};
/* It would be more flexible to have 'persistence'
* as a core option, but using a variable parameter
* reduces performance by ~15%. We therefore offer
* fixed values, and use macros to avoid excessive
* duplication of code...
* Note: persistence fraction is (persistence/128),
* using a power of 2 like this further increases
* performance by ~15% */
#define BLEND_FRAMES_GHOST_16(persistence) \
{ \
const uint32_t *palette32 = console->getPalette(0); \
uint16_t *palette16 = currentPalette16; \
uInt8 *in = stella_fb; \
uint16_t *prev = (uint16_t*)frameBufferPrev; \
uint16_t *out = (uint16_t*)frameBuffer; \
int i; \
\
/* If palette has changed, re-cache converted \
* RGB565 values */ \
if (palette32 != currentPalette32) \
{ \
currentPalette32 = palette32; \
convert_palette(palette32, palette16); \
} \
\
for (i = 0; i < width * height; i++) \
{ \
/* Get colours from current + previous frames */ \
uint16_t color_curr = *(palette16 + *(in + i)); \
uint16_t color_prev = *(prev + i); \
\
/* Unpack colours */ \
uint16_t r_curr = (color_curr >> 11) & 0x1F; \
uint16_t g_curr = (color_curr >> 6) & 0x1F; \
uint16_t b_curr = (color_curr ) & 0x1F; \
\
uint16_t r_prev = (color_prev >> 11) & 0x1F; \
uint16_t g_prev = (color_prev >> 6) & 0x1F; \
uint16_t b_prev = (color_prev ) & 0x1F; \
\
/* Mix colors */ \
uint16_t r_mix = ((r_curr * (128 - persistence)) >> 7) + ((r_prev * persistence) >> 7); \
uint16_t g_mix = ((g_curr * (128 - persistence)) >> 7) + ((g_prev * persistence) >> 7); \
uint16_t b_mix = ((b_curr * (128 - persistence)) >> 7) + ((b_prev * persistence) >> 7); \
\
/* Output colour is the maximum of the input \
* and decayed values */ \
uint16_t r_out = (r_mix > r_curr) ? r_mix : r_curr; \
uint16_t g_out = (g_mix > g_curr) ? g_mix : g_curr; \
uint16_t b_out = (b_mix > b_curr) ? b_mix : b_curr; \
uint16_t color_out = r_out << 11 | g_out << 6 | b_out; \
\
/* Assign colour and store for next frame */ \
*(out++) = color_out; \
*(prev + i) = color_out; \
} \
}
#define BLEND_FRAMES_GHOST_32(persistence) \
{ \
const uint32_t *palette = console->getPalette(0); \
uInt8 *in = stella_fb; \
uint32_t *prev = (uint32_t*)frameBufferPrev; \
uint32_t *out = (uint32_t*)frameBuffer; \
int i; \
\
for (i = 0; i < width * height; i++) \
{ \
/* Get colours from current + previous frames */ \
uint32_t color_curr = *(palette + *(in + i)); \
uint32_t color_prev = *(prev + i); \
\
/* Unpack colours */ \
uint32_t r_curr = (color_curr >> 16) & 0xFF; \
uint32_t g_curr = (color_curr >> 8) & 0xFF; \
uint32_t b_curr = (color_curr ) & 0xFF; \
\
uint32_t r_prev = (color_prev >> 16) & 0xFF; \
uint32_t g_prev = (color_prev >> 8) & 0xFF; \
uint32_t b_prev = (color_prev ) & 0xFF; \
\
/* Mix colors */ \
uint32_t r_mix = ((r_curr * (128 - persistence)) >> 7) + ((r_prev * persistence) >> 7); \
uint32_t g_mix = ((g_curr * (128 - persistence)) >> 7) + ((g_prev * persistence) >> 7); \
uint32_t b_mix = ((b_curr * (128 - persistence)) >> 7) + ((b_prev * persistence) >> 7); \
\
/* Output colour is the maximum of the input \
* and decayed values */ \
uint32_t r_out = (r_mix > r_curr) ? r_mix : r_curr; \
uint32_t g_out = (g_mix > g_curr) ? g_mix : g_curr; \
uint32_t b_out = (b_mix > b_curr) ? b_mix : b_curr; \
uint32_t color_out = r_out << 16 | g_out << 8 | b_out; \
\
/* Assign colour and store for next frame */ \
*(out++) = color_out; \
*(prev + i) = color_out; \
} \
}
static void convert_palette(const uint32_t *palette32, uint16_t *palette16)
{
size_t i;
for (i = 0; i < 256; i++)
{
uint32_t color32 = *(palette32 + i);
*(palette16 + i) = ((color32 & 0xF80000) >> 8) |
((color32 & 0x00F800) >> 5) |
((color32 & 0x0000F8) >> 3);
}
}
static void blend_frames_null_16(uInt8 *stella_fb, int width, int height)
{
const uint32_t *palette32 = console->getPalette(0);
uint16_t *palette16 = currentPalette16;
uInt8 *in = stella_fb;
uint16_t *out = (uint16_t*)frameBuffer;
int i;
/* If palette has changed, re-cache converted
* RGB565 values */
if (palette32 != currentPalette32)
{
currentPalette32 = palette32;
convert_palette(palette32, palette16);
}
for (i = 0; i < width * height; i++)
*(out++) = *(palette16 + *(in++));
}
static void blend_frames_null_32(uInt8 *stella_fb, int width, int height)
{
const uint32_t *palette = console->getPalette(0);
uInt8 *in = stella_fb;
uint32_t *out = (uint32_t*)frameBuffer;
int i;
for (i = 0; i < width * height; i++)
*(out++) = *(palette + *(in++));
}
static void blend_frames_mix_16(uInt8 *stella_fb, int width, int height)
{
const uint32_t *palette32 = console->getPalette(0);
uint16_t *palette16 = currentPalette16;
uInt8 *in = stella_fb;
uint16_t *prev = (uint16_t*)frameBufferPrev;
uint16_t *out = (uint16_t*)frameBuffer;
int i;
/* If palette has changed, re-cache converted
* RGB565 values */
if (palette32 != currentPalette32)
{
currentPalette32 = palette32;
convert_palette(palette32, palette16);
}
for (i = 0; i < width * height; i++)
{
/* Get colours from current + previous frames */
uint16_t color_curr = *(palette16 + *(in + i));
uint16_t color_prev = *(prev + i);
/* Store colours for next frame */
*(prev + i) = color_curr;
/* Mix colours */
*(out++) = (color_curr + color_prev + ((color_curr ^ color_prev) & 0x821)) >> 1;
}
}
static void blend_frames_mix_32(uInt8 *stella_fb, int width, int height)
{
const uint32_t *palette = console->getPalette(0);
uInt8 *in = stella_fb;
uint32_t *prev = (uint32_t*)frameBufferPrev;
uint32_t *out = (uint32_t*)frameBuffer;
int i;
for (i = 0; i < width * height; i++)
{
/* Get colours from current + previous frames */
uint32_t color_curr = *(palette + *(in + i));
uint32_t color_prev = *(prev + i);
/* Store colours for next frame */
*(prev + i) = color_curr;
/* Mix colours */
*(out++) = (color_curr + color_prev + ((color_curr ^ color_prev) & 0x1010101)) >> 1;
}
}
static void blend_frames_ghost65_16(uInt8 *stella_fb, int width, int height)
{
/* 65% = 83 / 128 */
BLEND_FRAMES_GHOST_16(83);
}
static void blend_frames_ghost65_32(uInt8 *stella_fb, int width, int height)
{
BLEND_FRAMES_GHOST_32(83);
}
static void blend_frames_ghost75_16(uInt8 *stella_fb, int width, int height)
{
/* 75% = 95 / 128 */
BLEND_FRAMES_GHOST_16(95);
}
static void blend_frames_ghost75_32(uInt8 *stella_fb, int width, int height)
{
BLEND_FRAMES_GHOST_32(95);
}
static void blend_frames_ghost85_16(uInt8 *stella_fb, int width, int height)
{
/* 85% ~= 109 / 128 */
BLEND_FRAMES_GHOST_16(109);
}
static void blend_frames_ghost85_32(uInt8 *stella_fb, int width, int height)
{
BLEND_FRAMES_GHOST_32(109);
}
static void blend_frames_ghost95_16(uInt8 *stella_fb, int width, int height)
{
/* 95% ~= 122 / 128 */
BLEND_FRAMES_GHOST_16(122);
}
static void blend_frames_ghost95_32(uInt8 *stella_fb, int width, int height)
{
BLEND_FRAMES_GHOST_32(122);
}
static void (*blend_frames_16)(uInt8 *stella_fb, int width, int height) = blend_frames_null_16;
static void (*blend_frames_32)(uInt8 *stella_fb, int width, int height) = blend_frames_null_32;
static void init_frame_blending(enum frame_blend_method blend_method)
{
/* Allocate/zero out buffer, if required */
if (blend_method != FRAME_BLEND_NONE)
{
if (!frameBufferPrev)
#ifdef _3DS
frameBufferPrev = (uint8_t*)linearMemAlign(FRAME_BUFFER_SIZE, 128);
#else
frameBufferPrev = (uint8_t*)malloc(FRAME_BUFFER_SIZE);
#endif
memset(frameBufferPrev, 0, FRAME_BUFFER_SIZE);
}
/* Assign function pointers */
switch (blend_method)
{
case FRAME_BLEND_MIX:
blend_frames_16 = blend_frames_mix_16;
blend_frames_32 = blend_frames_mix_32;
break;
case FRAME_BLEND_GHOST_65:
blend_frames_16 = blend_frames_ghost65_16;
blend_frames_32 = blend_frames_ghost65_32;
break;
case FRAME_BLEND_GHOST_75:
blend_frames_16 = blend_frames_ghost75_16;
blend_frames_32 = blend_frames_ghost75_32;
break;
case FRAME_BLEND_GHOST_85:
blend_frames_16 = blend_frames_ghost85_16;
blend_frames_32 = blend_frames_ghost85_32;
break;
case FRAME_BLEND_GHOST_95:
blend_frames_16 = blend_frames_ghost95_16;
blend_frames_32 = blend_frames_ghost95_32;
break;
default:
blend_frames_16 = blend_frames_null_16;
blend_frames_32 = blend_frames_null_32;
break;
}
}
/************************************
* Low pass audio filter
************************************/
static void apply_low_pass_filter_mono(int16_t *buf, int length)
{
int samples = length;
int16_t *out = buf;
/* Restore previous sample */
int32_t low_pass = low_pass_left_prev;
/* Single-pole low-pass filter (6 dB/octave) */
int32_t factor_a = low_pass_range;
int32_t factor_b = 0x10000 - factor_a;
do
{
/* Apply low-pass filter */
low_pass = (low_pass * factor_a) + (*out * factor_b);
/* 16.16 fixed point */
low_pass >>= 16;
/* Update sound buffer
* > Converted to stereo by duplicating
* the left/right channels */
*out++ = (int16_t)low_pass;
*out++ = (int16_t)low_pass;
}
while (--samples);
/* Save last sample for next frame */
low_pass_left_prev = low_pass;
}
static void apply_low_pass_filter_stereo(int16_t *buf, int length)
{
int samples = length;
int16_t *out = buf;
/* Restore previous samples */
int32_t low_pass_left = low_pass_left_prev;
int32_t low_pass_right = low_pass_right_prev;
/* Single-pole low-pass filter (6 dB/octave) */
int32_t factor_a = low_pass_range;
int32_t factor_b = 0x10000 - factor_a;
do
{
/* Apply low-pass filter */
low_pass_left = (low_pass_left * factor_a) + (*out * factor_b);
low_pass_right = (low_pass_right * factor_a) + (*(out + 1) * factor_b);
/* 16.16 fixed point */
low_pass_left >>= 16;
low_pass_right >>= 16;
/* Update sound buffer */
*out++ = (int16_t)low_pass_left;
*out++ = (int16_t)low_pass_right;
}
while (--samples);
/* Save last samples for next frame */
low_pass_left_prev = low_pass_left;
low_pass_right_prev = low_pass_right;
}
static void (*apply_low_pass_filter)(int16_t *buf, int length) = apply_low_pass_filter_mono;
/************************************
* Auxiliary functions
************************************/
static float get_stelladaptor_analog_sensitivity(int sensitivity)
{
/* STELLADAPTOR_ANALOG_SENSE_FACTOR *
* (STELLADAPTOR_ANALOG_SENSE_BASE ^
* STELLADAPTOR_ANALOG_SENSE_DEFAULT) = 1.0 */
int sense = (sensitivity > STELLADAPTOR_ANALOG_SENSE_MAX) ?
STELLADAPTOR_ANALOG_SENSE_MAX : sensitivity;
sense = (sense < STELLADAPTOR_ANALOG_SENSE_MIN) ?
STELLADAPTOR_ANALOG_SENSE_MIN : sense;
return STELLADAPTOR_ANALOG_SENSE_FACTOR * (float)pow(
(double)STELLADAPTOR_ANALOG_SENSE_BASE, (double)sense);
}
static float get_stelladaptor_analog_center(int center)
{
/* Convert into ~5 pixel steps */
int offset = (center > STELLADAPTOR_ANALOG_CENTER_MAX) ?
STELLADAPTOR_ANALOG_CENTER_MAX : center;
offset = (offset < STELLADAPTOR_ANALOG_CENTER_MIN) ?
STELLADAPTOR_ANALOG_CENTER_MIN : offset;
return STELLADAPTOR_ANALOG_CENTER_FACTOR * (float)offset;
}
static void init_paddles(void)
{
/* Check whether paddles are active */
left_controller_type = console->controller(Controller::Left).type();
if (left_controller_type == Controller::Paddles)
{
/* Set initial digital sensitivity */
Paddles::setDigitalSensitivity(paddle_digital_sensitivity);
/* Configure mouse control (mapped to
* gamepad analog sticks) */
console->controller(Controller::Left).setMouseControl(
Controller::Paddles, 0, Controller::Paddles, 1);
/* Stella internal mouse sensitivity is hard coded
* to a value of 1 - we handle 'actual' sensitivity
* via the libretro interface */
Paddles::setMouseSensitivity(1);
/* Check whether port 0/1 paddles should be swapped */
if (console->properties().get(Controller_SwapPaddles) == "YES")
{
MouseAxisValue1 = Event::MouseAxisXValue;
MouseButtonValue1 = Event::MouseButtonLeftValue;
MouseAxisValue0 = Event::MouseAxisYValue;
MouseButtonValue0 = Event::MouseButtonRightValue;
}
else
{
MouseAxisValue0 = Event::MouseAxisXValue;
MouseButtonValue0 = Event::MouseButtonLeftValue;
MouseAxisValue1 = Event::MouseAxisYValue;
MouseButtonValue1 = Event::MouseButtonRightValue;
}
}
}
static void update_input()
{
unsigned i;
if (!input_poll_cb)
return;
input_poll_cb();
Event &ev = osystem.eventHandler().event();
/* Loop over input devices */
for (i = 0; i < MAX_RETROPAD_DEVICES; i++)
{
int16_t joy_bits = 0;
/* Read button input (required in all cases) */
if (libretro_supports_bitmasks)
joy_bits = input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK);
else
{
unsigned j;
for (j = 0; j < (RETRO_DEVICE_ID_JOYPAD_R3+1); j++)
joy_bits |= input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j) ? (1 << j) : 0;
}
if (retropad_devices[i] == RETROPAD_STELLA_PADDLES)
{
/* Handle paddle devices */
/* Read analog input */
int paddle_a = input_state_cb(i, RETRO_DEVICE_ANALOG,
RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X);
int paddle_b = input_state_cb(i, RETRO_DEVICE_ANALOG,
RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y);
/* Apply sensitivity/offset factors */
paddle_a = (int)(((float)paddle_a * stelladaptor_analog_sensitivity) +
stelladaptor_analog_center);
paddle_a = (paddle_a > 0x7FFF) ? 0x7FFF : paddle_a;
paddle_a = (paddle_a < -0x7FFF) ? -0x7FFF : paddle_a;
paddle_b = (int)(((float)paddle_b * stelladaptor_analog_sensitivity) +
stelladaptor_analog_center);
paddle_b = (paddle_b > 0x7FFF) ? 0x7FFF : paddle_b;
paddle_b = (paddle_b < -0x7FFF) ? -0x7FFF : paddle_b;
if (i == 0)
{
/* Events for left player's paddles */
/* Paddle 0 */
ev.set(Event::Type(Event::SALeftAxis0Value), paddle_a);
ev.set(Event::Type(Event::PaddleZeroFire), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_A));
/* Paddle 1 */
ev.set(Event::Type(Event::SALeftAxis1Value), paddle_b);
ev.set(Event::Type(Event::PaddleOneFire), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_B));
/* Generic inputs */
ev.set(Event::Type(Event::ConsoleLeftDiffA), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_L));
ev.set(Event::Type(Event::ConsoleLeftDiffB), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_L2));
ev.set(Event::Type(Event::ConsoleColor), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_L3));
ev.set(Event::Type(Event::ConsoleRightDiffA), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_R));
ev.set(Event::Type(Event::ConsoleRightDiffB), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_R2));
ev.set(Event::Type(Event::ConsoleBlackWhite), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_R3));
ev.set(Event::Type(Event::ConsoleSelect), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT));
ev.set(Event::Type(Event::ConsoleReset), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_START));
}
else
{
/* Events for right player's paddles */
/* Paddle 2 */
ev.set(Event::Type(Event::SARightAxis0Value), paddle_a);
ev.set(Event::Type(Event::PaddleTwoFire), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_A));
/* Paddle 3 */
ev.set(Event::Type(Event::SARightAxis1Value), paddle_b);
ev.set(Event::Type(Event::PaddleThreeFire), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_B));
}
}
else
{
/* Handle regular gamepad devices */
if (i == 0)
{
/* Events for left player's joystick */
ev.set(Event::Type(Event::JoystickZeroUp), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_UP));
ev.set(Event::Type(Event::JoystickZeroDown), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN));
ev.set(Event::Type(Event::JoystickZeroLeft), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT));
ev.set(Event::Type(Event::JoystickZeroRight), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT));
ev.set(Event::Type(Event::JoystickZeroFire), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_B));
ev.set(Event::Type(Event::ConsoleLeftDiffA), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_L));
ev.set(Event::Type(Event::ConsoleLeftDiffB), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_L2));
ev.set(Event::Type(Event::ConsoleColor), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_L3));
ev.set(Event::Type(Event::ConsoleRightDiffA), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_R));
ev.set(Event::Type(Event::ConsoleRightDiffB), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_R2));
ev.set(Event::Type(Event::ConsoleBlackWhite), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_R3));
ev.set(Event::Type(Event::ConsoleSelect), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT));
ev.set(Event::Type(Event::ConsoleReset), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_START));
}
else
{
/* Events for right player's joystick */
ev.set(Event::Type(Event::JoystickOneUp), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_UP));
ev.set(Event::Type(Event::JoystickOneDown), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN));
ev.set(Event::Type(Event::JoystickOneLeft), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT));
ev.set(Event::Type(Event::JoystickOneRight), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT));
ev.set(Event::Type(Event::JoystickOneFire), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_B));
}
/* Read analog paddle input, if required */
if (left_controller_type == Controller::Paddles)
{
float paddle_amp = 0.0f;
int paddle = input_state_cb(i, RETRO_DEVICE_ANALOG,
RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X);
/* Account for paddle deadzone, and convert
* analog stick input to an 'amplitude' value */
if ((paddle < -paddle_analog_deadzone) ||
(paddle > paddle_analog_deadzone))
{
paddle_amp = (float)((paddle > paddle_analog_deadzone) ?
(paddle - paddle_analog_deadzone) :
(paddle + paddle_analog_deadzone)) /
(float)(PADDLE_ANALOG_RANGE - paddle_analog_deadzone);
/* Check whether paddle response is quadratic */
if (paddle_analog_is_quadratic)
{
if (paddle_amp < 0.0)
paddle_amp = -(paddle_amp * paddle_amp);
else
paddle_amp = paddle_amp * paddle_amp;
}
}
/* Convert paddle amplitude back to an integer,
* scaling by current analog sensitivity value
* > Note: Stella internally divides paddle value
* by 2 - counter this by premultiplying */
paddle = (int)(paddle_amp * paddle_analog_sensitivity) << 1;
if (i == 0)
{
/* Events for left player's paddle */
ev.set(Event::Type(MouseAxisValue0), paddle);
ev.set(Event::Type(MouseButtonValue0), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_Y));
}
else
{
/* Events for right player's paddle */
ev.set(Event::Type(MouseAxisValue1), paddle);
ev.set(Event::Type(MouseButtonValue1), joy_bits & (1 << RETRO_DEVICE_ID_JOYPAD_Y));
}
}
}
}
/* Tell all input devices to read their state from the event structure */
console->controller(Controller::Left).update();
console->controller(Controller::Right).update();
console->switches().update();
}
static void check_variables(bool first_run)
{
struct retro_variable var = {0};
enum frame_blend_method blend_method = FRAME_BLEND_NONE;
int last_paddle_sensitivity;
int stelladaptor_sensitivity;
int stelladaptor_center;
/* Only read colour depth option on first run */
if (first_run)
{
var.key = "stella2014_color_depth";
var.value = NULL;
/* Set 16bpp by default */
framePixelBytes = 2;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (strcmp(var.value, "24bit") == 0)
framePixelBytes = 4;
}
/* Read interframe blending option */
var.key = "stella2014_mix_frames";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (!strcmp(var.value, "mix"))
blend_method = FRAME_BLEND_MIX;
else if (!strcmp(var.value, "ghost_65"))
blend_method = FRAME_BLEND_GHOST_65;
else if (!strcmp(var.value, "ghost_75"))
blend_method = FRAME_BLEND_GHOST_75;
else if (!strcmp(var.value, "ghost_85"))
blend_method = FRAME_BLEND_GHOST_85;
else if (!strcmp(var.value, "ghost_95"))
blend_method = FRAME_BLEND_GHOST_95;
}
init_frame_blending(blend_method);
/* Read low pass audio filter settings */
var.key = "stella2014_low_pass_filter";
var.value = NULL;
low_pass_enabled = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (strcmp(var.value, "enabled") == 0)
low_pass_enabled = true;
var.key = "stella2014_low_pass_range";
var.value = NULL;
low_pass_range = (60 * 0x10000) / 100;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
low_pass_range = (strtol(var.value, NULL, 10) * 0x10000) / 100;
/* Read paddle digital sensitivity option */
var.key = "stella2014_paddle_digital_sensitivity";
var.value = NULL;
last_paddle_sensitivity = paddle_digital_sensitivity;
paddle_digital_sensitivity = 50;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
paddle_digital_sensitivity = atoi(var.value);
paddle_digital_sensitivity = (paddle_digital_sensitivity > 100) ?
100 : paddle_digital_sensitivity;
paddle_digital_sensitivity = (paddle_digital_sensitivity < 10) ?
10 : paddle_digital_sensitivity;
}
/* Only apply paddle sensitivity update if
* this is *not* the first run */
if (!first_run &&
(left_controller_type == Controller::Paddles) &&
(paddle_digital_sensitivity != last_paddle_sensitivity))
Paddles::setDigitalSensitivity(paddle_digital_sensitivity);
/* Read paddle analog sensitivity option */
var.key = "stella2014_paddle_analog_sensitivity";
var.value = NULL;
paddle_analog_sensitivity = 50.0f;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
int analog_sensitivity = atoi(var.value);
analog_sensitivity = (analog_sensitivity > 150) ?
150 : analog_sensitivity;
analog_sensitivity = (analog_sensitivity < 10) ?
10 : analog_sensitivity;
paddle_analog_sensitivity = (float)analog_sensitivity;
}
/* Read paddle analog response option */
var.key = "stella2014_paddle_analog_response";
var.value = NULL;
paddle_analog_is_quadratic = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (strcmp(var.value, "quadratic") == 0)
paddle_analog_is_quadratic = true;
/* Read paddle analog deadzone option */
var.key = "stella2014_paddle_analog_deadzone";
var.value = NULL;
paddle_analog_deadzone = (int)(0.15f * (float)PADDLE_ANALOG_RANGE);
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
paddle_analog_deadzone = (int)((float)atoi(var.value) * 0.01f * (float)PADDLE_ANALOG_RANGE);
/* Read Stelladaptor analog sensitivity option */
var.key = "stella2014_stelladaptor_analog_sensitivity";
var.value = NULL;
stelladaptor_sensitivity = STELLADAPTOR_ANALOG_SENSE_DEFAULT;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
stelladaptor_sensitivity = atoi(var.value);
stelladaptor_analog_sensitivity =
get_stelladaptor_analog_sensitivity(
stelladaptor_sensitivity);
/* Read Stelladaptor analog centre option */
var.key = "stella2014_stelladaptor_analog_center";
var.value = NULL;
stelladaptor_center = STELLADAPTOR_ANALOG_CENTER_DEFAULT;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
stelladaptor_center = atoi(var.value);
stelladaptor_analog_center =
get_stelladaptor_analog_center(
stelladaptor_center);
}
/************************************
* libretro implementation
************************************/
void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
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_environment(retro_environment_t cb)
{
struct retro_vfs_interface_info vfs_iface_info;
environ_cb = cb;
libretro_set_core_options(environ_cb);
environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)retropad_port_info);
vfs_iface_info.required_interface_version = 1;
vfs_iface_info.iface = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VFS_INTERFACE, &vfs_iface_info))
filestream_vfs_init(&vfs_iface_info);
}