mirror of
https://github.com/mnaberez/py65.git
synced 2024-12-29 06:29:48 +00:00
memory model: remove blist dependency, model just 256k memory for 32bit address space
This commit is contained in:
parent
40f77afd67
commit
36a0731483
@ -1,20 +1,11 @@
|
||||
# this sparse array module only needed for large-memory CPU models
|
||||
try:
|
||||
from blist import *
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
class ObservableMemory:
|
||||
def __init__(self, subject=None, addrWidth=16):
|
||||
self.physMask = 0xffff
|
||||
if addrWidth > 16:
|
||||
# even with 32-bit address space, model only 256k memory
|
||||
self.physMask = 0x3ffff
|
||||
if subject is None:
|
||||
if addrWidth <= 16:
|
||||
subject = 0x10000 * [0x00]
|
||||
else:
|
||||
try:
|
||||
subject = blist([0]) * (1 << addrWidth)
|
||||
except:
|
||||
print "Fatal: failed to initialise large memory for this CPU"
|
||||
exit (1)
|
||||
subject = (self.physMask+1) * [0x00]
|
||||
|
||||
self._subject = subject
|
||||
|
||||
@ -22,6 +13,7 @@ class ObservableMemory:
|
||||
self._write_subscribers = {}
|
||||
|
||||
def __setitem__(self, address, value):
|
||||
address &= self.physMask
|
||||
callbacks = self._write_subscribers.get(address, [])
|
||||
|
||||
for callback in callbacks:
|
||||
@ -32,6 +24,7 @@ class ObservableMemory:
|
||||
self._subject[address] = value
|
||||
|
||||
def __getitem__(self, address):
|
||||
address &= self.physMask
|
||||
callbacks = self._read_subscribers.get(address, [])
|
||||
final_result = None
|
||||
|
||||
@ -50,15 +43,18 @@ class ObservableMemory:
|
||||
|
||||
def subscribe_to_write(self, address_range, callback):
|
||||
for address in address_range:
|
||||
address &= self.physMask
|
||||
callbacks = self._write_subscribers.setdefault(address, [])
|
||||
if callback not in callbacks:
|
||||
callbacks.append(callback)
|
||||
|
||||
def subscribe_to_read(self, address_range, callback):
|
||||
for address in address_range:
|
||||
address &= self.physMask
|
||||
callbacks = self._read_subscribers.setdefault(address, [])
|
||||
if callback not in callbacks:
|
||||
callbacks.append(callback)
|
||||
|
||||
def write(self, start_address, bytes):
|
||||
start_address &= self.physMask
|
||||
self._subject[start_address:start_address+len(bytes)] = bytes
|
||||
|
Loading…
Reference in New Issue
Block a user