-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmemory.cc
More file actions
53 lines (43 loc) · 1.19 KB
/
memory.cc
File metadata and controls
53 lines (43 loc) · 1.19 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
46
47
48
49
50
51
52
53
// This file is part of the PiEMU Project
// Licensing information can be found in the LICENSE file
// (C) 2014 Nandor Licker. All rights reserved.
#include "common.h"
// -----------------------------------------------------------------------------
Memory::Memory(Emulator &emu, uint32_t ramSize, uint32_t vramSize)
: emu(emu)
, ramSize(ramSize)
, ram(nullptr)
, vramSize(vramSize)
, vram(nullptr)
{
ram = new uint8_t[ramSize];
memset(ram, 0, ramSize);
vram = ram + ramSize - vramSize;
}
// -----------------------------------------------------------------------------
Memory::~Memory()
{
delete[] ram;
}
// -----------------------------------------------------------------------------
void Memory::LoadImage(const std::string& image, size_t start)
{
std::ifstream file;
size_t size;
file.open(image, std::ios::binary);
if (!file.is_open())
{
EXCEPT << "Cannot open file '" << image << "'";
}
file.seekg(0, file.end);
size = file.tellg();
file.seekg(0, file.beg);
if (start + size >= ramSize - vramSize)
{
EXCEPT << "Image '" << image << "' too large";
}
if (!file.read((char*)(ram + start), size))
{
EXCEPT << "Cannot read '" << image << "'";
}
}