-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPRG.cpp
More file actions
61 lines (49 loc) · 1.12 KB
/
PRG.cpp
File metadata and controls
61 lines (49 loc) · 1.12 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
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
60
61
#include "PRG.h"
#include "SDL_log.h"
PRG::PRG(uint8_t size, uint8_t* rawPrgROM = nullptr) : size(size), ROM(rawPrgROM)
{
if (!rawPrgROM)
{
ROM = new uint8_t[size * PRG::BANK_SIZE];
}
bank1 = bank2 = ROM;
if (size >= 2) // more than one bank in ROM, map second to [0xC000, 0xFFFF]
{
bank2 = ROM + PRG::BANK_SIZE;
}
}
PRG::~PRG()
{
delete[] ROM;
}
//Get pointer to PRG ROM address
uint8_t* PRG::getPtr(uint16_t address)
{
if (address >= PRG::BANK_SIZE)
{
return bank2 + (address - PRG::BANK_SIZE);
}
return bank1 + address;
}
void PRG::mapBank1(uint8_t bankNum)
{
if (bankNum >= size)
{
SDL_LogWarn(0, "Attempted to map PRG bank1 to invalid number %d (PRG size: %d)", bankNum, size);
return;
}
bank1 = ROM + (bankNum * PRG::BANK_SIZE);
}
void PRG::mapBank2(uint8_t bankNum)
{
if (bankNum >= size)
{
SDL_LogWarn(0, "Attempted to map PRG bank2 to invalid number %d (PRG size: %d)", bankNum, size);
return;
}
bank2 = ROM + (bankNum * PRG::BANK_SIZE);
}
uint8_t PRG::getSize()
{
return size;
}