summaryrefslogtreecommitdiff
path: root/addmapper.py
diff options
context:
space:
mode:
Diffstat (limited to 'addmapper.py')
-rwxr-xr-xaddmapper.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/addmapper.py b/addmapper.py
new file mode 100755
index 0000000..8848e87
--- /dev/null
+++ b/addmapper.py
@@ -0,0 +1,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)
+