-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.c
More file actions
36 lines (30 loc) · 963 Bytes
/
memory.c
File metadata and controls
36 lines (30 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdint.h>
#include <string.h>
#include "memory.h"
#include "tinybit.h"
struct TinyBitMemory* tinybit_memory;
// Initialize TinyBit memory by clearing all sections (preserving lua_state)
void memory_init() {
memset(tinybit_memory, 0, TB_MEM_SIZE);
}
// Copy memory from source to destination within TinyBit memory space
void mem_copy(int dst, int src, int size) {
if (dst + size > TB_MEM_SIZE || src + size > TB_MEM_SIZE) {
return;
}
memcpy(&tinybit_memory[dst], &tinybit_memory[src], size);
}
// Read a byte from TinyBit memory at specified address
uint8_t mem_peek(int dst) {
if (dst < 0 || dst > TB_MEM_SIZE) {
return 0;
}
return *(uint8_t*)&tinybit_memory[dst];
}
// Write a byte to TinyBit memory at specified address
void mem_poke(int dst, int val){
if (dst < 0 || dst > TB_MEM_SIZE) {
return;
}
*(uint8_t*)&tinybit_memory[dst] = val & 0xff;
}