Files
MyLittleCPU/src/memory.c

25 lines
547 B
C
Raw Normal View History

2026-07-15 15:02:54 +10:00
#include "memory.h"
Memory* initMemory(uint32_t size) {
Memory* newMemory = malloc(sizeof(Memory));
if (!newMemory)
return NULL;
newMemory->size = size;
newMemory->data = calloc(size, sizeof(uint8_t));
if (!newMemory->data) {
free(newMemory);
return NULL;
}
return newMemory;
}
inline uint16_t memoryLoadWord(Memory* m, uint32_t address) {
return m->data[address];
}
inline void memorySaveWord(Memory* m, uint32_t address, uint16_t value) {
((uint16_t*)m->data)[address] = value;
}