1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-12-27 05:32:04 +00:00
r65emu/memory.h

62 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
typedef unsigned char byte;
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:
typedef unsigned short 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:
2014-11-29 13:36:51 +00:00
Device (unsigned bytes): _pages(bytes/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; }
virtual void operator= (byte) =0;
virtual operator byte () =0;
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
//
Device &operator[] (address a) {
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