--- SIDPlayer/src/main_sdl.cpp 2000/10/10 21:47:47 1.2 +++ SIDPlayer/src/main_sdl.cpp 2003/10/21 16:56:19 1.12 @@ -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,10 +21,79 @@ #include "sys.h" #include +#include + #include #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() +{ +#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 +} /* @@ -33,11 +102,12 @@ static void usage(const char *prg_name) { - printf("\nUsage: %s FILE [song_number]]\n", prg_name); + printf("Usage: %s [OPTION...] FILE [song_number]\n", prg_name); + PrefsPrintUsage(); exit(0); } -static void quit(void) +static void quit() { ExitAll(); SDL_Quit(); @@ -48,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" @@ -56,25 +126,37 @@ 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[1]; - int song = 0; - if (argc == 3) - song = atoi(argv[2]); - // Initialize everything if (SDL_Init(SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Couldn't initialize SDL (%s)\n", SDL_GetError()); exit(1); } atexit(quit); - InitAll(); + InitAll(argc, argv); + int32 speed = PrefsFindInt32("speed"); + + // Parse non-option arguments + const char *file_name = NULL; + int song = 0; + for (int i=1; i 8) { + // WAV file is little-endian, swap audio data + for (int b=0; b