1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-12-21 12:29:51 +00:00
r65emu/memory.h

60 lines
1.2 KiB
C
Raw Normal View History

2014-11-10 14:16:45 +00:00
#ifndef __MEMORY_H__
#define __MEMORY_H__
2014-10-18 11:33:48 +00:00
class Stream;
class Checkpointable {
public:
virtual void checkpoint(Stream &s) = 0;
virtual void restore(Stream &s) = 0;
};
2014-10-18 11:33:48 +00:00
class Memory {
public:
2018-08-13 13:41:23 +00:00
typedef uint16_t address;
2014-11-29 13:36:51 +00:00
static const unsigned page_size = 256;
2014-10-18 11:33:48 +00:00
2014-10-21 18:41:44 +00:00
class Device: public Checkpointable {
2014-10-18 11:33:48 +00:00
public:
2018-08-13 13:41:23 +00:00
Device (unsigned uint8_ts): _pages(uint8_ts/page_size) {}
2014-10-18 11:33:48 +00:00
virtual ~Device () {}
2014-10-21 18:41:44 +00:00
2014-11-29 13:36:51 +00:00
unsigned pages () const { return _pages; }
2014-10-18 11:33:48 +00:00
void access (address a) { _acc=a-_base; }
void base (address a) { _base=a; }
address base () const { return _base; }
2018-08-13 13:41:23 +00:00
virtual void operator= (uint8_t) =0;
virtual operator uint8_t () =0;
2014-10-18 11:33:48 +00:00
2014-10-21 18:41:44 +00:00
virtual void checkpoint(Stream &s) {};
virtual void restore(Stream &s) {};
2014-10-18 11:33:48 +00:00
protected:
address _acc, _base;
2014-10-22 19:14:23 +00:00
2014-10-18 11:33:48 +00:00
private:
2014-10-22 19:14:23 +00:00
friend class Memory;
2014-11-29 13:36:51 +00:00
unsigned _pages;
2014-10-18 11:33:48 +00:00
};
// insert a new device instance
//
void put (Device &d, address at);
2014-11-29 13:36:51 +00:00
void put (Device &d, address at, unsigned ep) { d._pages = ep; put(d, at); }
2014-10-18 11:33:48 +00:00
Device *get (address at) const { return _pages[at/page_size]; }
// primary access interface
//
2018-08-10 10:13:45 +00:00
Device &operator[] (address a) {
2014-10-18 11:33:48 +00:00
Device *d = get (a);
d->access (a);
return *d;
}
2014-10-31 08:44:57 +00:00
void begin();
2014-10-18 11:33:48 +00:00
private:
Device *_pages[256];
};
#endif