28 lines
860 B
Python
28 lines
860 B
Python
#!/usr/bin/python
|
||
|
||
class Caretaker:
|
||
|
||
def __init__(self):
|
||
self.objects=dict() # Create empty objects pool
|
||
# Add registers to pool
|
||
for reg in ["MAR","MDR", "PC", "MBR", "SP","LV","CPP","TOS","OPC","H"]:
|
||
self.objects[reg]=0
|
||
self.objects["RAM"]=None
|
||
|
||
def __getitem__(self,key):
|
||
if key=="MBRU": # If we ask for unsigned
|
||
return(self.objects["MBR"] & 0x000000FF)
|
||
elif key=="MBR": # If we ask for signed
|
||
if self.objects["MBR"]>=0:
|
||
return(self["MBRU"])
|
||
else: # Send 2 complement if it's lower than 0
|
||
return(self.objects["MBR"] & 0xFFFFFFFF)
|
||
return(self.objects[key])
|
||
|
||
def __setitem__(self,key,value):# TODO: Do special treatment for MBR (allow only 2^8 value)
|
||
# TODO: Force data to be at most 32 bits longs (Mic-1 architecture constraint)
|
||
self.objects[key]=value
|
||
|
||
def items(self):
|
||
return(self.objects.items())
|
||
|