1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-07-12 17:29:24 +00:00

added page wrapping bugs and tests for them

This commit is contained in:
martti 2011-06-22 17:03:10 +08:00 committed by BigEd
parent b5a8846455
commit 680b2dca2e
2 changed files with 54 additions and 4 deletions

View File

@ -73,6 +73,10 @@ class MPU:
def WordAt(self, addr):
return self.ByteAt(addr) + (self.ByteAt(addr + 1) << 8)
def WrapAt(self, addr):
wrap = lambda x: (x & 0xff00) + ((x + 1) & 0xff)
return self.ByteAt(addr) + (self.ByteAt(wrap(addr)) << 8)
def ProgramCounter(self):
return self.pc
@ -91,17 +95,17 @@ class MPU:
return 255 & (self.y + self.ByteAt(self.pc))
def IndirectXAddr(self):
return self.WordAt( 255 & (self.ByteAt(self.pc) + self.x))
return self.WrapAt( 255 & (self.ByteAt(self.pc) + self.x))
def IndirectYAddr(self):
if self.addcycles:
a1 = self.WordAt(self.ByteAt(self.pc))
a1 = self.WrapAt(self.ByteAt(self.pc))
a2 = (a1+self.y) & 0xffff
if (a1 & 0xff00) != (a2 & 0xff00):
self.excycles += 1
return a2
else:
return (self.WordAt(self.ByteAt(self.pc))+self.y)&0xffff
return (self.WrapAt(self.ByteAt(self.pc))+self.y)&0xffff
def AbsoluteAddr(self):
return self.WordAt(self.pc)
@ -793,7 +797,7 @@ class MPU:
@instruction(name="JMP", mode="ind", cycles=5)
def inst_0x6c(self):
ta = self.WordAt(self.pc)
self.pc = self.WordAt(ta)
self.pc = self.WrapAt(ta)
@instruction(name="ADC", mode="abs", cycles=4)
def inst_0x6d(self):

View File

@ -5088,6 +5088,52 @@ class Common6502Tests:
self.assertEqual(0x03, mpu.a)
self.assertEqual(0x0008, mpu.pc)
# page wrapping test
def test_zeropage_indexed_indirect_wrap(self):
mpu = self._make_mpu()
mpu.y = 0
self._write(mpu.memory, 0xb100, (0x31, ))
self._write(mpu.memory, 0xff, (0, ))
self._write(mpu.memory, 0, (0xb1, 0xff)) # LDA ($FF),Y
mpu.step()
self.assertEqual(mpu.a, 0x31)
def test_zeropage_indexed_wrap(self):
mpu = self._make_mpu()
mpu.x = 1
self._write(mpu.memory, 0, (0xb5, 0xff)) # LDA $FF,X
mpu.step()
self.assertEqual(mpu.a, 0xb5)
def test_zeropage_indirect_indexed_wrap(self):
mpu = self._make_mpu()
mpu.x = 0
self._write(mpu.memory, 0xa100, (0x31, ))
self._write(mpu.memory, 0xff, (0, ))
self._write(mpu.memory, 0, (0xa1, 0xff)) # LDA ($FF,X)
mpu.step()
self.assertEqual(mpu.a, 0x31)
def test_zeropage_indirect_indexed_indexwrap(self):
mpu = self._make_mpu()
mpu.x = 0xff
self._write(mpu.memory, 0xa100, (0x31, ))
self._write(mpu.memory, 0xff, (0, ))
self._write(mpu.memory, 0, (0xa1, 0)) # LDA ($00,X)
mpu.step()
self.assertEqual(mpu.a, 0x31)
def test_indirect_wrap(self):
mpu = self._make_mpu()
mpu.x = 0xff
self._write(mpu.memory, 0xff, (0, ))
self._write(mpu.memory, 0, (0x6c, 0xff, 0x00)) # LDA ($00,X)
mpu.step()
self.assertEqual(mpu.pc, 0x6c00)
# decimal flag chaos
# Test Helpers
def _write(self, memory, start_address, bytes):