19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* $XFree86: xc/lib/Xxf86dga/XF86DGA2.c,v 1.18 2001/08/17 13:27:51 dawes Exp $ */
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCopyright (c) 1995  Jon Tombs
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCopyright (c) 1995,1996  The XFree86 Project, Inc
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* THIS IS NOT AN X CONSORTIUM STANDARD */
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __EMX__ /* needed here to override certain constants in X headers */
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define INCL_DOS
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define INCL_DOSIOCTL
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <os2.h>
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define NEED_EVENTS
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define NEED_REPLIES
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Apparently some X11 systems can't include this multiple times... */
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef SDL_INCLUDED_XLIBINT_H
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SDL_INCLUDED_XLIBINT_H 1
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <X11/Xlibint.h>
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../extensions/xf86dga.h"
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../extensions/xf86dgastr.h"
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../extensions/Xext.h"
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../extensions/extutil.h"
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h>
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(ENABLE_FBCON)  /* Needed for framebuffer console support */
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <sys/ioctl.h>
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <linux/fb.h>
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* If you change this, change the Bases[] array below as well */
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define MAX_HEADS 16
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallchar *SDL_NAME(xdga_extension_name) = XF86DGANAME;
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic XExtensionInfo _xdga_info_data;
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic XExtensionInfo *xdga_info = &_xdga_info_data;
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBool SDL_NAME(XDGAMapFramebuffer)(int, char *, unsigned char*, CARD32, CARD32, CARD32);
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGAUnmapFramebuffer)(int);
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallunsigned char* SDL_NAME(XDGAGetMappedMemory)(int);
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define XDGACheckExtension(dpy,i,val) \
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val)
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*****************************************************************************
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *                                                                           *
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *			   private utility routines                          *
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *                                                                           *
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *****************************************************************************/
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int xdga_close_display(Display *dpy, XExtCodes *codes);
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Bool xdga_wire_to_event(Display *dpy, XEvent *event, xEvent *wire_ev);
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Status xdga_event_to_wire(Display *dpy, XEvent *event, xEvent *wire_ev);
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic XExtensionHooks xdga_extension_hooks = {
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,				/* create_gc */
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,				/* copy_gc */
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,				/* flush_gc */
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,				/* free_gc */
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,				/* create_font */
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,				/* free_font */
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xdga_close_display,			/* close_display */
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xdga_wire_to_event,			/* wire_to_event */
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xdga_event_to_wire,			/* event_to_wire */
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,				/* error */
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,				/* error_string */
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic XEXT_GENERATE_CLOSE_DISPLAY (xdga_close_display, xdga_info)
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallXEXT_GENERATE_FIND_DISPLAY (SDL_NAME(xdga_find_display), xdga_info,
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				   "XFree86-DGA",
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				   &xdga_extension_hooks,
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				   0, NULL)
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Status
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallxdga_event_to_wire(
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  Display *dpy,
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XEvent *event,
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xEvent *wire_ev
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return True;
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Bool
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallxdga_wire_to_event(
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  Display *dpy,
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XEvent *event,
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xEvent *wire_ev
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  dgaEvent *wire = (dgaEvent *) wire_ev;
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XDGAButtonEvent) *bevent;
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XDGAKeyEvent) *kevent;
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XDGAMotionEvent) *mevent;
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XDGACheckExtension (dpy, info, False);
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  switch((wire->u.u.type & 0x7f) - info->codes->first_event) {
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  case MotionNotify:
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mevent = (SDL_NAME(XDGAMotionEvent)*)event;
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mevent->type = wire->u.u.type & 0x7F;
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire);
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mevent->display = dpy;
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mevent->screen = wire->u.event.screen;
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mevent->time = wire->u.event.time;
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mevent->state = wire->u.event.state;
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mevent->dx = wire->u.event.dx;
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mevent->dy = wire->u.event.dy;
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return True;
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  case ButtonPress:
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  case ButtonRelease:
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bevent = (SDL_NAME(XDGAButtonEvent)*)event;
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bevent->type = wire->u.u.type & 0x7F;
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire);
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bevent->display = dpy;
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bevent->screen = wire->u.event.screen;
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bevent->time = wire->u.event.time;
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bevent->state = wire->u.event.state;
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bevent->button = wire->u.u.detail;
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return True;
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  case KeyPress:
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  case KeyRelease:
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	kevent = (SDL_NAME(XDGAKeyEvent)*)event;
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	kevent->type = wire->u.u.type & 0x7F;
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	kevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire);
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	kevent->display = dpy;
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	kevent->screen = wire->u.event.screen;
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	kevent->time = wire->u.event.time;
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	kevent->state = wire->u.event.state;
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	kevent->keycode = wire->u.u.detail;
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return True;
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return False;
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBool SDL_NAME(XDGAQueryExtension) (
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display *dpy,
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int *event_basep,
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int *error_basep
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (XextHasExtension(info)) {
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	*event_basep = info->codes->first_event;
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	*error_basep = info->codes->first_error;
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return True;
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    } else {
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return False;
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBool SDL_NAME(XDGAQueryVersion)(
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display *dpy,
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int *majorVersion,
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int *minorVersion
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAQueryVersionReply rep;
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAQueryVersionReq *req;
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XDGACheckExtension (dpy, info, False);
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGAQueryVersion, req);
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGAQueryVersion;
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	UnlockDisplay(dpy);
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SyncHandle();
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return False;
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    *majorVersion = rep.majorVersion;
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    *minorVersion = rep.minorVersion;
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (*majorVersion >= 2)
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int i, j;
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	for (i = 0, j = info->codes->first_event;
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	     i < XF86DGANumberEvents;
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	     i++, j++)
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	    XESetWireToEvent(dpy, j, xdga_wire_to_event);
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	    XESetEventToWire(dpy, j, xdga_event_to_wire);
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_NAME(XDGASetClientVersion)(dpy);
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return True;
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBool SDL_NAME(XDGASetClientVersion)(
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display	*dpy
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGASetClientVersionReq *req;
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XDGACheckExtension (dpy, info, False);
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGASetClientVersion, req);
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGASetClientVersion;
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->major = XDGA_MAJOR_VERSION;
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->minor = XDGA_MINOR_VERSION;
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return True;
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBool SDL_NAME(XDGAOpenFramebuffer)(
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display	*dpy,
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int 	screen
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAOpenFramebufferReply rep;
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAOpenFramebufferReq *req;
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    char *deviceName = NULL;
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Bool ret;
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XDGACheckExtension (dpy, info, False);
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGAOpenFramebuffer, req);
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGAOpenFramebuffer;
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	UnlockDisplay(dpy);
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SyncHandle();
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return False;
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if(rep.length) {
2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	deviceName = Xmalloc(rep.length << 2);
2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	_XRead(dpy, deviceName, rep.length << 2);
2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ret = SDL_NAME(XDGAMapFramebuffer)(screen, deviceName,
2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				(unsigned char*)(long)rep.mem1,
2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				rep.size, rep.offset, rep.extra);
2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if(deviceName)
2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Xfree(deviceName);
2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return ret;
2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGACloseFramebuffer)(
2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display	*dpy,
2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		screen
2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGACloseFramebufferReq *req;
2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name));
2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_NAME(XDGAUnmapFramebuffer)(screen);
2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGACloseFramebuffer, req);
2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGACloseFramebuffer;
2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XDGAMode)* SDL_NAME(XDGAQueryModes)(
2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display *dpy,
2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int screen,
2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int *num
2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy);
2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAQueryModesReply rep;
2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAQueryModesReq *req;
2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_NAME(XDGAMode) *modes = NULL;
2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    *num = 0;
2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XDGACheckExtension (dpy, dinfo, NULL);
3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGAQueryModes, req);
3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = dinfo->codes->major_opcode;
3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGAQueryModes;
3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if(rep.length) {
3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   xXDGAModeInfo info;
3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   int i, size;
3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   char *offset;
3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   size = rep.length << 2;
3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   size -= rep.number * sz_xXDGAModeInfo; /* find text size */
3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   modes = (SDL_NAME(XDGAMode)*)Xmalloc((rep.number * sizeof(SDL_NAME(XDGAMode))) + size);
3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   offset = (char*)(&modes[rep.number]); /* start of text */
3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   if(modes) {
3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      for(i = 0; i < rep.number; i++) {
3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		_XRead(dpy, (char*)(&info), sz_xXDGAModeInfo);
3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].num = info.num;
3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].verticalRefresh =
3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			(float)info.vsync_num / (float)info.vsync_den;
3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].flags = info.flags;
3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].imageWidth = info.image_width;
3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].imageHeight = info.image_height;
3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].pixmapWidth = info.pixmap_width;
3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].pixmapHeight = info.pixmap_height;
3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].bytesPerScanline = info.bytes_per_scanline;
3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].byteOrder = info.byte_order;
3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].depth = info.depth;
3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].bitsPerPixel = info.bpp;
3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].redMask = info.red_mask;
3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].greenMask = info.green_mask;
3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].blueMask = info.blue_mask;
3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].visualClass = info.visual_class;
3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].viewportWidth = info.viewport_width;
3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].viewportHeight = info.viewport_height;
3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].xViewportStep = info.viewport_xstep;
3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].yViewportStep = info.viewport_ystep;
3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].maxViewportX = info.viewport_xmax;
3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].maxViewportY = info.viewport_ymax;
3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].viewportFlags = info.viewport_flags;
3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].reserved1 = info.reserved1;
3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].reserved2 = info.reserved2;
3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		_XRead(dpy, offset, info.name_size);
3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		modes[i].name = offset;
3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		offset += info.name_size;
3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      }
3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      *num = rep.number;
3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   } else
3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		_XEatData(dpy, rep.length << 2);
3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return modes;
3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XDGADevice) *
3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XDGASetMode)(
3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display	*dpy,
3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		screen,
3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		mode
3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy);
3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGASetModeReply rep;
3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGASetModeReq *req;
3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_NAME(XDGADevice) *dev = NULL;
3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Pixmap pid;
3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XDGACheckExtension (dpy, dinfo, NULL);
3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGASetMode, req);
3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = dinfo->codes->major_opcode;
3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGASetMode;
3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->mode = mode;
3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->pid = pid = XAllocID(dpy);
3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if(rep.length) {
3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   xXDGAModeInfo info;
3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   int size;
3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   size = rep.length << 2;
3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   size -= sz_xXDGAModeInfo; /* get text size */
3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   dev = (SDL_NAME(XDGADevice)*)Xmalloc(sizeof(SDL_NAME(XDGADevice)) + size);
3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   if(dev) {
3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		_XRead(dpy, (char*)(&info), sz_xXDGAModeInfo);
4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.num = info.num;
4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.verticalRefresh =
4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				(float)info.vsync_num / (float)info.vsync_den;
4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.flags = info.flags;
4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.imageWidth = info.image_width;
4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.imageHeight = info.image_height;
4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.pixmapWidth = info.pixmap_width;
4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.pixmapHeight = info.pixmap_height;
4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.bytesPerScanline = info.bytes_per_scanline;
4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.byteOrder = info.byte_order;
4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.depth = info.depth;
4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.bitsPerPixel = info.bpp;
4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.redMask = info.red_mask;
4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.greenMask = info.green_mask;
4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.blueMask = info.blue_mask;
4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.visualClass = info.visual_class;
4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.viewportWidth = info.viewport_width;
4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.viewportHeight = info.viewport_height;
4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.xViewportStep = info.viewport_xstep;
4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.yViewportStep = info.viewport_ystep;
4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.maxViewportX = info.viewport_xmax;
4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.maxViewportY = info.viewport_ymax;
4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.viewportFlags = info.viewport_flags;
4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.reserved1 = info.reserved1;
4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.reserved2 = info.reserved2;
4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->mode.name = (char*)(&dev[1]);
4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		_XRead(dpy, dev->mode.name, info.name_size);
4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->pixmap = (rep.flags & XDGAPixmap) ? pid : 0;
4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		dev->data = SDL_NAME(XDGAGetMappedMemory)(screen);
4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if(dev->data)
4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		    dev->data += rep.offset;
4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   }
4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   /* not sure what to do if the allocation fails */
4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return dev;
4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGASetViewport)(
4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display	*dpy,
4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		screen,
4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		x,
4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		y,
4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		flags
4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGASetViewportReq *req;
4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name));
4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGASetViewport, req);
4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGASetViewport;
4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->x = x;
4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->y = y;
4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->flags = flags;
4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGAInstallColormap)(
4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display	*dpy,
4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		screen,
4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Colormap	cmap
4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAInstallColormapReq *req;
4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name));
4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGAInstallColormap, req);
4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGAInstallColormap;
4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->cmap = cmap;
4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGASelectInput)(
4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display	*dpy,
4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		screen,
4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    long	mask
4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGASelectInputReq *req;
4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name));
5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
5039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGASelectInput, req);
5049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
5059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGASelectInput;
5069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
5079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->mask = mask;
5089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
5099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
5109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
5119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGAFillRectangle)(
5139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display	*dpy,
5149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		screen,
5159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		x,
5169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		y,
5179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    unsigned int	width,
5189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    unsigned int	height,
5199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    unsigned long	color
5209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
5219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
5229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAFillRectangleReq *req;
5239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name));
5259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
5279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGAFillRectangle, req);
5289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
5299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGAFillRectangle;
5309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
5319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->x = x;
5329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->y = y;
5339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->width = width;
5349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->height = height;
5359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->color = color;
5369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
5379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
5389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
5399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGACopyArea)(
5419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display	*dpy,
5429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		screen,
5439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		srcx,
5449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		srcy,
5459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    unsigned int	width,
5469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    unsigned int	height,
5479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		dstx,
5489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		dsty
5499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
5509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
5519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGACopyAreaReq *req;
5529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name));
5549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
5569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGACopyArea, req);
5579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
5589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGACopyArea;
5599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
5609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->srcx = srcx;
5619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->srcy = srcy;
5629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->width = width;
5639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->height = height;
5649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dstx = dstx;
5659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dsty = dsty;
5669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
5679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
5689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
5699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGACopyTransparentArea)(
5719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display	*dpy,
5729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		screen,
5739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		srcx,
5749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		srcy,
5759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    unsigned int	width,
5769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    unsigned int	height,
5779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		dstx,
5789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int		dsty,
5799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    unsigned long key
5809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
5819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
5829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGACopyTransparentAreaReq *req;
5839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name));
5859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
5879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGACopyTransparentArea, req);
5889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
5899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGACopyTransparentArea;
5909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
5919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->srcx = srcx;
5929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->srcy = srcy;
5939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->width = width;
5949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->height = height;
5959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dstx = dstx;
5969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dsty = dsty;
5979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->key = key;
5989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
5999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
6009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
6019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_NAME(XDGAGetViewportStatus)(
6049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display *dpy,
6059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int screen
6069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
6079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
6089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAGetViewportStatusReply rep;
6099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAGetViewportStatusReq *req;
6109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int status = 0;
6119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XDGACheckExtension (dpy, info, 0);
6139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
6159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGAGetViewportStatus, req);
6169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
6179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGAGetViewportStatus;
6189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
6199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse))
6209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	status = rep.status;
6219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
6229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
6239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return status;
6249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
6259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGASync)(
6279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display *dpy,
6289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int screen
6299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
6309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
6319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGASyncReply rep;
6329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGASyncReq *req;
6339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name));
6359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
6379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGASync, req);
6389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
6399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGASync;
6409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
6419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    _XReply(dpy, (xReply *)&rep, 0, xFalse);
6429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
6439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
6449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
6459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGAChangePixmapMode)(
6489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display *dpy,
6499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int screen,
6509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int *x,
6519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int *y,
6529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int mode
6539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
6549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
6559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAChangePixmapModeReq *req;
6569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGAChangePixmapModeReply rep;
6579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XextSimpleCheckExtension (dpy, info, SDL_NAME(xdga_extension_name));
6599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
6619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGAChangePixmapMode, req);
6629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
6639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGAChangePixmapMode;
6649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
6659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->x = *x;
6669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->y = *y;
6679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->flags = mode;
6689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    _XReply(dpy, (xReply *)&rep, 0, xFalse);
6699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    *x = rep.x;
6709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    *y = rep.y;
6719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
6729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
6739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
6749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallColormap SDL_NAME(XDGACreateColormap)(
6769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Display *dpy,
6779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int screen,
6789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_NAME(XDGADevice) *dev,
6799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int	alloc
6809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
6819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
6829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xXDGACreateColormapReq *req;
6839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Colormap cid;
6849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XDGACheckExtension (dpy, info, -1);
6869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    LockDisplay(dpy);
6889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    GetReq(XDGACreateColormap, req);
6899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->reqType = info->codes->major_opcode;
6909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->dgaReqType = X_XDGACreateColormap;
6919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->screen = screen;
6929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->mode = dev->mode.num;
6939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    req->alloc = alloc;
6949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cid = req->id = XAllocID(dpy);
6959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    UnlockDisplay(dpy);
6969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SyncHandle();
6979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return cid;
6999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
7009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_NAME(XDGAKeyEventToXKeyEvent)(
7039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL_NAME(XDGAKeyEvent)* dk,
7049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    XKeyEvent* xk
7059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
7069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->type = dk->type;
7079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->serial = dk->serial;
7089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->send_event = False;
7099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->display = dk->display;
7109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->window = RootWindow(dk->display, dk->screen);
7119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->root = xk->window;
7129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->subwindow = None;
7139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->time = dk->time;
7149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->x = xk->y = xk->x_root = xk->y_root = 0;
7159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->state = dk->state;
7169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->keycode = dk->keycode;
7179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xk->same_screen = True;
7189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
7199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <X11/Xmd.h>
7219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdlib.h>
7229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h>
7239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <fcntl.h>
7249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(ISC)
7259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# define HAS_SVR3_MMAP
7269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# include <sys/types.h>
7279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# include <errno.h>
7289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# include <sys/at_ansi.h>
7309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# include <sys/kd.h>
7319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# include <sys/sysmacros.h>
7339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# include <sys/immu.h>
7349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# include <sys/region.h>
7359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# include <sys/mmap.h>
7379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
7389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# if !defined(Lynx)
7399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#  if !defined(__EMX__)
7409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#   include <sys/mman.h>
7419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#  endif
7429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# else
7439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#  include <sys/types.h>
7449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#  include <errno.h>
7459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#  include <smem.h>
7469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# endif
7479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
7489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <sys/wait.h>
7499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <signal.h>
7509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <unistd.h>
7519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(SVR4) && !defined(sun) && !defined(SCO325)
7539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define DEV_MEM "/dev/pmem"
7549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif defined(SVR4) && defined(sun)
7559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define DEV_MEM "/dev/xsvc"
7569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
7579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define DEV_MEM "/dev/mem"
7589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
7599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halltypedef struct _DGAMapRec{
7639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  unsigned char *physical;
7649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  unsigned char *virtual;
7659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  CARD32 size;
7669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  int fd;
7679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  int screen;
7689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  struct _DGAMapRec *next;
7699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} DGAMapRec, *DGAMapPtr;
7709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Bool
7729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallDGAMapPhysical(int, char*, unsigned char*, CARD32, CARD32, CARD32, DGAMapPtr);
7739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void DGAUnmapPhysical(DGAMapPtr);
7749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic DGAMapPtr _Maps = NULL;
7769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallunsigned char*
7799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XDGAGetMappedMemory)(int screen)
7809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
7819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    DGAMapPtr pMap = _Maps;
7829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    unsigned char *pntr = NULL;
7839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    while(pMap != NULL) {
7859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if(pMap->screen == screen) {
7869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	    pntr = pMap->virtual;
7879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	    break;
7889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
7899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pMap = pMap->next;
7909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
7919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return pntr;
7939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
7949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBool
7969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XDGAMapFramebuffer)(
7979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int screen,
7989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   char *name,			/* optional device name */
7999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   unsigned char* base,		/* physical memory */
8009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   CARD32 size,			/* size */
8019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   CARD32 offset,		/* optional offset */
8029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   CARD32 extra			/* optional extra data */
8039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
8049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   DGAMapPtr pMap = _Maps;
8059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   Bool result;
8069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   /* is it already mapped ? */
8089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   while(pMap != NULL) {
8099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     if(pMap->screen == screen)
8109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return True;
8119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     pMap = pMap->next;
8129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   }
8139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   if(extra & XDGANeedRoot) {
8159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* we should probably check if we have root permissions and
8169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       return False here */
8179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   }
8199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   pMap = (DGAMapPtr)Xmalloc(sizeof(DGAMapRec));
8219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   result = DGAMapPhysical(screen, name, base, size, offset, extra, pMap);
8239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   if(result) {
8259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pMap->next = _Maps;
8269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      _Maps = pMap;
8279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   } else
8289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      Xfree(pMap);
8299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   return result;
8319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
8329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid
8349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XDGAUnmapFramebuffer)(int screen)
8359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
8369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   DGAMapPtr pMap = _Maps;
8379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   DGAMapPtr pPrev = NULL;
8389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   /* is it already mapped */
8409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    while(pMap != NULL) {
8419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if(pMap->screen == screen)
8429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	    break;
8439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pPrev = pMap;
8449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pMap = pMap->next;
8459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
8469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if(!pMap)
8489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return;
8499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    DGAUnmapPhysical(pMap);
8519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if(!pPrev)
8539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	_Maps = pMap->next;
8549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    else
8559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pPrev->next = pMap->next;
8569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Xfree(pMap);
8589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
8599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Bool
8629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallDGAMapPhysical(
8639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int screen,
8649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   char *name,			/* optional device name */
8659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   unsigned char* base,		/* physical memory */
8669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   CARD32 size,			/* size */
8679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   CARD32 offset,		/* optional offset */
8689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   CARD32 extra,		/* optional extra data */
8699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   DGAMapPtr pMap
8709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall) {
8719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(ISC) && defined(HAS_SVR3_MMAP)
8729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    struct kd_memloc mloc;
8739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif defined(__EMX__)
8749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    APIRET rc;
8759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ULONG action;
8769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    HFILE hfd;
8779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
8789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    base += offset;
8809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    pMap->screen = screen;
8829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    pMap->physical = base;
8839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    pMap->size = size;
8849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(ISC) && defined(HAS_SVR3_MMAP)
8869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if ((pMap->fd = open("/dev/mmap", O_RDWR)) < 0)
8879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return False;
8889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mloc.vaddr = (char *)0;
8899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mloc.physaddr = (char *)base;
8909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mloc.length = size;
8919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mloc.ioflg=1;
8929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if ((pMap->virtual = (void *)ioctl(pMap->fd, MAP, &mloc)) == (void *)-1)
8949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return False;
8959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif defined (__EMX__)
8969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /*
8979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * Dragon warning here! /dev/pmap$ is never closed, except on progam exit.
8989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * Consecutive calling of this routine will make PMAP$ driver run out
8999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     * of memory handles. Some umap/close mechanism should be provided
9009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     */
9019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN,
9039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		 OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2)NULL);
9049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (rc != 0)
9059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return False;
9069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
9079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct map_ioctl {
9089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		union {
9099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			ULONG phys;
9109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			void* user;
9119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} a;
9129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		ULONG size;
9139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} pmap,dmap;
9149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ULONG plen,dlen;
9159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define XFREE86_PMAP	0x76
9169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define PMAP_MAP	0x44
9179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pmap.a.phys = base;
9199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pmap.size = size;
9209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP,
9219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			 (PULONG)&pmap, sizeof(pmap), &plen,
9229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			 (PULONG)&dmap, sizeof(dmap), &dlen);
9239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (rc == 0) {
9249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		pMap->virtual = dmap.a.user;
9259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
9269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   }
9279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   if (rc != 0)
9289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return False;
9299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif defined (Lynx)
9309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    pMap->virtual = smem_create("XF86DGA", (char*)base, size, SM_READ|SM_WRITE);
9319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
9329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef MAP_FILE
9339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define MAP_FILE 0
9349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
9359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (!name)
9369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	    name = DEV_MEM;
9379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if ((pMap->fd = open(name, O_RDWR)) < 0)
9389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(ENABLE_FBCON)
9399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    { /* /dev/fb0 fallback added by Sam Lantinga <hercules@lokigames.com> */
9409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* Try to fall back to /dev/fb on Linux - FIXME: verify the device */
9419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        struct fb_fix_screeninfo finfo;
9429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if ((pMap->fd = open("/dev/fb0", O_RDWR)) < 0) {
9449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            return False;
9459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
9469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* The useable framebuffer console memory may not be the whole
9479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall           framebuffer that X has access to. :-(
9489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         */
9499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        if ( ioctl(pMap->fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) {
9509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            close(pMap->fd);
9519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            return False;
9529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
9539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        /* Warning: On PPC, the size and virtual need to be offset by:
9549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall           (((long)finfo.smem_start) -
9559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall           (((long)finfo.smem_start)&~(PAGE_SIZE-1)))
9569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall         */
9579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        base = 0;
9589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        size = pMap->size = finfo.smem_len;
9599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
9609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
9619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return False;
9629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
9639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    pMap->virtual = mmap(NULL, size, PROT_READ | PROT_WRITE,
9649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			MAP_FILE | MAP_SHARED, pMap->fd, (off_t)((size_t)base));
9659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (pMap->virtual == (void *)-1)
9669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return False;
9679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
9689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
9709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	&& !defined(__EMX__)
9719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mprotect(pMap->virtual, size, PROT_READ | PROT_WRITE);
9729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
9739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    return True;
9759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
9769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void
9809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallDGAUnmapPhysical(DGAMapPtr pMap)
9819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
9829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
9839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	&& !defined(__EMX__)
9849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mprotect(pMap->virtual,pMap->size, PROT_READ);
9859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif defined(Lynx)
9869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* XXX this doesn't allow enable after disable */
9879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    smem_create(NULL, pMap->virtual, pMap->size, SM_DETACH);
9889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    smem_remove("XF86DGA");
9899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
9909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   /* We need to unmap and close too !!!!!!!!!!*/
9939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
994