aboutsummaryrefslogtreecommitdiff
path: root/components/ram.py
diff options
context:
space:
mode:
authorLoic GUEGAN <loic.guegan@yahoo.fr>2018-08-31 20:18:08 +0200
committerLoic GUEGAN <loic.guegan@yahoo.fr>2018-08-31 20:18:08 +0200
commit84de7cd481662167745131b95c78442a7ff45048 (patch)
treea6919826aea02d055a3a19fa6e424cbdcd2cbe2d /components/ram.py
parent10279426e5bd783d9525c0ef758d8642770cb534 (diff)
Clean code
Diffstat (limited to 'components/ram.py')
-rw-r--r--components/ram.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/components/ram.py b/components/ram.py
index d503929..ddf48d1 100644
--- a/components/ram.py
+++ b/components/ram.py
@@ -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]))