sys_null.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 "errno.h"
  18. /*
  19. ===============================================================================
  20. FILE IO
  21. ===============================================================================
  22. */
  23. #define MAX_HANDLES 10
  24. FILE *sys_handles[MAX_HANDLES];
  25. int findhandle (void)
  26. {
  27. int i;
  28. for (i=1 ; i<MAX_HANDLES ; i++)
  29. if (!sys_handles[i])
  30. return i;
  31. Sys_Error ("out of handles");
  32. return -1;
  33. }
  34. /*
  35. ================
  36. filelength
  37. ================
  38. */
  39. int filelength (FILE *f)
  40. {
  41. int pos;
  42. int end;
  43. pos = ftell (f);
  44. fseek (f, 0, SEEK_END);
  45. end = ftell (f);
  46. fseek (f, pos, SEEK_SET);
  47. return end;
  48. }
  49. int Sys_FileOpenRead (char *path, int *hndl)
  50. {
  51. FILE *f;
  52. int i;
  53. i = findhandle ();
  54. f = fopen(path, "rb");
  55. if (!f)
  56. {
  57. *hndl = -1;
  58. return -1;
  59. }
  60. sys_handles[i] = f;
  61. *hndl = i;
  62. return filelength(f);
  63. }
  64. int Sys_FileOpenWrite (char *path)
  65. {
  66. FILE *f;
  67. int i;
  68. i = findhandle ();
  69. f = fopen(path, "wb");
  70. if (!f)
  71. Sys_Error ("Error opening %s: %s", path,strerror(errno));
  72. sys_handles[i] = f;
  73. return i;
  74. }
  75. void Sys_FileClose (int handle)
  76. {
  77. fclose (sys_handles[handle]);
  78. sys_handles[handle] = NULL;
  79. }
  80. void Sys_FileSeek (int handle, int position)
  81. {
  82. fseek (sys_handles[handle], position, SEEK_SET);
  83. }
  84. int Sys_FileRead (int handle, void *dest, int count)
  85. {
  86. return fread (dest, 1, count, sys_handles[handle]);
  87. }
  88. int Sys_FileWrite (int handle, void *data, int count)
  89. {
  90. return fwrite (data, 1, count, sys_handles[handle]);
  91. }
  92. int Sys_FileTime (char *path)
  93. {
  94. FILE *f;
  95. f = fopen(path, "rb");
  96. if (f)
  97. {
  98. fclose(f);
  99. return 1;
  100. }
  101. return -1;
  102. }
  103. void Sys_mkdir (char *path)
  104. {
  105. }
  106. /*
  107. ===============================================================================
  108. SYSTEM IO
  109. ===============================================================================
  110. */
  111. void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
  112. {
  113. }
  114. void Sys_Error (char *error, ...)
  115. {
  116. va_list argptr;
  117. printf ("Sys_Error: ");
  118. va_start (argptr,error);
  119. vprintf (error,argptr);
  120. va_end (argptr);
  121. printf ("\n");
  122. exit (1);
  123. }
  124. void Sys_Printf (char *fmt, ...)
  125. {
  126. va_list argptr;
  127. va_start (argptr,fmt);
  128. vprintf (fmt,argptr);
  129. va_end (argptr);
  130. }
  131. void Sys_Quit (void)
  132. {
  133. exit (0);
  134. }
  135. double Sys_FloatTime (void)
  136. {
  137. static double t;
  138. t += 0.1;
  139. return t;
  140. }
  141. char *Sys_ConsoleInput (void)
  142. {
  143. return NULL;
  144. }
  145. void Sys_Sleep (void)
  146. {
  147. }
  148. void Sys_SendKeyEvents (void)
  149. {
  150. }
  151. void Sys_HighFPPrecision (void)
  152. {
  153. }
  154. void Sys_LowFPPrecision (void)
  155. {
  156. }
  157. //=============================================================================
  158. void main (int argc, char **argv)
  159. {
  160. static quakeparms_t parms;
  161. parms.memsize = 8*1024*1024;
  162. parms.membase = malloc (parms.memsize);
  163. parms.basedir = ".";
  164. COM_InitArgv (argc, argv);
  165. parms.argc = com_argc;
  166. parms.argv = com_argv;
  167. printf ("Host_Init\n");
  168. Host_Init (&parms);
  169. while (1)
  170. {
  171. Host_Frame (0.1);
  172. }
  173. }