From 775c886a88307bc2b08a8fe9073c87ae6f209ba6 Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 28 Jul 2006 07:42:14 +0000 Subject: [PATCH] cleaned some #ifdef windows code out of fceu.cpp spiffied a few docs --- driver.h | 4 +- drivers/win/main.cpp | 76 ++++++++++++++++++++++++ drivers/win/sound.cpp | 1 + fceu.cpp | 130 ++++++++++++------------------------------ wave.cpp | 1 + 5 files changed, 118 insertions(+), 94 deletions(-) diff --git a/driver.h b/driver.h index c724ed99..d1034b73 100644 --- a/driver.h +++ b/driver.h @@ -321,10 +321,10 @@ void FCEUD_DebugBreakpoint(); //(we should move the code in the win driver that does this to the shared area) void FCEUD_TraceInstruction(); -//the driver might should update its NTView +//the driver might should update its NTView (only used if debugging support is compiled in) void FCEUD_UpdateNTView(int scanline, int drawall); -//the driver might should update its PPUView +//the driver might should update its PPUView (only used if debugging support is compiled in) void FCEUD_UpdatePPUView(int scanline, int drawall); #endif /* __DRIVER_H_ */ diff --git a/drivers/win/main.cpp b/drivers/win/main.cpp index b734bf75..d4287775 100644 --- a/drivers/win/main.cpp +++ b/drivers/win/main.cpp @@ -35,6 +35,7 @@ #include "../../types.h" #include "../../fceu.h" +#include "../../state.h" #include "ppuview.h" #include "debugger.h" #include "input.h" @@ -346,6 +347,74 @@ void _updateMemWatch() { //but soon we will do more! } +#ifdef _USE_SHARED_MEMORY_ +HANDLE mapGameMemBlock; +HANDLE mapRAM; +HANDLE mapBotInput; +uint32 *BotInput; +void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM) { + + mapGameMemBlock = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE, 0, 131072,"fceu.GameMemBlock"); + if(mapGameMemBlock == NULL || GetLastError() == ERROR_ALREADY_EXISTS) + { + //mbg 7/38/06 - is this the proper error handling? + //do we need to indicate to user somehow that this failed in this emu instance? + CloseHandle(mapGameMemBlock); + mapGameMemBlock = NULL; + *GameMemBlock = (uint8 *) malloc(131072); + *RAM = (uint8 *) malloc(2048); + } + else + { + *GameMemBlock = (uint8 *)MapViewOfFile(mapGameMemBlock, FILE_MAP_WRITE, 0, 0, 0); + + // set up shared memory mappings + mapRAM = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE, 0, 0x800,"fceu.RAM"); + *RAM = (uint8 *)MapViewOfFile(mapRAM, FILE_MAP_WRITE, 0, 0, 0); + } + + // Give RAM pointer to state structure + //mbg 7/28/06 - wtf? + extern SFORMAT SFCPU[]; + SFCPU[6].v = *RAM; + + //Bot input + mapBotInput = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE,0, 4096, "fceu.BotInput"); + BotInput = (uint32 *) MapViewOfFile(mapBotInput, FILE_MAP_WRITE, 0, 0, 0); + BotInput[0] = 0; +} + +void win_FreeBuffers(uint8 *GameMemBlock, uint8 *RAM) { + //clean up shared memory + if(mapRAM) + { + UnmapViewOfFile(mapRAM); + CloseHandle(mapRAM); + RAM = NULL; + } + else + { + free(RAM); + RAM = NULL; + } + if(mapGameMemBlock) + { + UnmapViewOfFile(mapGameMemBlock); + CloseHandle(mapGameMemBlock); + GameMemBlock = NULL; + } + else + { + free(GameMemBlock); + GameMemBlock = NULL; + } + + UnmapViewOfFile(mapBotInput); + CloseHandle(mapBotInput); + BotInput = NULL; +} +#endif + int main(int argc,char *argv[]) { char *t; @@ -359,6 +428,7 @@ int main(int argc,char *argv[]) if(!FCEUI_Initialize()) goto doexito; + ApplyDefaultCommandMapping(); srand(GetTickCount()); // rand() is used for some GUI sillyness. @@ -423,6 +493,12 @@ doloopy: uint8 *gfx=0; int32 *sound=0; int32 ssize=0; + + #ifdef _USE_SHARED_MEMORY_ + UpdateBasicBot(); + #endif + FCEU_UpdateBot(); + FCEUI_Emulate(&gfx, &sound, &ssize, 0); xbsave = gfx; FCEUD_Update(gfx, sound, ssize); diff --git a/drivers/win/sound.cpp b/drivers/win/sound.cpp index 8033971e..50ce44a0 100644 --- a/drivers/win/sound.cpp +++ b/drivers/win/sound.cpp @@ -37,6 +37,7 @@ DSBUFFERDESC DSBufferDesc; WAVEFORMATEX wfa; WAVEFORMATEX wf; +//bittag=1 -> 8bit output int bittage; static int mute=0; /* TODO: add to config? add to GUI. */ diff --git a/fceu.cpp b/fceu.cpp index a0d5a756..918041fb 100644 --- a/fceu.cpp +++ b/fceu.cpp @@ -22,11 +22,6 @@ #include #include #include - -#ifdef _USE_SHARED_MEMORY_ -#include -#endif - #include "types.h" #include "x6502.h" #include "fceu.h" @@ -35,25 +30,23 @@ #include "netplay.h" #include "general.h" #include "endian.h" -#include "memory.h" +#include "memory.h" #include "cart.h" #include "nsf.h" #include "fds.h" #include "ines.h" #include "unif.h" -#include "cheat.h" +#include "cheat.h" #include "palette.h" #include "state.h" #include "movie.h" -#include "video.h" +#include "video.h" #include "input.h" #include "file.h" #include "crc32.h" #include "vsuni.h" -#ifdef _USE_SHARED_MEMORY_ -#include "drivers/win/basicbot.h" -#endif + uint64 timestampbase; @@ -177,21 +170,35 @@ void FASTAPASS(3) SetWriteHandler(int32 start, int32 end, writefunc func) BWrite[x]=func; } -#ifdef _USE_SHARED_MEMORY_ -HANDLE mapGameMemBlock; uint8 *GameMemBlock; -HANDLE mapRAM; uint8 *RAM; -HANDLE mapBotInput; -uint32 *BotInput; -#else -uint8 GameMemBlock[131072]; -uint8 RAM[0x800]; -#endif //_USE_SHARED_MEMORY_ + +//--------- +//windows might need to allocate these differently, so we have some special code + +static void AllocBuffers() { + #ifdef _USE_SHARED_MEMORY_ + void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM); + win_AllocBuffers(&GameMemBlock, &RAM); + #else + GameMemBlock = (uint8*)FCEU_gmalloc(131072); + RAM = (uint8*)FCEU_gmalloc(0x800); + #endif +} + +static void FreeBuffers() { + #ifdef _USE_SHARED_MEMORY_ + void win_FreeBuffers(uint8 *GameMemBlock, uint8 *RAM); + win_FreeBuffers(GameMemBlock, RAM); + #else + FCEU_free(GameMemBlock); + FCEU_free(RAM); + #endif +} +//------ uint8 PAL=0; - static DECLFW(BRAML) { RAM[A]=V; @@ -342,38 +349,11 @@ FCEUGI *FCEUI_LoadGame(const char *name, int OverwriteVidMode) int FCEUI_Initialize(void) { -#ifdef _USE_SHARED_MEMORY_ - // set up shared memory mappings - mapGameMemBlock = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE, 0, 131072,"fceu.GameMemBlock"); - if(mapGameMemBlock == NULL || GetLastError() == ERROR_ALREADY_EXISTS) - { - CloseHandle(mapGameMemBlock); - mapGameMemBlock = NULL; - GameMemBlock = (uint8 *) malloc(131072); - RAM = (uint8 *) malloc(2048); - } - else - { - GameMemBlock = (uint8 *)MapViewOfFile(mapGameMemBlock, FILE_MAP_WRITE, 0, 0, 0); - - // set up shared memory mappings - mapRAM = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE, 0, 0x800,"fceu.RAM"); - RAM = (uint8 *)MapViewOfFile(mapRAM, FILE_MAP_WRITE, 0, 0, 0); - } - - // Give RAM pointer to state structure - extern SFORMAT SFCPU[]; - SFCPU[6].v = RAM; - - //Bot input - mapBotInput = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE,0, 4096, "fceu.BotInput"); - BotInput = (uint32 *) MapViewOfFile(mapBotInput, FILE_MAP_WRITE, 0, 0, 0); - BotInput[0] = 0; - -#endif //_USE_SHARED_MEMORY_ - if(!FCEU_InitVirtualVideo()) return 0; + + AllocBuffers(); + memset(&FSettings,0,sizeof(FSettings)); FSettings.UsrFirstSLine[0]=8; FSettings.UsrFirstSLine[1]=0; @@ -389,36 +369,7 @@ void FCEUI_Kill(void) { FCEU_KillVirtualVideo(); FCEU_KillGenie(); - -#ifdef _USE_SHARED_MEMORY_ - //clean up shared memory - if(mapRAM) - { - UnmapViewOfFile(mapRAM); - CloseHandle(mapRAM); - RAM = NULL; - } - else - { - free(RAM); - RAM = NULL; - } - if(mapGameMemBlock) - { - UnmapViewOfFile(mapGameMemBlock); - CloseHandle(mapGameMemBlock); - GameMemBlock = NULL; - } - else - { - free(GameMemBlock); - GameMemBlock = NULL; - } - - UnmapViewOfFile(mapBotInput); - CloseHandle(mapBotInput); - BotInput = NULL; -#endif + FreeBuffers(); } int rapidAlternator = 0; @@ -479,12 +430,6 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski { int r,ssize; -#ifdef _USE_SHARED_MEMORY_ - UpdateBasicBot(); -#endif - - FCEU_UpdateBot(); - if(EmulationPaused&2) EmulationPaused &= ~1; // clear paused flag temporarily (frame advance) else if(EmulationPaused&1 || FCEU_BotMode()) @@ -525,11 +470,12 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski if(EmulationPaused&2) { EmulationPaused = 1; // restore paused flag -#ifdef WIN32 - #define SO_MUTEFA 16 - extern int soundoptions; - if(soundoptions&SO_MUTEFA) -#endif + //mbg merge 7/28/06 don't like the looks of this... +//#ifdef WIN32 +// #define SO_MUTEFA 16 +// extern int soundoptions; +// if(soundoptions&SO_MUTEFA) +//#endif *SoundBufSize=0; // keep sound muted } } diff --git a/wave.cpp b/wave.cpp index 81abd14b..0428c75c 100644 --- a/wave.cpp +++ b/wave.cpp @@ -32,6 +32,7 @@ void FCEU_WriteWaveData(int32 *Buffer, int Count) dest=temp; x=Count; + //mbg 7/28/06 - we appear to be guaranteeing little endian while(x--) { int16 tmp=*Buffer;