-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRAM.h
More file actions
39 lines (32 loc) · 672 Bytes
/
RAM.h
File metadata and controls
39 lines (32 loc) · 672 Bytes
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
#pragma once
#include <vector>
#include <array>
#include <stdexcept>
class RAM
{
private:
std::array<uint8_t, 0xFFFF> data = {0};
public:
RAM();
~RAM();
void write(uint16_t dest, uint8_t source)
{
if(dest > 0xFFFF || dest < 0x0000)
{
char hex_repr[4];
//sprintf(hex_repr, "%04X", dest);
throw std::out_of_range("RAM addressed out of bounds at address: " + dest);
}
data[dest] = source;
}
uint8_t read(uint16_t source)
{
if(source > 0xFFFF || source < 0x0000)
{
char hex_repr[4];
//sprintf(hex_repr, "%04X", source);
throw std::out_of_range("RAM addressed out of bounds at address: " + source);
}
return data[source];
}
};