-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInterconnect.cpp
47 lines (40 loc) · 2.13 KB
/
Interconnect.cpp
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
#include "Interconnect.hpp"
#include "Range.hpp"
#include "EmulatorRunner.hpp"
#include "Interconnect.tcc"
using namespace std;
const uint32_t regionMask[8] = {
// KUSEG: 2048MB
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
// KSEG0: 512MB
0x7fffffff,
// KSEG1: 512MB
0x1fffffff,
// KSEG2: 1024MB
0xffffffff, 0xffffffff,
};
Interconnect::Interconnect(LogLevel logLevel, std::unique_ptr<COP0> &cop0, unique_ptr<BIOS> &bios, unique_ptr<RAM> &ram, unique_ptr<GPU> &gpu, unique_ptr<DMA> &dma, unique_ptr<Scratchpad> &scratchpad, unique_ptr<CDROM> &cdrom, unique_ptr<InterruptController> &interruptController, unique_ptr<Expansion1> &expansion1, std::unique_ptr<Timer0> &timer0, std::unique_ptr<Timer1> &timer1, std::unique_ptr<Timer2> &timer2, std::unique_ptr<Controller> &controller, std::unique_ptr<SPU> &spu) : logger(logLevel), cop0(cop0), bios(bios), ram(ram), gpu(gpu), dma(dma), scratchpad(scratchpad), cdrom(cdrom), interruptController(interruptController), expansion1(expansion1), timer0(timer0), timer1(timer1), timer2(timer2), controller(controller), spu(spu) {
filesystem::path biosFilePath = filesystem::current_path() / "SCPH1001.BIN";
bios->loadBin(biosFilePath);
EmulatorRunner *emulatorRunner = EmulatorRunner::getInstance();
if (emulatorRunner->shouldRunTests()) {
filesystem::path expansionFilePath = filesystem::current_path() / "expansion" / "EXPNSION.BIN";
expansion1->loadBin(expansionFilePath);
} else if (emulatorRunner->shouldLoadExpansionROM()) {
expansion1->loadBin(emulatorRunner->romFilePath());
uint32_t maskedAddress = maskRegion(0x1F020018);
store<uint32_t>(maskedAddress, 0x1);
}
}
Interconnect::~Interconnect() {}
uint32_t Interconnect::maskRegion(uint32_t address) const {
uint8_t index = address >> 29;
return address & regionMask[index];
}
void Interconnect::transferToRAM(filesystem::path filePath, uint32_t origin, uint32_t size, uint32_t destination) {
uint32_t maskedDestination = maskRegion(destination);
ram->receiveTransfer(filePath, origin, size, maskedDestination);
}
void Interconnect::dumpRAM() {
ram->dump();
}