summaryrefslogtreecommitdiff
path: root/mapper.c
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-05-02 23:15:47 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-05-02 23:15:47 +0200
commit5808f00555c48e1cc1cc110af6a5cd73ddf13010 (patch)
treedff942b61441bafe297e7a99f0e799f32ae978b1 /mapper.c
parent9463faa436e1b981ef72000568445a83682f2658 (diff)
cleanup and rewrite of ppu_registers.c
Diffstat (limited to 'mapper.c')
-rw-r--r--mapper.c67
1 files changed, 0 insertions, 67 deletions
diff --git a/mapper.c b/mapper.c
deleted file mode 100644
index 935ff61..0000000
--- a/mapper.c
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-#include "mapper_0000.c"
-#include "mapper_0003.c"
-#include "mapper_0007.c"
-#include "mapper_000b.c"
-#include "mapper_0042.c"
-#include "mapper_2002.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[] = {
-/* 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: 2 */ { 0x02, mapper_2002_prg_read, mapper_2002_prg_write, mapper_2002_chr_read, mapper_2002_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_2002_init },
-/* Mapper: 3 */ { 0x03, mapper_0003_prg_read, mapper_0003_prg_write, mapper_0003_chr_read, mapper_0003_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_0003_init },
-/* Mapper: 7 */ { 0x7, mapper_0007_prg_read, mapper_0007_prg_write, mapper_0007_chr_read, mapper_0007_chr_write, mapper_0007_ciram_read, mapper_0007_ciram_write, mapper_default_tick, mapper_0007_init },
-/* Mapper: b */ { 0x0b, mapper_000b_prg_read, mapper_000b_prg_write, mapper_000b_chr_read, mapper_000b_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_000b_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 },
-/* Mapper: 2002 */ { 0x2002, mapper_2002_prg_read, mapper_2002_prg_write, mapper_2002_chr_read, mapper_2002_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_2002_init },
-/* Mapper: 2003 */ { 0x2003, mapper_0003_prg_read, mapper_0003_prg_write, mapper_0003_chr_read, mapper_0003_chr_write, mapper_default_ciram_read, mapper_default_ciram_write, mapper_default_tick, mapper_0003_init },
-/* Mapper: 7 */ { 0x2007, mapper_0007_prg_read, mapper_0007_prg_write, mapper_0007_chr_read, mapper_0007_chr_write, mapper_0007_ciram_read, mapper_0007_ciram_write, mapper_default_tick, mapper_0007_init },
-};
-
-static void mapper_setup(struct nes_state *state) {
- uint32_t mapper = (state->ines.submapper << 12) | state->ines.mapper;
- for(uint32_t i = 0; i < sizeof(mapper_table)/sizeof(mapper_table[0]); i++) {
- if(mapper_table[i].id == mapper) {
- printf("Mapper %4.4x\n", mapper);
- memcpy(&state->mapper, &mapper_table[i], sizeof(struct mapper_entry)); // NOTE(peter): BECAUSE GCC IS BROKEN
- // state->mapper = mapper_table[i];
- state->mapper.init(state);
- return;
- }
- }
-
- printf("Unsupported mapper %4.4x, falling back to NROM\n", mapper);
- memcpy(&state->mapper, &mapper_table[0], sizeof(struct mapper_entry)); // NOTE(peter): BECAUSE GCC IS BROKEN
- // state->mapper = mapper_table[0];
- state->mapper.init(state);
-}
-