From 69bc4b3f72544ed58ac6ff5bf385f1aa555e7a64 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 22 Jun 2008 02:38:00 +0000 Subject: [PATCH] added obj/bg display toggle much cleanups fix memwatch configuration saving --- src/driver.h | 6 +- src/drivers/common/config.h | 24 +- src/drivers/win/config.cpp | 119 +- src/drivers/win/directories.cpp | 16 +- src/drivers/win/main.cpp | 137 +- src/drivers/win/main.h | 11 +- src/drivers/win/memview.cpp | 9 +- src/drivers/win/memwatch.cpp | 25 +- src/drivers/win/memwatch.h | 1 + src/drivers/win/replay.cpp | 6 +- src/drivers/win/res.rc | 3 + src/drivers/win/resource.h | 7 +- src/drivers/win/window.cpp | 26 +- src/file.cpp | 738 ++++++----- src/file.h | 2 +- src/netplay.cpp | 11 +- src/ppu.cpp | 2084 +++++++++++++++---------------- 17 files changed, 1601 insertions(+), 1624 deletions(-) diff --git a/src/driver.h b/src/driver.h index 8c4834cd..8a5d163f 100644 --- a/src/driver.h +++ b/src/driver.h @@ -86,8 +86,8 @@ void FCEUI_SetSnapName(int a); //0 to keep 8-sprites limitation, 1 to remove it void FCEUI_DisableSpriteLimitation(int a); -//-1 = no change, 0 = show, 1 = hide, 2 = internal toggle -void FCEUI_SetRenderDisable(int sprites, int bg); +void FCEUI_SetRenderPlanes(bool sprites, bool bg); +void FCEUI_GetRenderPlanes(bool& sprites, bool& bg); //name=path and file to load. returns 0 on failure, 1 on success FCEUGI *FCEUI_LoadGame(const char *name, int OverwriteVidMode); @@ -125,7 +125,7 @@ void FCEUI_FrameSkip(int x); void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall); //Sets the base directory(save states, snapshots, etc. are saved in directories below this directory. -void FCEUI_SetBaseDirectory(const char *dir); +void FCEUI_SetBaseDirectory(std::string const & dir); //Tells FCE Ultra to copy the palette data pointed to by pal and use it. //Data pointed to by pal needs to be 64*3 bytes in length. diff --git a/src/drivers/common/config.h b/src/drivers/common/config.h index 3b63ab48..7c4f3aad 100644 --- a/src/drivers/common/config.h +++ b/src/drivers/common/config.h @@ -8,31 +8,29 @@ typedef struct { void SaveFCEUConfig(const char *filename, const CFGSTRUCT *cfgst); void LoadFCEUConfig(const char *filename, CFGSTRUCT *cfgst); -/* Macros for building CFGSTRUCT structures. */ +//Macros for building CFGSTRUCT structures. -/* CFGSTRUCT structures must always end with ENDCFGSTRUCT */ +// CFGSTRUCT structures must always end with ENDCFGSTRUCT #define ENDCFGSTRUCT { 0,0,0 } -/* When this macro is used, the config loading/saving code will parse - the new config structure until the end of it is detected, then it - will continue parsing the original config structure. -*/ + //When this macro is used, the config loading/saving code will parse + //the new config structure until the end of it is detected, then it + //will continue parsing the original config structure. #define ADDCFGSTRUCT(x) { 0,&x,0 } -/* Oops. The NAC* macros shouldn't have the # in front of the w, but - fixing this would break configuration files of previous versions and it - isn't really hurting much. -*/ +// Oops. The NAC* macros shouldn't have the # in front of the w, but +// fixing this would break configuration files of previous versions and it +// isn't really hurting much. -/* Single piece of data(integer). */ +// Single piece of data(integer). #define AC(x) { #x,&x,sizeof(x)} #define NAC(w,x) { #w,&x,sizeof(x)} -/* Array. */ +// Array. #define ACA(x) {#x,x,sizeof(x)} #define NACA(w,x) {#w,x,sizeof(x)} -/* String(pointer) with automatic memory allocation. */ +// String(pointer) with automatic memory allocation. #define ACS(x) {#x,&x,0} #define NACS(w,x) {#w,&x,0} diff --git a/src/drivers/win/config.cpp b/src/drivers/win/config.cpp index 7f057ee0..6bf0a0b0 100644 --- a/src/drivers/win/config.cpp +++ b/src/drivers/win/config.cpp @@ -54,71 +54,70 @@ extern int Tracer_wndx, Tracer_wndy; extern int CDLogger_wndx, CDLogger_wndy; extern int GGConv_wndx, GGConv_wndy; -/** -* Structure that contains configuration information -**/ + +//Structure that contains configuration information static CFGSTRUCT fceuconfig[] = { - ACS(recent_files[0]), - ACS(recent_files[1]), - ACS(recent_files[2]), - ACS(recent_files[3]), - ACS(recent_files[4]), - ACS(recent_files[5]), - ACS(recent_files[6]), - ACS(recent_files[7]), - ACS(recent_files[8]), - ACS(recent_files[9]), + ACS(recent_files[0]), + ACS(recent_files[1]), + ACS(recent_files[2]), + ACS(recent_files[3]), + ACS(recent_files[4]), + ACS(recent_files[5]), + ACS(recent_files[6]), + ACS(recent_files[7]), + ACS(recent_files[8]), + ACS(recent_files[9]), - ACS(memw_recent_files[0]), - ACS(memw_recent_files[1]), - ACS(memw_recent_files[2]), - ACS(memw_recent_files[3]), - ACS(memw_recent_files[4]), - + ACS(memw_recent_files[0]), + ACS(memw_recent_files[1]), + ACS(memw_recent_files[2]), + ACS(memw_recent_files[3]), + ACS(memw_recent_files[4]), - AC(ntsccol),AC(ntsctint),AC(ntschue), - NAC("palyo",pal_emulation), + AC(ntsccol),AC(ntsctint),AC(ntschue), + + NAC("palyo",pal_emulation), NAC("genie",genie), NAC("fs",fullscreen), NAC("vgamode",vmod), NAC("sound",soundo), - NAC("sicon",status_icon), + NAC("sicon",status_icon), - ACS(gfsdir), + ACS(gfsdir), - NACS("odroms",directory_names[0]), - NACS("odnonvol",directory_names[1]), - NACS("odstates",directory_names[2]), - NACS("odfdsrom",directory_names[3]), - NACS("odsnaps",directory_names[4]), - NACS("odcheats",directory_names[5]), - NACS("odmovies",directory_names[6]), - NACS("odmemwatch",directory_names[7]), - NACS("odbasicbot",directory_names[8]), - NACS("odmacro",directory_names[9]), - NACS("odinput",directory_names[10]), - NACS("odlua",directory_names[11]), - NACS("odbase",directory_names[12]), + NACS("odroms",directory_names[0]), + NACS("odnonvol",directory_names[1]), + NACS("odstates",directory_names[2]), + NACS("odfdsrom",directory_names[3]), + NACS("odsnaps",directory_names[4]), + NACS("odcheats",directory_names[5]), + NACS("odmovies",directory_names[6]), + NACS("odmemwatch",directory_names[7]), + NACS("odbasicbot",directory_names[8]), + NACS("odmacro",directory_names[9]), + NACS("odinput",directory_names[10]), + NACS("odlua",directory_names[11]), + NACS("odbase",directory_names[12]), - AC(winspecial), - AC(winsizemulx), - AC(winsizemuly), - NAC("saspectw987",saspectw), - NAC("saspecth987",saspecth), + AC(winspecial), + AC(winsizemulx), + AC(winsizemuly), + NAC("saspectw987",saspectw), + NAC("saspecth987",saspecth), AC(soundrate), - AC(soundbuftime), + AC(soundbuftime), AC(soundoptions), AC(soundquality), - AC(soundvolume), + AC(soundvolume), - AC(goptions), + AC(goptions), NAC("eoptions",eoptions), - NACA("cpalette",cpalette), + NACA("cpalette",cpalette), - NACA("InputType",InputType), + NACA("InputType",InputType), NAC("vmcx",vmodes[0].x), NAC("vmcy",vmodes[0].y), @@ -126,24 +125,24 @@ static CFGSTRUCT fceuconfig[] = { NAC("vmcf",vmodes[0].flags), NAC("vmcxs",vmodes[0].xscale), NAC("vmcys",vmodes[0].yscale), - NAC("vmspecial",vmodes[0].special), + NAC("vmspecial",vmodes[0].special), - NAC("srendline",srendlinen), - NAC("erendline",erendlinen), - NAC("srendlinep",srendlinep), - NAC("erendlinep",erendlinep), + NAC("srendline",srendlinen), + NAC("erendline",erendlinen), + NAC("srendlinep",srendlinep), + NAC("erendlinep",erendlinep), - AC(disvaccel), + AC(disvaccel), AC(winsync), - NAC("988fssync",fssync), + NAC("988fssync",fssync), - AC(ismaximized), - AC(maxconbskip), - AC(ffbskip), + AC(ismaximized), + AC(maxconbskip), + AC(ffbskip), - ADDCFGSTRUCT(NetplayConfig), - ADDCFGSTRUCT(InputConfig), - ADDCFGSTRUCT(HotkeyConfig), + ADDCFGSTRUCT(NetplayConfig), + ADDCFGSTRUCT(InputConfig), + ADDCFGSTRUCT(HotkeyConfig), AC(autoHoldKey), AC(autoHoldClearKey), @@ -188,7 +187,7 @@ static CFGSTRUCT fceuconfig[] = { AC(pauseAfterPlayback), //ACS(memwLastfile[2048]), - ENDCFGSTRUCT + ENDCFGSTRUCT }; void SaveConfig(const char *filename) diff --git a/src/drivers/win/directories.cpp b/src/drivers/win/directories.cpp index d8275292..4efb3fd6 100644 --- a/src/drivers/win/directories.cpp +++ b/src/drivers/win/directories.cpp @@ -3,12 +3,8 @@ #include "window.h" #include "gui.h" -/** -* Processes information from the Directories selection dialog after -* the dialog was closed. -* -* @param hwndDlg Handle of the dialog window. -**/ +///Processes information from the Directories selection dialog after the dialog was closed. +///@param hwndDlg Handle of the dialog window. void CloseDirectoriesDialog(HWND hwndDlg) { // Update the information from the screenshot naming checkbox @@ -90,9 +86,7 @@ void CloseDirectoriesDialog(HWND hwndDlg) EndDialog(hwndDlg, 0); } -/** -* Callback function for the directories configuration dialog. -**/ +///Callback function for the directories configuration dialog. static BOOL CALLBACK DirConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) @@ -167,9 +161,7 @@ static BOOL CALLBACK DirConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM return 0; } -/** -* Shows the dialog for configuring the standard directories. -**/ +//Shows the dialog for configuring the standard directories. void ConfigDirectories() { DialogBox(fceu_hInstance, "DIRCONFIG", hAppWnd, DirConCallB); diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index b495672e..509b40c6 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -121,23 +121,21 @@ double winsizemulx = 1, winsizemuly = 1; int genie = 0; int pal_emulation = 0; int ntsccol = 0, ntsctint, ntschue; -char BaseDirectory[2048]; +std::string BaseDirectory; // Contains the names of the overridden standard directories // in the order roms, nonvol, states, fdsrom, snaps, cheats, movies, memwatch, basicbot, macro, input presets, lua scripts, base char *directory_names[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -/** -* Handle of the main window. -**/ +//Handle of the main window. HWND hAppWnd = 0; uint32 goptions = GOO_DISABLESS; -/* Some timing-related variables (now ignored). */ -int maxconbskip = 32; /* Maximum consecutive blit skips. */ -int ffbskip = 32; /* Blit skips per blit when FF-ing */ +// Some timing-related variables (now ignored). +int maxconbskip = 32; //Maximum consecutive blit skips. +int ffbskip = 32; //Blit skips per blit when FF-ing HINSTANCE fceu_hInstance; HACCEL fceu_hAccel; @@ -165,18 +163,16 @@ int srendlinep = 0; int erendlinep = 239; //mbg 6/30/06 - indicates that the main loop should close the game as soon as it can -int closeGame = 0; +bool closeGame = false; + // qfox 09/17/06: moved the skipcount outside because it was completely pointless // in there. -/** - * Counts the number of frames that have not been displayed - * Used for the bot, to skip frames (and save time). - **/ +//Counts the number of frames that have not been displayed +//Used for the bot, to skip frames (and save time). int skipcount = 0; // Internal functions - void SetDirs() { int x; @@ -213,31 +209,22 @@ void SetDirs() } } -/** -* Creates a directory. -* -* @param dirname Name of the directory to create. -**/ +/// Creates a directory. +/// @param dirname Name of the directory to create. void DirectoryCreator(const char* dirname) { CreateDirectory(dirname, 0); } -/** -* Removes a directory. -* -* @param dirname Name of the directory to remove. -**/ +/// Removes a directory. +/// @param dirname Name of the directory to remove. void DirectoryRemover(const char* dirname) { RemoveDirectory(dirname); } -/** -* Used to walk over the default directories array. -* -* @param callback Callback function that's called for every default directory name. -**/ +/// Used to walk over the default directories array. +/// @param callback Callback function that's called for every default directory name. void DefaultDirectoryWalker(void (*callback)(const char*)) { unsigned int curr_dir; @@ -249,7 +236,7 @@ void DefaultDirectoryWalker(void (*callback)(const char*)) sprintf( TempArray, "%s\\%s", - directory_names[NUMBER_OF_DEFAULT_DIRECTORIES] ? directory_names[NUMBER_OF_DEFAULT_DIRECTORIES] : BaseDirectory, + directory_names[NUMBER_OF_DEFAULT_DIRECTORIES] ? directory_names[NUMBER_OF_DEFAULT_DIRECTORIES] : BaseDirectory.c_str(), default_directory_names[curr_dir] ); @@ -258,40 +245,31 @@ void DefaultDirectoryWalker(void (*callback)(const char*)) } } -/* Remove empty, unused directories. */ +/// Remove empty, unused directories. void RemoveDirs() { DefaultDirectoryWalker(DirectoryRemover); } -/** -* Creates the default directories. -**/ +///Creates the default directories. void CreateDirs() { DefaultDirectoryWalker(DirectoryCreator); } -/** -* Fills the BaseDirectory string -* -* TODO: Potential buffer overflow caused by limited size of BaseDirectory? -**/ + +//Fills the BaseDirectory string +//TODO: Potential buffer overflow caused by limited size of BaseDirectory? void GetBaseDirectory(void) { - unsigned int i; - GetModuleFileName(0, (LPTSTR)BaseDirectory, sizeof(BaseDirectory) - 1); + char temp[2048]; + GetModuleFileName(0, temp, 2048); + BaseDirectory = temp; - // Search for the last / or \ in the directory and terminate the string there - for(i = strlen(BaseDirectory); i >= 0 ; i--) - { - if(BaseDirectory[i]=='\\' || BaseDirectory[i]=='/') - { - BaseDirectory[i] = 0; - return; - } - } + size_t truncate_at = BaseDirectory.find_last_of("\\/"); + if(truncate_at != std::string::npos) + BaseDirectory = BaseDirectory.substr(0,truncate_at); } int BlockingCheck() @@ -348,11 +326,8 @@ void UpdateRendBounds() FCEUI_SetRenderedLines(srendlinen, erendlinen, srendlinep, erendlinep); } -/** -* Shows an error message in a message box. -* -* @param errormsg Text of the error message. -**/ +/// Shows an error message in a message box. +///@param errormsg Text of the error message. void FCEUD_PrintError(const char *errormsg) { AddLogText(errormsg, 1); @@ -370,54 +345,49 @@ void FCEUD_PrintError(const char *errormsg) } } -/** -* Generates a compiler identification string. -* -* @return Compiler identification string -**/ +///Generates a compiler identification string. +/// @return Compiler identification string const char *FCEUD_GetCompilerString() { return __COMPILER__STRING__; } -/** -* Displays the about box -**/ +//Displays the about box void ShowAboutBox() { MessageBox(hAppWnd, FCEUI_GetAboutString(), FCEU_NAME, MB_OK); } -/** -* Exits FCE Ultra -**/ +//Exits FCE Ultra void DoFCEUExit() { - /* Wolfenstein 3D had cute exit messages. */ - char *emsg[4]={"Are you sure you want to leave? I'll become lonely!", - "If you exit, I'll... EAT YOUR MOUSE.", - "You can never really exit, you know.", - "E-x-i-t?" - }; - - KillDebugger(); //mbg merge 7/19/06 added - - if(exiting) /* Eh, oops. I'll need to try to fix this later. */ + if(exiting) //Eh, oops. I'll need to try to fix this later. return; if(goptions & GOO_CONFIRMEXIT) { + //Wolfenstein 3D had cute exit messages. + const char * const emsg[4]={"Are you sure you want to leave? I'll become lonely!", + "If you exit, I'll... EAT YOUR MOUSE.", + "You can never really exit, you know.", + "E-x-i-t?" + }; + if(IDYES != MessageBox(hAppWnd, emsg[rand() & 3], "Exit FCE Ultra?", MB_ICONQUESTION | MB_YESNO) ) { return; } } + CloseMemoryWatch(); + + KillDebugger(); //mbg merge 7/19/06 added + FCEUI_StopMovie(); FCEUD_AviStop(); exiting = 1; - closeGame = 1;//mbg 6/30/06 - for housekeeping purposes we need to exit after the emulation cycle finishes + closeGame = true;//mbg 6/30/06 - for housekeeping purposes we need to exit after the emulation cycle finishes } void FCEUD_OnCloseGame() @@ -459,7 +429,7 @@ int DriverInitialize() static void DriverKill(void) { // Save config file - sprintf(TempArray, "%s/fceu98.cfg", BaseDirectory); + sprintf(TempArray, "%s/fceu98.cfg", BaseDirectory.c_str()); SaveConfig(TempArray); DestroyInput(); @@ -551,10 +521,7 @@ void do_exit() FCEUI_Kill(); } -/** -* Puts the default directory names into the elements of the directory_names array -* that aren't already defined. -**/ +//Puts the default directory names into the elements of the directory_names array that aren't already defined. void initDirectories() { for (unsigned int i = 0; i < NUMBER_OF_DEFAULT_DIRECTORIES; i++) @@ -564,7 +531,7 @@ void initDirectories() sprintf( TempArray, "%s\\%s", - directory_names[NUMBER_OF_DEFAULT_DIRECTORIES] ? directory_names[NUMBER_OF_DEFAULT_DIRECTORIES] : BaseDirectory, + directory_names[i] ? directory_names[i] : BaseDirectory.c_str(), default_directory_names[i] ); @@ -575,8 +542,8 @@ void initDirectories() if (directory_names[NUMBER_OF_DIRECTORIES - 1] == 0) { - directory_names[NUMBER_OF_DIRECTORIES - 1] = (char*)malloc(strlen(BaseDirectory) + 1); - strcpy(directory_names[NUMBER_OF_DIRECTORIES - 1], BaseDirectory); + directory_names[NUMBER_OF_DIRECTORIES - 1] = (char*)malloc(BaseDirectory.size() + 1); + strcpy(directory_names[NUMBER_OF_DIRECTORIES - 1], BaseDirectory.c_str()); } } @@ -607,7 +574,7 @@ int main(int argc,char *argv[]) GetBaseDirectory(); // Load the config information - sprintf(TempArray,"%s\\fceu98.cfg",BaseDirectory); + sprintf(TempArray,"%s\\fceu98.cfg",BaseDirectory.c_str()); LoadConfig(TempArray); initDirectories(); diff --git a/src/drivers/win/main.h b/src/drivers/win/main.h index a71730e7..47035c40 100644 --- a/src/drivers/win/main.h +++ b/src/drivers/win/main.h @@ -2,6 +2,7 @@ #define WIN_MAIN_H #include "common.h" +#include // #defines @@ -44,9 +45,7 @@ static char *gfsdir=0; extern char* directory_names[13]; -/** -* Contains the names of the default directories. -**/ +///Contains the names of the default directories. static const char *default_directory_names[12] = { "", // roms "sav", // nonvol @@ -88,10 +87,8 @@ extern int ntsccol, ntsctint, ntschue; static int changerecursive=0; -/** -* Contains the base directory of FCE -**/ -extern char BaseDirectory[2048]; +/// Contains the base directory of FCE +extern std::string BaseDirectory; extern int soundo; extern int eoptions; diff --git a/src/drivers/win/memview.cpp b/src/drivers/win/memview.cpp index bf7b06bf..7cd0ef3a 100644 --- a/src/drivers/win/memview.cpp +++ b/src/drivers/win/memview.cpp @@ -646,9 +646,12 @@ void InputData(char *input){ if(EditingMode == 0)BWrite[addr](addr,data[i]); if(EditingMode == 1){ addr &= 0x3FFF; - if(addr < 0x2000)VPage[addr>>10][addr] = data[i]; //todo: detect if this is vrom and turn it red if so - if((addr > 0x2000) && (addr < 0x3F00))vnapage[(addr>>10)&0x3][addr&0x3FF] = data[i]; //todo: this causes 0x3000-0x3f00 to mirror 0x2000-0x2f00, is this correct? - if((addr > 0x3F00) && (addr < 0x3FFF))PALRAM[addr&0x1F] = data[i]; + if(addr < 0x2000) + VPage[addr>>10][addr] = data[i]; //todo: detect if this is vrom and turn it red if so + if((addr >= 0x2000) && (addr < 0x3F00)) + vnapage[(addr>>10)&0x3][addr&0x3FF] = data[i]; //todo: this causes 0x3000-0x3f00 to mirror 0x2000-0x2f00, is this correct? + if((addr >= 0x3F00) && (addr < 0x3FFF)) + PALRAM[addr&0x1F] = data[i]; } if(EditingMode == 2){ ApplyPatch(addr,datasize,data); diff --git a/src/drivers/win/memwatch.cpp b/src/drivers/win/memwatch.cpp index 6a893a6c..56b5d9a1 100644 --- a/src/drivers/win/memwatch.cpp +++ b/src/drivers/win/memwatch.cpp @@ -584,19 +584,22 @@ fileChanged = false; void CloseMemoryWatch() { - SaveStrings(); - - //TODO: save window x,y and last file opened to some variables then save them to config when fceu closes - if (fileChanged==true) + if(hwndMemWatch) + { + SaveStrings(); + + //TODO: save window x,y and last file opened to some variables then save them to config when fceu closes + if (fileChanged==true) + { + if(MessageBox(hwndMemWatch, "Save Changes?", "Memory Watch Settings", MB_YESNO)==IDYES) { - if(MessageBox(hwndMemWatch, "Save Changes?", "Save", MB_YESNO)==IDYES) - { - SaveMemWatch(); - } + SaveMemWatch(); } - - DestroyWindow(hwndMemWatch); - hwndMemWatch=0; + } + + DestroyWindow(hwndMemWatch); + hwndMemWatch=0; + } } diff --git a/src/drivers/win/memwatch.h b/src/drivers/win/memwatch.h index f9c9280a..2f5eabf3 100644 --- a/src/drivers/win/memwatch.h +++ b/src/drivers/win/memwatch.h @@ -1,5 +1,6 @@ void UpdateMemWatch(); void CreateMemWatch(); +void CloseMemoryWatch(); void AddMemWatch(char memaddress[32]); extern char * MemWatchDir; extern bool MemWatchLoadOnStart; diff --git a/src/drivers/win/replay.cpp b/src/drivers/win/replay.cpp index dfe3d4f7..68b520ee 100644 --- a/src/drivers/win/replay.cpp +++ b/src/drivers/win/replay.cpp @@ -40,7 +40,7 @@ static char* GetReplayPath(HWND hwndDlg) else strcpy(szChoice, szTemp); - SetCurrentDirectory(BaseDirectory); + SetCurrentDirectory(BaseDirectory.c_str()); _splitpath(szChoice, szDrive, szDirectory, szFilename, szExt); if(szDrive[0]=='\0' && szDirectory[0]=='\0') @@ -374,7 +374,7 @@ BOOL CALLBACK ReplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP //if we get here, then we had a match char relative[MAX_PATH]; - AbsoluteToRelative(relative, filename, BaseDirectory); + AbsoluteToRelative(relative, filename, BaseDirectory.c_str()); SendDlgItemMessage(hwndDlg, IDC_COMBO_FILENAME, CB_INSERTSTRING, i++, (LPARAM)relative); } while(FindNextFile(hFind, &wfd)); FindClose(hFind); @@ -453,7 +453,7 @@ BOOL CALLBACK ReplayDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lP if(GetOpenFileName(&ofn)) { char relative[MAX_PATH]; - AbsoluteToRelative(relative, szFile, BaseDirectory); + AbsoluteToRelative(relative, szFile, BaseDirectory.c_str()); LONG lOtherIndex = SendDlgItemMessage(hwndDlg, IDC_COMBO_FILENAME, CB_FINDSTRING, (WPARAM)-1, (LPARAM)relative); if(lOtherIndex != CB_ERR) diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 650e7be5..ee9548a6 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -67,6 +67,9 @@ BEGIN MENUITEM "&Switch Disk Side", MENU_SWITCH_DISK MENUITEM SEPARATOR MENUITEM "&Insert Coin", MENU_INSERT_COIN + MENUITEM SEPARATOR + MENUITEM "Display BG", MENU_DISPLAY_BG + MENUITEM "Display OBJ", MENU_DISPLAY_OBJ END POPUP "&Config" BEGIN diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index a2697240..bb8ff69f 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -518,6 +518,11 @@ #define ID_FILE_OOADFM2 40141 #define ID_FILE_OPENFM2 40142 #define ID_FILE_SAVEFM2 40143 +#define ID_TWEAKS_DISPLAYBG 40144 +#define ID_TWEAKS_DISPLAYOBJ 40145 +#define ID_ 40146 +#define MENU_DISPLAY_BG 40147 +#define MENU_DISPLAY_OBJ 40148 #define MW_ValueLabel2 65423 #define MW_ValueLabel1 65426 #define GUI_BOT_DEBUG 65436 @@ -528,7 +533,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 114 -#define _APS_NEXT_COMMAND_VALUE 40144 +#define _APS_NEXT_COMMAND_VALUE 40149 #define _APS_NEXT_CONTROL_VALUE 1132 #define _APS_NEXT_SYMED_VALUE 101 #endif diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 9aa9e42c..46726ffb 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -166,16 +166,24 @@ void updateGameDependentMenus(unsigned int enable) //Updates menu items which need to be checked or unchecked. void UpdateCheckedMenuItems() { - static int *polo[] = { &genie, &pal_emulation, &status_icon }; + bool spr, bg; + FCEUI_GetRenderPlanes(spr,bg); + + static int *polo[] = { &genie, &pal_emulation, &status_icon}; static int polo2[]={ MENU_GAME_GENIE, MENU_PAL, MENU_SHOW_STATUS_ICON }; int x; + + // Check or uncheck the necessary menu items for(x = 0; x < sizeof(polo) / sizeof(*polo); x++) { CheckMenuItem(fceumenu, polo2[x], *polo[x] ? MF_CHECKED : MF_UNCHECKED); } + CheckMenuItem(fceumenu, MENU_DISPLAY_BG, bg?MF_CHECKED:MF_UNCHECKED); + CheckMenuItem(fceumenu, MENU_DISPLAY_OBJ, spr?MF_CHECKED:MF_UNCHECKED); + CheckMenuItem(fceumenu, MENU_PAUSEAFTERPLAYBACK, pauseAfterPlayback ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(fceumenu, MENU_RUN_IN_BACKGROUND, eoptions & EO_BGRUN ? MF_CHECKED : MF_UNCHECKED); @@ -871,6 +879,20 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) // DoVideoConfigFix(); SetMainWindowStuff(); break; + + case MENU_DISPLAY_BG: + case MENU_DISPLAY_OBJ: + { + bool spr, bg; + FCEUI_GetRenderPlanes(spr,bg); + if(LOWORD(wParam)==MENU_DISPLAY_BG) + bg = !bg; + else + spr = !spr; + FCEUI_SetRenderPlanes(spr,bg); + } + break; + case MENU_CHEATS: ConfigCheats(hWnd); @@ -1108,6 +1130,8 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) } goto proco; case WM_ENTERMENULOOP: + UpdateCheckedMenuItems(); + EnableMenuItem(fceumenu,MENU_RESET,MF_BYCOMMAND | (FCEU_IsValidUI(FCEUI_RESET)?MF_ENABLED:MF_GRAYED)); EnableMenuItem(fceumenu,MENU_POWER,MF_BYCOMMAND | (FCEU_IsValidUI(FCEUI_POWER)?MF_ENABLED:MF_GRAYED)); EnableMenuItem(fceumenu,MENU_TASEDIT,MF_BYCOMMAND | (FCEU_IsValidUI(FCEUI_TASEDIT)?MF_ENABLED:MF_GRAYED)); diff --git a/src/file.cpp b/src/file.cpp index 364b3281..1d535d2e 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -42,6 +42,8 @@ #include "driver.h" #include "utils/xstring.h" +using namespace std; + typedef struct { uint8 *data; uint32 size; @@ -50,397 +52,397 @@ typedef struct { void ApplyIPS(FILE *ips, MEMWRAP *dest) { - uint8 header[5]; - uint32 count=0; + uint8 header[5]; + uint32 count=0; - FCEU_printf(" Applying IPS...\n"); - if(fread(header,1,5,ips)!=5) - { - fclose(ips); - return; - } - if(memcmp(header,"PATCH",5)) - { - fclose(ips); - return; - } + FCEU_printf(" Applying IPS...\n"); + if(fread(header,1,5,ips)!=5) + { + fclose(ips); + return; + } + if(memcmp(header,"PATCH",5)) + { + fclose(ips); + return; + } - while(fread(header,1,3,ips)==3) - { - uint32 offset=(header[0]<<16)|(header[1]<<8)|header[2]; - uint16 size; + while(fread(header,1,3,ips)==3) + { + uint32 offset=(header[0]<<16)|(header[1]<<8)|header[2]; + uint16 size; - if(!memcmp(header,"EOF",3)) - { - FCEU_printf(" IPS EOF: Did %d patches\n\n",count); - fclose(ips); - return; - } + if(!memcmp(header,"EOF",3)) + { + FCEU_printf(" IPS EOF: Did %d patches\n\n",count); + fclose(ips); + return; + } - size=fgetc(ips)<<8; - size|=fgetc(ips); - if(!size) /* RLE */ - { - uint8 *start; - uint8 b; - size=fgetc(ips)<<8; - size|=fgetc(ips); + size=fgetc(ips)<<8; + size|=fgetc(ips); + if(!size) /* RLE */ + { + uint8 *start; + uint8 b; + size=fgetc(ips)<<8; + size|=fgetc(ips); - //FCEU_printf(" Offset: %8d Size: %5d RLE\n",offset,size); + //FCEU_printf(" Offset: %8d Size: %5d RLE\n",offset,size); - if((offset+size)>dest->size) - { - uint8 *tmp; + if((offset+size)>dest->size) + { + uint8 *tmp; - // Probably a little slow. - tmp=(uint8 *)realloc(dest->data,offset+size); - if(!tmp) - { - FCEU_printf(" Oops. IPS patch %d(type RLE) goes beyond end of file. Could not allocate memory.\n",count); - fclose(ips); - return; - } - dest->size=offset+size; - dest->data=tmp; - memset(dest->data+dest->size,0,offset+size-dest->size); - } - b=fgetc(ips); - start=dest->data+offset; - do - { - *start=b; - start++; - } while(--size); - } - else /* Normal patch */ - { - //FCEU_printf(" Offset: %8d Size: %5d\n",offset,size); - if((offset+size)>dest->size) - { - uint8 *tmp; + // Probably a little slow. + tmp=(uint8 *)realloc(dest->data,offset+size); + if(!tmp) + { + FCEU_printf(" Oops. IPS patch %d(type RLE) goes beyond end of file. Could not allocate memory.\n",count); + fclose(ips); + return; + } + dest->size=offset+size; + dest->data=tmp; + memset(dest->data+dest->size,0,offset+size-dest->size); + } + b=fgetc(ips); + start=dest->data+offset; + do + { + *start=b; + start++; + } while(--size); + } + else /* Normal patch */ + { + //FCEU_printf(" Offset: %8d Size: %5d\n",offset,size); + if((offset+size)>dest->size) + { + uint8 *tmp; - // Probably a little slow. - tmp=(uint8 *)realloc(dest->data,offset+size); - if(!tmp) - { - FCEU_printf(" Oops. IPS patch %d(type normal) goes beyond end of file. Could not allocate memory.\n",count); - fclose(ips); - return; - } - dest->data=tmp; - memset(dest->data+dest->size,0,offset+size-dest->size); - } - fread(dest->data+offset,1,size,ips); - } - count++; - } - fclose(ips); - FCEU_printf(" Hard IPS end!\n"); + // Probably a little slow. + tmp=(uint8 *)realloc(dest->data,offset+size); + if(!tmp) + { + FCEU_printf(" Oops. IPS patch %d(type normal) goes beyond end of file. Could not allocate memory.\n",count); + fclose(ips); + return; + } + dest->data=tmp; + memset(dest->data+dest->size,0,offset+size-dest->size); + } + fread(dest->data+offset,1,size,ips); + } + count++; + } + fclose(ips); + FCEU_printf(" Hard IPS end!\n"); } static MEMWRAP *MakeMemWrap(void *tz, int type) { - MEMWRAP *tmp; + MEMWRAP *tmp; - if(!(tmp=(MEMWRAP *)FCEU_malloc(sizeof(MEMWRAP)))) - goto doret; - tmp->location=0; + if(!(tmp=(MEMWRAP *)FCEU_malloc(sizeof(MEMWRAP)))) + goto doret; + tmp->location=0; - if(type==0) - { - fseek((FILE *)tz,0,SEEK_END); - tmp->size=ftell((FILE *)tz); - fseek((FILE *)tz,0,SEEK_SET); - if(!(tmp->data=(uint8*)FCEU_malloc(tmp->size))) - { - free(tmp); - tmp=0; - goto doret; - } - fread(tmp->data,1,tmp->size,(FILE *)tz); - } - else if(type==1) - { - /* Bleck. The gzip file format has the size of the uncompressed data, - but I can't get to the info with the zlib interface(?). */ - for(tmp->size=0; gzgetc(tz) != EOF; tmp->size++); - gzseek(tz,0,SEEK_SET); - if(!(tmp->data=(uint8 *)FCEU_malloc(tmp->size))) - { - free(tmp); - tmp=0; - goto doret; - } - gzread(tz,tmp->data,tmp->size); - } - else if(type==2) - { - unz_file_info ufo; - unzGetCurrentFileInfo(tz,&ufo,0,0,0,0,0,0); + if(type==0) + { + fseek((FILE *)tz,0,SEEK_END); + tmp->size=ftell((FILE *)tz); + fseek((FILE *)tz,0,SEEK_SET); + if(!(tmp->data=(uint8*)FCEU_malloc(tmp->size))) + { + free(tmp); + tmp=0; + goto doret; + } + fread(tmp->data,1,tmp->size,(FILE *)tz); + } + else if(type==1) + { + /* Bleck. The gzip file format has the size of the uncompressed data, + but I can't get to the info with the zlib interface(?). */ + for(tmp->size=0; gzgetc(tz) != EOF; tmp->size++); + gzseek(tz,0,SEEK_SET); + if(!(tmp->data=(uint8 *)FCEU_malloc(tmp->size))) + { + free(tmp); + tmp=0; + goto doret; + } + gzread(tz,tmp->data,tmp->size); + } + else if(type==2) + { + unz_file_info ufo; + unzGetCurrentFileInfo(tz,&ufo,0,0,0,0,0,0); - tmp->size=ufo.uncompressed_size; - if(!(tmp->data=(uint8 *)FCEU_malloc(ufo.uncompressed_size))) - { - free(tmp); - tmp=0; - goto doret; - } - unzReadCurrentFile(tz,tmp->data,ufo.uncompressed_size); - } + tmp->size=ufo.uncompressed_size; + if(!(tmp->data=(uint8 *)FCEU_malloc(ufo.uncompressed_size))) + { + free(tmp); + tmp=0; + goto doret; + } + unzReadCurrentFile(tz,tmp->data,ufo.uncompressed_size); + } - doret: - if(type==0) - { - fclose((FILE *)tz); - } - else if(type==1) - { - gzclose(tz); - } - else if(type==2) - { - unzCloseCurrentFile(tz); - unzClose(tz); - } - return tmp; +doret: + if(type==0) + { + fclose((FILE *)tz); + } + else if(type==1) + { + gzclose(tz); + } + else if(type==2) + { + unzCloseCurrentFile(tz); + unzClose(tz); + } + return tmp; } #ifndef __GNUC__ - #define strcasecmp strcmp +#define strcasecmp strcmp #endif FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext) { - FILE *ipsfile=0; - FCEUFILE *fceufp; - void *t; + FILE *ipsfile=0; + FCEUFILE *fceufp; + void *t; - if(ipsfn && strchr(mode,'r')) - ipsfile=FCEUD_UTF8fopen(ipsfn,"rb"); + if(ipsfn && strchr(mode,'r')) + ipsfile=FCEUD_UTF8fopen(ipsfn,"rb"); - fceufp=(FCEUFILE *)malloc(sizeof(FCEUFILE)); + fceufp=(FCEUFILE *)malloc(sizeof(FCEUFILE)); - { - unzFile tz; - if((tz=unzOpen(path))) // If it's not a zip file, use regular file handlers. - // Assuming file type by extension usually works, - // but I don't like it. :) - { - if(unzGoToFirstFile(tz)==UNZ_OK) - { - for(;;) - { - char tempu[512]; // Longer filenames might be possible, but I don't - // think people would name files that long in zip files... - unzGetCurrentFileInfo(tz,0,tempu,512,0,0,0,0); - tempu[511]=0; - if(strlen(tempu)>=4) - { - char *za=tempu+strlen(tempu)-4; + { + unzFile tz; + if((tz=unzOpen(path))) // If it's not a zip file, use regular file handlers. + // Assuming file type by extension usually works, + // but I don't like it. :) + { + if(unzGoToFirstFile(tz)==UNZ_OK) + { + for(;;) + { + char tempu[512]; // Longer filenames might be possible, but I don't + // think people would name files that long in zip files... + unzGetCurrentFileInfo(tz,0,tempu,512,0,0,0,0); + tempu[511]=0; + if(strlen(tempu)>=4) + { + char *za=tempu+strlen(tempu)-4; - if(!ext) - { - if(!strcasecmp(za,".nes") || !strcasecmp(za,".fds") || - !strcasecmp(za,".nsf") || !strcasecmp(za,".unf") || - !strcasecmp(za,".nez")) - break; - } - else if(!strcasecmp(za,ext)) - break; - } - if(strlen(tempu)>=5) - { - if(!strcasecmp(tempu+strlen(tempu)-5,".unif")) - break; - } - if(unzGoToNextFile(tz)!=UNZ_OK) - { - if(unzGoToFirstFile(tz)!=UNZ_OK) goto zpfail; - break; - } - } - if(unzOpenCurrentFile(tz)!=UNZ_OK) - goto zpfail; - } - else - { - zpfail: - free(fceufp); - unzClose(tz); - return 0; - } - if(!(fceufp->fp=MakeMemWrap(tz,2))) - { - free(fceufp); - return(0); - } - fceufp->type=2; - if(ipsfile) - ApplyIPS(ipsfile,(MEMWRAP *)fceufp->fp); - return(fceufp); - } - } + if(!ext) + { + if(!strcasecmp(za,".nes") || !strcasecmp(za,".fds") || + !strcasecmp(za,".nsf") || !strcasecmp(za,".unf") || + !strcasecmp(za,".nez")) + break; + } + else if(!strcasecmp(za,ext)) + break; + } + if(strlen(tempu)>=5) + { + if(!strcasecmp(tempu+strlen(tempu)-5,".unif")) + break; + } + if(unzGoToNextFile(tz)!=UNZ_OK) + { + if(unzGoToFirstFile(tz)!=UNZ_OK) goto zpfail; + break; + } + } + if(unzOpenCurrentFile(tz)!=UNZ_OK) + goto zpfail; + } + else + { +zpfail: + free(fceufp); + unzClose(tz); + return 0; + } + if(!(fceufp->fp=MakeMemWrap(tz,2))) + { + free(fceufp); + return(0); + } + fceufp->type=2; + if(ipsfile) + ApplyIPS(ipsfile,(MEMWRAP *)fceufp->fp); + return(fceufp); + } + } - if((t=FCEUD_UTF8fopen(path,"rb"))) - { - uint32 magic; + if((t=FCEUD_UTF8fopen(path,"rb"))) + { + uint32 magic; - magic=fgetc((FILE *)t); - magic|=fgetc((FILE *)t)<<8; - magic|=fgetc((FILE *)t)<<16; + magic=fgetc((FILE *)t); + magic|=fgetc((FILE *)t)<<8; + magic|=fgetc((FILE *)t)<<16; - if(magic!=0x088b1f) /* Not gzip... */ - fclose((FILE *)t); - else /* Probably gzip */ - { - int fd; + if(magic!=0x088b1f) /* Not gzip... */ + fclose((FILE *)t); + else /* Probably gzip */ + { + int fd; - fd = dup(fileno( (FILE *)t)); + fd = dup(fileno( (FILE *)t)); - fclose((FILE*)t); //mbg merge 7/17/06 - cast to FILE* + fclose((FILE*)t); //mbg merge 7/17/06 - cast to FILE* - lseek(fd, 0, SEEK_SET); + lseek(fd, 0, SEEK_SET); - if((t=gzdopen(fd,mode))) - { - fceufp->type=1; - fceufp->fp=t; - if(ipsfile) - { - fceufp->fp=MakeMemWrap(t,1); - gzclose(t); + if((t=gzdopen(fd,mode))) + { + fceufp->type=1; + fceufp->fp=t; + if(ipsfile) + { + fceufp->fp=MakeMemWrap(t,1); + gzclose(t); - if(fceufp->fp) - { - free(fceufp); - return(0); - } + if(fceufp->fp) + { + free(fceufp); + return(0); + } - fceufp->type=3; - ApplyIPS(ipsfile,(MEMWRAP *)fceufp->fp); - } - return(fceufp); - } - close(fd); - } + fceufp->type=3; + ApplyIPS(ipsfile,(MEMWRAP *)fceufp->fp); + } + return(fceufp); + } + close(fd); + } - } + } - if((t=FCEUD_UTF8fopen(path,mode))) - { - fseek((FILE *)t,0,SEEK_SET); - fceufp->type=0; - fceufp->fp=t; - if(ipsfile) - { - if(!(fceufp->fp=MakeMemWrap(t,0))) - { - free(fceufp); - return(0); - } - fceufp->type=3; - ApplyIPS(ipsfile,(MEMWRAP *)fceufp->fp); - } - return(fceufp); - } + if((t=FCEUD_UTF8fopen(path,mode))) + { + fseek((FILE *)t,0,SEEK_SET); + fceufp->type=0; + fceufp->fp=t; + if(ipsfile) + { + if(!(fceufp->fp=MakeMemWrap(t,0))) + { + free(fceufp); + return(0); + } + fceufp->type=3; + ApplyIPS(ipsfile,(MEMWRAP *)fceufp->fp); + } + return(fceufp); + } - free(fceufp); - return 0; + free(fceufp); + return 0; } int FCEU_fclose(FCEUFILE *fp) { - if(fp->type==1) - { - gzclose(fp->fp); - } - else if(fp->type>=2) - { - free(((MEMWRAP*)(fp->fp))->data); - free(fp->fp); - } - else - { - fclose((FILE *)fp->fp); - } - free(fp); - return 1; + if(fp->type==1) + { + gzclose(fp->fp); + } + else if(fp->type>=2) + { + free(((MEMWRAP*)(fp->fp))->data); + free(fp->fp); + } + else + { + fclose((FILE *)fp->fp); + } + free(fp); + return 1; } uint64 FCEU_fread(void *ptr, size_t size, size_t nmemb, FCEUFILE *fp) { - if(fp->type==1) - { - return gzread(fp->fp,ptr,size*nmemb); - } - else if(fp->type>=2) - { - MEMWRAP *wz; - uint32 total=size*nmemb; + if(fp->type==1) + { + return gzread(fp->fp,ptr,size*nmemb); + } + else if(fp->type>=2) + { + MEMWRAP *wz; + uint32 total=size*nmemb; - wz=(MEMWRAP*)fp->fp; - if(wz->location>=wz->size) return 0; + wz=(MEMWRAP*)fp->fp; + if(wz->location>=wz->size) return 0; - if((wz->location+total)>wz->size) - { - int ak=wz->size-wz->location; - memcpy((uint8*)ptr,wz->data+wz->location,ak); - wz->location=wz->size; - return(ak/size); - } - else - { - memcpy((uint8*)ptr,wz->data+wz->location,total); - wz->location+=total; - return nmemb; - } - } - else - { - return fread(ptr,size,nmemb,(FILE *)fp->fp); - } + if((wz->location+total)>wz->size) + { + int ak=wz->size-wz->location; + memcpy((uint8*)ptr,wz->data+wz->location,ak); + wz->location=wz->size; + return(ak/size); + } + else + { + memcpy((uint8*)ptr,wz->data+wz->location,total); + wz->location+=total; + return nmemb; + } + } + else + { + return fread(ptr,size,nmemb,(FILE *)fp->fp); + } } uint64 FCEU_fwrite(void *ptr, size_t size, size_t nmemb, FCEUFILE *fp) { - if(fp->type==1) - { - return gzwrite(fp->fp,ptr,size*nmemb); - } - else if(fp->type>=2) - { - return 0; - } - else - return fwrite(ptr,size,nmemb,(FILE *)fp->fp); + if(fp->type==1) + { + return gzwrite(fp->fp,ptr,size*nmemb); + } + else if(fp->type>=2) + { + return 0; + } + else + return fwrite(ptr,size,nmemb,(FILE *)fp->fp); } int FCEU_fseek(FCEUFILE *fp, long offset, int whence) { - if(fp->type==1) - { - return( (gzseek(fp->fp,offset,whence)>0)?0:-1); - } - else if(fp->type>=2) - { - MEMWRAP *wz; - wz=(MEMWRAP*)fp->fp; + if(fp->type==1) + { + return( (gzseek(fp->fp,offset,whence)>0)?0:-1); + } + else if(fp->type>=2) + { + MEMWRAP *wz; + wz=(MEMWRAP*)fp->fp; - switch(whence) - { - case SEEK_SET:if(offset>=(long)wz->size) //mbg merge 7/17/06 - added cast to long - return(-1); - wz->location=offset;break; - case SEEK_CUR:if(offset+wz->location>wz->size) - return (-1); - wz->location+=offset; - break; - } - return 0; - } - else - return fseek((FILE *)fp->fp,offset,whence); + switch(whence) + { + case SEEK_SET:if(offset>=(long)wz->size) //mbg merge 7/17/06 - added cast to long + return(-1); + wz->location=offset;break; + case SEEK_CUR:if(offset+wz->location>wz->size) + return (-1); + wz->location+=offset; + break; + } + return 0; + } + else + return fseek((FILE *)fp->fp,offset,whence); } uint64 FCEU_ftell(FCEUFILE *fp) @@ -584,21 +586,16 @@ int FCEU_fisarchive(FCEUFILE *fp) -static char BaseDirectory[2048]; +static std::string BaseDirectory; char FileBase[2048]; -static char FileExt[2048]; /* Includes the . character, as in ".nes" */ +static char FileExt[2048]; //Includes the . character, as in ".nes" static char FileBaseDirectory[2048]; -/** -* Updates the base directory -**/ -void FCEUI_SetBaseDirectory(const char *dir) +/// Updates the base directory +void FCEUI_SetBaseDirectory(std::string const & dir) { - strncpy(BaseDirectory, dir, sizeof(BaseDirectory)); - - // TODO: Necessary? - BaseDirectory[2047] = 0; + BaseDirectory = dir; } static char *odirs[FCEUIOD__COUNT]={0,0,0,0,0,0,0,0,0,0,0,0}; // odirs, odors. ^_^ @@ -644,43 +641,43 @@ std::string FCEU_GetPath(int type) if(odirs[FCEUIOD_STATES]) return (odirs[FCEUIOD_STATES]); else - sprintf(ret,"%s"PSS"fcs",BaseDirectory); + return BaseDirectory + PSS + "fcs"; break; case FCEUMKF_MOVIE: if(odirs[FCEUIOD_MOVIES]) return (odirs[FCEUIOD_MOVIES]); else - sprintf(ret,"%s"PSS"movies",BaseDirectory); + return BaseDirectory + PSS + "movies"; break; case FCEUMKF_MEMW: if(odirs[FCEUIOD_MEMW]) return (odirs[FCEUIOD_MEMW]); else - sprintf(ret,"%s"PSS"tools",BaseDirectory); + return BaseDirectory + PSS + "tools"; break; case FCEUMKF_BBOT: if(odirs[FCEUIOD_BBOT]) return (odirs[FCEUIOD_BBOT]); else - sprintf(ret,"%s"PSS"tools",BaseDirectory); + return BaseDirectory + PSS + "tools"; break; case FCEUMKF_ROMS: if(odirs[FCEUIOD_ROMS]) return (odirs[FCEUIOD_ROMS]); else - sprintf(ret,"%s",BaseDirectory); + return BaseDirectory; break; case FCEUMKF_INPUT: if(odirs[FCEUIOD_INPUT]) return (odirs[FCEUIOD_INPUT]); else - sprintf(ret,"%s"PSS"tools",BaseDirectory); + return BaseDirectory + PSS + "tools"; break; case FCEUMKF_LUA: if(odirs[FCEUIOD_LUA]) return (odirs[FCEUIOD_LUA]); else - sprintf(ret,"%s"PSS"tools",BaseDirectory); + return BaseDirectory + PSS + "tools"; break; } @@ -695,15 +692,15 @@ std::string FCEU_MakePath(int type, const char* filebase) { case FCEUMKF_MOVIE: if(odirs[FCEUIOD_MOVIES]) - sprintf(ret,"%s"PSS"%s",odirs[FCEUIOD_MOVIES],filebase); + return (string)odirs[FCEUIOD_MOVIES] + PSS + filebase; else - sprintf(ret,"%s"PSS"movies"PSS"%s",BaseDirectory,filebase); + return BaseDirectory + PSS + "movies" + PSS + filebase; break; case FCEUMKF_STATE: if(odirs[FCEUIOD_STATES]) - sprintf(ret,"%s"PSS"%s",odirs[FCEUIOD_STATES],filebase); + return (string)odirs[FCEUIOD_STATES] + PSS + filebase; else - sprintf(ret,"%s"PSS"fcs"PSS"%s",BaseDirectory,filebase); + return BaseDirectory + PSS + "fcs" + PSS + filebase; break; } return ret; @@ -716,12 +713,11 @@ std::string FCEU_MakeFName(int type, int id1, char *cd1) switch(type) { - case FCEUMKF_NPTEMP: sprintf(ret,"%s"PSS"m590plqd94fo.tmp",BaseDirectory);break; case FCEUMKF_MOVIE: if(odirs[FCEUIOD_MOVIES]) sprintf(ret,"%s"PSS"%s.fm2",odirs[FCEUIOD_MOVIES],FileBase); else - sprintf(ret,"%s"PSS"movies"PSS"%s.fm2",BaseDirectory,FileBase); + sprintf(ret,"%s"PSS"movies"PSS"%s.fm2",BaseDirectory.c_str(),FileBase); break; case FCEUMKF_STATE: { @@ -741,7 +737,7 @@ std::string FCEU_MakeFName(int type, int id1, char *cd1) } else { - sprintf(ret,"%s"PSS"fcs"PSS"%s%s.fc%d",BaseDirectory,FileBase,mfn,id1); + sprintf(ret,"%s"PSS"fcs"PSS"%s%s.fc%d",BaseDirectory.c_str(),FileBase,mfn,id1); } if(stat(ret,&tmpstat)==-1) { @@ -751,7 +747,7 @@ std::string FCEU_MakeFName(int type, int id1, char *cd1) } else { - sprintf(ret,"%s"PSS"fcs"PSS"%s%s.fc%d",BaseDirectory,FileBase,mfn,id1); + sprintf(ret,"%s"PSS"fcs"PSS"%s%s.fc%d",BaseDirectory.c_str(),FileBase,mfn,id1); } } } @@ -762,33 +758,33 @@ std::string FCEU_MakeFName(int type, int id1, char *cd1) if(odirs[FCEUIOD_SNAPS]) sprintf(ret,"%s"PSS"%s-%d.%s",odirs[FCEUIOD_SNAPS],FileBase,id1,cd1); else - sprintf(ret,"%s"PSS"snaps"PSS"%s-%d.%s",BaseDirectory,FileBase,id1,cd1); + sprintf(ret,"%s"PSS"snaps"PSS"%s-%d.%s",BaseDirectory.c_str(),FileBase,id1,cd1); } else { if(odirs[FCEUIOD_SNAPS]) sprintf(ret,"%s"PSS"%d.%s",odirs[FCEUIOD_SNAPS],id1,cd1); else - sprintf(ret,"%s"PSS"snaps"PSS"%d.%s",BaseDirectory,id1,cd1); + sprintf(ret,"%s"PSS"snaps"PSS"%d.%s",BaseDirectory.c_str(),id1,cd1); } break; case FCEUMKF_FDS: if(odirs[FCEUIOD_NV]) sprintf(ret,"%s"PSS"%s.fds",odirs[FCEUIOD_NV],FileBase); else - sprintf(ret,"%s"PSS"sav"PSS"%s.fds",BaseDirectory,FileBase); + sprintf(ret,"%s"PSS"sav"PSS"%s.fds",BaseDirectory.c_str(),FileBase); break; case FCEUMKF_SAV: if(odirs[FCEUIOD_NV]) sprintf(ret,"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1); else - sprintf(ret,"%s"PSS"sav"PSS"%s.%s",BaseDirectory,FileBase,cd1); + sprintf(ret,"%s"PSS"sav"PSS"%s.%s",BaseDirectory.c_str(),FileBase,cd1); if(stat(ret,&tmpstat)==-1) { if(odirs[FCEUIOD_NV]) sprintf(ret,"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1); else - sprintf(ret,"%s"PSS"sav"PSS"%s.%s",BaseDirectory,FileBase,cd1); + sprintf(ret,"%s"PSS"sav"PSS"%s.%s",BaseDirectory.c_str(),FileBase,cd1); } break; case FCEUMKF_REWINDSTATE: @@ -798,7 +794,7 @@ std::string FCEU_MakeFName(int type, int id1, char *cd1) } else { - sprintf(ret,"%s"PSS"fcs"PSS"rewind%d.fcs",BaseDirectory,id1); + sprintf(ret,"%s"PSS"fcs"PSS"rewind%d.fcs",BaseDirectory.c_str(),id1); } if(stat(ret,&tmpstat)==-1) { @@ -808,7 +804,7 @@ std::string FCEU_MakeFName(int type, int id1, char *cd1) } else { - sprintf(ret,"%s"PSS"fcs"PSS"rewind%d.fcs",BaseDirectory,id1); + sprintf(ret,"%s"PSS"fcs"PSS"rewind%d.fcs",BaseDirectory.c_str(),id1); } } break; @@ -816,30 +812,30 @@ std::string FCEU_MakeFName(int type, int id1, char *cd1) if(odirs[FCEUIOD_CHEATS]) sprintf(ret,"%s"PSS"%s.cht",odirs[FCEUIOD_CHEATS],FileBase); else - sprintf(ret,"%s"PSS"cheats"PSS"%s.cht",BaseDirectory,FileBase); + sprintf(ret,"%s"PSS"cheats"PSS"%s.cht",BaseDirectory.c_str(),FileBase); break; case FCEUMKF_IPS:sprintf(ret,"%s"PSS"%s%s.ips",FileBaseDirectory,FileBase,FileExt);break; - case FCEUMKF_GGROM:sprintf(ret,"%s"PSS"gg.rom",BaseDirectory);break; + case FCEUMKF_GGROM:sprintf(ret,"%s"PSS"gg.rom",BaseDirectory.c_str());break; case FCEUMKF_FDSROM: if(odirs[FCEUIOD_FDSROM]) sprintf(ret,"%s"PSS"disksys.rom",odirs[FCEUIOD_FDSROM]); else - sprintf(ret,"%s"PSS"disksys.rom",BaseDirectory); + sprintf(ret,"%s"PSS"disksys.rom",BaseDirectory.c_str()); break; - case FCEUMKF_PALETTE:sprintf(ret,"%s"PSS"%s.pal",BaseDirectory,FileBase);break; + case FCEUMKF_PALETTE:sprintf(ret,"%s"PSS"%s.pal",BaseDirectory.c_str(),FileBase);break; case FCEUMKF_MOVIEGLOB: //these globs use ??? because we can load multiple formats if(odirs[FCEUIOD_MOVIES]) sprintf(ret,"%s"PSS"*.???",odirs[FCEUIOD_MOVIES]); else - sprintf(ret,"%s"PSS"movies"PSS"*.???",BaseDirectory); + sprintf(ret,"%s"PSS"movies"PSS"*.???",BaseDirectory.c_str()); break; - case FCEUMKF_MOVIEGLOB2:sprintf(ret,"%s"PSS"*.???",BaseDirectory);break; + case FCEUMKF_MOVIEGLOB2:sprintf(ret,"%s"PSS"*.???",BaseDirectory.c_str());break; case FCEUMKF_STATEGLOB: if(odirs[FCEUIOD_STATES]) sprintf(ret,"%s"PSS"%s*.fc?",odirs[FCEUIOD_STATES],FileBase); else - sprintf(ret,"%s"PSS"fcs"PSS"%s*.fc?",BaseDirectory,FileBase); + sprintf(ret,"%s"PSS"fcs"PSS"%s*.fc?",BaseDirectory.c_str(),FileBase); break; } diff --git a/src/file.h b/src/file.h index d66a2564..d56505c6 100644 --- a/src/file.h +++ b/src/file.h @@ -38,7 +38,7 @@ std::string FCEU_MakeFName(int type, int id1, char *cd1); #define FCEUMKF_IPS 8 #define FCEUMKF_FDS 9 #define FCEUMKF_MOVIE 10 -#define FCEUMKF_NPTEMP 11 +//#define FCEUMKF_NPTEMP 11 //mbg 6/21/08 - who needs this..? #define FCEUMKF_MOVIEGLOB 12 #define FCEUMKF_STATEGLOB 13 #define FCEUMKF_MOVIEGLOB2 14 diff --git a/src/netplay.cpp b/src/netplay.cpp index 9980b141..f47411e1 100644 --- a/src/netplay.cpp +++ b/src/netplay.cpp @@ -155,7 +155,6 @@ static FILE *FetchFile(uint32 remlen) uLongf len; char *buf; FILE *fp; - char *fn; if(clen > 500000) // Sanity check { @@ -164,17 +163,14 @@ static FILE *FetchFile(uint32 remlen) } //printf("Receiving file: %d...\n",clen); - fn = strdup(FCEU_MakeFName(FCEUMKF_NPTEMP,0,0).c_str()); - if((fp = fopen(fn,"w+b"))) + if(fp = tmpfile()) { cbuf = (char *)malloc(clen); //mbg merge 7/17/06 added cast if(!FCEUD_RecvData(cbuf, clen)) { NetError(); - unlink(fn); fclose(fp); free(cbuf); - free(fn); return(0); } @@ -182,10 +178,8 @@ static FILE *FetchFile(uint32 remlen) if(len > 500000) // Another sanity check { NetError(); - unlink(fn); fclose(fp); free(cbuf); - free(fn); return(0); } buf = (char *)malloc(len); //mbg merge 7/17/06 added cast @@ -194,11 +188,8 @@ static FILE *FetchFile(uint32 remlen) fwrite(buf, 1, len, fp); free(buf); fseek(fp, 0, SEEK_SET); - unlink(fn); - free(fn); return(fp); } - free(fn); return(0); } diff --git a/src/ppu.cpp b/src/ppu.cpp index 59927d46..36892565 100644 --- a/src/ppu.cpp +++ b/src/ppu.cpp @@ -1,23 +1,23 @@ /* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 1998 BERO - * Copyright (C) 2003 Xodnizel - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ +* +* Copyright notice for this file: +* Copyright (C) 1998 BERO +* Copyright (C) 2003 Xodnizel +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ #include #include @@ -40,14 +40,14 @@ #include "input.h" #include "driver.h" -#define VBlankON (PPU[0]&0x80) /* Generate VBlank NMI */ -#define Sprite16 (PPU[0]&0x20) /* Sprites 8x16/8x8 */ -#define BGAdrHI (PPU[0]&0x10) /* BG pattern adr $0000/$1000 */ -#define SpAdrHI (PPU[0]&0x08) /* Sprite pattern adr $0000/$1000 */ -#define INC32 (PPU[0]&0x04) /* auto increment 1/32 */ +#define VBlankON (PPU[0]&0x80) //Generate VBlank NMI +#define Sprite16 (PPU[0]&0x20) //Sprites 8x16/8x8 +#define BGAdrHI (PPU[0]&0x10) //BG pattern adr $0000/$1000 +#define SpAdrHI (PPU[0]&0x08) //Sprite pattern adr $0000/$1000 +#define INC32 (PPU[0]&0x04) //auto increment 1/32 -#define SpriteON (PPU[1]&0x10) /* Show Sprite */ -#define ScreenON (PPU[1]&0x08) /* Show screen */ +#define SpriteON (PPU[1]&0x10) //Show Sprite +#define ScreenON (PPU[1]&0x08) //Show screen #define PPU_status (PPU[2]) @@ -73,21 +73,21 @@ static void makeppulut(void) for(x=0;x<256;x++) { ppulut1[x] = 0; - + for(y=0;y<8;y++) { ppulut1[x] |= ((x>>(7-y))&1)<<(y*4); } ppulut2[x] = ppulut1[x] << 1; - } + } for(cc=0;cc<16;cc++) { for(xo=0;xo<8;xo++) { ppulut3[ xo | ( cc << 3 ) ] = 0; - + for(pixel=0;pixel<8;pixel++) { int shiftr; @@ -99,7 +99,7 @@ static void makeppulut(void) } } } - + static int ppudead=1; static int kook=0; int fceuindbg=0; @@ -119,7 +119,7 @@ uint8 *vnapage[4]; uint8 PPUNTARAM=0; uint8 PPUCHRRAM=0; -/* Color deemphasis emulation. Joy... */ +//Color deemphasis emulation. Joy... static uint8 deemp=0; static int deempcnt[8]; @@ -128,16 +128,15 @@ void (*PPU_hook)(uint32 A); uint8 vtoggle=0; uint8 XOffset=0; - + uint32 TempAddr=0,RefreshAddr=0; - + static int maxsprites=8; - -/* scanline is equal to the current visible scanline we're on. */ - + +//scanline is equal to the current visible scanline we're on. int scanline; static uint32 scanlines_per_frame; - + uint8 PPU[4]; uint8 PPUSPL; uint8 NTARAM[0x800],PALRAM[0x20],SPRAM[0x100],SPRBUF[0x100]; @@ -150,227 +149,227 @@ uint8 NTARAM[0x800],PALRAM[0x20],SPRAM[0x100],SPRBUF[0x100]; static DECLFR(A2002) { - uint8 ret; - - FCEUPPU_LineUpdate(); - ret = PPU_status; - ret|=PPUGenLatch&0x1F; + uint8 ret; - #ifdef FCEUDEF_DEBUGGER - if(!fceuindbg) - #endif - { - vtoggle=0; - PPU_status&=0x7F; - PPUGenLatch=ret; - } - return ret; + FCEUPPU_LineUpdate(); + ret = PPU_status; + ret|=PPUGenLatch&0x1F; + +#ifdef FCEUDEF_DEBUGGER + if(!fceuindbg) +#endif + { + vtoggle=0; + PPU_status&=0x7F; + PPUGenLatch=ret; + } + return ret; } static DECLFR(A200x) /* Not correct for $2004 reads. */ { - FCEUPPU_LineUpdate(); - return PPUGenLatch; + FCEUPPU_LineUpdate(); + return PPUGenLatch; } /* static DECLFR(A2004) { - uint8 ret; +uint8 ret; - FCEUPPU_LineUpdate(); - ret = SPRAM[PPU[3]]; +FCEUPPU_LineUpdate(); +ret = SPRAM[PPU[3]]; - if(PPUSPL>=8) - { - if(PPU[3]>=8) - ret = SPRAM[PPU[3]]; - } - else - { - //printf("$%02x:$%02x\n",PPUSPL,V); - ret = SPRAM[PPUSPL]; - } - PPU[3]++; - PPUSPL++; - PPUGenLatch = ret; - printf("%d, %02x\n",scanline,ret); - return(ret); +if(PPUSPL>=8) +{ +if(PPU[3]>=8) +ret = SPRAM[PPU[3]]; +} +else +{ +//printf("$%02x:$%02x\n",PPUSPL,V); +ret = SPRAM[PPUSPL]; +} +PPU[3]++; +PPUSPL++; +PPUGenLatch = ret; +printf("%d, %02x\n",scanline,ret); +return(ret); } */ static DECLFR(A2007) { - uint8 ret; - uint32 tmp=RefreshAddr&0x3FFF; + uint8 ret; + uint32 tmp=RefreshAddr&0x3FFF; - FCEUPPU_LineUpdate(); - - ret=VRAMBuffer; + FCEUPPU_LineUpdate(); - #ifdef FCEUDEF_DEBUGGER - if(!fceuindbg) - #endif - { - if(PPU_hook) PPU_hook(tmp); - PPUGenLatch=VRAMBuffer; - if(tmp<0x2000) - { - VRAMBuffer=VPage[tmp>>10][tmp]; - } - else - { - VRAMBuffer=vnapage[(tmp>>10)&0x3][tmp&0x3FF]; - } - } - #ifdef FCEUDEF_DEBUGGER - if(!fceuindbg) - #endif - { - if(INC32) RefreshAddr+=32; - else RefreshAddr++; - if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); - } - return ret; + ret=VRAMBuffer; + +#ifdef FCEUDEF_DEBUGGER + if(!fceuindbg) +#endif + { + if(PPU_hook) PPU_hook(tmp); + PPUGenLatch=VRAMBuffer; + if(tmp<0x2000) + { + VRAMBuffer=VPage[tmp>>10][tmp]; + } + else + { + VRAMBuffer=vnapage[(tmp>>10)&0x3][tmp&0x3FF]; + } + } +#ifdef FCEUDEF_DEBUGGER + if(!fceuindbg) +#endif + { + if(INC32) RefreshAddr+=32; + else RefreshAddr++; + if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); + } + return ret; } static DECLFW(B2000) { -// FCEU_printf("%04x:%02x, (%d) %02x, %02x\n",A,V,scanline,PPU[0],PPU_status); + // FCEU_printf("%04x:%02x, (%d) %02x, %02x\n",A,V,scanline,PPU[0],PPU_status); - FCEUPPU_LineUpdate(); - PPUGenLatch=V; - if(!(PPU[0]&0x80) && (V&0x80) && (PPU_status&0x80)) - { -// FCEU_printf("Trigger NMI, %d, %d\n",timestamp,ppudead); - TriggerNMI2(); - } - PPU[0]=V; - TempAddr&=0xF3FF; - TempAddr|=(V&3)<<10; + FCEUPPU_LineUpdate(); + PPUGenLatch=V; + if(!(PPU[0]&0x80) && (V&0x80) && (PPU_status&0x80)) + { + // FCEU_printf("Trigger NMI, %d, %d\n",timestamp,ppudead); + TriggerNMI2(); + } + PPU[0]=V; + TempAddr&=0xF3FF; + TempAddr|=(V&3)<<10; } static DECLFW(B2001) { - //printf("%04x:$%02x, %d\n",A,V,scanline); - FCEUPPU_LineUpdate(); - PPUGenLatch=V; - PPU[1]=V; - if(V&0xE0) - deemp=V>>5; + //printf("%04x:$%02x, %d\n",A,V,scanline); + FCEUPPU_LineUpdate(); + PPUGenLatch=V; + PPU[1]=V; + if(V&0xE0) + deemp=V>>5; } - + static DECLFW(B2002) { - PPUGenLatch=V; + PPUGenLatch=V; } static DECLFW(B2003) { - //printf("$%04x:$%02x, %d, %d\n",A,V,timestamp,scanline); - PPUGenLatch=V; - PPU[3]=V; - PPUSPL=V&0x7; + //printf("$%04x:$%02x, %d, %d\n",A,V,timestamp,scanline); + PPUGenLatch=V; + PPU[3]=V; + PPUSPL=V&0x7; } - + static DECLFW(B2004) { - //printf("Wr: %04x:$%02x\n",A,V); + //printf("Wr: %04x:$%02x\n",A,V); - PPUGenLatch=V; - if(PPUSPL>=8) - { - if(PPU[3]>=8) - SPRAM[PPU[3]]=V; - } - else - { - //printf("$%02x:$%02x\n",PPUSPL,V); - SPRAM[PPUSPL]=V; - } - PPU[3]++; - PPUSPL++; + PPUGenLatch=V; + if(PPUSPL>=8) + { + if(PPU[3]>=8) + SPRAM[PPU[3]]=V; + } + else + { + //printf("$%02x:$%02x\n",PPUSPL,V); + SPRAM[PPUSPL]=V; + } + PPU[3]++; + PPUSPL++; } - + static DECLFW(B2005) { - uint32 tmp=TempAddr; - FCEUPPU_LineUpdate(); - PPUGenLatch=V; - if(!vtoggle) - { - tmp&=0xFFE0; - tmp|=V>>3; - XOffset=V&7; - } - else - { - tmp&=0x8C1F; - tmp|=((V&~0x7)<<2); - tmp|=(V&7)<<12; - } - TempAddr=tmp; - vtoggle^=1; + uint32 tmp=TempAddr; + FCEUPPU_LineUpdate(); + PPUGenLatch=V; + if(!vtoggle) + { + tmp&=0xFFE0; + tmp|=V>>3; + XOffset=V&7; + } + else + { + tmp&=0x8C1F; + tmp|=((V&~0x7)<<2); + tmp|=(V&7)<<12; + } + TempAddr=tmp; + vtoggle^=1; } static DECLFW(B2006) { - FCEUPPU_LineUpdate(); + FCEUPPU_LineUpdate(); - PPUGenLatch=V; - if(!vtoggle) - { - TempAddr&=0x00FF; - TempAddr|=(V&0x3f)<<8; - } - else - { - TempAddr&=0xFF00; - TempAddr|=V; + PPUGenLatch=V; + if(!vtoggle) + { + TempAddr&=0x00FF; + TempAddr|=(V&0x3f)<<8; + } + else + { + TempAddr&=0xFF00; + TempAddr|=V; - RefreshAddr=TempAddr; - if(PPU_hook) - PPU_hook(RefreshAddr); - //printf("%d, %04x\n",scanline,RefreshAddr); - } - vtoggle^=1; + RefreshAddr=TempAddr; + if(PPU_hook) + PPU_hook(RefreshAddr); + //printf("%d, %04x\n",scanline,RefreshAddr); + } + vtoggle^=1; } - + static DECLFW(B2007) { - uint32 tmp=RefreshAddr&0x3FFF; - PPUGenLatch=V; - if(tmp>=0x3F00) - { - // hmmm.... - if(!(tmp&0xf)) - PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]=V&0x3F; - else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f; - } - else if(tmp<0x2000) - { - if(PPUCHRRAM&(1<<(tmp>>10))) - VPage[tmp>>10][tmp]=V; - } - else - { - if(PPUNTARAM&(1<<((tmp&0xF00)>>10))) - vnapage[((tmp&0xF00)>>10)][tmp&0x3FF]=V; - } -// FCEU_printf("ppu (%04x) %04x:%04x %d, %d\n",X.PC,RefreshAddr,PPUGenLatch,scanline,timestamp); - if(INC32) RefreshAddr+=32; - else RefreshAddr++; - if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); + uint32 tmp=RefreshAddr&0x3FFF; + PPUGenLatch=V; + if(tmp>=0x3F00) + { + // hmmm.... + if(!(tmp&0xf)) + PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]=V&0x3F; + else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f; + } + else if(tmp<0x2000) + { + if(PPUCHRRAM&(1<<(tmp>>10))) + VPage[tmp>>10][tmp]=V; + } + else + { + if(PPUNTARAM&(1<<((tmp&0xF00)>>10))) + vnapage[((tmp&0xF00)>>10)][tmp&0x3FF]=V; + } + // FCEU_printf("ppu (%04x) %04x:%04x %d, %d\n",X.PC,RefreshAddr,PPUGenLatch,scanline,timestamp); + if(INC32) RefreshAddr+=32; + else RefreshAddr++; + if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); } - + static DECLFW(B4014) { - uint32 t=V<<8; - int x; + uint32 t=V<<8; + int x; - for(x=0;x<256;x++) - X6502_DMW(0x2004,X6502_DMR(t+x)); + for(x=0;x<256;x++) + X6502_DMW(0x2004,X6502_DMR(t+x)); } #define PAL(c) ((c)+cc) @@ -399,429 +398,427 @@ static uint8 sprlinebuf[256+8]; void FCEUPPU_LineUpdate(void) { - #ifdef FCEUDEF_DEBUGGER - if(!fceuindbg) - #endif - if(Pline) - { - int l=GETLASTPIXEL; - RefreshLine(l); - } +#ifdef FCEUDEF_DEBUGGER + if(!fceuindbg) +#endif + if(Pline) + { + int l=GETLASTPIXEL; + RefreshLine(l); + } } - -static int tileview=0; -static int rendis = 0; -void FCEUI_ToggleTileView(void) +static bool rendersprites=true, renderbg=true; + +void FCEUI_SetRenderPlanes(bool sprites, bool bg) { - tileview^=1; + rendersprites = sprites; + renderbg = bg; } -void FCEUI_SetRenderDisable(int sprites, int bg) +void FCEUI_GetRenderPlanes(bool& sprites, bool& bg) { - //printf("%d, %d\n",sprites,bg); - if(sprites >= 0) - { - if(sprites == 2) rendis ^= 1; - else rendis = (rendis &~1) | sprites?1:0; - } - if(bg >= 0) - { - if(bg == 2) rendis ^= 2; - else rendis = (rendis &~2) | bg?2:0; - } + sprites = rendersprites; + bg = renderbg; } -/* -static void TileView(void) -{ - uint8 *P=XBuf+16*256; - int bgh; - int y; - int X1; - for(bgh=0;bgh<2;bgh++) - for(y=0;y<16*8;y++) - for(P=XBuf+bgh*128+(16+y)*256,X1=16;X1;X1--,P+=8) - { - uint8 *C; - register uint8 cc; - uint32 vadr; - - vadr=((((16-X1)|((y>>3)<<4))<<4)|(y&7))+bgh*0x1000; - //C= ROM+vadr+turt*8192; - C = VRAMADR(vadr); - //if((vadr+turt*8192)>=524288) - //printf("%d ",vadr+turt*8192); - cc=0; - //#include "pputile.h" - } -} -*/ + +//mbg 6/21/08 - tileview is being ripped out since i dont know how long its been since it worked +//static int tileview=1; +//void FCEUI_ToggleTileView(void) +//{ +// tileview^=1; +//} + + +//mbg 6/21/08 - tileview is being ripped out since i dont know how long its been since it worked +//static void TileView(void) +//{ +// uint8 *P=XBuf+16*256; +// int bgh; +// int y; +// int X1; +// for(bgh=0;bgh<2;bgh++) +// for(y=0;y<16*8;y++) +// for(P=XBuf+bgh*128+(16+y)*256,X1=16;X1;X1--,P+=8) +// { +// uint8 *C; +// register uint8 cc; +// uint32 vadr; +// +// vadr=((((16-X1)|((y>>3)<<4))<<4)|(y&7))+bgh*0x1000; +// //C= ROM+vadr+turt*8192; +// C = VRAMADR(vadr); +// //if((vadr+turt*8192)>=524288) +// //printf("%d ",vadr+turt*8192); +// cc=0; +// //#include "pputile.h" +// } +//} + static void CheckSpriteHit(int p); static void EndRL(void) { - RefreshLine(272); - if(tofix) - Fixit1(); - CheckSpriteHit(272); - Pline=0; + RefreshLine(272); + if(tofix) + Fixit1(); + CheckSpriteHit(272); + Pline=0; } - + static int32 sphitx; static uint8 sphitdata; static void CheckSpriteHit(int p) { - int l=p-16; - int x; - - if(sphitx==0x100) return; + int l=p-16; + int x; - for(x=sphitx;x<(sphitx+8) && x>(x-sphitx))) && !(Plinef[x]&64)) - { - PPU_status|=0x40; - //printf("Ha: %d, %d, Hita: %d, %d, %d, %d, %d\n",p,p&~7,scanline,GETLASTPIXEL-16,&Plinef[x],Pline,Pline-Plinef); - //printf("%d\n",GETLASTPIXEL-16); - //if(Plinef[x] == 0xFF) - //printf("PL: %d, %02x\n",scanline, Plinef[x]); - sphitx=0x100; - break; - } - } + if(sphitx==0x100) return; + + for(x=sphitx;x<(sphitx+8) && x>(x-sphitx))) && !(Plinef[x]&64)) + { + PPU_status|=0x40; + //printf("Ha: %d, %d, Hita: %d, %d, %d, %d, %d\n",p,p&~7,scanline,GETLASTPIXEL-16,&Plinef[x],Pline,Pline-Plinef); + //printf("%d\n",GETLASTPIXEL-16); + //if(Plinef[x] == 0xFF) + //printf("PL: %d, %02x\n",scanline, Plinef[x]); + sphitx=0x100; + break; + } + } } -static int spork=0; /* spork the world. Any sprites on this line? - Then this will be set to 1. Needed for zapper - emulation and *gasp* sprite emulation. - */ - + +//spork the world. Any sprites on this line? Then this will be set to 1. +//Needed for zapper emulation and *gasp* sprite emulation. +static int spork=0; + // lasttile is really "second to last tile." static void RefreshLine(int lastpixel) { - static uint32 pshift[2]; - static uint32 atlatch; - uint32 smorkus=RefreshAddr; + static uint32 pshift[2]; + static uint32 atlatch; + uint32 smorkus=RefreshAddr; - #define RefreshAddr smorkus - uint32 vofs; - int X1; +#define RefreshAddr smorkus + uint32 vofs; + int X1; - register uint8 *P=Pline; - int lasttile=lastpixel>>3; - int numtiles; - static int norecurse=0; /* Yeah, recursion would be bad. - PPU_hook() functions can call - mirroring/chr bank switching functions, - which call FCEUPPU_LineUpdate, which call this - function. */ - if(norecurse) return; + register uint8 *P=Pline; + int lasttile=lastpixel>>3; + int numtiles; + static int norecurse=0; /* Yeah, recursion would be bad. + PPU_hook() functions can call + mirroring/chr bank switching functions, + which call FCEUPPU_LineUpdate, which call this + function. */ + if(norecurse) return; if(sphitx != 0x100 && !(PPU_status&0x40)) - { - if((sphitx < (lastpixel-16)) && !(sphitx < ((lasttile - 2)*8))) - { - //printf("OK: %d\n",scanline); - lasttile++; - } + { + if((sphitx < (lastpixel-16)) && !(sphitx < ((lasttile - 2)*8))) + { + //printf("OK: %d\n",scanline); + lasttile++; + } - } + } + + if(lasttile>34) lasttile=34; + numtiles=lasttile-firsttile; - if(lasttile>34) lasttile=34; - numtiles=lasttile-firsttile; - if(numtiles<=0) return; - P=Pline; - - vofs=0; - - vofs=((PPU[0]&0x10)<<8) | ((RefreshAddr>>12)&7); - - if(!ScreenON && !SpriteON) - { - uint32 tem; - tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24); - tem|=0x40404040; - FCEU_dwmemset(Pline,tem,numtiles*8); - P+=numtiles*8; - Pline=P; - - firsttile=lasttile; + P=Pline; - #define TOFIXNUM (272-0x4) - if(lastpixel>=TOFIXNUM && tofix) - { - Fixit1(); - tofix=0; - } + vofs=0; - if((lastpixel-16)>=0) - { - InputScanlineHook(Plinef,spork?sprlinebuf:0,linestartts,lasttile*8-16); - } - return; - } + vofs=((PPU[0]&0x10)<<8) | ((RefreshAddr>>12)&7); - /* Priority bits, needed for sprite emulation. */ - Pal[0]|=64; - Pal[4]|=64; - Pal[8]|=64; - Pal[0xC]|=64; + if(!ScreenON && !SpriteON) + { + uint32 tem; + tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24); + tem|=0x40404040; + FCEU_dwmemset(Pline,tem,numtiles*8); + P+=numtiles*8; + Pline=P; - /* This high-level graphics MMC5 emulation code was written - for MMC5 carts in "CL" mode. It's probably not totally - correct for carts in "SL" mode. - */ + firsttile=lasttile; - #define PPUT_MMC5 - if(MMC5Hack && geniestage!=1) - { - if(MMC5HackCHRMode==0 && (MMC5HackSPMode&0x80)) - { - int tochange=MMC5HackSPMode&0x1F; - tochange-=firsttile; - for(X1=firsttile;X10 && !(MMC5HackSPMode&0x40))) - { - #define PPUT_MMC5SP - #include "pputile.h" - #undef PPUT_MMC5SP - } - else - { - #include "pputile.h" - } - tochange--; - } - } - else if(MMC5HackCHRMode==1 && (MMC5HackSPMode&0x80)) - { - int tochange=MMC5HackSPMode&0x1F; - tochange-=firsttile; +#define TOFIXNUM (272-0x4) + if(lastpixel>=TOFIXNUM && tofix) + { + Fixit1(); + tofix=0; + } - #define PPUT_MMC5SP - #define PPUT_MMC5CHR1 - for(X1=firsttile;X1=0) + { + InputScanlineHook(Plinef,spork?sprlinebuf:0,linestartts,lasttile*8-16); + } + return; } - #undef PPUT_MMC5 + + //Priority bits, needed for sprite emulation. + Pal[0]|=64; + Pal[4]|=64; + Pal[8]|=64; + Pal[0xC]|=64; + + //This high-level graphics MMC5 emulation code was written for MMC5 carts in "CL" mode. + //It's probably not totally correct for carts in "SL" mode. + +#define PPUT_MMC5 + if(MMC5Hack && geniestage!=1) + { + if(MMC5HackCHRMode==0 && (MMC5HackSPMode&0x80)) + { + int tochange=MMC5HackSPMode&0x1F; + tochange-=firsttile; + for(X1=firsttile;X10 && !(MMC5HackSPMode&0x40))) + { +#define PPUT_MMC5SP +#include "pputile.h" +#undef PPUT_MMC5SP + } + else + { +#include "pputile.h" + } + tochange--; + } + } + else if(MMC5HackCHRMode==1 && (MMC5HackSPMode&0x80)) + { + int tochange=MMC5HackSPMode&0x1F; + tochange-=firsttile; + +#define PPUT_MMC5SP +#define PPUT_MMC5CHR1 + for(X1=firsttile;X10) - FCEU_dwmemset(Plinef+tstart*8,tem,tcount*8); + uint32 tem; + int tstart,tcount; + tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24); + tem|=0x40404040; + + tcount=lasttile-firsttile; + tstart=firsttile-2; + if(tstart<0) + { + tcount+=tstart; + tstart=0; + } + if(tcount>0) + FCEU_dwmemset(Plinef+tstart*8,tem,tcount*8); } - if(lastpixel>=TOFIXNUM && tofix) - { - //puts("Fixed"); - Fixit1(); - tofix=0; - } + if(lastpixel>=TOFIXNUM && tofix) + { + //puts("Fixed"); + Fixit1(); + tofix=0; + } - //CheckSpriteHit(lasttile*8); //lasttile*8); //lastpixel); + //CheckSpriteHit(lasttile*8); //lasttile*8); //lastpixel); + + //This only works right because of a hack earlier in this function. + CheckSpriteHit(lastpixel); - CheckSpriteHit(lastpixel); /* This only works right because - of a hack earlier in this function. - */ - if((lastpixel-16)>=0) - { - InputScanlineHook(Plinef,spork?sprlinebuf:0,linestartts,lasttile*8-16); - } - Pline=P; - firsttile=lasttile; + if((lastpixel-16)>=0) + { + InputScanlineHook(Plinef,spork?sprlinebuf:0,linestartts,lasttile*8-16); + } + Pline=P; + firsttile=lasttile; } static INLINE void Fixit2(void) { - if(ScreenON || SpriteON) - { - uint32 rad=RefreshAddr; - rad&=0xFBE0; - rad|=TempAddr&0x041f; - RefreshAddr=rad; - //PPU_hook(RefreshAddr); - //PPU_hook(RefreshAddr,-1); - } + if(ScreenON || SpriteON) + { + uint32 rad=RefreshAddr; + rad&=0xFBE0; + rad|=TempAddr&0x041f; + RefreshAddr=rad; + //PPU_hook(RefreshAddr); + //PPU_hook(RefreshAddr,-1); + } } static void Fixit1(void) { - if(ScreenON || SpriteON) - { - uint32 rad=RefreshAddr; + if(ScreenON || SpriteON) + { + uint32 rad=RefreshAddr; - if((rad&0x7000)==0x7000) - { - rad^=0x7000; - if((rad&0x3E0)==0x3A0) - { - rad^=0x3A0; - rad^=0x800; - } - else - { - if((rad&0x3E0)==0x3e0) - rad^=0x3e0; - else rad+=0x20; - } - } - else - rad+=0x1000; - RefreshAddr=rad; - //PPU_hook(RefreshAddr); //,-1); - } + if((rad&0x7000)==0x7000) + { + rad^=0x7000; + if((rad&0x3E0)==0x3A0) + { + rad^=0x3A0; + rad^=0x800; + } + else + { + if((rad&0x3E0)==0x3e0) + rad^=0x3e0; + else rad+=0x20; + } + } + else + rad+=0x1000; + RefreshAddr=rad; + //PPU_hook(RefreshAddr); //,-1); + } } -void MMC5_hb(int); /* Ugh ugh ugh. */ +void MMC5_hb(int); //Ugh ugh ugh. static void DoLine(void) { - int x; - uint8 *target=XBuf+(scanline<<8); + int x; + uint8 *target=XBuf+(scanline<<8); - if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline); + if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline); - X6502_Run(256); - EndRL(); + X6502_Run(256); + EndRL(); - if(rendis & 2) /* User asked to not display background data. */ - { - uint32 tem; - tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24); - tem|=0x40404040; - FCEU_dwmemset(target,tem,256); - } + if(!renderbg) // User asked to not display background data. + { + uint32 tem; + tem=Pal[0]|(Pal[0]<<8)|(Pal[0]<<16)|(Pal[0]<<24); + tem|=0x40404040; + FCEU_dwmemset(target,tem,256); + } - if(SpriteON) - CopySprites(target); + if(SpriteON) + CopySprites(target); - if(ScreenON || SpriteON) // Yes, very el-cheapo. - { - if(PPU[1]&0x01) - { - for(x=63;x>=0;x--) - *(uint32 *)&target[x<<2]=(*(uint32*)&target[x<<2])&0x30303030; - } - } - if((PPU[1]>>5)==0x7) - { - for(x=63;x>=0;x--) - *(uint32 *)&target[x<<2]=((*(uint32*)&target[x<<2])&0x3f3f3f3f)|0xc0c0c0c0; - } - else if(PPU[1]&0xE0) - for(x=63;x>=0;x--) - *(uint32 *)&target[x<<2]=(*(uint32*)&target[x<<2])|0x40404040; - else - for(x=63;x>=0;x--) - *(uint32 *)&target[x<<2]=((*(uint32*)&target[x<<2])&0x3f3f3f3f)|0x80808080; + if(ScreenON || SpriteON) // Yes, very el-cheapo. + { + if(PPU[1]&0x01) + { + for(x=63;x>=0;x--) + *(uint32 *)&target[x<<2]=(*(uint32*)&target[x<<2])&0x30303030; + } + } + if((PPU[1]>>5)==0x7) + { + for(x=63;x>=0;x--) + *(uint32 *)&target[x<<2]=((*(uint32*)&target[x<<2])&0x3f3f3f3f)|0xc0c0c0c0; + } + else if(PPU[1]&0xE0) + for(x=63;x>=0;x--) + *(uint32 *)&target[x<<2]=(*(uint32*)&target[x<<2])|0x40404040; + else + for(x=63;x>=0;x--) + *(uint32 *)&target[x<<2]=((*(uint32*)&target[x<<2])&0x3f3f3f3f)|0x80808080; - sphitx=0x100; + sphitx=0x100; - if(ScreenON || SpriteON) - FetchSpriteData(); + if(ScreenON || SpriteON) + FetchSpriteData(); - if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18)) - { - X6502_Run(6); - Fixit2(); - X6502_Run(4); - GameHBIRQHook(); - X6502_Run(85-16-10); - } - else - { - X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others) - Fixit2(); - X6502_Run(85-6-16); + if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18)) + { + X6502_Run(6); + Fixit2(); + X6502_Run(4); + GameHBIRQHook(); + X6502_Run(85-16-10); + } + else + { + X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others) + Fixit2(); + X6502_Run(85-6-16); - // A semi-hack for Star Trek: 25th Anniversary - if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18)) - GameHBIRQHook(); - } + // A semi-hack for Star Trek: 25th Anniversary + if(GameHBIRQHook && (ScreenON || SpriteON) && ((PPU[0]&0x38)!=0x18)) + GameHBIRQHook(); + } - DEBUG(FCEUD_UpdateNTView(scanline,0)); + DEBUG(FCEUD_UpdateNTView(scanline,0)); - if(SpriteON) - RefreshSprites(); - if(GameHBIRQHook2 && (ScreenON || SpriteON)) - GameHBIRQHook2(); - scanline++; - if(scanline<240) - { - ResetRL(XBuf+(scanline<<8)); - } - X6502_Run(16); + if(SpriteON) + RefreshSprites(); + if(GameHBIRQHook2 && (ScreenON || SpriteON)) + GameHBIRQHook2(); + scanline++; + if(scanline<240) + { + ResetRL(XBuf+(scanline<<8)); + } + X6502_Run(16); } #define V_FLIP 0x80 @@ -829,389 +826,388 @@ static void DoLine(void) #define SP_BACK 0x20 typedef struct { - uint8 y,no,atr,x; + uint8 y,no,atr,x; } SPR; typedef struct { - uint8 ca[2],atr,x; + uint8 ca[2],atr,x; } SPRB; void FCEUI_DisableSpriteLimitation(int a) { - maxsprites=a?64:8; + maxsprites=a?64:8; } static uint8 numsprites,SpriteBlurp; static void FetchSpriteData(void) { - uint8 ns,sb; - SPR *spr; - uint8 H; + uint8 ns,sb; + SPR *spr; + uint8 H; int n; int vofs; - uint8 P0=PPU[0]; + uint8 P0=PPU[0]; - spr=(SPR *)SPRAM; - H=8; + spr=(SPR *)SPRAM; + H=8; - ns=sb=0; + ns=sb=0; - vofs=(unsigned int)(P0&0x8&(((P0&0x20)^0x20)>>2))<<9; - H+=(P0&0x20)>>2; + vofs=(unsigned int)(P0&0x8&(((P0&0x20)^0x20)>>2))<<9; + H+=(P0&0x20)>>2; - if(!PPU_hook) - for(n=63;n>=0;n--,spr++) - { - if((unsigned int)(scanline-spr->y)>=H) continue; - //printf("%d, %u\n",scanline,(unsigned int)(scanline-spr->y)); - if(ns=0;n--,spr++) + { + if((unsigned int)(scanline-spr->y)>=H) continue; + //printf("%d, %u\n",scanline,(unsigned int)(scanline-spr->y)); + if(nsy); + t = (int)scanline-(spr->y); - if(Sprite16) - vadr = ((spr->no&1)<<12) + ((spr->no&0xFE)<<4); - else - vadr = (spr->no<<4)+vofs; + if(Sprite16) + vadr = ((spr->no&1)<<12) + ((spr->no&0xFE)<<4); + else + vadr = (spr->no<<4)+vofs; - if(spr->atr&V_FLIP) - { - vadr+=7; - vadr-=t; - vadr+=(P0&0x20)>>1; - vadr-=t&8; - } - else - { - vadr+=t; - vadr+=t&8; - } + if(spr->atr&V_FLIP) + { + vadr+=7; + vadr-=t; + vadr+=(P0&0x20)>>1; + vadr-=t&8; + } + else + { + vadr+=t; + vadr+=t&8; + } - /* Fix this geniestage hack */ - if(MMC5Hack && geniestage!=1) C = MMC5SPRVRAMADR(vadr); - else C = VRAMADR(vadr); - - - dst.ca[0]=C[0]; - dst.ca[1]=C[8]; - dst.x=spr->x; - dst.atr=spr->atr; - - *(uint32 *)&SPRBUF[ns<<2]=*(uint32 *)&dst; - } - - ns++; - } - else - { - PPU_status|=0x20; - break; - } - } - else - for(n=63;n>=0;n--,spr++) - { - if((unsigned int)(scanline-spr->y)>=H) continue; - - if(nsy); - - if(Sprite16) - vadr = ((spr->no&1)<<12) + ((spr->no&0xFE)<<4); - else - vadr = (spr->no<<4)+vofs; - - if(spr->atr&V_FLIP) - { - vadr+=7; - vadr-=t; - vadr+=(P0&0x20)>>1; - vadr-=t&8; - } - else - { - vadr+=t; - vadr+=t&8; - } - - if(MMC5Hack) C = MMC5SPRVRAMADR(vadr); - else C = VRAMADR(vadr); - dst.ca[0]=C[0]; - if(ns<8) - { - PPU_hook(0x2000); - PPU_hook(vadr); - } - dst.ca[1]=C[8]; - dst.x=spr->x; - dst.atr=spr->atr; + /* Fix this geniestage hack */ + if(MMC5Hack && geniestage!=1) C = MMC5SPRVRAMADR(vadr); + else C = VRAMADR(vadr); - *(uint32 *)&SPRBUF[ns<<2]=*(uint32 *)&dst; - } + dst.ca[0]=C[0]; + dst.ca[1]=C[8]; + dst.x=spr->x; + dst.atr=spr->atr; - ns++; - } - else - { - PPU_status|=0x20; - break; - } - } - //if(ns>=7) - //printf("%d %d\n",scanline,ns); - if(ns>8) PPU_status|=0x20; /* Handle case when >8 sprites per - scanline option is enabled. */ - else if(PPU_hook) - { - for(n=0;n<(8-ns);n++) - { - PPU_hook(0x2000); - PPU_hook(vofs); - } - } - numsprites=ns; - SpriteBlurp=sb; + *(uint32 *)&SPRBUF[ns<<2]=*(uint32 *)&dst; + } + + ns++; + } + else + { + PPU_status|=0x20; + break; + } + } + else + for(n=63;n>=0;n--,spr++) + { + if((unsigned int)(scanline-spr->y)>=H) continue; + + if(nsy); + + if(Sprite16) + vadr = ((spr->no&1)<<12) + ((spr->no&0xFE)<<4); + else + vadr = (spr->no<<4)+vofs; + + if(spr->atr&V_FLIP) + { + vadr+=7; + vadr-=t; + vadr+=(P0&0x20)>>1; + vadr-=t&8; + } + else + { + vadr+=t; + vadr+=t&8; + } + + if(MMC5Hack) C = MMC5SPRVRAMADR(vadr); + else C = VRAMADR(vadr); + dst.ca[0]=C[0]; + if(ns<8) + { + PPU_hook(0x2000); + PPU_hook(vadr); + } + dst.ca[1]=C[8]; + dst.x=spr->x; + dst.atr=spr->atr; + + + *(uint32 *)&SPRBUF[ns<<2]=*(uint32 *)&dst; + } + + ns++; + } + else + { + PPU_status|=0x20; + break; + } + } + //if(ns>=7) + //printf("%d %d\n",scanline,ns); + + //Handle case when >8 sprites per scanline option is enabled. + if(ns>8) PPU_status|=0x20; + else if(PPU_hook) + { + for(n=0;n<(8-ns);n++) + { + PPU_hook(0x2000); + PPU_hook(vofs); + } + } + numsprites=ns; + SpriteBlurp=sb; } static void RefreshSprites(void) { - int n; - SPRB *spr; + int n; + SPRB *spr; - spork=0; - if(!numsprites) return; + spork=0; + if(!numsprites) return; - FCEU_dwmemset(sprlinebuf,0x80808080,256); - numsprites--; - spr = (SPRB*)SPRBUF+numsprites; + FCEU_dwmemset(sprlinebuf,0x80808080,256); + numsprites--; + spr = (SPRB*)SPRBUF+numsprites; - for(n=numsprites;n>=0;n--,spr--) - { - uint32 pixdata; - uint8 J,atr; + for(n=numsprites;n>=0;n--,spr--) + { + uint32 pixdata; + uint8 J,atr; - int x=spr->x; - uint8 *C; - uint8 *VB; - - pixdata=ppulut1[spr->ca[0]]|ppulut2[spr->ca[1]]; - J=spr->ca[0]|spr->ca[1]; - atr=spr->atr; + int x=spr->x; + uint8 *C; + uint8 *VB; - if(J) - { - if(n==0 && SpriteBlurp && !(PPU_status&0x40)) - { - sphitx=x; - sphitdata=J; - if(atr&H_FLIP) - sphitdata= ((J<<7)&0x80) | - ((J<<5)&0x40) | - ((J<<3)&0x20) | - ((J<<1)&0x10) | - ((J>>1)&0x08) | - ((J>>3)&0x04) | - ((J>>5)&0x02) | - ((J>>7)&0x01); - } + pixdata=ppulut1[spr->ca[0]]|ppulut2[spr->ca[1]]; + J=spr->ca[0]|spr->ca[1]; + atr=spr->atr; - C = sprlinebuf+x; - VB = (PALRAM+0x10)+((atr&3)<<2); + if(J) + { + if(n==0 && SpriteBlurp && !(PPU_status&0x40)) + { + sphitx=x; + sphitdata=J; + if(atr&H_FLIP) + sphitdata= ((J<<7)&0x80) | + ((J<<5)&0x40) | + ((J<<3)&0x20) | + ((J<<1)&0x10) | + ((J>>1)&0x08) | + ((J>>3)&0x04) | + ((J>>5)&0x02) | + ((J>>7)&0x01); + } - if(atr&SP_BACK) - { - if(atr&H_FLIP) - { - if(J&0x80) C[7]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x40) C[6]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x20) C[5]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x10) C[4]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x08) C[3]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x04) C[2]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x02) C[1]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x01) C[0]=VB[pixdata]|0x40; - } else { - if(J&0x80) C[0]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x40) C[1]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x20) C[2]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x10) C[3]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x08) C[4]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x04) C[5]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x02) C[6]=VB[pixdata&3]|0x40; - pixdata>>=4; - if(J&0x01) C[7]=VB[pixdata]|0x40; - } - } else { - if(atr&H_FLIP) - { - if(J&0x80) C[7]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x40) C[6]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x20) C[5]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x10) C[4]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x08) C[3]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x04) C[2]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x02) C[1]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x01) C[0]=VB[pixdata]; - }else{ - if(J&0x80) C[0]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x40) C[1]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x20) C[2]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x10) C[3]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x08) C[4]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x04) C[5]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x02) C[6]=VB[pixdata&3]; - pixdata>>=4; - if(J&0x01) C[7]=VB[pixdata]; - } - } - } - } - SpriteBlurp=0; - spork=1; + C = sprlinebuf+x; + VB = (PALRAM+0x10)+((atr&3)<<2); + + if(atr&SP_BACK) + { + if(atr&H_FLIP) + { + if(J&0x80) C[7]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x40) C[6]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x20) C[5]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x10) C[4]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x08) C[3]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x04) C[2]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x02) C[1]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x01) C[0]=VB[pixdata]|0x40; + } else { + if(J&0x80) C[0]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x40) C[1]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x20) C[2]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x10) C[3]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x08) C[4]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x04) C[5]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x02) C[6]=VB[pixdata&3]|0x40; + pixdata>>=4; + if(J&0x01) C[7]=VB[pixdata]|0x40; + } + } else { + if(atr&H_FLIP) + { + if(J&0x80) C[7]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x40) C[6]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x20) C[5]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x10) C[4]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x08) C[3]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x04) C[2]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x02) C[1]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x01) C[0]=VB[pixdata]; + }else{ + if(J&0x80) C[0]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x40) C[1]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x20) C[2]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x10) C[3]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x08) C[4]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x04) C[5]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x02) C[6]=VB[pixdata&3]; + pixdata>>=4; + if(J&0x01) C[7]=VB[pixdata]; + } + } + } + } + SpriteBlurp=0; + spork=1; } static void CopySprites(uint8 *target) { - uint8 n=((PPU[1]&4)^4)<<1; - uint8 *P=target; + uint8 n=((PPU[1]&4)^4)<<1; + uint8 *P=target; - if(!spork) return; - spork=0; + if(!spork) return; + spork=0; - if(rendis & 1) return; /* User asked to not display sprites. */ + if(!rendersprites) return; //User asked to not display sprites. - loopskie: - { - uint32 t=*(uint32 *)(sprlinebuf+n); +loopskie: + { + uint32 t=*(uint32 *)(sprlinebuf+n); - if(t!=0x80808080) - { - #ifdef LSB_FIRST - if(!(t&0x80)) - { - if(!(t&0x40) || (P[n]&0x40)) // Normal sprite || behind bg sprite - P[n]=sprlinebuf[n]; - } + if(t!=0x80808080) + { +#ifdef LSB_FIRST + if(!(t&0x80)) + { + if(!(t&0x40) || (P[n]&0x40)) // Normal sprite || behind bg sprite + P[n]=sprlinebuf[n]; + } - if(!(t&0x8000)) - { - if(!(t&0x4000) || (P[n+1]&0x40)) // Normal sprite || behind bg sprite - P[n+1]=(sprlinebuf+1)[n]; - } + if(!(t&0x8000)) + { + if(!(t&0x4000) || (P[n+1]&0x40)) // Normal sprite || behind bg sprite + P[n+1]=(sprlinebuf+1)[n]; + } - if(!(t&0x800000)) - { - if(!(t&0x400000) || (P[n+2]&0x40)) // Normal sprite || behind bg sprite - P[n+2]=(sprlinebuf+2)[n]; - } + if(!(t&0x800000)) + { + if(!(t&0x400000) || (P[n+2]&0x40)) // Normal sprite || behind bg sprite + P[n+2]=(sprlinebuf+2)[n]; + } - if(!(t&0x80000000)) - { - if(!(t&0x40000000) || (P[n+3]&0x40)) // Normal sprite || behind bg sprite - P[n+3]=(sprlinebuf+3)[n]; - } - #else - /* TODO: Simplify */ - if(!(t&0x80000000)) - { - if(!(t&0x40000000)) // Normal sprite - P[n]=sprlinebuf[n]; - else if(P[n]&64) // behind bg sprite - P[n]=sprlinebuf[n]; - } + if(!(t&0x80000000)) + { + if(!(t&0x40000000) || (P[n+3]&0x40)) // Normal sprite || behind bg sprite + P[n+3]=(sprlinebuf+3)[n]; + } +#else + /* TODO: Simplify */ + if(!(t&0x80000000)) + { + if(!(t&0x40000000)) // Normal sprite + P[n]=sprlinebuf[n]; + else if(P[n]&64) // behind bg sprite + P[n]=sprlinebuf[n]; + } - if(!(t&0x800000)) - { - if(!(t&0x400000)) // Normal sprite - P[n+1]=(sprlinebuf+1)[n]; - else if(P[n+1]&64) // behind bg sprite - P[n+1]=(sprlinebuf+1)[n]; - } + if(!(t&0x800000)) + { + if(!(t&0x400000)) // Normal sprite + P[n+1]=(sprlinebuf+1)[n]; + else if(P[n+1]&64) // behind bg sprite + P[n+1]=(sprlinebuf+1)[n]; + } - if(!(t&0x8000)) - { - if(!(t&0x4000)) // Normal sprite - P[n+2]=(sprlinebuf+2)[n]; - else if(P[n+2]&64) // behind bg sprite - P[n+2]=(sprlinebuf+2)[n]; - } + if(!(t&0x8000)) + { + if(!(t&0x4000)) // Normal sprite + P[n+2]=(sprlinebuf+2)[n]; + else if(P[n+2]&64) // behind bg sprite + P[n+2]=(sprlinebuf+2)[n]; + } - if(!(t&0x80)) - { - if(!(t&0x40)) // Normal sprite - P[n+3]=(sprlinebuf+3)[n]; - else if(P[n+3]&64) // behind bg sprite - P[n+3]=(sprlinebuf+3)[n]; - } - #endif - } - } - n+=4; - if(n) goto loopskie; + if(!(t&0x80)) + { + if(!(t&0x40)) // Normal sprite + P[n+3]=(sprlinebuf+3)[n]; + else if(P[n+3]&64) // behind bg sprite + P[n+3]=(sprlinebuf+3)[n]; + } +#endif + } + } + n+=4; + if(n) goto loopskie; } void FCEUPPU_SetVideoSystem(int w) { - if(w) - { - scanlines_per_frame=312; - FSettings.FirstSLine=FSettings.UsrFirstSLine[1]; - FSettings.LastSLine=FSettings.UsrLastSLine[1]; - } - else - { - scanlines_per_frame=262; - FSettings.FirstSLine=FSettings.UsrFirstSLine[0]; - FSettings.LastSLine=FSettings.UsrLastSLine[0]; - } + if(w) + { + scanlines_per_frame=312; + FSettings.FirstSLine=FSettings.UsrFirstSLine[1]; + FSettings.LastSLine=FSettings.UsrLastSLine[1]; + } + else + { + scanlines_per_frame=262; + FSettings.FirstSLine=FSettings.UsrFirstSLine[0]; + FSettings.LastSLine=FSettings.UsrLastSLine[0]; + } } -/** -* Initializes the PPU -**/ +//Initializes the PPU void FCEUPPU_Init(void) { makeppulut(); @@ -1219,207 +1215,209 @@ void FCEUPPU_Init(void) void FCEUPPU_Reset(void) { - VRAMBuffer=PPU[0]=PPU[1]=PPU_status=PPU[3]=0; - PPUSPL=0; - PPUGenLatch=0; - RefreshAddr=TempAddr=0; - vtoggle = 0; - ppudead = 2; + VRAMBuffer=PPU[0]=PPU[1]=PPU_status=PPU[3]=0; + PPUSPL=0; + PPUGenLatch=0; + RefreshAddr=TempAddr=0; + vtoggle = 0; + ppudead = 2; kook = 0; -// XOffset=0; + // XOffset=0; } void FCEUPPU_Power(void) { int x; - memset(NTARAM,0x00,0x800); - memset(PALRAM,0x00,0x20); - memset(SPRAM,0x00,0x100); - FCEUPPU_Reset(); + memset(NTARAM,0x00,0x800); + memset(PALRAM,0x00,0x20); + memset(SPRAM,0x00,0x100); + FCEUPPU_Reset(); - for(x=0x2000;x<0x4000;x+=8) - { - ARead[x]=A200x; - BWrite[x]=B2000; - ARead[x+1]=A200x; - BWrite[x+1]=B2001; - ARead[x+2]=A2002; - BWrite[x+2]=B2002; - ARead[x+3]=A200x; - BWrite[x+3]=B2003; - ARead[x+4]=A200x; //A2004; - BWrite[x+4]=B2004; - ARead[x+5]=A200x; - BWrite[x+5]=B2005; - ARead[x+6]=A200x; - BWrite[x+6]=B2006; - ARead[x+7]=A2007; - BWrite[x+7]=B2007; - } - BWrite[0x4014]=B4014; + for(x=0x2000;x<0x4000;x+=8) + { + ARead[x]=A200x; + BWrite[x]=B2000; + ARead[x+1]=A200x; + BWrite[x+1]=B2001; + ARead[x+2]=A2002; + BWrite[x+2]=B2002; + ARead[x+3]=A200x; + BWrite[x+3]=B2003; + ARead[x+4]=A200x; //A2004; + BWrite[x+4]=B2004; + ARead[x+5]=A200x; + BWrite[x+5]=B2005; + ARead[x+6]=A200x; + BWrite[x+6]=B2006; + ARead[x+7]=A2007; + BWrite[x+7]=B2007; + } + BWrite[0x4014]=B4014; } int FCEUPPU_Loop(int skip) { - if(ppudead) /* Needed for Knight Rider, possibly others. */ - { - memset(XBuf, 0x80, 256*240); - X6502_Run(scanlines_per_frame*(256+85)); - ppudead--; - } - else - { - X6502_Run(256+85); - PPU_status |= 0x80; - PPU[3]=PPUSPL=0; /* Not sure if this is correct. According - to Matt Conte and my own tests, it is. Timing is probably - off, though. NOTE: Not having this here - breaks a Super Donkey Kong game. */ - /* I need to figure out the true nature and length - of this delay. - */ - X6502_Run(12); - if(GameInfo->type==GIT_NSF) - DoNSFFrame(); - else - { - if(VBlankON) - TriggerNMI(); - } - X6502_Run((scanlines_per_frame-242)*(256+85)-12); //-12); - PPU_status&=0x1f; - X6502_Run(256); + //Needed for Knight Rider, possibly others. + if(ppudead) + { + memset(XBuf, 0x80, 256*240); + X6502_Run(scanlines_per_frame*(256+85)); + ppudead--; + } + else + { + X6502_Run(256+85); + PPU_status |= 0x80; + + //Not sure if this is correct. According to Matt Conte and my own tests, it is. + //Timing is probably off, though. + //NOTE: Not having this here breaks a Super Donkey Kong game. + PPU[3]=PPUSPL=0; + + //I need to figure out the true nature and length of this delay. + X6502_Run(12); + if(GameInfo->type==GIT_NSF) + DoNSFFrame(); + else + { + if(VBlankON) + TriggerNMI(); + } + X6502_Run((scanlines_per_frame-242)*(256+85)-12); //-12); + PPU_status&=0x1f; + X6502_Run(256); - { - int x; + { + int x; - if(ScreenON || SpriteON) - { - if(GameHBIRQHook && ((PPU[0]&0x38)!=0x18)) - GameHBIRQHook(); - if(PPU_hook) - for(x=0;x<42;x++) {PPU_hook(0x2000); PPU_hook(0);} - if(GameHBIRQHook2) - GameHBIRQHook2(); - } - X6502_Run(85-16); - if(ScreenON || SpriteON) - { - RefreshAddr=TempAddr; - if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); - } + if(ScreenON || SpriteON) + { + if(GameHBIRQHook && ((PPU[0]&0x38)!=0x18)) + GameHBIRQHook(); + if(PPU_hook) + for(x=0;x<42;x++) {PPU_hook(0x2000); PPU_hook(0);} + if(GameHBIRQHook2) + GameHBIRQHook2(); + } + X6502_Run(85-16); + if(ScreenON || SpriteON) + { + RefreshAddr=TempAddr; + if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); + } - /* Clean this stuff up later. */ - spork=numsprites=0; - ResetRL(XBuf); + //Clean this stuff up later. + spork=numsprites=0; + ResetRL(XBuf); - X6502_Run(16-kook); - kook ^= 1; - } - if(GameInfo->type==GIT_NSF) - X6502_Run((256+85)*240); - #ifdef FRAMESKIP - else if(skip) - { - int y; + X6502_Run(16-kook); + kook ^= 1; + } + if(GameInfo->type==GIT_NSF) + X6502_Run((256+85)*240); +#ifdef FRAMESKIP + else if(skip) + { + int y; - y=SPRAM[0]; - y++; + y=SPRAM[0]; + y++; - PPU_status|=0x20; // Fixes "Bee 52". Does it break anything? - if(GameHBIRQHook) - { - X6502_Run(256); - for(scanline=0;scanline<240;scanline++) - { - if(ScreenON || SpriteON) - GameHBIRQHook(); - if(scanline==y && SpriteON) PPU_status|=0x40; - X6502_Run((scanline==239)?85:(256+85)); - } - } - else if(y<240) - { - X6502_Run((256+85)*y); - if(SpriteON) PPU_status|=0x40; // Quick and very dirty hack. - X6502_Run((256+85)*(240-y)); - } - else - X6502_Run((256+85)*240); - } - #endif - else - { - int x,max,maxref; + PPU_status|=0x20; // Fixes "Bee 52". Does it break anything? + if(GameHBIRQHook) + { + X6502_Run(256); + for(scanline=0;scanline<240;scanline++) + { + if(ScreenON || SpriteON) + GameHBIRQHook(); + if(scanline==y && SpriteON) PPU_status|=0x40; + X6502_Run((scanline==239)?85:(256+85)); + } + } + else if(y<240) + { + X6502_Run((256+85)*y); + if(SpriteON) PPU_status|=0x40; // Quick and very dirty hack. + X6502_Run((256+85)*(240-y)); + } + else + X6502_Run((256+85)*240); + } +#endif + else + { + int x,max,maxref; - deemp=PPU[1]>>5; - for(scanline=0;scanline<240;) //scanline is incremented in DoLine. Evil. :/ - { - deempcnt[deemp]++; - DEBUG(FCEUD_UpdatePPUView(scanline, 1)); - DoLine(); - } - if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline); - for(x=1,max=0,maxref=0;x<7;x++) - { - if(deempcnt[x]>max) - { - max=deempcnt[x]; - maxref=x; - } - deempcnt[x]=0; - } - //FCEU_DispMessage("%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x %d",deempcnt[0],deempcnt[1],deempcnt[2],deempcnt[3],deempcnt[4],deempcnt[5],deempcnt[6],deempcnt[7],maxref); - //memset(deempcnt,0,sizeof(deempcnt)); - SetNESDeemph(maxref,0); - } - } /* else... to if(ppudead) */ + deemp=PPU[1]>>5; + for(scanline=0;scanline<240;) //scanline is incremented in DoLine. Evil. :/ + { + deempcnt[deemp]++; + DEBUG(FCEUD_UpdatePPUView(scanline, 1)); + DoLine(); + } + if(MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline); + for(x=1,max=0,maxref=0;x<7;x++) + { + if(deempcnt[x]>max) + { + max=deempcnt[x]; + maxref=x; + } + deempcnt[x]=0; + } + //FCEU_DispMessage("%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x %d",deempcnt[0],deempcnt[1],deempcnt[2],deempcnt[3],deempcnt[4],deempcnt[5],deempcnt[6],deempcnt[7],maxref); + //memset(deempcnt,0,sizeof(deempcnt)); + SetNESDeemph(maxref,0); + } + } //else... to if(ppudead) - #ifdef FRAMESKIP - if(skip) - { - FCEU_PutImageDummy(); - return(0); - } - else - #endif - { - //if(tileview) TileView(); - FCEU_PutImage(); - return(1); - } +#ifdef FRAMESKIP + if(skip) + { + FCEU_PutImageDummy(); + return(0); + } + else +#endif + { + //mbg 6/21/08 - tileview is being ripped out since i dont know how long its been since it worked + //if(tileview) TileView(); + FCEU_PutImage(); + return(1); + } } static uint16 TempAddrT,RefreshAddrT; void FCEUPPU_LoadState(int version) { - TempAddr=TempAddrT; - RefreshAddr=RefreshAddrT; + TempAddr=TempAddrT; + RefreshAddr=RefreshAddrT; } SFORMAT FCEUPPU_STATEINFO[]={ - { NTARAM, 0x800, "NTAR"}, - { PALRAM, 0x20, "PRAM"}, - { SPRAM, 0x100, "SPRA"}, - { PPU, 0x4, "PPUR"}, - { &kook, 1, "KOOK"}, - { &ppudead, 1, "DEAD"}, - { &PPUSPL, 1, "PSPL"}, - { &XOffset, 1, "XOFF"}, - { &vtoggle, 1, "VTOG"}, - { &RefreshAddrT, 2|FCEUSTATE_RLSB, "RADD"}, - { &TempAddrT, 2|FCEUSTATE_RLSB, "TADD"}, - { &VRAMBuffer, 1, "VBUF"}, - { &PPUGenLatch, 1, "PGEN"}, - { 0 } - }; + { NTARAM, 0x800, "NTAR"}, + { PALRAM, 0x20, "PRAM"}, + { SPRAM, 0x100, "SPRA"}, + { PPU, 0x4, "PPUR"}, + { &kook, 1, "KOOK"}, + { &ppudead, 1, "DEAD"}, + { &PPUSPL, 1, "PSPL"}, + { &XOffset, 1, "XOFF"}, + { &vtoggle, 1, "VTOG"}, + { &RefreshAddrT, 2|FCEUSTATE_RLSB, "RADD"}, + { &TempAddrT, 2|FCEUSTATE_RLSB, "TADD"}, + { &VRAMBuffer, 1, "VBUF"}, + { &PPUGenLatch, 1, "PGEN"}, + { 0 } +}; void FCEUPPU_SaveState(void) { - TempAddrT=TempAddr; - RefreshAddrT=RefreshAddr; + TempAddrT=TempAddr; + RefreshAddrT=RefreshAddr; }