initial commit
This commit is contained in:
44
memory.cpp
Normal file
44
memory.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "memory.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "Bus.h"
|
||||
|
||||
CPUMemoryAccessor::CPUMemoryAccessor(Bus* bus)
|
||||
{
|
||||
ram = static_cast<std::uint8_t*>(malloc(0x0200));
|
||||
this->bus = bus;
|
||||
}
|
||||
|
||||
void CPUMemoryAccessor::write(std::uint16_t _addr, std::uint8_t value)
|
||||
{
|
||||
if (isRamAddress(_addr))
|
||||
{
|
||||
writeToRam(_addr, value);
|
||||
}
|
||||
}
|
||||
|
||||
std::uint8_t CPUMemoryAccessor::read8(const std::uint16_t _addr)
|
||||
{
|
||||
if (isRamAddress(_addr))
|
||||
{
|
||||
return readFromRam(_addr);
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
std::uint8_t CPUMemoryAccessor::readFromRam(const std::uint16_t _addr) const
|
||||
{
|
||||
return ram[_addr];
|
||||
}
|
||||
|
||||
void CPUMemoryAccessor::writeToRam(const std::uint16_t _addr, const std::uint8_t value) const
|
||||
{
|
||||
ram[_addr] = value;
|
||||
}
|
||||
|
||||
bool CPUMemoryAccessor::isRamAddress(const std::uint16_t _addr)
|
||||
{
|
||||
return _addr <= 0x0200;
|
||||
}
|
||||
Reference in New Issue
Block a user