-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGBLoader.cpp
More file actions
45 lines (41 loc) · 1.34 KB
/
GBLoader.cpp
File metadata and controls
45 lines (41 loc) · 1.34 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
#include <fstream>
#include <cstdint>
#include <filesystem>
#include "Sim.h"
#include "gb.h" //In lab, we included this because we implemented several Y86 funcs in here.
//Note to us: we may not even need half of this stuff; GB roms are already compiled to binary so itt we will just do a dumb unload into ram at 0x0100 (until mappers).
/*
* load
* Sets our status to OK, then checks the filename. If the filename is valid, then we proceed to readFile.
*/
bool gb::load(std::string filename){
bool status = true;
status = std::filesystem::exists(filename);
if(status) status = readFile(filename);
return status;
}
void gb::readBootRom(){
bool status = true;
std::ifstream file("asm/DMG_ROM.bin", std::ios::binary);
int baddy = PC_START;
int len = CART_HEADER - 1;
for(int i = 0; i <= len; i++){
getMemory().putByte((baddy + i), file.get());
}
file.close();
}
/*
* readFile
* Loads a file into Memory, by using successive calls to putByte().
*/
bool gb::readFile(std::string filename){
bool status = true;
std::ifstream file(filename, std::ios::binary);
int baddy = CART_HEADER; // byte address will just begin at 0x0100.
int len = (ROM_END - CART_HEADER);
for(int i = 0; i <= len; i++){
getMemory().putByte((baddy + i), file.get());
}
file.close();
return status;
}