-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.py
61 lines (50 loc) · 1.91 KB
/
loader.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import configparser
import extract
import memory
import dasm_objects
def load(rom_path, config_path=None):
prog_rom = extract.extract(rom_path)
mem = memory.Memory()
mem.map_prog_rom(prog_rom)
del prog_rom
program = dasm_objects.Program(mem)
load_config(config_path, program.symbols, program.config)
return program
def load_config(config_path, symbols, config):
if not config_path:
return
print("Loading config from {}".format(config_path))
parsed = configparser.ConfigParser(allow_no_value=True)
parsed.read(config_path)
count = 0
if "LABELS" in parsed:
for address, label in parsed.items("LABELS"):
address = int(address, base=0)
symbols.add_label(address, label)
count += 1
print("Loaded {} labels.".format(count))
count = 0
if "FORCE END CHUNK" in parsed:
for address, comment in parsed.items("FORCE END CHUNK"):
address = int(address, base=0)
config.forced_chunk_ends.append(address)
config.add_post_comment(address, comment)
count += 1
print("Loaded {} forced chunk ends.".format(count))
count = 0
if "PRE COMMENTS" in parsed:
for address, comment in parsed.items("PRE COMMENTS"):
address = int(address, base=0)
config.add_pre_comment(address, comment)
count += 1
if "INLINE COMMENTS" in parsed:
for address, comment in parsed.items("INLINE COMMENTS"):
address = int(address, base=0)
config.add_inline_comment(address, comment)
count += 1
if "POST COMMENTS" in parsed:
for address, comment in parsed.items("POST COMMENTS"):
address = int(address, base=0)
config.add_post_comment(address, comment)
count += 1
print("Loaded {} comments.".format(count))