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"
|
|
15
|
32
|
16 static int sdl_init = 0;
|
|
17
|
0
|
18 /******************** random stuff *************************/
|
|
19
|
|
20 extern void pwplib_dummy();
|
|
21 #define pwp_dummy pwplib_dummy
|
|
22
|
32
|
23 void pwpwrite(const char *fmt, ...)
|
|
24 {
|
|
25 if (!pwplib.setup[SETUP_SHUTUP]) {
|
|
26 va_list ap;
|
|
27 va_start(ap, fmt);
|
|
28 vfprintf(stderr, fmt, ap);
|
|
29 va_end(ap);
|
|
30
|
|
31 usleep(1000 * pwplib.set.infodelay);
|
|
32 }
|
|
33 }
|
|
34
|
0
|
35 /********************* timer ******************************/
|
|
36
|
|
37 #define TIMERHZ 72
|
|
38 int pwp_w32_ticks()
|
|
39 {
|
32
|
40 #ifdef DRIVE_SDL
|
|
41 if (sdl_init) {
|
|
42 int quit = 0;
|
|
43 SDL_Event event;
|
|
44 if (SDL_PollEvent(&event) >= 0) {
|
|
45 switch (event.type) {
|
|
46 case SDL_KEYDOWN:
|
|
47 if (event.key.keysym.sym == SDLK_ESCAPE)
|
|
48 quit = 1;
|
|
49 break;
|
|
50 case SDL_QUIT:
|
|
51 quit = 1;
|
|
52 break;
|
|
53 }
|
|
54 }
|
|
55 if (quit) {
|
|
56 SDL_Quit();
|
|
57 pwplib_shutdown();
|
|
58 exit(1);
|
|
59 }
|
|
60 return (SDL_GetTicks() * TIMERHZ) / 1000;
|
|
61 }
|
|
62 else
|
|
63 #endif
|
|
64 {
|
|
65 int ticks = GetTickCount();
|
|
66 return ((ticks*TIMERHZ)/1000);
|
|
67 // (10000000/10441));
|
|
68 }
|
0
|
69 }
|
|
70
|
|
71 /******************** initialization *********************/
|
|
72
|
|
73 int pwplib_initcore()
|
|
74 {
|
32
|
75 int sdl_flags = 0;
|
|
76
|
|
77 pwplib_init_common();
|
0
|
78
|
32
|
79 #ifdef DRIVE_SDL
|
|
80 if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) {
|
|
81 pwpwrite("* SDL could not be initialized (%s).\n", SDL_GetError());
|
|
82 sdl_init = 0;
|
|
83 } else
|
|
84 sdl_init = 1;
|
0
|
85
|
32
|
86 if (sdl_init && !pwp_SDL_init())
|
|
87 {
|
|
88 sdl_init = 0;
|
|
89 SDL_Quit();
|
|
90 }
|
|
91 if (sdl_init && !pwp_sdlaudio_init())
|
|
92 {
|
|
93 sdl_init = 0;
|
|
94 SDL_Quit();
|
|
95 }
|
|
96 #endif
|
0
|
97
|
32
|
98 if (!sdl_init) {
|
|
99 #ifdef DRIVE_WIN32
|
|
100 win32con_init();
|
|
101 win32snd_init();
|
|
102 if (pwplib.dump_rast == pwplib_dummy && pwplib.dump_attr != pwplib_dummy)
|
|
103 pwplib.dump_rast = pwplib_dump_rast_plain;
|
|
104 #else
|
|
105 return 0;
|
|
106 #endif
|
|
107 }
|
0
|
108
|
32
|
109 pwplib.timerfunc = pwp_w32_ticks;
|
|
110
|
|
111 return 1;
|
0
|
112 }
|
|
113
|
|
114 /*********************************************************************/
|
|
115
|
|
116 void pwplib_startup()
|
|
117 {
|
32
|
118 /* just dummy here */
|
0
|
119 }
|
|
120
|
|
121 void pwplib_end()
|
|
122 {
|
|
123 pwplib_shutdown();
|
|
124
|
|
125 /* write some stuph */
|
|
126 }
|
|
127
|
32
|
128 #ifdef __WIN32
|
|
129 int usleep(int t)
|
|
130 {
|
|
131 Sleep(t / 1000);
|
|
132 }
|
|
133 #endif
|
|
134
|
0
|
135 /***************************************************************/
|
|
136
|
|
137 extern void pwplib_getopts();
|
|
138
|
|
139 int pwplib_init(int argc,char**argv)
|
|
140 {
|
32
|
141 pwplib.argc=argc;
|
|
142 pwplib.argv=argv;
|
|
143
|
|
144 pwplib_getopts();
|
0
|
145
|
32
|
146 if (pwplib.setup[SETUP_WANTHELP])
|
|
147 {
|
|
148 printhelp();
|
|
149 exit(0);
|
|
150 }
|
0
|
151
|
32
|
152 if (!pwplib_initcore())
|
|
153 {
|
|
154 pwpwrite("initialization failed!\n");
|
|
155 return 0;
|
|
156 }
|
0
|
157
|
32
|
158 if (pwplib.setup[SETUP_WANTHELP])
|
|
159 return 0;
|
0
|
160
|
32
|
161 return 1;
|
0
|
162 }
|
|
163
|