From 84274fe6d61ec47d706633923531dbde9226cfa3 Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 9 May 2008 04:00:04 +0000 Subject: [PATCH] better frame advancing. debugger window no longer opens itsself. --- src/driver.h | 6 +++- src/drivers/win/debugger.cpp | 21 +++++++------- src/drivers/win/input.cpp | 7 +++-- src/drivers/win/keyboard.cpp | 40 ++++++++++++++------------ src/drivers/win/keyboard.h | 6 ++-- src/drivers/win/main.cpp | 55 +++++++++++++++++++++++++----------- src/drivers/win/mapinput.cpp | 2 +- src/fceu.cpp | 15 +++++++++- 8 files changed, 97 insertions(+), 55 deletions(-) diff --git a/src/driver.h b/src/driver.h index 15a20573..84fed9f9 100644 --- a/src/driver.h +++ b/src/driver.h @@ -276,8 +276,12 @@ void FCEUI_FDSSelect(void); int FCEUI_DatachSet(const uint8 *rcode); -///returns flags indicating whether emulation is paused (bit0) and whether it is single-stepping (bit1) +///returns a flag indicating whether emulation is paused int FCEUI_EmulationPaused(void); +///returns a flag indicating whether a one frame step has been requested +int FCEUI_EmulationFrameStepped(); +///clears the framestepped flag. use it after youve stepped your one frame +void FCEUI_ClearEmulationFrameStepped(); ///sets the EmulationPaused flags void FCEUI_SetEmulationPaused(int val); ///toggles the paused bit (bit0) for EmulationPaused. caused FCEUD_DebugUpdate() to fire if the emulation pauses diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 7109cef0..aa304611 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -476,20 +476,19 @@ void UpdateRegs(HWND hwndDlg) { ///indicates whether we're under the control of the debugger bool inDebugger = false; -void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); //HACK +//this code enters the debugger. void FCEUD_DebugBreakpoint() { - inDebugger = true; - DoDebug(1); - UpdateLogWindow(); - if(hMemView)UpdateMemoryView(0); - //mbg merge 6/30/06 - this architecture has changed - FCEUD_Update(0,0,0); - //FCEUD_BlitScreen(XBuf+8); //this looks odd, I know. but the pause routine is in here!! - //if(logging)LogInstruction(); //logging might have been started while we were paused - inDebugger = false; + UpdateDebugger(); + void win_debuggerLoop(); //HACK + win_debuggerLoop(); } -void UpdateDebugger() { +void UpdateDebugger() +{ + //dont do anything if the debugger is not visible + if(!hDebug) + return; + char str[256]={0},chr[8]; int tmp,ret,i; diff --git a/src/drivers/win/input.cpp b/src/drivers/win/input.cpp index b4891957..3edc5f8f 100644 --- a/src/drivers/win/input.cpp +++ b/src/drivers/win/input.cpp @@ -129,8 +129,8 @@ int NoWaiting=0; bool turbo = false; #include "keyscan.h" -static unsigned char *keys=0; -static unsigned char *keys_nr=0; +static unsigned int *keys=0; +static unsigned int *keys_nr=0; static int DIPS=0; //#define KEY(__a) keys_nr[MKK(__a)] @@ -1404,7 +1404,8 @@ int FCEUD_TestCommandState(int c) // else // keys_nr=GetKeyboard_nr(); } - else if(c != EMUCMD_SPEED_TURBO) // TODO: this should be made more general by detecting if the command has an "off" function, but right now Turbo is the only command that has it + else + if(c != EMUCMD_SPEED_TURBO) // TODO: this should be made more general by detecting if the command has an "off" function, but right now Turbo is the only command that has it { keys=GetKeyboard_jd(); keys_nr=GetKeyboard_nr(); diff --git a/src/drivers/win/keyboard.cpp b/src/drivers/win/keyboard.cpp index a2f5d15e..3488396d 100644 --- a/src/drivers/win/keyboard.cpp +++ b/src/drivers/win/keyboard.cpp @@ -34,14 +34,16 @@ void KeyboardClose(void) lpdid=0; } -static unsigned char keys[256] = {0,}; // with repeat -static unsigned char keys_nr[256] = {0,}; // non-repeating -static unsigned char keys_jd[256] = {0,}; // just-down -static unsigned char keys_jd_lock[256] = {0,}; // just-down released lock +static unsigned int keys[256] = {0,}; // with repeat +static unsigned int keys_nr[256] = {0,}; // non-repeating +static unsigned int keys_jd[256] = {0,}; // just-down +static unsigned int keys_jd_lock[256] = {0,}; // just-down released lock int autoHoldKey = 0, autoHoldClearKey = 0; +int ctr=0; void KeyboardUpdateState(void) { unsigned char tk[256]; + printf("%d!!\n",ctr++); ddrval=IDirectInputDevice7_GetDeviceState(lpdid,256,tk); @@ -49,6 +51,8 @@ void KeyboardUpdateState(void) if(GetAsyncKeyState(VK_PAUSE)) // normally this should have & 0x8000, but apparently this key is too special for that to work tk[0xC5] = 0x80; + DWORD time = timeGetTime(); + switch(ddrval) { case DI_OK: //memcpy(keys,tk,256);break; @@ -64,16 +68,16 @@ void KeyboardUpdateState(void) #define KEY_JUST_DOWN_DURATION (4) // must be >= 1 and <= 255 int i; + for(i = 0 ; i < 256 ; i++) - if(tk[i]) - if(keys_nr[i] < 255) - keys_nr[i]++; // activate key, and count up for repeat - else - keys_nr[i] = 255 - KEY_REPEAT_REPEATING_DELAY; // oscillate for repeat + if(tk[i]) { + if(keys_nr[i] == 0) + keys_nr[i] = time; + } else - keys_nr[i] = 0; // deactivate key + keys_nr[i] = 0; - memcpy(keys,keys_nr,256); + memcpy(keys,keys_nr,256*4); // key-down detection for(i = 0 ; i < 256 ; i++) @@ -87,18 +91,18 @@ void KeyboardUpdateState(void) else if(keys_jd[i] /*&& (i != 0x2A && i != 0x36 && i != 0x1D && i != 0x38)*/) { - if(++keys_jd[i] > KEY_JUST_DOWN_DURATION) + if(time - keys_jd[i] > KEY_JUST_DOWN_DURATION) { keys_jd[i] = 0; keys_jd_lock[i] = 1; } } else - keys_jd[i] = 1; + keys_jd[i] = time; // key repeat for(i = 0 ; i < 256 ; i++) - if(keys[i] >= KEY_REPEAT_INITIAL_DELAY && !(keys[i]%KEY_REPEAT_REPEATING_DELAY)) + if(time - keys[i] >= KEY_REPEAT_INITIAL_DELAY && !((time-keys[i])%KEY_REPEAT_REPEATING_DELAY)) keys[i] = 0; } break; @@ -106,7 +110,7 @@ void KeyboardUpdateState(void) case DIERR_INPUTLOST: case DIERR_NOTACQUIRED: - memset(keys,0,256); + memset(keys,0,256*4); IDirectInputDevice7_Acquire(lpdid); break; } @@ -116,15 +120,15 @@ void KeyboardUpdateState(void) autoHoldReset = autoHoldClearKey && keys[autoHoldClearKey] != 0; } -unsigned char *GetKeyboard(void) +unsigned int *GetKeyboard(void) { return(keys); } -unsigned char *GetKeyboard_nr(void) +unsigned int *GetKeyboard_nr(void) { return(keys_nr); } -unsigned char *GetKeyboard_jd(void) +unsigned int *GetKeyboard_jd(void) { return(keys_jd); } diff --git a/src/drivers/win/keyboard.h b/src/drivers/win/keyboard.h index 1db8d556..f9de9ee7 100644 --- a/src/drivers/win/keyboard.h +++ b/src/drivers/win/keyboard.h @@ -1,7 +1,7 @@ void KeyboardClose(void); int KeyboardInitialize(void); void KeyboardUpdate(void); -unsigned char *GetKeyboard(void); -unsigned char *GetKeyboard_nr(void); -unsigned char *GetKeyboard_jd(void); +unsigned int *GetKeyboard(void); +unsigned int *GetKeyboard_nr(void); +unsigned int *GetKeyboard_jd(void); int KeyboardSetBackgroundAccess(int on); diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index fcd265a5..5d76af3f 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -710,7 +710,6 @@ doloopy: void _updateWindow() { UpdateFCEUWindow(); - FCEUD_UpdateInput(); PPUViewDoBlit(); UpdateMemoryView(0); UpdateCDLogger(); @@ -921,9 +920,20 @@ void _updateWindow() // } // end of !(old sound code) block //} -/** - * Update the game and gamewindow with a new frame - **/ +void win_debuggerLoop() +{ + //delay until something causes us to unpause. + //either a hotkey or a debugger command + while(FCEUI_EmulationPaused() && !FCEUI_EmulationFrameStepped()) + { + Sleep(50); + FCEUD_UpdateInput(); + _updateWindow(); + } + int zzz=9; +} + +// Update the game and gamewindow with a new frame void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) { //mbg merge 7/19/06 - leaving this untouched but untested @@ -960,6 +970,7 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) //update debugging displays _updateWindow(); + //MBG TODO - think about this logic //throttle extern bool turbo; //needs to be declared better if(!(eoptions&EO_NOTHROTTLE)) //if throttling is enabled.. @@ -968,23 +979,33 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) //then throttle win_Throttle(); - //delay until we unpause. we will only stick here if we're paused by a breakpoint or debug command - while(FCEUI_EmulationPaused() && inDebugger) - { + //sleep just to be polite + if(FCEUI_EmulationPaused()) { Sleep(50); - BlockingCheck(); - FCEUD_UpdateInput(); //should this update the CONTROLS??? or only the hotkeys etc? } - //something of a hack, but straightforward: - //if we were paused, but not in the debugger, then unpause ourselves and step. - //this is so that the cpu won't cut off execution due to being paused, but the debugger _will_ - //cut off execution as soon as it makes it into the main cpu cycle loop - if(FCEUI_EmulationPaused() && !inDebugger) { - FCEUI_ToggleEmulationPause(); - FCEUI_Debugger().step = 1; - } + //while(EmulationPaused==1 && inDebugger) + //{ + // Sleep(50); + // BlockingCheck(); + // FCEUD_UpdateInput(); //should this update the CONTROLS??? or only the hotkeys etc? + //} + + ////so, we're not paused anymore. + + ////something of a hack, but straightforward: + ////if we were paused, but not in the debugger, then unpause ourselves and step. + ////this is so that the cpu won't cut off execution due to being paused, but the debugger _will_ + ////cut off execution as soon as it makes it into the main cpu cycle loop + //if(FCEUI_EmulationPaused() && !inDebugger) { + // FCEUI_ToggleEmulationPause(); + // FCEUI_Debugger().step = 1; + // FCEUD_DebugBreakpoint(); + //} + //make sure to update the input once per frame + FCEUD_UpdateInput(); + // if(soundo) //&& temp_fps_scale >= 64 // { diff --git a/src/drivers/win/mapinput.cpp b/src/drivers/win/mapinput.cpp index a74a0dec..79d9a72a 100644 --- a/src/drivers/win/mapinput.cpp +++ b/src/drivers/win/mapinput.cpp @@ -85,7 +85,7 @@ static struct #define NUM_DEFAULT_MAPPINGS (sizeof(DefaultCommandMapping)/sizeof(DefaultCommandMapping[0])) static uint8 keyonce[MKK_COUNT]; -static unsigned char *keys_nr = 0; +static unsigned int *keys_nr = 0; static const char* ScanNames[256]= { diff --git a/src/fceu.cpp b/src/fceu.cpp index da4407d5..e6e0da70 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -263,6 +263,7 @@ static void CloseGame(void) void ResetGameLoaded(void) { if(GameInfo) CloseGame(); + EmulationPaused = 0; //mbg 5/8/08 - loading games while paused was bad news. maybe this fixes it GameStateRestore=0; PPU_hook=0; GameHBIRQHook=0; @@ -510,6 +511,8 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski *SoundBuf=WaveFinal; *SoundBufSize=ssize; + //if we were asked to frame advance, then since we have just finished + //a frame, we should switch to regular pause if(EmulationPaused&2) { EmulationPaused = 1; // restore paused flag @@ -735,7 +738,17 @@ int32 FCEUI_GetDesiredFPS(void) int FCEUI_EmulationPaused(void) { - return (EmulationPaused&1); + return (EmulationPaused&1); +} + +int FCEUI_EmulationFrameStepped() +{ + return (EmulationPaused&2); +} + +void FCEUI_ClearEmulationFrameStepped() +{ + EmulationPaused &=~2; } //mbg merge 7/18/06 added