1
0
mirror of https://github.com/mnaberez/py65.git synced 2025-04-05 13:37:09 +00:00

Added PHX, PHY, PLX, PLY.

This commit is contained in:
Mike Naberezny 2009-04-07 19:23:24 -07:00
parent 9d7615a17e
commit fb8311b94b
2 changed files with 112 additions and 0 deletions

View File

@ -22,6 +22,10 @@ class MPU(NMOS6502):
# instructions
@instruction(0x5a, 3)
def i5a(self):
self.stPush(self.y)
@instruction(0x64, 3)
def i64(self):
self.opSTZ(self.ZeroPageAddr)
@ -32,6 +36,11 @@ class MPU(NMOS6502):
self.opSTZ(self.ZeroPageXAddr)
self.pc += 1
@instruction(0x7a, 4)
def ifa(self):
self.y = self.stPop()
self.FlagsNZ(self.y)
@instruction(0x9c, 4)
def i9c(self):
self.opSTZ(self.AbsoluteAddr)
@ -42,3 +51,11 @@ class MPU(NMOS6502):
self.opSTZ(self.AbsoluteXAddr)
self.pc+=2
@instruction(0xda, 3)
def i5a(self):
self.stPush(self.x)
@instruction(0xfa, 4)
def ifa(self):
self.x = self.stPop()
self.FlagsNZ(self.x)

View File

@ -12,6 +12,60 @@ class MPUTests(unittest.TestCase, Common6502Tests):
self.assertEquals('<65C02: A=00, X=00, Y=00, Flags=20, SP=ff, PC=0000>',
repr(mpu))
# PHX
def test_phx_pushes_x_and_updates_sp(self):
mpu = self._make_mpu()
mpu.x = 0xAB
mpu.memory[0x0000] = 0xDA #=> PHX
mpu.step()
self.assertEquals(0x0001, mpu.pc)
self.assertEquals(0xAB, mpu.x)
self.assertEquals(0xAB, mpu.memory[0x01FF])
self.assertEquals(0xFE, mpu.sp)
self.assertEquals(3, mpu.processorCycles)
# PHY
def test_phy_pushes_y_and_updates_sp(self):
mpu = self._make_mpu()
mpu.y = 0xAB
mpu.memory[0x0000] = 0x5A #=> PHY
mpu.step()
self.assertEquals(0x0001, mpu.pc)
self.assertEquals(0xAB, mpu.y)
self.assertEquals(0xAB, mpu.memory[0x01FF])
self.assertEquals(0xFE, mpu.sp)
self.assertEquals(3, mpu.processorCycles)
# PLX
def test_plx_pulls_top_byte_from_stack_into_x_and_updates_sp(self):
mpu = self._make_mpu()
mpu.memory[0x0000] = 0xFA #=> PLX
mpu.memory[0x01FF] = 0xAB
mpu.sp = 0xFE
mpu.step()
self.assertEquals(0x0001, mpu.pc)
self.assertEquals(0xAB, mpu.x)
self.assertEquals(0xFF, mpu.sp)
self.assertEquals(4, mpu.processorCycles)
# PLY
def test_ply_pulls_top_byte_from_stack_into_y_and_updates_sp(self):
mpu = self._make_mpu()
mpu.memory[0x0000] = 0x7A #=> PLY
mpu.memory[0x01FF] = 0xAB
mpu.sp = 0xFE
mpu.step()
self.assertEquals(0x0001, mpu.pc)
self.assertEquals(0xAB, mpu.y)
self.assertEquals(0xFF, mpu.sp)
self.assertEquals(4, mpu.processorCycles)
# STZ Zero Page
def test_stz_zp_stores_zero(self):
mpu = self._make_mpu(debug=True)
mpu.memory[0x0032] = 0x88
@ -19,8 +73,49 @@ class MPUTests(unittest.TestCase, Common6502Tests):
self.assertEquals(0x88, mpu.memory[0x0032])
mpu.step()
self.assertEquals(0x00, mpu.memory[0x0032])
self.assertEquals(0x0002, mpu.pc)
self.assertEquals(3, mpu.processorCycles)
# STZ Zero Page, X-Indexed
def test_stz_zp_x_stores_zero(self):
mpu = self._make_mpu(debug=True)
mpu.memory[0x0032] = 0x88
mpu.memory[0x0000:0x0000+2] = [0x74, 0x32] #=> STZ $32,X
self.assertEquals(0x88, mpu.memory[0x0032])
mpu.step()
self.assertEquals(0x00, mpu.memory[0x0032])
self.assertEquals(0x0002, mpu.pc)
self.assertEquals(4, mpu.processorCycles)
# STZ Absolute
def test_stz_abs_stores_zero(self):
mpu = self._make_mpu(debug=True)
mpu.memory[0xFEED] = 0x88
mpu.memory[0x0000:0x0000+3] = [0x9C, 0xED, 0xFE] #=> STZ $FEED
self.assertEquals(0x88, mpu.memory[0xFEED])
mpu.step()
self.assertEquals(0x00, mpu.memory[0xFEED])
self.assertEquals(0x0003, mpu.pc)
self.assertEquals(4, mpu.processorCycles)
# STZ Absolute, X-Indexed
def test_stz_abs_stores_zero(self):
mpu = self._make_mpu(debug=True)
mpu.memory[0xFEED] = 0x88
mpu.x = 0x0D
mpu.memory[0x0000:0x0000+3] = [0x9E, 0xE0, 0xFE] #=> STZ $FEE0,X
self.assertEquals(0x88, mpu.memory[0xFEED])
self.assertEquals(0x0D, mpu.x)
mpu.step()
self.assertEquals(0x00, mpu.memory[0xFEED])
self.assertEquals(0x0003, mpu.pc)
self.assertEquals(5, mpu.processorCycles)
# Test Helpers
def _get_target_class(self):