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 | #include "Console.hxx" |
19 | #include "Cart.hxx" |
20 | #include "OSystem.hxx" |
21 | #include "CheetahCheat.hxx" |
22 | |
23 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
24 | CheetahCheat::CheetahCheat(OSystem& os, const string& name, const string& code) |
25 | : Cheat(os, name, code), |
26 | address(0xf000 + unhex(code.substr(0, 3))), |
27 | value(uInt8(unhex(code.substr(3, 2)))), |
28 | count(uInt8(unhex(code.substr(5, 1)) + 1)) |
29 | { |
30 | // Back up original data; we need this if the cheat is ever disabled |
31 | for(int i = 0; i < count; ++i) |
32 | savedRom[i] = myOSystem.console().cartridge().peek(address + i); |
33 | } |
34 | |
35 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
36 | bool CheetahCheat::enable() |
37 | { |
38 | evaluate(); |
39 | return myEnabled; |
40 | } |
41 | |
42 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
43 | bool CheetahCheat::disable() |
44 | { |
45 | for(int i = 0; i < count; ++i) |
46 | myOSystem.console().cartridge().patch(address + i, savedRom[i]); |
47 | |
48 | return myEnabled = false; |
49 | } |
50 | |
51 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
52 | void CheetahCheat::evaluate() |
53 | { |
54 | if(!myEnabled) |
55 | { |
56 | for(int i = 0; i < count; ++i) |
57 | myOSystem.console().cartridge().patch(address + i, value); |
58 | |
59 | myEnabled = true; |
60 | } |
61 | } |
62 | |