ZombieCPU/memory.py
2021-02-01 18:25:35 -05:00

27 lines
767 B
Python

import numpy as np
class Memory:
def __init__(self, size):
self._memory = np.zeros(size)
def write(self, address, data):
address = int(address)
if 0 > address >= self._memory.size:
# TODO: Raise an exception and throw an interrupt here
raise RuntimeException('Invalid write address')
self._memory[address] = data
def read(self, address):
address = int(address)
if 0 > address >= self._memory.size:
# TODO: Raise an exception and throw an interrupt here
raise RuntimeException('Invalid write address')
return self._memory[address]
def clear(self, data=0):
self._memory.fill(data)
def size(self):
return self._memory.size