comparison src/video/Xext/Xxf86dga/XF86DGA.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents ecba4bbaf9c2
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
6 6
7 */ 7 */
8 8
9 /* THIS IS NOT AN X CONSORTIUM STANDARD */ 9 /* THIS IS NOT AN X CONSORTIUM STANDARD */
10 10
11 #ifdef __EMX__ /* needed here to override certain constants in X headers */ 11 #ifdef __EMX__ /* needed here to override certain constants in X headers */
12 #define INCL_DOS 12 #define INCL_DOS
13 #define INCL_DOSIOCTL 13 #define INCL_DOSIOCTL
14 #include <os2.h> 14 #include <os2.h>
15 #endif 15 #endif
16 16
17 #if defined(linux) 17 #if defined(linux)
18 #define HAS_MMAP_ANON 18 #define HAS_MMAP_ANON
19 #include <sys/types.h> 19 #include <sys/types.h>
20 #include <sys/mman.h> 20 #include <sys/mman.h>
21 #include <asm/page.h> /* PAGE_SIZE */ 21 #include <asm/page.h> /* PAGE_SIZE */
22 #define HAS_SC_PAGESIZE /* _SC_PAGESIZE may be an enum for Linux */ 22 #define HAS_SC_PAGESIZE /* _SC_PAGESIZE may be an enum for Linux */
23 #define HAS_GETPAGESIZE 23 #define HAS_GETPAGESIZE
24 #endif /* linux */ 24 #endif /* linux */
25 25
26 #if defined(CSRG_BASED) 26 #if defined(CSRG_BASED)
27 #define HAS_MMAP_ANON 27 #define HAS_MMAP_ANON
43 #include <sys/types.h> 43 #include <sys/types.h>
44 #include <sys/mman.h> 44 #include <sys/mman.h>
45 #include <unistd.h> 45 #include <unistd.h>
46 #endif /* SVR4 && !DGUX */ 46 #endif /* SVR4 && !DGUX */
47 47
48 #if defined(sun) && !defined(SVR4) /* SunOS */ 48 #if defined(sun) && !defined(SVR4) /* SunOS */
49 #define MMAP_DEV_ZERO /* doesn't SunOS have MAP_ANON ?? */ 49 #define MMAP_DEV_ZERO /* doesn't SunOS have MAP_ANON ?? */
50 #define HAS_GETPAGESIZE 50 #define HAS_GETPAGESIZE
51 #include <sys/types.h> 51 #include <sys/types.h>
52 #include <sys/mman.h> 52 #include <sys/mman.h>
53 #endif /* sun && !SVR4 */ 53 #endif /* sun && !SVR4 */
54 54
63 #include "../extensions/xf86dga.h" 63 #include "../extensions/xf86dga.h"
64 #include "../extensions/xf86dgastr.h" 64 #include "../extensions/xf86dgastr.h"
65 #include "../extensions/Xext.h" 65 #include "../extensions/Xext.h"
66 #include "../extensions/extutil.h" 66 #include "../extensions/extutil.h"
67 67
68 extern XExtDisplayInfo* SDL_NAME(xdga_find_display)(Display*); 68 extern XExtDisplayInfo *SDL_NAME (xdga_find_display) (Display *);
69 extern char *SDL_NAME(xdga_extension_name); 69 extern char *SDL_NAME (xdga_extension_name);
70 70
71 #define XF86DGACheckExtension(dpy,i,val) \ 71 #define XF86DGACheckExtension(dpy,i,val) \
72 XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val) 72 XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val)
73 73
74 /***************************************************************************** 74 /*****************************************************************************
75 * * 75 * *
76 * public XFree86-DGA Extension routines * 76 * public XFree86-DGA Extension routines *
77 * * 77 * *
78 *****************************************************************************/ 78 *****************************************************************************/
79 79
80 Bool SDL_NAME(XF86DGAQueryExtension) ( 80 Bool SDL_NAME (XF86DGAQueryExtension) (Display * dpy,
81 Display *dpy, 81 int *event_basep, int *error_basep)
82 int *event_basep, 82 {
83 int *error_basep 83 return SDL_NAME (XDGAQueryExtension) (dpy, event_basep, error_basep);
84 ){ 84 }
85 return SDL_NAME(XDGAQueryExtension)(dpy, event_basep, error_basep); 85
86 } 86 Bool SDL_NAME (XF86DGAQueryVersion) (Display * dpy,
87 87 int *majorVersion, int *minorVersion)
88 Bool SDL_NAME(XF86DGAQueryVersion)( 88 {
89 Display* dpy, 89 return SDL_NAME (XDGAQueryVersion) (dpy, majorVersion, minorVersion);
90 int* majorVersion, 90 }
91 int* minorVersion 91
92 ){ 92 Bool SDL_NAME (XF86DGAGetVideoLL) (Display * dpy,
93 return SDL_NAME(XDGAQueryVersion)(dpy, majorVersion, minorVersion); 93 int screen,
94 } 94 int *offset,
95 95 int *width, int *bank_size, int *ram_size)
96 Bool SDL_NAME(XF86DGAGetVideoLL)( 96 {
97 Display* dpy, 97 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy);
98 int screen,
99 int *offset,
100 int *width,
101 int *bank_size,
102 int *ram_size
103 ){
104 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
105 xXF86DGAGetVideoLLReply rep; 98 xXF86DGAGetVideoLLReply rep;
106 xXF86DGAGetVideoLLReq *req; 99 xXF86DGAGetVideoLLReq *req;
107 100
108 XF86DGACheckExtension (dpy, info, False); 101 XF86DGACheckExtension (dpy, info, False);
109 102
110 LockDisplay(dpy); 103 LockDisplay (dpy);
111 GetReq(XF86DGAGetVideoLL, req); 104 GetReq (XF86DGAGetVideoLL, req);
112 req->reqType = info->codes->major_opcode; 105 req->reqType = info->codes->major_opcode;
113 req->dgaReqType = X_XF86DGAGetVideoLL; 106 req->dgaReqType = X_XF86DGAGetVideoLL;
114 req->screen = screen; 107 req->screen = screen;
115 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 108 if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) {
116 UnlockDisplay(dpy); 109 UnlockDisplay (dpy);
117 SyncHandle(); 110 SyncHandle ();
118 return False; 111 return False;
119 } 112 }
120 113
121 *offset = /*(char *)*/rep.offset; 114 *offset = /*(char *) */ rep.offset;
122 *width = rep.width; 115 *width = rep.width;
123 *bank_size = rep.bank_size; 116 *bank_size = rep.bank_size;
124 *ram_size = rep.ram_size; 117 *ram_size = rep.ram_size;
125 118
126 UnlockDisplay(dpy); 119 UnlockDisplay (dpy);
127 SyncHandle(); 120 SyncHandle ();
128 return True; 121 return True;
129 } 122 }
130 123
131 124
132 Bool SDL_NAME(XF86DGADirectVideoLL)( 125 Bool SDL_NAME (XF86DGADirectVideoLL) (Display * dpy, int screen, int enable)
133 Display* dpy, 126 {
134 int screen, 127 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy);
135 int enable
136 ){
137 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
138 xXF86DGADirectVideoReq *req; 128 xXF86DGADirectVideoReq *req;
139 129
140 XF86DGACheckExtension (dpy, info, False); 130 XF86DGACheckExtension (dpy, info, False);
141 131
142 LockDisplay(dpy); 132 LockDisplay (dpy);
143 GetReq(XF86DGADirectVideo, req); 133 GetReq (XF86DGADirectVideo, req);
144 req->reqType = info->codes->major_opcode; 134 req->reqType = info->codes->major_opcode;
145 req->dgaReqType = X_XF86DGADirectVideo; 135 req->dgaReqType = X_XF86DGADirectVideo;
146 req->screen = screen; 136 req->screen = screen;
147 req->enable = enable; 137 req->enable = enable;
148 UnlockDisplay(dpy); 138 UnlockDisplay (dpy);
149 SyncHandle(); 139 SyncHandle ();
150 XSync(dpy,False); 140 XSync (dpy, False);
151 return True; 141 return True;
152 } 142 }
153 143
154 Bool SDL_NAME(XF86DGAGetViewPortSize)( 144 Bool SDL_NAME (XF86DGAGetViewPortSize) (Display * dpy,
155 Display* dpy, 145 int screen, int *width, int *height)
156 int screen, 146 {
157 int *width, 147 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy);
158 int *height
159 ){
160 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
161 xXF86DGAGetViewPortSizeReply rep; 148 xXF86DGAGetViewPortSizeReply rep;
162 xXF86DGAGetViewPortSizeReq *req; 149 xXF86DGAGetViewPortSizeReq *req;
163 150
164 XF86DGACheckExtension (dpy, info, False); 151 XF86DGACheckExtension (dpy, info, False);
165 152
166 LockDisplay(dpy); 153 LockDisplay (dpy);
167 GetReq(XF86DGAGetViewPortSize, req); 154 GetReq (XF86DGAGetViewPortSize, req);
168 req->reqType = info->codes->major_opcode; 155 req->reqType = info->codes->major_opcode;
169 req->dgaReqType = X_XF86DGAGetViewPortSize; 156 req->dgaReqType = X_XF86DGAGetViewPortSize;
170 req->screen = screen; 157 req->screen = screen;
171 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 158 if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) {
172 UnlockDisplay(dpy); 159 UnlockDisplay (dpy);
173 SyncHandle(); 160 SyncHandle ();
174 return False; 161 return False;
175 } 162 }
176 163
177 *width = rep.width; 164 *width = rep.width;
178 *height = rep.height; 165 *height = rep.height;
179 166
180 UnlockDisplay(dpy); 167 UnlockDisplay (dpy);
181 SyncHandle(); 168 SyncHandle ();
182 return True; 169 return True;
183 } 170 }
184 171
185 172
186 Bool SDL_NAME(XF86DGASetViewPort)( 173 Bool SDL_NAME (XF86DGASetViewPort) (Display * dpy, int screen, int x, int y)
187 Display* dpy, 174 {
188 int screen, 175 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy);
189 int x,
190 int y
191 ){
192 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
193 xXF86DGASetViewPortReq *req; 176 xXF86DGASetViewPortReq *req;
194 177
195 XF86DGACheckExtension (dpy, info, False); 178 XF86DGACheckExtension (dpy, info, False);
196 179
197 LockDisplay(dpy); 180 LockDisplay (dpy);
198 GetReq(XF86DGASetViewPort, req); 181 GetReq (XF86DGASetViewPort, req);
199 req->reqType = info->codes->major_opcode; 182 req->reqType = info->codes->major_opcode;
200 req->dgaReqType = X_XF86DGASetViewPort; 183 req->dgaReqType = X_XF86DGASetViewPort;
201 req->screen = screen; 184 req->screen = screen;
202 req->x = x; 185 req->x = x;
203 req->y = y; 186 req->y = y;
204 UnlockDisplay(dpy); 187 UnlockDisplay (dpy);
205 SyncHandle(); 188 SyncHandle ();
206 XSync(dpy,False); 189 XSync (dpy, False);
207 return True; 190 return True;
208 } 191 }
209 192
210 193
211 Bool SDL_NAME(XF86DGAGetVidPage)( 194 Bool SDL_NAME (XF86DGAGetVidPage) (Display * dpy, int screen, int *vpage)
212 Display* dpy, 195 {
213 int screen, 196 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy);
214 int *vpage
215 ){
216 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
217 xXF86DGAGetVidPageReply rep; 197 xXF86DGAGetVidPageReply rep;
218 xXF86DGAGetVidPageReq *req; 198 xXF86DGAGetVidPageReq *req;
219 199
220 XF86DGACheckExtension (dpy, info, False); 200 XF86DGACheckExtension (dpy, info, False);
221 201
222 LockDisplay(dpy); 202 LockDisplay (dpy);
223 GetReq(XF86DGAGetVidPage, req); 203 GetReq (XF86DGAGetVidPage, req);
224 req->reqType = info->codes->major_opcode; 204 req->reqType = info->codes->major_opcode;
225 req->dgaReqType = X_XF86DGAGetVidPage; 205 req->dgaReqType = X_XF86DGAGetVidPage;
226 req->screen = screen; 206 req->screen = screen;
227 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 207 if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) {
228 UnlockDisplay(dpy); 208 UnlockDisplay (dpy);
229 SyncHandle(); 209 SyncHandle ();
230 return False; 210 return False;
231 } 211 }
232 212
233 *vpage = rep.vpage; 213 *vpage = rep.vpage;
234 UnlockDisplay(dpy); 214 UnlockDisplay (dpy);
235 SyncHandle(); 215 SyncHandle ();
236 return True; 216 return True;
237 } 217 }
238 218
239 219
240 Bool SDL_NAME(XF86DGASetVidPage)( 220 Bool SDL_NAME (XF86DGASetVidPage) (Display * dpy, int screen, int vpage)
241 Display* dpy, 221 {
242 int screen, 222 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy);
243 int vpage
244 ){
245 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
246 xXF86DGASetVidPageReq *req; 223 xXF86DGASetVidPageReq *req;
247 224
248 XF86DGACheckExtension (dpy, info, False); 225 XF86DGACheckExtension (dpy, info, False);
249 226
250 LockDisplay(dpy); 227 LockDisplay (dpy);
251 GetReq(XF86DGASetVidPage, req); 228 GetReq (XF86DGASetVidPage, req);
252 req->reqType = info->codes->major_opcode; 229 req->reqType = info->codes->major_opcode;
253 req->dgaReqType = X_XF86DGASetVidPage; 230 req->dgaReqType = X_XF86DGASetVidPage;
254 req->screen = screen; 231 req->screen = screen;
255 req->vpage = vpage; 232 req->vpage = vpage;
256 UnlockDisplay(dpy); 233 UnlockDisplay (dpy);
257 SyncHandle(); 234 SyncHandle ();
258 XSync(dpy,False); 235 XSync (dpy, False);
259 return True; 236 return True;
260 } 237 }
261 238
262 Bool SDL_NAME(XF86DGAInstallColormap)( 239 Bool SDL_NAME (XF86DGAInstallColormap) (Display * dpy,
263 Display* dpy, 240 int screen, Colormap cmap)
264 int screen, 241 {
265 Colormap cmap 242 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy);
266 ){
267 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
268 xXF86DGAInstallColormapReq *req; 243 xXF86DGAInstallColormapReq *req;
269 244
270 XF86DGACheckExtension (dpy, info, False); 245 XF86DGACheckExtension (dpy, info, False);
271 246
272 LockDisplay(dpy); 247 LockDisplay (dpy);
273 GetReq(XF86DGAInstallColormap, req); 248 GetReq (XF86DGAInstallColormap, req);
274 req->reqType = info->codes->major_opcode; 249 req->reqType = info->codes->major_opcode;
275 req->dgaReqType = X_XF86DGAInstallColormap; 250 req->dgaReqType = X_XF86DGAInstallColormap;
276 req->screen = screen; 251 req->screen = screen;
277 req->id = cmap; 252 req->id = cmap;
278 UnlockDisplay(dpy); 253 UnlockDisplay (dpy);
279 SyncHandle(); 254 SyncHandle ();
280 XSync(dpy,False); 255 XSync (dpy, False);
281 return True; 256 return True;
282 } 257 }
283 258
284 Bool SDL_NAME(XF86DGAQueryDirectVideo)( 259 Bool SDL_NAME (XF86DGAQueryDirectVideo) (Display * dpy,
285 Display *dpy, 260 int screen, int *flags)
286 int screen, 261 {
287 int *flags 262 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy);
288 ){
289 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
290 xXF86DGAQueryDirectVideoReply rep; 263 xXF86DGAQueryDirectVideoReply rep;
291 xXF86DGAQueryDirectVideoReq *req; 264 xXF86DGAQueryDirectVideoReq *req;
292 265
293 XF86DGACheckExtension (dpy, info, False); 266 XF86DGACheckExtension (dpy, info, False);
294 267
295 LockDisplay(dpy); 268 LockDisplay (dpy);
296 GetReq(XF86DGAQueryDirectVideo, req); 269 GetReq (XF86DGAQueryDirectVideo, req);
297 req->reqType = info->codes->major_opcode; 270 req->reqType = info->codes->major_opcode;
298 req->dgaReqType = X_XF86DGAQueryDirectVideo; 271 req->dgaReqType = X_XF86DGAQueryDirectVideo;
299 req->screen = screen; 272 req->screen = screen;
300 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 273 if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) {
301 UnlockDisplay(dpy); 274 UnlockDisplay (dpy);
302 SyncHandle(); 275 SyncHandle ();
303 return False; 276 return False;
304 } 277 }
305 *flags = rep.flags; 278 *flags = rep.flags;
306 UnlockDisplay(dpy); 279 UnlockDisplay (dpy);
307 SyncHandle(); 280 SyncHandle ();
308 return True; 281 return True;
309 } 282 }
310 283
311 Bool SDL_NAME(XF86DGAViewPortChanged)( 284 Bool SDL_NAME (XF86DGAViewPortChanged) (Display * dpy, int screen, int n)
312 Display *dpy, 285 {
313 int screen, 286 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy);
314 int n
315 ){
316 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
317 xXF86DGAViewPortChangedReply rep; 287 xXF86DGAViewPortChangedReply rep;
318 xXF86DGAViewPortChangedReq *req; 288 xXF86DGAViewPortChangedReq *req;
319 289
320 XF86DGACheckExtension (dpy, info, False); 290 XF86DGACheckExtension (dpy, info, False);
321 291
322 LockDisplay(dpy); 292 LockDisplay (dpy);
323 GetReq(XF86DGAViewPortChanged, req); 293 GetReq (XF86DGAViewPortChanged, req);
324 req->reqType = info->codes->major_opcode; 294 req->reqType = info->codes->major_opcode;
325 req->dgaReqType = X_XF86DGAViewPortChanged; 295 req->dgaReqType = X_XF86DGAViewPortChanged;
326 req->screen = screen; 296 req->screen = screen;
327 req->n = n; 297 req->n = n;
328 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 298 if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) {
329 UnlockDisplay(dpy); 299 UnlockDisplay (dpy);
330 SyncHandle(); 300 SyncHandle ();
331 return False; 301 return False;
332 } 302 }
333 UnlockDisplay(dpy); 303 UnlockDisplay (dpy);
334 SyncHandle(); 304 SyncHandle ();
335 return rep.result; 305 return rep.result;
336 } 306 }
337 307
338 308
339 309
342 #include <X11/Xmd.h> 312 #include <X11/Xmd.h>
343 #include "../extensions/xf86dga.h" 313 #include "../extensions/xf86dga.h"
344 #include <stdlib.h> 314 #include <stdlib.h>
345 #include <stdio.h> 315 #include <stdio.h>
346 #include <fcntl.h> 316 #include <fcntl.h>
347 #if defined(ISC) 317 #if defined(ISC)
348 # define HAS_SVR3_MMAP 318 # define HAS_SVR3_MMAP
349 # include <sys/types.h> 319 # include <sys/types.h>
350 # include <errno.h> 320 # include <errno.h>
351 321
352 # include <sys/at_ansi.h> 322 # include <sys/at_ansi.h>
378 #define DEV_MEM "/dev/xsvc" 348 #define DEV_MEM "/dev/xsvc"
379 #else 349 #else
380 #define DEV_MEM "/dev/mem" 350 #define DEV_MEM "/dev/mem"
381 #endif 351 #endif
382 352
383 typedef struct { 353 typedef struct
384 unsigned long physaddr; /* actual requested physical address */ 354 {
385 unsigned long size; /* actual requested map size */ 355 unsigned long physaddr; /* actual requested physical address */
386 unsigned long delta; /* delta to account for page alignment */ 356 unsigned long size; /* actual requested map size */
387 void * vaddr; /* mapped address, without the delta */ 357 unsigned long delta; /* delta to account for page alignment */
388 int refcount; /* reference count */ 358 void *vaddr; /* mapped address, without the delta */
359 int refcount; /* reference count */
389 } MapRec, *MapPtr; 360 } MapRec, *MapPtr;
390 361
391 typedef struct { 362 typedef struct
392 Display * display; 363 {
393 int screen; 364 Display *display;
394 MapPtr map; 365 int screen;
366 MapPtr map;
395 } ScrRec, *ScrPtr; 367 } ScrRec, *ScrPtr;
396 368
397 static int mapFd = -1; 369 static int mapFd = -1;
398 static int numMaps = 0; 370 static int numMaps = 0;
399 static int numScrs = 0; 371 static int numScrs = 0;
400 static MapPtr *mapList = NULL; 372 static MapPtr *mapList = NULL;
401 static ScrPtr *scrList = NULL; 373 static ScrPtr *scrList = NULL;
402 374
403 static MapPtr 375 static MapPtr
404 AddMap(void) 376 AddMap (void)
405 { 377 {
406 MapPtr *old; 378 MapPtr *old;
407 379
408 old = mapList; 380 old = mapList;
409 mapList = realloc(mapList, sizeof(MapPtr) * (numMaps + 1)); 381 mapList = realloc (mapList, sizeof (MapPtr) * (numMaps + 1));
410 if (!mapList) { 382 if (!mapList) {
411 mapList = old; 383 mapList = old;
412 return NULL; 384 return NULL;
413 } 385 }
414 mapList[numMaps] = malloc(sizeof(MapRec)); 386 mapList[numMaps] = malloc (sizeof (MapRec));
415 if (!mapList[numMaps]) 387 if (!mapList[numMaps])
416 return NULL; 388 return NULL;
417 return mapList[numMaps++]; 389 return mapList[numMaps++];
418 } 390 }
419 391
420 static ScrPtr 392 static ScrPtr
421 AddScr(void) 393 AddScr (void)
422 { 394 {
423 ScrPtr *old; 395 ScrPtr *old;
424 396
425 old = scrList; 397 old = scrList;
426 scrList = realloc(scrList, sizeof(ScrPtr) * (numScrs + 1)); 398 scrList = realloc (scrList, sizeof (ScrPtr) * (numScrs + 1));
427 if (!scrList) { 399 if (!scrList) {
428 scrList = old; 400 scrList = old;
429 return NULL; 401 return NULL;
430 } 402 }
431 scrList[numScrs] = malloc(sizeof(ScrRec)); 403 scrList[numScrs] = malloc (sizeof (ScrRec));
432 if (!scrList[numScrs]) 404 if (!scrList[numScrs])
433 return NULL; 405 return NULL;
434 return scrList[numScrs++]; 406 return scrList[numScrs++];
435 } 407 }
436 408
437 static MapPtr 409 static MapPtr
438 FindMap(unsigned long address, unsigned long size) 410 FindMap (unsigned long address, unsigned long size)
439 { 411 {
440 int i; 412 int i;
441 413
442 for (i = 0; i < numMaps; i++) { 414 for (i = 0; i < numMaps; i++) {
443 if (mapList[i]->physaddr == address && 415 if (mapList[i]->physaddr == address && mapList[i]->size == size)
444 mapList[i]->size == size) 416 return mapList[i];
445 return mapList[i];
446 } 417 }
447 return NULL; 418 return NULL;
448 } 419 }
449 420
450 static ScrPtr 421 static ScrPtr
451 FindScr(Display *display, int screen) 422 FindScr (Display * display, int screen)
452 { 423 {
453 int i; 424 int i;
454 425
455 for (i = 0; i < numScrs; i++) { 426 for (i = 0; i < numScrs; i++) {
456 if (scrList[i]->display == display && 427 if (scrList[i]->display == display && scrList[i]->screen == screen)
457 scrList[i]->screen == screen) 428 return scrList[i];
458 return scrList[i];
459 } 429 }
460 return NULL; 430 return NULL;
461 } 431 }
462 432
463 static void * 433 static void *
464 MapPhysAddress(unsigned long address, unsigned long size) 434 MapPhysAddress (unsigned long address, unsigned long size)
465 { 435 {
466 unsigned long offset, delta; 436 unsigned long offset, delta;
467 int pagesize = -1; 437 int pagesize = -1;
468 void *vaddr; 438 void *vaddr;
469 MapPtr mp; 439 MapPtr mp;
473 APIRET rc; 443 APIRET rc;
474 ULONG action; 444 ULONG action;
475 HFILE hfd; 445 HFILE hfd;
476 #endif 446 #endif
477 447
478 if ((mp = FindMap(address, size))) { 448 if ((mp = FindMap (address, size))) {
479 mp->refcount++; 449 mp->refcount++;
480 return (void *)((unsigned long)mp->vaddr + mp->delta); 450 return (void *) ((unsigned long) mp->vaddr + mp->delta);
481 } 451 }
482
483 #if defined(_SC_PAGESIZE) && defined(HAS_SC_PAGESIZE) 452 #if defined(_SC_PAGESIZE) && defined(HAS_SC_PAGESIZE)
484 pagesize = sysconf(_SC_PAGESIZE); 453 pagesize = sysconf (_SC_PAGESIZE);
485 #endif 454 #endif
486 #ifdef _SC_PAGE_SIZE 455 #ifdef _SC_PAGE_SIZE
487 if (pagesize == -1) 456 if (pagesize == -1)
488 pagesize = sysconf(_SC_PAGE_SIZE); 457 pagesize = sysconf (_SC_PAGE_SIZE);
489 #endif 458 #endif
490 #ifdef HAS_GETPAGESIZE 459 #ifdef HAS_GETPAGESIZE
491 if (pagesize == -1) 460 if (pagesize == -1)
492 pagesize = getpagesize(); 461 pagesize = getpagesize ();
493 #endif 462 #endif
494 #ifdef PAGE_SIZE 463 #ifdef PAGE_SIZE
495 if (pagesize == -1) 464 if (pagesize == -1)
496 pagesize = PAGE_SIZE; 465 pagesize = PAGE_SIZE;
497 #endif 466 #endif
498 if (pagesize == -1) 467 if (pagesize == -1)
499 pagesize = 4096; 468 pagesize = 4096;
500 469
501 delta = address % pagesize; 470 delta = address % pagesize;
502 offset = address - delta; 471 offset = address - delta;
503 472
504 #if defined(ISC) && defined(HAS_SVR3_MMAP) 473 #if defined(ISC) && defined(HAS_SVR3_MMAP)
505 if (mapFd < 0) { 474 if (mapFd < 0) {
506 if ((mapFd = open("/dev/mmap", O_RDWR)) < 0) 475 if ((mapFd = open ("/dev/mmap", O_RDWR)) < 0)
507 return NULL; 476 return NULL;
508 } 477 }
509 mloc.vaddr = (char *)0; 478 mloc.vaddr = (char *) 0;
510 mloc.physaddr = (char *)offset; 479 mloc.physaddr = (char *) offset;
511 mloc.length = size + delta; 480 mloc.length = size + delta;
512 mloc.ioflg=1; 481 mloc.ioflg = 1;
513 482
514 if ((vaddr = (void *)ioctl(mapFd, MAP, &mloc)) == (void *)-1) 483 if ((vaddr = (void *) ioctl (mapFd, MAP, &mloc)) == (void *) -1)
515 return NULL; 484 return NULL;
516 #elif defined (__EMX__) 485 #elif defined (__EMX__)
517 /* 486 /*
518 * Dragon warning here! /dev/pmap$ is never closed, except on progam exit. 487 * Dragon warning here! /dev/pmap$ is never closed, except on progam exit.
519 * Consecutive calling of this routine will make PMAP$ driver run out 488 * Consecutive calling of this routine will make PMAP$ driver run out
520 * of memory handles. Some umap/close mechanism should be provided 489 * of memory handles. Some umap/close mechanism should be provided
521 */ 490 */
522 491
523 rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN, 492 rc = DosOpen ("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN,
524 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2)NULL); 493 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2) NULL);
525 if (rc != 0) 494 if (rc != 0)
526 return NULL; 495 return NULL;
527 { 496 {
528 struct map_ioctl { 497 struct map_ioctl
529 union { 498 {
530 ULONG phys; 499 union
531 void* user; 500 {
532 } a; 501 ULONG phys;
533 ULONG size; 502 void *user;
534 } pmap,dmap; 503 } a;
535 ULONG plen,dlen; 504 ULONG size;
505 } pmap, dmap;
506 ULONG plen, dlen;
536 #define XFREE86_PMAP 0x76 507 #define XFREE86_PMAP 0x76
537 #define PMAP_MAP 0x44 508 #define PMAP_MAP 0x44
538 509
539 pmap.a.phys = offset; 510 pmap.a.phys = offset;
540 pmap.size = size + delta; 511 pmap.size = size + delta;
541 rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP, 512 rc = DosDevIOCtl (hfd, XFREE86_PMAP, PMAP_MAP,
542 (PULONG)&pmap, sizeof(pmap), &plen, 513 (PULONG) & pmap, sizeof (pmap), &plen,
543 (PULONG)&dmap, sizeof(dmap), &dlen); 514 (PULONG) & dmap, sizeof (dmap), &dlen);
544 if (rc == 0) { 515 if (rc == 0) {
545 vaddr = dmap.a.user; 516 vaddr = dmap.a.user;
546 } 517 }
547 } 518 }
548 if (rc != 0) 519 if (rc != 0)
549 return NULL; 520 return NULL;
550 #elif defined (Lynx) 521 #elif defined (Lynx)
551 vaddr = (void *)smem_create("XF86DGA", (char *)offset, 522 vaddr = (void *) smem_create ("XF86DGA", (char *) offset,
552 size + delta, SM_READ|SM_WRITE); 523 size + delta, SM_READ | SM_WRITE);
553 #else 524 #else
554 #ifndef MAP_FILE 525 #ifndef MAP_FILE
555 #define MAP_FILE 0 526 #define MAP_FILE 0
556 #endif 527 #endif
557 if (mapFd < 0) { 528 if (mapFd < 0) {
558 if ((mapFd = open(DEV_MEM, O_RDWR)) < 0) 529 if ((mapFd = open (DEV_MEM, O_RDWR)) < 0)
559 return NULL; 530 return NULL;
560 } 531 }
561 vaddr = (void *)mmap(NULL, size + delta, PROT_READ | PROT_WRITE, 532 vaddr = (void *) mmap (NULL, size + delta, PROT_READ | PROT_WRITE,
562 MAP_FILE | MAP_SHARED, mapFd, (off_t)offset); 533 MAP_FILE | MAP_SHARED, mapFd, (off_t) offset);
563 if (vaddr == (void *)-1) 534 if (vaddr == (void *) -1)
564 return NULL; 535 return NULL;
565 #endif 536 #endif
566 537
567 if (!vaddr) { 538 if (!vaddr) {
568 if (!(mp = AddMap())) 539 if (!(mp = AddMap ()))
569 return NULL; 540 return NULL;
570 mp->physaddr = address; 541 mp->physaddr = address;
571 mp->size = size; 542 mp->size = size;
572 mp->delta = delta; 543 mp->delta = delta;
573 mp->vaddr = vaddr; 544 mp->vaddr = vaddr;
574 mp->refcount = 1; 545 mp->refcount = 1;
575 } 546 }
576 return (void *)((unsigned long)vaddr + delta); 547 return (void *) ((unsigned long) vaddr + delta);
577 } 548 }
578 549
579 /* 550 /*
580 * Still need to find a clean way of detecting the death of a DGA app 551 * Still need to find a clean way of detecting the death of a DGA app
581 * and returning things to normal - Jon 552 * and returning things to normal - Jon
582 * This is here to help debugging without rebooting... Also C-A-BS 553 * This is here to help debugging without rebooting... Also C-A-BS
583 * should restore text mode. 554 * should restore text mode.
584 */ 555 */
585 556
586 int 557 int SDL_NAME (XF86DGAForkApp) (int screen)
587 SDL_NAME(XF86DGAForkApp)(int screen)
588 { 558 {
589 pid_t pid; 559 pid_t pid;
590 int status; 560 int status;
591 int i; 561 int i;
592 562
593 /* fork the app, parent hangs around to clean up */ 563 /* fork the app, parent hangs around to clean up */
594 if ((pid = fork()) > 0) { 564 if ((pid = fork ()) > 0) {
595 ScrPtr sp; 565 ScrPtr sp;
596 566
597 waitpid(pid, &status, 0); 567 waitpid (pid, &status, 0);
598 for (i = 0; i < numScrs; i++) { 568 for (i = 0; i < numScrs; i++) {
599 sp = scrList[i]; 569 sp = scrList[i];
600 SDL_NAME(XF86DGADirectVideoLL)(sp->display, sp->screen, 0); 570 SDL_NAME (XF86DGADirectVideoLL) (sp->display, sp->screen, 0);
601 XSync(sp->display, False); 571 XSync (sp->display, False);
602 } 572 }
603 if (WIFEXITED(status)) 573 if (WIFEXITED (status))
604 _exit(0); 574 _exit (0);
605 else 575 else
606 _exit(-1); 576 _exit (-1);
607 } 577 }
608 return pid; 578 return pid;
609 } 579 }
610 580
611 581
612 Bool 582 Bool SDL_NAME (XF86DGADirectVideo) (Display * dis, int screen, int enable)
613 SDL_NAME(XF86DGADirectVideo)( 583 {
614 Display *dis,
615 int screen,
616 int enable
617 ){
618 ScrPtr sp; 584 ScrPtr sp;
619 MapPtr mp = NULL; 585 MapPtr mp = NULL;
620 586
621 if ((sp = FindScr(dis, screen))) 587 if ((sp = FindScr (dis, screen)))
622 mp = sp->map; 588 mp = sp->map;
623 589
624 if (enable & XF86DGADirectGraphics) { 590 if (enable & XF86DGADirectGraphics) {
625 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ 591 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
626 && !defined(__EMX__) 592 && !defined(__EMX__)
627 if (mp && mp->vaddr) 593 if (mp && mp->vaddr)
628 mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ | PROT_WRITE); 594 mprotect (mp->vaddr, mp->size + mp->delta,
595 PROT_READ | PROT_WRITE);
629 #endif 596 #endif
630 } else { 597 } else {
631 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ 598 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
632 && !defined(__EMX__) 599 && !defined(__EMX__)
633 if (mp && mp->vaddr) 600 if (mp && mp->vaddr)
634 mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ); 601 mprotect (mp->vaddr, mp->size + mp->delta, PROT_READ);
635 #elif defined(Lynx) 602 #elif defined(Lynx)
636 /* XXX this doesn't allow enable after disable */ 603 /* XXX this doesn't allow enable after disable */
637 smem_create(NULL, mp->vaddr, mp->size + mp->delta, SM_DETACH); 604 smem_create (NULL, mp->vaddr, mp->size + mp->delta, SM_DETACH);
638 smem_remove("XF86DGA"); 605 smem_remove ("XF86DGA");
639 #endif 606 #endif
640 } 607 }
641 608
642 SDL_NAME(XF86DGADirectVideoLL)(dis, screen, enable); 609 SDL_NAME (XF86DGADirectVideoLL) (dis, screen, enable);
643 return 1; 610 return 1;
644 } 611 }
645 612
646 613
647 static void 614 static void
648 XF86cleanup(int sig) 615 XF86cleanup (int sig)
649 { 616 {
650 ScrPtr sp; 617 ScrPtr sp;
651 int i; 618 int i;
652 static char beenhere = 0; 619 static char beenhere = 0;
653 620
654 if (beenhere) 621 if (beenhere)
655 _exit(3); 622 _exit (3);
656 beenhere = 1; 623 beenhere = 1;
657 624
658 for (i = 0; i < numScrs; i++) { 625 for (i = 0; i < numScrs; i++) {
659 sp = scrList[i]; 626 sp = scrList[i];
660 SDL_NAME(XF86DGADirectVideo)(sp->display, sp->screen, 0); 627 SDL_NAME (XF86DGADirectVideo) (sp->display, sp->screen, 0);
661 XSync(sp->display, False); 628 XSync (sp->display, False);
662 } 629 }
663 _exit(3); 630 _exit (3);
664 } 631 }
665 632
666 Bool 633 Bool
667 SDL_NAME(XF86DGAGetVideo)( 634 SDL_NAME (XF86DGAGetVideo) (Display * dis,
668 Display *dis, 635 int screen,
669 int screen, 636 char **addr, int *width, int *bank, int *ram)
670 char **addr, 637 {
671 int *width, 638 /*unsigned long */ int offset;
672 int *bank,
673 int *ram
674 ){
675 /*unsigned long*/ int offset;
676 static int beenHere = 0; 639 static int beenHere = 0;
677 ScrPtr sp; 640 ScrPtr sp;
678 MapPtr mp; 641 MapPtr mp;
679 642
680 if (!(sp = FindScr(dis, screen))) { 643 if (!(sp = FindScr (dis, screen))) {
681 if (!(sp = AddScr())) { 644 if (!(sp = AddScr ())) {
682 fprintf(stderr, "XF86DGAGetVideo: malloc failure\n"); 645 fprintf (stderr, "XF86DGAGetVideo: malloc failure\n");
683 exit(-2); 646 exit (-2);
684 } 647 }
685 sp->display = dis; 648 sp->display = dis;
686 sp->screen = screen; 649 sp->screen = screen;
687 sp->map = NULL; 650 sp->map = NULL;
688 } 651 }
689 652
690 SDL_NAME(XF86DGAGetVideoLL)(dis, screen , &offset, width, bank, ram); 653 SDL_NAME (XF86DGAGetVideoLL) (dis, screen, &offset, width, bank, ram);
691 654
692 *addr = MapPhysAddress(offset, *bank); 655 *addr = MapPhysAddress (offset, *bank);
693 if (*addr == NULL) { 656 if (*addr == NULL) {
694 fprintf(stderr, "XF86DGAGetVideo: failed to map video memory (%s)\n", 657 fprintf (stderr,
695 strerror(errno)); 658 "XF86DGAGetVideo: failed to map video memory (%s)\n",
696 exit(-2); 659 strerror (errno));
697 } 660 exit (-2);
698 661 }
699 if ((mp = FindMap(offset, *bank))) 662
700 sp->map = mp; 663 if ((mp = FindMap (offset, *bank)))
664 sp->map = mp;
701 665
702 if (!beenHere) { 666 if (!beenHere) {
703 beenHere = 1; 667 beenHere = 1;
704 atexit((void(*)(void))XF86cleanup); 668 atexit ((void (*)(void)) XF86cleanup);
705 /* one shot XF86cleanup attempts */ 669 /* one shot XF86cleanup attempts */
706 signal(SIGSEGV, XF86cleanup); 670 signal (SIGSEGV, XF86cleanup);
707 #ifdef SIGBUS 671 #ifdef SIGBUS
708 signal(SIGBUS, XF86cleanup); 672 signal (SIGBUS, XF86cleanup);
709 #endif 673 #endif
710 signal(SIGHUP, XF86cleanup); 674 signal (SIGHUP, XF86cleanup);
711 signal(SIGFPE, XF86cleanup); 675 signal (SIGFPE, XF86cleanup);
712 } 676 }
713 677
714 return 1; 678 return 1;
715 } 679 }
716 680
681 /* vi: set ts=4 sw=4 expandtab: */