--- previous/src/main.c 2018/04/24 19:25:30 1.1.1.2 +++ previous/src/main.c 2018/04/24 19:29:49 1.1.1.5 @@ -32,9 +32,12 @@ const char Main_fileid[] = "Hatari main. #include "nextMemory.h" #include "str.h" #include "video.h" +#include "audio.h" #include "avi_record.h" #include "debugui.h" #include "clocks_timings.h" +#include "file.h" +#include "dsp.h" #include "hatari-glue.h" @@ -42,6 +45,7 @@ const char Main_fileid[] = "Hatari main. #include #endif +int nFrameSkips; bool bQuitProgram = false; /* Flag to quit program cleanly */ @@ -150,7 +154,7 @@ bool Main_PauseEmulation(bool visualize) if ( !bEmulationActive ) return false; -// Audio_EnableAudio(false); + //Audio_Output_Enable(false); bEmulationActive = false; if (visualize) { @@ -172,9 +176,11 @@ bool Main_PauseEmulation(bool visualize) /* make sure msg gets shown */ Statusbar_Update(sdlscrn); - if (bGrabMouse && !bInFullScreen) + if (bGrabMouse && !bInFullScreen) { /* Un-grab mouse pointer in windowed mode */ - SDL_WM_GrabInput(SDL_GRAB_OFF); + SDL_SetRelativeMouseMode(SDL_FALSE); + SDL_SetWindowGrab(sdlWindow, SDL_FALSE); + } } return true; } @@ -190,16 +196,17 @@ bool Main_UnPauseEmulation(void) if ( bEmulationActive ) return false; -// Sound_BufferIndexNeedReset = true; -// Audio_EnableAudio(ConfigureParams.Sound.bEnableSound); + //Audio_Output_Enable(ConfigureParams.Sound.bEnableSound); bEmulationActive = true; /* Cause full screen update (to clear all) */ Screen_SetFullUpdate(); - if (bGrabMouse) + if (bGrabMouse) { /* Grab mouse pointer again */ - SDL_WM_GrabInput(SDL_GRAB_ON); + SDL_SetRelativeMouseMode(SDL_TRUE); + SDL_SetWindowGrab(sdlWindow, SDL_TRUE); + } return true; } @@ -269,29 +276,31 @@ void Main_WaitOnVbl(void) } // FrameDuration_micro = (Sint64) ( 1000000.0 / nScreenRefreshRate + 0.5 ); /* round to closest integer */ -// FrameDuration_micro = ClocksTimings_GetVBLDuration_micro ( ConfigureParams.System.nMachineType , nScreenRefreshRate ); - FrameDuration_micro = 1000000/50; + FrameDuration_micro = ClocksTimings_GetVBLDuration_micro ( ConfigureParams.System.nMachineType , 68 ); +// FrameDuration_micro = 1000000/50; CurrentTicks = Time_GetTicks(); if ( DestTicks == 0 ) /* first call, init DestTicks */ + { DestTicks = CurrentTicks + FrameDuration_micro; + } nDelay = DestTicks - CurrentTicks; /* Do not wait if we are in fast forward mode or if we are totally out of sync */ if (ConfigureParams.System.bFastForward == true - || nDelay < -4*FrameDuration_micro) + || nDelay < -4*FrameDuration_micro || nDelay > 50*FrameDuration_micro) { if (ConfigureParams.System.bFastForward == true) { if (!nFirstMilliTick) nFirstMilliTick = Main_GetTicks(); } -// if (nFrameSkips < ConfigureParams.Screen.nFrameSkips) -// { -// nFrameSkips += 1; - // Log_Printf(LOG_DEBUG, "Increased frameskip to %d\n", nFrameSkips); -// } + if (nFrameSkips < ConfigureParams.Screen.nFrameSkips) + { + nFrameSkips += 1; + Log_Printf(LOG_DEBUG, "Increased frameskip to %d\n", nFrameSkips); + } /* Only update DestTicks for next VBL */ DestTicks = CurrentTicks + FrameDuration_micro; return; @@ -299,13 +308,13 @@ void Main_WaitOnVbl(void) /* If automatic frameskip is enabled and delay's more than twice * the effect of single frameskip, decrease frameskip */ -// if (nFrameSkips > 0 -// && ConfigureParams.Screen.nFrameSkips >= AUTO_FRAMESKIP_LIMIT -// && 2*nDelay > FrameDuration_micro/nFrameSkips) -// { -// nFrameSkips -= 1; - // Log_Printf(LOG_DEBUG, "Decreased frameskip to %d\n", nFrameSkips); -// } + if (nFrameSkips > 0 + && ConfigureParams.Screen.nFrameSkips >= AUTO_FRAMESKIP_LIMIT + && 2*nDelay > FrameDuration_micro/nFrameSkips) + { + nFrameSkips -= 1; + Log_Printf(LOG_DEBUG, "Decreased frameskip to %d\n", nFrameSkips); + } if (bAccurateDelays) { @@ -325,6 +334,10 @@ void Main_WaitOnVbl(void) { CurrentTicks = Time_GetTicks(); nDelay = DestTicks - CurrentTicks; + /* If the delay is still bigger than one frame, somebody + * played tricks with the system clock and we have to abort */ + if (nDelay > FrameDuration_micro) + break; } //printf ( "tick %lld\n" , CurrentTicks ); @@ -366,8 +379,8 @@ static void Main_CheckForAccurateDelays( */ void Main_WarpMouse(int x, int y) { - SDL_WarpMouse(x, y); /* Set mouse pointer to new position */ - bIgnoreNextMouseMotion = true; /* Ignore mouse motion event from SDL_WarpMouse */ + SDL_WarpMouseInWindow(sdlWindow, x, y); /* Set mouse pointer to new position */ + bIgnoreNextMouseMotion = true; /* Ignore mouse motion event from SDL_WarpMouse */ } @@ -375,42 +388,28 @@ void Main_WarpMouse(int x, int y) /** * Handle mouse motion event. */ +SDL_Event mymouse[100]; static void Main_HandleMouseMotion(SDL_Event *pEvent) { int dx, dy; - static int ax = 0, ay = 0; - - /* Ignore motion when position has changed right after a reset or TOS - * (especially version 4.04) might get confused and play key clicks */ - if (bIgnoreNextMouseMotion) - { - bIgnoreNextMouseMotion = false; - return; - } + int i,nb; dx = pEvent->motion.xrel; dy = pEvent->motion.yrel; - /* In zoomed low res mode, we divide dx and dy by the zoom factor so that - * the ST mouse cursor stays in sync with the host mouse. However, we have - * to take care of lowest bit of dx and dy which will get lost when - * dividing. So we store these bits in ax and ay and add them to dx and dy - * the next time. */ - if (nScreenZoomX != 1) - { - dx += ax; - ax = dx % nScreenZoomX; - dx /= nScreenZoomX; - } - if (nScreenZoomY != 1) - { - dy += ay; - ay = dy % nScreenZoomY; - dy /= nScreenZoomY; + /* get all mouse event to clean the queue and sum them */ + nb=SDL_PeepEvents(&mymouse[0], 100, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION); + + for (i=0;i true */ Configuration_Apply(true); @@ -754,25 +740,12 @@ int main(int argc, char *argv[]) /* Check if SDL_Delay is accurate */ Main_CheckForAccurateDelays(); -// if ( AviRecordOnStartup ) /* Immediatly starts avi recording ? */ -// Avi_StartRecording ( ConfigureParams.Video.AviRecordFile , ConfigureParams.Screen.bCrop , -// ConfigureParams.Video.AviRecordFps == 0 ? -// ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , nScreenRefreshRate ) : -// (Uint32)ConfigureParams.Video.AviRecordFps << CLOCKS_TIMINGS_SHIFT_VBL , -// 1 << CLOCKS_TIMINGS_SHIFT_VBL , -// ConfigureParams.Video.AviRecordVcodec ); /* Run emulation */ Main_UnPauseEmulation(); M68000_Start(); /* Start emulation */ -// if (bRecordingAvi) -// { - /* cleanly close the avi file */ -// Statusbar_AddMessage("Finishing AVI file...", 100); -// Statusbar_Update(sdlscrn); -// Avi_StopRecording(); -// } + /* Un-init emulation system */ Main_UnInit();