From 0a40d9f9c644efc84a621b1696faf7934455a70b Mon Sep 17 00:00:00 2001 From: dborth Date: Wed, 29 Jul 2009 06:33:17 +0000 Subject: [PATCH] add game genie support, FDS BIOS and game genie ROM are set to load from fceugx/disksys.rom and fceugx/gg.rom --- source/fceultra/cart.cpp | 8 +++++-- source/fceultra/fceu.cpp | 4 ++++ source/ngc/cheatmgr.cpp | 49 ++++++++++++++++++++++++++++++++++++++ source/ngc/cheatmgr.h | 1 + source/ngc/fceugx.cpp | 2 +- source/ngc/fceugx.h | 1 + source/ngc/fceuload.cpp | 6 ++--- source/ngc/fceusupport.h | 1 + source/ngc/filebrowser.cpp | 6 ++++- 9 files changed, 71 insertions(+), 7 deletions(-) diff --git a/source/fceultra/cart.cpp b/source/fceultra/cart.cpp index 1a0f254..17da47e 100644 --- a/source/fceultra/cart.cpp +++ b/source/fceultra/cart.cpp @@ -293,7 +293,7 @@ void setchr8r(int r, unsigned int V) if(CHRram[r]) PPUCHRRAM|=(255); else - PPUCHRRAM=0; + PPUCHRRAM=0; } void setchr1(unsigned int A, unsigned int V) @@ -429,11 +429,15 @@ void SetupCartMirroring(int m, int hard, uint8 *extra) mirrorhard=hard; } +#ifdef GEKKO +uint8 *GENIEROM=0; +#else static uint8 *GENIEROM=0; +#endif void FixGenieMap(void); -// Called when a game(file) is opened successfully. +// Called when a game(file) is opened successfully. void OpenGenie(void) { FILE *fp; diff --git a/source/fceultra/fceu.cpp b/source/fceultra/fceu.cpp index 75d6cb7..008ea7d 100644 --- a/source/fceultra/fceu.cpp +++ b/source/fceultra/fceu.cpp @@ -110,7 +110,11 @@ static void CloseGame(void) if(GameInfo->type!=GIT_NSF) { + #ifdef GEKKO + FCEU_FlushGameCheats(0,1); // don't save cheats + #else FCEU_FlushGameCheats(0,0); + #endif } GameInterface(GI_CLOSE); diff --git a/source/ngc/cheatmgr.cpp b/source/ngc/cheatmgr.cpp index 684e696..cc2016e 100644 --- a/source/ngc/cheatmgr.cpp +++ b/source/ngc/cheatmgr.cpp @@ -9,6 +9,8 @@ * Cheat handling ***************************************************************************/ +#include + #include "fceugx.h" #include "fceusupport.h" #include "fileop.h" @@ -143,3 +145,50 @@ SetupCheats() FreeSaveBuffer (); } + +void OpenGameGenie() +{ + if (GENIEROM) // already loaded + { + geniestage=1; + return; + } + + int romSize = 0; + char * tmpbuffer = (char *) memalign(32, 512 * 1024); + if(!tmpbuffer) + return; + char filepath[1024]; + + if (MakeFilePath(filepath, FILE_GGROM, GCSettings.LoadMethod)) + { + romSize = LoadFile(tmpbuffer, filepath, 0, GCSettings.LoadMethod, SILENT); + } + + if (romSize > 0) + { + GENIEROM=(uint8 *)malloc(4096+1024); + + if(tmpbuffer[0]==0x4E) /* iNES ROM image */ + { + memcpy(GENIEROM,tmpbuffer+16,4096); + memcpy(GENIEROM+4096,tmpbuffer+16400,256); + } + else + { + memcpy(GENIEROM,tmpbuffer,4352); + } + + /* Workaround for the FCE Ultra CHR page size only being 1KB */ + for(int x=0; x<4; x++) + memcpy(GENIEROM+4096+(x<<8),GENIEROM+4096,256); + + geniestage=1; + } + else + { + free(GENIEROM); + GENIEROM=0; + } + free(tmpbuffer); +} diff --git a/source/ngc/cheatmgr.h b/source/ngc/cheatmgr.h index d9ce05b..9dd3cf7 100644 --- a/source/ngc/cheatmgr.h +++ b/source/ngc/cheatmgr.h @@ -10,5 +10,6 @@ ***************************************************************************/ void SetupCheats(); +void OpenGameGenie(); extern int numcheats; diff --git a/source/ngc/fceugx.cpp b/source/ngc/fceugx.cpp index 80caa50..e8d02fb 100644 --- a/source/ngc/fceugx.cpp +++ b/source/ngc/fceugx.cpp @@ -274,7 +274,7 @@ int main(int argc, char *argv[]) if (!FCEUI_Initialize()) ExitApp(); - FCEUI_SetGameGenie(0); // 0 - OFF, 1 - ON + FCEUI_SetGameGenie(1); // 0 - OFF, 1 - ON memset(FDSBIOS, 0, sizeof(FDSBIOS)); // clear FDS BIOS memory diff --git a/source/ngc/fceugx.h b/source/ngc/fceugx.h index f342d91..d9a55a3 100644 --- a/source/ngc/fceugx.h +++ b/source/ngc/fceugx.h @@ -40,6 +40,7 @@ enum { FILE_STATE, FILE_ROM, FILE_FDSBIOS, + FILE_GGROM, FILE_CHEAT, FILE_PREF }; diff --git a/source/ngc/fceuload.cpp b/source/ngc/fceuload.cpp index 41836ff..7e95d35 100644 --- a/source/ngc/fceuload.cpp +++ b/source/ngc/fceuload.cpp @@ -129,9 +129,9 @@ int GCMemROM(int method, int size) { FCEU_ResetVidSys(); - //if(GameInfo->type!=GIT_NSF) - // if(FSettings.GameGenie) - // OpenGenie(); + if(GameInfo->type!=GIT_NSF) + if(FSettings.GameGenie) + OpenGameGenie(); PowerNES(); //if(GameInfo->type!=GIT_NSF) diff --git a/source/ngc/fceusupport.h b/source/ngc/fceusupport.h index 4e8cf14..c5db766 100644 --- a/source/ngc/fceusupport.h +++ b/source/ngc/fceusupport.h @@ -42,6 +42,7 @@ extern int iNESLoad(const char *name, FCEUFILE *fp, int o); extern int UNIFLoad(const char *name, FCEUFILE *fp); extern int NSFLoad(FCEUFILE *fp); extern uint8 FDSBIOS[8192]; +extern uint8 *GENIEROM; extern FCEUGI *GameInfo; extern int CloseGame(); diff --git a/source/ngc/filebrowser.cpp b/source/ngc/filebrowser.cpp index 2d25b3e..16f39fc 100644 --- a/source/ngc/filebrowser.cpp +++ b/source/ngc/filebrowser.cpp @@ -269,9 +269,13 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi break; case FILE_FDSBIOS: - sprintf(folder, GCSettings.LoadFolder); + sprintf(folder, "fceugx"); sprintf(file, "disksys.rom"); break; + case FILE_GGROM: + sprintf(folder, "fceugx"); + sprintf(file, "gg.rom"); + break; case FILE_CHEAT: sprintf(folder, GCSettings.CheatFolder); sprintf(file, "%s.cht", romFilename);