-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.cpp
68 lines (52 loc) · 1.3 KB
/
memory.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
#include "memory.hpp"
#include "arithmetics.hpp"
using namespace ARITHMETICS;
using namespace TYPES;
namespace MEMORY {
//class Latch
void Latch::set(BIT d) {
status = d;
}
BIT Latch::get() {
return status;
}
Latch::Latch() {
status = 0;
}
Latch::Latch(BIT d) {
status = d;
}
//class Register
void Register::set(WORD d) {
status = d;
}
WORD Register::get() {
return status;
}
Register::Register() {
status = 0b0000000000000000;
}
Register::Register(WORD d) {
status = d;
}
//class Counter
void Counter::tick() {
status = inc16(status);
}
//class ROM
WORD ROM::get(WORD addr) {
return registers[addr].get();
}
ROM::ROM() {}
ROM::ROM(std::vector<Register> regs) {
for (WORD i = 0; i < regs.size(); ++i) {
registers[i].set(regs[i].get());
}
}
//class RAM
void RAM::set(WORD addr, WORD d) {
registers[addr].set(d);
}
RAM::RAM() : ROM() {}
RAM::RAM(std::vector<Register> regs) : ROM(regs) {}
}