comparison src/video/Xext/Xxf86dga/XF86DGA.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
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) (Display * dpy, 80 Bool SDL_NAME(XF86DGAQueryExtension) (Display * dpy,
81 int *event_basep, int *error_basep) 81 int *event_basep, int *error_basep)
82 { 82 {
83 return SDL_NAME (XDGAQueryExtension) (dpy, event_basep, error_basep); 83 return SDL_NAME(XDGAQueryExtension) (dpy, event_basep, error_basep);
84 } 84 }
85 85
86 Bool SDL_NAME (XF86DGAQueryVersion) (Display * dpy, 86 Bool SDL_NAME(XF86DGAQueryVersion) (Display * dpy,
87 int *majorVersion, int *minorVersion) 87 int *majorVersion, int *minorVersion)
88 { 88 {
89 return SDL_NAME (XDGAQueryVersion) (dpy, majorVersion, minorVersion); 89 return SDL_NAME(XDGAQueryVersion) (dpy, majorVersion, minorVersion);
90 } 90 }
91 91
92 Bool SDL_NAME (XF86DGAGetVideoLL) (Display * dpy, 92 Bool SDL_NAME(XF86DGAGetVideoLL) (Display * dpy,
93 int screen, 93 int screen,
94 int *offset, 94 int *offset,
95 int *width, int *bank_size, int *ram_size) 95 int *width, int *bank_size, int *ram_size)
96 { 96 {
97 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); 97 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
98 xXF86DGAGetVideoLLReply rep; 98 xXF86DGAGetVideoLLReply rep;
99 xXF86DGAGetVideoLLReq *req; 99 xXF86DGAGetVideoLLReq *req;
100 100
101 XF86DGACheckExtension (dpy, info, False); 101 XF86DGACheckExtension(dpy, info, False);
102 102
103 LockDisplay (dpy); 103 LockDisplay(dpy);
104 GetReq (XF86DGAGetVideoLL, req); 104 GetReq(XF86DGAGetVideoLL, req);
105 req->reqType = info->codes->major_opcode; 105 req->reqType = info->codes->major_opcode;
106 req->dgaReqType = X_XF86DGAGetVideoLL; 106 req->dgaReqType = X_XF86DGAGetVideoLL;
107 req->screen = screen; 107 req->screen = screen;
108 if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { 108 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
109 UnlockDisplay (dpy); 109 UnlockDisplay(dpy);
110 SyncHandle (); 110 SyncHandle();
111 return False; 111 return False;
112 } 112 }
113 113
114 *offset = /*(char *) */ rep.offset; 114 *offset = /*(char *) */ rep.offset;
115 *width = rep.width; 115 *width = rep.width;
116 *bank_size = rep.bank_size; 116 *bank_size = rep.bank_size;
117 *ram_size = rep.ram_size; 117 *ram_size = rep.ram_size;
118 118
119 UnlockDisplay (dpy); 119 UnlockDisplay(dpy);
120 SyncHandle (); 120 SyncHandle();
121 return True; 121 return True;
122 } 122 }
123 123
124 124
125 Bool SDL_NAME (XF86DGADirectVideoLL) (Display * dpy, int screen, int enable) 125 Bool SDL_NAME(XF86DGADirectVideoLL) (Display * dpy, int screen, int enable)
126 { 126 {
127 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); 127 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
128 xXF86DGADirectVideoReq *req; 128 xXF86DGADirectVideoReq *req;
129 129
130 XF86DGACheckExtension (dpy, info, False); 130 XF86DGACheckExtension(dpy, info, False);
131 131
132 LockDisplay (dpy); 132 LockDisplay(dpy);
133 GetReq (XF86DGADirectVideo, req); 133 GetReq(XF86DGADirectVideo, req);
134 req->reqType = info->codes->major_opcode; 134 req->reqType = info->codes->major_opcode;
135 req->dgaReqType = X_XF86DGADirectVideo; 135 req->dgaReqType = X_XF86DGADirectVideo;
136 req->screen = screen; 136 req->screen = screen;
137 req->enable = enable; 137 req->enable = enable;
138 UnlockDisplay (dpy); 138 UnlockDisplay(dpy);
139 SyncHandle (); 139 SyncHandle();
140 XSync (dpy, False); 140 XSync(dpy, False);
141 return True; 141 return True;
142 } 142 }
143 143
144 Bool SDL_NAME (XF86DGAGetViewPortSize) (Display * dpy, 144 Bool SDL_NAME(XF86DGAGetViewPortSize) (Display * dpy,
145 int screen, int *width, int *height) 145 int screen, int *width, int *height)
146 { 146 {
147 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); 147 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
148 xXF86DGAGetViewPortSizeReply rep; 148 xXF86DGAGetViewPortSizeReply rep;
149 xXF86DGAGetViewPortSizeReq *req; 149 xXF86DGAGetViewPortSizeReq *req;
150 150
151 XF86DGACheckExtension (dpy, info, False); 151 XF86DGACheckExtension(dpy, info, False);
152 152
153 LockDisplay (dpy); 153 LockDisplay(dpy);
154 GetReq (XF86DGAGetViewPortSize, req); 154 GetReq(XF86DGAGetViewPortSize, req);
155 req->reqType = info->codes->major_opcode; 155 req->reqType = info->codes->major_opcode;
156 req->dgaReqType = X_XF86DGAGetViewPortSize; 156 req->dgaReqType = X_XF86DGAGetViewPortSize;
157 req->screen = screen; 157 req->screen = screen;
158 if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { 158 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
159 UnlockDisplay (dpy); 159 UnlockDisplay(dpy);
160 SyncHandle (); 160 SyncHandle();
161 return False; 161 return False;
162 } 162 }
163 163
164 *width = rep.width; 164 *width = rep.width;
165 *height = rep.height; 165 *height = rep.height;
166 166
167 UnlockDisplay (dpy); 167 UnlockDisplay(dpy);
168 SyncHandle (); 168 SyncHandle();
169 return True; 169 return True;
170 } 170 }
171 171
172 172
173 Bool SDL_NAME (XF86DGASetViewPort) (Display * dpy, int screen, int x, int y) 173 Bool SDL_NAME(XF86DGASetViewPort) (Display * dpy, int screen, int x, int y)
174 { 174 {
175 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); 175 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
176 xXF86DGASetViewPortReq *req; 176 xXF86DGASetViewPortReq *req;
177 177
178 XF86DGACheckExtension (dpy, info, False); 178 XF86DGACheckExtension(dpy, info, False);
179 179
180 LockDisplay (dpy); 180 LockDisplay(dpy);
181 GetReq (XF86DGASetViewPort, req); 181 GetReq(XF86DGASetViewPort, req);
182 req->reqType = info->codes->major_opcode; 182 req->reqType = info->codes->major_opcode;
183 req->dgaReqType = X_XF86DGASetViewPort; 183 req->dgaReqType = X_XF86DGASetViewPort;
184 req->screen = screen; 184 req->screen = screen;
185 req->x = x; 185 req->x = x;
186 req->y = y; 186 req->y = y;
187 UnlockDisplay (dpy); 187 UnlockDisplay(dpy);
188 SyncHandle (); 188 SyncHandle();
189 XSync (dpy, False); 189 XSync(dpy, False);
190 return True; 190 return True;
191 } 191 }
192 192
193 193
194 Bool SDL_NAME (XF86DGAGetVidPage) (Display * dpy, int screen, int *vpage) 194 Bool SDL_NAME(XF86DGAGetVidPage) (Display * dpy, int screen, int *vpage)
195 { 195 {
196 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); 196 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
197 xXF86DGAGetVidPageReply rep; 197 xXF86DGAGetVidPageReply rep;
198 xXF86DGAGetVidPageReq *req; 198 xXF86DGAGetVidPageReq *req;
199 199
200 XF86DGACheckExtension (dpy, info, False); 200 XF86DGACheckExtension(dpy, info, False);
201 201
202 LockDisplay (dpy); 202 LockDisplay(dpy);
203 GetReq (XF86DGAGetVidPage, req); 203 GetReq(XF86DGAGetVidPage, req);
204 req->reqType = info->codes->major_opcode; 204 req->reqType = info->codes->major_opcode;
205 req->dgaReqType = X_XF86DGAGetVidPage; 205 req->dgaReqType = X_XF86DGAGetVidPage;
206 req->screen = screen; 206 req->screen = screen;
207 if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { 207 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
208 UnlockDisplay (dpy); 208 UnlockDisplay(dpy);
209 SyncHandle (); 209 SyncHandle();
210 return False; 210 return False;
211 } 211 }
212 212
213 *vpage = rep.vpage; 213 *vpage = rep.vpage;
214 UnlockDisplay (dpy); 214 UnlockDisplay(dpy);
215 SyncHandle (); 215 SyncHandle();
216 return True; 216 return True;
217 } 217 }
218 218
219 219
220 Bool SDL_NAME (XF86DGASetVidPage) (Display * dpy, int screen, int vpage) 220 Bool SDL_NAME(XF86DGASetVidPage) (Display * dpy, int screen, int vpage)
221 { 221 {
222 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); 222 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
223 xXF86DGASetVidPageReq *req; 223 xXF86DGASetVidPageReq *req;
224 224
225 XF86DGACheckExtension (dpy, info, False); 225 XF86DGACheckExtension(dpy, info, False);
226 226
227 LockDisplay (dpy); 227 LockDisplay(dpy);
228 GetReq (XF86DGASetVidPage, req); 228 GetReq(XF86DGASetVidPage, req);
229 req->reqType = info->codes->major_opcode; 229 req->reqType = info->codes->major_opcode;
230 req->dgaReqType = X_XF86DGASetVidPage; 230 req->dgaReqType = X_XF86DGASetVidPage;
231 req->screen = screen; 231 req->screen = screen;
232 req->vpage = vpage; 232 req->vpage = vpage;
233 UnlockDisplay (dpy); 233 UnlockDisplay(dpy);
234 SyncHandle (); 234 SyncHandle();
235 XSync (dpy, False); 235 XSync(dpy, False);
236 return True; 236 return True;
237 } 237 }
238 238
239 Bool SDL_NAME (XF86DGAInstallColormap) (Display * dpy, 239 Bool SDL_NAME(XF86DGAInstallColormap) (Display * dpy,
240 int screen, Colormap cmap) 240 int screen, Colormap cmap)
241 { 241 {
242 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); 242 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
243 xXF86DGAInstallColormapReq *req; 243 xXF86DGAInstallColormapReq *req;
244 244
245 XF86DGACheckExtension (dpy, info, False); 245 XF86DGACheckExtension(dpy, info, False);
246 246
247 LockDisplay (dpy); 247 LockDisplay(dpy);
248 GetReq (XF86DGAInstallColormap, req); 248 GetReq(XF86DGAInstallColormap, req);
249 req->reqType = info->codes->major_opcode; 249 req->reqType = info->codes->major_opcode;
250 req->dgaReqType = X_XF86DGAInstallColormap; 250 req->dgaReqType = X_XF86DGAInstallColormap;
251 req->screen = screen; 251 req->screen = screen;
252 req->id = cmap; 252 req->id = cmap;
253 UnlockDisplay (dpy); 253 UnlockDisplay(dpy);
254 SyncHandle (); 254 SyncHandle();
255 XSync (dpy, False); 255 XSync(dpy, False);
256 return True; 256 return True;
257 } 257 }
258 258
259 Bool SDL_NAME (XF86DGAQueryDirectVideo) (Display * dpy, 259 Bool SDL_NAME(XF86DGAQueryDirectVideo) (Display * dpy, int screen, int *flags)
260 int screen, int *flags) 260 {
261 { 261 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
262 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy);
263 xXF86DGAQueryDirectVideoReply rep; 262 xXF86DGAQueryDirectVideoReply rep;
264 xXF86DGAQueryDirectVideoReq *req; 263 xXF86DGAQueryDirectVideoReq *req;
265 264
266 XF86DGACheckExtension (dpy, info, False); 265 XF86DGACheckExtension(dpy, info, False);
267 266
268 LockDisplay (dpy); 267 LockDisplay(dpy);
269 GetReq (XF86DGAQueryDirectVideo, req); 268 GetReq(XF86DGAQueryDirectVideo, req);
270 req->reqType = info->codes->major_opcode; 269 req->reqType = info->codes->major_opcode;
271 req->dgaReqType = X_XF86DGAQueryDirectVideo; 270 req->dgaReqType = X_XF86DGAQueryDirectVideo;
272 req->screen = screen; 271 req->screen = screen;
273 if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { 272 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
274 UnlockDisplay (dpy); 273 UnlockDisplay(dpy);
275 SyncHandle (); 274 SyncHandle();
276 return False; 275 return False;
277 } 276 }
278 *flags = rep.flags; 277 *flags = rep.flags;
279 UnlockDisplay (dpy); 278 UnlockDisplay(dpy);
280 SyncHandle (); 279 SyncHandle();
281 return True; 280 return True;
282 } 281 }
283 282
284 Bool SDL_NAME (XF86DGAViewPortChanged) (Display * dpy, int screen, int n) 283 Bool SDL_NAME(XF86DGAViewPortChanged) (Display * dpy, int screen, int n)
285 { 284 {
286 XExtDisplayInfo *info = SDL_NAME (xdga_find_display) (dpy); 285 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
287 xXF86DGAViewPortChangedReply rep; 286 xXF86DGAViewPortChangedReply rep;
288 xXF86DGAViewPortChangedReq *req; 287 xXF86DGAViewPortChangedReq *req;
289 288
290 XF86DGACheckExtension (dpy, info, False); 289 XF86DGACheckExtension(dpy, info, False);
291 290
292 LockDisplay (dpy); 291 LockDisplay(dpy);
293 GetReq (XF86DGAViewPortChanged, req); 292 GetReq(XF86DGAViewPortChanged, req);
294 req->reqType = info->codes->major_opcode; 293 req->reqType = info->codes->major_opcode;
295 req->dgaReqType = X_XF86DGAViewPortChanged; 294 req->dgaReqType = X_XF86DGAViewPortChanged;
296 req->screen = screen; 295 req->screen = screen;
297 req->n = n; 296 req->n = n;
298 if (!_XReply (dpy, (xReply *) & rep, 0, xFalse)) { 297 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
299 UnlockDisplay (dpy); 298 UnlockDisplay(dpy);
300 SyncHandle (); 299 SyncHandle();
301 return False; 300 return False;
302 } 301 }
303 UnlockDisplay (dpy); 302 UnlockDisplay(dpy);
304 SyncHandle (); 303 SyncHandle();
305 return rep.result; 304 return rep.result;
306 } 305 }
307 306
308 307
309 308
371 static int numScrs = 0; 370 static int numScrs = 0;
372 static MapPtr *mapList = NULL; 371 static MapPtr *mapList = NULL;
373 static ScrPtr *scrList = NULL; 372 static ScrPtr *scrList = NULL;
374 373
375 static MapPtr 374 static MapPtr
376 AddMap (void) 375 AddMap(void)
377 { 376 {
378 MapPtr *old; 377 MapPtr *old;
379 378
380 old = mapList; 379 old = mapList;
381 mapList = realloc (mapList, sizeof (MapPtr) * (numMaps + 1)); 380 mapList = realloc(mapList, sizeof(MapPtr) * (numMaps + 1));
382 if (!mapList) { 381 if (!mapList) {
383 mapList = old; 382 mapList = old;
384 return NULL; 383 return NULL;
385 } 384 }
386 mapList[numMaps] = malloc (sizeof (MapRec)); 385 mapList[numMaps] = malloc(sizeof(MapRec));
387 if (!mapList[numMaps]) 386 if (!mapList[numMaps])
388 return NULL; 387 return NULL;
389 return mapList[numMaps++]; 388 return mapList[numMaps++];
390 } 389 }
391 390
392 static ScrPtr 391 static ScrPtr
393 AddScr (void) 392 AddScr(void)
394 { 393 {
395 ScrPtr *old; 394 ScrPtr *old;
396 395
397 old = scrList; 396 old = scrList;
398 scrList = realloc (scrList, sizeof (ScrPtr) * (numScrs + 1)); 397 scrList = realloc(scrList, sizeof(ScrPtr) * (numScrs + 1));
399 if (!scrList) { 398 if (!scrList) {
400 scrList = old; 399 scrList = old;
401 return NULL; 400 return NULL;
402 } 401 }
403 scrList[numScrs] = malloc (sizeof (ScrRec)); 402 scrList[numScrs] = malloc(sizeof(ScrRec));
404 if (!scrList[numScrs]) 403 if (!scrList[numScrs])
405 return NULL; 404 return NULL;
406 return scrList[numScrs++]; 405 return scrList[numScrs++];
407 } 406 }
408 407
409 static MapPtr 408 static MapPtr
410 FindMap (unsigned long address, unsigned long size) 409 FindMap(unsigned long address, unsigned long size)
411 { 410 {
412 int i; 411 int i;
413 412
414 for (i = 0; i < numMaps; i++) { 413 for (i = 0; i < numMaps; i++) {
415 if (mapList[i]->physaddr == address && mapList[i]->size == size) 414 if (mapList[i]->physaddr == address && mapList[i]->size == size)
417 } 416 }
418 return NULL; 417 return NULL;
419 } 418 }
420 419
421 static ScrPtr 420 static ScrPtr
422 FindScr (Display * display, int screen) 421 FindScr(Display * display, int screen)
423 { 422 {
424 int i; 423 int i;
425 424
426 for (i = 0; i < numScrs; i++) { 425 for (i = 0; i < numScrs; i++) {
427 if (scrList[i]->display == display && scrList[i]->screen == screen) 426 if (scrList[i]->display == display && scrList[i]->screen == screen)
429 } 428 }
430 return NULL; 429 return NULL;
431 } 430 }
432 431
433 static void * 432 static void *
434 MapPhysAddress (unsigned long address, unsigned long size) 433 MapPhysAddress(unsigned long address, unsigned long size)
435 { 434 {
436 unsigned long offset, delta; 435 unsigned long offset, delta;
437 int pagesize = -1; 436 int pagesize = -1;
438 void *vaddr; 437 void *vaddr;
439 MapPtr mp; 438 MapPtr mp;
443 APIRET rc; 442 APIRET rc;
444 ULONG action; 443 ULONG action;
445 HFILE hfd; 444 HFILE hfd;
446 #endif 445 #endif
447 446
448 if ((mp = FindMap (address, size))) { 447 if ((mp = FindMap(address, size))) {
449 mp->refcount++; 448 mp->refcount++;
450 return (void *) ((unsigned long) mp->vaddr + mp->delta); 449 return (void *) ((unsigned long) mp->vaddr + mp->delta);
451 } 450 }
452 #if defined(_SC_PAGESIZE) && defined(HAS_SC_PAGESIZE) 451 #if defined(_SC_PAGESIZE) && defined(HAS_SC_PAGESIZE)
453 pagesize = sysconf (_SC_PAGESIZE); 452 pagesize = sysconf(_SC_PAGESIZE);
454 #endif 453 #endif
455 #ifdef _SC_PAGE_SIZE 454 #ifdef _SC_PAGE_SIZE
456 if (pagesize == -1) 455 if (pagesize == -1)
457 pagesize = sysconf (_SC_PAGE_SIZE); 456 pagesize = sysconf(_SC_PAGE_SIZE);
458 #endif 457 #endif
459 #ifdef HAS_GETPAGESIZE 458 #ifdef HAS_GETPAGESIZE
460 if (pagesize == -1) 459 if (pagesize == -1)
461 pagesize = getpagesize (); 460 pagesize = getpagesize();
462 #endif 461 #endif
463 #ifdef PAGE_SIZE 462 #ifdef PAGE_SIZE
464 if (pagesize == -1) 463 if (pagesize == -1)
465 pagesize = PAGE_SIZE; 464 pagesize = PAGE_SIZE;
466 #endif 465 #endif
470 delta = address % pagesize; 469 delta = address % pagesize;
471 offset = address - delta; 470 offset = address - delta;
472 471
473 #if defined(ISC) && defined(HAS_SVR3_MMAP) 472 #if defined(ISC) && defined(HAS_SVR3_MMAP)
474 if (mapFd < 0) { 473 if (mapFd < 0) {
475 if ((mapFd = open ("/dev/mmap", O_RDWR)) < 0) 474 if ((mapFd = open("/dev/mmap", O_RDWR)) < 0)
476 return NULL; 475 return NULL;
477 } 476 }
478 mloc.vaddr = (char *) 0; 477 mloc.vaddr = (char *) 0;
479 mloc.physaddr = (char *) offset; 478 mloc.physaddr = (char *) offset;
480 mloc.length = size + delta; 479 mloc.length = size + delta;
481 mloc.ioflg = 1; 480 mloc.ioflg = 1;
482 481
483 if ((vaddr = (void *) ioctl (mapFd, MAP, &mloc)) == (void *) -1) 482 if ((vaddr = (void *) ioctl(mapFd, MAP, &mloc)) == (void *) -1)
484 return NULL; 483 return NULL;
485 #elif defined (__EMX__) 484 #elif defined (__EMX__)
486 /* 485 /*
487 * Dragon warning here! /dev/pmap$ is never closed, except on progam exit. 486 * Dragon warning here! /dev/pmap$ is never closed, except on progam exit.
488 * Consecutive calling of this routine will make PMAP$ driver run out 487 * Consecutive calling of this routine will make PMAP$ driver run out
489 * of memory handles. Some umap/close mechanism should be provided 488 * of memory handles. Some umap/close mechanism should be provided
490 */ 489 */
491 490
492 rc = DosOpen ("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN, 491 rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN,
493 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2) NULL); 492 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2) NULL);
494 if (rc != 0) 493 if (rc != 0)
495 return NULL; 494 return NULL;
496 { 495 {
497 struct map_ioctl 496 struct map_ioctl
498 { 497 {
507 #define XFREE86_PMAP 0x76 506 #define XFREE86_PMAP 0x76
508 #define PMAP_MAP 0x44 507 #define PMAP_MAP 0x44
509 508
510 pmap.a.phys = offset; 509 pmap.a.phys = offset;
511 pmap.size = size + delta; 510 pmap.size = size + delta;
512 rc = DosDevIOCtl (hfd, XFREE86_PMAP, PMAP_MAP, 511 rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP,
513 (PULONG) & pmap, sizeof (pmap), &plen, 512 (PULONG) & pmap, sizeof(pmap), &plen,
514 (PULONG) & dmap, sizeof (dmap), &dlen); 513 (PULONG) & dmap, sizeof(dmap), &dlen);
515 if (rc == 0) { 514 if (rc == 0) {
516 vaddr = dmap.a.user; 515 vaddr = dmap.a.user;
517 } 516 }
518 } 517 }
519 if (rc != 0) 518 if (rc != 0)
520 return NULL; 519 return NULL;
521 #elif defined (Lynx) 520 #elif defined (Lynx)
522 vaddr = (void *) smem_create ("XF86DGA", (char *) offset, 521 vaddr = (void *) smem_create("XF86DGA", (char *) offset,
523 size + delta, SM_READ | SM_WRITE); 522 size + delta, SM_READ | SM_WRITE);
524 #else 523 #else
525 #ifndef MAP_FILE 524 #ifndef MAP_FILE
526 #define MAP_FILE 0 525 #define MAP_FILE 0
527 #endif 526 #endif
528 if (mapFd < 0) { 527 if (mapFd < 0) {
529 if ((mapFd = open (DEV_MEM, O_RDWR)) < 0) 528 if ((mapFd = open(DEV_MEM, O_RDWR)) < 0)
530 return NULL; 529 return NULL;
531 } 530 }
532 vaddr = (void *) mmap (NULL, size + delta, PROT_READ | PROT_WRITE, 531 vaddr = (void *) mmap(NULL, size + delta, PROT_READ | PROT_WRITE,
533 MAP_FILE | MAP_SHARED, mapFd, (off_t) offset); 532 MAP_FILE | MAP_SHARED, mapFd, (off_t) offset);
534 if (vaddr == (void *) -1) 533 if (vaddr == (void *) -1)
535 return NULL; 534 return NULL;
536 #endif 535 #endif
537 536
538 if (!vaddr) { 537 if (!vaddr) {
539 if (!(mp = AddMap ())) 538 if (!(mp = AddMap()))
540 return NULL; 539 return NULL;
541 mp->physaddr = address; 540 mp->physaddr = address;
542 mp->size = size; 541 mp->size = size;
543 mp->delta = delta; 542 mp->delta = delta;
544 mp->vaddr = vaddr; 543 mp->vaddr = vaddr;
552 * and returning things to normal - Jon 551 * and returning things to normal - Jon
553 * This is here to help debugging without rebooting... Also C-A-BS 552 * This is here to help debugging without rebooting... Also C-A-BS
554 * should restore text mode. 553 * should restore text mode.
555 */ 554 */
556 555
557 int SDL_NAME (XF86DGAForkApp) (int screen) 556 int SDL_NAME(XF86DGAForkApp) (int screen)
558 { 557 {
559 pid_t pid; 558 pid_t pid;
560 int status; 559 int status;
561 int i; 560 int i;
562 561
563 /* fork the app, parent hangs around to clean up */ 562 /* fork the app, parent hangs around to clean up */
564 if ((pid = fork ()) > 0) { 563 if ((pid = fork()) > 0) {
565 ScrPtr sp; 564 ScrPtr sp;
566 565
567 waitpid (pid, &status, 0); 566 waitpid(pid, &status, 0);
568 for (i = 0; i < numScrs; i++) { 567 for (i = 0; i < numScrs; i++) {
569 sp = scrList[i]; 568 sp = scrList[i];
570 SDL_NAME (XF86DGADirectVideoLL) (sp->display, sp->screen, 0); 569 SDL_NAME(XF86DGADirectVideoLL) (sp->display, sp->screen, 0);
571 XSync (sp->display, False); 570 XSync(sp->display, False);
572 } 571 }
573 if (WIFEXITED (status)) 572 if (WIFEXITED(status))
574 _exit (0); 573 _exit(0);
575 else 574 else
576 _exit (-1); 575 _exit(-1);
577 } 576 }
578 return pid; 577 return pid;
579 } 578 }
580 579
581 580
582 Bool SDL_NAME (XF86DGADirectVideo) (Display * dis, int screen, int enable) 581 Bool SDL_NAME(XF86DGADirectVideo) (Display * dis, int screen, int enable)
583 { 582 {
584 ScrPtr sp; 583 ScrPtr sp;
585 MapPtr mp = NULL; 584 MapPtr mp = NULL;
586 585
587 if ((sp = FindScr (dis, screen))) 586 if ((sp = FindScr(dis, screen)))
588 mp = sp->map; 587 mp = sp->map;
589 588
590 if (enable & XF86DGADirectGraphics) { 589 if (enable & XF86DGADirectGraphics) {
591 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ 590 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
592 && !defined(__EMX__) 591 && !defined(__EMX__)
593 if (mp && mp->vaddr) 592 if (mp && mp->vaddr)
594 mprotect (mp->vaddr, mp->size + mp->delta, 593 mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ | PROT_WRITE);
595 PROT_READ | PROT_WRITE);
596 #endif 594 #endif
597 } else { 595 } else {
598 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ 596 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
599 && !defined(__EMX__) 597 && !defined(__EMX__)
600 if (mp && mp->vaddr) 598 if (mp && mp->vaddr)
601 mprotect (mp->vaddr, mp->size + mp->delta, PROT_READ); 599 mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ);
602 #elif defined(Lynx) 600 #elif defined(Lynx)
603 /* XXX this doesn't allow enable after disable */ 601 /* XXX this doesn't allow enable after disable */
604 smem_create (NULL, mp->vaddr, mp->size + mp->delta, SM_DETACH); 602 smem_create(NULL, mp->vaddr, mp->size + mp->delta, SM_DETACH);
605 smem_remove ("XF86DGA"); 603 smem_remove("XF86DGA");
606 #endif 604 #endif
607 } 605 }
608 606
609 SDL_NAME (XF86DGADirectVideoLL) (dis, screen, enable); 607 SDL_NAME(XF86DGADirectVideoLL) (dis, screen, enable);
610 return 1; 608 return 1;
611 } 609 }
612 610
613 611
614 static void 612 static void
615 XF86cleanup (int sig) 613 XF86cleanup(int sig)
616 { 614 {
617 ScrPtr sp; 615 ScrPtr sp;
618 int i; 616 int i;
619 static char beenhere = 0; 617 static char beenhere = 0;
620 618
621 if (beenhere) 619 if (beenhere)
622 _exit (3); 620 _exit(3);
623 beenhere = 1; 621 beenhere = 1;
624 622
625 for (i = 0; i < numScrs; i++) { 623 for (i = 0; i < numScrs; i++) {
626 sp = scrList[i]; 624 sp = scrList[i];
627 SDL_NAME (XF86DGADirectVideo) (sp->display, sp->screen, 0); 625 SDL_NAME(XF86DGADirectVideo) (sp->display, sp->screen, 0);
628 XSync (sp->display, False); 626 XSync(sp->display, False);
629 } 627 }
630 _exit (3); 628 _exit(3);
631 } 629 }
632 630
633 Bool 631 Bool
634 SDL_NAME (XF86DGAGetVideo) (Display * dis, 632 SDL_NAME(XF86DGAGetVideo) (Display * dis,
635 int screen, 633 int screen,
636 char **addr, int *width, int *bank, int *ram) 634 char **addr, int *width, int *bank, int *ram)
637 { 635 {
638 /*unsigned long */ int offset; 636 /*unsigned long */ int offset;
639 static int beenHere = 0; 637 static int beenHere = 0;
640 ScrPtr sp; 638 ScrPtr sp;
641 MapPtr mp; 639 MapPtr mp;
642 640
643 if (!(sp = FindScr (dis, screen))) { 641 if (!(sp = FindScr(dis, screen))) {
644 if (!(sp = AddScr ())) { 642 if (!(sp = AddScr())) {
645 fprintf (stderr, "XF86DGAGetVideo: malloc failure\n"); 643 fprintf(stderr, "XF86DGAGetVideo: malloc failure\n");
646 exit (-2); 644 exit(-2);
647 } 645 }
648 sp->display = dis; 646 sp->display = dis;
649 sp->screen = screen; 647 sp->screen = screen;
650 sp->map = NULL; 648 sp->map = NULL;
651 } 649 }
652 650
653 SDL_NAME (XF86DGAGetVideoLL) (dis, screen, &offset, width, bank, ram); 651 SDL_NAME(XF86DGAGetVideoLL) (dis, screen, &offset, width, bank, ram);
654 652
655 *addr = MapPhysAddress (offset, *bank); 653 *addr = MapPhysAddress(offset, *bank);
656 if (*addr == NULL) { 654 if (*addr == NULL) {
657 fprintf (stderr, 655 fprintf(stderr,
658 "XF86DGAGetVideo: failed to map video memory (%s)\n", 656 "XF86DGAGetVideo: failed to map video memory (%s)\n",
659 strerror (errno)); 657 strerror(errno));
660 exit (-2); 658 exit(-2);
661 } 659 }
662 660
663 if ((mp = FindMap (offset, *bank))) 661 if ((mp = FindMap(offset, *bank)))
664 sp->map = mp; 662 sp->map = mp;
665 663
666 if (!beenHere) { 664 if (!beenHere) {
667 beenHere = 1; 665 beenHere = 1;
668 atexit ((void (*)(void)) XF86cleanup); 666 atexit((void (*)(void)) XF86cleanup);
669 /* one shot XF86cleanup attempts */ 667 /* one shot XF86cleanup attempts */
670 signal (SIGSEGV, XF86cleanup); 668 signal(SIGSEGV, XF86cleanup);
671 #ifdef SIGBUS 669 #ifdef SIGBUS
672 signal (SIGBUS, XF86cleanup); 670 signal(SIGBUS, XF86cleanup);
673 #endif 671 #endif
674 signal (SIGHUP, XF86cleanup); 672 signal(SIGHUP, XF86cleanup);
675 signal (SIGFPE, XF86cleanup); 673 signal(SIGFPE, XF86cleanup);
676 } 674 }
677 675
678 return 1; 676 return 1;
679 } 677 }
680 678