2012-04-29 06:16:44 +00:00
|
|
|
#include <sfc/sfc.hpp>
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
#define CHEAT_CPP
|
2012-04-26 10:51:13 +00:00
|
|
|
namespace SuperFamicom {
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
Cheat cheat;
|
|
|
|
|
2014-01-13 09:35:46 +00:00
|
|
|
void Cheat::reset() {
|
|
|
|
codes.reset();
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-13 09:35:46 +00:00
|
|
|
void Cheat::append(unsigned addr, unsigned data) {
|
|
|
|
codes.append({addr, Unused, data});
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-13 09:35:46 +00:00
|
|
|
void Cheat::append(unsigned addr, unsigned comp, unsigned data) {
|
|
|
|
codes.append({addr, comp, data});
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-13 09:35:46 +00:00
|
|
|
optional<unsigned> Cheat::find(unsigned addr, unsigned comp) {
|
|
|
|
//WRAM mirroring: $00-3f,80-bf:0000-1fff -> $7e:0000-1fff
|
|
|
|
if((addr & 0x40e000) == 0x000000) addr = 0x7e0000 | (addr & 0x1fff);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2014-01-13 09:35:46 +00:00
|
|
|
for(auto& code : codes) {
|
|
|
|
if(code.addr == addr && (code.comp == Unused || code.comp == comp)) {
|
|
|
|
return {true, code.data};
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-13 09:35:46 +00:00
|
|
|
return false;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|