diff --git a/src/cpu.ts b/src/cpu.ts index 53d827c..9141d1f 100644 --- a/src/cpu.ts +++ b/src/cpu.ts @@ -11,15 +11,15 @@ const STACK_SIZE = 16; const REGISTERS = 16; class CPU { - pc: number; // 16b - indexReg: number; // 16b + pc: number; // 16b + indexReg: number; // 16b regs: Uint8Array; - delayTimer: number; // 8b - soundTimer: number; // 8b + delayTimer: number; // 8b + soundTimer: number; // 8b - stackPointer: number; // 16b - stack: Uint16Array; + stackPointer: number; // 16b + stack: Uint16Array; // 16b memory: Uint8Array; displayMemory: Uint8Array; @@ -27,9 +27,7 @@ class CPU { keyboard: Keyboard; audio: Chip8Audio; - - rng: RNG; - + rng: RNG; constructor(keyboard: Keyboard, audio: Chip8Audio) { this.memory = new Uint8Array(MEMORY_SIZE); @@ -77,7 +75,7 @@ class CPU { private setupFont() { - // Using address from 050 - 09F ?? + // Using address from 050 - 09F let addressFont = 0x050; // Every character has 5 Bytes @@ -104,7 +102,7 @@ class CPU { } public loadRom(rom: Uint8Array) { - // Loads a ROM into starting PC addres?? + // Loads a ROM into starting PC address console.log(rom); for(let i = 0; i < rom.length; i++) { this.memory[this.pc+i] = rom[i]; @@ -283,8 +281,8 @@ class CPU { // Vx <<= 1 // Set VF to 1 if the most significant bit of VX. // Then shift to the left Vx - this.regs[0xF] = (this.regs[nib2]) >> 7; - this.regs[nib2] = (this.regs[nib2] << 1); + this.regs[0xF] = (this.regs[nib2]) >> 7; // Get msb + this.regs[nib2] = (this.regs[nib2] << 1) & 0xFF; this.incrementPC(); } @@ -391,7 +389,7 @@ class CPU { } if(!keyPressed) - return; // NOT INCREMENT PC SO WE ARE STUCK IN THIS WAITING + return; // NOT INCREMENT PC SO WE ARE STUCK IN THIS WAITING (also don't decrement timers???) this.incrementPC(); }else if(secondOpcode == 0x15) {