-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rom.cpp
68 lines (59 loc) · 1.15 KB
/
Rom.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "Rom.hpp"
#include <fstream>
#include <iostream>
#include <string>
static Rom * instance = nullptr;
Rom * Rom::get_instance()
{
if (instance == nullptr)
{
instance = new Rom();
}
return instance;
}
bool Rom::is_address_for_device(unsigned int address)
{
if (address >= 0x1FC00000 && address < 0x1FC00000 + BIOS_SIZE)
{
return true;
}
else if (address >= 0x9FC00000 && address < 0x9FC00000 + BIOS_SIZE)
{
return true;
}
else if (address >= 0xBFC00000 && address < 0xBFC00000 + BIOS_SIZE)
{
return true;
}
return false;
}
unsigned char Rom::get_byte(unsigned int address)
{
return bios[address & 0x000FFFFF];
}
bool Rom::load_bios(std::string bios_filepath)
{
if (bios_filepath.empty() == false)
{
std::ifstream bios_file(bios_filepath);
if (bios_file.good())
{
bios_file.seekg(0, std::ios::end);
std::streampos len = bios_file.tellg();
bios_file.seekg(0, std::ios::beg);
bios_file.read((char*)&bios, len);
bios_file.close();
}
else
{
std::cerr << "Unable to load " << bios_filepath << "\n";
return false;
}
}
else
{
std::cerr << "No bios file specified!\n";
return false;
}
return true;
}