Mercurial > hg > forks > pwpunix
annotate pwplib/pwplib-win.c @ 56:5d819ba6891c
More cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 27 May 2010 22:48:37 +0300 |
parents | 85671798fdb3 |
children |
rev | line source |
---|---|
0 | 1 #define __PWPLIB_C |
2 | |
3 #include "config.h" | |
4 | |
5 #include <stdio.h> | |
6 #include <stdlib.h> | |
7 | |
8 #include <windows.h> | |
9 | |
32 | 10 #ifdef DRIVE_SDL |
11 #include <SDL.h> | |
12 #endif | |
13 | |
0 | 14 #include "pwplib.h" |
54
85671798fdb3
Various code cleanups, cosmetics, warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
15 #include "sound.h" |
56 | 16 #include "video.h" |
0 | 17 |
32 | 18 static int sdl_init = 0; |
19 | |
0 | 20 /******************** random stuff *************************/ |
21 | |
22 extern void pwplib_dummy(); | |
23 #define pwp_dummy pwplib_dummy | |
24 | |
32 | 25 void pwpwrite(const char *fmt, ...) |
26 { | |
27 if (!pwplib.setup[SETUP_SHUTUP]) { | |
28 va_list ap; | |
29 va_start(ap, fmt); | |
30 vfprintf(stderr, fmt, ap); | |
31 va_end(ap); | |
32 | |
33 usleep(1000 * pwplib.set.infodelay); | |
34 } | |
35 } | |
36 | |
0 | 37 /********************* timer ******************************/ |
38 | |
39 #define TIMERHZ 72 | |
40 int pwp_w32_ticks() | |
41 { | |
32 | 42 #ifdef DRIVE_SDL |
43 if (sdl_init) { | |
44 int quit = 0; | |
45 SDL_Event event; | |
46 if (SDL_PollEvent(&event) >= 0) { | |
47 switch (event.type) { | |
48 case SDL_KEYDOWN: | |
49 if (event.key.keysym.sym == SDLK_ESCAPE) | |
50 quit = 1; | |
51 break; | |
52 case SDL_QUIT: | |
53 quit = 1; | |
54 break; | |
55 } | |
56 } | |
57 if (quit) { | |
58 SDL_Quit(); | |
59 pwplib_shutdown(); | |
60 exit(1); | |
61 } | |
62 return (SDL_GetTicks() * TIMERHZ) / 1000; | |
63 } | |
64 else | |
65 #endif | |
66 { | |
67 int ticks = GetTickCount(); | |
68 return ((ticks*TIMERHZ)/1000); | |
69 // (10000000/10441)); | |
70 } | |
0 | 71 } |
72 | |
73 /******************** initialization *********************/ | |
74 | |
75 int pwplib_initcore() | |
76 { | |
32 | 77 int sdl_flags = 0; |
78 | |
79 pwplib_init_common(); | |
0 | 80 |
32 | 81 #ifdef DRIVE_SDL |
82 if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) { | |
83 pwpwrite("* SDL could not be initialized (%s).\n", SDL_GetError()); | |
84 sdl_init = 0; | |
85 } else | |
86 sdl_init = 1; | |
0 | 87 |
32 | 88 if (sdl_init && !pwp_SDL_init()) |
89 { | |
90 sdl_init = 0; | |
91 SDL_Quit(); | |
92 } | |
54
85671798fdb3
Various code cleanups, cosmetics, warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
93 if (sdl_init && !pwp_SDL_audio_init()) |
32 | 94 { |
95 sdl_init = 0; | |
96 SDL_Quit(); | |
97 } | |
98 #endif | |
0 | 99 |
32 | 100 if (!sdl_init) { |
101 #ifdef DRIVE_WIN32 | |
102 win32con_init(); | |
103 win32snd_init(); | |
104 if (pwplib.dump_rast == pwplib_dummy && pwplib.dump_attr != pwplib_dummy) | |
105 pwplib.dump_rast = pwplib_dump_rast_plain; | |
106 #else | |
107 return 0; | |
108 #endif | |
109 } | |
0 | 110 |
32 | 111 pwplib.timerfunc = pwp_w32_ticks; |
112 | |
113 return 1; | |
0 | 114 } |
115 | |
116 /*********************************************************************/ | |
117 | |
118 void pwplib_startup() | |
119 { | |
32 | 120 /* just dummy here */ |
0 | 121 } |
122 | |
123 void pwplib_end() | |
124 { | |
125 pwplib_shutdown(); | |
126 | |
127 /* write some stuph */ | |
128 } | |
129 | |
32 | 130 #ifdef __WIN32 |
131 int usleep(int t) | |
132 { | |
133 Sleep(t / 1000); | |
134 } | |
135 #endif | |
136 | |
0 | 137 /***************************************************************/ |
138 | |
139 extern void pwplib_getopts(); | |
140 | |
141 int pwplib_init(int argc,char**argv) | |
142 { | |
32 | 143 pwplib.argc=argc; |
144 pwplib.argv=argv; | |
145 | |
146 pwplib_getopts(); | |
0 | 147 |
32 | 148 if (pwplib.setup[SETUP_WANTHELP]) |
149 { | |
50
e2b6a35bcb0c
Remove usage of malloc.h; Other misc cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
150 pwplib_printhelp(); |
32 | 151 exit(0); |
152 } | |
0 | 153 |
32 | 154 if (!pwplib_initcore()) |
155 { | |
156 pwpwrite("initialization failed!\n"); | |
157 return 0; | |
158 } | |
0 | 159 |
32 | 160 if (pwplib.setup[SETUP_WANTHELP]) |
161 return 0; | |
0 | 162 |
32 | 163 return 1; |
0 | 164 } |
165 |