forked from hpingel/Sidekick64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path264screen.cpp
1364 lines (1179 loc) · 39.9 KB
/
264screen.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
/*
_________.__ .___ __ .__ __ ________ ________ _____
/ _____/|__| __| _/____ | | _|__| ____ | | __ \_____ \/ _____/ / | |
\_____ \ | |/ __ |/ __ \| |/ / |/ ___\| |/ / / ____/ __ \ / | |_
/ \| / /_/ \ ___/| <| \ \___| < / \ |__\ \/ ^ /
/_______ /|__\____ |\___ >__|_ \__|\___ >__|_ \ \_______ \_____ /\____ |
\/ \/ \/ \/ \/ \/ \/ \/ |__|
264screen.cpp
RasPiC64 - A framework for interfacing the C64 (and C16/+4) and a Raspberry Pi 3B/3B+
- menu/screen code
Copyright (c) 2019, 2020 Carsten Dachsbacher <frenetic@dachsbacher.de>
Logo created with http://patorjk.com/software/taag/
This program 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.
This program 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/>.
*/
// this file contains unelegant code for generating the menu screens
// and handling key presses forwarded from the C64
#include "linux/kernel.h"
#include "c64screen.h"
#include "lowlevel_arm64.h"
#include "dirscan.h"
#include "264config.h"
#include "crt.h"
#include "kernel_menu264.h"
#define KEY_AT 64
#define KEY_F1 133
#define KEY_F4 138
#define KEY_F2 137
#define KEY_F5 135
#define KEY_F3 134
#define KEY_F6 139
#define KEY_HELP 140
#define KEY_F7 136
extern CLogger *logger;
#ifdef WITH_NET
extern CSidekickNet * pSidekickNet;
#include "circle/version.h"
#endif
// todo
extern u32 prgSizeLaunch;
//extern unsigned char prgDataLaunch[ 65536 ];
//increasing size of prgDataLaunch so that we
//can either store a prg or a crt in it
//unsigned char prgDataLaunch[ 65536 ] AAA;
extern unsigned char prgDataLaunch[ 1027*1024 ] AAA;
static const char DRIVE[] = "SD:";
static const char SETTINGS_FILE[] = "SD:C16/special.cfg";
u8 c64screen[ 40 * 25 + 1024 * 4 ];
u8 c64color[ 40 * 25 + 1024 * 4 ];
boolean errorSticky = false;
char *errorMsg = NULL;
char errorMessages[5][41] = {
// 1234567890123456789012345678901234567890
" NO ERROR ",
" ERROR: UNKNOWN/UNSUPPORTED .CRT TYPE ",
" ERROR: NO .CRT-FILE ",
" ERROR READING FILE ",
" SETTINGS SAVED "
};
#define MENU_MAIN 0x00
#define MENU_BROWSER 0x01
#define MENU_ERROR 0x02
#define MENU_CONFIG 0x03
#ifdef WITH_NET
#define MENU_NETWORK 0x04
#define MENU_SKTP 0x05
#define MENU_SYSTEMINFO 0x06
#endif
u32 menuScreen = 0,
previousMenuScreen = 0;
u32 updateMenu = 1;
u32 typeInName = 0;
u32 typeCurPos = 0;
int cursorPos = 0;
int scrollPos = 0;
int lastLine;
int lastRolled = -1;
int lastSubIndex = -1;
int subGeoRAM = 0;
int subSID = 0;
int subHasKernal = -1;
int subHasLaunch = -1;
void clearC64()
{
memset( c64screen, ' ', 40 * 25 );
memset( c64color, 0, 40 * 25 );
}
u8 PETSCII2ScreenCode( u8 c )
{
if ( c < 32 ) return c + 128;
if ( c < 64 ) return c;
if ( c < 96 ) return c - 64;
if ( c < 128 ) return c - 32;
if ( c < 160 ) return c + 64;
if ( c < 192 ) return c - 64;
return c - 128;
}
void printC64( u32 x, u32 y, const char *t, u8 color, u8 flag, u32 convert, u32 maxL )
{
u32 l = min( strlen( t ), maxL );
for ( u32 i = 0; i < l; i++ )
{
u32 c = t[ i ], c2 = c;
// screen code conversion
if ( convert == 1 )
{
c2 = PETSCII2ScreenCode( c );
} else
{
if ( convert == 2 && c >= 'a' && c <= 'z' )
c = c + 'A' - 'a';
if ( convert == 3 && c >= 'A' && c <= 'Z' )
c = c + 'a' - 'A';
if ( ( c >= 'a' ) && ( c <= 'z' ) )
c2 = c + 1 - 'a';
}
c64screen[ x + y * 40 + i ] = c2 | flag;
c64color[ x + y * 40 + i ] = color;
}
}
int printFileTree( s32 cursorPos, s32 scrollPos )
{
s32 lines = 0;
s32 idx = scrollPos;
s32 lastVisible = 0;
while ( lines < DISPLAY_LINES && idx < nDirEntries )
{
if ( idx >= nDirEntries )
break;
u32 convert = 3;
u8 color = skinValues.SKIN_TEXT_BROWSER;
if ( dir[ idx ].f & DIR_DIRECTORY || dir[ idx ].f & DIR_D64_FILE )
color = skinValues.SKIN_TEXT_BROWSER_DIRECTORY;
if ( dir[ idx ].f & DIR_FILE_IN_D64 )
convert = 1;
if ( idx == cursorPos )
color = skinValues.SKIN_TEXT_BROWSER_CURRENT;
char temp[1024], t2[ 1024 ] = {0};
memset( t2, 0, 1024 );
if( dir[ idx ].level > 0 )
{
for ( u32 j = 0; j < dir[ idx ].level - 1; j++ )
strcat( t2, " " );
if ( convert != 3 )
t2[ dir[ idx ].level - 1 ] = 93+32; else
t2[ dir[ idx ].level - 1 ] = 93;
}
sprintf( temp, "%s%s", t2, dir[ idx ].name );
if ( strlen( temp ) > 34 )
temp[ 35 ] = 0;
printC64( 2, lines + 3, temp, color, idx == cursorPos ? 0x80 : 0, convert );
lastVisible = idx;
if ( dir[ idx ].f & DIR_DIRECTORY || dir[ idx ].f & DIR_D64_FILE )
{
if ( !(dir[ idx ].f & DIR_UNROLLED) )
idx = dir[ idx ].next; else
idx ++;
} else
idx ++;
lines ++;
}
return lastVisible;
}
void printBrowserScreen()
{
clearC64();
//printC64(0,0, "0123456789012345678901234567890123456789", 15, 0 );
printC64( 0, 1, " .- sidekick264 browser -. ", skinValues.SKIN_MENU_TEXT_HEADER, 0 );
printC64( 0, 23, " F1/F2 Page Up/Down, HELP Back to Menu ", skinValues.SKIN_BROWSER_TEXT_HEADER, 0, 3 );
if ( subGeoRAM )
{
printC64( 0, 24, " choose PRG w/ NeoRAM to start ", skinValues.SKIN_BROWSER_TEXT_FOOTER, 0, 3 );
printC64( 13, 24, "PRG w/ NeoRAM", skinValues.SKIN_BROWSER_TEXT_FOOTER_HIGHLIGHTED, 0, 3 );
} else
if ( subSID )
{
printC64( 0, 24, " choose PRG w/ SID+FM to start ", skinValues.SKIN_BROWSER_TEXT_FOOTER, 0, 3 );
printC64( 13, 24, "PRG w/ SID+FM", skinValues.SKIN_BROWSER_TEXT_FOOTER_HIGHLIGHTED, 0, 3 );
}
lastLine = printFileTree( cursorPos, scrollPos );
// scroll bar
int t = scrollPos * DISPLAY_LINES / nDirEntries;
int b = lastLine * DISPLAY_LINES / nDirEntries;
// bar on the right
for ( int i = 0; i < DISPLAY_LINES; i++ )
{
char c = 102;
if ( t <= i && i <= b )
c = 96 + 128;
c64screen[ 38 + ( i + 3 ) * 40 ] = c;
c64color[ 38 + ( i + 3 ) * 40 ] = 1;
}
c64screen[ 1000 ] = ((0x6000 >> 8) & 0xFC);
c64screen[ 1001 ] = skinValues.SKIN_BROWSER_BACKGROUND_COLOR;
c64screen[ 1002 ] = skinValues.SKIN_BROWSER_BORDER_COLOR;
/*startInjectCode();
// charset address
injectPOKE( 0xff13, ((0x6000 >> 8) & 0xFC) );
injectPOKE( 0xff15, skinValues.SKIN_BROWSER_BACKGROUND_COLOR );
injectPOKE( 0xff19, skinValues.SKIN_BROWSER_BORDER_COLOR );*/
}
void resetMenuState( int keep = 0 )
{
if ( !( keep & 1 ) ) subGeoRAM = 0;
if ( !( keep & 2 ) ) subSID = 0;
subHasKernal = -1;
subHasLaunch = -1;
}
int getMainMenuSelection( int key, char **FILE, char **FILE2, int *addIdx )
{
*FILE = NULL;
if ( key >= 'a' && key <= 'z' )
key = key + 'A' - 'a';
if ( key == KEY_F7 ) { resetMenuState(0); return 1;/* Exit */ } else
if ( key == KEY_HELP ) { resetMenuState(3); return 2;/* Browser */ } else
if ( key == KEY_F1 ) { resetMenuState(1); return 3;/* GEORAM */ } else
if ( key == KEY_F2 ) { resetMenuState(2); return 4;/* SID */ } else
#ifdef WITH_NET
if ( key == KEY_AT ) { resetMenuState(4); return 5;/* Network */ } else //hp: don't have a clue about these numbers here
#endif
{
if ( key >= 'A' && key < 'A' + menuItems[ 1 ] ) // PRG
{
int i = key - 'A';
*FILE = menuFile[ 1 ][ i ];
//logger->Write( "RaspiMenu", LogNotice, "getselection: %s -> %s\n", menuText[ 1 ][ i ], menuFile[ 1 ][ i ] );
return 6;
} else
if ( key >= '1' && key < '1' + menuItems[ 2 ] ) // CRT
{
resetMenuState();
int i = key - '1';
*FILE = menuFile[ 2 ][ i ];
*FILE2 = menuFile2[ 2 ][ i ];
//logger->Write( "RaspiMenu", LogNotice, "%s -> %s + %s\n", menuText[ 2 ][ i ], menuFile[ 2 ][ i ], menuFile2[ 2 ][ i ] );
return 5;
}
}
return 0;
}
extern void deactivateCart();
#define MAX_SETTINGS 16
u32 curSettingsLine = 0;
s32 rangeSettings[ MAX_SETTINGS ] = { 4, 10, 3, 2, 16, 15, 4, 2, 16, 15, 2, 2, 16, 15, 16, 16 };
s32 settings[ MAX_SETTINGS ] = { 0, 0, 0, 0, 15, 0, 0, 0, 15, 14, 0, 0, 15, 7, 15, 15 };
u8 geoRAM_SlotNames[ 10 ][ 21 ];
void writeSettingsFile()
{
char cfg[ 16384 ];
u32 cfgBytes = 0;
memset( cfg, 0, 16384 );
cfgBytes = sizeof( s32 ) * MAX_SETTINGS;
memcpy( cfg, settings, cfgBytes );
memcpy( &cfg[ cfgBytes ], geoRAM_SlotNames, sizeof( u8 ) * 10 * 21 );
cfgBytes += sizeof( u8 ) * 10 * 21;
writeFile( logger, DRIVE, SETTINGS_FILE, (u8*)cfg, cfgBytes );
}
void readSettingsFile()
{
char cfg[ 16384 ];
u32 cfgBytes;
memset( cfg, 0, 16384 );
memset( settings, 0, sizeof( s32 ) * MAX_SETTINGS );
memset( geoRAM_SlotNames, 32, sizeof( u8 ) * 10 * 21 );
if ( !readFile( logger, DRIVE, SETTINGS_FILE, (u8*)cfg, &cfgBytes ) )
writeSettingsFile();
memcpy( settings, cfg, sizeof( s32 ) * MAX_SETTINGS );
memcpy( geoRAM_SlotNames, &cfg[ sizeof( s32 ) * MAX_SETTINGS ], sizeof( u8 ) * 10 * 21 );
}
void applySIDSettings()
{
// how elegant...
extern void setSIDConfiguration( u32 mode, u32 sid1, u32 sid2, u32 sid2addr, u32 rr, u32 addr, u32 exp, s32 v1, s32 p1, s32 v2, s32 p2, s32 v3, s32 p3, s32 digiblasterVol, s32 sidfreq, s32 tedVol );
setSIDConfiguration( 0, settings[2], settings[6], settings[7]-1, settings[3], settings[7], settings[11],
settings[4], settings[5], settings[8], settings[9], settings[12], settings[13], settings[14], settings[10], settings[15] );
}
// ugly, hard-coded handling of UI
void handleC64( int k, u32 *launchKernel, char *FILENAME, char *filenameKernal )
{
char *filename, *filename2;
if ( menuScreen == MENU_MAIN )
{
if ( k == KEY_HELP )
{
menuScreen = MENU_BROWSER;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
if ( k == KEY_F3 )
{
menuScreen = MENU_CONFIG;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
#ifdef WITH_NET
//entering the network menu via at
if ( k == KEY_AT )
{
menuScreen = MENU_NETWORK;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
#endif
int temp;
int r = getMainMenuSelection( k, &filename, &filename2, &temp );
if ( subSID == 1 )
{
if ( k == 27 )
{
resetMenuState();
subHasLaunch = -1;
subSID = 0;
return;
}
// start
if ( ( r == 4 ) || ( k == 13 ) )
{
FILENAME[ 0 ] = 0;
*launchKernel = 8;
return;
}
}
if ( subGeoRAM == 1 )
{
if ( k == 27 )
{
resetMenuState();
subHasKernal = -1;
subHasLaunch = -1;
subGeoRAM = 0;
return;
}
//
if ( r == 7 ) // kernal selected
{
strcpy( filenameKernal, filename );
return;
}
// start
if ( ( ( r == 3 ) || ( k == 13 ) ) )
{
*launchKernel = 3;
return;
}
}
switch ( r )
{
case 1: // exit to basic
deactivateCart();
return;
case 2: // Browser
break;
case 3: // GeoRAM
subGeoRAM = 1;
subSID = 0;
return;
case 4: // SID+FM
subSID = 1;
subGeoRAM = 0;
return;
case 5: // .CRT file
*launchKernel = 5;
errorMsg = NULL;
strncpy( &FILENAME[0], filename, 2047 );
if ( strcmp( filename2, "none" ) == 0 )
FILENAME[2048] = 0; else
strncpy( &FILENAME[2048], filename2, 2047 );
return;
case 6: // .PRG file
strcpy( FILENAME, filename );
*launchKernel = 4;
return;
}
} else
if ( menuScreen == MENU_BROWSER )
{
// browser screen
if ( k == KEY_HELP )
{
menuScreen = MENU_MAIN;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
int rep = 1;
if ( k == KEY_F2 ) { k = 17; rep = DISPLAY_LINES - 1; }
if ( k == KEY_F1 ) { k = 145; rep = DISPLAY_LINES - 1; }
for ( int i = 0; i < rep; i++ )
{
// left
if ( k == 157 ||
( ( dir[ cursorPos ].f & DIR_DIRECTORY || dir[ cursorPos ].f & DIR_D64_FILE ) && k == 13 && (dir[ cursorPos ].f & DIR_UNROLLED ) ) )
{
if ( dir[ cursorPos ].parent != 0xffffffff )
{
lastSubIndex = cursorPos;
lastRolled = cursorPos = dir[ cursorPos ].parent;
}
if ( !( dir[ cursorPos ].f & DIR_UNROLLED ) )
k = 145;
if ( dir[ cursorPos ].f & DIR_DIRECTORY || dir[ cursorPos ].f & DIR_D64_FILE )
dir[ cursorPos ].f &= ~DIR_UNROLLED;
k = 0;
} else
// right
if ( k == 29 ||
( ( dir[ cursorPos ].f & DIR_DIRECTORY || dir[ cursorPos ].f & DIR_D64_FILE ) && k == 13 && !(dir[ cursorPos ].f & DIR_UNROLLED ) ) )
{
if ( dir[ cursorPos ].f & DIR_DIRECTORY || dir[ cursorPos ].f & DIR_D64_FILE )
dir[ cursorPos ].f |= DIR_UNROLLED;
if ( cursorPos == lastRolled )
cursorPos = lastSubIndex; else
if ( cursorPos < nDirEntries - 1 )
cursorPos ++;
lastRolled = -1;
k = 0;
} else
// down
if ( k == 17 )
{
if ( dir[ cursorPos ].f & DIR_DIRECTORY || dir[ cursorPos ].f & DIR_D64_FILE )
{
if ( dir[ cursorPos ].f & DIR_UNROLLED )
cursorPos ++; else
{
if ( (s32)dir[ cursorPos ].next < nDirEntries )
cursorPos = dir[ cursorPos ].next;
}
} else
cursorPos ++;
} else
// up
if ( k == 145 )
{
cursorPos --;
if ( cursorPos < 0 ) cursorPos = 0;
// current item has parent(s) -> check if they are unrolled
int c = cursorPos;
while ( c >= 0 && dir[ c ].parent != 0xffffffff )
{
c = dir[ c ].parent;
if ( c >= 0 && c < nDirEntries && ( dir[ c ].f & DIR_DIRECTORY || dir[ c ].f & DIR_D64_FILE ) && !(dir[ c ].f & DIR_UNROLLED) )
cursorPos = c;
}
}
if ( cursorPos < 0 ) cursorPos = 0;
if ( cursorPos >= nDirEntries ) cursorPos = nDirEntries - 1;
// scrollPos decrease
if ( cursorPos < scrollPos )
{
scrollPos --;
if ( scrollPos < 0 ) scrollPos = 0;
if ( dir[ scrollPos ].parent != 0xffffffff && !(dir[ dir[ scrollPos ].parent ].f & DIR_UNROLLED) )
scrollPos = dir[ scrollPos ].parent;
}
// scrollPos increase
if ( cursorPos > lastLine )
{
if ( dir[ scrollPos ].f & DIR_DIRECTORY || dir[ scrollPos ].f & DIR_D64_FILE )
{
if ( dir[ scrollPos ].f & DIR_UNROLLED )
scrollPos ++; else
scrollPos = dir[ scrollPos ].next;
} else
scrollPos ++;
}
if ( scrollPos < 0 ) scrollPos = 0;
if ( scrollPos >= nDirEntries ) scrollPos = nDirEntries - 1;
}
if ( k == 13 )
{
// build path
char path[ 8192 ] = {0};
char d64file[ 32 ] = {0};
s32 n = 0, c = cursorPos;
u32 fileIndex = 0xffffffff;
u32 nodes[ 256 ];
nodes[ n ++ ] = c;
s32 curC = c;
if ( (dir[ c ].f & DIR_FILE_IN_D64 && ((dir[ c ].f>>SHIFT_TYPE)&7) == 2) || dir[ c ].f & DIR_PRG_FILE || dir[ c ].f & DIR_CRT_FILE )
{
while ( dir[ c ].parent != 0xffffffff )
{
c = nodes[ n ++ ] = dir[ c ].parent;
}
int stopPath = 0;
if ( dir[ cursorPos ].f & DIR_FILE_IN_D64 )
{
strcpy( d64file, (char*)&dir[ cursorPos ].name[128] );
fileIndex = dir[ cursorPos ].f & ((1<<SHIFT_TYPE)-1);
stopPath = 1;
}
strcat( path, "SD:" );
for ( s32 i = n - 1; i >= stopPath; i -- )
{
if ( i != n-1 )
strcat( path, "\\" );
strcat( path, (char*)dir[ nodes[i] ].name );
}
if ( dir[ curC ].f & DIR_PRG_FILE )
{
strcpy( FILENAME, path );
*launchKernel = 4;
return;
}
if ( dir[ curC ].f & DIR_FILE_IN_D64 )
{
extern u8 d64buf[ 1024 * 1024 ];
extern int readD64File( CLogger *logger, const char *DRIVE, const char *FILENAME, u8 *data, u32 *size );
u32 imgsize = 0;
#ifndef WITH_NET
// mount file system
FATFS m_FileSystem;
if ( f_mount( &m_FileSystem, DRIVE, 1 ) != FR_OK )
logger->Write( "RaspiMenu", LogPanic, "Cannot mount drive: %s", DRIVE );
#endif
if ( !readD64File( logger, "", path, d64buf, &imgsize ) )
return;
#ifndef WITH_NET
// unmount file system
if ( f_mount( 0, DRIVE, 0 ) != FR_OK )
logger->Write( "RaspiMenu", LogPanic, "Cannot unmount drive: %s", DRIVE );
#endif
if ( d64ParseExtract( d64buf, imgsize, D64_GET_FILE + fileIndex, prgDataLaunch, (s32*)&prgSizeLaunch ) == 0 )
{
strcpy( FILENAME, path );
logger->Write( "RaspiMenu", LogNotice, "loaded: %d bytes", prgSizeLaunch );
*launchKernel = 40;
}
return;
}
}
}
} else
#ifdef WITH_NET
if ( menuScreen == MENU_NETWORK )
{
//keypress handling while inside of open menu
if ( k == KEY_F7 )
{
menuScreen = MENU_MAIN;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
if ( k == 42 ) // star
{
if (pSidekickNet->IsRunning() && strcmp(netSktpHostName,"") != 0)
{
pSidekickNet->enteringSktpScreen();
pSidekickNet->redrawSktpScreen();
menuScreen = MENU_SKTP;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
}
if ( k == 'w' || k == 'W')
{
if (pSidekickNet->IsRunning() && !netEnableWebserver)
{
netEnableWebserver = true;
}
}
else if ( k == 's' || k == 'S')
{
//if (pSidekickNet->IsRunning())
{
menuScreen = MENU_SYSTEMINFO;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
}
else if ( k == 'c' || k == 'C')
{
if (!pSidekickNet->IsRunning())
{
pSidekickNet->queueNetworkInit();
clearErrorMsg();
setErrorMsg( pSidekickNet->getNetworkActionStatusMessage() );
}
}
/*
else if ( k == 'q' || k == 'Q')
{
pSidekickNet->requestReboot();
}
*/
//get rid of this after implementing a proper error msg dialog
/*
else if ( k == 'd' || k == 'D')
{
if ( errorMsg != NULL ) errorMsg = NULL;
if (pSidekickNet->IsRunning() && menuScreen == MENU_SKTP)
{
pSidekickNet->redrawSktpScreen();
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
}*/
} else
if ( menuScreen == MENU_SKTP )
{
if ( k == KEY_F7 )
{
pSidekickNet->leavingSktpScreen();
menuScreen = MENU_MAIN;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
/*
else if ( k == 'n' || k == 'N')
{
//only needed temporarily for testing purposes
pSidekickNet->resetSktpSession();
}
else if ( k == 'd' || k == 'D')
{
//http errors might be displayed on top of sktp screen
//this assignment is a cheap trick to get rid of error popups
if ( errorMsg != NULL ) errorMsg = NULL;
}
else if (k == 92 )
{
//92 is pound key, this key is constantly sent by the rpimenu_net.prg
//automatically if the user doesn't press a key on the Commodore keyboard
pSidekickNet->queueSktpRefresh( 8 );
}*/
else
{
//the user has actually manually pressed a key on the Commodore keyboard
//and it is not the pound key which is reserved to enable
//constant screen refresh
pSidekickNet->queueSktpKeypress(k);
}
} else
if ( menuScreen == MENU_SYSTEMINFO )
{
if ( k == KEY_F7)
{
menuScreen = MENU_MAIN;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
} else
#endif
if ( menuScreen == MENU_CONFIG )
{
if ( k == KEY_HELP )
{
menuScreen = MENU_BROWSER;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
if ( k == KEY_F3 )
{
menuScreen = MENU_MAIN;
handleC64( 0xffffffff, launchKernel, FILENAME, filenameKernal );
return;
}
if ( ( ( k == 'n' || k == 'N' ) || ( k == 13 && curSettingsLine == 1 ) )&& typeInName == 0 )
{
typeInName = 1;
// currently selected georam slot is 'settings[ 1 ]'
typeCurPos = 0;
while ( typeCurPos < 19 && geoRAM_SlotNames[ settings[ 1 ] ][ typeCurPos ] != 0 ) typeCurPos ++;
} else
if ( typeInName == 1 )
{
int key = k;
if ( key >= 'a' && key <= 'z' )
key = key + 'A' - 'a';
switch ( k )
{
case 13:
typeInName = 0;
break;
case 157:
if ( typeCurPos > 0 )
typeCurPos --;
break;
case 20:
if ( typeCurPos > 0 )
typeCurPos --;
geoRAM_SlotNames[ settings[ 1 ] ][ typeCurPos ] = 32;
break;
case 29:
if ( typeCurPos < 18 )
typeCurPos ++;
break;
default:
// normal character
geoRAM_SlotNames[ settings[ 1 ] ][ typeCurPos ] = k;
if ( typeCurPos < 17 )
typeCurPos ++;
break;
}
} else
// left
if ( k == 157 )
{
settings[ curSettingsLine ] --;
//+= rangeSettings[ curSettingsLine ] - 1;
if ( settings[ curSettingsLine ] < 0 )
settings[ curSettingsLine ] = rangeSettings[ curSettingsLine ] - 1; else
settings[ curSettingsLine ] = max( 0, settings[ curSettingsLine ] );
if ( rangeSettings[ curSettingsLine ] < 15 )
{
settings[ curSettingsLine ] %= rangeSettings[ curSettingsLine ];
} else
settings[ curSettingsLine ] = max( 0, settings[ curSettingsLine ] );
} else
// right
if ( k == 29 )
{
settings[ curSettingsLine ] ++;
if ( rangeSettings[ curSettingsLine ] < 15 )
settings[ curSettingsLine ] %= rangeSettings[ curSettingsLine ]; else
settings[ curSettingsLine ] = min( settings[ curSettingsLine ], rangeSettings[ curSettingsLine ] - 1 );
} else
// down
if ( k == 17 )
{
curSettingsLine ++;
curSettingsLine %= MAX_SETTINGS;
} else
// up
if ( k == 145 )
{
if ( curSettingsLine == 0 )
curSettingsLine = MAX_SETTINGS - 1; else
curSettingsLine --;
}
if( (k == 's' || k == 'S') && typeInName == 0 )
{
writeSettingsFile();
errorMsg = errorMessages[ 4 ];
previousMenuScreen = menuScreen;
menuScreen = MENU_ERROR;
}
applySIDSettings();
} else
{
menuScreen = previousMenuScreen;
}
}
extern int subGeoRAM, subSID, subHasKernal;
void printSidekickLogo()
{
if ( skinFontLoaded )
{
u32 a = 91;
for ( u32 j = 0; j < 4; j++ )
for ( u32 i = 0; i < 7; i++ )
{
c64screen[ i + 33 + j * 40 ] = (a++);
c64color[ i + 33 + j * 40 ] = j < 2 ? skinValues.SKIN_MENU_TEXT_ITEM : skinValues.SKIN_MENU_TEXT_KEY;
}
}
}
void printMainMenu()
{
clearC64();
// "012345678901234567890123456789012345XXXX"
printC64( 0, 1, " .- Sidekick264 - Frenetic -. ", skinValues.SKIN_MENU_TEXT_HEADER, 0 );
extern u8 c64screen[ 40 * 25 + 1024 * 4 ];
if ( subGeoRAM )
{
printC64( 0, 23, " choose PRG (also via HELP) ", skinValues.SKIN_MENU_TEXT_FOOTER, 0 );
printC64( 0, 24, " ESC back, RETURN/F1 launch ", skinValues.SKIN_MENU_TEXT_FOOTER, 0 );
} else
if ( subSID )
{
printC64( 0, 23, " choose PRG (also via HELP) ", skinValues.SKIN_MENU_TEXT_FOOTER, 0 );
printC64( 0, 24, " ESC back, RETURN/F2 launch ", skinValues.SKIN_MENU_TEXT_FOOTER, 0 );
} else
{
printC64( 0, 23, " HELP Browser, F7 Exit to Basic", skinValues.SKIN_MENU_TEXT_FOOTER, 0 );
}
if ( machine264 & 1 )
printC64( 36, 23, "64KB", skinValues.SKIN_MENU_TEXT_SYSINFO, 0 ); else
printC64( 36, 23, "16KB", skinValues.SKIN_MENU_TEXT_SYSINFO, 0 );
if ( machine264 & 2 )
printC64( 36, 24, "NTSC", skinValues.SKIN_MENU_TEXT_SYSINFO, 0 ); else
printC64( 37, 24, "PAL", skinValues.SKIN_MENU_TEXT_SYSINFO, 0 );
// menu headers + titels
for ( int i = 0; i < CATEGORY_NAMES; i++ )
if ( menuX[ i ] != -1 )
printC64( menuX[ i ], menuY[ i ], categoryNamesPrint[ i ], skinValues.SKIN_MENU_TEXT_CATEGORY, 0 );
for ( int i = 1; i < CATEGORY_NAMES; i++ )
if ( menuX[ i ] != -1 )
for ( int j = 0; j < menuItems[ i ]; j++ )
{
char key[ 2 ] = { 0, 0 };
switch ( i )
{
case 1: key[ 0 ] = 'A' + j; break;
case 2: key[ 0 ] = '1' + j; break;
//case 3: key[ 0 ] = 'A' + j + menuItems[ 2 ]; break;
//case 4: key[ 0 ] = '1' + j + menuItems[ 1 ]; break;
};
int flag = 0;
if ( i == 4 && j == subHasKernal )
flag = 0x80;
printC64( menuItemPos[ i ][ j ][ 0 ], menuItemPos[ i ][ j ][ 1 ], key, skinValues.SKIN_MENU_TEXT_KEY, flag );
printC64( menuItemPos[ i ][ j ][ 0 ] + 2, menuItemPos[ i ][ j ][ 1 ], menuText[ i ][ j ], skinValues.SKIN_MENU_TEXT_ITEM, flag );
}
// special menu
printC64( menuX[ 0 ], menuY[ 0 ]+1, "F1", skinValues.SKIN_MENU_TEXT_KEY, subGeoRAM ? 0x80 : 0 );
printC64( menuX[ 0 ], menuY[ 0 ]+2, "F2", skinValues.SKIN_MENU_TEXT_KEY, subSID ? 0x80 : 0 );
printC64( menuX[ 0 ]+3, menuY[ 0 ]+1, "NeoRAM264 exptl.", skinValues.SKIN_MENU_TEXT_ITEM, subGeoRAM ? 0x80 : 0 );
printC64( menuX[ 0 ]+3, menuY[ 0 ]+2, "SID Emulation", skinValues.SKIN_MENU_TEXT_ITEM, subSID ? 0x80 : 0 );
printC64( menuX[ 0 ], menuY[ 0 ]+3, "F3", skinValues.SKIN_MENU_TEXT_KEY, 0 );
printC64( menuX[ 0 ]+3, menuY[ 0 ]+3, "Settings", skinValues.SKIN_MENU_TEXT_ITEM, 0 );
#ifdef WITH_NET
printC64( menuX[ 0 ], menuY[ 0 ]+4, "\x40", skinValues.SKIN_MENU_TEXT_KEY, 0, 1 );
printC64( menuX[ 0 ]+3, menuY[ 0 ]+4, "Network", skinValues.SKIN_MENU_TEXT_ITEM, 0 );
#endif
printSidekickLogo();
c64screen[ 1000 ] = ((0x6800 >> 8) & 0xFC);
c64screen[ 1001 ] = skinValues.SKIN_MENU_BACKGROUND_COLOR;
c64screen[ 1002 ] = skinValues.SKIN_MENU_BORDER_COLOR;
/* startInjectCode();
// charset address
injectPOKE( 0xff13, ((0x6800 >> 8) & 0xFC) );
injectPOKE( 0xff15, skinValues.SKIN_MENU_BACKGROUND_COLOR );
injectPOKE( 0xff19, skinValues.SKIN_MENU_BORDER_COLOR );*/
}
void settingsGetGEORAMInfo( char *filename, u32 *size )
{
*size = 512 * ( 1 << settings[ 0 ] );
sprintf( filename, "SD:GEORAM/slot%02d.ram", settings[ 1 ] );
}
#ifdef WITH_NET
void printNetworkScreen()
{
clearC64();
// "012345678901234567890123456789012345XXXX"
printC64( 0, 1, " .- Sidekick264 - Frenetic -. ", skinValues.SKIN_MENU_TEXT_HEADER, 0 );
printC64( 0, 23, " F6/F7 Back to Menu ", skinValues.SKIN_MENU_TEXT_HEADER, 0 );
const u32 x = 1;
CString strHostName = "Hostname: ";
CString strConnection = "Connection state: ";
CString strWebserver = "Webserver state: ";
CString strUPModemEmu = "Userport modem emu: ";
CString strModemBaudR = "Default baud rate: ";
CString strHelper;
if (strcmp(netSidekickHostname,"") != 0)
strHostName.Append( netSidekickHostname );
else
strHostName.Append( "sidekick64" );
if (netEnableWebserver)
if ( pSidekickNet->IsRunning() )
strWebserver.Append( "Running" );
else
strWebserver.Append( "Waiting" );
else
strWebserver.Append( "Stopped" );
if ( pSidekickNet->IsRunning() )
{
strConnection.Append( "Active" );
#ifdef WITH_USB_SERIAL
if ( pSidekickNet->isUsbUserportModemConnected() )
strUPModemEmu.Append( "Active" );
else
strUPModemEmu.Append( "No cable detected" );
#else
strUPModemEmu.Append( "No support" );
#endif
}
else
{
strConnection.Append( "Inactive" );
strUPModemEmu.Append( "Inactive" );
}
strModemBaudR.Append( pSidekickNet->getBaudrate() );