-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1253 lines (934 loc) · 41.6 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Doctor D64</title>
<link rel="icon" href="img/icon.png">
<style>
/* Dark Mode Styles for the tabs and content */
body {
background-color: #121212;
color: #FFFFFF;
}
.tabs {
display: flex;
justify-content: center;
margin-bottom: 20px;
}
.tab {
padding: 10px 20px;
border: 1px solid #555;
cursor: pointer;
background-color: #242424;
transition: background-color 0.2s;
}
.tab:hover {
background-color: #444;
}
.tab.active {
background-color: #0077FF;
/* Highlighted background color for active tab */
color: #FFFFFF;
}
.content {
display: none;
border: 1px solid #555;
padding: 20px;
background-color: #242424;
}
.content.active {
display: block;
}
h1,
h2,
p {
color: #ffc107;
/* Yellow color for headings and text */
}
input,
button {
background-color: #222;
/* Dark background for input and button */
color: #ffffff;
border: none;
padding: 8px;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #444;
/* Darken button on hover */
}
pre {
background-color: #333;
/* Dark background for output area */
color: #ffffff;
padding: 10px;
border-radius: 4px;
}
@font-face {
font-family: "C64 Pro Mono Local";
src: url(fonts/C64_Pro_Mono-STYLE.ttf) format("truetype")
}
.c64pm {
font: normal 12pt/16px "C64 Pro Mono Local", verdana, helvetica, sans-serif;
letter-spacing: 0;
padding: 0;
margin: 0
}
.c64pmsmall {
font: normal 10pt/12px "C64 Pro Mono Local", verdana, helvetica, sans-serif;
letter-spacing: 2;
padding: 0;
margin: 2px
}
.ascii {
font-family: 'Courier New', Monaco, Consolas, 'Lucida Console', monospace;
font-size: 16px;
/* Adjust as needed */
font-weight: bold;
letter-spacing: 0;
padding: 0;
margin: 0
}
.bigger {
font-size: 20px;
/* Adjust as needed */
}
</style>
</head>
<body>
<div class="tabs">
<div class="tab active" onclick="toggleTab('main')">Main</div>
<div class="tab" onclick="toggleTab('list')">List</div>
<div class="tab" onclick="toggleTab('extract')">Extract</div>
<div class="tab" onclick="toggleTab('multiList')">Multi List</div>
<div class="tab" onclick="toggleTab('basicPrg')">Basic PRG file</div>
</div>
<div class="content active" id="main">
<h1>Doctor D64</h1>
<p>Examine D64 files directly from your browser</p>
<img src="img/logo.png"><br>
</div>
<div class="content" id="list">
<h1>List</h1>
<p>List the contents of a single D64/T64 file.</p>
<div>
<label for="D64DetailedMode">Detailed Mode:</label>
<input type="checkbox" id="D64DetailedMode">
</div>
<div>
<label for="D64PETSCIIMode">PETSCII Mode:</label>
<input type="checkbox" id="D64PETSCIIMode">
</div>
<div>
<input type="file" id="D64FileInput" accept=".D64, .d64,.T64, .T64">
</div>
<div>
<button class="bigger" id="D64UploadButton">List</button>
</div>
<h2>Directory Information</h2>
<p><strong>Directory Entries:</strong></p>
<p id="D64DiskTitle"></p>
<pre class="c64pm" id="D64DirectoryEntries"></pre>
<p id="D64DiskFree"></p>
</div>
<div class="content" id="extract">
<h1>Extract</h1>
<p>Extract files from a D64.</p>
<div>
<input type="file" id="extractD64FileInput" accept=".D64, .d64">
</div>
<h2>Directory Information</h2>
<p><strong>Directory Entries:</strong></p>
<pre class="ascii" id="extractD64DirectoryEntries"></pre>
</div>
<div class="content" id="multiList">
<h1>Multi List</h1>
<p>List the contents of multiple D64 files. (provided as a ZIP)</p>
<div>
<label for="ZIPConcateningMode">Concatenating Mode:</label>
<input type="checkbox" id="ZIPConcateningMode">
</div>
<div>
<input type="file" id="zipFileInput" accept=".ZIP, .zip">
</div>
<div>
<button onclick="copyZipContentToClipboard()">Copy</button>
</div>
<div id="extractedFiles"></div>
</div>
<div class="content" id="basicPrg">
<h1>List</h1>
<p>List the contents of a Basic program (*.PGM file).</p>
<div>
<input type="file" id="BASICPRGInput" accept=".prg">
</div>
<div>
<button onclick="copyBasicListingToClipboard()">Copy</button>
</div>
<h2>Basic Program</h2>
<p><strong>Listing:</strong></p>
<pre class="c64pmsmall" id="BASICPRGLines"></pre>
</div>
<script src="lib/c64basicpgm.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip-utils/0.1.0/jszip-utils.min.js"></script>
<script>
var diskImages = [];
var ZipContentAsText = "";
function checkFileExtension(filePath, ext) {
const fileName = filePath;
// Extract the file extension
const extension = fileName.slice((fileName.lastIndexOf(".") - 1 >>> 0) + 2);
// Check if the extension is ext (case insensitive)
if (extension.toLowerCase() === ext.toLowerCase()) {
return true;
} else {
return false;
}
}
function checkT64FileExtension(filePath) {
return checkFileExtension(filePath, "t64");
}
function checkD64FileExtension(filePath) {
return checkFileExtension(filePath, "d64");
}
function checkZIPFileExtension(filePath) {
return checkFileExtension(filePath, "zip");
}
function checkPRGFileExtension(filePath) {
return checkFileExtension(filePath, "prg");
}
function blobToArrayBuffer(blob, callback) {
const reader = new FileReader();
reader.onload = function (event) {
const arrayBuffer = event.target.result;
callback(arrayBuffer);
};
reader.readAsArrayBuffer(blob);
}
function copyZipContentToClipboard() {
navigator.clipboard.writeText(ZipContentAsText).then(function () {
console.log('Text successfully copied to clipboard');
alert("Copied to Clipboard");
}).catch(function (err) {
console.error('Unable to copy text to clipboard', err);
});
}
function convertPETSIIByteArrayToAsciiString(byteArray) {
let result = '';
for (let i = 0; i < byteArray.length; i++) {
const byte = byteArray[i];
if (byte >= 32 && byte <= 93) {
result += String.fromCharCode(byte);
}
else if (byte == 160) {
result += " ";
}
else {
result += "?";
}
}
return result;
}
function convertPETSIIByteArrayToHTML(byteArray) {
let result = '';
for (let i = 0; i < byteArray.length; i++) {
const byte = byteArray[i];
if (byte >= 32 && byte <= 93) {
result += String.fromCharCode(byte);
} else if (byte >= 94 && byte <= 127) {
let code = `0ee${(byte - 32).toString(16).padStart(2, '0')}`;
const charCode = parseInt(code, 16);
result += String.fromCharCode(charCode);;
}
else if (byte == 160) {
result += " ";
} else if (byte >= 161 && byte <= 255) {
let code = `0ee${(byte - 64).toString(16).padStart(2, '0')}`;
const charCode = parseInt(code, 16);
result += String.fromCharCode(charCode);;
}
else {
let code = `0ee00`;
const charCode = parseInt(code, 16);
result += String.fromCharCode(charCode);;
}
}
return result;
}
document.getElementById("zipFileInput").addEventListener("change", function (event) {
//let fileList = document.getElementById("fileList");
//fileList.innerHTML = ""; // Clear any previous listings
let extractedFilesDiv = document.getElementById("extractedFiles");
let file = event.target.files[0];
if (!checkZIPFileExtension(file.name)) {
alert("Only ZIP files supported");
return;
}
const ZIPConcateningCheckBox = document.getElementById('ZIPConcateningMode').checked;
if (ZIPConcateningCheckBox == false) {
extractedFilesDiv.innerHTML = '';
ZipContentAsText = "";
}
JSZip.loadAsync(file).then(function (zip) {
diskImages = [];
var fileCount = Object.keys(zip.files).length;
// var lastFile = "";
// for( var i=0; i<Object.keys(zip.files).length; i++ ) {
// var file = Object.keys(zip.files)[i];
// if( checkD64FileExtension( file ) ) {
// lastFile = file;
// }
// }
// if( fileCount > 0) {
// //lastFile = zip.files[fileCount-1];
// lastFile = Object.keys(zip.files)[fileCount-1];
// }
zip.forEach(function (relativePath, zipEntry) {
zipEntry.async("blob").then(function (content) {
if (!checkD64FileExtension(relativePath)) {
return;
}
blobToArrayBuffer(content, function (arrayBuffer) {
// Use the arrayBuffer as needed
console.log(arrayBuffer);
//var buffer = stringToBinaryArray(content);
let image = { path: relativePath, content: new D64Disk(arrayBuffer, relativePath) };
diskImages.push(image);
let fileDiv = document.createElement("div");
var list = image.content.directory.getEntriesAsText(true);
fileDiv.innerHTML = `<strong>${relativePath}:</strong><pre>${list}</pre>`;
extractedFilesDiv.appendChild(fileDiv);
ZipContentAsText += `${relativePath}\n-------------\n${list}\n`;
// if( relativePath == lastFile ) {
//
// copyToClipboard( ZipContentAsText );
// }
});
});
});
});
});
function extractFiles() {
let fileInput = document.getElementById("zipFileInput");
let file = fileInput.files[0];
let extractedFilesDiv = document.getElementById("extractedFiles");
extractedFilesDiv.innerHTML = ""; // Clear any previous listings
if (file) {
JSZip.loadAsync(file).then(function (zip) {
zip.forEach(function (relativePath, zipEntry) {
zipEntry.async("text").then(function (content) {
let fileDiv = document.createElement("div");
fileDiv.innerHTML = `<strong>${relativePath}:</strong><pre>${content}</pre>`;
extractedFilesDiv.appendChild(fileDiv);
});
});
});
} else {
alert("Please select a zip file first!");
}
}
</script>
<script>
function toggleTab(pageId) {
// Get all content divs and tabs
let contents = document.querySelectorAll('.content');
let tabs = document.querySelectorAll('.tab');
// Hide all content divs and remove active state from tabs
contents.forEach(content => content.classList.remove('active'));
tabs.forEach(tab => tab.classList.remove('active'));
// Display the selected content div and set its tab to active state
document.getElementById(pageId).classList.add('active');
[...tabs].find(tab => tab.getAttribute("onclick").includes(pageId)).classList.add('active');
}
toggleTab('list')
//Type
function mapC64TypeToText(fileType) {
switch (fileType) {
case '80':
return 'DEL';
case '81':
return 'SEQ';
case '82':
return 'PRG';
case '83':
return 'USR';
case '84':
return 'REL';
case '80':
return 'DEL';
case '81':
return 'SEQ';
case '82':
return 'PRG';
case '83':
return 'USR';
case '84':
return 'REL';
case 'c0':
return 'DEL<';
case 'c1':
return 'SEQ<';
case 'c2':
return 'PRG<';
case 'c3':
return 'USR<';
case 'c4':
return 'REL<';
case 'c0':
return 'DEL<';
case 'c1':
return 'SEQ<';
case 'c2':
return 'PRG<';
case 'c3':
return 'USR<';
case 'c4':
return 'REL<';
default:
return '???';
}
}
//------------ tape
class TapeDirectoryEntry {
constructor(byteArray, startOffset) {
this.binaryFileName = byteArray.slice(startOffset + 0x10, startOffset + 0x20); // Storing raw Uint8Array for filename
this.binaryFileType = byteArray[startOffset + 0x01]; // Storing raw Uint8Array for filename
this.filename = this.extractFilename(this.binaryFileName);
this.fileType = this.binaryFileType.toString(16).padStart(2, '0');
}
// Extract filename from a 32-byte directory entry byteArray
extractFilename(binaryFileName) {
let filename = String.fromCharCode.apply(null, binaryFileName);
// Replace non-ASCII and null characters with "?", replace A0 with space, and trim spaces
filename = filename.replace(/\xA0/g, ' ').replace(/[^\x20-\x7E]/g, '?').replace(/\0/g, '').trim();
// Ensure filename is always 16 characters long
while (filename.length < 16) {
filename += " ";
}
return filename;
}
mapTypeToText() {
return mapC64TypeToText(this.fileType);
}
}
class TapeDirectory {
constructor(byteArray, dirLen) {
this.entries = [];
this.parseDirectory(byteArray, dirLen);
}
// Parse directory from the byteArray
parseDirectory(byteArray, dirLen) {
for (let i = 0x40; this.entries.length < dirLen; i += 32) { // Start at offset $40, each directory entry is 32 bytes
let tapeEntry = new TapeDirectoryEntry(byteArray, i);
this.entries.push(tapeEntry);
}
}
getEntriesAsInnerPETSCIIHTML(shortMode) {
let entriesText = '';
this.entries.forEach((entry, index) => {
let petsciiName;
petsciiName = entry.fileName;
if (entry.binaryFileName != null) {
petsciiName = convertPETSIIByteArrayToHTML(entry.binaryFileName);
}
if (shortMode) {
entriesText += `0\t"${petsciiName}" ${entry.mapTypeToText()}<br>`;
} else {
entriesText += `Entry ${index + 1}:<br>`;
entriesText += ` File Type: 0x${entry.fileType}<br>`;
entriesText += ` File Name: ${petsciiName}<br>`;
//entriesText += ` File Length: ${entry.fileLength}<br>`;
//entriesText += ` Next Track: ${entry.nextTrack}<br>`;
//entriesText += ` Next Sector: ${entry.nextSector}<br>`;
//entriesText += ` File Start Track: ${entry.fileStartTrack}<br>`;
//entriesText += ` File Start Sector: ${entry.fileStartSector}<br><br>`;
}
});
return entriesText; // Display or use the entries text as needed
}
getEntriesAsText(shortMode) {
let entriesText = '';
this.entries.forEach((entry, index) => {
let asciiName;
asciiName = entry.filename;
if (shortMode) {
//
entriesText += `0\t"${asciiName}" ${entry.mapTypeToText()}`
entriesText += `\n`;
//DEBUG entriesText += `\tN:T${entry.nextTrack}S${entry.nextSector} \n`;
} else {
entriesText += `Entry ${index + 1}:\n`;
entriesText += ` File Type: 0x${entry.fileType}\n`;
entriesText += ` File Name: ${asciiName}\n`;
//entriesText += ` File Length: ${entry.fileLength}\n`;
//entriesText += ` Next Track: ${entry.nextTrack}\n`;
//entriesText += ` Next Sector: ${entry.nextSector}\n`;
//entriesText += ` File Start Track: ${entry.fileStartTrack}\n`;
//entriesText += ` File Start Sector: ${entry.fileStartSector}\n\n`;
}
});
return entriesText; // Display or use the entries text as needed
}
}
class T64 {
constructor(arrayBuffer, filename) {
this.byteArray = new Uint8Array(arrayBuffer);
this.filename = filename;
this.numFiles = 0;
if (!this.hasValidSignature()) {
console.error("Invalid T64 signature. Aborting parsing.");
this.tapeDirectory = {};
this.tapeDirectory.entries = [];
return;
}
this.numFiles = this.extractNumFiles();
this.directory = new TapeDirectory(this.byteArray, this.numFiles);
}
hasValidSignature() {
const signature = "C64S tape image file";
const signature2 = "C64 tape image file";
let fileSignature = String.fromCharCode.apply(null, this.byteArray.slice(0, signature.length));
if (fileSignature.toLowerCase() === signature.toLowerCase()) {
return true;
}
fileSignature = String.fromCharCode.apply(null, this.byteArray.slice(0, signature2.length));
if (fileSignature.toLowerCase() === signature2.toLowerCase()) {
return true;
}
return false;
}
// Extract the number of files from the byteArray
extractNumFiles() {
return this.byteArray[0x22] + (this.byteArray[0x23] << 8); // Offset $22, 2 bytes, little endian
}
}
//------------ disk
class D64Disk {
constructor(arrayBuffer, fn) {
this.byteArray = new Uint8Array(arrayBuffer);
this.tracks = [];
this.currentPosition = 0;
this.maxSectors = 683;
var checkSum = 0;
for (var i = 0; i < this.byteArray.byteLength; i++) {
checkSum += this.byteArray[i];
}
console.log("image file: " + fn);
console.log("checkSum: " + checkSum);
console.log("binary length: " + this.byteArray.byteLength);
// Initialize tracks
this.tracks.push(null); // Placeholder for track 0
for (let trackNumber = 1; trackNumber <= 40; trackNumber++) {
this.tracks.push(this.processDiskTrack(trackNumber));
}
// Populate the directory
const directorySector = this.tracks[18].sectors[1];
if (fn === undefined) {
this.imageFileName = "UNKNOWN";
}
else {
this.imageFileName = fn;
}
this.directory = new Directory(directorySector, this);
}
getTrackOffset(t) {
if (t == 0) { return -1; }
return "$" + this.tracks[t].byteOffset.toString(16);
}
setImageFileName(fn) {
this.imageFileName = fn;
}
processDiskTrack(trackNumber) {
let sectorCount;
if (trackNumber <= 17) {
sectorCount = 21;
} else if (trackNumber <= 24) {
sectorCount = 19;
} else if (trackNumber <= 30) {
sectorCount = 18;
} else {
sectorCount = 17;
}
const sectors = [];
for (let i = 0; i < sectorCount; i++) {
sectors.push(this.byteArray.subarray(this.currentPosition, this.currentPosition + 256));
this.currentPosition += 256;
}
return {
trackNumber: trackNumber,
sectors: sectors,
byteOffset: this.currentPosition - 256 * sectorCount
};
}
getDiskTitle(bamSector) {
const diskTitleBytes = bamSector.subarray(0x90, 0xA0);
const diskTitle = String.fromCharCode(...diskTitleBytes);
return diskTitle;
}
getFreeSectors() {
const usedSectors = this.directory.entries.reduce((total, entry) => total + entry.fileLength, 0);
const freeSectors = this.maxSectors - usedSectors;
return freeSectors;
}
extractFile(ix) {
var dirEntry = this.directory.getEntry(ix);
if (dirEntry.fileLength == 0) {
return null;
}
var maxLength = dirEntry.fileLength * 254;
var buffer = new Uint8Array(maxLength);
var trackIx = dirEntry.fileStartTrack;
var sectorIx = dirEntry.fileStartSector;
var sectorsLeft = dirEntry.fileLength;
var byteIx = 0;
while (sectorsLeft > 0) {
var sector = this.tracks[trackIx].sectors[sectorIx];
var nextTrack = sector[0];
var nextSector = sector[1];
var sectByteIx = 2;
while (sectByteIx < 256 && byteIx < maxLength) {
buffer[byteIx] = sector[sectByteIx];
byteIx++;
sectByteIx++;
}
if (nextTrack == 0) { break; }
trackIx = nextTrack;
sectorIx = nextSector;
sectorsLeft--;
}
var asciiName = dirEntry.fileName;
if (dirEntry.fileNameBinary != null) {
asciiName = convertPETSIIByteArrayToAsciiString(dirEntry.fileNameBinary);
}
var ext = mapC64TypeToText(dirEntry.fileType).replace(/</g, "");
var downloadName = (asciiName + "." + ext).toLowerCase();
return {
fileName: downloadName,
buffer: buffer
};
}
}
class DirectoryEntry {
constructor(directoryEntryBytes) {
this.fileType = 0;
this.fileName = "UNDEFINED";
this.fileNameBinary = null;
this.fileLength = 0;
this.nextTrack = 0;
this.nextSector = 0;
this.fileStartTrack = 0; // New field
this.fileStartSector = 0; // New field
if (directoryEntryBytes === undefined) { ; }
else {
this.fileType = directoryEntryBytes[2].toString(16).padStart(2, '0');
this.fileName = String.fromCharCode(...directoryEntryBytes.subarray(5, 21));
this.fileNameBinary = (directoryEntryBytes.subarray(5, 21));
this.fileLength = (directoryEntryBytes[0x1F] << 8) + directoryEntryBytes[0x1E]; // Swapped length bytes
this.nextTrack = directoryEntryBytes[0];
this.nextSector = directoryEntryBytes[1];
this.fileStartTrack = directoryEntryBytes[3]; // New field
this.fileStartSector = directoryEntryBytes[4]; // New field
}
}
setFileName(name) {
this.fileName = name;
}
mapTypeToText() {
return mapC64TypeToText(this.fileType);
}
}
class Directory {
constructor(directorySector, disk) {
this.entries = [];
this.processDirectory(directorySector, disk);
this.disk = disk;
}
processDirectory(directorySector, disk) {
const directoryEntries = [];
while (true) {
this.processDirectorySector(directorySector, directoryEntries);
const nextDirectoryTrack = directorySector[0];
const nextDirectorySector = directorySector[1];
if (nextDirectoryTrack === 0 || nextDirectorySector === 255) {
break; // No next directory sector
}
//if (nextDirectorySector === 255) {
// break; // No next directory sector
//}
if (nextDirectoryTrack == 0 || nextDirectoryTrack > 40) {
var dummy = new DirectoryEntry(undefined);
dummy.setFileName("ERROR: Wrong next directory track T" + nextDirectoryTrack + " (S" + nextDirectorySector + ")");
directoryEntries.push(dummy);
break;
}
var nextTrack = disk.tracks[nextDirectoryTrack];
if (nextDirectorySector >= nextTrack.sectors.length) {
var dummy = new DirectoryEntry(undefined);
dummy.setFileName("ERROR: Non existent next directory track/sector T" + nextDirectoryTrack + " S" + nextDirectorySector);
directoryEntries.push(dummy);
break;
}
directorySector = disk.tracks[nextDirectoryTrack].sectors[nextDirectorySector];
}
this.entries = directoryEntries;
}
processDirectorySector(directorySector, directoryEntries) {
for (let entryIndex = 0; entryIndex < 8; entryIndex++) {
const directoryEntryOffset = entryIndex * 32;
const directoryEntryBytes = directorySector.subarray(directoryEntryOffset, directoryEntryOffset + 32);
const fileType = directoryEntryBytes[2];
if (fileType === 0) {
continue; // Skip unused entries
}
const directoryEntryObject = new DirectoryEntry(directoryEntryBytes);
directoryEntries.push(directoryEntryObject);
}
}
getEntry(ix) {
return this.entries[ix];
}
getEntriesAsText(shortMode) {
let entriesText = '';
this.entries.forEach((entry, index) => {
let asciiName;
asciiName = entry.fileName;
if (entry.fileNameBinary != null) {
asciiName = convertPETSIIByteArrayToAsciiString(entry.fileNameBinary);
}
if (shortMode) {
//
entriesText += `${entry.fileLength}\t"${asciiName}" ${entry.mapTypeToText()}`
entriesText += `\n`;
//DEBUG entriesText += `\tN:T${entry.nextTrack}S${entry.nextSector} \n`;
} else {
entriesText += `Entry ${index + 1}:\n`;
entriesText += ` File Type: 0x${entry.fileType}\n`;
entriesText += ` File Name: ${asciiName}\n`;
entriesText += ` File Length: ${entry.fileLength}\n`;
entriesText += ` Next Track: ${entry.nextTrack} (offset ${this.disk.getTrackOffset(entry.nextTrack)})\n`;
entriesText += ` Next Sector: ${entry.nextSector}\n`;
entriesText += ` File Start Track: ${entry.fileStartTrack} (offset ${this.disk.getTrackOffset(entry.fileStartTrack)})\n`;
entriesText += ` File Start Sector: ${entry.fileStartSector}\n\n`;
}
});
return entriesText; // Display or use the entries text as needed
}
getEntriesAsInnerPETSCIIHTML(shortMode) {
let entriesText = '';
this.entries.forEach((entry, index) => {
let petsciiName;
petsciiName = entry.fileName;
if (entry.fileNameBinary != null) {
petsciiName = convertPETSIIByteArrayToHTML(entry.fileNameBinary);
}
if (shortMode) {
entriesText += `${entry.fileLength}\t"${petsciiName}" ${entry.mapTypeToText()}<br>`;
} else {
entriesText += `Entry ${index + 1}:<br>`;
entriesText += ` File Type: 0x${entry.fileType}<br>`;
entriesText += ` File Name: ${petsciiName}<br>`;
entriesText += ` File Length: ${entry.fileLength}<br>`;
entriesText += ` Next Track: ${entry.nextTrack}<br>`;
entriesText += ` Next Sector: ${entry.nextSector}<br>`;
entriesText += ` File Start Track: ${entry.fileStartTrack}<br>`;
entriesText += ` File Start Sector: ${entry.fileStartSector}<br><br>`;
}
});
return entriesText; // Display or use the entries text as needed
}
}
function handleD64ListRequest() {
const fileInput = document.getElementById('D64FileInput');
var isTypeD64 = checkD64FileExtension(fileInput.value);
var isTypeT64 = checkT64FileExtension(fileInput.value);
if (!isTypeD64 && !isTypeT64) {
alert("Only D64 or T64 images supported");
return;
}
const directoryEntriesElement = document.getElementById('D64DirectoryEntries');
const shortModeCheckbox = !document.getElementById('D64DetailedMode').checked;
const PETSCIIModeCheckbox = document.getElementById('D64PETSCIIMode').checked;