28 lines
894 B
Python
28 lines
894 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(abs(self.objects["MBR"]))
|
||
elif key== "MBR":
|
||
if (self.objects[key]>>7)==1: # If it a negative number (2 complement)
|
||
return(-((self.objects[key]-1)^0xFF)) # transforme bin negative number to python negative number
|
||
else:
|
||
return(self.objects[key])
|
||
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())
|
||
|