-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapper003.cpp
More file actions
33 lines (25 loc) · 1.16 KB
/
mapper003.cpp
File metadata and controls
33 lines (25 loc) · 1.16 KB
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
#include "mapper003.hpp"
/**** iNES mapper 003 ****/
uint32_t Mapper003::MapReadPRG(uint16_t address, bool &fromRAM)
{
uint32_t mappedAddress = 0x00000000;
if (numBanksPRG == 1) // mapped PRG address == first 14 bits if 16 KiB (0x8000 - 0xBFFF mirrored 0xC000 - 0xFFFF)
mappedAddress = address &= 0x3FFF;
else if (numBanksPRG == 2) // mapped PRG address == first 15 bits if 32 KiB (0x8000 - 0xFFFF)
mappedAddress = address &= 0x7FFF;
return mappedAddress;
}
uint32_t Mapper003::MapWritePRG(uint16_t address, uint8_t data, bool &toRAM)
{
if (address >= 0x8000 && address <= 0xFFFF) // writing to 0x8000 - 0xFFFF selects CHR bank
mappedCHRBank = data;
return 0x00000000;
}
uint32_t Mapper003::MapReadCHR(uint16_t address)
{
return mappedCHRBank * 0x2000 + address; // mapped CHR address == index of CHR bank * 8 KiB + offset
}
uint32_t Mapper003::MapWriteCHR(uint16_t address)
{
return mappedCHRBank * 0x2000 + address; // mapped CHR address == index of CHR bank * 8 KiB + offset
}