1 #ifndef _MEMORYMAP_H_ 2 #define _MEMORYMAP_H_ 3 4 #include "Types.h" 5 #include <functional> 6 #include <vector> 7 8 enum MEMORYMAP_ENDIANESS 9 { 10 MEMORYMAP_ENDIAN_LSBF, 11 MEMORYMAP_ENDIAN_MSBF, 12 }; 13 14 class CMemoryMap 15 { 16 public: 17 typedef std::function<uint32(uint32, uint32)> MemoryMapHandlerType; 18 19 enum MEMORYMAP_TYPE 20 { 21 MEMORYMAP_TYPE_MEMORY, 22 MEMORYMAP_TYPE_FUNCTION 23 }; 24 25 struct MEMORYMAPELEMENT 26 { 27 uint32 nStart; 28 uint32 nEnd; 29 void* pPointer; 30 MemoryMapHandlerType handler; 31 MEMORYMAP_TYPE nType; 32 }; 33 typedef std::vector<MEMORYMAPELEMENT> MemoryMapListType; 34 35 virtual ~CMemoryMap() = default; 36 uint8 GetByte(uint32); 37 virtual uint16 GetHalf(uint32) = 0; 38 virtual uint32 GetWord(uint32) = 0; 39 virtual uint32 GetInstruction(uint32) = 0; 40 virtual void SetByte(uint32, uint8); 41 virtual void SetHalf(uint32, uint16) = 0; 42 virtual void SetWord(uint32, uint32) = 0; 43 void InsertReadMap(uint32, uint32, void*, unsigned char); 44 void InsertReadMap(uint32, uint32, const MemoryMapHandlerType&, unsigned char); 45 void InsertWriteMap(uint32, uint32, void*, unsigned char); 46 void InsertWriteMap(uint32, uint32, const MemoryMapHandlerType&, unsigned char); 47 void InsertInstructionMap(uint32, uint32, void*, unsigned char); 48 const MemoryMapListType& GetInstructionMaps(); 49 const MEMORYMAPELEMENT* GetReadMap(uint32) const; 50 const MEMORYMAPELEMENT* GetWriteMap(uint32) const; 51 52 protected: 53 static const MEMORYMAPELEMENT* GetMap(const MemoryMapListType&, uint32); 54 55 MemoryMapListType m_instructionMap; 56 MemoryMapListType m_readMap; 57 MemoryMapListType m_writeMap; 58 59 private: 60 static void InsertMap(MemoryMapListType&, uint32, uint32, void*, unsigned char); 61 static void InsertMap(MemoryMapListType&, uint32, uint32, const MemoryMapHandlerType&, unsigned char); 62 }; 63 64 class CMemoryMap_LSBF : public CMemoryMap 65 { 66 public: 67 uint16 GetHalf(uint32); 68 uint32 GetWord(uint32); 69 uint32 GetInstruction(uint32); 70 void SetHalf(uint32, uint16); 71 void SetWord(uint32, uint32); 72 }; 73 74 #endif 75