ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SIDPlayer/src/main_sdl.cpp
(Generate patch)

Comparing SIDPlayer/src/main_sdl.cpp (file contents):
Revision 1.9 by cebix, 2001-04-01T17:04:43Z vs.
Revision 1.11 by cebix, 2003-04-11T20:23:02Z

# Line 1 | Line 1
1   /*
2   *  main_sdl.cpp - SIDPlayer SDL main program
3   *
4 < *  SIDPlayer (C) Copyright 1996-2001 Christian Bauer
4 > *  SIDPlayer (C) Copyright 1996-2003 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 27 | Line 27
27   #include <stdlib.h>
28   #include <errno.h>
29  
30 + #ifdef __unix__
31 + #include <unistd.h>
32 + #include <sys/time.h>
33 + #endif
34 +
35   #include "main.h"
36   #include "prefs.h"
37   #include "sid.h"
38  
39  
40   /*
41 + *  Get current value of microsecond timer
42 + */
43 +
44 + uint64 GetTicks_usec(void)
45 + {
46 + #ifdef __unix__
47 +        struct timeval t;
48 +        gettimeofday(&t, NULL);
49 +        return uint64(t.tv_sec) * 1000000 + t.tv_usec;
50 + #else
51 +        return uint64(SDL_GetTicks()) * 1000;
52 + #endif
53 + }
54 +
55 +
56 + /*
57 + *  Delay by specified number of microseconds (<1 second)
58 + *  (adapted from SDL_Delay() source)
59 + */
60 +
61 + void Delay_usec(uint32 usec)
62 + {
63 + #ifdef __unix__
64 +        int was_error;
65 + #ifndef __linux__       /* Non-Linux implementations need to calculate time left */
66 +        uint64 then, now, elapsed;
67 + #endif
68 +        struct timeval tv;
69 +
70 +        /* Set the timeout interval - Linux only needs to do this once */
71 + #ifdef __linux__
72 +        tv.tv_sec = 0;
73 +        tv.tv_usec = usec;
74 + #else
75 +        then = GetTicks_usec();
76 + #endif
77 +        do {
78 +                errno = 0;
79 + #ifndef __linux__
80 +                /* Calculate the time interval left (in case of interrupt) */
81 +                now = GetTicks_usec();
82 +                elapsed = (now-then);
83 +                then = now;
84 +                if ( elapsed >= usec ) {
85 +                        break;
86 +                }
87 +                usec -= elapsed;
88 +                tv.tv_sec = 0;
89 +                tv.tv_usec = usec;
90 + #endif
91 +                was_error = select(0, NULL, NULL, NULL, &tv);
92 +        } while (was_error && (errno == EINTR));
93 + #else
94 +        SDL_Delay(usec / 1000);
95 + #endif
96 + }
97 +
98 +
99 + /*
100   *  Main program
101   */
102  
# Line 54 | Line 118 | int main(int argc, char **argv)
118          // Print banner
119          printf(
120                  PACKAGE " Version " VERSION "\n\n"
121 <                "Copyright (C) 1996-2001 Christian Bauer\n"
121 >                "Copyright (C) 1996-2003 Christian Bauer\n"
122                  "E-mail: Christian.Bauer@uni-mainz.de\n"
123                  "http://www.uni-mainz.de/~bauec002/\n\n"
124                  "This is free software with ABSOLUTELY NO WARRANTY.\n"
# Line 69 | Line 133 | int main(int argc, char **argv)
133          }
134          atexit(quit);
135          InitAll(argc, argv);
136 +        int32 speed = PrefsFindInt32("speed");
137  
138          // Parse non-option arguments
139          const char *file_name = NULL;
# Line 100 | Line 165 | int main(int argc, char **argv)
165                  if (song > number_of_songs)
166                          song = number_of_songs;
167                  SelectSong(song - 1);
103                SIDAdjustSpeed(PrefsFindInt32("speed")); // SelectSong resets this to 100%
168          }
169  
170 +        SIDAdjustSpeed(speed); // SelectSong and LoadPSIDFile() reset this to 100%
171 +
172          // Print file information
173          printf("Module Name: %s\n", module_name);
174          printf("Author     : %s\n", author_name);
# Line 166 | Line 232 | int main(int argc, char **argv)
232                  SDL_RWclose(f);
233                  printf("Output written to '%s'\n", outfile);
234  
235 +        } else if (PrefsFindBool("cwsid")) {
236 +
237 +                // Catweasel output, requires manual timing
238 +                while (true) {
239 +                        SIDExecute();
240 +
241 +                        SDL_Event e;
242 +                        if (SDL_PollEvent(&e)) {
243 +                                if (e.type == SDL_QUIT)
244 +                                        break;
245 +                        }
246 +                }
247 +
248          } else {
249  
250                  // Start replay and enter main loop
# Line 179 | Line 258 | int main(int argc, char **argv)
258                  }
259          }
260  
261 +        ExitAll();
262          return 0;
263   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines