/[cebix]/SIDPlayer/src/main_sdl.cpp
ViewVC logotype

Annotation of /SIDPlayer/src/main_sdl.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (hide annotations)
2001-04-01T12:13:49Z (17 years, 5 months ago) by cebix
Branch: MAIN
Changes since 1.7: +14 -13 lines
File MIME type: text/x-c++src
- PrefsInit() removes processed options
- changes to command line argument handling

1 cebix 1.1 /*
2     * main_sdl.cpp - SIDPlayer SDL main program
3     *
4 cebix 1.6 * SIDPlayer (C) Copyright 1996-2001 Christian Bauer
5 cebix 1.1 *
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
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #include "sys.h"
22    
23     #include <SDL.h>
24     #include <stdio.h>
25     #include <stdlib.h>
26    
27     #include "main.h"
28 cebix 1.4 #include "prefs.h"
29     #include "sid.h"
30 cebix 1.1
31    
32     /*
33     * Main program
34     */
35    
36     static void usage(const char *prg_name)
37     {
38 cebix 1.7 printf("Usage: %s [OPTION...] FILE [song_number]\n", prg_name);
39 cebix 1.5 PrefsPrintUsage();
40 cebix 1.1 exit(0);
41     }
42    
43     static void quit(void)
44     {
45     ExitAll();
46     SDL_Quit();
47     }
48    
49     int main(int argc, char **argv)
50     {
51     // Print banner
52     printf(
53     PACKAGE " Version " VERSION "\n\n"
54 cebix 1.5 "Copyright (C) 1996-2001 Christian Bauer\n"
55 cebix 1.1 "E-mail: Christian.Bauer@uni-mainz.de\n"
56     "http://www.uni-mainz.de/~bauec002/\n\n"
57     "This is free software with ABSOLUTELY NO WARRANTY.\n"
58     "You are welcome to redistribute it under certain conditions.\n"
59     "For details, see the file COPYING.\n\n"
60     );
61    
62 cebix 1.5 // Initialize everything
63     if (SDL_Init(SDL_INIT_AUDIO) < 0) {
64     fprintf(stderr, "Couldn't initialize SDL (%s)\n", SDL_GetError());
65     exit(1);
66     }
67     atexit(quit);
68     InitAll(argc, argv);
69     int32 selected_speed = PrefsFindInt32("speed");
70    
71     // Parse non-option arguments
72 cebix 1.8 const char *file_name = NULL;
73 cebix 1.1 int song = 0;
74 cebix 1.8 for (int i=1; i<argc; i++) {
75     if (strcmp(argv[i], "--help") == 0)
76     usage(argv[0]);
77     else if (argv[i][0] == '-') {
78     fprintf(stderr, "Unrecognized option '%s'\n", argv[i]);
79     usage(argv[0]);
80     } else {
81     if (file_name == NULL)
82     file_name = argv[i]; // First non-option argument is file name
83     else
84     song = atoi(argv[i]); // Second non-option argument is song number
85 cebix 1.3 }
86     }
87 cebix 1.8 if (file_name == NULL)
88     usage(argv[0]);
89 cebix 1.1
90     // Load given PSID file
91 cebix 1.3 if (!LoadPSIDFile(file_name)) {
92     fprintf(stderr, "Couldn't load '%s' (not a PSID file?)\n", file_name);
93 cebix 1.1 exit(1);
94     }
95    
96     // Select song
97     if (song > 0) {
98     if (song > number_of_songs)
99     song = number_of_songs;
100     SelectSong(song - 1);
101     }
102    
103     // Print file information
104     printf("Module Name: %s\n", module_name);
105     printf("Author : %s\n", author_name);
106     printf("Copyright : %s\n\n", copyright_info);
107     printf("Playing song %d/%d\n", current_song + 1, number_of_songs);
108    
109     // Start replay and enter main loop
110 cebix 1.5 SIDAdjustSpeed(selected_speed); // SelectSong resets this to 100%
111 cebix 1.1 SDL_PauseAudio(false);
112     while (true) {
113     SDL_Event e;
114     if (SDL_WaitEvent(&e)) {
115     if (e.type == SDL_QUIT)
116     break;
117     }
118     }
119    
120     return 0;
121     }

  ViewVC Help
Powered by ViewVC 1.1.26