-
Notifications
You must be signed in to change notification settings - Fork 0
/
MBC.h
61 lines (52 loc) · 1.23 KB
/
MBC.h
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
#ifndef _MBC_HPP
#define _MBC_HPP
#include <cstdint>
#include <fstream>
#include <array>
#include <iostream>
class Bus;
class MBC
{
public:
MBC(std::ifstream & in) : input(in)
{
input.read((char*)romBank0, 0x4000);
romType = romBank0[0x0147];
romSizeHeader = romBank0[0x0148];
ramSizeHeader = romBank0[0x0149];
ramSize = std::array<int,6>{0x0,0x800,0x2000,0x8000,0x20'000,0x10'000}[ramSizeHeader];
romSize = 0x8000 << romSizeHeader;
extRam = new uint8_t[ramSize];
std::cout << "Color flag: " << std::hex<<std::showbase<< (int)romBank0[0x143] << std::endl;
}
virtual void save(std::string path)
{
;//EMPTY
}
virtual void load(std::string path)
{
;//EMPTY
}
void attachBus(Bus * b)
{
bus = b;
}
virtual ~MBC()
{
if(extRam)
delete[] extRam;
}
virtual uint8_t read(uint16_t adr) = 0;
virtual void write(uint16_t adr, uint8_t data) = 0;
protected:
std::ifstream &input;
uint8_t romType;
uint8_t romSizeHeader;
uint8_t ramSizeHeader;
int ramSize;
int romSize;
uint8_t romBank0[0x4000];
uint8_t * extRam = nullptr;
Bus * bus;
};
#endif // _MBC_HPP