From ccf950019fcaea4cedc925df2b225eeb68290f50 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Fri, 7 Aug 2009 13:13:40 -0700 Subject: [PATCH] Remove duplicated code between addressing modes in ADC. Closes #4. --- src/py65/devices/mpu6502.py | 40 ++++++------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/src/py65/devices/mpu6502.py b/src/py65/devices/mpu6502.py index b1990ce..c3a5e89 100644 --- a/src/py65/devices/mpu6502.py +++ b/src/py65/devices/mpu6502.py @@ -248,7 +248,11 @@ class MPU: self.FlagsNZ(self.a) def opADC(self, x): - data=self.ByteAt(x()) + if callable(x): + data = self.ByteAt(x()) + else: + data = x + if self.flags & self.DECIMAL: if self.flags & self.CARRY: tmp = 1 @@ -737,39 +741,7 @@ class MPU: @instruction(name="ADC", mode="imm", cycles=2) def inst_0x69(self): - data = self.ImmediateByte() - - if self.flags & self.CARRY: - tmp = 1 - else: - tmp = 0 - - if self.flags & self.DECIMAL: - data = convert_to_bin(data) + convert_to_bin(self.a) + tmp - self.flags &= ~(self.CARRY+self.OVERFLOW+self.NEGATIVE+self.ZERO) - if data > 99: - self.flags |= self.CARRY+self.OVERFLOW - data -= 100 - if data == 0: - self.flags |= self.ZERO - else: - self.flags |= self.data & 128 - self.a = convert_to_bcd(data) - else: - if self.flags & self.CARRY: - tmp = 1 - else: - tmp = 0 - data += self.a + tmp - self.flags &= ~(self.CARRY+self.OVERFLOW+self.NEGATIVE+self.ZERO) - if data > 255: - self.flags |= self.OVERFLOW + self.CARRY - data &= 255 - if data == 0: - self.flags |= self.ZERO - else: - self.flags |= data & 128 - self.a=data + self.opADC(self.ImmediateByte()) self.pc += 1 @instruction(name="ROR", mode="acc", cycles=2)