Skip to content

Commit

Permalink
support gamegenie codes in cheat.dat format. alternately load cheatne…
Browse files Browse the repository at this point in the history
…s.dat for nes, cheatsnes.dat for snes
  • Loading branch information
dinkc64 committed Nov 23, 2024
1 parent ef63337 commit 402a96f
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 15 deletions.
51 changes: 43 additions & 8 deletions src/burner/conc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "burner.h"

#define HW_NES ( ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SNES) || ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_NES) || ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_FDS) )
// GameGenie stuff is handled a little differently..
#define HW_NES ( ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_NES) || ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_FDS) )
#define HW_SNES ( ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SNES) )
#define HW_GGENIE ( HW_NES || HW_SNES )

static bool SkipComma(TCHAR** s)
{
Expand Down Expand Up @@ -228,7 +231,7 @@ static INT32 ConfigParseFile(TCHAR* pszFilename)
INT32 nCPU = 0, nAddress = 0, nValue = 0;

if (SkipComma(&s)) {
if (HW_NES) {
if (HW_GGENIE) {
t = s;
INT32 newlen = 0;
#if defined(BUILD_WIN32)
Expand Down Expand Up @@ -475,6 +478,13 @@ static INT32 ConfigParseMAMEFile_internal(FILE *fz, const TCHAR *name)
nCurrentAddress++; \
} \

#define AddressInfoGameGenie() { \
pCurrentCheat->pOption[n]->AddressInfo[nCurrentAddress].nTotalByte = 1; \
pCurrentCheat->pOption[n]->AddressInfo[nCurrentAddress].nAddress = 0xffff; \
strcpy(pCurrentCheat->pOption[n]->AddressInfo[nCurrentAddress].szGenieCode, szGGenie); \
nCurrentAddress++; \
}

#define OptionName(a) \
if (pCurrentCheat->pOption[n] == NULL) { \
pCurrentCheat->pOption[n] = (CheatOption*)malloc(sizeof(CheatOption)); \
Expand All @@ -490,6 +500,7 @@ static INT32 ConfigParseMAMEFile_internal(FILE *fz, const TCHAR *name)
TCHAR tmp2[256];
TCHAR gName[64];
TCHAR szLine[1024];
char szGGenie[128] = { 0, };

INT32 nLen;
INT32 n = 0;
Expand Down Expand Up @@ -557,8 +568,10 @@ static INT32 ConfigParseMAMEFile_internal(FILE *fz, const TCHAR *name)
tmpcpy(2); // cheat address
#if defined(BUILD_WIN32)
_stscanf (tmp, _T("%x"), &nAddress);
strcpy(szGGenie, TCHARToANSI(tmp, NULL, 0));
#else
sscanf (tmp, _T("%x"), &nAddress);
strcpy(szGGenie, tmp);
#endif

tmpcpy(3); // cheat value
Expand Down Expand Up @@ -587,7 +600,11 @@ static INT32 ConfigParseMAMEFile_internal(FILE *fz, const TCHAR *name)

if ( flags & 0x00008000 || (flags & 0x00010000 && !menu)) { // Linked cheat "(2/2) etc.."
if (nCurrentAddress < CHEAT_MAX_ADDRESS) {
AddressInfo();
if (HW_GGENIE) {
AddressInfoGameGenie();
} else {
AddressInfo();
}
}

continue;
Expand Down Expand Up @@ -631,7 +648,7 @@ static INT32 ConfigParseMAMEFile_internal(FILE *fz, const TCHAR *name)

OptionName(_T("Disabled"));

if (nAddress) {
if (nAddress || HW_GGENIE) {
if ((flags & 0x80018) == 0 && nAttrib != 0xffffffff) {
pCurrentCheat->bWriteWithMask = 1; // nAttrib field is the mask
}
Expand Down Expand Up @@ -669,12 +686,20 @@ static INT32 ConfigParseMAMEFile_internal(FILE *fz, const TCHAR *name)
n++;
nCurrentAddress = 0;
OptionName(tmp2);
AddressInfo();
if (HW_GGENIE) {
AddressInfoGameGenie();
} else {
AddressInfo();
}
}
} else {
n++;
OptionName(tmp);
AddressInfo();
if (HW_GGENIE) {
AddressInfoGameGenie();
} else {
AddressInfo();
}
}
} else {
menu = 1;
Expand Down Expand Up @@ -710,7 +735,11 @@ static INT32 ConfigParseMAMEFile_internal(FILE *fz, const TCHAR *name)
}

OptionName(tmp);
AddressInfo();
if (HW_GGENIE) {
AddressInfoGameGenie();
} else {
AddressInfo();
}

continue;
}
Expand All @@ -725,7 +754,13 @@ static INT32 ConfigParseMAMEFile_internal(FILE *fz, const TCHAR *name)
static INT32 ConfigParseMAMEFile()
{
TCHAR szFileName[MAX_PATH] = _T("");
_stprintf(szFileName, _T("%scheat.dat"), szAppCheatsPath);
if (HW_NES) {
_stprintf(szFileName, _T("%scheatnes.dat"), szAppCheatsPath);
} else if (HW_SNES) {
_stprintf(szFileName, _T("%scheatsnes.dat"), szAppCheatsPath);
} else {
_stprintf(szFileName, _T("%scheat.dat"), szAppCheatsPath);
}

FILE *fz = _tfopen(szFileName, _T("rt"));

Expand Down
3 changes: 2 additions & 1 deletion src/burner/win32/burner_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ extern bool bAlwaysCreateSupportFolders;
extern bool bAutoLoadGameList;

extern bool bQuietLoading;
extern bool bNoPopups;
extern bool bShonkyProfileMode;

extern bool bNoChangeNumLock;
Expand Down Expand Up @@ -303,7 +304,7 @@ extern int nScreenSizeVer; // For vertical orientation
extern int nWindowSize;

#define SHOW_PREV_GAMES 10
extern TCHAR szPrevGames[SHOW_PREV_GAMES][32];
extern TCHAR szPrevGames[SHOW_PREV_GAMES][64];

extern bool bModelessMenu;

Expand Down
6 changes: 4 additions & 2 deletions src/burner/win32/bzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,10 @@ static int __cdecl BzipBurnLoadRom(unsigned char* Dest, int* pnWrote, int i)

#if defined (BUILD_WIN32)
// Check for messages:
while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
DispatchMessage(&Msg);
if (bNoPopups == false) {
while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
DispatchMessage(&Msg);
}
}
#endif

Expand Down
34 changes: 34 additions & 0 deletions src/burner/win32/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bool bAlwaysCreateSupportFolders = true;
bool bAutoLoadGameList = false;

bool bQuietLoading = false;
bool bNoPopups = false;

bool bShonkyProfileMode = false;

Expand Down Expand Up @@ -873,6 +874,29 @@ bool AppProcessKeyboardInput()
return true;
}

void make_sha1_database(bool snes)
{
UINT32 nGameSelect = 0;

bNoPopups = true;

for (nGameSelect = 0; nGameSelect < nBurnDrvCount; nGameSelect++) {

#define HW_NES ( ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_NES) )
#define HW_SNES ( ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SNES) )

nBurnDrvActive=nGameSelect;

if ((!snes && HW_NES) || (snes && HW_SNES)) {
bprintf(0, _T("generating for %S\n"), BurnDrvGetTextA(DRV_NAME));
DrvInit(nGameSelect, true);
DrvExit();
}
}

return;
}

int ProcessCmdLine()
{
unsigned int i;
Expand Down Expand Up @@ -905,6 +929,16 @@ int ProcessCmdLine()
}

if (_tcslen(szName)) {
if (_tcscmp(szName, _T("-nessha1")) == 0) {
make_sha1_database(0);
return 1;
}

if (_tcscmp(szName, _T("-snessha1")) == 0) {
make_sha1_database(1);
return 1;
}

if (_tcscmp(szName, _T("-listinfo")) == 0 ||
_tcscmp(szName, _T("-listxml")) == 0) {
write_datfile(DAT_ARCADE_ONLY, stdout);
Expand Down
2 changes: 1 addition & 1 deletion src/burner/win32/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int nScreenSize = 0;
int nScreenSizeHor = 0;
int nScreenSizeVer = 0;

TCHAR szPrevGames[SHOW_PREV_GAMES][32];
TCHAR szPrevGames[SHOW_PREV_GAMES][64];

static HHOOK hMenuHook;

Expand Down
2 changes: 1 addition & 1 deletion src/burner/win32/popup_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ int FBAPopupDisplay(int nFlags)

FBAPopupLog();

if (!(nPopupFlags & PUF_TYPE_LOGONLY) && hRiched) {
if (!(nPopupFlags & PUF_TYPE_LOGONLY) && hRiched && bNoPopups == false) {
DialogBox(hAppInst, MAKEINTRESOURCE(IDD_POPUP), hScrnWnd, (DLGPROC)FBAPopupProc);
}

Expand Down
2 changes: 1 addition & 1 deletion src/burner/win32/progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static unsigned __stdcall DoProgress(void*)

int ProgressCreate()
{
if (hProgressDlg || hProgressThread) {
if (hProgressDlg || hProgressThread || bNoPopups) {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/burner/win32/scrn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ static void UpdatePreviousGameList()
}

// Declare temporary array
TCHAR szTmp[SHOW_PREV_GAMES][32];
TCHAR szTmp[SHOW_PREV_GAMES][64];

// Backup info for later use
for(int x = 0; x < SHOW_PREV_GAMES; x++) {
Expand Down

0 comments on commit 402a96f

Please sign in to comment.