-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathunixv6.html
510 lines (442 loc) · 13.7 KB
/
unixv6.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
<html>
<head>
<meta charset="utf-8">
<title>PDP11 Emulator with UNIX V6</title>
<script type="text/javascript" src="utility/JsImport.js"></script>
<script type="text/javascript" src="pdp11/Import.js"></script>
<script type="text/javascript" src="pdp11/TextAreaView.js"></script>
<script type="text/javascript">
var __pdp11 ;
var __unixV6DiskImageURL = './disk_image/v6bin' ;
var __terminalView ;
var __debugView ;
var __debugCanvas ;
var __pdp11View ;
var __stackView ;
var __figureWindow ;
var __breakPoints = [ ] ;
/**
* TODO: maybe better to change the function name
*/
var dragOver = function( event ) {
event.preventDefault( ) ;
} ;
/**
* TODO: appropriate error message.
*/
var dropDiskImage = function( event ) {
event.preventDefault( ) ;
var file = event.dataTransfer.files[ 0 ] ;
var reader = new FileReader( ) ;
reader.onload = function( event ) {
initPdp11( event.target.result ) ;
} ;
reader.onerror = function( e ) {
__terminalView.outputLine( 'Error!' ) ;
for( var key in reader.error ) {
__terminalView.output( key + '=' + reader.error[ key ] + '<br />' ) ;
}
} ;
reader.readAsArrayBuffer( file ) ;
__terminalView.outputLine( 'loading image...' ) ;
} ;
/**
* TODO: appropriate error message.
*/
var loadUnixV6DiskImage = function( ) {
var request = new XMLHttpRequest( ) ;
request.responseType = 'arraybuffer' ;
request.onload = function( ) {
initPdp11( request.response ) ;
} ;
request.onerror = function( e ) {
__terminalView.outputLine( 'Error!' ) ;
} ;
request.open( 'GET', __unixV6DiskImageURL, true ) ;
request.send( null ) ;
__terminalView.outputLine( 'loading image...' ) ;
} ;
/**
* @param buffer ArrayBuffer including Disk image
*/
var initPdp11 = function( buffer ) {
document.getElementById( 'loadV6Button' ).disabled = true ;
document.getElementById( 'exportButton' ).disabled = false ;
document.getElementById( 'resetButton' ).disabled = false ;
document.getElementById( 'stopButton' ).disabled = false ;
__terminalView.focus( ) ;
__pdp11 = new Pdp11( __terminalView, __debugCanvas ) ;
__pdp11.disk.importBuffer( buffer ) ;
changeDebugFlags( ) ;
updateBreakPoints( ) ;
__pdp11.loadBootRom( buffer ) ;
__pdp11.run( ) ;
} ;
/**
* TODO: make it run as specification
*/
var resetPdp11 = function( ) {
if( __pdp11 )
initPdp11( __pdp11.disk.exportBuffer( ) ) ;
} ;
/**
* TODO: optimize
*/
var exportDiskImage = function( ) {
var span = document.getElementById( 'diskImageSpan' ) ;
while( span.firstChild )
span.removeChild( span.firstChild )
var buffer = __pdp11.disk.exportBuffer( ) ;
var a = document.createElement( 'a' ) ;
a.download = 'v6bin' ;
a.href = window.URL.createObjectURL( new Blob( [ new Uint8Array( buffer ) ] ) ) ;
a.textContent = 'disk image' ;
span.appendChild( a ) ;
} ;
/**
*
*/
var init = function( ) {
document.getElementById( 'exportButton' ).disabled = true ;
document.getElementById( 'resetButton' ).disabled = true ;
__terminalView = new TextAreaView( 'terminalView' ) ;
__debugView = new LimitedLinesTextAreaView( 'debugView' ) ;
__pdp11View = new TextAreaView( 'pdp11View' ) ;
__stackView = new TextAreaView( 'stackView' ) ;
document.getElementById( 'instructionCheck' ).disabled = true ;
document.getElementById( 'kernelSymbolCheck' ).disabled = true ;
document.getElementById( 'stopButton' ).disabled = true ;
document.getElementById( 'nextStepButton' ).disabled = true ;
document.getElementById( 'continueButton' ).disabled = true ;
document.getElementById( 'virtualAddressButton' ).disabled = true ;
document.getElementById( 'physicalAddressButton' ).disabled = true ;
__debugCanvas = document.getElementById( 'debugCanvas' ) ;
displayInitialMessage( ) ;
} ;
/**
*
*/
var changeDebugState = function( flag ) {
changeDebugFlags( ) ;
updateBreakPoints( ) ;
} ;
/**
*
*/
var changeDebugFlags = function( ) {
if( ! __pdp11 )
return ;
for( var key in __pdp11.debugFlags ) {
__pdp11.debugFlags[ key ] = document.getElementById( key + 'Check' ).checked ;
}
} ;
/**
*
*/
var inputTerminalByKeypress = function( e ) {
if( e.ctrlKey )
return ;
var keyCode = e.keyCode ;
if( keyCode >= 0x41 && keyCode <= 0x5a && ! e.shiftKey ) {
keyCode += 0x20 ;
}
if( __pdp11 )
__pdp11.terminal.input( keyCode ) ;
e.preventDefault( ) ;
} ;
/**
* handle special characters.
* TODO: combine to inputeTerminalByKeypress?
*/
var inputTerminalByKeydown = function( e ) {
var keyCode = e.keyCode ;
if( e.ctrlKey ) {
switch( keyCode ) {
case 0x44: // d
keyCode = 4 ;
break ;
default:
return ;
}
} else {
switch( keyCode ) {
case 0x8: // backspace
case 0x9: // tab
break ;
case 0x13: // pause
keyCode = 034 ;
break ;
case 0x2e: // del
keyCode = 0177 ;
break ;
default:
return ;
}
}
if( __pdp11 )
__pdp11.terminal.input( keyCode ) ;
e.preventDefault( ) ;
} ;
/**
*
*/
var inputTerminalForAndroid = function( ) {
var input = document.getElementById( 'androidInput' ) ;
if( __pdp11 ) {
input.setAttribute( 'readonly', true ) ;
var str = input.value + '\n' ;
var i = 0 ;
var func = function( ) {
__pdp11.terminal.input( str.charCodeAt( i ) ) ;
input.value = input.value.slice( 1, input.value.length ) ;
i++ ;
if( i < str.length )
setTimeout( func, 5 ) ;
else
input.removeAttribute( 'readonly' ) ;
} ;
func( ) ;
} else {
input.value = '' ;
}
} ;
/**
*
*/
var updateBreakPoints = function( value ) {
var select = document.getElementById( 'breakPointsSelect' ) ;
while( select.firstChild )
select.removeChild( select.firstChild ) ;
for( var i = 0; i < __breakPoints.length; i++ ) {
var option = document.createElement( 'option' ) ;
option.value = __breakPoints[ i ] ;
option.text = __breakPoints[ i ] ;
if( value != undefined && value == __breakPoints[ i ] )
option.selected = true ;
select.appendChild( option ) ;
}
if( __pdp11 ) {
__pdp11.setBreakPoints( __breakPoints ) ;
}
} ;
/**
*
*/
var addBreakPoint = function( ) {
var value = Number( document.getElementById( 'breakPointInput' ).value ) ;
if( ! isNaN( value ) && __breakPoints.indexOf( value ) < 0 ) {
__breakPoints.push( value ) ;
__breakPoints.sort(
function( a, b ) {
if( a < b ) return -1 ;
if( a > b ) return 1 ;
return 0 ;
}
) ;
updateBreakPoints( value ) ;
}
} ;
/**
*
*/
var removeBreakPoint = function( ) {
var select = document.getElementById( 'breakPointsSelect' ) ;
if( select.selectedIndex < 0 )
return ;
var value = Number( select.selectedOptions.item( ).value ) ;
__breakPoints.splice( __breakPoints.indexOf( value ), 1 ) ;
updateBreakPoints( ) ;
} ;
/**
* TODO: implement
*/
var stopPdp11 = function( ) {
document.getElementById( 'stopButton' ).disabled = true ;
__pdp11.break = true ;
} ;
/**
*
*/
var stopAtBreakPoint = function( ) {
document.getElementById( 'stopButton' ).disabled = true ;
document.getElementById( 'nextStepButton' ).disabled = false ;
document.getElementById( 'continueButton' ).disabled = false ;
document.getElementById( 'virtualAddressButton' ).disabled = false ;
document.getElementById( 'physicalAddressButton' ).disabled = false ;
} ;
/**
*
*/
var nextStep = function( ) {
document.getElementById( 'stopButton' ).disabled = false ;
document.getElementById( 'nextStepButton' ).disabled = true ;
document.getElementById( 'continueButton' ).disabled = true ;
document.getElementById( 'virtualAddressButton' ).disabled = true ;
document.getElementById( 'physicalAddressButton' ).disabled = true ;
__pdp11.resume( ) ;
} ;
/**
* TODO: function name
*/
var continueStep = function( ) {
document.getElementById( 'stopButton' ).disabled = false ;
document.getElementById( 'nextStepButton' ).disabled = true ;
document.getElementById( 'continueButton' ).disabled = true ;
document.getElementById( 'virtualAddressButton' ).disabled = true ;
document.getElementById( 'physicalAddressButton' ).disabled = true ;
__pdp11.break = false ;
__pdp11.resume( ) ;
} ;
/**
*
*/
var displayInitialMessage = function( ) {
__terminalView.outputLine( 'Drag and drop your UNIX V6 disk image here or' ) ;
__terminalView.outputLine( 'press the "load UNIX V6 Disk image" button to run UNIX V6.' ) ;
__terminalView.outputLine( '' ) ;
__terminalView.outputLine( 'Type "rkunix" slowly (\'cuz some reasons) when "@" is displayed.' ) ;
__terminalView.outputLine( 'And then, type "root" when "login: " is displayed.' ) ;
__terminalView.outputLine( '' ) ;
__terminalView.outputLine( 'Note that, use "#" instead of backspace.' ) ;
__terminalView.outputLine( 'And use "chdir" instead of "cd".' ) ;
__terminalView.outputLine( '' ) ;
__terminalView.outputLine( 'I confirmed only it runs on the combination of Windows and Chrome.' ) ;
__terminalView.outputLine( '' ) ;
__terminalView.outputLine( ' ' +
'Enjoy UNIX V6 on your web browser! -- Takahiro(@superhoge)' ) ;
__terminalView.outputLine( '' ) ;
} ;
/**
*
*/
var showDebugger = function( ) {
var span = document.getElementById( 'debuggerSpan' ) ;
if( span.style.cssText == '' ) {
span.style.cssText = 'display: none' ;
} else {
span.style.cssText = '' ;
} ;
} ;
/**
* TODO: duplicated codes.
*/
var loadVirtualAddress = function( ) {
var address = Number( document.getElementById( 'memoryAddressInput' ).value ) ;
if( isNaN( address ) )
return ;
var buffer = 'v_address:' + format( address ) + ' ' +
'p_address:' + format( __pdp11.mmu._convert( address, true ), 5 ) + ' ' +
'value:' + format( __pdp11.mmu.loadWord( address, true ) ) ;
__debugView.outputLine( buffer ) ;
} ;
/**
* TODO: duplicated codes.
*/
var loadPhysicalAddress = function( ) {
var address = Number( document.getElementById( 'memoryAddressInput' ).value ) ;
if( isNaN( address ) )
return ;
var buffer = 'p_address:' + format( address ) + ' ' +
'value:' + format( __pdp11.mmu.loadWordByPhysicalAddress( address ), 5 ) ;
__debugView.outputLine( buffer ) ;
} ;
/**
*
*/
var flushLog = function( ) {
if( __logger.getUrl == undefined )
return ;
var span = document.getElementById( 'traceLogSpan' ) ;
while( span.firstChild )
span.removeChild( span.firstChild )
var a = document.createElement( 'a' ) ;
a.download = 'log' ;
a.href = __logger.getUrl( ) ;
a.textContent = 'log' ;
span.appendChild( a ) ;
} ;
window.addEventListener( 'drop', dropDiskImage, false ) ;
window.addEventListener( 'dragover', dragOver, false ) ;
</script>
</head>
<body onLoad="init( )">
<p>
<ul>
<li>Introduction
<ul>
<li>This is the PDP11 emulator with JavaScript implemented by <a href="https://twitter.com/superhoge">takahiro(@superhoge)</a></li>
<li>You can run UNIX V6 on your web browser.</li>
<li><a href="http://d.hatena.ne.jp/takahirox/20130801/1375334305">See this page for the detail.</a></li>
<li><a href="http://www.youtube.com/watch?v=CsSPiM07amg">This is the demonstration video</a></li>
<li><a href="http://d.hatena.ne.jp/takahirox/20121214/1355490840">If you wanna study UNIX V6 kernel...</a></li>
</ul>
</li>
<li>UNIX V6 Tips
<ul>
<li>Type "rkunix" slowly ('cuz some reasons) when "@" is displayed.</li>
<li>Type "root" when "login: " is displayed.</li>
<li>Use "#" instead of backspace.</li>
<li>Use "chdir" instead of "cd".</li>
<li>Use "ed" to edit a file.</li>
</ul>
</li>
</ul>
</p>
<p>
<button id="loadV6Button" onclick="loadUnixV6DiskImage( )">load UNIX V6 Disk image</button>
<button id="exportButton" onclick="exportDiskImage( )">export Disk image</button>
<button id="resetButton" onclick="resetPdp11( )">reset</button>
<span id="diskImageSpan"></span>
<span id="traceLogSpan"></span>
</p>
<p>
<textarea id="terminalView" cols="80" rows="20" readonly="readonly" onkeypress="inputTerminalByKeypress( event )" onkeydown="inputTerminalByKeydown( event )"> </textarea>
</p>
<p>
<input type="text" id="androidInput" size="30" onchange="inputTerminalForAndroid( )" />
Input area for Android
</p>
<p>
show debugger (under construction)
<input type="checkbox" id="showDebuggerCheck" onchange="showDebugger( )" />
</p>
<span id="debuggerSpan" style="display: none">
<p>
instruction
<input type="checkbox" id="instructionCheck" onclick="changeDebugFlags( )" />
trap
<input type="checkbox" id="trapCheck" onclick="changeDebugFlags( )" />
interrupt
<input type="checkbox" id="interruptCheck" onclick="changeDebugFlags( )" />
system call
<input type="checkbox" id="systemCallCheck" onclick="changeDebugFlags( )" />
kernel symbol
<input type="checkbox" id="kernelSymbolCheck" onclick="changeDebugFlags( )" />
</p>
<p>
<input id="breakPointInput" type="text" size="10" />
<button onclick="addBreakPoint( )">add break point</button>
break points
<select id="breakPointsSelect">
</select>
<button onclick="removeBreakPoint( )">remove break point</button>
</p>
<p>
<button id="stopButton" onclick="stopPdp11( )">stop</button>
<button id="nextStepButton" onclick="nextStep( )">next step</button>
<button id="continueButton" onclick="continueStep( )">continue</button>
<input type="text" size="10" id="memoryAddressInput" />
<button id="virtualAddressButton" onclick="loadVirtualAddress( )">virtual address</button>
<button id="physicalAddressButton" onclick="loadPhysicalAddress( )">physical address</button>
</p>
<p>
<textarea id="debugView" cols="80" rows="21" readonly="readonly"> </textarea>
<canvas id="debugCanvas" width="50" height="250" />
</p>
<p>
<textarea id="pdp11View" cols="64" rows="15" readonly="readonly"> </textarea>
<textarea id="stackView" cols="12" rows="15" readonly="readonly"> </textarea>
</p>
</span>
</body>
</html>