From 4817dda20cbd6ed42ae5f1181e153d1592d7b0f1 Mon Sep 17 00:00:00 2001 From: John Ratliff Date: Sat, 10 Sep 2022 07:29:09 -0900 Subject: [PATCH] format code with clang-format --- source/exceptions/invalidgamegeniecode.cc | 3 - source/exceptions/invalidgamegeniecode.hh | 13 +-- source/ggencoder.cc | 7 +- source/model/comparerawcode.cc | 3 - source/model/comparerawcode.hh | 32 +++--- source/model/gamegeniecode.cc | 11 +- source/model/gamegeniecode.hh | 34 +++--- source/model/gbgggamegeniecode.cc | 48 ++++---- source/model/gbgggamegeniecode.hh | 28 +++-- source/model/gbggrawcode.cc | 5 +- source/model/gbggrawcode.hh | 13 +-- source/model/genesisgamegeniecode.cc | 49 ++++---- source/model/genesisgamegeniecode.hh | 33 +++--- source/model/genesisrawcode.cc | 3 - source/model/genesisrawcode.hh | 11 +- source/model/nesgamegeniecode.cc | 42 ++++--- source/model/nesgamegeniecode.hh | 28 +++-- source/model/nesrawcode.cc | 5 +- source/model/nesrawcode.hh | 13 +-- source/model/rawcode.cc | 3 - source/model/rawcode.hh | 21 ++-- source/model/snesgamegeniecode.cc | 46 ++++---- source/model/snesgamegeniecode.hh | 28 +++-- source/model/snesrawcode.cc | 3 - source/model/snesrawcode.hh | 11 +- source/tools/decoder.cc | 133 +++++++++++----------- source/tools/decoder.hh | 21 ++-- source/tools/encoder.cc | 125 ++++++++++---------- source/tools/encoder.hh | 19 ++-- source/view/geniedialog.cc | 117 ++++++++++--------- source/view/geniedialog.hh | 49 ++++---- source/view/system.hh | 7 +- 32 files changed, 431 insertions(+), 533 deletions(-) diff --git a/source/exceptions/invalidgamegeniecode.cc b/source/exceptions/invalidgamegeniecode.cc index 07db7c8..a270a26 100644 --- a/source/exceptions/invalidgamegeniecode.cc +++ b/source/exceptions/invalidgamegeniecode.cc @@ -19,10 +19,7 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: invalidgamegeniecode.cc,v 1.3 2008/12/18 03:23:30 jdratlif Exp $ #include "exceptions/invalidgamegeniecode.hh" using namespace ggencoder; - diff --git a/source/exceptions/invalidgamegeniecode.hh b/source/exceptions/invalidgamegeniecode.hh index 2c498c7..f162fa4 100644 --- a/source/exceptions/invalidgamegeniecode.hh +++ b/source/exceptions/invalidgamegeniecode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: invalidgamegeniecode.hh,v 1.8 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_INVALIDGAMEGENIECODEEXCEPTION_HH_ #define GGENCODER_INVALIDGAMEGENIECODEEXCEPTION_HH_ @@ -32,16 +30,15 @@ namespace ggencoder { * An exception thrown when a game genie code is invalid. */ class InvalidGameGenieCodeException : public std::runtime_error { - public: + public: /** * Constructor for an InvalidGameGenieCodeException. */ InvalidGameGenieCodeException(); }; - - inline InvalidGameGenieCodeException::InvalidGameGenieCodeException() : - std::runtime_error("InvalidGameGenieCodeException") {} -} -#endif + inline InvalidGameGenieCodeException::InvalidGameGenieCodeException() + : std::runtime_error("InvalidGameGenieCodeException") {} +} // namespace ggencoder +#endif diff --git a/source/ggencoder.cc b/source/ggencoder.cc index 76bbd1b..c7c3ec3 100644 --- a/source/ggencoder.cc +++ b/source/ggencoder.cc @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: ggencoder.cc,v 1.11 2008/12/18 03:31:46 jdratlif Exp $ #include @@ -30,10 +28,9 @@ using namespace ggencoder; int main(int argc, char *argv[]) { QApplication app(argc, argv); - + GenieDialog dlg; dlg.show(); - + return app.exec(); } - diff --git a/source/model/comparerawcode.cc b/source/model/comparerawcode.cc index 962795f..bb364a1 100644 --- a/source/model/comparerawcode.cc +++ b/source/model/comparerawcode.cc @@ -19,10 +19,7 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: comparerawcode.cc,v 1.2 2008/12/18 03:23:30 jdratlif Exp $ #include "model/comparerawcode.hh" using namespace ggencoder; - diff --git a/source/model/comparerawcode.hh b/source/model/comparerawcode.hh index 0bf23a7..91c38bb 100644 --- a/source/model/comparerawcode.hh +++ b/source/model/comparerawcode.hh @@ -10,8 +10,8 @@ * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * Game Genie Encoder/Decoder is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of + * Game Genie Encoder/Decoder is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: comparerawcode.hh,v 1.6 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_COMPARERAWCODE_HH_ #define GGENCODER_COMPARERAWCODE_HH_ @@ -30,24 +28,24 @@ namespace ggencoder { * A raw code interface with a compare value. */ class CompareRawCode { - protected: + protected: int compare; - - public: + + public: /** * Checks if this CompareRawCode uses a compare value. * * @return true if a compare is used; false otherwise. */ bool hasCompare() const; - + /** * Gets the compare value of this CompareRawCode. * * @return The compare value. */ int getCompare() const; - + /** * Sets the compare value of this CompareRawCode. * @@ -55,14 +53,12 @@ namespace ggencoder { */ void setCompare(int compare); }; - - inline bool CompareRawCode::hasCompare() const - { return (compare != -1); } - inline int CompareRawCode::getCompare() const - { return compare; } - inline void CompareRawCode::setCompare(int compare) - { this->compare = (compare & 0xFF); }; -} -#endif + inline bool CompareRawCode::hasCompare() const { return (compare != -1); } + inline int CompareRawCode::getCompare() const { return compare; } + inline void CompareRawCode::setCompare(int compare) { + this->compare = (compare & 0xFF); + }; +} // namespace ggencoder +#endif diff --git a/source/model/gamegeniecode.cc b/source/model/gamegeniecode.cc index 9bc52b3..9adcefd 100644 --- a/source/model/gamegeniecode.cc +++ b/source/model/gamegeniecode.cc @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: gamegeniecode.cc,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #include @@ -30,16 +28,15 @@ using namespace ggencoder; int GameGenieCode::toHex(char letter) const { letter = toupper(letter); - + const char *alphabet = getAlphabet(); - int count = getAlphabetCount(); - + int count = getAlphabetCount(); + for (int i = 0; i < count; i++) { if (alphabet[i] == letter) { return i; } } - + return -1; } - diff --git a/source/model/gamegeniecode.hh b/source/model/gamegeniecode.hh index 7c2425b..7b61420 100644 --- a/source/model/gamegeniecode.hh +++ b/source/model/gamegeniecode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: gamegeniecode.hh,v 1.9 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_GAMEGENIECODE_HH_ #define GGENCODER_GAMEGENIECODE_HH_ @@ -32,43 +30,43 @@ namespace ggencoder { * Interface for a Game Genie code. */ class GameGenieCode { - private: + private: QString code; - - public: + + public: /** * Virtual destructor for a GameGenieCode. */ virtual ~GameGenieCode(); - + /** * Gets the game genie alphabet. * * @return The genie alphabet array. */ virtual const char *getAlphabet() const = 0; - + /** * Gets the number of letters in the game genie alphabet. * * @return The alphabet letter count. */ virtual int getAlphabetCount() const; - + /** * Gets the game genie code. * * @return The game genie code. */ const QString &getCode() const; - + /** * Sets the game genie code. * * @param code The new game genie code. */ void setCode(const QString &code); - + /** * Gets the corresponding hex value for a particular game genie letter. * @@ -78,15 +76,13 @@ namespace ggencoder { */ virtual int toHex(char letter) const; }; - + inline GameGenieCode::~GameGenieCode() {} - inline int GameGenieCode::getAlphabetCount() const - { return 16; } - inline const QString &GameGenieCode::getCode() const - { return code; } - inline void GameGenieCode::setCode(const QString &code) - { this->code = code.toUpper(); } -} + inline int GameGenieCode::getAlphabetCount() const { return 16; } + inline const QString &GameGenieCode::getCode() const { return code; } + inline void GameGenieCode::setCode(const QString &code) { + this->code = code.toUpper(); + } +} // namespace ggencoder #endif - diff --git a/source/model/gbgggamegeniecode.cc b/source/model/gbgggamegeniecode.cc index 52daf94..5e3f4f9 100644 --- a/source/model/gbgggamegeniecode.cc +++ b/source/model/gbgggamegeniecode.cc @@ -19,24 +19,21 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: gbgggamegeniecode.cc,v 1.8 2008/12/18 03:23:30 jdratlif Exp $ #include "model/gbgggamegeniecode.hh" using namespace ggencoder; -const char GBGGGameGenieCode::ALPHABET[] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' -}; +const char GBGGGameGenieCode::ALPHABET[] = {'0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F'}; -GBGGGameGenieCode GBGGGameGenieCode::create(const QString &code) - throw(InvalidGameGenieCodeException) { +GBGGGameGenieCode GBGGGameGenieCode::create(const QString &code) throw( + InvalidGameGenieCodeException) { if (isValidCode(code)) { return GBGGGameGenieCode(code); } - + throw InvalidGameGenieCodeException(); } @@ -46,48 +43,47 @@ const char *GBGGGameGenieCode::getAlphabet() const { bool GBGGGameGenieCode::isValidCode(const QString &code) { GBGGGameGenieCode temp(code); - + const char *alphabet = temp.getAlphabet(); - int count = temp.getAlphabetCount(); - - QString upper = code.toUpper(); - int length = upper.length(); - + int count = temp.getAlphabetCount(); + + QString upper = code.toUpper(); + int length = upper.length(); + if ((length != 7) && (length != 11)) { return false; } - + if (code[3] != '-') { return false; } - + if (length == 11) { if (code[7] != '-') { return false; } } - + for (int i = 0; i < length; i++) { if ((i == 3) || (i == 7)) { continue; } - - bool found = false; - QChar ch = code[i]; - char letter = ch.toLatin1(); - + + bool found = false; + QChar ch = code[i]; + char letter = ch.toLatin1(); + for (int j = 0; j < count; j++) { if (letter == alphabet[j]) { found = true; break; } } - + if (!found) { return false; } } - + return true; } - diff --git a/source/model/gbgggamegeniecode.hh b/source/model/gbgggamegeniecode.hh index 09a5cd1..d22869c 100644 --- a/source/model/gbgggamegeniecode.hh +++ b/source/model/gbgggamegeniecode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: gbgggamegeniecode.hh,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_GBGGGAMEGENIECODE_HH_ #define GGENCODER_GBGGGAMEGENIECODE_HH_ @@ -34,16 +32,16 @@ namespace ggencoder { * An implementation of a Game Boy or Game Gear game genie code. */ class GBGGGameGenieCode : public GameGenieCode { - private: + private: /** * Constructor for an GBGGGameGenieCode. */ GBGGGameGenieCode(const QString &code); - - public: + + public: /// The game genie alphabet. static const char ALPHABET[]; - + /** * Creates a GBGGGameGenieCode object. * @@ -51,16 +49,16 @@ namespace ggencoder { * * @throws InvalidGameGenieCodeException if the code is invalid. */ - static GBGGGameGenieCode create(const QString &code) - throw(InvalidGameGenieCodeException); - + static GBGGGameGenieCode + create(const QString &code) throw(InvalidGameGenieCodeException); + /** * Gets the game genie alphabet. * * @return The genie alphabet array. */ const char *getAlphabet() const; - + /** * Checks if the code is a valid game genie code. * @@ -70,10 +68,10 @@ namespace ggencoder { */ static bool isValidCode(const QString &code); }; - - inline GBGGGameGenieCode::GBGGGameGenieCode(const QString &code) - { setCode(code); } -} -#endif + inline GBGGGameGenieCode::GBGGGameGenieCode(const QString &code) { + setCode(code); + } +} // namespace ggencoder +#endif diff --git a/source/model/gbggrawcode.cc b/source/model/gbggrawcode.cc index daa78f9..21f4055 100644 --- a/source/model/gbggrawcode.cc +++ b/source/model/gbggrawcode.cc @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: gbggrawcode.cc,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #include "model/gbggrawcode.hh" @@ -35,7 +33,7 @@ GBGGRawCode::GBGGRawCode(int address, int value, int compare) { GBGGRawCode::GBGGRawCode(int address, int value) { setAddress(address); setValue(value); - + compare = -1; } @@ -46,4 +44,3 @@ void GBGGRawCode::setAddress(int address) { void GBGGRawCode::setValue(int value) { this->value = (value & 0xFF); } - diff --git a/source/model/gbggrawcode.hh b/source/model/gbggrawcode.hh index dc080b9..5ef92b5 100644 --- a/source/model/gbggrawcode.hh +++ b/source/model/gbggrawcode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: gbggrawcode.hh,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_GBGGRAWCODE_HH_ #define GGENCODER_GBGGRAWCODE_HH_ @@ -33,7 +31,7 @@ namespace ggencoder { * Implementation of an GBGG raw hex code. */ class GBGGRawCode : public RawCode, public CompareRawCode { - public: + public: /** * Constructor for a GBGGRawCode with a compare value. * @@ -42,7 +40,7 @@ namespace ggencoder { * @param compare The code's compare value. */ GBGGRawCode(int address, int value, int compare); - + /** * Constructor for a GBGGRawCode with no compare value. * @@ -50,14 +48,14 @@ namespace ggencoder { * @param value The code's value. */ GBGGRawCode(int address, int value); - + /** * Sets the address of this RawCode. * * @param address The new address. */ void setAddress(int address); - + /** * Sets the value of this RawCode. * @@ -65,7 +63,6 @@ namespace ggencoder { */ void setValue(int value); }; -} +} // namespace ggencoder #endif - diff --git a/source/model/genesisgamegeniecode.cc b/source/model/genesisgamegeniecode.cc index aa22326..67a8c31 100644 --- a/source/model/genesisgamegeniecode.cc +++ b/source/model/genesisgamegeniecode.cc @@ -19,26 +19,22 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: genesisgamegeniecode.cc,v 1.8 2008/12/18 03:23:30 jdratlif Exp $ #include "model/genesisgamegeniecode.hh" using namespace ggencoder; const char GenesisGameGenieCode::ALPHABET[] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', - 'T', 'V', 'W', 'X', 'Y', 'Z', '0', '1', - '2', '3', '4', '5', '6', '7', '8', '9' -}; - -GenesisGameGenieCode GenesisGameGenieCode::create(const QString &code) - throw(InvalidGameGenieCodeException) { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', + 'M', 'N', 'P', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; + +GenesisGameGenieCode GenesisGameGenieCode::create(const QString &code) throw( + InvalidGameGenieCodeException) { if (isValidCode(code)) { return GenesisGameGenieCode(code); } - + throw InvalidGameGenieCodeException(); } @@ -48,42 +44,41 @@ const char *GenesisGameGenieCode::getAlphabet() const { bool GenesisGameGenieCode::isValidCode(const QString &code) { GenesisGameGenieCode temp(code); - + const char *alphabet = temp.getAlphabet(); - int count = temp.getAlphabetCount(); - - QString upper = code.toUpper(); - int length = upper.length(); - + int count = temp.getAlphabetCount(); + + QString upper = code.toUpper(); + int length = upper.length(); + if (length != 9) { return false; } - + if (code[4] != '-') { return false; } - + for (int i = 0; i < length; i++) { if (i == 4) { continue; } - - bool found = false; - QChar ch = code[i]; - char letter = ch.toLatin1(); - + + bool found = false; + QChar ch = code[i]; + char letter = ch.toLatin1(); + for (int j = 0; j < count; j++) { if (letter == alphabet[j]) { found = true; break; } } - + if (!found) { return false; } } - + return true; } - diff --git a/source/model/genesisgamegeniecode.hh b/source/model/genesisgamegeniecode.hh index e050e49..268ddc0 100644 --- a/source/model/genesisgamegeniecode.hh +++ b/source/model/genesisgamegeniecode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: genesisgamegeniecode.hh,v 1.8 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_GENESISGAMEGENIECODE_HH_ #define GGENCODER_GENESISGAMEGENIECODE_HH_ @@ -34,16 +32,16 @@ namespace ggencoder { * An implementation of a Genesis game genie code. */ class GenesisGameGenieCode : public GameGenieCode { - private: + private: /** * Constructor for an GenesisGameGenieCode. */ GenesisGameGenieCode(const QString &code); - - public: + + public: /// The game genie alphabet. static const char ALPHABET[]; - + /** * Creates a GenesisGameGenieCode object. * @@ -51,23 +49,23 @@ namespace ggencoder { * * @throws InvalidGameGenieCodeException if the code is invalid. */ - static GenesisGameGenieCode create(const QString &code) - throw (InvalidGameGenieCodeException); - + static GenesisGameGenieCode + create(const QString &code) throw(InvalidGameGenieCodeException); + /** * Gets the game genie alphabet. * * @return The genie alphabet array. */ const char *getAlphabet() const; - + /** * Gets the number of letters in the game genie alphabet. * * @return The alphabet letter count. */ int getAlphabetCount() const; - + /** * Checks if the code is a valid game genie code. * @@ -77,12 +75,11 @@ namespace ggencoder { */ static bool isValidCode(const QString &code); }; - - inline GenesisGameGenieCode::GenesisGameGenieCode(const QString &code) - { setCode(code); } - inline int GenesisGameGenieCode::getAlphabetCount() const - { return 32; } -} -#endif + inline GenesisGameGenieCode::GenesisGameGenieCode(const QString &code) { + setCode(code); + } + inline int GenesisGameGenieCode::getAlphabetCount() const { return 32; } +} // namespace ggencoder +#endif diff --git a/source/model/genesisrawcode.cc b/source/model/genesisrawcode.cc index 80e3b17..c2ede45 100644 --- a/source/model/genesisrawcode.cc +++ b/source/model/genesisrawcode.cc @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: genesisrawcode.cc,v 1.8 2008/12/18 03:23:30 jdratlif Exp $ #include "model/genesisrawcode.hh" @@ -38,4 +36,3 @@ void GenesisRawCode::setAddress(int address) { void GenesisRawCode::setValue(int value) { this->value = (value & 0xFFFF); } - diff --git a/source/model/genesisrawcode.hh b/source/model/genesisrawcode.hh index cb9dbeb..77e5839 100644 --- a/source/model/genesisrawcode.hh +++ b/source/model/genesisrawcode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: genesisrawcode.hh,v 1.6 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_GENESISRAWCODE_HH_ #define GGENCODER_GENESISRAWCODE_HH_ @@ -32,7 +30,7 @@ namespace ggencoder { * Implementation of a Genesis raw (or PAR) code. */ class GenesisRawCode : public RawCode { - public: + public: /** * Constructor for an GenesisRawCode. * @@ -40,14 +38,14 @@ namespace ggencoder { * @param value The code's value. */ GenesisRawCode(int address, int value); - + /** * Sets the address of this RawCode. * * @param address The new address. */ void setAddress(int address); - + /** * Sets the value of this RawCode. * @@ -55,7 +53,6 @@ namespace ggencoder { */ void setValue(int value); }; -} +} // namespace ggencoder #endif - diff --git a/source/model/nesgamegeniecode.cc b/source/model/nesgamegeniecode.cc index b3ac8b8..14ddaa7 100644 --- a/source/model/nesgamegeniecode.cc +++ b/source/model/nesgamegeniecode.cc @@ -19,24 +19,21 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: nesgamegeniecode.cc,v 1.8 2008/12/18 03:23:30 jdratlif Exp $ #include "model/nesgamegeniecode.hh" using namespace ggencoder; -const char NESGameGenieCode::ALPHABET[] = { - 'A', 'P', 'Z', 'L', 'G', 'I', 'T', 'Y', - 'E', 'O', 'X', 'U', 'K', 'S', 'V', 'N' -}; +const char NESGameGenieCode::ALPHABET[] = {'A', 'P', 'Z', 'L', 'G', 'I', + 'T', 'Y', 'E', 'O', 'X', 'U', + 'K', 'S', 'V', 'N'}; -NESGameGenieCode NESGameGenieCode::create(const QString &code) - throw(InvalidGameGenieCodeException) { +NESGameGenieCode NESGameGenieCode::create(const QString &code) throw( + InvalidGameGenieCodeException) { if (isValidCode(code)) { return NESGameGenieCode(code); } - + throw InvalidGameGenieCodeException(); } @@ -46,34 +43,33 @@ const char *NESGameGenieCode::getAlphabet() const { bool NESGameGenieCode::isValidCode(const QString &code) { NESGameGenieCode temp(code); - + const char *alphabet = temp.getAlphabet(); - int count = temp.getAlphabetCount(); - - QString upper = code.toUpper(); - int length = upper.length(); - + int count = temp.getAlphabetCount(); + + QString upper = code.toUpper(); + int length = upper.length(); + if ((length != 6) && (length != 8)) { return false; } - + for (int i = 0; i < length; i++) { - bool found = false; - QChar ch = code[i]; - char letter = ch.toLatin1(); - + bool found = false; + QChar ch = code[i]; + char letter = ch.toLatin1(); + for (int j = 0; j < count; j++) { if (letter == alphabet[j]) { found = true; break; } } - + if (!found) { return false; } } - + return true; } - diff --git a/source/model/nesgamegeniecode.hh b/source/model/nesgamegeniecode.hh index b1bacd5..087cafb 100644 --- a/source/model/nesgamegeniecode.hh +++ b/source/model/nesgamegeniecode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: nesgamegeniecode.hh,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_NESGAMEGENIECODE_HH_ #define GGENCODER_NESGAMEGENIECODE_HH_ @@ -34,16 +32,16 @@ namespace ggencoder { * An implementation of an NES game genie code. */ class NESGameGenieCode : public GameGenieCode { - private: + private: /** * Constructor for an NESGameGenieCode. */ NESGameGenieCode(const QString &code); - - public: + + public: /// The game genie alphabet. static const char ALPHABET[]; - + /** * Creates an NESGameGenieCode object. * @@ -51,16 +49,16 @@ namespace ggencoder { * * @throws InvalidGameGenieCodeException if the code is invalid. */ - static NESGameGenieCode create(const QString &code) - throw (InvalidGameGenieCodeException); - + static NESGameGenieCode + create(const QString &code) throw(InvalidGameGenieCodeException); + /** * Gets the game genie alphabet. * * @return The genie alphabet array. */ const char *getAlphabet() const; - + /** * Checks if the code is a valid game genie code. * @@ -70,10 +68,10 @@ namespace ggencoder { */ static bool isValidCode(const QString &code); }; - - inline NESGameGenieCode::NESGameGenieCode(const QString &code) - { setCode(code); } -} -#endif + inline NESGameGenieCode::NESGameGenieCode(const QString &code) { + setCode(code); + } +} // namespace ggencoder +#endif diff --git a/source/model/nesrawcode.cc b/source/model/nesrawcode.cc index a8ebb4d..e504bf0 100644 --- a/source/model/nesrawcode.cc +++ b/source/model/nesrawcode.cc @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: nesrawcode.cc,v 1.9 2008/12/18 03:23:30 jdratlif Exp $ #include "model/nesrawcode.hh" @@ -35,7 +33,7 @@ NESRawCode::NESRawCode(int address, int value, int compare) { NESRawCode::NESRawCode(int address, int value) { setAddress(address); setValue(value); - + compare = -1; } @@ -46,4 +44,3 @@ void NESRawCode::setAddress(int address) { void NESRawCode::setValue(int value) { this->value = (value & 0xFF); } - diff --git a/source/model/nesrawcode.hh b/source/model/nesrawcode.hh index 23c9e81..413f238 100644 --- a/source/model/nesrawcode.hh +++ b/source/model/nesrawcode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: nesrawcode.hh,v 1.8 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_NESRAWCODE_HH_ #define GGENCODER_NESRAWCODE_HH_ @@ -33,7 +31,7 @@ namespace ggencoder { * Implementation of an NES raw hex code. */ class NESRawCode : public RawCode, public CompareRawCode { - public: + public: /** * Constructor for an NESRawCode with a compare value. * @@ -42,7 +40,7 @@ namespace ggencoder { * @param compare The code's compare value. */ NESRawCode(int address, int value, int compare); - + /** * Constructor for an NESRawCode with no compare value. * @@ -50,14 +48,14 @@ namespace ggencoder { * @param value The code's value. */ NESRawCode(int address, int value); - + /** * Sets the address of this RawCode. * * @param address The new address. */ void setAddress(int address); - + /** * Sets the value of this RawCode. * @@ -65,7 +63,6 @@ namespace ggencoder { */ void setValue(int value); }; -} +} // namespace ggencoder #endif - diff --git a/source/model/rawcode.cc b/source/model/rawcode.cc index 1c6c3ff..64fde44 100644 --- a/source/model/rawcode.cc +++ b/source/model/rawcode.cc @@ -19,10 +19,7 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: rawcode.cc,v 1.2 2008/12/18 03:23:30 jdratlif Exp $ #include "model/rawcode.hh" using namespace ggencoder; - diff --git a/source/model/rawcode.hh b/source/model/rawcode.hh index 8cdc073..b4d004c 100644 --- a/source/model/rawcode.hh +++ b/source/model/rawcode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: rawcode.hh,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_RAWCODE_HH_ #define GGENCODER_RAWCODE_HH_ @@ -30,37 +28,37 @@ namespace ggencoder { * Interface for a raw hex/PAR code. */ class RawCode { - protected: + protected: int address; int value; - - public: + + public: /** * Virtual destructor for RawCode derivatives. */ virtual ~RawCode(); - + /** * Gets the address of this RawCode. * * @return The address. */ virtual int getAddress() const; - + /** * Sets the address of this RawCode. * * @param address The new address. */ virtual void setAddress(int address) = 0; - + /** * Gets the value of this RawCode. * * @return The value. */ virtual int getValue() const; - + /** * Sets the value of this RawCode. * @@ -68,11 +66,10 @@ namespace ggencoder { */ virtual void setValue(int value) = 0; }; - + inline RawCode::~RawCode() {} inline int RawCode::getAddress() const { return address; } inline int RawCode::getValue() const { return value; } -} +} // namespace ggencoder #endif - diff --git a/source/model/snesgamegeniecode.cc b/source/model/snesgamegeniecode.cc index 698a202..19f6f7f 100644 --- a/source/model/snesgamegeniecode.cc +++ b/source/model/snesgamegeniecode.cc @@ -19,24 +19,21 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: snesgamegeniecode.cc,v 1.8 2008/12/18 03:23:30 jdratlif Exp $ #include "model/snesgamegeniecode.hh" using namespace ggencoder; -const char SNESGameGenieCode::ALPHABET[] = { - 'D', 'F', '4', '7', '0', '9', '1', '5', - '6', 'B', 'C', '8', 'A', '2', '3', 'E' -}; +const char SNESGameGenieCode::ALPHABET[] = {'D', 'F', '4', '7', '0', '9', + '1', '5', '6', 'B', 'C', '8', + 'A', '2', '3', 'E'}; -SNESGameGenieCode SNESGameGenieCode::create(const QString &code) - throw(InvalidGameGenieCodeException) { +SNESGameGenieCode SNESGameGenieCode::create(const QString &code) throw( + InvalidGameGenieCodeException) { if (isValidCode(code)) { return SNESGameGenieCode(code); } - + throw InvalidGameGenieCodeException(); } @@ -46,42 +43,41 @@ const char *SNESGameGenieCode::getAlphabet() const { bool SNESGameGenieCode::isValidCode(const QString &code) { SNESGameGenieCode temp(code); - + const char *alphabet = temp.getAlphabet(); - int count = temp.getAlphabetCount(); - - QString upper = code.toUpper(); - int length = upper.length(); - + int count = temp.getAlphabetCount(); + + QString upper = code.toUpper(); + int length = upper.length(); + if (length != 9) { return false; } - + if (code[4] != '-') { return false; } - + for (int i = 0; i < length; i++) { if (i == 4) { continue; } - - bool found = false; - QChar ch = code[i]; - char letter = ch.toLatin1(); - + + bool found = false; + QChar ch = code[i]; + char letter = ch.toLatin1(); + for (int j = 0; j < count; j++) { if (letter == alphabet[j]) { found = true; break; } } - + if (!found) { return false; } } - + return true; } - diff --git a/source/model/snesgamegeniecode.hh b/source/model/snesgamegeniecode.hh index 54ec9fe..72e3467 100644 --- a/source/model/snesgamegeniecode.hh +++ b/source/model/snesgamegeniecode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: snesgamegeniecode.hh,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_SNESGAMEGENIECODE_HH_ #define GGENCODER_SNESGAMEGENIECODE_HH_ @@ -34,16 +32,16 @@ namespace ggencoder { * An implementation of an SNES game genie code. */ class SNESGameGenieCode : public GameGenieCode { - private: + private: /** * Constructor for an SNESGameGenieCode. */ SNESGameGenieCode(const QString &code); - - public: + + public: /// The game genie alphabet. static const char ALPHABET[]; - + /** * Creates an SNESGameGenieCode object. * @@ -51,16 +49,16 @@ namespace ggencoder { * * @throws InvalidGameGenieCodeException if the code is invalid. */ - static SNESGameGenieCode create(const QString &code) - throw(InvalidGameGenieCodeException); - + static SNESGameGenieCode + create(const QString &code) throw(InvalidGameGenieCodeException); + /** * Gets the game genie alphabet. * * @return The genie alphabet array. */ const char *getAlphabet() const; - + /** * Checks if the code is a valid game genie code. * @@ -70,10 +68,10 @@ namespace ggencoder { */ static bool isValidCode(const QString &code); }; - - inline SNESGameGenieCode::SNESGameGenieCode(const QString &code) - { setCode(code); } -} -#endif + inline SNESGameGenieCode::SNESGameGenieCode(const QString &code) { + setCode(code); + } +} // namespace ggencoder +#endif diff --git a/source/model/snesrawcode.cc b/source/model/snesrawcode.cc index 8e38279..104f6a2 100644 --- a/source/model/snesrawcode.cc +++ b/source/model/snesrawcode.cc @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: snesrawcode.cc,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #include "model/snesrawcode.hh" @@ -38,4 +36,3 @@ void SNESRawCode::setAddress(int address) { void SNESRawCode::setValue(int value) { this->value = (value & 0xFF); } - diff --git a/source/model/snesrawcode.hh b/source/model/snesrawcode.hh index 698558d..9d39cd0 100644 --- a/source/model/snesrawcode.hh +++ b/source/model/snesrawcode.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: snesrawcode.hh,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_SNESRAWCODE_HH_ #define GGENCODER_SNESRAWCODE_HH_ @@ -32,7 +30,7 @@ namespace ggencoder { * Implementation of an SNES raw (or PAR) code. */ class SNESRawCode : public RawCode { - public: + public: /** * Constructor for an SNESRawCode. * @@ -40,14 +38,14 @@ namespace ggencoder { * @param value The code's value. */ SNESRawCode(int address, int value); - + /** * Sets the address of this RawCode. * * @param address The new address. */ void setAddress(int address); - + /** * Sets the value of this RawCode. * @@ -55,7 +53,6 @@ namespace ggencoder { */ void setValue(int value); }; -} +} // namespace ggencoder #endif - diff --git a/source/tools/decoder.cc b/source/tools/decoder.cc index 6ee4ef0..4e859e8 100644 --- a/source/tools/decoder.cc +++ b/source/tools/decoder.cc @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: decoder.cc,v 1.9 2008/12/18 03:23:30 jdratlif Exp $ #include @@ -41,154 +39,154 @@ using namespace ggencoder; GBGGRawCode Decoder::decodeGBGG(const GameGenieCode &code) { QString ggcode = code.getCode(); - int length = ggcode.length(); - + int length = ggcode.length(); + if (!GBGGGameGenieCode::isValidCode(ggcode)) { throw InvalidGameGenieCodeException(); } - + qint64 bitstring = 0; - + for (int i = 0; i < length; i++) { if ((i == 3) || (i == 7)) { continue; } - + QChar ch = ggcode[i]; - + bitstring <<= 4; bitstring |= code.toHex(ch.toLatin1()); } - + int value; int address; int temp; - + if (length == 7) { bitstring <<= 12; } - + value = (int)(bitstring >> 28); - - temp = (int)((bitstring >> 12) & 0xF); - temp = (~temp & 0xF) << 12; + + temp = (int)((bitstring >> 12) & 0xF); + temp = (~temp & 0xF) << 12; address = (int)((bitstring >> 16) & 0xFFF) | temp; - + if (length == 7) { return GBGGRawCode(address, value); } - + temp = (int)(((bitstring >> 4) & 0xF0) | (bitstring & 0xF)); temp = (temp >> 2) | ((temp << 6) & 0xFC); - + int compare = temp ^ 0xBA; - + return GBGGRawCode(address, value, compare); } GenesisRawCode Decoder::decodeGenesis(const GameGenieCode &code) { QString ggcode = code.getCode(); - int length = ggcode.length(); - + int length = ggcode.length(); + if (!GenesisGameGenieCode::isValidCode(ggcode)) { throw InvalidGameGenieCodeException(); } - + qint64 bitstring = 0; - + for (int i = 0; i < length; i++) { if (i == 4) { continue; } - + QChar ch = ggcode[i]; - + bitstring <<= 5; bitstring |= code.toHex(ch.toLatin1()); } - + int value; int address; int temp; - + // position abcd value = (int)(((bitstring >> 7) & 0xE) | ((bitstring >> 15) & 0x1)); - + // position efgh temp = (int)(((bitstring >> 11) & 0xE) | ((bitstring >> 11) & 0x1)); value <<= 4; value |= temp; - + // position ijklmnop temp = (int)(bitstring >> 32); value <<= 8; value |= temp; - + // a-p = value, a-x = addy // ijkl mnop IJKL MNOP ABCD EFGH defg habc QRST UVWX // position ABCDEFGH address = (int)((bitstring >> 16) & 0xFF); - + // position IJKLMNOP temp = (int)((bitstring >> 24) & 0xFF); address <<= 8; address |= temp; - + // position QRSTUVWX temp = (int)(bitstring & 0xFF); address <<= 8; address |= temp; - + return GenesisRawCode(address, value); } NESRawCode Decoder::decodeNES(const GameGenieCode &code) { QString ggcode = code.getCode(); - int length = ggcode.length(); - + int length = ggcode.length(); + if (!NESGameGenieCode::isValidCode(ggcode)) { throw InvalidGameGenieCodeException(); } - + int bitstring = 0; - + for (int i = 0; i < length; i++) { QChar ch = ggcode[i]; - - bitstring <<= 4; + + bitstring <<= 4; bitstring |= code.toHex(ch.toLatin1()); } - + int value; int address; int temp; - + if (length == 6) { bitstring <<= 8; } - + // position 1234 value = ((bitstring >> 28) & 0x8) | ((bitstring >> 24) & 0x7); - + if (length == 6) { temp = (bitstring & 0x800) >> 8; } else { temp = bitstring & 0x8; } - + temp |= ((bitstring >> 28) & 0x7); - + value <<= 4; value |= temp; - + // position -ABC address = (bitstring & 0x70000) >> 16; - + // position DEFG temp = ((bitstring & 0x8000) >> 12) | ((bitstring & 0x700) >> 8); address <<= 4; address |= temp; - + // position HIJK temp = ((bitstring & 0x8000000) >> 24) | ((bitstring & 0x700000) >> 20); address <<= 4; @@ -198,80 +196,79 @@ NESRawCode Decoder::decodeNES(const GameGenieCode &code) { temp = ((bitstring & 0x80000) >> 16) | ((bitstring & 0x7000) >> 12); address <<= 4; address |= temp; - + if (length == 6) { return NESRawCode(address, value); } - + int compare; - + // position abcd compare = ((bitstring & 0x80) >> 4) | (bitstring & 0x7); - + // position efgh temp = ((bitstring & 0x800) >> 8) | ((bitstring & 0x70) >> 4); compare <<= 4; compare |= temp; - + return NESRawCode(address, value, compare); } SNESRawCode Decoder::decodeSNES(const GameGenieCode &code) { QString ggcode = code.getCode(); - int length = ggcode.length(); - + int length = ggcode.length(); + if (!SNESGameGenieCode::isValidCode(ggcode)) { throw InvalidGameGenieCodeException(); } - + int bitstring = 0; - + for (int i = 0; i < length; i++) { if (i == 4) { continue; } - + QChar ch = ggcode[i]; - + bitstring <<= 4; bitstring |= code.toHex(ch.toLatin1()); } - + int value; int address; int temp; - + // position 12345678 value = (bitstring >> 24) & 0xFF; - + // position ABCD address = ((bitstring >> 10) & 0xC) | ((bitstring >> 10) & 0x3); - + // position EFGH temp = ((bitstring >> 2) & 0xC) | ((bitstring >> 2) & 0x3); address <<= 4; address |= temp; - + // position IJKL temp = (bitstring >> 20) & 0xF; address <<= 4; address |= temp; - + // position MNOP temp = ((bitstring << 2) & 0xC) | ((bitstring >> 14) & 0x3); address <<= 4; address |= temp; - + // position QRST temp = (bitstring >> 16) & 0xF; address <<= 4; address |= temp; - + // position UVWX temp = ((bitstring >> 6) & 0xC) | ((bitstring >> 6) & 0x3); address <<= 4; address |= temp; - + return SNESRawCode(address, value); } - diff --git a/source/tools/decoder.hh b/source/tools/decoder.hh index 49c2f90..cdaabe2 100644 --- a/source/tools/decoder.hh +++ b/source/tools/decoder.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: decoder.hh,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_DECODER_HH_ #define GGENCODER_DECODER_HH_ @@ -31,18 +29,18 @@ namespace ggencoder { class GenesisRawCode; class NESRawCode; class SNESRawCode; - + /** * Class to decode game genie codes into raw/PAR codes. */ class Decoder { - private: + private: /** * Private constructor to prevent instantiation. */ Decoder(); - - public: + + public: /** * Decodes Game Boy or Game Gear game genie code into a GBGGRawCode. * @@ -51,7 +49,7 @@ namespace ggencoder { * @return The decoded GBGGRawCode. */ static GBGGRawCode decodeGBGG(const GameGenieCode &code); - + /** * Decodes Genesis game genie code into a GenesisRawCode. * @@ -60,7 +58,7 @@ namespace ggencoder { * @return The decoded GenesisRawCode. */ static GenesisRawCode decodeGenesis(const GameGenieCode &code); - + /** * Decodes NES game genie code into an NESRawCode. * @@ -69,7 +67,7 @@ namespace ggencoder { * @return The decoded NESRawCode. */ static NESRawCode decodeNES(const GameGenieCode &code); - + /** * Decodes SNES game genie code into an SNESRawCode. * @@ -79,9 +77,8 @@ namespace ggencoder { */ static SNESRawCode decodeSNES(const GameGenieCode &code); }; - + inline Decoder::Decoder() {} -} +} // namespace ggencoder #endif - diff --git a/source/tools/encoder.cc b/source/tools/encoder.cc index e013069..3e4d2b9 100644 --- a/source/tools/encoder.cc +++ b/source/tools/encoder.cc @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: encoder.cc,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #include "model/gbgggamegeniecode.hh" #include "model/gbggrawcode.hh" @@ -36,165 +34,165 @@ using namespace ggencoder; GBGGGameGenieCode Encoder::encode(const GBGGRawCode &code) { - int temp, address = code.getAddress(), value = code.getValue(); + int temp, address = code.getAddress(), value = code.getValue(); qint64 genie; - + // start with the value genie = value; - + temp = (address & 0xF000) >> 12; temp = (~temp & 0xF); temp |= (address & 0xFFF) << 4; genie <<= 16; genie |= temp; - + if (code.hasCompare()) { int compare = code.getCompare(); - + compare ^= 0xBA; compare = (compare << 2) | (compare >> 6); - temp = (compare & 0xF0) >> 4; + temp = (compare & 0xF0) >> 4; genie <<= 4; genie |= temp; - + temp ^= 8; genie <<= 4; genie |= temp; - + temp = (compare & 0xF); genie <<= 4; genie |= temp; } - - QString ggcode; + + QString ggcode; const char *alphabet = GBGGGameGenieCode::ALPHABET; - + for (int i = 0; i < (code.hasCompare() ? 9 : 6); i++) { if ((i == 3) || (i == 6)) { ggcode.insert(0, '-'); } - + ggcode.insert(0, alphabet[(int)((genie >> (i * 4)) & 0xF)]); } - + return GBGGGameGenieCode::create(ggcode); } GenesisGameGenieCode Encoder::encode(const GenesisRawCode &code) { - int temp; + int temp; qint64 genie; - int value = code.getValue(); - int address = code.getAddress(); - + int value = code.getValue(); + int address = code.getAddress(); + // position ijkl genie = (value & 0xF0) >> 4; - + // position mnop temp = (value & 0xF); genie <<= 4; genie |= temp; - + // position IJKL temp = (address & 0xF000) >> 12; genie <<= 4; genie |= temp; - + // position MNOP temp = (address & 0xF00) >> 8; genie <<= 4; genie |= temp; - + // position ABCD temp = (address & 0xF00000) >> 20; genie <<= 4; genie |= temp; - + // position EFGH temp = (address & 0xF0000) >> 16; genie <<= 4; genie |= temp; - + // position defg temp = ((value & 0x1000) >> 9) | ((value & 0xE00) >> 9); genie <<= 4; genie |= temp; - + // position habc temp = ((value & 0x100) >> 5) | ((value & 0xE000) >> 13); genie <<= 4; genie |= temp; - + // position QRST temp = (address & 0xF0) >> 4; genie <<= 4; genie |= temp; - + // position UVWX temp = (address & 0xF); genie <<= 4; genie |= temp; - - QString ggcode; + + QString ggcode; const char *alphabet = GenesisGameGenieCode::ALPHABET; - + for (int i = 0; i < 8; i++) { if (i == 4) { ggcode.insert(0, "-"); } - + ggcode.insert(0, alphabet[(int)((genie >> (i * 5)) & 0x1F)]); } - + return GenesisGameGenieCode::create(ggcode); } NESGameGenieCode Encoder::encode(const NESRawCode &code) { int genie; - int temp = 0; - int value = code.getValue(); + int temp = 0; + int value = code.getValue(); int address = code.getAddress(); - + // position 1678 genie = ((value & 0x80) >> 4) | (value & 0x7); - + // position H234 temp = ((address & 0x80) >> 4) | ((value & 0x70) >> 4); genie <<= 4; genie |= temp; - + // position -IJK temp = (address & 0x70) >> 4; - + if (code.hasCompare()) { temp |= 0x8; } - + genie <<= 4; genie |= temp; - + // position LABC temp = (address & 0x8) | ((address & 0x7000) >> 12); genie <<= 4; genie |= temp; - + // position DMNO temp = ((address & 0x800) >> 8) | (address & 0x7); genie <<= 4; genie |= temp; - + if (code.hasCompare()) { int compare = code.getCompare(); - + // position eEFG temp = (compare & 0x8) | ((address & 0x700) >> 8); genie <<= 4; genie |= temp; - + // position afgh temp = ((compare & 0x80) >> 4) | (compare & 0x7); genie <<= 4; genie |= temp; - + // position 5bcd temp = (value & 0x8) | ((compare & 0x70) >> 4); genie <<= 4; @@ -205,67 +203,66 @@ NESGameGenieCode Encoder::encode(const NESRawCode &code) { genie <<= 4; genie |= temp; } - - QString ggcode; + + QString ggcode; const char *alphabet = NESGameGenieCode::ALPHABET; - + for (int i = 0; i < (code.hasCompare() ? 8 : 6); i++) { ggcode.insert(0, alphabet[(genie >> (i * 4)) & 0xF]); } - + return NESGameGenieCode::create(ggcode); } SNESGameGenieCode Encoder::encode(const SNESRawCode &code) { int genie; int temp; - int value = code.getValue(); + int value = code.getValue(); int address = code.getAddress(); - + // position 1-8 genie = value; - + // position IJKL temp = (address & 0xF000) >> 12; genie <<= 4; genie |= temp; - + // position QRST temp = (address & 0xF0) >> 4; genie <<= 4; genie |= temp; - + // position OPAB temp = ((address & 0x300) >> 6) | (address >> 22); genie <<= 4; genie |= temp; - + // position CDUV temp = ((address & 0x300000) >> 18) | ((address & 0xC) >> 2); genie <<= 4; genie |= temp; - + // position WXEF temp = ((address & 0x3) << 2) | ((address & 0xC0000) >> 18); genie <<= 4; genie |= temp; - + // position GHMN temp = ((address & 0x30000) >> 14) | ((address & 0xC00) >> 10); genie <<= 4; genie |= temp; - - QString ggcode; + + QString ggcode; const char *alphabet = SNESGameGenieCode::ALPHABET; - + for (int i = 0; i < 8; i++) { if (i == 4) { ggcode.insert(0, '-'); } - + ggcode.insert(0, alphabet[(genie >> (i * 4)) & 0xF]); } - + return SNESGameGenieCode::create(ggcode); } - diff --git a/source/tools/encoder.hh b/source/tools/encoder.hh index 2e5c200..b45c3a7 100644 --- a/source/tools/encoder.hh +++ b/source/tools/encoder.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: encoder.hh,v 1.5 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_ENCODER_HH_ #define GGENCODER_ENCODER_HH_ @@ -34,18 +32,18 @@ namespace ggencoder { class NESRawCode; class SNESGameGenieCode; class SNESRawCode; - + /** * A class to encode raw/PAR codes into Game Genie codes. */ class Encoder { - private: + private: /** * Constructor for an Encoder. Private to prevent instantiation. */ Encoder(); - - public: + + public: /** * Encodes a GBGGRawCode into a GameGenieCode. * @@ -54,7 +52,7 @@ namespace ggencoder { * @return The encoded GameGenieCode. */ static GBGGGameGenieCode encode(const GBGGRawCode &code); - + /** * Encodes a GenesisRawCode into a GameGenieCode. * @@ -63,7 +61,7 @@ namespace ggencoder { * @return The encoded GameGenieCode. */ static GenesisGameGenieCode encode(const GenesisRawCode &code); - + /** * Encodes an NESRawCode into a GameGenieCode. * @@ -82,9 +80,8 @@ namespace ggencoder { */ static SNESGameGenieCode encode(const SNESRawCode &code); }; - + inline Encoder::Encoder() {} -} +} // namespace ggencoder #endif - diff --git a/source/view/geniedialog.cc b/source/view/geniedialog.cc index 32a46d0..311f581 100644 --- a/source/view/geniedialog.cc +++ b/source/view/geniedialog.cc @@ -20,8 +20,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -// $Id: geniedialog.cc,v 1.6 2008/12/18 03:23:30 jdratlif Exp $ - #include #include "exceptions/invalidgamegeniecode.hh" @@ -46,31 +44,31 @@ using namespace ggencoder; GenieDialog::GenieDialog() : QDialog(), encoding(false), decoding(false) { setAttribute(Qt::WA_QuitOnClose); ui.setupUi(this); - + // setup text box validation QRegExp regex; - - regex = QRegExp("[A-Fa-f0-9]+"); + + regex = QRegExp("[A-Fa-f0-9]+"); hexValidator = new QRegExpValidator(regex, this); - - regex = QRegExp("[APZLGITYEOXUKSVNapzlgityeoxuksvn]+"); + + regex = QRegExp("[APZLGITYEOXUKSVNapzlgityeoxuksvn]+"); nesValidator = new QRegExpValidator(regex, this); - - regex = QRegExp("[A-Fa-f0-9-]+"); + + regex = QRegExp("[A-Fa-f0-9-]+"); snesValidator = new QRegExpValidator(regex, this); - - regex = QRegExp("[A-HJ-NPR-TV-Z0-9a-hj-np-tv-z-]+"); + + regex = QRegExp("[A-HJ-NPR-TV-Z0-9a-hj-np-tv-z-]+"); genesisValidator = new QRegExpValidator(regex, this); - - regex = QRegExp("[A-Fa-f0-9-]+"); + + regex = QRegExp("[A-Fa-f0-9-]+"); gbggValidator = new QRegExpValidator(regex, this); - + ui.valueEdit->setValidator(hexValidator); ui.addressEdit->setValidator(hexValidator); ui.compareEdit->setValidator(hexValidator); - + ui.compareEdit->setMaxLength(2); - + // initialize the system on_nesRadio_toggled(true); } @@ -87,24 +85,24 @@ void GenieDialog::decode() { if (encoding) { return; } - + decoding = true; - + QString text = ui.gamegenieEdit->text().toUpper(); - + try { QString str; - + if (system == NES) { - NESGameGenieCode ggcode = NESGameGenieCode::create(text); - NESRawCode rawcode = Decoder::decodeNES(ggcode); - + NESGameGenieCode ggcode = NESGameGenieCode::create(text); + NESRawCode rawcode = Decoder::decodeNES(ggcode); + str = QString::asprintf("%02X", rawcode.getValue()); ui.valueEdit->setText(str); - + str = QString::asprintf("%04X", rawcode.getAddress()); ui.addressEdit->setText(str); - + if (rawcode.hasCompare()) { str = QString::asprintf("%02X", rawcode.getCompare()); ui.compareEdit->setText(str); @@ -112,33 +110,33 @@ void GenieDialog::decode() { ui.compareEdit->clear(); } } else if (system == SNES) { - SNESGameGenieCode ggcode = SNESGameGenieCode::create(text); - SNESRawCode rawcode = Decoder::decodeSNES(ggcode); - + SNESGameGenieCode ggcode = SNESGameGenieCode::create(text); + SNESRawCode rawcode = Decoder::decodeSNES(ggcode); + str = QString::asprintf("%02X", rawcode.getValue()); ui.valueEdit->setText(str); - + str = QString::asprintf("%04X", rawcode.getAddress()); ui.addressEdit->setText(str); } else if (system == GENESIS) { - GenesisGameGenieCode ggcode = GenesisGameGenieCode::create(text); - GenesisRawCode rawcode = Decoder::decodeGenesis(ggcode); - + GenesisGameGenieCode ggcode = GenesisGameGenieCode::create(text); + GenesisRawCode rawcode = Decoder::decodeGenesis(ggcode); + str = QString::asprintf("%04X", rawcode.getValue()); ui.valueEdit->setText(str); - + str = QString::asprintf("%04X", rawcode.getAddress()); ui.addressEdit->setText(str); } else if (system == GBGG) { - GBGGGameGenieCode ggcode = GBGGGameGenieCode::create(text); - GBGGRawCode rawcode = Decoder::decodeGBGG(ggcode); - + GBGGGameGenieCode ggcode = GBGGGameGenieCode::create(text); + GBGGRawCode rawcode = Decoder::decodeGBGG(ggcode); + str = QString::asprintf("%02X", rawcode.getValue()); ui.valueEdit->setText(str); - + str = QString::asprintf("%04X", rawcode.getAddress()); ui.addressEdit->setText(str); - + if (rawcode.hasCompare()) { str = QString::asprintf("%02X", rawcode.getCompare()); ui.compareEdit->setText(str); @@ -149,7 +147,7 @@ void GenieDialog::decode() { } catch (InvalidGameGenieCodeException e) { // must not be ready yet... } - + decoding = false; } @@ -157,63 +155,63 @@ void GenieDialog::encode() { if (decoding) { return; } - + encoding = true; - + bool ok; - - int value = ui.valueEdit->text().toInt(&ok, 16); + + int value = ui.valueEdit->text().toInt(&ok, 16); int address = ui.addressEdit->text().toInt(&ok, 16); int compare = ui.compareEdit->text().toInt(&ok, 16); - + if (system == NES) { NESRawCode *rawcode; - + if (!ui.compareEdit->text().isEmpty()) { rawcode = new NESRawCode(address, value, compare); } else { rawcode = new NESRawCode(address, value); } - + NESGameGenieCode ggcode = Encoder::encode(*rawcode); ui.gamegenieEdit->setText(ggcode.getCode()); - + delete rawcode; } else if (system == SNES) { - SNESRawCode rawcode(address, value); + SNESRawCode rawcode(address, value); SNESGameGenieCode ggcode = Encoder::encode(rawcode); ui.gamegenieEdit->setText(ggcode.getCode()); } else if (system == GENESIS) { - GenesisRawCode rawcode(address, value); + GenesisRawCode rawcode(address, value); GenesisGameGenieCode ggcode = Encoder::encode(rawcode); ui.gamegenieEdit->setText(ggcode.getCode()); } else if (system == GBGG) { GBGGRawCode *rawcode; - + if (!ui.compareEdit->text().isEmpty()) { rawcode = new GBGGRawCode(address, value, compare); } else { rawcode = new GBGGRawCode(address, value); } - + GBGGGameGenieCode ggcode = Encoder::encode(*rawcode); ui.gamegenieEdit->setText(ggcode.getCode()); - + delete rawcode; } - + encoding = false; } void GenieDialog::reset() { encoding = true; decoding = true; - + ui.gamegenieEdit->clear(); ui.valueEdit->clear(); ui.addressEdit->clear(); ui.compareEdit->clear(); - + encoding = false; decoding = false; } @@ -235,7 +233,7 @@ void GenieDialog::on_gbggRadio_toggled(bool checked) { reset(); system = GBGG; ui.compareEdit->setEnabled(true); - + ui.valueEdit->setMaxLength(2); ui.addressEdit->setMaxLength(4); ui.gamegenieEdit->setMaxLength(11); @@ -248,7 +246,7 @@ void GenieDialog::on_genesisRadio_toggled(bool checked) { reset(); system = GENESIS; ui.compareEdit->setEnabled(false); - + ui.valueEdit->setMaxLength(4); ui.addressEdit->setMaxLength(6); ui.gamegenieEdit->setMaxLength(9); @@ -261,7 +259,7 @@ void GenieDialog::on_nesRadio_toggled(bool checked) { reset(); system = NES; ui.compareEdit->setEnabled(true); - + ui.valueEdit->setMaxLength(2); ui.addressEdit->setMaxLength(4); ui.gamegenieEdit->setMaxLength(8); @@ -274,7 +272,7 @@ void GenieDialog::on_snesRadio_toggled(bool checked) { reset(); system = SNES; ui.compareEdit->setEnabled(false); - + ui.valueEdit->setMaxLength(2); ui.addressEdit->setMaxLength(6); ui.gamegenieEdit->setMaxLength(9); @@ -285,4 +283,3 @@ void GenieDialog::on_snesRadio_toggled(bool checked) { void GenieDialog::on_valueEdit_textEdited(const QString &) { encode(); } - diff --git a/source/view/geniedialog.hh b/source/view/geniedialog.hh index 29eaefa..bb3972b 100644 --- a/source/view/geniedialog.hh +++ b/source/view/geniedialog.hh @@ -19,8 +19,6 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: geniedialog.hh,v 1.7 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_GENIEDIALOG_HH_ #define GGENCODER_GENIEDIALOG_HH_ @@ -36,87 +34,87 @@ namespace ggencoder { */ class GenieDialog : public QDialog { Q_OBJECT - - private: + + private: QRegExpValidator *hexValidator; QRegExpValidator *nesValidator; QRegExpValidator *snesValidator; QRegExpValidator *genesisValidator; QRegExpValidator *gbggValidator; - Ui::MainDialog ui; - int system; - bool encoding, decoding; - + Ui::MainDialog ui; + int system; + bool encoding, decoding; + /** * Decodes the game genie code into value, address, and compare * components. */ void decode(); - + /** * Encodes the value, address, and compare into a game genie code. */ void encode(); - + /** * Resets the controls. */ void reset(); - - public: + + public: /** * Creates a new GenieDialog. */ GenieDialog(); - + /** * Destructor for a GenieDialog. */ ~GenieDialog(); - - private slots: + + private slots: /** * Called when the address box is edited. - * + * * @param text The new text. */ void on_addressEdit_textEdited(const QString &text); - + /** * Called when the compare box is edited. - * + * * @param text The new text. */ void on_compareEdit_textEdited(const QString &text); - + /** * Called when the game genie box is edited. - * + * * @param text The new text. */ void on_gamegenieEdit_textEdited(const QString &text); - + /** * Called when the Game Boy / Game Gear radio button is toggled. * * @param checked true if it was checked; false otherwise */ void on_gbggRadio_toggled(bool checked); - + /** * Called when the Genesis radio button is toggled. * * @param checked true if it was checked; false otherwise */ void on_genesisRadio_toggled(bool checked); - + /** * Called when the NES radio button is toggled. * * @param checked true if it was checked; false otherwise */ void on_nesRadio_toggled(bool checked); - + /** * Called when the SNES radio button is toggled. * @@ -131,7 +129,6 @@ namespace ggencoder { */ void on_valueEdit_textEdited(const QString &text); }; -} +} // namespace ggencoder #endif - diff --git a/source/view/system.hh b/source/view/system.hh index 1b8d5c1..99f54ad 100644 --- a/source/view/system.hh +++ b/source/view/system.hh @@ -19,18 +19,13 @@ * along with Game Genie Encoder/Decoder; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -// $Id: system.hh,v 1.6 2008/12/18 03:23:30 jdratlif Exp $ #ifndef GGENCODER_SYSTEM_HH_ #define GGENCODER_SYSTEM_HH_ /// The namespace for all application members namespace ggencoder { - enum System { - NES, SNES, GENESIS, GBGG - }; + enum System { NES, SNES, GENESIS, GBGG }; } #endif -