aboutsummaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/caretaker.py9
-rw-r--r--components/microprogram.py32
2 files changed, 38 insertions, 3 deletions
diff --git a/components/caretaker.py b/components/caretaker.py
index f005b27..7f8cc33 100644
--- a/components/caretaker.py
+++ b/components/caretaker.py
@@ -9,7 +9,14 @@ class Caretaker:
self.objects[reg]=0
self.objects["RAM"]=None
- def __getitem__(self,key): # TODO: Allow MBRU key and adapt its return value
+ 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)
diff --git a/components/microprogram.py b/components/microprogram.py
index e1b81a0..fb0e589 100644
--- a/components/microprogram.py
+++ b/components/microprogram.py
@@ -86,7 +86,7 @@ class Microprogram:
self.c["MAR"]=self.c["SP"]
self.c["H"]=self.c["TOS"]
self.rd()
- self.c["TOS"]=(self.c["MDR"] and self.c["H"])
+ self.c["TOS"]=(self.c["MDR"] & self.c["H"])
self.c["MDR"]=self.c["TOS"]
self.wr()
elif opcode==ijvm["IOR"]:
@@ -94,7 +94,7 @@ class Microprogram:
self.c["MAR"]=self.c["SP"]
self.c["H"]=self.c["TOS"]
self.rd()
- self.c["TOS"]=(self.c["MDR"] or self.c["H"])
+ self.c["TOS"]=(self.c["MDR"] | self.c["H"])
self.c["MDR"]=self.c["TOS"]
self.wr()
elif opcode==ijvm["SWAP"]:
@@ -107,6 +107,34 @@ class Microprogram:
self.c["MAR"]=self.c["SP"]-1
self.wr()
self.c["TOS"]=self.c["H"]
+ elif opcode==ijvm["ILOAD"]:
+ self.fetch();self.c["PC"]+=1 # Fetch local variable to push onto the stack
+ self.c["H"]=self.c["LV"]
+ self.c["MAR"]=self.c["MBRU"]+self.c["H"]
+ self.rd()
+ self.c["SP"]+=1
+ self.c["MAR"]=self.c["SP"]
+ self.wr()
+ self.c["TOS"]=self.c["MDR"]
+ elif opcode==ijvm["ISTORE"]:
+ self.fetch();self.c["PC"]+=1 # Fetch local variable offset where to store
+ self.c["H"]=self.c["LV"]
+ self.c["MAR"]=self.c["MBRU"]+self.c["H"]
+ self.c["MDR"]=self.c["TOS"]
+ self.wr()
+ self.c["SP"]-=1
+ self.c["MAR"]=self.c["SP"]
+ self.rd()
+ self.c["TOS"]=self.c["MDR"]
+ elif opcode==ijvm["IINC"]:
+ self.fetch();self.c["PC"]+=1 # Fetch local variable offset to inc
+ self.c["H"]=self.c["LV"]
+ self.c["MAR"]=self.c["MBRU"]+self.c["H"]
+ self.rd()
+ self.fetch();self.c["PC"]+=1 # Fetch inc value
+ self.c["H"]=self.c["MDR"]
+ self.c["MDR"]=self.c["MBR"]+self.c["H"]
+ self.wr()
elif opcode==ijvm["OUT"]:
self.fetch();self.c["PC"]+=1 # Fetch byte to push in MBR
print(str(chr(self.c["MBR"])),end="")