-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameBoy.cpp
35 lines (26 loc) · 849 Bytes
/
GameBoy.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
//
// Created by Christian aan de Wiel on 08/03/2021.
//
#include "GameBoy.h"
void GameBoy::loadRom(const std::string &filename) {
std::ifstream file(filename, std::ios::binary);
file.unsetf(std::ios::skipws);
std::streampos fileSize;
if (!file) {
throw std::runtime_error("Could not loadFromMemoryBus rom");
}
file.seekg(0, std::ios::end);
fileSize = file.tellg();
file.seekg(0, std::ios::beg);
std::vector<uint8_t> content;
content.reserve(fileSize);
content.insert(content.begin(), std::istream_iterator<uint8_t>(file), std::istream_iterator<uint8_t>());
this->memoryBus->loadRom(std::move(content));
}
GameBoy::GameBoy() {
this->memoryBus = std::make_shared<MemoryBus>();
this->cpu = std::make_unique<CPU>(this->memoryBus);
}
void GameBoy::run() {
this->cpu->run();
}