Debug caretaker
This commit is contained in:
parent
fbd6725e84
commit
878c2b84a9
2 changed files with 26 additions and 15 deletions
|
@ -15,20 +15,28 @@ class Caretaker:
|
||||||
if key=="MBRU": # If we ask for unsigned
|
if key=="MBRU": # If we ask for unsigned
|
||||||
return(abs(self.objects["MBR"]))
|
return(abs(self.objects["MBR"]))
|
||||||
elif key== "MBR":
|
elif key== "MBR":
|
||||||
if abs(self.objects[key]>>7)==1: # If it a negative number (2 complement)
|
if self.objects[key] < 0:
|
||||||
return(-((self.objects[key]-1)^0xFF)) # transforme bin negative number to python negative number
|
return(self.objects[key])
|
||||||
|
elif self.objects[key]>>7==1: # If it a negative number (2 complement)
|
||||||
|
return(-(self.objects[key]&0x7F))
|
||||||
else:
|
else:
|
||||||
return(self.objects[key])
|
return(self.objects[key])
|
||||||
return(self.objects[key])
|
return(self.objects[key])
|
||||||
|
|
||||||
def __setitem__(self,key,value):
|
def __setitem__(self,key,value):
|
||||||
if key!="RAM":
|
if key!="RAM":
|
||||||
if value > (2**32) and key!="MBR" and key!="MBRU": # Check value fit in word
|
if (-(2**7-1))>value and (key=="MBR" or key=="MBRU"):
|
||||||
print("Warning word overflow: value {} on register {}".format(value,key))
|
raise RuntimeError("Value {} cannot fit in MBR register (-2^7 minimum value)".format(value))
|
||||||
value=value%(2**32) # Force to fit in word
|
elif value>(2**32-1) and (key!="MBR" and key!="MBRU"):
|
||||||
elif value > (2**8) and key=="MBR" and key=="MBRU": # Check value fit in byte
|
raise RuntimeError("Value {} cannot fit in MBR register (2^32 minimum value)".format(value))
|
||||||
print("Warning byte overflow: value {} on register {}".format(value,key))
|
|
||||||
value=value%256 # Force to fit in byte
|
# if key!="RAM":
|
||||||
|
# if (value > (2**32) or value <(2**32)/2) and key!="MBR" and key!="MBRU": # Check value fit in word
|
||||||
|
# print("Warning word overflow: value {} on register {}".format(value,key))
|
||||||
|
# value=value%(2**32) # Force to fit in word
|
||||||
|
# elif (value > (2**8) or value <126) and key=="MBR" or key=="MBRU": # Check value fit in byte
|
||||||
|
# print("Warning byte overflow: value {} on register {}".format(value,key))
|
||||||
|
# value=abs(value)%256 # Force to fit in byte
|
||||||
self.objects[key]=value
|
self.objects[key]=value
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
|
|
|
@ -16,13 +16,16 @@ class CaretakerTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
Test if getitem operation follow Mic-1 rules
|
Test if getitem operation follow Mic-1 rules
|
||||||
"""
|
"""
|
||||||
toWrite=randint(0,126) # Only 7 bit for signed MBR (2^7=127)
|
for toWrite in range(0,127):# Only 7 bit for signed MBR (2^7=127)
|
||||||
self.c["MBR"]=-toWrite
|
self.c["MBR"]=-toWrite
|
||||||
self.assertEqual(self.c["MBRU"],toWrite,"Tested with {}".format(-toWrite))
|
self.assertEqual(self.c["MBRU"],toWrite,"Tested with {}".format(-toWrite))
|
||||||
self.assertEqual(self.c["MBR"],-(-((toWrite-1)^0xFF)),"Tested with {}".format(-toWrite))
|
self.assertEqual(self.c["MBR"],-toWrite,"Tested with {}".format(-toWrite))
|
||||||
self.c["MBR"]=toWrite
|
|
||||||
self.assertEqual(self.c["MBRU"],toWrite,"Tested with {}".format(toWrite))
|
for toWrite in range(0,255):# Only 2^8 value for unsigned
|
||||||
self.assertEqual(self.c["MBR"],toWrite,"Tested with {}".format(toWrite))
|
self.c["MBR"]=toWrite
|
||||||
|
self.assertEqual(self.c["MBRU"],toWrite,"Tested with {}".format(toWrite))
|
||||||
|
if toWrite>127: # We enter in the zone of negative number at 127
|
||||||
|
self.assertEqual(self.c["MBR"],-(toWrite&0x7F),"Tested with {}".format(toWrite))
|
||||||
|
|
||||||
with self.assertRaises(KeyError): # Check it returns a KeyError
|
with self.assertRaises(KeyError): # Check it returns a KeyError
|
||||||
self.c["kjhkjhkoih"+str(randint(0,7698))]
|
self.c["kjhkjhkoih"+str(randint(0,7698))]
|
||||||
|
|
Loading…
Add table
Reference in a new issue