From 0b71b99b792e050941f79555571678c0ad88aa72 Mon Sep 17 00:00:00 2001 From: MichaelValwin Date: Fri, 6 Sep 2024 14:37:24 +0200 Subject: [PATCH] Fix a instruction from overflowing indexReg --- src/cpu.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cpu.ts b/src/cpu.ts index cd505cd..02e3428 100644 --- a/src/cpu.ts +++ b/src/cpu.ts @@ -222,7 +222,7 @@ class CPU { case 0x8: { if(nib4 == 0x0) { // 8XY0 - // Vx |= Vy + // Vx = Vy this.regs[nib2] = this.regs[nib3]; this.incrementPC(); }else if(nib4 == 0x1) { @@ -307,7 +307,7 @@ class CPU { break; case 0xB:{ // BNNN - // Jumps to the address NNN plus V0 + // Jumps to the address (NNN + V0) let address = opcode & 0x0FFF; this.pc = this.regs[0] + address; } @@ -406,12 +406,13 @@ class CPU { // I += Vx // Adds VX to I. VF is not affected this.indexReg += this.regs[nib2]; + this.indexReg = this.indexReg & 0xFFFF; this.incrementPC(); }else if(secondOpcode == 0x29) { // FX29 // I = sprite_addr[Vx] // Sets I to the location of the sprite for the character in VX - this.indexReg = this.regs[nib2] * 0x5; // ?? + this.indexReg = this.regs[nib2] * 0x5; this.incrementPC(); }else if(secondOpcode == 0x33) { // FX33