]> icculus.org git repositories - divverent/darkplaces.git/blob - sys_wind.c
add ALSA support
[divverent/darkplaces.git] / sys_wind.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // sys_null.h -- null system driver to aid porting efforts
21
22 #include "quakedef.h"
23 #include "winquake.h"
24 #include "errno.h"
25 #include <sys\types.h>
26 #include <sys\timeb.h>
27
28
29 /*
30 ===============================================================================
31
32 FILE IO
33
34 ===============================================================================
35 */
36
37 // LordHavoc: 256 pak files (was 10)
38 #define MAX_HANDLES             256
39 FILE    *sys_handles[MAX_HANDLES];
40
41 int             findhandle (void)
42 {
43         int             i;
44         
45         for (i=1 ; i<MAX_HANDLES ; i++)
46                 if (!sys_handles[i])
47                         return i;
48         Sys_Error ("out of handles");
49         return -1;
50 }
51
52 /*
53 ================
54 filelength
55 ================
56 */
57 int filelength (FILE *f)
58 {
59         int             pos;
60         int             end;
61
62         pos = ftell (f);
63         fseek (f, 0, SEEK_END);
64         end = ftell (f);
65         fseek (f, pos, SEEK_SET);
66
67         return end;
68 }
69
70 int Sys_FileOpenRead (char *path, int *hndl)
71 {
72         FILE    *f;
73         int             i;
74         
75         i = findhandle ();
76
77         f = fopen(path, "rb");
78         if (!f)
79         {
80                 *hndl = -1;
81                 return -1;
82         }
83         sys_handles[i] = f;
84         *hndl = i;
85         
86         return filelength(f);
87 }
88
89 int Sys_FileOpenWrite (char *path)
90 {
91         FILE    *f;
92         int             i;
93         
94         i = findhandle ();
95
96         f = fopen(path, "wb");
97         if (!f)
98                 Sys_Error ("Error opening %s: %s", path,strerror(errno));
99         sys_handles[i] = f;
100         
101         return i;
102 }
103
104 void Sys_FileClose (int handle)
105 {
106         fclose (sys_handles[handle]);
107         sys_handles[handle] = NULL;
108 }
109
110 void Sys_FileSeek (int handle, int position)
111 {
112         fseek (sys_handles[handle], position, SEEK_SET);
113 }
114
115 int Sys_FileRead (int handle, void *dest, int count)
116 {
117         return fread (dest, 1, count, sys_handles[handle]);
118 }
119
120 int Sys_FileWrite (int handle, void *data, int count)
121 {
122         return fwrite (data, 1, count, sys_handles[handle]);
123 }
124
125 int     Sys_FileTime (char *path)
126 {
127         FILE    *f;
128         
129         f = fopen(path, "rb");
130         if (f)
131         {
132                 fclose(f);
133                 return 1;
134         }
135         
136         return -1;
137 }
138
139 void Sys_mkdir (char *path)
140 {
141 }
142
143
144 /*
145 ===============================================================================
146
147 SYSTEM IO
148
149 ===============================================================================
150 */
151
152 void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
153 {
154 }
155
156
157 void Sys_DebugLog(char *file, char *fmt, ...)
158 {
159 }
160
161 void Sys_Error (char *error, ...)
162 {
163         va_list         argptr;
164         char            text[1024];
165
166         va_start (argptr,error);
167         vsprintf (text, error,argptr);
168         va_end (argptr);
169
170 //    MessageBox(NULL, text, "Error", 0 /* MB_OK */ );
171         printf ("ERROR: %s\n", text);
172
173         exit (1);
174 }
175
176 void Sys_Printf (char *fmt, ...)
177 {
178         va_list         argptr;
179         
180         va_start (argptr,fmt);
181         vprintf (fmt,argptr);
182         va_end (argptr);
183 }
184
185 void Sys_Quit (void)
186 {
187         exit (0);
188 }
189
190 double Sys_FloatTime (void)
191 {
192         double t;
193     struct _timeb tstruct;
194         static int      starttime;
195
196         _ftime( &tstruct );
197  
198         if (!starttime)
199                 starttime = tstruct.time;
200         t = (tstruct.time-starttime) + tstruct.millitm*0.001;
201         
202         return t;
203 }
204
205 void Sys_Sleep (void)
206 {
207 }
208
209
210 void Sys_SendKeyEvents (void)
211 {
212 }
213
214 void Sys_HighFPPrecision (void)
215 {
216 }
217
218 void Sys_LowFPPrecision (void)
219 {
220 }
221
222 char *Sys_ConsoleInput (void)
223 {
224         static char     text[256];
225         static int              len;
226         INPUT_RECORD    recs[1024];
227         int             count;
228         int             i;
229         int             c;
230
231         // read a line out
232         while (_kbhit())
233         {
234                 c = _getch();
235                 putch (c);
236                 if (c == '\r')
237                 {
238                         text[len] = 0;
239                         putch ('\n');
240                         len = 0;
241                         return text;
242                 }
243                 if (c == 8)
244                 {
245                         putch (' ');
246                         putch (c);
247                         len--;
248                         text[len] = 0;
249                         continue;
250                 }
251                 text[len] = c;
252                 len++;
253                 text[len] = 0;
254                 if (len == sizeof(text))
255                         len = 0;
256         }
257
258         return NULL;
259 }
260
261
262
263 /*
264 ==================
265 main
266
267 ==================
268 */
269 char    *newargv[256];
270
271 int main (int argc, char **argv)
272 {
273     MSG        msg;
274         quakeparms_t    parms;
275         double                  time, oldtime;
276         static  char    cwd[1024];
277
278         memset (&parms, 0, sizeof(parms));
279
280         parms.memsize = 16384*1024;
281         parms.membase = malloc (parms.memsize);
282
283         _getcwd (cwd, sizeof(cwd));
284         if (cwd[strlen(cwd)-1] == '\\')
285                 cwd[strlen(cwd)-1] = 0;
286         parms.basedir = cwd; //"f:/quake";
287 //      parms.basedir = "f:\\quake";
288
289         COM_InitArgv (argc, argv);
290
291         // dedicated server ONLY!
292         if (!COM_CheckParm ("-dedicated"))
293         {
294                 memcpy (newargv, argv, argc*4);
295                 newargv[argc] = "-dedicated";
296                 argc++;
297                 argv = newargv;
298                 COM_InitArgv (argc, argv);
299         }
300
301         parms.argc = argc;
302         parms.argv = argv;
303
304         printf ("Host_Init\n");
305         Host_Init (&parms);
306
307         oldtime = Sys_FloatTime ();
308
309     /* main window message loop */
310         while (1)
311         {
312                 time = Sys_FloatTime();
313                 if (time - oldtime < sys_ticrate.value )
314                 {
315                         Sleep(1);
316                         continue;
317                 }
318
319                 Host_Frame ( time - oldtime );
320                 oldtime = time;
321         }
322
323     /* return success of application */
324     return TRUE;
325 }
326