Clean code
This commit is contained in:
parent
10279426e5
commit
84de7cd481
4 changed files with 24 additions and 3 deletions
|
@ -8,6 +8,9 @@ class Ram:
|
|||
self.c=components
|
||||
|
||||
def loadRamFile(self,filepath):
|
||||
"""
|
||||
Load a Ram file into self.data
|
||||
"""
|
||||
data=dict()
|
||||
addr=0
|
||||
f=open(filepath,"r")
|
||||
|
@ -22,12 +25,18 @@ class Ram:
|
|||
self.data=data
|
||||
|
||||
def write(self):
|
||||
"""
|
||||
Write data to memory based Mic-1 architecture
|
||||
"""
|
||||
addr=self.c["MAR"]
|
||||
if addr>self.lastAddr:
|
||||
raise ValueError("You get out of the ram by trying to set a value at address {}, max address is {}".format(addr,self.lastAddr))
|
||||
self.data[addr]=self.c["MDR"]
|
||||
|
||||
def read(self):
|
||||
"""
|
||||
Read data from memory based Mic-1 architecture
|
||||
"""
|
||||
addr=self.c["MAR"]
|
||||
value=None
|
||||
try:
|
||||
|
@ -40,6 +49,9 @@ class Ram:
|
|||
return(value)
|
||||
|
||||
def fetch(self):
|
||||
"""
|
||||
Fetch next byte from memory based Mic-1 architecture
|
||||
"""
|
||||
addr=self.c["PC"]
|
||||
value=None
|
||||
try:
|
||||
|
@ -52,11 +64,17 @@ class Ram:
|
|||
return(value)
|
||||
|
||||
def dump(self):
|
||||
"""
|
||||
Simple dump helper
|
||||
"""
|
||||
for key,value in self.data.items():
|
||||
#print("{}:{}".format(key,bin(value)[2:]))
|
||||
print("{}:{}".format(key,value))
|
||||
|
||||
def dumpRange(self,start,end):
|
||||
"""
|
||||
Another dump helper
|
||||
"""
|
||||
for i in range(start,end+1):
|
||||
try:
|
||||
print("{}:{}".format(i,self.data[i]))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue