mirror of
https://github.com/mnaberez/py65.git
synced 2025-01-19 23:31:03 +00:00
Added DEC A and BRA to 65C02
Signed-off-by: Mike Naberezny <mike@naberezny.com>
This commit is contained in:
parent
c56b8590aa
commit
c77647c834
@ -19,6 +19,9 @@ class MPU(NMOS6502):
|
||||
def ZeroPageIndirectAddr(self):
|
||||
return self.WordAt( 255 & (self.ByteAt(self.pc)))
|
||||
|
||||
def AccumulatorAddr(self):
|
||||
return self.a
|
||||
|
||||
# operations
|
||||
|
||||
def opSTZ(self, x):
|
||||
@ -137,6 +140,21 @@ class MPU(NMOS6502):
|
||||
self.opTRB(self.AbsoluteAddr)
|
||||
self.pc += 2
|
||||
|
||||
@instruction(name="DEC", mode="imp", cycles=2)
|
||||
def inst_0x3a(self):
|
||||
tbyte = self.a
|
||||
self.flags &= ~(self.ZERO + self.NEGATIVE)
|
||||
tbyte = (tbyte - 1) & 0xFF
|
||||
if tbyte:
|
||||
self.flags |= tbyte & self.NEGATIVE
|
||||
else:
|
||||
self.flags |= self.ZERO
|
||||
self.a = tbyte
|
||||
|
||||
@instruction(name="BRA", mode="rel", cycles=1, extracycles=1)
|
||||
def inst_0x80(self):
|
||||
self.BranchRelAddr()
|
||||
|
||||
@instruction(name="SBC", mode="zpi", cycles=5)
|
||||
def inst_0xf2(self):
|
||||
self.opSBC(self.ZeroPageIndirectAddr)
|
||||
|
@ -595,6 +595,47 @@ class MPUTests(unittest.TestCase, Common6502Tests):
|
||||
self.assertEquals(0x0003, mpu.pc)
|
||||
self.assertEquals(6, mpu.processorCycles)
|
||||
|
||||
def test_dec_a_decreases_a(self):
|
||||
mpu = self._make_mpu(debug=True)
|
||||
self._write(mpu.memory, 0x0000, [0x3A]) #=> DEC A
|
||||
mpu.a = 0x48
|
||||
mpu.step()
|
||||
self.assertEquals(0, mpu.flags & mpu.ZERO)
|
||||
self.assertEquals(0, mpu.flags & mpu.NEGATIVE)
|
||||
self.assertEquals(0x47, mpu.a)
|
||||
|
||||
def test_dec_a_sets_zero_flag(self):
|
||||
mpu = self._make_mpu(debug=True)
|
||||
self._write(mpu.memory, 0x0000, [0x3A]) #=> DEC A
|
||||
mpu.a = 0x01
|
||||
mpu.step()
|
||||
self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO)
|
||||
self.assertEquals(0, mpu.flags & mpu.NEGATIVE)
|
||||
self.assertEquals(0x00, mpu.a)
|
||||
|
||||
def test_dec_a_wraps_at_zero(self):
|
||||
mpu = self._make_mpu(debug=True)
|
||||
self._write(mpu.memory, 0x0000, [0x3A]) #=> DEC A
|
||||
mpu.a = 0x00
|
||||
mpu.step()
|
||||
self.assertEquals(0, mpu.flags & mpu.ZERO)
|
||||
self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE)
|
||||
self.assertEquals(0xFF, mpu.a)
|
||||
|
||||
def test_bra_forward(self):
|
||||
mpu = self._make_mpu(debug=True)
|
||||
self._write(mpu.memory, 0x0000, [0x80, 0x10]) #=> BRA $10
|
||||
mpu.step()
|
||||
self.assertEquals(0x12, mpu.pc)
|
||||
self.assertEquals(2, mpu.processorCycles)
|
||||
|
||||
def test_bra_backward(self):
|
||||
mpu = self._make_mpu(debug=True)
|
||||
self._write(mpu.memory, 0x0204, [0x80, 0xF0]) #=> BRA $F0
|
||||
mpu.pc = 0x0204
|
||||
mpu.step()
|
||||
self.assertEquals(0x1F6, mpu.pc)
|
||||
self.assertEquals(3, mpu.processorCycles) # Crossed boundry
|
||||
|
||||
# Test Helpers
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user