mirror of
https://github.com/andwati/mos-6502.git
synced 2026-10-18 03:02:51 +00:00
implement memory module with read, write, and reset functions
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user