Skip to content

Commit

Permalink
Add opcode 0x0XXX and some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Snarr committed Nov 3, 2023
1 parent 2e0c2c2 commit 64436b5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions emulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ let default_font = [0b11110000,0b10010000,0b10010000,0b10010000,0b11110000,0b001
class CHIP8_Emulator {
constructor() {
this.RAM = new Uint8Array(0x1000).fill(0x00);
this.PC = 0x0200;
this.SP = 0x00;
this.PC = 0x0200; // Program counter
this.SP = 0x00; // Stack pointer
this.I = 0x0000;
this.DT = 0x0;
this.ST = 0x0;
this.DT = 0x0; // Delay timer
this.ST = 0x0; // Sound timer
this.vRegisters = new Uint8Array(16).fill(0x00);

this.DISPLAY = new Array(32)
for (let i = 0; i < 32; i++) {
this.DISPLAY[i] = new Array(64).fill(0);
Expand Down Expand Up @@ -57,7 +58,7 @@ class CHIP8_Emulator {
}
} else if (opcode == 0x00EE) {
// Return from a subroutine
}else if (firstByte == 0x1) {
} else if (firstByte == 0x1) {
// Jump to location nnn
this.PC = getNNN(opcode);
} else if (firstByte == 0x2) {
Expand Down Expand Up @@ -167,14 +168,17 @@ class CHIP8_Emulator {
let kk = getKK(opcode);
if (kk == 0x9E) {
// Skip next instruction if key with the value of Vx is pressed

} else if (kk == 0xA1) {
// Skip next instruction if key with the value of Vx is not pressed.
} else {
return 0;
}
} else if (firstByte == 0xF) {

} else if (firstByte == 0x0) {
// Jump to a machine code routine at nnn
// Ignored by modern interpreters
} else {
console.log("Invalid opcode", opcode)
return 0;
Expand Down

0 comments on commit 64436b5

Please sign in to comment.