-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
235 lines (216 loc) · 9.42 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
<!DOCTYPE html>
<html>
<head>
<title>GALasm web</title>
<style>
body {
margin: 0;
padding: 0;
display: flex;
}
#left-container,
#right-container {
width: 50%;
height: 100vh;
box-sizing: border-box;
padding: 10px;
background-color: #f8f8f8;
}
#left-container {
background-color: #f0f0f0;
display: flex;
flex-direction: column;
align-items: center;
}
#options {
width: 100%;
}
.optionlabel {
display: block;
font-family: monospace;
}
#fileoutput {
overflow: scroll;
max-height: 100%;
}
#output {
overflow: scroll;
max-height: 100%;
width: 100%;
}
textarea {
width: 100%;
height: 70%;
resize: none;
margin-bottom: 10px;
}
button {
width: 100%;
}
#right-container {
background-color: #e0e0e0;
}
#downloadbuttons {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-bottom: 10px;
}
#right-container div button {
width: 50%;
}
select {
width: 100%;
margin-bottom: 10px;
}
</style>
<script>
let defaultfile = atob("R0FMMTZWOCAgICA7IDQtQml0LUNvdW50ZXIgIGZpcnN0IGxpbmUgOiB1c2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9hZCBRMC1RMyB3aXRoIHN0YXRlIG9mIEQwLUQzCgogUGluICdDbGVhcicgSElHSCB3aGlsZSBjbG9jayBzaWduYWw6CiAgICAgICAgUTAtUTMgYXJlIGNsZWFyZWQKCiBDbG9jayBzaWduYWwgd2hpbGUgcGlucyAnU2V0JyBhbmQgJ0NsZWFyJyBhcmUgTE9XOgogICAgICAgIGluY3JlbWVudCBjb3VudGVyCgo=");
var Module = {
onRuntimeInitialized: () => {
let assembleButton = document.querySelector('#assemble');
assembleButton.disabled = false;
assembleButton.textContent = 'Assemble';
},
print: (text) => {
let outputContainer = document.querySelector('#output');
let element = document.createElement('div');
element.appendChild(document.createTextNode(text));
outputContainer.appendChild(element);
},
printErr: (text) => {
let outputContainer = document.querySelector('#output');
let element = document.createElement('div');
element.style.color = 'red';
element.appendChild(document.createTextNode(text));
outputContainer.appendChild(element);
},
noInitialRun: true,
}
function populatefileoutput() {
let fileoutput = document.querySelector('#fileoutput');
let fileselect = document.querySelector('#fileselect');
let filename = "input." + fileselect.options[fileselect.selectedIndex].value;
fileoutput.textContent = FS.readFile(filename, { encoding: 'utf8' });
}
document.addEventListener('DOMContentLoaded', () => {
let assembleButton = document.querySelector('#assemble');
assembleButton.addEventListener('click', () => {
let input = document.querySelector('#input').value;
let fileoutput = document.querySelector('#fileoutput');
fileoutput.textContent = '';
let output = document.querySelector('#output');
output.textContent = '';
FS.writeFile('input.pld', input);
options = '-v';
if (document.querySelector('#securityfuse').checked) {
options += 's';
}
if (document.querySelector('#restrictchecksum').checked) {
options += 'a';
}
if (document.querySelector('#forcecrlf').checked) {
options += 'w';
}
Module.callMain([options, 'input.pld']);
populatefileoutput();
localStorage.setItem('input', input);
});
let fileselect = document.querySelector('#fileselect');
fileselect.addEventListener('change', () => {
populatefileoutput();
});
function downloadfile(content, filename) {
let blob = new Blob([content], {type: 'text/plain'});
let link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(link.href);
}
let downloadbuttons = document.querySelector('#downloadjed');
downloadbuttons.addEventListener('click', () => {
try {
let jedfile = FS.readFile('input.jed');
downloadfile(jedfile, 'input.jed');
} catch {
alert('No jed file to download, try assembling first');
return;
}
});
let downloadall = document.querySelector('#downloadall');
downloadall.addEventListener('click', () => {
try {
let jedfile = FS.readFile('input.jed');
let chpfile = FS.readFile('input.chp');
let fusfile = FS.readFile('input.fus');
let pinfile = FS.readFile('input.pin');
let zip = new JSZip();
zip.file('input.jed', jedfile);
zip.file('input.chp', chpfile);
zip.file('input.fus', fusfile);
zip.file('input.pin', pinfile);
zip.generateAsync({type: 'blob'}).then((content) => {
downloadfile(content, 'input.zip');
});
} catch {
alert('No files to download, try assembling first');
return;
}
});
setTimeout(() => {
if (localStorage.getItem('input')) {
document.querySelector('#input').value = localStorage.getItem('input');
} else {
document.querySelector('#input').value = defaultfile;
}
document.querySelector('#assemble').click();
}, 100);
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="src/galasm.js"></script>
</head>
<body>
<div id="left-container">
<button id="assemble" disabled>Loading...</button>
<div id="options">
<!--
-s Enable security fuse
-a Restrict checksum to the fuse array only
-w Force <CR><LF> line endings for .jed file overriding platform default
-->
<div class="optionlabel">
<input type="checkbox" id="securityfuse" />
<label for="securityfuse">-s Enable security fuse</label>
</div>
<div class="optionlabel">
<input type="checkbox" id="restrictchecksum" />
<label for="restrictchecksum">-a Restrict checksum to the fuse array only</label>
</div>
<div class="optionlabel">
<input type="checkbox" id="forcecrlf" />
<label for="forcecrlf">-w Force <CR>
<LF> line endings for .jed file overriding platform default</label>
</div>
</div>
<textarea id="input"></textarea>
<pre id="output"></pre>
</div>
<div id="right-container">
<div id="downloadbuttons">
<button id="downloadjed">Download JED</button>
<button id="downloadall">Download all as zip</button>
</div>
<select id="fileselect">
<option value="chp">chp</option>
<option value="fus">fus</option>
<option value="jed" selected>jed</option>
<option value="pin">pin</option>
</select>
<pre id="fileoutput"></pre>
</div>
</body>
</html>