Fix a instruction from overflowing indexReg

This commit is contained in:
Miguel Angel 2024-09-06 14:37:24 +02:00
parent bab8065322
commit 0b71b99b79

View File

@ -222,7 +222,7 @@ class CPU {
case 0x8: { case 0x8: {
if(nib4 == 0x0) { if(nib4 == 0x0) {
// 8XY0 // 8XY0
// Vx |= Vy // Vx = Vy
this.regs[nib2] = this.regs[nib3]; this.regs[nib2] = this.regs[nib3];
this.incrementPC(); this.incrementPC();
}else if(nib4 == 0x1) { }else if(nib4 == 0x1) {
@ -307,7 +307,7 @@ class CPU {
break; break;
case 0xB:{ case 0xB:{
// BNNN // BNNN
// Jumps to the address NNN plus V0 // Jumps to the address (NNN + V0)
let address = opcode & 0x0FFF; let address = opcode & 0x0FFF;
this.pc = this.regs[0] + address; this.pc = this.regs[0] + address;
} }
@ -406,12 +406,13 @@ class CPU {
// I += Vx // I += Vx
// Adds VX to I. VF is not affected // Adds VX to I. VF is not affected
this.indexReg += this.regs[nib2]; this.indexReg += this.regs[nib2];
this.indexReg = this.indexReg & 0xFFFF;
this.incrementPC(); this.incrementPC();
}else if(secondOpcode == 0x29) { }else if(secondOpcode == 0x29) {
// FX29 // FX29
// I = sprite_addr[Vx] // I = sprite_addr[Vx]
// Sets I to the location of the sprite for the character in 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(); this.incrementPC();
}else if(secondOpcode == 0x33) { }else if(secondOpcode == 0x33) {
// FX33 // FX33