2016-07-10 05:28:26 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Emulator {
|
|
|
|
|
|
|
|
struct Cheat {
|
|
|
|
struct Code {
|
|
|
|
uint addr;
|
|
|
|
uint data;
|
|
|
|
maybe<uint> comp;
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit operator bool() const {
|
|
|
|
return codes.size() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto reset() -> void {
|
|
|
|
codes.reset();
|
|
|
|
}
|
|
|
|
|
2018-07-25 12:24:03 +00:00
|
|
|
auto append(uint addr, uint data, maybe<uint> comp = {}) -> void {
|
2016-07-10 05:28:26 +00:00
|
|
|
codes.append({addr, data, comp});
|
|
|
|
}
|
|
|
|
|
2018-07-25 12:24:03 +00:00
|
|
|
auto assign(const vector<string>& list) -> void {
|
2016-07-10 05:28:26 +00:00
|
|
|
reset();
|
|
|
|
for(auto& entry : list) {
|
|
|
|
for(auto code : entry.split("+")) {
|
2017-06-22 06:04:07 +00:00
|
|
|
auto part = code.transform("=?", "//").split("/");
|
2016-07-10 05:28:26 +00:00
|
|
|
if(part.size() == 2) append(part[0].hex(), part[1].hex());
|
|
|
|
if(part.size() == 3) append(part[0].hex(), part[2].hex(), part[1].hex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto find(uint addr, uint comp) -> maybe<uint> {
|
|
|
|
for(auto& code : codes) {
|
|
|
|
if(code.addr == addr && (!code.comp || code.comp() == comp)) {
|
|
|
|
return code.data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nothing;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vector<Code> codes;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|