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;
|
|
|
|
|
|
|
|
bool Cheat::enabled() const {
|
|
|
|
return system_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cheat::enable(bool state) {
|
|
|
|
system_enabled = state;
|
|
|
|
cheat_enabled = system_enabled && code_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cheat::synchronize() {
|
2011-06-26 12:51:37 +00:00
|
|
|
memset(override, 0x00, 16 * 1024 * 1024);
|
2011-09-15 12:41:49 +00:00
|
|
|
code_enabled = size() > 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
for(unsigned i = 0; i < size(); i++) {
|
|
|
|
const CheatCode &code = operator[](i);
|
2011-09-15 12:41:49 +00:00
|
|
|
|
|
|
|
unsigned addr = mirror(code.addr);
|
|
|
|
override[addr] = true;
|
|
|
|
if((addr & 0xffe000) == 0x7e0000) {
|
|
|
|
//mirror $7e:0000-1fff to $00-3f|80-bf:0000-1fff
|
|
|
|
unsigned mirroraddr;
|
|
|
|
for(unsigned x = 0; x <= 0x3f; x++) {
|
|
|
|
mirroraddr = ((0x00 + x) << 16) + (addr & 0x1fff);
|
|
|
|
override[mirroraddr] = true;
|
|
|
|
|
|
|
|
mirroraddr = ((0x80 + x) << 16) + (addr & 0x1fff);
|
|
|
|
override[mirroraddr] = true;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cheat_enabled = system_enabled && code_enabled;
|
|
|
|
}
|
|
|
|
|
2011-01-18 10:17:48 +00:00
|
|
|
uint8 Cheat::read(unsigned addr) const {
|
2010-08-09 13:28:56 +00:00
|
|
|
addr = mirror(addr);
|
|
|
|
|
|
|
|
for(unsigned i = 0; i < size(); i++) {
|
|
|
|
const CheatCode &code = operator[](i);
|
2011-09-15 12:41:49 +00:00
|
|
|
if(addr == mirror(code.addr)) {
|
|
|
|
return code.data;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-18 10:17:48 +00:00
|
|
|
return 0x00;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cheat::init() {
|
2011-06-26 12:51:37 +00:00
|
|
|
memset(override, 0x00, 16 * 1024 * 1024);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Cheat::Cheat() {
|
2011-06-26 12:51:37 +00:00
|
|
|
override = new uint8[16 * 1024 * 1024];
|
2010-08-09 13:28:56 +00:00
|
|
|
system_enabled = true;
|
|
|
|
}
|
|
|
|
|
2011-01-18 10:17:48 +00:00
|
|
|
Cheat::~Cheat() {
|
2011-06-26 12:51:37 +00:00
|
|
|
delete[] override;
|
2011-01-18 10:17:48 +00:00
|
|
|
}
|
|
|
|
|
2011-09-16 11:44:07 +00:00
|
|
|
bool Cheat::decode(const string &code, unsigned &addr, unsigned &data) {
|
|
|
|
string t = code;
|
2010-08-09 13:28:56 +00:00
|
|
|
t.lower();
|
|
|
|
|
|
|
|
#define ischr(n) ((n >= '0' && n <= '9') || (n >= 'a' && n <= 'f'))
|
|
|
|
|
Update to v082r15 release.
byuu says:
7.5 hours of power coding. Das Keyboard definitely helped (but didn't
eliminate) RSI, neato.
Okay, the NES resampler was using 315 / 88.8 by mistake, so the output
rate was wrong, causing way more video/audio stuttering than necessary.
STILL forgot the NES APU frame IRQ clear thing on $4015 reads, blah. Why
do I always remember things right after uploading the WIPs?
Recreated the input manager with a new design, works much nicer than the
old one, a whole lot less duplicated code.
Recreated the input settings window to work with the new multi-system
emulation.
All input settings are saved to their own configuration file, input.cfg.
Going to batch folder for now.
Okay, so the new input settings window ... basically there are now three
drop-downs, and I'm not even trying to label them anymore.
They are primary, secondary, tertiary selectors for the listed group
below. Examples:
"NES -> Controller Port 1 -> Gamepad"
"SNES -> Controller Port 2 -> Super Scope"
"User Interface -> Hotkeys -> Save States"
I am aware that "Clear" gets disabled when assigning. I will work on
that later, being lazy for now and disabling the entire window. Have to
add the mouse binders back, too.
Escape and modifiers are both mappable as individual keys now. If you
want to clear, click the damn clear button :P
Oh, and all input goes to all windows for now. That'll be fixed too when
input focus stuff is re-added.
2011-09-17 06:42:17 +00:00
|
|
|
if(t.wildcard("??????:??")) {
|
2011-09-27 11:55:02 +00:00
|
|
|
//Direct
|
Update to v082r15 release.
byuu says:
7.5 hours of power coding. Das Keyboard definitely helped (but didn't
eliminate) RSI, neato.
Okay, the NES resampler was using 315 / 88.8 by mistake, so the output
rate was wrong, causing way more video/audio stuttering than necessary.
STILL forgot the NES APU frame IRQ clear thing on $4015 reads, blah. Why
do I always remember things right after uploading the WIPs?
Recreated the input manager with a new design, works much nicer than the
old one, a whole lot less duplicated code.
Recreated the input settings window to work with the new multi-system
emulation.
All input settings are saved to their own configuration file, input.cfg.
Going to batch folder for now.
Okay, so the new input settings window ... basically there are now three
drop-downs, and I'm not even trying to label them anymore.
They are primary, secondary, tertiary selectors for the listed group
below. Examples:
"NES -> Controller Port 1 -> Gamepad"
"SNES -> Controller Port 2 -> Super Scope"
"User Interface -> Hotkeys -> Save States"
I am aware that "Clear" gets disabled when assigning. I will work on
that later, being lazy for now and disabling the entire window. Have to
add the mouse binders back, too.
Escape and modifiers are both mappable as individual keys now. If you
want to clear, click the damn clear button :P
Oh, and all input goes to all windows for now. That'll be fixed too when
input focus stuff is re-added.
2011-09-17 06:42:17 +00:00
|
|
|
t = { substr(t, 0, 6), substr(t, 7, 2) };
|
|
|
|
for(unsigned n = 0; n < 8; n++) if(!ischr(t[n])) return false; //validate input
|
2011-09-16 11:44:07 +00:00
|
|
|
unsigned r = hex(t);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
addr = r >> 8;
|
|
|
|
data = r & 0xff;
|
|
|
|
return true;
|
Update to v082r15 release.
byuu says:
7.5 hours of power coding. Das Keyboard definitely helped (but didn't
eliminate) RSI, neato.
Okay, the NES resampler was using 315 / 88.8 by mistake, so the output
rate was wrong, causing way more video/audio stuttering than necessary.
STILL forgot the NES APU frame IRQ clear thing on $4015 reads, blah. Why
do I always remember things right after uploading the WIPs?
Recreated the input manager with a new design, works much nicer than the
old one, a whole lot less duplicated code.
Recreated the input settings window to work with the new multi-system
emulation.
All input settings are saved to their own configuration file, input.cfg.
Going to batch folder for now.
Okay, so the new input settings window ... basically there are now three
drop-downs, and I'm not even trying to label them anymore.
They are primary, secondary, tertiary selectors for the listed group
below. Examples:
"NES -> Controller Port 1 -> Gamepad"
"SNES -> Controller Port 2 -> Super Scope"
"User Interface -> Hotkeys -> Save States"
I am aware that "Clear" gets disabled when assigning. I will work on
that later, being lazy for now and disabling the entire window. Have to
add the mouse binders back, too.
Escape and modifiers are both mappable as individual keys now. If you
want to clear, click the damn clear button :P
Oh, and all input goes to all windows for now. That'll be fixed too when
input focus stuff is re-added.
2011-09-17 06:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(t.wildcard("????" "-" "????")) {
|
2011-09-16 11:44:07 +00:00
|
|
|
//Game Genie
|
Update to v082r15 release.
byuu says:
7.5 hours of power coding. Das Keyboard definitely helped (but didn't
eliminate) RSI, neato.
Okay, the NES resampler was using 315 / 88.8 by mistake, so the output
rate was wrong, causing way more video/audio stuttering than necessary.
STILL forgot the NES APU frame IRQ clear thing on $4015 reads, blah. Why
do I always remember things right after uploading the WIPs?
Recreated the input manager with a new design, works much nicer than the
old one, a whole lot less duplicated code.
Recreated the input settings window to work with the new multi-system
emulation.
All input settings are saved to their own configuration file, input.cfg.
Going to batch folder for now.
Okay, so the new input settings window ... basically there are now three
drop-downs, and I'm not even trying to label them anymore.
They are primary, secondary, tertiary selectors for the listed group
below. Examples:
"NES -> Controller Port 1 -> Gamepad"
"SNES -> Controller Port 2 -> Super Scope"
"User Interface -> Hotkeys -> Save States"
I am aware that "Clear" gets disabled when assigning. I will work on
that later, being lazy for now and disabling the entire window. Have to
add the mouse binders back, too.
Escape and modifiers are both mappable as individual keys now. If you
want to clear, click the damn clear button :P
Oh, and all input goes to all windows for now. That'll be fixed too when
input focus stuff is re-added.
2011-09-17 06:42:17 +00:00
|
|
|
t = { substr(t, 0, 4), substr(t, 5, 4) };
|
|
|
|
for(unsigned n = 0; n < 8; n++) if(!ischr(t[n])) return false; //validate input
|
2010-08-09 13:28:56 +00:00
|
|
|
t.transform("df4709156bc8a23e", "0123456789abcdef");
|
2011-09-16 11:44:07 +00:00
|
|
|
unsigned r = hex(t);
|
|
|
|
static unsigned bits[] = { 13, 12, 11, 10, 5, 4, 3, 2, 23, 22, 21, 20, 1, 0, 15, 14, 19, 18, 17, 16, 9, 8, 7, 6 };
|
|
|
|
|
|
|
|
addr = 0;
|
|
|
|
for(unsigned n = 0; n < 24; n++) addr |= r & (1 << bits[n]) ? 0x800000 >> n : 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
data = r >> 24;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef ischr
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned Cheat::mirror(unsigned addr) const {
|
|
|
|
//$00-3f|80-bf:0000-1fff -> $7e:0000-1fff
|
|
|
|
if((addr & 0x40e000) == 0x000000) return (0x7e0000 + (addr & 0x1fff));
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|