]> icculus.org git repositories - divverent/darkplaces.git/blob - sys_wind.c
build number 101
[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 #if NOTUSED
153 void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
154 {
155 }
156 #endif
157
158
159 void Sys_DebugLog(char *file, char *fmt, ...)
160 {
161 }
162
163 void Sys_Error (char *error, ...)
164 {
165         va_list         argptr;
166         char            text[1024];
167
168         va_start (argptr,error);
169         vsprintf (text, error,argptr);
170         va_end (argptr);
171
172 //    MessageBox(NULL, text, "Error", 0 /* MB_OK */ );
173         printf ("ERROR: %s\n", text);
174
175         exit (1);
176 }
177
178 void Sys_Printf (char *fmt, ...)
179 {
180         va_list         argptr;
181         
182         va_start (argptr,fmt);
183         vprintf (fmt,argptr);
184         va_end (argptr);
185 }
186
187 void Sys_Quit (void)
188 {
189         exit (0);
190 }
191
192 double Sys_FloatTime (void)
193 {
194         double t;
195     struct _timeb tstruct;
196         static int      starttime;
197
198         _ftime( &tstruct );
199  
200         if (!starttime)
201                 starttime = tstruct.time;
202         t = (tstruct.time-starttime) + tstruct.millitm*0.001;
203         
204         return t;
205 }
206
207 void Sys_Sleep (void)
208 {
209 }
210
211
212 void Sys_SendKeyEvents (void)
213 {
214 }
215
216 char *Sys_ConsoleInput (void)
217 {
218         static char     text[256];
219         static int              len;
220         INPUT_RECORD    recs[1024];
221         int             count;
222         int             i;
223         int             c;
224
225         // read a line out
226         while (_kbhit())
227         {
228                 c = _getch();
229                 putch (c);
230                 if (c == '\r')
231                 {
232                         text[len] = 0;
233                         putch ('\n');
234                         len = 0;
235                         return text;
236                 }
237                 if (c == 8)
238                 {
239                         putch (' ');
240                         putch (c);
241                         len--;
242                         text[len] = 0;
243                         continue;
244                 }
245                 text[len] = c;
246                 len++;
247                 text[len] = 0;
248                 if (len == sizeof(text))
249                         len = 0;
250         }
251
252         return NULL;
253 }
254
255
256
257 /*
258 ==================
259 main
260
261 ==================
262 */
263 char    *newargv[256];
264
265 int main (int argc, char **argv)
266 {
267     MSG        msg;
268         double                  time, oldtime;
269         static  char    cwd[1024];
270
271         memset (&host_parms, 0, sizeof(host_parms));
272
273         host_parms.memsize = DEFAULTMEM * 1024*1024;
274         host_parms.membase = qmalloc(parms.memsize);
275
276         _getcwd (cwd, sizeof(cwd));
277         if (cwd[strlen(cwd)-1] == '\\')
278                 cwd[strlen(cwd)-1] = 0;
279         host_parms.basedir = cwd;
280
281         COM_InitArgv (argc, argv);
282
283         // dedicated server ONLY!
284         if (!COM_CheckParm ("-dedicated"))
285         {
286                 memcpy (newargv, argv, argc*4);
287                 newargv[argc] = "-dedicated";
288                 argc++;
289                 argv = newargv;
290                 COM_InitArgv (argc, argv);
291         }
292
293         host_parms.argc = argc;
294         host_parms.argv = argv;
295
296         printf ("Host_Init\n");
297         Host_Init ();
298
299         oldtime = Sys_FloatTime ();
300
301     /* main window message loop */
302         while (1)
303         {
304                 time = Sys_FloatTime();
305                 if (time - oldtime < sys_ticrate.value )
306                 {
307                         Sleep(1);
308                         continue;
309                 }
310
311                 Host_Frame ( time - oldtime );
312                 oldtime = time;
313         }
314
315     /* return success of application */
316     return true;
317 }
318