chip8_core/cpu/
memory.rs

1const MEMORY_SIZE: usize = 4096;
2
3pub struct Memory {
4    data: [u8; MEMORY_SIZE],
5}
6
7impl Memory {
8    pub fn new() -> Self {
9        Self {
10            data: [0; MEMORY_SIZE],
11        }
12    }
13
14    pub fn read(&self, offset: usize, size: usize) -> &[u8] {
15        &self.data[offset..offset + size]
16    }
17
18    pub fn load(&mut self, offset: usize, bytes: &[u8]) {
19        let range = offset..offset + bytes.len();
20        self.data[range].copy_from_slice(bytes);
21    }
22}