comparison src/video/Xext/Xxf86dga/XF86DGA2.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents ecba4bbaf9c2
children
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
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
22 #include "../extensions/xf86dgastr.h" 22 #include "../extensions/xf86dgastr.h"
23 #include "../extensions/Xext.h" 23 #include "../extensions/Xext.h"
24 #include "../extensions/extutil.h" 24 #include "../extensions/extutil.h"
25 #include <stdio.h> 25 #include <stdio.h>
26 26
27 #if defined(ENABLE_FBCON) /* Needed for framebuffer console support */ 27 #if defined(ENABLE_FBCON) /* Needed for framebuffer console support */
28 #include <sys/ioctl.h> 28 #include <sys/ioctl.h>
29 #include <linux/fb.h> 29 #include <linux/fb.h>
30 #endif 30 #endif
31 31
32 /* If you change this, change the Bases[] array below as well */ 32 /* If you change this, change the Bases[] array below as well */
35 char *SDL_NAME(xdga_extension_name) = XF86DGANAME; 35 char *SDL_NAME(xdga_extension_name) = XF86DGANAME;
36 36
37 static XExtensionInfo _xdga_info_data; 37 static XExtensionInfo _xdga_info_data;
38 static XExtensionInfo *xdga_info = &_xdga_info_data; 38 static XExtensionInfo *xdga_info = &_xdga_info_data;
39 39
40 40
41 Bool SDL_NAME(XDGAMapFramebuffer)(int, char *, unsigned char*, CARD32, CARD32, CARD32); 41 Bool SDL_NAME(XDGAMapFramebuffer) (int, char *, unsigned char *, CARD32,
42 void SDL_NAME(XDGAUnmapFramebuffer)(int); 42 CARD32, CARD32);
43 unsigned char* SDL_NAME(XDGAGetMappedMemory)(int); 43 void SDL_NAME(XDGAUnmapFramebuffer) (int);
44 unsigned char *SDL_NAME(XDGAGetMappedMemory) (int);
44 45
45 #define XDGACheckExtension(dpy,i,val) \ 46 #define XDGACheckExtension(dpy,i,val) \
46 XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val) 47 XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val)
47 48
48 /***************************************************************************** 49 /*****************************************************************************
49 * * 50 * *
50 * private utility routines * 51 * private utility routines *
51 * * 52 * *
52 *****************************************************************************/ 53 *****************************************************************************/
53 54
54 static int xdga_close_display(Display *dpy, XExtCodes *codes); 55 static int xdga_close_display(Display * dpy, XExtCodes * codes);
55 static Bool xdga_wire_to_event(Display *dpy, XEvent *event, xEvent *wire_ev); 56 static Bool xdga_wire_to_event(Display * dpy, XEvent * event,
56 static Status xdga_event_to_wire(Display *dpy, XEvent *event, xEvent *wire_ev); 57 xEvent * wire_ev);
58 static Status xdga_event_to_wire(Display * dpy, XEvent * event,
59 xEvent * wire_ev);
57 60
58 static XExtensionHooks xdga_extension_hooks = { 61 static XExtensionHooks xdga_extension_hooks = {
59 NULL, /* create_gc */ 62 NULL, /* create_gc */
60 NULL, /* copy_gc */ 63 NULL, /* copy_gc */
61 NULL, /* flush_gc */ 64 NULL, /* flush_gc */
62 NULL, /* free_gc */ 65 NULL, /* free_gc */
63 NULL, /* create_font */ 66 NULL, /* create_font */
64 NULL, /* free_font */ 67 NULL, /* free_font */
65 xdga_close_display, /* close_display */ 68 xdga_close_display, /* close_display */
66 xdga_wire_to_event, /* wire_to_event */ 69 xdga_wire_to_event, /* wire_to_event */
67 xdga_event_to_wire, /* event_to_wire */ 70 xdga_event_to_wire, /* event_to_wire */
68 NULL, /* error */ 71 NULL, /* error */
69 NULL, /* error_string */ 72 NULL, /* error_string */
70 }; 73 };
71 74
72 static XEXT_GENERATE_CLOSE_DISPLAY (xdga_close_display, xdga_info) 75 static
73 76 XEXT_GENERATE_CLOSE_DISPLAY(xdga_close_display, xdga_info)
74 77 XEXT_GENERATE_FIND_DISPLAY(SDL_NAME(xdga_find_display), xdga_info,
75 XEXT_GENERATE_FIND_DISPLAY (SDL_NAME(xdga_find_display), xdga_info, 78 "XFree86-DGA", &xdga_extension_hooks, 0, NULL)
76 "XFree86-DGA", 79 static Status
77 &xdga_extension_hooks, 80 xdga_event_to_wire(Display * dpy, XEvent * event, xEvent * wire_ev)
78 0, NULL) 81 {
79
80
81 static Status
82 xdga_event_to_wire(
83 Display *dpy,
84 XEvent *event,
85 xEvent *wire_ev
86 ){
87 return True; 82 return True;
88 } 83 }
89 84
90 static Bool 85 static Bool
91 xdga_wire_to_event( 86 xdga_wire_to_event(Display * dpy, XEvent * event, xEvent * wire_ev)
92 Display *dpy, 87 {
93 XEvent *event, 88 dgaEvent *wire = (dgaEvent *) wire_ev;
94 xEvent *wire_ev 89 SDL_NAME(XDGAButtonEvent) * bevent;
95 ){ 90 SDL_NAME(XDGAKeyEvent) * kevent;
96 dgaEvent *wire = (dgaEvent *) wire_ev; 91 SDL_NAME(XDGAMotionEvent) * mevent;
97 SDL_NAME(XDGAButtonEvent) *bevent; 92 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
98 SDL_NAME(XDGAKeyEvent) *kevent; 93
99 SDL_NAME(XDGAMotionEvent) *mevent; 94 XDGACheckExtension(dpy, info, False);
100 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 95
101 96 switch ((wire->u.u.type & 0x7f) - info->codes->first_event) {
102 XDGACheckExtension (dpy, info, False); 97 case MotionNotify:
103 98 mevent = (SDL_NAME(XDGAMotionEvent) *) event;
104 switch((wire->u.u.type & 0x7f) - info->codes->first_event) { 99 mevent->type = wire->u.u.type & 0x7F;
105 case MotionNotify: 100 mevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire);
106 mevent = (SDL_NAME(XDGAMotionEvent)*)event; 101 mevent->display = dpy;
107 mevent->type = wire->u.u.type & 0x7F; 102 mevent->screen = wire->u.event.screen;
108 mevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire); 103 mevent->time = wire->u.event.time;
109 mevent->display = dpy; 104 mevent->state = wire->u.event.state;
110 mevent->screen = wire->u.event.screen; 105 mevent->dx = wire->u.event.dx;
111 mevent->time = wire->u.event.time; 106 mevent->dy = wire->u.event.dy;
112 mevent->state = wire->u.event.state; 107 return True;
113 mevent->dx = wire->u.event.dx; 108 case ButtonPress:
114 mevent->dy = wire->u.event.dy; 109 case ButtonRelease:
115 return True; 110 bevent = (SDL_NAME(XDGAButtonEvent) *) event;
116 case ButtonPress: 111 bevent->type = wire->u.u.type & 0x7F;
117 case ButtonRelease: 112 bevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire);
118 bevent = (SDL_NAME(XDGAButtonEvent)*)event; 113 bevent->display = dpy;
119 bevent->type = wire->u.u.type & 0x7F; 114 bevent->screen = wire->u.event.screen;
120 bevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire); 115 bevent->time = wire->u.event.time;
121 bevent->display = dpy; 116 bevent->state = wire->u.event.state;
122 bevent->screen = wire->u.event.screen; 117 bevent->button = wire->u.u.detail;
123 bevent->time = wire->u.event.time; 118 return True;
124 bevent->state = wire->u.event.state; 119 case KeyPress:
125 bevent->button = wire->u.u.detail; 120 case KeyRelease:
126 return True; 121 kevent = (SDL_NAME(XDGAKeyEvent) *) event;
127 case KeyPress: 122 kevent->type = wire->u.u.type & 0x7F;
128 case KeyRelease: 123 kevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire);
129 kevent = (SDL_NAME(XDGAKeyEvent)*)event; 124 kevent->display = dpy;
130 kevent->type = wire->u.u.type & 0x7F; 125 kevent->screen = wire->u.event.screen;
131 kevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire); 126 kevent->time = wire->u.event.time;
132 kevent->display = dpy; 127 kevent->state = wire->u.event.state;
133 kevent->screen = wire->u.event.screen; 128 kevent->keycode = wire->u.u.detail;
134 kevent->time = wire->u.event.time; 129 return True;
135 kevent->state = wire->u.event.state; 130 }
136 kevent->keycode = wire->u.u.detail; 131
137 return True; 132 return False;
138 } 133 }
139 134
140 return False; 135
141 } 136 Bool SDL_NAME(XDGAQueryExtension) (Display * dpy,
142 137 int *event_basep, int *error_basep)
143 138 {
144 Bool SDL_NAME(XDGAQueryExtension) (
145 Display *dpy,
146 int *event_basep,
147 int *error_basep
148 ){
149 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 139 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
150 140
151 if (XextHasExtension(info)) { 141 if (XextHasExtension(info)) {
152 *event_basep = info->codes->first_event; 142 *event_basep = info->codes->first_event;
153 *error_basep = info->codes->first_error; 143 *error_basep = info->codes->first_error;
154 return True; 144 return True;
155 } else { 145 } else {
156 return False; 146 return False;
157 } 147 }
158 } 148 }
159 149
160 150
161 Bool SDL_NAME(XDGAQueryVersion)( 151 Bool SDL_NAME(XDGAQueryVersion) (Display * dpy,
162 Display *dpy, 152 int *majorVersion, int *minorVersion)
163 int *majorVersion, 153 {
164 int *minorVersion
165 ){
166 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 154 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
167 xXDGAQueryVersionReply rep; 155 xXDGAQueryVersionReply rep;
168 xXDGAQueryVersionReq *req; 156 xXDGAQueryVersionReq *req;
169 157
170 XDGACheckExtension (dpy, info, False); 158 XDGACheckExtension(dpy, info, False);
171 159
172 LockDisplay(dpy); 160 LockDisplay(dpy);
173 GetReq(XDGAQueryVersion, req); 161 GetReq(XDGAQueryVersion, req);
174 req->reqType = info->codes->major_opcode; 162 req->reqType = info->codes->major_opcode;
175 req->dgaReqType = X_XDGAQueryVersion; 163 req->dgaReqType = X_XDGAQueryVersion;
176 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 164 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
177 UnlockDisplay(dpy); 165 UnlockDisplay(dpy);
178 SyncHandle(); 166 SyncHandle();
179 return False; 167 return False;
180 } 168 }
181 *majorVersion = rep.majorVersion; 169 *majorVersion = rep.majorVersion;
182 *minorVersion = rep.minorVersion; 170 *minorVersion = rep.minorVersion;
183 UnlockDisplay(dpy); 171 UnlockDisplay(dpy);
184 SyncHandle(); 172 SyncHandle();
185 if (*majorVersion >= 2) 173 if (*majorVersion >= 2) {
186 { 174 int i, j;
187 int i, j; 175
188 176 for (i = 0, j = info->codes->first_event;
189 for (i = 0, j = info->codes->first_event; 177 i < XF86DGANumberEvents; i++, j++) {
190 i < XF86DGANumberEvents; 178 XESetWireToEvent(dpy, j, xdga_wire_to_event);
191 i++, j++) 179 XESetEventToWire(dpy, j, xdga_event_to_wire);
192 { 180 }
193 XESetWireToEvent(dpy, j, xdga_wire_to_event); 181 SDL_NAME(XDGASetClientVersion) (dpy);
194 XESetEventToWire(dpy, j, xdga_event_to_wire);
195 }
196 SDL_NAME(XDGASetClientVersion)(dpy);
197 } 182 }
198 return True; 183 return True;
199 } 184 }
200 185
201 Bool SDL_NAME(XDGASetClientVersion)( 186 Bool SDL_NAME(XDGASetClientVersion) (Display * dpy)
202 Display *dpy 187 {
203 ){
204 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 188 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
205 xXDGASetClientVersionReq *req; 189 xXDGASetClientVersionReq *req;
206 190
207 XDGACheckExtension (dpy, info, False); 191 XDGACheckExtension(dpy, info, False);
208 192
209 LockDisplay(dpy); 193 LockDisplay(dpy);
210 GetReq(XDGASetClientVersion, req); 194 GetReq(XDGASetClientVersion, req);
211 req->reqType = info->codes->major_opcode; 195 req->reqType = info->codes->major_opcode;
212 req->dgaReqType = X_XDGASetClientVersion; 196 req->dgaReqType = X_XDGASetClientVersion;
215 UnlockDisplay(dpy); 199 UnlockDisplay(dpy);
216 SyncHandle(); 200 SyncHandle();
217 return True; 201 return True;
218 } 202 }
219 203
220 Bool SDL_NAME(XDGAOpenFramebuffer)( 204 Bool SDL_NAME(XDGAOpenFramebuffer) (Display * dpy, int screen)
221 Display *dpy, 205 {
222 int screen
223 ){
224 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 206 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
225 xXDGAOpenFramebufferReply rep; 207 xXDGAOpenFramebufferReply rep;
226 xXDGAOpenFramebufferReq *req; 208 xXDGAOpenFramebufferReq *req;
227 char *deviceName = NULL; 209 char *deviceName = NULL;
228 Bool ret; 210 Bool ret;
229 211
230 XDGACheckExtension (dpy, info, False); 212 XDGACheckExtension(dpy, info, False);
231 213
232 LockDisplay(dpy); 214 LockDisplay(dpy);
233 GetReq(XDGAOpenFramebuffer, req); 215 GetReq(XDGAOpenFramebuffer, req);
234 req->reqType = info->codes->major_opcode; 216 req->reqType = info->codes->major_opcode;
235 req->dgaReqType = X_XDGAOpenFramebuffer; 217 req->dgaReqType = X_XDGAOpenFramebuffer;
236 req->screen = screen; 218 req->screen = screen;
237 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 219 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
238 UnlockDisplay(dpy); 220 UnlockDisplay(dpy);
239 SyncHandle(); 221 SyncHandle();
240 return False; 222 return False;
241 } 223 }
242 224
243 if(rep.length) { 225 if (rep.length) {
244 deviceName = Xmalloc(rep.length << 2); 226 deviceName = Xmalloc(rep.length << 2);
245 _XRead(dpy, deviceName, rep.length << 2); 227 _XRead(dpy, deviceName, rep.length << 2);
246 } 228 }
247 229
248 ret = SDL_NAME(XDGAMapFramebuffer)(screen, deviceName, 230 ret = SDL_NAME(XDGAMapFramebuffer) (screen, deviceName,
249 (unsigned char*)(long)rep.mem1, 231 (unsigned char *) (long) rep.mem1,
250 rep.size, rep.offset, rep.extra); 232 rep.size, rep.offset, rep.extra);
251 233
252 if(deviceName) 234 if (deviceName)
253 Xfree(deviceName); 235 Xfree(deviceName);
254 236
255 UnlockDisplay(dpy); 237 UnlockDisplay(dpy);
256 SyncHandle(); 238 SyncHandle();
257 return ret; 239 return ret;
258 } 240 }
259 241
260 void SDL_NAME(XDGACloseFramebuffer)( 242 void SDL_NAME(XDGACloseFramebuffer) (Display * dpy, int screen)
261 Display *dpy, 243 {
262 int screen
263 ){
264 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 244 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
265 xXDGACloseFramebufferReq *req; 245 xXDGACloseFramebufferReq *req;
266 246
267 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); 247 XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
268 248
269 SDL_NAME(XDGAUnmapFramebuffer)(screen); 249 SDL_NAME(XDGAUnmapFramebuffer) (screen);
270 250
271 LockDisplay(dpy); 251 LockDisplay(dpy);
272 GetReq(XDGACloseFramebuffer, req); 252 GetReq(XDGACloseFramebuffer, req);
273 req->reqType = info->codes->major_opcode; 253 req->reqType = info->codes->major_opcode;
274 req->dgaReqType = X_XDGACloseFramebuffer; 254 req->dgaReqType = X_XDGACloseFramebuffer;
277 SyncHandle(); 257 SyncHandle();
278 } 258 }
279 259
280 260
281 261
282 SDL_NAME(XDGAMode)* SDL_NAME(XDGAQueryModes)( 262 SDL_NAME(XDGAMode) * SDL_NAME(XDGAQueryModes) (Display * dpy,
283 Display *dpy, 263 int screen, int *num)
284 int screen, 264 {
285 int *num
286 ){
287 XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy); 265 XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy);
288 xXDGAQueryModesReply rep; 266 xXDGAQueryModesReply rep;
289 xXDGAQueryModesReq *req; 267 xXDGAQueryModesReq *req;
290 SDL_NAME(XDGAMode) *modes = NULL; 268 SDL_NAME(XDGAMode) * modes = NULL;
291 269
292 *num = 0; 270 *num = 0;
293 271
294 XDGACheckExtension (dpy, dinfo, NULL); 272 XDGACheckExtension(dpy, dinfo, NULL);
295 273
296 LockDisplay(dpy); 274 LockDisplay(dpy);
297 GetReq(XDGAQueryModes, req); 275 GetReq(XDGAQueryModes, req);
298 req->reqType = dinfo->codes->major_opcode; 276 req->reqType = dinfo->codes->major_opcode;
299 req->dgaReqType = X_XDGAQueryModes; 277 req->dgaReqType = X_XDGAQueryModes;
300 req->screen = screen; 278 req->screen = screen;
301 279
302 if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 280 if (_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
303 if(rep.length) { 281 if (rep.length) {
304 xXDGAModeInfo info; 282 xXDGAModeInfo info;
305 int i, size; 283 int i, size;
306 char *offset; 284 char *offset;
307 285
308 size = rep.length << 2; 286 size = rep.length << 2;
309 size -= rep.number * sz_xXDGAModeInfo; /* find text size */ 287 size -= rep.number * sz_xXDGAModeInfo; /* find text size */
310 modes = (SDL_NAME(XDGAMode)*)Xmalloc((rep.number * sizeof(SDL_NAME(XDGAMode))) + size); 288 modes = (SDL_NAME(XDGAMode) *)
311 offset = (char*)(&modes[rep.number]); /* start of text */ 289 Xmalloc((rep.number * sizeof(SDL_NAME(XDGAMode))) + size);
312 290 offset = (char *) (&modes[rep.number]); /* start of text */
313 291
314 if(modes) { 292
315 for(i = 0; i < rep.number; i++) { 293 if (modes) {
316 _XRead(dpy, (char*)(&info), sz_xXDGAModeInfo); 294 for (i = 0; i < rep.number; i++) {
317 295 _XRead(dpy, (char *) (&info), sz_xXDGAModeInfo);
318 modes[i].num = info.num; 296
319 modes[i].verticalRefresh = 297 modes[i].num = info.num;
320 (float)info.vsync_num / (float)info.vsync_den; 298 modes[i].verticalRefresh =
321 modes[i].flags = info.flags; 299 (float) info.vsync_num / (float) info.vsync_den;
322 modes[i].imageWidth = info.image_width; 300 modes[i].flags = info.flags;
323 modes[i].imageHeight = info.image_height; 301 modes[i].imageWidth = info.image_width;
324 modes[i].pixmapWidth = info.pixmap_width; 302 modes[i].imageHeight = info.image_height;
325 modes[i].pixmapHeight = info.pixmap_height; 303 modes[i].pixmapWidth = info.pixmap_width;
326 modes[i].bytesPerScanline = info.bytes_per_scanline; 304 modes[i].pixmapHeight = info.pixmap_height;
327 modes[i].byteOrder = info.byte_order; 305 modes[i].bytesPerScanline = info.bytes_per_scanline;
328 modes[i].depth = info.depth; 306 modes[i].byteOrder = info.byte_order;
329 modes[i].bitsPerPixel = info.bpp; 307 modes[i].depth = info.depth;
330 modes[i].redMask = info.red_mask; 308 modes[i].bitsPerPixel = info.bpp;
331 modes[i].greenMask = info.green_mask; 309 modes[i].redMask = info.red_mask;
332 modes[i].blueMask = info.blue_mask; 310 modes[i].greenMask = info.green_mask;
333 modes[i].visualClass = info.visual_class; 311 modes[i].blueMask = info.blue_mask;
334 modes[i].viewportWidth = info.viewport_width; 312 modes[i].visualClass = info.visual_class;
335 modes[i].viewportHeight = info.viewport_height; 313 modes[i].viewportWidth = info.viewport_width;
336 modes[i].xViewportStep = info.viewport_xstep; 314 modes[i].viewportHeight = info.viewport_height;
337 modes[i].yViewportStep = info.viewport_ystep; 315 modes[i].xViewportStep = info.viewport_xstep;
338 modes[i].maxViewportX = info.viewport_xmax; 316 modes[i].yViewportStep = info.viewport_ystep;
339 modes[i].maxViewportY = info.viewport_ymax; 317 modes[i].maxViewportX = info.viewport_xmax;
340 modes[i].viewportFlags = info.viewport_flags; 318 modes[i].maxViewportY = info.viewport_ymax;
341 modes[i].reserved1 = info.reserved1; 319 modes[i].viewportFlags = info.viewport_flags;
342 modes[i].reserved2 = info.reserved2; 320 modes[i].reserved1 = info.reserved1;
343 321 modes[i].reserved2 = info.reserved2;
344 _XRead(dpy, offset, info.name_size); 322
345 modes[i].name = offset; 323 _XRead(dpy, offset, info.name_size);
346 offset += info.name_size; 324 modes[i].name = offset;
347 } 325 offset += info.name_size;
348 *num = rep.number; 326 }
349 } else 327 *num = rep.number;
350 _XEatData(dpy, rep.length << 2); 328 } else
351 } 329 _XEatData(dpy, rep.length << 2);
330 }
352 } 331 }
353 332
354 UnlockDisplay(dpy); 333 UnlockDisplay(dpy);
355 SyncHandle(); 334 SyncHandle();
356 335
357 return modes; 336 return modes;
358 } 337 }
359 338
360 339
361 SDL_NAME(XDGADevice) * 340 SDL_NAME(XDGADevice) *
362 SDL_NAME(XDGASetMode)( 341 SDL_NAME(XDGASetMode) (Display * dpy, int screen, int mode)
363 Display *dpy, 342 {
364 int screen,
365 int mode
366 ){
367 XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy); 343 XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy);
368 xXDGASetModeReply rep; 344 xXDGASetModeReply rep;
369 xXDGASetModeReq *req; 345 xXDGASetModeReq *req;
370 SDL_NAME(XDGADevice) *dev = NULL; 346 SDL_NAME(XDGADevice) * dev = NULL;
371 Pixmap pid; 347 Pixmap pid;
372 348
373 XDGACheckExtension (dpy, dinfo, NULL); 349 XDGACheckExtension(dpy, dinfo, NULL);
374 350
375 LockDisplay(dpy); 351 LockDisplay(dpy);
376 GetReq(XDGASetMode, req); 352 GetReq(XDGASetMode, req);
377 req->reqType = dinfo->codes->major_opcode; 353 req->reqType = dinfo->codes->major_opcode;
378 req->dgaReqType = X_XDGASetMode; 354 req->dgaReqType = X_XDGASetMode;
379 req->screen = screen; 355 req->screen = screen;
380 req->mode = mode; 356 req->mode = mode;
381 req->pid = pid = XAllocID(dpy); 357 req->pid = pid = XAllocID(dpy);
382 358
383 if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 359 if (_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
384 if(rep.length) { 360 if (rep.length) {
385 xXDGAModeInfo info; 361 xXDGAModeInfo info;
386 int size; 362 int size;
387 363
388 size = rep.length << 2; 364 size = rep.length << 2;
389 size -= sz_xXDGAModeInfo; /* get text size */ 365 size -= sz_xXDGAModeInfo; /* get text size */
390 366
391 dev = (SDL_NAME(XDGADevice)*)Xmalloc(sizeof(SDL_NAME(XDGADevice)) + size); 367 dev = (SDL_NAME(XDGADevice) *)
392 368 Xmalloc(sizeof(SDL_NAME(XDGADevice)) + size);
393 if(dev) { 369
394 _XRead(dpy, (char*)(&info), sz_xXDGAModeInfo); 370 if (dev) {
395 371 _XRead(dpy, (char *) (&info), sz_xXDGAModeInfo);
396 dev->mode.num = info.num; 372
397 dev->mode.verticalRefresh = 373 dev->mode.num = info.num;
398 (float)info.vsync_num / (float)info.vsync_den; 374 dev->mode.verticalRefresh =
399 dev->mode.flags = info.flags; 375 (float) info.vsync_num / (float) info.vsync_den;
400 dev->mode.imageWidth = info.image_width; 376 dev->mode.flags = info.flags;
401 dev->mode.imageHeight = info.image_height; 377 dev->mode.imageWidth = info.image_width;
402 dev->mode.pixmapWidth = info.pixmap_width; 378 dev->mode.imageHeight = info.image_height;
403 dev->mode.pixmapHeight = info.pixmap_height; 379 dev->mode.pixmapWidth = info.pixmap_width;
404 dev->mode.bytesPerScanline = info.bytes_per_scanline; 380 dev->mode.pixmapHeight = info.pixmap_height;
405 dev->mode.byteOrder = info.byte_order; 381 dev->mode.bytesPerScanline = info.bytes_per_scanline;
406 dev->mode.depth = info.depth; 382 dev->mode.byteOrder = info.byte_order;
407 dev->mode.bitsPerPixel = info.bpp; 383 dev->mode.depth = info.depth;
408 dev->mode.redMask = info.red_mask; 384 dev->mode.bitsPerPixel = info.bpp;
409 dev->mode.greenMask = info.green_mask; 385 dev->mode.redMask = info.red_mask;
410 dev->mode.blueMask = info.blue_mask; 386 dev->mode.greenMask = info.green_mask;
411 dev->mode.visualClass = info.visual_class; 387 dev->mode.blueMask = info.blue_mask;
412 dev->mode.viewportWidth = info.viewport_width; 388 dev->mode.visualClass = info.visual_class;
413 dev->mode.viewportHeight = info.viewport_height; 389 dev->mode.viewportWidth = info.viewport_width;
414 dev->mode.xViewportStep = info.viewport_xstep; 390 dev->mode.viewportHeight = info.viewport_height;
415 dev->mode.yViewportStep = info.viewport_ystep; 391 dev->mode.xViewportStep = info.viewport_xstep;
416 dev->mode.maxViewportX = info.viewport_xmax; 392 dev->mode.yViewportStep = info.viewport_ystep;
417 dev->mode.maxViewportY = info.viewport_ymax; 393 dev->mode.maxViewportX = info.viewport_xmax;
418 dev->mode.viewportFlags = info.viewport_flags; 394 dev->mode.maxViewportY = info.viewport_ymax;
419 dev->mode.reserved1 = info.reserved1; 395 dev->mode.viewportFlags = info.viewport_flags;
420 dev->mode.reserved2 = info.reserved2; 396 dev->mode.reserved1 = info.reserved1;
421 397 dev->mode.reserved2 = info.reserved2;
422 dev->mode.name = (char*)(&dev[1]); 398
423 _XRead(dpy, dev->mode.name, info.name_size); 399 dev->mode.name = (char *) (&dev[1]);
424 400 _XRead(dpy, dev->mode.name, info.name_size);
425 dev->pixmap = (rep.flags & XDGAPixmap) ? pid : 0; 401
426 dev->data = SDL_NAME(XDGAGetMappedMemory)(screen); 402 dev->pixmap = (rep.flags & XDGAPixmap) ? pid : 0;
427 403 dev->data = SDL_NAME(XDGAGetMappedMemory) (screen);
428 if(dev->data) 404
429 dev->data += rep.offset; 405 if (dev->data)
430 } 406 dev->data += rep.offset;
431 /* not sure what to do if the allocation fails */ 407 }
432 } 408 /* not sure what to do if the allocation fails */
409 }
433 } 410 }
434 411
435 UnlockDisplay(dpy); 412 UnlockDisplay(dpy);
436 SyncHandle(); 413 SyncHandle();
437 414
438 return dev; 415 return dev;
439 } 416 }
440 417
441 418
442 void SDL_NAME(XDGASetViewport)( 419 void SDL_NAME(XDGASetViewport) (Display * dpy,
443 Display *dpy, 420 int screen, int x, int y, int flags)
444 int screen, 421 {
445 int x,
446 int y,
447 int flags
448 ){
449 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 422 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
450 xXDGASetViewportReq *req; 423 xXDGASetViewportReq *req;
451 424
452 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); 425 XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
453 426
454 LockDisplay(dpy); 427 LockDisplay(dpy);
455 GetReq(XDGASetViewport, req); 428 GetReq(XDGASetViewport, req);
456 req->reqType = info->codes->major_opcode; 429 req->reqType = info->codes->major_opcode;
457 req->dgaReqType = X_XDGASetViewport; 430 req->dgaReqType = X_XDGASetViewport;
462 UnlockDisplay(dpy); 435 UnlockDisplay(dpy);
463 SyncHandle(); 436 SyncHandle();
464 } 437 }
465 438
466 439
467 void SDL_NAME(XDGAInstallColormap)( 440 void SDL_NAME(XDGAInstallColormap) (Display * dpy, int screen, Colormap cmap)
468 Display *dpy, 441 {
469 int screen,
470 Colormap cmap
471 ){
472 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 442 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
473 xXDGAInstallColormapReq *req; 443 xXDGAInstallColormapReq *req;
474 444
475 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); 445 XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
476 446
477 LockDisplay(dpy); 447 LockDisplay(dpy);
478 GetReq(XDGAInstallColormap, req); 448 GetReq(XDGAInstallColormap, req);
479 req->reqType = info->codes->major_opcode; 449 req->reqType = info->codes->major_opcode;
480 req->dgaReqType = X_XDGAInstallColormap; 450 req->dgaReqType = X_XDGAInstallColormap;
482 req->cmap = cmap; 452 req->cmap = cmap;
483 UnlockDisplay(dpy); 453 UnlockDisplay(dpy);
484 SyncHandle(); 454 SyncHandle();
485 } 455 }
486 456
487 void SDL_NAME(XDGASelectInput)( 457 void SDL_NAME(XDGASelectInput) (Display * dpy, int screen, long mask)
488 Display *dpy, 458 {
489 int screen,
490 long mask
491 ){
492 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 459 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
493 xXDGASelectInputReq *req; 460 xXDGASelectInputReq *req;
494 461
495 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); 462 XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
496 463
497 LockDisplay(dpy); 464 LockDisplay(dpy);
498 GetReq(XDGASelectInput, req); 465 GetReq(XDGASelectInput, req);
499 req->reqType = info->codes->major_opcode; 466 req->reqType = info->codes->major_opcode;
500 req->dgaReqType = X_XDGASelectInput; 467 req->dgaReqType = X_XDGASelectInput;
502 req->mask = mask; 469 req->mask = mask;
503 UnlockDisplay(dpy); 470 UnlockDisplay(dpy);
504 SyncHandle(); 471 SyncHandle();
505 } 472 }
506 473
507 void SDL_NAME(XDGAFillRectangle)( 474 void SDL_NAME(XDGAFillRectangle) (Display * dpy,
508 Display *dpy, 475 int screen,
509 int screen, 476 int x,
510 int x, 477 int y,
511 int y, 478 unsigned int width,
512 unsigned int width, 479 unsigned int height, unsigned long color)
513 unsigned int height, 480 {
514 unsigned long color
515 ){
516 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 481 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
517 xXDGAFillRectangleReq *req; 482 xXDGAFillRectangleReq *req;
518 483
519 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); 484 XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
520 485
521 LockDisplay(dpy); 486 LockDisplay(dpy);
522 GetReq(XDGAFillRectangle, req); 487 GetReq(XDGAFillRectangle, req);
523 req->reqType = info->codes->major_opcode; 488 req->reqType = info->codes->major_opcode;
524 req->dgaReqType = X_XDGAFillRectangle; 489 req->dgaReqType = X_XDGAFillRectangle;
530 req->color = color; 495 req->color = color;
531 UnlockDisplay(dpy); 496 UnlockDisplay(dpy);
532 SyncHandle(); 497 SyncHandle();
533 } 498 }
534 499
535 void SDL_NAME(XDGACopyArea)( 500 void SDL_NAME(XDGACopyArea) (Display * dpy,
536 Display *dpy, 501 int screen,
537 int screen, 502 int srcx,
538 int srcx, 503 int srcy,
539 int srcy, 504 unsigned int width,
540 unsigned int width, 505 unsigned int height, int dstx, int dsty)
541 unsigned int height, 506 {
542 int dstx,
543 int dsty
544 ){
545 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 507 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
546 xXDGACopyAreaReq *req; 508 xXDGACopyAreaReq *req;
547 509
548 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); 510 XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
549 511
550 LockDisplay(dpy); 512 LockDisplay(dpy);
551 GetReq(XDGACopyArea, req); 513 GetReq(XDGACopyArea, req);
552 req->reqType = info->codes->major_opcode; 514 req->reqType = info->codes->major_opcode;
553 req->dgaReqType = X_XDGACopyArea; 515 req->dgaReqType = X_XDGACopyArea;
560 req->dsty = dsty; 522 req->dsty = dsty;
561 UnlockDisplay(dpy); 523 UnlockDisplay(dpy);
562 SyncHandle(); 524 SyncHandle();
563 } 525 }
564 526
565 void SDL_NAME(XDGACopyTransparentArea)( 527 void SDL_NAME(XDGACopyTransparentArea) (Display * dpy,
566 Display *dpy, 528 int screen,
567 int screen, 529 int srcx,
568 int srcx, 530 int srcy,
569 int srcy, 531 unsigned int width,
570 unsigned int width, 532 unsigned int height,
571 unsigned int height, 533 int dstx, int dsty, unsigned long key)
572 int dstx, 534 {
573 int dsty,
574 unsigned long key
575 ){
576 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 535 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
577 xXDGACopyTransparentAreaReq *req; 536 xXDGACopyTransparentAreaReq *req;
578 537
579 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); 538 XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
580 539
581 LockDisplay(dpy); 540 LockDisplay(dpy);
582 GetReq(XDGACopyTransparentArea, req); 541 GetReq(XDGACopyTransparentArea, req);
583 req->reqType = info->codes->major_opcode; 542 req->reqType = info->codes->major_opcode;
584 req->dgaReqType = X_XDGACopyTransparentArea; 543 req->dgaReqType = X_XDGACopyTransparentArea;
593 UnlockDisplay(dpy); 552 UnlockDisplay(dpy);
594 SyncHandle(); 553 SyncHandle();
595 } 554 }
596 555
597 556
598 int SDL_NAME(XDGAGetViewportStatus)( 557 int SDL_NAME(XDGAGetViewportStatus) (Display * dpy, int screen)
599 Display *dpy, 558 {
600 int screen
601 ){
602 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 559 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
603 xXDGAGetViewportStatusReply rep; 560 xXDGAGetViewportStatusReply rep;
604 xXDGAGetViewportStatusReq *req; 561 xXDGAGetViewportStatusReq *req;
605 int status = 0; 562 int status = 0;
606 563
607 XDGACheckExtension (dpy, info, 0); 564 XDGACheckExtension(dpy, info, 0);
608 565
609 LockDisplay(dpy); 566 LockDisplay(dpy);
610 GetReq(XDGAGetViewportStatus, req); 567 GetReq(XDGAGetViewportStatus, req);
611 req->reqType = info->codes->major_opcode; 568 req->reqType = info->codes->major_opcode;
612 req->dgaReqType = X_XDGAGetViewportStatus; 569 req->dgaReqType = X_XDGAGetViewportStatus;
613 req->screen = screen; 570 req->screen = screen;
614 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) 571 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
615 status = rep.status; 572 status = rep.status;
616 UnlockDisplay(dpy); 573 UnlockDisplay(dpy);
617 SyncHandle(); 574 SyncHandle();
618 return status; 575 return status;
619 } 576 }
620 577
621 void SDL_NAME(XDGASync)( 578 void SDL_NAME(XDGASync) (Display * dpy, int screen)
622 Display *dpy, 579 {
623 int screen
624 ){
625 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 580 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
626 xXDGASyncReply rep; 581 xXDGASyncReply rep;
627 xXDGASyncReq *req; 582 xXDGASyncReq *req;
628 583
629 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); 584 XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
630 585
631 LockDisplay(dpy); 586 LockDisplay(dpy);
632 GetReq(XDGASync, req); 587 GetReq(XDGASync, req);
633 req->reqType = info->codes->major_opcode; 588 req->reqType = info->codes->major_opcode;
634 req->dgaReqType = X_XDGASync; 589 req->dgaReqType = X_XDGASync;
635 req->screen = screen; 590 req->screen = screen;
636 _XReply(dpy, (xReply *)&rep, 0, xFalse); 591 _XReply(dpy, (xReply *) & rep, 0, xFalse);
637 UnlockDisplay(dpy); 592 UnlockDisplay(dpy);
638 SyncHandle(); 593 SyncHandle();
639 } 594 }
640 595
641 596
642 void SDL_NAME(XDGAChangePixmapMode)( 597 void SDL_NAME(XDGAChangePixmapMode) (Display * dpy,
643 Display *dpy, 598 int screen, int *x, int *y, int mode)
644 int screen, 599 {
645 int *x,
646 int *y,
647 int mode
648 ){
649 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 600 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
650 xXDGAChangePixmapModeReq *req; 601 xXDGAChangePixmapModeReq *req;
651 xXDGAChangePixmapModeReply rep; 602 xXDGAChangePixmapModeReply rep;
652 603
653 XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name)); 604 XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
654 605
655 LockDisplay(dpy); 606 LockDisplay(dpy);
656 GetReq(XDGAChangePixmapMode, req); 607 GetReq(XDGAChangePixmapMode, req);
657 req->reqType = info->codes->major_opcode; 608 req->reqType = info->codes->major_opcode;
658 req->dgaReqType = X_XDGAChangePixmapMode; 609 req->dgaReqType = X_XDGAChangePixmapMode;
659 req->screen = screen; 610 req->screen = screen;
660 req->x = *x; 611 req->x = *x;
661 req->y = *y; 612 req->y = *y;
662 req->flags = mode; 613 req->flags = mode;
663 _XReply(dpy, (xReply *)&rep, 0, xFalse); 614 _XReply(dpy, (xReply *) & rep, 0, xFalse);
664 *x = rep.x; 615 *x = rep.x;
665 *y = rep.y; 616 *y = rep.y;
666 UnlockDisplay(dpy); 617 UnlockDisplay(dpy);
667 SyncHandle(); 618 SyncHandle();
668 } 619 }
669 620
670 Colormap SDL_NAME(XDGACreateColormap)( 621 Colormap SDL_NAME(XDGACreateColormap) (Display * dpy,
671 Display *dpy, 622 int screen,
672 int screen, 623 SDL_NAME(XDGADevice) * dev, int alloc)
673 SDL_NAME(XDGADevice) *dev, 624 {
674 int alloc
675 ){
676 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy); 625 XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
677 xXDGACreateColormapReq *req; 626 xXDGACreateColormapReq *req;
678 Colormap cid; 627 Colormap cid;
679 628
680 XDGACheckExtension (dpy, info, -1); 629 XDGACheckExtension(dpy, info, -1);
681 630
682 LockDisplay(dpy); 631 LockDisplay(dpy);
683 GetReq(XDGACreateColormap, req); 632 GetReq(XDGACreateColormap, req);
684 req->reqType = info->codes->major_opcode; 633 req->reqType = info->codes->major_opcode;
685 req->dgaReqType = X_XDGACreateColormap; 634 req->dgaReqType = X_XDGACreateColormap;
692 641
693 return cid; 642 return cid;
694 } 643 }
695 644
696 645
697 void SDL_NAME(XDGAKeyEventToXKeyEvent)( 646 void SDL_NAME(XDGAKeyEventToXKeyEvent) (SDL_NAME(XDGAKeyEvent) * dk,
698 SDL_NAME(XDGAKeyEvent)* dk, 647 XKeyEvent * xk)
699 XKeyEvent* xk 648 {
700 ){
701 xk->type = dk->type; 649 xk->type = dk->type;
702 xk->serial = dk->serial; 650 xk->serial = dk->serial;
703 xk->send_event = False; 651 xk->send_event = False;
704 xk->display = dk->display; 652 xk->display = dk->display;
705 xk->window = RootWindow(dk->display, dk->screen); 653 xk->window = RootWindow(dk->display, dk->screen);
714 662
715 #include <X11/Xmd.h> 663 #include <X11/Xmd.h>
716 #include <stdlib.h> 664 #include <stdlib.h>
717 #include <stdio.h> 665 #include <stdio.h>
718 #include <fcntl.h> 666 #include <fcntl.h>
719 #if defined(ISC) 667 #if defined(ISC)
720 # define HAS_SVR3_MMAP 668 # define HAS_SVR3_MMAP
721 # include <sys/types.h> 669 # include <sys/types.h>
722 # include <errno.h> 670 # include <errno.h>
723 671
724 # include <sys/at_ansi.h> 672 # include <sys/at_ansi.h>
752 #define DEV_MEM "/dev/mem" 700 #define DEV_MEM "/dev/mem"
753 #endif 701 #endif
754 702
755 703
756 704
757 typedef struct _DGAMapRec{ 705 typedef struct _DGAMapRec
758 unsigned char *physical; 706 {
759 unsigned char *virtual; 707 unsigned char *physical;
760 CARD32 size; 708 unsigned char *virtual;
761 int fd; 709 CARD32 size;
762 int screen; 710 int fd;
763 struct _DGAMapRec *next; 711 int screen;
712 struct _DGAMapRec *next;
764 } DGAMapRec, *DGAMapPtr; 713 } DGAMapRec, *DGAMapPtr;
765 714
766 static Bool 715 static Bool
767 DGAMapPhysical(int, char*, unsigned char*, CARD32, CARD32, CARD32, DGAMapPtr); 716 DGAMapPhysical(int, char *, unsigned char *, CARD32, CARD32, CARD32,
717 DGAMapPtr);
768 static void DGAUnmapPhysical(DGAMapPtr); 718 static void DGAUnmapPhysical(DGAMapPtr);
769 719
770 static DGAMapPtr _Maps = NULL; 720 static DGAMapPtr _Maps = NULL;
771 721
772 722
773 unsigned char* 723 unsigned char *SDL_NAME(XDGAGetMappedMemory) (int screen)
774 SDL_NAME(XDGAGetMappedMemory)(int screen)
775 { 724 {
776 DGAMapPtr pMap = _Maps; 725 DGAMapPtr pMap = _Maps;
777 unsigned char *pntr = NULL; 726 unsigned char *pntr = NULL;
778 727
779 while(pMap != NULL) { 728 while (pMap != NULL) {
780 if(pMap->screen == screen) { 729 if (pMap->screen == screen) {
781 pntr = pMap->virtual; 730 pntr = pMap->virtual;
782 break; 731 break;
783 } 732 }
784 pMap = pMap->next; 733 pMap = pMap->next;
785 } 734 }
786 735
787 return pntr; 736 return pntr;
788 } 737 }
789 738
790 Bool 739 Bool SDL_NAME(XDGAMapFramebuffer) (int screen, char *name, /* optional device name */
791 SDL_NAME(XDGAMapFramebuffer)( 740 unsigned char *base, /* physical memory */
792 int screen, 741 CARD32 size, /* size */
793 char *name, /* optional device name */ 742 CARD32 offset, /* optional offset */
794 unsigned char* base, /* physical memory */ 743 CARD32 extra /* optional extra data */
795 CARD32 size, /* size */ 744 )
796 CARD32 offset, /* optional offset */ 745 {
797 CARD32 extra /* optional extra data */ 746 DGAMapPtr pMap = _Maps;
798 ){ 747 Bool result;
799 DGAMapPtr pMap = _Maps; 748
800 Bool result; 749 /* is it already mapped ? */
801 750 while (pMap != NULL) {
802 /* is it already mapped ? */ 751 if (pMap->screen == screen)
803 while(pMap != NULL) { 752 return True;
804 if(pMap->screen == screen) 753 pMap = pMap->next;
805 return True; 754 }
806 pMap = pMap->next; 755
807 } 756 if (extra & XDGANeedRoot) {
808 757 /* we should probably check if we have root permissions and
809 if(extra & XDGANeedRoot) { 758 return False here */
810 /* we should probably check if we have root permissions and 759
811 return False here */ 760 }
812 761
813 } 762 pMap = (DGAMapPtr) Xmalloc(sizeof(DGAMapRec));
814 763
815 pMap = (DGAMapPtr)Xmalloc(sizeof(DGAMapRec)); 764 result = DGAMapPhysical(screen, name, base, size, offset, extra, pMap);
816 765
817 result = DGAMapPhysical(screen, name, base, size, offset, extra, pMap); 766 if (result) {
818 767 pMap->next = _Maps;
819 if(result) { 768 _Maps = pMap;
820 pMap->next = _Maps; 769 } else
821 _Maps = pMap; 770 Xfree(pMap);
822 } else 771
823 Xfree(pMap); 772 return result;
824 773 }
825 return result; 774
826 } 775 void SDL_NAME(XDGAUnmapFramebuffer) (int screen)
827 776 {
828 void 777 DGAMapPtr pMap = _Maps;
829 SDL_NAME(XDGAUnmapFramebuffer)(int screen) 778 DGAMapPtr pPrev = NULL;
830 { 779
831 DGAMapPtr pMap = _Maps; 780 /* is it already mapped */
832 DGAMapPtr pPrev = NULL; 781 while (pMap != NULL) {
833 782 if (pMap->screen == screen)
834 /* is it already mapped */ 783 break;
835 while(pMap != NULL) { 784 pPrev = pMap;
836 if(pMap->screen == screen) 785 pMap = pMap->next;
837 break; 786 }
838 pPrev = pMap; 787
839 pMap = pMap->next; 788 if (!pMap)
840 } 789 return;
841
842 if(!pMap)
843 return;
844 790
845 DGAUnmapPhysical(pMap); 791 DGAUnmapPhysical(pMap);
846 792
847 if(!pPrev) 793 if (!pPrev)
848 _Maps = pMap->next; 794 _Maps = pMap->next;
849 else 795 else
850 pPrev->next = pMap->next; 796 pPrev->next = pMap->next;
851 797
852 Xfree(pMap); 798 Xfree(pMap);
853 } 799 }
854 800
855 801
856 static Bool 802 static Bool
857 DGAMapPhysical( 803 DGAMapPhysical(int screen, char *name, /* optional device name */
858 int screen, 804 unsigned char *base, /* physical memory */
859 char *name, /* optional device name */ 805 CARD32 size, /* size */
860 unsigned char* base, /* physical memory */ 806 CARD32 offset, /* optional offset */
861 CARD32 size, /* size */ 807 CARD32 extra, /* optional extra data */
862 CARD32 offset, /* optional offset */ 808 DGAMapPtr pMap)
863 CARD32 extra, /* optional extra data */ 809 {
864 DGAMapPtr pMap
865 ) {
866 #if defined(ISC) && defined(HAS_SVR3_MMAP) 810 #if defined(ISC) && defined(HAS_SVR3_MMAP)
867 struct kd_memloc mloc; 811 struct kd_memloc mloc;
868 #elif defined(__EMX__) 812 #elif defined(__EMX__)
869 APIRET rc; 813 APIRET rc;
870 ULONG action; 814 ULONG action;
871 HFILE hfd; 815 HFILE hfd;
872 #endif 816 #endif
873 817
874 base += offset; 818 base += offset;
875 819
876 pMap->screen = screen; 820 pMap->screen = screen;
877 pMap->physical = base; 821 pMap->physical = base;
878 pMap->size = size; 822 pMap->size = size;
879 823
880 #if defined(ISC) && defined(HAS_SVR3_MMAP) 824 #if defined(ISC) && defined(HAS_SVR3_MMAP)
881 if ((pMap->fd = open("/dev/mmap", O_RDWR)) < 0) 825 if ((pMap->fd = open("/dev/mmap", O_RDWR)) < 0)
882 return False; 826 return False;
883 mloc.vaddr = (char *)0; 827 mloc.vaddr = (char *) 0;
884 mloc.physaddr = (char *)base; 828 mloc.physaddr = (char *) base;
885 mloc.length = size; 829 mloc.length = size;
886 mloc.ioflg=1; 830 mloc.ioflg = 1;
887 831
888 if ((pMap->virtual = (void *)ioctl(pMap->fd, MAP, &mloc)) == (void *)-1) 832 if ((pMap->virtual = (void *) ioctl(pMap->fd, MAP, &mloc)) == (void *) -1)
889 return False; 833 return False;
890 #elif defined (__EMX__) 834 #elif defined (__EMX__)
891 /* 835 /*
892 * Dragon warning here! /dev/pmap$ is never closed, except on progam exit. 836 * Dragon warning here! /dev/pmap$ is never closed, except on progam exit.
893 * Consecutive calling of this routine will make PMAP$ driver run out 837 * Consecutive calling of this routine will make PMAP$ driver run out
894 * of memory handles. Some umap/close mechanism should be provided 838 * of memory handles. Some umap/close mechanism should be provided
895 */ 839 */
896 840
897 rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN, 841 rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN,
898 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2)NULL); 842 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2) NULL);
899 if (rc != 0) 843 if (rc != 0)
900 return False; 844 return False;
901 { 845 {
902 struct map_ioctl { 846 struct map_ioctl
903 union { 847 {
904 ULONG phys; 848 union
905 void* user; 849 {
906 } a; 850 ULONG phys;
907 ULONG size; 851 void *user;
908 } pmap,dmap; 852 } a;
909 ULONG plen,dlen; 853 ULONG size;
854 } pmap, dmap;
855 ULONG plen, dlen;
910 #define XFREE86_PMAP 0x76 856 #define XFREE86_PMAP 0x76
911 #define PMAP_MAP 0x44 857 #define PMAP_MAP 0x44
912 858
913 pmap.a.phys = base; 859 pmap.a.phys = base;
914 pmap.size = size; 860 pmap.size = size;
915 rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP, 861 rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP,
916 (PULONG)&pmap, sizeof(pmap), &plen, 862 (PULONG) & pmap, sizeof(pmap), &plen,
917 (PULONG)&dmap, sizeof(dmap), &dlen); 863 (PULONG) & dmap, sizeof(dmap), &dlen);
918 if (rc == 0) { 864 if (rc == 0) {
919 pMap->virtual = dmap.a.user; 865 pMap->virtual = dmap.a.user;
920 } 866 }
921 } 867 }
922 if (rc != 0) 868 if (rc != 0)
923 return False; 869 return False;
924 #elif defined (Lynx) 870 #elif defined (Lynx)
925 pMap->virtual = smem_create("XF86DGA", (char*)base, size, SM_READ|SM_WRITE); 871 pMap->virtual =
872 smem_create("XF86DGA", (char *) base, size, SM_READ | SM_WRITE);
926 #else 873 #else
927 #ifndef MAP_FILE 874 #ifndef MAP_FILE
928 #define MAP_FILE 0 875 #define MAP_FILE 0
929 #endif 876 #endif
930 if (!name) 877 if (!name)
931 name = DEV_MEM; 878 name = DEV_MEM;
932 if ((pMap->fd = open(name, O_RDWR)) < 0) 879 if ((pMap->fd = open(name, O_RDWR)) < 0)
933 #if defined(ENABLE_FBCON) 880 #if defined(ENABLE_FBCON)
934 { /* /dev/fb0 fallback added by Sam Lantinga <hercules@lokigames.com> */ 881 { /* /dev/fb0 fallback added by Sam Lantinga <hercules@lokigames.com> */
935 /* Try to fall back to /dev/fb on Linux - FIXME: verify the device */ 882 /* Try to fall back to /dev/fb on Linux - FIXME: verify the device */
936 struct fb_fix_screeninfo finfo; 883 struct fb_fix_screeninfo finfo;
937 884
938 if ((pMap->fd = open("/dev/fb0", O_RDWR)) < 0) { 885 if ((pMap->fd = open("/dev/fb0", O_RDWR)) < 0) {
939 return False; 886 return False;
940 } 887 }
941 /* The useable framebuffer console memory may not be the whole 888 /* The useable framebuffer console memory may not be the whole
942 framebuffer that X has access to. :-( 889 framebuffer that X has access to. :-(
943 */ 890 */
944 if ( ioctl(pMap->fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { 891 if (ioctl(pMap->fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
945 close(pMap->fd); 892 close(pMap->fd);
946 return False; 893 return False;
947 } 894 }
948 /* Warning: On PPC, the size and virtual need to be offset by: 895 /* Warning: On PPC, the size and virtual need to be offset by:
949 (((long)finfo.smem_start) - 896 (((long)finfo.smem_start) -
951 */ 898 */
952 base = 0; 899 base = 0;
953 size = pMap->size = finfo.smem_len; 900 size = pMap->size = finfo.smem_len;
954 } 901 }
955 #else 902 #else
956 return False; 903 return False;
957 #endif 904 #endif
958 pMap->virtual = mmap(NULL, size, PROT_READ | PROT_WRITE, 905 pMap->virtual = mmap(NULL, size, PROT_READ | PROT_WRITE,
959 MAP_FILE | MAP_SHARED, pMap->fd, (off_t)base); 906 MAP_FILE | MAP_SHARED, pMap->fd, (off_t) base);
960 if (pMap->virtual == (void *)-1) 907 if (pMap->virtual == (void *) -1)
961 return False; 908 return False;
962 #endif 909 #endif
963 910
964 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ 911 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
965 && !defined(__EMX__) 912 && !defined(__EMX__)
966 mprotect(pMap->virtual, size, PROT_READ | PROT_WRITE); 913 mprotect(pMap->virtual, size, PROT_READ | PROT_WRITE);
974 static void 921 static void
975 DGAUnmapPhysical(DGAMapPtr pMap) 922 DGAUnmapPhysical(DGAMapPtr pMap)
976 { 923 {
977 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \ 924 #if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
978 && !defined(__EMX__) 925 && !defined(__EMX__)
979 mprotect(pMap->virtual,pMap->size, PROT_READ); 926 mprotect(pMap->virtual, pMap->size, PROT_READ);
980 #elif defined(Lynx) 927 #elif defined(Lynx)
981 /* XXX this doesn't allow enable after disable */ 928 /* XXX this doesn't allow enable after disable */
982 smem_create(NULL, pMap->virtual, pMap->size, SM_DETACH); 929 smem_create(NULL, pMap->virtual, pMap->size, SM_DETACH);
983 smem_remove("XF86DGA"); 930 smem_remove("XF86DGA");
984 #endif 931 #endif
985 932
986 933
987 /* We need to unmap and close too !!!!!!!!!!*/ 934 /* We need to unmap and close too !!!!!!!!!! */
988 } 935 }
936
937 /* vi: set ts=4 sw=4 expandtab: */