1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-09-16 00:59:06 +00:00

Update imports, move instruction decorator to utils.

This commit is contained in:
Mike Naberezny 2009-04-07 17:37:53 -07:00
parent 857292958a
commit 594bfcaf71
2 changed files with 44 additions and 39 deletions

View File

@ -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

10
src/py65/utils/devices.py Normal file
View File

@ -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