diff options
| author | Peter Fors <peter.fors@mindkiller.com> | 2025-04-05 08:58:12 +0200 |
|---|---|---|
| committer | Peter Fors <peter.fors@mindkiller.com> | 2025-04-05 08:58:12 +0200 |
| commit | f1bd6a7d2f4ffe3e5263e0254bcf7522ab381264 (patch) | |
| tree | e75bde292329f337d619f9a997aab9b17c37e38b /mapper.c | |
| parent | 8c82be43720d9e221a9e2541c9ff6151015838bb (diff) | |
transform to switch case for ppu_tick()
Diffstat (limited to 'mapper.c')
| -rw-r--r-- | mapper.c | 72 |
1 files changed, 36 insertions, 36 deletions
@@ -1,54 +1,54 @@ -#include "mapper_001.c" -// #include "mapper_mmc1.c" -// #include "mapper_uxrom.c" -#include "mapper_066.c" - -struct mapper_entry { - int id; - uint8_t (*prg_read)(struct nes_state *state, uint32_t addr); - void (*prg_write)(struct nes_state *state, uint32_t addr, uint8_t value); - uint8_t (*chr_read)(struct nes_state *state, uint32_t addr); - void (*chr_write)(struct nes_state *state, uint32_t addr, uint8_t value); - uint8_t (*ciram_read)(struct nes_state *state, uint32_t addr); - void (*ciram_write)(struct nes_state *state, uint32_t addr, uint8_t value); - void (*tick)(struct nes_state *state); - void (*init)(struct nes_state *state); -}; +#include "mapper_0000.c" +#include "mapper_0042.c" + + +static uint8_t mapper_default_ciram_read(struct nes_state *state, uint32_t addr) { + if(state->ines.mirroring == 0) { // Horizontal + addr = (addr & 0x800) | (addr & 0x3ff); + } else { // Vertical (default fallback) + addr = addr & 0x7ff; + } + return state->ciram[addr]; +} + +static void mapper_default_ciram_write(struct nes_state *state, uint32_t addr, uint8_t value) { + if(state->ines.mirroring == 0) { + addr = (addr & 0x800) | (addr & 0x3ff); + } else { + addr = addr & 0x7ff; + } + state->ciram[addr] = value; +} + +static void mapper_default_tick(struct nes_state *state) { // No IRQ or timing logic needed +} + +/* + * Mapper numbers are constructed like this: (submapper << 12 | mapperid) both in hex. + * + * NOTE(peter): Mapper 0 always has to be first! + */ static struct mapper_entry mapper_table[] = { - { 0, mapper_001_prg_read, mapper_001_prg_write, mapper_001_chr_read, mapper_001_chr_write, mapper_001_ciram_read, mapper_001_ciram_write, mapper_001_tick, mapper_001_init }, - { 66, mapper_066_prg_read, mapper_066_prg_write, mapper_066_chr_read, mapper_066_chr_write, mapper_066_ciram_read, mapper_066_ciram_write, mapper_066_tick, mapper_066_init }, - // { 1, mapper_mmc1_read, ... }, etc +/* Mapper: 0 */ { 0x00, mapper_0000_prg_read, mapper_0000_prg_write, mapper_0000_chr_read, mapper_0000_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_0000_init }, +/* Mapper: 66 */ { 0x42, mapper_0042_prg_read, mapper_0042_prg_write, mapper_0042_chr_read, mapper_0042_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_0042_init }, }; + static void mapper_setup(struct nes_state *state) { uint32_t mapper = state->ines.mapper; for(uint32_t i = 0; i < sizeof(mapper_table)/sizeof(mapper_table[0]); i++) { if(mapper_table[i].id == mapper) { - state->mapper.prg_read = mapper_table[i].prg_read; - state->mapper.prg_write = mapper_table[i].prg_write; - state->mapper.chr_read = mapper_table[i].chr_read; - state->mapper.chr_write = mapper_table[i].chr_write; - state->mapper.ciram_read = mapper_table[i].ciram_read; - state->mapper.ciram_write = mapper_table[i].ciram_write; - state->mapper.tick = mapper_table[i].tick; - state->mapper.init = mapper_table[i].init; + state->mapper = mapper_table[i]; state->mapper.init(state); return; } } - // NOTE(peter): Not sure how safe this is, but it sure is funny... printf("Unsupported mapper %d, falling back to NROM\n", mapper); - state->mapper.prg_read = mapper_001_prg_read; - state->mapper.prg_write = mapper_001_prg_write; - state->mapper.chr_read = mapper_001_chr_read; - state->mapper.chr_write = mapper_001_chr_write; - state->mapper.ciram_read = mapper_001_ciram_read; - state->mapper.ciram_write = mapper_001_ciram_write; - state->mapper.tick = mapper_001_tick; - state->mapper.init = mapper_001_init; + state->mapper = mapper_table[0]; state->mapper.init(state); } + |
