-
Notifications
You must be signed in to change notification settings - Fork 2
/
dc_sys.c
384 lines (309 loc) · 7.76 KB
/
dc_sys.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// dc_sys.c -- Dreamcast/KOS System Driver
#include "quakedef.h"
#include "errno.h"
#include <SDL/SDL.h>
#include <arch/timer.h>
#include <arch/arch.h>
#include <dc/cdrom.h>
#include "cdaudio.h"
static qboolean wasPlaying = false;
extern qboolean cdPlaying;
qboolean isDedicated = false;
int noconinput = 0;
cvar_t sys_linerefresh = {"sys_linerefresh","0"};// set for entity display
cvar_t sys_nostdout = {"sys_nostdout","0"};
/*
===============================================================================
FILE IO
===============================================================================
*/
#define MAX_HANDLES 50 // 4.8
FILE *sys_handles[MAX_HANDLES];
int findhandle (void)
{
int i;
for (i=1 ; i<MAX_HANDLES ; i++)
if (!sys_handles[i])
return i;
Sys_Error ("out of handles");
return -1;
}
/*
================
filelength
================
*/
int filelength (FILE *f)
{
// bgmvolume.value = 0;
if (CD_PLAYING) {
// bgmvolume.value = 0;
// CDAudio_Pause();
// bgmvolume.value = 1;
wasPlaying = true;
}
int pos;
int end;
pos = ftell (f);
fseek (f, 0, SEEK_END);
end = ftell (f);
fseek (f, pos, SEEK_SET);
// bgmvolume.value = 1;
if (CD_PLAYING) {
bgmvolume.value = 1;
CDAudio_Update();
CDAudio_Resume();
wasPlaying = false;
}
return end;
}
int Sys_FileOpenRead (char *path, int *hndl)
{
// bgmvolume.value = 1;
if (CD_PLAYING) {
// bgmvolume.value = 1;
// CDAudio_Pause();
wasPlaying = true;
}
FILE *f;
int i;
i = findhandle ();
f = fopen(path, "rb");
if (!f)
{
*hndl = -1;
return -1;
}
sys_handles[i] = f;
*hndl = i;
// bgmvolume.value = 1;
if (CD_PLAYING) {
bgmvolume.value = 1;
CDAudio_Update();
CDAudio_Resume();
wasPlaying = false;
}
return filelength(f);
}
int Sys_FileOpenWrite (char *path)
{
// bgmvolume.value = 1;
if (CD_PLAYING) {
// bgmvolume.value = 1;
// CDAudio_Pause();
wasPlaying = true;
}
FILE *f;
int i;
i = findhandle ();
f = fopen(path, "wb");
if (!f)
Sys_Error ("Error opening %s", path);
sys_handles[i] = f;
// bgmvolume.value = 1;
if (CD_PLAYING) {
bgmvolume.value = 1;
CDAudio_Update();
CDAudio_Resume();
wasPlaying = false;
}
return i;
}
void Sys_FileClose (int handle)
{
bgmvolume.value = 0;
fclose (sys_handles[handle]);
sys_handles[handle] = NULL;
// bgmvolume.value = 1;
}
void Sys_LineRefresh(void)
{
}
void moncontrol(int x)
{
}
void Sys_FileSeek (int handle, int position)
{
bgmvolume.value = 1;
fseek (sys_handles[handle], position, SEEK_SET);
// bgmvolume.value = 1;
}
int Sys_FileRead (int handle, void *dest, int count)
{
// bgmvolume.value = 1;
if (CD_PLAYING) {
// bgmvolume.value = 1;
// CDAudio_Pause();
wasPlaying = true;
}
return fread (dest, 1, count, sys_handles[handle]);
// bgmvolume.value = 1;
if (CD_PLAYING) {
bgmvolume.value = 1;
CDAudio_Update();
CDAudio_Resume();
wasPlaying = false;
}
}
int Sys_FileWrite (int handle, void *data, int count)
{
// bgmvolume.value = 0;
if (CD_PLAYING) {
// bgmvolume.value = 1;
// CDAudio_Pause();
wasPlaying = true;
}
return fwrite (data, 1, count, sys_handles[handle]);
// bgmvolume.value = 1;
if (CD_PLAYING) {
bgmvolume.value = 1;
CDAudio_Update();
CDAudio_Resume();
wasPlaying = false;
}
}
int Sys_FileTime (char *path)
{
FILE *f;
f = fopen(path, "rb");
if (f)
{
fclose(f);
return 1;
}
return -1;
}
void Sys_mkdir (char *path)
{
}
/*
===============================================================================
SYSTEM IO
===============================================================================
*/
void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
{
}
void Sys_Error (char *error, ...)
{
va_list argptr;
char strbuffer[2048];
printf ("Sys_Error: ");
va_start (argptr, error);
vsprintf (strbuffer, error, argptr);
va_end (argptr);
printf ("%s\n", strbuffer);
exit (1);
}
void Sys_Printf (char *fmt, ...)
{
va_list argptr;
char strbuffer[2048];
va_start (argptr, fmt);
vsprintf (strbuffer, fmt, argptr);
printf (strbuffer);
va_end (argptr);
}
void Sys_Quit (void)
{
}
float Sys_FloatTime (void) {
struct timeval tp;
struct timezone tzp;
static int secbase;
gettimeofday(&tp, &tzp);
if (!secbase) {
secbase = tp.tv_sec;
return tp.tv_usec / 1000000.0f;
}
return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0f;
}
char *Sys_ConsoleInput (void)
{
return NULL;
}
void Sys_Sleep (void)
{
}
void Sys_HighFPPrecision (void)
{
}
void Sys_LowFPPrecision (void)
{
}
//int VCRFILE (void)
//{
// return 0;
//}
//=============================================================================
// BlackAura (24-12-2002) - Modlist interface
extern int modmenu_argc;
extern char **modmenu_argv;
#define DC_BASEDIR "/cd/quake"
//char *cachedir = "cache[1024]";
void ModMenu(const char *basedir);
int main ()
{
static quakeparms_t parms;
double time, oldtime, newtime;
extern int vcrFile;
extern int recording;
static int frame;
//double time, oldtime, newtime;
// moncontrol(0);
// BlackAura (24-12-2002) - Jump to the ModMenu
ModMenu(DC_BASEDIR);
// BlackAura (08-12-2002) - Allocate 10MB of RAM
parms.memsize = 11*1024*1024;
parms.membase = malloc (parms.memsize);
// parms.cachedir = cachedir;
// BlackAura (08-12-2002) - Set base directory
parms.basedir = DC_BASEDIR;
// BlackAura (24-12-2002) - Initialise arguments from modlist
COM_InitArgv (modmenu_argc, modmenu_argv);
parms.argc = com_argc;
parms.argv = com_argv;
//Disable CD AUDIO for modmenu
SDL_Init(SDL_INIT_CDROM);
// BlackAura (08-12-2002) - Init the host
printf ("Host_Init\n");
Host_Init (&parms);
oldtime = Sys_FloatTime () - 0.1;
while (1)
{
// find time spent rendering last frame
newtime = Sys_FloatTime ();
time = newtime - oldtime;
if (cls.state == ca_dedicated)
{ // play vcrfiles at max speed
if (time < sys_ticrate.value && (vcrFile == -1 || recording) )
{
usleep(1);
continue; // not time to run a server only tic yet
}
time = sys_ticrate.value;
}
if (time > sys_ticrate.value*2)
oldtime = newtime;
else
oldtime += time;
Host_Frame (time);
// graphic debugging aids
if (sys_linerefresh.value)
Sys_LineRefresh ();
}
}