__attribute__((section(".mapper_007_2"))) static uint8_t mapper_007_2_prg_rom_read(struct nes_state *state, uint32_t addr) { struct mapper_007_2 *mapper = &state->mapper_data.m007_2; if(addr >= 0x8000) { return mapper->prg_rom[addr & 0x7fff]; } return 0; } __attribute__((section(".mapper_007_2"))) static void mapper_007_2_prg_rom_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_007_2 *mapper = &state->mapper_data.m007_2; if(addr >= 0x8000) { uint32_t prg_off = (value & 0x0f) << 15; uint32_t ciram_off = (value & 0x10) << 11; mapper->prg_rom = state->prg_rom + prg_off; mapper->ciram = state->ciram + ciram_off; // mapper->prg_rom = state->prg_rom + ((value & 0x0f) * 0x8000); // mapper->ciram = state->ciram + ((value & 0x10) ? 0x400 : 0x000); } } __attribute__((section(".mapper_007_2"))) static uint8_t mapper_007_2_chr_read(struct nes_state *state, uint32_t addr) { return state->chr_ram[addr]; } __attribute__((section(".mapper_007_2"))) static void mapper_007_2_chr_write(struct nes_state *state, uint32_t addr, uint8_t value) { state->chr_ram[addr] = value; } __attribute__((section(".mapper_007_2"))) static uint8_t mapper_007_2_ciram_read(struct nes_state *state, uint32_t addr) { struct mapper_007_2 *mapper = &state->mapper_data.m007_2; return mapper->ciram[addr & 0x3ff]; } __attribute__((section(".mapper_007_2"))) static void mapper_007_2_ciram_write(struct nes_state *state, uint32_t addr, uint8_t value) { struct mapper_007_2 *mapper = &state->mapper_data.m007_2; mapper->ciram[addr & 0x3ff] = value; } __attribute__((section(".mapper_007_2"))) static void mapper_007_2_init(struct nes_state *state) { struct mapper_007_2 *mapper = &state->mapper_data.m007_2; mapper->prg_rom = state->prg_rom; mapper->ciram = 0; state->mapper_function.prg_rom_read = mapper_007_2_prg_rom_read; state->mapper_function.prg_rom_write = mapper_007_2_prg_rom_write; state->mapper_function.chr_read = mapper_007_2_chr_read; state->mapper_function.chr_write = mapper_007_2_chr_write; state->mapper_function.ciram_read = mapper_007_2_ciram_read; state->mapper_function.ciram_write = mapper_007_2_ciram_write; }