Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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. #define MAX_HANDLES             10
  38. FILE    *sys_handles[MAX_HANDLES];
  39.  
  40. int             findhandle (void)
  41. {
  42.         int             i;
  43.        
  44.         for (i=1 ; i<MAX_HANDLES ; i++)
  45.                 if (!sys_handles[i])
  46.                         return i;
  47.         Sys_Error ("out of handles");
  48.         return -1;
  49. }
  50.  
  51. /*
  52. ================
  53. filelength
  54. ================
  55. */
  56. int filelength (FILE *f)
  57. {
  58.         int             pos;
  59.         int             end;
  60.  
  61.         pos = ftell (f);
  62.         fseek (f, 0, SEEK_END);
  63.         end = ftell (f);
  64.         fseek (f, pos, SEEK_SET);
  65.  
  66.         return end;
  67. }
  68.  
  69. int Sys_FileOpenRead (char *path, int *hndl)
  70. {
  71.         FILE    *f;
  72.         int             i;
  73.        
  74.         i = findhandle ();
  75.  
  76.         f = fopen(path, "rb");
  77.         if (!f)
  78.         {
  79.                 *hndl = -1;
  80.                 return -1;
  81.         }
  82.         sys_handles[i] = f;
  83.         *hndl = i;
  84.        
  85.         return filelength(f);
  86. }
  87.  
  88. int Sys_FileOpenWrite (char *path)
  89. {
  90.         FILE    *f;
  91.         int             i;
  92.        
  93.         i = findhandle ();
  94.  
  95.         f = fopen(path, "wb");
  96.         if (!f)
  97.                 Sys_Error ("Error opening %s: %s", path,strerror(errno));
  98.         sys_handles[i] = f;
  99.        
  100.         return i;
  101. }
  102.  
  103. void Sys_FileClose (int handle)
  104. {
  105.         fclose (sys_handles[handle]);
  106.         sys_handles[handle] = NULL;
  107. }
  108.  
  109. void Sys_FileSeek (int handle, int position)
  110. {
  111.         fseek (sys_handles[handle], position, SEEK_SET);
  112. }
  113.  
  114. int Sys_FileRead (int handle, void *dest, int count)
  115. {
  116.         return fread (dest, 1, count, sys_handles[handle]);
  117. }
  118.  
  119. int Sys_FileWrite (int handle, void *data, int count)
  120. {
  121.         return fwrite (data, 1, count, sys_handles[handle]);
  122. }
  123.  
  124. int     Sys_FileTime (char *path)
  125. {
  126.         FILE    *f;
  127.        
  128.         f = fopen(path, "rb");
  129.         if (f)
  130.         {
  131.                 fclose(f);
  132.                 return 1;
  133.         }
  134.        
  135.         return -1;
  136. }
  137.  
  138. void Sys_mkdir (char *path)
  139. {
  140. }
  141.  
  142.  
  143. /*
  144. ===============================================================================
  145.  
  146. SYSTEM IO
  147.  
  148. ===============================================================================
  149. */
  150.  
  151. void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
  152. {
  153. }
  154.  
  155.  
  156. void Sys_DebugLog(char *file, char *fmt, ...)
  157. {
  158. }
  159.  
  160. void Sys_Error (char *error, ...)
  161. {
  162.         va_list         argptr;
  163.         char            text[1024];
  164.  
  165.         va_start (argptr,error);
  166.         vsprintf (text, error,argptr);
  167.         va_end (argptr);
  168.  
  169. //    MessageBox(NULL, text, "Error", 0 /* MB_OK */ );
  170.         printf ("ERROR: %s\n", text);
  171.  
  172.         exit (1);
  173. }
  174.  
  175. void Sys_Printf (char *fmt, ...)
  176. {
  177.         va_list         argptr;
  178.        
  179.         va_start (argptr,fmt);
  180.         vprintf (fmt,argptr);
  181.         va_end (argptr);
  182. }
  183.  
  184. void Sys_Quit (void)
  185. {
  186.         exit (0);
  187. }
  188.  
  189. double Sys_FloatTime (void)
  190. {
  191.         double t;
  192.     struct _timeb tstruct;
  193.         static int      starttime;
  194.  
  195.         _ftime( &tstruct );
  196.  
  197.         if (!starttime)
  198.                 starttime = tstruct.time;
  199.         t = (tstruct.time-starttime) + tstruct.millitm*0.001;
  200.        
  201.         return t;
  202. }
  203.  
  204. void Sys_Sleep (void)
  205. {
  206. }
  207.  
  208.  
  209. void Sys_SendKeyEvents (void)
  210. {
  211. }
  212.  
  213. void Sys_HighFPPrecision (void)
  214. {
  215. }
  216.  
  217. void Sys_LowFPPrecision (void)
  218. {
  219. }
  220.  
  221. char *Sys_ConsoleInput (void)
  222. {
  223.         static char     text[256];
  224.         static int              len;
  225.         INPUT_RECORD    recs[1024];
  226.         int             count;
  227.         int             i;
  228.         int             c;
  229.  
  230.         // read a line out
  231.         while (_kbhit())
  232.         {
  233.                 c = _getch();
  234.                 putch (c);
  235.                 if (c == '\r')
  236.                 {
  237.                         text[len] = 0;
  238.                         putch ('\n');
  239.                         len = 0;
  240.                         return text;
  241.                 }
  242.                 if (c == 8)
  243.                 {
  244.                         putch (' ');
  245.                         putch (c);
  246.                         len--;
  247.                         text[len] = 0;
  248.                         continue;
  249.                 }
  250.                 text[len] = c;
  251.                 len++;
  252.                 text[len] = 0;
  253.                 if (len == sizeof(text))
  254.                         len = 0;
  255.         }
  256.  
  257.         return NULL;
  258. }
  259.  
  260.  
  261.  
  262. /*
  263. ==================
  264. main
  265.  
  266. ==================
  267. */
  268. char    *newargv[256];
  269.  
  270. int main (int argc, char **argv)
  271. {
  272.     MSG        msg;
  273.         quakeparms_t    parms;
  274.         double                  time, oldtime;
  275.         static  char    cwd[1024];
  276.  
  277.         memset (&parms, 0, sizeof(parms));
  278.  
  279.         parms.memsize = 16384*1024;
  280.         parms.membase = malloc (parms.memsize);
  281.  
  282.         _getcwd (cwd, sizeof(cwd));
  283.         if (cwd[Q_strlen(cwd)-1] == '\\')
  284.                 cwd[Q_strlen(cwd)-1] = 0;
  285.         parms.basedir = cwd; //"f:/quake";
  286. //      parms.basedir = "f:\\quake";
  287.  
  288.         COM_InitArgv (argc, argv);
  289.  
  290.         // dedicated server ONLY!
  291.         if (!COM_CheckParm ("-dedicated"))
  292.         {
  293.                 memcpy (newargv, argv, argc*4);
  294.                 newargv[argc] = "-dedicated";
  295.                 argc++;
  296.                 argv = newargv;
  297.                 COM_InitArgv (argc, argv);
  298.         }
  299.  
  300.         parms.argc = argc;
  301.         parms.argv = argv;
  302.  
  303.         printf ("Host_Init\n");
  304.         Host_Init (&parms);
  305.  
  306.         oldtime = Sys_FloatTime ();
  307.  
  308.     /* main window message loop */
  309.         while (1)
  310.         {
  311.                 time = Sys_FloatTime();
  312.                 if (time - oldtime < sys_ticrate.value )
  313.                 {
  314.                         Sleep(1);
  315.                         continue;
  316.                 }
  317.  
  318.                 Host_Frame ( time - oldtime );
  319.                 oldtime = time;
  320.         }
  321.  
  322.     /* return success of application */
  323.     return TRUE;
  324. }
  325.  
  326.