-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
180 lines (160 loc) · 5.7 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>8086 Emulator</title>
<style>
body {
display: flex;
height: 100vh;
margin: 0;
}
.left-panel {
width: 40%;
border-right: 1px solid #ccc;
padding: 10px;
box-sizing: border-box;
}
.right-panel {
width: 60%;
display: flex;
flex-direction: column;
padding: 10px;
box-sizing: border-box;
}
.registers,
.memory {
flex: 1;
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ccc;
box-sizing: border-box;
overflow: auto;
}
.registers {
margin-bottom: 10px;
}
textarea {
width: 100%;
height: calc(100% - 50px);
box-sizing: border-box;
}
.button-container {
margin-bottom: 10px;
}
button {
margin-right: 5px;
}
</style>
</head>
<body>
<div class="left-panel">
<div class="button-container">
<button id="buildButton">Build</button>
<button id="stepButton">Step</button>
<button>Run</button>
</div>
<textarea id="codeInput">start:
mov ax, 1h
mov bx, 2h
inc cx
jmp start</textarea>
</div>
<div class="right-panel">
<div class="registers" id="registers">
<h3>8086 Registers</h3>
<pre id="registersOutput">No data yet</pre>
</div>
<div class="memory">
<h3>Memory</h3>
<pre id="memoryOutput">No data yet</pre>
</div>
</div>
<script>
let currentLine = 0;
document.getElementById('buildButton').addEventListener('click', () => {
const codeInput = document.getElementById('codeInput');
const lines = codeInput.value.split('\n');
currentLine = 0;
clearHighlight(codeInput);
if (lines) {
fetch('http://127.0.0.1:8080/build', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ code: lines })
})
.then(response => response.json())
.then(data => {
displayRegisters(data);
displayMemory(data);
})
.catch(error => {
console.error('Network error:', error);
});
}
});
document.getElementById('stepButton').addEventListener('click', () => {
const codeInput = document.getElementById('codeInput');
const lines = codeInput.value.split('\n');
if (currentLine < lines.length) {
fetch('http://127.0.0.1:8080/step', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ line: currentLine })
})
.then(response => response.json())
.then(data => {
displayRegisters(data);
displayMemory(data);
currentLine = data.nextline;
})
.catch(error => {
console.error('Network error:', error);
});
highlightLine(codeInput, currentLine);
} else {
console.log('No more lines to send.');
}
});
function displayRegisters(data) {
const registersOutput = document.getElementById('registersOutput');
registersOutput.textContent = `
AX: ${parseInt(data.AX, 10).toString(16).toUpperCase().padStart(4, '0')}
BX: ${parseInt(data.BX, 10).toString(16).toUpperCase().padStart(4, '0')}
CX: ${parseInt(data.CX, 10).toString(16).toUpperCase().padStart(4, '0')}
DX: ${parseInt(data.DX, 10).toString(16).toUpperCase().padStart(4, '0')}
SI: ${parseInt(data.SI, 10).toString(16).toUpperCase().padStart(4, '0')}
DI: ${parseInt(data.DI, 10).toString(16).toUpperCase().padStart(4, '0')}
BP: ${parseInt(data.BP, 10).toString(16).toUpperCase().padStart(4, '0')}
SP: ${parseInt(data.SP, 10).toString(16).toUpperCase().padStart(4, '0')}
CS: ${parseInt(data.CS, 10).toString(16).toUpperCase().padStart(4, '0')}
DS: ${parseInt(data.DS, 10).toString(16).toUpperCase().padStart(4, '0')}
ES: ${parseInt(data.ES, 10).toString(16).toUpperCase().padStart(4, '0')}
SS: ${parseInt(data.SS, 10).toString(16).toUpperCase().padStart(4, '0')}
IP: ${parseInt(data.IP, 10).toString(16).toUpperCase().padStart(4, '0')}
FLAGS: ${parseInt(data.FLAGS, 10).toString(16).toUpperCase().padStart(4, '0')}
`;
}
function displayMemory(data) {
const memoryOutput = document.getElementById('memoryOutput');
memoryOutput.textContent = data.memory || "No memory data";
}
function highlightLine(textarea, line) {
const lines = textarea.value.split('\n');
const start = lines.slice(0, line).join('\n').length + (line > 0 ? 1 : 0);
const end = start + lines[line].length;
textarea.setSelectionRange(start, end);
textarea.focus();
}
function clearHighlight(textarea) {
textarea.setSelectionRange(0, 0);
textarea.blur();
}
</script>
</body>
</html>