summaryrefslogtreecommitdiff
path: root/mappers/mapper_007_2.c
blob: 9f5a3dcdcfc34330d3bc87ab0c2d4eb68497306d (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
43
44
45
46
47
48
49
50
51
52
53

static uint8_t mapper_007_2_prg_rom_read(struct nes_state *state, uint32_t addr) {
	struct mapper_007_2 *mapper = &state->mapper_data.m007_2;

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

static void mapper_007_2_prg_rom_write(struct nes_state *state, uint32_t addr, uint8_t value) {
	struct mapper_007_2 *mapper = &state->mapper_data.m007_2;
	if(addr >= 0x8000) {
		uint32_t prg_off = (value & 0x0f) << 15;
		uint32_t ciram_off = (value & 0x10) << 11;
		mapper->prg_rom = state->prg_rom + prg_off;
		mapper->ciram = state->ciram + ciram_off;

		// mapper->prg_rom = state->prg_rom + ((value & 0x0f) * 0x8000);
		// mapper->ciram = state->ciram + ((value & 0x10) ? 0x400 : 0x000);
	}
}

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

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

static uint8_t mapper_007_2_ciram_read(struct nes_state *state, uint32_t addr) {
	struct mapper_007_2 *mapper = &state->mapper_data.m007_2;
	return mapper->ciram[addr & 0x3ff];
}

static void mapper_007_2_ciram_write(struct nes_state *state, uint32_t addr, uint8_t value) {
	struct mapper_007_2 *mapper = &state->mapper_data.m007_2;
	mapper->ciram[addr & 0x3ff] = value;
}

static void mapper_007_2_init(struct nes_state *state) {
	struct mapper_007_2 *mapper = &state->mapper_data.m007_2;
	mapper->prg_rom = state->prg_rom;
	mapper->ciram = 0;

	state->mapper_function.prg_rom_read		= mapper_007_2_prg_rom_read;
	state->mapper_function.prg_rom_write	= mapper_007_2_prg_rom_write;
	state->mapper_function.chr_read			= mapper_007_2_chr_read;
	state->mapper_function.chr_write			= mapper_007_2_chr_write;
	state->mapper_function.ciram_read		= mapper_007_2_ciram_read;
	state->mapper_function.ciram_write		= mapper_007_2_ciram_write;
}