-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
144 lines (124 loc) · 3.22 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* main.c - Main program's entry point
*
* Copyright (C) 2020-2022 M374LX <[email protected]>
*
* This file is part of Pseym.
*
* Pseym is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Pseym is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with Pseym; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#define VERSION "0.2"
#include <SDL2/SDL.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#endif
//From ui.c
bool ui_init();
void ui_shutdown();
bool ui_handle_events();
void ui_draw();
//From audio.c
bool audio_init();
void audio_shutdown();
bool audio_buffer_full();
void audio_update();
void help(const char* progname)
{
const char* str =
"Options:\n"
"-h Show this usage information and exit.\n"
"-v Show version and license information and exit.\n"
"\n"
"By not using any options, the program runs in normal UI mode. The list of\n"
"keys can be found in the file README.md.\n\n";
#ifdef _WIN32
MessageBox(NULL, str, "Pseym", 0);
#else
printf("Usage: %s [options]\n\n", progname);
printf(str);
#endif
}
void version()
{
const char* str =
"Pseym " VERSION "\n"
"\n"
"Copyright (C) 2020-2022 M374LX <[email protected]>\n"
"\n"
"For a more complete list of authors, see the file AUTHORS.\n"
"\n"
"Pseym is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2 of the License, or\n"
"(at your option) any later version.\n"
"\n"
"Pseym is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"GNU General Public License for more details.\n"
"\n"
"You should have received a copy of the GNU General Public License along\n"
"with Pseym; if not, write to the Free Software Foundation, Inc.,\n"
"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n"
"\n";
#ifdef _WIN32
MessageBox(NULL, str, "Pseym", 0);
#else
printf(str);
#endif
}
int main(int argc, char* argv[])
{
bool quit = false;
int i;
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 'h':
help(argv[0]);
return 0;
case 'v':
version();
return 0;
}
}
}
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
printf("SDL initialization failed.\n");
return 1;
}
if (!audio_init()) {
printf("Failed to initialize audio.\n");
return 1;
}
if (!ui_init()) {
return 1;
}
while (!quit) {
quit = !ui_handle_events();
if (!audio_buffer_full()) {
ui_draw();
audio_update();
}
}
audio_shutdown();
ui_shutdown();
SDL_Quit();
return 0;
}