-
Notifications
You must be signed in to change notification settings - Fork 0
/
Memory.hpp
46 lines (39 loc) · 804 Bytes
/
Memory.hpp
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
/*
* FILENAME: Memory.hpp
* AUTHOR: Josh Trzebiatowski <trzebiatowskj@msoe.edu>
* DATE: April 10, 2015
*/
#ifndef MEMORY_HPP
#define MEMORY_HPP
/*
* Memory namespace, contains simple read and write functions
* to interface with memory addresses
*/
namespace Memory {
/*
* Read a single byte from memory
*/
char read(int address) {
volatile char* ptr = (char*)address;
return *ptr;
}
/*
* Read a range of bytes from memory
*/
char* readRange(int addr1, int addr2) {
char* rv = new char[addr2 - addr1 + 1];
char* wr = rv;
volatile char* ptr = (char*)addr1;
while(ptr <= (char*)addr2)
*(wr++) = *(ptr++);
return rv;
}
/*
* Write a byte to memory
*/
void write(int address, char value) {
volatile char* ptr = (char*)address;
*ptr = value;
}
}
#endif