Trying to find a more efficient way to know which byte has a cheat. It might be memory cost but it's 2020.
This commit is contained in:
parent
c830d2cc7d
commit
c3d0d40aa6
|
@ -39,7 +39,6 @@ using namespace std;
|
||||||
static uint8 *CheatRPtrs[64];
|
static uint8 *CheatRPtrs[64];
|
||||||
|
|
||||||
vector<uint16> FrozenAddresses; //List of addresses that are currently frozen
|
vector<uint16> FrozenAddresses; //List of addresses that are currently frozen
|
||||||
void UpdateFrozenList(void); //Function that populates the list of frozen addresses
|
|
||||||
unsigned int FrozenAddressCount = 0; //Keeps up with the Frozen address count, necessary for using in other dialogs (such as hex editor)
|
unsigned int FrozenAddressCount = 0; //Keeps up with the Frozen address count, necessary for using in other dialogs (such as hex editor)
|
||||||
|
|
||||||
void FCEU_CheatResetRAM(void)
|
void FCEU_CheatResetRAM(void)
|
||||||
|
@ -64,6 +63,7 @@ CHEATF_SUBFAST SubCheats[256] = { 0 };
|
||||||
uint32 numsubcheats = 0;
|
uint32 numsubcheats = 0;
|
||||||
int globalCheatDisabled = 0;
|
int globalCheatDisabled = 0;
|
||||||
int disableAutoLSCheats = 0;
|
int disableAutoLSCheats = 0;
|
||||||
|
static unsigned char cheatMap[0x10000 / 8] = { 0 };
|
||||||
struct CHEATF *cheats = 0, *cheatsl = 0;
|
struct CHEATF *cheats = 0, *cheatsl = 0;
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,11 +102,16 @@ void RebuildSubCheats(void)
|
||||||
{
|
{
|
||||||
uint32 x;
|
uint32 x;
|
||||||
struct CHEATF *c = cheats;
|
struct CHEATF *c = cheats;
|
||||||
for(x = 0; x < numsubcheats; x++)
|
for (x = 0; x < numsubcheats; x++)
|
||||||
|
{
|
||||||
SetReadHandler(SubCheats[x].addr, SubCheats[x].addr, SubCheats[x].PrevRead);
|
SetReadHandler(SubCheats[x].addr, SubCheats[x].addr, SubCheats[x].PrevRead);
|
||||||
|
SetByteCheat(SubCheats[x].addr, false);
|
||||||
|
}
|
||||||
|
|
||||||
numsubcheats = 0;
|
numsubcheats = 0;
|
||||||
|
|
||||||
if (!globalCheatDisabled)
|
if (!globalCheatDisabled)
|
||||||
|
{
|
||||||
while(c)
|
while(c)
|
||||||
{
|
{
|
||||||
if(c->type == 1 && c->status && GetReadHandler(c->addr) != SubCheatsRead)
|
if(c->type == 1 && c->status && GetReadHandler(c->addr) != SubCheatsRead)
|
||||||
|
@ -116,26 +121,28 @@ void RebuildSubCheats(void)
|
||||||
SubCheats[numsubcheats].val = c->val;
|
SubCheats[numsubcheats].val = c->val;
|
||||||
SubCheats[numsubcheats].compare = c->compare;
|
SubCheats[numsubcheats].compare = c->compare;
|
||||||
SetReadHandler(c->addr, c->addr, SubCheatsRead);
|
SetReadHandler(c->addr, c->addr, SubCheatsRead);
|
||||||
|
SetByteCheat(SubCheats[numsubcheats].addr, true);
|
||||||
numsubcheats++;
|
numsubcheats++;
|
||||||
}
|
}
|
||||||
c = c->next;
|
c = c->next;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
FrozenAddressCount = numsubcheats; //Update the frozen address list
|
FrozenAddressCount = numsubcheats; //Update the frozen address list
|
||||||
UpdateFrozenList();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FCEU_PowerCheats()
|
void FCEU_PowerCheats()
|
||||||
{
|
{
|
||||||
numsubcheats = 0; /* Quick hack to prevent setting of ancient read addresses. */
|
numsubcheats = 0; /* Quick hack to prevent setting of ancient read addresses. */
|
||||||
|
memset(cheatMap, 0, sizeof(cheatMap));
|
||||||
RebuildSubCheats();
|
RebuildSubCheats();
|
||||||
}
|
}
|
||||||
|
|
||||||
int FCEU_CalcCheatAffectedBytes(uint32 address, uint32 size) {
|
int FCEU_CalcCheatAffectedBytes(uint32 address, uint32 size) {
|
||||||
|
|
||||||
uint32 count = 0;
|
uint32 count = 0;
|
||||||
for (uint32 i = 0; i < numsubcheats && count < size; ++i)
|
for (uint32 i = 0; i < size; ++i)
|
||||||
if (SubCheats[i].addr >= address && SubCheats[i].addr < address + size)
|
if (IsByteCheat(address + i))
|
||||||
++count;
|
++count;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -195,9 +202,11 @@ void FCEU_LoadGameCheats(FILE *override, int override_existing)
|
||||||
int tc = 0;
|
int tc = 0;
|
||||||
char *fn;
|
char *fn;
|
||||||
|
|
||||||
savecheats = 0;
|
|
||||||
if (override_existing)
|
if (override_existing)
|
||||||
|
{
|
||||||
numsubcheats = 0;
|
numsubcheats = 0;
|
||||||
|
memset(cheatMap, 0, sizeof(cheatMap));
|
||||||
|
}
|
||||||
|
|
||||||
if(override)
|
if(override)
|
||||||
fp = override;
|
fp = override;
|
||||||
|
@ -870,22 +879,6 @@ void FCEU_CheatSetByte(uint32 A, uint8 V)
|
||||||
BWrite[A](A, V);
|
BWrite[A](A, V);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateFrozenList(void)
|
|
||||||
{
|
|
||||||
//The purpose of this function is to keep an up to date list of addresses that are currently frozen
|
|
||||||
//and make these accessible to other dialogs that deal with memory addresses such as
|
|
||||||
//memwatch, hex editor, ramfilter, etc.
|
|
||||||
|
|
||||||
uint32 x;
|
|
||||||
FrozenAddresses.clear(); //Clear vector and repopulate
|
|
||||||
for(x = 0; x < numsubcheats; x++)
|
|
||||||
{
|
|
||||||
FrozenAddresses.push_back(SubCheats[x].addr);
|
|
||||||
//FCEU_printf("Address %d: %d \n",x,FrozenAddresses[x]); //Debug
|
|
||||||
}
|
|
||||||
//FCEUI_DispMessage("FrozenCount: %d",0,FrozenAddressCount);//Debug
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable all cheats
|
// disable all cheats
|
||||||
int FCEU_DisableAllCheats(){
|
int FCEU_DisableAllCheats(){
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -902,3 +895,14 @@ int FCEU_DisableAllCheats(){
|
||||||
RebuildSubCheats();
|
RebuildSubCheats();
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int IsByteCheat(uint8 address)
|
||||||
|
{
|
||||||
|
return cheatMap[address / 8] >> (address % 8) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetByteCheat(uint8 address, bool cheat)
|
||||||
|
{
|
||||||
|
cheat ? cheatMap[address / 8] |= (1 << address % 8) : cheatMap[address / 8] ^= (1 << address % 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
12
src/cheat.h
12
src/cheat.h
|
@ -11,7 +11,6 @@ void FCEU_ApplyPeriodicCheats(void);
|
||||||
void FCEU_PowerCheats(void);
|
void FCEU_PowerCheats(void);
|
||||||
int FCEU_CalcCheatAffectedBytes(uint32 address, uint32 size);
|
int FCEU_CalcCheatAffectedBytes(uint32 address, uint32 size);
|
||||||
|
|
||||||
|
|
||||||
int FCEU_CheatGetByte(uint32 A);
|
int FCEU_CheatGetByte(uint32 A);
|
||||||
void FCEU_CheatSetByte(uint32 A, uint8 V);
|
void FCEU_CheatSetByte(uint32 A, uint8 V);
|
||||||
|
|
||||||
|
@ -45,6 +44,11 @@ struct SEARCHPOSSIBLE {
|
||||||
bool update;
|
bool update;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Trying to find a more efficient way for determining if an address has a cheat
|
||||||
|
// 1 byte represents to 8 bytes in NES,
|
||||||
|
int IsByteCheat(uint8 address);
|
||||||
|
void SetByteCheat(uint8 address, bool cheat);
|
||||||
|
|
||||||
#define FCEU_SEARCH_SPECIFIC_CHANGE 0
|
#define FCEU_SEARCH_SPECIFIC_CHANGE 0
|
||||||
#define FCEU_SEARCH_RELATIVE_CHANGE 1
|
#define FCEU_SEARCH_RELATIVE_CHANGE 1
|
||||||
#define FCEU_SEARCH_PUERLY_RELATIVE_CHANGE 2
|
#define FCEU_SEARCH_PUERLY_RELATIVE_CHANGE 2
|
||||||
|
@ -55,10 +59,4 @@ struct SEARCHPOSSIBLE {
|
||||||
#define FCEU_SEARCH_NEWVAL_GT_KNOWN 7
|
#define FCEU_SEARCH_NEWVAL_GT_KNOWN 7
|
||||||
#define FCEU_SEARCH_NEWVAL_LT_KNOWN 8
|
#define FCEU_SEARCH_NEWVAL_LT_KNOWN 8
|
||||||
|
|
||||||
|
|
||||||
#define CalcAddressRangeCheatCount(count, address, size) \
|
|
||||||
count = 0; \
|
|
||||||
for (int i = 0; i < numsubcheats && count < size; ++i) \
|
|
||||||
if (SubCheats[i].addr >= address && SubCheats[i].addr < address + size) \
|
|
||||||
++count
|
|
||||||
#endif
|
#endif
|
|
@ -1415,24 +1415,22 @@ void UpdateCheatRelatedWindow()
|
||||||
// ram search
|
// ram search
|
||||||
extern HWND RamSearchHWnd;
|
extern HWND RamSearchHWnd;
|
||||||
if (RamSearchHWnd)
|
if (RamSearchHWnd)
|
||||||
{
|
|
||||||
// if ram search is open then update the ram list.
|
// if ram search is open then update the ram list.
|
||||||
SendDlgItemMessage(RamSearchHWnd, IDC_RAMLIST, LVM_REDRAWITEMS,
|
SendDlgItemMessage(RamSearchHWnd, IDC_RAMLIST, LVM_REDRAWITEMS,
|
||||||
SendDlgItemMessage(RamSearchHWnd, IDC_RAMLIST, LVM_GETTOPINDEX, 0, 0),
|
SendDlgItemMessage(RamSearchHWnd, IDC_RAMLIST, LVM_GETTOPINDEX, 0, 0),
|
||||||
|
SendDlgItemMessage(RamSearchHWnd, IDC_RAMLIST, LVM_GETTOPINDEX, 0, 0) +
|
||||||
SendDlgItemMessage(RamSearchHWnd, IDC_RAMLIST, LVM_GETCOUNTPERPAGE, 0, 0) + 1);
|
SendDlgItemMessage(RamSearchHWnd, IDC_RAMLIST, LVM_GETCOUNTPERPAGE, 0, 0) + 1);
|
||||||
}
|
|
||||||
|
|
||||||
// ram watch
|
// ram watch
|
||||||
extern void UpdateWatchCheats();
|
extern void UpdateWatchCheats();
|
||||||
UpdateWatchCheats();
|
UpdateWatchCheats();
|
||||||
extern HWND RamWatchHWnd;
|
extern HWND RamWatchHWnd;
|
||||||
if (RamWatchHWnd)
|
if (RamWatchHWnd)
|
||||||
{
|
|
||||||
// if ram watch is open then update the ram list.
|
// if ram watch is open then update the ram list.
|
||||||
SendDlgItemMessage(RamWatchHWnd, IDC_WATCHLIST, LVM_REDRAWITEMS,
|
SendDlgItemMessage(RamWatchHWnd, IDC_WATCHLIST, LVM_REDRAWITEMS,
|
||||||
SendDlgItemMessage(RamWatchHWnd, IDC_WATCHLIST, LVM_GETTOPINDEX, 0, 0),
|
SendDlgItemMessage(RamWatchHWnd, IDC_WATCHLIST, LVM_GETTOPINDEX, 0, 0),
|
||||||
|
SendDlgItemMessage(RamSearchHWnd, IDC_RAMLIST, LVM_GETTOPINDEX, 0, 0) +
|
||||||
SendDlgItemMessage(RamWatchHWnd, IDC_WATCHLIST, LVM_GETCOUNTPERPAGE, 0, 0) + 1);
|
SendDlgItemMessage(RamWatchHWnd, IDC_WATCHLIST, LVM_GETCOUNTPERPAGE, 0, 0) + 1);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ static void SetCheatToolTip(HWND hwndDlg, UINT id);
|
||||||
char* GetCheatToolTipStr(HWND hwndDlg, UINT id);
|
char* GetCheatToolTipStr(HWND hwndDlg, UINT id);
|
||||||
|
|
||||||
extern unsigned int FrozenAddressCount;
|
extern unsigned int FrozenAddressCount;
|
||||||
extern std::vector<uint16> FrozenAddresses;
|
|
||||||
//void ConfigAddCheat(HWND wnd); //bbit edited:commented out this line
|
//void ConfigAddCheat(HWND wnd); //bbit edited:commented out this line
|
||||||
extern struct CHEATF* cheats;
|
extern struct CHEATF* cheats;
|
||||||
extern char* GameGenieLetters;
|
extern char* GameGenieLetters;
|
||||||
|
|
|
@ -315,17 +315,13 @@ void UpdateMemWatch()
|
||||||
MWRec& mwrec = mwrecs[i];
|
MWRec& mwrec = mwrecs[i];
|
||||||
|
|
||||||
//Display blue if address is frozen
|
//Display blue if address is frozen
|
||||||
if (FrozenAddressCount && FrozenAddresses.size())
|
if (FrozenAddressCount)
|
||||||
{
|
|
||||||
for (unsigned int x = 0; x < FrozenAddressCount; x++)
|
for (unsigned int x = 0; x < FrozenAddressCount; x++)
|
||||||
{
|
{
|
||||||
if (mwrec.addr == FrozenAddresses[x])
|
extern int IsByteCheat(uint8);
|
||||||
{
|
if (IsByteCheat(mwrec.addr))
|
||||||
//SetTextColor(hdc,RGB(0,0,255));
|
|
||||||
SetTextColor(hdc,GetSysColor(COLOR_HIGHLIGHT));
|
SetTextColor(hdc,GetSysColor(COLOR_HIGHLIGHT));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
char* text;
|
char* text;
|
||||||
if(mwrec.valid && GameInfo)
|
if(mwrec.valid && GameInfo)
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include <commctrl.h>
|
#include <commctrl.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include "BaseTsd.h"
|
#include "BaseTsd.h"
|
||||||
typedef INT_PTR intptr_t;
|
typedef INT_PTR intptr_t;
|
||||||
|
@ -1262,20 +1263,20 @@ LRESULT CustomDraw (LPARAM lParam)
|
||||||
int rv = CDRF_DODEFAULT;
|
int rv = CDRF_DODEFAULT;
|
||||||
int cheat = CALL_WITH_T_SIZE_TYPES_1(GetNumCheatsFromIndex, rs_type_size, rs_t == 's', noMisalign, lplvcd->nmcd.dwItemSpec);
|
int cheat = CALL_WITH_T_SIZE_TYPES_1(GetNumCheatsFromIndex, rs_type_size, rs_t == 's', noMisalign, lplvcd->nmcd.dwItemSpec);
|
||||||
switch (cheat) {
|
switch (cheat) {
|
||||||
default:
|
default:
|
||||||
case 0:
|
case 0:
|
||||||
if (lplvcd->nmcd.dwItemSpec % 2)
|
if (lplvcd->nmcd.dwItemSpec % 2)
|
||||||
lplvcd->clrTextBk = RGB(248, 248, 255);
|
lplvcd->clrTextBk = RGB(248, 248, 255);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
lplvcd->clrTextBk = CHEAT_1BYTE_BG; break;
|
lplvcd->clrTextBk = CHEAT_1BYTE_BG; break;
|
||||||
case 2:
|
case 2:
|
||||||
lplvcd->clrTextBk = CHEAT_2BYTE_BG; break;
|
lplvcd->clrTextBk = CHEAT_2BYTE_BG; break;
|
||||||
case 3:
|
case 3:
|
||||||
lplvcd->clrTextBk = CHEAT_3BYTE_BG; break;
|
lplvcd->clrTextBk = CHEAT_3BYTE_BG; break;
|
||||||
case 4:
|
case 4:
|
||||||
lplvcd->clrTextBk = CHEAT_4BYTE_BG;
|
lplvcd->clrTextBk = CHEAT_4BYTE_BG;
|
||||||
lplvcd->clrText = CHEAT_4BYTE_TEXT; break; // use a more visual color in dark background
|
lplvcd->clrText = CHEAT_4BYTE_TEXT; break; // use a more visual color in dark background
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!IsSatisfied(lplvcd->nmcd.dwItemSpec))
|
if(!IsSatisfied(lplvcd->nmcd.dwItemSpec))
|
||||||
|
|
Loading…
Reference in New Issue