MicSim/components/caretaker.py

29 lines
860 B
Python
Raw Normal View History

2018-08-31 18:42:12 +02:00
#!/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
2018-09-01 10:19:06 +02:00
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)
2018-08-31 18:42:12 +02:00
return(self.objects[key])
2018-08-31 20:18:08 +02:00
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)
2018-08-31 18:42:12 +02:00
self.objects[key]=value
def items(self):
return(self.objects.items())