#!/usr/bin/env python3 import sys def generate_mapper_files(mapper_id, submapper_id=0): mapper_id = int(mapper_id) submapper_id = int(submapper_id) # Format: mapper__ full_id = f"{mapper_id}_{submapper_id:x}" filename = f"mapper_{full_id}" # Generate C file content c_content = f"""#include "{filename}.h" static uint8_t {filename}_prg_rom_read(struct nes_state *state, uint32_t addr) {{ return 0; }} static void {filename}_prg_rom_write(struct nes_state *state, uint32_t addr, uint8_t value) {{ }} static uint8_t {filename}_chr_read(struct nes_state *state, uint32_t addr) {{ return 0; }} 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) {{ return 0; }} static void {filename}_ciram_write(struct nes_state *state, uint32_t addr, uint8_t value) {{ }} static void {filename}_tick(struct nes_state *state) {{ }} void {filename}_init(struct nes_state *state) {{ state->mapper.prg_rom_read = {filename}_prg_read; state->mapper.prg_rom_write = {filename}_prg_rom_write; state->mapper.chr_read = {filename}_chr_read; state->mapper.chr_write = {filename}_chr_write; state->mapper.ciram_read = {filename}_ciram_read; state->mapper.ciram_write = {filename}_ciram_write; state->mapper.tick = {filename}_tick; }} """ # Generate H file content h_content = f"""#pragma once struct {filename} {{ }}; void {filename}_init(struct nes_state *state); """ # Only generate mapper ID -> init pointer table_entry = f"""\t{{ 0x{mapper_id:x}, {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: python3 newmapper.py [submapper_id=0]") print("Example: python3 newmapper.py 3 0 # Creates mapper_3_0.*") sys.exit(1) mapper_id = sys.argv[1] submapper_id = sys.argv[2] if len(sys.argv) > 2 else 0 generate_mapper_files(mapper_id, submapper_id)