-
-
Notifications
You must be signed in to change notification settings - Fork 332
/
user_io.cpp
4194 lines (3618 loc) · 93.1 KB
/
user_io.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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <stdbool.h>
#include <fcntl.h>
#include <time.h>
#include <limits.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include "lib/imlib2/Imlib2.h"
#include "hardware.h"
#include "osd.h"
#include "user_io.h"
#include "debug.h"
#include "spi.h"
#include "cfg.h"
#include "input.h"
#include "fpga_io.h"
#include "file_io.h"
#include "menu.h"
#include "DiskImage.h"
#include "brightness.h"
#include "sxmlc.h"
#include "bootcore.h"
#include "charrom.h"
#include "scaler.h"
#include "miniz.h"
#include "cheats.h"
#include "video.h"
#include "audio.h"
#include "shmem.h"
#include "ide.h"
#include "ide_cdrom.h"
#include "profiling.h"
#include "support.h"
static char core_path[1024] = {};
static char rbf_path[1024] = {};
static fileTYPE sd_image[16] = {};
static int sd_type[16] = {};
static int sd_image_cangrow[16] = {};
static uint64_t buffer_lba[16] = { ULLONG_MAX,ULLONG_MAX,ULLONG_MAX,ULLONG_MAX,
ULLONG_MAX,ULLONG_MAX,ULLONG_MAX,ULLONG_MAX,
ULLONG_MAX,ULLONG_MAX,ULLONG_MAX,ULLONG_MAX,
ULLONG_MAX,ULLONG_MAX,ULLONG_MAX,ULLONG_MAX };
static int use_save = 0;
// mouse and keyboard emulation state
static int emu_mode = EMU_NONE;
// keep state over core type and its capabilities
static unsigned char core_type = CORE_TYPE_UNKNOWN;
static unsigned char dual_sdr = 0;
static int fio_size = 0;
static int io_ver = 0;
// keep state of caps lock
static char caps_lock_toggle = 0;
#define LED_FREQ 100 // 100 ms
static unsigned long led_timer;
static char keyboard_leds = 0;
static bool caps_status = 0;
static bool num_status = 0;
static bool scrl_status = 0;
static bool winkey_pressed = 0;
static uint16_t sdram_cfg = 0;
static char last_filename[1024] = {};
void user_io_store_filename(char *filename)
{
char *p = strrchr(filename, '/');
if (p) strcpy(last_filename, p + 1);
else strcpy(last_filename, filename);
p = strrchr(last_filename, '.');
if (p) *p = 0;
}
const char *get_image_name(int i)
{
if (!sd_image[i].size) return NULL;
char *p = strrchr(sd_image[i].name, '/');
if (!p) p = sd_image[i].name; else p++;
return p;
}
fileTYPE *get_image(int i)
{
return &sd_image[i];
}
static uint32_t uart_mode;
uint32_t user_io_get_uart_mode()
{
return uart_mode;
}
// set by OSD code to suppress forwarding of those keys to the core which
// may be in use by an active OSD
static char osd_is_visible = 0;
char user_io_osd_is_visible()
{
return osd_is_visible;
}
unsigned char user_io_core_type()
{
return core_type;
}
static char config_ver[10] = {};
char* user_io_create_config_name(int with_ver)
{
static char str[40];
str[0] = 0;
char *p = user_io_get_core_name();
if (p[0])
{
strcpy(str, p);
if (with_ver) strcat(str, config_ver);
strcat(str, ".CFG");
}
return str;
}
static char core_name[32] = {};
static char ovr_name[32] = {};
static char orig_name[32] = {};
static int ovr_samedir = 0;
char *user_io_make_filepath(const char *path, const char *filename)
{
static char filepath_store[1024];
snprintf(filepath_store, 1024, "%s/%s", path, filename);
return filepath_store;
}
void user_io_name_override(const char* name, int samedir)
{
snprintf(ovr_name, sizeof(ovr_name), "%s", name);
ovr_samedir = samedir;
}
void user_io_set_core_name(const char *name)
{
snprintf(core_name, sizeof(core_name), name);
printf("Core name set to \"%s\"\n", core_name);
}
char *user_io_get_core_name(int orig)
{
return orig ? orig_name : core_name;
}
char *user_io_get_core_name2()
{
return (ovr_name[0] && ovr_samedir) ? orig_name : core_name;
}
char *user_io_get_core_path(const char *suffix, int recheck)
{
static char old_name[256] = {};
static char tmp[1024] = {};
char *name = (ovr_name[0] && ovr_samedir) ? orig_name : core_name;
if (!suffix) suffix = (!strcasecmp(name, "minimig")) ? "Amiga" : name;
if (recheck || strcmp(old_name, suffix) || !tmp[0])
{
strcpy(old_name, suffix);
strcpy(tmp, suffix);
prefixGameDir(tmp, sizeof(tmp));
}
return tmp;
}
static char is_arcade_type = 0;
char is_arcade()
{
return is_arcade_type;
}
static int is_menu_type = 0;
char is_menu()
{
if (!is_menu_type) is_menu_type = strcasecmp(orig_name, "MENU") ? 2 : 1;
return (is_menu_type == 1);
}
static int is_x86_type = 0;
char is_x86()
{
if (!is_x86_type) is_x86_type = strcasecmp(orig_name, "AO486") ? 2 : 1;
return (is_x86_type == 1);
}
static int is_snes_type = 0;
char is_snes()
{
if (!is_snes_type) is_snes_type = strcasecmp(orig_name, "SNES") ? 2 : 1;
return (is_snes_type == 1);
}
static int is_sgb_type = 0;
char is_sgb()
{
if (!is_sgb_type) is_sgb_type = strcasecmp(orig_name, "SGB") ? 2 : 1;
return (is_sgb_type == 1);
}
static int is_cpc_type = 0;
char is_cpc()
{
if (!is_cpc_type) is_cpc_type = strcasecmp(orig_name, "amstrad") ? 2 : 1;
return (is_cpc_type == 1);
}
static int is_zx81_type = 0;
char is_zx81()
{
if (!is_zx81_type) is_zx81_type = strcasecmp(orig_name, "zx81") ? 2 : 1;
return (is_zx81_type == 1);
}
static int is_neogeo_type = 0;
char is_neogeo()
{
if (!is_neogeo_type) is_neogeo_type = strcasecmp(orig_name, "neogeo") ? 2 : 1;
return (is_neogeo_type == 1);
}
char is_neogeo_cd() {
return is_neogeo() && neocd_is_en();
}
static int is_minimig_type = 0;
char is_minimig()
{
if (!is_minimig_type) is_minimig_type = strcasecmp(orig_name, "minimig") ? 2 : 1;
return (is_minimig_type == 1);
}
static int is_megacd_type = 0;
char is_megacd()
{
if (!is_megacd_type) is_megacd_type = strcasecmp(orig_name, "MEGACD") ? 2 : 1;
return (is_megacd_type == 1);
}
static int is_pce_type = 0;
char is_pce()
{
if (!is_pce_type) is_pce_type = strcasecmp(orig_name, "TGFX16") ? 2 : 1;
return (is_pce_type == 1);
}
static int is_archie_type = 0;
char is_archie()
{
if (!is_archie_type) is_archie_type = strcasecmp(orig_name, "ARCHIE") ? 2 : 1;
return (is_archie_type == 1);
}
static int is_pcxt_type = 0;
char is_pcxt()
{
if (!is_pcxt_type) is_pcxt_type = strcasecmp(orig_name, "PCXT") ? 2 : 1;
return (is_pcxt_type == 1);
}
static int is_gba_type = 0;
char is_gba()
{
if (!is_gba_type) is_gba_type = strcasecmp(orig_name, "GBA") ? 2 : 1;
return (is_gba_type == 1);
}
static int is_c64_type = 0;
char is_c64()
{
if (!is_c64_type) is_c64_type = strcasecmp(orig_name, "C64") ? 2 : 1;
return (is_c64_type == 1);
}
static int is_c128_type = 0;
char is_c128()
{
if (!is_c128_type) is_c128_type = strcasecmp(orig_name, "C128") ? 2 : 1;
return (is_c128_type == 1);
}
static int is_psx_type = 0;
char is_psx()
{
if (!is_psx_type) is_psx_type = strcasecmp(orig_name, "PSX") ? 2 : 1;
return (is_psx_type == 1);
}
static int is_st_type = 0;
char is_st()
{
if (!is_st_type) is_st_type = strcasecmp(orig_name, "AtariST") ? 2 : 1;
return (is_st_type == 1);
}
char is_sharpmz()
{
return(core_type == CORE_TYPE_SHARPMZ);
}
static int is_electron_type = 0;
char is_electron()
{
if (!is_electron_type) is_electron_type = strcasecmp(orig_name, "AcornElectron") ? 2 : 1;
return (is_electron_type == 1);
}
static int is_saturn_type = 0;
char is_saturn()
{
if (!is_saturn_type) is_saturn_type = strcasecmp(orig_name, "Saturn") ? 2 : 1;
return (is_saturn_type == 1);
}
static int is_n64_type = 0;
char is_n64()
{
if (!is_n64_type) is_n64_type = strcasecmp(orig_name, "N64") ? 2 : 1;
return (is_n64_type == 1);
}
static int is_uneon_type = 0;
char is_uneon()
{
if (!is_uneon_type) is_uneon_type = strcasecmp(orig_name, "Uneon") ? 2 : 1;
return (is_uneon_type == 1);
}
static int is_no_type = 0;
static int disable_osd = 0;
char has_menu()
{
if (disable_osd) return 0;
if (!is_no_type) is_no_type = user_io_get_core_name()[0] ? 1 : 2;
return (is_no_type == 1);
}
void user_io_read_core_name()
{
is_menu_type = 0;
is_x86_type = 0;
is_no_type = 0;
is_snes_type = 0;
is_sgb_type = 0;
is_cpc_type = 0;
is_zx81_type = 0;
is_neogeo_type = 0;
is_minimig_type = 0;
is_megacd_type = 0;
is_pce_type = 0;
is_archie_type = 0;
is_gba_type = 0;
is_c64_type = 0;
is_c128_type = 0;
is_st_type = 0;
is_pcxt_type = 0;
is_uneon_type = 0;
core_name[0] = 0;
char *p = user_io_get_confstr(0);
if (p && p[0]) snprintf(orig_name, sizeof(orig_name), "%s", p);
// get core name
if (ovr_name[0]) strcpy(core_name, ovr_name);
else if (orig_name[0]) strcpy(core_name, p);
printf("Core name is \"%s\"\n", core_name);
}
int substrcpy(char *d, const char *s, char idx)
{
char p = 0;
char *b = d;
while (*s)
{
if ((p == idx) && *s && (*s != ',')) *d++ = *s;
if (*s == ',')
{
if (p == idx) break;
p++;
}
s++;
}
*d = 0;
return (int)(d - b);
}
static char cur_status[16] = {};
int user_io_status_bits(const char *opt, int *s, int *e, int ex, int single)
{
uint32_t start = 0, end = 0;
if (opt[0] == '[')
{
if (!single && sscanf(opt, "[%u:%u]", &end, &start) == 2)
{
if (start > 127 || end > 127 || end <= start) return 0;
}
else if (sscanf(opt, "[%u]", &start) == 1)
{
if (start > 127) return 0;
end = start;
}
else return 0;
}
else
{
if ((opt[0] >= '0') && (opt[0] <= '9')) start = opt[0] - '0';
else if ((opt[0] >= 'A') && (opt[0] <= 'V')) start = opt[0] - 'A' + 10;
else return 0;
if (!single && (opt[1] >= '0') && (opt[1] <= '9')) end = opt[1] - '0';
else if (!single && (opt[1] >= 'A') && (opt[1] <= 'V')) end = opt[1] - 'A' + 10;
else
{
single = 1;
end = start;
}
if (ex)
{
start += 32;
end += 32;
}
if (start > 127 || end > 127 || (!single && end <= start)) return 0;
}
//max 8 bits per option
if (end - start > 8) return 0;
if (s) *s = (int)start;
if (e) *e = (int)end;
return 1 + end - start;
}
uint32_t user_io_status_get(const char *opt, int ex)
{
int start, end;
int size = user_io_status_bits(opt, &start, &end, ex);
if (!size) return 0;
uint32_t x = (cur_status[end / 8] << 8) | cur_status[start / 8];
x >>= start % 8;
return x & ~(0xffffffff << size);
}
uint32_t user_io_status_mask(const char *opt)
{
return ~(0xffffffff << user_io_status_bits(opt, 0, 0, 0));
}
uint32_t user_io_hd_mask(const char *opt)
{
int start;
int size = user_io_status_bits(opt, &start, 0, 0, 1);
if (!size) return 0;
return start;
}
void user_io_status_set(const char *opt, uint32_t value, int ex)
{
int start, end;
int size = user_io_status_bits(opt, &start, &end, ex);
if (!size) return;
int s = start / 8;
int e = end / 8;
uint32_t mask = ~(0xffffffff << size);
mask <<= start % 8;
uint32_t x = (cur_status[e] << 8) | cur_status[s];
x = (x & ~mask) | ((value << (start % 8)) & mask);
cur_status[s] = (char)x;
if (e != s) cur_status[e] = (char)(x >> 8);
if (!is_st())
{
spi_uio_cmd_cont(UIO_SET_STATUS2);
for (uint32_t i = 0; i < sizeof(cur_status); i += 2) spi_w((cur_status[i + 1] << 8) | cur_status[i]);
DisableIO();
}
}
int user_io_status_save(const char *filename)
{
return FileSaveConfig(filename, cur_status, sizeof(cur_status));
}
void user_io_status_reset()
{
memset(cur_status, 0, sizeof(cur_status));
user_io_status_set("[0]", 0);
}
static void set_kbd_led(int led, int state)
{
if (led & HID_LED_CAPS_LOCK)
{
caps_status = state&HID_LED_CAPS_LOCK;
if (!(keyboard_leds & KBD_LED_CAPS_CONTROL)) set_kbdled(led&HID_LED_CAPS_LOCK, caps_status);
}
if (led & HID_LED_NUM_LOCK)
{
num_status = state&HID_LED_NUM_LOCK;
if (!(keyboard_leds & KBD_LED_NUM_CONTROL)) set_kbdled(led&HID_LED_NUM_LOCK, num_status);
}
if (led & HID_LED_SCROLL_LOCK)
{
scrl_status = state&HID_LED_SCROLL_LOCK;
if (!(keyboard_leds & KBD_LED_SCRL_CONTROL)) set_kbdled(led&HID_LED_SCROLL_LOCK, scrl_status);
}
}
static void set_emu_mode(int mode)
{
uint8_t emu_led;
emu_mode = mode;
switch (emu_mode)
{
case EMU_JOY0:
emu_led = 0x20;
set_kbd_led(HID_LED_NUM_LOCK | HID_LED_SCROLL_LOCK, HID_LED_NUM_LOCK);
Info("Kbd mode: Joystick 1", 1000);
break;
case EMU_JOY1:
emu_led = 0x40;
set_kbd_led(HID_LED_NUM_LOCK | HID_LED_SCROLL_LOCK, HID_LED_SCROLL_LOCK);
Info("Kbd mode: Joystick 2", 1000);
break;
case EMU_MOUSE:
emu_led = 0x60;
set_kbd_led(HID_LED_NUM_LOCK | HID_LED_SCROLL_LOCK, HID_LED_NUM_LOCK | HID_LED_SCROLL_LOCK);
Info("Kbd mode: Mouse", 1000);
break;
default:
emu_led = 0;
set_kbd_led(HID_LED_NUM_LOCK | HID_LED_SCROLL_LOCK, 0);
Info("Kbd mode: Normal", 1000);
}
spi_uio_cmd16(UIO_LEDS, 0x6000 | emu_led);
input_notify_mode();
}
int user_io_get_kbdemu()
{
return emu_mode;
}
static int joy_force = 0;
// Analog/Digital Joystick translation
// 0 - translate Analog to Digital (default)
// 1 - translate Digital to Analog
// 2 - do not translate
static int joy_transl = 0;
int user_io_get_joy_transl()
{
return joy_transl;
}
static int use_cheats = 0;
static uint32_t ss_base = 0;
static uint32_t ss_size = 0;
static uint32_t uart_speeds[13] = {};
static char uart_speed_labels[13][32] = {};
static uint32_t midi_speeds[13] = {};
static char midi_speed_labels[13][32] = {};
static const uint32_t mlink_speeds[13] = { 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250, 38400, 57600, 115200 };
static const char mlink_speed_labels[13][32] = { "110", "300", "600", "1200", "2400", "4800", "9600", "14400", "19200", "31250/MIDI", "38400", "57600", "115200" };
static char defmra[1024] = {};
static int boot0_loaded = 0;
static int boot0_mounted = 0;
static void parse_config()
{
static char str[1024];
static char ext[256];
char mask[sizeof(cur_status) * 8] = {};
char overlap[sizeof(cur_status) * 8] = {};
int start, end, sz;
int i = 0;
char *p;
joy_force = 0;
joy_bcount = 0;
do {
p = user_io_get_confstr(i);
printf("get cfgstring %d = %s\n", i, p ? p : "NULL");
if (!i)
{
OsdCoreNameSet((p && p[0]) ? p : "CORE");
}
if (i == 1 && p)
{
while (p && *p)
{
if (!strncasecmp(p, "SS", 2))
{
char *end = 0;
ss_base = strtoul(p+2, &end, 16);
p = end;
if (p && *p == ':')
{
p++;
ss_size = strtoul(p, &end, 16);
}
printf("Got save state parameters: base=0x%X, size=0x%X\n", ss_base, ss_size);
if (!ss_size || ss_size > (128 * 1024 * 1024))
{
ss_size = 0;
ss_base = 0;
printf("Invalid size!\n");
}
else if (ss_base < 0x20000000 || ss_base >= 0x40000000 || (ss_base + ss_size) >= 0x40000000)
{
ss_size = 0;
ss_base = 0;
printf("Invalid base!\n");
}
}
if (!strncasecmp(p, "UART", 4))
{
p += 4;
for (int i = 0; i < 10 && p && *p; i++)
{
char *end = 0;
uart_speeds[i] = strtoul(p, &end, 10);
p = end;
if (p && *p == '(')
{
p++;
int n = 0;
while (*p != ';' && *p != ':' && *p != ')' && *p != ',')
{
if (n < 16) uart_speed_labels[i][n] = *p;
p++;
n++;
}
if (*p == ')') p++;
}
else
{
sprintf(uart_speed_labels[i], "%d", uart_speeds[i]);
}
if (p && *p == ':') p++;
}
printf("Got UART speeds:");
for(int i=0; i<10; i++) printf(" %d", uart_speeds[i]);
printf("\n");
}
if (!strncasecmp(p, "MIDI", 4))
{
p += 4;
for (int i = 0; i < 10 && p && *p; i++)
{
char *end = 0;
midi_speeds[i] = strtoul(p, &end, 10);
p = end;
if (p && *p == '(')
{
p++;
int n = 0;
while (*p != ';' && *p != ':' && *p != ')' && *p != ',')
{
if (n < 16) midi_speed_labels[i][n] = *p;
p++;
n++;
}
if (*p == ')') p++;
}
else
{
sprintf(midi_speed_labels[i], "%d", midi_speeds[i]);
}
if (p && *p == ':') p++;
}
if (!midi_speeds[0])
{
midi_speeds[0] = 31250;
strcpy(midi_speed_labels[0], "31250");
}
printf("Got MIDI speeds:");
for (int i = 0; i < 10; i++) printf(" %d", midi_speeds[i]);
printf("\n");
}
p = strchr(p, ',');
if (p) p++;
}
}
if (i >= 2 && p && p[0])
{
if (!strncmp(p, "DEFMRA,", 7))
{
snprintf(defmra, sizeof(defmra), (p[7] == '/') ? "%s%s" : "%s/_Arcades/%s", getRootDir(), p + 7);
}
else if (!strncmp(p, "DIP", 3))
{
}
else
{
//skip Disable/Hide masks
while ((p[0] == 'H' || p[0] == 'D' || p[0] == 'h' || p[0] == 'd') && strlen(p) >= 2) p += 2;
}
if (p[0] == 'P') p += 2;
if (p[0] == 'R' || p[0] == 'T' || p[0] == 'r' || p[0] == 't')
{
sz = user_io_status_bits(p + 1, &start, &end, p[0] == 'r' || p[0] == 't');
if (sz == 1)
{
overlap[start] |= mask[start];
mask[start] |= 1;
}
else
{
printf("Invalid OSD option: %s\n", p);
}
}
else if (p[0] == 'O' || p[0] == 'o')
{
char *opt = (p[1] == 'X') ? (p + 2) : (p + 1);
sz = user_io_status_bits(opt, &start, &end, p[0] == 'o');
if (sz)
{
while (sz)
{
overlap[start] |= mask[start];
mask[start] |= 1;
sz--;
start++;
}
}
else
{
printf("Invalid OSD option: %s\n", p);
}
}
if (p[0] == 'J')
{
int n = 1;
if (p[1] == 'D') { joy_transl = 0; n++; }
if (p[1] == 'A') { joy_transl = 1; n++; }
if (p[1] == 'N') { joy_transl = 2; n++; }
if (p[n] == '1')
{
joy_force = 1;
set_emu_mode(EMU_JOY0);
}
}
if (p[0] == 'O' && p[1] == 'X')
{
int x = user_io_status_get(p + 2);
printf("found OX option: %s: %d\n", p, x);
if (is_x86())
{
if (p[2] == '2') x86_set_fdd_boot(!(x & 1));
}
}
if (p[0] == 'X')
{
disable_osd = 1;
}
if (p[0] == 'V')
{
// get version string
char s[128];
strcpy(s, OsdCoreNameGet());
strcat(s, " ");
substrcpy(s + strlen(s), p, 1);
OsdCoreNameSet(s);
}
if (p[0] == 'v')
{
static char str[256];
substrcpy(str, p, 1);
str[2] = 0;
int v = strtoul(str, 0, 10);
if(v) snprintf(config_ver, sizeof(config_ver), "_v%d", v);
}
if (p[0] == 'C')
{
use_cheats = 1;
}
if (p[0] == 'F')
{
int opensave = 0;
int idx = 1;
if (p[idx] == 'S')
{
opensave = 1;
idx++;
}
if (p[idx] == 'C')
{
idx++;
uint32_t load_addr = 0;
if (substrcpy(str, p, 3))
{
load_addr = strtoul(str, NULL, 16);
if (load_addr < 0x20000000 || load_addr >= 0x40000000)
{
printf("Loading address 0x%X is outside the supported range! Using normal load.\n", load_addr);
load_addr = 0;
}
}
sprintf(str, "%s.f%c", user_io_get_core_name(), p[idx]);
substrcpy(ext, p, 1);
while (strlen(ext) % 3) strcat(ext, " ");
if (FileLoadConfig(str, str, sizeof(str)) && str[0])
{
idx = p[idx] - '0';
StoreIdx_F(idx, str);
user_io_file_tx(str, (user_io_ext_idx(str, ext) << 6) | idx, opensave, 0, 0, load_addr);
if (!idx) boot0_loaded = 1;
if (is_cpc())
{
char *p = strrchr(str, '.');
if (p && (!strcasecmp(p, ".eZZ") || !strcasecmp(p, ".eZ0"))) boot0_loaded = 1;
}
}
}
}
if (p[0] == 'S' && p[1] == 'C')
{
sprintf(str, "%s.s%c", user_io_get_core_name(), p[2]);
substrcpy(ext, p, 1);
while (strlen(ext) % 3) strcat(ext, " ");
if (FileLoadConfig(str, str, sizeof(str)) && str[0])
{
int idx = p[2] - '0';
StoreIdx_S(idx, str);
if (is_x86() || is_pcxt() || (is_uneon() && idx >= 2))
{
x86_set_image(idx, str);
}
else if (is_megacd())
{
mcd_set_image(idx, str);
}
else if (is_pce())
{
pcecd_set_image(idx, str);
cheats_init(str, 0);
}
else
{
if (!is_c128()) user_io_set_index((user_io_ext_idx(str, ext) << 6) | idx);
user_io_file_mount(str, idx);
}
if (!idx) boot0_mounted = 1;
}
}
}
i++;
} while (p || i<3);
mask[0] = 1; // reset is always on bit 0
printf("\n// Status Bit Map:\n");
printf("// Upper Lower\n");
printf("// 0 1 2 3 4 5 6 \n");
printf("// 01234567890123456789012345678901 23456789012345678901234567890123\n");
printf("// 0123456789ABCDEFGHIJKLMNOPQRSTUV 0123456789ABCDEFGHIJKLMNOPQRSTUV\n");
strcpy(str, "// ");
for (int i = 0; i < 32; i++) strcat(str, mask[i] ? "X" : " ");
strcat(str, " ");
for (int i = 32; i < 64; i++) strcat(str, mask[i] ? "X" : " ");
strcat(str, "\n");
printf(str);
int ovr = 0;
for (int i = 0; i < 64; i++) ovr |= overlap[i];
if (ovr)
{
strcpy(str, "// ");
for (int i = 0; i < 32; i++) strcat(str, overlap[i] ? "^" : " ");
strcat(str, " ");
for (int i = 32; i < 64; i++) strcat(str, overlap[i] ? "^" : " ");
strcat(str, "\n");
printf(str);
printf("// *Overlapped bits!* (can be intentional)\n");
}
printf("\n");
ovr = 0;
for (int i = 64; i < 128; i++) ovr |= mask[i];
if (ovr)
{
printf("// 0 0 0 0 1 1 1 \n");
printf("// 6 7 8 9 0 1 2 \n");
printf("// 45678901234567890123456789012345 67890123456789012345678901234567\n");
strcpy(str, "// ");
for (int i = 64; i < 96; i++) strcat(str, mask[i] ? "X" : " ");
strcat(str, " ");
for (int i = 96; i < 128; i++) strcat(str, mask[i] ? "X" : " ");
strcat(str, "\n");
printf(str);
ovr = 0;
for (int i = 64; i < 128; i++) ovr |= overlap[i];
if (ovr)
{
strcpy(str, "// ");
for (int i = 64; i < 96; i++) strcat(str, overlap[i] ? "^" : " ");
strcat(str, " ");
for (int i = 96; i < 128; i++) strcat(str, overlap[i] ? "^" : " ");
strcat(str, "\n");
printf(str);
printf("// *Overlapped bits!* (can be intentional)\n");
}
printf("\n");
}
// legacy GBA versions
if (is_gba() && !ss_base)
{
ss_base = 0x3E000000;
ss_size = 0x100000;
}
}
//MSM6242B layout
static void send_rtc(int type)
{
//printf("Update RTC\n");
time_t t = time(NULL);