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 |
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 |
|
|
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" |
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 |
258 |
|
} |
259 |
|
} |
260 |
|
|
261 |
+ |
ExitAll(); |
262 |
|
return 0; |
263 |
|
} |