1 | #include "ppu.hpp" |
---|---|
2 | #include "mappers/mapper3.hpp" |
3 | |
4 | /* Based off of https://wiki.nesdev.com/w/index.php/INES_Mapper_003 */ |
5 | |
6 | /* Apply the registers state */ |
7 | void Mapper3::apply() |
8 | { |
9 | if (PRG_size_16k) |
10 | { |
11 | /* |
12 | * mirror the bottom on the top |
13 | * 0x8000 - 0xBFFF == |
14 | * 0xC000 - 0xFFFF |
15 | */ |
16 | map_prg<16>(0,0); |
17 | map_prg<16>(1,0); |
18 | } |
19 | else |
20 | { |
21 | /* no mirroring */ |
22 | map_prg<16>(0,0); |
23 | map_prg<16>(1,1); |
24 | } |
25 | |
26 | /* 8k bankswitched CHR */ |
27 | map_chr<8>(0, regs[0] & 0b11); |
28 | |
29 | /* mirroring is based on the header (soldered) */ |
30 | set_mirroring(vertical_mirroring?PPU::VERTICAL:PPU::HORIZONTAL); |
31 | } |
32 | |
33 | u8 Mapper3::write(u16 addr, u8 v) |
34 | { |
35 | /* check for bus contingency? */ |
36 | |
37 | /* chr bank switching */ |
38 | if (addr & 0x8000) |
39 | { |
40 | regs[0] = v; |
41 | apply(); |
42 | } |
43 | return v; |
44 | } |
45 | |
46 | u8 Mapper3::chr_write(u16 addr, u8 v) |
47 | { |
48 | return chr[addr] = v; |
49 | } |
50 | |
51 |