2023-08-26 19:04:02 +02:00
|
|
|
#include "ram.h"
|
|
|
|
|
|
|
|
RAM::RAM(u16 size) : size(size), readonly(false) {
|
|
|
|
memory = new u8[size];
|
|
|
|
}
|
|
|
|
|
2023-08-26 21:17:47 +02:00
|
|
|
RAM::RAM(u8* memory, u16 size, bool readonly)
|
2023-08-26 19:04:02 +02:00
|
|
|
: 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];
|
|
|
|
}
|
|
|
|
|
|
|
|
void RAM::write16(u16 addr, u16 data) {
|
|
|
|
if(addr >= size - 1 || readonly) return;
|
|
|
|
u16 *ptr = (u16*)&memory[addr];
|
|
|
|
*ptr = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 RAM::read16(u16 addr) {
|
2023-08-26 21:17:47 +02:00
|
|
|
if(addr >= size - 1) return 0xFFFFu;
|
2023-08-26 19:04:02 +02:00
|
|
|
u16 *ptr = (u16*)&memory[addr];
|
|
|
|
return *ptr;
|
|
|
|
}
|