forked from MiSTer-devel/Main_MiSTer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.cpp
4643 lines (4100 loc) · 113 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 "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 "bootcore.h"
#include "cheats.h"
#include "video.h"
#include "support.h"
unsigned char iso_mode = 0;
/*menu states*/
enum MENU
{
MENU_NONE1,
MENU_NONE2,
MENU_MAIN1,
MENU_MAIN2,
MENU_FILE_SELECT1,
MENU_FILE_SELECT2,
MENU_FILE_SELECTED,
MENU_RESET1,
MENU_RESET2,
MENU_RECONF1,
MENU_RECONF2,
MENU_SETTINGS1,
MENU_SETTINGS2,
MENU_ROMFILE_SELECTED,
MENU_SETTINGS_VIDEO1,
MENU_SETTINGS_VIDEO2,
MENU_SETTINGS_MEMORY1,
MENU_SETTINGS_MEMORY2,
MENU_SETTINGS_CHIPSET1,
MENU_SETTINGS_CHIPSET2,
MENU_SETTINGS_DRIVES1,
MENU_SETTINGS_DRIVES2,
MENU_SETTINGS_HARDFILE1,
MENU_SETTINGS_HARDFILE2,
MENU_HARDFILE_SELECT1,
MENU_HARDFILE_SELECT2,
MENU_HARDFILE_SELECTED,
MENU_HARDFILE_SELECTED2,
MENU_HARDFILE_SELECTED3,
MENU_LOADCONFIG_1,
MENU_LOADCONFIG_2,
MENU_SAVECONFIG_1,
MENU_SAVECONFIG_2,
MENU_SYSTEM1,
MENU_SYSTEM2,
MENU_CORE_FILE_SELECTED1,
MENU_CORE_FILE_SELECTED2,
MENU_CORE_FILE_CANCELED,
MENU_ERROR,
MENU_INFO,
MENU_JOYDIGMAP,
MENU_JOYDIGMAP1,
MENU_JOYDIGMAP2,
MENU_JOYDIGMAP3,
MENU_JOYDIGMAP4,
MENU_JOYKBDMAP,
MENU_JOYKBDMAP1,
MENU_KBDMAP,
MENU_KBDMAP1,
MENU_SCRIPTS_PRE,
MENU_SCRIPTS_PRE1,
MENU_SCRIPTS,
MENU_SCRIPTS1,
MENU_SCRIPTS_FB,
MENU_SCRIPTS_FB2,
MENU_BTPAIR,
MENU_WMPAIR,
MENU_WMPAIR1,
MENU_LGCAL,
MENU_LGCAL1,
MENU_LGCAL2,
MENU_CHEATS1,
MENU_CHEATS2,
// Mist/atari specific pages
MENU_MIST_MAIN1,
MENU_MIST_MAIN2,
MENU_MIST_MAIN_FILE_SELECTED,
MENU_MIST_STORAGE1,
MENU_MIST_STORAGE2,
MENU_MIST_STORAGE_FILE_SELECTED,
MENU_MIST_SYSTEM1,
MENU_MIST_SYSTEM2,
MENU_MIST_SYSTEM_FILE_SELECTED,
MENU_MIST_VIDEO1,
MENU_MIST_VIDEO2,
MENU_MIST_VIDEO_ADJUST1,
MENU_MIST_VIDEO_ADJUST2,
// archimedes menu entries
MENU_ARCHIE_MAIN1,
MENU_ARCHIE_MAIN2,
MENU_ARCHIE_MAIN_FILE_SELECTED,
MENU_UART1,
MENU_UART2,
// 8bit menu entries
MENU_8BIT_MAIN1,
MENU_8BIT_MAIN2,
MENU_8BIT_MAIN_FILE_SELECTED,
MENU_8BIT_MAIN_IMAGE_SELECTED,
MENU_8BIT_SYSTEM1,
MENU_8BIT_SYSTEM2,
MENU_COEFF_FILE_SELECTED,
MENU_8BIT_INFO,
MENU_8BIT_INFO2,
MENU_8BIT_ABOUT1,
MENU_8BIT_ABOUT2
};
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 uint32_t menumask = 0; // Used to determine which rows are selectable...
static uint32_t menu_timer = 0;
extern const char *version;
const char *config_tos_mem[] = { "512 kB", "1 MB", "2 MB", "4 MB", "8 MB", "14 MB", "--", "--" };
const char *config_tos_wrprot[] = { "none", "A:", "B:", "A: and B:" };
const char *config_tos_usb[] = { "none", "control", "debug", "serial", "parallel", "midi" };
const char *config_memory_chip_msg[] = { "512K", "1M", "1.5M", "2M" };
const char *config_memory_slow_msg[] = { "none", "512K", "1M", "1.5M" };
const char *config_memory_fast_msg[] = { "none", "2M", "4M", "24M" };
const char *config_scanlines_msg[] = { "off", "dim", "black" };
const char *config_ar_msg[] = { "4:3", "16:9" };
const char *config_blank_msg[] = { "Blank", "Blank+" };
const char *config_dither_msg[] = { "off", "SPT", "RND", "S+R" };
const char *config_cpu_msg[] = { "68000", "68010", "-----","68020" };
const char *config_chipset_msg[] = { "OCS-A500", "OCS-A1000", "ECS", "---", "---", "---", "AGA", "---" };
const char *config_turbo_msg[] = { "none", "CHIPRAM", "KICK", "BOTH" };
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 1", "BUTTON 2", "BUTTON 3", "BUTTON 4", "KBD TOGGLE", "MENU", " Stick X: Tilt RIGHT", " Stick Y: 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: Tilt RIGHT", " Stick 1: Tilt DOWN", " Stick 2: Tilt RIGHT", " Stick 2: Tilt DOWN" };
const char *config_stereo_msg[] = { "0%", "25%", "50%", "100%" };
const char *config_uart_msg[] = { " None", " PPP", " Console", " MIDI" };
const char *config_scaler_msg[] = { "Internal","Custom" };
char joy_bnames[32][32];
int joy_bcount = 0;
#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_exited;
enum HelpText_Message { HELPTEXT_NONE, HELPTEXT_MAIN, HELPTEXT_HARDFILE, HELPTEXT_CHIPSET, HELPTEXT_MEMORY, HELPTEXT_VIDEO };
static const char *helptexts[] =
{
0,
" 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 or 68020 processor (though the 68020 mode is still experimental.) If you're running software built for 68000, there's no advantage to using the 68020 mode, since the 68000 emulation runs just as fast.",
" 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 24 megabytes of true Fast RAM. To use the HRTmon feature you will need a file on the SD card named hrtmon.rom.",
" Minimig's video features include a blur filter, to simulate the poorer picture quality on older monitors, and also scanline generation to simulate the appearance of a screen with low vertical resolution.",
0
};
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";
// one screen width
static const char* HELPTEXT_SPACER = " ";
static char helptext_custom[1024];
const char* scanlines[] = { "Off","25%","50%","75%" };
const char* stereo[] = { "Mono","Stereo" };
const char* atari_chipset[] = { "ST","STE","MegaSTE","STEroids" };
// 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 SelectedRBF[1024] = { 0 };
static char SelectedDir[1024] = { 0 };
static char SelectedPath[1024] = { 0 };
static int changeDir(char *dir)
{
char curdir[128];
memset(curdir, 0, sizeof(curdir));
if(!dir || !strcmp(dir, ".."))
{
if (!strlen(SelectedPath))
{
return 0;
}
char *p = strrchr(SelectedPath, '/');
if (p)
{
*p = 0;
uint32_t len = strlen(p+1);
if (len > sizeof(curdir) - 1) len = sizeof(curdir) - 1;
strncpy(curdir, p+1, len);
}
else
{
uint32_t len = strlen(SelectedPath);
if (len > sizeof(curdir) - 1) len = sizeof(curdir) - 1;
strncpy(curdir, SelectedPath, len);
SelectedPath[0] = 0;
}
}
else
{
if (strlen(SelectedPath) + strlen(dir) > sizeof(SelectedPath) - 100)
{
return 0;
}
if (strlen(SelectedPath)) strcat(SelectedPath, "/");
strcat(SelectedPath, dir);
}
ScanDirectory(SelectedPath, SCANF_INIT, fs_pFileExt, fs_Options);
if(curdir[0])
{
ScanDirectory(SelectedPath, SCANF_SET_ITEM, curdir, fs_Options);
}
return 1;
}
// this function displays file selection menu
static void SelectFile(const char* pFileExt, unsigned char Options, unsigned char MenuSelect, unsigned char MenuCancel)
{
printf("pFileExt = %s\n", pFileExt);
if (Options & SCANO_CORES)
{
strcpy(SelectedPath, get_rbf_dir());
if (strlen(get_rbf_name()))
{
strcat(SelectedPath, "/");
strcat(SelectedPath, get_rbf_name());
}
pFileExt = "RBF";
}
else if (Options & SCANO_COEFF)
{
pFileExt = "TXT";
}
else
{
if (strncasecmp(HomeDir, SelectedPath, strlen(HomeDir))) strcpy(SelectedPath, HomeDir);
}
ScanDirectory(SelectedPath, SCANF_INIT, pFileExt, Options);
if (!flist_nDirEntries())
{
SelectedPath[0] = 0;
ScanDirectory(SelectedPath, SCANF_INIT, pFileExt, Options);
}
AdjustDirectory(SelectedPath);
strcpy(fs_pFileExt, pFileExt);
fs_ExtLen = strlen(fs_pFileExt);
fs_Options = Options;
fs_MenuSelect = MenuSelect;
fs_MenuCancel = MenuCancel;
menustate = MENU_FILE_SELECT1;
}
void substrcpy(char *d, char *s, char idx)
{
char p = 0;
while (*s) {
if ((p == idx) && *s && (*s != ','))
*d++ = *s;
if (*s == ',')
p++;
s++;
}
*d = 0;
}
#define STD_EXIT " exit"
#define STD_SPACE_EXIT " SPACE to exit"
#define STD_COMBO_EXIT " Ctrl+ESC to exit"
#define HELPTEXT_DELAY 10000
#define FRAME_DELAY 150
static unsigned char getIdx(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 = getIdx(opt);
char idx2 = getIdx(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 = getIdx(opt);
unsigned char idx2 = getIdx(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 = getIdx(opt);
char idx2 = getIdx(opt + 1);
uint32_t x = 1;
if (idx2>idx1) x = ~(0xffffffff << (idx2 - idx1 + 1));
//printf("grtStatusMask %d %d %x\n", idx1, idx2, x);
return x << idx1;
}
// 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 c2;
static unsigned long repeat;
uint32_t c1, c;
c1 = menu_key;
c = 0;
if (c1 != c2)
{
c = c1;
hold_cnt = 1;
}
c2 = c1;
// inject a fake "MENU_KEY" if no menu is visible and the menu key is loaded
if (!user_io_osd_is_visible() && !video_fb_state() && is_menu_core()) c = KEY_F12;
// 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_8BIT_SYSTEM2) && (menusub == 9)))
{
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;
menustate = MENU_BTPAIR;
}
if (!but && last_but && !longpress_consumed) c = KEY_F12;
if (!but) longpress_consumed = 0;
last_but = but;
}
return(c);
}
static int has_bt()
{
FILE *fp;
static char out[1035];
fp = popen("hcitool dev | grep hci0", "r");
if (!fp) return 0;
int ret = 0;
while (fgets(out, sizeof(out) - 1, fp) != NULL)
{
if (strlen(out)) ret = 1;
}
pclose(fp);
return ret;
}
static int toggle_wminput()
{
if (access("/bin/wminput", F_OK) < 0 || access("/media/fat/linux/wiimote.cfg", F_OK) < 0) return -1;
FILE *fp;
static char out[1035];
fp = popen("pidof wminput", "r");
if (!fp) return -1;
int ret = -1;
if (fgets(out, sizeof(out) - 1, fp) != NULL)
{
if (strlen(out))
{
system("killall wminput");
ret = 0;
}
}
else
{
system("taskset 1 wminput --daemon --config /media/fat/linux/wiimote.cfg &");
ret = 1;
}
pclose(fp);
return ret;
}
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 = is_menu_core() ? 10 : 5;
char str[40];
OsdWrite(n++, info_top, 0, 0);
if (!hasbat)
{
infowrite(n++, "");
}
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)
{
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++, "");
}
OsdWrite(n++, info_bottom, 0, 0);
}
}
static int firstmenu = 0;
static int adjvisible;
static char lastrow[256];
static void MenuWrite(unsigned char n, const char *s, unsigned char invert, 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;
}
if (row == (OsdGetSize() - 1))
{
int len = strlen(s);
if (len > 255) len = 255;
memcpy(lastrow, s, len);
lastrow[len] = 0;
}
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"))
{
*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);
OsdEnable(0);
EnableOsd_on(OSD_HDMI);
}
OsdDisable();
EnableOsd_on(OSD_ALL);
}
static int joymap_first = 0;
static int wm_x = 0;
static int wm_y = 0;
static int wm_ok = 0;
static int wm_side = 0;
static uint16_t wm_pos[4] = {};
void HandleUI(void)
{
switch (user_io_core_type())
{
case CORE_TYPE_MIST:
case CORE_TYPE_MINIMIG2:
case CORE_TYPE_8BIT:
case CORE_TYPE_SHARPMZ:
case CORE_TYPE_ARCHIE:
break;
default:
// No UI in unknown cores.
return;
}
struct RigidDiskBlock *rdb = nullptr;
static char opensave;
char *p;
static char s[256];
unsigned char m = 0, up, down, select, menu, right, left, plus, minus;
char enable;
static int reboot_req = 0;
static long helptext_timer;
static const char *helptext;
static char helpstate = 0;
static char drive_num = 0;
static char flag;
static int cr = 0;
static uint32_t cheatsub = 0;
static uint8_t card_cid[32];
static uint32_t hdmask = 0;
static pid_t ttypid = 0;
static int has_fb_terminal = 0;
static char cp_MenuCancel;
// get user control codes
uint32_t c = menu_key_get();
// decode and set events
menu = false;
select = false;
up = false;
down = false;
left = false;
right = false;
plus = false;
minus = false;
if (c && c != KEY_F12 && cfg.bootcore[0] != '\0') cfg.bootcore[0] = '\0';
if (is_menu_core())
{
static int menu_visible = 1;
static unsigned long timeout = 0;
if (!video_fb_state() && cfg.fb_terminal)
{
if (timeout && CheckTimer(timeout))
{
timeout = 0;
if (menu_visible > 0)
{
menu_visible = 0;
video_menu_bg((user_io_8bit_set_status(0, 0) & 0xE) >> 1, 1);
spi_osd_cmd(MM1_OSDCMDDISABLE);
}
else if (!menu_visible)
{
menu_visible--;
video_menu_bg((user_io_8bit_set_status(0, 0) & 0xE) >> 1, 2);
}
}
if (c || menustate != MENU_FILE_SELECT2)
{
timeout = 0;
if (menu_visible <= 0)
{
c = 0;
menu_visible = 1;
video_menu_bg((user_io_8bit_set_status(0, 0) & 0xE) >> 1);
spi_osd_cmd(MM1_OSDCMDWRITE | 8);
spi_osd_cmd(MM1_OSDCMDENABLE);
}
}
if (!timeout)
{
if (!cfg.osd_timeout) cfg.osd_timeout = 30;
timeout = GetTimer(cfg.osd_timeout * 1000);
}
}
else
{
timeout = 0;
menu_visible = 1;
}
}
//prevent OSD control while script is executing on framebuffer
if (!video_fb_state() || video_chvt(0) != 2)
{
switch (c)
{
case KEY_F12:
menu = true;
menu_key_set(KEY_F12 | UPSTROKE);
video_fb_enable(0);
break;
case KEY_F1:
if (is_menu_core() && cfg.fb_terminal)
{
unsigned long status = (user_io_8bit_set_status(0, 0)+ 2) & 0xE;
user_io_8bit_set_status(status, 0xE);
FileSaveConfig(user_io_create_config_name(), &status, 4);
video_menu_bg(status >> 1);
}
break;
case KEY_F11:
if (user_io_osd_is_visible())
{
menustate = MENU_BTPAIR;
}
break;
case KEY_F10:
if (user_io_osd_is_visible() && !access("/bin/wminput", F_OK))
{
menustate = MENU_WMPAIR;
}
else if (input_has_lightgun())
{
menustate = MENU_LGCAL;
}
break;
case KEY_F9:
if ((is_menu_core() || ((get_key_mod() & (LALT | RALT)) && (get_key_mod() & (LCTRL | RCTRL))) || has_fb_terminal) && cfg.fb_terminal)
{
video_chvt(1);
video_fb_enable(!video_fb_state());
if (video_fb_state())
{
menustate = MENU_NONE1;
has_fb_terminal = 1;
}
}
break;
// Within the menu the esc key acts as the menu key. problem:
// if the menu is left with a press of ESC, then the follwing
// break code for the ESC key when the key is released will
// reach the core which never saw the make code. Simple solution:
// react on break code instead of make code
case KEY_ESC | UPSTROKE:
if (menustate != MENU_NONE2) menu = true;
break;
case KEY_ENTER:
case KEY_SPACE:
select = true;
break;
case KEY_UP:
up = true;
break;
case KEY_DOWN:
down = true;
break;
case KEY_LEFT:
left = true;
break;
case KEY_RIGHT:
right = true;
break;
case KEY_KPPLUS:
case KEY_EQUAL: // =/+
plus = true;
break;
case KEY_KPMINUS:
case KEY_MINUS: // -/_
minus = true;
break;
}
}
if (menu || select || up || down || left || right)
{
if (helpstate) OsdWrite(OsdGetSize()-1, STD_EXIT, (menumask - ((1 << (menusub + 1)) - 1)) <= 0, 0); // Redraw the Exit line...
helpstate = 0;
helptext_timer = GetTimer(HELPTEXT_DELAY);
}
if (helptext)
{
if (helpstate<9)
{
if (CheckTimer(helptext_timer))
{
helptext_timer = GetTimer(FRAME_DELAY);
OsdWriteOffset(OsdGetSize() - 1, (menustate == MENU_8BIT_MAIN2) ? lastrow : STD_EXIT, 0, 0, helpstate, 0);
++helpstate;
}
}
else if (helpstate == 9)
{
ScrollReset();
++helpstate;
}
else
{
ScrollText(OsdGetSize() - 1, helptext, 0, 0, 0, 0);
}
}
// Standardised menu up/down.