Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: iNES header editor #58

Merged
merged 23 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cart.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef CART_H
#define CART_H

typedef struct {
// Set by mapper/board code:
void (*Power)(void);
Expand Down Expand Up @@ -100,3 +103,5 @@ void FCEU_GeniePower(void);
bool FCEU_OpenGenie(void);
void FCEU_CloseGenie(void);
void FCEU_KillGenie(void);

#endif#endif
71 changes: 41 additions & 30 deletions src/cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p)

CHEATF_SUBFAST SubCheats[256] = { 0 };
uint32 numsubcheats = 0;
int globalCheatDisabled = 0;
int disableAutoLSCheats = 0;
struct CHEATF *cheats = 0, *cheatsl = 0;


Expand Down Expand Up @@ -104,11 +106,10 @@ void RebuildSubCheats(void)
SetReadHandler(SubCheats[x].addr, SubCheats[x].addr, SubCheats[x].PrevRead);

numsubcheats = 0;
while(c)
{
if(c->type == 1 && c->status)
if (!globalCheatDisabled)
while(c)
{
if(GetReadHandler(c->addr) != SubCheatsRead)
if(c->type == 1 && c->status && GetReadHandler(c->addr) != SubCheatsRead)
{
SubCheats[numsubcheats].PrevRead = GetReadHandler(c->addr);
SubCheats[numsubcheats].addr = c->addr;
Expand All @@ -117,9 +118,9 @@ void RebuildSubCheats(void)
SetReadHandler(c->addr, c->addr, SubCheatsRead);
numsubcheats++;
}
c = c->next;
}
c = c->next;
}

FrozenAddressCount = numsubcheats; //Update the frozen address list
UpdateFrozenList();

Expand Down Expand Up @@ -243,7 +244,6 @@ void FCEU_LoadGameCheats(FILE *override, int override_existing)
char *neo = &tbuf[4+2+2+1+1+1];
if(sscanf(tbuf, "%04x%*[:]%02x%*[:]%02x", &addr, &val, &compare) != 3)
continue;
char namebuf[128];
strcpy(namebuf, neo);
}
else
Expand Down Expand Up @@ -277,6 +277,31 @@ void FCEU_LoadGameCheats(FILE *override, int override_existing)
fclose(fp);
}

void FCEU_SaveGameCheats(FILE* fp, int release)
{
struct CHEATF *next = cheats;
while (next)
{
if (next->type)
fputc('S', fp);
if (next->compare >= 0)
fputc('C', fp);

if (!next->status)
fputc(':', fp);

if (next->compare >= 0)
fprintf(fp, "%04x:%02x:%02x:%s\n", next->addr, next->val, next->compare, next->name);
else
fprintf(fp, "%04x:%02x:%s\n", next->addr, next->val, next->name);

if (release) free(next->name);
struct CHEATF *t = next;
next = next->next;
if (release) free(t);
}
}

void FCEU_FlushGameCheats(FILE *override, int nosave)
{
if(CheatComp)
Expand Down Expand Up @@ -309,7 +334,6 @@ void FCEU_FlushGameCheats(FILE *override, int nosave)

if(cheats)
{
struct CHEATF *next=cheats;
FILE *fp;

if(override)
Expand All @@ -319,28 +343,7 @@ void FCEU_FlushGameCheats(FILE *override, int nosave)

if(fp)
{
for(;;)
{
struct CHEATF *t;
if(next->type)
fputc('S',fp);
if(next->compare>=0)
fputc('C',fp);

if(!next->status)
fputc(':',fp);

if(next->compare>=0)
fprintf(fp,"%04x:%02x:%02x:%s\n",next->addr,next->val,next->compare,next->name);
else
fprintf(fp,"%04x:%02x:%s\n",next->addr,next->val,next->name);

free(next->name);
t=next;
next=next->next;
free(t);
if(!next) break;
}
FCEU_SaveGameCheats(fp, 1);
if(!override)
fclose(fp);
}
Expand Down Expand Up @@ -642,6 +645,14 @@ int FCEUI_ToggleCheat(uint32 which)
return(-1);
}

int FCEUI_GlobalToggleCheat(int global_enabled)
{
int _numsubcheats = numsubcheats;
globalCheatDisabled = !global_enabled;
RebuildSubCheats();
return _numsubcheats != numsubcheats;
}

static int InitCheatComp(void)
{
uint32 x;
Expand Down
7 changes: 7 additions & 0 deletions src/cheat.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#ifndef CHEAT_H
#define CHEAT_H
void FCEU_CheatResetRAM(void);
void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p);

void FCEU_LoadGameCheats(FILE *override, int override_existing = 1);
void FCEU_FlushGameCheats(FILE *override, int nosave);
void FCEU_SaveGameCheats(FILE *fp, int release = 0);
int FCEUI_GlobalToggleCheat(int global_enabled);
void FCEU_ApplyPeriodicCheats(void);
void FCEU_PowerCheats(void);
int FCEU_CalcCheatAffectedBytes(uint32 address, uint32 size);
Expand All @@ -12,6 +16,8 @@ int FCEU_CheatGetByte(uint32 A);
void FCEU_CheatSetByte(uint32 A, uint8 V);

extern int savecheats;
extern int globalCheatDisabled;
extern int disableAutoLSCheats;

int FCEU_DisableAllCheats();

Expand Down Expand Up @@ -55,3 +61,4 @@ struct SEARCHPOSSIBLE {
for (int i = 0; i < numsubcheats && count < size; ++i) \
if (SubCheats[i].addr >= address && SubCheats[i].addr < address + size) \
++count
#endif
1 change: 1 addition & 0 deletions src/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ int FCEUI_DecodeGG(const char *str, int *a, int *v, int *c);
int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type);
int FCEUI_DelCheat(uint32 which);
int FCEUI_ToggleCheat(uint32 which);
int FCEUI_GlobalToggleCheat(int global_enable);

int32 FCEUI_CheatSearchGetCount(void);
void FCEUI_CheatSearchGetRange(uint32 first, uint32 last, int (*callb)(uint32 a, uint8 last, uint8 current));
Expand Down
4 changes: 3 additions & 1 deletion src/drivers/common/cheat.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef COMMON_CHEAT_H
#define COMMON_CHEAT_H
void DoConsoleCheatConfig(void);
#endif
2 changes: 1 addition & 1 deletion src/drivers/win/cdlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ BOOL CALLBACK CDLoggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
FreeCDLog();
RenameCDLog("");
hCDLogger = 0;
EndDialog(hwndDlg, 0);
DestroyWindow(hwndDlg);
}
break;
case WM_COMMAND:
Expand Down
Loading