-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsprom.h
39 lines (30 loc) · 931 Bytes
/
sprom.h
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
#ifndef _SPROM_H
#define _SPROM_H
// a switchable prom: the state of the switch is checkpointable
class sprom: public prom {
public:
sprom(const byte *mem, int bytes): prom(mem, bytes) {}
void delegate(Checkpointable *chk) { _chk = chk; }
void checkpoint(Stream &s) { _chk->checkpoint(s); }
void restore(Stream &s) { _chk->restore(s); }
private:
Checkpointable *_chk;
};
extern Memory memory;
// manages a set of proms
class promswitch: public Checkpointable {
public:
promswitch(sprom *sproms, int n, Memory::address addr): _sproms(sproms), _n(n), _curr(0), _addr(addr) {
for (int i = 0; i < n; i++)
sproms[i].delegate(this);
}
void set(int c) { _curr=c; memory.put(_sproms[c], _addr); }
void next() { int c=_curr; set(++c == _n? 0: c); }
void checkpoint(Stream &s) { s.write(_curr); }
void restore(Stream &s) { set(s.read()); }
private:
sprom *_sproms;
int _n, _curr;
Memory::address _addr;
};
#endif