c533b93f21b646980b393237f7213c28b6ec5f64
[pcsx_rearmed.git] / libpcsxcore / cheat.h
1 /*  Cheat Support for PCSX-Reloaded
2  *  Copyright (C) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA
17  */
18
19 #ifndef CHEAT_H
20 #define CHEAT_H
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 typedef struct {
27         uint32_t        Addr;
28         uint16_t        Val;
29 } CheatCode;
30
31 typedef struct {
32         char            *Descr;
33         int                     First;          // index of the first cheat code
34         int                     n;                      // number of cheat codes for this cheat
35         int                     Enabled;
36 } Cheat;
37
38 void ClearAllCheats();
39
40 void LoadCheats(const char *filename);
41 void SaveCheats(const char *filename);
42
43 void ApplyCheats();
44
45 int AddCheat(const char *descr, char *code);
46 void RemoveCheat(int index);
47 int EditCheat(int index, const char *descr, char *code);
48
49 void FreeCheatSearchResults();
50 void FreeCheatSearchMem();
51 void CheatSearchBackupMemory();
52
53 void CheatSearchEqual8(u8 val);
54 void CheatSearchEqual16(u16 val);
55 void CheatSearchEqual32(u32 val);
56 void CheatSearchNotEqual8(u8 val);
57 void CheatSearchNotEqual16(u16 val);
58 void CheatSearchNotEqual32(u32 val);
59 void CheatSearchRange8(u8 min, u8 max);
60 void CheatSearchRange16(u16 min, u16 max);
61 void CheatSearchRange32(u32 min, u32 max);
62 void CheatSearchIncreasedBy8(u8 val);
63 void CheatSearchIncreasedBy16(u16 val);
64 void CheatSearchIncreasedBy32(u32 val);
65 void CheatSearchDecreasedBy8(u8 val);
66 void CheatSearchDecreasedBy16(u16 val);
67 void CheatSearchDecreasedBy32(u32 val);
68 void CheatSearchIncreased8();
69 void CheatSearchIncreased16();
70 void CheatSearchIncreased32();
71 void CheatSearchDecreased8();
72 void CheatSearchDecreased16();
73 void CheatSearchDecreased32();
74 void CheatSearchDifferent8();
75 void CheatSearchDifferent16();
76 void CheatSearchDifferent32();
77 void CheatSearchNoChange8();
78 void CheatSearchNoChange16();
79 void CheatSearchNoChange32();
80
81 extern Cheat *Cheats;
82 extern CheatCode *CheatCodes;
83 extern int NumCheats;
84 extern int NumCodes;
85
86 extern s8 *prevM;
87 extern u32 *SearchResults;
88 extern int NumSearchResults;
89
90 extern int NumCheatsAllocated;
91 extern int NumCodesAllocated;
92
93 #define PREVM(mem)              (&prevM[mem])
94 #define PrevMu8(mem)    (*(u8 *)PREVM(mem))
95 #define PrevMu16(mem)   (SWAP16(*(u16 *)PREVM(mem)))
96 #define PrevMu32(mem)   (SWAP32(*(u32 *)PREVM(mem)))
97
98 // cheat types
99 #define CHEAT_CONST8            0x30    /* 8-bit Constant Write */
100 #define CHEAT_CONST16           0x80    /* 16-bit Constant Write */
101 #define CHEAT_INC16                     0x10    /* 16-bit Increment */
102 #define CHEAT_DEC16                     0x11    /* 16-bit Decrement */
103 #define CHEAT_INC8                      0x20    /* 8-bit Increment */
104 #define CHEAT_DEC8                      0x21    /* 8-bit Decrement */
105 #define CHEAT_SLIDE                     0x50    /* Slide Codes */
106 #define CHEAT_MEMCPY            0xC2    /* Memory Copy */
107
108 #define CHEAT_EQU8                      0xE0    /* 8-bit Equal To */
109 #define CHEAT_NOTEQU8           0xE1    /* 8-bit Not Equal To */
110 #define CHEAT_LESSTHAN8         0xE2    /* 8-bit Less Than */
111 #define CHEAT_GREATERTHAN8  0xE3        /* 8-bit Greater Than */
112 #define CHEAT_EQU16                     0xD0    /* 16-bit Equal To */
113 #define CHEAT_NOTEQU16          0xD1    /* 16-bit Not Equal To */
114 #define CHEAT_LESSTHAN16        0xD2    /* 16-bit Less Than */
115 #define CHEAT_GREATERTHAN16 0xD3        /* 16-bit Greater Than */
116
117 #ifdef __cplusplus
118 }
119 #endif
120 #endif