--- SIDPlayer/src/main_sdl.cpp 2001/05/22 20:01:34 1.10 +++ SIDPlayer/src/main_sdl.cpp 2003/04/11 20:23:02 1.11 @@ -1,7 +1,7 @@ /* * main_sdl.cpp - SIDPlayer SDL main program * - * SIDPlayer (C) Copyright 1996-2001 Christian Bauer + * SIDPlayer (C) Copyright 1996-2003 Christian Bauer * * 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 @@ -27,12 +27,76 @@ #include #include +#ifdef __unix__ +#include +#include +#endif + #include "main.h" #include "prefs.h" #include "sid.h" /* + * Get current value of microsecond timer + */ + +uint64 GetTicks_usec(void) +{ +#ifdef __unix__ + struct timeval t; + gettimeofday(&t, NULL); + return uint64(t.tv_sec) * 1000000 + t.tv_usec; +#else + return uint64(SDL_GetTicks()) * 1000; +#endif +} + + +/* + * Delay by specified number of microseconds (<1 second) + * (adapted from SDL_Delay() source) + */ + +void Delay_usec(uint32 usec) +{ +#ifdef __unix__ + int was_error; +#ifndef __linux__ /* Non-Linux implementations need to calculate time left */ + uint64 then, now, elapsed; +#endif + struct timeval tv; + + /* Set the timeout interval - Linux only needs to do this once */ +#ifdef __linux__ + tv.tv_sec = 0; + tv.tv_usec = usec; +#else + then = GetTicks_usec(); +#endif + do { + errno = 0; +#ifndef __linux__ + /* Calculate the time interval left (in case of interrupt) */ + now = GetTicks_usec(); + elapsed = (now-then); + then = now; + if ( elapsed >= usec ) { + break; + } + usec -= elapsed; + tv.tv_sec = 0; + tv.tv_usec = usec; +#endif + was_error = select(0, NULL, NULL, NULL, &tv); + } while (was_error && (errno == EINTR)); +#else + SDL_Delay(usec / 1000); +#endif +} + + +/* * Main program */ @@ -54,7 +118,7 @@ int main(int argc, char **argv) // Print banner printf( PACKAGE " Version " VERSION "\n\n" - "Copyright (C) 1996-2001 Christian Bauer\n" + "Copyright (C) 1996-2003 Christian Bauer\n" "E-mail: Christian.Bauer@uni-mainz.de\n" "http://www.uni-mainz.de/~bauec002/\n\n" "This is free software with ABSOLUTELY NO WARRANTY.\n" @@ -168,6 +232,19 @@ int main(int argc, char **argv) SDL_RWclose(f); printf("Output written to '%s'\n", outfile); + } else if (PrefsFindBool("cwsid")) { + + // Catweasel output, requires manual timing + while (true) { + SIDExecute(); + + SDL_Event e; + if (SDL_PollEvent(&e)) { + if (e.type == SDL_QUIT) + break; + } + } + } else { // Start replay and enter main loop @@ -181,5 +258,6 @@ int main(int argc, char **argv) } } + ExitAll(); return 0; }