diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 4aaea0d2..59f240e7 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "libretro.h" @@ -580,7 +582,7 @@ void retro_cheat_reset(void) void retro_cheat_set(unsigned index, bool enabled, const char *code) { - const char *begin, *c; + /*const char *begin, *c; begin = c = code; @@ -617,7 +619,68 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code) log_cb(RETRO_LOG_ERROR, "[VBA] Invalid cheat code '%s'\n", buf); } - } while (*c++); + } while (*c++);*/ + + #define ISHEXDEC \ + ((codeLine[cursor] >= '0') && (codeLine[cursor] <= '9')) || \ + ((codeLine[cursor] >= 'a') && (codeLine[cursor] <= 'f')) || \ + ((codeLine[cursor] >= 'A') && (codeLine[cursor] <= 'F')) \ + + std::string codeLine = code; + std::string name = "cheat_" + index; + int matchLength = 0; + std::vector codeParts; + int cursor; + + //Break the code into Parts + for (cursor=0;;cursor++) + { + if (ISHEXDEC) + matchLength++; + else + { + if (matchLength) + { + if (matchLength > 8) + { + codeParts.push_back(codeLine.substr(cursor - matchLength, 8)); + codeParts.push_back(codeLine.substr(cursor - matchLength + 8, matchLength - 8)); + } + else + codeParts.push_back(codeLine.substr(cursor - matchLength, matchLength)); + + matchLength = 0; + } + } + if (!codeLine[cursor]) + break; + } + + //Add to core + for (cursor = 0; cursor