implement memory module with read, write, and reset functions

This commit is contained in:
2025-12-21 17:33:22 +03:00
parent 59acb3b233
commit 7dd9d16f44
2 changed files with 34 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
#include "memory.h"
#include <string.h>
uint8_t mem_read(Memory *mem, uint16_t addr)
{
return mem->data[addr];
}
void mem_write(Memory *mem, uint16_t addr, uint8_t value)
{
mem->data[addr] = value;
}
void mem_reset(Memory *mem)
{
memset(mem->data, 0, MEM_SIZE);
}
+17
View File
@@ -0,0 +1,17 @@
#ifndef MEMORY_H
#define MEMORY_H
#include <stdint.h>
#define MEM_SIZE 65536 // 64KB memory size
typedef struct
{
uint8_t data[MEM_SIZE];
} Memory;
uint8_t mem_read(Memory *mem, uint16_t addr);
void mem_write(Memory *mem, uint16_t addr, uint8_t value);
void mem_reset(Memory *mem);
#endif