summaryrefslogtreecommitdiff
path: root/tools/make_shim.py
blob: 67b9f4ed7ee071386ede37e9667b771711cd09e9 (plain)
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
from sys import argv, stderr

for line in open(argv[1]):
    line = line.split(";")[0]
    line = line.strip()
    if line and " " in line:
        address, symbol = line.split()
        bank, pointer = address.split(":")
        bank = int(bank, 16)
        pointer = int(pointer, 16)
        section = None
        if bank == 0 and pointer < 0x4000:
            section = "ROM0"
            bank = None
        elif pointer < 0x8000:
            section = "ROMX"
        elif pointer < 0xa000:
            section = "VRAM"
        elif pointer < 0xc000:
            section = "SRAM"
        elif bank == 0 and pointer < 0xd000:
            section = "WRAM0"
            bank = None
        elif pointer < 0xe000:
            section = "WRAMX"
        elif pointer > 0xff80 and pointer <= 0xffff:
            section = "HRAM"
        else:
            stderr.write(f"Unknown section for {line}\n")
        
        if section:
            if bank:
                print(f"SECTION \"Shim for {symbol}\", {section}[${pointer:x}], BANK[${bank:x}]")
            else:
                print(f"SECTION \"Shim for {symbol}\", {section}[${pointer:x}]")
            print(f"{symbol}::\n\n")