From 594bfcaf716505425dd68eb658f148b2d5fccfd7 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Tue, 7 Apr 2009 17:37:53 -0700 Subject: [PATCH] Update imports, move instruction decorator to utils. --- src/py65/mpu65c02.py | 73 ++++++++++++++++++--------------------- src/py65/utils/devices.py | 10 ++++++ 2 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 src/py65/utils/devices.py diff --git a/src/py65/mpu65c02.py b/src/py65/mpu65c02.py index 1641f93..b5f6954 100644 --- a/src/py65/mpu65c02.py +++ b/src/py65/mpu65c02.py @@ -1,49 +1,44 @@ -#from py65.utils.conversions import convert_to_bin, convert_to_bcd -import mpu6502 +from py65.mpu6502 import MPU as NMOS6502 +from py65.utils.devices import make_instruction_decorator -def make_instruction_decorator(instruct, cycletime, extracycles): - def instruction(opcode, opcycles, opextracycles=0): - def decorate(f): - instruct[opcode] = f - cycletime[opcode] = opcycles - extracycles[opcode] = opextracycles - return f # Return the original function - return decorate - return instruction +class MPU(NMOS6502): + def __init__(self, *args, **kwargs): + NMOS6502.__init__(self, *args, **kwargs) + self.name = '65C02' + instruct = NMOS6502.instruct[:] + cycletime = NMOS6502.cycletime[:] + extracycles = NMOS6502.extracycles[:] -class MPU(mpu6502.MPU): - def __init__(self, memory=None, pc=0x0000, debug=False): - mpu6502.MPU.__init__(self, memory=memory, pc=pc, debug=debug) - self.name = '65C02' - - instruct = mpu6502.MPU.instruct[:] - cycletime = mpu6502.MPU.cycletime[:] - extracycles = mpu6502.MPU.extracycles[:] - - instruction = \ + instruction = \ make_instruction_decorator(instruct, cycletime, extracycles) - def opSTZ(self, x): - self.memory[x()] = 0x00 - @instruction(0x64, 3) - def i64(self): - self.opSTZ(self.ZeroPageAddr) - self.pc += 1 + # operations - @instruction(0x74, 4) - def i74(self): - self.opSTZ(self.ZeroPageXAddr) - self.pc += 1 + def opSTZ(self, x): + self.memory[x()] = 0x00 - @instruction(0x9c, 4) - def i9c(self): - self.opSTZ(self.AbsoluteAddr) - self.pc += 2 - @instruction(0x9e, 5) - def i9e(self): - self.opSTZ(self.AbsoluteXAddr) - self.pc+=2 + # instructions + + @instruction(0x64, 3) + def i64(self): + self.opSTZ(self.ZeroPageAddr) + self.pc += 1 + + @instruction(0x74, 4) + def i74(self): + self.opSTZ(self.ZeroPageXAddr) + self.pc += 1 + + @instruction(0x9c, 4) + def i9c(self): + self.opSTZ(self.AbsoluteAddr) + self.pc += 2 + + @instruction(0x9e, 5) + def i9e(self): + self.opSTZ(self.AbsoluteXAddr) + self.pc+=2 diff --git a/src/py65/utils/devices.py b/src/py65/utils/devices.py new file mode 100644 index 0000000..d0672c2 --- /dev/null +++ b/src/py65/utils/devices.py @@ -0,0 +1,10 @@ + +def make_instruction_decorator(instruct, cycletime, extracycles): + def instruction(opcode, opcycles, opextracycles=0): + def decorate(f): + instruct[opcode] = f + cycletime[opcode] = opcycles + extracycles[opcode] = opextracycles + return f # Return the original function + return decorate + return instruction