-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmemory.h
More file actions
59 lines (47 loc) · 1.19 KB
/
Copy pathmemory.h
File metadata and controls
59 lines (47 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
54
55
56
57
58
59
#ifndef __MEMORY_H__
#define __MEMORY_H__
class Stream;
class Checkpointable {
public:
virtual void checkpoint(Stream &s) = 0;
virtual void restore(Stream &s) = 0;
};
class Memory {
public:
typedef uint16_t address;
static const unsigned page_size = 256;
class Device: public Checkpointable {
public:
Device (unsigned uint8_ts): _pages(uint8_ts/page_size) {}
virtual ~Device () {}
unsigned pages () const { return _pages; }
void access (address a) { _acc=a-_base; }
void base (address a) { _base=a; }
address base () const { return _base; }
virtual void operator= (uint8_t) =0;
virtual operator uint8_t () =0;
virtual void checkpoint(Stream &s) {};
virtual void restore(Stream &s) {};
protected:
address _acc, _base;
private:
friend class Memory;
unsigned _pages;
};
// insert a new device instance
//
void put (Device &d, address at);
void put (Device &d, address at, unsigned ep) { d._pages = ep; put(d, at); }
Device *get (address at) const { return _pages[at/page_size]; }
// primary access interface
//
Device &operator[] (address a) {
Device *d = get (a);
d->access (a);
return *d;
}
void begin();
private:
Device *_pages[256];
};
#endif