/
mount.c
1353 lines (1103 loc) · 36.6 KB
/
mount.c
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
/*
GeoUMount
Disk mounter for the Ultimate II+ in GEOS
Written in 2023 by Xander Mol
https://github.com/xahmol/GeoUTools
https://www.idreamtin8bits.com/
Code and resources from others used:
- Scott Hutter - Ultimate II+ library and GeoUTerm:
https://github.com/xlar54/ultimateii-dos-lib/
(library for the UII+ UCI functions. And GeoUTerm as GEOS sample application using this)
- CC65 cross compiler:
https://cc65.github.io/
- Daniel England (Daniel England) - GEOSBuild:
https://github.com/M3wP/GEOSBuild
(buildtool for GEOS disks)
- David Lee - GEOS Image Editor
https://www.facebook.com/groups/704637082964003/permalink/5839146806179646
(editor for GEOS icons)
- Subchrist Software - SpritePad Pro
https://subchristsoftware.itch.io/spritepad-c64-pro
(editor used for the file icons)
- Hitchhikers Guide to GEOS v2020
Berkeley Softworks / Paul B Murdaugh
https://github.com/geos64128/HG2G2020
- Sample sequential application header of GeoProgrammer
Berkeley Softworks
- ntp2ultimate by MaxPlap: code for obtaining time via NTP
https://github.com/MaxPlap/ntp2ultimate
- Heureks: GEOS64 Programming Examples
https://codeberg.org/heurekus/C64-Geos-Programming
(sample code using C in CC65 for writing applications in GEOS)
- Lyonlabs / Cenbe GEOS resources page:
https://www.lyonlabs.org/commodore/onrequest/geos/index.html
- Bo Zimmerman GEOS resources page:
http://www.zimmers.net/geos/
- CVM Files GEOS disk images
https://cbmfiles.com/geos/geos-13.php
- GEOS - Wheels - GeoWorks - MegaPatch - gateWay - BreadBox Facebook Group
https://www.facebook.com/groups/704637082964003/permalink/5839146806179646
- Bart van Leeuwen for testing and providing the Device Manager ROM and GEOS RAM Boot
- markusC64 (https://github.com/markusC64)
for code rveiew, testiing and adapting UII+ firmware to enableRAM disk functionality.
- mkslack ( https://github.com/mkslack ) for code review and testing
- Forum64.de forum thread for testing and suggestions
( https://www.forum64.de/index.php?thread/133681-news-zur-ultimate-1541-ii-und-geos/ )
- Gideon Zweijtzer for creating the Ultimate II+ cartridge and the Ultimate64, and the Ultimate Command Interface enabling this software.
- Tested using real hardware (C128D, C128DCR, Ultimate 64) using GEOS128 2.0, GEOS64 2.0 and Megapatch3 128.
Licensed under the GNU General Public License v3.0
The code can be used freely as long as you retain
a notice describing original source and author.
THE PROGRAMS ARE DISTRIBUTED IN THE HOPE THAT THEY WILL BE USEFUL,
BUT WITHOUT ANY WARRANTY. USE THEM AT YOUR OWN RISK!
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <geos.h>
#include <peekpoke.h>
//#include <conio.h>
#include "defines.h"
#include "interface.h"
#include "mount_common.h"
#include "ultimate_common_lib.h"
#include "ultimate_dos_lib.h"
// Global variables
char buffer[81];
unsigned char clickflag;
unsigned char reusavesize;
// Directory entry struct
struct DirElement {
unsigned char type; // Type: 1=dir, 2=D64, 3=D71, 4=D81
char filename[21];
struct DirElement* next;
struct DirElement* prev;
};
struct DirElement *presentdirelement;
struct Directory {
struct DirElement* firstelement;
struct DirElement* lastelement;
struct DirElement* firstprint;
struct DirElement* lastprint;
};
struct Directory presentdir;
// Icons
// Select drive icons: two cards wide (16 pxiels) amd 16 lines
char iconA[] = {
0xA0,0xFF,0xFE,0x80,0x03,0x80,0x03,0x81,0x83,0x81,0x83,0x83,0xC3,0x83,0xC3,0x86,
0x63,0x86,0x63,0x8F,0xF3,0x8C,0x33,0x8C,0x33,0x80,0x03,0x80,0x03,0xFF,0xFF,0x7F,
0xFF
};
char iconB[] = {
0xA0,0xFF,0xFE,0x80,0x03,0x80,0x03,0x8F,0xC3,0x8C,0x63,0x8C,0x63,0x8F,0xC3,0x8C,
0x63,0x8C,0x63,0x8C,0x63,0x8C,0x63,0x8F,0xC3,0x80,0x03,0x80,0x03,0xFF,0xFF,0x7F,
0xFF
};
char iconC[] = {
0xA0,0xFF,0xFE,0x80,0x03,0x80,0x03,0x87,0xC3,0x8C,0x63,0x8C,0x03,0x8C,0x03,0x8C,
0x03,0x8C,0x03,0x8C,0x03,0x8C,0x63,0x87,0xC3,0x80,0x03,0x80,0x03,0xFF,0xFF,0x7F,
0xFF
};
char iconD[] = {
0xA0,0xFF,0xFE,0x80,0x03,0x80,0x03,0x8F,0x83,0x8C,0xC3,0x8C,0x63,0x8C,0x63,0x8C,
0x63,0x8C,0x63,0x8C,0x63,0x8C,0xC3,0x8F,0x83,0x80,0x03,0x80,0x03,0xFF,0xFF,0x7F,
0xFF
};
// Scroll arrow icons of 1 card by 8 lines
char iconArrowUp[] = {
0x88,0xFF,0x88,0x9C,0xBE,0x80,0xBE,0x80,0xFF
};
char iconArrowDown[] = {
0x88,0xFF,0x80,0xBE,0x80,0xBE,0x9C,0x88,0xFF
};
// Dir travel icons of 2 cards by 16 lines
char iconBack[] = {
0xA0,0xFF,0xFE,0x80,0x03,0x80,0x03,0x81,0x03,0x83,0x03,0x87,0x03,0x8F,0xF3,0x9F,
0xF3,0x8F,0xF3,0x87,0x03,0x83,0x03,0x81,0x03,0x80,0x03,0x80,0x03,0xFF,0xFF,0x7F,
0xFF
};
char iconRoot[] = {
0xA0,0xFF,0xFE,0x80,0x03,0x80,0x03,0x80,0x33,0x80,0x73,0x80,0xE3,0x81,0xC3,0x83,
0x83,0x87,0x03,0x8E,0x03,0x9C,0x03,0x98,0x03,0x80,0x03,0x80,0x03,0xFF,0xFF,0x7F,
0xFF
};
char iconHome[] = {
0xA0,0xFF,0xFE,0x80,0x03,0x80,0x03,0x81,0x03,0x82,0x83,0x84,0x43,0x88,0x23,0x90,
0x13,0x97,0x53,0x95,0x53,0x95,0x13,0x9F,0xF3,0x80,0x03,0x80,0x03,0xFF,0xFF,0x7F,
0xFF
};
char iconTop[] = {
0x94,0xFF,0xFE,0x80,0x03,0x80,0x03,0x9F,0xF3,0x9F,0xF3,0x80,0x03,0x81,0x03,0x83,
0x83,0x87,0xC3,0x8F,0xE3,0x04,0x83,0x88,0x80,0x03,0x80,0x03,0xFF,0xFF,0x7F,0xFF
};
char iconBottom[] = {
0x86,0xFF,0xFE,0x80,0x03,0x80,0x03,0x04,0x83,0x96,0x8F,0xE3,0x87,0xC3,0x83,0x83,
0x81,0x03,0x80,0x03,0x9F,0xF3,0x9F,0xF3,0x80,0x03,0x80,0x03,0xFF,0xFF,0x7F,0xFF
};
char iconSave[] = {
0xA0,0xFF,0xFE,0x80,0x03,0x80,0x03,0x9F,0xE3,0x97,0x53,0x97,0x53,0x97,0x53,0x97,
0xD3,0x90,0x13,0x97,0xD3,0x98,0x33,0x9F,0xF3,0x80,0x03,0x80,0x03,0xFF,0xFF,0x7F,
0xFF
};
// Declare interface functions
void DriveselectA (void);
void DriveselectB (void);
void DriveselectC (void);
void DriveselectD (void);
void DirBack (void);
void DirRoot (void);
void DirHome (void);
void DirTop (void);
void DirBottom (void);
void SaveImage (void);
void ScrollUp (void);
void ScrollDown (void);
// Interface icontab
struct icontab vic_mainicons = {
12,
{ 0,0 },
{
{ iconA, 28, 50, 2, 16, (int)DriveselectA },
{ iconB, 28, 70, 2, 16, (int)DriveselectB },
{ iconC, 28, 90, 2, 16, (int)DriveselectC },
{ iconD, 28, 110, 2, 16, (int)DriveselectD },
{ iconBack, 28, 130, 2, 16, (int)DirBack },
{ iconRoot, 28, 150, 2, 16, (int)DirRoot },
{ iconHome, 28, 170, 2, 16, (int)DirHome },
{ iconTop, 31, 130, 2, 16, (int)DirTop },
{ iconBottom, 31, 150, 2, 16, (int)DirBottom },
{ iconSave, 31,170, 2, 16,(int)SaveImage},
{ iconArrowUp, 25, 45, 1, 8, (int)ScrollUp },
{ iconArrowDown, 25, 180, 1, 8, (int)ScrollDown }
}
};
struct icontab vdc_mainicons = {
12,
{ 0,0 },
{
{ iconA, 56, 50, 2 | DOUBLE_B, 16, (int)DriveselectA },
{ iconB, 56, 70, 2 | DOUBLE_B, 16, (int)DriveselectB },
{ iconC, 56, 90, 2 | DOUBLE_B, 16, (int)DriveselectC },
{ iconD, 56, 110, 2 | DOUBLE_B, 16, (int)DriveselectD },
{ iconBack, 56, 130, 2 | DOUBLE_B, 16, (int)DirBack },
{ iconRoot, 56, 150, 2 | DOUBLE_B, 16, (int)DirRoot },
{ iconHome, 56, 170, 2 | DOUBLE_B, 16, (int)DirHome },
{ iconTop, 61, 130, 2 | DOUBLE_B, 16, (int)DirTop },
{ iconBottom, 61, 150, 2 | DOUBLE_B, 16, (int)DirBottom },
{ iconSave, 61,170, 2 | DOUBLE_B, 16,(int)SaveImage},
{ iconArrowUp, 49, 45, 1 | DOUBLE_B, 8, (int)ScrollUp },
{ iconArrowDown, 49, 180, 1 | DOUBLE_B, 8, (int)ScrollDown },
}
};
// Interface coords for handling 40 and 80 column
struct intCoords {
unsigned int filelist_xstart;
unsigned int filelist_xend;
unsigned int scroll_xend;
unsigned int righttab_xstart;
};
struct intCoords *interfaceCoords;
struct intCoords vic_intCoords = { 5,200,208,224 };
struct intCoords vdc_intCoords = { 5,392,408,464 };
// Declare functions prototypes that are called when menu items are
// clicked on and are used in the structs that defines the menus below.
void geosSwitch4080(void);
void geosExit (void);
void REUSave0 (void);
void REUSave1 (void);
void REUSave2 (void);
void REUSave3 (void);
void REUSave4 (void);
void REUSave5 (void);
void REUSave6 (void);
void REUSave7 (void);
void informationCredits (void);
// Menu structures with pointers to the menu handlers above
static struct menu menuGEOS = {
// GEOS
{ 15, 15+3*14, 0, 100 },
3 | VERTICAL,
{
{ "Switch 40/80", MENU_ACTION, geosSwitch4080 },
{ "Credits", MENU_ACTION, informationCredits},
{ "Exit", MENU_ACTION, geosExit },
}
};
static struct menu menuREUSave = {
// GEOS
{ 15, 15+8*14, 50, 100 },
8 | VERTICAL,
{
{ "16 MB", MENU_ACTION, REUSave7},
{ "8 MB", MENU_ACTION, REUSave6},
{ "4 MB", MENU_ACTION, REUSave5},
{ "2 MB", MENU_ACTION, REUSave4},
{ "1 MB", MENU_ACTION, REUSave3},
{ "512 KB", MENU_ACTION, REUSave2},
{ "256 KB", MENU_ACTION, REUSave1},
{ "128 KB", MENU_ACTION, REUSave0}
}
};
static struct menu menuMain = {
// Main menu
{ 0, 15, 0, 100 },
2 | HORIZONTAL,
{
{ "GEOS", SUB_MENU, &menuGEOS},
{ "Save REU", SUB_MENU, &menuREUSave}
}
};
// Declare scroll routines
void vdc_write_reg(void);
void vdc_copyline(unsigned char srchi, unsigned char srclo, unsigned char desthi, unsigned char destlo);
// Application routines
void Freedir() {
// Free memory of presently loaded dir
struct DirElement* next = 0;
struct DirElement* present;
present = presentdir.firstelement;
do
{
presentdirelement = present;
next = presentdirelement->next;
free(present);
present = next;
//SetPattern(0);
//SetRectangleCoords(150,186,interfaceCoords->filelist_xstart+1,interfaceCoords->filelist_xend-1);
//Rectangle();
//gotoxy(1,20);
//cprintf("%d %d",present,next);
} while (next);
}
void Readdir() {
// Read present dir of UCI DOS target
struct DirElement* previous = 0;
struct DirElement* present = 0;
unsigned char presenttype;
unsigned char datalength,maxlength;
// Free memory of previous dir if any
if(presentdir.firstelement) { Freedir(); }
// Clear directory values
presentdir.firstelement = 0;
presentdir.firstprint = 0;
presentdir.firstprint = 0;
presentdir.lastprint = 0;
// Initialise reading dir
enableIO();
uii_open_dir();
if(!uii_success()) {
uii_abort();
restoreIO();
return;
}
uii_get_dir();
// Loop while dir data is available or memory is full
while(uii_isdataavailable())
{
// Reset entry type
presenttype = 0;
// Get next dir entry
uii_readdata();
uii_accept();
// Quick fix for when uii_isdataavailable() does not work correctly
// (works for me on GEOS128, not on GEOS64)
// Check on second byte of data that is set 0 in last iteration
// If still zero and not overwritten, no new data is received
// Abort on receiving empty data
//if(!uii_data[1]) {
// uii_abort();
// restoreIO();
// return;
//}
datalength = strlen(uii_data);
// Check if entry is a dir by checking if bit 4 of first byte is set
if(uii_data[0]&0x10) { presenttype=1; }
// Check if file is a matching image type
if(!presenttype && datalength>4) {
// Check for filename extension of a disk image (D64/G64, D71/G71 or D81)
// First check for D or G as first letter of extension after a dot
if( ( uii_data[datalength-4] == '.') &&
( uii_data[datalength-3] == 'd' || uii_data[datalength-3] == 'D' ||
uii_data[datalength-3] == 'g' || uii_data[datalength-3] == 'G' ) ) {
// Check for D64/G64
if( (uii_data[datalength-2] == '6') && (uii_data[datalength-1] == '4') ) {
// Allow D64/G64 on 1541, 1571 and RAM 1541
if (validdrive[targetdrive-1] == 1 ||
validdrive[targetdrive-1] == 2 ||
validdrive[targetdrive-1] == 4) {
presenttype = 2; }
}
// Check for D71/G71
if( (uii_data[datalength-2] == '7') && (uii_data[datalength-1] == '1') ) {
// Allow D71/G71 on 1571 and RAM 1571
if (validdrive[targetdrive-1] == 2 ||
validdrive[targetdrive-1] == 5) {
presenttype = 3; }
}
// Check for D81
if( (uii_data[datalength-2] == '8') && (uii_data[datalength-1] == '1') ) {
// Allow D81 on 1581 and RAM 1581
if (validdrive[targetdrive-1] == 3 ||
validdrive[targetdrive-1] == 6) {
presenttype = 4; }
}
// Check for DNP
if( ((uii_data[datalength-2] == 'n') && (uii_data[datalength-1] == 'p')) ||
((uii_data[datalength-2] == 'N') && (uii_data[datalength-1] == 'P')) ) {
// Allow DNP on RAM DNP
if (validdrive[targetdrive-1] == 7 ) {
presenttype = 5; }
}
}
}
//SetPattern(0);
//SetRectangleCoords(150,186,interfaceCoords->filelist_xstart+1,interfaceCoords->filelist_xend-1);
//Rectangle();
//gotoxy(1,20);
//cprintf("%d %d %d %d %d",presenttype,uii_data[0],uii_data[1],uii_data[2],uii_isdataavailable());
//gotoxy(1,21);
//cprintf("%s",uii_data+1);
if(presenttype) {
// Get file or dir name to buffer
maxlength = datalength-1; // Minus 1 for first attribute byte
if(maxlength>20) {maxlength=20; presenttype=6; } // Truncate for max 20
memset(buffer,0,21);
CopyFString(maxlength,buffer,uii_data+1);
// Allocate memory for dir entry
present = calloc(1, 26);
// Break loop if memory is full
if(!present || _heapmemavail()<MIN_HEAP_SIZE) {
// Abort UCI dir reading
uii_abort();
restoreIO();
return;
}
// Set direntry data
presentdirelement = present;
CopyString(presentdirelement->filename,buffer);
presentdirelement->type = presenttype;
//gotoxy(1,21);
//cprintf("%d %4x %s %s %d",maxlength,present,buffer,presentdirelement->filename,presentdirelement->type);
// Set direntry pointers
presentdir.lastelement = present; // Update dir last element
if(!previous) { presentdir.firstelement = present; presentdir.firstprint = present; previous=present; }
else {
presentdirelement->prev = previous; // Set prev in new entry
presentdirelement = previous; // Load previous element
presentdirelement->next = present; // Set next in this prev element
previous=present; // Update previous pointer
}
//gotoxy(1,22);
//cprintf("%4x %4x %4x %4x",previous,presentdirelement->next,presentdir.firstelement,presentdir.lastelement);
}
// Clear second byte for quick fix on data available test
//uii_data[1]=0;
//cgetc();
}
// Switch out IO again and restore original GEOS state
restoreIO();
}
// Screen functions
void DrawIDandPath(unsigned char refresh) {
// Draw UCI ID and pathname. Clear previous if refresh flag set
unsigned int maxlength = interfaceCoords->scroll_xend-11;
unsigned char maxchar, nowchar;
// Clear previous text if refresh flag is set
if(refresh)
{
SetPattern(0);
SetRectangleCoords(21,44,interfaceCoords->filelist_xstart+1,interfaceCoords->scroll_xend-1);
Rectangle();
}
// Get ID from UCI and print
enableIO();
uii_identify();
restoreIO();
sprintf(buffer,"ID: %s",uii_data);
PutString(buffer,29,interfaceCoords->filelist_xstart+5);
// Get present path from UCI and print
enableIO();
uii_get_path();
restoreIO();
// Get width of pathname
CopyString(buffer,uii_data);
// Check if it fits and continue to shorten till it fits
nowchar = strlen(buffer);
maxchar = nowchar-1;
while (StringLength(buffer) > maxlength)
{
CopyString(buffer,uii_data+(nowchar-maxchar--));
}
PutString(buffer,39,interfaceCoords->filelist_xstart+5);
}
void DrawDrivetypes() {
// Draw the drive types of the targets
unsigned char drive;
for(drive=0;drive<4;drive++)
{
PutString(drivetypes[validdrive[drive]],58+(20*drive),interfaceCoords->righttab_xstart+20);
}
}
void DrawTargetdrive(unsigned char refresh) {
// Draw presently selected target. Clear area first on refresh flag.
// unsigned char drive;
if(refresh)
{
SetPattern(0);
SetRectangleCoords(20,30,interfaceCoords->righttab_xstart+1,screen_pixel_width-2);
Rectangle();
}
if(targetdrive)
{
sprintf(buffer,"Target is drive %c",targetdrive-1+'A');
}
else
{
sprintf(buffer,"No valid target");
}
PutString(buffer,29,interfaceCoords->righttab_xstart);
//for(drive=0;drive<8;drive++)
//{
// sprintf(buffer,"%2X",ramdiskID[drive]);
// PutString(buffer,39,interfaceCoords->righttab_xstart+16*drive);
//}
}
void PrintDirEntry(unsigned char printpos) {
// Print entry
unsigned char type = presentdirelement->type;
if(type == 5) {
// Check if DNP is correct size
enableIO();
uii_loadIntoRamDisk(targetdrive-1,presentdirelement->filename,1);
if(!uii_success()) {
uii_abort();
type=7;
presentdirelement->type = type;
}
restoreIO();
}
PutString(presentdirelement->filename,printpos,interfaceCoords->filelist_xstart+5);
PutString(entrytypes[type-1],printpos,interfaceCoords->filelist_xstart+165);
}
void DrawDir(refresh) {
// Draw the dirlisting
unsigned char printpos = 59;
struct DirElement* present;
// Clear area on request
if(refresh)
{
SetPattern(0);
SetRectangleCoords(46,186,interfaceCoords->filelist_xstart+1,interfaceCoords->filelist_xend-1);
Rectangle();
}
// Read directory contents
if(refresh!=2) { Readdir(); }
// Print no data if no valid entries in dir are found
if(!presentdir.firstprint) {
PutString("No data.",59,interfaceCoords->filelist_xstart+5);
}
// Print entries until area is filled or last item is reached
else
{
// Get direlement
present = presentdir.firstprint;
// Loop while area is not full and further direntries are still present
do
{
// Get new element
presentdirelement = present;
// Print entry
PrintDirEntry(printpos);
//SetPattern(0);
//SetRectangleCoords(150,186,interfaceCoords->filelist_xstart+1,interfaceCoords->filelist_xend-1);
//Rectangle();
//gotoxy(1,20);
//cprintf("%4x %d",present,type);
// Update lastprinted and printpos
presentdir.lastprint = present;
printpos += 10;
// Check if next dir entry is present, if no: break. If yes: update present pointer
if(!presentdirelement->next) { break; }
else { present = presentdirelement->next; }
//gotoxy(1,21);
//cprintf("%4x %4x %4x %d",present,presentdir.firstprint,presentdir.lastprint,printpos);
//cgetc();
} while (printpos<187);
}
}
void DrawFilebrowser() {
// Draw file browser interface
// Set x coords based on 40 or 80
if(vdc) {
interfaceCoords = &vdc_intCoords;
}
else {
interfaceCoords = &vic_intCoords;
}
// Draw interface
SetRectangleCoords(20,187,interfaceCoords->filelist_xstart,interfaceCoords->scroll_xend);
FrameRectangle(255);
HorizontalLine(255,45,interfaceCoords->filelist_xstart,interfaceCoords->filelist_xend);
HorizontalLine(255,116,interfaceCoords->filelist_xend,interfaceCoords->scroll_xend);
VerticalLine(255,45,187,interfaceCoords->filelist_xend);
// Print ID and present path
DrawIDandPath(0);
// Draw target section
DrawTargetdrive(0);
DrawDrivetypes();
DrawDir(0);
}
void scroll_down() {
// Scroll one position down
unsigned char t = 0;
struct DirElement* present;
// Get next element
present = presentdir.lastprint;
presentdirelement = present;
present = presentdirelement->next;
if(!present) { return; }
presentdirelement = present;
// Update printed pointers
presentdir.lastprint = present;
present = presentdir.firstprint;
presentdirelement = present;
presentdir.firstprint = presentdirelement->next;
// Check for VDC
if(vdc == 0)
{
// Redraw dir
DrawDir(2);
}
else
{
// Do scroll for VDC backscreen for the upper 100 scanlines
for(t=60;t<100;t++)
{
// Move line row up
MoveData( BACK_SCR_BASE + ((t-10)*80) + 1,
BACK_SCR_BASE + (t*80) + 1,
49);
}
// Do scroll for VDC backscreen for the lines 100-110
for(t=0;t<10;t++)
{
// Move line row up
MoveData( BACK_SCR_BASE + ((t+90)*80) + 1,
SCREEN_BASE + (t*80) + 65,
49);
}
// Do scroll for VDC backscreen for the lower 90 scanlines
for(t=10;t<82;t++)
{
// Move line row up
MoveData( SCREEN_BASE + ((t-10)*80) + 65,
SCREEN_BASE + (t*80) + 65,
49);
}
// Copy from back screen
SetRectangleCoords(50,180,8,interfaceCoords->filelist_xend-1);
RecoverRectangle();
// Clear upper area to avoid leftovers
SetPattern(0);
SetRectangleCoords(46,49,8,interfaceCoords->filelist_xend-1);
Rectangle();
// Clear lower area to avoid leftovers
SetRectangleCoords(172,186,8,interfaceCoords->filelist_xend-1);
Rectangle();
// Print last element afgain
present = presentdir.lastprint;
presentdirelement = present;
PrintDirEntry(179);
}
}
void scroll_up() {
// Scroll one position up
signed char t = 0;
struct DirElement* present;
// Get previous element
present = presentdir.firstprint;
presentdirelement = present;
present = presentdirelement->prev;
if(!present) { return; }
presentdirelement = present;
// Update printed pointers
presentdir.firstprint = present;
present = presentdir.lastprint;
presentdirelement = present;
presentdir.lastprint = presentdirelement->prev;
// Check for VDC
if(vdc == 0)
{
// Redraw dir
DrawDir(2);
}
else
{
// Do scroll for VDC backscreen for the lower 90 scanlines
for(t=69;t>-1;t--)
{
// Move line row up
MoveData( SCREEN_BASE + ((t+10)*80) + 65,
SCREEN_BASE + (t*80) + 65,
49);
}
// Do scroll for VDC backscreen for the lines 100-110
for(t=9;t>-1;t--)
{
// Move line row up
MoveData( SCREEN_BASE + (t*80) + 65,
BACK_SCR_BASE + ((t+90)*80) + 1,
49);
}
// Do scroll for VDC backscreen for the upper 100 scanlines
for(t=89;t>47;t--)
{
// Move line row up
MoveData( BACK_SCR_BASE + ((t+10)*80) + 1,
BACK_SCR_BASE + (t*80) + 1,
49);
}
// Copy from back screen
SetRectangleCoords(50,180,8,interfaceCoords->filelist_xend-1);
RecoverRectangle();
// Clear upper area to avoid leftovers
SetPattern(0);
SetRectangleCoords(46,59,8,interfaceCoords->filelist_xend-1);
Rectangle();
// Clear lower area to avoid leftovers
SetRectangleCoords(182,186,8,interfaceCoords->filelist_xend-1);
Rectangle();
// Print last element afgain
present = presentdir.firstprint;
presentdirelement = present;
PrintDirEntry(59);
}
}
void page_down() {
// Perform a page down
struct DirElement* present;
// Get next element
present = presentdir.lastprint;
presentdirelement = present;
present = presentdirelement->next;
if(!present) { return; }
presentdirelement = present;
// Update first print pointer
presentdir.firstprint = present;
// Redraw dir
DrawDir(2);
}
void page_up() {
// Perform a page up
struct DirElement* present;
unsigned char count;
// Set first printed as start point
present = presentdir.firstprint;
presentdirelement = present;
// Go to begin of previous page
for(count=0;count<13;count++)
{
present = presentdirelement->prev;
if(!present) { break; }
presentdirelement = present;
// Update first print pointer
presentdir.firstprint = present;
}
// Redraw dir
DrawDir(2);
}
// Icon handlers
void TargetChange(unsigned char newdrive) {
// Change target drive
unsigned char oldtype = validdrive[targetdrive-1];
targetdrive = newdrive;
DrawTargetdrive(1);
if(oldtype != validdrive[newdrive-1]) { DrawDir(1); }
}
void DriveselectA() {
// Select drive A as target if valid as target
if(validdrive[0])
{
TargetChange(1);
}
}
void DriveselectB() {
// Select drive B as target if valid as target
if(validdrive[1])
{
TargetChange(2);
}
}
void DriveselectC() {
// Select drive C as target if valid as target
if(validdrive[2])
{
TargetChange(3);
}
}
void DriveselectD() {
// Select drive A as target if valid as target
if(validdrive[3])
{
TargetChange(4);
}
}
void DirBack() {
// Go back to parent dir
enableIO();
uii_change_dir("..");
restoreIO();
DrawIDandPath(1);
DrawDir(1);
}
void DirRoot() {
// Go back to root dir
enableIO();
uii_change_dir("/");
restoreIO();
DrawIDandPath(1);
DrawDir(1);
}
void DirHome() {
// Go to default home dir
enableIO();
uii_change_dir_home();
restoreIO();
DrawIDandPath(1);
DrawDir(1);
}
void DirTop() {
// Go to top of filelist
// Check if first printed is also the first item available. If yes, return
if(presentdir.firstprint == presentdir.firstelement) { return; }
// Set first printed at first element
presentdir.firstprint = presentdir.firstelement;
// Redraw dir
DrawDir(2);
}
void DirBottom() {
// Go to bottom of filelist
struct DirElement* present;
unsigned char count;
// Check if last printed is also the last item available. If yes, return
if(presentdir.lastprint == presentdir.lastelement) { return; }
// Set first printed as start point
present = presentdir.lastelement;
presentdirelement = present;
// Get first print element
for(count=0;count<12;count++)
{
present = presentdirelement->prev;
if(!present) { break; }
presentdirelement = present;
}
// Update first print pointer
presentdir.firstprint = present;
// Redraw dir
DrawDir(2);
}
void SaveImage() {
// Save RAM disk image back to an image file
char imagename[21] = "ramdisk";
unsigned char namelen = 0;
// Check if targetdrive is a valid and supported RAM disk
if(validdrive[targetdrive-1]<4) {return; }
// Ask for filename
if( DlgBoxGetString(imagename,16,"Enter filename for the image","(or press Cancel)")
== CANCEL) { return ; }
// Add extention based on RAM disk type
namelen = strlen(imagename);
imagename[namelen] = '.';
CopyString(imagename+1+namelen,entrytypes[validdrive[targetdrive-1]-3]);
// Check if file exists
enableIO();
uii_open_file(1,imagename);
if(uii_success()) {