-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.js
127 lines (102 loc) · 3.4 KB
/
console.js
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
// for display instructions executed
// prints output to web ui
// all ui events are written here
function printInstruction(str){
var formattedOut = '';
for(var i = 0; i < str.length;i++)
formattedOut += '<span style="background-color: lightgrey;">'+str[i]+'</span>'; document.getElementById('executed_instruction').innerHTML = formattedOut;
}
function printRegisterContent(regs){
// var data = '<tr><th>Register</th><th>Value</th></tr>';
var headers = '<tr>',data='<tr>';
for(var i = 0; i < regs.length;i++){
// data += '<tr>'+'<td>R'+i+'</td>'+'<td>'+regs[i]+'</td>'+'</tr>';
headers += '<th>R'+i+'</th>';
data += '<td>'+regs[i]+'</td>';
}
headers += '</tr>';
data +='</tr>';
document.getElementById('register_content').innerHTML = headers+data;
}
function openFile(){
showDropBox();
}
function showDropBox(){
document.getElementById('fileDropBox').style.display = "block";
}
function hideDropBox(){
document.getElementById('fileDropBox').style.display = "none";
}
function readFileContent(event){
"use strict";
var file = event.target.files[0];
if(file){
var reader = new FileReader();
reader.onload = function(e){
var contents = e.target.result;
var program = new Uint8Array(contents);
for(var i = 0; i < program.length;i++)
mem[i] = program[i]; // temp fix
setBeginningConfig();
notify('Success','File read');
}
reader.readAsArrayBuffer(file);
}else{
alert('Failed to load file');
}
hideDropBox();
}
function resizeUint8(baseArrayBuffer, newByteSize) {
var resizedArrayBuffer = new ArrayBuffer(newByteSize),
len = baseArrayBuffer.byteLength,
resizeLen = (len > newByteSize)? newByteSize : len;
(new Uint8Array(resizedArrayBuffer, 0, resizeLen)).set(new Uint8Array(baseArrayBuffer, 0, resizeLen));
return resizedArrayBuffer;
}
function setBeginningConfig(){
regs[13] = mem[0] | mem[1]<<8 | mem[2]<<16 | mem[3]<<24;
regs[15] = (mem[4] | mem[5]<<8 | mem[6]<<16 | mem[7]<<24) + 4; // point two words ahead
}
function addEventListeners(){
document.getElementById('filesIn').addEventListener('change',readFileContent,true);
document.addEventListener('DOMContentLoaded', function () {
if (Notification.permission !== "granted")
Notification.requestPermission();
});
printRegisterContent(regs);
//testcode();
}
// for testing software interrupts
function testcode(){
regs[0] = 120;
regs[1] = 10;
var instr = (0xdf << 8) | 2;
softwareInterrupt(instr);
regs[0] = 120;
var instr = (0xdf << 8) | 5;
softwareInterrupt(instr)
}
function notify(title,prompt){
if(!Notification){
alert('Desktop notifications not available');
return;
}
if(Notification.permission !== "granted")
Notification.requestPermission();
else{
var notification = new Notification(title, {
body: prompt,
});
}
}
function printProgramOut(instr){
document.getElementById("program_output").innerHTML += instr + "</br>";
}
function disableExecutionButtons(){
var start = document.getElementById('start_button');
var stop = document.getElementById('stop_button');
var step = document.getElementById('step_button');
start.disabled = true;
stop.disabled = true;
step.disabled = true;
}