1706f2543Smrg/*
2706f2543Smrg * Copyright 1998 by Alan Hourihane, Wigan, England.
3706f2543Smrg *
4706f2543Smrg * Permission to use, copy, modify, distribute, and sell this software and its
5706f2543Smrg * documentation for any purpose is hereby granted without fee, provided that
6706f2543Smrg * the above copyright notice appear in all copies and that both that
7706f2543Smrg * copyright notice and this permission notice appear in supporting
8706f2543Smrg * documentation, and that the name of Alan Hourihane not be used in
9706f2543Smrg * advertising or publicity pertaining to distribution of the software without
10706f2543Smrg * specific, written prior permission.  Alan Hourihane makes no representations
11706f2543Smrg * about the suitability of this software for any purpose.  It is provided
12706f2543Smrg * "as is" without express or implied warranty.
13706f2543Smrg *
14706f2543Smrg * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15706f2543Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16706f2543Smrg * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17706f2543Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18706f2543Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19706f2543Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20706f2543Smrg * PERFORMANCE OF THIS SOFTWARE.
21706f2543Smrg *
22706f2543Smrg * Authors:  Alan Hourihane, <alanh@fairlite.demon.co.uk>
23706f2543Smrg *
24706f2543Smrg * Generic RAMDAC access to colormaps.
25706f2543Smrg */
26706f2543Smrg
27706f2543Smrg#ifdef HAVE_XORG_CONFIG_H
28706f2543Smrg#include <xorg-config.h>
29706f2543Smrg#endif
30706f2543Smrg
31706f2543Smrg#include <X11/X.h>
32706f2543Smrg#include <X11/Xproto.h>
33706f2543Smrg#include "windowstr.h"
34706f2543Smrg#include "mipointer.h"
35706f2543Smrg#include "micmap.h"
36706f2543Smrg
37706f2543Smrg#include "xf86.h"
38706f2543Smrg#include "compiler.h"
39706f2543Smrg#include "colormapst.h"
40706f2543Smrg#include "xf86RamDacPriv.h"
41706f2543Smrg
42706f2543Smrgvoid
43706f2543SmrgRamDacLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors,
44706f2543Smrg		 VisualPtr pVisual)
45706f2543Smrg{
46706f2543Smrg    RamDacRecPtr hwp = RAMDACSCRPTR(pScrn);
47706f2543Smrg    int i, index;
48706f2543Smrg
49706f2543Smrg    for (i = 0; i < numColors; i++) {
50706f2543Smrg	index = indices[i];
51706f2543Smrg	(*hwp->WriteAddress)(pScrn, index);
52706f2543Smrg	(*hwp->WriteData)(pScrn, colors[index].red);
53706f2543Smrg	(*hwp->WriteData)(pScrn, colors[index].green);
54706f2543Smrg	(*hwp->WriteData)(pScrn, colors[index].blue);
55706f2543Smrg    }
56706f2543Smrg}
57706f2543Smrg
58706f2543SmrgBool
59706f2543SmrgRamDacHandleColormaps(ScreenPtr pScreen, int maxColors, int sigRGBbits,
60706f2543Smrg		      unsigned int flags)
61706f2543Smrg{
62706f2543Smrg    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
63706f2543Smrg    RamDacRecPtr hwp = RAMDACSCRPTR(pScrn);
64706f2543Smrg
65706f2543Smrg    if (hwp->LoadPalette == NULL)
66706f2543Smrg   	return xf86HandleColormaps(pScreen, maxColors, sigRGBbits,
67706f2543Smrg			     RamDacLoadPalette, NULL, flags);
68706f2543Smrg    else
69706f2543Smrg    	return xf86HandleColormaps(pScreen, maxColors, sigRGBbits,
70706f2543Smrg			     hwp->LoadPalette, NULL, flags);
71706f2543Smrg}
72