1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-11-18 15:06:35 +00:00

Add support for 65C02 opcode 0x89 (BIT immediate)

This commit is contained in:
Mike Naberezny 2012-11-22 14:27:33 -08:00
parent 222c324fa6
commit e48058e7c1
3 changed files with 63 additions and 0 deletions

View File

@ -11,6 +11,8 @@
- Fixed a bug where the MPU status display would wrap unexpectedly
on some terminals.
- Added support for 65C02 opcode 0x89 (BIT immediate).
0.13 (2012-11-15)
- Fixed a bug where negative numbers could be entered

View File

@ -159,6 +159,16 @@ class MPU(mpu6502.MPU):
self.opSMB(self.ZeroPageAddr, 0x01)
self.pc += 1
@instruction(name="BIT", mode="imm", cycles=2)
def inst_0x89(self):
# This instruction (BIT #$12) does not use opBIT because in the
# immediate mode, BIT only affects the Z flag.
tbyte = self.ImmediateByte()
self.p &= ~(self.ZERO)
if (self.a & tbyte) == 0:
self.p |= self.ZERO
self.pc += 1
@instruction(name="STA", mode="zpi", cycles=5)
def inst_0x92(self):
self.opSTA(self.ZeroPageIndirectAddr)

View File

@ -280,6 +280,57 @@ class MPUTests(unittest.TestCase, Common6502Tests):
self.assertEqual(4, mpu.processorCycles)
self.assertEqual(0x0003, mpu.pc)
# BIT (Immediate)
def test_bit_imm_does_not_affect_n_and_z_flags(self):
mpu = self._make_mpu()
mpu.p |= mpu.NEGATIVE | mpu.OVERFLOW
# $0000 BIT #$FF
self._write(mpu.memory, 0x0000, (0x89, 0xff))
mpu.a = 0x00
mpu.step()
self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE)
self.assertEqual(mpu.OVERFLOW, mpu.p & mpu.OVERFLOW)
self.assertEqual(0x00, mpu.a)
self.assertEqual(2, mpu.processorCycles)
self.assertEqual(0x02, mpu.pc)
def test_bit_imm_stores_result_of_and_in_z_preserves_a_when_1(self):
mpu = self._make_mpu()
mpu.p &= ~mpu.ZERO
# $0000 BIT #$00
self._write(mpu.memory, 0x0000, (0x89, 0x00))
mpu.a = 0x01
mpu.step()
self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO)
self.assertEqual(0x01, mpu.a)
self.assertEqual(2, mpu.processorCycles)
self.assertEqual(0x02, mpu.pc)
def test_bit_imm_stores_result_of_and_when_nonzero_in_z_preserves_a(self):
mpu = self._make_mpu()
mpu.p |= mpu.ZERO
# $0000 BIT #$01
self._write(mpu.memory, 0x0000, (0x89, 0x01))
mpu.a = 0x01
mpu.step()
self.assertEqual(0, mpu.p & mpu.ZERO) # result of AND is non-zero
self.assertEqual(0x01, mpu.a)
self.assertEqual(2, mpu.processorCycles)
self.assertEqual(0x02, mpu.pc)
def test_bit_imm_stores_result_of_and_when_zero_in_z_preserves_a(self):
mpu = self._make_mpu()
mpu.p &= ~(mpu.ZERO)
# $0000 BIT #$00
self._write(mpu.memory, 0x0000, (0x89, 0x00))
mpu.a = 0x01
mpu.step()
self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) # result of AND is zero
self.assertEqual(0x01, mpu.a)
self.assertEqual(2, mpu.processorCycles)
self.assertEqual(0x02, mpu.pc)
# BIT (Zero Page, X-Indexed)
def test_bit_zp_x_copies_bit_7_of_memory_to_n_flag_when_0(self):