-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
50 lines (42 loc) · 1.37 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
<!DOCTYPE html>
<html>
<head>
<title>JS Chip 8 Emulator</title>
<link rel="stylesheet" href="style.css"></link>
</head>
<body>
<div id="main">
<h1>Chip-8 Emulator by Jason Brown</h1>
<canvas id="screen" style="border:1px solid #000"></canvas>
</div>
<script src="chip8.js"></script>
<script>
(function() {
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
window.requestAnimationFrame = requestAnimationFrame;
})();
var chip = new chip8();
document.addEventListener("keydown", function(e) {
chip.keys[chip.keyMap[e.keyCode]] = true;
chip.currentKey = chip.keyMap[e.keyCode];
});
document.addEventListener("keyup", function(e) {
chip.keys[chip.keyMap[e.keyCode]] = false;
chip.currentKey = false;
});
function loadRom(){
// Load a rom.
var xhr = new XMLHttpRequest;
xhr.open("GET", "roms/Chip8 Picture.ch8", true);
xhr.responseType = "arraybuffer";
xhr.onload = function () {
var rom = new Uint8Array(xhr.response);
chip.loadRom(rom);
};
xhr.send();
}
loadRom();
</script>
</body>
</html>