1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "mapper_001.c"
// #include "mapper_mmc1.c"
// #include "mapper_uxrom.c"
#include "mapper_066.c"
struct mapper_entry {
int id;
uint8_t (*read)(struct nes_state *state, uint32_t addr);
void (*write)(struct nes_state *state, uint32_t addr, uint8_t value);
void (*tick)(struct nes_state *state);
void (*init)(struct nes_state *state);
};
static struct mapper_entry mapper_table[] = {
{ 0, mapper_001_read, mapper_001_write, mapper_001_tick, mapper_001_init },
{ 66, mapper_066_read, mapper_066_write, mapper_066_tick, mapper_066_init },
// { 1, mapper_mmc1_read, ... }, etc
};
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.read = mapper_table[i].read;
state->mapper.write = mapper_table[i].write;
state->mapper.tick = mapper_table[i].tick;
state->mapper.init = mapper_table[i].init;
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.read = mapper_001_read;
state->mapper.write = mapper_001_write;
state->mapper.tick = mapper_001_tick;
state->mapper.init = mapper_001_init;
state->mapper.init(state);
}
|