-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
104 lines (73 loc) · 3.24 KB
/
index.html
File metadata and controls
104 lines (73 loc) · 3.24 KB
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<title>Color Computer web disassembler</title>
<link rel="stylesheet" type="text/css" href="./lib/bootstrap.min.css" />
</head>
<body>
<div id="navbar"></div>
<div>Upload DEBC file to disassemble <input type="file" id="files" name="files[]" accept=".bin" single /></div>
<div id="fileInfo"></div>
<div> Download a "Hello World" DECB sample to try the disassembler: <a href="./samples/HELLO.BIN">HELLO.BIN</a></div>
<script type="module">
import { decbParse } from './src/modules/decb_parser.mjs';
import { setupNavBar } from './src/view/setupNavBar.mjs';
import { Section, addSection, saveAllSections } from './src/model/section.mjs';
function humanFileSize(bytes, si = false, dp = 1) {
const thresh = si ? 1000 : 1024;
if (Math.abs(bytes) < thresh) {
return bytes + ' B';
}
const units = si
? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
let u = -1;
const r = 10 ** dp;
do {
bytes /= thresh;
++u;
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
return bytes.toFixed(dp) + ' ' + units[u];
}
function fillFileInfo(currentFile) {
document.getElementById('fileInfo').innerHTML = `<ul> <li><strong>Name: </strong>` + escape(currentFile.name) + `</li></ul>
<ul> <li><strong>Size: </strong>` + humanFileSize(currentFile.size) + `</li></ul>
<ul> <li><strong>Modified date: </strong>` + new Intl.DateTimeFormat('en-GB').format(new Date().setTime(currentFile.modifiedDate)) + `</li></ul>
<ul> <li><strong>Upload date: </strong>` + new Intl.DateTimeFormat('en-GB').format(new Date().setTime(currentFile.uploadDate)) + `</li></ul>`;
console.log(currentFile.name);
}
function onLoad() {
setupNavBar();
let currentFile = JSON.parse(localStorage.getItem("currentFile"));
if (currentFile) {
fillFileInfo(currentFile);
}
}
window.addEventListener("load", onLoad);
function handleFileSelect(evt) {
var file = evt.target.files[0]; // FileList object
var reader = new FileReader();
reader.onload = function () {
let retVal = decbParse(reader.result);
const sections = retVal.sections;
for (let i = 0; i < sections.length; i++) {
let section = new Section(i, sections[i].length, sections[i].startAddress, sections[i].data, "LDA $4000");
addSection(section);
}
saveAllSections();
let currentFile = {
name: file.name,
uploadDate: new Date().getTime(),
modifiedDate: file.lastModifiedDate.getTime(),
size: file.size
};
localStorage.setItem("currentFile", JSON.stringify(currentFile));
fillFileInfo(currentFile);
}
reader.readAsArrayBuffer(file);
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
</body>
</html>