vgbc/memory/ram.cpp

21 lines
450 B
C++

#include "ram.h"
#include <cstring>
RAM::RAM(u16 size) : size(size), readonly(false) {
memory = new u8[size];
std::memset(memory, 0, sizeof(u8) * size);
}
RAM::RAM(u8* memory, u16 size, bool readonly)
: memory(memory), size(size), readonly(readonly)
{}
void RAM::write8(u16 addr, u8 data) {
if(addr >= size || readonly) return;
memory[addr] = data;
}
u8 RAM::read8(u16 addr) {
if (addr >= size) return 0xFFu;
return memory[addr];
}