forked from MiSTer-devel/Main_MiSTer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.cpp
7035 lines (6221 loc) · 169 KB
/
menu.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
/*
Copyright 2005, 2006, 2007 Dennis van Weeren
Copyright 2008, 2009 Jakub Bednarski
This file is part of Minimig
Minimig is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Minimig is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// 2009-11-14 - OSD labels changed
// 2009-12-15 - added display of directory name extensions
// 2010-01-09 - support for variable number of tracks
// 2016-06-01 - improvements to 8-bit menu
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <fcntl.h>
#include <time.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <stdbool.h>
#include <stdio.h>
#include <sched.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <libgen.h>
#include <bluetooth.h>
#include <hci.h>
#include <hci_lib.h>
#include "file_io.h"
#include "osd.h"
#include "hardware.h"
#include "menu.h"
#include "user_io.h"
#include "debug.h"
#include "fpga_io.h"
#include "cfg.h"
#include "input.h"
#include "battery.h"
#include "cheats.h"
#include "video.h"
#include "audio.h"
#include "joymapping.h"
#include "recent.h"
#include "support.h"
#include "bootcore.h"
#include "ide.h"
/*menu states*/
enum MENU
{
MENU_NONE1,
MENU_NONE2,
MENU_INFO,
MENU_SYSTEM1,
MENU_SYSTEM2,
MENU_COMMON1,
MENU_COMMON2,
MENU_MISC1,
MENU_MISC2,
MENU_FILE_SELECT1,
MENU_FILE_SELECT2,
MENU_CORE_FILE_SELECTED1,
MENU_CORE_FILE_SELECTED2,
MENU_CORE_FILE_CANCELED,
MENU_RECENT1,
MENU_RECENT2,
MENU_RECENT3,
MENU_RECENT4,
MENU_ABOUT1,
MENU_ABOUT2,
MENU_RESET1,
MENU_RESET2,
MENU_JOYSYSMAP,
MENU_JOYDIGMAP,
MENU_JOYDIGMAP1,
MENU_JOYDIGMAP2,
MENU_JOYDIGMAP3,
MENU_JOYDIGMAP4,
MENU_JOYRESET,
MENU_JOYRESET1,
MENU_JOYKBDMAP,
MENU_JOYKBDMAP1,
MENU_KBDMAP,
MENU_KBDMAP1,
MENU_BTPAIR,
MENU_BTPAIR2,
MENU_LGCAL,
MENU_LGCAL1,
MENU_LGCAL2,
MENU_SCRIPTS_PRE,
MENU_SCRIPTS_PRE1,
MENU_SCRIPTS,
MENU_SCRIPTS1,
MENU_SCRIPTS_FB,
MENU_SCRIPTS_FB2,
MENU_DOC_FILE_SELECTED,
MENU_DOC_FILE_SELECTED_2,
MENU_CHEATS1,
MENU_CHEATS2,
MENU_UART1,
MENU_UART2,
MENU_UART3,
MENU_UART4,
MENU_BAUD1,
MENU_BAUD2,
MENU_SFONT_FILE_SELECTED,
MENU_VIDEOPROC1,
MENU_VIDEOPROC2,
MENU_COEFF_FILE_SELECTED,
MENU_GAMMA_FILE_SELECTED,
MENU_SMASK_FILE_SELECTED,
MENU_PRESET_FILE_SELECTED,
MENU_AFILTER_FILE_SELECTED,
// Generic
MENU_GENERIC_MAIN1,
MENU_GENERIC_MAIN2,
MENU_GENERIC_FILE_SELECTED,
MENU_GENERIC_IMAGE_SELECTED,
MENU_GENERIC_SAVE_WAIT,
// Arcade
MENU_ARCADE_DIP1,
MENU_ARCADE_DIP2,
// Minimig
MENU_MINIMIG_MAIN1,
MENU_MINIMIG_MAIN2,
MENU_MINIMIG_VIDEO1,
MENU_MINIMIG_VIDEO2,
MENU_MINIMIG_CHIPSET1,
MENU_MINIMIG_CHIPSET2,
MENU_MINIMIG_DISK1,
MENU_MINIMIG_DISK2,
MENU_MINIMIG_HDFFILE_SELECTED,
MENU_MINIMIG_ADFFILE_SELECTED,
MENU_MINIMIG_ROMFILE_SELECTED,
MENU_MINIMIG_LOADCONFIG1,
MENU_MINIMIG_LOADCONFIG2,
MENU_MINIMIG_SAVECONFIG1,
MENU_MINIMIG_SAVECONFIG2,
// Atari ST
MENU_ST_MAIN1,
MENU_ST_MAIN2,
MENU_ST_SYSTEM1,
MENU_ST_SYSTEM2,
MENU_ST_FDD_FILE_SELECTED,
MENU_ST_HDD_FILE_SELECTED,
MENU_ST_SYSTEM_FILE_SELECTED,
MENU_ST_LOAD_CONFIG1,
MENU_ST_LOAD_CONFIG2,
MENU_ST_SAVE_CONFIG1,
MENU_ST_SAVE_CONFIG2,
// Archie
MENU_ARCHIE_MAIN1,
MENU_ARCHIE_MAIN2,
MENU_ARCHIE_MAIN_FILE_SELECTED,
// MT32-pi
MENU_MT32PI_MAIN1,
MENU_MT32PI_MAIN2,
};
static uint32_t menustate = MENU_NONE1;
static uint32_t parentstate;
static uint32_t menusub = 0;
static uint32_t menusub_last = 0; //for when we allocate it dynamically and need to know last row
static uint64_t menumask = 0; // Used to determine which rows are selectable...
static uint32_t menu_timer = 0;
static uint32_t menu_save_timer = 0;
static uint32_t load_addr = 0;
static int32_t bt_timer = 0;
extern const char *version;
const char *config_tos_wrprot[] = { "None", "A:", "B:", "A: and B:" };
const char *config_scanlines_msg[] = { "Off", "HQ2x", "CRT 25%" , "CRT 50%" , "CRT 75%" };
const char *config_blank_msg[] = { "Blank", "Blank+" };
const char *config_dither_msg[] = { "off", "SPT", "RND", "S+R" };
const char *config_autofire_msg[] = { " AUTOFIRE OFF", " AUTOFIRE FAST", " AUTOFIRE MEDIUM", " AUTOFIRE SLOW" };
const char *config_cd32pad_msg[] = { "OFF", "ON" };
const char *config_button_turbo_msg[] = { "OFF", "FAST", "MEDIUM", "SLOW" };
const char *config_button_turbo_choice_msg[] = { "A only", "B only", "A & B" };
const char *joy_button_map[] = { "RIGHT", "LEFT", "DOWN", "UP", "BUTTON A", "BUTTON B", "BUTTON X", "BUTTON Y", "BUTTON L", "BUTTON R", "SELECT", "START", "KBD TOGGLE", "MENU", " Stick 1: Tilt RIGHT", " Stick 1: Tilt DOWN", " Mouse emu X: Tilt RIGHT", " Mouse emu Y: Tilt DOWN" };
const char *joy_ana_map[] = { " DPAD test: Press RIGHT", " DPAD test: Press DOWN", " Stick 1 Test: Tilt RIGHT", " Stick 1 Test: Tilt DOWN", " Stick 2 Test: Tilt RIGHT", " Stick 2 Test: Tilt DOWN" };
const char *config_stereo_msg[] = { "0%", "25%", "50%", "100%" };
const char *config_uart_msg[] = { " None", " PPP", " Console", " MIDI", " Modem"};
const char *config_midilink_mode[] = {"Local", "Local", " USB", " UDP", "-----", "-----", " USB" };
const char *config_afilter_msg[] = { "Internal","Custom" };
const char *config_smask_msg[] = { "None", "1x", "2x", "1x Rotated", "2x Rotated" };
const char *config_scale[] = { "Normal", "V-Integer", "HV-Integer-", "HV-Integer+", "HV-Integer", "???", "???", "???" };
#define DPAD_NAMES 4
#define DPAD_BUTTON_NAMES 12 //DPAD_NAMES + 6 buttons + start/select
#define script_line_length 1024
#define script_lines 50
static FILE *script_pipe;
static int script_file;
static char script_command[script_line_length];
static int script_line;
static char script_output[script_lines][script_line_length];
static char script_line_output[script_line_length];
static bool script_finished;
// one screen width
static const char* HELPTEXT_SPACER = " ";
static char helptext_custom[1024];
enum HelpText_Message
{
HELPTEXT_NONE, HELPTEXT_CUSTOM, HELPTEXT_MAIN, HELPTEXT_HARDFILE, HELPTEXT_CHIPSET, HELPTEXT_MEMORY, HELPTEXT_EJECT, HELPTEXT_CLEAR
};
static const char *helptexts[] =
{
0,
helptext_custom,
" Welcome to MiSTer! Use the cursor keys to navigate the menus. Use space bar or enter to select an item. Press Esc or F12 to exit the menus. Joystick emulation on the numeric keypad can be toggled with the numlock or scrlock key, while pressing Ctrl-Alt-0 (numeric keypad) toggles autofire mode.",
" Minimig can emulate an A600/A1200 IDE harddisk interface. The emulation can make use of Minimig-style hardfiles (complete disk images) or UAE-style hardfiles (filesystem images with no partition table).",
" Minimig's processor core can emulate a 68000 (cycle accuracy as A500/A600) or 68020 (maximum performance) processor with transparent cache.",
" Minimig can make use of up to 2 megabytes of Chip RAM, up to 1.5 megabytes of Slow RAM (A500 Trapdoor RAM), and up to 384 megabytes of Fast RAM (8MB max for 68000 mode). To use the HRTmon feature you will need a file on the SD card named hrtmon.rom.",
" Backspace key (or B-hold + A on gamepad) to unmount",
" Backspace key (or B-hold + A on gamepad) to clear stored option. You have to reload the core to be able to use default value.",
};
static const uint32_t helptext_timeouts[] =
{
10000,
10000,
10000,
10000,
10000,
10000,
2000,
2000
};
static const char *info_top = "\x80\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x82";
static const char *info_bottom = "\x85\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x84";
// file selection menu variables
static char fs_pFileExt[13] = "xxx";
static uint32_t fs_ExtLen = 0;
static uint32_t fs_Options;
static uint32_t fs_MenuSelect;
static uint32_t fs_MenuCancel;
static char* GetExt(char *ext)
{
static char extlist[32];
char *p = extlist;
while (*ext) {
strcpy(p, ",");
strncat(p, ext, 3);
while (*(p + strlen(p) - 1) == ' ') *(p + strlen(p) - 1) = 0;
if (strlen(ext) <= 3) break;
ext += 3;
p += strlen(p);
}
return extlist + 1;
}
static char SelectedDir[1024] = {};
static char SelectedLabel[1024] = {};
static char Selected_F[16][1024] = {};
static char Selected_S[16][1024] = {};
static char Selected_tmp[1024] = {};
void StoreIdx_F(int idx, const char *path)
{
strcpy(Selected_F[idx], path);
}
void StoreIdx_S(int idx, const char *path)
{
strcpy(Selected_S[idx], path);
}
static char selPath[1024] = {};
static int changeDir(char *dir)
{
char curdir[128];
memset(curdir, 0, sizeof(curdir));
if(!dir || !strcmp(dir, ".."))
{
if (!strlen(selPath))
{
return 0;
}
char *p = strrchr(selPath, '/');
if (p)
{
*p = 0;
strncpy(curdir, p + 1, sizeof(curdir) - 1);
}
else
{
strncpy(curdir, selPath, sizeof(curdir) - 1);
selPath[0] = 0;
}
}
else
{
if (strlen(selPath) + strlen(dir) > sizeof(selPath) - 100)
{
return 0;
}
if (strlen(selPath)) strcat(selPath, "/");
strcat(selPath, dir);
}
ScanDirectory(selPath, SCANF_INIT, fs_pFileExt, fs_Options);
if(curdir[0])
{
ScanDirectory(selPath, SCANF_SET_ITEM, curdir, fs_Options);
}
return 1;
}
static const char *home_dir = NULL;
static char filter[256] = {};
static unsigned long filter_typing_timer = 0;
// this function displays file selection menu
void SelectFile(const char* path, const char* pFileExt, int Options, unsigned char MenuSelect, unsigned char MenuCancel)
{
static char tmp[1024];
printf("pFileExt = %s\n", pFileExt);
filter_typing_timer = 0;
filter[0] = 0;
strncpy(selPath, path, sizeof(selPath) - 1);
selPath[sizeof(selPath) - 1] = 0;
if (Options & SCANO_CORES)
{
strcpy(selPath, get_rbf_dir());
if (strlen(get_rbf_name()))
{
if(strlen(selPath)) strcat(selPath, "/");
strcat(selPath, get_rbf_name());
}
pFileExt = "RBFMRAMGL";
home_dir = NULL;
}
else if (Options & SCANO_TXT)
{
if(pFileExt == 0) pFileExt = "TXT";
home_dir = NULL;
}
else
{
const char *home = is_menu() ? "Scripts" : user_io_get_core_path((is_pce() && !strncasecmp(pFileExt, "CUE", 3)) ? PCECD_DIR : NULL, 1);
home_dir = strrchr(home, '/');
if (home_dir) home_dir++;
else home_dir = home;
if (Options & SCANO_SAVES)
{
snprintf(tmp, sizeof(tmp), "%s/%s", SAVE_DIR, CoreName);
home = tmp;
}
if (strncasecmp(home, selPath, strlen(home)) || !strcasecmp(home, selPath) || (!FileExists(selPath) && !PathIsDir(selPath)))
{
Options &= ~SCANO_NOENTER;
strcpy(selPath, home);
}
}
ScanDirectory(selPath, SCANF_INIT, pFileExt, Options);
AdjustDirectory(selPath);
strcpy(fs_pFileExt, pFileExt);
fs_ExtLen = strlen(fs_pFileExt);
fs_Options = Options & ~SCANO_NOENTER;
fs_MenuSelect = MenuSelect;
fs_MenuCancel = MenuCancel;
menustate = MENU_FILE_SELECT1;
}
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);
}
#define STD_EXIT " exit"
#define STD_BACK " back"
#define STD_SPACE_EXIT " SPACE to exit"
#define STD_COMBO_EXIT " Ctrl+ESC to exit"
int getOptIdx(char *opt)
{
if ((opt[1] >= '0') && (opt[1] <= '9')) return opt[1] - '0';
if ((opt[1] >= 'A') && (opt[1] <= 'V')) return opt[1] - 'A' + 10;
return 0; // basically 0 cannot be valid because used as a reset. Thus can be used as a error.
}
uint32_t getStatus(char *opt, uint32_t status)
{
char idx1 = getOptIdx(opt);
char idx2 = getOptIdx(opt + 1);
uint32_t x = (status & (1 << idx1)) ? 1 : 0;
if (idx2>idx1) {
x = status >> idx1;
x = x & ~(0xffffffff << (idx2 - idx1 + 1));
}
return x;
}
uint32_t setStatus(char *opt, uint32_t status, uint32_t value)
{
unsigned char idx1 = getOptIdx(opt);
unsigned char idx2 = getOptIdx(opt + 1);
uint32_t x = 1;
if (idx2>idx1) x = ~(0xffffffff << (idx2 - idx1 + 1));
x = x << idx1;
return (status & ~x) | ((value << idx1) & x);
}
uint32_t getStatusMask(char *opt)
{
char idx1 = getOptIdx(opt);
char idx2 = getOptIdx(opt + 1);
uint32_t x = 1;
if (idx2 > idx1) x = ~(0xffffffff << (idx2 - idx1 + 1));
return x;
}
// conversion table of Amiga keyboard scan codes to ASCII codes
static const uint8_t keycode_table[128] =
{
0,'1','2','3','4','5','6','7','8','9','0', 0, 0, 0, 0, 0,
'Q','W','E','R','T','Y','U','I','O','P', 0, 0, 0, 0, 0, 0,
'A','S','D','F','G','H','J','K','L', 0, 0, 0, 0, 0, 0, 0,
0,'Z','X','C','V','B','N','M', 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
static uint8_t GetASCIIKey(uint32_t keycode)
{
if (keycode & UPSTROKE)
return 0;
return keycode_table[get_amiga_code(keycode & 0xFFFF) & 0x7F];
}
/* the Atari core handles OSD keys competely inside the core */
static uint32_t menu_key = 0;
void menu_key_set(unsigned int c)
{
//printf("OSD enqueue: %x\n", c);
menu_key = c;
}
// get key status
static int hold_cnt = 0;
static uint32_t menu_key_get(void)
{
static uint32_t prev_key = 0;
static unsigned long db_time = 0;
if (prev_key != menu_key || !db_time)
{
prev_key = menu_key;
db_time = GetTimer(20);
}
uint32_t c = 0;
if (CheckTimer(db_time))
{
static uint32_t c2;
static unsigned long repeat;
uint32_t c1;
c1 = menu_key;
c = 0;
if (c1 != c2)
{
c = c1;
hold_cnt = 1;
}
c2 = c1;
// generate repeat "key-pressed" events
if ((c1 & UPSTROKE) || (!c1))
{
hold_cnt = 0;
repeat = GetTimer(REPEATDELAY);
}
else if (CheckTimer(repeat))
{
repeat = GetTimer(REPEATRATE);
if (GetASCIIKey(c1) || ((menustate == MENU_COMMON2) && (menusub == 15)) || ((menustate == MENU_SYSTEM2) && (menusub == 4)))
{
c = c1;
hold_cnt++;
}
}
}
// currently no key pressed
if (!c)
{
static unsigned long longpress = 0, longpress_consumed = 0;
static unsigned char last_but = 0;
unsigned char but = user_io_menu_button();
if (but && !last_but) longpress = GetTimer(3000);
if (but && CheckTimer(longpress) && !longpress_consumed)
{
longpress_consumed = 1;
if (menustate == MENU_SCRIPTS1) c = KEY_BACKSPACE;
else menustate = MENU_BTPAIR;
}
if (!but && last_but && !longpress_consumed) c = KEY_F12;
if (!but) longpress_consumed = 0;
last_but = but;
}
if (!c)
{
static unsigned long longpress = 0, longpress_consumed = 0;
static unsigned char last_but = 0;
unsigned char but = user_io_user_button();
if (user_io_osd_is_visible())
{
if (but && !last_but) longpress = GetTimer(1500);
if (but && CheckTimer(longpress) && !longpress_consumed)
{
longpress_consumed = 1;
if (is_menu())
{
if (menustate == MENU_SYSTEM2 || menustate == MENU_FILE_SELECT2) menustate = MENU_JOYSYSMAP;
}
else if (get_map_vid() || get_map_pid())
{
menustate = MENU_JOYRESET;
}
}
if (!but && last_but && !longpress_consumed)
{
if (get_map_vid() || get_map_pid())
{
send_map_cmd(KEY_ALTERASE);
}
}
}
if (!but) longpress_consumed = 0;
last_but = but;
}
return(c);
}
static char* getNet(int spec)
{
int netType = 0;
struct ifaddrs *ifaddr, *ifa, *ifae = 0, *ifaw = 0;
static char host[NI_MAXHOST];
if (getifaddrs(&ifaddr) == -1)
{
printf("getifaddrs: error\n");
return NULL;
}
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
{
if (ifa->ifa_addr == NULL) continue;
if (!memcmp(ifa->ifa_addr->sa_data, "\x00\x00\xa9\xfe", 4)) continue; // 169.254.x.x
if ((strcmp(ifa->ifa_name, "eth0") == 0) && (ifa->ifa_addr->sa_family == AF_INET)) ifae = ifa;
if ((strncmp(ifa->ifa_name, "wlan", 4) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) ifaw = ifa;
}
ifa = 0;
netType = 0;
if (ifae && (!spec || spec == 1))
{
ifa = ifae;
netType = 1;
}
if (ifaw && (!spec || spec == 2))
{
ifa = ifaw;
netType = 2;
}
if (spec && ifa)
{
strcpy(host, "IP: ");
getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host + strlen(host), NI_MAXHOST - strlen(host), NULL, 0, NI_NUMERICHOST);
}
freeifaddrs(ifaddr);
return spec ? (ifa ? host : 0) : (char*)netType;
}
static long sysinfo_timer;
static void infowrite(int pos, const char* txt)
{
char str[40];
memset(str, 0x20, 29);
int len = strlen(txt);
if (len > 27) len = 27;
if(len) strncpy(str + 1+ ((27-len)/2), txt, len);
str[0] = 0x83;
str[28] = 0x83;
str[29] = 0;
OsdWrite(pos, str, 0, 0);
}
static void printSysInfo()
{
if (!sysinfo_timer || CheckTimer(sysinfo_timer))
{
sysinfo_timer = GetTimer(2000);
struct battery_data_t bat;
int hasbat = getBattery(0, &bat);
int n = 2;
char str[40];
OsdWrite(n++, info_top, 0, 0);
int j = 0;
char *net;
net = getNet(1);
if (net)
{
sprintf(str, "\x1c %s", net);
infowrite(n++, str);
j++;
}
net = getNet(2);
if (net)
{
sprintf(str, "\x1d %s", net);
infowrite(n++, str);
j++;
}
if (!j) infowrite(n++, "No network");
if (j<2) infowrite(n++, "");
if (hasbat)
{
infowrite(n++, "");
sprintf(str, "\x1F ");
if (bat.capacity == -1) strcat(str, "n/a");
else sprintf(str + strlen(str), "%d%%", bat.capacity);
if (bat.current != -1) sprintf(str + strlen(str), " %dmAh", bat.current);
if (bat.voltage != -1) sprintf(str + strlen(str), " %d.%dV", bat.voltage / 1000, (bat.voltage / 100) % 10);
infowrite(n++, str);
str[0] = 0;
if (bat.load_current > 0)
{
sprintf(str + strlen(str), " \x12 %dmA", bat.load_current);
if (bat.time != -1)
{
if (bat.time < 90) sprintf(str + strlen(str), ", ETA: %dm", bat.time);
else sprintf(str + strlen(str), ", ETA: %dh%02dm", bat.time / 60, bat.time % 60);
}
}
else if (bat.load_current < -1)
{
sprintf(str + strlen(str), " \x13 %dmA", -bat.load_current);
if (bat.time != -1)
{
if (bat.time < 90) sprintf(str + strlen(str), ", ETA: %dm", bat.time);
else sprintf(str + strlen(str), ", ETA: %dh%02dm", bat.time / 60, bat.time % 60);
}
}
else
{
strcat(str, "Not charging");
}
infowrite(n++, str);
}
else
{
infowrite(n++, "");
video_core_description(str, 40);
infowrite(n++, str);
video_scaler_description(str, 40);
infowrite(n++, str);
}
OsdWrite(n++, info_bottom, 0, 0);
}
}
static int firstmenu = 0;
static int adjvisible;
static void MenuWrite(unsigned char n, const char *s = "", unsigned char invert = 0, unsigned char stipple = 0, int arrow = 0)
{
int row = n - firstmenu;
if (row < 0)
{
if (invert) adjvisible = row;
return;
}
if (row >= OsdGetSize())
{
if (invert) adjvisible = row - OsdGetSize() + 1;
return;
}
OsdSetArrow(arrow);
OsdWriteOffset(row, s, invert, stipple, 0, (row == 0 && firstmenu) ? 17 : (row == (OsdGetSize()-1) && !arrow) ? 16 : 0, 0);
}
const char* get_rbf_name_bootcore(char *str)
{
if (!strlen(cfg.bootcore)) return "";
char *p = strrchr(str, '/');
if (!p) return str;
char *spl = strrchr(p + 1, '.');
if (spl && (!strcmp(spl, ".rbf") || !strcmp(spl, ".mra") || !strcmp(spl, ".mgl")))
{
*spl = 0;
}
else
{
return NULL;
}
return p + 1;
}
static void vga_nag()
{
if (video_fb_state())
{
EnableOsd_on(OSD_VGA);
OsdSetSize(16);
OsdSetTitle("Information");
int n = 0;
OsdWrite(n++);
OsdWrite(n++);
OsdWrite(n++);
OsdWrite(n++);
OsdWrite(n++, " If you see this, then you");
OsdWrite(n++, " need to modify MiSTer.ini");
OsdWrite(n++);
OsdWrite(n++, " Either disable framebuffer:");
OsdWrite(n++, " fb_terminal=0");
OsdWrite(n++);
OsdWrite(n++, " or enable scaler on VGA:");
OsdWrite(n++, " vga_scaler=1");
for (; n < OsdGetSize(); n++) OsdWrite(n);
OsdUpdate();
OsdEnable(OSD_MSG);
EnableOsd_on(OSD_HDMI);
}
OsdDisable();
EnableOsd_on(OSD_ALL);
}
void process_addon(char *ext, uint8_t idx)
{
static char name[1024];
while (*ext && *ext != ',') ext++;
if (*ext) ext++;
if (!*ext) return;
printf("addons: %s\n", ext);
int i = 0;
while (1)
{
char *fname = name;
strcpy(name, selPath);
char *p = strrchr(name, '.');
if (!p) p = name + strlen(name);
*p++ = '.';
substrcpy(p, ext, i);
if (!strlen(p)) return;
if (*p == '!')
{
*p = 0;
char *bs = strrchr(name, '/');
if (!bs)
{
fname = p + 1;
}
else
{
strcpy(bs + 1, p + 1);
}
}
printf("Trying: %s\n", fname);
user_io_file_tx_a(fname, ((i+1) << 8) | idx);
i++;
}
}
static int get_arc(const char *str)
{
int arc = 0;
if (!strcmp(str, "[ARC1]")) arc = 1;
else if(!strcmp(str, "[ARC2]")) arc = 2;
else return 0;
uint32_t x = 0, y = 0;
if (sscanf(cfg.custom_aspect_ratio[arc - 1], "%u:%u", &x, &y) != 2 || x < 1 || x > 4095 || y < 1 || y > 4095) arc = -1;
return arc;
}
static int get_ar_name(int ar, char *str)
{
switch (ar)
{
case 0:
strcat(str, "Original");
break;
case 1:
strcat(str, "Full Screen");
break;
case 2:
if (get_arc("[ARC1]") <= 0)
{
strcat(str, "Original");
ar = 0;
}
else
{
strcat(str, cfg.custom_aspect_ratio[0]);
}
break;
case 3:
if (get_arc("[ARC2]") <= 0)
{
strcat(str, "Original");
ar = 0;
}
else
{
strcat(str, cfg.custom_aspect_ratio[1]);
}
break;
}
return ar;
}
static int next_ar(int ar, int minus)
{
if (minus)
{
ar = (ar - 1) & 3;
while (1)
{
if (ar == 3 && get_arc("[ARC2]") > 0 && get_arc("[ARC1]") > 0) break;
if (ar == 2 && get_arc("[ARC1]") > 0) break;
if (ar < 2) break;
ar--;
}
}
else
{
ar = (ar + 1) & 3;
if (ar == 3 && get_arc("[ARC2]") <= 0) ar = 0;
if (ar == 2 && get_arc("[ARC1]") <= 0) ar = 0;
}
return ar;
}
static int joymap_first = 0;
static int gun_x = 0;
static int gun_y = 0;
static int gun_ok = 0;
static int gun_side = 0;
static int gun_idx = 0;
static int32_t gun_pos[4] = {};
static int page = 0;
void HandleUI(void)
{
if (bt_timer >= 0)
{
if (!bt_timer) bt_timer = (int32_t)GetTimer(6000);
else if (CheckTimer((uint32_t)bt_timer))
{
bt_timer = -1;
if (hci_get_route(0) < 0)
{
// Some BT dongles get stuck after boot.
// Kicking of USB port usually make it work.
printf("*** reset bt ***\n");
system("/bin/bluetoothd hcireset &");
}
}
}
switch (user_io_core_type())
{
case CORE_TYPE_8BIT:
case CORE_TYPE_SHARPMZ:
break;
default:
// No UI in unknown cores.
return;
}
static char opensave;
static char ioctl_index;
char *p;
static char s[256];
unsigned char m = 0, up, down, select, menu, back, right, left, plus, minus, recent;
char enable;
static int reboot_req = 0;
static uint32_t helptext_timer;
static int helptext_idx = 0;