summaryrefslogtreecommitdiff
path: root/mappers/mapper_007_2.c
blob: c42bc62f8ee07de7ad0cccd83974d98a44136779 (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
54
55
56
57
58
59

__attribute__((section(".mapper_007_2")))
static uint8_t mapper_007_2_prg_read(struct nes_state *state, uint32_t addr) {
	struct mapper_007_2 *mapper = (struct mapper_007_2 *)&state->map;
	if(addr >= 0x8000) {
		return mapper->prg_rom[addr & 0x7fff];
	}
	return 0;
}

__attribute__((section(".mapper_007_2")))
static void mapper_007_2_prg_write(struct nes_state *state, uint32_t addr, uint8_t value) {
	struct mapper_007_2 *mapper = (struct mapper_007_2 *)&state->map;
	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);
	}
}

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

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

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

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

__attribute__((section(".mapper_007_2")))
static void mapper_007_2_init(struct nes_state *state) {
	struct mapper_007_2 *mapper = (struct mapper_007_2 *)&state->map;
	mapper->prg_rom = state->prg_rom;
	mapper->ciram = 0;

	state->mapper.prg_read		= mapper_007_2_prg_read;
	state->mapper.prg_write		= mapper_007_2_prg_write;
	state->mapper.chr_read		= mapper_007_2_chr_read;
	state->mapper.chr_write		= mapper_007_2_chr_write;
	state->mapper.ciram_read	= mapper_007_2_ciram_read;
	state->mapper.ciram_write	= mapper_007_2_ciram_write;
}