From 99147966a0f64a9ce4ef74b2f2680077badb0d48 Mon Sep 17 00:00:00 2001 From: Bill Lord Date: Sat, 20 Jan 2018 22:39:32 -0600 Subject: [PATCH] cpu: fix error in shift opcodes --- src/Chip8.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Chip8.cpp b/src/Chip8.cpp index db7400d..0b4e955 100644 --- a/src/Chip8.cpp +++ b/src/Chip8.cpp @@ -110,16 +110,16 @@ void Chip8::step() { state.v[x(opcode)] -= state.v[y(opcode)]; } else if (opidx(opcode) == 0x8 && nibble(opcode) == 0x6) { // If the least-significant bit of Vx is 1, then VF is set to 1, otherwise 0. Then Vx is divided by 2. - state.v[0xF] = state.v[x(opcode)] & 1; - state.v[x(opcode)] >>= 1; + state.v[0xF] = state.v[y(opcode)] & 1; + state.v[x(opcode)] = state.v[y(opcode)] >> 1; } else if (opidx(opcode) == 0x8 && nibble(opcode) == 0x7) { // sub Vx from Vy and store result in Vx, VF is 1 if Vy > Vx state.v[0xF] = state.v[y(opcode)] > state.v[x(opcode)]; state.v[x(opcode)] = state.v[y(opcode)] - state.v[x(opcode)]; } else if (opidx(opcode) == 0x8 && nibble(opcode) == 0x6) { // If the most-significant bit of Vx is 1, then VF is set to 1, otherwise to 0. Then Vx is multiplied by 2. - state.v[0xF] = (state.v[x(opcode)] & 0b10000000) >> 7; - state.v[x(opcode)] <<= 1; + state.v[0xF] = (state.v[y(opcode)] & 0b10000000) >> 7; + state.v[x(opcode)] = state.v[y(opcode)] << 1; } else if (opidx(opcode) == 0x9 && nibble(opcode) == 0x0) { // Skip next instruction if Vx != Vy if (state.v[x(opcode)] != state.v[y(opcode)]) {