71f1598033
FossilOrigin-Name: e488943c77e9374b79a733321829ae4b2908bf12b25748ec7ac3f61466e7e053
33 lines
844 B
Python
33 lines
844 B
Python
import os
|
|
import struct
|
|
|
|
|
|
class Memory(list):
|
|
def __init__(self, source, initial, size):
|
|
m = [0] * size
|
|
self.extend(m)
|
|
if len(initial) == 0:
|
|
cells = int(os.path.getsize(source) / 4)
|
|
f = open(source, "rb")
|
|
i = 0
|
|
for cell in list(struct.unpack(cells * "i", f.read())):
|
|
self[i] = cell
|
|
i = i + 1
|
|
f.close()
|
|
else:
|
|
i = 0
|
|
for cell in initial:
|
|
self[i] = cell
|
|
i = i + 1
|
|
|
|
def load_image(self, name):
|
|
cells = int(os.path.getsize(name) / 4)
|
|
f = open(name, "rb")
|
|
i = 0
|
|
for cell in list(struct.unpack(cells * "i", f.read())):
|
|
self[i] = cell
|
|
i = i + 1
|
|
f.close()
|
|
|
|
def size(self):
|
|
return len(self)
|