-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathram.cpp
84 lines (70 loc) · 1.98 KB
/
ram.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <vector>
#include "header/spec.hpp"
#define Byte unsigned char
std::vector<Byte> ram;
// RAMおよびVRAMを管理する関数
/*void ram_boot(std::vector<Byte>& ram, std::vector<Byte>& vram) {
ram.resize(S3HS_RAM_SIZE, Byte(0));
}
Byte vram_peek(std::vector<Byte>& vram, int addr) {
if (addr < 0) {
return Byte(0);
}
if (addr < S3HS_VRAM_SIZE) {
return vram.at(addr);
}
return Byte(0);
}
void vram_poke(std::vector<Byte>& vram, int addr, Byte val) {
if (addr < 0) {
return;
}
if (addr < S3HS_VRAM_SIZE) {
vram.at(addr) = val;
}
}
std::vector<Byte> vram_peek2array(std::vector<Byte>& vram, int addr, int block) {
std::vector<Byte> out;
for (int i = addr; i < addr + block; i++)
{
out.push_back(vram_peek(vram, i));
}
return out;
}
void vram_pokefill(std::vector<Byte>& vram, int addr, int block, Byte val) {
std::fill(vram.begin() + addr, vram.begin() + addr + block, val);
}
void vram_poke2array(std::vector<Byte>& vram, int addr, std::vector<Byte>& vals) {
std::copy(vals.begin(), vals.end(), vram.begin() + addr);
} */
Byte ram_peek(std::vector<Byte>& ram, int addr) {
if (addr < 0) {
return Byte(0);
}
if (addr < S3HS_RAM_SIZE) {
return ram.at(addr);
}
return Byte(0);
}
void ram_poke(std::vector<Byte>& ram, int addr, Byte val) {
if (addr < 0) {
return;
}
if (addr < S3HS_RAM_SIZE) {
ram.at(addr) = val;
}
}
std::vector<Byte> ram_peek2array(std::vector<Byte>& ram, int addr, int block) {
std::vector<Byte> out;
for (int i = addr; i < addr + block; i++)
{
out.push_back(ram_peek(ram, i));
}
return out;
}
void ram_pokefill(std::vector<Byte>& ram, int addr, int block, Byte val) {
std::fill(ram.begin() + addr, ram.begin() + addr + block, val);
}
void ram_poke2array(std::vector<Byte>& ram, int addr, std::vector<Byte>& vals) {
std::copy(vals.begin(), vals.end(), ram.begin() + addr);
}