Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
cpu: fix error in shift opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Lord committed Jan 21, 2018
1 parent 642132f commit 9914796
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Chip8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)]) {
Expand Down

0 comments on commit 9914796

Please sign in to comment.