retroforth/vm/nga-python/Memory.py
crc 3dbab4061a nga-python: load & use embedded image (#33)
FossilOrigin-Name: 2775527083e92f7292440e98cb7e143d3760f0c8f779078684976eb4f3c0e371
2020-12-25 04:30:14 +00:00

24 lines
590 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 size(self):
return len(self)