sys_wind.c 5.0 KB

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