forked from jtauber/applepy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.py
More file actions
59 lines (52 loc) · 1.85 KB
/
memory.py
File metadata and controls
59 lines (52 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
from intelhex import IntelHex
class Memory:
def __init__(self, display=None):
self.mem = np.zeros(0x10000, dtype=np.int32)
self.display = display
self.kbd = 0
def store(self, address, data):
for offset, datum in enumerate(data):
self.mem[address + offset] = datum
def read_byte(self, address):
if address == 0xC000:
return self.kdb
if address == 0xC010:
self.kdb = self.kbd & 0x7F
elif address == 0xC050:
self.display.txtclr()
elif address == 0xC051:
self.display.txtset()
elif address == 0xC052:
self.display.mixclr()
elif address == 0xC053:
self.display.mixset()
elif address == 0xC054:
self.display.lowscr()
elif address == 0xC055:
self.display.hiscr()
elif address == 0xC056:
self.display.lores()
elif address == 0xC057:
self.display.hires()
return self.mem[address]
def write_byte(self, address, value):
self.mem[address] = value
if self.display and 0x400 <= address < 0x800:
self.display.update(address, value)
if self.display and 0x2000 <= address < 0x5FFF:
self.display.update(address, value)
def load_file(self, filename):
ih = IntelHex(filename)
d = ih.todict()
if "start_addr" in d:
del d["start_addr"]
for addr, v in d.items():
self.write_byte(addr, v)
def read_word(self, address):
return self.read_byte(address) + (self.read_byte(address + 1) << 8)
def read_word_bug(self, address):
if address & 0xff == 0xff:
return self.read_byte(address) + (self.read_byte(address & 0xff00) << 8)
else:
return self.read_word(address)