Comments
Loading Dream Comments...
You must be logged in to write a comment - Log In
static int g_FrameCount = 0; // GLOBAL check to cause swapping when no more RAM
static PageFrame* g_LRUhead = NULL; // GLOBAL LRU list head
static int g_SwapLBA = 0; // GLOBAL Swappable Page LBA
class PageHeader {
DaTime m_timestamp;
char m_name[16]; // TODO
unsigned long m_chksum; // TODO
byte m_attribflags; // TODO
unsigned long m_version; // TODO
AddressRegister m_AddressRegs[32]; //TODO
public:
PageHeader() {
m_timestamp = NOW;
}
};
class PageFrame {
PageFrame* m_LRUprior;
PageFrame* m_LRUnext;
handle m_h;
int m_lba;
PageHeader m_ph;
unsigned char m_page [32768];
public:
PageFrame(handle h, int lba) {
g_FrameCount++;
m_LRUnext = g_LRUhead; // Put this page on the front of the list
g_LRUhead = this;
m_LRUprior = NULL; // This is the most recent page
m_h = h;
m_lba = lba;
FILE_READ(m_h, m_lba, &m_page);
}
~PageFrame(void) {
g_FrameCount--;
this.CheckPoint();
PageFrame* p = m_LRUprior;
PageFrame* n = m_LRUnext;
p->m_LRUnext = n;
if (n==NULL) g_SwapLBA = p->m_lba;
n->m_LRUprior = p;
}
void CheckPoint(void) {
m_timestamp = NOW;
FILE_WRITE(m_h, m_lba, m_page);
}
void* operator() () {
// Put us at the front of the LRU list
PageFrame* p = m_LRUprior;
PageFrame* n = m_LRUnext;
m_LRUprior = NULL;
m_LRUnext = g_LRUhead;
g_LRUhead = this;
p->m_LRUnext = n;
if (n==NULL) g_SwapLBA = p->m_lba;
n->m_LRUprior = p;
return m_page;
}
};
//For the MS-Windows version, define FILE_READ and FILE_WRITE as their Win32 equivalents. For standalone (BIOS) mode, define them using INT 13h calls. For Linux or Mac systems, use the appropriate API's. Have phun :)