Skip to content

Commit 460ac4f

Browse files
authored
Fix right shift bit one bug. (#49)
1 parent bb3b55a commit 460ac4f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

chip8/cpu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ def right_shift_reg(self):
699699
self.v[0xF] = bit_one
700700
self.last_op = f"SHR V{x:01X}"
701701
else:
702-
bit_one = self.v[x] & 0x1
702+
bit_one = self.v[y] & 0x1
703703
self.v[x] = self.v[y] >> 1
704704
self.v[0xF] = bit_one
705705
self.last_op = f"SHR V{x:01X}, V{y:01X}"

test/test_chip8cpu.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,15 @@ def test_right_shift_reg(self):
399399
self.assertEqual(self.cpu.v[x], shifted_val)
400400
self.assertEqual(self.cpu.v[0xF], bit_zero)
401401

402+
def test_right_shift_reg_y_bug(self):
403+
self.cpu.shift_quirks = False
404+
self.cpu.operand = 0x0120
405+
self.cpu.v[1] = 0
406+
self.cpu.v[2] = 1
407+
self.cpu.right_shift_reg()
408+
self.assertEqual(0, self.cpu.v[1])
409+
self.assertEqual(1, self.cpu.v[0xF])
410+
402411
def test_subtract_reg_from_reg1(self):
403412
for x in range(0xF):
404413
for y in range(0xF):

0 commit comments

Comments
 (0)