summaryrefslogtreecommitdiff
path: root/mappers/mapper_066_0.c
blob: 9629fb2437ff2d8dcaafd0be27a4c2d02751dac7 (plain)
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

__attribute__((section(".mapper_066_0")))
static uint8_t mapper_066_0_prg_read(struct nes_state *state, uint32_t addr) {
	struct mapper_066_0 *mapper = (struct mapper_066_0 *)&state->map;

	if(addr >= 0x8000) {
		return state->prg_rom[addr & 0x7fff];
	}
	return 0;
}

__attribute__((section(".mapper_066_0")))
static void mapper_066_0_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) {
	struct mapper_066_0 *mapper = (struct mapper_066_0 *)&state->map;

	if(addr >= 0x8000) {
		uint32_t prg_bank = (value >> 4) & 3;
		uint32_t chr_bank = (value >> 0) & 3;

		mapper->prg_offset = state->prg_rom + (prg_bank * 0x8000);
		mapper->chr_offset = state->chr_rom + (chr_bank * 0x2000);
	}
}

__attribute__((section(".mapper_066_0")))
static uint8_t mapper_066_0_chr_read(struct nes_state *state, uint32_t addr) {
	struct mapper_066_0 *mapper = (struct mapper_066_0 *)&state->map;
	return mapper->chr_offset[addr];
}

__attribute__((section(".mapper_066_0")))
static void mapper_066_0_init(struct nes_state *state) {
	struct mapper_066_0 *mapper = (struct mapper_066_0 *)&state->map;

	mapper->prg_offset = state->prg_rom;
	mapper->chr_offset = state->chr_rom;

	state->mapper.prg_read	= mapper_066_0_prg_read;
	state->mapper.prg_write	= mapper_066_0_prg_write;
	state->mapper.chr_read	= mapper_066_0_chr_read;
}