Browse Source

WIP: Added RAM implementation.

master
Ian Burgmyer 4 years ago
parent
commit
e2bd300704
  1. 1
      CMakeLists.txt
  2. 9
      libplip/PlipMemoryMap.cpp
  3. 1
      libplip/PlipMemoryMap.h
  4. 29
      libplip/PlipMemoryRam.cpp
  5. 24
      libplip/PlipMemoryRam.h

1
CMakeLists.txt

@ -36,6 +36,7 @@ add_library(${lib_name}
libplip/PlipInput.cpp
libplip/PlipInputDefinition.cpp
libplip/PlipMemoryMap.cpp
libplip/PlipMemoryRam.cpp
)
add_dependencies(${lib_name} GENERATE_LIB_VERSION_HEADER)

9
libplip/PlipMemoryMap.cpp

@ -8,6 +8,10 @@
#include "PlipMemoryMap.h"
namespace Plip {
void PlipMemoryMap::AddBlock(PlipMemory *memory, uint32_t offset) {
AddBlock(memory, offset, memory->GetLength());
}
void PlipMemoryMap::AddBlock(PlipMemory *memory, uint32_t offset, uint32_t length) {
uint32_t start = 0;
@ -25,11 +29,12 @@ namespace Plip {
}
std::tuple<PlipMemory*, uint32_t> PlipMemoryMap::FindAddress(uint32_t address) {
printf("Finding memory address: 0x%.8X\n", address);
for(auto const &memory : m_range) {
if(address < memory.startAddress || address > memory.startAddress + memory.length)
if(address < memory.startAddress || address > memory.startAddress + memory.length - 1)
continue;
return { memory.memory, address - memory.startAddress };
return { memory.memory, address - memory.startAddress + memory.offset };
}
return { nullptr, 0 };

1
libplip/PlipMemoryMap.h

@ -20,6 +20,7 @@ namespace Plip {
class PlipMemoryMap {
public:
void AddBlock(PlipMemory *memory, uint32_t offset);
void AddBlock(PlipMemory *memory, uint32_t offset, uint32_t length);
uint8_t GetByte(uint32_t address);
uint32_t GetLength();

29
libplip/PlipMemoryRam.cpp

@ -0,0 +1,29 @@
/* PlipMemoryRam.cpp
*
* A random access memory implementation.
*/
#include "PlipMemoryRam.h"
namespace Plip {
PlipMemoryRam::PlipMemoryRam(uint32_t amount) {
m_data = new uint8_t[amount] {};
m_length = amount;
}
PlipMemoryRam::~PlipMemoryRam() {
delete m_data;
}
uint8_t PlipMemoryRam::GetByte(uint32_t address) {
return m_data[address];
}
uint32_t PlipMemoryRam::GetLength() {
return m_length;
}
void PlipMemoryRam::SetByte(uint32_t address, uint8_t value) {
m_data[address] = value;
}
}

24
libplip/PlipMemoryRam.h

@ -0,0 +1,24 @@
/* PlipMemoryRam.h
*
* A random access memory implementation.
*/
#pragma once
#include "PlipMemory.h"
namespace Plip {
class PlipMemoryRam : public PlipMemory {
public:
explicit PlipMemoryRam(uint32_t amount);
~PlipMemoryRam();
uint8_t GetByte(uint32_t address) override;
uint32_t GetLength() override;
void SetByte(uint32_t address, uint8_t value) override;
private:
uint32_t m_length;
uint8_t *m_data;
};
}
Loading…
Cancel
Save