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