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_nrom.c"
// #include "mapper_mmc1.c"
// #include "mapper_uxrom.c"
#include "mapper_gxrom.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_nrom_read, mapper_nrom_write, mapper_nrom_tick, mapper_nrom_init },
{ 66, mapper_66_read, mapper_66_write, mapper_66_tick, mapper_66_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) {
printf("%d\n", 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;
}
}
printf("Unsupported mapper %d, falling back to NROM\n", mapper);
state->mapper.read = mapper_nrom_read;
state->mapper.write = mapper_nrom_write;
state->mapper.tick = mapper_nrom_tick;
state->mapper.init = mapper_nrom_init;
state->mapper.init(state);
}
|