public MemoryPage FindPage(int address) { // If the address isn't out of bounds, use the same page if (address >= m_CurrentAddressOffset && address < m_CurrentAddressBound) { return(m_CurrentPage); } // Else we need to figure out the new page to access MemoryPage page = null; // Check each offset address and see where address falls in range with foreach (int offset in m_Pages.Keys) { // if address is >= of that key, it is a possible page if (address >= offset) { // Get the reference of the page if (m_Pages.TryGetValue(offset, out page)) { // if the address within bounds of the page, then get it, else keep searching if (address < (offset + page.Size)) { m_CurrentPage = page; m_CurrentAddressBound = offset + page.Size; m_CurrentAddressOffset = offset; return(page); } } } } return(page); }
public Memory(VirtualMachine machine) { m_ParentMachine = machine; m_MemBound = 0; m_CurrentAddressOffset = 0; m_CurrentAddressBound = 0; m_Pages = new Dictionary <int, MemoryPage>(); m_CurrentPage = null; AllocatePages(); }
protected void AddManualPage(int address, MemoryPage page) { m_Pages.Add(address, page); }
protected void AddPage(MemoryPage page) { m_Pages.Add(m_MemBound, page); m_MemBound += page.Size; }