]> git.lizzy.rs Git - plan9front.git/blob - sys/src/games/doom/i_system.c
doom: disable mouse grab on crash, prevent some crashed
[plan9front.git] / sys / src / games / doom / i_system.c
1 /* i_system.c */
2
3 #include "doomdef.h"
4 #include "doomtype.h"
5
6 #include "i_system.h"
7 #include "i_sound.h"
8 #include "i_video.h"
9
10 #include "d_net.h"
11 #include "g_game.h"
12 #include "m_misc.h"
13
14 int mb_used = 6;        /* 6MB heap */
15
16 void I_Init (void)
17 {
18         I_InitSound();
19         I_InitGraphics();
20         I_MouseEnable(1);
21 }
22
23 byte* I_ZoneBase (int *size)
24 {
25         *size = mb_used*1024*1024;
26         return (byte *) malloc(*size);
27 }
28
29 /* returns time in 1/70th second tics */
30 int I_GetTime (void)
31 {
32         return (int)((nsec()*TICRATE)/1000000000);
33 }
34
35 static ticcmd_t emptycmd;
36 ticcmd_t* I_BaseTiccmd (void)
37 {
38         return &emptycmd;
39 }
40
41 void I_Quit (void)
42 {
43         D_QuitNetGame ();
44         I_ShutdownSound();
45         I_ShutdownMusic();
46         M_SaveDefaults ();
47         I_ShutdownGraphics();
48         exits(nil);
49 }
50
51 byte* I_AllocLow (int length)
52 {
53         byte *mem;
54         
55         mem = (byte *)malloc (length);
56         memset (mem,0,length);
57         return mem;
58 }
59
60 void I_Tactile(int on, int off, int total)
61 {
62         USED(on, off, total);
63 }
64
65 /*
66 ticcmd_t        emptycmd;
67 ticcmd_t*       I_BaseTiccmd(void)
68 {
69     return &emptycmd;
70 }
71
72
73 int  I_GetHeapSize (void)
74 {
75     return mb_used*1024*1024;
76 }
77
78 byte* I_ZoneBase (int*  size)
79 {
80     *size = mb_used*1024*1024;
81     return (byte *) malloc (*size);
82 }
83 */
84
85
86 //
87 // I_Error
88 //
89 extern boolean demorecording;
90
91 void I_Error (char *error, ...)
92 {
93     va_list     argptr;
94
95     // Message first.
96     va_start (argptr,error);
97     fprintf (stderr, "Error: ");
98     vfprintf (stderr,error,argptr);
99     fprintf (stderr, "\n");
100     va_end (argptr);
101
102     fflush( stderr );
103
104     // Shutdown. Here might be other errors.
105     if (demorecording)
106         G_CheckDemoStatus();
107
108     D_QuitNetGame ();
109     I_ShutdownGraphics();
110
111     exits("I_Error");
112 }
113
114 int I_FileExists (char *filepath)
115 {
116         return (0 == access(filepath, AREAD));
117 }
118
119 int I_Open (char *filepath)
120 {
121         return open(filepath, OREAD);
122 }
123
124 void I_Close (int handle)
125 {
126         close (handle);
127 }
128
129 int I_Seek (int handle, int n)
130 {
131         return seek(handle, n, 0);
132 }
133
134 int I_Read (int handle, void *buf, int n)
135 {
136         return read(handle, buf, n);
137 }
138
139 char* I_IdentifyWAD(char *wadname)
140 {
141         char path[1024];
142
143         snprintf(path, sizeof path, "/sys/lib/doom/%s", wadname);
144         if (I_FileExists (path))
145                 return path;
146
147         snprintf(path, sizeof path, "/sys/games/lib/doom/%s", wadname);
148         if (I_FileExists (path))
149                 return path;
150
151         snprintf(path, sizeof path, "%s/lib/doom/%s", getenv("home"), wadname);
152         if (I_FileExists (path))
153                 return path;
154
155         return nil;
156 }