forked from jonbstanley/Tek405xEmulator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsTEKTRONIX4051.html
477 lines (359 loc) · 18.8 KB
/
jsTEKTRONIX4051.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
<html>
<head>
<meta charset="UTF-8">
<TITLE>jsTEKTRONIX4051 - A Tektronix 4051 emulator written in Javascript. Copyright (c) 2015 David E. Roberts.</TITLE>
<link rel='stylesheet' href='styleSheet.css' type='text/css' charset='utf-8'>
<script src="mc6800.js" language="JavaScript"></script>
<script src="Tek4051Rom.js" language="JavaScript"></script>
<script src="TekDisplay.js" language="JavaScript"></script>
<script src="TekKeyboard.js" language="JavaScript"></script>
<script src="TEKTRONIX4051.js" language="JavaScript"></script>
<script src="Storage.js" language="JavaScript"></script>
<script src="JSZip.js" language="JavaScript"></script>
<script src="RomExp.js" language="JavaScript"></script>
</head>
<body onload="tek_init();">
<div id="container">
<div id="storage" hidden="true">
<p><b>File information:</b></p>
<div id="fileInfoCtrls">
Select: <select id="fileList" class="storestyle1" onchange="storage.loadFile();"></select> 
Type: <select id="fileType" class="storestyle1" onchange="storage.changeType();">
<option value="">None</option>
<option value="A">Ascii</option>
<option value="B">Binary</option>
<option value="N">New</option>
<option value="L">Last</option>
</select> 
Usage: <select id="fileUsage" class="storestyle1" onchange="storage.changeUsage();">
<option value="">None</option>
<option value="P">Program</option>
<option value="D">Data</option>
<option value="L">Log</option>
<option value="T">Text</option>
</select> 
Secret: <select id="fileSecret" class="storestyle1" onClick="storage.toggleSecret();">
<option value="N">N</option>
<option value="Y">Y</option>
</select> 
Size: <input type="text" id="fileSize" class="storestyle1" disabled></input>
</div>
<div id="fileWindow">
<p><b>File content viewer:</b> [<SPAN id="fname">Drop a file to this window</SPAN>]</p>
<p>
<textarea id="fileViewer" rows="25" cols="74" ondrop="storage.dropHandler(event, storage);" ondragover="storage.dragOverHandler(event);" readonly></textarea><BR>
</p>
</div>
<div id="storebtns1">
<input type="button" class="storebtn" value="Save" onClick="storage.saveFile();"></input>
<input type="button" class="storebtn" value="Load" onClick="storage.loadFile();"></input>
<input type="button" class="storebtn" value="Clear" onClick="storage.clearView();"></input>
<input type="button" class="storebtn" value="DelFile" onClick="storage.deleteFile();"></input>
<input type="button" class="storebtn" value="DelALL" onClick="storage.clearAll();"></input>
</div>
<div id="savefnum">
Save to file number:
<input type="text" class="storestyle1" id="fileNum"></input>
</div>
<div id="storebtns3">
<input type="button" class="storebtn" value="Select" onClick="storage.selectTekFile();"></input>
<input type="button" class="storebtn" value="Cancel" onClick="storage.closeStorage();"></input>
</div>
<div id="importCtrls">
<input type="button" class="storebtn" value="Export" onClick="storage.storageAdm(0);"></input>
<input type="button" class="storebtn" value="Import" onClick="storage.storageAdm(1);"></input>
<input type="file" id="importObj" onchange="importObject(storage);" hidden="true"></input>
<select id="importType" class="storestyle1">
<option>Single file</option>
<option>Storage Archive</option>
<option>4050 Tape Emulator files</option>
</select>
</div>
</div>
<div class="inline">
<!-- NOTE: Canvas size set here is used by emulator for pixel locations, but is scaled down in CSS -->
<canvas id="screen" name="screen" width="1046" height="830"> </canvas>
</div>
<div class="inline">
<div class="status" id="status_busy">BUSY</div>
<div class="status" id="status_break">BREAK</div>
<div class="status" id="status_io">I/O</div>
<div class="status" id="status_power">POWER</div>
</div>
<div id="keyboard">
<div class="inlinekeys">
<table class="keys">
<tr><td>11</td><td>12</td><td>13</td><td>14</td><td>15</td></tr>
<tr>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0060);"
onmouseup="tek.fcnkey_release(0x0060);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0061);"
onmouseup="tek.fcnkey_release(0x0061);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0062);"
onmouseup="tek.fcnkey_release(0x0062);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0063);"
onmouseup="tek.fcnkey_release(0x0063);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0064);"
onmouseup="tek.fcnkey_release(0x0064);" /></td></tr>
<tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr>
<tr><td colspan="5"><div class="centerline"><div><span>USER DEFINABLE</span></div></div></td></tr>
<tr><td>16</td><td>17</td><td>18</td><td>19</td><td>20</td></tr>
<tr>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0065);"
onmouseup="tek.fcnkey_release(0x0065);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0066);"
onmouseup="tek.fcnkey_release(0x0066);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0067);"
onmouseup="tek.fcnkey_release(0x0067);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0068);"
onmouseup="tek.fcnkey_release(0x0068);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0069);"
onmouseup="tek.fcnkey_release(0x0069);" /></td></tr>
<tr><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td></tr>
</table>
</div>
<div class="inlinekeys">
<table class="keys">
<tr><td class="wider">COMPRESS</td><td class="wider">RUB OUT<br>←</td><td class="wider">RUB OUT<br>→</td>
<td class="wider">REPRINT</td><td class="wider">RECALL<br>NEXT LINE</td><td></td><td></td></tr>
<tr>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0070);"
onmouseup="tek.fcnkey_release(0x0070);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0071);"
onmouseup="tek.fcnkey_release(0x0071);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0072);"
onmouseup="tek.fcnkey_release(0x0072);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0073);"
onmouseup="tek.fcnkey_release(0x0073);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0074);"
onmouseup="tek.fcnkey_release(0x0074);" /></td>
<tr><td class="wider">EXPAND</td><td class="wider">BACK<br>SPACE</td><td class="wider">SPACE</td>
<td class="wider">CLEAR</td><td class="wider">RECALL<br>LINE</td></tr>
<tr><td colspan="5"><div class="centerline"><div><span>LINE EDITOR</span></div></div></td></tr>
</table>
</div>
<div class="inlinekeys">
<table class="keys">
<tr>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0075);"
onmouseup="tek.fcnkey_release(0x0075);" /></td>
<td><div class="key" onmousedown="tek.fcnkey_press(0x0076);"
onmouseup="tek.fcnkey_release(0x0076);" /></td>
<td><div class="key" onmousedown="tek.execute_copy();" /></td></tr>
<tr><td class="wider">AUTO<br>NUMBER</td><td class="wider">STEP<br>PROGRAM</td><td class="wider">MAKE<br>COPY</td></tr>
</table>
</div>
</div>
<br>
<div class="inline">
<div>
<table class="keys"><tr>
<td><div class="kbkey" onmousedown="tek.fcnkey_press(0x006A);"
onmouseup="tek.fcnkey_release(0x006A);">HOME<br>PAGE</div></td>
<td><div class="kbkey" onmousedown="tek.fcnkey_press(0x005E);"
onmouseup="tek.fcnkey_release(0x005E);">~<br>^</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x0031);"
onmouseup="tek.fcnkey_release(0x0031);">!<br>1</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x0032);"
onmouseup="tek.fcnkey_release(0x0032);">"<br>2</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x0033);"
onmouseup="tek.fcnkey_release(0x0033);">#<br>3</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x0034);"
onmouseup="tek.fcnkey_release(0x0034);">$<br>4</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x0035);"
onmouseup="tek.fcnkey_release(0x0035);">%<br>5</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x0036);"
onmouseup="tek.fcnkey_release(0x0036);">&<br>6</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x0037);"
onmouseup="tek.fcnkey_release(0x0037);">'<br>7</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x0038);"
onmouseup="tek.fcnkey_release(0x0038);">(<br>8</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x0039);"
onmouseup="tek.fcnkey_release(0x0039);">)<br>9</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x0030);"
onmouseup="tek.fcnkey_release(0x0030);">0</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x00C0);"
onmouseup="tek.fcnkey_release(0x00C0);">`<br>@</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x003A);"
onmouseup="tek.fcnkey_release(0x003A);">*<br>:</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x003B);"
onmouseup="tek.fcnkey_release(0x003B);">+<br>;</div></td>
<td><div class="kbkeylight" onmousedown="tek.fcnkey_press(0x003D);"
onmouseup="tek.fcnkey_release(0x003D);">=<br>-</div></td>
<td><div class="kbkey" onmousedown="tek.fcnkey_press(0x005F);"
onmouseup="tek.fcnkey_release(0x005F);">RUB<br>OUT</div></td>
<td><div class="kbkeybreak" onmousedown="tek.fcnkey_press(0x006B);"
onmouseup="tek.fcnkey_release(0x006B);">BREAK</div></td></tr>
<tr><td colspan="18"><div class="centerline"><div><span>Tektronix Keys</span></div></div></td></tr>
<tr><td colspan="18"><br>
<input id="start" class="mainbtn" value="▶ start" onclick="javascript:tek_start();" type="button">
<input id="stop" class="mainbtn" value="▣ pause" disabled="true" onclick="javascript:tek_stop();" type="button">
<input id="reset" class="mainbtn" value="⎌ reset" onclick="javascript:tek_reset();" type="button">
<input id="mutespkr" class="mainbtn" value="♫ mute" onClick="toggleAudioStatus();" type="button" >
<input id="storeopts" class="mainbtn" value="⎘ storage" disabled="true" onClick="storage.showStorageOptions();" type="button" >
</td>
</tr></table>
</div>
</div>
</div>
<script language="JavaScript">
var tek;
var storage = new Storage();
var audioOn = true;
function tek_init() {
var canvas = document.getElementById('screen');
tek = new TEKTRONIX4051( window, canvas);
} // End of function tek_init.
function tek_start() {
tek.execute_start.apply( tek );
document.getElementById('start').disabled = true;
document.getElementById('stop').disabled = false;
document.getElementById('storeopts').disabled = false;
document.getElementById('status_power').style.color = "#00EE00";
document.getElementById('start').blur();
} // End of function tek_start.
function tek_stop() {
tek.execute_stop.apply( tek );
document.getElementById('start').disabled = false;
document.getElementById('stop').disabled = true;
document.getElementById('storeopts').disabled = true;
document.getElementById('status_power').style.color = "#005500";
} // End of function tek_stop.
function tek_reset() {
tek.execute_reset.call( tek );
} // End of function tek_reset.
function tek_load() {
// See what file has been selected by the user (if any).
var file = document.getElementById('loadfile').files[0];
// Ignore if no file has been selected by the user.
if( !file )
return;
// Create a new instance of the FileReader to actually read the selected file.
var fread = new FileReader();
// This is the function invoked after a successful file load.
fread.onload = function( levent ) {
upload_to_tek(levent.target.result);
} // End of function fread.onload.
// Initiate the file load.
fread.readAsArrayBuffer( file );
} // End of function tek_load.
function upload_to_tek(buffer) {
var data = new DataView( buffer );
var size = buffer.byteLength;
var i; // Index into source data.
var j; // Index into destination data.
var BackslashSeen;
var BackspaceSeen;
var OneChar;
var ASCIIbackslash = 92;
var ASCIIunderscore = 95;
var bytes = Array( size );
j = 0;
BackslashSeen = 0; // None seen yet.
BackspaceSeen = 0; // None seen yet.
for( i=0; i<size; i++ ) {
// Pick up the first/next character.
//
OneChar = data.getUint8( i );
// Convert any Line Feeds (0x0A) into CRs (0x0D).
//
// if( OneChar == 0x0A )
// OneChar = 0x0D;
// Convert 0x08 into 0x00.
// if( OneChar == 0x08 ) {
// OneChar = 0x00;
// BackspaceSeen = 1;
// }
if( 1 == 1 ) {
if( OneChar == ASCIIunderscore ) {
// Seen an ASCII '_' character.
if( BackspaceSeen == 0 ) {
// Current character is an underscore and the 'Backspace seen' flag is clear.
// We really must want an underscore then!
// Store the character away and bump the index.
//
bytes[ j++ ] = OneChar;
} else {
// The current character is an underscore but the 'Backspace seen' flag is set.
// Check if the previous character stored in the buffer is between '@' and '_' and
// (if so) convert into a control character. If not - clear the 'backspace seen' flag.
var temp = bytes[ j-1 ];
if( (temp >= 0x40) && (temp <= 0x5F) ) {
// Convert to a control character if underscore follows backspace
//
temp -= 0x40;
// Store back away.
//
bytes[ j-1 ] = temp;
BackspaceSeen = 0; // now clear Backspace seen flag
} // End if last character stored in range.
} // End if UnderscoreSeen.
} else {
// Not an ASCII '_' character.
// Store the character away (if not null) and bump the index.
//
if( OneChar != 0x00 )
bytes[ j++ ] = OneChar;
// Clear the 'underscore seen' flag.
//
// UnderscoreSeen = 0;
} // End if current character is an '_'.
} else {
// Did we see a backslash on the last iteration of the loop?
//
if( BackslashSeen > 0 ) {
// Yes - so process this character accordingly.
// Is this character a backslash? If so - this means a real backslash is required!
//
if( OneChar == ASCIIbackslash ) {
// A 'real' backslash is required - so store it and bump the index.
//
bytes[ j++ ] = OneChar;
// Fall through...
} else {
// A 'control character' is required.
//
bytes[ j++ ] = (OneChar - 0x40) & 0xFF;
// Fall through...
} // End if backslash character.
// Either way - clear the flag for the next iteration.
//
BackslashSeen = 0;
// Fall through...
} else {
// No backslash character was seen last time.
// Is this a backslash this time?
if( OneChar == ASCIIbackslash ) {
// YES. Set the flag only.
BackslashSeen = 1;
// fall through...
} else {
// Not a backslash. Store the character and bump the index.
bytes[ j++ ] = OneChar;
// Fall through...
} // End if backslash character.
} // End if BackslashSeen.
} // End if patch.
} // End for.
// There is a remote possibility that the BackslashSeen flag is set here.
// I will assume that would be a BASIC syntax error for now and ignore the
// fact. I can't think of a TekBASIC construct that would finish with a backslash.
// If array is empty force a NO PRORGAM FOUND (error 69) to prevent BUSY hang
if (j==0){
bytes[0] = 256;
j = 1;
}
tek.execute_load.call( tek, j, bytes ); // Source and destination data length may be different.
}
function toggleAudioStatus(){
mutebtn = document.getElementById('mutespkr');
audioOn = !audioOn;
if (audioOn) {
mutebtn.value = "♫ mute";
}else{
mutebtn.value = "‼ mute";
}
}
</script>
</body>
</html>