forked from MSXALL/pymsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsxdos2.py
47 lines (31 loc) · 1.12 KB
/
msxdos2.py
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
# (C) 2020 by Folkert van Heusden <[email protected]>
# released under AGPL v3.0
import sys
from typing import List, Tuple
class msxdos2:
def __init__(self, msxdos2_rom_file, debug):
print('Loading MSX-DOS2 rom %s...' % msxdos2_rom_file, file=sys.stderr)
fh = open(msxdos2_rom_file, 'rb')
self.msxdos2_rom = [ int(b) for b in fh.read() ]
fh.close()
assert len(self.msxdos2_rom) == 65536
self.msxdos2_page: int = 0
self.debug = debug
def get_ios(self):
return [ [ ] , [ ] ]
def get_name(self):
return 'MSX-DOS2'
def get_n_pages(self):
return 1
def split_addr(self, a: int) -> Tuple[int, int]:
assert a >= 0x4000
bank = a // 0x4000 - 1
offset = a & 0x3fff
return bank, offset
def write_mem(self, a: int, v: int) -> None:
self.debug('MSX-DOS2: set bank to %d (%d) via %04x' % (v, v & 3, a))
self.msxdos2_page = v & 3
def read_mem(self, a: int) -> int:
bank, offset = self.split_addr(a)
p = self.msxdos2_page * 0x4000 + offset
return self.msxdos2_rom[p]