-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.js
39 lines (39 loc) · 1.23 KB
/
main.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
var oReq = new XMLHttpRequest();
oReq.open("GET", "invaders.rom", true);
oReq.responseType = "arraybuffer";
var processor = new cpu.Intel8080();
var canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 224;
var container = document.createElement("div");
container.id = 'container';
container.appendChild(canvas);
document.body.appendChild(container);
var context = canvas.getContext("2d");
var screen = new video.Screen(processor, context, canvas.width, canvas.height, false, 0);
var input = new io.Input(document, this, processor);
input.init();
processor.setInput(input);
oReq.onload = function (oEvent) {
var arrayBuffer = oReq.response;
if(arrayBuffer) {
var source = new Uint8Array(arrayBuffer);
if(source.length > 8192) {
throw new Error("Bad rom size!");
}
var byteArray = new ArrayBuffer(16384);
var view = new Uint8Array(byteArray);
view.set(source);
processor.memory = view;
processor.init();
var id = setInterval(run, 16);
input.interval = id;
}
};
function run() {
input.update();
processor.Run();
screen.render();
}
oReq.send(null);
//@ sourceMappingURL=main.js.map