summaryrefslogtreecommitdiff
path: root/addmapper.py
blob: 8848e874d38cb40642e9f5437660fe03a5ae01ca (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
import sys

def generate_mapper_files(mapper_id, submapper_id=0):
    # Format: submapper (1 hex digit) + mapper_id (3 hex digits, zero-padded)
    full_id = f"{submapper_id:01x}{int(mapper_id):03x}"
    filename = f"mapper_{full_id}"

    # Generate C file content
    c_content = f"""

static void {filename}_init(struct nes_state *state) {{
}}

static uint8_t {filename}_prg_read(struct nes_state *state, uint32_t addr) {{
}}

static void {filename}_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) {{
}}

static uint8_t {filename}_chr_read(struct nes_state *state, uint32_t addr) {{
}}

static void {filename}_chr_write(struct nes_state *state, uint32_t addr, uint8_t value) {{
}}

static uint8_t {filename}_ciram_read(struct nes_state *state, uint32_t addr) {{
}}

static void {filename}_ciram_write(struct nes_state *state, uint32_t addr, uint8_t value) {{
}}

static void {filename}_tick(struct nes_state *state) {{
}}
"""

    # Generate H file content
    h_content = f"""

struct {filename} {{
}};
"""

    # Generate table entry
    table_entry = f"""	{{ 0x{int(mapper_id):x}, {filename}_prg_read, {filename}_prg_write, {filename}_chr_read, {filename}_chr_write, {filename}_ciram_read, {filename}_ciram_write, {filename}_tick, {filename}_init }},"""

    # Write files
    with open(f"{filename}.c", "w") as f:
        f.write(c_content)

    with open(f"{filename}.h", "w") as f:
        f.write(h_content)

    print(f"Generated files: {filename}.c, {filename}.h")
    print("\nTable entry (copy-paste this into your mapper table):")
    print(table_entry)

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python newmapper.py <mapper_id> [submapper_id=0]")
        print("Example: python newmapper.py 123 0  # Creates mapper_0123.*")
        sys.exit(1)

    mapper_id = sys.argv[1]
    submapper_id = int(sys.argv[2]) if len(sys.argv) > 2 else 0
    generate_mapper_files(mapper_id, submapper_id)