diff options
| author | Peter Fors <peter.fors@mindkiller.com> | 2025-05-02 23:15:47 +0200 |
|---|---|---|
| committer | Peter Fors <peter.fors@mindkiller.com> | 2025-05-02 23:15:47 +0200 |
| commit | 5808f00555c48e1cc1cc110af6a5cd73ddf13010 (patch) | |
| tree | dff942b61441bafe297e7a99f0e799f32ae978b1 /mappers/mapper_002_2.c | |
| parent | 9463faa436e1b981ef72000568445a83682f2658 (diff) | |
cleanup and rewrite of ppu_registers.c
Diffstat (limited to 'mappers/mapper_002_2.c')
| -rw-r--r-- | mappers/mapper_002_2.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/mappers/mapper_002_2.c b/mappers/mapper_002_2.c new file mode 100644 index 0000000..079fb0b --- /dev/null +++ b/mappers/mapper_002_2.c @@ -0,0 +1,41 @@ + + +static uint8_t mapper_002_2_prg_read(struct nes_state *state, uint32_t addr) { + struct mapper_002_2 *mapper = (struct mapper_002_2 *)&state->map; + + if(addr >= 0x8000 && addr < 0xc000) { + return mapper->prg_bank0[addr & 0x3fff]; + + } else if(addr >= 0xc000) { + return mapper->prg_bank1[addr & 0x3fff]; + } + return 0; +} + +static void mapper_002_2_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) { + struct mapper_002_2 *mapper = (struct mapper_002_2 *)&state->map; + + if(addr >= 0x8000) { + mapper->prg_bank0 = state->prg_rom + ((value & 0x0f) * 0x4000); + } +} + +static uint8_t mapper_002_2_chr_read(struct nes_state *state, uint32_t addr) { + return state->chr_ram[addr]; +} + +static void mapper_002_2_chr_write(struct nes_state *state, uint32_t addr, uint8_t value) { + state->chr_ram[addr] = value; +} + +static void mapper_002_2_init(struct nes_state *state) { + struct mapper_002_2 *mapper = (struct mapper_002_2 *)&state->map; + + mapper->prg_bank0 = state->prg_rom; + mapper->prg_bank1 = state->prg_rom + state->ines.prg_size - 0x4000; + + state->mapper.prg_read = mapper_002_2_prg_read; + state->mapper.prg_write = mapper_002_2_prg_write; + state->mapper.chr_read = mapper_002_2_chr_read; + state->mapper.chr_write = mapper_002_2_chr_write; +} |
