-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbreakpoint_memory.cpp
82 lines (63 loc) · 1.95 KB
/
breakpoint_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <ctype.h>
#include "breakpoint_memory.h"
#include "cpu.h"
#include "utils.h"
breakpoint_memory::breakpoint_memory(bus *const b, const uint32_t addr, const word_mode_t word_mode, const bool is_virtual, const std::set<uint16_t> & values):
breakpoint(b),
addr(addr),
word_mode(word_mode),
is_virtual(is_virtual),
values(values)
{
}
breakpoint_memory::~breakpoint_memory()
{
}
std::optional<std::string> breakpoint_memory::is_triggered() const
{
uint16_t v = 0;
if (is_virtual) {
auto temp = b->peek_word(rm_cur, addr); // FIXME rm_cur
if (temp.has_value() == false)
return { };
v = temp.value();
}
else {
v = b->read_physical(addr);
}
auto it = values.find(v);
if (it == values.end())
return { };
return format("MEM%c%c[%08o]=%06o", word_mode == wm_byte ? 'B' : 'W', is_virtual ? 'V' : 'P', addr, v);
}
std::pair<breakpoint_memory *, std::optional<std::string> > breakpoint_memory::parse(bus *const b, const std::string & in)
{
auto parts = split(in, "=");
if (parts.size() != 2)
return { nullptr, "memory: key or value missing" };
auto values_in = parts.at(1);
auto v_parts = split(std::move(values_in), ",");
std::set<uint16_t> values;
for(auto & v: v_parts)
values.insert(std::stoi(v, nullptr, 8));
auto key = parts.at(0);
if (key.size() < 8 || (key.substr(0, 3) != "MEM" && key.substr(0, 3) != "mem"))
return { nullptr, { } };
word_mode_t wm = toupper(key[3]) == 'B' ? wm_byte : wm_word;
bool is_virtual = toupper(key[4]) == 'V';
std::size_t end_marker = key.find(']');
uint32_t addr = std::stoi(key.substr(6, end_marker - 6), nullptr, 8);
return { new breakpoint_memory(b, addr, wm, is_virtual, values), { } };
}
std::string breakpoint_memory::emit() const
{
std::string out;
for(auto & v: values) {
if (out.empty())
out = format("MEM%c%c[%08o]=", word_mode == wm_byte ? 'B' : 'W', is_virtual ? 'V' : 'P', addr);
else
out += ",";
out += format("%06o", v);
}
return out;
}