Hey, you asked for a code review, I'll go through your code and review it in this issue. I'll start with chip8.js
.
Your entire time measuring system is broken:
function step() {
now = Date.now()
elapsed = now - then
if (elapsed > fpsInterval) {
cpu.cycle()
}
loop = requestAnimationFrame(step)
}
You never re-assign then
, so the condition is always true, so first of all you might as well do this:
function step() {
cpu.cycle()
loop = requestAnimationFrame(step)
}
This is actually already a slight improvement on your code, and since browsers will typically run requestAnimationFrame
60 times per second, it works just fine for display. You already do multiple clock cycles in one cycle()
call anyway with this.speed
in the CPU, so the actual CPU speed isn't locked by this change.
That's all I have to say about timing, I'll do more in another comment.