mirror of
https://github.com/mnaberez/py65.git
synced 2024-11-18 15:06:35 +00:00
added page wrapping bugs and tests for them
This commit is contained in:
parent
b5a8846455
commit
680b2dca2e
@ -73,6 +73,10 @@ class MPU:
|
|||||||
def WordAt(self, addr):
|
def WordAt(self, addr):
|
||||||
return self.ByteAt(addr) + (self.ByteAt(addr + 1) << 8)
|
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):
|
def ProgramCounter(self):
|
||||||
return self.pc
|
return self.pc
|
||||||
|
|
||||||
@ -91,17 +95,17 @@ class MPU:
|
|||||||
return 255 & (self.y + self.ByteAt(self.pc))
|
return 255 & (self.y + self.ByteAt(self.pc))
|
||||||
|
|
||||||
def IndirectXAddr(self):
|
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):
|
def IndirectYAddr(self):
|
||||||
if self.addcycles:
|
if self.addcycles:
|
||||||
a1 = self.WordAt(self.ByteAt(self.pc))
|
a1 = self.WrapAt(self.ByteAt(self.pc))
|
||||||
a2 = (a1+self.y) & 0xffff
|
a2 = (a1+self.y) & 0xffff
|
||||||
if (a1 & 0xff00) != (a2 & 0xff00):
|
if (a1 & 0xff00) != (a2 & 0xff00):
|
||||||
self.excycles += 1
|
self.excycles += 1
|
||||||
return a2
|
return a2
|
||||||
else:
|
else:
|
||||||
return (self.WordAt(self.ByteAt(self.pc))+self.y)&0xffff
|
return (self.WrapAt(self.ByteAt(self.pc))+self.y)&0xffff
|
||||||
|
|
||||||
def AbsoluteAddr(self):
|
def AbsoluteAddr(self):
|
||||||
return self.WordAt(self.pc)
|
return self.WordAt(self.pc)
|
||||||
@ -793,7 +797,7 @@ class MPU:
|
|||||||
@instruction(name="JMP", mode="ind", cycles=5)
|
@instruction(name="JMP", mode="ind", cycles=5)
|
||||||
def inst_0x6c(self):
|
def inst_0x6c(self):
|
||||||
ta = self.WordAt(self.pc)
|
ta = self.WordAt(self.pc)
|
||||||
self.pc = self.WordAt(ta)
|
self.pc = self.WrapAt(ta)
|
||||||
|
|
||||||
@instruction(name="ADC", mode="abs", cycles=4)
|
@instruction(name="ADC", mode="abs", cycles=4)
|
||||||
def inst_0x6d(self):
|
def inst_0x6d(self):
|
||||||
|
@ -5088,6 +5088,52 @@ class Common6502Tests:
|
|||||||
self.assertEqual(0x03, mpu.a)
|
self.assertEqual(0x03, mpu.a)
|
||||||
self.assertEqual(0x0008, mpu.pc)
|
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
|
# Test Helpers
|
||||||
|
|
||||||
def _write(self, memory, start_address, bytes):
|
def _write(self, memory, start_address, bytes):
|
||||||
|
Loading…
Reference in New Issue
Block a user