1 | //============================================================================ |
2 | // |
3 | // SSSS tt lll lll |
4 | // SS SS tt ll ll |
5 | // SS tttttt eeee ll ll aaaa |
6 | // SSSS tt ee ee ll ll aa |
7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
8 | // SS SS tt ee ll ll aa aa |
9 | // SSSS ttt eeeee llll llll aaaaa |
10 | // |
11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
12 | // and the Stella Team |
13 | // |
14 | // See the file "License.txt" for information on usage and redistribution of |
15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
16 | //============================================================================ |
17 | |
18 | #ifndef CHEAT_HXX |
19 | #define CHEAT_HXX |
20 | |
21 | class OSystem; |
22 | |
23 | #include "bspf.hxx" |
24 | |
25 | class Cheat |
26 | { |
27 | public: |
28 | Cheat(OSystem& osystem, const string& name, const string& code) |
29 | : myOSystem(osystem), |
30 | myName(name == "" ? code : name), |
31 | myCode(code), |
32 | myEnabled(false) |
33 | { } |
34 | virtual ~Cheat() = default; |
35 | |
36 | bool enabled() const { return myEnabled; } |
37 | const string& name() const { return myName; } |
38 | const string& code() const { return myCode; } |
39 | |
40 | virtual bool enable() = 0; |
41 | virtual bool disable() = 0; |
42 | |
43 | virtual void evaluate() = 0; |
44 | |
45 | protected: |
46 | static uInt16 unhex(const string& hex) |
47 | { |
48 | int ret = 0; |
49 | for(char c: hex) |
50 | { |
51 | ret *= 16; |
52 | if(c >= '0' && c <= '9') |
53 | ret += c - '0'; |
54 | else if(c >= 'A' && c <= 'F') |
55 | ret += c - 'A' + 10; |
56 | else |
57 | ret += c - 'a' + 10; |
58 | } |
59 | return ret; |
60 | } |
61 | |
62 | protected: |
63 | OSystem& myOSystem; |
64 | |
65 | string myName; |
66 | string myCode; |
67 | |
68 | bool myEnabled; |
69 | |
70 | private: |
71 | // Following constructors and assignment operators not supported |
72 | Cheat() = delete; |
73 | Cheat(const Cheat&) = delete; |
74 | Cheat(Cheat&&) = delete; |
75 | Cheat& operator=(const Cheat&) = delete; |
76 | Cheat& operator=(Cheat&&) = delete; |
77 | }; |
78 | |
79 | #endif |
80 | |