From 9d59f057d376501e03e4e3bba83bedb06a8f7f67 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Mon, 8 May 2017 17:08:38 -0700 Subject: [PATCH] Fix Z flag handling for TSB and TRB. Closes #32 --- CHANGES.txt | 3 +++ py65/devices/mpu65c02.py | 4 ++-- py65/tests/devices/test_mpu65c02.py | 16 ++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 824af3e..edabb21 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,9 @@ allow the addresses of the ``getc`` and ``putc`` handlers to be changed. Patch by Mario Keller. + - Fixed a 65C02 bug where the TSB and TRB instructions did not set + the Z flag correctly. Thanks to Kris Kennaway for reporting it. + 0.24 (2015-03-31) - Released as a universal wheel. diff --git a/py65/devices/mpu65c02.py b/py65/devices/mpu65c02.py index 7d685d9..ef37f74 100644 --- a/py65/devices/mpu65c02.py +++ b/py65/devices/mpu65c02.py @@ -50,7 +50,7 @@ class MPU(mpu6502.MPU): m = self.memory[address] self.p &= ~self.ZERO z = m & self.a - if z != 0: + if z == 0: self.p |= self.ZERO self.memory[address] = m | self.a @@ -59,7 +59,7 @@ class MPU(mpu6502.MPU): m = self.memory[address] self.p &= ~self.ZERO z = m & self.a - if z != 0: + if z == 0: self.p |= self.ZERO self.memory[address] = m & ~self.a diff --git a/py65/tests/devices/test_mpu65c02.py b/py65/tests/devices/test_mpu65c02.py index 0dc4e5f..79e779e 100644 --- a/py65/tests/devices/test_mpu65c02.py +++ b/py65/tests/devices/test_mpu65c02.py @@ -1227,7 +1227,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0xE0, mpu.memory[0x00BB]) mpu.step() self.assertEqual(0xF0, mpu.memory[0x00BB]) - self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) + self.assertEqual(0, mpu.p & mpu.ZERO) self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -1240,7 +1240,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0x80, mpu.memory[0x00BB]) mpu.step() self.assertEqual(0xE0, mpu.memory[0x00BB]) - self.assertEqual(0, mpu.p & mpu.ZERO) + self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -1255,7 +1255,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0xE0, mpu.memory[0xFEED]) mpu.step() self.assertEqual(0xF0, mpu.memory[0xFEED]) - self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) + self.assertEqual(0, mpu.p & mpu.ZERO) self.assertEqual(0x0003, mpu.pc) self.assertEqual(6, mpu.processorCycles) @@ -1268,7 +1268,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0x80, mpu.memory[0xFEED]) mpu.step() self.assertEqual(0xE0, mpu.memory[0xFEED]) - self.assertEqual(0, mpu.p & mpu.ZERO) + self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0x0003, mpu.pc) self.assertEqual(6, mpu.processorCycles) @@ -1283,7 +1283,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0xE0, mpu.memory[0x00BB]) mpu.step() self.assertEqual(0x80, mpu.memory[0x00BB]) - self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) + self.assertEqual(0, mpu.p & mpu.ZERO) self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -1296,7 +1296,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0x80, mpu.memory[0x00BB]) mpu.step() self.assertEqual(0x80, mpu.memory[0x00BB]) - self.assertEqual(0, mpu.p & mpu.ZERO) + self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0x0002, mpu.pc) self.assertEqual(5, mpu.processorCycles) @@ -1311,7 +1311,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0xE0, mpu.memory[0xFEED]) mpu.step() self.assertEqual(0x80, mpu.memory[0xFEED]) - self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) + self.assertEqual(0, mpu.p & mpu.ZERO) self.assertEqual(0x0003, mpu.pc) self.assertEqual(6, mpu.processorCycles) @@ -1324,7 +1324,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0x80, mpu.memory[0xFEED]) mpu.step() self.assertEqual(0x80, mpu.memory[0xFEED]) - self.assertEqual(0, mpu.p & mpu.ZERO) + self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0x0003, mpu.pc) self.assertEqual(6, mpu.processorCycles)