--- SIDPlayer/src/main_sdl.cpp 2001/01/16 14:12:54 1.4 +++ 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-2000 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 @@ -21,8 +21,16 @@ #include "sys.h" #include +#include + #include #include +#include + +#ifdef __unix__ +#include +#include +#endif #include "main.h" #include "prefs.h" @@ -30,12 +38,72 @@ /* + * 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 */ static void usage(const char *prg_name) { - printf("\nUsage: %s [options] FILE [song_number]]\n", prg_name); + printf("Usage: %s [OPTION...] FILE [song_number]\n", prg_name); + PrefsPrintUsage(); exit(0); } @@ -50,7 +118,7 @@ int main(int argc, char **argv) // Print banner printf( PACKAGE " Version " VERSION "\n\n" - "Copyright (C) 1996-2000 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" @@ -58,24 +126,6 @@ int main(int argc, char **argv) "For details, see the file COPYING.\n\n" ); - // Parse arguments - if (argc < 2) - usage(argv[0]); - char *file_name = argv[argc - 1]; - int song = 0; - if (argc >= 3) { - bool only_numbers = true; - for (int i=0; i 8) { + // WAV file is little-endian, swap audio data + for (int b=0; b