-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (38 loc) · 1.12 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
40
41
42
43
import Emulator from "./emulator.js";
import Renderer from "./browser/renderer.js";
import Controller from "./browser/controller.js";
import Loader from "./browser/loader.js";
import Speaker from "./browser/speaker.js";
const renderer = new Renderer("canvas");
const controller = new Controller();
const loader = new Loader();
const speaker = new Speaker();
const emulator = new Emulator(controller, renderer, speaker, loader);
let fpsInterval, lastTime;
function step(currentTime) {
if (currentTime - lastTime < fpsInterval) {
window.requestAnimationFrame(step);
return;
}
lastTime = currentTime;
emulator.step();
window.requestAnimationFrame(step);
}
function main(fps) {
console.log(
"Github repository: https://github.com/songquanpeng/chip8-emulator"
);
lastTime = 0;
fpsInterval = 1000 / fps;
emulator.speed = 20;
const params = new URLSearchParams(window.location.search);
let rom = "BLINKY";
if (params.has("rom")) {
rom = params.get("rom");
}
emulator.controller.adjustKeyMapping(rom);
emulator.loadRom(`/rom/${rom}`).then(() => {
window.requestAnimationFrame(step);
});
}
main(60);