summaryrefslogtreecommitdiff
path: root/mappers/mapper_002_2.c
blob: 2145b52ea51bea1b3e59c0d5dbddef2767eb9848 (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


static uint8_t mapper_002_2_prg_rom_read(struct nes_state *state, uint32_t addr) {
	struct mapper_002_2 *mapper = &state->mapper_data.m002_2;

	if(addr >= 0xc000) {
		return mapper->prg_bank1[addr & 0x3fff];
	}
	return mapper->prg_bank0[addr & 0x3fff];
}

static void mapper_002_2_prg_rom_write(struct nes_state *state, uint32_t addr, uint8_t value) {
	struct mapper_002_2 *mapper = &state->mapper_data.m002_2;

	mapper->prg_bank0 = state->prg_rom + ((value & 0x0f) * 0x4000);
}

static uint8_t mapper_002_2_chr_read(struct nes_state *state, uint32_t addr) {
	return state->chr_ram[addr];
}

static void mapper_002_2_chr_write(struct nes_state *state, uint32_t addr, uint8_t value) {
	state->chr_ram[addr] = value;
}

static void mapper_002_2_init(struct nes_state *state) {
	struct mapper_002_2 *mapper = &state->mapper_data.m002_2;

	mapper->prg_bank0 = state->prg_rom;
	mapper->prg_bank1 = state->prg_rom + state->ines.prg_size - 0x4000;

	state->mapper_function.prg_rom_read		= mapper_002_2_prg_rom_read;
	state->mapper_function.prg_rom_write	= mapper_002_2_prg_rom_write;
	state->mapper_function.chr_read			= mapper_002_2_chr_read;
	state->mapper_function.chr_write			= mapper_002_2_chr_write;
}